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

--no-omni, cleanup

This commit is contained in:
CrazyRedMachine 2023-07-10 21:35:09 +02:00
parent 2127e8c928
commit 5ede5a3692
6 changed files with 100 additions and 120 deletions

View File

@ -79,9 +79,9 @@
<disable_redirection __type="bool">0</disable_redirection> <disable_redirection __type="bool">0</disable_redirection>
<!-- Translation --> <!-- Translation -->
<!-- Disable string replacements from .dict file --> <!-- Disable .dict string replacements and .ips patches -->
<disable_translation __type="bool">0</disable_translation> <disable_translation __type="bool">0</disable_translation>
<!-- Dump applied translations in dict_applied.txt (requires translation) --> <!-- Dump applied translations and dll runtime data to help debug translation -->
<dump_dict __type="bool">0</dump_dict> <translation_debug __type="bool">0</translation_debug>
</popnhax> </popnhax>

View File

@ -111,7 +111,8 @@ PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, audio_source_f
"/popnhax/audio_source_fix") "/popnhax/audio_source_fix")
PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, unset_volume, PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, unset_volume,
"/popnhax/unset_volume") "/popnhax/unset_volume")
PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, event_mode, "/popnhax/event_mode") PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, event_mode,
"/popnhax/event_mode")
PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, remove_timer, PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, remove_timer,
"/popnhax/remove_timer") "/popnhax/remove_timer")
PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, freeze_timer, PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, freeze_timer,
@ -1106,9 +1107,9 @@ static bool patch_unset_volume() {
char *data = getDllData(g_game_dll_fn, &dllSize); char *data = getDllData(g_game_dll_fn, &dllSize);
int64_t first_loc = search(data, dllSize, "\x04\x00\x81\xC4\x00\x01\x00\x00\xC3\xCC", 10, 0); int64_t first_loc = search(data, dllSize, "\x04\x00\x81\xC4\x00\x01\x00\x00\xC3\xCC", 10, 0);
if (first_loc == -1) { if (first_loc == -1) {
return false; return false;
} }
int64_t pattern_offset = search(data, 0x10, "\x83", 1, first_loc); int64_t pattern_offset = search(data, 0x10, "\x83", 1, first_loc);
if (pattern_offset == -1) { if (pattern_offset == -1) {
@ -1148,10 +1149,10 @@ static bool patch_remove_timer() {
if (pattern_offset == -1) { if (pattern_offset == -1) {
return false; return false;
} }
uint64_t patch_addr = (int64_t)data + pattern_offset; uint64_t patch_addr = (int64_t)data + pattern_offset;
patch_memory(patch_addr, (char *)"\x90\xE9", 2); patch_memory(patch_addr, (char *)"\x90\xE9", 2);
LOG("popnhax: timer removed\n"); LOG("popnhax: timer removed\n");
return true; return true;
@ -1172,17 +1173,17 @@ static bool patch_skip_tutorials() {
DWORD dllSize = 0; DWORD dllSize = 0;
char *data = getDllData(g_game_dll_fn, &dllSize); char *data = getDllData(g_game_dll_fn, &dllSize);
{ {
int64_t first_loc = search(data, dllSize, "\xFD\xFF\x5E\xC2\x04\x00\xE8", 7, 0); int64_t first_loc = search(data, dllSize, "\xFD\xFF\x5E\xC2\x04\x00\xE8", 7, 0);
if (first_loc == -1) { if (first_loc == -1) {
return false; return false;
} }
int64_t pattern_offset = search(data, 0x10, "\x74", 1, first_loc); int64_t pattern_offset = search(data, 0x10, "\x74", 1, first_loc);
if (pattern_offset == -1) { if (pattern_offset == -1) {
return false; return false;
} }
uint64_t patch_addr = (int64_t)data + pattern_offset; uint64_t patch_addr = (int64_t)data + pattern_offset;
patch_memory(patch_addr, (char *)"\xEB", 1); patch_memory(patch_addr, (char *)"\xEB", 1);
} }
@ -1231,7 +1232,7 @@ bool force_unlock_songs() {
int music_unlocks = 0, chart_unlocks = 0; int music_unlocks = 0, chart_unlocks = 0;
{ {
// 0xac here is the size of music_entry. May change in the future // 0xac here is the size of music_entry. May change in the future
int64_t pattern_offset = search(data, dllSize, "\x69\xC0\xAC\x00\x00\x00\x8B\x80", 8, 0); int64_t pattern_offset = search(data, dllSize, "\x69\xC0\xAC\x00\x00\x00\x8B\x80", 8, 0);
if (pattern_offset == -1) { if (pattern_offset == -1) {
LOG("popnhax: couldn't unlock songs and charts\n"); LOG("popnhax: couldn't unlock songs and charts\n");
@ -1281,7 +1282,7 @@ bool force_unlock_charas() {
int chara_unlocks = 0; int chara_unlocks = 0;
{ {
// 0x4c here is the size of character_entry. May change in the future // 0x4c here is the size of character_entry. May change in the future
int64_t pattern_offset = search(data, dllSize, "\x98\x6B\xC0\x4C\x8B\x80", 6, 0); int64_t pattern_offset = search(data, dllSize, "\x98\x6B\xC0\x4C\x8B\x80", 6, 0);
if (pattern_offset == -1) { if (pattern_offset == -1) {
LOG("popnhax: couldn't unlock characters\n"); LOG("popnhax: couldn't unlock characters\n");
@ -1527,7 +1528,7 @@ static bool patch_hidden_is_offset()
patch_memory(hiddencommitoptionaddr+placeholder_offset+1, eax_to_offset, 5); patch_memory(hiddencommitoptionaddr+placeholder_offset+1, eax_to_offset, 5);
/* find option commit function (unilab) */ /* find option commit function (unilab) */
uint8_t shift = 6; uint8_t shift = 6;
int64_t pattern_offset = search(data, dllSize, "\x03\xC7\x8D\x44\x01\x2A\x89\x10", 8, 0); int64_t pattern_offset = search(data, dllSize, "\x03\xC7\x8D\x44\x01\x2A\x89\x10", 8, 0);
if (pattern_offset == -1) { if (pattern_offset == -1) {
/* wasn't found, look for older function */ /* wasn't found, look for older function */
@ -1578,10 +1579,10 @@ static bool patch_show_hidden_adjust_result_screen() {
char *data = getDllData(g_game_dll_fn, &dllSize); char *data = getDllData(g_game_dll_fn, &dllSize);
int64_t first_loc = search(data, dllSize, "\x6A\x00\x0F\xBE\xCB", 5, 0); int64_t first_loc = search(data, dllSize, "\x6A\x00\x0F\xBE\xCB", 5, 0);
if (first_loc == -1) if (first_loc == -1)
return false; return false;
int64_t pattern_offset = search(data, 0x200, "\x80\xBC\x24", 3, first_loc); int64_t pattern_offset = search(data, 0x200, "\x80\xBC\x24", 3, first_loc);
if (pattern_offset == -1) { if (pattern_offset == -1) {
return false; return false;
@ -1590,7 +1591,7 @@ static bool patch_show_hidden_adjust_result_screen() {
uint64_t hook_addr = (int64_t)data + pattern_offset; uint64_t hook_addr = (int64_t)data + pattern_offset;
MH_CreateHook((LPVOID)(hook_addr), (LPVOID)asm_show_hidden_result, MH_CreateHook((LPVOID)(hook_addr), (LPVOID)asm_show_hidden_result,
(void **)&real_show_hidden_result); (void **)&real_show_hidden_result);
LOG("popnhax: show hidden/adjust value on result screen\n"); LOG("popnhax: show hidden/adjust value on result screen\n");
@ -2074,7 +2075,7 @@ static bool patch_score_challenge()
/* Part1: retrieve course id and song id, useful and will simplify a little */ /* Part1: retrieve course id and song id, useful and will simplify a little */
{ {
int64_t pattern_offset = search(data, dllSize, "\x81\xC6\xCC\x08\x00\x00\xC7\x44\x24", 9, 0); int64_t pattern_offset = search(data, dllSize, "\x81\xC6\xCC\x08\x00\x00\xC7\x44\x24", 9, 0);
if (pattern_offset == -1) { if (pattern_offset == -1) {
LOG("popnhax: score challenge: cannot find course/song address\n"); LOG("popnhax: score challenge: cannot find course/song address\n");
return false; return false;
@ -2493,13 +2494,13 @@ static bool get_rendaddr()
DWORD dllSize = 0; DWORD dllSize = 0;
char *data = getDllData(g_game_dll_fn, &dllSize); char *data = getDllData(g_game_dll_fn, &dllSize);
{ {
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); 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);
if (pattern_offset == -1) { if (pattern_offset == -1) {
return false; return false;
} }
g_rend_addr = (uint32_t *)((int64_t)data + pattern_offset -4); g_rend_addr = (uint32_t *)((int64_t)data + pattern_offset -4);
font_color = (uint32_t *)((int64_t)data + pattern_offset +36); font_color = (uint32_t *)((int64_t)data + pattern_offset +36);
} }
{ {
@ -2911,16 +2912,13 @@ static bool patch_practice_mode()
return true; return true;
} }
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) { switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH: { case DLL_PROCESS_ATTACH: {
g_log_fp = fopen("popnhax.log", "w"); g_log_fp = fopen("popnhax.log", "w");
if (g_log_fp == NULL) if (g_log_fp == NULL)
{ {
g_log_fp = stderr; LOG("cannot open popnhax.log for write, output to stderr only\n");
LOG("cannot open popnhax.log for write, output to stderr\n");
} }
LOG("popnhax: Initializing\n"); LOG("popnhax: Initializing\n");
if (MH_Initialize() != MH_OK) { if (MH_Initialize() != MH_OK) {
@ -2929,7 +2927,8 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
return TRUE; return TRUE;
} }
bool force_trans_debug = false; bool force_trans_debug = false;
bool force_no_omni = false;
LPWSTR *szArglist; LPWSTR *szArglist;
int nArgs; int nArgs;
@ -2957,9 +2956,14 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
} }
else if ( wcscmp(szArglist[i], L"--translation-debug") == 0 ) else if ( wcscmp(szArglist[i], L"--translation-debug") == 0 )
{ {
LOG("--translation-debug: turning on translation-related dumps\n"); LOG("--translation-debug: turning on translation-related dumps\n");
force_trans_debug = true; force_trans_debug = true;
} }
else if ( wcscmp(szArglist[i], L"--no-omni") == 0 )
{
LOG("--no-omni: force disable patch_db\n");
force_no_omni = true;
}
} }
LocalFree(szArglist); LocalFree(szArglist);
@ -2983,8 +2987,11 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
_load_config(g_config_fn, &config, config_psmap); _load_config(g_config_fn, &config, config_psmap);
if (force_trans_debug) if (force_trans_debug)
config.translation_debug = true; config.translation_debug = true;
if (force_no_omni)
config.patch_db = false;
if (!config.disable_multiboot) if (!config.disable_multiboot)
{ {
@ -2992,7 +2999,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
if ( (strlen(g_game_dll_fn) == 21) if ( (strlen(g_game_dll_fn) == 21)
&& (config.force_datecode[0] == '\0') ) && (config.force_datecode[0] == '\0') )
{ {
LOG("popnhax: multiboot autotune activated (custom game dll, default xml, force_datecode off)\n"); LOG("popnhax: multiboot autotune activated (custom game dll, force_datecode off)\n");
memcpy(config.force_datecode, g_game_dll_fn+7, 10); memcpy(config.force_datecode, g_game_dll_fn+7, 10);
LOG("popnhax: multiboot: auto set datecode to %s\n", config.force_datecode); LOG("popnhax: multiboot: auto set datecode to %s\n", config.force_datecode);
if (config.force_unlock_deco && ( strcmp(config.force_datecode, "2022061300") > 0) ) 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
/* parse */ /* parse */
if (config.force_datecode[0] != '\0') if (config.force_datecode[0] != '\0')
{ {
sprintf(translation_folder, "_%s%s", config.force_datecode, "_tr"); sprintf(translation_folder, "_%s%s", config.force_datecode, "_tr");
sprintf(translation_path, "%s%s", "data_mods\\", translation_folder); sprintf(translation_path, "%s%s", "data_mods\\", translation_folder);
if (access(translation_path, F_OK) != 0) if (access(translation_path, F_OK) != 0)
{ {
translation_folder[0] = '\0'; translation_folder[0] = '\0';
} }
} }
if (translation_folder[0] == '\0') if (translation_folder[0] == '\0')
{ {
sprintf(translation_folder, "%s", "_translation"); sprintf(translation_folder, "%s", "_translation");
sprintf(translation_path, "%s%s", "data_mods\\", translation_folder); sprintf(translation_path, "%s%s", "data_mods\\", translation_folder);
if (access(translation_path, F_OK) != 0) if (access(translation_path, F_OK) != 0)
{ {
translation_folder[0] = '\0'; translation_folder[0] = '\0';
} }
} }
if (translation_folder[0] != '\0') if (translation_folder[0] != '\0')
{ {
LOG("popnhax: translation: using folder \"%s\"\n", translation_folder); LOG("popnhax: translation: using folder \"%s\"\n", translation_folder);
patch_translate(g_game_dll_fn, translation_folder, config.translation_debug); patch_translate(g_game_dll_fn, translation_folder, config.translation_debug);
}
else if ( config.translation_debug )
{
DWORD dllSize = 0;
char *data = getDllData(g_game_dll_fn, &dllSize);
LOG("popnhax: translation debug: no translation applied, dump prepatched dll\n");
FILE* dllrtp = fopen("dllruntime_prepatched.dll", "wb");
fwrite(data, 1, dllSize, dllrtp);
fclose(dllrtp);
} }
else if ( config.translation_debug )
{
DWORD dllSize = 0;
char *data = getDllData(g_game_dll_fn, &dllSize);
LOG("popnhax: translation debug: no translation applied, dump prepatched dll\n");
FILE* dllrtp = fopen("dllruntime_prepatched.dll", "wb");
fwrite(data, 1, dllSize, dllrtp);
fclose(dllrtp);
}
} }
if (config.practice_mode) { if (config.practice_mode) {
@ -3181,4 +3188,4 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
} }
return TRUE; return TRUE;
} }

View File

@ -81,23 +81,6 @@ bool patch_sjis(const char *dllFilename, const char *find, uint8_t find_size, in
return true; return true;
} }
FILE* _translation_open_dict(char *foldername, bool *ips)
{
*ips = true;
char dict_filepath[64];
sprintf(dict_filepath, "%s%s%s", "data_mods\\", foldername, "\\popn22.ips");
FILE *file = fopen(dict_filepath, "rb");
if (file != NULL)
{
return file;
}
*ips = false;
sprintf(dict_filepath, "%s%s%s", "data_mods\\", foldername, "\\popn22.dict");
file = fopen(dict_filepath, "rb");
return file;
}
#define RELOC_HIGHLOW 0x3 #define RELOC_HIGHLOW 0x3
static void perform_reloc(char *data, int32_t delta, uint32_t ext_base, uint32_t ext_delta) static void perform_reloc(char *data, int32_t delta, uint32_t ext_base, uint32_t ext_delta)
{ {
@ -105,14 +88,14 @@ static void perform_reloc(char *data, int32_t delta, uint32_t ext_base, uint32_t
PIMAGE_DATA_DIRECTORY datadir = &headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC]; PIMAGE_DATA_DIRECTORY datadir = &headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
PIMAGE_BASE_RELOCATION reloc = (PIMAGE_BASE_RELOCATION)(data + datadir->VirtualAddress); PIMAGE_BASE_RELOCATION reloc = (PIMAGE_BASE_RELOCATION)(data + datadir->VirtualAddress);
while(reloc->VirtualAddress != 0) while(reloc->VirtualAddress != 0)
{ {
if (reloc->SizeOfBlock >= sizeof(IMAGE_BASE_RELOCATION)) if (reloc->SizeOfBlock >= sizeof(IMAGE_BASE_RELOCATION))
{ {
DWORD relocDescNb = (reloc->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(WORD); DWORD relocDescNb = (reloc->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(WORD);
LPWORD relocDescList = (LPWORD)((LPBYTE)reloc + sizeof(IMAGE_BASE_RELOCATION)); LPWORD relocDescList = (LPWORD)((LPBYTE)reloc + sizeof(IMAGE_BASE_RELOCATION));
for (DWORD i = 0; i < relocDescNb; i++) for (DWORD i = 0; i < relocDescNb; i++)
{ {
if ( ((relocDescList[i])>>12) == RELOC_HIGHLOW ) if ( ((relocDescList[i])>>12) == RELOC_HIGHLOW )
{ {
@ -450,11 +433,6 @@ static bool patch_translation_dict(const char *dllFilename, const char *folderna
#undef STATE_TRANSLATION #undef STATE_TRANSLATION
} }
/*
*/
bool patch_translate(const char *dllFilename, const char *folder, bool debug) bool patch_translate(const char *dllFilename, const char *folder, bool debug)
{ {
bool ips_done = false; bool ips_done = false;

View File

@ -3,8 +3,6 @@
#include <stdint.h> #include <stdint.h>
FILE* _translation_open_dict(char *foldername, bool *ips);
bool patch_translate(const char *dllFilename, const char *folder, bool debug); bool patch_translate(const char *dllFilename, const char *folder, bool debug);
#endif #endif

View File

@ -9,7 +9,7 @@
extern FILE *g_log_fp; extern FILE *g_log_fp;
#define LOG(...) do { \ #define LOG(...) do { \
if (g_log_fp != stderr) { \ if (g_log_fp != NULL) { \
fprintf(g_log_fp, __VA_ARGS__); \ fprintf(g_log_fp, __VA_ARGS__); \
fflush(g_log_fp);\ fflush(g_log_fp);\
}\ }\

View File

@ -5,74 +5,71 @@
#include "util/log.h" #include "util/log.h"
#define NO_OF_CHARS 256 #define NO_OF_CHARS 256
// A utility function to get maximum of two integers // A utility function to get maximum of two integers
static int max(int a, int b) { static int max(int a, int b) {
return (a > b) ? a : b; return (a > b) ? a : b;
} }
// The preprocessing function for Boyer Moore's bad character heuristic // The preprocessing function for Boyer Moore's bad character heuristic
static void badCharHeuristic(const unsigned char *str, int size, int* badchar) { static void badCharHeuristic(const unsigned char *str, int size, int* badchar) {
int i; int i;
// Initialize all occurrences as -1 // Initialize all occurrences as -1
for (i = 0; i < NO_OF_CHARS; i++) for (i = 0; i < NO_OF_CHARS; i++)
badchar[i] = -1; badchar[i] = -1;
// Fill the actual value of last occurrence of a character // Fill the actual value of last occurrence of a character
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
badchar[(int) str[i]] = i; badchar[(int) str[i]] = i;
} }
#define DEBUG_SEARCH 0 #define DEBUG_SEARCH 0
int _search(unsigned char *haystack, size_t haystack_size, const unsigned char *needle, size_t needle_size, int orig_offset, int debug) { int _search(unsigned char *haystack, size_t haystack_size, const unsigned char *needle, size_t needle_size, int orig_offset, int debug) {
int badchar[NO_OF_CHARS]; int badchar[NO_OF_CHARS];
badCharHeuristic(needle, needle_size, badchar); badCharHeuristic(needle, needle_size, badchar);
int64_t s = 0; // s is shift of the pattern with respect to text int64_t s = 0; // s is shift of the pattern with respect to text
while (s <= (haystack_size - needle_size)) { while (s <= (haystack_size - needle_size)) {
int j = needle_size - 1; int j = needle_size - 1;
if (debug == 2) if (debug == 2)
{ {
LOG("--------------------------------\n"); LOG("--------------------------------\n");
LOG("txt..."); LOG("txt...");
for (size_t i = 0; i < needle_size; i++) for (size_t i = 0; i < needle_size; i++)
{ {
LOG("%02x ", haystack[orig_offset+s+i]); LOG("%02x ", haystack[orig_offset+s+i]);
} }
LOG("\n"); LOG("\n");
LOG("pat..."); LOG("pat...");
for (size_t i = 0; i < needle_size; i++) for (size_t i = 0; i < needle_size; i++)
{ {
LOG("%02x ", needle[i]); LOG("%02x ", needle[i]);
} }
LOG("\n"); LOG("\n");
} }
while (j >= 0 && needle[j] == haystack[orig_offset + s + j]) while (j >= 0 && needle[j] == haystack[orig_offset + s + j])
j--; j--;
if (j < 0) { if (j < 0) {
//printf("\n pattern occurs at shift = %d", s); if (debug)
//s += (s + needle_size < haystack_size) ? needle_size - badchar[txt[s + needle_size]] : 1; LOG("found string at offset %llx!\n", orig_offset +s);
if (debug) return orig_offset + s;
LOG("found string at offset %llx!\n", orig_offset +s);
return orig_offset + s;
} }
else else
{ {
s += max(1, j - badchar[(int)haystack[orig_offset + s + j]]); s += max(1, j - badchar[(int)haystack[orig_offset + s + j]]);
if (debug) if (debug)
LOG("mismatch at pos %d, new offset %llx\n\n", j, orig_offset+s); LOG("mismatch at pos %d, new offset %llx\n\n", j, orig_offset+s);
} }
} }
return -1; return -1;
} }
int search(char *haystack, size_t haystack_size, const char *needle, size_t needle_size, size_t orig_offset) { int search(char *haystack, size_t haystack_size, const char *needle, size_t needle_size, size_t orig_offset) {
int res = _search((unsigned char*) haystack, haystack_size, (const unsigned char *)needle, needle_size, orig_offset, 0); int res = _search((unsigned char*) haystack, haystack_size, (const unsigned char *)needle, needle_size, orig_offset, 0);
return res; return res;
} }