Compare commits

..

4 Commits

2 changed files with 37 additions and 11 deletions

View File

@ -232,8 +232,8 @@ $$(dll_$1_$2_$3) $$(implib_$1_$2_$3): $$(obj_$1_$2_$3) $$(abslib_$1_$2_$3) \
$(ccache) $$(toolchain_$1)gcc -shared $$(srcdir_$3)/$3.def \ $(ccache) $$(toolchain_$1)gcc -shared $$(srcdir_$3)/$3.def \
-o $$(dll_$1_$2_$3) -Wl,--out-implib,$$(implib_$1_$2_$3) \ -o $$(dll_$1_$2_$3) -Wl,--out-implib,$$(implib_$1_$2_$3) \
$$^ $$(ldflags_$3) $(optflags_$1) $$^ $$(ldflags_$3) $(optflags_$1)
strip -s $$(dll_$1_$2_$3) $$(toolchain_$1)strip -s $$(dll_$1_$2_$3)
ranlib $$(implib_$1_$2_$3) $$(toolchain_$1)ranlib $$(implib_$1_$2_$3)
endef endef
@ -248,7 +248,7 @@ exe_$1_$2_$3 := $$(bindir_$1_$2)/$3.exe
$$(exe_$1_$2_$3): $$(obj_$1_$2_$3) $$(abslib_$1_$2_$3) $$(absdpl_$1_$2_$3) \ $$(exe_$1_$2_$3): $$(obj_$1_$2_$3) $$(abslib_$1_$2_$3) $$(absdpl_$1_$2_$3) \
| $$(bindir_$1_$2) | $$(bindir_$1_$2)
$(ccache) $$(toolchain_$1)gcc -o $$@ $$^ $$(ldflags_$3) $(optflags_$1) $(ccache) $$(toolchain_$1)gcc -o $$@ $$^ $$(ldflags_$3) $(optflags_$1)
strip -s $$@ $$(toolchain_$1)strip -s $$@
endef endef
@ -259,7 +259,7 @@ define t_import
impdef_$1_$2_$3 ?= imports/import_$1_$2_$3.def impdef_$1_$2_$3 ?= imports/import_$1_$2_$3.def
$$(bindir_$1_$2)/lib$3.a: $$(impdef_$1_$2_$3) | $$(bindir_$1_$2) $$(bindir_$1_$2)/lib$3.a: $$(impdef_$1_$2_$3) | $$(bindir_$1_$2)
dlltool -l $$@ -d $$< $$(toolchain_$1)dlltool -l $$@ -d $$<
endef endef

View File

