From d17bd63f3a1b1f789b43e88611cd6f6d06e18a86 Mon Sep 17 00:00:00 2001 From: CrazyRedMachine Date: Thu, 6 Jun 2024 09:55:31 +0200 Subject: [PATCH] fix local favorite end of credit crash with guest --- dist/popnhax/popnhax.xml | 1 - popnhax/custom_categs.cc | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/dist/popnhax/popnhax.xml b/dist/popnhax/popnhax.xml index 704fb4f..fbf369b 100644 --- a/dist/popnhax/popnhax.xml +++ b/dist/popnhax/popnhax.xml @@ -99,7 +99,6 @@ 0 - 0 diff --git a/popnhax/custom_categs.cc b/popnhax/custom_categs.cc index d508588..d0021bc 100644 --- a/popnhax/custom_categs.cc +++ b/popnhax/custom_categs.cc @@ -680,6 +680,31 @@ static bool patch_custom_track_format(const char *game_dll_fn) { return true; } +void (*real_remove_fake_login)(); +void hook_remove_fake_login() +{ + //getPlayerDataAddr was just called so eax contains _playerdata_addr + __asm("push ebx\n"); + __asm("push ecx\n"); + __asm("lea ebx, [eax+0x1A5]\n"); //login status offset + __asm("lea ecx, [eax+0x08]\n"); //friendid offset + __asm("mov ecx, [ecx]\n"); + __asm("cmp ecx, 0x61666564\n"); //defa + __asm("jne skip_remove_login\n"); + __asm("lea ecx, [eax+0x0C]\n"); //friendid offset + __asm("mov ecx, [ecx]\n"); + __asm("cmp ecx, 0x00746C75\n"); //ult + __asm("jne skip_remove_login\n"); + + //fake login detected, cleanup + __asm("mov dword ptr [ebx], 0x00000000\n"); + + __asm("skip_remove_login:\n"); + __asm("pop ecx\n"); + __asm("pop ebx\n"); + real_remove_fake_login(); +} + static bool patch_favorite_categ(const char *game_dll_fn) { DWORD dllSize = 0; @@ -722,6 +747,19 @@ static bool patch_favorite_categ(const char *game_dll_fn) { g_playerdata_ptr_addr = (*(uint32_t *)(data + pattern_offset + 0x25)); } + //and I need to remove the fake "logged in" status on credit end to prevent a crash + { + int64_t pattern_offset = search(data, dllSize, "\x84\xC0\x74\x07\xBB\x01\x00\x00\x00\xEB\x02\x33\xDB", 13, 0); + if (pattern_offset == -1) { + LOG("popnhax: local_favorites: cannot find end of credit check if logged function\n"); + return false; + } + + uint64_t patch_addr = (int64_t)data + pattern_offset - 0x05; + + MH_CreateHook((LPVOID)patch_addr, (LPVOID)hook_remove_fake_login, + (void **)&real_remove_fake_login); + } //hook result screen to replace 3 functions {