From e2c1b8c1789bfdfa8770482bb6daaf1024178c19 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 6 Feb 2006 11:13:27 +0000 Subject: [PATCH] Fixed bug where invalid keys were saved as blank translations Fixed bug where dictionary caches were invalidated before being used Loads with MM 5:11 now --- amxmodx/CLang.cpp | 51 ++++++++++++++++++++++------ amxmodx/CLang.h | 3 +- amxmodx/emsg.cpp | 5 +++ amxmodx/meta_api.cpp | 14 +++++--- amxmodx/msvc/amxmodx_mm.vcproj | 61 ++++++++++++++++++++++++++++++++++ amxmodx/newmenus.cpp | 2 +- 6 files changed, 118 insertions(+), 18 deletions(-) diff --git a/amxmodx/CLang.cpp b/amxmodx/CLang.cpp index 6d975edc..a1539d99 100755 --- a/amxmodx/CLang.cpp +++ b/amxmodx/CLang.cpp @@ -155,11 +155,13 @@ size_t CLangMngr::strip(char *str, char *newstr, bool makelower) CLangMngr::CLang::CLang() { m_LookUpTable.clear(); + m_entries = 0; } CLangMngr::CLang::CLang(const char *lang) { m_LookUpTable.clear(); + m_entries = 0; strncpy(m_LanguageName, lang, 2); m_LanguageName[2] = 0; } @@ -167,9 +169,13 @@ CLangMngr::CLang::CLang(const char *lang) void CLangMngr::CLang::AddEntry(int key, const char *definition) { defentry &d = m_LookUpTable[key]; - + if (d.definition) + { delete d.definition; + } else { + m_entries++; + } d.definition = new String(definition); } @@ -191,6 +197,7 @@ void CLangMngr::CLang::Clear() } } m_LookUpTable.clear(); + m_entries = 0; } void CLangMngr::CLang::MergeDefinitions(CQueue &vec) @@ -229,14 +236,13 @@ bool CLangMngr::CLang::SaveDefinitions(FILE *fp, uint32_t &curOffset) { unsigned short defLen = 0; String *pdef; - String blank; THash::iterator iter; for (iter=m_LookUpTable.begin(); iter!=m_LookUpTable.end(); iter++) { pdef = iter->val.definition; if (!pdef) - pdef = ␣ + continue; defLen = pdef->size(); fwrite((void *)&defLen, sizeof(unsigned short), 1, fp); curOffset += sizeof(unsigned short); @@ -247,24 +253,38 @@ bool CLangMngr::CLang::SaveDefinitions(FILE *fp, uint32_t &curOffset) return true; } +int CLangMngr::CLang::Entries() +{ + return m_entries; +} + // Assumes fp is set to the right position bool CLangMngr::CLang::Save(FILE *fp, int &defOffset, uint32_t &curOffset) { uint32_t keynum = 0; - uint32_t size = m_LookUpTable.size(); + uint32_t size = 0; String *pdef; - String blank; + + //:TODO: speed this up by writing 0, then fseek()ing back + // and writing the right amt + THash::iterator iter; + for (iter=m_LookUpTable.begin(); iter!=m_LookUpTable.end(); iter++) + { + if (iter->val.definition) + size++; + } + + assert(size == m_entries); fwrite((void*)&size, sizeof(uint32_t), 1, fp); curOffset += sizeof(uint32_t); - THash::iterator iter; for (iter=m_LookUpTable.begin(); iter!=m_LookUpTable.end(); iter++) { keynum = iter->key; pdef = iter->val.definition; if (!pdef) - pdef = ␣ + continue; fwrite((void *)&keynum, sizeof(uint32_t), 1, fp); curOffset += sizeof(uint32_t); fwrite((void *)&defOffset, sizeof(uint32_t), 1, fp); @@ -284,6 +304,15 @@ bool CLangMngr::CLang::Load(FILE *fp) /******** CLangMngr *********/ +String &make_string(const char *str) +{ + static String g_temp; + + g_temp.assign(str); + + return g_temp; +} + CLangMngr::CLangMngr() { Clear(); @@ -299,7 +328,7 @@ const char * CLangMngr::GetKey(int key) int CLangMngr::GetKeyEntry(const char *key) { - keytbl_val val = KeyTable[key]; + keytbl_val &val = KeyTable[make_string(key)]; return val.index; } @@ -319,7 +348,7 @@ int CLangMngr::AddKeyEntry(String &key) int CLangMngr::GetKeyEntry(String &key) { - keytbl_val val = KeyTable[key]; + keytbl_val &val = KeyTable[key]; return val.index; } @@ -992,7 +1021,7 @@ CLangMngr::CLang * CLangMngr::GetLangR(const char *name) const char *CLangMngr::GetDef(const char *langName, const char *key, int &status) { CLang *lang = GetLangR(langName); - keytbl_val val = KeyTable[key]; + keytbl_val &val = KeyTable[make_string(key)]; if (lang == NULL) { status = ERR_BADLANG; @@ -1124,7 +1153,7 @@ bool CLangMngr::SaveCache(const char *filename) } #define CACHEREAD(expr, type) \ - if (! (expr==sizeof(type)) ) { \ + if (! (expr==1) ) { \ FileList.clear(); \ fclose(fp); \ return false; \ diff --git a/amxmodx/CLang.h b/amxmodx/CLang.h index 77f650cf..74a521f7 100755 --- a/amxmodx/CLang.h +++ b/amxmodx/CLang.h @@ -118,7 +118,7 @@ class CLangMngr bool Load(FILE *fp); void SetMngr(CLangMngr *l) { m_LMan = l; } // Get number of entries - int Entries() { return m_LookUpTable.size(); } + int Entries(); protected: typedef THash LookUpVec; typedef LookUpVec::iterator LookUpVecIter; @@ -127,6 +127,7 @@ class CLangMngr // our lookup table LookUpVec m_LookUpTable; + int m_entries; CLangMngr *m_LMan; public: void AddEntry(int key, const char *definition); diff --git a/amxmodx/emsg.cpp b/amxmodx/emsg.cpp index d20ecd67..63b46c99 100755 --- a/amxmodx/emsg.cpp +++ b/amxmodx/emsg.cpp @@ -65,6 +65,7 @@ void Client_VGUIMenu(void* mValue) { case 0: mPlayer->menu = -(*(int*)mValue); + mPlayer->newmenu = -1; break; case 1: mPlayer->keys = *(int*)mValue; @@ -83,7 +84,11 @@ void Client_ShowMenu(void* mValue) mPlayer->keys = *(int*)mValue; break; case 3: + { mPlayer->menu = g_menucmds.findMenuId((char*)mValue); + mPlayer->newmenu = 0; + break; + } } } diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 89747cc4..b228780e 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -247,10 +247,11 @@ int C_Spawn(edict_t *pent) // ###### Load lang char file[256]; - g_langMngr.LoadCache(build_pathname_r(file, sizeof(file) - 1, "%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data"))); if (!g_langMngr.Load(build_pathname_r(file, sizeof(file) - 1, "%s/languages.dat", get_localinfo("amxmodx_datadir", "addons/amxmodx/data")))) { g_langMngr.InvalidateCache(); + } else { + g_langMngr.LoadCache(build_pathname_r(file, sizeof(file) - 1, "%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data"))); } // ###### Initialize commands prefixes @@ -1124,7 +1125,7 @@ C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_ int mmajor = 0, mminor = 0, pmajor = 0, pminor = 0; sscanf(ifvers, "%d:%d", &mmajor, &mminor); - sscanf(META_INTERFACE_VERSION, "%d:%d", &pmajor, &pminor); + sscanf(Plugin_info.ifvers, "%d:%d", &pmajor, &pminor); g_mm_vers = mminor; @@ -1154,11 +1155,14 @@ C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_ return FALSE; } } else if (pminor < mminor) { + //there's a later version of MM. //if we have 1.19, tell MM that we're okay. - //NOTE: ifvers 5:12 did not exist. - if (mminor == 13) + //NOTE: ifvers 5:11 did not exist. + if (mminor <= 13) { - Plugin_info.ifvers = "5:13"; + static char newvers[16]; + snprintf(newvers, sizeof(newvers)-1, "%d:%d", mmajor, mminor); + Plugin_info.ifvers = newvers; } } } diff --git a/amxmodx/msvc/amxmodx_mm.vcproj b/amxmodx/msvc/amxmodx_mm.vcproj index 83e24a47..ca770cc0 100755 --- a/amxmodx/msvc/amxmodx_mm.vcproj +++ b/amxmodx/msvc/amxmodx_mm.vcproj @@ -890,6 +890,67 @@ RelativePath="..\natives-x86.asm"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index 1d67dd0b..126bee66 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -682,7 +682,7 @@ static cell AMX_NATIVE_CALL player_menu_info(AMX *amx, cell *params) *m = player->menu; *n = player->newmenu; - if ( (*m != 0 && *m != -1) && (*n != 0 && *n != -1)) + if ( (*m != 0 && *m != -1) || (*n != -1)) return 1; return 0;