From 8b014a5b4d4ba9a7c4d21b1949ae4bdc44e4bc24 Mon Sep 17 00:00:00 2001 From: quaK <38787176+Joelrau@users.noreply.github.com> Date: Tue, 30 Aug 2022 19:23:41 +0300 Subject: [PATCH] use tag_weapon when other tags aren't found --- src/client/component/weapon.cpp | 23 +++++++++++++++++++++++ src/client/game/structs.hpp | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/src/client/component/weapon.cpp b/src/client/component/weapon.cpp index 4bfa3713..b323332e 100644 --- a/src/client/component/weapon.cpp +++ b/src/client/component/weapon.cpp @@ -42,6 +42,25 @@ namespace weapon } } + utils::hook::detour xmodel_get_bone_index_hook; + bool xmodel_get_bone_index_stub(game::XModel* model, game::scr_string_t name, unsigned int offset, char* index) + { + auto result = xmodel_get_bone_index_hook.invoke(model, name, offset, index); + if (!result) + { + if (name == game::SL_GetString("tag_weapon_right", 0) || + name == game::SL_GetString("tag_knife_attach", 0)) + { + result = xmodel_get_bone_index_hook.invoke(model, game::SL_GetString("tag_weapon", 0), offset, index); + if (result) + { + console::debug("using tag_weapon instead of %s (%s, %d)\n", game::SL_ConvertToString(name), model->name, offset); + } + } + } + return result; + } + template void set_weapon_field(const std::string& weapon_name, unsigned int field, T value) { @@ -86,8 +105,12 @@ namespace weapon { if (!game::environment::is_sp()) { + // precache all weapons that are loaded in zones g_setup_level_weapon_def_hook.create(0x462630_b, g_setup_level_weapon_def_stub); + // use tag_weapon if tag_weapon_right or tag_knife_attach are not found on model + xmodel_get_bone_index_hook.create(0x5C82B0_b, xmodel_get_bone_index_stub); + // disable custom weapon index mismatch (fix for custom attachments) (NEEDS TESTING) //utils::hook::set(0x11B910_b, 0xC3); // CG_SetupCustomWeapon } diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index fd6db443..8b2d7ac6 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1411,6 +1411,11 @@ namespace game const char* name; }; + struct XModel + { + const char* name; + }; + struct WeaponDef { const char* name; @@ -1427,6 +1432,7 @@ namespace game LuaFile* luaFile; GfxImage* image; TTF* ttf; + XModel* model; WeaponDef* weapon; };