Skip to content

Commit

Permalink
Merge pull request #7 from tmp64/gamedata-vtable
Browse files Browse the repository at this point in the history
AMXX GameData VTable Offsets
  • Loading branch information
tmp64 authored Aug 19, 2023
2 parents ee2a118 + d815a2a commit 50395a3
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 145 deletions.
11 changes: 11 additions & 0 deletions gamedir/amxmodx/data/gamedata/weaponmod.games/master.games.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"Game Master"
{
//
// Half-Life: Deathmatch
//

"valve/offsets-vtable.txt"
{
"game" "valve"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"Games"
{
"#default"
{
"Offsets"
{
"AddAmmo"
{
"windows" "57"
"linux" "59"
}

"AddToPlayer"
{
"windows" "58"
"linux" "60"
}

"CanDeploy"
{
"windows" "61"
"linux" "63"
}

"Deploy"
{
"windows" "62"
"linux" "64"
}

"CanHolster"
{
"windows" "63"
"linux" "65"
}

"Holster"
{
"windows" "64"
"linux" "66"
}

"ItemPostFrame"
{
"windows" "67"
"linux" "69"
}

"ItemSlot"
{
"windows" "75"
"linux" "77"
}

"IsUseable"
{
"windows" "82"
"linux" "84"
}
}
}
}
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_sources(
sdk/amxx_gameconfigs.h
sdk/amxxmodule.cpp
sdk/amxxmodule.h
sdk/HLTypeConversion.h
Expand Down
65 changes: 65 additions & 0 deletions src/sdk/amxx_gameconfigs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Half-Life Weapon Mod
* Copyright (c) 2012 - 2023 AGHL.RU Dev Team
*
* http://aghl.ru/forum/ - Russian Half-Life and Adrenaline Gamer Community
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*
*/

#pragma once
#include <memory>
#include "sdk/amxxmodule.h"
#include "sdk/IGameConfigs.h"
#include "wpnmod_log.h"

//! Deleter for IGameConfig pointers.
struct AmxxGameConfigDeleter
{
void operator()(IGameConfig* pCfg)
{
MF_GetConfigManager()->CloseGameConfigFile(pCfg);
}
};

//! Smart pointer for IGameConfig.
using IGameConfigPtr = std::unique_ptr<IGameConfig, AmxxGameConfigDeleter>;

//! Loads a game config file. Crashes if fails.
static IGameConfigPtr WpnMod_LoadGameConfigFile(const char* file)
{
IGameConfig* pCfg = nullptr;
char error[256] = "";

if (!MF_GetConfigManager()->LoadGameConfigFile(file, &pCfg, error, sizeof(error)))
{
WPNMOD_LOG("Failed to load game config '%s': %s\n", file, error);
std::abort();
}

return IGameConfigPtr(pCfg, AmxxGameConfigDeleter());
}
48 changes: 24 additions & 24 deletions src/wpnmod_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@

inline BOOL CAN_DEPLOY(edict_t* pentItem)
{
return reinterpret_cast<FuncCanDeploy>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_CanDeploy)])(pentItem->pvPrivateData, DUMMY_VAL);
return GetEntityVTableFunc<FuncCanDeploy>(pentItem, VO_CanDeploy)(pentItem->pvPrivateData, DUMMY_VAL);
}

// virtual BOOL Deploy(void);
Expand All @@ -277,7 +277,7 @@

inline BOOL DEPLOY(edict_t* pentItem)
{
return reinterpret_cast<FuncDeploy>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_Deploy)])(pentItem->pvPrivateData, DUMMY_VAL);
return GetEntityVTableFunc<FuncDeploy>(pentItem, VO_Deploy)(pentItem->pvPrivateData, DUMMY_VAL);
}

// virtual BOOL CanHolster(void);
Expand All @@ -289,7 +289,7 @@

inline BOOL CAN_HOLSTER( edict_t* pentItem )
{
return reinterpret_cast<FuncCanHolster>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_CanHolster)])(pentItem->pvPrivateData, DUMMY_VAL);
return GetEntityVTableFunc<FuncCanHolster>(pentItem, VO_CanHolster)(pentItem->pvPrivateData, DUMMY_VAL);
}

// virtual void Holster(int skiplocal = 0);
Expand All @@ -301,7 +301,7 @@

inline void HOLSTER(edict_t* pentItem)
{
reinterpret_cast<FuncHolster>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_Holster)])(pentItem->pvPrivateData, DUMMY_VAL, 0);
GetEntityVTableFunc<FuncHolster>(pentItem, VO_Holster)(pentItem->pvPrivateData, DUMMY_VAL, 0);
}

// virtual void ItemPostFrame(void);
Expand All @@ -320,7 +320,7 @@

inline BOOL IS_USEABLE(edict_t* pentItem)
{
return reinterpret_cast<FuncIsUseable>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_IsUseable)])(pentItem->pvPrivateData, DUMMY_VAL);
return GetEntityVTableFunc<FuncIsUseable>(pentItem, VO_IsUseable)(pentItem->pvPrivateData, DUMMY_VAL);
}

