diff --git a/src/Components/Modules/Weapon.cpp b/src/Components/Modules/Weapon.cpp index 58a90e46..c11b5e2e 100644 --- a/src/Components/Modules/Weapon.cpp +++ b/src/Components/Modules/Weapon.cpp @@ -2,17 +2,15 @@ namespace Components { - Game::XAssetHeader Weapon::WeaponFileLoad(Game::XAssetType /*type*/, const std::string& filename) + Game::WeaponCompleteDef* Weapon::LoadWeaponCompleteDef(const char* name) { - Game::XAssetHeader header = { nullptr }; - - // Try loading raw weapon - if (FileSystem::File(Utils::String::VA("weapons/mp/%s", filename.data())).exists()) + if (auto* rawWeaponFile = Game::BG_LoadWeaponCompleteDefInternal("mp", name)) { - header.data = Game::BG_LoadWeaponDef_LoadObj(filename.data()); + return rawWeaponFile; } - return header; + auto* zoneWeaponFile = Game::DB_FindXAssetHeader(Game::ASSET_TYPE_WEAPON, name).weapon; + return Game::DB_IsXAssetDefault(Game::ASSET_TYPE_WEAPON, name) ? nullptr : zoneWeaponFile; } const char* Weapon::GetWeaponConfigString(int index) @@ -542,8 +540,10 @@ namespace Components PatchLimit(); PatchConfigStrings(); - // Intercept weapon loading - AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_WEAPON, Weapon::WeaponFileLoad); + // BG_LoadWEaponCompleteDef_FastFile + Utils::Hook(0x57B650, LoadWeaponCompleteDef, HOOK_JUMP).install()->quick(); + // Disable warning if raw weapon file cannot be found + Utils::Hook::Nop(0x57AF60, 5); // weapon asset existence check Utils::Hook::Nop(0x408228, 5); // find asset header diff --git a/src/Components/Modules/Weapon.hpp b/src/Components/Modules/Weapon.hpp index 7599c772..3b6d14d5 100644 --- a/src/Components/Modules/Weapon.hpp +++ b/src/Components/Modules/Weapon.hpp @@ -13,7 +13,7 @@ namespace Components Weapon(); private: - static Game::XAssetHeader WeaponFileLoad(Game::XAssetType type, const std::string& filename); + static Game::WeaponCompleteDef* LoadWeaponCompleteDef(const char* name); static void PatchLimit(); static void* LoadNoneWeaponHook(); static void LoadNoneWeaponHookStub(); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 9bf202cf..8877ef02 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -33,6 +33,7 @@ namespace Game BG_GetNumWeapons_t BG_GetNumWeapons = BG_GetNumWeapons_t(0x4F5CC0); BG_GetWeaponName_t BG_GetWeaponName = BG_GetWeaponName_t(0x4E6EC0); BG_LoadWeaponDef_LoadObj_t BG_LoadWeaponDef_LoadObj = BG_LoadWeaponDef_LoadObj_t(0x57B5F0); + BG_LoadWeaponCompleteDefInternal_t BG_LoadWeaponCompleteDefInternal = BG_LoadWeaponCompleteDefInternal_t(0x4B5F10); BG_GetWeaponDef_t BG_GetWeaponDef = BG_GetWeaponDef_t(0x440EB0); BG_GetEntityTypeName_t BG_GetEntityTypeName = BG_GetEntityTypeName_t(0x43A0E0); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 5f2fed37..60654959 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -46,9 +46,12 @@ namespace Game typedef const char*(__cdecl * BG_GetWeaponName_t)(unsigned int index); extern BG_GetWeaponName_t BG_GetWeaponName; - typedef void*(__cdecl * BG_LoadWeaponDef_LoadObj_t)(const char* filename); + typedef void*(__cdecl * BG_LoadWeaponDef_LoadObj_t)(const char* name); extern BG_LoadWeaponDef_LoadObj_t BG_LoadWeaponDef_LoadObj; + typedef WeaponCompleteDef*(__cdecl * BG_LoadWeaponCompleteDefInternal_t)(const char* folder, const char* name); + extern BG_LoadWeaponCompleteDefInternal_t BG_LoadWeaponCompleteDefInternal; + typedef WeaponDef*(__cdecl * BG_GetWeaponDef_t)(unsigned int weaponIndex); extern BG_GetWeaponDef_t BG_GetWeaponDef; @@ -235,7 +238,7 @@ namespace Game typedef const char *(__cdecl * DB_GetXAssetTypeName_t)(XAssetType type); extern DB_GetXAssetTypeName_t DB_GetXAssetTypeName; - typedef const char *(__cdecl * DB_IsXAssetDefault_t)(XAssetType type, const char* name); + typedef int(__cdecl * DB_IsXAssetDefault_t)(XAssetType type, const char* name); extern DB_IsXAssetDefault_t DB_IsXAssetDefault; typedef void(__cdecl * DB_GetRawBuffer_t)(RawFile* rawfile, char* buffer, int size); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index cbc87b27..09b623c3 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -4455,7 +4455,7 @@ namespace Game IMPACT_TYPE_COUNT = 0xB, }; - struct /*__declspec(align(2))*/ WeaponCompleteDef + struct WeaponCompleteDef { const char *szInternalName; WeaponDef *weapDef;