Skip to content

Commit

Permalink
Implement port for 1.12f and 1.30
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed May 12, 2024
2 parents b28755a + 269f60f commit 62a0725
Show file tree
Hide file tree
Showing 97 changed files with 1,206 additions and 800 deletions.
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ CONTENT := $(INCDIR)injections$(INCEXT)
# Included files
INC := $(INCDIR)stackops$(INCEXT) $(INCDIR)macros$(INCEXT) $(INCDIR)engine$(INCEXT)
INC_G1 := $(INC) $(INCDIR)engine_g1$(INCEXT)
INC_G112 := $(INC) $(INCDIR)engine_g112$(INCEXT)
INC_G130 := $(INC) $(INCDIR)engine_g130$(INCEXT)
INC_G2 := $(INC) $(INCDIR)engine_g2$(INCEXT)

# Intermediate files
Expand Down Expand Up @@ -179,6 +181,8 @@ DATA_BASE := symbols \
messages

BINARIES_G1 := $(BIN_BASE:%=$(BINDIR)%_g1)
BINARIES_G112 := $(BIN_BASE:%=$(BINDIR)%_g112)
BINARIES_G130 := $(BIN_BASE:%=$(BINDIR)%_g130) $(BIN_BASE_G2:%=$(BINDIR)%_g130)
BINARIES_G2 := $(BIN_BASE:%=$(BINDIR)%_g2) $(BIN_BASE_G2:%=$(BINDIR)%_g2)
FUNC := $(FUNC_BASE:%=$(FUNCDIR)%$(ASMEXT))
EXEC := $(EXEC_BASE:%=$(EXECDIR)%$(ASMEXT))
Expand Down Expand Up @@ -231,7 +235,7 @@ $(OBJ) : $(SRCDLL) $(CONTENT) $(IKLG)
$(RSC) : $(RC)
gorc $(FLAGS_RC) /fo $@ /r $^

$(CONTENT) : $(BINARIES_G1) $(BINARIES_G2)
$(CONTENT) : $(BINARIES_G1) $(BINARIES_G112) $(BINARIES_G130) $(BINARIES_G2)
$(GETBINLIST) $(call FixPath,$@) $(SRCDIR)