// virtual int AddToPlayer(CBasePlayer* pPlayer);
Expand All @@ -332,7 +332,7 @@

inline int ADD_TO_PLAYER(edict_t* pentItem, edict_t* pentPlayer)
{
return reinterpret_cast<FuncAddToPlayer>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_AddToPlayer)])(pentItem->pvPrivateData, DUMMY_VAL, pentPlayer->pvPrivateData);
return GetEntityVTableFunc<FuncAddToPlayer>(pentItem, VO_AddToPlayer)(pentItem->pvPrivateData, DUMMY_VAL, pentPlayer->pvPrivateData);
}

// virtual int ItemSlot(void);
Expand All @@ -344,7 +344,7 @@

inline int ITEM_SLOT(edict_t* pentItem)
{
return reinterpret_cast<FuncItemSlot>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_ItemSlot)])(pentItem->pvPrivateData, DUMMY_VAL);
return GetEntityVTableFunc<FuncItemSlot>(pentItem, VO_ItemSlot)(pentItem->pvPrivateData, DUMMY_VAL);
}

// virtual CBaseEntity* Respawn(void);
Expand All @@ -356,7 +356,7 @@

inline void* RESPAWN(edict_t* pentItem)
{
return reinterpret_cast<FuncRespawn>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_Respawn)])(pentItem->pvPrivateData, DUMMY_VAL);
return GetEntityVTableFunc<FuncRespawn>(pentItem, VO_Respawn)(pentItem->pvPrivateData, DUMMY_VAL);
}

// void Spawn(void);
Expand Down Expand Up @@ -384,28 +384,28 @@
//
inline int GET_DAMAGE_DECAL(edict_t* pentEntity)
{
return reinterpret_cast<FuncDamageDecal>(GET_VTABLE_ENT(pentEntity)[GET_VTABLE_OFFSET(VO_DamageDecal)])(pentEntity->pvPrivateData, DUMMY_VAL, 0);
return GetEntityVTableFunc<FuncDamageDecal>(pentEntity, VO_DamageDecal)(pentEntity->pvPrivateData, DUMMY_VAL, 0);
}

// int Classify( void );
//
inline int CLASSIFY(edict_t* pentEntity)
{
return reinterpret_cast<FuncClassify>(GET_VTABLE_ENT(pentEntity)[GET_VTABLE_OFFSET(VO_Classify)])(pentEntity->pvPrivateData, DUMMY_VAL);
return GetEntityVTableFunc<FuncClassify>(pentEntity, VO_Classify)(pentEntity->pvPrivateData, DUMMY_VAL);
}

// virtual void TraceAttack(entvars_t* pevAttacker, float flDamage, Vector vecDir, TraceResult* ptr, int bitsDamageType);
//
inline void TRACE_ATTACK(edict_t* pentVictim, edict_t* pentAttacker, float damage, Vector vecDir, TraceResult tr, int bitsDamageType)
{
reinterpret_cast<FuncTraceAttack>(GET_VTABLE_ENT(pentVictim)[GET_VTABLE_OFFSET(VO_TraceAttack)])(pentVictim->pvPrivateData, DUMMY_VAL, VARS(pentAttacker), damage, vecDir, &tr, bitsDamageType);
GetEntityVTableFunc<FuncTraceAttack>(pentVictim, VO_TraceAttack)(pentVictim->pvPrivateData, DUMMY_VAL, VARS(pentAttacker), damage, vecDir, &tr, bitsDamageType);
}

// virtual int TakeDamage(entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType);
//
inline int TAKE_DAMAGE(edict_t* pentVictim, edict_t* pentInflictor, edict_t* pentAttacker, float damage, int bitsDamageType)
{
return reinterpret_cast<FuncTakeDamage>(GET_VTABLE_ENT(pentVictim)[GET_VTABLE_OFFSET(VO_TakeDamage)])(pentVictim->pvPrivateData, DUMMY_VAL, VARS(pentInflictor), VARS(pentAttacker), damage, bitsDamageType);
return GetEntityVTableFunc<FuncTakeDamage>(pentVictim, VO_TakeDamage)(pentVictim->pvPrivateData, DUMMY_VAL, VARS(pentInflictor), VARS(pentAttacker), damage, bitsDamageType);
}

#else
Expand Down Expand Up @@ -467,7 +467,7 @@

inline BOOL CAN_DEPLOY(edict_t* pentItem)
{
return reinterpret_cast<FuncCanDeploy>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_CanDeploy)])(pentItem->pvPrivateData);
return GetEntityVTableFunc<FuncCanDeploy>(pentItem, VO_CanDeploy)(pentItem->pvPrivateData);
}

// virtual BOOL Deploy(void);
Expand All @@ -479,7 +479,7 @@

inline BOOL DEPLOY(edict_t* pentItem)
{
return reinterpret_cast<FuncDeploy>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_Deploy)])(pentItem->pvPrivateData);
return GetEntityVTableFunc<FuncDeploy>(pentItem, VO_Deploy)(pentItem->pvPrivateData);
}

// virtual BOOL CanHolster(void);
Expand All @@ -491,7 +491,7 @@

