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

Add methods for clearing netprop cache #1943

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions core/HalfLife2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,3 +1572,26 @@ uint64_t CHalfLife2::GetServerSteamId64() const

return 1ULL;
}

void CHalfLife2::RemoveDataTableCache(datamap_t *pMap)
{
if (pMap == nullptr)
{
m_Maps.clear();
return;
}

m_Maps.removeIfExists(pMap);
}

bool CHalfLife2::RemoveSendPropCache(const char *classname)
{
if (classname == nullptr)
{
m_Classes.clear();
return true;
}

return m_Classes.remove(classname);
}

2 changes: 2 additions & 0 deletions core/HalfLife2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = nullptr);
bool RemoveSendPropCache(const char *classname = nullptr);
public:
void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
void ProcessFakeCliCmdQueue();
Expand Down
17 changes: 16 additions & 1 deletion public/IGameHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/

#define SMINTERFACE_GAMEHELPERS_NAME "IGameHelpers"
#define SMINTERFACE_GAMEHELPERS_VERSION 11
#define SMINTERFACE_GAMEHELPERS_VERSION 12

class CBaseEntity;
class CBaseHandle;
Expand Down Expand Up @@ -351,6 +351,21 @@ namespace SourceMod
* @return 64-bit server Steam id.
*/
virtual uint64_t GetServerSteamId64() const =0;

/**
* @brief Clears all, or removes a single datamap from the DataTable cache.
*
* @param pMap NULL or datamap_t pointer.
*/
virtual void RemoveDataTableCache(datamap_t *pMap = nullptr) =0;

/**
* @brief Clears all, or removes a single class from the SendProp cache.
*
* @param classname NULL pointer or entity class name.
* @return True if cache was found and removed.
*/
virtual bool RemoveSendPropCache(const char *classname = nullptr) =0;
};
}

Expand Down