Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API update SK #1. #699

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -14,7 +14,7 @@ on:
jobs:
windows:
name: 'Windows'
runs-on: windows-latest
runs-on: windows-2019

env:
solution: 'msvc/ReGameDLL.sln'
Expand Down
66 changes: 19 additions & 47 deletions regamedll/dlls/API/CAPI_Impl.cpp
Expand Up @@ -30,12 +30,15 @@

CReGameHookchains g_ReGameHookchains;

int EXT_FUNC Cmd_Argc_api() {
return CMD_ARGC_();
}
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];
}

const char *EXT_FUNC Cmd_Argv_api(int i) {
return CMD_ARGV_(i);
Q_strcpy(dest, source);
}

CGrenade *PlantBomb_api(entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity) {
Expand All @@ -51,22 +54,22 @@ void SpawnRandomGibs_api(entvars_t *pevVictim, int cGibs, int human) {
}

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,
ClearMultiDamage,
ApplyMultiDamage,
AddMultiDamage,

&UTIL_FindEntityByString,
UTIL_FindEntityByString,

&AddEntityHashValue,
&RemoveEntityHashValue,
AddEntityHashValue,
RemoveEntityHashValue,

Cmd_Argc_api,
Cmd_Argv_api,
CMD_ARGC_,
CMD_ARGV_,

PlantBomb_api,

Expand Down Expand Up @@ -265,35 +268,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);
}

EXPOSE_SINGLE_INTERFACE(CReGameApi, IReGameApi, VRE_GAMEDLL_API_VERSION);
11 changes: 2 additions & 9 deletions regamedll/dlls/API/CAPI_Impl.h
Expand Up @@ -906,8 +906,8 @@ class CReGameHookchains: public IReGameHookchains {
virtual IReGameHookRegistry_CBasePlayer_JoiningThink *CBasePlayer_JoiningThink();
};

extern CReGameHookchains g_ReGameHookchains;
extern ReGameFuncs_t g_ReGameApiFuncs;
C_DLLEXPORT CReGameHookchains g_ReGameHookchains;
C_DLLEXPORT ReGameFuncs_t g_ReGameApiFuncs;

