Moved C++ patches to a subdirectory

This commit is contained in:
Eddoursul 2023-12-21 12:41:08 +01:00
parent 85c1cc1b0c
commit 78ad540b93
17 changed files with 50 additions and 149 deletions

BIN
SKSE/Plugins/EnderalSE.dll (Stored with Git LFS)

Binary file not shown.

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <unordered_set>
static bool bMessageShown = false; static bool bMessageShown = false;
static std::unordered_set<std::string> aModNames; static std::unordered_set<std::string> aModNames;

View File

@ -1,5 +1,4 @@
#include "EventListener.h" #include "EventListener.h"
#include "Patches/HeroMenuPatch.h"
auto EventListener::GetSingleton() -> EventListener* auto EventListener::GetSingleton() -> EventListener*
{ {

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "DialogueMenuPatch.h" #include "Patches/DialogueMenuPatch.h"
#include "Patches/HeroMenuPatch.h"
#include "Util.h" #include "Util.h"
#include <shellapi.h> #include <shellapi.h>

View File

@ -1,12 +1,12 @@
#include "EventListener.h" #include "EventListener.h"
#include "Util.h" #include "Util.h"
#include "Papyrus.h" #include "Papyrus.h"
#include "FlatMapMarkers.h" #include "Patches/FlatMapMarkers.h"
#include "StayAtSystemPage.h" #include "Patches/StayAtSystemPage.h"
#include "MapMarkerPlacement.h" #include "Patches/MapMarkerPlacement.h"
#include "AchievementFix.h" #include "Patches/AchievementFix.h"
#include "BinkInterruptPatch.h" #include "Patches/BinkInterruptPatch.h"
#include "DialogueMenuPatch.h" #include "Patches/DialogueMenuPatch.h"
#include "Patches/TweenMenuPatch.h" #include "Patches/TweenMenuPatch.h"
#include "Patches/HeroMenuPatch.h" #include "Patches/HeroMenuPatch.h"
#include "Patches/HUDMenuPatch.h" #include "Patches/HUDMenuPatch.h"

View File

@ -1,107 +1,10 @@
#pragma once #pragma once
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfenv>
#include <cfloat>
#include <cinttypes>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cuchar>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <any>
#include <array>
#include <atomic>
#include <barrier>
#include <bit>
#include <bitset>
#include <charconv>
#include <chrono>
#include <compare>
#include <complex>
#include <concepts>
#include <condition_variable>
#include <deque>
#include <exception>
#include <execution>
#include <filesystem>
#include <format>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <initializer_list>
#include <iomanip>
#include <iosfwd>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <latch>
#include <limits>
#include <locale>
#include <map>
#include <memory>
#include <memory_resource>
#include <mutex>
#include <new>
#include <numbers>
#include <numeric>
#include <optional>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <regex>
#include <ratio>
#include <scoped_allocator>
#include <semaphore>
#include <set>
#include <shared_mutex>
#include <source_location>
#include <span>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <string_view>
#include <syncstream>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <typeinfo>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <variant>
#include <vector>
#include <version>
#include <RE/Skyrim.h> #include <RE/Skyrim.h>
#include <SKSE/SKSE.h> #include <SKSE/SKSE.h>
#include <REL/Relocation.h> #include <REL/Relocation.h>
#include <ShlObj_core.h> #include <ShlObj_core.h>
#include <Windows.h>
#include <Psapi.h>
#undef cdecl // Workaround for Clang 14 CMake configure error. #undef cdecl // Workaround for Clang 14 CMake configure error.
#include <spdlog/sinks/basic_file_sink.h> #include <spdlog/sinks/basic_file_sink.h>
@ -114,7 +17,3 @@ using namespace std::literals;
using namespace REL::literals; using namespace REL::literals;
namespace logger = SKSE::log; namespace logger = SKSE::log;
namespace util {
using SKSE::stl::report_and_fail;
}

View File

@ -2,8 +2,6 @@
#define BIND(a_method, ...) a_vm.RegisterFunction(#a_method##sv, script, a_method __VA_OPT__(, ) __VA_ARGS__) #define BIND(a_method, ...) a_vm.RegisterFunction(#a_method##sv, script, a_method __VA_OPT__(, ) __VA_ARGS__)
#include <RE/Skyrim.h>
namespace Papyrus { namespace Papyrus {
using VM = RE::BSScript::Internal::VirtualMachine; using VM = RE::BSScript::Internal::VirtualMachine;
using StackID = RE::VMStackID; using StackID = RE::VMStackID;

View File

@ -2,7 +2,7 @@
#include "Util.h" #include "Util.h"
#include "PersistentFormManager.h" #include "PersistentFormManager.h"
#include "DialogueMenuPatch.h" #include "Patches/DialogueMenuPatch.h"
namespace Papyrus::PapyrusFunctions namespace Papyrus::PapyrusFunctions
{ {

View File

@ -2,19 +2,19 @@
namespace AchievementFix namespace AchievementFix
{ {
constexpr std::uint8_t NOP{ 0x90 };
void Install() void Install()
{ {
REL::Relocation<std::uintptr_t> target; REL::Relocation<std::uintptr_t> target;
if (GetLoadInterface()->RuntimeVersion().minor() > 6 || GetLoadInterface()->RuntimeVersion().patch() >= 1130) { if (GetLoadInterface()->RuntimeVersion().minor() > 6 || GetLoadInterface()->RuntimeVersion().patch() >= 1130) {
// Checked: 1.6.1130
target = REL::ID(441528); target = REL::ID(441528);
} else { } else {
// Checked: 1.5.97, 1.6.640, 1.6.659
target = REL::RelocationID(13647, 13755); target = REL::RelocationID(13647, 13755);
} }
std::uint8_t code[] = { 0xB0, 0x00, 0xC3, NOP }; std::uint8_t code[] = { 0xB0, 0x00, 0xC3, REL::NOP };
REL::safe_write(target.address(), code, sizeof(code)); REL::safe_write(target.address(), code, sizeof(code));
} }
} }

View File

@ -35,10 +35,9 @@ namespace BinkInterruptPatch
void Install() void Install()
{ {
// Checked: 1.5.97, 1.6.640, 1.6.659, 1.6.1130
REL::Relocation<std::uintptr_t> target{ REL::RelocationID(87890, 90259), REL::Relocate(0x22, 0x21) }; REL::Relocation<std::uintptr_t> target{ REL::RelocationID(87890, 90259), REL::Relocate(0x22, 0x21) };
auto& trampoline = SKSE::GetTrampoline();
SKSE::AllocTrampoline(14); SKSE::AllocTrampoline(14);
BinkListener::func = trampoline.write_call<5>(target.address(), BinkListener::thunk); BinkListener::func = SKSE::GetTrampoline().write_call<5>(target.address(), BinkListener::thunk);
} }
} }

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "Util.h"
inline bool bTabBlocked = false; inline bool bTabBlocked = false;
class DialogueMenuPatch final : public RE::DialogueMenu class DialogueMenuPatch final : public RE::DialogueMenu
@ -38,7 +36,15 @@ private:
return _ProcessMessageFn(this, a_message); return _ProcessMessageFn(this, a_message);
} }
using ProcessMessageFn = decltype(&RE::DialogueMenu::ProcessMessage); // When opening from dialogue menu, a_bool must be false to not break framerate of the UI
void static OpenJournal(bool a_bool)
{
using func_t = decltype(&OpenJournal);
// Checked: 1.5.97, 1.6.640, 1.6.659, 1.6.1130
REL::Relocation<func_t> func{ REL::RelocationID(52428, 53327) };
func(a_bool);
}
using ProcessMessageFn = decltype(&ProcessMessage);
inline static REL::Relocation<ProcessMessageFn> _ProcessMessageFn; inline static REL::Relocation<ProcessMessageFn> _ProcessMessageFn;
}; };

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#include "Util.h"
// Based on Ryan McKenzie's Flat Map Markers // Based on Ryan McKenzie's Flat Map Markers
// CommonLibSSE-NG update by Eddoursul // CommonLibSSE-NG update by Eddoursul
namespace FlatMapMarkers namespace FlatMapMarkers
@ -14,9 +12,9 @@ namespace FlatMapMarkers
inline void Install() inline void Install()
{ {
// Checked: 1.5.97, 1.6.640, 1.6.659, 1.6.1130
REL::Relocation<std::uintptr_t> offset{ REL::RelocationID(52224, 53111), REL::Relocate(0x22F, 0x21F) }; REL::Relocation<std::uintptr_t> offset{ REL::RelocationID(52224, 53111), REL::Relocate(0x22F, 0x21F) };
SKSE::AllocTrampoline(14); SKSE::AllocTrampoline(14);
auto& trampoline = SKSE::GetTrampoline(); SKSE::GetTrampoline().write_call<5>(offset.address(), &Hook_WorldPtToScreenPt3);
trampoline.write_call<5>(offset.address(), &Hook_WorldPtToScreenPt3);
} }
} }

