Skip to content
66 changes: 19 additions & 47 deletions regamedll/dlls/API/CAPI_Impl.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
4 changes: 4 additions & 0 deletions regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,11 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
{
int j;
char *p;
#ifdef REGAMEDLL_FIXES
char text[140];
#else
char text[128];
#endif
char szTemp[256];
const char *cpSay = "say";
const char *cpSayTeam = "say_team";
Expand Down
28 changes: 28 additions & 0 deletions regamedll/dlls/func_tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ BOOL CFuncTank::OnControls(entvars_t *pevTest)
if (!(pev->spawnflags & SF_TANK_CANCONTROL))
return FALSE;

#ifdef REGAMEDLL_FIXES
if((pev->origin - pevTest->origin).Length() < (m_vecControllerUsePos.x + m_vecControllerUsePos.y))
#else
Vector offset = pevTest->origin - pev->origin;
if ((m_vecControllerUsePos - pevTest->origin).Length() < 30.0f)
#endif
{
return TRUE;
}
Expand Down Expand Up @@ -254,7 +258,12 @@ BOOL CFuncTank::StartControl(CBasePlayer *pController)
}

m_pController->m_iHideHUD |= HIDEHUD_WEAPONS;
#ifdef REGAMEDLL_FIXES
m_vecControllerUsePos.x = (pev->origin - m_pController->pev->origin).Length();
m_vecControllerUsePos.y = MAX_PLAYER_USE_TANK_RADIUS;
#else
m_vecControllerUsePos = m_pController->pev->origin;
#endif

pev->nextthink = pev->ltime + 0.1f;

Expand Down Expand Up @@ -876,6 +885,25 @@ void CFuncTankControls::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_T
if (m_pTank)
{
m_pTank->Use(pActivator, pCaller, useType, value);

#ifdef REGAMEDLL_FIXES
m_pTank->m_vecControllerUsePos.x = (m_pTank->pev->origin - pActivator->pev->origin).Length();

// Extended distance setting, up to "MAX_PLAYER_USE_TANK_RADIUS" units or more depending on how close we were in "PlayerUse", or if we did not used it.
if(pActivator && pActivator->IsPlayer() && (((CBasePlayer *)pActivator)->m_afButtonPressed & IN_USE))
{
m_pTank->m_vecControllerUsePos.y = MAX_PLAYER_USE_RADIUS - (this->Center() - pActivator->pev->origin).Length();

if(m_pTank->m_vecControllerUsePos.y < 0) // Since radius function can get and higher range, so fix it to avoid "StartControl" followed by "StopControl" on a next think!
{
m_pTank->m_vecControllerUsePos.y = -m_pTank->m_vecControllerUsePos.y;
}
}
else
{
m_pTank->m_vecControllerUsePos.y = MAX_PLAYER_USE_TANK_RADIUS;
}
#endif
}

// if this fails, most likely means save/restore hasn't worked properly
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/func_tank.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class CFuncTank: public CBaseEntity
static Vector m_TankSpread[];

protected:
#ifdef REGAMEDLL_FIXES
friend class CFuncTankControls;
#endif

CBasePlayer *m_pController;
float m_flNextAttack;
Vector m_vecControllerUsePos;
Expand Down
16 changes: 15 additions & 1 deletion regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4005,6 +4005,11 @@ void CBasePlayer::PlayerUse()
if (!((pev->button | m_afButtonPressed | m_afButtonReleased) & IN_USE))
return;

#ifdef REGAMEDLL_FIXES
if (IsReloading())
return;
#endif

// Hit Use on a train?
if (m_afButtonPressed & IN_USE)
{
Expand Down Expand Up @@ -5040,6 +5045,11 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PostThink)()
}
}

#ifdef REGAMEDLL_FIXES
// Handle use events
PlayerUse();
ImpulseCommands();
#endif
// do weapon stuff
ItemPostFrame();

Expand Down Expand Up @@ -6296,8 +6306,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(ImpulseCommands)()
{
TraceResult tr;

#ifndef REGAMEDLL_FIXES
// Handle use events
PlayerUse();
#endif

int iImpulse = pev->impulse;

Expand Down Expand Up @@ -6915,15 +6927,17 @@ void CBasePlayer::ItemPostFrame()
#endif
return;

#ifndef REGAMEDLL_FIXES
ImpulseCommands();
#endif

if (m_pActiveItem)
m_pActiveItem->ItemPostFrame();
}

int CBasePlayer::AmmoInventory(int iAmmoIndex)
{
if (iAmmoIndex == -1)
if (iAmmoIndex <= -1)
return -1;

return m_rgAmmo[iAmmoIndex];
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const float SUIT_FIRST_UPDATE_TIME = 0.1f;
const float MAX_PLAYER_FATAL_FALL_SPEED = 1100.0f;
const float MAX_PLAYER_SAFE_FALL_SPEED = 500.0f;
const float MAX_PLAYER_USE_RADIUS = 64.0f;
const float MAX_PLAYER_USE_TANK_RADIUS = 30.0f;

const float ARMOR_RATIO = 0.5f; // Armor Takes 50% of the damage
const float ARMOR_BONUS = 0.5f; // Each Point of Armor is work 1/x points of health
Expand Down
15 changes: 13 additions & 2 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,20 +1108,31 @@ void CBasePlayerItem::DestroyItem()
{
if (m_pPlayer)
{
#ifdef REGAMEDLL_FIXES
bool bShouldCallGetNextBestWeapon = (this == m_pPlayer->m_pActiveItem);
#endif
// if attached to a player, remove.
if (m_pPlayer->RemovePlayerItem(this))
{

#ifdef REGAMEDLL_FIXES
m_pPlayer->pev->weapons &= ~(1 << m_iId);

// No more weapon
if ((m_pPlayer->pev->weapons & ~(1 << WEAPON_SUIT)) == 0) {
m_pPlayer->m_iHideHUD |= HIDEHUD_WEAPONS;
}
// Helps to fix problem when we throw our last grenade right before using a tank (< 0.5 seconds) and when we unuse it,
// we no longer have an active item and we are unable to select another via mouse wheel.
else if(bShouldCallGetNextBestWeapon)
{
g_pGameRules->GetNextBestWeapon(m_pPlayer, this);
}
#endif

}
#ifdef REGAMEDLL_FIXES
else if(!(pev->flags & FL_KILLME)) // Do not kill the item when unable to unhook from player's inventory (as if we manually refused this).
return;
#endif
}

Kill();
Expand Down