From f9c058433590d22354c16c03eb849bae8ee699d7 Mon Sep 17 00:00:00 2001 From: szapp Date: Mon, 11 Nov 2019 21:01:36 +0100 Subject: [PATCH] Rename jump symbols in DAT Fix #19 --- src/data/messages.asm | 7 +++--- src/data/symbols.asm | 9 +++++-- src/func/armParser.asm | 55 ++++++++++++++++++++++++++++++++++++++++++ src/func/injectOU.asm | 7 +----- src/inc/engine_g1.inc | 3 +++ src/inc/engine_g2.inc | 3 +++ 6 files changed, 72 insertions(+), 12 deletions(-) diff --git a/src/data/messages.asm b/src/data/messages.asm index cf48aa2..6814e4c 100644 --- a/src/data/messages.asm +++ b/src/data/messages.asm @@ -21,6 +21,7 @@ NIJNA_INFO_ADD db AUTHOR_PREFIX, ': NINJA: Adding info: ', 0 NINJA_INFO_BEFORE db AUTHOR_PREFIX, ': NINJA: Infos before: ', 0 NINJA_INFO_AFTER db AUTHOR_PREFIX, ': NINJA: Infos after: ', 0 NINJA_REMOVE_NPC db AUTHOR_PREFIX, ':NINJA: Removing invalid NPC', 0 +NINJA_RENAME_SYMB db AUTHOR_PREFIX, ':NINJA: Renaming symbol', 0 NINJA_SYMBOL_ADD_DIV db AUTHOR_PREFIX, ':NINJA: Adding divider symbol', 0 NINJA_SYMBOL_ADD_HLP db AUTHOR_PREFIX, ':NINJA: Adding helper symbols', 0 NINJA_SYMBOL_FAILED db AUTHOR_PREFIX, ':NINJA: Failed to add symbol: ', 0 @@ -32,13 +33,11 @@ NINJA_VERIFY_VERSION db AUTHOR_PREFIX, ':NINJA: Verifying version', 0 NINJA_COMPARE_VERSIONS db AUTHOR_PREFIX, ':NINJA: Comparing versions', 0 NINJA_PARSER_FAILED db AUTHOR_PREFIX, ':NINJA: Version mismatch of ', 0 NINJA_PARSER_FAILED_2 db '. ', 10, 13 -NINJA_PATH_INVALID db 'One of your patches contains Ikarus/LeGo. ', 10, 13 - db 'This is not allowed. Ninja already provides the latest ', 10, 13 - db 'versions of both - including necessary adjustments.', 0 +NINJA_PATH_INVALID db 'Ikarus/LeGo must not be contained in any patch.', 0 NINJA_LEGO_VER_ERROR db AUTHOR_PREFIX, ':NINJA: LeGo version not understood: ', 0 NINJA_LEGO_END db 'Onset not found.', 0 NINJA_LEGO_BMM db 'BMM incomplete.', 0 -NINJA_VERSION_INVALID db AUTHOR_PREFIX, ':NINJA: The %s version of the game is newer than that of Ninja. ', 10, 13 +NINJA_VERSION_INVALID db AUTHOR_PREFIX, ':NINJA: Version mismatch of %s. ', 10, 13 db 'Game: %09d, Ninja: %09d ', 10, 13 db 'Please update Ninja or report this error at ', 10, 13 db '<', NINJA_WEBSITE, '>', 0 diff --git a/src/data/symbols.asm b/src/data/symbols.asm index 3073da2..deb46b8 100644 --- a/src/data/symbols.asm +++ b/src/data/symbols.asm @@ -2,13 +2,18 @@ char_ikarus_symb db 'IKARUS_VERSION', 0 char_lego_symb db 'LEGO_VERSION', 0 +char__repeat db '_REPEAT', 0 +char__repeat_len equ $-char__repeat +char__while db '_WHILE', 0 + ; Preserved Gothic symbols keep_func_symbol_start db 'INIT_GLOBAL', 0 db 'INITPERCEPTIONS', 0 ; Preserved Ikarus symbols - db 'REPEAT', 0 - db 'WHILE', 0 +char_repeat db 'REPEAT', 0 +char_repeat_len equ $-char_repeat +char_while db 'WHILE', 0 db 'MEM_LABEL', 0 db 'MEM_GOTO', 0 diff --git a/src/func/armParser.asm b/src/func/armParser.asm index e6251e5..bebca20 100644 --- a/src/func/armParser.asm +++ b/src/func/armParser.asm @@ -47,6 +47,61 @@ ninja_armParser: cmp DWORD [esp+stackoffset+arg_2], NINJA_PATH_CONTENT jnz .dispatch + sub esp, 0x14 ; Rename _while/_repeat to while/repeat + mov ecx, esp + call zSTRING__zSTRING_void + + xor edi, edi + dec edi + +.checkunderscore: + inc edi + cmp edi, 0x1 + jg .sortTable + + mov ecx, esp + mov eax, edi + imul eax, char__repeat_len + add eax, char__repeat + push eax + call zSTRING__operator_eq + addStack 4 + push ecx + mov ecx, [esp+stackoffset+arg_1] + call zCParser__GetSymbol_str + addStack 4 + test eax, eax + jz .checkunderscore + mov esi, eax + + mov ecx, esp ; Check if while already exists + mov edx, edi + imul edx, char_repeat_len + add edx, char_repeat + push edx + call zSTRING__operator_eq + addStack 4 + push ecx + mov ecx, [esp+stackoffset+arg_1] + call zCParser__GetSymbol_str + addStack 4 + test eax, eax + jnz .checkunderscore + + reportToSpy NINJA_RENAME_SYMB + mov ecx, esi + push edx + call zSTRING__operator_eq + addStack 4 + jmp .checkunderscore + +.sortTable: + add esp, 0x14 + + mov ecx, DWORD [zCPar_SymbolTable__cur_table] ; Resort zCParser.symtab.tablesort + add ecx, 0x14 + call zCArraySort_int___QuickSort + reportToSpy NINJA_SYMBOL_ADD_HLP push zPAR_TYPE_INT | zPAR_FLAG_CONST | 0x1 push char_nversion_symb diff --git a/src/func/injectOU.asm b/src/func/injectOU.asm index 9f448b0..8e5e9ce 100644 --- a/src/func/injectOU.asm +++ b/src/func/injectOU.asm @@ -192,12 +192,7 @@ ninja_injectOU: .loopBlocksEnd: mov ecx, [esp+stackoffset+var_blocks] - push DWORD [ecx+zCArraySort.compare] - push 0x4 - push DWORD [ecx+zCArraySort.numInArray] - push DWORD [ecx+zCArraySort.array] - call _qsort - add esp, 0x10 + call zCArraySort_int___QuickSort mov ecx, [esp+stackoffset+var_lib] mov eax, [ecx+0x4] diff --git a/src/inc/engine_g1.inc b/src/inc/engine_g1.inc index 6b2fea6..f8ffe79 100644 --- a/src/inc/engine_g1.inc +++ b/src/inc/engine_g1.inc @@ -12,6 +12,7 @@ %define zCArray_int___zCArray_int_ 0x5499D0 ; void %define zCArray_int___InsertEnd 0x530010 ; int const & %define zCArray_int____zCArray_int_ 0x52FF50 ; void + %define zCArraySort_int___QuickSort 0x60F100 ; void %define _qsort 0x77757F ; void *, size_t, size_t, int (__cdecl *)(const void *, const void *) %define _fopen 0x778672 ; const char *, const char * %define _fseek 0x778588 ; FILE *, __int32, int @@ -28,6 +29,7 @@ %define _atol 0x77774D ; const char * %define _itoa 0x789587 ; int, char *, int %define zSTRING__zSTRING 0x4013A0 ; char const * + %define zSTRING__zSTRING_void 0x402B30 ; void %define zSTRING___zSTRING 0x401260 ; void %define zSTRING__Sprintf 0x467A90 ; char const *, ... %define zSTRING__Upper 0x465390 ; void @@ -35,6 +37,7 @@ %define zSTRING__TrimRight 0x4675A0 ; char %define zSTRING__Delete 0x4668D0 ; uint, ulong %define zSTRING__DeleteRight 0x4667C0 ; uint + %define zSTRING__operator_eq 0x4C5820 ; char const * %define zSTRING__operator_plusEq 0x644ED0 ; char const * %define ds_lstrcatA 0x7D02D8 ; LPTSTR, LPTSTR %define ds_lstrcpyA 0x7D0288 ; LPTSTR, LPTSTR diff --git a/src/inc/engine_g2.inc b/src/inc/engine_g2.inc index 7289ab3..3c06939 100644 --- a/src/inc/engine_g2.inc +++ b/src/inc/engine_g2.inc @@ -12,6 +12,7 @@ %define zCArray_int___zCArray_int_ 0x560690 ; void %define zCArray_int___InsertEnd 0x4D5A30 ; int const & %define zCArray_int____zCArray_int_ 0x543CC0 ; void + %define zCArraySort_int___QuickSort 0x63FCA0 ; void %define _qsort 0x7D0F6F ; void *, size_t, size_t, int (__cdecl *)(const void *, const void *) %define _fopen 0x7D2010 ; const char *, const char * %define _fseek 0x7D1F26 ; FILE *, __int32, int @@ -28,6 +29,7 @@ %define _atol 0x7D113D ; const char * %define _itoa 0x7E2E57 ; int, char *, int %define zSTRING__zSTRING 0x4010C0 ; char const * + %define zSTRING__zSTRING_void 0x402AF0 ; void %define zSTRING___zSTRING 0x401160 ; void %define zSTRING__Sprintf 0x46CC60 ; char const *, ... %define zSTRING__Upper 0x46AB00 ; void @@ -35,6 +37,7 @@ %define zSTRING__TrimRight 0x46C770 ; char %define zSTRING__Delete 0x46BAA0 ; uint, ulong %define zSTRING__DeleteRight 0x46B990 ; uint + %define zSTRING__operator_eq 0x4CFAF0 ; char const * %define zSTRING__operator_plusEq 0x67A7B0 ; char const * %define ds_lstrcatA 0x82E1E0 ; LPTSTR, LPTSTR %define ds_lstrcpyA 0x82E1E4 ; LPTSTR, LPTSTR