Add FreeGameRules hook, util api functions, player api functions (#808)

This commit is contained in:
fl0werD 2023-03-12 23:33:15 +04:00 committed by GitHub
parent 8ff30b4c3e
commit eb91f9280d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 11 deletions

View File

@ -71,7 +71,11 @@ ReGameFuncs_t g_ReGameApiFuncs = {
PlantBomb_api,
SpawnHeadGib_api,
SpawnRandomGibs_api
SpawnRandomGibs_api,
UTIL_RestartOther_api,
UTIL_ResetEntities_api,
UTIL_RemoveOther_api,
};
GAMEHOOK_REGISTRY(CBasePlayer_Spawn);
@ -204,6 +208,8 @@ GAMEHOOK_REGISTRY(CBasePlayer_Pain);
GAMEHOOK_REGISTRY(CBasePlayer_DeathSound);
GAMEHOOK_REGISTRY(CBasePlayer_JoiningThink);
GAMEHOOK_REGISTRY(FreeGameRules);
int CReGameApi::GetMajorVersion() {
return REGAMEDLL_API_VERSION_MAJOR;
}
@ -296,4 +302,17 @@ EXT_FUNC void AddMultiDamage_api(entvars_t *pevInflictor, CBaseEntity *pEntity,
AddMultiDamage(pevInflictor, pEntity, flDamage, bitsDamageType);
}
EXT_FUNC void UTIL_RestartOther_api(const char *szClassname) {
UTIL_RestartOther(szClassname);
}
EXT_FUNC void UTIL_ResetEntities_api() {
UTIL_ResetEntities();
}
EXT_FUNC void UTIL_RemoveOther_api(const char *szClassname, int nCount)
{
UTIL_RemoveOther(szClassname, nCount);
}
EXPOSE_SINGLE_INTERFACE(CReGameApi, IReGameApi, VRE_GAMEDLL_API_VERSION);

View File

@ -641,6 +641,10 @@ typedef IHookChainRegistryClassImpl<void, CBasePlayer> CReGameHookRegistry_CBase
typedef IHookChainClassImpl<void, CBasePlayer> CReGameHook_CBasePlayer_JoiningThink;
typedef IHookChainRegistryClassImpl<void, CBasePlayer> CReGameHookRegistry_CBasePlayer_JoiningThink;
// FreeGameRules hook
typedef IHookChainImpl<void, CGameRules **> CReGameHook_FreeGameRules;
typedef IHookChainRegistryImpl<void, CGameRules **> CReGameHookRegistry_FreeGameRules;
class CReGameHookchains: public IReGameHookchains {
public:
// CBasePlayer virtual
@ -774,6 +778,8 @@ public:
CReGameHookRegistry_CBasePlayer_DeathSound m_CBasePlayer_DeathSound;
CReGameHookRegistry_CBasePlayer_JoiningThink m_CBasePlayer_JoiningThink;
CReGameHookRegistry_FreeGameRules m_FreeGameRules;
public:
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
virtual IReGameHookRegistry_CBasePlayer_Precache *CBasePlayer_Precache();
@ -904,6 +910,8 @@ public:
virtual IReGameHookRegistry_CBasePlayer_Pain *CBasePlayer_Pain();
virtual IReGameHookRegistry_CBasePlayer_DeathSound *CBasePlayer_DeathSound();
virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink();
virtual IReGameHookRegistry_FreeGameRules *FreeGameRules();
};
extern CReGameHookchains g_ReGameHookchains;
@ -937,3 +945,7 @@ void RadiusDamage_api(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAtta
void ClearMultiDamage_api();
void ApplyMultiDamage_api(entvars_t *pevInflictor, entvars_t *pevAttacker);
void AddMultiDamage_api(entvars_t *pevInflictor, CBaseEntity *pEntity, float flDamage, int bitsDamageType);
void UTIL_RestartOther_api(const char *szClassname);
void UTIL_ResetEntities_api();
void UTIL_RemoveOther_api(const char *szClassname, int nCount = 0);

View File

@ -516,6 +516,21 @@ EXT_FUNC bool CCSPlayer::HintMessageEx(const char *pMessage, float duration, boo
return BasePlayer()->HintMessageEx(pMessage, duration, bDisplayIfPlayerDead, bOverride);
}
EXT_FUNC void CCSPlayer::Reset()
{
BasePlayer()->Reset();
}
EXT_FUNC void CCSPlayer::OnSpawnEquip(bool addDefault, bool equipGame)
{
BasePlayer()->OnSpawnEquip(addDefault, equipGame);
}
EXT_FUNC void CCSPlayer::SetScoreboardAttributes(CBasePlayer *destination)
{
BasePlayer()->SetScoreboardAttributes(destination);
}
EXT_FUNC bool CCSPlayer::CheckActivityInGame()
{
const CBasePlayer* pPlayer = BasePlayer();
@ -528,7 +543,7 @@ EXT_FUNC bool CCSPlayer::CheckActivityInGame()
return (fabs(deltaYaw) >= 0.1f && fabs(deltaPitch) >= 0.1f);
}
void CCSPlayer::Reset()
void CCSPlayer::ResetVars()
{
m_szModel[0] = '\0';

View File

@ -727,7 +727,7 @@ void EXT_FUNC ClientPutInServer(edict_t *pEntity)
}
#ifdef REGAMEDLL_API
pPlayer->CSPlayer()->Reset();
pPlayer->CSPlayer()->ResetVars();
#endif
UTIL_ClientPrintAll(HUD_PRINTNOTIFY, "#Game_connected", (sName[0] != '\0') ? sName : "<unconnected>");

View File

@ -141,3 +141,13 @@ CGameRules *EXT_FUNC __API_HOOK(InstallGameRules)()
return new CHalfLifeMultiplay;
}
LINK_HOOK_VOID_CHAIN(FreeGameRules, (CGameRules **pGameRules), pGameRules)
void EXT_FUNC __API_HOOK(FreeGameRules)(CGameRules **pGameRules)
{
if (!pGameRules || !(*pGameRules))
return;
delete (*pGameRules);
}

View File

@ -831,9 +831,11 @@ extern CGameRules DLLEXPORT *g_pGameRules;
#ifdef REGAMEDLL_API
CGameRules *InstallGameRules_OrigFunc();
void FreeGameRules_OrigFunc(CGameRules **pGameRules);
#endif
CGameRules *InstallGameRules();
void FreeGameRules(CGameRules **pGameRules);
// Gets us at the CS game rules
inline CHalfLifeMultiplay *CSGameRules()

View File

@ -288,11 +288,7 @@ void CWorld::Precache()
CVAR_SET_STRING("room_type", "0");
// Set up game rules
if (g_pGameRules)
{
delete g_pGameRules;
}
FreeGameRules(&g_pGameRules);
g_pGameRules = InstallGameRules();
// NOTE: What is the essence of soundent in CS 1.6? I think this is for NPC monsters - s1lent

View File

@ -100,8 +100,11 @@ public:
virtual void SetSpawnProtection(float flProtectionTime);
virtual void RemoveSpawnProtection();
virtual bool HintMessageEx(const char *pMessage, float duration = 6.0f, bool bDisplayIfPlayerDead = false, bool bOverride = false);
virtual void Reset();
virtual void OnSpawnEquip(bool addDefault = true, bool equipGame = true);
virtual void SetScoreboardAttributes(CBasePlayer *destination = nullptr);
void Reset();
void ResetVars();
void OnSpawn();
void OnKilled();

View File

@ -38,7 +38,7 @@
#include <API/CSInterfaces.h>
#define REGAMEDLL_API_VERSION_MAJOR 5
#define REGAMEDLL_API_VERSION_MINOR 21
#define REGAMEDLL_API_VERSION_MINOR 22
// CBasePlayer::Spawn hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn;
@ -520,6 +520,10 @@ typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBa
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_JoiningThink;
typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBasePlayer_JoiningThink;
// FreeGameRules hook
typedef IHookChain<void, class CGameRules **> IReGameHook_FreeGameRules;
typedef IHookChainRegistry<void, class CGameRules **> IReGameHookRegistry_FreeGameRules;
class IReGameHookchains {
public:
virtual ~IReGameHookchains() {}
@ -653,6 +657,8 @@ public:
virtual IReGameHookRegistry_CBasePlayer_Pain *CBasePlayer_Pain() = 0;
virtual IReGameHookRegistry_CBasePlayer_DeathSound *CBasePlayer_DeathSound() = 0;
virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink() = 0;
virtual IReGameHookRegistry_FreeGameRules *FreeGameRules() = 0;
};
struct ReGameFuncs_t {
@ -670,6 +676,9 @@ struct ReGameFuncs_t {
class CGrenade *(*PlantBomb)(entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity);
class CGib *(*SpawnHeadGib)(entvars_t* pevVictim);
void (*SpawnRandomGibs)(entvars_t* pevVictim, int cGibs, int human);
void (*UTIL_RestartOther)(const char *szClassname);
void (*UTIL_ResetEntities)();
void (*UTIL_RemoveOther)(const char *szClassname, int nCount);
};
class IReGameApi {

View File

@ -6,5 +6,5 @@
#pragma once
#define VERSION_MAJOR 5
#define VERSION_MINOR 21
#define VERSION_MINOR 22
#define VERSION_MAINTENANCE 0