From 9e2cd2b1e489f6b0af5ab8c7a12d7751c3b3bc3b Mon Sep 17 00:00:00 2001 From: CrazyRedMachine Date: Sun, 22 Sep 2024 21:19:18 +0200 Subject: [PATCH] attract lights --- dist/popnhax/popnhax.xml | 4 +- popnhax/attract.cc | 150 ++++++++++++++++++++++++++++----------- popnhax/attract.h | 1 + popnhax/config.h | 1 + popnhax/dllmain.cc | 7 ++ 5 files changed, 120 insertions(+), 43 deletions(-) diff --git a/dist/popnhax/popnhax.xml b/dist/popnhax/popnhax.xml index fbc4f33..e245678 100644 --- a/dist/popnhax/popnhax.xml +++ b/dist/popnhax/popnhax.xml @@ -91,8 +91,10 @@ 0 - + 0 + + 0 0 diff --git a/popnhax/attract.cc b/popnhax/attract.cc index cad2fca..b4c1038 100644 --- a/popnhax/attract.cc +++ b/popnhax/attract.cc @@ -160,68 +160,69 @@ bool patch_full_attract() void (*real_attract_inter)(void); void hook_attract_inter() { - __asm("push 0x1EF\n"); - __asm("mov eax, dword ptr [_g_is_button_pressed_fn]\n"); - __asm("call eax\n"); - __asm("add esp, 4\n"); - __asm("test al, al\n"); - __asm("je skip_disable_autoplay\n"); - __asm("mov eax, dword ptr [_g_autoplay_marker_addr]\n"); - __asm("mov dword ptr [eax], 0\n"); - __asm("skip_disable_autoplay:"); - real_attract_inter(); + __asm("push 0x1EF\n"); + __asm("mov eax, dword ptr [_g_is_button_pressed_fn]\n"); + __asm("call eax\n"); + __asm("add esp, 4\n"); + __asm("test al, al\n"); + __asm("je skip_disable_autoplay\n"); + __asm("mov eax, dword ptr [_g_autoplay_marker_addr]\n"); + __asm("mov dword ptr [eax], 0\n"); + __asm("skip_disable_autoplay:"); + real_attract_inter(); } void (*real_retire_handling)(void); void hook_attract_inter_rearm() { - __asm("push eax\n"); - __asm("mov eax, dword ptr [_g_attract_marker_addr]\n"); - __asm("cmp word ptr [eax], 0x0101\n"); - __asm("jne skip_rearm_autoplay\n"); - __asm("mov eax, dword ptr [_g_autoplay_marker_addr]\n"); - __asm("mov dword ptr [eax], 1\n"); - __asm("skip_rearm_autoplay:"); - __asm("pop eax\n"); - real_retire_handling(); + __asm("push eax\n"); + __asm("mov eax, dword ptr [_g_attract_marker_addr]\n"); + __asm("cmp word ptr [eax], 0x0101\n"); + __asm("jne skip_rearm_autoplay\n"); + __asm("mov eax, dword ptr [_g_autoplay_marker_addr]\n"); + __asm("mov dword ptr [eax], 1\n"); + __asm("skip_rearm_autoplay:"); + __asm("pop eax\n"); + real_retire_handling(); } void (*real_songend_handling)(void); void hook_attract_inter_songend_rearm() { - __asm("push eax\n"); - __asm("mov eax, dword ptr [_g_attract_marker_addr]\n"); - __asm("cmp word ptr [eax], 0x0101\n"); - __asm("jne skip_se_rearm_autoplay\n"); - __asm("mov eax, dword ptr [_g_autoplay_marker_addr]\n"); - __asm("mov dword ptr [eax], 1\n"); - __asm("skip_se_rearm_autoplay:"); - __asm("pop eax\n"); - real_songend_handling(); + __asm("push eax\n"); + __asm("mov eax, dword ptr [_g_attract_marker_addr]\n"); + __asm("cmp word ptr [eax], 0x0101\n"); + __asm("jne skip_se_rearm_autoplay\n"); + __asm("mov eax, dword ptr [_g_autoplay_marker_addr]\n"); + __asm("mov dword ptr [eax], 1\n"); + __asm("skip_se_rearm_autoplay:"); + __asm("pop eax\n"); + real_songend_handling(); } void (*real_test_handling)(void); void hook_attract_inter_rearm_test() { - __asm("push eax\n"); - __asm("mov eax, dword ptr [_g_attract_marker_addr]\n"); - __asm("cmp word ptr [eax], 0x0101\n"); - __asm("jne skip_rearm_autoplay_test\n"); - __asm("mov eax, dword ptr [_g_autoplay_marker_addr]\n"); - __asm("mov dword ptr [eax], 1\n"); - __asm("skip_rearm_autoplay_test:"); - __asm("pop eax\n"); - real_test_handling(); + __asm("push eax\n"); + __asm("mov eax, dword ptr [_g_attract_marker_addr]\n"); + __asm("cmp word ptr [eax], 0x0101\n"); + __asm("jne skip_rearm_autoplay_test\n"); + __asm("mov eax, dword ptr [_g_autoplay_marker_addr]\n"); + __asm("mov dword ptr [eax], 1\n"); + __asm("skip_rearm_autoplay_test:"); + __asm("pop eax\n"); + real_test_handling(); } void (*real_rearm_marker)(void); void hook_retrieve_attractmarker() { - __asm("add esi, 0x18\n"); - __asm("mov dword ptr [_g_attract_marker_addr], esi\n"); - __asm("sub esi, 0x18\n"); - real_rearm_marker(); + __asm("add esi, 0x18\n"); + __asm("mov dword ptr [_g_attract_marker_addr], esi\n"); + __asm("sub esi, 0x18\n"); + real_rearm_marker(); } + bool patch_attract_interactive() { DWORD dllSize = 0; @@ -280,7 +281,7 @@ bool patch_attract_interactive() } /* disable interactive mode after a while without button press */ - { + { int64_t pattern_offset = search(data, dllSize, "\x3D\x58\x02\x00\x00\x7C", 6, 0); if (pattern_offset == -1) { LOG("popnhax: attract_interactive: cannot find retire handling\n"); @@ -340,4 +341,69 @@ bool patch_attract_interactive() LOG("popnhax: attract mode is interactive\n"); return true; +} + +uint32_t g_button_bitfield_addr = 0; + +void (*real_autoplay_handling)(void); +void hook_attract_autoplay() +{ + // ax contains button, need to OR g_button_bitfield_addr with 1<