diff --git a/src/deh_lua.c b/src/deh_lua.c index 9a60c494b..bbcb3879d 100644 --- a/src/deh_lua.c +++ b/src/deh_lua.c @@ -587,13 +587,11 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word) else if (mathlib && fastncmp("TRANSLATION_",word,12)) { p = word+12; - for (i = 0; i < (signed)numcustomtranslations; i++) + int id = R_FindCustomTranslation_CaseInsensitive(p); + if (id != -1) { - if (fasticmp(p, customtranslations[i].name)) - { - lua_pushinteger(L, (int)customtranslations[i].id); - return 1; - } + lua_pushinteger(L, id); + return 1; } return luaL_error(L, "translation '%s' could not be found.\n", word); } diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 69050ec72..ea99a2e1c 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -343,9 +343,13 @@ static int mobj_get(lua_State *L) break; case mobj_translation: if (mo->translation) - lua_pushinteger(L, mo->translation); - else - lua_pushnil(L); + { + const char *name = R_GetCustomTranslationName(mo->translation); + if (name) + lua_pushstring(L, name); + break; + } + lua_pushnil(L); break; case mobj_blendmode: lua_pushinteger(L, mo->blendmode); diff --git a/src/r_translation.c b/src/r_translation.c index 24019ed00..7f320d498 100644 --- a/src/r_translation.c +++ b/src/r_translation.c @@ -819,8 +819,15 @@ fail: Z_Free(text); } -customtranslation_t *customtranslations = NULL; -unsigned numcustomtranslations = 0; +typedef struct CustomTranslation +{ + char *name; + unsigned id; + UINT32 hash; +} customtranslation_t; + +static customtranslation_t *customtranslations = NULL; +static unsigned numcustomtranslations = 0; int R_FindCustomTranslation(const char *name) { @@ -835,6 +842,18 @@ int R_FindCustomTranslation(const char *name) return -1; } +// This is needed for SOC (which is case insensitive) +int R_FindCustomTranslation_CaseInsensitive(const char *name) +{ + for (unsigned i = 0; i < numcustomtranslations; i++) + { + if (stricmp(name, customtranslations[i].name) == 0) + return (int)customtranslations[i].id; + } + + return -1; +} + void R_AddCustomTranslation(const char *name, int trnum) { customtranslation_t *tr = NULL; @@ -862,6 +881,17 @@ void R_AddCustomTranslation(const char *name, int trnum) tr->hash = quickncasehash(name, strlen(name)); } +const char *R_GetCustomTranslationName(unsigned id) +{ + for (unsigned i = 0; i < numcustomtranslations; i++) + { + if (id == customtranslations[i].id) + return customtranslations[i].name; + } + + return NULL; +} + unsigned R_NumCustomTranslations(void) { return numcustomtranslations; diff --git a/src/r_translation.h b/src/r_translation.h index c7a4562e3..24b0597ef 100644 --- a/src/r_translation.h +++ b/src/r_translation.h @@ -82,18 +82,10 @@ struct PaletteRemapParseResult *PaletteRemap_ParseTranslation(const char *transl void PaletteRemap_ApplyResult(remaptable_t *tr, struct PaletteRemapParseResult *data); -typedef struct CustomTranslation -{ - char *name; - unsigned id; - UINT32 hash; -} customtranslation_t; - -extern customtranslation_t *customtranslations; -extern unsigned numcustomtranslations; - int R_FindCustomTranslation(const char *name); +int R_FindCustomTranslation_CaseInsensitive(const char *name); void R_AddCustomTranslation(const char *name, int trnum); +const char *R_GetCustomTranslationName(unsigned id); unsigned R_NumCustomTranslations(void); remaptable_t *R_GetTranslationByID(int id); boolean R_TranslationIsValid(int id);