From 900f541dcb46b4dbe2570fe583b4288627c1356a Mon Sep 17 00:00:00 2001 From: AyeZeeBB Date: Tue, 7 Jul 2026 00:14:06 -0500 Subject: [PATCH 1/2] Add server frame plugin callback hook Bumps the plugin system interface to VPluginSystem003 and adds a new `CServer_RunFrame` callback that plugins can register/unregister and receive each server frame. Also exposes additional server-side entity/player/combat-character getters (position/velocity, ownership/move handles, view/weapon handles, inventory snapshots) to support richer plugin-side inspection, and inlines `CBaseEntity::GetModelName` in the header. --- src/engine/server/server.cpp | 6 +++++- src/game/server/basecombatcharacter.h | 7 ++++++- src/game/server/baseentity.cpp | 5 ----- src/game/server/baseentity.h | 8 +++++++- src/game/server/player.h | 2 ++ src/pluginsystem/ipluginsystem.h | 5 ++++- src/pluginsystem/pluginsystem.cpp | 10 ++++++++++ src/pluginsystem/pluginsystem.h | 1 + 8 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 27b651f74..54ad407ac 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1,4 +1,4 @@ -//=============================================================================// +//=============================================================================// // // Purpose: // @@ -223,6 +223,9 @@ void CServer::BroadcastMessage(CNetMessage* const msg, const bool onlyActive, co void CServer::RunFrame(CServer* pServer) { CServer__RunFrame(pServer); + + for (auto& callback : !PluginSystem()->GetServerFrameCallbacks()) + callback.Function()(pServer); } bool CServer::SpawnServer(CServer* pServer, const char* pszMapName, const char* pszMapGroupName) @@ -249,3 +252,4 @@ void VServer::Detour(const bool bAttach) const /////////////////////////////////////////////////////////////////////////////// CServer* g_pServer = nullptr; CClientExtended CServer::sm_ClientsExtended[MAX_PLAYERS]; + diff --git a/src/game/server/basecombatcharacter.h b/src/game/server/basecombatcharacter.h index 157e09798..f4da59e57 100644 --- a/src/game/server/basecombatcharacter.h +++ b/src/game/server/basecombatcharacter.h @@ -1,4 +1,4 @@ -//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======// +//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======// // // Purpose: Base combat character with no AI // @@ -50,6 +50,11 @@ class CBaseCombatCharacter : public CBaseAnimatingOverlay Hull_e GetHullType() const { return m_eHull; } void SetHullType(Hull_e hullType) { m_eHull = hullType; } + const WeaponInventory& GetWeaponInventory() const { return m_inventory; } + const EHANDLE* GetLatestPrimaryWeapons() const { return m_latestPrimaryWeapons; } + const EHANDLE* GetLatest3pWeapons() const { return m_latest3pWeaponGettingEquipped; } + const EHANDLE* GetSwitchingWeapons() const { return m_weaponGettingSwitchedOut; } + private: bool m_bPreventWeaponPickup; char gap_15b1[3]; diff --git a/src/game/server/baseentity.cpp b/src/game/server/baseentity.cpp index b568faa03..3b74f6ec6 100644 --- a/src/game/server/baseentity.cpp +++ b/src/game/server/baseentity.cpp @@ -48,11 +48,6 @@ model_t* CBaseEntity::GetModel(void) return (model_t*)g_pModelInfoServer->GetModel(GetModelIndex()); } -inline string_t CBaseEntity::GetModelName(void) const -{ - return m_ModelName; -} - inline int CBaseEntity::GetModelIndex(void) const { return m_nModelIndex; diff --git a/src/game/server/baseentity.h b/src/game/server/baseentity.h index 552f20d64..01204baaa 100644 --- a/src/game/server/baseentity.h +++ b/src/game/server/baseentity.h @@ -118,12 +118,18 @@ class CBaseEntity : public IServerEntity model_t* GetModel(void); int GetModelIndex(void) const; // Virtual in-engine! - string_t GetModelName(void) const; // Virtual in-engine! + inline string_t GetModelName(void) const { return m_ModelName; } const Vector3D& GetViewOffset(void) const { return m_vecViewOffset; } + const Vector3D& GetAbsOrigin(void) const { return m_vecAbsOrigin; } + const Vector3D& GetAbsVelocity(void) const { return m_vecAbsVelocity; } const Vector3D& GetVecPrevAbsOrigin(void) const { return m_vecPrevAbsOrigin; } inline edict_t GetEdict(void) const { return NetworkProp()->GetEdict(); } inline string_t GetEntityName(void) const { return m_iName; } + inline const EHANDLE& GetMoveParentHandle(void) const { return m_hMoveParent; } + inline const EHANDLE& GetMoveChildHandle(void) const { return m_hMoveChild; } + inline const EHANDLE& GetMovePeerHandle(void) const { return m_hMovePeer; } + inline const EHANDLE& GetOwnerEntityHandle(void) const { return m_hOwnerEntity; } inline int GetFlags(void) const { return m_fFlags; } diff --git a/src/game/server/player.h b/src/game/server/player.h index 6f24732e0..4c1d756ad 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -209,6 +209,8 @@ class CPlayer : public CBaseCombatCharacter char GetLifeState(void) const { return m_lifeState; } int GetTeamNum(void) const { return m_iTeamNum; } + const EHANDLE& GetThirdPersonEnt() const { return m_hThirdPersonEnt; } + const EHANDLE* GetViewModels() const { return m_hViewModels; } private: char m_szNetname[256]; bool m_zoomViewdriftDebounceEnabled; diff --git a/src/pluginsystem/ipluginsystem.h b/src/pluginsystem/ipluginsystem.h index 3d757abb5..94b52a3b9 100644 --- a/src/pluginsystem/ipluginsystem.h +++ b/src/pluginsystem/ipluginsystem.h @@ -1,6 +1,8 @@ #pragma once -#define INTERFACEVERSION_PLUGINSYSTEM "VPluginSystem002" +#define INTERFACEVERSION_PLUGINSYSTEM "VPluginSystem003" + +class CServer; struct PluginOperation_s { @@ -23,6 +25,7 @@ struct PluginOperation_s OnRegisterServerScriptFunctions = 5, OnRegisterClientScriptFunctions = 6, OnRegisterUIScriptFunctions = 7, + CServer_RunFrame = 8, }; PluginCommand_e commandId; diff --git a/src/pluginsystem/pluginsystem.cpp b/src/pluginsystem/pluginsystem.cpp index 97eed9ec5..9ebe09084 100644 --- a/src/pluginsystem/pluginsystem.cpp +++ b/src/pluginsystem/pluginsystem.cpp @@ -246,6 +246,11 @@ void CPluginSystem::InstallCallback(PluginOperation_s* const pio) ADD_PLUGIN_CALLBACK(OnRegisterUIScriptFunctionsFn, GetRegisterUIScriptFuncsCallbacks(), pio->function); break; } + case PluginOperation_s::PluginCallback_e::CServer_RunFrame: + { + ADD_PLUGIN_CALLBACK(OnServerFrameFn, GetServerFrameCallbacks(), pio->function); + break; + } default: Assert(0); // Unimplemented. break; @@ -307,6 +312,11 @@ void CPluginSystem::RemoveCallback(PluginOperation_s* const pio) REMOVE_PLUGIN_CALLBACK(OnRegisterUIScriptFunctionsFn, GetRegisterUIScriptFuncsCallbacks(), pio->function); break; } + case PluginOperation_s::PluginCallback_e::CServer_RunFrame: + { + REMOVE_PLUGIN_CALLBACK(OnServerFrameFn, GetServerFrameCallbacks(), pio->function); + break; + } default: Assert(0); // Unimplemented. break; diff --git a/src/pluginsystem/pluginsystem.h b/src/pluginsystem/pluginsystem.h index 1d1387ac9..822d51051 100644 --- a/src/pluginsystem/pluginsystem.h +++ b/src/pluginsystem/pluginsystem.h @@ -164,6 +164,7 @@ class CPluginSystem : public IPluginSystem CREATE_PLUGIN_CALLBACK(OnRegisterServerScriptFunctionsFn, void(*)(CSquirrelVM*), GetRegisterServerScriptFuncsCallbacks, registerServerScriptFuncsCallbacks); CREATE_PLUGIN_CALLBACK(OnRegisterClientScriptFunctionsFn, void(*)(CSquirrelVM*), GetRegisterClientScriptFuncsCallbacks, registerClientScriptFuncsCallbacks); CREATE_PLUGIN_CALLBACK(OnRegisterUIScriptFunctionsFn, void(*)(CSquirrelVM*), GetRegisterUIScriptFuncsCallbacks, registerUIScriptFuncsCallbacks); + CREATE_PLUGIN_CALLBACK(OnServerFrameFn, void(*)(CServer*), GetServerFrameCallbacks, serverFrameCallbacks); #undef CREATE_PLUGIN_CALLBACK From 8d8fa8a4f3e0a7fba6a4ea69985e30e9d6e095ce Mon Sep 17 00:00:00 2001 From: AyeZeeBB Date: Tue, 7 Jul 2026 17:32:57 -0500 Subject: [PATCH 2/2] Inline GetModelIndex and revert API version Move `CBaseEntity::GetModelIndex()` into the header as an inline accessor and remove the duplicate source definition. Also revert the plugin system interface version string from `VPluginSystem003` to `VPluginSystem002` --- src/game/server/baseentity.cpp | 5 ----- src/game/server/baseentity.h | 2 +- src/pluginsystem/ipluginsystem.h | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/game/server/baseentity.cpp b/src/game/server/baseentity.cpp index 3b74f6ec6..7ec1669ed 100644 --- a/src/game/server/baseentity.cpp +++ b/src/game/server/baseentity.cpp @@ -48,11 +48,6 @@ model_t* CBaseEntity::GetModel(void) return (model_t*)g_pModelInfoServer->GetModel(GetModelIndex()); } -inline int CBaseEntity::GetModelIndex(void) const -{ - return m_nModelIndex; -} - const HSCRIPT CBaseEntity::GetScriptInstance() { return v_CBaseEntity__GetScriptInstance(this); diff --git a/src/game/server/baseentity.h b/src/game/server/baseentity.h index 01204baaa..549c8a897 100644 --- a/src/game/server/baseentity.h +++ b/src/game/server/baseentity.h @@ -117,7 +117,7 @@ class CBaseEntity : public IServerEntity const CServerNetworkProperty* NetworkProp() const; model_t* GetModel(void); - int GetModelIndex(void) const; // Virtual in-engine! + inline int GetModelIndex(void) const { return m_nModelIndex; } // Virtual in-engine! inline string_t GetModelName(void) const { return m_ModelName; } const Vector3D& GetViewOffset(void) const { return m_vecViewOffset; } const Vector3D& GetAbsOrigin(void) const { return m_vecAbsOrigin; } diff --git a/src/pluginsystem/ipluginsystem.h b/src/pluginsystem/ipluginsystem.h index 94b52a3b9..aa994ad3a 100644 --- a/src/pluginsystem/ipluginsystem.h +++ b/src/pluginsystem/ipluginsystem.h @@ -1,6 +1,6 @@ #pragma once -#define INTERFACEVERSION_PLUGINSYSTEM "VPluginSystem003" +#define INTERFACEVERSION_PLUGINSYSTEM "VPluginSystem002" class CServer;