[Weapon] Fix loading code

This commit is contained in:
Diavolo 2022-07-02 18:30:35 +02:00
parent 69bbdc0e9d
commit 8127aa395e
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
5 changed files with 17 additions and 13 deletions

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -4455,7 +4455,7 @@ namespace Game
IMPACT_TYPE_COUNT = 0xB,
};
struct /*__declspec(align(2))*/ WeaponCompleteDef
struct WeaponCompleteDef
{
const char *szInternalName;
WeaponDef *weapDef;