inline BOOL CAN_HOLSTER(edict_t* pentItem)
{
return reinterpret_cast<FuncCanHolster>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_CanHolster)])(pentItem->pvPrivateData);
return GetEntityVTableFunc<FuncCanHolster>(pentItem, VO_CanHolster)(pentItem->pvPrivateData);
}

// virtual void Holster(int skiplocal = 0);
Expand All @@ -503,7 +503,7 @@

inline void HOLSTER(edict_t* pentItem)
{
reinterpret_cast<FuncHolster>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_Holster)])(pentItem->pvPrivateData, 0);
GetEntityVTableFunc<FuncHolster>(pentItem, VO_Holster)(pentItem->pvPrivateData, 0);
}

// virtual void ItemPostFrame(void);
Expand All @@ -522,7 +522,7 @@

inline BOOL IS_USEABLE(edict_t* pentItem)
{
return reinterpret_cast<FuncIsUseable>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_IsUseable)])(pentItem->pvPrivateData);
return GetEntityVTableFunc<FuncIsUseable>(pentItem, VO_IsUseable)(pentItem->pvPrivateData);
}

// virtual int AddToPlayer(CBasePlayer* pPlayer);
Expand All @@ -534,7 +534,7 @@

inline int ADD_TO_PLAYER(edict_t* pentItem, edict_t* pentPlayer)
{
return reinterpret_cast<FuncAddToPlayer>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_AddToPlayer)])(pentItem->pvPrivateData, pentPlayer->pvPrivateData);
return GetEntityVTableFunc<FuncAddToPlayer>(pentItem, VO_AddToPlayer)(pentItem->pvPrivateData, pentPlayer->pvPrivateData);
}

// virtual int ItemSlot(void);
Expand All @@ -546,7 +546,7 @@

inline int ITEM_SLOT(edict_t* pentItem)
{
return reinterpret_cast<FuncItemSlot>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_ItemSlot)])(pentItem->pvPrivateData);
return GetEntityVTableFunc<FuncItemSlot>(pentItem, VO_ItemSlot)(pentItem->pvPrivateData);
}

// virtual CBaseEntity* Respawn(void);
Expand All @@ -558,7 +558,7 @@

inline void* RESPAWN(edict_t* pentItem)
{
return reinterpret_cast<FuncRespawn>(GET_VTABLE_ENT(pentItem)[GET_VTABLE_OFFSET(VO_Respawn)])(pentItem->pvPrivateData);
return GetEntityVTableFunc<FuncRespawn>(pentItem, VO_Respawn)(pentItem->pvPrivateData);
}

// void Spawn(void);
Expand Down Expand Up @@ -586,28 +586,28 @@
//
inline int GET_DAMAGE_DECAL(edict_t* pentEntity)
{
return reinterpret_cast<FuncDamageDecal>(GET_VTABLE_ENT(pentEntity)[GET_VTABLE_OFFSET(VO_DamageDecal)])(pentEntity->pvPrivateData, 0);
return GetEntityVTableFunc<FuncDamageDecal>(pentEntity, VO_DamageDecal)(pentEntity->pvPrivateData, 0);
}

// int Classify( void );
//
inline int CLASSIFY(edict_t* pentEntity)
{
return reinterpret_cast<FuncClassify>(GET_VTABLE_ENT(pentEntity)[GET_VTABLE_OFFSET(VO_Classify)])(pentEntity->pvPrivateData);
return GetEntityVTableFunc<FuncClassify>(pentEntity, VO_Classify)(pentEntity->pvPrivateData);
}

// virtual void TraceAttack(entvars_t* pevAttacker, float flDamage, Vector vecDir, TraceResult* ptr, int bitsDamageType);
//
inline void TRACE_ATTACK(edict_t* pentVictim, edict_t* pentAttacker, float damage, Vector vecDir, TraceResult tr, int bitsDamageType)
{
reinterpret_cast<FuncTraceAttack>(GET_VTABLE_ENT(pentVictim)[GET_VTABLE_OFFSET(VO_TraceAttack)])(pentVictim->pvPrivateData, VARS(pentAttacker), damage, vecDir, &tr, bitsDamageType);
GetEntityVTableFunc<FuncTraceAttack>(pentVictim, VO_TraceAttack)(pentVictim->pvPrivateData, VARS(pentAttacker), damage, vecDir, &tr, bitsDamageType);
}

// virtual int TakeDamage(entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType);
//
inline int TAKE_DAMAGE(edict_t* pentVictim, edict_t* pentInflictor, edict_t* pentAttacker, float damage, int bitsDamageType)
{
return reinterpret_cast<FuncTakeDamage>(GET_VTABLE_ENT(pentVictim)[GET_VTABLE_OFFSET(VO_TakeDamage)])(pentVictim->pvPrivateData, VARS(pentInflictor), VARS(pentAttacker), damage, bitsDamageType);
return GetEntityVTableFunc<FuncTakeDamage>(pentVictim, VO_TakeDamage)(pentVictim->pvPrivateData, VARS(pentInflictor), VARS(pentAttacker), damage, bitsDamageType);
}

#endif
Expand Down
Loading

0 comments on commit 50395a3

Please sign in to comment.