diff --git a/regamedll/dlls/API/CAPI_Impl.cpp b/regamedll/dlls/API/CAPI_Impl.cpp index 0fe10a490..47532642b 100644 --- a/regamedll/dlls/API/CAPI_Impl.cpp +++ b/regamedll/dlls/API/CAPI_Impl.cpp @@ -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) { @@ -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, @@ -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); diff --git a/regamedll/dlls/API/CAPI_Impl.h b/regamedll/dlls/API/CAPI_Impl.h index 1be3dd232..311f612ed 100644 --- a/regamedll/dlls/API/CAPI_Impl.h +++ b/regamedll/dlls/API/CAPI_Impl.h @@ -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: @@ -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); diff --git a/regamedll/dlls/client.cpp b/regamedll/dlls/client.cpp index 5ddf63adb..3d79df07c 100644 --- a/regamedll/dlls/client.cpp +++ b/regamedll/dlls/client.cpp @@ -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"; diff --git a/regamedll/dlls/func_tank.cpp b/regamedll/dlls/func_tank.cpp index 1ca0e966e..acb772d1b 100644 --- a/regamedll/dlls/func_tank.cpp +++ b/regamedll/dlls/func_tank.cpp @@ -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; } @@ -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; @@ -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 diff --git a/regamedll/dlls/func_tank.h b/regamedll/dlls/func_tank.h index d30acdb7a..d93e6b330 100644 --- a/regamedll/dlls/func_tank.h +++ b/regamedll/dlls/func_tank.h @@ -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; diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index c48545051..c5cd27a45 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -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) { @@ -5040,6 +5045,11 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PostThink)() } } +#ifdef REGAMEDLL_FIXES + // Handle use events + PlayerUse(); + ImpulseCommands(); +#endif // do weapon stuff ItemPostFrame(); @@ -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; @@ -6915,7 +6927,9 @@ void CBasePlayer::ItemPostFrame() #endif return; +#ifndef REGAMEDLL_FIXES ImpulseCommands(); +#endif if (m_pActiveItem) m_pActiveItem->ItemPostFrame(); @@ -6923,7 +6937,7 @@ void CBasePlayer::ItemPostFrame() int CBasePlayer::AmmoInventory(int iAmmoIndex) { - if (iAmmoIndex == -1) + if (iAmmoIndex <= -1) return -1; return m_rgAmmo[iAmmoIndex]; diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index e62c1b730..54c341fca 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -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 diff --git a/regamedll/dlls/weapons.cpp b/regamedll/dlls/weapons.cpp index 22d61fc9f..57b5afaf5 100644 --- a/regamedll/dlls/weapons.cpp +++ b/regamedll/dlls/weapons.cpp @@ -1108,10 +1108,12 @@ 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); @@ -1119,9 +1121,18 @@ void CBasePlayerItem::DestroyItem() 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();