Skip to content

Commit 5ede5a3

Browse files
--no-omni, cleanup
1 parent 2127e8c commit 5ede5a3

File tree

6 files changed

+100
-120
lines changed

6 files changed

+100
-120
lines changed

dist/popnhax/popnhax.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@
7979
<disable_redirection __type="bool">0</disable_redirection>
8080

8181
<!-- Translation -->
82-
<!-- Disable string replacements from .dict file -->
82+
<!-- Disable .dict string replacements and .ips patches -->
8383
<disable_translation __type="bool">0</disable_translation>
84-
<!-- Dump applied translations in dict_applied.txt (requires translation) -->
85-
<dump_dict __type="bool">0</dump_dict>
84+
<!-- Dump applied translations and dll runtime data to help debug translation -->
85+
<translation_debug __type="bool">0</translation_debug>
8686

8787
</popnhax>

popnhax/dllmain.cc

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, audio_source_f
111111
"/popnhax/audio_source_fix")
112112
PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, unset_volume,
113113
"/popnhax/unset_volume")
114-
PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, event_mode, "/popnhax/event_mode")
114+
PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, event_mode,
115+
"/popnhax/event_mode")
115116
PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, remove_timer,
116117
"/popnhax/remove_timer")
117118
PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, freeze_timer,
@@ -1106,9 +1107,9 @@ static bool patch_unset_volume() {
11061107
char *data = getDllData(g_game_dll_fn, &dllSize);
11071108

11081109
int64_t first_loc = search(data, dllSize, "\x04\x00\x81\xC4\x00\x01\x00\x00\xC3\xCC", 10, 0);
1109-
if (first_loc == -1) {
1110-
return false;
1111-
}
1110+
if (first_loc == -1) {
1111+
return false;
1112+
}
11121113

11131114
int64_t pattern_offset = search(data, 0x10, "\x83", 1, first_loc);
11141115
if (pattern_offset == -1) {
@@ -1148,10 +1149,10 @@ static bool patch_remove_timer() {
11481149
if (pattern_offset == -1) {
11491150
return false;
11501151
}
1151-
1152+
11521153
uint64_t patch_addr = (int64_t)data + pattern_offset;
11531154
patch_memory(patch_addr, (char *)"\x90\xE9", 2);
1154-
1155+
11551156
LOG("popnhax: timer removed\n");
11561157

11571158
return true;
@@ -1172,17 +1173,17 @@ static bool patch_skip_tutorials() {
11721173
DWORD dllSize = 0;
11731174
char *data = getDllData(g_game_dll_fn, &dllSize);
11741175

1175-
{
1176+
{
11761177
int64_t first_loc = search(data, dllSize, "\xFD\xFF\x5E\xC2\x04\x00\xE8", 7, 0);
11771178
if (first_loc == -1) {
11781179
return false;
11791180
}
1180-
1181+
11811182
int64_t pattern_offset = search(data, 0x10, "\x74", 1, first_loc);
11821183
if (pattern_offset == -1) {
11831184
return false;
11841185
}
1185-
1186+
11861187
uint64_t patch_addr = (int64_t)data + pattern_offset;
11871188
patch_memory(patch_addr, (char *)"\xEB", 1);
11881189
}
@@ -1231,7 +1232,7 @@ bool force_unlock_songs() {
12311232
int music_unlocks = 0, chart_unlocks = 0;
12321233

12331234
{
1234-
// 0xac here is the size of music_entry. May change in the future
1235+
// 0xac here is the size of music_entry. May change in the future
12351236
int64_t pattern_offset = search(data, dllSize, "\x69\xC0\xAC\x00\x00\x00\x8B\x80", 8, 0);
12361237
if (pattern_offset == -1) {
12371238
LOG("popnhax: couldn't unlock songs and charts\n");
@@ -1281,7 +1282,7 @@ bool force_unlock_charas() {
12811282
int chara_unlocks = 0;
12821283

12831284
{
1284-
// 0x4c here is the size of character_entry. May change in the future
1285+
// 0x4c here is the size of character_entry. May change in the future
12851286
int64_t pattern_offset = search(data, dllSize, "\x98\x6B\xC0\x4C\x8B\x80", 6, 0);
12861287
if (pattern_offset == -1) {
12871288
LOG("popnhax: couldn't unlock characters\n");
@@ -1527,7 +1528,7 @@ static bool patch_hidden_is_offset()
15271528
patch_memory(hiddencommitoptionaddr+placeholder_offset+1, eax_to_offset, 5);
15281529

15291530
/* find option commit function (unilab) */
1530-
uint8_t shift = 6;
1531+
uint8_t shift = 6;
15311532
int64_t pattern_offset = search(data, dllSize, "\x03\xC7\x8D\x44\x01\x2A\x89\x10", 8, 0);
15321533
if (pattern_offset == -1) {
15331534
/* wasn't found, look for older function */
@@ -1578,10 +1579,10 @@ static bool patch_show_hidden_adjust_result_screen() {
15781579
char *data = getDllData(g_game_dll_fn, &dllSize);
15791580

15801581
int64_t first_loc = search(data, dllSize, "\x6A\x00\x0F\xBE\xCB", 5, 0);
1581-
if (first_loc == -1)
1582-
return false;
1582+
if (first_loc == -1)
1583+
return false;
1584+
15831585

1584-
15851586
int64_t pattern_offset = search(data, 0x200, "\x80\xBC\x24", 3, first_loc);
15861587
if (pattern_offset == -1) {
15871588
return false;
@@ -1590,7 +1591,7 @@ static bool patch_show_hidden_adjust_result_screen() {
15901591
uint64_t hook_addr = (int64_t)data + pattern_offset;
15911592
MH_CreateHook((LPVOID)(hook_addr), (LPVOID)asm_show_hidden_result,
15921593
(void **)&real_show_hidden_result);
1593-
1594+
15941595

15951596
LOG("popnhax: show hidden/adjust value on result screen\n");
15961597

@@ -2074,7 +2075,7 @@ static bool patch_score_challenge()
20742075
/* Part1: retrieve course id and song id, useful and will simplify a little */
20752076
{
20762077

2077-
int64_t pattern_offset = search(data, dllSize, "\x81\xC6\xCC\x08\x00\x00\xC7\x44\x24", 9, 0);
2078+
int64_t pattern_offset = search(data, dllSize, "\x81\xC6\xCC\x08\x00\x00\xC7\x44\x24", 9, 0);
20782079
if (pattern_offset == -1) {
20792080
LOG("popnhax: score challenge: cannot find course/song address\n");
20802081
return false;
@@ -2493,13 +2494,13 @@ static bool get_rendaddr()
24932494
DWORD dllSize = 0;
24942495
char *data = getDllData(g_game_dll_fn, &dllSize);
24952496

2496-
{
2497-
int64_t pattern_offset = search(data, dllSize, "\x3b\xC3\x74\x13\xC7\x00\x02\x00\x00\x00\x89\x58\x04\x89\x58\x08", 16, 0);
2498-
if (pattern_offset == -1) {
2499-
return false;
2500-
}
2501-
g_rend_addr = (uint32_t *)((int64_t)data + pattern_offset -4);
2502-
font_color = (uint32_t *)((int64_t)data + pattern_offset +36);
2497+
{
2498+
int64_t pattern_offset = search(data, dllSize, "\x3b\xC3\x74\x13\xC7\x00\x02\x00\x00\x00\x89\x58\x04\x89\x58\x08", 16, 0);
2499+
if (pattern_offset == -1) {
2500+
return false;
2501+
}
2502+
g_rend_addr = (uint32_t *)((int64_t)data + pattern_offset -4);
2503+
font_color = (uint32_t *)((int64_t)data + pattern_offset +36);
25032504
}
25042505

25052506
{
@@ -2911,16 +2912,13 @@ static bool patch_practice_mode()
29112912
return true;
29122913
}
29132914

2914-
2915-
29162915
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
29172916
switch (ul_reason_for_call) {
29182917
case DLL_PROCESS_ATTACH: {
29192918
g_log_fp = fopen("popnhax.log", "w");
29202919
if (g_log_fp == NULL)
29212920
{
2922-
g_log_fp = stderr;
2923-
LOG("cannot open popnhax.log for write, output to stderr\n");
2921+
LOG("cannot open popnhax.log for write, output to stderr only\n");
29242922
}
29252923
LOG("popnhax: Initializing\n");
29262924
if (MH_Initialize() != MH_OK) {
@@ -2929,7 +2927,8 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
29292927
return TRUE;
29302928
}
29312929

2932-
bool force_trans_debug = false;
2930+
bool force_trans_debug = false;
2931+
bool force_no_omni = false;
29332932

29342933
LPWSTR *szArglist;
29352934
int nArgs;
@@ -2957,9 +2956,14 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
29572956
}
29582957
else if ( wcscmp(szArglist[i], L"--translation-debug") == 0 )
29592958
{
2960-
LOG("--translation-debug: turning on translation-related dumps\n");
2959+
LOG("--translation-debug: turning on translation-related dumps\n");
29612960
force_trans_debug = true;
29622961
}
2962+
else if ( wcscmp(szArglist[i], L"--no-omni") == 0 )
2963+
{
2964+
LOG("--no-omni: force disable patch_db\n");
2965+
force_no_omni = true;
2966+
}
29632967
}
29642968
LocalFree(szArglist);
29652969

@@ -2983,16 +2987,19 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
29832987

29842988
_load_config(g_config_fn, &config, config_psmap);
29852989

2986-
if (force_trans_debug)
2987-
config.translation_debug = true;
2990+
if (force_trans_debug)
2991+
config.translation_debug = true;
2992+
2993+
if (force_no_omni)
2994+
config.patch_db = false;
29882995

29892996
if (!config.disable_multiboot)
29902997
{
29912998
/* automatically force datecode based on dll name when applicable (e.g. popn22_2022061300.dll and no force_datecode) */
29922999
if ( (strlen(g_game_dll_fn) == 21)
29933000
&& (config.force_datecode[0] == '\0') )
29943001
{
2995-
LOG("popnhax: multiboot autotune activated (custom game dll, default xml, force_datecode off)\n");
3002+
LOG("popnhax: multiboot autotune activated (custom game dll, force_datecode off)\n");
29963003
memcpy(config.force_datecode, g_game_dll_fn+7, 10);
29973004
LOG("popnhax: multiboot: auto set datecode to %s\n", config.force_datecode);
29983005
if (config.force_unlock_deco && ( strcmp(config.force_datecode, "2022061300") > 0) )
@@ -3030,39 +3037,39 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
30303037
/* parse */
30313038
if (config.force_datecode[0] != '\0')
30323039
{
3033-
3040+
30343041
sprintf(translation_folder, "_%s%s", config.force_datecode, "_tr");
3035-
sprintf(translation_path, "%s%s", "data_mods\\", translation_folder);
3036-
if (access(translation_path, F_OK) != 0)
3037-
{
3038-
translation_folder[0] = '\0';
3039-
}
3042+
sprintf(translation_path, "%s%s", "data_mods\\", translation_folder);
3043+
if (access(translation_path, F_OK) != 0)
3044+
{
3045+
translation_folder[0] = '\0';
3046+
}
30403047
}
30413048

30423049
if (translation_folder[0] == '\0')
30433050
{
30443051
sprintf(translation_folder, "%s", "_translation");
3045-
sprintf(translation_path, "%s%s", "data_mods\\", translation_folder);
3046-
if (access(translation_path, F_OK) != 0)
3047-
{
3048-
translation_folder[0] = '\0';
3049-
}
3052+
sprintf(translation_path, "%s%s", "data_mods\\", translation_folder);
3053+
if (access(translation_path, F_OK) != 0)
3054+
{
3055+
translation_folder[0] = '\0';
3056+
}
30503057
}
30513058

30523059
if (translation_folder[0] != '\0')
30533060
{
30543061
LOG("popnhax: translation: using folder \"%s\"\n", translation_folder);
3055-
patch_translate(g_game_dll_fn, translation_folder, config.translation_debug);
3062+
patch_translate(g_game_dll_fn, translation_folder, config.translation_debug);
3063+
}
3064+
else if ( config.translation_debug )
3065+
{
3066+
DWORD dllSize = 0;
3067+
char *data = getDllData(g_game_dll_fn, &dllSize);
3068+
LOG("popnhax: translation debug: no translation applied, dump prepatched dll\n");
3069+
FILE* dllrtp = fopen("dllruntime_prepatched.dll", "wb");
3070+
fwrite(data, 1, dllSize, dllrtp);
3071+
fclose(dllrtp);
30563072
}
3057-
else if ( config.translation_debug )
3058-
{
3059-
DWORD dllSize = 0;
3060-
char *data = getDllData(g_game_dll_fn, &dllSize);
3061-
LOG("popnhax: translation debug: no translation applied, dump prepatched dll\n");
3062-
FILE* dllrtp = fopen("dllruntime_prepatched.dll", "wb");
3063-
fwrite(data, 1, dllSize, dllrtp);
3064-
fclose(dllrtp);
3065-
}
30663073
}
30673074

30683075
if (config.practice_mode) {
@@ -3181,4 +3188,4 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
31813188
}
31823189

31833190
return TRUE;
3184-
}
3191+
}

popnhax/translation.cc

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,38 +81,21 @@ bool patch_sjis(const char *dllFilename, const char *find, uint8_t find_size, in
8181
return true;
8282
}
8383

84-
FILE* _translation_open_dict(char *foldername, bool *ips)
85-
{
86-
*ips = true;
87-
char dict_filepath[64];
88-
sprintf(dict_filepath, "%s%s%s", "data_mods\\", foldername, "\\popn22.ips");
89-
FILE *file = fopen(dict_filepath, "rb");
90-
if (file != NULL)
91-
{
92-
return file;
93-
}
94-
95-
*ips = false;
96-
sprintf(dict_filepath, "%s%s%s", "data_mods\\", foldername, "\\popn22.dict");
97-
file = fopen(dict_filepath, "rb");
98-
return file;
99-
}
100-
10184
#define RELOC_HIGHLOW 0x3
10285
static void perform_reloc(char *data, int32_t delta, uint32_t ext_base, uint32_t ext_delta)
10386
{
10487
PIMAGE_NT_HEADERS headers = (PIMAGE_NT_HEADERS)((int64_t)data + ((PIMAGE_DOS_HEADER)data)->e_lfanew);
10588
PIMAGE_DATA_DIRECTORY datadir = &headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
10689
PIMAGE_BASE_RELOCATION reloc = (PIMAGE_BASE_RELOCATION)(data + datadir->VirtualAddress);
10790

108-
while(reloc->VirtualAddress != 0)
91+
while(reloc->VirtualAddress != 0)
10992
{
110-
if (reloc->SizeOfBlock >= sizeof(IMAGE_BASE_RELOCATION))
93+
if (reloc->SizeOfBlock >= sizeof(IMAGE_BASE_RELOCATION))
11194
{
11295
DWORD relocDescNb = (reloc->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(WORD);
11396
LPWORD relocDescList = (LPWORD)((LPBYTE)reloc + sizeof(IMAGE_BASE_RELOCATION));
11497

115-
for (DWORD i = 0; i < relocDescNb; i++)
98+
for (DWORD i = 0; i < relocDescNb; i++)
11699
{
117100
if ( ((relocDescList[i])>>12) == RELOC_HIGHLOW )
118101
{
@@ -450,11 +433,6 @@ static bool patch_translation_dict(const char *dllFilename, const char *folderna
450433
#undef STATE_TRANSLATION
451434
}
452435

453-
454-
/*
455-
456-
*/
457-
458436
bool patch_translate(const char *dllFilename, const char *folder, bool debug)
459437
{
460438
bool ips_done = false;

popnhax/translation.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#include <stdint.h>
55

6-
FILE* _translation_open_dict(char *foldername, bool *ips);
7-
86
bool patch_translate(const char *dllFilename, const char *folder, bool debug);
97

108
#endif

util/log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
extern FILE *g_log_fp;
1010

1111
#define LOG(...) do { \
12-
if (g_log_fp != stderr) { \
12+
if (g_log_fp != NULL) { \
1313
fprintf(g_log_fp, __VA_ARGS__); \
1414
fflush(g_log_fp);\
1515
}\

0 commit comments

Comments
 (0)