From 49beaf556682b332f39f1b4aa2d885c05ccb2403 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 18 Sep 2016 18:08:30 +0200 Subject: [PATCH 01/13] Start implementing codo maps --- src/Components/Modules/AssetHandler.hpp | 4 + src/Components/Modules/FastFiles.cpp | 6 + src/Components/Modules/Maps.cpp | 14 + src/Components/Modules/ModelSurfs.cpp | 4 +- src/Components/Modules/Zones.cpp | 1136 +++++++++++++++++++++++ src/Main.cpp | 2 +- 6 files changed, 1163 insertions(+), 3 deletions(-) diff --git a/src/Components/Modules/AssetHandler.hpp b/src/Components/Modules/AssetHandler.hpp index 9ff1c981..b1ee949c 100644 --- a/src/Components/Modules/AssetHandler.hpp +++ b/src/Components/Modules/AssetHandler.hpp @@ -29,6 +29,10 @@ namespace Components static void Relocate(void* start, void* to, DWORD size = 4); + static void Relocate(DWORD start, DWORD size, DWORD to) { + Relocate((void*)start, (void*)to, size); + } + static void ZoneSave(Game::XAsset asset, ZoneBuilder::Zone* builder); static void ZoneMark(Game::XAsset asset, ZoneBuilder::Zone* builder); diff --git a/src/Components/Modules/FastFiles.cpp b/src/Components/Modules/FastFiles.cpp index 0a69c314..7853b68a 100644 --- a/src/Components/Modules/FastFiles.cpp +++ b/src/Components/Modules/FastFiles.cpp @@ -154,6 +154,12 @@ namespace Components } Zones::InstallPatches(*version); + + // TODO: Ugly hotpatch, beautify that! +// if (*version >= 316) +// { +// *version = XFILE_VERSION; +// } } FastFiles::FastFiles() diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index c0960b5c..0296dc67 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -84,6 +84,15 @@ namespace Components return; } + if (type == Game::XAssetType::ASSET_TYPE_WEAPON) + { + if (!strstr(name.data(), "_mp") && name != "none" && name != "destructible_car") + { + *restrict = true; + return; + } + } + if (type == Game::XAssetType::ASSET_TYPE_MAP_ENTS) { static std::string mapEntities; @@ -106,7 +115,10 @@ namespace Components if (_strnicmp("mp_", mapname, 3)) { format = "maps/%s.d3dbsp"; + } + if (_strnicmp("mp_", mapname, 3) || mapname == "mp_nuked"s || mapname == "mp_bloc"s) + { // Adjust pointer to GameMap_Data Utils::Hook::Set(0x4D90B7, &(Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAME_MAP_SP].gameMapSP[0].data)); } @@ -218,6 +230,8 @@ namespace Components //Maps::AddDependency("gulag", "mp_subbase"); //Maps::AddDependency("invasion", "mp_rust"); Maps::AddDependency("co_hunted", "mp_storm"); + Maps::AddDependency("mp_nuked", "iw4x_dependencies_mp"); + Maps::AddDependency("mp_bloc", "iw4x_dependencies_mp"); Maps::AddDependency("^(?!mp_).*", "iw4x_dependencies_mp"); // All maps not starting with "mp_" } diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 7d18fca1..2b7aa5e1 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -79,7 +79,7 @@ namespace Components Game::CModelSectionHeader* section = &header.sectionHeader[i]; for (int j = section->fixupStart; j < section->fixupStart + section->fixupCount; ++j) { - unsigned int fixup = fixups[i]; + unsigned int fixup = fixups[j]; *reinterpret_cast(reinterpret_cast(section->buffer) + (fixup >> 3)) += reinterpret_cast(header.sectionHeader[fixup & 3].buffer); } } @@ -103,7 +103,7 @@ namespace Components memcpy(&tempSurfaces[i], surfaceData + (i * 84), 12); memcpy(&tempSurfaces[i].indexBuffer, surfaceData + (i * 84) + 16, 20); memcpy(&tempSurfaces[i].numCT, surfaceData + (i * 84) + 40, 8); - memcpy(&tempSurfaces[i].pad5, surfaceData + (i * 84) + 52, 24); + memcpy(&tempSurfaces[i].something, surfaceData + (i * 84) + 52, 24); tempSurfaces[i].streamHandle = 0xFF; // Fake handle for buffer interception } diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index fa72f063..f28ff362 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -4,14 +4,1150 @@ namespace Components { int Zones::ZoneVersion; + + extern bool* useEntryNames; + + Utils::Hook fxEffectLoadHook; + DWORD fxEffectLoadHookLoc = 0x49591B; + + static DWORD fxEffectStringValue[64]; + static int fxEffectIndex = 0; + + int ffVersion = 0; + +#define VERSION_ALPHA2 316 +#define VERSION_ALPHA3 318//319 + + void FxEffectLoadHookFunc(int a1, char* buffer, int len) + { + len /= 252; + + int count = len; + len *= 260; + + __asm + { + push len + push buffer + push a1 + call fxEffectLoadHook.Original + add esp, 0Ch + } + + fxEffectIndex = 0; + char* tempVar = new char[len]; + + for (int i = 0; i < count; i++) + { + AssetHandler::Relocate((DWORD)buffer + (260 * i), 252, (DWORD)buffer + (252 * i)); + + memcpy(tempVar + (252 * i), buffer + (260 * i), 252); + + fxEffectStringValue[i] = *(DWORD*)(buffer + (260 * i) + 256); + } + + memcpy(buffer, tempVar, len); + + delete[] tempVar; + } + + Utils::Hook fxEffectModifyHook; + DWORD fxEffectModifyHookLoc = 0x45ADA0; + + bool ignoreThisFx = false; + + void FxEffectModifyHookFunc(int a1, char* buffer, size_t len) + { + char typeNum = *(char*)(buffer + 176); + + //DBG(("ot %i\n", typeNum)); + + if (typeNum == 2) + { + ignoreThisFx = true; + } + else if (typeNum == 3) + { + typeNum = 2; + } + else if (typeNum == 4) + { + ignoreThisFx = true; + } + else if (typeNum >= 5) + { + typeNum -= 2; + } + + /*if (typeNum >= 2) + { + typeNum -= 2; + }*/ + + *(char*)(buffer + 176) = typeNum; + + __asm + { + push len + push buffer + push a1 + call fxEffectModifyHook.Original + add esp, 0Ch + } + } + + Utils::Hook fxEffectTailHook; + DWORD fxEffectTailHookLoc = 0x495938; + + void FxEffectTailHookFunc() + { + // varXString = (varFxEffect + 256) + //*(DWORD*)0x112B340 = (*(DWORD*)0x112B018) + 256; + DWORD thisFX = *(DWORD*)0x112B018; + + /*if (*(char*)(thisFX + 176) == 0 || *(char*)(thisFX + 176) == 4) + { + Material* material = *(Material**)(thisFX + 188); + + if (material && ((DWORD)material) != 0x3F800000) + { + //DBG(("%s\n", material->name)); + } + else + { + *(void**)(thisFX + 188) = DB_FindXAssetHeader(ASSET_TYPE_MATERIAL, "$default"); + //DBG(("!!nullmat!!\n")); + } + }*/ + + *(DWORD**)0x112B340 = &fxEffectStringValue[fxEffectIndex++]; + + // Load_XStringPtr(0) + __asm + { + mov eax, 47FDA0h + + push 0 + call eax + add esp, 4h + } + } + + void __declspec(naked) FxEffectTailHookStub() + { + __asm + { + push 0 + call fxEffectTailHook.Original + add esp, 4 + + jmp FxEffectTailHookFunc + } + } + + Utils::Hook xModelModifyHook; + DWORD xModelModifyHookLoc = 0x410D90; + + void XModelModifyHookFunc(int a1, char* buffer, size_t len) + { + __asm + { + push len + push buffer + push a1 + call xModelModifyHook.Original + add esp, 0Ch + } + + int elSize = (ffVersion == VERSION_ALPHA2) ? 364 : 360; + + static unsigned char tempVar[364]; + memcpy(&tempVar[0], &buffer[0], 36); + memcpy(&tempVar[36], &buffer[44], 28); + + //DB_AddRelocation((DWORD)buffer + 44, 28, (DWORD)buffer + 36); + + for (int i = 0; i < 4; i++) + { + //DB_AddRelocation((DWORD)buffer + 72 + (i * 56), 12, (DWORD)buffer + 64 + (i * 44)); + //DB_AddRelocation((DWORD)buffer + 72 + (i * 56) + 12, 32, (DWORD)buffer + 64 + (i * 44) + 16); + + memcpy(&tempVar[64 + (i * 44)], &buffer[72 + (i * 56)], 12); + memcpy(&tempVar[64 + (i * 44) + 12], &buffer[72 + (i * 56) + 16], 32); + + memcpy(&tempVar[(elSize - 4) - (i * 4)], &buffer[72 + (i * 56) + 12], 4); + } + + //DB_AddRelocation((DWORD)buffer + 292, (elSize - 292 - 4), (DWORD)buffer + 236); + //DB_AddRelocation((DWORD)buffer + (elSize - 8), 8, (DWORD)buffer + 296); + + memcpy(&tempVar[236], &buffer[292], (elSize - 292 - 4)/*68*/); + memcpy(&tempVar[296], &buffer[(elSize - 8)], 8); + + tempVar[304] = 0xDE; + tempVar[305] = 0xAD; + tempVar[306] = 0xC0; + tempVar[307] = 0xDE; + + memcpy(buffer, tempVar, elSize); + + /*void* grenade = DB_FindXAssetHeader(ASSET_TYPE_XMODELSURFS, "us_smoke_grenade_proj10"); + *(void**)(buffer + 72) = grenade; + *(void**)(buffer + 72 + 44) = grenade; + *(void**)(buffer + 72 + 88) = grenade; + *(void**)(buffer + 72 + 88 + 44) = grenade;*/ + } + + Utils::Hook xLodTailHook; + DWORD xLodTailHookLoc = 0x4EA6FE; + + void XModelLODTailHookFunc(int i) + { + int elSize = (ffVersion == VERSION_ALPHA2) ? 364 : 360; + i = (4 - i)/* + 1*/; + + // varXString = (varXModel + 0x16C - (4 * i)) // where the above function parked the new xstring + *(DWORD*)0x112B340 = ((*(DWORD*)0x112AE14) + (elSize - 4)) - (4 * i); + + // Load_XStringPtr(0) + __asm + { + mov eax, 47FDA0h + + push 0 + call eax + add esp, 4h + } + } + + void __declspec(naked) XModelLODTailHookStub() + { + __asm + { + push edi + call XModelLODTailHookFunc + add esp, 4h + + mov eax, [esp + 8h] + push eax + add eax, 8 + push eax + call xLodTailHook.Original + add esp, 8h + + retn + } + } + + Utils::Hook fxDefaultHook; + DWORD fxDefaultHookLoc = 0x4D9C0E; + + void FxDefaultHookFunc() + { + DWORD* varFxEffectDefPtr = *(DWORD**)0x112ACC0; + + *varFxEffectDefPtr = (DWORD)Game::DB_FindXAssetHeader(Game::ASSET_TYPE_FX, "misc/missing_fx").data; + } + + void __declspec(naked) FxDefaultHookStub() + { + __asm + { + jmp FxDefaultHookFunc + } + } + + Utils::Hook xmodelDefaultHook; + DWORD xmodelDefaultHookLoc = 0x4FCAEE; + + void XModelDefaultHookFunc() + { + DWORD* varXModelPtr = *(DWORD**)0x112A934; + + *varXModelPtr = (DWORD)Game::DB_FindXAssetHeader(Game::ASSET_TYPE_XMODEL, "void").data; + } + + void __declspec(naked) XModelDefaultHookStub() + { + __asm + { + jmp XModelDefaultHookFunc + } + } + + Utils::Hook xsurfaceIntLoadHook; + DWORD xsurfaceIntLoadHookLoc = 0x4925C8; + + void XSurfaceIntLoadHookFunc(int a1, char* buffer, size_t len) + { + len >>= 6; + + int count = len; + len *= 84; + + __asm + { + push len + push buffer + push a1 + call xsurfaceIntLoadHook.Original + add esp, 0Ch + } + + char* tempVar = new char[len]; + + for (int i = 0; i < count; i++) + { + char* source = &buffer[i * 84]; + char* dest = &tempVar[i * 64]; + + //memcpy(dest, source, 12); + //memcpy(dest + 12, source + 16, 72); + memcpy(dest, source, 12); + memcpy(dest + 12, source + 16, 20); + memcpy(dest + 32, source + 40, 8); + memcpy(dest + 40, source + 52, 24); + } + + memcpy(buffer, tempVar, len); + + delete[] tempVar; + } + + Utils::Hook loadWeaponDefHook; + DWORD loadWeaponDefHookLoc = 0x47CCD2; + + typedef void(__cdecl * Load_Stream_t)(int load, DWORD ptr, int len); + Load_Stream_t Load_Stream = (Load_Stream_t)0x470E30; + + typedef DWORD(__cdecl * DB_PushStreamPos_t)(int block); + DB_PushStreamPos_t DB_PushStreamPos = (DB_PushStreamPos_t)0x458A20; + + typedef void(__cdecl * DB_PopStreamPos_t)(); + DB_PopStreamPos_t DB_PopStreamPos = (DB_PopStreamPos_t)0x4D1D60; + + typedef DWORD(__cdecl * Load_XStringPtr_t)(int a1); + Load_XStringPtr_t Load_XStringPtr = (Load_XStringPtr_t)0x47FDA0; + Load_XStringPtr_t Load_XStringPtr_ = (Load_XStringPtr_t)0x47FDA0; + + DWORD* varXModelPtr = (DWORD*)0x112A934; + Load_XStringPtr_t Load_XModelPtr = (Load_XStringPtr_t)0x4FCA70; + + typedef void(__cdecl * Load_XString_t)(int a1, int count); + DWORD* varXString_ = (DWORD*)0x112B340; + Load_XString_t Load_XString = (Load_XString_t)0x4977F0; + + typedef void(__cdecl * Load_XStringData_t)(DWORD* target); + DWORD* varXStringData = (DWORD*)0x112A774; + Load_XStringData_t Load_XStringData = (Load_XStringData_t)0x4E0DD0; + + DWORD* varFxEffectDefPtr = (DWORD*)0x112ACC0; + Load_XStringPtr_t Load_FxEffectDefPtr = (Load_XStringPtr_t)0x4D9B90; + + typedef void(__cdecl * Load_SndAliasCustom_t)(DWORD); + DWORD* varsnd_alias_list_name = (DWORD*)0x112AF38; + Load_SndAliasCustom_t Load_SndAliasCustom = (Load_SndAliasCustom_t)0x49B6B0; + + DWORD* varMaterialPtr = (DWORD*)0x112A878; + Load_XStringPtr_t Load_MaterialPtr = (Load_XStringPtr_t)0x403960; + + DWORD* varPhysCollmapPtr = (DWORD*)0x112B440; + Load_XStringPtr_t Load_PhysCollmapPtr = (Load_XStringPtr_t)0x47E990; + + DWORD* varTracerPtr = (DWORD*)0x112B3BC; + Load_XStringPtr_t Load_TracerPtr = (Load_XStringPtr_t)0x493090; + + Load_XStringPtr_t DB_AllocStreamPos = (Load_XStringPtr_t)0x418380; + Load_XString_t _load_lookupMultipleSounds = (Load_XString_t)0x4499F0; + + //#define Load_XStringPtr(x) Load_XStringPtr_(x); DBG(("wF: %s\n", **(DWORD**)varXString)) +#define Load_XStringPtr Load_XStringPtr_ + + void Load_WeaponDef_CodC(int doLoad) + { + // setup structures we use + DWORD varWeaponDef = *(DWORD*)0x112A9F4;//*(DWORD*)0x112AE14; + DWORD* varXString = (DWORD*)0x112B340; + + // and do the stuff + Load_Stream(1, varWeaponDef, (ffVersion >= 318) ? 3156 : 3112); + + DB_PushStreamPos(3); + + *varXString = varWeaponDef + 0; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 4; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 8; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 12; + Load_XStringPtr(0); + + *varXModelPtr = varWeaponDef + 16; + Load_XModelPtr(0); + + for (int i = 0, offset = 20; i < 32; i++, offset += 4) + { + *varXModelPtr = varWeaponDef + offset; + Load_XModelPtr(0); + } + + // 148 + for (int offset = 148; offset <= 168; offset += 4) + { + *varXModelPtr = varWeaponDef + offset; + Load_XModelPtr(0); + } + + // 172 + // 32 scriptstrings, should not need to be loaded + + // 236 + *varXString_ = varWeaponDef + 236; + Load_XString(0, 48); + + // 428 + *varXString_ = varWeaponDef + 428; + Load_XString(0, 48); + + // 620 + *varXString_ = varWeaponDef + 620; + Load_XString(0, 48); + + // 812 + // 16 * 4 scriptstrings + + // 972 + *varFxEffectDefPtr = varWeaponDef + 972; + Load_FxEffectDefPtr(0); + + *varFxEffectDefPtr = varWeaponDef + 976; + Load_FxEffectDefPtr(0); + + // 980 + // 50 soundalias name references; up to and including 1180 + for (int i = 0, offset = 980; i < 50; i++, offset += 4) + { + *varsnd_alias_list_name = varWeaponDef + offset; + Load_SndAliasCustom(*varsnd_alias_list_name); + } + + if (ffVersion >= 318) + { + for (int i = 0, offset = 1184; i < 2; i++, offset += 4) + { + *varsnd_alias_list_name = varWeaponDef + offset; + Load_SndAliasCustom(*varsnd_alias_list_name); + } + + varWeaponDef += 8; // to compensate for the 2 in between here + } + + if (*(DWORD*)(varWeaponDef + 1184)) + { + if (*(DWORD*)(varWeaponDef + 1184) == -1) + { + *(DWORD*)(varWeaponDef + 1184) = DB_AllocStreamPos(3); + *varsnd_alias_list_name = *(DWORD*)(varWeaponDef + 1184); + + _load_lookupMultipleSounds(1, 31); + } + else + { + // full usability requires ConvertOffsetToPointer here + } + } + + if (*(DWORD*)(varWeaponDef + 1188)) + { + if (*(DWORD*)(varWeaponDef + 1188) == -1) + { + *(DWORD*)(varWeaponDef + 1188) = DB_AllocStreamPos(3); + *varsnd_alias_list_name = *(DWORD*)(varWeaponDef + 1188); + + _load_lookupMultipleSounds(1, 31); + } + else + { + // full usability requires ConvertOffsetToPointer here + } + } + + // 1192 + for (int offset = 1192; offset <= 1204; offset += 4) + { + *varFxEffectDefPtr = varWeaponDef + offset; + Load_FxEffectDefPtr(0); + } + + // 1208 + int matOffsets1[] = { 1208, 1212, 1428, 1432, 1436, 1440, 1444, 1448, 1456, 1464 }; + + for (int i = 0; i < sizeof(matOffsets1) / sizeof(int); i++) + { + *varMaterialPtr = varWeaponDef + matOffsets1[i]; + Load_MaterialPtr(0); + } + + *varXString = varWeaponDef + 1484; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 1492; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 1508; + Load_XStringPtr(0); + + for (int offset = 1764; offset <= 1776; offset += 4) + { + *varMaterialPtr = varWeaponDef + offset; + Load_MaterialPtr(0); + } + + *varPhysCollmapPtr = varWeaponDef + 1964; + Load_PhysCollmapPtr(0); + + *varXModelPtr = varWeaponDef + 2052; + Load_XModelPtr(0); + + *varFxEffectDefPtr = varWeaponDef + 2060; + Load_FxEffectDefPtr(0); + + *varFxEffectDefPtr = varWeaponDef + 2064; + Load_FxEffectDefPtr(0); + + *varsnd_alias_list_name = varWeaponDef + 2068; + Load_SndAliasCustom(*varsnd_alias_list_name); + + *varsnd_alias_list_name = varWeaponDef + 2072; + Load_SndAliasCustom(*varsnd_alias_list_name); + + *varFxEffectDefPtr = varWeaponDef + 2336; + Load_FxEffectDefPtr(0); + + *varFxEffectDefPtr = varWeaponDef + 2340; + Load_FxEffectDefPtr(0); + + *varFxEffectDefPtr = varWeaponDef + 2368; // 2376 + Load_FxEffectDefPtr(0); + + *varsnd_alias_list_name = varWeaponDef + 2372; // 2380 + Load_SndAliasCustom(*varsnd_alias_list_name); + + *varXString = varWeaponDef + 2548; // 2556 + Load_XStringPtr(0); + + if (*(DWORD*)(varWeaponDef + 2556) == -1) // 2564 + { + DWORD vec2 = DB_AllocStreamPos(3); + *(DWORD*)(varWeaponDef + 2556) = vec2; + + Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((ffVersion >= 318) ? 3076 : 3040))); + } + + *varXString = varWeaponDef + 2552; + Load_XStringPtr(0); + + if (*(DWORD*)(varWeaponDef + 2560) == -1) + { + DWORD vec2 = DB_AllocStreamPos(3); + *(DWORD*)(varWeaponDef + 2560) = vec2; + + Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((ffVersion >= 318) ? 3078 : 3042))); + } + + *varXString = varWeaponDef + 2640; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 2644; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 2676; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 2680; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 2804; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 2808; + Load_XStringPtr(0); + + *varTracerPtr = varWeaponDef + 2812; + Load_TracerPtr(0); + + *varsnd_alias_list_name = varWeaponDef + 2840; + Load_SndAliasCustom(*varsnd_alias_list_name); // 2848 + + *varFxEffectDefPtr = varWeaponDef + 2844; + Load_FxEffectDefPtr(0); + + *varXString = varWeaponDef + 2848; + Load_XStringPtr(0); + + *varsnd_alias_list_name = varWeaponDef + 2864; + Load_SndAliasCustom(*varsnd_alias_list_name); + + *varsnd_alias_list_name = varWeaponDef + 2868; + _load_lookupMultipleSounds(0, 4); + + *varsnd_alias_list_name = varWeaponDef + 2884; + _load_lookupMultipleSounds(0, 4); + + *varsnd_alias_list_name = varWeaponDef + 2900; + Load_SndAliasCustom(*varsnd_alias_list_name); + + *varsnd_alias_list_name = varWeaponDef + 2904; // 2912 + Load_SndAliasCustom(*varsnd_alias_list_name); + + if (ffVersion >= 318) + { + for (int i = 0, offset = 2972; i < 6; i++, offset += 4) + { + *varsnd_alias_list_name = varWeaponDef + offset; + Load_SndAliasCustom(*varsnd_alias_list_name); + } + + varWeaponDef += (6 * 4); + varWeaponDef += 12; + } + else + { + + } + + *varXString = varWeaponDef + 2984; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 2996; + Load_XStringPtr(0); + + *varXString = varWeaponDef + 3000; + Load_XStringPtr(0); + + *varMaterialPtr = varWeaponDef + 3008; + Load_MaterialPtr(0); + + *varMaterialPtr = varWeaponDef + 3012; + Load_MaterialPtr(0); + + *varMaterialPtr = varWeaponDef + 3016; + Load_MaterialPtr(0); + + if (*(DWORD*)(varWeaponDef + 3044) == -1) + { + DWORD vec2 = DB_AllocStreamPos(3); + *(DWORD*)(varWeaponDef + 3044) = vec2; + + Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + 3040)); + } + + if (*(DWORD*)(varWeaponDef + 3048) == -1) + { + DWORD vec2 = DB_AllocStreamPos(3); + *(DWORD*)(varWeaponDef + 3048) = vec2; + + Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + 3042)); + } + + DB_PopStreamPos(); + } + +#undef Load_XStringPtr +#define Load_XStringPtr Load_XStringPtr_ + + Utils::Hook gameWorldSpLoadHook; + DWORD gameWorldSpLoadHookLoc = 0x4F4D0D; + + void GameWorldSpLoadHookFunc(int a1, char* buffer, size_t len) + { + len = 84; + + __asm + { + push len + push buffer + push a1 + call gameWorldSpLoadHook.Original + add esp, 0Ch + } + + static char tempVar[84]; + memcpy(&tempVar[0], &buffer[0], 44); + memcpy(&tempVar[56], &buffer[44], 28); + memcpy(&tempVar[44], &buffer[72], 12); + + memcpy(buffer, tempVar, sizeof(tempVar)); + } + + Utils::Hook pathDataTailHook; + DWORD pathDataTailHookLoc = 0x427A1B; + + void PathDataTailHookFunc() + { + DWORD varStuff = *(DWORD*)0x112AD7C; + DWORD varThing; + + if (*(DWORD*)(varStuff + 56)) + { + *(DWORD*)(varStuff + 56) = DB_AllocStreamPos(0); + varThing = *(DWORD*)(varStuff + 56); + Load_Stream(1, varThing, *(DWORD*)(varStuff + 52)); + } + + if (*(DWORD*)(varStuff + 64)) + { + *(DWORD*)(varStuff + 64) = DB_AllocStreamPos(0); + varThing = *(DWORD*)(varStuff + 64); + Load_Stream(1, varThing, *(DWORD*)(varStuff + 60)); + } + + if (*(DWORD*)(varStuff + 76)) + { + *(DWORD*)(varStuff + 76) = DB_AllocStreamPos(0); + varThing = *(DWORD*)(varStuff + 76); + Load_Stream(1, varThing, *(DWORD*)(varStuff + 72)); + } + } + + Utils::Hook allocZoneMemoryHook; + DWORD allocZoneMemoryHookLoc = 0x415A57; + + void AllocXZoneMemoryHookFunc(unsigned int* sizes) + { + sizes[3] = (unsigned int)(sizes[3] * 1.5); + } + + void __declspec(naked) AllocXZoneMemoryHookStub() + { + __asm + { + mov eax, [esp + 4] + push eax + call AllocXZoneMemoryHookFunc + add esp, 4h + + jmp allocZoneMemoryHook.Original + } + } + + Utils::Hook sndAliasLoadHook; + DWORD sndAliasLoadHookLoc = 0x4F0AC8; + + void SndAliasLoadHookFunc(int a1, char* buffer, size_t len) + { + len /= 100; + int count = len; + len *= 108; + + __asm + { + push len + push buffer + push a1 + call gameWorldSpLoadHook.Original + add esp, 0Ch + } + + char* tempVar = new char[len]; + + for (int i = 0; i < count; i++) + { + /*char* src = &buffer[i * 108]; + char* dest = &tempVar[i * 100]; + + memcpy(dest + 0, src + 0, 80); + memcpy(dest + 80, src + 88, 20); + + DB_AddRelocation((DWORD)src + 0, 80, (DWORD)(buffer + (i * 100)) + 0); + DB_AddRelocation((DWORD)src + 88, 20, (DWORD)(buffer + (i * 100)) + 80);*/ + + char* src = &buffer[i * 108]; + char* dest = &tempVar[i * 100]; + + memcpy(dest + 0, src + 0, 60); + memcpy(dest + 60, src + 68, 20); + memcpy(dest + 80, src + 88, 20); + + AssetHandler::Relocate((DWORD)src + 0, 60, (DWORD)(buffer + (i * 100)) + 0); + AssetHandler::Relocate((DWORD)src + 68, 20, (DWORD)(buffer + (i * 100)) + 60); + AssetHandler::Relocate((DWORD)src + 88, 20, (DWORD)(buffer + (i * 100)) + 80); + } + + memcpy(buffer, tempVar, len); + delete[] tempVar; + } + + Utils::Hook mssSoundLoadHook; + DWORD mssSoundLoadHookLoc = 0x403A5D; + + void MssSoundLoadHookFunc(int a1, char* buffer, size_t len) + { + len = 48; + + __asm + { + push len + push buffer + push a1 + call gameWorldSpLoadHook.Original + add esp, 0Ch + } + + memcpy(buffer + 28, buffer + 32, 16); + AssetHandler::Relocate((DWORD)buffer + 32, 16, (DWORD)buffer + 28); + //memcpy(buffer + 40, buffer + 44, 4); + } + + Utils::Hook vehicleLoadHook; + DWORD vehicleLoadHookLoc = 0x483DA0; + + void VehicleLoadHookFunc(int a1, char* buffer, int len) + { + len = 788; + + __asm + { + push len + push buffer + push a1 + call vehicleLoadHook.Original + add esp, 0Ch + } + + static char tempVar[788]; + memcpy(&tempVar[0], &buffer[0], 400); + memcpy(&tempVar[408], &buffer[400], 388); + + AssetHandler::Relocate((DWORD)buffer + 400, 388, (DWORD)buffer + 408); + + memcpy(buffer, tempVar, sizeof(tempVar)); + } + + Utils::Hook loadWeaponAttachHook; + DWORD loadWeaponAttachHookLoc = 0x463022; + + DWORD varWeaponAttachStuff; + + void Load_WeaponAttachStuff(int count) + { + Load_Stream(1, varWeaponAttachStuff, 12 * count); + + DWORD* varStuff = (DWORD*)varWeaponAttachStuff; + + for (int i = 0; i < count; i++) + { + DWORD* varXString = (DWORD*)0x112B340; + + if (varStuff[1] < 16 || varStuff[1] == 39) + { + if (varStuff[2] == -1) + { + varStuff[2] = DB_AllocStreamPos(0); + *varXStringData = varStuff[2]; + Load_XStringData(varXStringData); + + //if (*useEntryNames) + { + //DBG(("wA: %s\n", *varXStringData)); + } + } + else if (varStuff[2]) + { + // meh, no convertin' here + } + } + + varStuff += 3; + } + } + + Utils::Hook menuDefLoadHook; + DWORD menuDefLoadHookLoc = 0x41A570; + + void MenuDefLoadHookFunc(int doLoad, char* buffer, int len) + { + len += 4; + + __asm + { + push len + push buffer + push doLoad + call menuDefLoadHook.Original + add esp, 0Ch + } + + memcpy(buffer + 168, buffer + 172, 232); + + AssetHandler::Relocate((DWORD)buffer + 172, 232, (DWORD)buffer + 168); + } + + void Load_WeaponAttach(int doLoad) + { + // setup structures we use + DWORD varWeaponAttach = *(DWORD*)0x112ADE0;//*(DWORD*)0x112AE14; + DWORD* varXString = (DWORD*)0x112B340; + + // and do the stuff + Load_Stream(1, varWeaponAttach, 12); + + DB_PushStreamPos(3); + + *varXString = varWeaponAttach + 0; + Load_XStringPtr(0); + + *(DWORD*)(varWeaponAttach + 8) = DB_AllocStreamPos(3); + + varWeaponAttachStuff = *(DWORD*)(varWeaponAttach + 8); + Load_WeaponAttachStuff(*(int*)(varWeaponAttach + 4)); + + DB_PopStreamPos(); + } + + Utils::Hook gameWorldSpIntHook; + DWORD gameWorldSpIntHookLoc = 0x4F4D3B; + + void GameWorldSpIntHookFunc(int doLoad) + { + memset(*(void**)0x112AD7C, 0, 40); + } + + extern char lastZoneName[256]; + + FILE* outFile; + DWORD sb3Start = 0; + + void DB_InitStreamsHook() + { + sb3Start = *(DWORD*)0x16E5564; + } + + struct MaterialArgumentDef + { + short a1; + short a2; + short paramID; + short more; + }; + + Utils::Hook loadTechniquePassHook; + DWORD loadTechniquePassHookLoc = 0x428F0A; + + void Load_TechniquePassHookFunc(int a1, MaterialArgumentDef* pass, size_t size) + { + int count = size / 8; + + Game::MaterialPass* curPass = *(Game::MaterialPass**)0x112A960; + count = curPass->argCount1 + curPass->argCount2 + curPass->argCount3; + + Load_Stream(a1, (DWORD)pass, size); + + for (int i = 0; i < count; i++) + { + MaterialArgumentDef* arg = &pass[i]; + + //if (arg->a1 == 1 || arg->a1 == 7) + if (arg->a1 != 3 && arg->a1 != 5) + { + continue; + } + + // 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->paramID >= 58 && arg->paramID <= 135) // >= 34 would be 31 in iw4 terms + { + arg->paramID -= 3; + } + // >= 21 works fine for specular, but breaks trees + // >= 4 is too low, breaks specular + else if (arg->paramID >= 11 && arg->paramID < 58) + { + arg->paramID -= 2; + } + + /*if (arg->paramID >= 132) + { + DBG(("(bad) changed from %i to %i\n", arg->paramID + 3, arg->paramID)); + }*/ + } + } + + Utils::Hook loadStructuredDataChildArrayHook; + DWORD loadStructuredDataChildArrayHookLoc = 0x4B1EB8; + + void Load_StructuredDataChildArrayHookFunc(int a1, char* data, size_t size) + { + int count = size / 16; + size = count * 24; + + Load_Stream(a1, (DWORD)data, size); + + for (int i = 0; i < count; i++) + { + memcpy(data + (i * 16), data + (i * 24), 16); + AssetHandler::Relocate((DWORD)data + (i * 24), 16, (DWORD)data + (i * 16)); + } + } + + void PatchMW2_FifthInfinityApply(int fileVersion, bool iw5) + { + ffVersion = fileVersion; + + // patch the expected version + int version = (iw5) ? 316 : 276; + + if (iw5 && fileVersion >= 318) + { + version = fileVersion; + } + + *(DWORD*)0x4158F4 = version; + *(DWORD*)0x4158FB = version; + + // physpreset size + *(BYTE*)0x49CE0A = (iw5) ? 68 : 44; + + // XModel size + *(DWORD*)0x410D8A = (iw5) ? ((ffVersion == VERSION_ALPHA2) ? 0x16C : 0x168) : 0x130; + + // XSurface size + *(BYTE*)0x48E84A = (iw5) ? 48 : 36; + + // impactfx internal size/count + *(DWORD*)0x4447B6 = (iw5) ? 0x8C0 : 0x834; + *(DWORD*)0x4447D1 = (iw5) ? 16 : 15; + + // GameWorldSp asset type + *(BYTE*)0x41899A = (iw5) ? 18 : 17; + + // PathData internal struct size + *(DWORD*)0x4D6A04 = (iw5) ? 148 : 136; + *(DWORD*)0x4D6A49 = (iw5) ? 148 : 136; + + // PathData internal struct data size + *(WORD*)0x463D63 = (iw5) ? 0x9090 : 0x048D; + *(BYTE*)0x463D65 = (iw5) ? 0x90 : 0x40; + *(DWORD*)0x463D66 = (iw5) ? 0x9004E0C1 : 0xC003C003; // shl eax, 4 instead of add eax, eax * 2 + + // addon_map_ents asset type (we reuse it for weaponattach) + *(BYTE*)0x418B30 = (iw5) ? 43 : Game::ASSET_TYPE_ADDON_MAP_ENTS; + + // hooks + if (iw5) + { + fxEffectTailHook.Install(); + fxEffectModifyHook.Install(); + + xLodTailHook.Install(); + xModelModifyHook.Install(); + + xsurfaceIntLoadHook.Install(); + gameWorldSpLoadHook.Install(); + pathDataTailHook.Install(); + + loadWeaponDefHook.Install(); + vehicleLoadHook.Install(); + + sndAliasLoadHook.Install(); + mssSoundLoadHook.Install(); + menuDefLoadHook.Install(); + fxEffectLoadHook.Install(); + + loadWeaponAttachHook.Install(); + + if (ffVersion >= VERSION_ALPHA3) + { + gameWorldSpIntHook.Install(); + } + + loadTechniquePassHook.Install(); + loadStructuredDataChildArrayHook.Install(); + + //xmodelDefaultHook.Install(); + fxDefaultHook.Install(); + } + else + { + fxEffectTailHook.Uninstall(); + fxEffectModifyHook.Uninstall(); + + xLodTailHook.Uninstall(); + xModelModifyHook.Uninstall(); + + xsurfaceIntLoadHook.Uninstall(); + gameWorldSpLoadHook.Uninstall(); + pathDataTailHook.Uninstall(); + + loadWeaponDefHook.Uninstall(); + vehicleLoadHook.Uninstall(); + + sndAliasLoadHook.Uninstall(); + mssSoundLoadHook.Uninstall(); + menuDefLoadHook.Uninstall(); + fxEffectLoadHook.Uninstall(); + + loadWeaponAttachHook.Uninstall(); + + xmodelDefaultHook.Uninstall(); + fxDefaultHook.Uninstall(); + + gameWorldSpIntHook.Uninstall(); + + loadTechniquePassHook.Uninstall(); + loadStructuredDataChildArrayHook.Uninstall(); + + //xmodelDefaultHook.Uninstall(); + fxDefaultHook.Uninstall(); + } + } + void Zones::InstallPatches(int version) { Zones::ZoneVersion = version; + PatchMW2_FifthInfinityApply(version, version >= 316); + } + + bool IgnoreEntityHookFunc(const char* entity) + { + return (!strncmp(entity, "dyn_", 4) || !strncmp(entity, "node_", 5) || !strncmp(entity, "actor_", 6)/* || !strncmp(entity, "weapon_", 7)*/); } Zones::Zones() { + // Ignore missing soundaliases for now + // TODO: Include them in the dependency zone! + Utils::Hook::Nop(0x644207, 5); + Utils::Hook(0x5FBD6E, IgnoreEntityHookFunc).Install()->Quick(); + + fxEffectTailHook.Initialize(fxEffectTailHookLoc, FxEffectTailHookStub, HOOK_CALL); + fxEffectModifyHook.Initialize(fxEffectModifyHookLoc, FxEffectModifyHookFunc, HOOK_CALL); + xLodTailHook.Initialize(xLodTailHookLoc, XModelLODTailHookStub, HOOK_CALL); + xModelModifyHook.Initialize(xModelModifyHookLoc, XModelModifyHookFunc, HOOK_CALL); + xsurfaceIntLoadHook.Initialize(xsurfaceIntLoadHookLoc, XSurfaceIntLoadHookFunc, HOOK_CALL); + gameWorldSpLoadHook.Initialize(gameWorldSpLoadHookLoc, GameWorldSpLoadHookFunc, HOOK_CALL); + loadWeaponDefHook.Initialize(loadWeaponDefHookLoc, Load_WeaponDef_CodC, HOOK_CALL); + vehicleLoadHook.Initialize(vehicleLoadHookLoc, VehicleLoadHookFunc, HOOK_CALL); + xmodelDefaultHook.Initialize(xmodelDefaultHookLoc, XModelDefaultHookStub, HOOK_CALL); + fxDefaultHook.Initialize(fxDefaultHookLoc, FxDefaultHookStub, HOOK_CALL); + allocZoneMemoryHook.Initialize(allocZoneMemoryHookLoc, AllocXZoneMemoryHookStub, HOOK_CALL); + sndAliasLoadHook.Initialize(sndAliasLoadHookLoc, SndAliasLoadHookFunc, HOOK_CALL); + mssSoundLoadHook.Initialize(mssSoundLoadHookLoc, MssSoundLoadHookFunc, HOOK_CALL); + loadWeaponAttachHook.Initialize(loadWeaponAttachHookLoc, Load_WeaponAttach, HOOK_CALL); + menuDefLoadHook.Initialize(menuDefLoadHookLoc, MenuDefLoadHookFunc, HOOK_CALL); + fxEffectLoadHook.Initialize(fxEffectLoadHookLoc, FxEffectLoadHookFunc, HOOK_CALL); + gameWorldSpIntHook.Initialize(gameWorldSpIntHookLoc, GameWorldSpIntHookFunc, HOOK_CALL); + loadTechniquePassHook.Initialize(loadTechniquePassHookLoc, Load_TechniquePassHookFunc, HOOK_CALL); + loadStructuredDataChildArrayHook.Initialize(loadStructuredDataChildArrayHookLoc, Load_StructuredDataChildArrayHookFunc, HOOK_CALL); + + pathDataTailHook.Initialize(pathDataTailHookLoc, PathDataTailHookFunc, HOOK_JUMP); } Zones::~Zones() diff --git a/src/Main.cpp b/src/Main.cpp index cbcc4de0..279d9514 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -59,7 +59,7 @@ BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*l DWORD oldProtect; std::uint8_t* module = reinterpret_cast(GetModuleHandle(NULL)); VirtualProtect(module, 0x6C73000, PAGE_EXECUTE_READWRITE, &oldProtect); // Unprotect the entire process - VirtualProtect(module + 0x1000, 0x2D6000, PAGE_EXECUTE_READ, &oldProtect); // Protect the .text segment + VirtualProtect(module + 0x1000, 0x2D6000, PAGE_EXECUTE_READWRITE, &oldProtect); // Protect the .text segment Main::EntryPointHook.Initialize(0x6BAC0F, [] () { From 3ff854f0dd1f4122eb4f45950048633a70d0f325 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 18 Sep 2016 20:52:32 +0200 Subject: [PATCH 02/13] More stuff --- src/Components/Modules/Maps.cpp | 8 + src/Components/Modules/Maps.hpp | 2 + src/Components/Modules/ModelSurfs.cpp | 273 +++++++++++++++++++++++++- src/Components/Modules/ModelSurfs.hpp | 2 +- src/Components/Modules/Zones.cpp | 11 +- 5 files changed, 285 insertions(+), 11 deletions(-) diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 0296dc67..8ceb7174 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -149,6 +149,11 @@ namespace Components Maps::DependencyList[expression] = zone; } + bool Maps::IgnoreEntityStub(const char* entity) + { + return (Utils::String::StartsWith(entity, "dyn_") || Utils::String::StartsWith(entity, "node_") || Utils::String::StartsWith(entity, "actor_")); + } + void Maps::ReallocateEntryPool() { Assert_Size(Game::XAssetEntry, 16); @@ -208,6 +213,9 @@ namespace Components // Intercept map zone loading Utils::Hook(0x42C2AF, Maps::LoadMapZones, HOOK_CALL).Install()->Quick(); + // Ignore SP entities + Utils::Hook(0x5FBD6E, Maps::IgnoreEntityStub, HOOK_CALL).Install()->Quick(); + Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_GAME_MAP_SP, 1); Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMAGE, 7168); Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_LOADED_SOUND, 2700); diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index d6b04dcc..a033ba3d 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -24,6 +24,8 @@ namespace Components static void OverrideMapEnts(Game::MapEnts* ents); + static bool IgnoreEntityStub(const char* entity); + void ReallocateEntryPool(); }; } diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 2b7aa5e1..208aec30 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -114,6 +114,239 @@ namespace Components return modelSurfs; } + Game::FS_FOpenFileRead_t FS_FOpenFileReadDatabase = (Game::FS_FOpenFileRead_t)0x42ECA0; + + void FS_FOpenFileReadCurrentThread(char* filename, int* handle) + { + if (GetCurrentThreadId() == *(DWORD*)0x1CDE7FC) + { + Game::FS_FOpenFileRead(filename, handle, 0); + } + else if (GetCurrentThreadId() == *(DWORD*)0x1CDE814) + { + FS_FOpenFileReadDatabase(filename, handle, 0); + } + else + { + *handle = NULL; + } + } + + struct CModelSectionHeader + { + int size; + int offset; + int fixupStart; + int fixupCount; + char* buffer; + }; + + struct CModelHeader + { + int version; + unsigned int signature; + CModelSectionHeader main; + CModelSectionHeader index; + CModelSectionHeader vertex; + CModelSectionHeader fixup; + }; + + void ReadCModelSection(int handle, CModelSectionHeader& header) + { + Game::FS_Seek(handle, header.offset, FS_SEEK_SET); + Game::FS_Read(header.buffer, header.size, handle); + } + + void FixupCModelSection(CModelHeader& header, CModelSectionHeader& section, DWORD* fixups) + { + for (int i = section.fixupStart; i < section.fixupStart + section.fixupCount; i++) + { + DWORD fixup = fixups[i]; + int targetSectionNum = fixup & 3; + CModelSectionHeader* targetSection; + + if (targetSectionNum == 0) + { + targetSection = &header.main; + } + else if (targetSectionNum == 1) + { + targetSection = &header.index; + } + else if (targetSectionNum == 2) + { + targetSection = &header.vertex; + } + + *(DWORD*)(section.buffer + (fixup >> 3)) += (DWORD)targetSection->buffer; + } + } + + void Load_VertexBuffer(void* data, void** where, int len) + { + DWORD func = 0x5112C0; + + __asm + { + push edi + + mov eax, len + mov edi, where + push data + + call func + + add esp, 4 + pop edi + } + } + + typedef void* (__cdecl * R_AllocStaticIndexBuffer_t)(void** store, int length); + R_AllocStaticIndexBuffer_t R_AllocStaticIndexBuffer = (R_AllocStaticIndexBuffer_t)0x51E7A0; + + void Load_IndexBuffer(void* data, void** storeHere, int count) + { + static Game::dvar_t* r_loadForRenderer = *(Game::dvar_t**)0x69F0ED4; + + if (r_loadForRenderer->current.boolean) + { + void* buffer = R_AllocStaticIndexBuffer(storeHere, 2 * count); + memcpy(buffer, data, 2 * count); + + if (IsBadReadPtr(storeHere, 4) || IsBadReadPtr(*storeHere, 4)) + { + Game::Com_Error(0, "Static index buffer allocation failed."); + } + + __asm + { + push ecx + mov ecx, storeHere + mov ecx, [ecx] + + mov eax, [ecx] + add eax, 30h + mov eax, [eax] + + push ecx + call eax + + pop ecx + } + } + } + + void CreateCModelBuffers(void* surfs) + { + Game::XModelSurfs* model = (Game::XModelSurfs*)surfs; + + for (int i = 0; i < model->numSurfaces; i++) + { + Game::XSurface* surface = &model->surfaces[i]; + + void* vertexBuffer; + void* indexBuffer; + + Load_VertexBuffer(surface->vertexBuffer, &vertexBuffer, surface->numVertices * 32); + Load_IndexBuffer(surface->indexBuffer, &indexBuffer, surface->numPrimitives * 3); + + ModelSurfs::BufferMap[surface->vertexBuffer] = (IUnknown*)vertexBuffer; + ModelSurfs::BufferMap[surface->indexBuffer] = (IUnknown*)indexBuffer; + } + } + + char* LoadCModel(const char* name) + { + char filename[512]; + sprintf_s(filename, sizeof(filename), "models/%s", name); + + int handle; + FS_FOpenFileReadCurrentThread(filename, &handle); + + if (handle <= 0) + { + Game::Com_Error(1, "Error opening %s", filename); + } + + CModelHeader header; + + if (Game::FS_Read(&header, sizeof(header), handle) != sizeof(header)) + { + Game::FS_FCloseFile(handle); + Game::Com_Error(1, "%s: header could not be read", filename); + } + + if (header.version != 1) + { + Game::FS_FCloseFile(handle); + Game::Com_Error(1, "%s: header version is not '1'", filename); + } + + static DWORD fixups[4096]; + + if (header.fixup.size >= sizeof(fixups)) + { + Game::FS_FCloseFile(handle); + Game::Com_Error(1, "%s: fixup size too big", filename); + } + + header.main.buffer = (char*)malloc(header.main.size); + header.index.buffer = (char*)_aligned_malloc(header.index.size, 16); + header.vertex.buffer = (char*)_aligned_malloc(header.vertex.size, 16); + header.fixup.buffer = (char*)fixups; + + ReadCModelSection(handle, header.main); + ReadCModelSection(handle, header.index); + ReadCModelSection(handle, header.vertex); + ReadCModelSection(handle, header.fixup); + + Game::FS_FCloseFile(handle); + + FixupCModelSection(header, header.main, fixups); + FixupCModelSection(header, header.index, fixups); + FixupCModelSection(header, header.vertex, fixups); + + Game::CModelAllocData* allocationData = (Game::CModelAllocData*)malloc(sizeof(Game::CModelAllocData)); + allocationData->mainArray = header.main.buffer; + allocationData->indexBuffer = header.index.buffer; + allocationData->vertexBuffer = header.vertex.buffer; + + *(void**)(header.main.buffer + 44) = allocationData; + + // maybe the +36/48 = 0 stuff here? + + // move buffers to work with iw4 + int numSurfaces = *(short*)(header.main.buffer + 8); + + char* tempSurface = new char[84 * numSurfaces]; + char* surface = *(char**)(header.main.buffer + 4); + + for (int i = 0; i < numSurfaces; i++) + { + char* source = &surface[84 * i]; + char* dest = &tempSurface[64 * i]; + + memcpy(dest, source, 12); + memcpy(dest + 12, source + 16, 20); + memcpy(dest + 32, source + 40, 8); + memcpy(dest + 40, source + 52, 24); + + dest[6] = 0xFF; // fake stream handle for the vertex/index buffer get code to use + } + + memcpy(surface, tempSurface, 84 * numSurfaces); + + delete[] tempSurface; + + // create vertex/index buffers + CreateCModelBuffers(header.main.buffer); + + // store the buffer bit + ModelSurfs::AllocMap[header.vertex.buffer] = allocationData; + + return header.main.buffer; + } + bool ModelSurfs::LoadSurfaces(Game::XModel* model) { if (!model) return false; @@ -121,6 +354,9 @@ namespace Components short surfCount = 0; + static_assert(offsetof(Game::XModel, lods) == 64, ""); + static_assert(offsetof(Game::XModelLodInfo, surfs) == 36, ""); + for (char i = 0; i < model->numLods; ++i) { Game::XModelSurfs* surfs = model->lods[i].surfaces; @@ -139,12 +375,46 @@ namespace Components model->lods[i].someCount = numSurfs; model->lods[i].someTotalCount = surfCount; surfCount += numSurfs; + + changed = true; } } return changed; } + bool Load_XModelAssetHookFunc(char* xmodel) + { + bool didStuff = false; + short totalv = 0; + + for (int i = 0; i < xmodel[241]; i++) + { + Game::XModelSurfs* surfs = *(Game::XModelSurfs**)(xmodel + 72 + (44 * i)); + + if (!surfs->surfaces) + { + char* newSurfs = LoadCModel(surfs->name); + + memcpy(xmodel + 76 + (44 * i), &newSurfs[12], 24); + memcpy(xmodel + 100 + (44 * i), &newSurfs[4], 4); + + short v = *(short*)(newSurfs + 8); + *(short*)(xmodel + 68 + (44 * i)) = v; + *(short*)(xmodel + 70 + (44 * i)) = totalv; + + totalv += v; + + surfs->numSurfaces = ((Game::XModelSurfs*)newSurfs)->numSurfaces; + surfs->surfaces = ((Game::XModelSurfs*)newSurfs)->surfaces; + + didStuff = true; + } + } + + return didStuff; + } + void ModelSurfs::ReleaseModelSurf(Game::XAssetHeader header) { for (int i = 0; i < header.surfaces->numSurfaces && header.surfaces->surfaces; ++i) @@ -200,7 +470,8 @@ namespace Components void ModelSurfs::XModelSurfsFixup(Game::XModel* model) { - if (!ModelSurfs::LoadSurfaces(model)) + //if (!ModelSurfs::LoadSurfaces(model)) + if(!Load_XModelAssetHookFunc((char*)model)) { Game::DB_XModelSurfsFixup(model); } diff --git a/src/Components/Modules/ModelSurfs.hpp b/src/Components/Modules/ModelSurfs.hpp index 4a68f7b1..bbf8b864 100644 --- a/src/Components/Modules/ModelSurfs.hpp +++ b/src/Components/Modules/ModelSurfs.hpp @@ -10,7 +10,7 @@ namespace Components const char* GetName() { return "ModelSurfs"; }; #endif - private: + //private: static std::map BufferMap; static std::map AllocMap; diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index f28ff362..0863558f 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -1036,7 +1036,7 @@ namespace Components *(BYTE*)0x463D65 = (iw5) ? 0x90 : 0x40; *(DWORD*)0x463D66 = (iw5) ? 0x9004E0C1 : 0xC003C003; // shl eax, 4 instead of add eax, eax * 2 - // addon_map_ents asset type (we reuse it for weaponattach) + // addon_map_ents asset type (we reuse it for weaponattach) *(BYTE*)0x418B30 = (iw5) ? 43 : Game::ASSET_TYPE_ADDON_MAP_ENTS; // hooks @@ -1103,7 +1103,7 @@ namespace Components loadTechniquePassHook.Uninstall(); loadStructuredDataChildArrayHook.Uninstall(); - //xmodelDefaultHook.Uninstall(); + xmodelDefaultHook.Uninstall(); fxDefaultHook.Uninstall(); } } @@ -1114,19 +1114,12 @@ namespace Components PatchMW2_FifthInfinityApply(version, version >= 316); } - bool IgnoreEntityHookFunc(const char* entity) - { - return (!strncmp(entity, "dyn_", 4) || !strncmp(entity, "node_", 5) || !strncmp(entity, "actor_", 6)/* || !strncmp(entity, "weapon_", 7)*/); - } - Zones::Zones() { // Ignore missing soundaliases for now // TODO: Include them in the dependency zone! Utils::Hook::Nop(0x644207, 5); - Utils::Hook(0x5FBD6E, IgnoreEntityHookFunc).Install()->Quick(); - fxEffectTailHook.Initialize(fxEffectTailHookLoc, FxEffectTailHookStub, HOOK_CALL); fxEffectModifyHook.Initialize(fxEffectModifyHookLoc, FxEffectModifyHookFunc, HOOK_CALL); xLodTailHook.Initialize(xLodTailHookLoc, XModelLODTailHookStub, HOOK_CALL); From 23570ee64d4fa532a519f6953c5fa6abbcb531a8 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 19 Sep 2016 00:08:37 +0200 Subject: [PATCH 03/13] Pure mess, but maps load! A lot of cleanup and fixes need to be done! --- src/Components/Modules/AssetHandler.cpp | 14 +- src/Components/Modules/AssetHandler.hpp | 1 + src/Components/Modules/ModelSurfs.cpp | 278 ++++++++++++++++++++---- src/Components/Modules/Zones.cpp | 10 +- 4 files changed, 255 insertions(+), 48 deletions(-) diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index 95cf3e8e..3430ef08 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -155,6 +155,11 @@ namespace Components AssetHandler::RestrictSignal.connect(callback); } + void AssetHandler::ClearRelocations() + { + AssetHandler::Relocations.clear(); + } + void AssetHandler::Relocate(void* start, void* to, DWORD size) { for (DWORD i = 0; i < size; i += 4) @@ -167,12 +172,14 @@ namespace Components void AssetHandler::OffsetToAlias(Utils::Stream::Offset* offset) { // Same here, reinterpret the value, as we're operating inside the game's environment - offset->pointer = *reinterpret_cast((*Game::g_streamBlocks)[offset->GetUnpackedBlock()].data + offset->GetUnpackedOffset()); + void* pointer = (*Game::g_streamBlocks)[offset->GetUnpackedBlock()].data + offset->GetUnpackedOffset(); - if (AssetHandler::Relocations.find(offset->pointer) != AssetHandler::Relocations.end()) + if (AssetHandler::Relocations.find(pointer) != AssetHandler::Relocations.end()) { - offset->pointer = AssetHandler::Relocations[offset->pointer]; + pointer = AssetHandler::Relocations[pointer]; } + + offset->pointer = *reinterpret_cast(pointer); } void AssetHandler::ZoneSave(Game::XAsset asset, ZoneBuilder::Zone* builder) @@ -285,6 +292,7 @@ namespace Components delete i->second; } + AssetHandler::Relocations.clear(); AssetHandler::AssetInterfaces.clear(); AssetHandler::RestrictSignal.clear(); AssetHandler::TypeCallbacks.clear(); diff --git a/src/Components/Modules/AssetHandler.hpp b/src/Components/Modules/AssetHandler.hpp index b1ee949c..b04e0b7c 100644 --- a/src/Components/Modules/AssetHandler.hpp +++ b/src/Components/Modules/AssetHandler.hpp @@ -27,6 +27,7 @@ namespace Components static void OnFind(Game::XAssetType type, Callback* callback); static void OnLoad(RestrictCallback* callback); + static void ClearRelocations(); static void Relocate(void* start, void* to, DWORD size = 4); static void Relocate(DWORD start, DWORD size, DWORD to) { diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 208aec30..d4b48729 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -114,6 +114,9 @@ namespace Components return modelSurfs; } + + static std::map bufferMap; + Game::FS_FOpenFileRead_t FS_FOpenFileReadDatabase = (Game::FS_FOpenFileRead_t)0x42ECA0; void FS_FOpenFileReadCurrentThread(char* filename, int* handle) @@ -250,11 +253,20 @@ namespace Components Load_VertexBuffer(surface->vertexBuffer, &vertexBuffer, surface->numVertices * 32); Load_IndexBuffer(surface->indexBuffer, &indexBuffer, surface->numPrimitives * 3); - ModelSurfs::BufferMap[surface->vertexBuffer] = (IUnknown*)vertexBuffer; - ModelSurfs::BufferMap[surface->indexBuffer] = (IUnknown*)indexBuffer; + bufferMap[(DWORD)surface->vertexBuffer] = vertexBuffer; + bufferMap[(DWORD)surface->indexBuffer] = indexBuffer; } } + struct CModelAllocData + { + void* mainArray; + void* vertexBuffer; + void* indexBuffer; + }; + + static std::map allocData; + char* LoadCModel(const char* name) { char filename[512]; @@ -306,7 +318,7 @@ namespace Components FixupCModelSection(header, header.index, fixups); FixupCModelSection(header, header.vertex, fixups); - Game::CModelAllocData* allocationData = (Game::CModelAllocData*)malloc(sizeof(Game::CModelAllocData)); + CModelAllocData* allocationData = (CModelAllocData*)malloc(sizeof(CModelAllocData)); allocationData->mainArray = header.main.buffer; allocationData->indexBuffer = header.index.buffer; allocationData->vertexBuffer = header.vertex.buffer; @@ -342,46 +354,13 @@ namespace Components CreateCModelBuffers(header.main.buffer); // store the buffer bit - ModelSurfs::AllocMap[header.vertex.buffer] = allocationData; + allocData[(DWORD)header.vertex.buffer] = allocationData; return header.main.buffer; } - bool ModelSurfs::LoadSurfaces(Game::XModel* model) - { - if (!model) return false; - bool changed = false; - - short surfCount = 0; - - static_assert(offsetof(Game::XModel, lods) == 64, ""); - static_assert(offsetof(Game::XModelLodInfo, surfs) == 36, ""); - - for (char i = 0; i < model->numLods; ++i) - { - Game::XModelSurfs* surfs = model->lods[i].surfaces; - - if (!surfs->surfaces) - { - Game::XModelSurfs* newSurfs = ModelSurfs::LoadXModelSurfaces(surfs->name); - - surfs->surfaces = newSurfs->surfaces; - surfs->numSurfaces = newSurfs->numSurfaces; - - model->lods[i].surfaces = newSurfs; - memcpy(model->lods[i].pad3, newSurfs->pad, 24); - - short numSurfs = static_cast(newSurfs->numSurfaces); - model->lods[i].someCount = numSurfs; - model->lods[i].someTotalCount = surfCount; - surfCount += numSurfs; - - changed = true; - } - } - - return changed; - } + Utils::Hook loadXModelAssetHook; + DWORD loadXModelAssetHookLoc = 0x47A6BD; bool Load_XModelAssetHookFunc(char* xmodel) { @@ -415,6 +394,221 @@ namespace Components return didStuff; } +#pragma optimize("", off) + void __declspec(naked) Load_XModelAssetHookStub() + { + __asm + { + mov eax, [esp + 4] + push eax + call Load_XModelAssetHookFunc + add esp, 4h + + cmp al, al + jnz justReturn + + retn + + justReturn : + jmp loadXModelAssetHook.Original + } + } +#pragma optimize("", on) + + Utils::Hook getIndexBufferHook; + DWORD getIndexBufferHookLoc = 0x4B4DE0; + DWORD getIndexBufferHookRet = 0x4B4DE5; + + void GetIndexBufferHookFunc(char streamHandle, void* buffer, void** bufferOut, int* offsetOut) + { + *offsetOut = 0; + *bufferOut = bufferMap[(DWORD)buffer];//buffer; + } + +#pragma optimize("", off) + void __declspec(naked) GetIndexBufferHookStub() + { + __asm + { + mov eax, [esp + 4h] + cmp al, 0FFh + + je handleOwn + movzx eax, [esp + 4h] + jmp getIndexBufferHookRet + + handleOwn : + jmp GetIndexBufferHookFunc + } + } +#pragma optimize("", on) + + Utils::Hook getVertexBufferHook; + DWORD getVertexBufferHookLoc = 0x5BC050; + DWORD getVertexBufferHookRet = 0x5BC055; + + void GetVertexBufferHookFunc(char streamHandle, void* buffer, void** bufferOut, int* offsetOut) + { + *offsetOut = 0; + *bufferOut = bufferMap[(DWORD)buffer];//buffer; + } + +#pragma optimize("", off) + void __declspec(naked) GetVertexBufferHookStub() + { + __asm + { + mov eax, [esp + 4h] + cmp al, 0FFh + + je handleOwnVertex + movzx eax, [esp + 4h] + jmp getVertexBufferHookRet + + handleOwnVertex : + jmp GetVertexBufferHookFunc + } + } + + /*CallHook getIndexBuffer2Hook; + DWORD getIndexBuffer2HookLoc = 0x558F12; + + void* GetIndexBuffer2HookFunc(char streamHandle, void* buffer) + { + return buffer; + } + + void __declspec(naked) GetIndexBuffer2HookStub() + { + __asm + { + mov eax, [esp + 4h] + cmp al, 0FFh + + je handleOwn + movzx eax, [esp + 4h] + jmp getIndexBuffer2Hook.pOriginal + + handleOwn: + jmp GetIndexBuffer2HookFunc + } + }*/ + + Utils::Hook getIndexBuffer3Hook; + DWORD getIndexBuffer3HookLoc = 0x558E70; + + void* GetIndexBuffer3HookFunc(DWORD buffer) + { + return bufferMap[buffer]; + } + + void __declspec(naked) GetIndexBuffer3HookStub() + { + __asm + { + mov eax, [esp + 4h] + cmp al, 0FFh + + je handleOwn + movzx eax, [esp + 4h] + jmp getIndexBuffer3Hook.Original + + handleOwn : + mov eax, [edi + 0Ch] + push eax + call GetIndexBuffer3HookFunc + add esp, 4h + retn + } + } + + Utils::Hook getIndexBaseHook; + DWORD getIndexBaseHookLoc = 0x558F12; + + void __declspec(naked) GetIndexBaseHookStub() + { + __asm + { + mov eax, [esp + 4h] + cmp al, 0FFh + + je handleOwn + jmp getIndexBaseHook.Original + + handleOwn : + xor eax, eax + retn + } + } +#pragma optimize("", on) + + void PatchMW2_CModels() + { + loadXModelAssetHook.Initialize(loadXModelAssetHookLoc, Load_XModelAssetHookStub, HOOK_CALL); + loadXModelAssetHook.Install(); + + getIndexBufferHook.Initialize(getIndexBufferHookLoc, GetIndexBufferHookStub, HOOK_JUMP); + getIndexBufferHook.Install(); + + //getIndexBuffer2Hook.initialize(getIndexBuffer2HookLoc, GetIndexBuffer2HookStub); + //getIndexBuffer2Hook.installHook(); + + getIndexBuffer3Hook.Initialize(getIndexBuffer3HookLoc, GetIndexBuffer3HookStub, HOOK_CALL); + getIndexBuffer3Hook.Install(); + + getIndexBaseHook.Initialize(getIndexBaseHookLoc, GetIndexBaseHookStub, HOOK_CALL); + getIndexBaseHook.Install(); + + getVertexBufferHook.Initialize(getVertexBufferHookLoc, GetVertexBufferHookStub, HOOK_JUMP); + getVertexBufferHook.Install(); + + //*(DWORD*)0x799AC4 = (DWORD)DB_RemoveXModelSurfs; + + //getBoneIndexHook1.initialize(getBoneIndexHook1Loc, GetBoneIndexHookStub); + //getBoneIndexHook1.installHook(); + + //*(void**)0x4E3409 = CL_DObjCreateHookFunc; + + //updateDObjSetBitsHook.initialize(updateDObjSetBitsHookLoc, UpdateDObjSetBitsHookStub); + //updateDObjSetBitsHook.installHook(); + + //getBoneIndexHook2.initialize(getBoneIndexHook2Loc, GetBoneIndexHookStub); + //getBoneIndexHook2.installHook(); + } + + bool ModelSurfs::LoadSurfaces(Game::XModel* model) + { + if (!model) return false; + bool changed = false; + + short surfCount = 0; + + for (char i = 0; i < model->numLods; ++i) + { + Game::XModelSurfs* surfs = model->lods[i].surfaces; + + if (!surfs->surfaces) + { + Game::XModelSurfs* newSurfs = ModelSurfs::LoadXModelSurfaces(surfs->name); + + surfs->surfaces = newSurfs->surfaces; + surfs->numSurfaces = newSurfs->numSurfaces; + + model->lods[i].surfs = newSurfs->surfaces; + memcpy(model->lods[i].pad3, newSurfs->pad, 24); + + short numSurfs = static_cast(newSurfs->numSurfaces); + model->lods[i].someCount = numSurfs; + model->lods[i].someTotalCount = surfCount; + surfCount += numSurfs; + + changed = true; + } + } + + return changed; + } + void ModelSurfs::ReleaseModelSurf(Game::XAssetHeader header) { for (int i = 0; i < header.surfaces->numSurfaces && header.surfaces->surfaces; ++i) @@ -470,8 +664,8 @@ namespace Components void ModelSurfs::XModelSurfsFixup(Game::XModel* model) { - //if (!ModelSurfs::LoadSurfaces(model)) - if(!Load_XModelAssetHookFunc((char*)model)) + if (!ModelSurfs::LoadSurfaces(model)) + //if(!Load_XModelAssetHookFunc((char*)model)) { Game::DB_XModelSurfsFixup(model); } @@ -554,6 +748,8 @@ namespace Components ModelSurfs::ModelSurfs() { + PatchMW2_CModels(); + return; ModelSurfs::BufferMap.clear(); // Install release handler diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 0863558f..742727ed 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -1071,7 +1071,7 @@ namespace Components loadStructuredDataChildArrayHook.Install(); //xmodelDefaultHook.Install(); - fxDefaultHook.Install(); + //fxDefaultHook.Install(); } else { @@ -1102,15 +1102,14 @@ namespace Components loadTechniquePassHook.Uninstall(); loadStructuredDataChildArrayHook.Uninstall(); - - xmodelDefaultHook.Uninstall(); - fxDefaultHook.Uninstall(); } } void Zones::InstallPatches(int version) { Zones::ZoneVersion = version; + AssetHandler::ClearRelocations(); + PatchMW2_FifthInfinityApply(version, version >= 316); } @@ -1141,6 +1140,9 @@ namespace Components loadStructuredDataChildArrayHook.Initialize(loadStructuredDataChildArrayHookLoc, Load_StructuredDataChildArrayHookFunc, HOOK_CALL); pathDataTailHook.Initialize(pathDataTailHookLoc, PathDataTailHookFunc, HOOK_JUMP); + + // path_node_constant_t marking function; has some terrible string references + *(BYTE*)0x4F74B0 = 0xC3; } Zones::~Zones() From 83d6ab2d6bf8d497dd3ee1c1def3f8fddf7bf7bb Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 19 Sep 2016 20:18:36 +0200 Subject: [PATCH 04/13] Fix custom models and fix some memory leaks nta had --- src/Components/Modules/ModelSurfs.cpp | 510 ++------------------------ src/Components/Modules/ModelSurfs.hpp | 2 +- src/Components/Modules/Zones.cpp | 66 ++-- src/Game/Structs.hpp | 9 +- src/Utils/Memory.cpp | 14 + src/Utils/Memory.hpp | 3 + 6 files changed, 69 insertions(+), 535 deletions(-) diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index d4b48729..4b5d4db7 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -3,7 +3,7 @@ namespace Components { std::map ModelSurfs::BufferMap; - std::map ModelSurfs::AllocMap; + std::map ModelSurfs::AllocMap; IUnknown* ModelSurfs::GetBuffer(void* buffer) { @@ -90,14 +90,14 @@ namespace Components allocationData->indexBuffer = header.sectionHeader[Game::SECTION_INDEX].buffer; allocationData->vertexBuffer = header.sectionHeader[Game::SECTION_VERTEX].buffer; - ModelSurfs::AllocMap[allocationData->vertexBuffer] = allocationData; - *reinterpret_cast(reinterpret_cast(allocationData->mainArray) + 44) = allocationData; - Assert_Size(Game::XSurface, 64); Game::XModelSurfs* modelSurfs = reinterpret_cast(allocationData->mainArray); Game::XSurface* tempSurfaces = allocator.AllocateArray(modelSurfs->numSurfaces); char* surfaceData = reinterpret_cast(modelSurfs->surfaces); + ModelSurfs::AllocMap[modelSurfs->name] = allocationData; + *reinterpret_cast(reinterpret_cast(allocationData->mainArray) + 44) = allocationData; + for (int i = 0; i < modelSurfs->numSurfaces; ++i) { memcpy(&tempSurfaces[i], surfaceData + (i * 84), 12); @@ -114,473 +114,11 @@ namespace Components return modelSurfs; } - - static std::map bufferMap; - - Game::FS_FOpenFileRead_t FS_FOpenFileReadDatabase = (Game::FS_FOpenFileRead_t)0x42ECA0; - - void FS_FOpenFileReadCurrentThread(char* filename, int* handle) - { - if (GetCurrentThreadId() == *(DWORD*)0x1CDE7FC) - { - Game::FS_FOpenFileRead(filename, handle, 0); - } - else if (GetCurrentThreadId() == *(DWORD*)0x1CDE814) - { - FS_FOpenFileReadDatabase(filename, handle, 0); - } - else - { - *handle = NULL; - } - } - - struct CModelSectionHeader - { - int size; - int offset; - int fixupStart; - int fixupCount; - char* buffer; - }; - - struct CModelHeader - { - int version; - unsigned int signature; - CModelSectionHeader main; - CModelSectionHeader index; - CModelSectionHeader vertex; - CModelSectionHeader fixup; - }; - - void ReadCModelSection(int handle, CModelSectionHeader& header) - { - Game::FS_Seek(handle, header.offset, FS_SEEK_SET); - Game::FS_Read(header.buffer, header.size, handle); - } - - void FixupCModelSection(CModelHeader& header, CModelSectionHeader& section, DWORD* fixups) - { - for (int i = section.fixupStart; i < section.fixupStart + section.fixupCount; i++) - { - DWORD fixup = fixups[i]; - int targetSectionNum = fixup & 3; - CModelSectionHeader* targetSection; - - if (targetSectionNum == 0) - { - targetSection = &header.main; - } - else if (targetSectionNum == 1) - { - targetSection = &header.index; - } - else if (targetSectionNum == 2) - { - targetSection = &header.vertex; - } - - *(DWORD*)(section.buffer + (fixup >> 3)) += (DWORD)targetSection->buffer; - } - } - - void Load_VertexBuffer(void* data, void** where, int len) - { - DWORD func = 0x5112C0; - - __asm - { - push edi - - mov eax, len - mov edi, where - push data - - call func - - add esp, 4 - pop edi - } - } - - typedef void* (__cdecl * R_AllocStaticIndexBuffer_t)(void** store, int length); - R_AllocStaticIndexBuffer_t R_AllocStaticIndexBuffer = (R_AllocStaticIndexBuffer_t)0x51E7A0; - - void Load_IndexBuffer(void* data, void** storeHere, int count) - { - static Game::dvar_t* r_loadForRenderer = *(Game::dvar_t**)0x69F0ED4; - - if (r_loadForRenderer->current.boolean) - { - void* buffer = R_AllocStaticIndexBuffer(storeHere, 2 * count); - memcpy(buffer, data, 2 * count); - - if (IsBadReadPtr(storeHere, 4) || IsBadReadPtr(*storeHere, 4)) - { - Game::Com_Error(0, "Static index buffer allocation failed."); - } - - __asm - { - push ecx - mov ecx, storeHere - mov ecx, [ecx] - - mov eax, [ecx] - add eax, 30h - mov eax, [eax] - - push ecx - call eax - - pop ecx - } - } - } - - void CreateCModelBuffers(void* surfs) - { - Game::XModelSurfs* model = (Game::XModelSurfs*)surfs; - - for (int i = 0; i < model->numSurfaces; i++) - { - Game::XSurface* surface = &model->surfaces[i]; - - void* vertexBuffer; - void* indexBuffer; - - Load_VertexBuffer(surface->vertexBuffer, &vertexBuffer, surface->numVertices * 32); - Load_IndexBuffer(surface->indexBuffer, &indexBuffer, surface->numPrimitives * 3); - - bufferMap[(DWORD)surface->vertexBuffer] = vertexBuffer; - bufferMap[(DWORD)surface->indexBuffer] = indexBuffer; - } - } - - struct CModelAllocData - { - void* mainArray; - void* vertexBuffer; - void* indexBuffer; - }; - - static std::map allocData; - - char* LoadCModel(const char* name) - { - char filename[512]; - sprintf_s(filename, sizeof(filename), "models/%s", name); - - int handle; - FS_FOpenFileReadCurrentThread(filename, &handle); - - if (handle <= 0) - { - Game::Com_Error(1, "Error opening %s", filename); - } - - CModelHeader header; - - if (Game::FS_Read(&header, sizeof(header), handle) != sizeof(header)) - { - Game::FS_FCloseFile(handle); - Game::Com_Error(1, "%s: header could not be read", filename); - } - - if (header.version != 1) - { - Game::FS_FCloseFile(handle); - Game::Com_Error(1, "%s: header version is not '1'", filename); - } - - static DWORD fixups[4096]; - - if (header.fixup.size >= sizeof(fixups)) - { - Game::FS_FCloseFile(handle); - Game::Com_Error(1, "%s: fixup size too big", filename); - } - - header.main.buffer = (char*)malloc(header.main.size); - header.index.buffer = (char*)_aligned_malloc(header.index.size, 16); - header.vertex.buffer = (char*)_aligned_malloc(header.vertex.size, 16); - header.fixup.buffer = (char*)fixups; - - ReadCModelSection(handle, header.main); - ReadCModelSection(handle, header.index); - ReadCModelSection(handle, header.vertex); - ReadCModelSection(handle, header.fixup); - - Game::FS_FCloseFile(handle); - - FixupCModelSection(header, header.main, fixups); - FixupCModelSection(header, header.index, fixups); - FixupCModelSection(header, header.vertex, fixups); - - CModelAllocData* allocationData = (CModelAllocData*)malloc(sizeof(CModelAllocData)); - allocationData->mainArray = header.main.buffer; - allocationData->indexBuffer = header.index.buffer; - allocationData->vertexBuffer = header.vertex.buffer; - - *(void**)(header.main.buffer + 44) = allocationData; - - // maybe the +36/48 = 0 stuff here? - - // move buffers to work with iw4 - int numSurfaces = *(short*)(header.main.buffer + 8); - - char* tempSurface = new char[84 * numSurfaces]; - char* surface = *(char**)(header.main.buffer + 4); - - for (int i = 0; i < numSurfaces; i++) - { - char* source = &surface[84 * i]; - char* dest = &tempSurface[64 * i]; - - memcpy(dest, source, 12); - memcpy(dest + 12, source + 16, 20); - memcpy(dest + 32, source + 40, 8); - memcpy(dest + 40, source + 52, 24); - - dest[6] = 0xFF; // fake stream handle for the vertex/index buffer get code to use - } - - memcpy(surface, tempSurface, 84 * numSurfaces); - - delete[] tempSurface; - - // create vertex/index buffers - CreateCModelBuffers(header.main.buffer); - - // store the buffer bit - allocData[(DWORD)header.vertex.buffer] = allocationData; - - return header.main.buffer; - } - - Utils::Hook loadXModelAssetHook; - DWORD loadXModelAssetHookLoc = 0x47A6BD; - - bool Load_XModelAssetHookFunc(char* xmodel) - { - bool didStuff = false; - short totalv = 0; - - for (int i = 0; i < xmodel[241]; i++) - { - Game::XModelSurfs* surfs = *(Game::XModelSurfs**)(xmodel + 72 + (44 * i)); - - if (!surfs->surfaces) - { - char* newSurfs = LoadCModel(surfs->name); - - memcpy(xmodel + 76 + (44 * i), &newSurfs[12], 24); - memcpy(xmodel + 100 + (44 * i), &newSurfs[4], 4); - - short v = *(short*)(newSurfs + 8); - *(short*)(xmodel + 68 + (44 * i)) = v; - *(short*)(xmodel + 70 + (44 * i)) = totalv; - - totalv += v; - - surfs->numSurfaces = ((Game::XModelSurfs*)newSurfs)->numSurfaces; - surfs->surfaces = ((Game::XModelSurfs*)newSurfs)->surfaces; - - didStuff = true; - } - } - - return didStuff; - } - -#pragma optimize("", off) - void __declspec(naked) Load_XModelAssetHookStub() - { - __asm - { - mov eax, [esp + 4] - push eax - call Load_XModelAssetHookFunc - add esp, 4h - - cmp al, al - jnz justReturn - - retn - - justReturn : - jmp loadXModelAssetHook.Original - } - } -#pragma optimize("", on) - - Utils::Hook getIndexBufferHook; - DWORD getIndexBufferHookLoc = 0x4B4DE0; - DWORD getIndexBufferHookRet = 0x4B4DE5; - - void GetIndexBufferHookFunc(char streamHandle, void* buffer, void** bufferOut, int* offsetOut) - { - *offsetOut = 0; - *bufferOut = bufferMap[(DWORD)buffer];//buffer; - } - -#pragma optimize("", off) - void __declspec(naked) GetIndexBufferHookStub() - { - __asm - { - mov eax, [esp + 4h] - cmp al, 0FFh - - je handleOwn - movzx eax, [esp + 4h] - jmp getIndexBufferHookRet - - handleOwn : - jmp GetIndexBufferHookFunc - } - } -#pragma optimize("", on) - - Utils::Hook getVertexBufferHook; - DWORD getVertexBufferHookLoc = 0x5BC050; - DWORD getVertexBufferHookRet = 0x5BC055; - - void GetVertexBufferHookFunc(char streamHandle, void* buffer, void** bufferOut, int* offsetOut) - { - *offsetOut = 0; - *bufferOut = bufferMap[(DWORD)buffer];//buffer; - } - -#pragma optimize("", off) - void __declspec(naked) GetVertexBufferHookStub() - { - __asm - { - mov eax, [esp + 4h] - cmp al, 0FFh - - je handleOwnVertex - movzx eax, [esp + 4h] - jmp getVertexBufferHookRet - - handleOwnVertex : - jmp GetVertexBufferHookFunc - } - } - - /*CallHook getIndexBuffer2Hook; - DWORD getIndexBuffer2HookLoc = 0x558F12; - - void* GetIndexBuffer2HookFunc(char streamHandle, void* buffer) - { - return buffer; - } - - void __declspec(naked) GetIndexBuffer2HookStub() - { - __asm - { - mov eax, [esp + 4h] - cmp al, 0FFh - - je handleOwn - movzx eax, [esp + 4h] - jmp getIndexBuffer2Hook.pOriginal - - handleOwn: - jmp GetIndexBuffer2HookFunc - } - }*/ - - Utils::Hook getIndexBuffer3Hook; - DWORD getIndexBuffer3HookLoc = 0x558E70; - - void* GetIndexBuffer3HookFunc(DWORD buffer) - { - return bufferMap[buffer]; - } - - void __declspec(naked) GetIndexBuffer3HookStub() - { - __asm - { - mov eax, [esp + 4h] - cmp al, 0FFh - - je handleOwn - movzx eax, [esp + 4h] - jmp getIndexBuffer3Hook.Original - - handleOwn : - mov eax, [edi + 0Ch] - push eax - call GetIndexBuffer3HookFunc - add esp, 4h - retn - } - } - - Utils::Hook getIndexBaseHook; - DWORD getIndexBaseHookLoc = 0x558F12; - - void __declspec(naked) GetIndexBaseHookStub() - { - __asm - { - mov eax, [esp + 4h] - cmp al, 0FFh - - je handleOwn - jmp getIndexBaseHook.Original - - handleOwn : - xor eax, eax - retn - } - } -#pragma optimize("", on) - - void PatchMW2_CModels() - { - loadXModelAssetHook.Initialize(loadXModelAssetHookLoc, Load_XModelAssetHookStub, HOOK_CALL); - loadXModelAssetHook.Install(); - - getIndexBufferHook.Initialize(getIndexBufferHookLoc, GetIndexBufferHookStub, HOOK_JUMP); - getIndexBufferHook.Install(); - - //getIndexBuffer2Hook.initialize(getIndexBuffer2HookLoc, GetIndexBuffer2HookStub); - //getIndexBuffer2Hook.installHook(); - - getIndexBuffer3Hook.Initialize(getIndexBuffer3HookLoc, GetIndexBuffer3HookStub, HOOK_CALL); - getIndexBuffer3Hook.Install(); - - getIndexBaseHook.Initialize(getIndexBaseHookLoc, GetIndexBaseHookStub, HOOK_CALL); - getIndexBaseHook.Install(); - - getVertexBufferHook.Initialize(getVertexBufferHookLoc, GetVertexBufferHookStub, HOOK_JUMP); - getVertexBufferHook.Install(); - - //*(DWORD*)0x799AC4 = (DWORD)DB_RemoveXModelSurfs; - - //getBoneIndexHook1.initialize(getBoneIndexHook1Loc, GetBoneIndexHookStub); - //getBoneIndexHook1.installHook(); - - //*(void**)0x4E3409 = CL_DObjCreateHookFunc; - - //updateDObjSetBitsHook.initialize(updateDObjSetBitsHookLoc, UpdateDObjSetBitsHookStub); - //updateDObjSetBitsHook.installHook(); - - //getBoneIndexHook2.initialize(getBoneIndexHook2Loc, GetBoneIndexHookStub); - //getBoneIndexHook2.installHook(); - } - bool ModelSurfs::LoadSurfaces(Game::XModel* model) { if (!model) return false; - bool changed = false; + bool changed = false; short surfCount = 0; for (char i = 0; i < model->numLods; ++i) @@ -591,15 +129,15 @@ namespace Components { Game::XModelSurfs* newSurfs = ModelSurfs::LoadXModelSurfaces(surfs->name); - surfs->surfaces = newSurfs->surfaces; - surfs->numSurfaces = newSurfs->numSurfaces; + surfs->surfaces = newSurfs->surfaces; + surfs->numSurfaces = newSurfs->numSurfaces; model->lods[i].surfs = newSurfs->surfaces; memcpy(model->lods[i].pad3, newSurfs->pad, 24); short numSurfs = static_cast(newSurfs->numSurfaces); - model->lods[i].someCount = numSurfs; - model->lods[i].someTotalCount = surfCount; + model->lods[i].numSurfs = numSurfs; + model->lods[i].maxSurfs = surfCount; surfCount += numSurfs; changed = true; @@ -611,11 +149,15 @@ namespace Components void ModelSurfs::ReleaseModelSurf(Game::XAssetHeader header) { + bool hasCustomSurface = false; for (int i = 0; i < header.surfaces->numSurfaces && header.surfaces->surfaces; ++i) { Game::XSurface* surface = &header.surfaces->surfaces[i]; + if (surface->streamHandle == 0xFF) { + hasCustomSurface = true; + auto buffer = ModelSurfs::BufferMap.find(surface->indexBuffer); if (buffer != ModelSurfs::BufferMap.end()) { @@ -629,17 +171,20 @@ namespace Components buffer->second->Release(); ModelSurfs::BufferMap.erase(buffer); } + } + } - auto allocData = ModelSurfs::AllocMap.find(surface->vertexBuffer); - if (allocData != ModelSurfs::AllocMap.end()) - { - Utils::Memory::Free(allocData->second->indexBuffer); - Utils::Memory::Free(allocData->second->vertexBuffer); - Utils::Memory::Free(allocData->second->mainArray); - Utils::Memory::Free(allocData->second); + if (hasCustomSurface) + { + auto allocData = ModelSurfs::AllocMap.find(header.surfaces->name); + if (allocData != ModelSurfs::AllocMap.end()) + { + Utils::Memory::FreeAlign(allocData->second->indexBuffer); + Utils::Memory::FreeAlign(allocData->second->vertexBuffer); + Utils::Memory::Free(allocData->second->mainArray); + Utils::Memory::Free(allocData->second); - ModelSurfs::AllocMap.erase(allocData); - } + ModelSurfs::AllocMap.erase(allocData); } } } @@ -665,7 +210,6 @@ namespace Components void ModelSurfs::XModelSurfsFixup(Game::XModel* model) { if (!ModelSurfs::LoadSurfaces(model)) - //if(!Load_XModelAssetHookFunc((char*)model)) { Game::DB_XModelSurfsFixup(model); } @@ -748,8 +292,6 @@ namespace Components ModelSurfs::ModelSurfs() { - PatchMW2_CModels(); - return; ModelSurfs::BufferMap.clear(); // Install release handler @@ -762,7 +304,7 @@ namespace Components // Install hooks Utils::Hook(0x47A6BD, ModelSurfs::XModelSurfsFixup, HOOK_CALL).Install()->Quick(); Utils::Hook(0x558F12, ModelSurfs::GetIndexBaseStub, HOOK_CALL).Install()->Quick(); - Utils::Hook(0x5BC050, ModelSurfs::GetIndexBufferStub, HOOK_JUMP).Install()->Quick(); + Utils::Hook(0x4B4DE0, ModelSurfs::GetIndexBufferStub, HOOK_JUMP).Install()->Quick(); Utils::Hook(0x558E70, ModelSurfs::GetIndexBufferStub2, HOOK_CALL).Install()->Quick(); Utils::Hook(0x5BC050, ModelSurfs::GetVertexBufferStub, HOOK_JUMP).Install()->Quick(); } diff --git a/src/Components/Modules/ModelSurfs.hpp b/src/Components/Modules/ModelSurfs.hpp index bbf8b864..2f69f59d 100644 --- a/src/Components/Modules/ModelSurfs.hpp +++ b/src/Components/Modules/ModelSurfs.hpp @@ -12,7 +12,7 @@ namespace Components //private: static std::map BufferMap; - static std::map AllocMap; + static std::map AllocMap; static void ReleaseModelSurf(Game::XAssetHeader header); diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 742727ed..5162778f 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -8,7 +8,6 @@ namespace Components extern bool* useEntryNames; Utils::Hook fxEffectLoadHook; - DWORD fxEffectLoadHookLoc = 0x49591B; static DWORD fxEffectStringValue[64]; static int fxEffectIndex = 0; @@ -52,7 +51,6 @@ namespace Components } Utils::Hook fxEffectModifyHook; - DWORD fxEffectModifyHookLoc = 0x45ADA0; bool ignoreThisFx = false; @@ -97,7 +95,6 @@ namespace Components } Utils::Hook fxEffectTailHook; - DWORD fxEffectTailHookLoc = 0x495938; void FxEffectTailHookFunc() { @@ -146,7 +143,6 @@ namespace Components } Utils::Hook xModelModifyHook; - DWORD xModelModifyHookLoc = 0x410D90; void XModelModifyHookFunc(int a1, char* buffer, size_t len) { @@ -199,7 +195,6 @@ namespace Components } Utils::Hook xLodTailHook; - DWORD xLodTailHookLoc = 0x4EA6FE; void XModelLODTailHookFunc(int i) { @@ -240,7 +235,6 @@ namespace Components } Utils::Hook fxDefaultHook; - DWORD fxDefaultHookLoc = 0x4D9C0E; void FxDefaultHookFunc() { @@ -258,7 +252,6 @@ namespace Components } Utils::Hook xmodelDefaultHook; - DWORD xmodelDefaultHookLoc = 0x4FCAEE; void XModelDefaultHookFunc() { @@ -276,7 +269,6 @@ namespace Components } Utils::Hook xsurfaceIntLoadHook; - DWORD xsurfaceIntLoadHookLoc = 0x4925C8; void XSurfaceIntLoadHookFunc(int a1, char* buffer, size_t len) { @@ -315,7 +307,6 @@ namespace Components } Utils::Hook loadWeaponDefHook; - DWORD loadWeaponDefHookLoc = 0x47CCD2; typedef void(__cdecl * Load_Stream_t)(int load, DWORD ptr, int len); Load_Stream_t Load_Stream = (Load_Stream_t)0x470E30; @@ -661,7 +652,6 @@ namespace Components #define Load_XStringPtr Load_XStringPtr_ Utils::Hook gameWorldSpLoadHook; - DWORD gameWorldSpLoadHookLoc = 0x4F4D0D; void GameWorldSpLoadHookFunc(int a1, char* buffer, size_t len) { @@ -685,7 +675,6 @@ namespace Components } Utils::Hook pathDataTailHook; - DWORD pathDataTailHookLoc = 0x427A1B; void PathDataTailHookFunc() { @@ -715,7 +704,6 @@ namespace Components } Utils::Hook allocZoneMemoryHook; - DWORD allocZoneMemoryHookLoc = 0x415A57; void AllocXZoneMemoryHookFunc(unsigned int* sizes) { @@ -736,7 +724,6 @@ namespace Components } Utils::Hook sndAliasLoadHook; - DWORD sndAliasLoadHookLoc = 0x4F0AC8; void SndAliasLoadHookFunc(int a1, char* buffer, size_t len) { @@ -783,7 +770,6 @@ namespace Components } Utils::Hook mssSoundLoadHook; - DWORD mssSoundLoadHookLoc = 0x403A5D; void MssSoundLoadHookFunc(int a1, char* buffer, size_t len) { @@ -804,7 +790,6 @@ namespace Components } Utils::Hook vehicleLoadHook; - DWORD vehicleLoadHookLoc = 0x483DA0; void VehicleLoadHookFunc(int a1, char* buffer, int len) { @@ -829,7 +814,6 @@ namespace Components } Utils::Hook loadWeaponAttachHook; - DWORD loadWeaponAttachHookLoc = 0x463022; DWORD varWeaponAttachStuff; @@ -867,7 +851,6 @@ namespace Components } Utils::Hook menuDefLoadHook; - DWORD menuDefLoadHookLoc = 0x41A570; void MenuDefLoadHookFunc(int doLoad, char* buffer, int len) { @@ -910,7 +893,6 @@ namespace Components } Utils::Hook gameWorldSpIntHook; - DWORD gameWorldSpIntHookLoc = 0x4F4D3B; void GameWorldSpIntHookFunc(int doLoad) { @@ -936,7 +918,6 @@ namespace Components }; Utils::Hook loadTechniquePassHook; - DWORD loadTechniquePassHookLoc = 0x428F0A; void Load_TechniquePassHookFunc(int a1, MaterialArgumentDef* pass, size_t size) { @@ -980,7 +961,6 @@ namespace Components } Utils::Hook loadStructuredDataChildArrayHook; - DWORD loadStructuredDataChildArrayHookLoc = 0x4B1EB8; void Load_StructuredDataChildArrayHookFunc(int a1, char* data, size_t size) { @@ -1119,30 +1099,30 @@ namespace Components // TODO: Include them in the dependency zone! Utils::Hook::Nop(0x644207, 5); - fxEffectTailHook.Initialize(fxEffectTailHookLoc, FxEffectTailHookStub, HOOK_CALL); - fxEffectModifyHook.Initialize(fxEffectModifyHookLoc, FxEffectModifyHookFunc, HOOK_CALL); - xLodTailHook.Initialize(xLodTailHookLoc, XModelLODTailHookStub, HOOK_CALL); - xModelModifyHook.Initialize(xModelModifyHookLoc, XModelModifyHookFunc, HOOK_CALL); - xsurfaceIntLoadHook.Initialize(xsurfaceIntLoadHookLoc, XSurfaceIntLoadHookFunc, HOOK_CALL); - gameWorldSpLoadHook.Initialize(gameWorldSpLoadHookLoc, GameWorldSpLoadHookFunc, HOOK_CALL); - loadWeaponDefHook.Initialize(loadWeaponDefHookLoc, Load_WeaponDef_CodC, HOOK_CALL); - vehicleLoadHook.Initialize(vehicleLoadHookLoc, VehicleLoadHookFunc, HOOK_CALL); - xmodelDefaultHook.Initialize(xmodelDefaultHookLoc, XModelDefaultHookStub, HOOK_CALL); - fxDefaultHook.Initialize(fxDefaultHookLoc, FxDefaultHookStub, HOOK_CALL); - allocZoneMemoryHook.Initialize(allocZoneMemoryHookLoc, AllocXZoneMemoryHookStub, HOOK_CALL); - sndAliasLoadHook.Initialize(sndAliasLoadHookLoc, SndAliasLoadHookFunc, HOOK_CALL); - mssSoundLoadHook.Initialize(mssSoundLoadHookLoc, MssSoundLoadHookFunc, HOOK_CALL); - loadWeaponAttachHook.Initialize(loadWeaponAttachHookLoc, Load_WeaponAttach, HOOK_CALL); - menuDefLoadHook.Initialize(menuDefLoadHookLoc, MenuDefLoadHookFunc, HOOK_CALL); - fxEffectLoadHook.Initialize(fxEffectLoadHookLoc, FxEffectLoadHookFunc, HOOK_CALL); - gameWorldSpIntHook.Initialize(gameWorldSpIntHookLoc, GameWorldSpIntHookFunc, HOOK_CALL); - loadTechniquePassHook.Initialize(loadTechniquePassHookLoc, Load_TechniquePassHookFunc, HOOK_CALL); - loadStructuredDataChildArrayHook.Initialize(loadStructuredDataChildArrayHookLoc, Load_StructuredDataChildArrayHookFunc, HOOK_CALL); - - pathDataTailHook.Initialize(pathDataTailHookLoc, PathDataTailHookFunc, HOOK_JUMP); + // Block Mark_pathnode_constant_t + Utils::Hook::Set(0x4F74B0, 0xC3); - // path_node_constant_t marking function; has some terrible string references - *(BYTE*)0x4F74B0 = 0xC3; + fxEffectTailHook.Initialize(0x495938, FxEffectTailHookStub, HOOK_CALL); + fxEffectModifyHook.Initialize(0x45ADA0, FxEffectModifyHookFunc, HOOK_CALL); + xLodTailHook.Initialize(0x4EA6FE, XModelLODTailHookStub, HOOK_CALL); + xModelModifyHook.Initialize(0x410D90, XModelModifyHookFunc, HOOK_CALL); + xsurfaceIntLoadHook.Initialize(0x4925C8, XSurfaceIntLoadHookFunc, HOOK_CALL); + gameWorldSpLoadHook.Initialize(0x4F4D0D, GameWorldSpLoadHookFunc, HOOK_CALL); + loadWeaponDefHook.Initialize(0x47CCD2, Load_WeaponDef_CodC, HOOK_CALL); + vehicleLoadHook.Initialize(0x483DA0, VehicleLoadHookFunc, HOOK_CALL); + xmodelDefaultHook.Initialize(0x4FCAEE, XModelDefaultHookStub, HOOK_CALL); + fxDefaultHook.Initialize(0x4D9C0E, FxDefaultHookStub, HOOK_CALL); + allocZoneMemoryHook.Initialize(0x415A57, AllocXZoneMemoryHookStub, HOOK_CALL); + sndAliasLoadHook.Initialize(0x4F0AC8, SndAliasLoadHookFunc, HOOK_CALL); + mssSoundLoadHook.Initialize(0x403A5D, MssSoundLoadHookFunc, HOOK_CALL); + loadWeaponAttachHook.Initialize(0x463022, Load_WeaponAttach, HOOK_CALL); + menuDefLoadHook.Initialize(0x41A570, MenuDefLoadHookFunc, HOOK_CALL); + fxEffectLoadHook.Initialize(0x49591B, FxEffectLoadHookFunc, HOOK_CALL); + gameWorldSpIntHook.Initialize(0x4F4D3B, GameWorldSpIntHookFunc, HOOK_CALL); + loadTechniquePassHook.Initialize(0x428F0A, Load_TechniquePassHookFunc, HOOK_CALL); + loadStructuredDataChildArrayHook.Initialize(0x4B1EB8, Load_StructuredDataChildArrayHookFunc, HOOK_CALL); + + pathDataTailHook.Initialize(0x427A1B, PathDataTailHookFunc, HOOK_JUMP); } Zones::~Zones() diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 719c98d2..41df012c 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -1398,12 +1398,9 @@ namespace Game struct XModelLodInfo { - // I'm not sure if this is correct - short someCount; - short someTotalCount; - + char pad[4]; short numSurfs; // +4 - short pad2;// +6 + short maxSurfs;// +6 XModelSurfs* surfaces; // +8 char pad3[24]; XSurface* surfs; @@ -1532,8 +1529,6 @@ namespace Game PhysCollmap* physCollmap; }; // total size 304 - //static_assert(offsetof(XModel, lods) <= 70, ""); - struct CModelAllocData { void* mainArray; diff --git a/src/Utils/Memory.cpp b/src/Utils/Memory.cpp index 97f97674..dcf486b9 100644 --- a/src/Utils/Memory.cpp +++ b/src/Utils/Memory.cpp @@ -27,6 +27,7 @@ namespace Utils { if (data) { + OutputDebugStringA(Utils::String::VA("Free: %X\n", (DWORD)data)); free(data); } } @@ -36,6 +37,19 @@ namespace Utils Memory::Free(const_cast(data)); } + void Memory::FreeAlign(void* data) + { + if (data) + { + _aligned_free(data); + } + } + + void Memory::FreeAlign(const void* data) + { + Memory::FreeAlign(const_cast(data)); + } + // Complementary function for memset, which checks if memory is filled with a char bool Memory::IsSet(void* mem, char chr, size_t length) { diff --git a/src/Utils/Memory.hpp b/src/Utils/Memory.hpp index a4c83bfb..d6b98bb6 100644 --- a/src/Utils/Memory.hpp +++ b/src/Utils/Memory.hpp @@ -108,6 +108,9 @@ namespace Utils static void Free(void* data); static void Free(const void* data); + static void FreeAlign(void* data); + static void FreeAlign(const void* data); + static bool IsSet(void* mem, char chr, size_t length); }; } From 39110c9db7125252da802ec6a070d043248b6a65 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 19 Sep 2016 20:55:31 +0200 Subject: [PATCH 05/13] More cleanup --- src/Components/Modules/Logger.cpp | 6 +++++ src/Components/Modules/Maps.cpp | 14 +++++++++++- src/Components/Modules/Zones.cpp | 37 ++++++++++++++----------------- src/Utils/Memory.cpp | 1 - 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index 98aa5e30..e030dd0c 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -300,5 +300,11 @@ namespace Components Logger::MessageMutex.lock(); Logger::MessageQueue.clear(); Logger::MessageMutex.unlock(); + + // Flush the console log + if (int fh = *reinterpret_cast(0x1AD8F28)) + { + Game::FS_FCloseFile(fh); + } } } diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 8ceb7174..3e8a7a9a 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -93,6 +93,15 @@ namespace Components } } + if (type == Game::XAssetType::ASSET_TYPE_STRINGTABLE) + { + if (FastFiles::Current() == "mp_cross_fire") + { + *restrict = true; + return; + } + } + if (type == Game::XAssetType::ASSET_TYPE_MAP_ENTS) { static std::string mapEntities; @@ -117,7 +126,7 @@ namespace Components format = "maps/%s.d3dbsp"; } - if (_strnicmp("mp_", mapname, 3) || mapname == "mp_nuked"s || mapname == "mp_bloc"s) + if (_strnicmp("mp_", mapname, 3) || mapname == "mp_nuked"s || mapname == "mp_bloc"s || mapname == "mp_cargoship"s || mapname == "mp_cross_fire"s) { // Adjust pointer to GameMap_Data Utils::Hook::Set(0x4D90B7, &(Game::DB_XAssetPool[Game::XAssetType::ASSET_TYPE_GAME_MAP_SP].gameMapSP[0].data)); @@ -240,6 +249,9 @@ namespace Components Maps::AddDependency("co_hunted", "mp_storm"); Maps::AddDependency("mp_nuked", "iw4x_dependencies_mp"); Maps::AddDependency("mp_bloc", "iw4x_dependencies_mp"); + Maps::AddDependency("mp_bloc", "iw4x_dependencies_mp"); + Maps::AddDependency("mp_cargoship", "iw4x_dependencies_mp"); + Maps::AddDependency("mp_cross_fire", "iw4x_dependencies_mp"); Maps::AddDependency("^(?!mp_).*", "iw4x_dependencies_mp"); // All maps not starting with "mp_" } diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 5162778f..ed8b7c50 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -100,7 +100,7 @@ namespace Components { // varXString = (varFxEffect + 256) //*(DWORD*)0x112B340 = (*(DWORD*)0x112B018) + 256; - DWORD thisFX = *(DWORD*)0x112B018; + //DWORD thisFX = *(DWORD*)0x112B018; /*if (*(char*)(thisFX + 176) == 0 || *(char*)(thisFX + 176) == 4) { @@ -354,7 +354,7 @@ namespace Components //#define Load_XStringPtr(x) Load_XStringPtr_(x); DBG(("wF: %s\n", **(DWORD**)varXString)) #define Load_XStringPtr Load_XStringPtr_ - void Load_WeaponDef_CodC(int doLoad) + void Load_WeaponDef_CodC(int /*doLoad*/) { // setup structures we use DWORD varWeaponDef = *(DWORD*)0x112A9F4;//*(DWORD*)0x112AE14; @@ -825,7 +825,7 @@ namespace Components for (int i = 0; i < count; i++) { - DWORD* varXString = (DWORD*)0x112B340; + //DWORD* varXString = (DWORD*)0x112B340; if (varStuff[1] < 16 || varStuff[1] == 39) { @@ -870,7 +870,7 @@ namespace Components AssetHandler::Relocate((DWORD)buffer + 172, 232, (DWORD)buffer + 168); } - void Load_WeaponAttach(int doLoad) + void Load_WeaponAttach(int /*doLoad*/) { // setup structures we use DWORD varWeaponAttach = *(DWORD*)0x112ADE0;//*(DWORD*)0x112AE14; @@ -894,7 +894,7 @@ namespace Components Utils::Hook gameWorldSpIntHook; - void GameWorldSpIntHookFunc(int doLoad) + void GameWorldSpIntHookFunc(int /*doLoad*/) { memset(*(void**)0x112AD7C, 0, 40); } @@ -980,17 +980,6 @@ namespace Components { ffVersion = fileVersion; - // patch the expected version - int version = (iw5) ? 316 : 276; - - if (iw5 && fileVersion >= 318) - { - version = fileVersion; - } - - *(DWORD*)0x4158F4 = version; - *(DWORD*)0x4158FB = version; - // physpreset size *(BYTE*)0x49CE0A = (iw5) ? 68 : 44; @@ -1087,10 +1076,18 @@ namespace Components void Zones::InstallPatches(int version) { - Zones::ZoneVersion = version; - AssetHandler::ClearRelocations(); - - PatchMW2_FifthInfinityApply(version, version >= 316); + Zones::ZoneVersion = version; +// AssetHandler::ClearRelocations(); +// +// if (Zones::ZoneVersion == VERSION_ALPHA2 || Zones::ZoneVersion == VERSION_ALPHA3 || Zones::ZoneVersion == XFILE_VERSION) +// { +// Utils::Hook::Set(0x4158F4, version); +// Utils::Hook::Set(0x4158FB, version); +// } +// +// PatchMW2_FifthInfinityApply(version, version >= 316); +// +// AntiCheat::EmptyHash(); } Zones::Zones() diff --git a/src/Utils/Memory.cpp b/src/Utils/Memory.cpp index dcf486b9..7e56bd80 100644 --- a/src/Utils/Memory.cpp +++ b/src/Utils/Memory.cpp @@ -27,7 +27,6 @@ namespace Utils { if (data) { - OutputDebugStringA(Utils::String::VA("Free: %X\n", (DWORD)data)); free(data); } } From aa89132770c0097ea59824bcb4f644dd9c00066e Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 19 Sep 2016 21:16:26 +0200 Subject: [PATCH 06/13] Fix map looping --- deps/protobuf | 2 +- src/Components/Modules/Maps.cpp | 4 ++-- src/Components/Modules/Maps.hpp | 2 +- src/Components/Modules/Zones.cpp | 22 +++++++++++----------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/deps/protobuf b/deps/protobuf index c44ca26f..7b00595d 160000 --- a/deps/protobuf +++ b/deps/protobuf @@ -1 +1 @@ -Subproject commit c44ca26fe89ed8a81d3ee475a2ccc1797141dbce +Subproject commit 7b00595ddf8622ae429ef37de8ea2f44b6333ad0 diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 3e8a7a9a..a967aa3e 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -158,7 +158,7 @@ namespace Components Maps::DependencyList[expression] = zone; } - bool Maps::IgnoreEntityStub(const char* entity) + int Maps::IgnoreEntityStub(const char* entity) { return (Utils::String::StartsWith(entity, "dyn_") || Utils::String::StartsWith(entity, "node_") || Utils::String::StartsWith(entity, "actor_")); } @@ -223,7 +223,7 @@ namespace Components Utils::Hook(0x42C2AF, Maps::LoadMapZones, HOOK_CALL).Install()->Quick(); // Ignore SP entities - Utils::Hook(0x5FBD6E, Maps::IgnoreEntityStub, HOOK_CALL).Install()->Quick(); + Utils::Hook(0x444810, Maps::IgnoreEntityStub, HOOK_JUMP).Install()->Quick(); Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_GAME_MAP_SP, 1); Game::ReallocateAssetPool(Game::XAssetType::ASSET_TYPE_IMAGE, 7168); diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index a033ba3d..730e60b5 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -24,7 +24,7 @@ namespace Components static void OverrideMapEnts(Game::MapEnts* ents); - static bool IgnoreEntityStub(const char* entity); + static int IgnoreEntityStub(const char* entity); void ReallocateEntryPool(); }; diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index ed8b7c50..29608632 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -1077,17 +1077,17 @@ namespace Components void Zones::InstallPatches(int version) { Zones::ZoneVersion = version; -// AssetHandler::ClearRelocations(); -// -// if (Zones::ZoneVersion == VERSION_ALPHA2 || Zones::ZoneVersion == VERSION_ALPHA3 || Zones::ZoneVersion == XFILE_VERSION) -// { -// Utils::Hook::Set(0x4158F4, version); -// Utils::Hook::Set(0x4158FB, version); -// } -// -// PatchMW2_FifthInfinityApply(version, version >= 316); -// -// AntiCheat::EmptyHash(); + AssetHandler::ClearRelocations(); + + if (Zones::ZoneVersion == VERSION_ALPHA2 || Zones::ZoneVersion == VERSION_ALPHA3 || Zones::ZoneVersion == XFILE_VERSION) + { + Utils::Hook::Set(0x4158F4, version); + Utils::Hook::Set(0x4158FB, version); + } + + PatchMW2_FifthInfinityApply(version, version >= 316); + + AntiCheat::EmptyHash(); } Zones::Zones() From 61fcea77429034b5968377c8be2e05402e982248 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 19 Sep 2016 22:52:00 +0200 Subject: [PATCH 07/13] Some fixes and introduce FileReader --- src/Components/Modules/Download.cpp | 2 +- src/Components/Modules/FileSystem.cpp | 33 ++++++++--- src/Components/Modules/FileSystem.hpp | 25 ++++++-- src/Components/Modules/ModelSurfs.cpp | 2 +- src/Components/Modules/Zones.cpp | 85 ++++----------------------- src/Components/Modules/Zones.hpp | 2 +- 6 files changed, 61 insertions(+), 88 deletions(-) diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index e4d14444..66de47ff 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -532,7 +532,7 @@ namespace Components "\r\n", mimeType.data(), buffer.size()); mg_send(nc, buffer.data(), static_cast(buffer.size())); - } + } else { mg_printf(nc, diff --git a/src/Components/Modules/FileSystem.cpp b/src/Components/Modules/FileSystem.cpp index f11c3c3b..779a8b6a 100644 --- a/src/Components/Modules/FileSystem.cpp +++ b/src/Components/Modules/FileSystem.cpp @@ -2,30 +2,45 @@ namespace Components { - FileSystem::File::File(std::string file) : Name(file), Handle(0) + void FileSystem::File::Read() + { + char* buffer = nullptr; + int size = Game::FS_ReadFile(this->FilePath.data(), &buffer); + + this->Buffer.clear(); + + if (size >= 0) + { + this->Buffer.append(buffer, size); + Game::FS_FreeFile(buffer); + } + } + + + FileSystem::FileReader::FileReader(std::string file) : Name(file), Handle(0) { this->Size = Game::FS_FOpenFileRead(this->Name.data(), &this->Handle, 0); } - FileSystem::File::~File() + FileSystem::FileReader::~FileReader() { - if (this->Exists()) + if (this->Exists() && this->Handle) { Game::FS_FCloseFile(this->Handle); } } - bool FileSystem::File::Exists() + bool FileSystem::FileReader::Exists() { return (this->Size > 0); } - std::string FileSystem::File::GetName() + std::string FileSystem::FileReader::GetName() { return this->Name; } - std::string FileSystem::File::GetBuffer() + std::string FileSystem::FileReader::GetBuffer() { Utils::Memory::Allocator allocator; if (!this->Exists()) return std::string(); @@ -34,7 +49,7 @@ namespace Components this->Seek(0, FS_SEEK_SET); char* buffer = allocator.AllocateArray(this->Size); - if (!FileSystem::File::Read(buffer, this->Size)) + if (!this->Read(buffer, this->Size)) { this->Seek(position, FS_SEEK_SET); return std::string(); @@ -45,7 +60,7 @@ namespace Components return std::string(buffer, this->Size); } - bool FileSystem::File::Read(void* buffer, size_t size) + bool FileSystem::FileReader::Read(void* buffer, size_t size) { if (!this->Exists() || static_cast(this->Size) < size || Game::FS_Read(buffer, size, this->Handle) != static_cast(size)) { @@ -55,7 +70,7 @@ namespace Components return true; } - void FileSystem::File::Seek(int offset, int origin) + void FileSystem::FileReader::Seek(int offset, int origin) { if (this->Exists()) { diff --git a/src/Components/Modules/FileSystem.hpp b/src/Components/Modules/FileSystem.hpp index 554710db..37b43f44 100644 --- a/src/Components/Modules/FileSystem.hpp +++ b/src/Components/Modules/FileSystem.hpp @@ -4,12 +4,29 @@ namespace Components { public: - class File + class File + { + public: + File() {}; + File(std::string file) : FilePath(file) { this->Read(); }; + + bool Exists() { return !this->Buffer.empty(); }; + std::string GetName() { return this->FilePath; }; + std::string& GetBuffer() { return this->Buffer; }; + + private: + std::string FilePath; + std::string Buffer; + + void Read(); + }; + + class FileReader { public: - File() : Size(-1), Name(), Handle(0) {}; - File(std::string file); - ~File(); + FileReader() : Size(-1), Name(), Handle(0) {}; + FileReader(std::string file); + ~FileReader(); bool Exists(); std::string GetName(); diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 4b5d4db7..40433ec5 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -38,7 +38,7 @@ namespace Components Game::XModelSurfs* ModelSurfs::LoadXModelSurfaces(std::string name) { Utils::Memory::Allocator allocator; - FileSystem::File model(fmt::sprintf("models/%s", name.data())); + FileSystem::FileReader model(fmt::sprintf("models/%s", name.data())); if (!model.Exists()) { diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 29608632..3f8df669 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -2,18 +2,13 @@ namespace Components { - int Zones::ZoneVersion; - - - extern bool* useEntryNames; + int Zones::ZoneVersion; Utils::Hook fxEffectLoadHook; static DWORD fxEffectStringValue[64]; static int fxEffectIndex = 0; - int ffVersion = 0; - #define VERSION_ALPHA2 316 #define VERSION_ALPHA3 318//319 @@ -52,26 +47,16 @@ namespace Components Utils::Hook fxEffectModifyHook; - bool ignoreThisFx = false; - void FxEffectModifyHookFunc(int a1, char* buffer, size_t len) { char typeNum = *(char*)(buffer + 176); //DBG(("ot %i\n", typeNum)); - if (typeNum == 2) - { - ignoreThisFx = true; - } - else if (typeNum == 3) + if (typeNum == 3) { typeNum = 2; } - else if (typeNum == 4) - { - ignoreThisFx = true; - } else if (typeNum >= 5) { typeNum -= 2; @@ -155,7 +140,7 @@ namespace Components add esp, 0Ch } - int elSize = (ffVersion == VERSION_ALPHA2) ? 364 : 360; + int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360; static unsigned char tempVar[364]; memcpy(&tempVar[0], &buffer[0], 36); @@ -198,7 +183,7 @@ namespace Components void XModelLODTailHookFunc(int i) { - int elSize = (ffVersion == VERSION_ALPHA2) ? 364 : 360; + int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360; i = (4 - i)/* + 1*/; // varXString = (varXModel + 0x16C - (4 * i)) // where the above function parked the new xstring @@ -234,40 +219,6 @@ namespace Components } } - Utils::Hook fxDefaultHook; - - void FxDefaultHookFunc() - { - DWORD* varFxEffectDefPtr = *(DWORD**)0x112ACC0; - - *varFxEffectDefPtr = (DWORD)Game::DB_FindXAssetHeader(Game::ASSET_TYPE_FX, "misc/missing_fx").data; - } - - void __declspec(naked) FxDefaultHookStub() - { - __asm - { - jmp FxDefaultHookFunc - } - } - - Utils::Hook xmodelDefaultHook; - - void XModelDefaultHookFunc() - { - DWORD* varXModelPtr = *(DWORD**)0x112A934; - - *varXModelPtr = (DWORD)Game::DB_FindXAssetHeader(Game::ASSET_TYPE_XMODEL, "void").data; - } - - void __declspec(naked) XModelDefaultHookStub() - { - __asm - { - jmp XModelDefaultHookFunc - } - } - Utils::Hook xsurfaceIntLoadHook; void XSurfaceIntLoadHookFunc(int a1, char* buffer, size_t len) @@ -361,7 +312,7 @@ namespace Components DWORD* varXString = (DWORD*)0x112B340; // and do the stuff - Load_Stream(1, varWeaponDef, (ffVersion >= 318) ? 3156 : 3112); + Load_Stream(1, varWeaponDef, (Zones::ZoneVersion >= 318) ? 3156 : 3112); DB_PushStreamPos(3); @@ -426,7 +377,7 @@ namespace Components Load_SndAliasCustom(*varsnd_alias_list_name); } - if (ffVersion >= 318) + if (Zones::ZoneVersion >= 318) { for (int i = 0, offset = 1184; i < 2; i++, offset += 4) { @@ -536,7 +487,7 @@ namespace Components DWORD vec2 = DB_AllocStreamPos(3); *(DWORD*)(varWeaponDef + 2556) = vec2; - Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((ffVersion >= 318) ? 3076 : 3040))); + Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3076 : 3040))); } *varXString = varWeaponDef + 2552; @@ -547,7 +498,7 @@ namespace Components DWORD vec2 = DB_AllocStreamPos(3); *(DWORD*)(varWeaponDef + 2560) = vec2; - Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((ffVersion >= 318) ? 3078 : 3042))); + Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3078 : 3042))); } *varXString = varWeaponDef + 2640; @@ -595,7 +546,7 @@ namespace Components *varsnd_alias_list_name = varWeaponDef + 2904; // 2912 Load_SndAliasCustom(*varsnd_alias_list_name); - if (ffVersion >= 318) + if (Zones::ZoneVersion >= 318) { for (int i = 0, offset = 2972; i < 6; i++, offset += 4) { @@ -976,15 +927,13 @@ namespace Components } } - void PatchMW2_FifthInfinityApply(int fileVersion, bool iw5) + void PatchMW2_FifthInfinityApply(bool iw5) { - ffVersion = fileVersion; - // physpreset size *(BYTE*)0x49CE0A = (iw5) ? 68 : 44; // XModel size - *(DWORD*)0x410D8A = (iw5) ? ((ffVersion == VERSION_ALPHA2) ? 0x16C : 0x168) : 0x130; + *(DWORD*)0x410D8A = (iw5) ? ((Zones::ZoneVersion == VERSION_ALPHA2) ? 0x16C : 0x168) : 0x130; // XSurface size *(BYTE*)0x48E84A = (iw5) ? 48 : 36; @@ -1031,16 +980,13 @@ namespace Components loadWeaponAttachHook.Install(); - if (ffVersion >= VERSION_ALPHA3) + if (Zones::ZoneVersion >= VERSION_ALPHA3) { gameWorldSpIntHook.Install(); } loadTechniquePassHook.Install(); loadStructuredDataChildArrayHook.Install(); - - //xmodelDefaultHook.Install(); - //fxDefaultHook.Install(); } else { @@ -1064,9 +1010,6 @@ namespace Components loadWeaponAttachHook.Uninstall(); - xmodelDefaultHook.Uninstall(); - fxDefaultHook.Uninstall(); - gameWorldSpIntHook.Uninstall(); loadTechniquePassHook.Uninstall(); @@ -1085,7 +1028,7 @@ namespace Components Utils::Hook::Set(0x4158FB, version); } - PatchMW2_FifthInfinityApply(version, version >= 316); + PatchMW2_FifthInfinityApply(version >= 316); AntiCheat::EmptyHash(); } @@ -1107,8 +1050,6 @@ namespace Components gameWorldSpLoadHook.Initialize(0x4F4D0D, GameWorldSpLoadHookFunc, HOOK_CALL); loadWeaponDefHook.Initialize(0x47CCD2, Load_WeaponDef_CodC, HOOK_CALL); vehicleLoadHook.Initialize(0x483DA0, VehicleLoadHookFunc, HOOK_CALL); - xmodelDefaultHook.Initialize(0x4FCAEE, XModelDefaultHookStub, HOOK_CALL); - fxDefaultHook.Initialize(0x4D9C0E, FxDefaultHookStub, HOOK_CALL); allocZoneMemoryHook.Initialize(0x415A57, AllocXZoneMemoryHookStub, HOOK_CALL); sndAliasLoadHook.Initialize(0x4F0AC8, SndAliasLoadHookFunc, HOOK_CALL); mssSoundLoadHook.Initialize(0x403A5D, MssSoundLoadHookFunc, HOOK_CALL); diff --git a/src/Components/Modules/Zones.hpp b/src/Components/Modules/Zones.hpp index 84ab67bd..dffddf5b 100644 --- a/src/Components/Modules/Zones.hpp +++ b/src/Components/Modules/Zones.hpp @@ -12,7 +12,7 @@ namespace Components static void InstallPatches(int version); - private: + //private: static int ZoneVersion; }; } From 77f38525c4353706e1825a4b14d53d934b2b8019 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 20 Sep 2016 22:00:02 +0200 Subject: [PATCH 08/13] More zone stuff --- src/Components/Modules/AntiCheat.cpp | 7 +- src/Components/Modules/Logger.cpp | 15 + src/Components/Modules/Logger.hpp | 2 + src/Components/Modules/Zones.cpp | 512 ++++++++++----------------- src/Components/Modules/Zones.hpp | 3 + src/Game/Functions.cpp | 25 ++ src/Game/Functions.hpp | 51 +++ src/Game/Structs.hpp | 14 + src/Main.cpp | 2 +- 9 files changed, 298 insertions(+), 333 deletions(-) diff --git a/src/Components/Modules/AntiCheat.cpp b/src/Components/Modules/AntiCheat.cpp index ac994710..993f51f9 100644 --- a/src/Components/Modules/AntiCheat.cpp +++ b/src/Components/Modules/AntiCheat.cpp @@ -89,6 +89,7 @@ namespace Components void AntiCheat::CrashClient() { #ifdef DEBUG_DETECTIONS + Logger::Flush(); MessageBoxA(0, "Check the log for more information!", "AntiCheat triggered", MB_ICONERROR); ExitProcess(0xFFFFFFFF); #else @@ -217,8 +218,8 @@ namespace Components if (lastCheck) count = 0; else ++count; - // If there was no check within the last 120 seconds, crash! - if ((milliseconds > 1000 * 25) && ((lastCheck && (milliseconds - lastCheck) > 1000 * 40) || count > 1)) + // If there was no check within the last 40 seconds, crash! + if ((milliseconds > 1000 * 40) && ((lastCheck && (milliseconds - lastCheck) > 1000 * 40) || count > 1)) { #ifdef DEBUG_DETECTIONS Logger::Print("AntiCheat: Integrity check failed"); @@ -260,7 +261,7 @@ namespace Components void AntiCheat::Frame() { - // Perform check only every 30 seconds + // Perform check only every 10 seconds if (AntiCheat::LastCheck && (Game::Sys_Milliseconds() - AntiCheat::LastCheck) < 1000 * 10) return; AntiCheat::LastCheck = Game::Sys_Milliseconds(); diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index e030dd0c..e025e4c3 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -83,6 +83,21 @@ namespace Components return buffer; } + void Logger::Flush() + { + if (!Game::Sys_IsMainThread()) + { + while (!Logger::MessageQueue.empty()) + { + std::this_thread::sleep_for(10ms); + } + } + else + { + Logger::Frame(); + } + } + void Logger::Frame() { std::lock_guard _(Logger::MessageMutex); diff --git a/src/Components/Modules/Logger.hpp b/src/Components/Modules/Logger.hpp index 47e9fca8..1628a619 100644 --- a/src/Components/Modules/Logger.hpp +++ b/src/Components/Modules/Logger.hpp @@ -23,6 +23,8 @@ namespace Components static void PipeOutput(void(*callback)(std::string)); + static void Flush(); + private: static std::mutex MessageMutex; static std::vector MessageQueue; diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 3f8df669..84e0c030 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -9,9 +9,6 @@ namespace Components static DWORD fxEffectStringValue[64]; static int fxEffectIndex = 0; -#define VERSION_ALPHA2 316 -#define VERSION_ALPHA3 318//319 - void FxEffectLoadHookFunc(int a1, char* buffer, int len) { len /= 252; @@ -83,26 +80,7 @@ namespace Components void FxEffectTailHookFunc() { - // varXString = (varFxEffect + 256) - //*(DWORD*)0x112B340 = (*(DWORD*)0x112B018) + 256; - //DWORD thisFX = *(DWORD*)0x112B018; - - /*if (*(char*)(thisFX + 176) == 0 || *(char*)(thisFX + 176) == 4) - { - Material* material = *(Material**)(thisFX + 188); - - if (material && ((DWORD)material) != 0x3F800000) - { - //DBG(("%s\n", material->name)); - } - else - { - *(void**)(thisFX + 188) = DB_FindXAssetHeader(ASSET_TYPE_MATERIAL, "$default"); - //DBG(("!!nullmat!!\n")); - } - }*/ - - *(DWORD**)0x112B340 = &fxEffectStringValue[fxEffectIndex++]; + *Game::varXString = (char*)&fxEffectStringValue[fxEffectIndex++]; // Load_XStringPtr(0) __asm @@ -171,12 +149,6 @@ namespace Components tempVar[307] = 0xDE; memcpy(buffer, tempVar, elSize); - - /*void* grenade = DB_FindXAssetHeader(ASSET_TYPE_XMODELSURFS, "us_smoke_grenade_proj10"); - *(void**)(buffer + 72) = grenade; - *(void**)(buffer + 72 + 44) = grenade; - *(void**)(buffer + 72 + 88) = grenade; - *(void**)(buffer + 72 + 88 + 44) = grenade;*/ } Utils::Hook xLodTailHook; @@ -187,17 +159,9 @@ namespace Components i = (4 - i)/* + 1*/; // varXString = (varXModel + 0x16C - (4 * i)) // where the above function parked the new xstring - *(DWORD*)0x112B340 = ((*(DWORD*)0x112AE14) + (elSize - 4)) - (4 * i); + *Game::varXString = (char*)((*(DWORD*)0x112AE14) + (elSize - 4)) - (4 * i); - // Load_XStringPtr(0) - __asm - { - mov eax, 47FDA0h - - push 0 - call eax - add esp, 4h - } + Game::Load_XString(false); } void __declspec(naked) XModelLODTailHookStub() @@ -259,130 +223,83 @@ namespace Components Utils::Hook loadWeaponDefHook; - typedef void(__cdecl * Load_Stream_t)(int load, DWORD ptr, int len); - Load_Stream_t Load_Stream = (Load_Stream_t)0x470E30; - - typedef DWORD(__cdecl * DB_PushStreamPos_t)(int block); - DB_PushStreamPos_t DB_PushStreamPos = (DB_PushStreamPos_t)0x458A20; - - typedef void(__cdecl * DB_PopStreamPos_t)(); - DB_PopStreamPos_t DB_PopStreamPos = (DB_PopStreamPos_t)0x4D1D60; - - typedef DWORD(__cdecl * Load_XStringPtr_t)(int a1); - Load_XStringPtr_t Load_XStringPtr = (Load_XStringPtr_t)0x47FDA0; - Load_XStringPtr_t Load_XStringPtr_ = (Load_XStringPtr_t)0x47FDA0; - - DWORD* varXModelPtr = (DWORD*)0x112A934; - Load_XStringPtr_t Load_XModelPtr = (Load_XStringPtr_t)0x4FCA70; - - typedef void(__cdecl * Load_XString_t)(int a1, int count); - DWORD* varXString_ = (DWORD*)0x112B340; - Load_XString_t Load_XString = (Load_XString_t)0x4977F0; - - typedef void(__cdecl * Load_XStringData_t)(DWORD* target); - DWORD* varXStringData = (DWORD*)0x112A774; - Load_XStringData_t Load_XStringData = (Load_XStringData_t)0x4E0DD0; - - DWORD* varFxEffectDefPtr = (DWORD*)0x112ACC0; - Load_XStringPtr_t Load_FxEffectDefPtr = (Load_XStringPtr_t)0x4D9B90; - - typedef void(__cdecl * Load_SndAliasCustom_t)(DWORD); - DWORD* varsnd_alias_list_name = (DWORD*)0x112AF38; - Load_SndAliasCustom_t Load_SndAliasCustom = (Load_SndAliasCustom_t)0x49B6B0; - - DWORD* varMaterialPtr = (DWORD*)0x112A878; - Load_XStringPtr_t Load_MaterialPtr = (Load_XStringPtr_t)0x403960; - - DWORD* varPhysCollmapPtr = (DWORD*)0x112B440; - Load_XStringPtr_t Load_PhysCollmapPtr = (Load_XStringPtr_t)0x47E990; - - DWORD* varTracerPtr = (DWORD*)0x112B3BC; - Load_XStringPtr_t Load_TracerPtr = (Load_XStringPtr_t)0x493090; - - Load_XStringPtr_t DB_AllocStreamPos = (Load_XStringPtr_t)0x418380; - Load_XString_t _load_lookupMultipleSounds = (Load_XString_t)0x4499F0; - - //#define Load_XStringPtr(x) Load_XStringPtr_(x); DBG(("wF: %s\n", **(DWORD**)varXString)) -#define Load_XStringPtr Load_XStringPtr_ - void Load_WeaponDef_CodC(int /*doLoad*/) { // setup structures we use DWORD varWeaponDef = *(DWORD*)0x112A9F4;//*(DWORD*)0x112AE14; - DWORD* varXString = (DWORD*)0x112B340; // and do the stuff - Load_Stream(1, varWeaponDef, (Zones::ZoneVersion >= 318) ? 3156 : 3112); + Game::Load_Stream(1, (void*)varWeaponDef, (Zones::ZoneVersion >= 318) ? 3156 : 3112); - DB_PushStreamPos(3); + Game::DB_PushStreamPos(3); - *varXString = varWeaponDef + 0; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 0; + Game::Load_XString(false); - *varXString = varWeaponDef + 4; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 4; + Game::Load_XString(false); - *varXString = varWeaponDef + 8; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 8; + Game::Load_XString(false); - *varXString = varWeaponDef + 12; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 12; + Game::Load_XString(false); - *varXModelPtr = varWeaponDef + 16; - Load_XModelPtr(0); + *Game::varXModelPtr = (Game::XModel*)(varWeaponDef + 16); + Game::Load_XModelPtr(false); for (int i = 0, offset = 20; i < 32; i++, offset += 4) { - *varXModelPtr = varWeaponDef + offset; - Load_XModelPtr(0); + *Game::varXModelPtr = (Game::XModel*)(varWeaponDef + offset); + Game::Load_XModelPtr(false); } // 148 for (int offset = 148; offset <= 168; offset += 4) { - *varXModelPtr = varWeaponDef + offset; - Load_XModelPtr(0); + *Game::varXModelPtr = (Game::XModel*)(varWeaponDef + offset); + Game::Load_XModelPtr(false); } // 172 // 32 scriptstrings, should not need to be loaded // 236 - *varXString_ = varWeaponDef + 236; - Load_XString(0, 48); + *Game::varXString = (char*)varWeaponDef + 236; + Game::Load_XStringArray(false, 48); // 428 - *varXString_ = varWeaponDef + 428; - Load_XString(0, 48); + *Game::varXString = (char*)varWeaponDef + 428; + Game::Load_XStringArray(false, 48); // 620 - *varXString_ = varWeaponDef + 620; - Load_XString(0, 48); + *Game::varXString = (char*)varWeaponDef + 620; + Game::Load_XStringArray(false, 48); // 812 // 16 * 4 scriptstrings // 972 - *varFxEffectDefPtr = varWeaponDef + 972; - Load_FxEffectDefPtr(0); + *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 972);; + Game::Load_FxEffectDefHandle(false); - *varFxEffectDefPtr = varWeaponDef + 976; - Load_FxEffectDefPtr(0); + *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 976); + Game::Load_FxEffectDefHandle(false); // 980 // 50 soundalias name references; up to and including 1180 for (int i = 0, offset = 980; i < 50; i++, offset += 4) { - *varsnd_alias_list_name = varWeaponDef + offset; - Load_SndAliasCustom(*varsnd_alias_list_name); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + offset); + Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } if (Zones::ZoneVersion >= 318) { for (int i = 0, offset = 1184; i < 2; i++, offset += 4) { - *varsnd_alias_list_name = varWeaponDef + offset; - Load_SndAliasCustom(*varsnd_alias_list_name); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + offset); + Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } varWeaponDef += 8; // to compensate for the 2 in between here @@ -392,10 +309,10 @@ namespace Components { if (*(DWORD*)(varWeaponDef + 1184) == -1) { - *(DWORD*)(varWeaponDef + 1184) = DB_AllocStreamPos(3); - *varsnd_alias_list_name = *(DWORD*)(varWeaponDef + 1184); + *(DWORD*)(varWeaponDef + 1184) = (DWORD)Game::DB_AllocStreamPos(3); + *Game::varsnd_alias_list_name = *(Game::snd_alias_list_t***)(varWeaponDef + 1184); - _load_lookupMultipleSounds(1, 31); + Game::Load_snd_alias_list_nameArray(true, 31); } else { @@ -407,10 +324,10 @@ namespace Components { if (*(DWORD*)(varWeaponDef + 1188) == -1) { - *(DWORD*)(varWeaponDef + 1188) = DB_AllocStreamPos(3); - *varsnd_alias_list_name = *(DWORD*)(varWeaponDef + 1188); + *(DWORD*)(varWeaponDef + 1188) = (DWORD)Game::DB_AllocStreamPos(3); + *Game::varsnd_alias_list_name = *(Game::snd_alias_list_t***)(varWeaponDef + 1188); - _load_lookupMultipleSounds(1, 31); + Game::Load_snd_alias_list_nameArray(true, 31); } else { @@ -421,137 +338,137 @@ namespace Components // 1192 for (int offset = 1192; offset <= 1204; offset += 4) { - *varFxEffectDefPtr = varWeaponDef + offset; - Load_FxEffectDefPtr(0); + *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + offset); + Game::Load_FxEffectDefHandle(false); } // 1208 - int matOffsets1[] = { 1208, 1212, 1428, 1432, 1436, 1440, 1444, 1448, 1456, 1464 }; + static int matOffsets1[] = { 1208, 1212, 1428, 1432, 1436, 1440, 1444, 1448, 1456, 1464 }; for (int i = 0; i < sizeof(matOffsets1) / sizeof(int); i++) { - *varMaterialPtr = varWeaponDef + matOffsets1[i]; - Load_MaterialPtr(0); + *Game::varMaterialHandle = (Game::Material*)(varWeaponDef + matOffsets1[i]); + Game::Load_MaterialHandle(false); } - *varXString = varWeaponDef + 1484; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 1484; + Game::Load_XString(false); - *varXString = varWeaponDef + 1492; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 1492; + Game::Load_XString(false); - *varXString = varWeaponDef + 1508; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 1508; + Game::Load_XString(false); for (int offset = 1764; offset <= 1776; offset += 4) { - *varMaterialPtr = varWeaponDef + offset; - Load_MaterialPtr(0); + *Game::varMaterialHandle = (Game::Material*)(varWeaponDef + offset); + Game::Load_MaterialHandle(false); } - *varPhysCollmapPtr = varWeaponDef + 1964; - Load_PhysCollmapPtr(0); + *Game::varPhysCollmapPtr = (Game::PhysCollmap*)(varWeaponDef + 1964); + Game::Load_PhysCollmapPtr(0); - *varXModelPtr = varWeaponDef + 2052; - Load_XModelPtr(0); + *Game::varXModelPtr = (Game::XModel*)(varWeaponDef + 2052); + Game::Load_XModelPtr(0); - *varFxEffectDefPtr = varWeaponDef + 2060; - Load_FxEffectDefPtr(0); + *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 2060); + Game::Load_FxEffectDefHandle(false); - *varFxEffectDefPtr = varWeaponDef + 2064; - Load_FxEffectDefPtr(0); + *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 2064); + Game::Load_FxEffectDefHandle(false); - *varsnd_alias_list_name = varWeaponDef + 2068; - Load_SndAliasCustom(*varsnd_alias_list_name); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2068); + Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); - *varsnd_alias_list_name = varWeaponDef + 2072; - Load_SndAliasCustom(*varsnd_alias_list_name); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2072); + Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); - *varFxEffectDefPtr = varWeaponDef + 2336; - Load_FxEffectDefPtr(0); + *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 2336); + Game::Load_FxEffectDefHandle(false); - *varFxEffectDefPtr = varWeaponDef + 2340; - Load_FxEffectDefPtr(0); + *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 2340); + Game::Load_FxEffectDefHandle(false); - *varFxEffectDefPtr = varWeaponDef + 2368; // 2376 - Load_FxEffectDefPtr(0); + *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 2368); // 2376 + Game::Load_FxEffectDefHandle(false); - *varsnd_alias_list_name = varWeaponDef + 2372; // 2380 - Load_SndAliasCustom(*varsnd_alias_list_name); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2372); // 2380 + Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); - *varXString = varWeaponDef + 2548; // 2556 - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2548; // 2556 + Game::Load_XString(false); if (*(DWORD*)(varWeaponDef + 2556) == -1) // 2564 { - DWORD vec2 = DB_AllocStreamPos(3); + DWORD vec2 = (DWORD)Game::DB_AllocStreamPos(3); *(DWORD*)(varWeaponDef + 2556) = vec2; - Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3076 : 3040))); + Game::Load_Stream(1, (void*)vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3076 : 3040))); } - *varXString = varWeaponDef + 2552; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2552; + Game::Load_XString(false); if (*(DWORD*)(varWeaponDef + 2560) == -1) { - DWORD vec2 = DB_AllocStreamPos(3); + DWORD vec2 = (DWORD)Game::DB_AllocStreamPos(3); *(DWORD*)(varWeaponDef + 2560) = vec2; - Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3078 : 3042))); + Game::Load_Stream(1, (void*)vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3078 : 3042))); } - *varXString = varWeaponDef + 2640; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2640; + Game::Load_XString(false); - *varXString = varWeaponDef + 2644; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2644; + Game::Load_XString(false); - *varXString = varWeaponDef + 2676; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2676; + Game::Load_XString(false); - *varXString = varWeaponDef + 2680; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2680; + Game::Load_XString(false); - *varXString = varWeaponDef + 2804; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2804; + Game::Load_XString(false); - *varXString = varWeaponDef + 2808; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2808; + Game::Load_XString(false); - *varTracerPtr = varWeaponDef + 2812; - Load_TracerPtr(0); + *Game::varTracerDefPtr = (Game::TracerDef*)(varWeaponDef + 2812); + Game::Load_TracerDefPtr(false); - *varsnd_alias_list_name = varWeaponDef + 2840; - Load_SndAliasCustom(*varsnd_alias_list_name); // 2848 + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2840); + Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); // 2848 - *varFxEffectDefPtr = varWeaponDef + 2844; - Load_FxEffectDefPtr(0); + *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 2844); + Game::Load_FxEffectDefHandle(false); - *varXString = varWeaponDef + 2848; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2848; + Game::Load_XString(false); - *varsnd_alias_list_name = varWeaponDef + 2864; - Load_SndAliasCustom(*varsnd_alias_list_name); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2864); + Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); - *varsnd_alias_list_name = varWeaponDef + 2868; - _load_lookupMultipleSounds(0, 4); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2868); + Game::Load_snd_alias_list_nameArray(false, 4); - *varsnd_alias_list_name = varWeaponDef + 2884; - _load_lookupMultipleSounds(0, 4); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2884); + Game::Load_snd_alias_list_nameArray(false, 4); - *varsnd_alias_list_name = varWeaponDef + 2900; - Load_SndAliasCustom(*varsnd_alias_list_name); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2900); + Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); - *varsnd_alias_list_name = varWeaponDef + 2904; // 2912 - Load_SndAliasCustom(*varsnd_alias_list_name); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2904); // 2912 + Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); if (Zones::ZoneVersion >= 318) { for (int i = 0, offset = 2972; i < 6; i++, offset += 4) { - *varsnd_alias_list_name = varWeaponDef + offset; - Load_SndAliasCustom(*varsnd_alias_list_name); + *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + offset); + Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); } varWeaponDef += (6 * 4); @@ -562,46 +479,43 @@ namespace Components } - *varXString = varWeaponDef + 2984; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2984; + Game::Load_XString(false); - *varXString = varWeaponDef + 2996; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 2996; + Game::Load_XString(false); - *varXString = varWeaponDef + 3000; - Load_XStringPtr(0); + *Game::varXString = (char*)varWeaponDef + 3000; + Game::Load_XString(false); - *varMaterialPtr = varWeaponDef + 3008; - Load_MaterialPtr(0); + *Game::varMaterialHandle = (Game::Material*)(varWeaponDef + 3008); + Game::Load_MaterialHandle(false); - *varMaterialPtr = varWeaponDef + 3012; - Load_MaterialPtr(0); + *Game::varMaterialHandle = (Game::Material*)(varWeaponDef + 3012); + Game::Load_MaterialHandle(false); - *varMaterialPtr = varWeaponDef + 3016; - Load_MaterialPtr(0); + *Game::varMaterialHandle = (Game::Material*)(varWeaponDef + 3016); + Game::Load_MaterialHandle(false); if (*(DWORD*)(varWeaponDef + 3044) == -1) { - DWORD vec2 = DB_AllocStreamPos(3); + DWORD vec2 = (DWORD)Game::DB_AllocStreamPos(3); *(DWORD*)(varWeaponDef + 3044) = vec2; - Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + 3040)); + Game::Load_Stream(1, (void*)vec2, 8 * *(short*)(varWeaponDef + 3040)); } if (*(DWORD*)(varWeaponDef + 3048) == -1) { - DWORD vec2 = DB_AllocStreamPos(3); + DWORD vec2 = (DWORD)Game::DB_AllocStreamPos(3); *(DWORD*)(varWeaponDef + 3048) = vec2; - Load_Stream(1, vec2, 8 * *(short*)(varWeaponDef + 3042)); + Game::Load_Stream(1, (void*)vec2, 8 * *(short*)(varWeaponDef + 3042)); } - DB_PopStreamPos(); + Game::DB_PopStreamPos(); } -#undef Load_XStringPtr -#define Load_XStringPtr Load_XStringPtr_ - Utils::Hook gameWorldSpLoadHook; void GameWorldSpLoadHookFunc(int a1, char* buffer, size_t len) @@ -634,43 +548,23 @@ namespace Components if (*(DWORD*)(varStuff + 56)) { - *(DWORD*)(varStuff + 56) = DB_AllocStreamPos(0); + *(DWORD*)(varStuff + 56) = (DWORD)Game::DB_AllocStreamPos(0); varThing = *(DWORD*)(varStuff + 56); - Load_Stream(1, varThing, *(DWORD*)(varStuff + 52)); + Game::Load_Stream(1, (void*)varThing, *(DWORD*)(varStuff + 52)); } if (*(DWORD*)(varStuff + 64)) { - *(DWORD*)(varStuff + 64) = DB_AllocStreamPos(0); + *(DWORD*)(varStuff + 64) = (DWORD)Game::DB_AllocStreamPos(0); varThing = *(DWORD*)(varStuff + 64); - Load_Stream(1, varThing, *(DWORD*)(varStuff + 60)); + Game::Load_Stream(1, (void*)varThing, *(DWORD*)(varStuff + 60)); } if (*(DWORD*)(varStuff + 76)) { - *(DWORD*)(varStuff + 76) = DB_AllocStreamPos(0); + *(DWORD*)(varStuff + 76) = (DWORD)Game::DB_AllocStreamPos(0); varThing = *(DWORD*)(varStuff + 76); - Load_Stream(1, varThing, *(DWORD*)(varStuff + 72)); - } - } - - Utils::Hook allocZoneMemoryHook; - - void AllocXZoneMemoryHookFunc(unsigned int* sizes) - { - sizes[3] = (unsigned int)(sizes[3] * 1.5); - } - - void __declspec(naked) AllocXZoneMemoryHookStub() - { - __asm - { - mov eax, [esp + 4] - push eax - call AllocXZoneMemoryHookFunc - add esp, 4h - - jmp allocZoneMemoryHook.Original + Game::Load_Stream(1, (void*)varThing, *(DWORD*)(varStuff + 72)); } } @@ -695,15 +589,6 @@ namespace Components for (int i = 0; i < count; i++) { - /*char* src = &buffer[i * 108]; - char* dest = &tempVar[i * 100]; - - memcpy(dest + 0, src + 0, 80); - memcpy(dest + 80, src + 88, 20); - - DB_AddRelocation((DWORD)src + 0, 80, (DWORD)(buffer + (i * 100)) + 0); - DB_AddRelocation((DWORD)src + 88, 20, (DWORD)(buffer + (i * 100)) + 80);*/ - char* src = &buffer[i * 108]; char* dest = &tempVar[i * 100]; @@ -737,7 +622,6 @@ namespace Components memcpy(buffer + 28, buffer + 32, 16); AssetHandler::Relocate((DWORD)buffer + 32, 16, (DWORD)buffer + 28); - //memcpy(buffer + 40, buffer + 44, 4); } Utils::Hook vehicleLoadHook; @@ -770,7 +654,7 @@ namespace Components void Load_WeaponAttachStuff(int count) { - Load_Stream(1, varWeaponAttachStuff, 12 * count); + Game::Load_Stream(1, (void*)varWeaponAttachStuff, 12 * count); DWORD* varStuff = (DWORD*)varWeaponAttachStuff; @@ -782,9 +666,9 @@ namespace Components { if (varStuff[2] == -1) { - varStuff[2] = DB_AllocStreamPos(0); - *varXStringData = varStuff[2]; - Load_XStringData(varXStringData); + varStuff[2] = (DWORD)Game::DB_AllocStreamPos(0); + *Game::varConstChar = (const char*)varStuff[2]; + Game::Load_XStringCustom(Game::varConstChar); //if (*useEntryNames) { @@ -828,19 +712,19 @@ namespace Components DWORD* varXString = (DWORD*)0x112B340; // and do the stuff - Load_Stream(1, varWeaponAttach, 12); + Game::Load_Stream(1, (void*)varWeaponAttach, 12); - DB_PushStreamPos(3); + Game::DB_PushStreamPos(3); *varXString = varWeaponAttach + 0; - Load_XStringPtr(0); + Game::Load_XString(false); - *(DWORD*)(varWeaponAttach + 8) = DB_AllocStreamPos(3); + *(void**)(varWeaponAttach + 8) = Game::DB_AllocStreamPos(3); varWeaponAttachStuff = *(DWORD*)(varWeaponAttach + 8); Load_WeaponAttachStuff(*(int*)(varWeaponAttach + 4)); - DB_PopStreamPos(); + Game::DB_PopStreamPos(); } Utils::Hook gameWorldSpIntHook; @@ -850,41 +734,22 @@ namespace Components memset(*(void**)0x112AD7C, 0, 40); } - extern char lastZoneName[256]; - - FILE* outFile; - DWORD sb3Start = 0; - - void DB_InitStreamsHook() - { - sb3Start = *(DWORD*)0x16E5564; - } - - struct MaterialArgumentDef - { - short a1; - short a2; - short paramID; - short more; - }; - Utils::Hook loadTechniquePassHook; - void Load_TechniquePassHookFunc(int a1, MaterialArgumentDef* pass, size_t size) + void Load_TechniquePassHookFunc(bool atStreamStart, Game::ShaderArgumentDef* pass, size_t size) { int count = size / 8; Game::MaterialPass* curPass = *(Game::MaterialPass**)0x112A960; count = curPass->argCount1 + curPass->argCount2 + curPass->argCount3; - Load_Stream(a1, (DWORD)pass, size); + Game::Load_Stream(atStreamStart, pass, size); for (int i = 0; i < count; i++) { - MaterialArgumentDef* arg = &pass[i]; + Game::ShaderArgumentDef* arg = &pass[i]; - //if (arg->a1 == 1 || arg->a1 == 7) - if (arg->a1 != 3 && arg->a1 != 5) + if (arg->type != 3 && arg->type != 5) { continue; } @@ -903,22 +768,17 @@ namespace Components { arg->paramID -= 2; } - - /*if (arg->paramID >= 132) - { - DBG(("(bad) changed from %i to %i\n", arg->paramID + 3, arg->paramID)); - }*/ } } Utils::Hook loadStructuredDataChildArrayHook; - void Load_StructuredDataChildArrayHookFunc(int a1, char* data, size_t size) + void Load_StructuredDataChildArrayHookFunc(bool atStreamStart, char* data, size_t size) { int count = size / 16; size = count * 24; - Load_Stream(a1, (DWORD)data, size); + Game::Load_Stream(atStreamStart, data, size); for (int i = 0; i < count; i++) { @@ -926,40 +786,49 @@ namespace Components AssetHandler::Relocate((DWORD)data + (i * 24), 16, (DWORD)data + (i * 16)); } } - - void PatchMW2_FifthInfinityApply(bool iw5) - { + + void Zones::InstallPatches(int version) + { + bool patch = (version >= VERSION_ALPHA2); + Zones::ZoneVersion = version; + AssetHandler::ClearRelocations(); + + if (Zones::ZoneVersion == VERSION_ALPHA2 || Zones::ZoneVersion == VERSION_ALPHA3 || Zones::ZoneVersion == XFILE_VERSION) + { + Utils::Hook::Set(0x4158F4, version); + Utils::Hook::Set(0x4158FB, version); + } + // physpreset size - *(BYTE*)0x49CE0A = (iw5) ? 68 : 44; + Utils::Hook::Set(0x49CE0A, (patch) ? 68 : 44); // XModel size - *(DWORD*)0x410D8A = (iw5) ? ((Zones::ZoneVersion == VERSION_ALPHA2) ? 0x16C : 0x168) : 0x130; + Utils::Hook::Set(0x410D8A, (patch) ? ((Zones::ZoneVersion == VERSION_ALPHA2) ? 0x16C : 0x168) : 0x130); // XSurface size - *(BYTE*)0x48E84A = (iw5) ? 48 : 36; + Utils::Hook::Set(0x48E84A, (patch) ? 48 : 36); // impactfx internal size/count - *(DWORD*)0x4447B6 = (iw5) ? 0x8C0 : 0x834; - *(DWORD*)0x4447D1 = (iw5) ? 16 : 15; + Utils::Hook::Set(0x4447B6, (patch) ? 0x8C0 : 0x834); + Utils::Hook::Set(0x4447D1, (patch) ? 16 : 15); // GameWorldSp asset type - *(BYTE*)0x41899A = (iw5) ? 18 : 17; + Utils::Hook::Set(0x41899A, (patch) ? 18 : 17); // PathData internal struct size - *(DWORD*)0x4D6A04 = (iw5) ? 148 : 136; - *(DWORD*)0x4D6A49 = (iw5) ? 148 : 136; + Utils::Hook::Set(0x4D6A04, (patch) ? 148 : 136); + Utils::Hook::Set(0x4D6A49, (patch) ? 148 : 136); // PathData internal struct data size - *(WORD*)0x463D63 = (iw5) ? 0x9090 : 0x048D; - *(BYTE*)0x463D65 = (iw5) ? 0x90 : 0x40; - *(DWORD*)0x463D66 = (iw5) ? 0x9004E0C1 : 0xC003C003; // shl eax, 4 instead of add eax, eax * 2 + Utils::Hook::Set(0x463D63, (patch) ? 0x9090 : 0x048D); + Utils::Hook::Set(0x463D65, (patch) ? 0x90 : 0x40); + Utils::Hook::Set(0x463D66, (patch) ? 0x9004E0C1 : 0xC003C003); // shl eax, 4 instead of add eax, eax * 2 // addon_map_ents asset type (we reuse it for weaponattach) - *(BYTE*)0x418B30 = (iw5) ? 43 : Game::ASSET_TYPE_ADDON_MAP_ENTS; - - // hooks - if (iw5) - { + Utils::Hook::Set(0x418B30, (patch) ? 43 : Game::ASSET_TYPE_ADDON_MAP_ENTS); + + if (patch) + { fxEffectTailHook.Install(); fxEffectModifyHook.Install(); @@ -986,10 +855,10 @@ namespace Components } loadTechniquePassHook.Install(); - loadStructuredDataChildArrayHook.Install(); - } - else - { + loadStructuredDataChildArrayHook.Install(); + } + else + { fxEffectTailHook.Uninstall(); fxEffectModifyHook.Uninstall(); @@ -1013,23 +882,9 @@ namespace Components gameWorldSpIntHook.Uninstall(); loadTechniquePassHook.Uninstall(); - loadStructuredDataChildArrayHook.Uninstall(); - } - } - - void Zones::InstallPatches(int version) - { - Zones::ZoneVersion = version; - AssetHandler::ClearRelocations(); - - if (Zones::ZoneVersion == VERSION_ALPHA2 || Zones::ZoneVersion == VERSION_ALPHA3 || Zones::ZoneVersion == XFILE_VERSION) - { - Utils::Hook::Set(0x4158F4, version); - Utils::Hook::Set(0x4158FB, version); + loadStructuredDataChildArrayHook.Uninstall(); } - PatchMW2_FifthInfinityApply(version >= 316); - AntiCheat::EmptyHash(); } @@ -1050,7 +905,6 @@ namespace Components gameWorldSpLoadHook.Initialize(0x4F4D0D, GameWorldSpLoadHookFunc, HOOK_CALL); loadWeaponDefHook.Initialize(0x47CCD2, Load_WeaponDef_CodC, HOOK_CALL); vehicleLoadHook.Initialize(0x483DA0, VehicleLoadHookFunc, HOOK_CALL); - allocZoneMemoryHook.Initialize(0x415A57, AllocXZoneMemoryHookStub, HOOK_CALL); sndAliasLoadHook.Initialize(0x4F0AC8, SndAliasLoadHookFunc, HOOK_CALL); mssSoundLoadHook.Initialize(0x403A5D, MssSoundLoadHookFunc, HOOK_CALL); loadWeaponAttachHook.Initialize(0x463022, Load_WeaponAttach, HOOK_CALL); diff --git a/src/Components/Modules/Zones.hpp b/src/Components/Modules/Zones.hpp index dffddf5b..29fc4ce7 100644 --- a/src/Components/Modules/Zones.hpp +++ b/src/Components/Modules/Zones.hpp @@ -1,3 +1,6 @@ +#define VERSION_ALPHA2 316 +#define VERSION_ALPHA3 318//319 + namespace Components { class Zones : public Component diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index eda3e309..c505c3a1 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -32,6 +32,10 @@ namespace Game Con_DrawMiniConsole_t Con_DrawMiniConsole = (Con_DrawMiniConsole_t)0x464F30; Con_DrawSolidConsole_t Con_DrawSolidConsole = (Con_DrawSolidConsole_t)0x5A5040; + DB_AllocStreamPos_t DB_AllocStreamPos = (DB_AllocStreamPos_t)0x418380; + DB_PushStreamPos_t DB_PushStreamPos = (DB_PushStreamPos_t)0x458A20; + DB_PopStreamPos_t DB_PopStreamPos = (DB_PopStreamPos_t)0x4D1D60; + DB_BeginRecoverLostDevice_t DB_BeginRecoverLostDevice = (DB_BeginRecoverLostDevice_t)0x4BFF90; DB_EndRecoverLostDevice_t DB_EndRecoverLostDevice = (DB_EndRecoverLostDevice_t)0x46B660; DB_EnumXAssets_t DB_EnumXAssets = (DB_EnumXAssets_t)0x4B76D0; @@ -94,6 +98,18 @@ namespace Game Image_Release_t Image_Release = (Image_Release_t)0x51F010; LargeLocalInit_t LargeLocalInit = (LargeLocalInit_t)0x4A62A0; + + Load_Stream_t Load_Stream = (Load_Stream_t)0x470E30; + Load_XString_t Load_XString = (Load_XString_t)0x47FDA0; + Load_XModelPtr_t Load_XModelPtr = (Load_XModelPtr_t)0x4FCA70; + Load_XStringArray_t Load_XStringArray = (Load_XStringArray_t)0x4977F0; + Load_XStringCustom_t Load_XStringCustom = (Load_XStringCustom_t)0x4E0DD0; + Load_FxEffectDefHandle_t Load_FxEffectDefHandle = (Load_FxEffectDefHandle_t)0x4D9B90; + Load_SndAliasCustom_t Load_SndAliasCustom = (Load_SndAliasCustom_t)0x49B6B0; + Load_MaterialHandle_t Load_MaterialHandle = (Load_MaterialHandle_t)0x403960; + Load_PhysCollmapPtr_t Load_PhysCollmapPtr = (Load_PhysCollmapPtr_t)0x47E990; + Load_TracerDefPtr_t Load_TracerDefPtr = (Load_TracerDefPtr_t)0x493090; + Load_snd_alias_list_nameArray_t Load_snd_alias_list_nameArray = (Load_snd_alias_list_nameArray_t)0x4499F0; Menus_CloseAll_t Menus_CloseAll = (Menus_CloseAll_t)0x4BA5B0; Menus_OpenByName_t Menus_OpenByName = (Menus_OpenByName_t)0x4CCE60; @@ -257,6 +273,15 @@ namespace Game mapname_t* mapnames = (mapname_t*)0x7471D0; + const char** varXString = (const char**)0x112B340; + TracerDef** varTracerDefPtr = (TracerDef**)0x112B3BC; + XModel** varXModelPtr = (XModel**)0x112A934; + const char** varConstChar = (const char**)0x112A774; + Material** varMaterialHandle = (Material**)0x112A878; + FxEffectDef** varFxEffectDefHandle = (FxEffectDef**)0x112ACC0; + PhysCollmap** varPhysCollmapPtr = (PhysCollmap **)0x112B440; + snd_alias_list_t*** varsnd_alias_list_name = (snd_alias_list_t***)0x112AF38; + XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize) { int elSize = DB_GetXAssetSizeHandlers[type](); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 637e202c..ed348446 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -66,6 +66,15 @@ namespace Game typedef void (__cdecl * Con_DrawSolidConsole_t)(); extern Con_DrawSolidConsole_t Con_DrawSolidConsole; + typedef char *(__cdecl *DB_AllocStreamPos_t)(int alignment); + extern DB_AllocStreamPos_t DB_AllocStreamPos; + + typedef void(__cdecl * DB_PushStreamPos_t)(unsigned int index); + extern DB_PushStreamPos_t DB_PushStreamPos; + + typedef void(__cdecl * DB_PopStreamPos_t)(); + extern DB_PopStreamPos_t DB_PopStreamPos; + typedef void(__cdecl * DB_BeginRecoverLostDevice_t)(); extern DB_BeginRecoverLostDevice_t DB_BeginRecoverLostDevice; @@ -224,6 +233,39 @@ namespace Game typedef void(__cdecl * LargeLocalInit_t)(); extern LargeLocalInit_t LargeLocalInit; + typedef bool(__cdecl * Load_Stream_t)(bool atStreamStart, const void *ptr, int size); + extern Load_Stream_t Load_Stream; + + typedef void(__cdecl * Load_XString_t)(bool atStreamStart); + extern Load_XString_t Load_XString; + + typedef void(__cdecl * Load_XModelPtr_t)(bool atStreamStart); + extern Load_XModelPtr_t Load_XModelPtr; + + typedef void(__cdecl * Load_XStringArray_t)(bool atStreamStart, int count); + extern Load_XStringArray_t Load_XStringArray; + + typedef void(__cdecl * Load_XStringCustom_t)(const char **str); + extern Load_XStringCustom_t Load_XStringCustom; + + typedef void(__cdecl *Load_FxEffectDefHandle_t)(bool atStreamStart); + extern Load_FxEffectDefHandle_t Load_FxEffectDefHandle; + + typedef void(__cdecl * Load_SndAliasCustom_t)(snd_alias_list_t** var); + extern Load_SndAliasCustom_t Load_SndAliasCustom; + + typedef void(__cdecl *Load_MaterialHandle_t)(bool atStreamStart); + extern Load_MaterialHandle_t Load_MaterialHandle; + + typedef void(__cdecl *Load_PhysCollmapPtr_t)(bool atStreamStart); + extern Load_PhysCollmapPtr_t Load_PhysCollmapPtr; + + typedef void(__cdecl *Load_TracerDefPtr_t)(bool atStreamStart); + extern Load_TracerDefPtr_t Load_TracerDefPtr; + + typedef void(__cdecl *Load_snd_alias_list_nameArray_t)(bool atStreamStart, int count); + extern Load_snd_alias_list_nameArray_t Load_snd_alias_list_nameArray; + typedef void(__cdecl * Menus_CloseAll_t)(UiContext *dc); extern Menus_CloseAll_t Menus_CloseAll; @@ -517,6 +559,15 @@ namespace Game extern mapname_t* mapnames; + extern const char** varXString; + extern TracerDef** varTracerDefPtr; + extern XModel** varXModelPtr; + extern const char** varConstChar; + extern Material** varMaterialHandle; + extern FxEffectDef** varFxEffectDefHandle; + extern PhysCollmap** varPhysCollmapPtr; + extern snd_alias_list_t*** varsnd_alias_list_name; + XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize); void Menu_FreeItemMemory(Game::itemDef_t* item); const char* TableLookup(StringTable* stringtable, int row, int column); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 41df012c..4bbf2086 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -368,6 +368,19 @@ namespace Game void *stateBitTable; }; + struct TracerDef + { + const char * name; + Material * material; + unsigned int drawInterval; + float speed; + float beamLength; + float beamWidth; + float screwRadius; + float screwDist; + float colors[5][4]; + }; + struct keyname_t { const char *name; @@ -2309,6 +2322,7 @@ namespace Game FxEffectDef* fx; GameMap_MP* gameMapMP; GameMap_SP* gameMapSP; + TracerDef* tracer; }; struct XAsset diff --git a/src/Main.cpp b/src/Main.cpp index 279d9514..cbcc4de0 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -59,7 +59,7 @@ BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*l DWORD oldProtect; std::uint8_t* module = reinterpret_cast(GetModuleHandle(NULL)); VirtualProtect(module, 0x6C73000, PAGE_EXECUTE_READWRITE, &oldProtect); // Unprotect the entire process - VirtualProtect(module + 0x1000, 0x2D6000, PAGE_EXECUTE_READWRITE, &oldProtect); // Protect the .text segment + VirtualProtect(module + 0x1000, 0x2D6000, PAGE_EXECUTE_READ, &oldProtect); // Protect the .text segment Main::EntryPointHook.Initialize(0x6BAC0F, [] () { From 50dfee6db7ed51d64d53d5cc63253a53894b97f3 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 20 Sep 2016 22:55:40 +0200 Subject: [PATCH 09/13] FIx anticheat stuff --- src/Components/Modules/Logger.cpp | 16 ++++++++-------- src/Components/Modules/Zones.cpp | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index e025e4c3..5e0c9730 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -85,14 +85,14 @@ namespace Components void Logger::Flush() { - if (!Game::Sys_IsMainThread()) - { - while (!Logger::MessageQueue.empty()) - { - std::this_thread::sleep_for(10ms); - } - } - else +// if (!Game::Sys_IsMainThread()) +// { +// while (!Logger::MessageQueue.empty()) +// { +// std::this_thread::sleep_for(10ms); +// } +// } +// else { Logger::Frame(); } diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 84e0c030..17f34920 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -789,10 +789,12 @@ namespace Components void Zones::InstallPatches(int version) { - bool patch = (version >= VERSION_ALPHA2); - Zones::ZoneVersion = version; AssetHandler::ClearRelocations(); + if (Zones::ZoneVersion == version) return; + Zones::ZoneVersion = version; + + bool patch = (version >= VERSION_ALPHA2); if (Zones::ZoneVersion == VERSION_ALPHA2 || Zones::ZoneVersion == VERSION_ALPHA3 || Zones::ZoneVersion == XFILE_VERSION) { Utils::Hook::Set(0x4158F4, version); @@ -890,6 +892,8 @@ namespace Components Zones::Zones() { + Zones::ZoneVersion = 0; + // Ignore missing soundaliases for now // TODO: Include them in the dependency zone! Utils::Hook::Nop(0x644207, 5); From db2e572612e4c954107813df0d5e4370e24fa109 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 21 Sep 2016 19:27:31 +0200 Subject: [PATCH 10/13] Begin refactoring the zone loading code --- deps/protobuf | 2 +- deps/zlib | 2 +- src/Components/Modules/Zones.cpp | 157 +++++++++++-------------------- src/Components/Modules/Zones.hpp | 10 ++ src/Game/Functions.cpp | 5 +- src/Game/Functions.hpp | 9 +- 6 files changed, 77 insertions(+), 108 deletions(-) diff --git a/deps/protobuf b/deps/protobuf index 7b00595d..4f379f81 160000 --- a/deps/protobuf +++ b/deps/protobuf @@ -1 +1 @@ -Subproject commit 7b00595ddf8622ae429ef37de8ea2f44b6333ad0 +Subproject commit 4f379f81cef4dd8e005fd0bcc9199bf842fc35d4 diff --git a/deps/zlib b/deps/zlib index 70a8763b..9852c209 160000 --- a/deps/zlib +++ b/deps/zlib @@ -1 +1 @@ -Subproject commit 70a8763b7187f2536ce7fe4d399ce9a79c9faf7c +Subproject commit 9852c209ac49c0d8d1192e46115d7c37d4344bbd diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 17f34920..993edcee 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -4,9 +4,13 @@ namespace Components { int Zones::ZoneVersion; + Utils::Hook Zones::LoadFxElemDefHook; + Utils::Hook Zones::LoadFxElemDefArrayHook; + Utils::Hook Zones::LoadXModelLodInfoHook; + Utils::Hook fxEffectLoadHook; - static DWORD fxEffectStringValue[64]; + static char* fxEffectStringValue[64]; static int fxEffectIndex = 0; void FxEffectLoadHookFunc(int a1, char* buffer, int len) @@ -34,7 +38,7 @@ namespace Components memcpy(tempVar + (252 * i), buffer + (260 * i), 252); - fxEffectStringValue[i] = *(DWORD*)(buffer + (260 * i) + 256); + fxEffectStringValue[i] = *(char**)(buffer + (260 * i) + 256); } memcpy(buffer, tempVar, len); @@ -42,67 +46,25 @@ namespace Components delete[] tempVar; } - Utils::Hook fxEffectModifyHook; - - void FxEffectModifyHookFunc(int a1, char* buffer, size_t len) + bool Zones::LoadFxElemDefStub(bool atStreamStart, Game::FxElemDef* fxElem, int size) { - char typeNum = *(char*)(buffer + 176); - - //DBG(("ot %i\n", typeNum)); - - if (typeNum == 3) + if (fxElem->elemType == 3) { - typeNum = 2; + fxElem->elemType = 2; } - else if (typeNum >= 5) + else if (fxElem->elemType >= 5) { - typeNum -= 2; + fxElem->elemType -= 2; } - /*if (typeNum >= 2) - { - typeNum -= 2; - }*/ - - *(char*)(buffer + 176) = typeNum; - - __asm - { - push len - push buffer - push a1 - call fxEffectModifyHook.Original - add esp, 0Ch - } + return Game::Load_Stream(atStreamStart, fxElem, size); } - Utils::Hook fxEffectTailHook; - - void FxEffectTailHookFunc() + void Zones::LoadFxElemDefArrayStub(bool atStreamStart) { - *Game::varXString = (char*)&fxEffectStringValue[fxEffectIndex++]; - - // Load_XStringPtr(0) - __asm - { - mov eax, 47FDA0h - - push 0 - call eax - add esp, 4h - } - } - - void __declspec(naked) FxEffectTailHookStub() - { - __asm - { - push 0 - call fxEffectTailHook.Original - add esp, 4 - - jmp FxEffectTailHookFunc - } + Game::Load_FxElemDef(atStreamStart); + *Game::varXString = &fxEffectStringValue[fxEffectIndex++]; + Game::Load_XString(0); } Utils::Hook xModelModifyHook; @@ -151,35 +113,22 @@ namespace Components memcpy(buffer, tempVar, elSize); } - Utils::Hook xLodTailHook; - - void XModelLODTailHookFunc(int i) + void Zones::LoadXModelLodInfo(int i) { int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360; - i = (4 - i)/* + 1*/; - - // varXString = (varXModel + 0x16C - (4 * i)) // where the above function parked the new xstring - *Game::varXString = (char*)((*(DWORD*)0x112AE14) + (elSize - 4)) - (4 * i); - + *Game::varXString = reinterpret_cast(reinterpret_cast(*Game::varXModel) + (elSize - 4) - (4 * (4 - i))); Game::Load_XString(false); } - void __declspec(naked) XModelLODTailHookStub() + void __declspec(naked) Zones::LoadXModelLodInfoStub() { __asm { push edi - call XModelLODTailHookFunc - add esp, 4h + call Zones::LoadXModelLodInfo + pop edi - mov eax, [esp + 8h] - push eax - add eax, 8 - push eax - call xLodTailHook.Original - add esp, 8h - - retn + jmp Game::Load_XModelSurfsFixup } } @@ -233,16 +182,16 @@ namespace Components Game::DB_PushStreamPos(3); - *Game::varXString = (char*)varWeaponDef + 0; + *Game::varXString = (char**)(varWeaponDef + 0); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 4; + *Game::varXString = (char**)(varWeaponDef + 4); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 8; + *Game::varXString = (char**)(varWeaponDef + 8); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 12; + *Game::varXString = (char**)(varWeaponDef + 12); Game::Load_XString(false); *Game::varXModelPtr = (Game::XModel*)(varWeaponDef + 16); @@ -265,15 +214,15 @@ namespace Components // 32 scriptstrings, should not need to be loaded // 236 - *Game::varXString = (char*)varWeaponDef + 236; + *Game::varXString = (char**)(varWeaponDef + 236); Game::Load_XStringArray(false, 48); // 428 - *Game::varXString = (char*)varWeaponDef + 428; + *Game::varXString = (char**)(varWeaponDef + 428); Game::Load_XStringArray(false, 48); // 620 - *Game::varXString = (char*)varWeaponDef + 620; + *Game::varXString = (char**)(varWeaponDef + 620); Game::Load_XStringArray(false, 48); // 812 @@ -351,13 +300,13 @@ namespace Components Game::Load_MaterialHandle(false); } - *Game::varXString = (char*)varWeaponDef + 1484; + *Game::varXString = (char**)(varWeaponDef + 1484); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 1492; + *Game::varXString = (char**)(varWeaponDef + 1492); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 1508; + *Game::varXString = (char**)(varWeaponDef + 1508); Game::Load_XString(false); for (int offset = 1764; offset <= 1776; offset += 4) @@ -396,7 +345,7 @@ namespace Components *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2372); // 2380 Game::Load_SndAliasCustom(*Game::varsnd_alias_list_name); - *Game::varXString = (char*)varWeaponDef + 2548; // 2556 + *Game::varXString = (char**)(varWeaponDef + 2548); // 2556 Game::Load_XString(false); if (*(DWORD*)(varWeaponDef + 2556) == -1) // 2564 @@ -407,7 +356,7 @@ namespace Components Game::Load_Stream(1, (void*)vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3076 : 3040))); } - *Game::varXString = (char*)varWeaponDef + 2552; + *Game::varXString = (char**)(varWeaponDef + 2552); Game::Load_XString(false); if (*(DWORD*)(varWeaponDef + 2560) == -1) @@ -418,22 +367,22 @@ namespace Components Game::Load_Stream(1, (void*)vec2, 8 * *(short*)(varWeaponDef + ((Zones::ZoneVersion >= 318) ? 3078 : 3042))); } - *Game::varXString = (char*)varWeaponDef + 2640; + *Game::varXString = (char**)(varWeaponDef + 2640); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2644; + *Game::varXString = (char**)(varWeaponDef + 2644); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2676; + *Game::varXString = (char**)(varWeaponDef + 2676); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2680; + *Game::varXString = (char**)(varWeaponDef + 2680); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2804; + *Game::varXString = (char**)(varWeaponDef + 2804); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2808; + *Game::varXString = (char**)(varWeaponDef + 2808); Game::Load_XString(false); *Game::varTracerDefPtr = (Game::TracerDef*)(varWeaponDef + 2812); @@ -445,7 +394,7 @@ namespace Components *Game::varFxEffectDefHandle = (Game::FxEffectDef*)(varWeaponDef + 2844); Game::Load_FxEffectDefHandle(false); - *Game::varXString = (char*)varWeaponDef + 2848; + *Game::varXString = (char**)(varWeaponDef + 2848); Game::Load_XString(false); *Game::varsnd_alias_list_name = (Game::snd_alias_list_t**)(varWeaponDef + 2864); @@ -479,13 +428,13 @@ namespace Components } - *Game::varXString = (char*)varWeaponDef + 2984; + *Game::varXString = (char**)(varWeaponDef + 2984); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 2996; + *Game::varXString = (char**)(varWeaponDef + 2996); Game::Load_XString(false); - *Game::varXString = (char*)varWeaponDef + 3000; + *Game::varXString = (char**)(varWeaponDef + 3000); Game::Load_XString(false); *Game::varMaterialHandle = (Game::Material*)(varWeaponDef + 3008); @@ -831,10 +780,10 @@ namespace Components if (patch) { - fxEffectTailHook.Install(); - fxEffectModifyHook.Install(); + Zones::LoadFxElemDefArrayHook.Install(); + Zones::LoadFxElemDefHook.Install(); - xLodTailHook.Install(); + Zones::LoadXModelLodInfoHook.Install(); xModelModifyHook.Install(); xsurfaceIntLoadHook.Install(); @@ -861,10 +810,10 @@ namespace Components } else { - fxEffectTailHook.Uninstall(); - fxEffectModifyHook.Uninstall(); + Zones::LoadFxElemDefArrayHook.Uninstall(); + Zones::LoadFxElemDefHook.Uninstall(); - xLodTailHook.Uninstall(); + Zones::LoadXModelLodInfoHook.Uninstall(); xModelModifyHook.Uninstall(); xsurfaceIntLoadHook.Uninstall(); @@ -901,9 +850,9 @@ namespace Components // Block Mark_pathnode_constant_t Utils::Hook::Set(0x4F74B0, 0xC3); - fxEffectTailHook.Initialize(0x495938, FxEffectTailHookStub, HOOK_CALL); - fxEffectModifyHook.Initialize(0x45ADA0, FxEffectModifyHookFunc, HOOK_CALL); - xLodTailHook.Initialize(0x4EA6FE, XModelLODTailHookStub, HOOK_CALL); + Zones::LoadFxElemDefArrayHook.Initialize(0x495938, Zones::LoadFxElemDefArrayStub, HOOK_CALL); + Zones::LoadFxElemDefHook.Initialize(0x45ADA0, Zones::LoadFxElemDefStub, HOOK_CALL); + Zones::LoadXModelLodInfoHook.Initialize(0x4EA6FE, Zones::LoadXModelLodInfoStub, HOOK_CALL); xModelModifyHook.Initialize(0x410D90, XModelModifyHookFunc, HOOK_CALL); xsurfaceIntLoadHook.Initialize(0x4925C8, XSurfaceIntLoadHookFunc, HOOK_CALL); gameWorldSpLoadHook.Initialize(0x4F4D0D, GameWorldSpLoadHookFunc, HOOK_CALL); diff --git a/src/Components/Modules/Zones.hpp b/src/Components/Modules/Zones.hpp index 29fc4ce7..164cc978 100644 --- a/src/Components/Modules/Zones.hpp +++ b/src/Components/Modules/Zones.hpp @@ -17,5 +17,15 @@ namespace Components //private: static int ZoneVersion; + + static Utils::Hook LoadFxElemDefHook; + static Utils::Hook LoadFxElemDefArrayHook; + static Utils::Hook LoadXModelLodInfoHook; + + static void LoadFxElemDefArrayStub(bool atStreamStart); + static bool LoadFxElemDefStub(bool atStreamStart, Game::FxElemDef* fxElem, int size); + + static void LoadXModelLodInfo(int i); + static void LoadXModelLodInfoStub(); }; } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index c505c3a1..28861d9e 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -102,9 +102,11 @@ namespace Game Load_Stream_t Load_Stream = (Load_Stream_t)0x470E30; Load_XString_t Load_XString = (Load_XString_t)0x47FDA0; Load_XModelPtr_t Load_XModelPtr = (Load_XModelPtr_t)0x4FCA70; + Load_XModelSurfsFixup_t Load_XModelSurfsFixup = (Load_XModelSurfsFixup_t)0x40D7A0; Load_XStringArray_t Load_XStringArray = (Load_XStringArray_t)0x4977F0; Load_XStringCustom_t Load_XStringCustom = (Load_XStringCustom_t)0x4E0DD0; Load_FxEffectDefHandle_t Load_FxEffectDefHandle = (Load_FxEffectDefHandle_t)0x4D9B90; + Load_FxElemDef_t Load_FxElemDef = (Load_FxElemDef_t)0x45AD90; Load_SndAliasCustom_t Load_SndAliasCustom = (Load_SndAliasCustom_t)0x49B6B0; Load_MaterialHandle_t Load_MaterialHandle = (Load_MaterialHandle_t)0x403960; Load_PhysCollmapPtr_t Load_PhysCollmapPtr = (Load_PhysCollmapPtr_t)0x47E990; @@ -273,9 +275,10 @@ namespace Game mapname_t* mapnames = (mapname_t*)0x7471D0; - const char** varXString = (const char**)0x112B340; + char*** varXString = (char***)0x112B340; TracerDef** varTracerDefPtr = (TracerDef**)0x112B3BC; XModel** varXModelPtr = (XModel**)0x112A934; + XModel** varXModel = (XModel**)0x112AE14; const char** varConstChar = (const char**)0x112A774; Material** varMaterialHandle = (Material**)0x112A878; FxEffectDef** varFxEffectDefHandle = (FxEffectDef**)0x112ACC0; diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index ed348446..fdf0c6a9 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -242,6 +242,9 @@ namespace Game typedef void(__cdecl * Load_XModelPtr_t)(bool atStreamStart); extern Load_XModelPtr_t Load_XModelPtr; + typedef void(__cdecl * Load_XModelSurfsFixup_t)(XModelSurfs **, XModelLodInfo *); + extern Load_XModelSurfsFixup_t Load_XModelSurfsFixup; + typedef void(__cdecl * Load_XStringArray_t)(bool atStreamStart, int count); extern Load_XStringArray_t Load_XStringArray; @@ -251,6 +254,9 @@ namespace Game typedef void(__cdecl *Load_FxEffectDefHandle_t)(bool atStreamStart); extern Load_FxEffectDefHandle_t Load_FxEffectDefHandle; + typedef void(__cdecl *Load_FxElemDef_t)(bool atStreamStart); + extern Load_FxElemDef_t Load_FxElemDef; + typedef void(__cdecl * Load_SndAliasCustom_t)(snd_alias_list_t** var); extern Load_SndAliasCustom_t Load_SndAliasCustom; @@ -559,9 +565,10 @@ namespace Game extern mapname_t* mapnames; - extern const char** varXString; + extern char*** varXString; extern TracerDef** varTracerDefPtr; extern XModel** varXModelPtr; + extern XModel** varXModel; extern const char** varConstChar; extern Material** varMaterialHandle; extern FxEffectDef** varFxEffectDefHandle; From efbbaec1d6f6ad4f72b863c97c36b6b1324dca58 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 21 Sep 2016 23:19:16 +0200 Subject: [PATCH 11/13] SOme stuff, breaks cargoship! --- src/Components/Modules/AssetHandler.cpp | 19 +- src/Components/Modules/ModelSurfs.cpp | 10 +- src/Components/Modules/Zones.cpp | 269 +++++++++--------------- src/Components/Modules/Zones.hpp | 13 ++ src/Game/Functions.cpp | 1 + src/Game/Functions.hpp | 1 + src/Game/Structs.hpp | 32 ++- 7 files changed, 162 insertions(+), 183 deletions(-) diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index 3430ef08..51970eb2 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -50,16 +50,19 @@ namespace Components { Game::XAssetHeader header = { 0 }; - // Allow call DB_FindXAssetHeader within the hook - AssetHandler::BypassState = true; - - if (AssetHandler::TypeCallbacks.find(type) != AssetHandler::TypeCallbacks.end()) + if (filename) { - header = AssetHandler::TypeCallbacks[type](type, filename); - } + // Allow call DB_FindXAssetHeader within the hook + AssetHandler::BypassState = true; - // Disallow calling DB_FindXAssetHeader ;) - AssetHandler::BypassState = false; + if (AssetHandler::TypeCallbacks.find(type) != AssetHandler::TypeCallbacks.end()) + { + header = AssetHandler::TypeCallbacks[type](type, filename); + } + + // Disallow calling DB_FindXAssetHeader ;) + AssetHandler::BypassState = false; + } return header; } diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 40433ec5..19e9d595 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -100,10 +100,12 @@ namespace Components for (int i = 0; i < modelSurfs->numSurfaces; ++i) { - memcpy(&tempSurfaces[i], surfaceData + (i * 84), 12); - memcpy(&tempSurfaces[i].indexBuffer, surfaceData + (i * 84) + 16, 20); - memcpy(&tempSurfaces[i].numCT, surfaceData + (i * 84) + 40, 8); - memcpy(&tempSurfaces[i].something, surfaceData + (i * 84) + 52, 24); + char* source = &surfaceData[i * 84]; + + memcpy(&tempSurfaces[i], source, 12); + memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20); + memcpy(&tempSurfaces[i].numCT, source + 40, 8); + memcpy(&tempSurfaces[i].something, source + 52, 24); tempSurfaces[i].streamHandle = 0xFF; // Fake handle for buffer interception } diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 993edcee..7f6c076a 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -7,6 +7,13 @@ namespace Components Utils::Hook Zones::LoadFxElemDefHook; Utils::Hook Zones::LoadFxElemDefArrayHook; Utils::Hook Zones::LoadXModelLodInfoHook; + Utils::Hook Zones::LoadXModelHook; + Utils::Hook Zones::LoadXSurfaceArrayHook; + Utils::Hook Zones::LoadGameWorldSpHook; + Utils::Hook Zones::LoadPathDataHook; + Utils::Hook Zones::LoadVehicleDefHook; + Utils::Hook Zones::Loadsnd_alias_tArrayHook; + Utils::Hook Zones::LoadLoadedSoundHook; Utils::Hook fxEffectLoadHook; @@ -67,50 +74,33 @@ namespace Components Game::Load_XString(0); } - Utils::Hook xModelModifyHook; - - void XModelModifyHookFunc(int a1, char* buffer, size_t len) + bool Zones::LoadXModel(bool atStreamStart, char* xmodel, int size) { - __asm - { - push len - push buffer - push a1 - call xModelModifyHook.Original - add esp, 0Ch - } + bool result = Game::Load_Stream(atStreamStart, xmodel, size); int elSize = (Zones::ZoneVersion == VERSION_ALPHA2) ? 364 : 360; - static unsigned char tempVar[364]; - memcpy(&tempVar[0], &buffer[0], 36); - memcpy(&tempVar[36], &buffer[44], 28); + Game::XModel model[2]; // Allocate 2 models, as we exceed the buffer - //DB_AddRelocation((DWORD)buffer + 44, 28, (DWORD)buffer + 36); + memcpy(model, xmodel, 36); + memcpy(&model->pad3[0x1C], &xmodel[44], 28); for (int i = 0; i < 4; i++) { - //DB_AddRelocation((DWORD)buffer + 72 + (i * 56), 12, (DWORD)buffer + 64 + (i * 44)); - //DB_AddRelocation((DWORD)buffer + 72 + (i * 56) + 12, 32, (DWORD)buffer + 64 + (i * 44) + 16); + memcpy(&model->lods[i], &xmodel[72 + (i * 56)], 12); + memcpy(&model->lods[i].pad3, &xmodel[72 + (i * 56) + 16], 32); - memcpy(&tempVar[64 + (i * 44)], &buffer[72 + (i * 56)], 12); - memcpy(&tempVar[64 + (i * 44) + 12], &buffer[72 + (i * 56) + 16], 32); - - memcpy(&tempVar[(elSize - 4) - (i * 4)], &buffer[72 + (i * 56) + 12], 4); + memcpy(reinterpret_cast(&model) + (elSize - 4) - (i * 4), &xmodel[72 + (i * 56) + 12], 4); } - //DB_AddRelocation((DWORD)buffer + 292, (elSize - 292 - 4), (DWORD)buffer + 236); - //DB_AddRelocation((DWORD)buffer + (elSize - 8), 8, (DWORD)buffer + 296); + memcpy(&model->lods[3].pad4[0], &xmodel[292], (elSize - 292 - 4)/*68*/); + memcpy(&model->physPreset, &xmodel[(elSize - 8)], 8); - memcpy(&tempVar[236], &buffer[292], (elSize - 292 - 4)/*68*/); - memcpy(&tempVar[296], &buffer[(elSize - 8)], 8); + model[1].name = reinterpret_cast(0xDEC0ADDE); - tempVar[304] = 0xDE; - tempVar[305] = 0xAD; - tempVar[306] = 0xC0; - tempVar[307] = 0xDE; + memcpy(xmodel, &model, elSize); - memcpy(buffer, tempVar, elSize); + return result; } void Zones::LoadXModelLodInfo(int i) @@ -132,42 +122,31 @@ namespace Components } } - Utils::Hook xsurfaceIntLoadHook; - - void XSurfaceIntLoadHookFunc(int a1, char* buffer, size_t len) + bool Zones::LoadXSurfaceArray(bool atStreamStart, char* buffer, int size) { - len >>= 6; + size >>= 6; - int count = len; - len *= 84; + int count = size; + size *= 84; - __asm - { - push len - push buffer - push a1 - call xsurfaceIntLoadHook.Original - add esp, 0Ch + bool result = Game::Load_Stream(atStreamStart, buffer, size); + + Utils::Memory::Allocator allocator; + Game::XSurface* tempSurfaces = allocator.AllocateArray(count); + + for (int i = 0; i < count; ++i) + { + char* source = &buffer[i * 84]; + + memcpy(&tempSurfaces[i], source, 12); + memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20); + memcpy(&tempSurfaces[i].numCT, source + 40, 8); + memcpy(&tempSurfaces[i].something, source + 52, 24); } - char* tempVar = new char[len]; + memcpy(buffer, tempSurfaces, sizeof(Game::XSurface) * count); - for (int i = 0; i < count; i++) - { - char* source = &buffer[i * 84]; - char* dest = &tempVar[i * 64]; - - //memcpy(dest, source, 12); - //memcpy(dest + 12, source + 16, 72); - memcpy(dest, source, 12); - memcpy(dest + 12, source + 16, 20); - memcpy(dest + 32, source + 40, 8); - memcpy(dest + 40, source + 52, 24); - } - - memcpy(buffer, tempVar, len); - - delete[] tempVar; + return result; } Utils::Hook loadWeaponDefHook; @@ -465,27 +444,18 @@ namespace Components Game::DB_PopStreamPos(); } - Utils::Hook gameWorldSpLoadHook; - - void GameWorldSpLoadHookFunc(int a1, char* buffer, size_t len) + bool Zones::LoadGameWorldSp(bool atStreamStart, char* buffer) { - len = 84; + bool result = Game::Load_Stream(atStreamStart, buffer, 84); - __asm - { - push len - push buffer - push a1 - call gameWorldSpLoadHook.Original - add esp, 0Ch - } + Game::GameWorldSp world[2]; + memcpy(&world, buffer, 44); + memcpy(&world[1], &buffer[44], 28); + memcpy(&world->vehicleTrack, &buffer[72], 12); - static char tempVar[84]; - memcpy(&tempVar[0], &buffer[0], 44); - memcpy(&tempVar[56], &buffer[44], 28); - memcpy(&tempVar[44], &buffer[72], 12); + memcpy(buffer, world, 84); - memcpy(buffer, tempVar, sizeof(tempVar)); + return result; } Utils::Hook pathDataTailHook; @@ -517,84 +487,58 @@ namespace Components } } - Utils::Hook sndAliasLoadHook; - - void SndAliasLoadHookFunc(int a1, char* buffer, size_t len) + bool Zones::Loadsnd_alias_tArray(bool atStreamStart, char* buffer, int len) { len /= 100; int count = len; len *= 108; - __asm - { - push len - push buffer - push a1 - call gameWorldSpLoadHook.Original - add esp, 0Ch - } + bool result = Game::Load_Stream(atStreamStart, buffer, len); - char* tempVar = new char[len]; + 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 = &tempVar[i * 100]; + for (int i = 0; i < count; i++) + { + char* src = &buffer[i * 108]; + + memcpy(&tempSounds[i], src + 0, 60); + memcpy(&tempSounds[i].pad2[36], src + 68, 20); + memcpy(&tempSounds[i].pad2[56], 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); + } + + memcpy(buffer, tempSounds, sizeof(Game::snd_alias_t) * count); - memcpy(dest + 0, src + 0, 60); - memcpy(dest + 60, src + 68, 20); - memcpy(dest + 80, src + 88, 20); - - AssetHandler::Relocate((DWORD)src + 0, 60, (DWORD)(buffer + (i * 100)) + 0); - AssetHandler::Relocate((DWORD)src + 68, 20, (DWORD)(buffer + (i * 100)) + 60); - AssetHandler::Relocate((DWORD)src + 88, 20, (DWORD)(buffer + (i * 100)) + 80); - } - - memcpy(buffer, tempVar, len); - delete[] tempVar; + return result; } - Utils::Hook mssSoundLoadHook; - - void MssSoundLoadHookFunc(int a1, char* buffer, size_t len) + bool Zones::LoadLoadedSound(bool atStreamStart, char* buffer) { - len = 48; - - __asm - { - push len - push buffer - push a1 - call gameWorldSpLoadHook.Original - add esp, 0Ch - } + bool result = Game::Load_Stream(atStreamStart, buffer, 48); memcpy(buffer + 28, buffer + 32, 16); - AssetHandler::Relocate((DWORD)buffer + 32, 16, (DWORD)buffer + 28); + AssetHandler::Relocate(buffer + 32, buffer + 28, 16); + + return result; } - Utils::Hook vehicleLoadHook; - - void VehicleLoadHookFunc(int a1, char* buffer, int len) + bool Zones::LoadVehicleDef(bool atStreamStart, char* buffer) { - len = 788; + bool result = Game::Load_Stream(atStreamStart, buffer, 788); + + Game::VehicleDef vehicle[2]; + memcpy(vehicle, &buffer[0], 400); + memcpy(&vehicle->pad[404], &buffer[400], 388); - __asm - { - push len - push buffer - push a1 - call vehicleLoadHook.Original - add esp, 0Ch - } + AssetHandler::Relocate(buffer + 400, buffer + 408, 388); - static char tempVar[788]; - memcpy(&tempVar[0], &buffer[0], 400); - memcpy(&tempVar[408], &buffer[400], 388); + memcpy(buffer, vehicle, sizeof(788)); - AssetHandler::Relocate((DWORD)buffer + 400, 388, (DWORD)buffer + 408); - - memcpy(buffer, tempVar, sizeof(tempVar)); + return result; } Utils::Hook loadWeaponAttachHook; @@ -676,13 +620,6 @@ namespace Components Game::DB_PopStreamPos(); } - Utils::Hook gameWorldSpIntHook; - - void GameWorldSpIntHookFunc(int /*doLoad*/) - { - memset(*(void**)0x112AD7C, 0, 40); - } - Utils::Hook loadTechniquePassHook; void Load_TechniquePassHookFunc(bool atStreamStart, Game::ShaderArgumentDef* pass, size_t size) @@ -784,17 +721,17 @@ namespace Components Zones::LoadFxElemDefHook.Install(); Zones::LoadXModelLodInfoHook.Install(); - xModelModifyHook.Install(); + Zones::LoadXModelHook.Install(); - xsurfaceIntLoadHook.Install(); - gameWorldSpLoadHook.Install(); + Zones::LoadXSurfaceArrayHook.Install(); + Zones::LoadGameWorldSpHook.Install(); pathDataTailHook.Install(); loadWeaponDefHook.Install(); - vehicleLoadHook.Install(); + Zones::LoadVehicleDefHook.Install(); - sndAliasLoadHook.Install(); - mssSoundLoadHook.Install(); + Zones::Loadsnd_alias_tArrayHook.Install(); + Zones::LoadLoadedSoundHook.Install(); menuDefLoadHook.Install(); fxEffectLoadHook.Install(); @@ -802,7 +739,7 @@ namespace Components if (Zones::ZoneVersion >= VERSION_ALPHA3) { - gameWorldSpIntHook.Install(); + Zones::LoadPathDataHook.Install(); } loadTechniquePassHook.Install(); @@ -814,23 +751,23 @@ namespace Components Zones::LoadFxElemDefHook.Uninstall(); Zones::LoadXModelLodInfoHook.Uninstall(); - xModelModifyHook.Uninstall(); + Zones::LoadXModelHook.Uninstall(); - xsurfaceIntLoadHook.Uninstall(); - gameWorldSpLoadHook.Uninstall(); + Zones::LoadXSurfaceArrayHook.Uninstall(); + Zones::LoadGameWorldSpHook.Uninstall(); pathDataTailHook.Uninstall(); loadWeaponDefHook.Uninstall(); - vehicleLoadHook.Uninstall(); + Zones::LoadVehicleDefHook.Uninstall(); - sndAliasLoadHook.Uninstall(); - mssSoundLoadHook.Uninstall(); + Zones::Loadsnd_alias_tArrayHook.Uninstall(); + Zones::LoadLoadedSoundHook.Uninstall(); menuDefLoadHook.Uninstall(); fxEffectLoadHook.Uninstall(); loadWeaponAttachHook.Uninstall(); - gameWorldSpIntHook.Uninstall(); + Zones::LoadPathDataHook.Uninstall(); loadTechniquePassHook.Uninstall(); loadStructuredDataChildArrayHook.Uninstall(); @@ -853,21 +790,25 @@ namespace Components Zones::LoadFxElemDefArrayHook.Initialize(0x495938, Zones::LoadFxElemDefArrayStub, HOOK_CALL); Zones::LoadFxElemDefHook.Initialize(0x45ADA0, Zones::LoadFxElemDefStub, HOOK_CALL); Zones::LoadXModelLodInfoHook.Initialize(0x4EA6FE, Zones::LoadXModelLodInfoStub, HOOK_CALL); - xModelModifyHook.Initialize(0x410D90, XModelModifyHookFunc, HOOK_CALL); - xsurfaceIntLoadHook.Initialize(0x4925C8, XSurfaceIntLoadHookFunc, HOOK_CALL); - gameWorldSpLoadHook.Initialize(0x4F4D0D, GameWorldSpLoadHookFunc, HOOK_CALL); + Zones::LoadXModelHook.Initialize(0x410D90, Zones::LoadXModel, HOOK_CALL); + Zones::LoadXSurfaceArrayHook.Initialize(0x4925C8, Zones::LoadXSurfaceArray, HOOK_CALL); + Zones::LoadGameWorldSpHook.Initialize(0x4F4D0D, Zones::LoadGameWorldSp, HOOK_CALL); loadWeaponDefHook.Initialize(0x47CCD2, Load_WeaponDef_CodC, HOOK_CALL); - vehicleLoadHook.Initialize(0x483DA0, VehicleLoadHookFunc, HOOK_CALL); - sndAliasLoadHook.Initialize(0x4F0AC8, SndAliasLoadHookFunc, HOOK_CALL); - mssSoundLoadHook.Initialize(0x403A5D, MssSoundLoadHookFunc, HOOK_CALL); + Zones::LoadVehicleDefHook.Initialize(0x483DA0, Zones::LoadVehicleDef, HOOK_CALL); + Zones::Loadsnd_alias_tArrayHook.Initialize(0x4F0AC8, Zones::Loadsnd_alias_tArray, HOOK_CALL); + Zones::LoadLoadedSoundHook.Initialize(0x403A5D, Zones::LoadLoadedSound, HOOK_CALL); loadWeaponAttachHook.Initialize(0x463022, Load_WeaponAttach, HOOK_CALL); menuDefLoadHook.Initialize(0x41A570, MenuDefLoadHookFunc, HOOK_CALL); fxEffectLoadHook.Initialize(0x49591B, FxEffectLoadHookFunc, HOOK_CALL); - gameWorldSpIntHook.Initialize(0x4F4D3B, GameWorldSpIntHookFunc, HOOK_CALL); loadTechniquePassHook.Initialize(0x428F0A, Load_TechniquePassHookFunc, HOOK_CALL); loadStructuredDataChildArrayHook.Initialize(0x4B1EB8, Load_StructuredDataChildArrayHookFunc, HOOK_CALL); pathDataTailHook.Initialize(0x427A1B, PathDataTailHookFunc, HOOK_JUMP); + + Zones::LoadPathDataHook.Initialize(0x4F4D3B, [] () + { + ZeroMemory(*Game::varPathData, sizeof(Game::PathData)); + }, HOOK_CALL); } Zones::~Zones() diff --git a/src/Components/Modules/Zones.hpp b/src/Components/Modules/Zones.hpp index 164cc978..96938b9b 100644 --- a/src/Components/Modules/Zones.hpp +++ b/src/Components/Modules/Zones.hpp @@ -21,11 +21,24 @@ namespace Components static Utils::Hook LoadFxElemDefHook; static Utils::Hook LoadFxElemDefArrayHook; static Utils::Hook LoadXModelLodInfoHook; + static Utils::Hook LoadXModelHook; + static Utils::Hook LoadXSurfaceArrayHook; + static Utils::Hook LoadGameWorldSpHook; + static Utils::Hook LoadPathDataHook; + static Utils::Hook LoadVehicleDefHook; + static Utils::Hook Loadsnd_alias_tArrayHook; + static Utils::Hook LoadLoadedSoundHook; static void LoadFxElemDefArrayStub(bool atStreamStart); static bool LoadFxElemDefStub(bool atStreamStart, Game::FxElemDef* fxElem, int size); static void LoadXModelLodInfo(int i); static void LoadXModelLodInfoStub(); + static bool LoadXModel(bool atStreamStart, char* xmodel, int size); + static bool LoadXSurfaceArray(bool atStreamStart, char* buffer, int size); + static bool LoadGameWorldSp(bool atStreamStart, char* buffer); + static bool LoadVehicleDef(bool atStreamStart, char* buffer); + static bool Loadsnd_alias_tArray(bool atStreamStart, char* buffer, int len); + static bool LoadLoadedSound(bool atStreamStart, char* buffer); }; } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 28861d9e..c8e06237 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -279,6 +279,7 @@ namespace Game TracerDef** varTracerDefPtr = (TracerDef**)0x112B3BC; XModel** varXModelPtr = (XModel**)0x112A934; XModel** varXModel = (XModel**)0x112AE14; + PathData** varPathData = (PathData**)0x112AD7C; const char** varConstChar = (const char**)0x112A774; Material** varMaterialHandle = (Material**)0x112A878; FxEffectDef** varFxEffectDefHandle = (FxEffectDef**)0x112ACC0; diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index fdf0c6a9..39181e76 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -569,6 +569,7 @@ namespace Game extern TracerDef** varTracerDefPtr; extern XModel** varXModelPtr; extern XModel** varXModel; + extern PathData** varPathData; extern const char** varConstChar; extern Material** varMaterialHandle; extern FxEffectDef** varFxEffectDefHandle; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 4bbf2086..7ecb1c14 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -1415,9 +1415,9 @@ namespace Game short numSurfs; // +4 short maxSurfs;// +6 XModelSurfs* surfaces; // +8 - char pad3[24]; + char pad3[24]; // +12 XSurface* surfs; - char pad4[4]; // +12 + char pad4[4]; }; struct cplane_t @@ -2281,20 +2281,37 @@ namespace Game char pad[112]; }; - struct GameMap_SP + struct PathData + { + char pad[40]; + }; + + struct VehicleTrack + { + char pad[8]; + }; + + struct GameWorldSp { const char* name; - char pad[48]; + PathData pathData; + VehicleTrack vehicleTrack; GameMap_Data* data; }; - struct GameMap_MP + struct GameWorldMp { const char* name; GameMap_Data* data; }; + struct VehicleDef + { + const char* name; + char pad[716]; + }; + union XAssetHeader { void *data; @@ -2320,9 +2337,10 @@ namespace Game XAnimParts* xanim; clipMap_t* clipMap; FxEffectDef* fx; - GameMap_MP* gameMapMP; - GameMap_SP* gameMapSP; + GameWorldMp* gameMapMP; + GameWorldSp* gameMapSP; TracerDef* tracer; + VehicleDef* vehicle; }; struct XAsset From 33b9509ab84a0a103ce37b07b5a3c98a32306d0e Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 21 Sep 2016 23:42:34 +0200 Subject: [PATCH 12/13] Fix cargoship --- src/Components/Modules/Zones.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 7f6c076a..67b8e13f 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -520,7 +520,7 @@ namespace Components { bool result = Game::Load_Stream(atStreamStart, buffer, 48); - memcpy(buffer + 28, buffer + 32, 16); + memmove(buffer + 28, buffer + 32, 16); AssetHandler::Relocate(buffer + 32, buffer + 28, 16); return result; @@ -536,7 +536,7 @@ namespace Components AssetHandler::Relocate(buffer + 400, buffer + 408, 388); - memcpy(buffer, vehicle, sizeof(788)); + memcpy(buffer, vehicle, 788); return result; } From 775cde47e24bee923d438464a96eee55475da567 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 22 Sep 2016 08:23:40 +0200 Subject: [PATCH 13/13] Use std::memcpy --- src/Components/Modules/Menus.cpp | 2 +- src/Components/Modules/ModelSurfs.cpp | 12 +++--- src/Components/Modules/QuickPatch.cpp | 4 +- src/Components/Modules/Zones.cpp | 58 +++++++++++++-------------- src/Game/Functions.cpp | 2 +- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Components/Modules/Menus.cpp b/src/Components/Modules/Menus.cpp index 21a6efe5..9625b7d0 100644 --- a/src/Components/Modules/Menus.cpp +++ b/src/Components/Modules/Menus.cpp @@ -45,7 +45,7 @@ namespace Components Game::Script_SetupTokens(script, reinterpret_cast(0x797F80)); script->punctuations = reinterpret_cast(0x797F80); - memcpy(script->buffer, buffer.data(), script->length + 1); + std::memcpy(script->buffer, buffer.data(), script->length + 1); script->length = Game::Script_CleanString(script->buffer); diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index 19e9d595..9fac8e6f 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -102,14 +102,14 @@ namespace Components { char* source = &surfaceData[i * 84]; - memcpy(&tempSurfaces[i], source, 12); - memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20); - memcpy(&tempSurfaces[i].numCT, source + 40, 8); - memcpy(&tempSurfaces[i].something, source + 52, 24); + std::memcpy(&tempSurfaces[i], source, 12); + std::memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20); + std::memcpy(&tempSurfaces[i].numCT, source + 40, 8); + std::memcpy(&tempSurfaces[i].something, source + 52, 24); tempSurfaces[i].streamHandle = 0xFF; // Fake handle for buffer interception } - memcpy(surfaceData, tempSurfaces, 64 * modelSurfs->numSurfaces); + std::memcpy(surfaceData, tempSurfaces, 64 * modelSurfs->numSurfaces); ModelSurfs::CreateBuffers(modelSurfs); @@ -135,7 +135,7 @@ namespace Components surfs->numSurfaces = newSurfs->numSurfaces; model->lods[i].surfs = newSurfs->surfaces; - memcpy(model->lods[i].pad3, newSurfs->pad, 24); + std::memcpy(model->lods[i].pad3, newSurfs->pad, 24); short numSurfs = static_cast(newSurfs->numSurfaces); model->lods[i].numSurfs = numSurfs; diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 8b84f6d1..a11b28a4 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -88,7 +88,7 @@ namespace Components size = Game::MSG_ReadBitsCompress(from, buffer, size); if (size > 0x800) return 0; - memcpy(to, buffer, size); + std::memcpy(to, buffer, size); return size; } @@ -101,7 +101,7 @@ namespace Components size = Game::MSG_ReadBitsCompress(from, buffer, size); if (size > 0x20000) return 0; - memcpy(to, buffer, size); + std::memcpy(to, buffer, size); return size; } diff --git a/src/Components/Modules/Zones.cpp b/src/Components/Modules/Zones.cpp index 67b8e13f..5fd8174e 100644 --- a/src/Components/Modules/Zones.cpp +++ b/src/Components/Modules/Zones.cpp @@ -43,12 +43,12 @@ namespace Components { AssetHandler::Relocate((DWORD)buffer + (260 * i), 252, (DWORD)buffer + (252 * i)); - memcpy(tempVar + (252 * i), buffer + (260 * i), 252); + std::memcpy(tempVar + (252 * i), buffer + (260 * i), 252); fxEffectStringValue[i] = *(char**)(buffer + (260 * i) + 256); } - memcpy(buffer, tempVar, len); + std::memcpy(buffer, tempVar, len); delete[] tempVar; } @@ -82,23 +82,23 @@ namespace Components Game::XModel model[2]; // Allocate 2 models, as we exceed the buffer - memcpy(model, xmodel, 36); - memcpy(&model->pad3[0x1C], &xmodel[44], 28); + std::memcpy(model, xmodel, 36); + std::memcpy(&model->pad3[0x1C], &xmodel[44], 28); for (int i = 0; i < 4; i++) { - memcpy(&model->lods[i], &xmodel[72 + (i * 56)], 12); - memcpy(&model->lods[i].pad3, &xmodel[72 + (i * 56) + 16], 32); + std::memcpy(&model->lods[i], &xmodel[72 + (i * 56)], 12); + std::memcpy(&model->lods[i].pad3, &xmodel[72 + (i * 56) + 16], 32); - memcpy(reinterpret_cast(&model) + (elSize - 4) - (i * 4), &xmodel[72 + (i * 56) + 12], 4); + std::memcpy(reinterpret_cast(&model) + (elSize - 4) - (i * 4), &xmodel[72 + (i * 56) + 12], 4); } - memcpy(&model->lods[3].pad4[0], &xmodel[292], (elSize - 292 - 4)/*68*/); - memcpy(&model->physPreset, &xmodel[(elSize - 8)], 8); + std::memcpy(&model->lods[3].pad4[0], &xmodel[292], (elSize - 292 - 4)/*68*/); + std::memcpy(&model->physPreset, &xmodel[(elSize - 8)], 8); model[1].name = reinterpret_cast(0xDEC0ADDE); - memcpy(xmodel, &model, elSize); + std::memcpy(xmodel, &model, elSize); return result; } @@ -138,13 +138,13 @@ namespace Components { char* source = &buffer[i * 84]; - memcpy(&tempSurfaces[i], source, 12); - memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20); - memcpy(&tempSurfaces[i].numCT, source + 40, 8); - memcpy(&tempSurfaces[i].something, source + 52, 24); + std::memcpy(&tempSurfaces[i], source, 12); + std::memcpy(&tempSurfaces[i].indexBuffer, source + 16, 20); + std::memcpy(&tempSurfaces[i].numCT, source + 40, 8); + std::memcpy(&tempSurfaces[i].something, source + 52, 24); } - memcpy(buffer, tempSurfaces, sizeof(Game::XSurface) * count); + std::memcpy(buffer, tempSurfaces, sizeof(Game::XSurface) * count); return result; } @@ -449,11 +449,11 @@ namespace Components bool result = Game::Load_Stream(atStreamStart, buffer, 84); Game::GameWorldSp world[2]; - memcpy(&world, buffer, 44); - memcpy(&world[1], &buffer[44], 28); - memcpy(&world->vehicleTrack, &buffer[72], 12); + std::memcpy(&world, buffer, 44); + std::memcpy(&world[1], &buffer[44], 28); + std::memcpy(&world->vehicleTrack, &buffer[72], 12); - memcpy(buffer, world, 84); + std::memcpy(buffer, world, 84); return result; } @@ -502,16 +502,16 @@ namespace Components { char* src = &buffer[i * 108]; - memcpy(&tempSounds[i], src + 0, 60); - memcpy(&tempSounds[i].pad2[36], src + 68, 20); - memcpy(&tempSounds[i].pad2[56], src + 88, 20); + std::memcpy(&tempSounds[i], src + 0, 60); + std::memcpy(&tempSounds[i].pad2[36], src + 68, 20); + std::memcpy(&tempSounds[i].pad2[56], 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); } - memcpy(buffer, tempSounds, sizeof(Game::snd_alias_t) * count); + std::memcpy(buffer, tempSounds, sizeof(Game::snd_alias_t) * count); return result; } @@ -520,7 +520,7 @@ namespace Components { bool result = Game::Load_Stream(atStreamStart, buffer, 48); - memmove(buffer + 28, buffer + 32, 16); + std::memmove(buffer + 28, buffer + 32, 16); AssetHandler::Relocate(buffer + 32, buffer + 28, 16); return result; @@ -531,12 +531,12 @@ namespace Components bool result = Game::Load_Stream(atStreamStart, buffer, 788); Game::VehicleDef vehicle[2]; - memcpy(vehicle, &buffer[0], 400); - memcpy(&vehicle->pad[404], &buffer[400], 388); + std::memcpy(vehicle, &buffer[0], 400); + std::memcpy(&vehicle->pad[404], &buffer[400], 388); AssetHandler::Relocate(buffer + 400, buffer + 408, 388); - memcpy(buffer, vehicle, 788); + std::memcpy(buffer, vehicle, 788); return result; } @@ -593,7 +593,7 @@ namespace Components add esp, 0Ch } - memcpy(buffer + 168, buffer + 172, 232); + std::memcpy(buffer + 168, buffer + 172, 232); AssetHandler::Relocate((DWORD)buffer + 172, 232, (DWORD)buffer + 168); } @@ -668,7 +668,7 @@ namespace Components for (int i = 0; i < count; i++) { - memcpy(data + (i * 16), data + (i * 24), 16); + std::memcpy(data + (i * 16), data + (i * 24), 16); AssetHandler::Relocate((DWORD)data + (i * 24), 16, (DWORD)data + (i * 16)); } } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index c8e06237..eceb4b54 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -505,7 +505,7 @@ namespace Game if (Components::Dvar::Var("r_loadForRenderer").Get()) { void* buffer = R_AllocStaticIndexBuffer(storeHere, 2 * count); - memcpy(buffer, data, 2 * count); + std::memcpy(buffer, data, 2 * count); if (storeHere && *storeHere) {