Begin refactoring the zone loading code

This commit is contained in:
momo5502 2016-09-21 19:27:31 +02:00
parent 50dfee6db7
commit db2e572612
6 changed files with 77 additions and 108 deletions

2
deps/protobuf vendored

@ -1 +1 @@
Subproject commit 7b00595ddf8622ae429ef37de8ea2f44b6333ad0 Subproject commit 4f379f81cef4dd8e005fd0bcc9199bf842fc35d4

2
deps/zlib vendored

@ -1 +1 @@
Subproject commit 70a8763b7187f2536ce7fe4d399ce9a79c9faf7c Subproject commit 9852c209ac49c0d8d1192e46115d7c37d4344bbd

View File

@ -4,9 +4,13 @@ namespace Components
{ {
int Zones::ZoneVersion; int Zones::ZoneVersion;
Utils::Hook Zones::LoadFxElemDefHook;
Utils::Hook Zones::LoadFxElemDefArrayHook;
Utils::Hook Zones::LoadXModelLodInfoHook;
Utils::Hook fxEffectLoadHook; Utils::Hook fxEffectLoadHook;
static DWORD fxEffectStringValue[64]; static char* fxEffectStringValue[64];
static int fxEffectIndex = 0; static int fxEffectIndex = 0;
void FxEffectLoadHookFunc(int a1, char* buffer, int len) void FxEffectLoadHookFunc(int a1, char* buffer, int len)
@ -34,7 +38,7 @@ namespace Components
memcpy(tempVar + (252 * i), buffer + (260 * i), 252); 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); memcpy(buffer, tempVar, len);
@ -42,67 +46,25 @@ namespace Components
delete[] tempVar; delete[] tempVar;
} }
Utils::Hook fxEffectModifyHook; bool Zones::LoadFxElemDefStub(bool atStreamStart, Game::FxElemDef* fxElem, int size)
void FxEffectModifyHookFunc(int a1, char* buffer, size_t len)
{ {
char typeNum = *(char*)(buffer + 176); if (fxElem->elemType == 3)
//DBG(("ot %i\n", typeNum));
if (typeNum == 3)
{ {
typeNum = 2; fxElem->elemType = 2;
} }
else if (typeNum >= 5) else if (fxElem->elemType >= 5)
{ {
typeNum -= 2; fxElem->elemType -= 2;
} }
/*if (typeNum >= 2) return Game::Load_Stream(atStreamStart, fxElem, size);
{
typeNum -= 2;
}*/
*(char*)(buffer + 176) = typeNum;
__asm
{
push len
push buffer
push a1
call fxEffectModifyHook.Original
add esp, 0Ch
}
} }
Utils::Hook fxEffectTailHook; void Zones::LoadFxElemDefArrayStub(bool atStreamStart)
void FxEffectTailHookFunc()
{ {
*Game::varXString = (char*)&fxEffectStringValue[fxEffectIndex++]; Game::Load_FxElemDef(atStreamStart);
*Game::varXString = &fxEffectStringValue[fxEffectIndex++];
// Load_XStringPtr(0) Game::Load_XString(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
}
} }
Utils::Hook xModelModifyHook; Utils::Hook xModelModifyHook;
@ -151,35 +113,22 @@ namespace Components
memcpy(buffer, tempVar, elSize); memcpy(buffer, tempVar, elSize);
} }
Utils::Hook xLodTailHook; void Zones::LoadXModelLodInfo(int i)
void XModelLODTailHookFunc(int i)
{ {
int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360; int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360;
i = (4 - i)/* + 1*/; *Game::varXString = reinterpret_cast<char**>(reinterpret_cast<char*>(*Game::varXModel) + (elSize - 4) - (4 * (4 - i)));
// varXString = (varXModel + 0x16C - (4 * i)) // where the above function parked the new xstring
*Game::varXString = (char*)((*(DWORD*)0x112AE14) + (elSize - 4)) - (4 * i);
Game::Load_XString(false); Game::Load_XString(false);
} }
void __declspec(naked) XModelLODTailHookStub() void __declspec(naked) Zones::LoadXModelLodInfoStub()
{ {
__asm __asm
{ {
push edi push edi
call XModelLODTailHookFunc call Zones::LoadXModelLodInfo
add esp, 4h pop edi
mov eax, [esp + 8h] jmp Game::Load_XModelSurfsFixup
push eax
add eax, 8
push eax
call xLodTailHook.Original
add esp, 8h
retn
} }
} }
@ -233,16 +182,16 @@ namespace Components
Game::DB_PushStreamPos(3); Game::DB_PushStreamPos(3);
*Game::varXString = (char*)varWeaponDef + 0; *Game::varXString = (char**)(varWeaponDef + 0);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 4; *Game::varXString = (char**)(varWeaponDef + 4);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 8; *Game::varXString = (char**)(varWeaponDef + 8);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 12; *Game::varXString = (char**)(varWeaponDef + 12);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXModelPtr = (Game::XModel*)(varWeaponDef + 16); *Game::varXModelPtr = (Game::XModel*)(varWeaponDef + 16);
@ -265,15 +214,15 @@ namespace Components
// 32 scriptstrings, should not need to be loaded // 32 scriptstrings, should not need to be loaded
// 236 // 236
*Game::varXString = (char*)varWeaponDef + 236; *Game::varXString = (char**)(varWeaponDef + 236);
Game::Load_XStringArray(false, 48); Game::Load_XStringArray(false, 48);
// 428 // 428
*Game::varXString = (char*)varWeaponDef + 428; *Game::varXString = (char**)(varWeaponDef + 428);
Game::Load_XStringArray(false, 48); Game::Load_XStringArray(false, 48);
// 620 // 620
*Game::varXString = (char*)varWeaponDef + 620; *Game::varXString = (char**)(varWeaponDef + 620);
Game::Load_XStringArray(false, 48); Game::Load_XStringArray(false, 48);
// 812 // 812
@ -351,13 +300,13 @@ namespace Components
Game::Load_MaterialHandle(false); Game::Load_MaterialHandle(false);
} }
*Game::varXString = (char*)varWeaponDef + 1484; *Game::varXString = (char**)(varWeaponDef + 1484);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 1492; *Game::varXString = (char**)(varWeaponDef + 1492);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 1508; *Game::varXString = (char**)(varWeaponDef + 1508);
Game::Load_XString(false); Game::Load_XString(false);
for (int offset = 1764; offset <= 1776; offset += 4) 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::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2372); // 2380
Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name);
*Game::varXString = (char*)varWeaponDef + 2548; // 2556 *Game::varXString = (char**)(varWeaponDef + 2548); // 2556
Game::Load_XString(false); Game::Load_XString(false);
if (*(DWORD*)(varWeaponDef + 2556) == -1) // 2564 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::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); Game::Load_XString(false);
if (*(DWORD*)(varWeaponDef + 2560) == -1) 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::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::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 2644; *Game::varXString = (char**)(varWeaponDef + 2644);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 2676; *Game::varXString = (char**)(varWeaponDef + 2676);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 2680; *Game::varXString = (char**)(varWeaponDef + 2680);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 2804; *Game::varXString = (char**)(varWeaponDef + 2804);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 2808; *Game::varXString = (char**)(varWeaponDef + 2808);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varTracerDefPtr = (Game::TracerDef*)(varWeaponDef + 2812); *Game::varTracerDefPtr = (Game::TracerDef*)(varWeaponDef + 2812);
@ -445,7 +394,7 @@ namespace Components
*Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 2844); *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 2844);
Game::Load_FxEffectDefHandle(false); Game::Load_FxEffectDefHandle(false);
*Game::varXString = (char*)varWeaponDef + 2848; *Game::varXString = (char**)(varWeaponDef + 2848);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2864); *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::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 2996; *Game::varXString = (char**)(varWeaponDef + 2996);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varXString = (char*)varWeaponDef + 3000; *Game::varXString = (char**)(varWeaponDef + 3000);
Game::Load_XString(false); Game::Load_XString(false);
*Game::varMaterialHandle = (Game::Material*)(varWeaponDef + 3008); *Game::varMaterialHandle = (Game::Material*)(varWeaponDef + 3008);
@ -831,10 +780,10 @@ namespace Components
if (patch) if (patch)
{ {
fxEffectTailHook.Install(); Zones::LoadFxElemDefArrayHook.Install();
fxEffectModifyHook.Install(); Zones::LoadFxElemDefHook.Install();
xLodTailHook.Install(); Zones::LoadXModelLodInfoHook.Install();
xModelModifyHook.Install(); xModelModifyHook.Install();
xsurfaceIntLoadHook.Install(); xsurfaceIntLoadHook.Install();
@ -861,10 +810,10 @@ namespace Components
} }
else else
{ {
fxEffectTailHook.Uninstall(); Zones::LoadFxElemDefArrayHook.Uninstall();
fxEffectModifyHook.Uninstall(); Zones::LoadFxElemDefHook.Uninstall();
xLodTailHook.Uninstall(); Zones::LoadXModelLodInfoHook.Uninstall();
xModelModifyHook.Uninstall(); xModelModifyHook.Uninstall();
xsurfaceIntLoadHook.Uninstall(); xsurfaceIntLoadHook.Uninstall();
@ -901,9 +850,9 @@ namespace Components
// Block Mark_pathnode_constant_t // Block Mark_pathnode_constant_t
Utils::Hook::Set<BYTE>(0x4F74B0, 0xC3); Utils::Hook::Set<BYTE>(0x4F74B0, 0xC3);
fxEffectTailHook.Initialize(0x495938, FxEffectTailHookStub, HOOK_CALL); Zones::LoadFxElemDefArrayHook.Initialize(0x495938, Zones::LoadFxElemDefArrayStub, HOOK_CALL);
fxEffectModifyHook.Initialize(0x45ADA0, FxEffectModifyHookFunc, HOOK_CALL); Zones::LoadFxElemDefHook.Initialize(0x45ADA0, Zones::LoadFxElemDefStub, HOOK_CALL);
xLodTailHook.Initialize(0x4EA6FE, XModelLODTailHookStub, HOOK_CALL); Zones::LoadXModelLodInfoHook.Initialize(0x4EA6FE, Zones::LoadXModelLodInfoStub, HOOK_CALL);
xModelModifyHook.Initialize(0x410D90, XModelModifyHookFunc, HOOK_CALL); xModelModifyHook.Initialize(0x410D90, XModelModifyHookFunc, HOOK_CALL);
xsurfaceIntLoadHook.Initialize(0x4925C8, XSurfaceIntLoadHookFunc, HOOK_CALL); xsurfaceIntLoadHook.Initialize(0x4925C8, XSurfaceIntLoadHookFunc, HOOK_CALL);
gameWorldSpLoadHook.Initialize(0x4F4D0D, GameWorldSpLoadHookFunc, HOOK_CALL); gameWorldSpLoadHook.Initialize(0x4F4D0D, GameWorldSpLoadHookFunc, HOOK_CALL);

View File

@ -17,5 +17,15 @@ namespace Components
//private: //private:
static int ZoneVersion; 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();
}; };
} }

