-
Notifications
You must be signed in to change notification settings - Fork 3
Hook example #2
Gratt-5r2 edited this page Apr 9, 2022
·
3 revisions
← Previous example 'Hello, world!'
Instance number is an index of the Gothic.dat
bytecode which contains the initialization code. This number is used in the InitByScript
functions of come classes. In this example, we uses the oCNpc class.
⠀
In the Names
file find the line with the oCNpc::InitByScript
function.
⠀
Create a function by this example.
void __fastcall oCNpc_InitByScript( oCNpc* _this, void*, int instance, int savegame );
⠀
auto Hook_oCNpc_InitByScript = CreateHookByName( &oCNpc::InitByScript, &oCNpc_InitByScript, Hook_Auto );
⠀
The NPCs name is array. In the game used 0
element. To change the name use operators +
of zSTRING
class.
void __fastcall oCNpc_InitByScript( oCNpc* _this, void* p0, int instance, int savegame ) {
// TODO
_this->name[0] = _this->name[0] + " " + zSTRING( instance );
}
⠀
Before of the name changing we should call the original functions.
Hook_oCNpc_InitByScript( _this, p0, instance, savegame );
⠀
void __fastcall oCNpc_InitByScript( oCNpc* _this, void*, int instance, int savegame );
auto Hook_oCNpc_InitByScript = CreateHookByName( &oCNpc::InitByScript, &oCNpc_InitByScript, Hook_CallPatch );
void __fastcall oCNpc_InitByScript( oCNpc* _this, void* p0, int instance, int savegame ) {
Hook_oCNpc_InitByScript( _this, p0, instance, savegame );
_this->name[0] = _this->name[0] + " " + zSTRING( instance );
}
⠀
Compile, place .dll
in the game, start the game.
- Introduction
- Project hierarchy
- Default functions
- Build options
-
Gothic API
- Base objects
- Models and visuals
- Static and interactive objects
- Animations
- Interface
- Scripts
- Worlds
- Renderer
- Other
- User API
-
Union API
- Hook
- Hook Functions
- Array
- ArraySorted
- Map
- MapArray
- String
- Unicode string
- UTF-8 converter
- RowString
- Console
- Logger
- Message
- Thread
- Event
- Semaphore
- ThreadLocker
- Crc checker
- Options
- Timer
- Union
- VDFS functions
- VirtualFile
- Hooks
- dynamic_cast patch