From 1dbb75574323086cf7859584c9c4073361cf39a6 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Fri, 29 May 2020 17:35:07 +0200 Subject: [PATCH 1/6] Add dofile() to Lua --- src/blua/lbaselib.c | 26 ++++++++++++++++++++++++++ src/lua_script.c | 14 +++++++------- src/lua_script.h | 4 ++-- src/w_wad.c | 20 ++++++++++++++------ 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/blua/lbaselib.c b/src/blua/lbaselib.c index 3c919cb64..644565c28 100644 --- a/src/blua/lbaselib.c +++ b/src/blua/lbaselib.c @@ -11,6 +11,10 @@ #include #include +#include "../doomdef.h" +#include "../lua_script.h" +#include "../w_wad.h" + #define lbaselib_c #define LUA_LIB @@ -263,6 +267,27 @@ static int luaB_ipairs (lua_State *L) { } +// Edited to load PK3 entries instead +static int luaB_dofile (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + char fullfilename[256]; + UINT16 lumpnum; + int n = lua_gettop(L); + + if (wadfiles[numwadfiles - 1]->type != RET_PK3) + luaL_error(L, "dofile() only works with PK3 files"); + + snprintf(fullfilename, sizeof(fullfilename), "Lua/%s", filename); + lumpnum = W_CheckNumForFullNamePK3(fullfilename, numwadfiles - 1, 0); + if (lumpnum == INT16_MAX) + luaL_error(L, "can't find script " LUA_QS, fullfilename); + + LUA_LoadLump(numwadfiles - 1, lumpnum, false); + + return lua_gettop(L) - n; +} + + static int luaB_assert (lua_State *L) { luaL_checkany(L, 1); if (!lua_toboolean(L, 1)) @@ -380,6 +405,7 @@ static const luaL_Reg base_funcs[] = { {"assert", luaB_assert}, {"collectgarbage", luaB_collectgarbage}, {"error", luaB_error}, + {"dofile", luaB_dofile}, {"gcinfo", luaB_gcinfo}, {"getfenv", luaB_getfenv}, {"getmetatable", luaB_getmetatable}, diff --git a/src/lua_script.c b/src/lua_script.c index 4f94b007e..0e0361535 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -395,10 +395,10 @@ void LUA_ClearExtVars(void) // Use this variable to prevent certain functions from running // if they were not called on lump load // (i.e. they were called in hooks or coroutines etc) -boolean lua_lumploading = false; +INT32 lua_lumploading = 0; // Load a script from a MYFILE -static inline void LUA_LoadFile(MYFILE *f, char *name) +static inline void LUA_LoadFile(MYFILE *f, char *name, boolean noresults) { if (!name) name = wadfiles[f->wad]->filename; @@ -408,19 +408,19 @@ static inline void LUA_LoadFile(MYFILE *f, char *name) lua_pushinteger(gL, f->wad); lua_setfield(gL, LUA_REGISTRYINDEX, "WAD"); - lua_lumploading = true; // turn on loading flag + lua_lumploading++; // turn on loading flag - if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, 0, 0)) { + if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, noresults ? 0 : LUA_MULTRET, 0)) { CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1)); lua_pop(gL,1); } lua_gc(gL, LUA_GCCOLLECT, 0); - lua_lumploading = false; // turn off again + lua_lumploading--; // turn off again } // Load a script from a lump -void LUA_LoadLump(UINT16 wad, UINT16 lump) +void LUA_LoadLump(UINT16 wad, UINT16 lump, boolean noresults) { MYFILE f; char *name; @@ -447,7 +447,7 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump) name[len] = '\0'; } - LUA_LoadFile(&f, name); // actually load file! + LUA_LoadFile(&f, name, noresults); // actually load file! free(name); Z_Free(f.data); diff --git a/src/lua_script.h b/src/lua_script.h index 8d5bed7c7..6815434c5 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -37,9 +37,9 @@ void LUA_ClearExtVars(void); #endif -extern boolean lua_lumploading; // is LUA_LoadLump being called? +extern INT32 lua_lumploading; // is LUA_LoadLump being called? -void LUA_LoadLump(UINT16 wad, UINT16 lump); +void LUA_LoadLump(UINT16 wad, UINT16 lump, boolean noresults); #ifdef LUA_ALLOW_BYTECODE void LUA_DumpFile(const char *filename); #endif diff --git a/src/w_wad.c b/src/w_wad.c index 041222479..af9f9a7c0 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -199,12 +199,20 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum, boolean mainfile) { UINT16 posStart, posEnd; - posStart = W_CheckNumForFolderStartPK3("Lua/", wadnum, 0); + posStart = W_CheckNumForFullNamePK3("Init.lua", wadnum, 0); if (posStart != INT16_MAX) { - posEnd = W_CheckNumForFolderEndPK3("Lua/", wadnum, posStart); - for (; posStart < posEnd; posStart++) - LUA_LoadLump(wadnum, posStart); + LUA_LoadLump(wadnum, posStart, true); + } + else + { + posStart = W_CheckNumForFolderStartPK3("Lua/", wadnum, 0); + if (posStart != INT16_MAX) + { + posEnd = W_CheckNumForFolderEndPK3("Lua/", wadnum, posStart); + for (; posStart < posEnd; posStart++) + LUA_LoadLump(wadnum, posStart, true); + } } posStart = W_CheckNumForFolderStartPK3("SOC/", wadnum, 0); @@ -236,7 +244,7 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum, boolean mainfile) lumpinfo_t *lump_p = wadfiles[wadnum]->lumpinfo; for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++) if (memcmp(lump_p->name,"LUA_",4)==0) - LUA_LoadLump(wadnum, lump); + LUA_LoadLump(wadnum, lump, true); } { @@ -854,7 +862,7 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup) DEH_LoadDehackedLumpPwad(numwadfiles - 1, 0, mainfile); break; case RET_LUA: - LUA_LoadLump(numwadfiles - 1, 0); + LUA_LoadLump(numwadfiles - 1, 0, true); break; default: break; From d589e6bc959ff072531fbe61c8956b24563f665b Mon Sep 17 00:00:00 2001 From: SwitchKaze Date: Fri, 29 May 2020 21:41:20 -0500 Subject: [PATCH 2/6] Fix signpost shade. --- src/p_enemy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_enemy.c b/src/p_enemy.c index 18de57b54..68b246cdc 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -5213,7 +5213,7 @@ void A_SignPlayer(mobj_t *actor) actor->tracer->color = signcolor; if (signcolor && signcolor < numskincolors) - signframe += (15 - skincolors[signcolor].invshade); + signframe += (15 - skincolors[facecolor].invshade); actor->tracer->frame = signframe; } From 5a18bdf20b3e062b3d7d8b1935bb93385fb37801 Mon Sep 17 00:00:00 2001 From: SwitchKaze Date: Sat, 30 May 2020 16:52:44 -0500 Subject: [PATCH 3/6] Fix SOC color name reading --- src/dehacked.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 627a3a119..b5ba248ce 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -769,7 +769,8 @@ static void readthing(MYFILE *f, INT32 num) static void readskincolor(MYFILE *f, INT32 num) { char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); - char *word, *word2, *word3; + char *word = s; + char *word2; char *tmp; Color_cons_t[num].value = num; @@ -781,32 +782,31 @@ static void readskincolor(MYFILE *f, INT32 num) if (s[0] == '\n') break; + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + tmp = strchr(s, '#'); if (tmp) *tmp = '\0'; if (s == tmp) continue; // Skip comment lines, but don't break. - word = strtok(s, " "); - if (word) - strupr(word); + // Get the part before the " = " + tmp = strchr(s, '='); + if (tmp) + *(tmp-1) = '\0'; else break; + strupr(word); - word2 = strtok(NULL, " = "); - if (word2) { - word3 = Z_StrDup(word2); - strupr(word2); - } else - break; - if (word2[strlen(word2)-1] == '\n') - word2[strlen(word2)-1] = '\0'; - if (word3[strlen(word3)-1] == '\n') - word3[strlen(word3)-1] = '\0'; + // Now get the part after + word2 = tmp += 2; if (fastcmp(word, "NAME")) { - deh_strlcpy(skincolors[num].name, word3, + deh_strlcpy(skincolors[num].name, word2, sizeof (skincolors[num].name), va("Skincolor %d: name", num)); } else if (fastcmp(word, "RAMP")) From 286b316cf98722a6c80130fd1714370762aa2663 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Mon, 1 Jun 2020 15:43:14 +0200 Subject: [PATCH 4/6] Fix dofile() return incorrect values --- src/lua_script.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index a0e4588a4..374294d6e 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -452,6 +452,8 @@ INT32 lua_lumploading = 0; // Load a script from a MYFILE static inline void LUA_LoadFile(MYFILE *f, char *name, boolean noresults) { + int errorhandlerindex; + if (!name) name = wadfiles[f->wad]->filename; CONS_Printf("Loading Lua script from %s\n", name); @@ -463,12 +465,13 @@ static inline void LUA_LoadFile(MYFILE *f, char *name, boolean noresults) lua_lumploading++; // turn on loading flag lua_pushcfunction(gL, LUA_GetErrorMessage); + errorhandlerindex = lua_gettop(gL); if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, noresults ? 0 : LUA_MULTRET, lua_gettop(gL) - 1)) { CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1)); lua_pop(gL,1); } lua_gc(gL, LUA_GCCOLLECT, 0); - lua_pop(gL, 1); // Pop error handler + lua_remove(gL, errorhandlerindex); lua_lumploading--; // turn off again } From 2cefe8295094653eb54c1bb82e76315cdee7cd40 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 8 Jun 2020 00:08:07 -0400 Subject: [PATCH 5/6] Fix OSX null-pointer-arithmetic error --- src/hardware/r_opengl/r_opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index ed60f2175..73f6a4044 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1924,7 +1924,7 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) } } -#define BUFFER_OFFSET(i) ((char*)NULL + (i)) +#define BUFFER_OFFSET(i) ((void*)(i)) static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, FTransform *pos, float scale, UINT8 flipped, UINT8 *color) { From a5f7f9a5342fb632a7887a7dc5995fc5f669ab51 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 6 Jun 2020 17:34:07 -0400 Subject: [PATCH 6/6] Fix OPENMPT deprecation error, openmpt_module_ctl_set --- src/sdl/mixer_sound.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 9a713608c..5a086880a 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -880,13 +880,18 @@ boolean I_SetSongSpeed(float speed) #ifdef HAVE_OPENMPT if (openmpt_mhandle) { - char modspd[13]; - if (speed > 4.0f) speed = 4.0f; // Limit this to 4x to prevent crashing, stupid fix but... ~SteelT 27/9/19 - - sprintf(modspd, "%g", speed); - openmpt_module_ctl_set(openmpt_mhandle, "play.tempo_factor", modspd); +#if OPENMPT_API_VERSION_MAJOR < 1 && OPENMPT_API_VERSION_MINOR < 5 + { + // deprecated in 0.5.0 + char modspd[13]; + sprintf(modspd, "%g", speed); + openmpt_module_ctl_set(openmpt_mhandle, "play.tempo_factor", modspd); + } +#else + openmpt_module_ctl_set_floatingpoint(openmpt_mhandle, "play.tempo_factor", (double)speed); +#endif return true; } #else