From 88f0c74b79219fb436d967da477d1a5e2d813401 Mon Sep 17 00:00:00 2001 From: sirdigbot Date: Sat, 4 Mar 2023 12:06:27 +1100 Subject: [PATCH 1/4] Add methods for clearing netprop cache --- core/HalfLife2.cpp | 20 ++++++++++++++++++++ core/HalfLife2.h | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 6e5507b84f..7eaf0da52f 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -503,6 +503,26 @@ bool CHalfLife2::FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatab return true; } +void CHalfLife2::ClearDataTableCache() +{ + m_Maps.clear(); +} + +void CHalfLife2::ClearDataTableCache(datamap_t *pMap) +{ + m_Maps.removeIfExists(pMap); +} + +void CHalfLife2::ClearSendPropCache() +{ + m_Classes.clear(); +} + +bool CHalfLife2::ClearSendPropCache(const char *classname) +{ + return m_Classes.remove(classname); +} + void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset) { #if SOURCE_ENGINE != SE_DARKMESSIAH diff --git a/core/HalfLife2.h b/core/HalfLife2.h index 4c1d90a267..c33144b088 100644 --- a/core/HalfLife2.h +++ b/core/HalfLife2.h @@ -257,6 +257,11 @@ class CHalfLife2 : private: void InitLogicalEntData(); void InitCommandLine(); +public: + void CHalfLife2::ClearDataTableCache(); + void CHalfLife2::ClearDataTableCache(datamap_t *pMap); + void CHalfLife2::ClearSendPropCache(); + bool CHalfLife2::ClearSendPropCache(const char *classname); private: typedef ke::HashMap > DataTableMap; From 660b6343576558058288db7feac5c8963cf2919a Mon Sep 17 00:00:00 2001 From: Corey D Date: Sat, 4 Mar 2023 18:28:45 +1100 Subject: [PATCH 2/4] Fix dumb typo Why did that even compile on msvc? --- core/HalfLife2.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/HalfLife2.h b/core/HalfLife2.h index c33144b088..3ac0783ad5 100644 --- a/core/HalfLife2.h +++ b/core/HalfLife2.h @@ -258,10 +258,10 @@ class CHalfLife2 : void InitLogicalEntData(); void InitCommandLine(); public: - void CHalfLife2::ClearDataTableCache(); - void CHalfLife2::ClearDataTableCache(datamap_t *pMap); - void CHalfLife2::ClearSendPropCache(); - bool CHalfLife2::ClearSendPropCache(const char *classname); + void ClearDataTableCache(); + void ClearDataTableCache(datamap_t *pMap); + void ClearSendPropCache(); + bool ClearSendPropCache(const char *classname); private: typedef ke::HashMap > DataTableMap; From 0aaf89da22798de9fccc92060b0f4a8b9342af85 Mon Sep 17 00:00:00 2001 From: sirdigbot Date: Fri, 31 Mar 2023 11:57:06 +1100 Subject: [PATCH 3/4] Expose cache-clearing methods to extensions --- core/HalfLife2.cpp | 10 ++++++++++ core/HalfLife2.h | 2 ++ public/IGameHelpers.h | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index b7bb3fe303..7725175736 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -1592,3 +1592,13 @@ uint64_t CHalfLife2::GetServerSteamId64() const return 1ULL; } + +void CHalfLife2::RemoveDataTableCache(datamap_t *pMap) +{ + this->ClearDataTableCache(pMap); +} + +bool CHalfLife2::RemoveSendPropCache(const char *classname) +{ + return this->ClearSendPropCache(classname); +} diff --git a/core/HalfLife2.h b/core/HalfLife2.h index c440be3310..918db711a0 100644 --- a/core/HalfLife2.h +++ b/core/HalfLife2.h @@ -258,6 +258,8 @@ class CHalfLife2 : string_t AllocPooledString(const char *pszValue); bool GetServerSteam3Id(char *pszOut, size_t len) const override; uint64_t GetServerSteamId64() const override; + void RemoveDataTableCache(datamap_t *pMap); + bool RemoveSendPropCache(const char *classname); public: void AddToFakeCliCmdQueue(int client, int userid, const char *cmd); void ProcessFakeCliCmdQueue(); diff --git a/public/IGameHelpers.h b/public/IGameHelpers.h index b05c98d403..14d6ce7bc7 100644 --- a/public/IGameHelpers.h +++ b/public/IGameHelpers.h @@ -40,7 +40,7 @@ */ #define SMINTERFACE_GAMEHELPERS_NAME "IGameHelpers" -#define SMINTERFACE_GAMEHELPERS_VERSION 11 +#define SMINTERFACE_GAMEHELPERS_VERSION 12 class CBaseEntity; class CBaseHandle; @@ -351,6 +351,21 @@ namespace SourceMod * @return 64-bit server Steam id. */ virtual uint64_t GetServerSteamId64() const =0; + + /** + * @brief Removes a datamap from the DataTable cache. + * + * @param pMap datamap_t pointer. + */ + virtual void RemoveDataTableCache(datamap_t *pMap) =0; + + /** + * @brief Removes a class from the SendProp cache. + * + * @param classname Entity class name. + * @return True if cache was found and removed. + */ + virtual bool RemoveSendPropCache(const char *classname) =0; }; } From eb98f362caa7b2d4bce1e9991f44ab757b711eb6 Mon Sep 17 00:00:00 2001 From: sirdigbot Date: Thu, 27 Apr 2023 16:00:38 +1000 Subject: [PATCH 4/4] Remove redundant API --- core/HalfLife2.cpp | 37 +++++++++++++++---------------------- core/HalfLife2.h | 9 ++------- public/IGameHelpers.h | 12 ++++++------ 3 files changed, 23 insertions(+), 35 deletions(-) diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 7725175736..ff4fc97951 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -518,26 +518,6 @@ bool CHalfLife2::FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatab return pDataTable->prop != nullptr; } -void CHalfLife2::ClearDataTableCache() -{ - m_Maps.clear(); -} - -void CHalfLife2::ClearDataTableCache(datamap_t *pMap) -{ - m_Maps.removeIfExists(pMap); -} - -void CHalfLife2::ClearSendPropCache() -{ - m_Classes.clear(); -} - -bool CHalfLife2::ClearSendPropCache(const char *classname) -{ - return m_Classes.remove(classname); -} - void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset) { #if SOURCE_ENGINE != SE_DARKMESSIAH @@ -1595,10 +1575,23 @@ uint64_t CHalfLife2::GetServerSteamId64() const void CHalfLife2::RemoveDataTableCache(datamap_t *pMap) { - this->ClearDataTableCache(pMap); + if (pMap == nullptr) + { + m_Maps.clear(); + return; + } + + m_Maps.removeIfExists(pMap); } bool CHalfLife2::RemoveSendPropCache(const char *classname) { - return this->ClearSendPropCache(classname); + if (classname == nullptr) + { + m_Classes.clear(); + return true; + } + + return m_Classes.remove(classname); } + diff --git a/core/HalfLife2.h b/core/HalfLife2.h index 918db711a0..eee2dcf2e1 100644 --- a/core/HalfLife2.h +++ b/core/HalfLife2.h @@ -258,8 +258,8 @@ class CHalfLife2 : string_t AllocPooledString(const char *pszValue); bool GetServerSteam3Id(char *pszOut, size_t len) const override; uint64_t GetServerSteamId64() const override; - void RemoveDataTableCache(datamap_t *pMap); - bool RemoveSendPropCache(const char *classname); + void RemoveDataTableCache(datamap_t *pMap = nullptr); + bool RemoveSendPropCache(const char *classname = nullptr); public: void AddToFakeCliCmdQueue(int client, int userid, const char *cmd); void ProcessFakeCliCmdQueue(); @@ -275,11 +275,6 @@ class CHalfLife2 : private: void InitLogicalEntData(); void InitCommandLine(); -public: - void ClearDataTableCache(); - void ClearDataTableCache(datamap_t *pMap); - void ClearSendPropCache(); - bool ClearSendPropCache(const char *classname); private: typedef ke::HashMap > DataTableMap; diff --git a/public/IGameHelpers.h b/public/IGameHelpers.h index 14d6ce7bc7..ee1c91b55f 100644 --- a/public/IGameHelpers.h +++ b/public/IGameHelpers.h @@ -353,19 +353,19 @@ namespace SourceMod virtual uint64_t GetServerSteamId64() const =0; /** - * @brief Removes a datamap from the DataTable cache. + * @brief Clears all, or removes a single datamap from the DataTable cache. * - * @param pMap datamap_t pointer. + * @param pMap NULL or datamap_t pointer. */ - virtual void RemoveDataTableCache(datamap_t *pMap) =0; + virtual void RemoveDataTableCache(datamap_t *pMap = nullptr) =0; /** - * @brief Removes a class from the SendProp cache. + * @brief Clears all, or removes a single class from the SendProp cache. * - * @param classname Entity class name. + * @param classname NULL pointer or entity class name. * @return True if cache was found and removed. */ - virtual bool RemoveSendPropCache(const char *classname) =0; + virtual bool RemoveSendPropCache(const char *classname = nullptr) =0; }; }