@ -31,6 +31,8 @@
#include "SearchFile.h" #include "SearchFile.h"
#define PROGRAM_VERSION "1.9c_rc1"
const char *g_game_dll_fn = NULL; const char *g_game_dll_fn = NULL;
const char *g_config_fn = NULL; const char *g_config_fn = NULL;
FILE *g_log_fp = NULL; FILE *g_log_fp = NULL;
@ -2346,17 +2348,19 @@ static bool patch_quick_retire(bool pfree)
/* no need to press red button when numpad 8 or 9 is pressed on result screen */ /* no need to press red button when numpad 8 or 9 is pressed on result screen */
{ {
int64_t pattern_offset = search(data, dllSize, "\x84\xC0\x75\x0F\x8B\x8D\x1C\x0A\x00\x00\xE8", 11, 0); int64_t pattern_offset = search(data, dllSize, "\x84\xC0\x75\x0F\x8B\x8D\x1C\x0A\x00\x00\xE8", 11, 0);
int adjust = 0;
if (pattern_offset == -1) { if (pattern_offset == -1) {
/* fallback */ /* fallback */
pattern_offset = search(data, dllSize, "\x84\xC0\x75\x0F\x8B\x8D\x98\x1C\x00\x00\xE8", 11, 0); pattern_offset = search(data, dllSize, "\x09\x00\x84\xC0\x75\x0F\x8B\x8D", 8, 0);
adjust = 2;
if (pattern_offset == -1) { if (pattern_offset == -1) {
LOG("popnhax: cannot retrieve result screen button check\n"); LOG("popnhax: cannot retrieve result screen button check\n");
return false; return false;
} }
} }
uint64_t patch_addr = (int64_t)data + pattern_offset + 0x1A; uint64_t patch_addr = (int64_t)data + pattern_offset + 0x1A + adjust;
MH_CreateHook((LPVOID)patch_addr, (LPVOID)quickexit_result_button_loop, MH_CreateHook((LPVOID)patch_addr, (LPVOID)quickexit_result_button_loop,
(void **)&real_result_button_loop); (void **)&real_result_button_loop);
@ -4307,6 +4311,7 @@ uint16_t *g_base_bpm_ptr = 0; //will point to g_low_bpm or g_hi_bpm according to
uint16_t g_low_bpm = 0; uint16_t g_low_bpm = 0;
uint16_t g_hi_bpm = 0; uint16_t g_hi_bpm = 0;
uint16_t g_longest_bpm = 0; uint16_t g_longest_bpm = 0;
uint16_t g_low_bpm_ebp_offset = 0;
unsigned char *g_chart_addr = 0; unsigned char *g_chart_addr = 0;
typedef struct chart_chunk_s { typedef struct chart_chunk_s {
@ -4449,9 +4454,14 @@ void hook_read_hispeed()
__asm("push ecx\n"); __asm("push ecx\n");
__asm("push edx\n"); __asm("push edx\n");
__asm("mov %0, word ptr [ebp+0xA1A]\n":"=a"(g_low_bpm): :); __asm("mov ecx, ebp\n");
__asm("mov %0, word ptr [ebp+0xA1C]\n":"=a"(g_hi_bpm): :); __asm("add cx, word ptr [%0]\n"::"a"(&g_low_bpm_ebp_offset));
__asm("mov %0, byte ptr [ebp+0xA1E]\n":"=a"(g_mystery_bpm): :);
__asm __volatile__("mov %0, word ptr [ecx]\n":"=a"(g_low_bpm): :);
__asm("add cx, 2\n");
__asm __volatile__("mov %0, word ptr [ecx]\n":"=a"(g_hi_bpm): :);
__asm("add cx, 2\n");
__asm __volatile__("mov %0, byte ptr [ecx]\n":"=a"(g_mystery_bpm): :);
if ( g_bypass_hispeed || g_target_bpm == 0 ) //bypass for mystery BPM and soflan songs (to avoid hi-speed being locked since target won't change) if ( g_bypass_hispeed || g_target_bpm == 0 ) //bypass for mystery BPM and soflan songs (to avoid hi-speed being locked since target won't change)
{ {
@ -4586,13 +4596,28 @@ bool patch_hispeed_auto(uint8_t mode, uint16_t default_bpm)
} }
/* write new hispeed according to target bpm */ /* write new hispeed according to target bpm */
{ {
int64_t pattern_offset = search(data, dllSize, "\x98\x50\x66\x8B\x85", 5, 0); /* improve compatibility with newer games */
int64_t pattern_offset = search(data, dllSize, "\xEB\x57\x8B\xBC\x24\x50\x01\x00\x00\x66\x8B\x85", 12, 0);
if (pattern_offset == -1) {
LOG("popnhax: auto hi-speed: cannot find chart BPM address offset\n");
return false;
}
uint64_t patch_addr = (int64_t)data + pattern_offset + 0x1C;
g_low_bpm_ebp_offset = *((uint16_t *)(patch_addr));
if (g_low_bpm_ebp_offset != 0x0A1A && g_low_bpm_ebp_offset != 0x0A1E)
{
LOG("popnhax: auto hi-speed: WARNING: unexpected BPM address offset (%hu), might not work\n", g_low_bpm_ebp_offset);
}
pattern_offset = search(data, dllSize, "\x98\x50\x66\x8B\x85", 5, 0);
if (pattern_offset == -1) { if (pattern_offset == -1) {
LOG("popnhax: auto hi-speed: cannot find hi-speed apply address\n"); LOG("popnhax: auto hi-speed: cannot find hi-speed apply address\n");
return false; return false;
} }
uint64_t patch_addr = (int64_t)data + pattern_offset - 0x07; patch_addr = (int64_t)data + pattern_offset - 0x07;
MH_CreateHook((LPVOID)(patch_addr), (LPVOID)hook_read_hispeed, MH_CreateHook((LPVOID)(patch_addr), (LPVOID)hook_read_hispeed,
(void **)&real_read_hispeed); (void **)&real_read_hispeed);
@ -5156,6 +5181,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
{ {
LOG("cannot open popnhax.log for write, output to stderr only\n"); LOG("cannot open popnhax.log for write, output to stderr only\n");
} }
LOG("== popnhax version " PROGRAM_VERSION " ==\n");
LOG("popnhax: Initializing\n"); LOG("popnhax: Initializing\n");
if (MH_Initialize() != MH_OK) { if (MH_Initialize() != MH_OK) {
LOG("Failed to initialize minhook\n"); LOG("Failed to initialize minhook\n");