From db2e572612e4c954107813df0d5e4370e24fa109 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 21 Sep 2016 19:27:31 +0200 Subject: [PATCH] Begin refactoring the zone loading code --- deps/protobuf | 2 +- deps/zlib | 2 +- src/Components/Modules/Zones.cpp | 157 +++++++++++-------------------- src/Components/Modules/Zones.hpp | 10 ++ src/Game/Functions.cpp | 5 +- src/Game/Functions.hpp | 9 +- 6 files changed, 77 insertions(+), 108 deletions(-) diff --git a/deps/protobuf b/deps/protobuf index 7b00595d..4f379f81 160000 --- a/deps/protobuf +++ b/deps/protobuf @@ -1 +1 @@ -Subproject commit 7b00595ddf8622ae429ef37de8ea2f44b6333ad0 +Subproject commit 4f379f81cef4dd8e005fd0bcc9199bf842fc35d4 diff --git a/deps/zlib b/deps/zlib index 70a8763b..9852c209 160000 --- a/deps/zlib +++ b/deps/zlib @@ -1 +1 @@ -Subproject commit 70a8763b7187f2536ce7fe4d399ce9a79c9faf7c +Subproject commit 9852c209ac49c0d8d1192e46115d7c37d4344bbd diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 17f34920..993edcee 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -4,9 +4,13 @@ namespace Components { int Zones::ZoneVersion; + Utils::Hook Zones::LoadFxElemDefHook; + Utils::Hook Zones::LoadFxElemDefArrayHook; + Utils::Hook Zones::LoadXModelLodInfoHook; + Utils::Hook fxEffectLoadHook; - static DWORD fxEffectStringValue[64]; + static char* fxEffectStringValue[64]; static int fxEffectIndex = 0; void FxEffectLoadHookFunc(int a1, char* buffer, int len) @@ -34,7 +38,7 @@ namespace Components memcpy(tempVar + (252 * i), buffer + (260 * i), 252); - fxEffectStringValue[i] = *(DWORD*)(buffer + (260 * i) + 256); + fxEffectStringValue[i] = *(char**)(buffer + (260 * i) + 256); } memcpy(buffer, tempVar, len); @@ -42,67 +46,25 @@ namespace Components delete[] tempVar; } - Utils::Hook fxEffectModifyHook; - - void FxEffectModifyHookFunc(int a1, char* buffer, size_t len) + bool Zones::LoadFxElemDefStub(bool atStreamStart, Game::FxElemDef* fxElem, int size) { - char typeNum = *(char*)(buffer + 176); - - //DBG(("ot %i\n", typeNum)); - - if (typeNum == 3) + if (fxElem->elemType == 3) { - typeNum = 2; + fxElem->elemType = 2; } - else if (typeNum >= 5) + else if (fxElem->elemType >= 5) { - typeNum -= 2; + fxElem->elemType -= 2; } - /*if (typeNum >= 2) - { - typeNum -= 2; - }*/ - - *(char*)(buffer + 176) = typeNum; - - __asm - { - push len - push buffer - push a1 - call fxEffectModifyHook.Original - add esp, 0Ch - } + return Game::Load_Stream(atStreamStart, fxElem, size); } - Utils::Hook fxEffectTailHook; - - void FxEffectTailHookFunc() + void Zones::LoadFxElemDefArrayStub(bool atStreamStart) { - *Game::varXString = (char*)&fxEffectStringValue[fxEffectIndex++]; - - // Load_XStringPtr(0) - __asm - { - mov eax, 47FDA0h - - push 0 - call eax - add esp, 4h - } - } - - void __declspec(naked) FxEffectTailHookStub() - { - __asm - { - push 0 - call fxEffectTailHook.Original - add esp, 4 - - jmp FxEffectTailHookFunc - } + Game::Load_FxElemDef(atStreamStart); + *Game::varXString = &fxEffectStringValue[fxEffectIndex++]; + Game::Load_XString(0); } Utils::Hook xModelModifyHook; @@ -151,35 +113,22 @@ namespace Components memcpy(buffer, tempVar, elSize); } - Utils::Hook xLodTailHook; - - void XModelLODTailHookFunc(int i) + void Zones::LoadXModelLodInfo(int i) { int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360; - i = (4 - i)/* + 1*/; - - // varXString = (varXModel + 0x16C - (4 * i)) // where the above function parked the new xstring - *Game::varXString = (char*)((*(DWORD*)0x112AE14) + (elSize - 4)) - (4 * i); - + *Game::varXString = reinterpret_cast(reinterpret_cast(*Game::varXModel) + (elSize - 4) - (4 * (4 - i))); Game::Load_XString(false); } - void __declspec(naked) XModelLODTailHookStub() + void __declspec(naked) Zones::LoadXModelLodInfoStub() { __asm { push edi - call XModelLODTailHookFunc - add esp, 4h + call Zones::LoadXModelLodInfo + pop edi - mov eax, [esp + 8h] - push eax - add eax, 8 - push eax - call xLodTailHook.Original - add esp, 8h - - retn + jmp Game::Load_XModelSurfsFixup } } @@ -233,16 +182,16 @@ namespace Components Game::DB_PushStreamPos(3); - *Game::varXString = (char*)varWeaponDef + 0; + *Game::varXString = (char**)(varWeaponDef + 0); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 4; + *Game::varXString = (char**)(varWeaponDef + 4); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 8; + *Game::varXString = (char**)(varWeaponDef + 8); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 12; + *Game::varXString = (char**)(varWeaponDef + 12); Game::Load_XString(false); *Game::varXModelPtr = (Game::XModel*)(varWeaponDef + 16); @@ -265,15 +214,15 @@ namespace Components // 32 scriptstrings, should not need to be loaded // 236 - *Game::varXString = (char*)varWeaponDef + 236; + *Game::varXString = (char**)(varWeaponDef + 236); Game::Load_XStringArray(false, 48); // 428 - *Game::varXString = (char*)varWeaponDef + 428; + *Game::varXString = (char**)(varWeaponDef + 428); Game::Load_XStringArray(false, 48); // 620 - *Game::varXString = (char*)varWeaponDef + 620; + *Game::varXString = (char**)(varWeaponDef + 620); Game::Load_XStringArray(false, 48); // 812 @@ -351,13 +300,13 @@ namespace Components Game::Load_MaterialHandle(false); } - *Game::varXString = (char*)varWeaponDef + 1484; + *Game::varXString = (char**)(varWeaponDef + 1484); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 1492; + *Game::varXString = (char**)(varWeaponDef + 1492); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 1508; + *Game::varXString = (char**)(varWeaponDef + 1508); Game::Load_XString(false); for (int offset = 1764; offset <= 1776; offset += 4) @@ -396,7 +345,7 @@ namespace Components *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2372); // 2380 Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); - *Game::varXString = (char*)varWeaponDef + 2548; // 2556 + *Game::varXString = (char**)(varWeaponDef + 2548); // 2556 Game::Load_XString(false); if (*(DWORD*)(varWeaponDef + 2556) == -1) // 2564 @@ -407,7 +356,7 @@ namespace Components Game::Load_Stream(1, (void*)vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3076 : 3040))); } - *Game::varXString = (char*)varWeaponDef + 2552; + *Game::varXString = (char**)(varWeaponDef + 2552); Game::Load_XString(false); if (*(DWORD*)(varWeaponDef + 2560) == -1) @@ -418,22 +367,22 @@ namespace Components Game::Load_Stream(1, (void*)vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3078 : 3042))); } - *Game::varXString = (char*)varWeaponDef + 2640; + *Game::varXString = (char**)(varWeaponDef + 2640); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2644; + *Game::varXString = (char**)(varWeaponDef + 2644); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2676; + *Game::varXString = (char**)(varWeaponDef + 2676); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2680; + *Game::varXString = (char**)(varWeaponDef + 2680); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2804; + *Game::varXString = (char**)(varWeaponDef + 2804); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2808; + *Game::varXString = (char**)(varWeaponDef + 2808); Game::Load_XString(false); *Game::varTracerDefPtr = (Game::TracerDef*)(varWeaponDef + 2812); @@ -445,7 +394,7 @@ namespace Components *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 2844); Game::Load_FxEffectDefHandle(false); - *Game::varXString = (char*)varWeaponDef + 2848; + *Game::varXString = (char**)(varWeaponDef + 2848); Game::Load_XString(false); *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2864); @@ -479,13 +428,13 @@ namespace Components } - *Game::varXString = (char*)varWeaponDef + 2984; + *Game::varXString = (char**)(varWeaponDef + 2984); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2996; + *Game::varXString = (char**)(varWeaponDef + 2996); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 3000; + *Game::varXString = (char**)(varWeaponDef + 3000); Game::Load_XString(false); *Game::varMaterialHandle = (Game::Material*)(varWeaponDef + 3008); @@ -831,10 +780,10 @@ namespace Components if (patch) { - fxEffectTailHook.Install(); - fxEffectModifyHook.Install(); + Zones::LoadFxElemDefArrayHook.Install(); + Zones::LoadFxElemDefHook.Install(); - xLodTailHook.Install(); + Zones::LoadXModelLodInfoHook.Install(); xModelModifyHook.Install(); xsurfaceIntLoadHook.Install(); @@ -861,10 +810,10 @@ namespace Components } else { - fxEffectTailHook.Uninstall(); - fxEffectModifyHook.Uninstall(); + Zones::LoadFxElemDefArrayHook.Uninstall(); + Zones::LoadFxElemDefHook.Uninstall(); - xLodTailHook.Uninstall(); + Zones::LoadXModelLodInfoHook.Uninstall(); xModelModifyHook.Uninstall(); xsurfaceIntLoadHook.Uninstall(); @@ -901,9 +850,9 @@ namespace Components // Block Mark_pathnode_constant_t Utils::Hook::Set(0x4F74B0, 0xC3); - fxEffectTailHook.Initialize(0x495938, FxEffectTailHookStub, HOOK_CALL); - fxEffectModifyHook.Initialize(0x45ADA0, FxEffectModifyHookFunc, HOOK_CALL); - xLodTailHook.Initialize(0x4EA6FE, XModelLODTailHookStub, HOOK_CALL); + Zones::LoadFxElemDefArrayHook.Initialize(0x495938, Zones::LoadFxElemDefArrayStub, HOOK_CALL); + Zones::LoadFxElemDefHook.Initialize(0x45ADA0, Zones::LoadFxElemDefStub, HOOK_CALL); + Zones::LoadXModelLodInfoHook.Initialize(0x4EA6FE, Zones::LoadXModelLodInfoStub, HOOK_CALL); xModelModifyHook.Initialize(0x410D90, XModelModifyHookFunc, HOOK_CALL); xsurfaceIntLoadHook.Initialize(0x4925C8, XSurfaceIntLoadHookFunc, HOOK_CALL); gameWorldSpLoadHook.Initialize(0x4F4D0D, GameWorldSpLoadHookFunc, HOOK_CALL); diff --git a/src/Components/Modules/Zones.hpp b/src/Components/Modules/Zones.hpp index 29fc4ce7..164cc978 100644 --- a/src/Components/Modules/Zones.hpp +++ b/src/Components/Modules/Zones.hpp @@ -17,5 +17,15 @@ namespace Components //private: static int ZoneVersion; + + static Utils::Hook LoadFxElemDefHook; + static Utils::Hook LoadFxElemDefArrayHook; + static Utils::Hook LoadXModelLodInfoHook; + + static void LoadFxElemDefArrayStub(bool atStreamStart); + static bool LoadFxElemDefStub(bool atStreamStart, Game::FxElemDef* fxElem, int size); + + static void LoadXModelLodInfo(int i); + static void LoadXModelLodInfoStub(); }; } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index c505c3a1..28861d9e 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -102,9 +102,11 @@ namespace Game Load_Stream_t Load_Stream = (Load_Stream_t)0x470E30; Load_XString_t Load_XString = (Load_XString_t)0x47FDA0; Load_XModelPtr_t Load_XModelPtr = (Load_XModelPtr_t)0x4FCA70; + Load_XModelSurfsFixup_t Load_XModelSurfsFixup = (Load_XModelSurfsFixup_t)0x40D7A0; Load_XStringArray_t Load_XStringArray = (Load_XStringArray_t)0x4977F0; Load_XStringCustom_t Load_XStringCustom = (Load_XStringCustom_t)0x4E0DD0; Load_FxEffectDefHandle_t Load_FxEffectDefHandle = (Load_FxEffectDefHandle_t)0x4D9B90; + Load_FxElemDef_t Load_FxElemDef = (Load_FxElemDef_t)0x45AD90; Load_SndAliasCustom_t Load_SndAliasCustom = (Load_SndAliasCustom_t)0x49B6B0; Load_MaterialHandle_t Load_MaterialHandle = (Load_MaterialHandle_t)0x403960; Load_PhysCollmapPtr_t Load_PhysCollmapPtr = (Load_PhysCollmapPtr_t)0x47E990; @@ -273,9 +275,10 @@ namespace Game mapname_t* mapnames = (mapname_t*)0x7471D0; - const char** varXString = (const char**)0x112B340; + char*** varXString = (char***)0x112B340; TracerDef** varTracerDefPtr = (TracerDef**)0x112B3BC; XModel** varXModelPtr = (XModel**)0x112A934; + XModel** varXModel = (XModel**)0x112AE14; const char** varConstChar = (const char**)0x112A774; Material** varMaterialHandle = (Material**)0x112A878; FxEffectDef** varFxEffectDefHandle = (FxEffectDef**)0x112ACC0; diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index ed348446..fdf0c6a9 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -242,6 +242,9 @@ namespace Game typedef void(__cdecl * Load_XModelPtr_t)(bool atStreamStart); extern Load_XModelPtr_t Load_XModelPtr; + typedef void(__cdecl * Load_XModelSurfsFixup_t)(XModelSurfs **, XModelLodInfo *); + extern Load_XModelSurfsFixup_t Load_XModelSurfsFixup; + typedef void(__cdecl * Load_XStringArray_t)(bool atStreamStart, int count); extern Load_XStringArray_t Load_XStringArray; @@ -251,6 +254,9 @@ namespace Game typedef void(__cdecl *Load_FxEffectDefHandle_t)(bool atStreamStart); extern Load_FxEffectDefHandle_t Load_FxEffectDefHandle; + typedef void(__cdecl *Load_FxElemDef_t)(bool atStreamStart); + extern Load_FxElemDef_t Load_FxElemDef; + typedef void(__cdecl * Load_SndAliasCustom_t)(snd_alias_list_t** var); extern Load_SndAliasCustom_t Load_SndAliasCustom; @@ -559,9 +565,10 @@ namespace Game extern mapname_t* mapnames; - extern const char** varXString; + extern char*** varXString; extern TracerDef** varTracerDefPtr; extern XModel** varXModelPtr; + extern XModel** varXModel; extern const char** varConstChar; extern Material** varMaterialHandle; extern FxEffectDef** varFxEffectDefHandle;