From 7064fa31e26a5e198465d7c2f7be3835578c026b Mon Sep 17 00:00:00 2001 From: s1lent Date: Wed, 14 Feb 2018 16:02:00 +0700 Subject: [PATCH] Add trace log for a particular case. Enable RTTI --- regamedll/build.gradle | 2 +- regamedll/dlls/cbase.cpp | 22 ++++++++++++++++++++++ regamedll/dlls/client.cpp | 21 +++++++++++++++++++++ regamedll/dlls/client.h | 2 ++ regamedll/msvc/ReGameDLL.vcxproj | 5 +++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/regamedll/build.gradle b/regamedll/build.gradle index 4e46ebce..2b462306 100644 --- a/regamedll/build.gradle +++ b/regamedll/build.gradle @@ -119,7 +119,7 @@ void setupToolchain(NativeBinarySpec b) cfg.compilerOptions.enhancedInstructionsSet = EnhancedInstructionsSet.DISABLED } else { - cfg.compilerOptions.args '/Oi', '/GF', '/GS-', '/GR-' + cfg.compilerOptions.args '/Oi', '/GF', '/GS-' } cfg.projectLibpath(project, '/lib') diff --git a/regamedll/dlls/cbase.cpp b/regamedll/dlls/cbase.cpp index e8474954..fc843725 100644 --- a/regamedll/dlls/cbase.cpp +++ b/regamedll/dlls/cbase.cpp @@ -1438,6 +1438,28 @@ void OnFreeEntPrivateData(edict_t *pEnt) if (!pEntity) return; +#ifdef REGAMEDLL_FIXES + for (int i = 1; i <= gpGlobals->maxClients; i++) + { + CBasePlayer *pPlayer = UTIL_PlayerByIndex(i); + + if (!pPlayer) + continue; + + if (FNullEnt(pPlayer->edict())) + continue; + + if (pPlayer->IsDormant()) + continue; + + if (pPlayer->m_pActiveItem && pPlayer->m_pActiveItem == pEntity) + { + ALERT(at_warning, "Trying to release the entity: (%s : `%s`) without pre-reset m_pActiveItem\n", pEntity->GetClassname(), pEntity->pev->model.str()); + pPlayer->m_pActiveItem = nullptr; + } + } +#endif + #ifdef REGAMEDLL_API pEntity->OnDestroy(); #endif diff --git a/regamedll/dlls/client.cpp b/regamedll/dlls/client.cpp index 5278b327..ce97cefc 100644 --- a/regamedll/dlls/client.cpp +++ b/regamedll/dlls/client.cpp @@ -4610,8 +4610,19 @@ int EXT_FUNC GetWeaponData(edict_t *pEdict, struct weapon_data_s *info) auto pPlayerItem = pPlayer->m_rgpPlayerItems[i]; while (pPlayerItem) { +#ifdef REGAMEDLL_FIXES + // Make sure that entity is CBasePlayerItem + auto pItem = dynamic_cast(pPlayerItem); + if (pItem = nullptr) + { + ALERT(at_error, "GetWeaponData: m_rgpPlayerItems[%i] is non-item, entity: (%s `%s`), (%s)\n", i, pPlayerItem->GetClassname(), pPlayerItem->pev->model.str(), typeid(pPlayer->m_pActiveItem).name()); + return 0; + } +#endif + // there's a weapon here. Should I pack it? auto weapon = (CBasePlayerWeapon *)pPlayerItem->GetWeaponPtr(); + if (weapon && weapon->UseDecrement()) { // Get The ID @@ -4749,6 +4760,16 @@ void EXT_FUNC UpdateClientData(const edict_t *ent, int sendweapons, struct clien ItemInfo II; Q_memset(&II, 0, sizeof(II)); +#ifdef REGAMEDLL_FIXES + // Make sure that entity is CBasePlayerItem + auto pItem = dynamic_cast(pPlayer->m_pActiveItem); + if (pItem = nullptr) + { + ALERT(at_error, "GetWeaponData: m_pActiveItem is non-item, entity: (%s `%s`), (%s)\n", pPlayer->m_pActiveItem->GetClassname(), pPlayer->m_pActiveItem->pev->model.str(), typeid(pPlayer->m_pActiveItem).name()); + return; + } +#endif + CBasePlayerWeapon *weapon = (CBasePlayerWeapon *)pPlayer->m_pActiveItem->GetWeaponPtr(); if (weapon && weapon->UseDecrement() && weapon->GetItemInfo(&II)) { diff --git a/regamedll/dlls/client.h b/regamedll/dlls/client.h index d00252e8..b7e79121 100644 --- a/regamedll/dlls/client.h +++ b/regamedll/dlls/client.h @@ -28,6 +28,8 @@ #pragma once +#include + // custom enum enum ChooseTeamMenuSlot { diff --git a/regamedll/msvc/ReGameDLL.vcxproj b/regamedll/msvc/ReGameDLL.vcxproj index 6e1541e9..79330af3 100644 --- a/regamedll/msvc/ReGameDLL.vcxproj +++ b/regamedll/msvc/ReGameDLL.vcxproj @@ -911,6 +911,7 @@ MultiThreadedDebug Use precompiled.h + true true @@ -953,6 +954,7 @@ Default true true + true true @@ -998,6 +1000,7 @@ Default true true + true true @@ -1037,6 +1040,7 @@ MultiThreadedDebug Use precompiled.h + true true @@ -1072,6 +1076,7 @@ Use precompiled.h NoExtensions + true true