3
0
mirror of https://github.com/CrazyRedMachine/popnhax.git synced 2024-11-27 23:40:50 +01:00

fix quickretire without pfree

This commit is contained in:
CrazyRedMachine 2023-02-19 15:08:38 +01:00
parent fe6fd21802
commit 9bb1f8b363

View File

@ -245,6 +245,16 @@ void hidden_is_offset_commit_options()
}
void (*real_stage_update)();
void hook_stage_update_pfree()
{
//__asm("push ebx\n"); //handled by :"=b"
__asm("mov ebx, dword ptr [esi+0x14]\n");
__asm("lea ebx, [ebx+0xC]\n");
__asm("mov %0, ebx\n":"=b"(g_transition_addr): :);
//__asm("pop ebx\n");
//__asm("ret\n");
}
void hook_stage_update()
{
//__asm("push ebx\n"); //handled by :"=b"
@ -253,6 +263,7 @@ void hook_stage_update()
__asm("mov %0, ebx\n":"=b"(g_transition_addr): :);
//__asm("pop ebx\n");
//__asm("ret\n");
real_stage_update();
}
void (*real_check_music_idx)();
@ -1430,7 +1441,7 @@ static bool patch_pfree() {
g_stage_addr = *(uint32_t*)(patch_addr+1);
/* hook to retrieve address for exit to thank you for playing screen */
MH_CreateHook((LPVOID)patch_addr, (LPVOID)hook_stage_update,
MH_CreateHook((LPVOID)patch_addr, (LPVOID)hook_stage_update_pfree,
(void **)&real_stage_update);
}
@ -1553,11 +1564,37 @@ pfree_apply:
return true;
}
static bool patch_quick_retire()
static bool patch_quick_retire(bool pfree)
{
DWORD dllSize = 0;
char *data = getDllData("popn22.dll", &dllSize);
if ( !pfree )
{
/* hook the stage counter function to retrieve stage and transition addr for quick exit session
* (when pfree is active it's taking care of hooking that function differently to prevent stage from incrementing)
*/
{
fuzzy_search_task task;
FUZZY_START(task, 1)
FUZZY_CODE(task, 0, "\x83\xF8\x04\x77\x3E", 5)
int64_t pattern_offset = find_block(data, dllSize, &task, 0);
if (pattern_offset == -1) {
printf("couldn't find stop stage counter\n");
return false;
}
uint64_t patch_addr = (int64_t)data + pattern_offset - 0x05;
g_stage_addr = *(uint32_t*)(patch_addr+1);
/* hook to retrieve address for exit to thank you for playing screen */
MH_CreateHook((LPVOID)patch_addr, (LPVOID)hook_stage_update,
(void **)&real_stage_update);
}
}
/* hook numpad for instant quit song */
{
fuzzy_search_task task;
@ -1698,7 +1735,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
}
if (config.quick_retire) {
patch_quick_retire();
patch_quick_retire(config.pfree);
}
if (config.hd_on_sd) {