View File

@ -102,9 +102,11 @@ namespace Game
Load_Stream_t Load_Stream = (Load_Stream_t)0x470E30; Load_Stream_t Load_Stream = (Load_Stream_t)0x470E30;
Load_XString_t Load_XString = (Load_XString_t)0x47FDA0; Load_XString_t Load_XString = (Load_XString_t)0x47FDA0;
Load_XModelPtr_t Load_XModelPtr = (Load_XModelPtr_t)0x4FCA70; 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_XStringArray_t Load_XStringArray = (Load_XStringArray_t)0x4977F0;
Load_XStringCustom_t Load_XStringCustom = (Load_XStringCustom_t)0x4E0DD0; Load_XStringCustom_t Load_XStringCustom = (Load_XStringCustom_t)0x4E0DD0;
Load_FxEffectDefHandle_t Load_FxEffectDefHandle = (Load_FxEffectDefHandle_t)0x4D9B90; 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_SndAliasCustom_t Load_SndAliasCustom = (Load_SndAliasCustom_t)0x49B6B0;
Load_MaterialHandle_t Load_MaterialHandle = (Load_MaterialHandle_t)0x403960; Load_MaterialHandle_t Load_MaterialHandle = (Load_MaterialHandle_t)0x403960;
Load_PhysCollmapPtr_t Load_PhysCollmapPtr = (Load_PhysCollmapPtr_t)0x47E990; Load_PhysCollmapPtr_t Load_PhysCollmapPtr = (Load_PhysCollmapPtr_t)0x47E990;
@ -273,9 +275,10 @@ namespace Game
mapname_t* mapnames = (mapname_t*)0x7471D0; mapname_t* mapnames = (mapname_t*)0x7471D0;
const char** varXString = (const char**)0x112B340; char*** varXString = (char***)0x112B340;
TracerDef** varTracerDefPtr = (TracerDef**)0x112B3BC; TracerDef** varTracerDefPtr = (TracerDef**)0x112B3BC;
XModel** varXModelPtr = (XModel**)0x112A934; XModel** varXModelPtr = (XModel**)0x112A934;
XModel** varXModel = (XModel**)0x112AE14;
const char** varConstChar = (const char**)0x112A774; const char** varConstChar = (const char**)0x112A774;
Material** varMaterialHandle = (Material**)0x112A878; Material** varMaterialHandle = (Material**)0x112A878;
FxEffectDef** varFxEffectDefHandle = (FxEffectDef**)0x112ACC0; FxEffectDef** varFxEffectDefHandle = (FxEffectDef**)0x112ACC0;