$(BINDIR)core_g% : $(SRCDIR)core$(ASMEXT) $(FUNC) $(EXEC) $(DATA) $(INC_G%) $(META)
Expand All @@ -246,6 +250,14 @@ $(BINDIR)%_g1 : $(SRCDIR)%$(ASMEXT) $(INCDIR)symbols_g1$(INCEXT) $(INC_G1) $(MET
@$(call mkdir,$(BINDIR))
$(NASM) -DGOTHIC_BASE_VERSION=1 $(FLAGS_C) -o $@ $<

$(BINDIR)%_g112 : $(SRCDIR)%$(ASMEXT) $(INCDIR)symbols_g112$(INCEXT) $(INC_G112) $(META)
@$(call mkdir,$(BINDIR))
$(NASM) -DGOTHIC_BASE_VERSION=112 $(FLAGS_C) -o $@ $<

$(BINDIR)%_g130 : $(SRCDIR)%$(ASMEXT) $(INCDIR)symbols_g130$(INCEXT) $(INC_G130) $(META)
@$(call mkdir,$(BINDIR))
$(NASM) -DGOTHIC_BASE_VERSION=130 $(FLAGS_C) -o $@ $<

$(BINDIR)%_g2 : $(SRCDIR)%$(ASMEXT) $(INCDIR)symbols_g2$(INCEXT) $(INC_G2) $(META)
@$(call mkdir,$(BINDIR))
$(NASM) -DGOTHIC_BASE_VERSION=2 $(FLAGS_C) -o $@ $<
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
[![Steam Gothic 1](https://img.shields.io/badge/steam-Gothic%201-2a3f5a?logo=steam&labelColor=1b2838)](https://steamcommunity.com/sharedfiles/filedetails/?id=2786936496)
[![Steam Gothic 2](https://img.shields.io/badge/steam-Gothic%202-2a3f5a?logo=steam&labelColor=1b2838)](https://steamcommunity.com/sharedfiles/filedetails/?id=2786910489)

This repository contains the source code of the Ninja extension for Gothic 1 and Gothic 2 NotR.
This repository contains the source code of the Ninja extension for the Gothic game series.

If you are interested in developing patches with Ninja, please follow the instructions in the relevant chapters of the
[documentation](https://github.com/szapp/Ninja/wiki).
[documentation](https://github.com/szapp/Ninja/wiki) and get started with the official [patch template](https://github.com/szapp/patch-template).

# About

Ninja is supported by the games Gothic (1.08k_mod), Gothic Sequel (1.12f), Gothic 2 (1.30 fix report version), and Gothic 2 NotR (2.6 fix report version).

For information on Ninja, please visit the [documentation](https://github.com/szapp/Ninja/wiki).

# Usage
Expand Down
12 changes: 8 additions & 4 deletions extractSymbols.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
::
:: Extract all global symbols from assembly files and format them into a macro file
::
:: Arguments: OUTFILE.ASM GOTHIC-BASE-VERSION(1 or 2) SOURCE.ASM [SOURCE.ASM ...]
:: Arguments: OUTFILE.ASM GOTHIC-BASE-VERSION(1, 112, 130, or 2) SOURCE.ASM [SOURCE.ASM ...]
::
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
Expand All @@ -13,8 +13,12 @@ SET getAddress=%~pd0getAddress
IF [%1] == [] GOTO usage
IF [%2] == [] GOTO usage
IF [%3] == [] GOTO usage
IF %2 LSS 1 GOTO usage
IF %2 GTR 2 GOTO usage
IF %2 EQU 1 GOTO start
IF %2 EQU 112 GOTO start
IF %2 EQU 130 GOTO start
IF %2 NEQ 2 GOTO usage

:start
SET gothic=%2

:: Write file header
Expand Down Expand Up @@ -65,4 +69,4 @@ DEL /Q temp.O
EXIT /B

:usage
ECHO Usage: %~nx0 OUTFILE.ASM GOTHIC-BASE-VERSION(1 or 2) SOURCE.ASM [SOURCE.ASM ...]
ECHO Usage: %~nx0 OUTFILE.ASM GOTHIC-BASE-VERSION(1, 112, 130, or 2) SOURCE.ASM [SOURCE.ASM ...]
17 changes: 11 additions & 6 deletions getAddress.bat
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
::
:: Read starting address (ORG) from assembly file
::
:: Arguments: SOURCE.ASM GOTHIC-BASE-VERSION(1 or 2)
:: Arguments: SOURCE.ASM GOTHIC-BASE-VERSION(1, 112, 130, or 2)
::
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

:: Sanity check
IF [%1] == [] GOTO usage
IF [%2] == [] GOTO usage
IF %2 LSS 1 GOTO usage
IF %2 GTR 2 GOTO usage
IF %2 EQU 1 SET gId=1&& GOTO start
IF %2 EQU 112 SET gId=2&& GOTO start
IF %2 EQU 130 SET gId=3&& GOTO start
IF %2 EQU 2 SET gId=4&& GOTO start
GOTO usage

:start

:: Parse file name
SET filefull=%~f1
Expand All @@ -32,10 +37,10 @@ SET i=0
FOR /F "tokens=*" %%A IN (tmp.text) DO (
SET /A i=i+1
SET addr=%%A
IF !i!==%2 GOTO break
IF !i!==%gId% GOTO break
)
:: Only one address found
IF %i% LSS %2 GOTO break
IF %i% LSS %gId% GOTO break

:: None found
DEL /Q tmp.text
Expand All @@ -47,4 +52,4 @@ ECHO %addr%
EXIT /B 0

:usage
ECHO Usage: %~nx0 SOURCE.ASM GOTHIC-BASE-VERSION(1 or 2)
ECHO Usage: %~nx0 SOURCE.ASM GOTHIC-BASE-VERSION(1, 112, 130, or 2)
6 changes: 6 additions & 0 deletions getBinList.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ COPY /Y NUL "%outfile%" >NUL
SET gothic=1
FOR %%N IN ("%indir%") DO CALL :fileloop %%N || EXIT /B 3
ECHO/>> %outfile%
SET gothic=112
FOR %%N IN ("%indir%") DO CALL :fileloop %%N || EXIT /B 3
ECHO/>> %outfile%
SET gothic=130
FOR %%N IN ("%indir%") DO CALL :fileloop %%N || EXIT /B 3
ECHO/>> %outfile%
SET gothic=2
FOR %%N IN ("%indir%") DO CALL :fileloop %%N || EXIT /B 3

Expand Down
2 changes: 1 addition & 1 deletion src/core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%include "inc/engine.inc"

%ifidn __OUTPUT_FORMAT__, bin
org g1g2(0x452640,0x457470)
org g1g2(0x452640,0x459190,0x456D20,0x457470)
%endif

bits 32
Expand Down
6 changes: 3 additions & 3 deletions src/data/io.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
char_ikarus db 'IKARUS', 0
char_lego db 'LEGO', 0
char_rb db 'rb', 0
char_g1g2 db '_G', g1g2('1','2'), 0
char_g1g2 db '_G', g1g2('1','112','130','2'), 0
char_bin db '.BIN', 0
char_csl db '.CSL', 0
char_zOPT_ignorePatches db 'IncompatibleNinjaPatches', 0
Expand All @@ -19,8 +19,8 @@ NINJA_PATH_DATA db 'DATA\', 0
NINJA_PATH_VDF db 'DATA\*.VDF', 0
NINJA_PATH_IKARUS db '\NINJA\_INTERN\IKARUS\IKARUS.D', 0
NINJA_PATH_LEGO db '\NINJA\_INTERN\LEGO\LEGO.D', 0
NINJA_PATH_IKARUSSRC db '\NINJA\_INTERN\IKARUS\IKARUS_G', g1g2('1','2'), '.SRC', 0
NINJA_PATH_LEGOSRC db '\NINJA\_INTERN\LEGO\HEADER_G', g1g2('1','2'),'.SRC', 0
NINJA_PATH_IKARUSSRC db '\NINJA\_INTERN\IKARUS\IKARUS_G', g1g2('1','112','130','2'), '.SRC', 0
NINJA_PATH_LEGOSRC db '\NINJA\_INTERN\LEGO\HEADER_G', g1g2('1','112','130','2'),'.SRC', 0
NINJA_MDS_PREFIX db 'ANIMS_', 0
NINJA_FILE db '\SYSTEM\NINJA.DLL', 0
NINJA_VDF_VERSION1 db 'PSVDSC_V2.00', 0xD, 0xA, 0xD, 0xA
Expand Down
75 changes: 74 additions & 1 deletion src/dll/Ninja.asm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
%assign inject_g1_count inject_g1_count + 1
%endmacro

%assign inject_g112_count 0
%macro add_inject_g112 2
injectObj_g112_%[inject_g112_count]_addr equ %1
injectObj_g112_%[inject_g112_count]_new incbin %2
injectObj_g112_%[inject_g112_count]_size equ $-injectObj_g112_%[inject_g112_count]_new
%assign inject_g112_count inject_g112_count + 1
%endmacro

%assign inject_g130_count 0
%macro add_inject_g130 2
injectObj_g130_%[inject_g130_count]_addr equ %1
injectObj_g130_%[inject_g130_count]_new incbin %2
injectObj_g130_%[inject_g130_count]_size equ $-injectObj_g130_%[inject_g130_count]_new
%assign inject_g130_count inject_g130_count + 1
%endmacro

%assign inject_g2_count 0
%macro add_inject_g2 2
injectObj_g2_%[inject_g2_count]_addr equ %1
Expand Down Expand Up @@ -61,9 +77,13 @@ section .data
db 'privileges and/or delete the hidden file \Data\', scriptsFileName, 0

verify_addr_g1 equ 0x82C0C0
verify_addr_g112 equ 0x87F918
verify_addr_g130 equ 0x88F858
verify_addr_g2 equ 0x89A7FC

zCParser__ParseBlock_g1 equ 0x6E6C00
zCParser__ParseBlock_g112 equ 0x71F8E0
zCParser__ParseBlock_g130 equ 0x7303F0
zCParser__ParseBlock_g2 equ 0x78FE30

%include "inc/injections.inc"
Expand Down Expand Up @@ -167,6 +187,10 @@ inject:
injectAll:
cmp DWORD [verify_addr_g2], 'Goth'
jz .g2
cmp DWORD [verify_addr_g112], 'GOTH'
jz .g112
cmp DWORD [verify_addr_g130], 'Goth'
jz .g130
cmp DWORD [verify_addr_g1], 'Goth'
jz .g1

Expand All @@ -188,7 +212,7 @@ injectAll:
push injectObj_g1_%[it]_size
push injectObj_g1_%[it]_addr
call inject
addStack 4*4
addStack 3*4
test eax, eax
jz .failed
%assign it it + 1
Expand All @@ -205,13 +229,58 @@ injectAll:
mov eax, DWORD 0x1
ret

.g112:
%assign it 0
%rep inject_g112_count
push injectObj_g112_%[it]_new
push injectObj_g112_%[it]_size
push injectObj_g112_%[it]_addr
call inject
addStack 3*4
test eax, eax
jz .failed
%assign it it + 1
%endrep

push 0x8
push zCParser__ParseBlock_g112
call clearAccess
addStack 2*4
test eax, eax
jz .failed

jmp .success

.g130:
%assign it 0
%rep inject_g130_count
push injectObj_g130_%[it]_new
push injectObj_g130_%[it]_size
push injectObj_g130_%[it]_addr
call inject
addStack 3*4
test eax, eax
jz .failed
%assign it it + 1
%endrep

push 0x8
push zCParser__ParseBlock_g130
call clearAccess
addStack 2*4
test eax, eax
jz .failed

jmp .success

.g2:
%assign it 0
%rep inject_g2_count
push injectObj_g2_%[it]_new
push injectObj_g2_%[it]_size
push injectObj_g2_%[it]_addr
call inject
addStack 3*4
test eax, eax
jz .failed
%assign it it + 1
Expand Down Expand Up @@ -267,7 +336,11 @@ verifyModuleName:
xor eax, eax
inc ecx
cmp DWORD [ecx], 'Goth'
jz .funcSucc
cmp DWORD [ecx], 'GOTH'
jnz .funcEnd

.funcSucc:
inc eax

.funcEnd:
Expand Down
8 changes: 6 additions & 2 deletions src/exec/createVdfArray.asm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ createVdfArray:
call zSTRING___zSTRING
add esp, 0x14

mov al, [SystemPack_version_info+g1g2(0xD,0xB)] ; Check for old Ninja system
%if GOTHIC_BASE_VERSION == 1 || GOTHIC_BASE_VERSION == 2
mov al, [SystemPack_version_info+g1g2(0xD,,,0xB)] ; Check for old Ninja system
cmp al, 'N'
jnz .checkScripts

Expand All @@ -64,6 +65,7 @@ createVdfArray:
; mov ecx, esp ; Never reached: Safe some space
; call zSTRING___zSTRING
add esp, 0x14
%endif

.checkScripts:
call zFILE_VDFS__LockCriticalSection
Expand Down Expand Up @@ -120,6 +122,7 @@ createVdfArray:
call zCConsole__AddEvalFunc
addStack 4

%if GOTHIC_BASE_VERSION == 1 || GOTHIC_BASE_VERSION == 2
reportToSpy NINJA_READING_INI
mov esi, DWORD [zCOption_zgameoptions]
test esi, esi
Expand Down Expand Up @@ -158,6 +161,7 @@ createVdfArray:
lea ecx, [esp+stackoffset+var_retstr]
call zSTRING___zSTRING
jmp .detect
%endif

.ignoreListEmpty:
push char_NUL
Expand Down Expand Up @@ -561,7 +565,7 @@ createVdfArray:
verifyStackoffset

push char_zStartupWindowed
jmp g1g2(0x6019C6,0x630B61)
jmp g1g2(0x6019C1,0x62377E,0x6293DC,0x630B5C)+5


; int __cdecl ninja_compareTimestampsUnsigned(void const *, void const *)
Expand Down

0 comments on commit 62a0725

Please sign in to comment.