Skip to content

Commit

Permalink
API: Added new API funcs (6) and new Hookchains (21) (#849)
Browse files Browse the repository at this point in the history
* Added few newest API Hookchains
* Added hookchain for PM_CheckWaterJump
* Added hookchain for PM_Jump
* Added hookchain for PM_Duck
* Added hookchain for PM_UnDuck
* Added hookchain for ClearMultiDamage
* Added hookchain for AddMultiDamage
* Added hookchain for ApplyMultiDamage
* Added hookchain for CSGameRules::TeamFull
* Added hookchain for CSGameRules::TeamStacked
* Added hookchain for CSGameRules::PlayerGotWeapon
* Added hookchain for CBotManager::OnEvent
* Added hookchain for CBasePlayer::EntSelectSpawnPoint
* Added hookchain for CBasePlayerWeapon::KickBack
* Added hookchain for CBasePlayerWeapon::SendWeaponAnim
* Added new PM_* Hookchains
* Added PM_WaterJump
* Added PM_PlayStepSound
* Added PM_AirAccelerate
* Added CBasePlayer::CheckTimeBasedDamage
* Added CBasePlayerWeapon::ItemPostFrame
* Added BuyItem and CSGameRules::Think
* AddAmmoNameToAmmoRegistry refactory
* Bump minor version in an API bump up to 23
  • Loading branch information
dystopm authored Sep 5, 2023
1 parent f3723d7 commit 696f465
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 121 deletions.
193 changes: 135 additions & 58 deletions regamedll/dlls/API/CAPI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,133 @@

CReGameHookchains g_ReGameHookchains;

int EXT_FUNC Cmd_Argc_api() {
void EXT_FUNC Regamedll_ChangeString_api(char *&dest, const char *source)
{
size_t len = Q_strlen(source);
if (dest == nullptr || Q_strlen(dest) != len) {
delete [] dest;
dest = new char [len + 1];
}

Q_strcpy(dest, source);
}

void EXT_FUNC RadiusDamage_api(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, float flRadius, int iClassIgnore, int bitsDamageType)
{
RadiusDamage(vecSrc, pevInflictor, pevAttacker, flDamage, flRadius, iClassIgnore, bitsDamageType);
}

void EXT_FUNC ClearMultiDamage_api()
{
ClearMultiDamage();
}

void EXT_FUNC ApplyMultiDamage_api(entvars_t *pevInflictor, entvars_t *pevAttacker)
{
ApplyMultiDamage(pevInflictor, pevAttacker);
}

void EXT_FUNC AddMultiDamage_api(entvars_t *pevInflictor, CBaseEntity *pEntity, float flDamage, int bitsDamageType)
{
AddMultiDamage(pevInflictor, pEntity, flDamage, bitsDamageType);
}

int EXT_FUNC Cmd_Argc_api()
{
return CMD_ARGC_();
}

const char *EXT_FUNC Cmd_Argv_api(int i) {
const char *EXT_FUNC Cmd_Argv_api(int i)
{
return CMD_ARGV_(i);
}

CGrenade *PlantBomb_api(entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity) {
CGrenade *EXT_FUNC PlantBomb_api(entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity)
{
return CGrenade::ShootSatchelCharge(pevOwner, vecStart, vecVelocity);
}

CGib *SpawnHeadGib_api(entvars_t *pevVictim) {
CGib *EXT_FUNC SpawnHeadGib_api(entvars_t *pevVictim)
{
return CGib::SpawnHeadGib(pevVictim);
}

void SpawnRandomGibs_api(entvars_t *pevVictim, int cGibs, int human) {
void EXT_FUNC SpawnRandomGibs_api(entvars_t *pevVictim, int cGibs, int human)
{
CGib::SpawnRandomGibs(pevVictim, cGibs, human);
}

void EXT_FUNC UTIL_RestartOther_api(const char *szClassname)
{
UTIL_RestartOther(szClassname);
}

void EXT_FUNC UTIL_ResetEntities_api()
{
UTIL_ResetEntities();
}

void EXT_FUNC UTIL_RemoveOther_api(const char *szClassname, int nCount)
{
UTIL_RemoveOther(szClassname, nCount);
}

void EXT_FUNC UTIL_DecalTrace_api(TraceResult *pTrace, int decalNumber)
{
UTIL_DecalTrace(pTrace, decalNumber);
}

void EXT_FUNC UTIL_Remove_api(CBaseEntity *pEntity)
{
UTIL_Remove(pEntity);
}

int EXT_FUNC AddAmmoNameToAmmoRegistry_api(const char *szAmmoname)
{
return AddAmmoNameToAmmoRegistry(szAmmoname);
}

void EXT_FUNC TextureTypePlaySound_api(TraceResult *ptr, Vector vecSrc, Vector vecEnd, int iBulletType)
{
TEXTURETYPE_PlaySound(ptr, vecSrc, vecEnd, iBulletType);
}

CWeaponBox *EXT_FUNC CreateWeaponBox_api(CBasePlayerItem *pItem, CBasePlayer *pPlayerOwner, const char *modelName, Vector &origin, Vector &angles, Vector &velocity, float lifeTime, bool packAmmo)
{
return CreateWeaponBox(pItem, pPlayerOwner, modelName, origin, angles, velocity, lifeTime < 0.0 ? CGameRules::GetItemKillDelay() : lifeTime, packAmmo);
}

CGrenade *EXT_FUNC SpawnGrenade_api(WeaponIdType weaponId, entvars_t *pevOwner, Vector &vecSrc, Vector &vecThrow, float time, int iTeam, unsigned short usEvent)
{
switch (weaponId)
{
case WEAPON_HEGRENADE:
return CGrenade::ShootTimed2(pevOwner, vecSrc, vecThrow, time, iTeam, usEvent);
case WEAPON_FLASHBANG:
return CGrenade::ShootTimed(pevOwner, vecSrc, vecThrow, time);
case WEAPON_SMOKEGRENADE:
return CGrenade::ShootSmokeGrenade(pevOwner, vecSrc, vecThrow, time, usEvent);
case WEAPON_C4:
return CGrenade::ShootSatchelCharge(pevOwner, vecSrc, vecThrow);
}

return nullptr;
}

ReGameFuncs_t g_ReGameApiFuncs = {
&CREATE_NAMED_ENTITY,
CREATE_NAMED_ENTITY,

&Regamedll_ChangeString_api,
Regamedll_ChangeString_api,

&RadiusDamage_api,
&ClearMultiDamage_api,
&ApplyMultiDamage_api,
&AddMultiDamage_api,
RadiusDamage_api,
ClearMultiDamage_api,
ApplyMultiDamage_api,
AddMultiDamage_api,

&UTIL_FindEntityByString,
UTIL_FindEntityByString,

&AddEntityHashValue,
&RemoveEntityHashValue,
AddEntityHashValue,
RemoveEntityHashValue,

Cmd_Argc_api,
Cmd_Argv_api,
Expand All @@ -76,6 +169,13 @@ ReGameFuncs_t g_ReGameApiFuncs = {
UTIL_RestartOther_api,
UTIL_ResetEntities_api,
UTIL_RemoveOther_api,
UTIL_DecalTrace_api,
UTIL_Remove_api,

AddAmmoNameToAmmoRegistry_api,
TextureTypePlaySound_api,
CreateWeaponBox_api,
SpawnGrenade_api,
};

GAMEHOOK_REGISTRY(CBasePlayer_Spawn);
Expand Down Expand Up @@ -210,6 +310,27 @@ GAMEHOOK_REGISTRY(CBasePlayer_JoiningThink);

GAMEHOOK_REGISTRY(FreeGameRules);
GAMEHOOK_REGISTRY(PM_LadderMove);
GAMEHOOK_REGISTRY(PM_WaterJump);
GAMEHOOK_REGISTRY(PM_CheckWaterJump);
GAMEHOOK_REGISTRY(PM_Jump);
GAMEHOOK_REGISTRY(PM_Duck);
GAMEHOOK_REGISTRY(PM_UnDuck);
GAMEHOOK_REGISTRY(PM_PlayStepSound);
GAMEHOOK_REGISTRY(PM_AirAccelerate);
GAMEHOOK_REGISTRY(ClearMultiDamage);
GAMEHOOK_REGISTRY(AddMultiDamage);
GAMEHOOK_REGISTRY(ApplyMultiDamage);
GAMEHOOK_REGISTRY(BuyItem);
GAMEHOOK_REGISTRY(CSGameRules_Think);
GAMEHOOK_REGISTRY(CSGameRules_TeamFull);
GAMEHOOK_REGISTRY(CSGameRules_TeamStacked);
GAMEHOOK_REGISTRY(CSGameRules_PlayerGotWeapon);
GAMEHOOK_REGISTRY(CBotManager_OnEvent);
GAMEHOOK_REGISTRY(CBasePlayer_CheckTimeBasedDamage);
GAMEHOOK_REGISTRY(CBasePlayer_EntSelectSpawnPoint);
GAMEHOOK_REGISTRY(CBasePlayerWeapon_ItemPostFrame);
GAMEHOOK_REGISTRY(CBasePlayerWeapon_KickBack);
GAMEHOOK_REGISTRY(CBasePlayerWeapon_SendWeaponAnim);

int CReGameApi::GetMajorVersion() {
return REGAMEDLL_API_VERSION_MAJOR;
Expand Down Expand Up @@ -272,48 +393,4 @@ bool CReGameApi::BGetIGameRules(const char *pchVersion) const
return false;
}

EXT_FUNC void Regamedll_ChangeString_api(char *&dest, const char *source)
{
size_t len = Q_strlen(source);
if (dest == nullptr || Q_strlen(dest) != len) {
delete [] dest;
dest = new char [len + 1];
}

Q_strcpy(dest, source);
}

EXT_FUNC void RadiusDamage_api(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, float flRadius, int iClassIgnore, int bitsDamageType)
{
RadiusDamage(vecSrc, pevInflictor, pevAttacker, flDamage, flRadius, iClassIgnore, bitsDamageType);
}

EXT_FUNC void ClearMultiDamage_api()
{
ClearMultiDamage();
}

EXT_FUNC void ApplyMultiDamage_api(entvars_t *pevInflictor, entvars_t *pevAttacker)
{
ApplyMultiDamage(pevInflictor, pevAttacker);
}

EXT_FUNC void AddMultiDamage_api(entvars_t *pevInflictor, CBaseEntity *pEntity, float flDamage, int bitsDamageType)
{
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);
Loading

0 comments on commit 696f465

Please sign in to comment.