From b0cbc8ab2a59cd863c5c59f7593215fc1cd316a0 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Wed, 2 Mar 2016 23:47:06 -0600 Subject: [PATCH 01/31] Lua slope manipulation stuff! Warning: Incomplete. Very prone to crashing and I might not have handled some things properly. Use with caution. --- src/dehacked.c | 6 ++ src/lua_libs.h | 1 + src/lua_maplib.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++- src/p_slopes.c | 2 +- src/p_slopes.h | 1 + 5 files changed, 220 insertions(+), 2 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index d6a1881e..d8847fd3 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -7230,6 +7230,12 @@ struct { {"FF_COLORMAPONLY",FF_COLORMAPONLY}, ///< Only copy the colormap, not the lightlevel {"FF_GOOWATER",FF_GOOWATER}, ///< Used with ::FF_SWIMMABLE. Makes thick bouncey goop. + // Slope flags + {"SL_NOPHYSICS",SL_NOPHYSICS}, // Don't do momentum adjustment with this slope + {"SL_NODYNAMIC",SL_NODYNAMIC}, // Slope will never need to move during the level, so don't fuss with recalculating it + {"SL_ANCHORVERTEX",SL_ANCHORVERTEX},// Slope is using a Slope Vertex Thing to anchor its position + {"SL_VERTEXSLOPE",SL_VERTEXSLOPE}, // Slope is built from three Slope Vertex Things + // Angles {"ANG1",ANG1>>16}, {"ANG2",ANG2>>16}, diff --git a/src/lua_libs.h b/src/lua_libs.h index d19ad885..893f5668 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -38,6 +38,7 @@ extern lua_State *gL; #define META_SUBSECTOR "SUBSECTOR_T*" #define META_SECTOR "SECTOR_T*" #define META_FFLOOR "FFLOOR_T*" +#define META_SLOPE "PSLOPE_T*" #define META_MAPHEADER "MAPHEADER_T*" #define META_CVAR "CONSVAR_T*" diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 16d05dac..a6ebf1ab 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -16,6 +16,8 @@ #include "p_local.h" #include "p_setup.h" #include "z_zone.h" +#include "p_slopes.h" +#include "r_main.h" #include "lua_script.h" #include "lua_libs.h" @@ -37,7 +39,10 @@ enum sector_e { sector_thinglist, sector_heightsec, sector_camsec, - sector_ffloors + sector_ffloors, + sector_fslope, + sector_cslope, + sector_hasslope }; static const char *const sector_opt[] = { @@ -53,6 +58,9 @@ static const char *const sector_opt[] = { "heightsec", "camsec", "ffloors", + "f_slope", + "c_slope", + "hasslope", NULL}; enum subsector_e { @@ -158,6 +166,8 @@ enum ffloor_e { ffloor_toplightlevel, ffloor_bottomheight, ffloor_bottompic, + ffloor_tslope, + ffloor_bslope, ffloor_sector, ffloor_flags, ffloor_master, @@ -174,6 +184,8 @@ static const char *const ffloor_opt[] = { "toplightlevel", "bottomheight", "bottompic", + "t_slope", + "b_slope", "sector", // secnum pushed as control sector userdata "flags", "master", // control linedef @@ -183,6 +195,32 @@ static const char *const ffloor_opt[] = { "alpha", NULL}; +enum slope_e { + slope_valid = 0, + slope_o, + slope_d, + slope_zdelta, + slope_normal, + slope_zangle, + slope_xydirection, + slope_sourceline, + slope_refpos, + slope_flags +}; + +static const char *const slope_opt[] = { + "valid", + "o", + "d", + "zdelta", + "normal", + "zangle", + "xydirection", + "sourceline", + "refpos", + "flags", + NULL}; + static const char *const array_opt[] ={"iterate",NULL}; static const char *const valid_opt[] ={"valid",NULL}; @@ -330,6 +368,15 @@ static int sector_get(lua_State *L) LUA_PushUserdata(L, sector->ffloors, META_FFLOOR); lua_pushcclosure(L, sector_iterate, 2); // push lib_iterateFFloors and sector->ffloors as upvalues for the function return 1; + case sector_fslope: // f_slope + LUA_PushUserdata(L, sector->f_slope, META_SLOPE); + return 1; + case sector_cslope: // c_slope + LUA_PushUserdata(L, sector->c_slope, META_SLOPE); + return 1; + case sector_hasslope: // hasslope + lua_pushboolean(L, sector->hasslope); + return 1; } return 0; } @@ -392,6 +439,9 @@ static int sector_set(lua_State *L) case sector_heightsec: // heightsec case sector_camsec: // camsec case sector_ffloors: // ffloors + case sector_fslope: // f_slope + case sector_cslope: // c_slope + case sector_hasslope: // hasslope default: return luaL_error(L, "sector_t field " LUA_QS " cannot be set.", sector_opt[field]); case sector_floorheight: { // floorheight @@ -1026,6 +1076,12 @@ static int ffloor_get(lua_State *L) lua_pushlstring(L, levelflat->name, 8); return 1; } + case ffloor_tslope: + LUA_PushUserdata(L, *ffloor->t_slope, META_SLOPE); + return 1; + case ffloor_bslope: + LUA_PushUserdata(L, *ffloor->b_slope, META_SLOPE); + return 1; case ffloor_sector: LUA_PushUserdata(L, §ors[ffloor->secnum], META_SECTOR); return 1; @@ -1065,6 +1121,8 @@ static int ffloor_set(lua_State *L) switch(field) { case ffloor_valid: // valid + case ffloor_tslope: // t_slope + case ffloor_bslope: // b_slope case ffloor_sector: // sector case ffloor_master: // master case ffloor_target: // target @@ -1125,6 +1183,150 @@ static int ffloor_set(lua_State *L) return 0; } +static int slope_get(lua_State *L) +{ + pslope_t *slope = *((pslope_t **)luaL_checkudata(L, 1, META_SLOPE)); + enum slope_e field = luaL_checkoption(L, 2, slope_opt[0], slope_opt); + + if (!slope) + { + if (field == slope_valid) { + lua_pushboolean(L, 0); + return 1; + } + return luaL_error(L, "accessed pslope_t doesn't exist anymore."); + } + + switch(field) + { + case slope_valid: // valid + lua_pushboolean(L, 1); + return 1; + case slope_o: // o + lua_createtable(L, 0, 3); + lua_pushfixed(L, slope->o.x); + lua_setfield(L, -2, "x"); + lua_pushfixed(L, slope->o.y); + lua_setfield(L, -2, "y"); + lua_pushfixed(L, slope->o.z); + lua_setfield(L, -2, "z"); + return 1; + case slope_d: // d + lua_createtable(L, 0, 2); + lua_pushfixed(L, slope->o.x); + lua_setfield(L, -2, "x"); + lua_pushfixed(L, slope->o.y); + lua_setfield(L, -2, "y"); + return 1; + case slope_zdelta: // zdelta + lua_pushfixed(L, slope->zdelta); + return 1; + case slope_normal: // normal + lua_createtable(L, 0, 2); + lua_pushfixed(L, slope->o.x); + lua_setfield(L, -2, "x"); + lua_pushfixed(L, slope->o.y); + lua_setfield(L, -2, "y"); + return 1; + case slope_zangle: // zangle + lua_pushangle(L, slope->zangle); + return 1; + case slope_xydirection: // xydirection + lua_pushangle(L, slope->xydirection); + return 1; + case slope_sourceline: // source linedef + LUA_PushUserdata(L, slope->sourceline, META_LINE); + return 1; + case slope_refpos: // refpos + lua_pushinteger(L, slope->refpos); + return 1; + case slope_flags: // flags + lua_pushinteger(L, slope->flags); + return 1; + } + return 0; +} + +static int slope_set(lua_State *L) +{ + pslope_t *slope = *((pslope_t **)luaL_checkudata(L, 1, META_SLOPE)); + enum slope_e field = luaL_checkoption(L, 2, slope_opt[0], slope_opt); + + if (!slope) + return luaL_error(L, "accessed pslope_t doesn't exist anymore."); + + if (hud_running) + return luaL_error(L, "Do not alter pslope_t in HUD rendering code!"); + + switch(field) // todo: reorganize this shit + { + case slope_valid: // valid + case slope_sourceline: // sourceline + case slope_d: // d + case slope_flags: // flags + case slope_normal: // normal + case slope_refpos: // refpos + default: + return luaL_error(L, "pslope_t field " LUA_QS " cannot be set.", slope_opt[field]); + case slope_o: { // o + luaL_checktype(L, 3, LUA_TTABLE); + + lua_getfield(L, 3, "x"); + if (lua_isnil(L, -1)) + { + lua_pop(L, 1); + lua_rawgeti(L, 3, 1); + } + if (!lua_isnil(L, -1)) + slope->o.x = luaL_checkfixed(L, -1); + else + slope->o.x = 0; + lua_pop(L, 1); + + lua_getfield(L, 3, "y"); + if (lua_isnil(L, -1)) + { + lua_pop(L, 1); + lua_rawgeti(L, 3, 2); + } + if (!lua_isnil(L, -1)) + slope->o.y = luaL_checkfixed(L, -1); + else + slope->o.y = 0; + lua_pop(L, 1); + + lua_getfield(L, 3, "z"); + if (lua_isnil(L, -1)) + { + lua_pop(L, 1); + lua_rawgeti(L, 3, 3); + } + if (!lua_isnil(L, -1)) + slope->o.z = luaL_checkfixed(L, -1); + else + slope->o.z = 0; + lua_pop(L, 1); + break; + } + case slope_zdelta: { // zdelta, this is temp until i figure out wtf to do + slope->zdelta = luaL_checkfixed(L, 3); + slope->zangle = R_PointToAngle2(0, 0, FRACUNIT, slope->zdelta); + P_CalculateSlopeNormal(slope); + break; + } + case slope_zangle: // zangle + slope->zangle = luaL_checkangle(L, 3); + slope->zdelta = FINETANGENT(slope->zangle); + P_CalculateSlopeNormal(slope); + break; + case slope_xydirection: // xydirection + slope->xydirection = luaL_checkangle(L, 3); + P_CalculateSlopeNormal(slope); + break; + } + return 0; +} + static int lib_getMapheaderinfo(lua_State *L) { // i -> mapheaderinfo[i-1] @@ -1293,6 +1495,14 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__newindex"); lua_pop(L, 1); + luaL_newmetatable(L, META_SLOPE); + lua_pushcfunction(L, slope_get); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, slope_set); + lua_setfield(L, -2, "__newindex"); + lua_pop(L, 1); + luaL_newmetatable(L, META_MAPHEADER); lua_pushcfunction(L, mapheaderinfo_get); lua_setfield(L, -2, "__index"); diff --git a/src/p_slopes.c b/src/p_slopes.c index 2d55cf19..b51b2a4d 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -46,7 +46,7 @@ static pslope_t *slopelist = NULL; static UINT16 slopecount = 0; // Calculate line normal -static void P_CalculateSlopeNormal(pslope_t *slope) { +void P_CalculateSlopeNormal(pslope_t *slope) { slope->normal.z = FINECOSINE(slope->zangle>>ANGLETOFINESHIFT); slope->normal.x = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.x); slope->normal.y = -FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.y); diff --git a/src/p_slopes.h b/src/p_slopes.h index 8d82632f..7898302e 100644 --- a/src/p_slopes.h +++ b/src/p_slopes.h @@ -29,6 +29,7 @@ #define P_SLOPES_H__ #ifdef ESLOPE +void P_CalculateSlopeNormal(pslope_t *slope); void P_ResetDynamicSlopes(void); void P_RunDynamicSlopes(void); // P_SpawnSlope_Line From b3d842e8590938de3e4ac6cfea61a7df3023f4cc Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 3 Mar 2016 14:43:42 +0000 Subject: [PATCH 02/31] Fix accidental copy+paste of o to d and normal in slope_get code --- src/lua_maplib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index a6ebf1ab..218f26e1 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1213,9 +1213,9 @@ static int slope_get(lua_State *L) return 1; case slope_d: // d lua_createtable(L, 0, 2); - lua_pushfixed(L, slope->o.x); + lua_pushfixed(L, slope->d.x); lua_setfield(L, -2, "x"); - lua_pushfixed(L, slope->o.y); + lua_pushfixed(L, slope->d.y); lua_setfield(L, -2, "y"); return 1; case slope_zdelta: // zdelta @@ -1223,9 +1223,9 @@ static int slope_get(lua_State *L) return 1; case slope_normal: // normal lua_createtable(L, 0, 2); - lua_pushfixed(L, slope->o.x); + lua_pushfixed(L, slope->normal.x); lua_setfield(L, -2, "x"); - lua_pushfixed(L, slope->o.y); + lua_pushfixed(L, slope->normal.y); lua_setfield(L, -2, "y"); return 1; case slope_zangle: // zangle From ad0069676a4cbc1201dbf3bfef35f28052df303b Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Thu, 3 Mar 2016 20:47:05 -0600 Subject: [PATCH 03/31] slope->normal is vector3_t, not vector2_t --- src/lua_maplib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 218f26e1..f584ce4c 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1222,11 +1222,13 @@ static int slope_get(lua_State *L) lua_pushfixed(L, slope->zdelta); return 1; case slope_normal: // normal - lua_createtable(L, 0, 2); + lua_createtable(L, 0, 3); lua_pushfixed(L, slope->normal.x); lua_setfield(L, -2, "x"); lua_pushfixed(L, slope->normal.y); lua_setfield(L, -2, "y"); + lua_pushfixed(L, slope->normal.z); + lua_setfield(L, -2, "z"); return 1; case slope_zangle: // zangle lua_pushangle(L, slope->zangle); From cb62f08364d4d53e51d4770198e2b65b3547e62b Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Thu, 20 Oct 2016 22:23:50 -0400 Subject: [PATCH 04/31] "PlayerQuit" hook --- src/lua_hook.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lua_hook.h b/src/lua_hook.h index 804d99e1..240fdaec 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -43,6 +43,7 @@ enum hook { hook_PlayerMsg, hook_HurtMsg, hook_PlayerSpawn, + hook_PlayerQuit, hook_MAX // last hook }; @@ -77,5 +78,6 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg); // Hook for chat messages boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source); // Hook for hurt messages #define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for G_SpawnPlayer +boolean LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting #endif From cfb2feff8ef4344130bed3456937ecb9609c593a Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Thu, 20 Oct 2016 22:25:11 -0400 Subject: [PATCH 05/31] "PlayerQuit" hook --- src/lua_hooklib.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 1b965257..be3f8b0e 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -54,6 +54,7 @@ const char *const hookNames[hook_MAX+1] = { "PlayerMsg", "HurtMsg", "PlayerSpawn", + "PlayerQuit", NULL }; @@ -798,4 +799,41 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc) // stack: tables } +boolean LUAh_PlayerQuit(player_t *plr, int reason) +{ + hook_p hookp; + boolean hooked = false; + if (!gL || !(hooksAvailable[hook_PlayerQuit/8] & (1<<(hook_PlayerQuit%8)))) + return false; + + lua_settop(gL, 0); + + for (hookp = roothook; hookp; hookp = hookp->next) + if (hookp->type == hook_PlayerQuit) + { + if (lua_gettop(gL) == 0) + { + LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit + lua_pushinteger(gL, reason); // Reason for quitting + } + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + lua_pushvalue(gL, -3); + lua_pushvalue(gL, -3); + if (lua_pcall(gL, 2, 1, 0)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + continue; + } + if (lua_toboolean(gL, -1)) + hooked = true; + lua_pop(gL, 1); + } + + lua_settop(gL, 0); + return hooked; +} + #endif From 89e8766b77f0176e9680522cd4a9b325a2e1b33c Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Thu, 20 Oct 2016 22:30:11 -0400 Subject: [PATCH 06/31] "PlayerQuit" hook --- src/d_clisrv.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index c0f81ba3..973564a9 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2208,7 +2208,7 @@ void CL_ClearPlayer(INT32 playernum) // // Removes a player from the current game // -static void CL_RemovePlayer(INT32 playernum) +static void CL_RemovePlayer(INT32 playernum, INT32 reason) { // Sanity check: exceptional cases (i.e. c-fails) can cause multiple // kick commands to be issued for the same player. @@ -2262,6 +2262,10 @@ static void CL_RemovePlayer(INT32 playernum) } } } + +#ifdef HAVE_BLUA + LUAh_PlayerQuit(&players[playernum], reason); // Lua hook for player quitting +#endif // Reset player data CL_ClearPlayer(playernum); @@ -2513,6 +2517,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) INT32 pnum, msg; XBOXSTATIC char buf[3 + MAX_REASONLENGTH]; char *reason = buf; + INT32 kickreason = 1; pnum = READUINT8(*p); msg = READUINT8(*p); @@ -2593,14 +2598,17 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) { case KICK_MSG_GO_AWAY: CONS_Printf(M_GetText("has been kicked (Go away)\n")); + kickreason = 1; break; #ifdef NEWPING case KICK_MSG_PING_HIGH: CONS_Printf(M_GetText("left the game (Broke ping limit)\n")); + kickreason = 2; break; #endif case KICK_MSG_CON_FAIL: CONS_Printf(M_GetText("left the game (Synch failure)\n")); + kickreason = 3; if (M_CheckParm("-consisdump")) // Helps debugging some problems { @@ -2637,21 +2645,26 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) break; case KICK_MSG_TIMEOUT: CONS_Printf(M_GetText("left the game (Connection timeout)\n")); + kickreason = 4; break; case KICK_MSG_PLAYER_QUIT: if (netgame) // not splitscreen/bots CONS_Printf(M_GetText("left the game\n")); + kickreason = 6; break; case KICK_MSG_BANNED: CONS_Printf(M_GetText("has been banned (Don't come back)\n")); + kickreason = 5; break; case KICK_MSG_CUSTOM_KICK: READSTRINGN(*p, reason, MAX_REASONLENGTH+1); CONS_Printf(M_GetText("has been kicked (%s)\n"), reason); + kickreason = 1; break; case KICK_MSG_CUSTOM_BAN: READSTRINGN(*p, reason, MAX_REASONLENGTH+1); CONS_Printf(M_GetText("has been banned (%s)\n"), reason); + kickreason = 5; break; } @@ -2679,7 +2692,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) M_StartMessage(M_GetText("You have been kicked by the server\n\nPress ESC\n"), NULL, MM_NOTHING); } else - CL_RemovePlayer(pnum); + CL_RemovePlayer(pnum, kickreason); } consvar_t cv_allownewplayer = {"allowjoin", "On", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; From fcf2fe79e00dae735cf383ce04422a6548fe4288 Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Thu, 20 Oct 2016 23:25:47 -0400 Subject: [PATCH 07/31] Oops; PlayerQuit isn't a boolean! --- src/lua_hook.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 240fdaec..94b934f3 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -78,6 +78,6 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg); // Hook for chat messages boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source); // Hook for hurt messages #define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for G_SpawnPlayer -boolean LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting +void LUAh_PlayerQuit(player_t *plr, int reason); // Hook for player quitting #endif From defc7c164545eeae8db8f81de5c8ca46eff9af14 Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Thu, 20 Oct 2016 23:26:41 -0400 Subject: [PATCH 08/31] Oops; PlayerQuit isn't a boolean! --- src/lua_hooklib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index be3f8b0e..5ac77da9 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -799,12 +799,12 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc) // stack: tables } -boolean LUAh_PlayerQuit(player_t *plr, int reason) +void LUAh_PlayerQuit(player_t *plr, int reason) { hook_p hookp; boolean hooked = false; if (!gL || !(hooksAvailable[hook_PlayerQuit/8] & (1<<(hook_PlayerQuit%8)))) - return false; + return; lua_settop(gL, 0); From 673315265107da0740372f2ba1917cb89396c208 Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Fri, 21 Oct 2016 16:16:54 -0400 Subject: [PATCH 09/31] No more magic numbers --- src/d_clisrv.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 973564a9..cfe0c1cd 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2517,7 +2517,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) INT32 pnum, msg; XBOXSTATIC char buf[3 + MAX_REASONLENGTH]; char *reason = buf; - INT32 kickreason = 1; + kickreason_t kickreason = KR_KICK; pnum = READUINT8(*p); msg = READUINT8(*p); @@ -2598,17 +2598,17 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) { case KICK_MSG_GO_AWAY: CONS_Printf(M_GetText("has been kicked (Go away)\n")); - kickreason = 1; + kickreason = KR_KICK; break; #ifdef NEWPING case KICK_MSG_PING_HIGH: CONS_Printf(M_GetText("left the game (Broke ping limit)\n")); - kickreason = 2; + kickreason = KR_PINGLIMIT; break; #endif case KICK_MSG_CON_FAIL: CONS_Printf(M_GetText("left the game (Synch failure)\n")); - kickreason = 3; + kickreason = KR_SYNCH; if (M_CheckParm("-consisdump")) // Helps debugging some problems { @@ -2645,26 +2645,26 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) break; case KICK_MSG_TIMEOUT: CONS_Printf(M_GetText("left the game (Connection timeout)\n")); - kickreason = 4; + kickreason = KR_TIMEOUT; break; case KICK_MSG_PLAYER_QUIT: if (netgame) // not splitscreen/bots CONS_Printf(M_GetText("left the game\n")); - kickreason = 6; + kickreason = KR_LEAVE; break; case KICK_MSG_BANNED: CONS_Printf(M_GetText("has been banned (Don't come back)\n")); - kickreason = 5; + kickreason = KR_BAN; break; case KICK_MSG_CUSTOM_KICK: READSTRINGN(*p, reason, MAX_REASONLENGTH+1); CONS_Printf(M_GetText("has been kicked (%s)\n"), reason); - kickreason = 1; + kickreason = KR_KICK; break; case KICK_MSG_CUSTOM_BAN: READSTRINGN(*p, reason, MAX_REASONLENGTH+1); CONS_Printf(M_GetText("has been banned (%s)\n"), reason); - kickreason = 5; + kickreason = KR_BAN; break; } From c38457f23c70509cef3fd131e380332c2e43ab4f Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Fri, 21 Oct 2016 16:25:07 -0400 Subject: [PATCH 10/31] No more magic numbers --- src/d_clisrv.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 14b59092..cd726d9b 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -436,6 +436,17 @@ extern consvar_t cv_playbackspeed; #define KICK_MSG_CUSTOM_KICK 7 #define KICK_MSG_CUSTOM_BAN 8 +typedef enum +{ + KR_KICK = 1, //Kicked by server + KR_PINGLIMIT = 2, //Broke Ping Limit + KR_SYNCH = 3, //Synch Failure + KR_TIMEOUT = 4, //Connection Timeout + KR_BAN = 5, //Banned by server + KR_LEAVE = 6, //Quit the game + +} kickreason_t; + extern boolean server; extern boolean dedicated; // for dedicated server extern UINT16 software_MAXPACKETLENGTH; From b5988e082cd012555e532d7c0a25b73818ec6566 Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Fri, 21 Oct 2016 16:27:15 -0400 Subject: [PATCH 11/31] No more magic numbers --- src/dehacked.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dehacked.c b/src/dehacked.c index f03dd73b..62a7ad81 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -31,6 +31,7 @@ #include "fastcmp.h" #include "lua_script.h" #include "lua_hook.h" +#include "d_clisrv.h" #include "m_cond.h" @@ -7392,6 +7393,14 @@ struct { {"V_CHARCOLORSHIFT",V_CHARCOLORSHIFT}, {"V_ALPHASHIFT",V_ALPHASHIFT}, + + //Kick Reasons + {"KR_KICK",KR_KICK}, + {"KR_PINGLIMIT",KR_PINGLIMIT}, + {"KR_SYNCH",KR_SYNCH}, + {"KR_TIMEOUT",KR_TIMEOUT}, + {"KR_BAN",KR_BAN}, + {"KR_LEAVE",KR_LEAVE}, #endif {NULL,0} From b1ce5896aa97509268589cbcba26431c08f8adf9 Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Tue, 8 Nov 2016 10:30:01 -0500 Subject: [PATCH 12/31] Remove boolean remnants --- src/lua_hooklib.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 5ac77da9..16f8c55d 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -802,7 +802,6 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc) void LUAh_PlayerQuit(player_t *plr, int reason) { hook_p hookp; - boolean hooked = false; if (!gL || !(hooksAvailable[hook_PlayerQuit/8] & (1<<(hook_PlayerQuit%8)))) return; @@ -811,29 +810,16 @@ void LUAh_PlayerQuit(player_t *plr, int reason) for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerQuit) { - if (lua_gettop(gL) == 0) - { - LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit - lua_pushinteger(gL, reason); // Reason for quitting - } + LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit + lua_pushinteger(gL, reason); // Reason for quitting lua_pushfstring(gL, FMT_HOOKID, hookp->id); lua_gettable(gL, LUA_REGISTRYINDEX); lua_pushvalue(gL, -3); lua_pushvalue(gL, -3); - if (lua_pcall(gL, 2, 1, 0)) { - if (!hookp->error || cv_debug & DBG_LUA) - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); - hookp->error = true; - continue; - } - if (lua_toboolean(gL, -1)) - hooked = true; - lua_pop(gL, 1); + LUA_Call(gL, 2); } lua_settop(gL, 0); - return hooked; } #endif From d788cb7676e8832147d9e6ae911b10005987a85c Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Fri, 25 Nov 2016 15:20:41 -0500 Subject: [PATCH 13/31] Keeping the lua_gettop(gL) thing, otherwise the player/reason values will be pushed once to the stack each for every hook. Thanks MonsterIestyn! --- src/lua_hooklib.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 16f8c55d..7c10b7e3 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -810,7 +810,11 @@ void LUAh_PlayerQuit(player_t *plr, int reason) for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerQuit) { - LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit + if (lua_gettop(gL) == 0) + { + LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit + lua_pushinteger(gL, reason); // Reason for quitting + } lua_pushinteger(gL, reason); // Reason for quitting lua_pushfstring(gL, FMT_HOOKID, hookp->id); lua_gettable(gL, LUA_REGISTRYINDEX); From dd13df230831debbfb08a447800ea8cc18bd4abf Mon Sep 17 00:00:00 2001 From: Prisima the Fox Date: Sat, 3 Dec 2016 18:18:16 -0500 Subject: [PATCH 14/31] Whoops, didn't see the duplicate line. --- src/lua_hooklib.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 7c10b7e3..273264d7 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -815,7 +815,6 @@ void LUAh_PlayerQuit(player_t *plr, int reason) LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit lua_pushinteger(gL, reason); // Reason for quitting } - lua_pushinteger(gL, reason); // Reason for quitting lua_pushfstring(gL, FMT_HOOKID, hookp->id); lua_gettable(gL, LUA_REGISTRYINDEX); lua_pushvalue(gL, -3); From 61fa7026a107e30688bf836e0fc7c6a7c9f77861 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 20 Oct 2018 19:00:37 +0100 Subject: [PATCH 15/31] add vector2 and vector3 userdata types to simplify getting a slope's o/d/normal --- src/lua_libs.h | 2 ++ src/lua_maplib.c | 82 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/src/lua_libs.h b/src/lua_libs.h index bf7fe03e..a9c82bce 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -39,6 +39,8 @@ extern lua_State *gL; #define META_SECTOR "SECTOR_T*" #define META_FFLOOR "FFLOOR_T*" #define META_SLOPE "PSLOPE_T*" +#define META_VECTOR2 "VECTOR2_T" +#define META_VECTOR3 "VECTOR3_T" #define META_MAPHEADER "MAPHEADER_T*" #define META_CVAR "CONSVAR_T*" diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 7a94060e..e769a00d 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -223,6 +223,19 @@ static const char *const slope_opt[] = { "flags", NULL}; +// shared by both vector2_t and vector3_t +enum vector_e { + vector_x = 0, + vector_y, + vector_z +}; + +static const char *const vector_opt[] = { + "x", + "y", + "z", + NULL}; + static const char *const array_opt[] ={"iterate",NULL}; static const char *const valid_opt[] ={"valid",NULL}; @@ -1232,32 +1245,16 @@ static int slope_get(lua_State *L) lua_pushboolean(L, 1); return 1; case slope_o: // o - lua_createtable(L, 0, 3); - lua_pushfixed(L, slope->o.x); - lua_setfield(L, -2, "x"); - lua_pushfixed(L, slope->o.y); - lua_setfield(L, -2, "y"); - lua_pushfixed(L, slope->o.z); - lua_setfield(L, -2, "z"); + LUA_PushUserdata(L, &slope->o, META_VECTOR3); return 1; case slope_d: // d - lua_createtable(L, 0, 2); - lua_pushfixed(L, slope->d.x); - lua_setfield(L, -2, "x"); - lua_pushfixed(L, slope->d.y); - lua_setfield(L, -2, "y"); + LUA_PushUserdata(L, &slope->d, META_VECTOR2); return 1; case slope_zdelta: // zdelta lua_pushfixed(L, slope->zdelta); return 1; case slope_normal: // normal - lua_createtable(L, 0, 3); - lua_pushfixed(L, slope->normal.x); - lua_setfield(L, -2, "x"); - lua_pushfixed(L, slope->normal.y); - lua_setfield(L, -2, "y"); - lua_pushfixed(L, slope->normal.z); - lua_setfield(L, -2, "z"); + LUA_PushUserdata(L, &slope->normal, META_VECTOR3); return 1; case slope_zangle: // zangle lua_pushangle(L, slope->zangle); @@ -1358,6 +1355,43 @@ static int slope_set(lua_State *L) return 0; } +static int vector2_get(lua_State *L) +{ + vector2_t *vec = *((vector2_t **)luaL_checkudata(L, 1, META_VECTOR2)); + enum vector_e field = luaL_checkoption(L, 2, vector_opt[0], vector_opt); + + if (!vec) + return luaL_error(L, "accessed vector2_t doesn't exist anymore."); + + switch(field) + { + case vector_x: lua_pushfixed(L, vec->x); return 1; + case vector_y: lua_pushfixed(L, vec->y); return 1; + default: break; + } + + return 0; +} + +static int vector3_get(lua_State *L) +{ + vector3_t *vec = *((vector3_t **)luaL_checkudata(L, 1, META_VECTOR3)); + enum vector_e field = luaL_checkoption(L, 2, vector_opt[0], vector_opt); + + if (!vec) + return luaL_error(L, "accessed vector3_t doesn't exist anymore."); + + switch(field) + { + case vector_x: lua_pushfixed(L, vec->x); return 1; + case vector_y: lua_pushfixed(L, vec->y); return 1; + case vector_z: lua_pushfixed(L, vec->z); return 1; + default: break; + } + + return 0; +} + static int lib_getMapheaderinfo(lua_State *L) { // i -> mapheaderinfo[i-1] @@ -1542,6 +1576,16 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__newindex"); lua_pop(L, 1); + luaL_newmetatable(L, META_VECTOR2); + lua_pushcfunction(L, vector2_get); + lua_setfield(L, -2, "__index"); + lua_pop(L, 1); + + luaL_newmetatable(L, META_VECTOR3); + lua_pushcfunction(L, vector3_get); + lua_setfield(L, -2, "__index"); + lua_pop(L, 1); + luaL_newmetatable(L, META_MAPHEADER); lua_pushcfunction(L, mapheaderinfo_get); lua_setfield(L, -2, "__index"); From 4edeeb69539267dce61e9841c564632dc6cad20d Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 20 Oct 2018 21:08:59 +0100 Subject: [PATCH 16/31] Add P_GetZAt to Lua --- src/lua_baselib.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index e8e8fd02..f60756f1 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -14,6 +14,9 @@ #ifdef HAVE_BLUA #include "p_local.h" #include "p_setup.h" // So we can have P_SetupLevelSky +#ifdef ESLOPE +#include "p_slopes.h" // P_GetZAt +#endif #include "z_zone.h" #include "r_main.h" #include "r_things.h" @@ -1547,6 +1550,24 @@ static int lib_evCrumbleChain(lua_State *L) return 0; } +#ifdef ESLOPE +// P_SLOPES +//////////// + +static int lib_pGetZAt(lua_State *L) +{ + pslope_t *slope = *((pslope_t **)luaL_checkudata(L, 1, META_SLOPE)); + fixed_t x = luaL_checkfixed(L, 2); + fixed_t y = luaL_checkfixed(L, 3); + //HUDSAFE + if (!slope) + return LUA_ErrInvalid(L, "pslope_t"); + + lua_pushfixed(L, P_GetZAt(slope, x, y)); + return 1; +} +#endif + // R_DEFS //////////// @@ -2113,6 +2134,11 @@ static luaL_Reg lib[] = { {"P_StartQuake",lib_pStartQuake}, {"EV_CrumbleChain",lib_evCrumbleChain}, +#ifdef ESLOPE + // p_slopes + {"P_GetZAt",lib_pGetZAt}, +#endif + // r_defs {"R_PointToAngle",lib_rPointToAngle}, {"R_PointToAngle2",lib_rPointToAngle2}, From 9296aaa28c720057b4b0752c82256701ee0ae6ac Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 20 Oct 2018 23:36:06 +0100 Subject: [PATCH 17/31] zangle should be shifted down by ANGLETOFINESHIFT if we're to use FINETANGENT on it --- src/lua_maplib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index e769a00d..7635ded1 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1344,7 +1344,7 @@ static int slope_set(lua_State *L) } case slope_zangle: // zangle slope->zangle = luaL_checkangle(L, 3); - slope->zdelta = FINETANGENT(slope->zangle); + slope->zdelta = FINETANGENT(slope->zangle>>ANGLETOFINESHIFT); P_CalculateSlopeNormal(slope); break; case slope_xydirection: // xydirection From 2ec4f2024f784af6bc5562cbd0e5f62d5d722d1a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 21 Oct 2018 15:00:07 +0100 Subject: [PATCH 18/31] Added support for pslope_t userdata variables in Lua archive/unarchive code --- src/lua_script.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/lua_script.c b/src/lua_script.c index ddfbf5c7..0440efd5 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -22,6 +22,9 @@ #include "byteptr.h" #include "p_saveg.h" #include "p_local.h" +#ifdef ESLOPE +#include "p_slopes.h" // for P_SlopeById +#endif #ifdef LUA_ALLOW_BYTECODE #include "d_netfil.h" // for LUA_DumpFile #endif @@ -457,6 +460,9 @@ enum ARCH_SIDE, ARCH_SUBSECTOR, ARCH_SECTOR, +#ifdef ESLOPE + ARCH_SLOPE, +#endif ARCH_MAPHEADER, ARCH_TEND=0xFF, @@ -476,6 +482,9 @@ static const struct { {META_SIDE, ARCH_SIDE}, {META_SUBSECTOR,ARCH_SUBSECTOR}, {META_SECTOR, ARCH_SECTOR}, +#ifdef ESLOPE + {META_SLOPE, ARCH_SLOPE}, +#endif {META_MAPHEADER, ARCH_MAPHEADER}, {NULL, ARCH_NULL} }; @@ -680,6 +689,19 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) } break; } +#ifdef ESLOPE + case ARCH_SLOPE: + { + pslope_t *slope = *((pslope_t **)lua_touserdata(gL, myindex)); + if (!slope) + WRITEUINT8(save_p, ARCH_NULL); + else { + WRITEUINT8(save_p, ARCH_SLOPE); + WRITEUINT16(save_p, slope->id); + } + break; + } +#endif case ARCH_MAPHEADER: { mapheader_t *header = *((mapheader_t **)lua_touserdata(gL, myindex)); @@ -884,6 +906,11 @@ static UINT8 UnArchiveValue(int TABLESINDEX) case ARCH_SECTOR: LUA_PushUserdata(gL, §ors[READUINT16(save_p)], META_SECTOR); break; +#ifdef ESLOPE + case ARCH_SLOPE: + LUA_PushUserdata(gL, P_SlopeById(READUINT16(save_p)), META_SLOPE); + break; +#endif case ARCH_MAPHEADER: LUA_PushUserdata(gL, §ors[READUINT16(save_p)], META_MAPHEADER); break; From efff869e6e1e15b616f425ba84ce4d339e7052e3 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 21 Oct 2018 15:12:51 +0100 Subject: [PATCH 19/31] Add mobj.standingslope to Lua --- src/lua_mobjlib.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 6bb1388f..05091f12 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -80,7 +80,12 @@ enum mobj_e { mobj_extravalue1, mobj_extravalue2, mobj_cusval, +#ifdef ESLOPE + mobj_cvmem, + mobj_standingslope +#else mobj_cvmem +#endif }; static const char *const mobj_opt[] = { @@ -140,6 +145,9 @@ static const char *const mobj_opt[] = { "extravalue2", "cusval", "cvmem", +#ifdef ESLOPE + "standingslope", +#endif NULL}; #define UNIMPLEMENTED luaL_error(L, LUA_QL("mobj_t") " field " LUA_QS " is not implemented for Lua and cannot be accessed.", mobj_opt[field]) @@ -343,6 +351,11 @@ static int mobj_get(lua_State *L) case mobj_cvmem: lua_pushinteger(L, mo->cvmem); break; +#ifdef ESLOPE + case mobj_standingslope: + LUA_PushUserdata(L, mo->standingslope, META_SLOPE); + break; +#endif default: // extra custom variables in Lua memory lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS); I_Assert(lua_istable(L, -1)); @@ -634,6 +647,10 @@ static int mobj_set(lua_State *L) case mobj_cvmem: mo->cvmem = luaL_checkinteger(L, 3); break; +#ifdef ESLOPE + case mobj_standingslope: + return NOSET; +#endif default: lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS); I_Assert(lua_istable(L, -1)); From e15ed742c124f556ebebd4983e9f09136fa7cca3 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 21 Oct 2018 16:27:54 +0100 Subject: [PATCH 20/31] add ESLOPE ifdef checks around all the Lua slope support code that was there before I was involved --- src/dehacked.c | 2 ++ src/lua_libs.h | 2 ++ src/lua_maplib.c | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/dehacked.c b/src/dehacked.c index 251b0532..d470c7fa 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -7261,11 +7261,13 @@ struct { {"FF_COLORMAPONLY",FF_COLORMAPONLY}, ///< Only copy the colormap, not the lightlevel {"FF_GOOWATER",FF_GOOWATER}, ///< Used with ::FF_SWIMMABLE. Makes thick bouncey goop. +#ifdef ESLOPE // Slope flags {"SL_NOPHYSICS",SL_NOPHYSICS}, // Don't do momentum adjustment with this slope {"SL_NODYNAMIC",SL_NODYNAMIC}, // Slope will never need to move during the level, so don't fuss with recalculating it {"SL_ANCHORVERTEX",SL_ANCHORVERTEX},// Slope is using a Slope Vertex Thing to anchor its position {"SL_VERTEXSLOPE",SL_VERTEXSLOPE}, // Slope is built from three Slope Vertex Things +#endif // Angles {"ANG1",ANG1}, diff --git a/src/lua_libs.h b/src/lua_libs.h index a9c82bce..15d988ef 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -38,9 +38,11 @@ extern lua_State *gL; #define META_SUBSECTOR "SUBSECTOR_T*" #define META_SECTOR "SECTOR_T*" #define META_FFLOOR "FFLOOR_T*" +#ifdef ESLOPE #define META_SLOPE "PSLOPE_T*" #define META_VECTOR2 "VECTOR2_T" #define META_VECTOR3 "VECTOR3_T" +#endif #define META_MAPHEADER "MAPHEADER_T*" #define META_CVAR "CONSVAR_T*" diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 7635ded1..d8363429 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -40,10 +40,14 @@ enum sector_e { sector_heightsec, sector_camsec, sector_lines, +#ifdef ESLOPE sector_ffloors, sector_fslope, sector_cslope, sector_hasslope +#else + sector_ffloors +#endif }; static const char *const sector_opt[] = { @@ -60,9 +64,11 @@ static const char *const sector_opt[] = { "camsec", "lines", "ffloors", +#ifdef ESLOPE "f_slope", "c_slope", "hasslope", +#endif NULL}; enum subsector_e { @@ -168,8 +174,10 @@ enum ffloor_e { ffloor_toplightlevel, ffloor_bottomheight, ffloor_bottompic, +#ifdef ESLOPE ffloor_tslope, ffloor_bslope, +#endif ffloor_sector, ffloor_flags, ffloor_master, @@ -186,8 +194,10 @@ static const char *const ffloor_opt[] = { "toplightlevel", "bottomheight", "bottompic", +#ifdef ESLOPE "t_slope", "b_slope", +#endif "sector", // secnum pushed as control sector userdata "flags", "master", // control linedef @@ -197,6 +207,7 @@ static const char *const ffloor_opt[] = { "alpha", NULL}; +#ifdef ESLOPE enum slope_e { slope_valid = 0, slope_o, @@ -235,6 +246,7 @@ static const char *const vector_opt[] = { "y", "z", NULL}; +#endif static const char *const array_opt[] ={"iterate",NULL}; static const char *const valid_opt[] ={"valid",NULL}; @@ -450,6 +462,7 @@ static int sector_get(lua_State *L) LUA_PushUserdata(L, sector->ffloors, META_FFLOOR); lua_pushcclosure(L, sector_iterate, 2); // push lib_iterateFFloors and sector->ffloors as upvalues for the function return 1; +#ifdef ESLOPE case sector_fslope: // f_slope LUA_PushUserdata(L, sector->f_slope, META_SLOPE); return 1; @@ -459,6 +472,7 @@ static int sector_get(lua_State *L) case sector_hasslope: // hasslope lua_pushboolean(L, sector->hasslope); return 1; +#endif } return 0; } @@ -481,9 +495,11 @@ static int sector_set(lua_State *L) case sector_heightsec: // heightsec case sector_camsec: // camsec case sector_ffloors: // ffloors +#ifdef ESLOPE case sector_fslope: // f_slope case sector_cslope: // c_slope case sector_hasslope: // hasslope +#endif default: return luaL_error(L, "sector_t field " LUA_QS " cannot be set.", sector_opt[field]); case sector_floorheight: { // floorheight @@ -1118,12 +1134,14 @@ static int ffloor_get(lua_State *L) lua_pushlstring(L, levelflat->name, 8); return 1; } +#ifdef ESLOPE case ffloor_tslope: LUA_PushUserdata(L, *ffloor->t_slope, META_SLOPE); return 1; case ffloor_bslope: LUA_PushUserdata(L, *ffloor->b_slope, META_SLOPE); return 1; +#endif case ffloor_sector: LUA_PushUserdata(L, §ors[ffloor->secnum], META_SECTOR); return 1; @@ -1163,8 +1181,10 @@ static int ffloor_set(lua_State *L) switch(field) { case ffloor_valid: // valid +#ifdef ESLOPE case ffloor_tslope: // t_slope case ffloor_bslope: // b_slope +#endif case ffloor_sector: // sector case ffloor_master: // master case ffloor_target: // target @@ -1225,6 +1245,7 @@ static int ffloor_set(lua_State *L) return 0; } +#ifdef ESLOPE static int slope_get(lua_State *L) { pslope_t *slope = *((pslope_t **)luaL_checkudata(L, 1, META_SLOPE)); @@ -1391,6 +1412,7 @@ static int vector3_get(lua_State *L) return 0; } +#endif static int lib_getMapheaderinfo(lua_State *L) { @@ -1568,6 +1590,7 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__newindex"); lua_pop(L, 1); +#ifdef ESLOPE luaL_newmetatable(L, META_SLOPE); lua_pushcfunction(L, slope_get); lua_setfield(L, -2, "__index"); @@ -1585,6 +1608,7 @@ int LUA_MapLib(lua_State *L) lua_pushcfunction(L, vector3_get); lua_setfield(L, -2, "__index"); lua_pop(L, 1); +#endif luaL_newmetatable(L, META_MAPHEADER); lua_pushcfunction(L, mapheaderinfo_get); From 3ec8743c1bbdec71ecaa7d4d4cd41a3f00f1516c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 21 Oct 2018 17:32:53 +0100 Subject: [PATCH 21/31] Fix up the ability to edit slope zdelta and zangle with Lua (zangle is untested as of writing) --- src/lua_maplib.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index d8363429..975ea1cb 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1359,15 +1359,19 @@ static int slope_set(lua_State *L) } case slope_zdelta: { // zdelta, this is temp until i figure out wtf to do slope->zdelta = luaL_checkfixed(L, 3); - slope->zangle = R_PointToAngle2(0, 0, FRACUNIT, slope->zdelta); + slope->zangle = R_PointToAngle2(0, 0, FRACUNIT, -slope->zdelta); P_CalculateSlopeNormal(slope); break; } - case slope_zangle: // zangle - slope->zangle = luaL_checkangle(L, 3); - slope->zdelta = FINETANGENT(slope->zangle>>ANGLETOFINESHIFT); + case slope_zangle: { // zangle + angle_t zangle = luaL_checkangle(L, 3); + if (zangle == ANGLE_90 || zangle == ANGLE_270) + return luaL_error(L, "invalid zangle for slope!"); + slope->zangle = zangle; + slope->zdelta = -FINETANGENT(((slope->zangle+ANGLE_90)>>ANGLETOFINESHIFT) & 4095); P_CalculateSlopeNormal(slope); break; + } case slope_xydirection: // xydirection slope->xydirection = luaL_checkangle(L, 3); P_CalculateSlopeNormal(slope); From 772004d3fd8032f6397b43221227af488e82cfd4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 21 Oct 2018 18:25:13 +0100 Subject: [PATCH 22/31] Fix editing slope xydirection with Lua --- src/lua_maplib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 975ea1cb..2ccb3b5f 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1374,6 +1374,8 @@ static int slope_set(lua_State *L) } case slope_xydirection: // xydirection slope->xydirection = luaL_checkangle(L, 3); + slope->d.x = -FINECOSINE((slope->xydirection>>ANGLETOFINESHIFT) & FINEMASK); + slope->d.y = -FINESINE((slope->xydirection>>ANGLETOFINESHIFT) & FINEMASK); P_CalculateSlopeNormal(slope); break; } From e95b54e64f2cbb13b79ac46b13b8e104f17f5517 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 21 Oct 2018 20:35:14 +0100 Subject: [PATCH 23/31] missed this ESLOPE-needed area from a few commits ago apparently :V --- src/lua_maplib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 2ccb3b5f..b59c3c17 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -16,7 +16,9 @@ #include "p_local.h" #include "p_setup.h" #include "z_zone.h" +#ifdef ESLOPE #include "p_slopes.h" +#endif #include "r_main.h" #include "lua_script.h" From ab38e6cebb7765e1fe0ce846e2a30deab285e7d2 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 13 Oct 2018 20:44:01 +0100 Subject: [PATCH 24/31] Creating a quick get_WSAErrorStr function to act as a wrapper for FormatMessageA so we can string-ify Winsock errors properly Untested! --- src/i_tcp.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/i_tcp.c b/src/i_tcp.c index 6488e984..9febd56f 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -262,6 +262,28 @@ static void wattcp_outch(char s) } #endif +#ifdef USE_WINSOCK +// stupid microsoft makes things complicated +static inline char *get_WSAErrorStr(int e) +{ + char *buf = NULL; + + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + (DWORD)e, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&buf, + 0, NULL); + + return buf; +} +#undef strerror +#define strerror get_WSAErrorStr +#endif + #ifdef USE_WINSOCK2 #define inet_ntop inet_ntopA #define HAVE_NTOP From 3b39a25adec80437e56f8a6d886d220786a889f6 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Oct 2018 15:49:04 +0100 Subject: [PATCH 25/31] Save the result of errno (aka WSAGetLastError() for WinSock) as soon as possible, to prevent anything in SOCK_GetNodeAddress resetting the value to 0 while trying to print the message for the error itself! --- src/i_tcp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 9febd56f..6a212786 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -781,9 +781,13 @@ static void SOCK_Send(void) &clientaddress[doomcom->remotenode].any, d); } - if (c == ERRSOCKET && errno != ECONNREFUSED && errno != EWOULDBLOCK) - I_Error("SOCK_Send, error sending to node %d (%s) #%u: %s", doomcom->remotenode, - SOCK_GetNodeAddress(doomcom->remotenode), errno, strerror(errno)); + if (c == ERRSOCKET) + { + int e = errno; // save error code so it can't be modified later + if (e != ECONNREFUSED && e != EWOULDBLOCK) + I_Error("SOCK_Send, error sending to node %d (%s) #%u: %s", doomcom->remotenode, + SOCK_GetNodeAddress(doomcom->remotenode), e, strerror(e)); + } } #endif From e4e76f83c3e6c4de8ac467667df7daf05d2d9582 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Oct 2018 16:09:14 +0100 Subject: [PATCH 26/31] Use temporary buffer with a max size of 255 bytes instead of having Microsoft's FormatMessageA alloc one for us. Also, provide a fallback message in case no message was available for some reason --- src/i_tcp.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 6a212786..c054b3a4 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -266,17 +266,22 @@ static void wattcp_outch(char s) // stupid microsoft makes things complicated static inline char *get_WSAErrorStr(int e) { - char *buf = NULL; + char buf[256]; // allow up to 255 bytes + + buf[0] = '\0'; FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)e, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&buf, - 0, NULL); + (LPTSTR)buf, + sizeof (buf), + NULL); + + if (!buf[0]) // provide a fallback error message if no message is available for some reason + sprintf(buf, "Unknown error"); return buf; } From bb3d850bbfaf9fe9c333e1c0c4a79706ec878c8c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Oct 2018 16:27:00 +0100 Subject: [PATCH 27/31] static the buffer, forgot to do this earlier --- src/i_tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index c054b3a4..43dba4aa 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -266,7 +266,7 @@ static void wattcp_outch(char s) // stupid microsoft makes things complicated static inline char *get_WSAErrorStr(int e) { - char buf[256]; // allow up to 255 bytes + static char buf[256]; // allow up to 255 bytes buf[0] = '\0'; From 9fb301ecb587ed933f300cc9b65f23f8072e9d57 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Oct 2018 16:47:56 +0100 Subject: [PATCH 28/31] don't bother with inlining the function, on second thoughts --- src/i_tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 43dba4aa..0728c7aa 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -264,7 +264,7 @@ static void wattcp_outch(char s) #ifdef USE_WINSOCK // stupid microsoft makes things complicated -static inline char *get_WSAErrorStr(int e) +static char *get_WSAErrorStr(int e) { static char buf[256]; // allow up to 255 bytes From a3bc7ddfa0bca4d52b8de2a7151095ecc6968e04 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Tue, 6 Nov 2018 18:09:45 -0600 Subject: [PATCH 29/31] Add Lua Ultimate Mode global variable so people can use it. --- src/dehacked.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dehacked.c b/src/dehacked.c index 97e1965e..212715dd 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8217,6 +8217,9 @@ static inline int lib_getenum(lua_State *L) } else if (fastcmp(word,"maptol")) { lua_pushinteger(L, maptol); return 1; + } else if (fastcmp(word,"ultimatemode")) { + lua_pushboolean(L, ultimatemode != 0); + return 1; } else if (fastcmp(word,"mariomode")) { lua_pushboolean(L, mariomode != 0); return 1; From 82c738ea4b7ee4b1c03de261d26387107da9dd3c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 8 Nov 2018 21:13:58 +0000 Subject: [PATCH 30/31] Remove hasslope, per colette's warning about it potentially causing desyncs --- src/lua_maplib.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index b59c3c17..37dae5fa 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -46,7 +46,6 @@ enum sector_e { sector_ffloors, sector_fslope, sector_cslope, - sector_hasslope #else sector_ffloors #endif @@ -69,7 +68,6 @@ static const char *const sector_opt[] = { #ifdef ESLOPE "f_slope", "c_slope", - "hasslope", #endif NULL}; @@ -471,9 +469,6 @@ static int sector_get(lua_State *L) case sector_cslope: // c_slope LUA_PushUserdata(L, sector->c_slope, META_SLOPE); return 1; - case sector_hasslope: // hasslope - lua_pushboolean(L, sector->hasslope); - return 1; #endif } return 0; @@ -500,7 +495,6 @@ static int sector_set(lua_State *L) #ifdef ESLOPE case sector_fslope: // f_slope case sector_cslope: // c_slope - case sector_hasslope: // hasslope #endif default: return luaL_error(L, "sector_t field " LUA_QS " cannot be set.", sector_opt[field]); From 98fd9f8e426e40cc70d6248bf7c5a42bf13f25f1 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 8 Nov 2018 21:22:45 +0000 Subject: [PATCH 31/31] WHY DID I FORGET THIS --- src/lua_maplib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 37dae5fa..1886d7d1 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -45,7 +45,7 @@ enum sector_e { #ifdef ESLOPE sector_ffloors, sector_fslope, - sector_cslope, + sector_cslope #else sector_ffloors #endif