From d4ad09619e419565dc33cd8797f1f4bd6042ab82 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 21 Aug 2004 21:39:21 +0000 Subject: [PATCH] Prevented keys from overwriting each other --- amxmodx/CLang.cpp | 27 +++++++++++++++++++++++---- amxmodx/CLang.h | 6 +++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/amxmodx/CLang.cpp b/amxmodx/CLang.cpp index 99e584f8..f93695bc 100755 --- a/amxmodx/CLang.cpp +++ b/amxmodx/CLang.cpp @@ -189,6 +189,16 @@ uint32_t CLangMngr::CLang::LangEntry::GetDefHash() return m_DefHash; } +void CLangMngr::CLang::LangEntry::SetCache(bool c) +{ + m_isCache = c; +} + +bool CLangMngr::CLang::LangEntry::GetCache() +{ + return m_isCache; +} + const char *CLangMngr::CLang::LangEntry::GetDef() { return m_pDef.c_str(); @@ -268,10 +278,12 @@ CLangMngr::CLang::CLang(const char *lang) m_LanguageName[2]=0; } -CLangMngr::CLang::LangEntry *CLangMngr::CLang::AddEntry(int pKey, uint32_t defHash, const char *def) +CLangMngr::CLang::LangEntry *CLangMngr::CLang::AddEntry(int pKey, uint32_t defHash, const char *def, bool cache) { LangEntry *p = new LangEntry(pKey, defHash, def); + p->SetCache(cache); + m_LookUpTable.push_back(p); return p; @@ -306,6 +318,7 @@ CLangMngr::CLang::LangEntry * CLangMngr::CLang::GetEntry(int pkey) LangEntry *e = new LangEntry(pkey); e->SetKey(pkey); + e->SetCache(true); m_LookUpTable.push_back(e); return e; @@ -322,8 +335,14 @@ void CLangMngr::CLang::MergeDefinitions(CQueue &vec) LangEntry *entry = GetEntry(key); if (entry->GetDefHash() != MakeHash(def)) { - entry->SetDef(def); - entry->SetKey(key); + if (entry->GetCache()) + { + entry->SetDef(def); + entry->SetKey(key); + entry->SetCache(false); + } else { + AMXXLOG_Log("[AMXX] Language key %s[%s] defined twice", m_LMan->GetKey(key), m_LanguageName); + } } delete vec.front(); vec.pop(); @@ -1184,7 +1203,7 @@ bool CLangMngr::Load(const char *filename) char *data = new char[deflen+1]; fread(data, sizeof(char), deflen, fp); data[deflen] = 0; - m_Languages[i]->AddEntry(keynum, defhash, data); + m_Languages[i]->AddEntry(keynum, defhash, data, true); delete [] data; fseek(fp, save, SEEK_SET); //bring back to next entry } diff --git a/amxmodx/CLang.h b/amxmodx/CLang.h index 487bd703..37690117 100755 --- a/amxmodx/CLang.h +++ b/amxmodx/CLang.h @@ -102,15 +102,19 @@ class CLangMngr int key; // the definition String m_pDef; + // is this from the cache or not? + bool m_isCache; public: // Set void SetKey(int key); void SetDef(const char *pDef); + void SetCache(bool c); // Get uint32_t GetDefHash(); int GetKey(); const char *GetDef(); int GetDefLength(); + bool GetCache(); // Constructors / destructors LangEntry(); @@ -135,7 +139,7 @@ class CLangMngr LookUpVec m_LookUpTable; CLangMngr *m_LMan; public: - LangEntry *AddEntry(int pKey, uint32_t defHash, const char *def); + LangEntry *AddEntry(int pKey, uint32_t defHash, const char *def, bool cache); }; // Merge definitions into a language