class CReGameApi: public IReGameApi {
public:
Expand All @@ -930,10 +930,3 @@ class CReGameApi: public IReGameApi {
EXT_FUNC virtual bool BGetICSEntity(const char *pchVersion) const;
EXT_FUNC virtual bool BGetIGameRules(const char *pchVersion) const;
};

void Regamedll_ChangeString_api(char *&dest, const char *source);
void RadiusDamage_api(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, float flRadius, int iClassIgnore, int bitsDamageType);

void ClearMultiDamage_api();
void ApplyMultiDamage_api(entvars_t *pevInflictor, entvars_t *pevAttacker);
void AddMultiDamage_api(entvars_t *pevInflictor, CBaseEntity *pEntity, float flDamage, int bitsDamageType);
57 changes: 32 additions & 25 deletions regamedll/dlls/API/CSPlayer.cpp
Expand Up @@ -43,6 +43,11 @@ EXT_FUNC bool CCSPlayer::JoinTeam(TeamName team)
pPlayer->pev->deadflag = DEAD_DEAD;
pPlayer->pev->health = 0;

// Drop the C4 when we move toward spectator!
if(pPlayer->m_bHasC4)
{
pPlayer->DropPlayerItem("weapon_c4");
}
pPlayer->RemoveAllItems(TRUE);
pPlayer->m_bHasC4 = false;

Expand Down Expand Up @@ -200,7 +205,6 @@ EXT_FUNC bool CCSPlayer::RemovePlayerItemEx(const char* pszItemName, bool bRemov

return true;
}

else if (FStrEq(pszItemName, "weapon_shield"))
{
return RemoveShield();
Expand All @@ -209,33 +213,35 @@ EXT_FUNC bool CCSPlayer::RemovePlayerItemEx(const char* pszItemName, bool bRemov
auto pItem = GetItemByName(pszItemName);
if (pItem)
{
if (FClassnameIs(pItem->pev, "weapon_c4")) {
pPlayer->m_bHasC4 = false;
pPlayer->pev->body = 0;
pPlayer->SetBombIcon(FALSE);
pPlayer->SetProgressBarTime(0);
}

if (pItem->IsWeapon())
{
if (pItem == pPlayer->m_pActiveItem) {
((CBasePlayerWeapon *)pItem)->RetireWeapon();
}

if (bRemoveAmmo) {
pPlayer->m_rgAmmo[ pItem->PrimaryAmmoIndex() ] = 0;
}
}
CBasePlayerItem *pActiveItem = pPlayer->m_pActiveItem;

if (pPlayer->RemovePlayerItem(pItem)) {
pPlayer->pev->weapons &= ~(1 << pItem->m_iId);
// No more weapon
// No more weapon.
if ((pPlayer->pev->weapons & ~(1 << WEAPON_SUIT)) == 0) {
pPlayer->m_iHideHUD |= HIDEHUD_WEAPONS;
}

pItem->Kill();

if (pItem->IsWeapon()) {
if (pItem == pActiveItem) {
g_pGameRules->GetNextBestWeapon(pPlayer, pActiveItem);
}

// Critical if we share BP ammo with others, a mode like <0|1|2> where "1" check if no other weapon use such ammo type would have been better.
if (bRemoveAmmo || (pItem->iFlags() & ITEM_FLAG_EXHAUSTIBLE)) {
pPlayer->m_rgAmmo[ pItem->PrimaryAmmoIndex() ] = 0;
}
}

if (FClassnameIs(pItem->pev, "weapon_c4")) {
pPlayer->m_bHasC4 = false;
pPlayer->pev->body = 0;
pPlayer->SetBombIcon(FALSE);
pPlayer->SetProgressBarTime(0);
}

if (!pPlayer->m_rgpPlayerItems[PRIMARY_WEAPON_SLOT]) {
pPlayer->m_bHasPrimary = false;
}
Expand Down Expand Up @@ -303,14 +309,14 @@ EXT_FUNC void CCSPlayer::GiveShield(bool bDeploy)
BasePlayer()->GiveShield(bDeploy);
}

EXT_FUNC void CCSPlayer::DropShield(bool bDeploy)
EXT_FUNC CBaseEntity *CCSPlayer::DropShield(bool bDeploy)
{
BasePlayer()->DropShield(bDeploy);
return BasePlayer()->DropShield(bDeploy);
}

EXT_FUNC void CCSPlayer::DropPlayerItem(const char *pszItemName)
EXT_FUNC CBaseEntity *CCSPlayer::DropPlayerItem(const char *pszItemName)
{
BasePlayer()->DropPlayerItem(pszItemName);
return BasePlayer()->DropPlayerItem(pszItemName);
}

EXT_FUNC bool CCSPlayer::RemoveShield()
Expand Down Expand Up @@ -531,8 +537,8 @@ void CCSPlayer::Reset()
m_szModel[0] = '\0';

m_bForceShowMenu = false;
m_flRespawnPending =
m_flSpawnProtectionEndTime = 0.0f;
m_flRespawnPending = 0.0f;
m_flSpawnProtectionEndTime = 0.0f;

m_vecOldvAngle = g_vecZero;
m_iWeaponInfiniteAmmo = 0;
Expand All @@ -541,6 +547,7 @@ void CCSPlayer::Reset()
m_bGameForcingRespawn = false;
m_bAutoBunnyHopping = false;
m_bMegaBunnyJumping = false;
m_bPlantC4Anywhere = false;
}

void CCSPlayer::OnSpawn()
Expand Down
4 changes: 2 additions & 2 deletions regamedll/public/regamedll/API/CSPlayer.h
Expand Up @@ -61,8 +61,8 @@ class CCSPlayer: public CCSMonster {
virtual CBaseEntity *GiveNamedItemEx(const char *pszName);
virtual void GiveDefaultItems();
virtual void GiveShield(bool bDeploy = true);
virtual void DropShield(bool bDeploy = true);
virtual void DropPlayerItem(const char *pszItemName);
virtual CBaseEntity *DropShield(bool bDeploy = true);
virtual CBaseEntity *DropPlayerItem(const char *pszItemName);
virtual bool RemoveShield();
virtual void RemoveAllItems(bool bRemoveSuit);
virtual bool RemovePlayerItem(const char* pszItemName);
Expand Down
2 changes: 1 addition & 1 deletion regamedll/public/regamedll/regamedll_api.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion regamedll/version/version.h
Expand Up @@ -6,5 +6,5 @@
#pragma once

#define VERSION_MAJOR 5
#define VERSION_MINOR 21
#define VERSION_MINOR 22
#define VERSION_MAINTENANCE 0