From 947946fa0a94c8a66cf9811cebada5a7ada54ed3 Mon Sep 17 00:00:00 2001 From: Ramen2X <64166386+Ramen2X@users.noreply.github.com> Date: Wed, 11 Jan 2023 19:35:01 -0500 Subject: [PATCH] patch: move transition animation patch to C++ --- lib/dllmain.cpp | 27 +++++++-------------------- lib/hooks.cpp | 20 ++++++++++++++++++++ lib/hooks.h | 26 ++++++++++++++++++++++++++ lib/util.h | 2 ++ 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/lib/dllmain.cpp b/lib/dllmain.cpp index a751134..9d04f48 100644 --- a/lib/dllmain.cpp +++ b/lib/dllmain.cpp @@ -177,26 +177,13 @@ __declspec(dllexport) DWORD WINAPI Patch() SearchReplacePattern(dllBase, mq_pattern, mq_replace, 8); // Transition Animation - std::string animation_type = config.GetString("TransitionType"); - int anim_val = 3; - if (animation_type == "No Animation") { - anim_val = 1; - } else if (animation_type == "Dissolve") { - anim_val = 2; - } else if (animation_type == "Pixelation") { - anim_val = 3; - } else if (animation_type == "Vertical Wipe") { - anim_val = 4; - } else if (animation_type == "Window") { - anim_val = 5; - } - const char *at_pattern = "\x89\x46\x2C\x8A\x44\x24\x14\x32\xC1\x24\x01\x32\xC1"; - char at_replace[13]; - memcpy(at_replace, at_pattern, 13); - memcpy(at_replace, "\xC7", 1); - memcpy(at_replace+3, &anim_val, sizeof(anim_val)); - memcpy(at_replace+11, "\xB0\x00", 2); - SearchReplacePattern(dllBase, at_pattern, at_replace, 13); + LPCVOID start_transition_offset = SearchPattern(dllBase, "\x89\x46\x2C\x8A\x44\x24\x14\x32\xC1\x24\x01\x32\xC1", 13); + + MxResult (MxTransitionManager::* pFunc)(TransitionType, int, byte, bool) = &MxTransitionManager::InterceptStartTransition; + OverwriteAllCalls(dllBase, (char*)start_transition_offset - 40, (void*&) pFunc); + + startTransitionOriginal = PointerToMemberFunction((char*)start_transition_offset - 40); + // Field of view const char *fov_pattern = "\x00\x00\x00\x3F\x17\x6C\xC1\x16\x6C\xC1\x76\x3F"; diff --git a/lib/hooks.cpp b/lib/hooks.cpp index 1a74d40..8f3b1eb 100644 --- a/lib/hooks.cpp +++ b/lib/hooks.cpp @@ -736,3 +736,23 @@ _CRTIMP size_t __cdecl InterceptFread(void *buffer, size_t size, size_t count, F return freadOriginal(buffer, size, count, stream); } + +startTransitionFunction startTransitionOriginal = NULL; +MxResult MxTransitionManager::InterceptStartTransition(TransitionType animationType, int speed, byte unk, bool playMusicInTransition) +{ + std::string animation_type = config.GetString("TransitionType"); + + if (animation_type == "No Animation") { + animationType = NO_ANIMATION; + } else if (animation_type == "Dissolve") { + animationType = DISSOLVE; + } else if (animation_type == "Pixelation") { + animationType = PIXELATION; + } else if (animation_type == "Vertical Wipe") { + animationType = VERTICAL_WIPE; + } else if (animation_type == "Window") { + animationType = WINDOW; + } + + return (this->*startTransitionOriginal)(animationType, speed, unk, playMusicInTransition); +} diff --git a/lib/hooks.h b/lib/hooks.h index bb8c9d9..1f85a1a 100644 --- a/lib/hooks.h +++ b/lib/hooks.h @@ -69,4 +69,30 @@ typedef _CRTIMP size_t (__cdecl *freadFunction)(void *buffer, size_t size, size_ extern freadFunction freadOriginal; _CRTIMP size_t __cdecl InterceptFread(void *buffer, size_t size, size_t count, FILE *stream); +enum MxResult +{ + SUCCESS = 0, + FAILURE = 0xFFFFFFFF +}; + +enum TransitionType +{ + NOT_TRANSITIONING = 0, + NO_ANIMATION = 1, + DISSOLVE = 2, + PIXELATION = 3, + VERTICAL_WIPE = 4, + WINDOW = 5, + BROKEN = 6 +}; + +class MxTransitionManager +{ +public: + MxResult InterceptStartTransition(TransitionType animationType, int speed, byte unk, bool playMusicInTransition); +}; + +typedef MxResult (MxTransitionManager::* startTransitionFunction)(TransitionType, int, byte, bool); +extern startTransitionFunction startTransitionOriginal; + #endif // HOOKS_H diff --git a/lib/util.h b/lib/util.h index b5ca9f0..11a077e 100644 --- a/lib/util.h +++ b/lib/util.h @@ -7,6 +7,8 @@ BOOL WriteMemory(LPVOID destination, LPVOID source, size_t length, LPVOID oldDat LPVOID OverwriteCall(LPVOID destination, LPVOID localCall); +int OverwriteAllCalls(LPVOID imageBase, LPCVOID from, LPCVOID to); + LPVOID SearchPattern(LPVOID imageBase, LPCVOID search, SIZE_T count); SIZE_T SearchReplacePattern(LPVOID imageBase, LPCVOID search, LPCVOID replace, SIZE_T count, BOOL only_once = FALSE);