From 9d84b0bb747434e2d5d81c083db092880c85211d Mon Sep 17 00:00:00 2001 From: Eddoursul Date: Sun, 10 Dec 2023 21:10:58 +0100 Subject: [PATCH] Map marker placement fixes: - Allow placing map markers on discovered locations (from po3's Tweaks) - Place map markers on undiscovered locations without asking --- SKSE/Plugins/EnderalSE.dll | 4 +- SKSE/Plugins/EnderalSE.ini | 1 + source/Enderal DLL/src/FlatMapMarkers.h | 1 + source/Enderal DLL/src/Main.cpp | 10 ++- source/Enderal DLL/src/MapMarkerPlacement.h | 67 +++++++++++++++++++++ source/Enderal DLL/vcpkg-configuration.json | 31 ++++++---- 6 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 source/Enderal DLL/src/MapMarkerPlacement.h diff --git a/SKSE/Plugins/EnderalSE.dll b/SKSE/Plugins/EnderalSE.dll index 2989e47a..291f51f9 100644 --- a/SKSE/Plugins/EnderalSE.dll +++ b/SKSE/Plugins/EnderalSE.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c71b1d48c90e85a61283eba094d6349926d6506784e7dc788f481102726165a5 -size 726528 +oid sha256:6ab861df47b2f179f3027237b840764dd31fe1cac6d636587698d9a2f28d386f +size 730624 diff --git a/SKSE/Plugins/EnderalSE.ini b/SKSE/Plugins/EnderalSE.ini index 8c672f65..0583456b 100644 --- a/SKSE/Plugins/EnderalSE.ini +++ b/SKSE/Plugins/EnderalSE.ini @@ -1,2 +1,3 @@ FlatMapMarkers = true StayAtSystemPage = true +MapMarkerPlacementFixes = true diff --git a/source/Enderal DLL/src/FlatMapMarkers.h b/source/Enderal DLL/src/FlatMapMarkers.h index 3c0bc2f2..b106f5e8 100644 --- a/source/Enderal DLL/src/FlatMapMarkers.h +++ b/source/Enderal DLL/src/FlatMapMarkers.h @@ -14,6 +14,7 @@ namespace FlatMapMarkers inline void Install() { REL::Relocation offset{ RELOCATION_ID(52224, 53111), IsSE() ? 0x22F : 0x21F }; + SKSE::AllocTrampoline(14); auto& trampoline = SKSE::GetTrampoline(); trampoline.write_call<5>(offset.address(), &Hook_WorldPtToScreenPt3); } diff --git a/source/Enderal DLL/src/Main.cpp b/source/Enderal DLL/src/Main.cpp index 2c17e3ea..45ac83b7 100644 --- a/source/Enderal DLL/src/Main.cpp +++ b/source/Enderal DLL/src/Main.cpp @@ -3,12 +3,14 @@ #include "Papyrus.h" #include "FlatMapMarkers.h" #include "StayAtSystemPage.h" +#include "MapMarkerPlacement.h" using namespace SKSE; static std::map g_settings{ { "FlatMapMarkers", true }, - { "StayAtSystemPage", true } + { "StayAtSystemPage", true }, + { "MapMarkerPlacementFixes", true } }; namespace { @@ -48,7 +50,10 @@ namespace { exit(EXIT_FAILURE); } } - + if (g_settings.at("MapMarkerPlacementFixes")) { + logger::info("Initializing map market placement fixes..."); + MapMarkerPlacement::Install(); + } } else if (message->type == MessagingInterface::kDataLoaded) { const auto dataHandler = RE::TESDataHandler::GetSingleton(); if (dataHandler) { @@ -148,7 +153,6 @@ SKSEPluginLoad(const LoadInterface* skse) { if (!IsVR()) { if (g_settings.at("FlatMapMarkers")) { logger::info("Initializing Flat Map Markers..."); - SKSE::AllocTrampoline(1 << 4); FlatMapMarkers::Install(); } if (g_settings.at("StayAtSystemPage")) { diff --git a/source/Enderal DLL/src/MapMarkerPlacement.h b/source/Enderal DLL/src/MapMarkerPlacement.h new file mode 100644 index 00000000..506c3f30 --- /dev/null +++ b/source/Enderal DLL/src/MapMarkerPlacement.h @@ -0,0 +1,67 @@ +#pragma once + +// Based on powerofthree's Tweaks 1.8.1 by powerofthree (MIT) +namespace MapMarkerPlacement +{ + constexpr std::uint8_t NOP{ 0x90 }; + + struct IsFastTravelEnabled + { + static bool thunk(RE::PlayerCharacter* a_this, bool a_hideNotification) + { + const auto enabled = func(a_this, a_hideNotification); + if (!enabled) { + if (const auto mapMenu = RE::UI::GetSingleton()->GetMenu(); mapMenu) { + mapMenu->PlaceMarker(); + } + } + return enabled; + } + static inline REL::Relocation func; + }; + + void InstallPlacementDiscoveredFix() + { + // Place a marker, if a location has been discovered and fast travel is disabled + + REL::Relocation target{ REL::RelocationID(52208, 53095), REL::Relocate(0x2C5, 0x328, 0x358) }; + auto& trampoline = SKSE::GetTrampoline(); + + SKSE::AllocTrampoline(14); + IsFastTravelEnabled::func = trampoline.write_call<5>(target.address(), IsFastTravelEnabled::thunk); + + logger::info("Applied discovered map marker placement fix"sv); + } + + void InstallPlacementUndiscoveredFix() + { + // Place a marker without asking, if a location isn't discovered yet + + REL::Relocation target2{ REL::RelocationID(52208, 53095), REL::Relocate(0x17A, 0x183) }; + std::uint8_t code[] = { 0xB0, 0x01, NOP, NOP, NOP }; + REL::safe_write(target2.address(), code, 5); + + logger::info("Applied undiscovered map marker placement fix"sv); + } + + void Install() + { + if (GetLoadInterface()->GetPluginInfo("DisableFastTravel")) { + logger::info("Detected Disable Fast Travel SKSE, skipping discovered map marker placement fix"); + } else if (!GetLoadInterface()->GetPluginInfo("po3_Tweaks")) { + InstallPlacementDiscoveredFix(); + } else if (std::filesystem::exists("Data/SKSE/Plugins/po3_Tweaks.ini")) { + CSimpleIniA ini; + ini.SetMultiKey(false); + ini.LoadFile("Data/SKSE/Plugins/po3_Tweaks.ini"); + if (!ini.GetBoolValue("Fixes", "Map Marker Placement Fix", false)) { + logger::info("Detected po3's Tweaks with disabled discovered Map Marker Placement Fix"); + InstallPlacementDiscoveredFix(); + } else { + logger::info("Detected po3's Tweaks with enabled discovered Map Marker Placement Fix"); + } + } + + InstallPlacementUndiscoveredFix(); + } +} diff --git a/source/Enderal DLL/vcpkg-configuration.json b/source/Enderal DLL/vcpkg-configuration.json index 95905a0a..54bfde8c 100644 --- a/source/Enderal DLL/vcpkg-configuration.json +++ b/source/Enderal DLL/vcpkg-configuration.json @@ -1,15 +1,20 @@ { - "registries": [ - { - "kind": "git", - "repository": "https://gitlab.com/colorglass/vcpkg-colorglass", - "baseline": "6309841a1ce770409708a67a9ba5c26c537d2937", - "packages": [ - "commonlibsse-ng", - "gluino", - "script-extender-common", - "skse" - ] - } - ] + "default-registry": { + "kind": "git", + "repository": "https://github.com/microsoft/vcpkg.git", + "baseline": "08c4e71048eb54733d9b180a28b9b1d7ce637454" + }, + "registries": [ + { + "kind": "git", + "repository": "https://gitlab.com/colorglass/vcpkg-colorglass", + "baseline": "6309841a1ce770409708a67a9ba5c26c537d2937", + "packages": [ + "commonlibsse-ng", + "gluino", + "script-extender-common", + "skse" + ] + } + ] }