mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 14:25:38 +03:00
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
This commit is contained in:
parent
458f2acfe7
commit
e2c1b8c178
@ -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<sKeyDef> &vec)
|
||||
@ -229,14 +236,13 @@ bool CLangMngr::CLang::SaveDefinitions(FILE *fp, uint32_t &curOffset)
|
||||
{
|
||||
unsigned short defLen = 0;
|
||||
String *pdef;
|
||||
String blank;
|
||||
|
||||
THash<int, defentry>::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<int, defentry>::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<int, defentry>::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; \
|
||||
|
@ -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<int, defentry> 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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -890,6 +890,67 @@
|
||||
RelativePath="..\natives-x86.asm">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="SDK"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath="..\sdk\amxxmodule.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="MemtestDebug|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="MemtestRelease|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="JITDebug|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="JITRelease|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="JITMemtestRelease|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="MaximalSpeed|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\sdk\amxxmodule.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\sdk\moduleconfig.h">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user