View File

@ -5,8 +5,10 @@ RE::BSEventNotifyControl HeroMenuPatch::ProcessEvent_Hook(RE::InputEvent** a_eve
if (RE::UI::GetSingleton()->GameIsPaused() && a_event && *a_event) { if (RE::UI::GetSingleton()->GameIsPaused() && a_event && *a_event) {
auto buttonEvent = (*a_event)->AsButtonEvent(); auto buttonEvent = (*a_event)->AsButtonEvent();
if (buttonEvent && buttonEvent->IsDown() && RE::UI::GetSingleton()->IsMenuOpen("CustomMenu")) { if (buttonEvent && buttonEvent->IsDown() && RE::UI::GetSingleton()->IsMenuOpen("CustomMenu")) {
auto& eventName = (*a_event)->QUserEvent(); auto& eventName = (*a_event)->QUserEvent();
auto userEvents = RE::UserEvents::GetSingleton(); auto userEvents = RE::UserEvents::GetSingleton();
if (eventName == userEvents->cancel || eventName == userEvents->quickStats) { if (eventName == userEvents->cancel || eventName == userEvents->quickStats) {
auto uiMovie = RE::UI::GetSingleton()->GetMovieView("CustomMenu"); auto uiMovie = RE::UI::GetSingleton()->GetMovieView("CustomMenu");
if (uiMovie && std::strstr(uiMovie->GetMovieDef()->GetFileURL(), "00e_heromenu.swf") != NULL) { if (uiMovie && std::strstr(uiMovie->GetMovieDef()->GetFileURL(), "00e_heromenu.swf") != NULL) {
@ -21,17 +23,17 @@ RE::BSEventNotifyControl HeroMenuPatch::ProcessEvent_Hook(RE::InputEvent** a_eve
void HeroMenuPatch::Install() void HeroMenuPatch::Install()
{ {
// Patch MenuControls // Patch MenuControls to close the menu
REL::Relocation<std::uintptr_t> vTable(RE::VTABLE_MenuControls[0]); REL::Relocation<std::uintptr_t> vTable(RE::VTABLE_MenuControls[0]);
_ProcessEvent = vTable.write_vfunc(0x1, &HeroMenuPatch::ProcessEvent_Hook); _ProcessEvent = vTable.write_vfunc(0x1, &HeroMenuPatch::ProcessEvent_Hook);
// Patch the Quick Stats hotkey // Patch the Quick Stats hotkey to open the menu
// Checked: 1.5.97, 1.6.640, 1.6.659, 1.6.1130
REL::Relocation<std::uintptr_t> target{ REL::RelocationID(51400, 52249), REL::Relocate(0x41E, 0x421) }; REL::Relocation<std::uintptr_t> target{ REL::RelocationID(51400, 52249), REL::Relocate(0x41E, 0x421) };
REL::safe_fill(target.address(), REL::NOP, 45); REL::safe_fill(target.address(), REL::NOP, 45);
auto& trampoline = SKSE::GetTrampoline();
SKSE::AllocTrampoline(14); SKSE::AllocTrampoline(14);
_OpenStats = trampoline.write_call<5>(target.address(), OpenStats); _OpenStats = SKSE::GetTrampoline().write_call<5>(target.address(), OpenStats);
REL::Relocation<std::uintptr_t> target2{ REL::RelocationID(51400, 52249), REL::Relocate(0x436, 0x439) }; REL::Relocation<std::uintptr_t> target2{ REL::RelocationID(51400, 52249), REL::Relocate(0x436, 0x439) };
std::uint8_t code[] = { 0x40, 0xB5, 0x01 }; std::uint8_t code[] = { 0x40, 0xB5, 0x01 };
@ -60,7 +62,7 @@ void HeroMenuPatch::FillMenuValues()
if (a_result.IsString()) { if (a_result.IsString()) {
auto uiMovie = RE::UI::GetSingleton()->GetMovieView("CustomMenu"); auto uiMovie = RE::UI::GetSingleton()->GetMovieView("CustomMenu");
if (uiMovie) { if (uiMovie) {
uiMovie->SetVariable("_root.heromenu_mc.stats.playerclass.stat_value.text", a_result.GetString()); uiMovie->SetVariable("heromenu_mc.stats.playerclass.stat_value.text", a_result.GetString(), RE::GFxMovie::SetVarType::kNormal);
} }
} }
} }
@ -69,6 +71,12 @@ void HeroMenuPatch::FillMenuValues()
}; };
auto uiMovie = RE::UI::GetSingleton()->GetMovieView("CustomMenu"); auto uiMovie = RE::UI::GetSingleton()->GetMovieView("CustomMenu");
if (!uiMovie) {
return;
}
// Fit the movie into the screen (widescreen support)
uiMovie->SetViewScaleMode(RE::BSScaleformManager::ScaleModeType::kShowAll); uiMovie->SetViewScaleMode(RE::BSScaleformManager::ScaleModeType::kShowAll);
const auto dataHandler = RE::TESDataHandler::GetSingleton(); const auto dataHandler = RE::TESDataHandler::GetSingleton();
@ -89,7 +97,7 @@ void HeroMenuPatch::FillMenuValues()
RE::GFxValue args[2]; RE::GFxValue args[2];
args[0].SetString(player->GetDisplayFullName()); args[0].SetString(player->GetDisplayFullName());
args[1].SetString(""); args[1].SetString("");
uiMovie->Invoke("_root.heromenu_mc.SetStringValues", nullptr, args, 2); uiMovie->Invoke("heromenu_mc.SetStringValues", nullptr, args, 2);
RE::BSTSmartPointer<RE::BSScript::IStackCallbackFunctor> stackCallback{ new ScriptClassNameCallback }; RE::BSTSmartPointer<RE::BSScript::IStackCallbackFunctor> stackCallback{ new ScriptClassNameCallback };
RE::BSScript::Internal::VirtualMachine::GetSingleton()->DispatchStaticCall("_00E_AffinityControl", "GetPlayerClassNameGlobal", RE::MakeFunctionArguments(), stackCallback); RE::BSScript::Internal::VirtualMachine::GetSingleton()->DispatchStaticCall("_00E_AffinityControl", "GetPlayerClassNameGlobal", RE::MakeFunctionArguments(), stackCallback);
@ -129,7 +137,7 @@ void HeroMenuPatch::FillMenuValues()
args2[31].SetNumber(playerExp->value - fEXPNeededForCurrentLevel); args2[31].SetNumber(playerExp->value - fEXPNeededForCurrentLevel);
args2[32].SetNumber(fEXPNeededForNextLevel - fEXPNeededForCurrentLevel); args2[32].SetNumber(fEXPNeededForNextLevel - fEXPNeededForCurrentLevel);
uiMovie->Invoke("_root.heromenu_mc.SetIntValues", nullptr, args2, 33); uiMovie->Invoke("heromenu_mc.SetIntValues", nullptr, args2, 33);
RE::GFxValue args3[21]; RE::GFxValue args3[21];
args3[0].SetNumber(0); args3[0].SetNumber(0);
@ -153,5 +161,5 @@ void HeroMenuPatch::FillMenuValues()
args3[18].SetNumber(playerAV->GetActorValue(RE::ActorValue::kEnchanting) - playerAV->GetBaseActorValue(RE::ActorValue::kEnchanting)); args3[18].SetNumber(playerAV->GetActorValue(RE::ActorValue::kEnchanting) - playerAV->GetBaseActorValue(RE::ActorValue::kEnchanting));
args3[19].SetNumber(playerAV->GetActorValue(RE::ActorValue::kSmithing) - playerAV->GetBaseActorValue(RE::ActorValue::kSmithing)); args3[19].SetNumber(playerAV->GetActorValue(RE::ActorValue::kSmithing) - playerAV->GetBaseActorValue(RE::ActorValue::kSmithing));
args3[20].SetNumber(playerAV->GetActorValue(RE::ActorValue::kSpeech) - playerAV->GetBaseActorValue(RE::ActorValue::kSpeech)); args3[20].SetNumber(playerAV->GetActorValue(RE::ActorValue::kSpeech) - playerAV->GetBaseActorValue(RE::ActorValue::kSpeech));
uiMovie->Invoke("_root.heromenu_mc.SetModifier", nullptr, args3, 21); uiMovie->Invoke("heromenu_mc.SetModifier", nullptr, args3, 21);
} }

View File

@ -21,12 +21,10 @@ namespace MapMarkerPlacement
void InstallPlacementDiscoveredFix() void InstallPlacementDiscoveredFix()
{ {
// Place a marker, if a location has been discovered and fast travel is disabled // Place a marker, if a location has been discovered and fast travel is disabled
// Checked: 1.5.97, 1.6.640, 1.6.659, 1.6.1130
REL::Relocation<std::uintptr_t> target{ REL::RelocationID(52208, 53095), REL::Relocate(0x2C5, 0x328, 0x358) }; REL::Relocation<std::uintptr_t> target{ REL::RelocationID(52208, 53095), REL::Relocate(0x2C5, 0x328, 0x358) };
auto& trampoline = SKSE::GetTrampoline();
SKSE::AllocTrampoline(14); SKSE::AllocTrampoline(14);
IsFastTravelEnabled::func = trampoline.write_call<5>(target.address(), IsFastTravelEnabled::thunk); IsFastTravelEnabled::func = SKSE::GetTrampoline().write_call<5>(target.address(), IsFastTravelEnabled::thunk);
logger::info("Applied discovered map marker placement fix"sv); logger::info("Applied discovered map marker placement fix"sv);
} }
@ -34,9 +32,9 @@ namespace MapMarkerPlacement
void InstallPlacementUndiscoveredFix() void InstallPlacementUndiscoveredFix()
{ {
// Place a marker without asking, if a location isn't discovered yet // Place a marker without asking, if a location isn't discovered yet
// Checked: 1.5.97, 1.6.640, 1.6.659, 1.6.1130
REL::Relocation<std::uintptr_t> target2{ REL::RelocationID(52208, 53095), REL::Relocate(0x17A, 0x183) }; REL::Relocation<std::uintptr_t> target2{ REL::RelocationID(52208, 53095), REL::Relocate(0x17A, 0x183) };
std::uint8_t code[] = { 0xB0, 0x01, REL::NOP, REL::NOP, REL::NOP }; std::uint8_t code[] = { 0xB0, 0x01, REL::NOP, REL::NOP, REL::NOP }; // mov al,0x1
REL::safe_write(target2.address(), code, sizeof(code)); REL::safe_write(target2.address(), code, sizeof(code));
logger::info("Applied undiscovered map marker placement fix"sv); logger::info("Applied undiscovered map marker placement fix"sv);

View File

@ -54,5 +54,5 @@ public:
static inline REL::Relocation<decltype(&Hook_Accept)> _Accept; static inline REL::Relocation<decltype(&Hook_Accept)> _Accept;
static inline REL::Relocation<decltype(&Hook_ProcessMessage)> _ProcessMessage; static inline REL::Relocation<decltype(&Hook_ProcessMessage)> _ProcessMessage;
static inline REL::Relocation<Tab*> _savedTabIdx{ RELOCATION_ID(520167, 406697) }; static inline REL::Relocation<Tab*> _savedTabIdx{ REL::RelocationID(520167, 406697) };
}; };

View File

@ -11,6 +11,7 @@ private:
static void OpenMenu(RE::IMenu* tweenMenu, std::int32_t index) static void OpenMenu(RE::IMenu* tweenMenu, std::int32_t index)
{ {
using func_t = decltype(&OpenMenu); using func_t = decltype(&OpenMenu);
// Checked: 1.5.97, 1.6.640, 1.6.659, 1.6.1130
REL::Relocation<func_t> func{ REL::RelocationID(51845, 52718) }; REL::Relocation<func_t> func{ REL::RelocationID(51845, 52718) };
return func(tweenMenu, index); return func(tweenMenu, index);
} }

View File

@ -162,14 +162,6 @@ inline void LoadINI(std::map<std::string, bool>* settings, const char* iniPath)
} }
} }
// When opening from dialogue menu, a_bool must be false to not break framerate of the UI
inline void OpenJournal(bool a_bool)
{
using func_t = decltype(&OpenJournal);
REL::Relocation<func_t> func{ REL::RelocationID(52428, 53327) };
return func(a_bool);
}
inline void CloseTweenMenu() inline void CloseTweenMenu()
{ {
if (RE::UI::GetSingleton()->IsMenuOpen(RE::TweenMenu::MENU_NAME)) { if (RE::UI::GetSingleton()->IsMenuOpen(RE::TweenMenu::MENU_NAME)) {