patch: move transition animation patch to C++

This commit is contained in:
Ramen2X 2023-01-11 19:35:01 -05:00
parent cbc989348c
commit 947946fa0a
4 changed files with 55 additions and 20 deletions

View file

@ -177,26 +177,13 @@ __declspec(dllexport) DWORD WINAPI Patch()
SearchReplacePattern(dllBase, mq_pattern, mq_replace, 8); SearchReplacePattern(dllBase, mq_pattern, mq_replace, 8);
// Transition Animation // Transition Animation
std::string animation_type = config.GetString("TransitionType"); LPCVOID start_transition_offset = SearchPattern(dllBase, "\x89\x46\x2C\x8A\x44\x24\x14\x32\xC1\x24\x01\x32\xC1", 13);
int anim_val = 3;
if (animation_type == "No Animation") { MxResult (MxTransitionManager::* pFunc)(TransitionType, int, byte, bool) = &MxTransitionManager::InterceptStartTransition;
anim_val = 1; OverwriteAllCalls(dllBase, (char*)start_transition_offset - 40, (void*&) pFunc);
} else if (animation_type == "Dissolve") {
anim_val = 2; startTransitionOriginal = PointerToMemberFunction<startTransitionFunction>((char*)start_transition_offset - 40);
} 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);
// Field of view // Field of view
const char *fov_pattern = "\x00\x00\x00\x3F\x17\x6C\xC1\x16\x6C\xC1\x76\x3F"; const char *fov_pattern = "\x00\x00\x00\x3F\x17\x6C\xC1\x16\x6C\xC1\x76\x3F";

View file

@ -736,3 +736,23 @@ _CRTIMP size_t __cdecl InterceptFread(void *buffer, size_t size, size_t count, F
return freadOriginal(buffer, size, count, stream); 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);
}

View file

@ -69,4 +69,30 @@ typedef _CRTIMP size_t (__cdecl *freadFunction)(void *buffer, size_t size, size_
extern freadFunction freadOriginal; extern freadFunction freadOriginal;
_CRTIMP size_t __cdecl InterceptFread(void *buffer, size_t size, size_t count, FILE *stream); _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 #endif // HOOKS_H

View file

@ -7,6 +7,8 @@ BOOL WriteMemory(LPVOID destination, LPVOID source, size_t length, LPVOID oldDat
LPVOID OverwriteCall(LPVOID destination, LPVOID localCall); LPVOID OverwriteCall(LPVOID destination, LPVOID localCall);
int OverwriteAllCalls(LPVOID imageBase, LPCVOID from, LPCVOID to);
LPVOID SearchPattern(LPVOID imageBase, LPCVOID search, SIZE_T count); 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); SIZE_T SearchReplacePattern(LPVOID imageBase, LPCVOID search, LPCVOID replace, SIZE_T count, BOOL only_once = FALSE);