Skip to content

Commit

Permalink
Rename jump symbols in DAT
Browse files Browse the repository at this point in the history
Fix #19
  • Loading branch information
szapp committed Nov 11, 2019
1 parent cfc77ed commit f9c0584
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/data/messages.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
9 changes: 7 additions & 2 deletions src/data/symbols.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
55 changes: 55 additions & 0 deletions src/func/armParser.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions src/func/injectOU.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions src/inc/engine_g1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,13 +29,15 @@
%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
%define zSTRING__Search 0x467750 ; int, char const *, uint
%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
Expand Down
3 changes: 3 additions & 0 deletions src/inc/engine_g2.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,13 +29,15 @@
%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
%define zSTRING__Search 0x46C920 ; int, char const *, uint
%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
Expand Down

0 comments on commit f9c0584

Please sign in to comment.