#include #include #include "FastFiles.hpp" #pragma optimize( "", off ) namespace Components { int Zones::ZoneVersion; int Zones::FxEffectIndex; char* Zones::FxEffectStrings[64]; static std::unordered_map shellshock_replace_list = { { "66","bg_shock_screenType" }, { "67","bg_shock_screenBlurBlendTime"}, { "68","bg_shock_screenBlurBlendFadeTime"}, { "69","bg_shock_screenFlashWhiteFadeTime"}, { "70","bg_shock_screenFlashShotFadeTime"}, { "71","bg_shock_viewKickPeriod"}, { "72","bg_shock_viewKickRadius"}, { "73","bg_shock_viewKickFadeTime"}, { "78","bg_shock_sound"}, { "74","bg_shock_soundLoop"}, { "75","bg_shock_soundLoopSilent"}, { "76","bg_shock_soundEnd"}, { "77","bg_shock_soundEndAbort"}, { "79","bg_shock_soundFadeInTime"}, { "80","bg_shock_soundFadeOutTime"}, { "81","bg_shock_soundLoopFadeTime"}, { "82","bg_shock_soundLoopEndDelay"}, { "83","bg_shock_soundRoomType"}, { "84","bg_shock_soundDryLevel"}, { "85","bg_shock_soundWetLevel"}, { "86","bg_shock_soundModEndDelay"}, // guessed, not sure { "87","bg_shock_lookControl"}, { "88","bg_shock_lookControl_maxpitchspeed"}, { "89","bg_shock_lookControl_maxyawspeed"}, { "90","bg_shock_lookControl_mousesensitivityscale"}, { "91","bg_shock_lookControl_fadeTime"}, { "92","bg_shock_movement"} }; Game::XAssetType currentAssetType = Game::XAssetType::ASSET_TYPE_INVALID; Game::XAssetType previousAssetType = Game::XAssetType::ASSET_TYPE_INVALID; bool Zones::LoadFxEffectDef(bool atStreamStart, char* buffer, int size) { int count = 0; if (Zones::Version() >= VERSION_ALPHA2) { size /= 252; count = size; size *= 260; } bool result = Game::Load_Stream(atStreamStart, buffer, size); Zones::FxEffectIndex = 0; if (Zones::Version() >= VERSION_ALPHA2) { Utils::Memory::Allocator allocator; Game::FxElemDef* elems = allocator.allocateArray(count); for (int i = 0; i < count; ++i) { AssetHandler::Relocate(buffer + (260 * i), buffer + (252 * i), 252); std::memcpy(&elems[i], buffer + (260 * i), 252); Zones::FxEffectStrings[i] = *reinterpret_cast(buffer + (260 * i) + 256); } std::memcpy(buffer, elems, sizeof(Game::FxElemDef) * count); } return result; } bool Zones::LoadFxElemDefStub(bool atStreamStart, Game::FxElemDef* fxElem, int size) { if (Zones::Version() >= VERSION_ALPHA2) { if (fxElem->elemType == 3) { fxElem->elemType = 2; } else if (fxElem->elemType >= 5) { fxElem->elemType -= 2; } } return Game::Load_Stream(atStreamStart, fxElem, size); } void Zones::LoadFxElemDefArrayStub(bool atStreamStart) { Game::Load_FxElemDef(atStreamStart); if (Zones::Version() >= VERSION_ALPHA2) { *Game::varXString = &Zones::FxEffectStrings[Zones::FxEffectIndex++]; Game::Load_XString(false); } } bool Zones::LoadXModel(bool atStreamStart, char* xmodel, int size) { if (Zones::Version() >= VERSION_ALPHA2) { if (Zones::Version() == VERSION_ALPHA2) { size = 0x16C; } else { size = 0x168; } } bool result = Game::Load_Stream(atStreamStart, xmodel, size); if (Zones::Version() >= VERSION_ALPHA2) { Game::XModel model[2]; // Allocate 2 models, as we exceed the buffer std::memcpy(model, xmodel, 36); std::memcpy(&model->boneNames, &xmodel[44], 28); for (int i = 0; i < 4; ++i) { AssertOffset(Game::XModelLodInfo, partBits, 12); std::memcpy(&model->lodInfo[i], &xmodel[72 + (i * 56)], 12); std::memcpy(&model->lodInfo[i].partBits, &xmodel[72 + (i * 56) + 16], 32); std::memcpy(reinterpret_cast(&model) + (size - 4) - (i * 4), &xmodel[72 + (i * 56) + 12], 4); } std::memcpy(&model->lodInfo[3].lod, &xmodel[292], (size - 292 - 4)/*68*/); std::memcpy(&model->physPreset, &xmodel[(size - 8)], 8); model[1].name = reinterpret_cast(0xDEADC0DE); std::memcpy(xmodel, &model, size); } return result; } void Zones::LoadXModelLodInfo(int i) { if (Zones::Version() >= VERSION_ALPHA2) { int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360; *Game::varXString = reinterpret_cast(reinterpret_cast(*Game::varXModel) + (elSize - 4) - (4 * (4 - i))); Game::Load_XString(false); } } __declspec(naked) void Zones::LoadXModelLodInfoStub() { __asm { pushad push edi call Zones::LoadXModelLodInfo add esp, 4h popad push 0x4EA703 // Return address push 0x40D7A0 // Load_XModelSurfsFixup retn } } bool Zones::LoadXSurfaceArray(bool atStreamStart, char* buffer, int size) { int count = 0; if (Zones::Version() >= VERSION_ALPHA2) { size >>= 6; count = size; size *= 84; } bool result = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::Version() >= VERSION_ALPHA2) { Utils::Memory::Allocator allocator; Game::XSurface* tempSurfaces = allocator.allocateArray(count); for (int i = 0; i < count; ++i) { char* source = &buffer[i * 84]; std::memcpy(&tempSurfaces[i], source, 12); std::memcpy(&tempSurfaces[i].triIndices, source + 16, 20); std::memcpy(&tempSurfaces[i].vertListCount, source + 40, 8); std::memcpy(&tempSurfaces[i].partBits, source + 52, 24); if (Zones::ZoneVersion >= 332) { struct { short pad; // +0 char flag; // +2 char zoneHandle; // +3 unsigned short vertCount; // +4 unsigned short triCount; // +6 // [...] } surface332; // Copy the data to our new structure std::memcpy(&surface332, &tempSurfaces[i], sizeof(surface332)); // Check if that special flag is set if (!(surface332.flag & 0x20)) { Logger::Error(Game::ERR_FATAL, "We're not able to handle XSurface buffer allocation yet!"); } // Copy the correct data back to our surface tempSurfaces[i].zoneHandle = surface332.zoneHandle; tempSurfaces[i].vertCount = surface332.vertCount; tempSurfaces[i].triCount = surface332.triCount; //std::memmove(&tempSurfaces[i].numVertices, &tempSurfaces[i].numPrimitives, 6); } } std::memcpy(buffer, tempSurfaces, sizeof(Game::XSurface) * count); } return result; } void Zones::LoadWeaponCompleteDef() { if (Zones::ZoneVersion < VERSION_ALPHA2) { return Utils::Hook::Call(0x4AE7B0)(true); } // setup structures we use char* varWeaponCompleteDef = *reinterpret_cast(0x112A9F4); int size = 3112; if (Zones::ZoneVersion >= 461) size = 4124; else if (Zones::ZoneVersion >= 460) size = 4120; else if (Zones::ZoneVersion >= 365) size = 3124; else if (Zones::ZoneVersion >= 359) size = 3120; else if (Zones::ZoneVersion >= 332) size = 3068; else if (Zones::ZoneVersion >= 318) size = 3156; int offsetShift = (Zones::ZoneVersion >= 461) ? 4 : 0; // and do the stuff Game::Load_Stream(true, varWeaponCompleteDef, size); Game::DB_PushStreamPos(3); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 0); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 4); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 8); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 12); Game::Load_XString(false); *Game::varXModelPtr = reinterpret_cast(varWeaponCompleteDef + 16); Game::Load_XModelPtr(false); if (Zones::ZoneVersion >= 359) { auto count = (Zones::Version() >= 460) ? 52 : 56; for (int offset = 20; offset <= count; offset += 4) { *Game::varXModelPtr = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_XModelPtr(false); } } else { for (int i = 0, offset = 20; i < 32; ++i, offset += 4) { *Game::varXModelPtr = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_XModelPtr(false); } // 148 for (int offset = 148; offset <= 168; offset += 4) { *Game::varXModelPtr = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_XModelPtr(false); } } // 172 // 32 scriptstrings, should not need to be loaded if (Zones::ZoneVersion >= 359) { auto stringCount = (Zones::Version() >= 460) ? 62 : 52; auto arraySize = stringCount * 4; // 236 *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 124); Game::Load_XStringArray(false, stringCount); // 428 *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 124 + arraySize); Game::Load_XStringArray(false, stringCount); // 620 *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 124 + (arraySize * 2)); Game::Load_XStringArray(false, stringCount); } else { // 236 *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 236); Game::Load_XStringArray(false, 48); // 428 *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 428); Game::Load_XStringArray(false, 48); // 620 *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 620); Game::Load_XStringArray(false, 48); } // 812 // 16 * 4 scriptstrings if (Zones::Version() >= 460) { for (int i = 0; i < 16; i++) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 1028 + (i * 4)); Game::Load_FxEffectDefHandle(false); } for (int i = 0; i < 16; i++) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 1124 + (i * 4)); Game::Load_FxEffectDefHandle(false); } for (int i = 0; i < 16; i++) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 1188 + (i * 4)); Game::Load_FxEffectDefHandle(false); } for (int i = 0; i < 16; i++) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 1316 + (i * 4)); Game::Load_FxEffectDefHandle(false); } for (int i = 0; i < 5; i++) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 1444 + (i * 4)); Game::Load_FxEffectDefHandle(false); } } else if (Zones::ZoneVersion >= 359) { // 972 *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 908); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 912); Game::Load_FxEffectDefHandle(false); } else { // 972 *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 972); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 976); Game::Load_FxEffectDefHandle(false); } if (Zones::Version() >= 460) { *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 1464); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 1472); Game::Load_XString(false); } // 980 if (Zones::ZoneVersion >= 359) { auto offset = (Zones::Version() >= 460) ? 1476 : 916; auto count = (Zones::Version() >= 461) ? 58 : (Zones::Version() >= 460) ? 57 : 52; // 53 soundalias name references; up to and including 1124 for (int i = 0; i < count; ++i, offset += 4) { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } } else { // 50 soundalias name references; up to and including 1180 for (int i = 0, offset = 980; i < 50; ++i, offset += 4) { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } if (Zones::ZoneVersion >= 318) { for (int i = 0, offset = 1184; i < 2; ++i, offset += 4) { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } varWeaponCompleteDef += 8; // to compensate for the 2 in between here } } if (Zones::Version() >= 460) { if (*reinterpret_cast(varWeaponCompleteDef + 1708)) { if (*reinterpret_cast(varWeaponCompleteDef + 1708) == -1) { *reinterpret_cast(varWeaponCompleteDef + 1708) = Game::DB_AllocStreamPos(3); *Game::varsnd_alias_list_name = *reinterpret_cast(varWeaponCompleteDef + 1708); Game::Load_snd_alias_list_nameArray(true, 31); } else { // full usability requires ConvertOffsetToPointer here } } if (*reinterpret_cast(varWeaponCompleteDef + 1712)) { if (*reinterpret_cast(varWeaponCompleteDef + 1712) == -1) { *reinterpret_cast(varWeaponCompleteDef + 1712) = Game::DB_AllocStreamPos(3); *Game::varsnd_alias_list_name = *reinterpret_cast(varWeaponCompleteDef + 1712); Game::Load_snd_alias_list_nameArray(true, 31); } else { // full usability requires ConvertOffsetToPointer here } } } else if (Zones::ZoneVersion >= 359) { if (*reinterpret_cast(varWeaponCompleteDef + 1128)) { if (*reinterpret_cast(varWeaponCompleteDef + 1128) == -1) { *reinterpret_cast(varWeaponCompleteDef + 1128) = Game::DB_AllocStreamPos(3); *Game::varsnd_alias_list_name = *reinterpret_cast(varWeaponCompleteDef + 1128); Game::Load_snd_alias_list_nameArray(true, 31); } else { // full usability requires ConvertOffsetToPointer here } } if (*reinterpret_cast(varWeaponCompleteDef + 1132)) { if (*reinterpret_cast(varWeaponCompleteDef + 1132) == -1) { *reinterpret_cast(varWeaponCompleteDef + 1132) = Game::DB_AllocStreamPos(3); *Game::varsnd_alias_list_name = *reinterpret_cast(varWeaponCompleteDef + 1132); Game::Load_snd_alias_list_nameArray(true, 31); } else { // full usability requires ConvertOffsetToPointer here } } } else { if (*reinterpret_cast(varWeaponCompleteDef + 1184)) { if (*reinterpret_cast(varWeaponCompleteDef + 1184) == -1) { *reinterpret_cast(varWeaponCompleteDef + 1184) = Game::DB_AllocStreamPos(3); *Game::varsnd_alias_list_name = *reinterpret_cast(varWeaponCompleteDef + 1184); Game::Load_snd_alias_list_nameArray(true, 31); } else { // full usability requires ConvertOffsetToPointer here } } if (*reinterpret_cast(varWeaponCompleteDef + 1188)) { if (*reinterpret_cast(varWeaponCompleteDef + 1188) == -1) { *reinterpret_cast(varWeaponCompleteDef + 1188) = Game::DB_AllocStreamPos(3); *Game::varsnd_alias_list_name = *reinterpret_cast(varWeaponCompleteDef + 1188); Game::Load_snd_alias_list_nameArray(true, 31); } else { // full usability requires ConvertOffsetToPointer here } } } if (Zones::Version() >= 460) { // 1192 for (int offset = 1716; offset <= 1728; offset += 4) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_FxEffectDefHandle(false); } } else if (Zones::ZoneVersion >= 359) { // 1192 for (int offset = 1136; offset <= 1148; offset += 4) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_FxEffectDefHandle(false); } } else { // 1192 for (int offset = 1192; offset <= 1204; offset += 4) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_FxEffectDefHandle(false); } } if (Zones::Version() >= 460) { // 1208 static int matOffsets1[] = { 1732, 1736, 1952, 1956, 1960, 1964, 1968, 1972, 1980, 1988, 2000, 2004, 2008, 2012 }; for (int i = 0; i < ARRAYSIZE(matOffsets1); ++i) { *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + matOffsets1[i]); Game::Load_MaterialHandle(false); } } else if (Zones::ZoneVersion >= 359) { // 1208 static int matOffsets1[] = { 1152, 1156, 1372,1376,1380, 1384, 1388, 1392, 1400, 1408 }; for (int i = 0; i < ARRAYSIZE(matOffsets1); ++i) { *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + matOffsets1[i]); Game::Load_MaterialHandle(false); } } else { // 1208 static int matOffsets1[] = { 1208, 1212, 1428, 1432, 1436, 1440, 1444, 1448, 1456, 1464 }; for (int i = 0; i < ARRAYSIZE(matOffsets1); ++i) { *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + matOffsets1[i]); Game::Load_MaterialHandle(false); } } if (Zones::Version() >= 460) { *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2024); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2032); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2048); Game::Load_XString(false); } else if (Zones::ZoneVersion >= 359) { *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 1428); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 1436); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 1452); Game::Load_XString(false); } else { *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 1484); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 1492); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 1508); Game::Load_XString(false); } if (Zones::Version() >= 460) { for (int offset = 2332; offset <= 2344; offset += 4) { *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_MaterialHandle(false); } } else if (Zones::ZoneVersion >= 359) { for (int offset = 1716; offset <= 1728; offset += 4) { *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_MaterialHandle(false); } } else { for (int offset = 1764; offset <= 1776; offset += 4) { *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_MaterialHandle(false); } } if (Zones::Version() >= 460) { *Game::varPhysCollmapPtr = reinterpret_cast(varWeaponCompleteDef + 2544); Game::Load_PhysCollmapPtr(false); *Game::varPhysPresetPtr = reinterpret_cast(varWeaponCompleteDef + 2548); Game::Load_PhysPresetPtr(false); } else if (Zones::ZoneVersion >= 359) { *Game::varPhysCollmapPtr = reinterpret_cast(varWeaponCompleteDef + 1928); Game::Load_PhysCollmapPtr(false); *Game::varPhysPresetPtr = reinterpret_cast(varWeaponCompleteDef + 1932); Game::Load_PhysPresetPtr(false); } else { *Game::varPhysCollmapPtr = reinterpret_cast(varWeaponCompleteDef + 1964); Game::Load_PhysCollmapPtr(false); } if (Zones::Version() >= 460) { *Game::varXModelPtr = reinterpret_cast(varWeaponCompleteDef + 2656); Game::Load_XModelPtr(false); } else if (Zones::ZoneVersion >= 359) { *Game::varXModelPtr = reinterpret_cast(varWeaponCompleteDef + 2020); Game::Load_XModelPtr(false); } else { *Game::varXModelPtr = reinterpret_cast(varWeaponCompleteDef + 2052); Game::Load_XModelPtr(false); } if (Zones::Version() >= 460) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2664); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2668); Game::Load_FxEffectDefHandle(false); } else if (Zones::ZoneVersion >= 359) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2028); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2032); Game::Load_FxEffectDefHandle(false); } else { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2060); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2064); Game::Load_FxEffectDefHandle(false); } if (Zones::Version() >= 460) { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2672); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2676); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } else if (Zones::ZoneVersion >= 359) { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2036); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2040); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } else { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2068); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2072); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } if (Zones::Version() >= 460) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2952); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2956); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2984); Game::Load_FxEffectDefHandle(false); } else if (Zones::ZoneVersion >= 359) { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2304); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2308); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2336); Game::Load_FxEffectDefHandle(false); } else { *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2336); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2340); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2368); // 2376 Game::Load_FxEffectDefHandle(false); } if (Zones::Version() >= 460) { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2988); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2992); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2996); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 3000); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 3004); Game::Load_FxEffectDefHandle(false); *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 3008); Game::Load_FxEffectDefHandle(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3196); Game::Load_XString(false); } else if (Zones::ZoneVersion >= 359) { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2340); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2516); Game::Load_XString(false); } else { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2372); // 2380 Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2548); // 2556 Game::Load_XString(false); } if (Zones::Version() >= 460) { if (*reinterpret_cast(varWeaponCompleteDef + 3204) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 3204) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + 3776 + offsetShift)); } *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3200); Game::Load_XString(false); if (*reinterpret_cast(varWeaponCompleteDef + 3208) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 3208) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + 3778 + offsetShift)); } } else if (Zones::ZoneVersion >= 359) { if (*reinterpret_cast(varWeaponCompleteDef + 2524) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 2524) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + 3044)); } *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2520); Game::Load_XString(false); if (*reinterpret_cast(varWeaponCompleteDef + 2528) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 2528) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + 3046)); } } else { if (*reinterpret_cast(varWeaponCompleteDef + 2556) == -1) // 2564 { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 2556) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + ((Zones::ZoneVersion >= 318) ? 3076 : 3040))); } *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2552); Game::Load_XString(false); if (*reinterpret_cast(varWeaponCompleteDef + 2560) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 2560) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + ((Zones::ZoneVersion >= 318) ? 3078 : 3042))); } } if (Zones::Version() >= 460) { *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3288 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3292 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3324 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3328 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3484 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3488 + offsetShift); Game::Load_XString(false); } else if (Zones::ZoneVersion >= 359) { *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2608); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2612); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2644); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2648); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2772); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2776); Game::Load_XString(false); } else { *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2640); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2644); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2676); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2680); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2804); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2808); Game::Load_XString(false); } if (Zones::Version() >= 460) { *Game::varTracerDefPtr = reinterpret_cast(varWeaponCompleteDef + 3492 + offsetShift); Game::Load_TracerDefPtr(false); *Game::varTracerDefPtr = reinterpret_cast(varWeaponCompleteDef + 3496 + offsetShift); Game::Load_TracerDefPtr(false); *Game::varTracerDefPtr = reinterpret_cast(varWeaponCompleteDef + 3500 + offsetShift); Game::Load_TracerDefPtr(false); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 3528 + offsetShift); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); // 2848 *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 3532 + offsetShift); Game::Load_FxEffectDefHandle(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3536 + offsetShift); Game::Load_XString(false); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 3552 + offsetShift); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 3556 + offsetShift); Game::Load_snd_alias_list_nameArray(false, 4); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 3572 + offsetShift); Game::Load_snd_alias_list_nameArray(false, 4); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 3588 + offsetShift); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 3592 + offsetShift); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } else if (Zones::ZoneVersion >= 359) { *Game::varTracerDefPtr = reinterpret_cast(varWeaponCompleteDef + 2780); Game::Load_TracerDefPtr(false); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2808); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); // 2848 *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2812); Game::Load_FxEffectDefHandle(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2816); Game::Load_XString(false); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2832); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2836); Game::Load_snd_alias_list_nameArray(false, 4); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2852); Game::Load_snd_alias_list_nameArray(false, 4); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2868); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2872); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } else { *Game::varTracerDefPtr = reinterpret_cast(varWeaponCompleteDef + 2812); Game::Load_TracerDefPtr(false); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2840); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); // 2848 *Game::varFxEffectDefHandle = reinterpret_cast(varWeaponCompleteDef + 2844); Game::Load_FxEffectDefHandle(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2848); Game::Load_XString(false); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2864); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2868); Game::Load_snd_alias_list_nameArray(false, 4); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2884); Game::Load_snd_alias_list_nameArray(false, 4); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2900); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + 2904); // 2912 Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } if (Zones::Version() >= 460) { for (int i = 0, offset = 3660 + offsetShift; i < 6; ++i, offset += 4) { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } } else if (Zones::ZoneVersion >= 359) { for (int i = 0, offset = 2940; i < 6; ++i, offset += 4) { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } } else { if (Zones::ZoneVersion >= 318) { for (int i = 0, offset = 2972; i < 6; ++i, offset += 4) { *Game::varsnd_alias_list_name = reinterpret_cast(varWeaponCompleteDef + offset); Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } varWeaponCompleteDef += (6 * 4); varWeaponCompleteDef += 12; } else { } } if (Zones::Version() >= 460) { *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3712 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3728 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3732 + offsetShift); Game::Load_XString(false); *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + 3740 + offsetShift); Game::Load_MaterialHandle(false); *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + 3744 + offsetShift); Game::Load_MaterialHandle(false); *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + 3748 + offsetShift); Game::Load_MaterialHandle(false); *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + 3752 + offsetShift); Game::Load_MaterialHandle(false); } else if (Zones::ZoneVersion >= 359) { *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2988); Game::Load_XString(false); if (Zones::ZoneVersion >= 365) { varWeaponCompleteDef += 4; } *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3000); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3004); Game::Load_XString(false); *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + 3012); Game::Load_MaterialHandle(false); *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + 3016); Game::Load_MaterialHandle(false); *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + 3020); Game::Load_MaterialHandle(false); } else { *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2984); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 2996); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3000); Game::Load_XString(false); *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + 3008); Game::Load_MaterialHandle(false); *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + 3012); Game::Load_MaterialHandle(false); *Game::varMaterialHandle = reinterpret_cast(varWeaponCompleteDef + 3016); Game::Load_MaterialHandle(false); } if (Zones::Version() >= 460) { if (*reinterpret_cast(varWeaponCompleteDef + 3780 + offsetShift) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 3780 + offsetShift) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + 3776 + offsetShift)); } if (*reinterpret_cast(varWeaponCompleteDef + 3784 + offsetShift) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 3784 + offsetShift) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + 3778 + offsetShift)); } *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3876 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3880 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3884 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 3996 + offsetShift); Game::Load_XString(false); *Game::varXString = reinterpret_cast(varWeaponCompleteDef + 4012 + offsetShift); Game::Load_XString(false); } else if (Zones::ZoneVersion >= 359) { if (*reinterpret_cast(varWeaponCompleteDef + 3048) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 3048) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + 3044)); } if (*reinterpret_cast(varWeaponCompleteDef + 3052) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 3052) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + 3046)); } } else { if (*reinterpret_cast(varWeaponCompleteDef + 3044) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 3044) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + 3040)); } if (*reinterpret_cast(varWeaponCompleteDef + 3048) == -1) { void* vec2 = Game::DB_AllocStreamPos(3); *reinterpret_cast(varWeaponCompleteDef + 3048) = vec2; Game::Load_Stream(true, vec2, 8 * *reinterpret_cast(varWeaponCompleteDef + 3042)); } } Game::DB_PopStreamPos(); } // Code-analysis has a bug, the first memcpy makes it believe size of tempVar is 44 instead of 84 #pragma warning(push) #pragma warning(disable: 6385) bool Zones::LoadGameWorldSp(bool atStreamStart, char* buffer, int size) { if (Zones::Version() >= VERSION_ALPHA2) { size = 84; } bool result = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::Version() >= VERSION_ALPHA2) { char tempVar[84] = { 0 }; std::memcpy(&tempVar[0], &buffer[0], 44); std::memcpy(&tempVar[56], &buffer[44], 28); std::memcpy(&tempVar[44], &buffer[72], 12); std::memcpy(buffer, tempVar, sizeof(tempVar)); } return result; } #pragma warning(pop) void Zones::LoadPathDataTail() { if (Zones::ZoneVersion >= VERSION_ALPHA2) { char* varPathData = reinterpret_cast(*Game::varPathData); if (*reinterpret_cast(varPathData + 56)) { *reinterpret_cast(varPathData + 56) = Game::DB_AllocStreamPos(0); Game::Load_Stream(true, *reinterpret_cast(varPathData + 56), *reinterpret_cast(varPathData + 52)); } if (*reinterpret_cast(varPathData + 64)) { *reinterpret_cast(varPathData + 64) = Game::DB_AllocStreamPos(0); Game::Load_Stream(true, *reinterpret_cast(varPathData + 64), *reinterpret_cast(varPathData + 60)); } if (*reinterpret_cast(varPathData + 76)) { *reinterpret_cast(varPathData + 76) = Game::DB_AllocStreamPos(0); Game::Load_Stream(true, *reinterpret_cast(varPathData + 76), *reinterpret_cast(varPathData + 72)); } } } bool Zones::Loadsnd_alias_tArray(bool atStreamStart, char* buffer, int len) { int count = 0; if (Zones::Version() >= VERSION_ALPHA2) { len /= 100; count = len; len *= 108; } bool result = Game::Load_Stream(atStreamStart, buffer, len); if (Zones::Version() >= VERSION_ALPHA2) { Utils::Memory::Allocator allocator; Game::snd_alias_t* tempSounds = allocator.allocateArray(count); for (int i = 0; i < count; ++i) { char* src = &buffer[i * 108]; char* dest = reinterpret_cast(&tempSounds[i]); std::memcpy(dest + 0, src + 0, 60); std::memcpy(dest + 60, src + 68, 20); std::memcpy(dest + 80, src + 88, 20); AssetHandler::Relocate(src + 0, buffer + (i * 100) + 0, 60); AssetHandler::Relocate(src + 68, buffer + (i * 100) + 60, 20); AssetHandler::Relocate(src + 88, buffer + (i * 100) + 80, 20); } std::memcpy(buffer, tempSounds, sizeof(Game::snd_alias_t) * count); } return result; } bool Zones::LoadLoadedSound(bool atStreamStart, char* buffer, int size) { if (Zones::Version() >= VERSION_ALPHA2) { size = 48; } bool result = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::Version() >= VERSION_ALPHA2) { std::memmove(buffer + 28, buffer + 32, 16); AssetHandler::Relocate(buffer + 32, buffer + 28, 16); } return result; } // Code-analysis has a bug, the first memcpy makes it believe size of tempVar is 400 instead of 788 #pragma warning(push) #pragma warning(disable: 6385) bool Zones::LoadVehicleDef(bool atStreamStart, char* buffer, int size) { if (Zones::Version() >= VERSION_ALPHA2) { size = 788; } bool result = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::Version() >= VERSION_ALPHA2) { char tempVar[788] = { 0 }; std::memcpy(&tempVar[0], &buffer[0], 400); std::memcpy(&tempVar[408], &buffer[400], 380); AssetHandler::Relocate(buffer + 400, buffer + 408, 388); std::memmove(buffer, tempVar, sizeof(tempVar)); } return result; } #pragma warning(pop) void Zones::LoadWeaponAttachStuff(DWORD* varWeaponAttachStuff, int count) { Game::Load_Stream(true, varWeaponAttachStuff, 12 * count); for (int i = 0; i < count; ++i) { if (varWeaponAttachStuff[1] < 16 || varWeaponAttachStuff[1] == 39) { if (varWeaponAttachStuff[2] == -1) { varWeaponAttachStuff[2] = reinterpret_cast(Game::DB_AllocStreamPos(0)); *Game::varConstChar = reinterpret_cast(varWeaponAttachStuff[2]); Game::Load_XStringCustom(Game::varConstChar); } } varWeaponAttachStuff += 3; } } bool Zones::LoadmenuDef_t(bool atStreamStart, char* buffer, int size) { if (Zones::ZoneVersion != 359 && Zones::ZoneVersion >= VERSION_ALPHA2) size += 4; bool result = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::ZoneVersion >= VERSION_ALPHA2) { std::memmove(buffer + 168, buffer + 172, (Zones::ZoneVersion != 359 ? 232 : 228)); AssetHandler::Relocate(buffer + 172, buffer + 168, (Zones::ZoneVersion != 359 ? 232 : 228)); reinterpret_cast(buffer)->expressionData = nullptr; } return result; } void Zones::LoadWeaponAttach() { if (Zones::ZoneVersion < VERSION_ALPHA2) { return Utils::Hook::Call(0x4F4160)(true); } // setup structures we use char* varWeaponAttach = *reinterpret_cast(0x112ADE0); // varAddonMapEnts // and do the stuff if (Zones::Version() >= 446) { Game::Load_Stream(true, varWeaponAttach, 20); Game::DB_PushStreamPos(3); *Game::varXString = reinterpret_cast(varWeaponAttach); Game::Load_XString(false); // load string array if (*reinterpret_cast(varWeaponAttach + 16) != nullptr) { if (*reinterpret_cast(varWeaponAttach + 16) == -1) { *reinterpret_cast(varWeaponAttach + 16) = Game::DB_AllocStreamPos(3); *Game::varXString = reinterpret_cast(varWeaponAttach + 16); Game::Load_XStringArray(true, *reinterpret_cast(varWeaponAttach + 12)); } else { Utils::Hook::Call(0x4A82B0)(reinterpret_cast(varWeaponAttach + 16)); } } Game::DB_PopStreamPos(); } else { Game::Load_Stream(true, varWeaponAttach, 12); Game::DB_PushStreamPos(3); *Game::varXString = reinterpret_cast(varWeaponAttach); Game::Load_XString(false); *reinterpret_cast(varWeaponAttach + 8) = Game::DB_AllocStreamPos(3); Zones::LoadWeaponAttachStuff(*reinterpret_cast(varWeaponAttach + 8), *reinterpret_cast(varWeaponAttach + 4)); Game::DB_PopStreamPos(); } } bool Zones::LoadMaterialShaderArgumentArray(bool atStreamStart, Game::MaterialShaderArgument* argument, int size) { // if (Zones::ZoneVersion >= 446 && currentAssetType == Game::XAssetType::ASSET_TYPE_FX) __debugbreak(); bool result = Game::Load_Stream(atStreamStart, argument, size); Game::MaterialPass* curPass = *Game::varMaterialPass; int count = curPass->perPrimArgCount + curPass->perObjArgCount + curPass->stableArgCount; for (int i = 0; i < count && (Zones::ZoneVersion >= VERSION_ALPHA2); ++i) { Game::MaterialShaderArgument* arg = &argument[i]; if (arg->type != Game::MaterialShaderArgumentType::MTL_ARG_CODE_VERTEX_CONST && arg->type != Game::MaterialShaderArgumentType::MTL_ARG_CODE_PIXEL_CONST) { continue; } if (Zones::Version() < 446) { // should be min 68 currently // >= 58 fixes foliage without bad side effects // >= 53 still has broken shadow mapping // >= 23 is still broken somehow if (arg->u.codeConst.index >= 58 && arg->u.codeConst.index <= 135) // >= 34 would be 31 in iw4 terms { arg->u.codeConst.index -= 3; if (Zones::Version() >= 359/* && arg->paramID <= 113*/) { arg->u.codeConst.index -= 7; if (arg->u.codeConst.index <= 53) { arg->u.codeConst.index += 1; } } } // >= 21 works fine for specular, but breaks trees // >= 4 is too low, breaks specular else if (arg->u.codeConst.index >= 11 && arg->u.codeConst.index < 58) { arg->u.codeConst.index -= 2; if (Zones::Version() >= 359) { if (arg->u.codeConst.index > 15 && arg->u.codeConst.index < 30) { arg->u.codeConst.index -= 1; if (arg->u.codeConst.index == 19) { arg->u.codeConst.index = 21; } } else if (arg->u.codeConst.index >= 50) { arg->u.codeConst.index += 6; } } } } else { if (arg->type == 3 || arg->type == 5) { // 446 is from a special client version that had lot of // unrelased/unfinished maps, is just enough for explore, // trees had issue with it if (Zones::Version() == 446) { static std::unordered_map mapped_constants = { { 33, 31 }, { 34, 32 }, { 36, 34 }, { 39, 37 }, { 40, 38 }, { 42, 40 }, { 43, 41 }, { 45, 43 }, { 62, 52 }, { 63, 53 }, { 199, 58 }, { 259, 86 }, { 263, 90 }, { 271, 98 }, { 279, 106 }, }; const auto itr = mapped_constants.find(arg->u.codeConst.index); if (itr != mapped_constants.end()) { arg->u.codeConst.index = itr->second; } } else if (Zones::Version() == 461) { static std::unordered_map mapped_constants = { // mp_raid { 33, 31 }, { 34, 32 }, { 36, 34 }, { 39, 37 }, { 40, 38 }, { 42, 40 }, { 43, 41 }, { 45, 43 }, { 62, 52 }, { 63, 53 }, { 197, 58 }, { 202, 63 }, { 203, 64 }, { 261, 90 }, { 265, 94 }, { 269, 98 }, { 277, 106 }, // mp_dome { 38, 36 }, { 40, 38 }, { 118, 86 }, }; const auto itr = mapped_constants.find(arg->u.codeConst.index); if (itr != mapped_constants.end()) { arg->u.codeConst.index = itr->second; } if (arg->u.codeConst.index == 257) { auto techsetName = (*reinterpret_cast(0x112AE8C))->name; // dont know if this applies to 460 too, but I dont have 460 files to test if (!strncmp(techsetName, "wc_unlit_add", 12) || !strncmp(techsetName, "wc_unlit_multiply", 17)) { // fixes glass and water arg->u.codeConst.index = 116; } else { // anything else arg->u.codeConst.index = 86; } } else { // copy-paste from 460 if (arg->u.codeConst.index >= 259) { arg->u.codeConst.index -= 171; } else if (arg->u.codeConst.index >= 197) { arg->u.codeConst.index -= 139; } } } else if (Zones::Version() == 460 /*|| Zones::Version() == 446*/) // 446 is no longer compatible, needs correct mappings { static std::unordered_map mapped_constants = { { 22, 21 }, { 33, 31 }, { 34, 32 }, { 36, 34 }, { 37, 35 }, { 38, 36 }, { 39, 37 }, { 40, 38 }, { 41, 39 }, { 42, 40 }, { 43, 41 }, { 44, 42 }, { 45, 43 }, { 62, 52 }, { 63, 53 }, // these might need fixes? { 197, 58 }, { 198, 59 }, { 202, 63 }, { 203, 64 }, { 207, 68 }, { 252, 81 }, { 253, 82 }, // these seem fine { 261, 90 }, { 265, 94 }, { 269, 98 }, { 272, 101 }, { 273, 102 }, { 274, 103 }, { 277, 106 }, }; const auto itr = mapped_constants.find(arg->u.codeConst.index); if (itr != mapped_constants.end()) { arg->u.codeConst.index = itr->second; } else { if (arg->u.codeConst.index == 257) { if (FastFiles::Current() != "mp_conflict" && FastFiles::Current() != "mp_derail_sh" && FastFiles::Current() != "mp_overwatch_sh" && FastFiles::Current() != "mp_con_spring" && FastFiles::Current() != "mp_resistance_sh" && FastFiles::Current() != "mp_lookout_sh") { const auto varMaterialTechniqueSet = *reinterpret_cast(0x112AE8C); if (varMaterialTechniqueSet->name && !strncmp(varMaterialTechniqueSet->name, "mc_", 3)) { // fixes trees arg->u.codeConst.index = 86; } else { // fixes black spots in the maps arg->u.codeConst.index = 128; } } //else /*{ arg->u.codeConst.index = 134; }*/ } else if (arg->u.codeConst.index >= 259) { arg->u.codeConst.index -= 171; } else if (arg->u.codeConst.index >= 197) { arg->u.codeConst.index -= 139; } } } } } } return result; } bool Zones::LoadStructuredDataStructPropertyArray(bool atStreamStart, char* data, int size) { int count = 0; if (Zones::ZoneVersion >= VERSION_ALPHA2) { size /= 16; count = size; size *= 24; } bool result = Game::Load_Stream(atStreamStart, data, size); if (Zones::ZoneVersion >= VERSION_ALPHA2) { for (int i = 0; i < count; ++i) { std::memmove(data + (i * 16), data + (i * 24), 16); AssetHandler::Relocate(data + (i * 24), data + (i * 16), 16); } } return result; } bool Zones::LoadGfxImage(bool atStreamStart, char* buffer, int size) { if (Zones::ZoneVersion >= 332) { size = (Zones::ZoneVersion >= 359) ? 52 : 36; } bool result = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::ZoneVersion >= 332) { AssetHandler::Relocate(buffer + (size - 4), buffer + 28, 4); if (Zones::Version() >= 359) { struct { Game::GfxImageLoadDef* texture; char mapType; Game::TextureSemantic semantic; char category; char flags; int cardMemory; char pad[8]; // ? int dataLen1; int dataLen2; char pad2[4]; // ? short width; short height; short depth; char loaded; char pad3[5]; Game::GfxImageLoadDef* storedTexture; char* name; } image359; AssertSize(image359, 52); // Copy to new struct std::memcpy(&image359, buffer, sizeof(image359)); // Convert to old struct Game::GfxImage* image = reinterpret_cast(buffer); image->mapType = image359.mapType; image->semantic = image359.semantic; image->category = image359.category; image->useSrgbReads = image359.flags; //image->cardMemory = image359.cardMemory; //image->dataLen1 = image359.dataLen1; //image->dataLen2 = image359.dataLen2; std::memcpy(image->picmip.platform, &image359.cardMemory, sizeof(int) * 3); image->height = image359.height; image->width = image359.width; image->depth = image359.depth; image->delayLoadPixels = image359.loaded; image->name = image359.name; FixImageCategory(image); // Used for later stuff (&image->delayLoadPixels)[1] = image359.pad3[1]; } else { std::memcpy(buffer + 28, buffer + (size - 4), 4); Game::GfxImage* image = reinterpret_cast(buffer); FixImageCategory(image); } } return result; } void Zones::FixImageCategory(Game::GfxImage* image) { // CODO makes use of additional enumerator values (9, 10, 11) that don't exist in IW4 // We have to translate them. 9 is for Reflection probes, 11 is for Compass, 10 is for Lightmap switch (image->category) { case 9: image->category = Game::ImageCategory::IMG_CATEGORY_AUTO_GENERATED; break; case 10: image->category = Game::ImageCategory::IMG_CATEGORY_LIGHTMAP; break; case 11: image->category = Game::ImageCategory::IMG_CATEGORY_LOAD_FROM_FILE; break; } if (image->category > 7 || image->category < 0) { #ifdef DEBUG if (IsDebuggerPresent()) __debugbreak(); #endif } } bool Zones::LoadXAsset(bool atStreamStart, char* buffer, int size) { int count = 0; if (Zones::ZoneVersion >= 334) { size /= 8; count = size; size *= 16; } bool result = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::ZoneVersion >= 334) { for (int i = 0; i < count; ++i) { std::memmove(buffer + (i * 8), buffer + (i * 16), 4); std::memmove(buffer + (i * 8) + 4, buffer + (i * 16) + 8, 4); if (Zones::Version() >= 423) { // don't read assets that are unused by codol, for some retarded reason their header is written in the FF anyway if (*reinterpret_cast(buffer + (i * 8)) == Game::XAssetType::ASSET_TYPE_CLIPMAP_SP || *reinterpret_cast(buffer + (i * 8)) == Game::XAssetType::ASSET_TYPE_GAMEWORLD_SP || *reinterpret_cast(buffer + (i * 8)) == Game::XAssetType::ASSET_TYPE_GAMEWORLD_MP) { *reinterpret_cast(buffer + (i * 8)) = Game::XAssetType::ASSET_TYPE_UI_MAP; *reinterpret_cast(buffer + (i * 8) + 4) = nullptr; } } AssetHandler::Relocate(buffer + (i * 16), buffer + (i * 8) + 0, 4); AssetHandler::Relocate(buffer + (i * 16) + 8, buffer + (i * 8) + 4, 4); } } return result; } bool Zones::LoadMaterialTechnique(bool atStreamStart, char* buffer, int size) { // 359 and above adds an extra remapped techset ptr if (Zones::ZoneVersion >= 359) size += 4; // 446 amd above adds an additional technique if (Zones::ZoneVersion >= 446) size += 4; bool result = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::ZoneVersion >= 359) { // This shouldn't make any difference. // The new entry is an additional remapped techset which is linked at runtime. // It's used when the 0x100 gameFlag in a material is set. // As MW2 flags are only 1 byte large, this won't be possible anyways int shiftTest = 4; std::memmove(buffer + 8 + shiftTest, buffer + 12 + shiftTest, (Zones::Version() >= 446) ? 200 : 196 - shiftTest); AssetHandler::Relocate(buffer + 12 + shiftTest, buffer + 8 + shiftTest, (Zones::Version() >= 446) ? 200 : 196 - shiftTest); } return result; } int Zones::LoadMaterialTechniqueArray(bool atStreamStart, int count) { if (Zones::Version() >= 446) { count += 1; } auto retval = Utils::Hook::Call(0x497020)(atStreamStart, count); if (Zones::Version() >= 446) { auto lastTechnique = **reinterpret_cast(0x112AEDC); auto varMaterialTechniqueSet = **reinterpret_cast(0x112B070); // patch last technique to match iw4 varMaterialTechniqueSet->techniques[47] = lastTechnique; } return retval; } bool Zones::LoadMaterial(bool atStreamStart, char* buffer, int size) { // if (Zones::ZoneVersion >= 446 && currentAssetType == Game::ASSET_TYPE_XMODEL) __debugbreak(); bool result = Game::Load_Stream(atStreamStart, buffer, (Zones::Version() >= 446) ? 104 : size); if (Zones::Version() >= 446) { char codol_material[104]; memcpy(codol_material, buffer, 104); // move material data std::memmove(buffer, codol_material + 0x10, 4); std::memmove(buffer + 0x11, codol_material + 0x14, 6); std::memmove(buffer + 4, codol_material + 0x1A, 1); std::memmove(buffer + 5, codol_material + 0x1C, 3); std::memmove(buffer + 8, codol_material, 16); std::memmove(buffer + 0x18, codol_material + 0x20, 0x30); std::memmove(buffer + 0x48, codol_material + 0x51, 5); std::memmove(buffer + 0x50, codol_material + 0x58, 0x10); std::memset(buffer + 0x48 + 5, 0, 3); // relocate pointers AssetHandler::Relocate(buffer + 10, buffer, 4); AssetHandler::Relocate(buffer + 0x1B, buffer + 4, 4); AssetHandler::Relocate(buffer, buffer + 8, 16); AssetHandler::Relocate(buffer + 0x20, buffer + 0x18, 0x30); AssetHandler::Relocate(buffer + 0x51, buffer + 0x48, 5); AssetHandler::Relocate(buffer + 0x58, buffer + 0x50, 0x10); // fix statebit reinterpret_cast(buffer)->stateBitsEntry[47] = codol_material[0x50]; } else if (Zones::ZoneVersion >= 359) { struct material339_s { char drawSurfBegin[8]; // 4 //int surfaceTypeBits; const char* name; char drawSurf[6]; union { char gameFlags; short sGameFlags; }; char sortKey; char textureAtlasRowCount; char textureAtlasColumnCount; } material359; static_assert(offsetof(material339_s, gameFlags) == 18, ""); static_assert(offsetof(material339_s, sortKey) == 20, ""); static_assert(offsetof(material339_s, textureAtlasColumnCount) == 22, ""); static_assert(offsetof(Game::Material, stateBitsEntry) == 24, ""); Game::Material* material = reinterpret_cast(buffer); memcpy(&material359, material, sizeof(material359)); material->info.name = material359.name; material->info.sortKey = material359.sortKey; material->info.textureAtlasRowCount = material359.textureAtlasRowCount; material->info.textureAtlasColumnCount = material359.textureAtlasColumnCount; material->info.gameFlags = material359.gameFlags; // Probably wrong material->info.surfaceTypeBits = 0;//material359.surfaceTypeBits; // Pretty sure that's wrong // Actually, it's not // yes it was lol memcpy(&material->info.drawSurf.packed, material359.drawSurfBegin, 8); memcpy(&material->info.surfaceTypeBits, &material359.drawSurf[0], 6); // copies both surfaceTypeBits and hashIndex //material->drawSurf[8] = material359.drawSurf[0]; //material->drawSurf[9] = material359.drawSurf[1]; //material->drawSurf[10] = material359.drawSurf[2]; //material->drawSurf[11] = material359.drawSurf[3]; } return result; } int gfxLightMapExtraCount = 0; int* gfxLightMapExtraPtr1 = nullptr; int* gfxLightMapExtraPtr2 = nullptr; bool Zones::LoadGfxWorld(bool atStreamStart, char* buffer, int size) { gfxLightMapExtraPtr1 = nullptr; gfxLightMapExtraPtr2 = nullptr; if (Zones::Version() >= 460) size += 984; else if (Zones::Version() >= 423) size += 980; else if (Zones::Version() >= 359) size += 968; bool result = Game::Load_Stream(atStreamStart, buffer, size); // fix 4 byte difference in FF ver 460+ this turns 460+ into 423 if (Zones::Version() >= 460) { std::memmove(buffer + 0x34, buffer + 0x38, size - 0x38); AssetHandler::Relocate(buffer + 0x38, buffer + 0x34, size - 0x38); } // fix 12 byte difference in FF ver 423+, this turns 423+ into 359 if (Zones::Version() >= 423) { // store extra pointers we just yeeted out of the structure gfxLightMapExtraCount = *reinterpret_cast(buffer + 0x50 + 0x10); gfxLightMapExtraPtr1 = *reinterpret_cast(buffer + 0x50 + 0x14); gfxLightMapExtraPtr2 = *reinterpret_cast(buffer + 0x50 + 0x18); // move gfxworld into 359 format std::memmove(buffer + 0x50 + 0x10, buffer + 0x50 + 0x1C, size - 0x6C); AssetHandler::Relocate(buffer + 0x50 + 0x1C, buffer + 0x50 + 0x10, size - 0x6C); } if (Zones::Version() >= 359) { int sunDiff = 8; // Stuff that is part of the sunflare we would overwrite std::memmove(buffer + 348 + sunDiff, buffer + 1316 + sunDiff, 280 - sunDiff); AssetHandler::Relocate(buffer + 1316, buffer + 348, 280); } return result; } void Zones::Loadsunflare_t(bool atStreamStart) { Game::Load_MaterialHandle(atStreamStart); if (Zones::ZoneVersion >= 359) { char* varsunflare_t = *reinterpret_cast(0x112A848); *Game::varMaterialHandle = reinterpret_cast(varsunflare_t + 12); Game::Load_MaterialHandle(atStreamStart); *Game::varMaterialHandle = reinterpret_cast(varsunflare_t + 16); Game::Load_MaterialHandle(atStreamStart); std::memmove(varsunflare_t + 12, varsunflare_t + 20, 84); // Copy the remaining struct data we couldn't copy in LoadGfxWorld char* varGfxWorld = *reinterpret_cast(0x112A7F4); std::memmove(varGfxWorld + 348, varGfxWorld + 1316, 8); } } bool Zones::LoadStatement(bool atStreamStart, char* buffer, int size) { if (Zones::Version() >= 359) size -= 4; bool result = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::Version() >= 359) { std::memmove(buffer + 12, buffer + 8, 12); } return result; } void Zones::LoadWindowImage(bool atStreamStart) { Game::Load_MaterialHandle(atStreamStart); if (Zones::Version() >= 360) { char** varGfxImagePtr = reinterpret_cast(0x112B4A0); char** varwindowDef_t = reinterpret_cast(0x112AF94); *varGfxImagePtr = *varwindowDef_t + 164; Game::Load_GfxImagePtr(atStreamStart); } } void Zones::LoadPhysPreset(bool atStreamStart, char* buffer, int size) { if (Zones::Version() >= VERSION_ALPHA2) { size = 68; } Game::Load_Stream(atStreamStart, buffer, size); } void Zones::LoadXModelSurfs(bool atStreamStart, char* buffer, int size) { if (Zones::Version() >= VERSION_ALPHA2) { size = 48; } Game::Load_Stream(atStreamStart, buffer, size); } void Zones::LoadImpactFx(bool atStreamStart, char* buffer, int size) { if (Zones::Version() >= 460) size = 0xB94; else if (Zones::Version() >= 446) size = 0xA64; else if (Zones::Version() >= VERSION_ALPHA2) size = 0x8C0; Game::Load_Stream(atStreamStart, buffer, size); if (Zones::Version() >= 460) { for (auto i = 0; i < Zones::ImpactFxArrayCount(); i++) { std::memmove(buffer + (i * 140), buffer + (i * 156), 140); AssetHandler::Relocate(buffer + (i * 156), buffer + (i * 140), 140); } } } int Zones::ImpactFxArrayCount() { if (Zones::Version() >= 446) { return 19; } if (Zones::Version() >= VERSION_ALPHA2) { return 16; } return 15; } __declspec(naked) void Zones::LoadImpactFxArray() { __asm { push edi pushad push edi call Zones::ImpactFxArrayCount pop edi mov [esp + 20h], eax popad pop edi push 4447E0h retn } } void Zones::LoadPathNodeArray(bool atStreamStart, char* buffer, int size) { if (Zones::Version() >= VERSION_ALPHA2) { size /= 136; size *= 148; } Game::Load_Stream(atStreamStart, buffer, size); } void Zones::LoadPathnodeConstantTail(bool atStreamStart, char* buffer, int size) { if (Zones::Version() >= VERSION_ALPHA2) { size /= 12; size *= 16; } Game::Load_Stream(atStreamStart, buffer, size); } void Zones::LoadExpressionSupportingDataPtr(bool atStreamStart) { if (Zones::Version() < 359) { Utils::Hook::Call(0x4AF680)(atStreamStart); } } void Zones::SetVersion(int version) { AssetHandler::ClearRelocations(); Zones::ZoneVersion = version; } __declspec(noinline) bool Zones::CheckGameMapSp(int type) { if (type == Game::XAssetType::ASSET_TYPE_GAMEWORLD_SP) { return true; } if (Zones::Version() >= VERSION_ALPHA2 && Zones::Version() < 423 && type == Game::XAssetType::ASSET_TYPE_GAMEWORLD_MP) { Maps::HandleAsSPMap(); return true; } return false; } __declspec(naked) void Zones::GameMapSpPatchStub() { __asm { pushad push eax call Zones::CheckGameMapSp add esp, 4h test al, al jnz returnSafe popad push 4189AEh retn returnSafe: popad push 41899Dh retn } } int Zones::PathDataSize() { if (Zones::Version() >= VERSION_ALPHA2) { return 148; } return 136; } __declspec(naked) void Zones::LoadPathDataConstant() { __asm { push esi pushad call Zones::PathDataSize add [esp + 20h], eax popad pop esi push 4D6A4Dh retn } } __declspec(naked) void Zones::GetCurrentAssetTypeStub() { __asm pushad; previousAssetType = currentAssetType; __asm popad; __asm { // get asset type mov eax, ds:0x112aa54 mov eax, [eax]; // log asset type // mov previousAssetType, currentAssetType; mov currentAssetType, eax; // go back push 0x418847; retn; } } int Zones::LoadRandomFxGarbage(bool atStreamStart, char* buffer, int size) { int count = 0; if (Zones::Version() >= 446) { size /= 48; count = size; size *= 64; } const auto retval = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::Version() >= 446) { for (auto i = 0; i < count; i++) { std::memcpy(buffer + (48 * i) + 0, buffer + (64 * i) + 0, 24); std::memcpy(buffer + (48 * i) + 24, buffer + (64 * i) + 32, 24); AssetHandler::Relocate(buffer + (64 * i) + 0, buffer + (48 * i) + 0, 24); AssetHandler::Relocate(buffer + (64 * i) + 32, buffer + (48 * i) + 24, 24); } } return retval; } int currentGfxSurfaceIndex = 0; std::vector> gfxSurfaceExtraData; int Zones::LoadGfxXSurfaceArray(bool atStreamStart, char* buffer, int size) { currentGfxSurfaceIndex = 0; gfxSurfaceExtraData.clear(); int count = 0; if (Zones::Version() >= 423) { size /= 40; count = size; size *= 48; } const auto retval = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::Version() >= 423) { // fix structure for (auto i = 0; i < count; i++) { auto read_count = *reinterpret_cast(buffer + (48 * i) + 40); auto read_ptr = *reinterpret_cast(buffer + (48 * i) + 44); // extra data stuff we need to load gfxSurfaceExtraData.push_back({ read_count, read_ptr }); // fix structure std::memmove(buffer + (40 * i), buffer + (48 * i), 40); AssetHandler::Relocate(buffer + (48 * i), buffer + (40 * i), 40); } } return retval; } int Zones::LoadGfxXSurfaceExtraData(bool atStreamStart) { const auto retval = Utils::Hook::Call(0x4516B0)(atStreamStart); if (Zones::Version() >= 423) { const auto currentData = &gfxSurfaceExtraData[currentGfxSurfaceIndex]; if (currentData->second) { currentData->second = reinterpret_cast(Game::DB_AllocStreamPos(0)); Game::Load_Stream(true, currentData->second, currentData->first); } currentGfxSurfaceIndex++; } return retval; } int Zones::LoadGfxReflectionProbes(bool atStreamStart, char* buffer, int size) { int count = 0; if (Zones::Version() >= 446) { size /= 12; count = size; size *= 20; } auto retval = Game::Load_Stream(atStreamStart, buffer, size); if (Zones::Version() >= 446) { for (int i = 0; i < count; i++) { auto garbage = *reinterpret_cast(buffer + (20 * i) + 12); auto garbage_count = *reinterpret_cast(buffer + (20 * i) + 16); if (garbage != nullptr) { garbage = Game::DB_AllocStreamPos(3); Game::Load_Stream(true, garbage, 8 * garbage_count); for (int j = 0; j < garbage_count; j++) { auto garbage_2 = *reinterpret_cast(garbage + (8 * j) + 0); auto garbage_2_count = *reinterpret_cast(garbage + (8 * j) + 4); if (garbage_2) { garbage_2 = Game::DB_AllocStreamPos(1); Game::Load_Stream(true, garbage_2, 2 * garbage_2_count); } } } std::memmove(buffer + (12 * i), buffer + (20 * i), 12); AssetHandler::Relocate(buffer + (20 * i), buffer + (12 * i), 12); } } return retval; } void Zones::LoadGfxLightMapExtraData() { Game::DB_PopStreamPos(); if (Zones::Version() >= 423) { if (gfxLightMapExtraPtr1) { gfxLightMapExtraPtr1 = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, gfxLightMapExtraPtr1, 12 * gfxLightMapExtraCount); } if (gfxLightMapExtraPtr2) { gfxLightMapExtraPtr2 = reinterpret_cast(Game::DB_AllocStreamPos(0)); Game::Load_Stream(true, gfxLightMapExtraPtr2, gfxLightMapExtraCount); } } } __declspec(naked) void Zones::LoadXModelColSurfPtr() { static auto DB_ConvertOffsetToPointer_Address = 0x4A82B0; __asm { cmp dword ptr[eax], 0; je dontLoadAssetData; cmp dword ptr[eax], 0xFFFFFFFF; je loadAssetData; // check if FF is below 446, still load data in that case cmp Zones::ZoneVersion, 446; jl loadAssetData; // offset to pointer magic pushad; push eax; call DB_ConvertOffsetToPointer_Address; add esp, 4; popad; dontLoadAssetData: push 0x4C870E; retn; loadAssetData: push 0x4C86DD; retn; } } struct ClipInfo { int numCPlanes; Game::cplane_s* cPlanes; int numMaterials; Game::ClipMaterial* materials; int numCBrushSides; Game::cbrushside_t* cBrushSides; int numCBrushEdges; char* cBrushEdges; int numCLeafBrushNodes; Game::cLeafBrushNode_s* cLeafBrushNodes; // cmodels use this? int numLeafBrushes; short* leafBrushes; unsigned short numBrushes; Game::cbrush_t* brushes; Game::Bounds* brushBounds; int* brushContents; }; struct codolCmodel_t { Game::Bounds bounds; float radius; ClipInfo* infoPtr; Game::cLeaf_t leaf; }; struct codolClipMap_t { char* name; bool isInUse; char pad1[3]; ClipInfo info; ClipInfo* pInfo; int numStaticModels; Game::cStaticModel_s* staticModelList; int numCNodes; Game::cNode_t* cNodes; int numCLeaf; Game::cLeaf_t* cLeaf; int numVerts; float(*verts)[3]; int numTriIndices; short* triIndices; char* triEdgeIsWalkable; //Size = ((triCount << 1) + triCount + 0x1F) >> 3 << 2 int numCollisionBorders; Game::CollisionBorder* collisionBorders; int numCollisionPartitions; Game::CollisionPartition* collisionPartitions; int numCollisionAABBTrees; Game::CollisionAabbTree* collisionAABBTrees; int numCModels; codolCmodel_t* cModels; Game::MapEnts* mapEnts; Game::Stage* stages; unsigned char stageCount; char pad2[3]; Game::MapTriggers trigger; short smodelNodeCount; Game::SModelAabbNode* smodelNodes; unsigned short dynEntCount[2]; Game::DynEntityDef* dynEntDefList[2]; Game::DynEntityPose* dynEntPoseList[2]; Game::DynEntityClient* dynEntClientList[2]; Game::DynEntityColl* dynEntCollList[2]; char pad3[20]; std::uint32_t isPlutoniumMap; }; static Game::MapEnts codolMapEnts; static Game::MapEnts* codolMapEntsPtr; int Zones::LoadMapEnts(bool atStreamStart, Game::MapEnts* buffer, int size) { if (Zones::Version() >= 446) { size /= 44; size *= 36; memset(&codolMapEnts, 0, sizeof Game::MapEnts); buffer = &codolMapEnts; codolMapEntsPtr = &codolMapEnts; *reinterpret_cast(0x112B3E8) = &codolMapEnts; // varMapEnts *reinterpret_cast(0x112B388) = &codolMapEntsPtr; // varMapEntsPtr AssetHandler::Relocate(&codolMapEnts, buffer, size); } return Game::Load_Stream(atStreamStart, buffer, size); } ClipInfo* varClipInfoPtr; void Zones::Load_ClipInfo(bool atStreamStart) { AssertSize(ClipInfo, 64); AssertSize(Game::cplane_s, 20); AssertSize(Game::Bounds, 24); Game::Load_Stream(atStreamStart, varClipInfoPtr, sizeof ClipInfo); if (varClipInfoPtr->cPlanes) { if (varClipInfoPtr->cPlanes == reinterpret_cast(0xFFFFFFFF)) { varClipInfoPtr->cPlanes = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, varClipInfoPtr->cPlanes, varClipInfoPtr->numCPlanes * sizeof(Game::cplane_s)); } else { Game::DB_ConvertOffsetToPointer(&varClipInfoPtr->cPlanes); } } if (varClipInfoPtr->materials) { if (varClipInfoPtr->materials == reinterpret_cast(0xFFFFFFFF)) { varClipInfoPtr->materials = reinterpret_cast(Game::DB_AllocStreamPos(3)); *reinterpret_cast(0x112A958) = varClipInfoPtr->materials; Utils::Hook::Call(0x4895F0)(true, varClipInfoPtr->numMaterials); } else { Game::DB_ConvertOffsetToPointer(&varClipInfoPtr->materials); } } if (varClipInfoPtr->cBrushSides) { if (varClipInfoPtr->cBrushSides == reinterpret_cast(0xFFFFFFFF)) { varClipInfoPtr->cBrushSides = reinterpret_cast(Game::DB_AllocStreamPos(3)); *reinterpret_cast(0x112B33C) = varClipInfoPtr->cBrushSides; Utils::Hook::Call(0x420790)(true, varClipInfoPtr->numCBrushSides); } else { Game::DB_ConvertOffsetToPointer(&varClipInfoPtr->cBrushSides); } } if (varClipInfoPtr->cBrushEdges) { if (varClipInfoPtr->cBrushEdges == reinterpret_cast(0xFFFFFFFF)) { varClipInfoPtr->cBrushEdges = reinterpret_cast(Game::DB_AllocStreamPos(0)); Game::Load_Stream(true, varClipInfoPtr->cBrushEdges, varClipInfoPtr->numCBrushEdges); } else { Game::DB_ConvertOffsetToPointer(&varClipInfoPtr->cBrushEdges); } } if (varClipInfoPtr->cLeafBrushNodes) { if (varClipInfoPtr->cLeafBrushNodes == reinterpret_cast(0xFFFFFFFF)) { varClipInfoPtr->cLeafBrushNodes = reinterpret_cast(Game::DB_AllocStreamPos(3)); *reinterpret_cast(0x112B130) = varClipInfoPtr->cLeafBrushNodes; Utils::Hook::Call(0x4C29D0)(true, varClipInfoPtr->numCLeafBrushNodes); } else { Game::DB_ConvertOffsetToPointer(&varClipInfoPtr->cLeafBrushNodes); } } if (varClipInfoPtr->leafBrushes) { if (varClipInfoPtr->leafBrushes == reinterpret_cast(0xFFFFFFFF)) { varClipInfoPtr->leafBrushes = reinterpret_cast(Game::DB_AllocStreamPos(1)); Game::Load_Stream(true, varClipInfoPtr->leafBrushes, varClipInfoPtr->numLeafBrushes * sizeof(short)); } else { Game::DB_ConvertOffsetToPointer(&varClipInfoPtr->leafBrushes); } } AssertOffset(ClipInfo, numBrushes, 48); AssertOffset(ClipInfo, brushes, 52); AssertSize(Game::cbrush_t, 36); if (varClipInfoPtr->brushes) { if (varClipInfoPtr->brushes == reinterpret_cast(0xFFFFFFFF)) { varClipInfoPtr->brushes = reinterpret_cast(Game::DB_AllocStreamPos(127)); *reinterpret_cast(0x112B2B8) = varClipInfoPtr->brushes; Utils::Hook::Call(0x4B4160)(true, varClipInfoPtr->numBrushes); } else { Game::DB_ConvertOffsetToPointer(&varClipInfoPtr->brushes); } } AssertOffset(ClipInfo, brushBounds, 56); if (varClipInfoPtr->brushBounds) { if (varClipInfoPtr->brushBounds == reinterpret_cast(0xFFFFFFFF)) { varClipInfoPtr->brushBounds = reinterpret_cast(Game::DB_AllocStreamPos(127)); Game::Load_Stream(true, varClipInfoPtr->brushBounds, varClipInfoPtr->numBrushes * sizeof(Game::Bounds)); } else { Game::DB_ConvertOffsetToPointer(&varClipInfoPtr->brushBounds); } } AssertOffset(ClipInfo, brushContents, 60); if (varClipInfoPtr->brushContents) { if (varClipInfoPtr->brushContents == reinterpret_cast(0xFFFFFFFF)) { varClipInfoPtr->brushContents = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, varClipInfoPtr->brushContents, 4 * varClipInfoPtr->numBrushes); } else { Game::DB_ConvertOffsetToPointer(&varClipInfoPtr->brushContents); } } } int Zones::LoadClipMap(bool atStreamStart) { if (Zones::Version() >= 446) { AssertOffset(codolClipMap_t, pInfo, 72); AssertSize(Game::cStaticModel_s, 76); AssertOffset(codolClipMap_t, numStaticModels, 76); AssertOffset(codolClipMap_t, staticModelList, 80); auto varClipMap = *reinterpret_cast(0x112A758); Game::Load_Stream(atStreamStart, varClipMap, 256); Game::DB_PushStreamPos(3); *Game::varXString = &varClipMap->name; Game::Load_XString(false); varClipInfoPtr = &varClipMap->info; Load_ClipInfo(false); Game::DB_PushStreamPos(0); varClipInfoPtr = varClipMap->pInfo; ClipInfo** assetPointer = nullptr; if (varClipMap->pInfo) { if (varClipMap->pInfo == reinterpret_cast(0xFFFFFFFF) || varClipMap->pInfo == reinterpret_cast(0xFFFFFFFE)) { const auto needsToAllocPointer = varClipMap->pInfo == reinterpret_cast(0xFFFFFFFE); varClipMap->pInfo = reinterpret_cast(Game::DB_AllocStreamPos(3)); if (needsToAllocPointer) // 0xFFFFFFFE { assetPointer = Game::DB_InsertPointer(); } varClipInfoPtr = varClipMap->pInfo; Load_ClipInfo(true); // varClipMap->pInfo = &varClipMap->info; if (assetPointer) { *assetPointer = varClipMap->pInfo; } } } Game::DB_PopStreamPos(); if (varClipMap->staticModelList) { varClipMap->staticModelList = reinterpret_cast(Game::DB_AllocStreamPos(3)); *reinterpret_cast(0x112B0E4) = varClipMap->staticModelList; Utils::Hook::Call(0x4B7440)(true, varClipMap->numStaticModels); } if (varClipMap->cNodes) { varClipMap->cNodes = reinterpret_cast(Game::DB_AllocStreamPos(3)); *reinterpret_cast(0x112B1D0) = varClipMap->cNodes; Utils::Hook::Call(0x4E65A0)(true, varClipMap->numCNodes); } if (varClipMap->cLeaf) { varClipMap->cLeaf = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, varClipMap->cLeaf, sizeof(Game::cLeaf_t) * varClipMap->numCLeaf); } if (varClipMap->verts) { varClipMap->verts = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, varClipMap->verts, 12 * varClipMap->numVerts); } if (varClipMap->triIndices) { varClipMap->triIndices = reinterpret_cast(Game::DB_AllocStreamPos(1)); Game::Load_Stream(true, varClipMap->triIndices, sizeof(short) * varClipMap->numTriIndices * 3); } if (varClipMap->triEdgeIsWalkable) { varClipMap->triEdgeIsWalkable = static_cast(Game::DB_AllocStreamPos(0)); #pragma warning(push) #pragma warning(disable: 4554) Game::Load_Stream(true, varClipMap->triEdgeIsWalkable, 0x1F + varClipMap->numTriIndices * 3 >> 3 & 0xFFFFFFFC); #pragma warning(pop) } if (varClipMap->collisionBorders) { varClipMap->collisionBorders = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, varClipMap->collisionBorders, varClipMap->numCollisionBorders * sizeof(Game::CollisionBorder)); } if (varClipMap->collisionPartitions) { varClipMap->collisionPartitions = reinterpret_cast(Game::DB_AllocStreamPos(3)); *reinterpret_cast(0x112AA38) = varClipMap->collisionPartitions; Utils::Hook::Call(0x444AF0)(true, varClipMap->numCollisionPartitions); } AssertSize(Game::CollisionAabbTree, 32); if (varClipMap->collisionAABBTrees) { varClipMap->collisionAABBTrees = reinterpret_cast(Game::DB_AllocStreamPos(15)); Game::Load_Stream(true, varClipMap->collisionAABBTrees, varClipMap->numCollisionAABBTrees * sizeof(Game::CollisionAabbTree)); } AssertSize(Game::cmodel_t, 68); AssertSize(codolCmodel_t, 72); AssertOffset(codolCmodel_t, infoPtr, 28); if (varClipMap->cModels) { varClipMap->cModels = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, varClipMap->cModels, sizeof(codolCmodel_t) * varClipMap->numCModels); // read garbage iw5 data we don't need in iw4 for (auto i = 0; i < varClipMap->numCModels; i++) { Game::DB_PushStreamPos(0); varClipInfoPtr = varClipMap->cModels[i].infoPtr; if (varClipInfoPtr) { if (varClipInfoPtr == reinterpret_cast(0xFFFFFFFF) || varClipInfoPtr == reinterpret_cast(0xFFFFFFFE)) { const auto needsToAllocPointer = varClipMap->pInfo == reinterpret_cast(0xFFFFFFFE); ClipInfo** info = nullptr; varClipInfoPtr = reinterpret_cast(Game::DB_AllocStreamPos(3)); if (needsToAllocPointer) // 0xFFFFFFFE { info = Game::DB_InsertPointer(); } Load_ClipInfo(true); if (info) { *info = varClipInfoPtr; } } } Game::DB_PopStreamPos(); } // fix cmodels std::vector iw4Models; iw4Models.resize(varClipMap->numCModels); for (int i = 0; i < varClipMap->numCModels; i++) { std::memcpy(&iw4Models[i], &varClipMap->cModels[i], 28); std::memcpy(&iw4Models[i].leaf, &varClipMap->cModels[i].leaf, 40); } std::memcpy(varClipMap->cModels, iw4Models.data(), iw4Models.size() * sizeof Game::cmodel_t); } if (varClipMap->smodelNodes) { varClipMap->smodelNodes = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, varClipMap->smodelNodes, varClipMap->smodelNodeCount * sizeof(Game::SModelAabbNode)); } // load mapents *reinterpret_cast(0x112B388) = &varClipMap->mapEnts; Utils::Hook::Call(0x5B9E10)(false); // load stages if (varClipMap->stages) { varClipMap->stages = (Game::Stage*)Game::DB_AllocStreamPos(3); *reinterpret_cast(0x112A818) = varClipMap->stages; Utils::Hook::Call(0x4AC760)(true, varClipMap->stageCount); // IW4 expects stages in mapents instaed of clipmap codolMapEnts.stageCount = varClipMap->stageCount; codolMapEnts.stages = varClipMap->stages; } // load map triggers *reinterpret_cast(0x112AB3C) = &varClipMap->trigger; Utils::Hook::Call(0x43CBA0)(false); AssertOffset(codolClipMap_t, dynEntCount[0], 196); AssertOffset(codolClipMap_t, dynEntCount[1], 198); // dynamic entity shit for (int i = 0; i < 2; i++) { if (varClipMap->dynEntDefList[i]) { varClipMap->dynEntDefList[i] = reinterpret_cast(Game::DB_AllocStreamPos(3)); *reinterpret_cast(0x112AF3C) = varClipMap->dynEntDefList[i]; Utils::Hook::Call(0x47CE10)(true, varClipMap->dynEntCount[i]); } } Game::DB_PushStreamPos(2); for (int i = 0; i < 2; i++) { if (varClipMap->dynEntPoseList[i]) { varClipMap->dynEntPoseList[i] = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, varClipMap->dynEntPoseList[i], varClipMap->dynEntCount[i] * sizeof(Game::DynEntityPose)); } } for (int i = 0; i < 2; i++) { if (varClipMap->dynEntClientList[i]) { varClipMap->dynEntClientList[i] = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, varClipMap->dynEntClientList[i], varClipMap->dynEntCount[i] * sizeof(Game::DynEntityClient)); } } for (int i = 0; i < 2; i++) { if (varClipMap->dynEntCollList[i]) { varClipMap->dynEntCollList[i] = reinterpret_cast(Game::DB_AllocStreamPos(3)); Game::Load_Stream(true, varClipMap->dynEntCollList[i], varClipMap->dynEntCount[i] * sizeof(Game::DynEntityColl)); } } Game::DB_PopStreamPos(); Game::DB_PopStreamPos(); auto codolMap = new codolClipMap_t; memcpy(codolMap, varClipMap, sizeof codolClipMap_t); auto cancerMap = reinterpret_cast(varClipMap); auto iw4Map = reinterpret_cast(varClipMap); memcpy(&iw4Map->planeCount, &codolMap->info.numCPlanes, 8); memcpy(&iw4Map->numStaticModels, &codolMap->numStaticModels, 8); memcpy(&iw4Map->numMaterials, &codolMap->info.numMaterials, 24); memcpy(&iw4Map->numNodes, &codolMap->numCNodes, 16); memcpy(&iw4Map->leafbrushNodesCount, &codolMap->info.numCLeafBrushNodes, 16); memcpy(&iw4Map->vertCount, &codolMap->numVerts, 52); memcpy(&iw4Map->numBrushes, &codolMap->info.numBrushes, 16); iw4Map->mapEnts = &codolMapEnts; memcpy(&iw4Map->smodelNodeCount, &codolMap->smodelNodeCount, 48); // unused on IW4 iw4Map->numLeafSurfaces = 0; AssetHandler::Relocate(&cancerMap->info.numCPlanes, &iw4Map->planeCount, 8); AssetHandler::Relocate(&cancerMap->numStaticModels, &iw4Map->numStaticModels, 8); AssetHandler::Relocate(&cancerMap->info.numMaterials, &iw4Map->numMaterials, 24); AssetHandler::Relocate(&cancerMap->numCNodes, &iw4Map->numNodes, 16); AssetHandler::Relocate(&cancerMap->info.numCLeafBrushNodes, &iw4Map->leafbrushNodesCount, 16); AssetHandler::Relocate(&cancerMap->numVerts, &iw4Map->vertCount, 52); AssetHandler::Relocate(&cancerMap->info.numBrushes, &iw4Map->numBrushes, 16); AssetHandler::Relocate(&cancerMap->smodelNodeCount, &iw4Map->smodelNodeCount, 48); delete codolMap; return 1; } else { return Utils::Hook::Call(0x46C390)(atStreamStart); } } __declspec(naked) void Zones::LoadMapTriggersModelPointer() { static auto DB_ConvertOffsetToPointer_Address = 0x4A82B0; __asm { cmp dword ptr[edx + 4], 0; je dontLoadAssetData; cmp dword ptr[edx + 4], 0xFFFFFFFF; je loadAssetData; // check if FF is below 446, still load data in that case cmp Zones::ZoneVersion, 446; jl loadAssetData; // offset to pointer magic pushad; push eax; call DB_ConvertOffsetToPointer_Address; add esp, 4; popad; dontLoadAssetData: push 0x43CBF3; retn; loadAssetData: push 0x43CBC1; retn; } } __declspec(naked) void Zones::LoadMapTriggersHullPointer() { static auto DB_ConvertOffsetToPointer_Address = 0x4A82B0; __asm { cmp dword ptr[eax + 0Ch], 0; je dontLoadAssetData; cmp dword ptr[eax + 0Ch], 0xFFFFFFFF; je loadAssetData; // check if FF is below 446, still load data in that case cmp Zones::ZoneVersion, 446; jl loadAssetData; // offset to pointer magic pushad; push eax; call DB_ConvertOffsetToPointer_Address; add esp, 4; popad; dontLoadAssetData: push 0x43CC2E; retn; loadAssetData: push 0x43CBFE; retn; } } __declspec(naked) void Zones::LoadMapTriggersSlabPointer() { static auto DB_ConvertOffsetToPointer_Address = 0x4A82B0; __asm { cmp dword ptr[eax + 14h], 0; je dontLoadAssetData; cmp dword ptr[eax + 14h], 0xFFFFFFFF; je loadAssetData; // check if FF is below 446, still load data in that case cmp Zones::ZoneVersion, 446; jl loadAssetData; // offset to pointer magic pushad; push eax; call DB_ConvertOffsetToPointer_Address; add esp, 4; popad; dontLoadAssetData: push 0x43CC6D; retn; loadAssetData: push 0x43CC39; retn; } } void Zones::LoadFxWorldAsset(Game::FxWorld** asset) { Utils::Hook::Call(0x4857F0)(asset); if (Zones::Version() >= 423 && asset && *asset) { // allocate glass data structures static Game::GameWorldMp glassMap; static Game::GameWorldMp* glassMapPtr; static Game::G_GlassData glassData; static std::vector glassPieces; // clear previous glass data memset(&glassMap, 0, sizeof Game::GameWorldMp); memset(&glassData, 0, sizeof Game::G_GlassData); glassPieces.clear(); // generate glassPieces array const auto pieceCount = (*asset)->glassSys.initPieceCount; if (pieceCount > 0) { glassPieces.resize(pieceCount); memset(&glassPieces[0], 0, sizeof(Game::G_GlassPiece) * pieceCount); // generate glassData array glassData.glassPieces = glassPieces.data(); glassData.pieceCount = glassPieces.size(); } else { // game seems to do an array lookup on the first index even if there's no glass pieces? static Game::G_GlassPiece emptyPiece; glassData.glassPieces = &emptyPiece; } // build glass asset glassMap.g_glassData = &glassData; glassMap.name = (*asset)->name; // set glass map ptr glassMapPtr = &glassMap; // add glass to DB Utils::Hook::Call(0x4A6240)(&glassMapPtr); } } void Zones::LoadXModelAsset(Game::XModel** asset) { if (Zones::Version() >= 446) { for (int i = 0; i < (*asset)->numLods; i++) { if ((*asset)->lodInfo[i].surfs == nullptr && Zones::Version() >= 446) { const auto name = (*asset)->name; const auto fx_model = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_XMODEL, "void").model; memcpy(*asset, fx_model, sizeof Game::XModel); (*asset)->name = name; break; } } } return Utils::Hook::Call(0x47A690)(asset); } // patch max file amount returned by Sys_ListFiles constexpr auto fileCountMultiplier = 8; constexpr auto maxFileCount = 8191 * fileCountMultiplier; Game::HunkUser* Hunk_UserCreate_Stub(int maxSize, const char* name, bool fixed, int type) { maxSize *= fileCountMultiplier; return Utils::Hook::Call(0x430E90)(maxSize, name, fixed, type); } void Zones::LoadMaterialAsset(Game::Material** asset) { if (asset && *asset && Zones::Version() >= 446) { static std::vector broken_materials = { "gfx_fxt_debris_wind_ash_z10", "gfx_fxt_smk_light_z3" }; // replace broken materials with the default one as restricting them does not seem to work. const auto itr = std::find(broken_materials.begin(), broken_materials.end(), (*asset)->info.name); if (itr != broken_materials.end()) { const auto name = (*asset)->info.name; const auto default_material = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, "$default").material; memcpy(*asset, default_material, sizeof Game::Material); (*asset)->info.name = name; } } return Utils::Hook::Call(0x476750)(asset); } void Zones::LoadTracerDef(bool atStreamStart, Game::TracerDef* tracer, int size) { if (Zones::Version() >= 460) { size = 116; } Game::Load_Stream(atStreamStart, tracer, size); *Game::varFxEffectDefHandle = nullptr; if (Zones::Version() >= 460) { *Game::varFxEffectDefHandle = reinterpret_cast(tracer + 8); std::memmove(tracer + 8, tracer + 12, size - 12); AssetHandler::Relocate(tracer + 12, tracer + 8, size - 12); } } void Zones::LoadTracerDefFxEffect() { if (Zones::Version() >= 460) { Game::Load_FxEffectDefHandle(false); } Game::DB_PopStreamPos(); } char* Zones::ParseShellShock_Stub(const char** data_p) { auto token = Game::Com_Parse(data_p); if (shellshock_replace_list.find(token) != shellshock_replace_list.end()) { return shellshock_replace_list[token].data(); } return token; } Zones::Zones() { Zones::ZoneVersion = 0; // patch max filecount Sys_ListFiles can return Utils::Hook::Set(0x45A66B, (maxFileCount + fileCountMultiplier) * 4); Utils::Hook::Set(0x64AF78, maxFileCount); Utils::Hook::Set(0x64B04F, maxFileCount); Utils::Hook::Set(0x45A8CE, maxFileCount); Utils::Hook(0x45A806, Hunk_UserCreate_Stub, HOOK_CALL).install()->quick(); Utils::Hook(0x45A6A0, Hunk_UserCreate_Stub, HOOK_CALL).install()->quick(); #ifndef DEBUG // Ignore missing soundaliases for now // TODO: Include them in the dependency zone! Utils::Hook::Nop(0x644207, 5); #endif // Block Mark_pathnode_constant_t Utils::Hook::Set(0x4F74B0, 0xC3); // addon_map_ents asset type (we reuse it for weaponattach) Utils::Hook::Set(0x418B31, 0x72); // asset hooks Utils::Hook(0x47146D, Zones::LoadTracerDef, HOOK_CALL).install()->quick(); Utils::Hook(0x4714A3, Zones::LoadTracerDefFxEffect, HOOK_JUMP).install()->quick(); Utils::Hook(0x4039DE, Zones::LoadMaterialAsset, HOOK_CALL).install()->quick(); Utils::Hook(0x4FCAEE, Zones::LoadXModelAsset, HOOK_CALL).install()->quick(); Utils::Hook(0x5BA01E, Zones::LoadFxWorldAsset, HOOK_CALL).install()->quick(); Utils::Hook(0x43CBBB, Zones::LoadMapTriggersModelPointer, HOOK_JUMP).install()->quick(); Utils::Hook(0x43CBF8, Zones::LoadMapTriggersHullPointer, HOOK_JUMP).install()->quick(); Utils::Hook(0x43CC33, Zones::LoadMapTriggersSlabPointer, HOOK_JUMP).install()->quick(); Utils::Hook(0x47E1DD, Zones::LoadMapEnts, HOOK_CALL).install()->quick(); Utils::Hook(0x4BF992, Zones::LoadClipMap, HOOK_CALL).install()->quick(); Utils::Hook(0x4C86D8, Zones::LoadXModelColSurfPtr, HOOK_JUMP).install()->quick(); Utils::Hook(0x44EB21, Zones::LoadGfxLightMapExtraData, HOOK_CALL).install()->quick(); Utils::Hook(0x44EAD3, Zones::LoadGfxReflectionProbes, HOOK_CALL).install()->quick(); Utils::Hook(0x4C08F8, Zones::LoadGfxXSurfaceExtraData, HOOK_CALL).install()->quick(); Utils::Hook(0x4C08DC, Zones::LoadGfxXSurfaceArray, HOOK_CALL).install()->quick(); Utils::Hook(0x45AE3D, Zones::LoadRandomFxGarbage, HOOK_CALL).install()->quick(); Utils::Hook(0x495938, Zones::LoadFxElemDefArrayStub, HOOK_CALL).install()->quick(); Utils::Hook(0x45ADA0, Zones::LoadFxElemDefStub, HOOK_CALL).install()->quick(); Utils::Hook(0x4EA6FE, Zones::LoadXModelLodInfoStub, HOOK_JUMP).install()->quick(); Utils::Hook(0x410D90, Zones::LoadXModel, HOOK_CALL).install()->quick(); Utils::Hook(0x4925C8, Zones::LoadXSurfaceArray, HOOK_CALL).install()->quick(); Utils::Hook(0x4F4D0D, Zones::LoadGameWorldSp, HOOK_CALL).install()->quick(); Utils::Hook(0x47CCD2, Zones::LoadWeaponCompleteDef, HOOK_CALL).install()->quick(); Utils::Hook(0x483DA0, Zones::LoadVehicleDef, HOOK_CALL).install()->quick(); Utils::Hook(0x4F0AC8, Zones::Loadsnd_alias_tArray, HOOK_CALL).install()->quick(); Utils::Hook(0x403A5D, Zones::LoadLoadedSound, HOOK_CALL).install()->quick(); Utils::Hook(0x463022, Zones::LoadWeaponAttach, HOOK_CALL).install()->quick(); Utils::Hook(0x41A570, Zones::LoadmenuDef_t, HOOK_CALL).install()->quick(); Utils::Hook(0x49591B, Zones::LoadFxEffectDef, HOOK_CALL).install()->quick(); Utils::Hook(0x428F0A, Zones::LoadMaterialShaderArgumentArray, HOOK_CALL).install()->quick(); Utils::Hook(0x4B1EB8, Zones::LoadStructuredDataStructPropertyArray, HOOK_CALL).install()->quick(); Utils::Hook(0x49CE0D, Zones::LoadPhysPreset, HOOK_CALL).install()->quick(); Utils::Hook(0x48E84D, Zones::LoadXModelSurfs, HOOK_CALL).install()->quick(); Utils::Hook(0x4447C2, Zones::LoadImpactFx, HOOK_CALL).install()->quick(); Utils::Hook(0x4447D0, Zones::LoadImpactFxArray, HOOK_JUMP).install()->quick(); Utils::Hook(0x4D6A0B, Zones::LoadPathNodeArray, HOOK_CALL).install()->quick(); Utils::Hook(0x4D6A47, Zones::LoadPathDataConstant, HOOK_JUMP).install()->quick(); Utils::Hook(0x463D6E, Zones::LoadPathnodeConstantTail, HOOK_CALL).install()->quick(); Utils::Hook(0x4471AD, Zones::LoadGfxImage, HOOK_CALL).install()->quick(); Utils::Hook(0x41A590, Zones::LoadExpressionSupportingDataPtr, HOOK_CALL).install()->quick(); Utils::Hook(0x459833, Zones::LoadExpressionSupportingDataPtr, HOOK_JUMP).install()->quick(); Utils::Hook(0x5B9AA5, Zones::LoadXAsset, HOOK_CALL).install()->quick(); Utils::Hook(0x461740, Zones::LoadMaterialTechniqueArray, HOOK_CALL).install()->quick(); Utils::Hook(0x461710, Zones::LoadMaterialTechnique, HOOK_CALL).install()->quick(); Utils::Hook(0x40330D, Zones::LoadMaterial, HOOK_CALL).install()->quick(); Utils::Hook(0x4B8DC0, Zones::LoadGfxWorld, HOOK_CALL).install()->quick(); Utils::Hook(0x4B8FF5, Zones::Loadsunflare_t, HOOK_CALL).install()->quick(); Utils::Hook(0x418998, Zones::GameMapSpPatchStub, HOOK_JUMP).install()->quick(); Utils::Hook(0x427A1B, Zones::LoadPathDataTail, HOOK_JUMP).install()->quick(); Utils::Hook(0x4B4EA1, Zones::ParseShellShock_Stub, HOOK_CALL).install()->quick(); Utils::Hook(0x4B4F0C, Zones::ParseShellShock_Stub, HOOK_CALL).install()->quick(); Utils::Hook(0x4F4D3B, [] { if (Zones::ZoneVersion >= VERSION_ALPHA3) { ZeroMemory(*Game::varPathData, sizeof(Game::PathData)); } else { // Load_PathData Utils::Hook::Call(0x4278A0)(false); } }, HOOK_CALL).install()->quick(); // Change stream for images Utils::Hook(0x4D3225, []() { Game::DB_PushStreamPos((Zones::ZoneVersion >= 332) ? 3 : 0); }, HOOK_CALL).install()->quick(); Utils::Hook(0x4597DD, Zones::LoadStatement, HOOK_CALL).install()->quick(); Utils::Hook(0x471A39, Zones::LoadWindowImage, HOOK_JUMP).install()->quick(); } } #pragma optimize( "", on )