diff --git a/gamedir/amxmodx/data/gamedata/weaponmod.games/valve/settings.txt b/gamedir/amxmodx/data/gamedata/weaponmod.games/valve/settings.txt index 3e0e60a..667ec71 100644 --- a/gamedir/amxmodx/data/gamedata/weaponmod.games/valve/settings.txt +++ b/gamedir/amxmodx/data/gamedata/weaponmod.games/valve/settings.txt @@ -5,7 +5,7 @@ "Keys" { "reference_weapon" "weapon_crowbar" - "reference_ammo" "ammo_rpgclip" + "reference_ammobox" "ammo_rpgclip" } } } diff --git a/src/wpnmod_config.cpp b/src/wpnmod_config.cpp index 4bd28fa..6cd7cbf 100644 --- a/src/wpnmod_config.cpp +++ b/src/wpnmod_config.cpp @@ -49,6 +49,11 @@ cvar_t* cvar_mp_weaponstay = NULL; +void CConfig::LoadGameData(void) +{ + m_pAmxxGameData = WpnMod_LoadGameConfigFile("weaponmod.games"); +} + void CConfig::InitGameMod(void) { m_bInited = true; @@ -172,6 +177,7 @@ void CConfig::ServerDeactivate(void) UnsetHookVirtual(&g_PlayerPostThink_Hook); m_pEquipEnt = NULL; + m_pAmxxGameData = nullptr; } diff --git a/src/wpnmod_config.h b/src/wpnmod_config.h index 7896d9d..5e0421b 100644 --- a/src/wpnmod_config.h +++ b/src/wpnmod_config.h @@ -35,6 +35,7 @@ #define _CONFIG_H #include "sdk/amxxmodule.h" +#include "sdk/amxx_gameconfigs.h" #include #include @@ -142,6 +143,7 @@ class CConfig bool m_bInited; char m_cfgpath[1024]; SUBMOD m_GameMod; + IGameConfigPtr m_pAmxxGameData; public: CConfig() @@ -157,6 +159,7 @@ class CConfig std::vector m_pStartAmmoList; std::vector m_pBlockedItemsList; + void LoadGameData (void); void InitGameMod (void); void SetConfigFile (void); char* GetConfigFile (void) { return &m_cfgpath[0]; }; @@ -173,6 +176,9 @@ class CConfig void DecalPushList (const char *name); bool IsItemBlocked (const char *name); + //! @returns the game data config. Loaded from amxmodx/data/gamedata/weaponmod.games. + IGameConfig* GetGameData() { return m_pAmxxGameData.get(); } + static void ServerCommand (void); static bool ClientCommand (edict_t *pEntity); }; diff --git a/src/wpnmod_hooks.cpp b/src/wpnmod_hooks.cpp index 06b2309..ebcef28 100644 --- a/src/wpnmod_hooks.cpp +++ b/src/wpnmod_hooks.cpp @@ -31,6 +31,7 @@ * */ +#include #include "wpnmod_entity.h" #include "wpnmod_parse.h" #include "wpnmod_utils.h" @@ -63,6 +64,20 @@ VirtualHookData g_PlayerSpawn_Hook = VHOOK("player", VO_Spawn, Player_Spaw VirtualHookData g_PlayerPostThink_Hook = VHOOK("player", VO_Player_PostThink, Player_PostThink); +void Hooks_InitReferenceEntities() +{ + auto fnInitArray = [](const char* name, auto& arr) + { + assert(name); + + for (VirtualHookData& i : arr) + i.classname = name; + }; + + fnInitArray(gWeaponReference, g_CrowbarHooks); + fnInitArray(gAmmoBoxReference, g_AmmoBoxRefHooks); +} + #ifdef WIN32 void __fastcall AmmoBox_Spawn(void* pvItem) #else diff --git a/src/wpnmod_hooks.h b/src/wpnmod_hooks.h index 53027e3..a70e56c 100644 --- a/src/wpnmod_hooks.h +++ b/src/wpnmod_hooks.h @@ -40,6 +40,7 @@ #include "wpnmod_utils.h" #include "wpnmod_vtable.h" +void Hooks_InitReferenceEntities(); #ifdef WIN32 @@ -169,12 +170,12 @@ #define VHOOK_WEAPON_REF(call) \ { \ - gWeaponReference, VO_##call, (void*)Weapon_##call, NULL, NULL, \ + nullptr, VO_##call, (void*)Weapon_##call, NULL, NULL, \ } \ #define VHOOK_AMMOBOX_REF(call) \ { \ - gAmmoBoxReference, VO_##call, (void*)AmmoBox_##call, NULL, NULL, \ + nullptr, VO_##call, (void*)AmmoBox_##call, NULL, NULL, \ } \ enum AmmoBoxRefHooks diff --git a/src/wpnmod_items.cpp b/src/wpnmod_items.cpp index 576fbba..9b703eb 100644 --- a/src/wpnmod_items.cpp +++ b/src/wpnmod_items.cpp @@ -39,8 +39,8 @@ CItems g_Items; -const char* gWeaponReference = "weapon_crowbar"; -const char* gAmmoBoxReference = "ammo_rpgclip"; +const char* gWeaponReference; +const char* gAmmoBoxReference; CItems::CItems() { @@ -57,6 +57,28 @@ CItems::CItems() memset(m_WeaponsInfo, 0, sizeof(m_WeaponsInfo)); } +void CItems::LoadGameData() +{ + // Load reference weapons + IGameConfig* pCfg = g_Config.GetGameData(); + gWeaponReference = pCfg->GetKeyValue("reference_weapon"); + if (!gWeaponReference) + WPNMOD_LOG(" reference_weapon not found\n"); + + gAmmoBoxReference = pCfg->GetKeyValue("reference_ammobox"); + if (!gAmmoBoxReference) + WPNMOD_LOG(" reference_ammobox not found\n"); + + if (!gWeaponReference || !gAmmoBoxReference) + { + WPNMOD_LOG("Invalid WeaponMod setup. gamedata is missing.\n"); + WPNMOD_LOG("The server will now crash. Goodbye.\n"); + std::abort(); + } + + Hooks_InitReferenceEntities(); +} + void CItems::AllocWeaponSlots(int slots, int positions) { m_iMaxWeaponSlots = slots; diff --git a/src/wpnmod_items.h b/src/wpnmod_items.h index 9c02b66..2bbd857 100644 --- a/src/wpnmod_items.h +++ b/src/wpnmod_items.h @@ -179,6 +179,7 @@ class CItems int m_iMaxWeaponSlots; int m_iMaxWeaponPositions; + void LoadGameData(); void AllocWeaponSlots (int slots, int positions); void FreeWeaponSlots (void); bool CheckSlots (int iWeaponID); diff --git a/src/wpnmod_main.cpp b/src/wpnmod_main.cpp index 9ea5003..1c0b1a6 100644 --- a/src/wpnmod_main.cpp +++ b/src/wpnmod_main.cpp @@ -46,6 +46,8 @@ int AmxxCheckGame(const char* game) void OnAmxxAttach(void) { MF_AddNatives(Natives); + g_Config.LoadGameData(); + g_Items.LoadGameData(); } // Called by Meta_Attach. diff --git a/src/wpnmod_vtable.cpp b/src/wpnmod_vtable.cpp index 257155c..1c69e8b 100644 --- a/src/wpnmod_vtable.cpp +++ b/src/wpnmod_vtable.cpp @@ -32,7 +32,6 @@ */ #include -#include "sdk/amxx_gameconfigs.h" #include "wpnmod_vtable.h" #include "wpnmod_memory.h" #include "wpnmod_config.h" @@ -90,7 +89,7 @@ void Vtable_Init(void) g_OffsetInitializers[VO_AddAmmo] = { "CBasePlayerAmmo", "AddAmmo" }; // Load offsets - IGameConfigPtr pWpnModCfg = WpnMod_LoadGameConfigFile("weaponmod.games"); + IGameConfig* pWpnModCfg = g_Config.GetGameData(); IGameConfigPtr pAmxxCfg = WpnMod_LoadGameConfigFile("common.games"); bool anyNotFound = false; @@ -137,10 +136,9 @@ void Vtable_Init(void) } // Load pev offset - IGameConfigPtr pEntityCfg = WpnMod_LoadGameConfigFile("common.games"); TypeDescription pevOffset; - if (!pEntityCfg->GetOffsetByClass("CBaseEntity", "pev", &pevOffset)) + if (!pAmxxCfg->GetOffsetByClass("CBaseEntity", "pev", &pevOffset)) { WPNMOD_LOG("CBaseEntity::pev offset not found\n"); std::abort();