View File

@ -242,6 +242,9 @@ namespace Game
typedef void(__cdecl * Load_XModelPtr_t)(bool atStreamStart); typedef void(__cdecl * Load_XModelPtr_t)(bool atStreamStart);
extern Load_XModelPtr_t Load_XModelPtr; 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); typedef void(__cdecl * Load_XStringArray_t)(bool atStreamStart, int count);
extern Load_XStringArray_t Load_XStringArray; extern Load_XStringArray_t Load_XStringArray;
@ -251,6 +254,9 @@ namespace Game
typedef void(__cdecl *Load_FxEffectDefHandle_t)(bool atStreamStart); typedef void(__cdecl *Load_FxEffectDefHandle_t)(bool atStreamStart);
extern Load_FxEffectDefHandle_t Load_FxEffectDefHandle; 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); typedef void(__cdecl * Load_SndAliasCustom_t)(snd_alias_list_t** var);
extern Load_SndAliasCustom_t Load_SndAliasCustom; extern Load_SndAliasCustom_t Load_SndAliasCustom;
@ -559,9 +565,10 @@ namespace Game
extern mapname_t* mapnames; extern mapname_t* mapnames;
extern const char** varXString; extern char*** varXString;
extern TracerDef** varTracerDefPtr; extern TracerDef** varTracerDefPtr;
extern XModel** varXModelPtr; extern XModel** varXModelPtr;
extern XModel** varXModel;
extern const char** varConstChar; extern const char** varConstChar;
extern Material** varMaterialHandle; extern Material** varMaterialHandle;
extern FxEffectDef** varFxEffectDefHandle; extern FxEffectDef** varFxEffectDefHandle;