From 68c46cdca31826510ffce982d953b36ce657f73f Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Nov 2018 17:53:49 -0500 Subject: [PATCH 01/11] toptexture, bottomtexture, and midtexture use strings instead of magic numbers --- src/lua_maplib.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 8deb5abf..a550bc8f 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -645,6 +645,7 @@ static int side_get(lua_State *L) { side_t *side = *((side_t **)luaL_checkudata(L, 1, META_SIDE)); enum side_e field = luaL_checkoption(L, 2, side_opt[0], side_opt); + UINT8 i; if (!side) { @@ -667,14 +668,32 @@ static int side_get(lua_State *L) lua_pushfixed(L, side->rowoffset); return 1; case side_toptexture: - lua_pushinteger(L, side->toptexture); + { + texture_t *texture = textures[side->toptexture]; + for (i = 0; i < 8; i++) + if (!texture->name[i]) + break; + lua_pushlstring(L, texture->name, i); return 1; + } case side_bottomtexture: - lua_pushinteger(L, side->bottomtexture); + { + texture_t *texture = textures[side->bottomtexture]; + for (i = 0; i < 8; i++) + if (!texture->name[i]) + break; + lua_pushlstring(L, texture->name, i); return 1; + } case side_midtexture: - lua_pushinteger(L, side->midtexture); + { + texture_t *texture = textures[side->midtexture]; + for (i = 0; i < 8; i++) + if (!texture->name[i]) + break; + lua_pushlstring(L, texture->name, i); return 1; + } case side_sector: LUA_PushUserdata(L, side->sector, META_SECTOR); return 1; @@ -720,13 +739,16 @@ static int side_set(lua_State *L) side->rowoffset = luaL_checkfixed(L, 3); break; case side_toptexture: - side->toptexture = luaL_checkinteger(L, 3); + if (R_CheckTextureNumForName(luaL_checkstring(L, 3)) != -1) + side->toptexture = R_TextureNumForName(luaL_checkstring(L, 3)); break; case side_bottomtexture: - side->bottomtexture = luaL_checkinteger(L, 3); + if (R_CheckTextureNumForName(luaL_checkstring(L, 3)) != -1) + side->bottomtexture = R_TextureNumForName(luaL_checkstring(L, 3)); break; case side_midtexture: - side->midtexture = luaL_checkinteger(L, 3); + if (R_CheckTextureNumForName(luaL_checkstring(L, 3)) != -1) + side->midtexture = R_TextureNumForName(luaL_checkstring(L, 3)); break; case side_repeatcnt: side->repeatcnt = luaL_checkinteger(L, 3); From 868118d0cd33ac14b8d4008e9404a92067983bcc Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Nov 2018 18:07:34 -0500 Subject: [PATCH 02/11] IsPlayerAdmin support, since admin was removed --- src/dehacked.c | 10 +++++----- src/lua_baselib.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index b2e6e22c..08b65c71 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9698,11 +9698,11 @@ static inline int lib_getenum(lua_State *L) return 0; LUA_PushUserdata(L, &players[serverplayer], META_PLAYER); return 1; - } else if (fastcmp(word,"admin")) { - //if (!playeringame[adminplayer] || IsPlayerAdmin(serverplayer)) - //return 0; - //LUA_PushUserdata(L, &players[adminplayer], META_PLAYER); - return 1; + /*} else if (fastcmp(word,"admin")) { // Replaced with IsPlayerAdmin + if (!playeringame[adminplayer] || IsPlayerAdmin(serverplayer)) + return 0; + LUA_PushUserdata(L, &players[adminplayer], META_PLAYER); + return 1;*/ } else if (fastcmp(word,"emeralds")) { lua_pushinteger(L, emeralds); return 1; diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 05facf18..2238e0d4 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -22,7 +22,8 @@ #include "g_game.h" #include "hu_stuff.h" #include "console.h" -#include "k_kart.h" +#include "k_kart.h" // SRB2Kart +#include "d_netcmd.h" // IsPlayerAdmin #include "lua_script.h" #include "lua_libs.h" @@ -142,6 +143,16 @@ static int lib_evalMath(lua_State *L) return 1; } +static int lib_isPlayerAdmin(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + //HUDSAFE + if (!player) + return LUA_ErrInvalid(L, "player_t"); + lua_pushboolean(L, IsPlayerAdmin(player-players)); + return 1; +} + // M_RANDOM ////////////// @@ -2336,6 +2347,7 @@ static luaL_Reg lib[] = { {"chatprint", lib_chatprint}, {"chatprintf", lib_chatprintf}, {"EvalMath", lib_evalMath}, + {"IsPlayerAdmin", lib_isPlayerAdmin}, // m_random {"P_RandomFixed",lib_pRandomFixed}, From 7ad0347ab0df0533faefd0989f01ea6ac3e162b3 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Nov 2018 18:23:28 -0500 Subject: [PATCH 03/11] Add missing K_ functions --- src/k_kart.c | 2 +- src/k_kart.h | 1 - src/lua_baselib.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 39ef34c0..29506a2c 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -6783,7 +6783,7 @@ static void K_drawKartBumpersOrKarma(void) } } -fixed_t K_FindCheckX(fixed_t px, fixed_t py, angle_t ang, fixed_t mx, fixed_t my) +static fixed_t K_FindCheckX(fixed_t px, fixed_t py, angle_t ang, fixed_t mx, fixed_t my) { fixed_t dist, x; fixed_t range = RING_DIST/3; diff --git a/src/k_kart.h b/src/k_kart.h index 67229330..9eaa4186 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -64,7 +64,6 @@ void K_CheckSpectateStatus(void); const char *K_GetItemPatch(UINT8 item, boolean tiny); INT32 K_calcSplitFlags(INT32 snapflags); void K_LoadKartHUDGraphics(void); -fixed_t K_FindCheckX(fixed_t px, fixed_t py, angle_t ang, fixed_t mx, fixed_t my); void K_drawKartHUD(void); void K_drawKartFreePlay(UINT32 flashtime); void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, boolean playing); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 2238e0d4..bbfc2ae6 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2211,6 +2211,17 @@ static int lib_kSpawnKartExplosion(lua_State *L) return 0; } +static int lib_kSpawnMineExplosion(lua_State *L) +{ + mobj_t *source = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + UINT8 color = (UINT8)luaL_checkinteger(L, 2); + NOHUD + if (!source) + return LUA_ErrInvalid(L, "mobj_t"); + K_SpawnMineExplosion(source, color); + return 0; +} + static int lib_kSpawnBoostTrail(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); @@ -2301,6 +2312,59 @@ static int lib_kRepairOrbitChain(lua_State *L) return 0; } +static int lib_kFindJawzTarget(lua_State *L) +{ + mobj_t *actor = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + player_t *source = *((player_t **)luaL_checkudata(L, 2, META_PLAYER)); + NOHUD + if (!actor) + return LUA_ErrInvalid(L, "mobj_t"); + if (!source) + return LUA_ErrInvalid(L, "player_t"); + LUA_PushUserdata(L, K_FindJawzTarget(actor, source), META_PLAYER); + return 0; +} + +static int lib_kGetKartDriftSparkValue(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + NOHUD + if (!player) + return LUA_ErrInvalid(L, "player_t"); + lua_pushfixed(L, K_GetKartDriftSparkValue(player)); + return 0; +} + +static int lib_kDropItems(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + NOHUD + if (!player) + return LUA_ErrInvalid(L, "player_t"); + K_DropItems(player); + return 0; +} + +static int lib_kStripItems(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + NOHUD + if (!player) + return LUA_ErrInvalid(L, "player_t"); + K_StripItems(player); + return 0; +} + +static int lib_kStripOther(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + NOHUD + if (!player) + return LUA_ErrInvalid(L, "player_t"); + K_StripOther(player); + return 0; +} + static int lib_kMomentumToFacing(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); @@ -2342,6 +2406,15 @@ static int lib_kGetKartFlashing(lua_State *L) return 0; } +static int lib_kGetItemPatch(lua_State *L) +{ + UINT8 item = luaL_checkinteger(L, 1); + boolean tiny = luaL_checkboolean(L, 2); + //HUDSAFE + lua_pushstring(L, K_GetItemPatch(item, tiny)); + return 1; +} + static luaL_Reg lib[] = { {"print", lib_print}, {"chatprint", lib_chatprint}, @@ -2532,6 +2605,7 @@ static luaL_Reg lib[] = { {"K_ExplodePlayer",lib_kExplodePlayer}, {"K_StealBumper",lib_kStealBumper}, {"K_SpawnKartExplosion",lib_kSpawnKartExplosion}, + {"K_SpawnMineExplosion",lib_kSpawnMineExplosion}, {"K_SpawnBoostTrail",lib_kSpawnBoostTrail}, {"K_SpawnSparkleTrail",lib_kSpawnSparkleTrail}, {"K_SpawnWipeoutTrail",lib_kSpawnWipeoutTrail}, @@ -2540,10 +2614,16 @@ static luaL_Reg lib[] = { {"K_DoPogoSpring",lib_kDoPogoSpring}, {"K_KillBananaChain",lib_kKillBananaChain}, {"K_RepairOrbitChain",lib_kRepairOrbitChain}, + {"K_FindJawzTarget",lib_kFindJawzTarget}, + {"K_GetKartDriftSparkValue",lib_kGetKartDriftSparkValue}, + {"K_DropItems",lib_kDropItems}, + {"K_StripItems",lib_kStripItems}, + {"K_StripOther",lib_kStripOther}, {"K_MomentumToFacing",lib_kMomentumToFacing}, {"K_GetKartSpeed",lib_kGetKartSpeed}, {"K_GetKartAccel",lib_kGetKartAccel}, {"K_GetKartFlashing",lib_kGetKartFlashing}, + {"K_GetItemPatch",lib_kK_GetItemPatch}, {NULL, NULL} }; From b9161871a12366a00dd0508805ea79261a35f16e Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Nov 2018 18:24:44 -0500 Subject: [PATCH 04/11] typo --- src/lua_baselib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index bbfc2ae6..f3b21a85 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2623,7 +2623,7 @@ static luaL_Reg lib[] = { {"K_GetKartSpeed",lib_kGetKartSpeed}, {"K_GetKartAccel",lib_kGetKartAccel}, {"K_GetKartFlashing",lib_kGetKartFlashing}, - {"K_GetItemPatch",lib_kK_GetItemPatch}, + {"K_GetItemPatch",lib_kGetItemPatch}, {NULL, NULL} }; From 95a163743705930d04be8c894537cb1f030755a3 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Nov 2018 18:31:07 -0500 Subject: [PATCH 05/11] Add Kart globals --- src/dehacked.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/dehacked.c b/src/dehacked.c index 08b65c71..057b9cea 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9715,6 +9715,27 @@ static inline int lib_getenum(lua_State *L) } else if (fastcmp(word, "token")) { lua_pushinteger(L, token); return 1; + } else if (fastcmp(word,"gamespeed")) { + lua_pushinteger(L, gamespeed); + return 1; + } else if (fastcmp(word,"encoremode")) { + lua_pushboolean(L, encoremode); + return 1; + } else if (fastcmp(word,"franticitems")) { + lua_pushboolean(L, franticitems); + return 1; + } else if (fastcmp(word,"comeback")) { + lua_pushboolean(L, comeback); + return 1; + } else if (fastcmp(word,"wantedcalcdelay")) { + lua_pushboolean(L, wantedcalcdelay); + return 1; + } else if (fastcmp(word,"indirectitemcooldown")) { + lua_pushboolean(L, indirectitemcooldown); + return 1; + } else if (fastcmp(word,"thwompsactive")) { + lua_pushboolean(L, thwompsactive); + return 1; } return 0; From 2b9b1e3bff351d43a0990295a90af36d703c882e Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Nov 2018 18:37:06 -0500 Subject: [PATCH 06/11] These are integers, whoops --- src/dehacked.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 057b9cea..500dfea8 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9728,10 +9728,10 @@ static inline int lib_getenum(lua_State *L) lua_pushboolean(L, comeback); return 1; } else if (fastcmp(word,"wantedcalcdelay")) { - lua_pushboolean(L, wantedcalcdelay); + lua_pushinteger(L, wantedcalcdelay); return 1; } else if (fastcmp(word,"indirectitemcooldown")) { - lua_pushboolean(L, indirectitemcooldown); + lua_pushinteger(L, indirectitemcooldown); return 1; } else if (fastcmp(word,"thwompsactive")) { lua_pushboolean(L, thwompsactive); From bc7e865e6b7b34be6834a0ebe07266fde834c429 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Nov 2018 21:04:57 -0500 Subject: [PATCH 07/11] Serious deep-cleaning to most of the kartstuff More optional fields, more careful eye placed on return values and other checks --- src/dehacked.c | 29 ++++++++++++ src/k_kart.c | 17 +++---- src/k_kart.h | 2 +- src/lua_baselib.c | 110 +++++++++++++++++++++++----------------------- 4 files changed, 94 insertions(+), 64 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 500dfea8..77dfbf7d 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8788,6 +8788,35 @@ struct { {"V_CHARCOLORSHIFT",V_CHARCOLORSHIFT}, {"V_ALPHASHIFT",V_ALPHASHIFT}, + + // SRB2Kart + // kartitems_t + {"KITEM_SAD",KITEM_SAD}, // Actual items (can be set for k_itemtype) + {"KITEM_NONE",KITEM_NONE}, + {"KITEM_SNEAKER",KITEM_SNEAKER}, + {"KITEM_ROCKETSNEAKER",KITEM_ROCKETSNEAKER}, + {"KITEM_INVINCIBILITY",KITEM_INVINCIBILITY}, + {"KITEM_BANANA",KITEM_BANANA}, + {"KITEM_EGGMAN",KITEM_EGGMAN}, + {"KITEM_ORBINAUT",KITEM_ORBINAUT}, + {"KITEM_JAWZ",KITEM_JAWZ}, + {"KITEM_MINE",KITEM_MINE}, + {"KITEM_BALLHOG",KITEM_BALLHOG}, + {"KITEM_SPB",KITEM_SPB}, + {"KITEM_GROW",KITEM_GROW}, + {"KITEM_SHRINK",KITEM_SHRINK}, + {"KITEM_THUNDERSHIELD",KITEM_THUNDERSHIELD}, + {"KITEM_HYUDORO",KITEM_HYUDORO}, + {"KITEM_POGOSPRING",KITEM_POGOSPRING}, + {"KITEM_KITCHENSINK",KITEM_KITCHENSINK}, + {"NUMKARTITEMS",NUMKARTITEMS}, + {"KRITEM_TRIPLESNEAKER",KRITEM_TRIPLESNEAKER}, // Additional roulette IDs (not usable for much in Lua besides K_GetItemPatch) + {"KRITEM_TRIPLEBANANA",KRITEM_TRIPLEBANANA}, + {"KRITEM_TENFOLDBANANA",KRITEM_TENFOLDBANANA}, + {"KRITEM_TRIPLEORBINAUT",KRITEM_TRIPLEORBINAUT}, + {"KRITEM_QUADORBINAUT",KRITEM_QUADORBINAUT}, + {"KRITEM_DUALJAWZ",KRITEM_DUALJAWZ}, + {"NUMKARTRESULTS",NUMKARTRESULTS}, #endif {NULL,0} diff --git a/src/k_kart.c b/src/k_kart.c index 29506a2c..822a3bc1 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -2256,7 +2256,8 @@ void K_SpawnKartExplosion(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 mobj->momy = FixedMul(FixedDiv(mobjy - y, dist), FixedDiv(dist, 6*FRACUNIT)); mobj->momz = FixedMul(FixedDiv(mobjz - z, dist), FixedDiv(dist, 6*FRACUNIT)); - P_SetTarget(&mobj->target, source); + if (source && !P_MobjWasRemoved(source)) + P_SetTarget(&mobj->target, source); } } @@ -4373,7 +4374,7 @@ INT16 K_GetKartTurnValue(player_t *player, INT16 turnvalue) return turnvalue; } -fixed_t K_GetKartDriftSparkValue(player_t *player) +INT32 K_GetKartDriftSparkValue(player_t *player) { UINT8 kartspeed = (G_BattleGametype() && player->kartstuff[k_bumper] <= 0) ? 1 @@ -4383,9 +4384,9 @@ fixed_t K_GetKartDriftSparkValue(player_t *player) static void K_KartDrift(player_t *player, boolean onground) { - fixed_t dsone = K_GetKartDriftSparkValue(player); - fixed_t dstwo = dsone*2; - fixed_t dsthree = dstwo*2; + INT32 dsone = K_GetKartDriftSparkValue(player); + INT32 dstwo = dsone*2; + INT32 dsthree = dstwo*2; // Drifting is actually straffing + automatic turning. // Holding the Jump button will enable drifting. @@ -7368,9 +7369,9 @@ static void K_drawKartFirstPerson(void) if (stplyr->mo) { - fixed_t dsone = K_GetKartDriftSparkValue(stplyr); - fixed_t dstwo = dsone*2; - fixed_t dsthree = dstwo*2; + INT32 dsone = K_GetKartDriftSparkValue(stplyr); + INT32 dstwo = dsone*2; + INT32 dsthree = dstwo*2; #ifndef DONTLIKETOASTERSFPTWEAKS { diff --git a/src/k_kart.h b/src/k_kart.h index 9eaa4186..ed9a63e5 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -47,7 +47,7 @@ void K_RepairOrbitChain(mobj_t *orbit); player_t *K_FindJawzTarget(mobj_t *actor, player_t *source); boolean K_CheckPlayersRespawnColliding(INT32 playernum, fixed_t x, fixed_t y); INT16 K_GetKartTurnValue(player_t *player, INT16 turnvalue); -fixed_t K_GetKartDriftSparkValue(player_t *player); +INT32 K_GetKartDriftSparkValue(player_t *player); void K_DropItems(player_t *player); void K_StripItems(player_t *player); void K_StripOther(player_t *player); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index f3b21a85..0a35559f 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2068,8 +2068,8 @@ static int lib_kIsPlayerLosing(lua_State *L) //HUDSAFE if (!player) return LUA_ErrInvalid(L, "player_t"); - K_IsPlayerLosing(player); - return 0; + lua_pushboolean(L, K_IsPlayerLosing(player)); + return 1; } static int lib_kIsPlayerWanted(lua_State *L) @@ -2078,16 +2078,16 @@ static int lib_kIsPlayerWanted(lua_State *L) //HUDSAFE if (!player) return LUA_ErrInvalid(L, "player_t"); - K_IsPlayerWanted(player); - return 0; + lua_pushboolean(L, K_IsPlayerWanted(player)); + return 1; } static int lib_kKartBouncing(lua_State *L) { mobj_t *mobj1 = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); mobj_t *mobj2 = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); - boolean bounce = luaL_checkboolean(L, 3); - boolean solid = luaL_checkboolean(L, 4); + boolean bounce = lua_optboolean(L, 3); + boolean solid = lua_optboolean(L, 4); NOHUD if (!mobj1) return LUA_ErrInvalid(L, "mobj_t"); @@ -2123,13 +2123,13 @@ static int lib_kDoInstashield(lua_State *L) static int lib_kSpawnBattlePoints(lua_State *L) { player_t *source = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - player_t *victim = *((player_t **)luaL_checkudata(L, 2, META_PLAYER)); + player_t *victim = NULL; UINT8 amount = (UINT8)luaL_checkinteger(L, 3); NOHUD if (!source) return LUA_ErrInvalid(L, "player_t"); - if (!victim) - return LUA_ErrInvalid(L, "player_t"); + if (!lua_isnone(L, 2) && lua_isuserdata(L, 2)) + victim = *((player_t **)luaL_checkudata(L, 2, META_PLAYER)); K_SpawnBattlePoints(source, victim, amount); return 0; } @@ -2137,14 +2137,14 @@ static int lib_kSpawnBattlePoints(lua_State *L) static int lib_kSpinPlayer(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - mobj_t *source = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); - INT32 type = (INT32)luaL_checkinteger(L, 3); - boolean trapitem = luaL_checkboolean(L, 4); + mobj_t *source = NULL; + INT32 type = (INT32)luaL_optinteger(L, 3, 0); + boolean trapitem = lua_optboolean(L, 4); NOHUD if (!player) return LUA_ErrInvalid(L, "player_t"); - if (!source) - return LUA_ErrInvalid(L, "mobj_t"); + if (!lua_isnone(L, 2) && lua_isuserdata(L, 2)) + source = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); K_SpinPlayer(player, source, type, trapitem); return 0; } @@ -2152,12 +2152,12 @@ static int lib_kSpinPlayer(lua_State *L) static int lib_kSquishPlayer(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - mobj_t *source = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); + mobj_t *source = NULL; NOHUD if (!player) return LUA_ErrInvalid(L, "player_t"); - if (!source) - return LUA_ErrInvalid(L, "mobj_t"); + if (!lua_isnone(L, 2) && lua_isuserdata(L, 2)) + source = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); K_SquishPlayer(player, source); return 0; } @@ -2165,15 +2165,15 @@ static int lib_kSquishPlayer(lua_State *L) static int lib_kExplodePlayer(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - mobj_t *source = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); - mobj_t *inflictor = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); + mobj_t *source = NULL; + mobj_t *inflictor = NULL; NOHUD if (!player) return LUA_ErrInvalid(L, "player_t"); - if (!source) - return LUA_ErrInvalid(L, "mobj_t"); - if (!inflictor) - return LUA_ErrInvalid(L, "mobj_t"); + if (!lua_isnone(L, 2) && lua_isuserdata(L, 2)) + source = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); + if (!lua_isnone(L, 3) && lua_isuserdata(L, 3)) + inflictor = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); K_ExplodePlayer(player, source, inflictor); return 0; } @@ -2182,7 +2182,7 @@ static int lib_kStealBumper(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); player_t *victim = *((player_t **)luaL_checkudata(L, 2, META_PLAYER)); - boolean force = luaL_checkboolean(L, 3); + boolean force = lua_optboolean(L, 3); NOHUD if (!player) return LUA_ErrInvalid(L, "player_t"); @@ -2197,16 +2197,16 @@ static int lib_kSpawnKartExplosion(lua_State *L) fixed_t x = luaL_checkfixed(L, 1); fixed_t y = luaL_checkfixed(L, 2); fixed_t z = luaL_checkfixed(L, 3); - fixed_t radius = luaL_checkfixed(L, 4); - INT32 number = (INT32)luaL_checkinteger(L, 5); - mobjtype_t type = luaL_checkinteger(L, 6); - angle_t rotangle = luaL_checkangle(L, 7); - boolean spawncenter = luaL_checkboolean(L, 8); - boolean ghostit = luaL_checkboolean(L, 9); - mobj_t *source = *((mobj_t **)luaL_checkudata(L, 10, META_MOBJ)); + fixed_t radius = (fixed_t)luaL_optinteger(L, 4, 32*FRACUNIT); + INT32 number = (INT32)luaL_optinteger(L, 5, 32); + mobjtype_t type = luaL_optinteger(L, 6, MT_MINEEXPLOSION); + angle_t rotangle = luaL_optinteger(L, 7, 0); + boolean spawncenter = lua_opttrueboolean(L, 8); + boolean ghostit = lua_optboolean(L, 9); + mobj_t *source = NULL; NOHUD - if (!source) - return LUA_ErrInvalid(L, "mobj_t"); + if (!lua_isnone(L, 10) && lua_isuserdata(L, 10)) + source = *((mobj_t **)luaL_checkudata(L, 10, META_MOBJ)); K_SpawnKartExplosion(x, y, z, radius, number, type, rotangle, spawncenter, ghostit, source); return 0; } @@ -2214,7 +2214,7 @@ static int lib_kSpawnKartExplosion(lua_State *L) static int lib_kSpawnMineExplosion(lua_State *L) { mobj_t *source = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); - UINT8 color = (UINT8)luaL_checkinteger(L, 2); + UINT8 color = (UINT8)luaL_optinteger(L, 2, SKINCOLOR_KETCHUP); NOHUD if (!source) return LUA_ErrInvalid(L, "mobj_t"); @@ -2245,7 +2245,7 @@ static int lib_kSpawnSparkleTrail(lua_State *L) static int lib_kSpawnWipeoutTrail(lua_State *L) { mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); - boolean translucent = luaL_checkboolean(L, 2); + boolean translucent = lua_optboolean(L, 2); NOHUD if (!mo) return LUA_ErrInvalid(L, "mobj_t"); @@ -2266,7 +2266,7 @@ static int lib_kDriftDustHandling(lua_State *L) static int lib_kDoSneaker(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - INT32 type = luaL_checkinteger(L, 2); + INT32 type = luaL_optinteger(L, 2, 0); NOHUD if (!player) return LUA_ErrInvalid(L, "player_t"); @@ -2277,8 +2277,8 @@ static int lib_kDoSneaker(lua_State *L) static int lib_kDoPogoSpring(lua_State *L) { mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); - fixed_t vertispeed = luaL_checkfixed(L, 2); - UINT8 sound = luaL_checkinteger(L, 3); + fixed_t vertispeed = (fixed_t)luaL_optinteger(L, 2, 0); + UINT8 sound = (UINT8)luaL_optinteger(L, 3, 1); NOHUD if (!mo) return LUA_ErrInvalid(L, "mobj_t"); @@ -2289,15 +2289,15 @@ static int lib_kDoPogoSpring(lua_State *L) static int lib_kKillBananaChain(lua_State *L) { mobj_t *banana = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); - mobj_t *inflictor = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); - mobj_t *source = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + mobj_t *inflictor = NULL; + mobj_t *source = NULL; NOHUD if (!banana) return LUA_ErrInvalid(L, "mobj_t"); - if (!inflictor) - return LUA_ErrInvalid(L, "mobj_t"); - if (!source) - return LUA_ErrInvalid(L, "mobj_t"); + if (!lua_isnone(L, 2) && lua_isuserdata(L, 2)) + inflictor = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); + if (!lua_isnone(L, 3) && lua_isuserdata(L, 3)) + source = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); K_KillBananaChain(banana, inflictor, source); return 0; } @@ -2322,7 +2322,7 @@ static int lib_kFindJawzTarget(lua_State *L) if (!source) return LUA_ErrInvalid(L, "player_t"); LUA_PushUserdata(L, K_FindJawzTarget(actor, source), META_PLAYER); - return 0; + return 1; } static int lib_kGetKartDriftSparkValue(lua_State *L) @@ -2331,8 +2331,8 @@ static int lib_kGetKartDriftSparkValue(lua_State *L) NOHUD if (!player) return LUA_ErrInvalid(L, "player_t"); - lua_pushfixed(L, K_GetKartDriftSparkValue(player)); - return 0; + lua_pushinteger(L, K_GetKartDriftSparkValue(player)); + return 1; } static int lib_kDropItems(lua_State *L) @@ -2378,12 +2378,12 @@ static int lib_kMomentumToFacing(lua_State *L) static int lib_kGetKartSpeed(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - boolean doboostpower = luaL_checkboolean(L, 2); + boolean doboostpower = lua_optboolean(L, 2); //HUDSAFE if (!player) return LUA_ErrInvalid(L, "player_t"); - lua_pushinteger(L, K_GetKartSpeed(player, doboostpower)); - return 0; + lua_pushfixed(L, K_GetKartSpeed(player, doboostpower)); + return 1; } static int lib_kGetKartAccel(lua_State *L) @@ -2392,8 +2392,8 @@ static int lib_kGetKartAccel(lua_State *L) //HUDSAFE if (!player) return LUA_ErrInvalid(L, "player_t"); - lua_pushinteger(L, K_GetKartAccel(player)); - return 0; + lua_pushfixed(L, K_GetKartAccel(player)); + return 1; } static int lib_kGetKartFlashing(lua_State *L) @@ -2403,13 +2403,13 @@ static int lib_kGetKartFlashing(lua_State *L) if (!player) return LUA_ErrInvalid(L, "player_t"); lua_pushinteger(L, K_GetKartFlashing(player)); - return 0; + return 1; } static int lib_kGetItemPatch(lua_State *L) { - UINT8 item = luaL_checkinteger(L, 1); - boolean tiny = luaL_checkboolean(L, 2); + UINT8 item = (UINT8)luaL_optinteger(L, 1, KITEM_NONE); + boolean tiny = lua_optboolean(L, 2); //HUDSAFE lua_pushstring(L, K_GetItemPatch(item, tiny)); return 1; From aa3ad733afb9da05ea2f237b76d63d1221f46b80 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Nov 2018 22:01:57 -0500 Subject: [PATCH 08/11] Textures' string bits are now optional. I thought about just exposing R_TextureNumForName and leaving it to the user, since that makes it obvious that this is still an integer field, but I also liked being able to just specify a string and be done with it. I'm not picky either way. --- src/lua_baselib.c | 23 +++++++++++++++++++++++ src/lua_maplib.c | 43 +++++++++++++++---------------------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 0a35559f..a536593b 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1719,6 +1719,26 @@ static int lib_rSetPlayerSkin(lua_State *L) return 0; } +// R_DATA +//////////// + +// This also doesn't exist, but we need it for texture find+replace to not be a horrible chore. +static int lib_rGetTextureName(lua_State *L) +{ + INT32 texnum = luaL_checkinteger(L, 1); + texture_t *texture; + UINT8 i; + //HUDSAFE + if (texnum < 0 || texnum >= numtextures) + return luaL_error(L, "texture number %d out of range (0 - %d)", texnum, numtextures-1); + texture = textures[texnum]; + for (i = 0; i < 8; i++) + if (!texture->name[i]) + break; + lua_pushlstring(L, texture->name, i); + return 1; +} + // S_SOUND //////////// @@ -2564,6 +2584,9 @@ static luaL_Reg lib[] = { {"R_Frame2Char",lib_rFrame2Char}, {"R_SetPlayerSkin",lib_rSetPlayerSkin}, + // r_data + {"R_GetTextureName",lib_rGetTextureName}, + // s_sound {"S_StartSound",lib_sStartSound}, {"S_StartSoundAtVolume",lib_sStartSoundAtVolume}, diff --git a/src/lua_maplib.c b/src/lua_maplib.c index a550bc8f..0b60c9c9 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -645,7 +645,6 @@ static int side_get(lua_State *L) { side_t *side = *((side_t **)luaL_checkudata(L, 1, META_SIDE)); enum side_e field = luaL_checkoption(L, 2, side_opt[0], side_opt); - UINT8 i; if (!side) { @@ -668,32 +667,14 @@ static int side_get(lua_State *L) lua_pushfixed(L, side->rowoffset); return 1; case side_toptexture: - { - texture_t *texture = textures[side->toptexture]; - for (i = 0; i < 8; i++) - if (!texture->name[i]) - break; - lua_pushlstring(L, texture->name, i); + lua_pushinteger(L, side->toptexture); return 1; - } case side_bottomtexture: - { - texture_t *texture = textures[side->bottomtexture]; - for (i = 0; i < 8; i++) - if (!texture->name[i]) - break; - lua_pushlstring(L, texture->name, i); + lua_pushinteger(L, side->bottomtexture); return 1; - } case side_midtexture: - { - texture_t *texture = textures[side->midtexture]; - for (i = 0; i < 8; i++) - if (!texture->name[i]) - break; - lua_pushlstring(L, texture->name, i); + lua_pushinteger(L, side->midtexture); return 1; - } case side_sector: LUA_PushUserdata(L, side->sector, META_SECTOR); return 1; @@ -739,16 +720,22 @@ static int side_set(lua_State *L) side->rowoffset = luaL_checkfixed(L, 3); break; case side_toptexture: - if (R_CheckTextureNumForName(luaL_checkstring(L, 3)) != -1) - side->toptexture = R_TextureNumForName(luaL_checkstring(L, 3)); + if (lua_isstring(L, 3)) + side->toptexture = R_TextureNumForName(lua_tostring(L, 3)); + else + side->toptexture = luaL_checkinteger(L, 3); break; case side_bottomtexture: - if (R_CheckTextureNumForName(luaL_checkstring(L, 3)) != -1) - side->bottomtexture = R_TextureNumForName(luaL_checkstring(L, 3)); + if (lua_isstring(L, 3)) + side->bottomtexture = R_TextureNumForName(lua_tostring(L, 3)); + else + side->bottomtexture = luaL_checkinteger(L, 3); break; case side_midtexture: - if (R_CheckTextureNumForName(luaL_checkstring(L, 3)) != -1) - side->midtexture = R_TextureNumForName(luaL_checkstring(L, 3)); + if (lua_isstring(L, 3)) + side->midtexture = R_TextureNumForName(lua_tostring(L, 3)); + else + side->midtexture = luaL_checkinteger(L, 3); break; case side_repeatcnt: side->repeatcnt = luaL_checkinteger(L, 3); From f5a45534fa560f462298045f74a9b59524f2ee62 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Thu, 8 Nov 2018 14:58:31 -0500 Subject: [PATCH 09/11] Make the texture stuff completely integer-based again, but expose R_TextureNumForName Decided that being able to set a string and then have it return an integer when retrieving would ultimately be confusing, so let's just let the user handle the string functions. --- src/lua_baselib.c | 20 +++++++++++++++++++- src/lua_maplib.c | 15 +++------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index a536593b..179cedc7 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1722,7 +1722,23 @@ static int lib_rSetPlayerSkin(lua_State *L) // R_DATA //////////// -// This also doesn't exist, but we need it for texture find+replace to not be a horrible chore. +static int lib_rCheckTextureNumForName(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + //HUDSAFE + lua_pushinteger(L, R_CheckTextureNumForName(name)); + return 1; +} + +static int lib_rTextureNumForName(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + //HUDSAFE + lua_pushinteger(L, R_TextureNumForName(name)); + return 1; +} + +// This doesn't exist, but we need it for texture find+replace to not be a horrible chore. static int lib_rGetTextureName(lua_State *L) { INT32 texnum = luaL_checkinteger(L, 1); @@ -2585,6 +2601,8 @@ static luaL_Reg lib[] = { {"R_SetPlayerSkin",lib_rSetPlayerSkin}, // r_data + {"R_CheckTextureNumForName",lib_rCheckTextureNumForName), + {"R_TextureNumForName",lib_rTextureNumForName), {"R_GetTextureName",lib_rGetTextureName}, // s_sound diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 0b60c9c9..2e342278 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -720,22 +720,13 @@ static int side_set(lua_State *L) side->rowoffset = luaL_checkfixed(L, 3); break; case side_toptexture: - if (lua_isstring(L, 3)) - side->toptexture = R_TextureNumForName(lua_tostring(L, 3)); - else - side->toptexture = luaL_checkinteger(L, 3); + side->toptexture = luaL_checkinteger(L, 3); break; case side_bottomtexture: - if (lua_isstring(L, 3)) - side->bottomtexture = R_TextureNumForName(lua_tostring(L, 3)); - else - side->bottomtexture = luaL_checkinteger(L, 3); + side->bottomtexture = luaL_checkinteger(L, 3); break; case side_midtexture: - if (lua_isstring(L, 3)) - side->midtexture = R_TextureNumForName(lua_tostring(L, 3)); - else - side->midtexture = luaL_checkinteger(L, 3); + side->midtexture = luaL_checkinteger(L, 3); break; case side_repeatcnt: side->repeatcnt = luaL_checkinteger(L, 3); From 03bf72bf9e5c3172f3c20fc933c64ecbaee675ae Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Thu, 8 Nov 2018 15:02:19 -0500 Subject: [PATCH 10/11] This fake Lua function is probably no longer needed, now. --- src/lua_baselib.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 179cedc7..c69194a5 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1738,23 +1738,6 @@ static int lib_rTextureNumForName(lua_State *L) return 1; } -// This doesn't exist, but we need it for texture find+replace to not be a horrible chore. -static int lib_rGetTextureName(lua_State *L) -{ - INT32 texnum = luaL_checkinteger(L, 1); - texture_t *texture; - UINT8 i; - //HUDSAFE - if (texnum < 0 || texnum >= numtextures) - return luaL_error(L, "texture number %d out of range (0 - %d)", texnum, numtextures-1); - texture = textures[texnum]; - for (i = 0; i < 8; i++) - if (!texture->name[i]) - break; - lua_pushlstring(L, texture->name, i); - return 1; -} - // S_SOUND //////////// @@ -2603,7 +2586,6 @@ static luaL_Reg lib[] = { // r_data {"R_CheckTextureNumForName",lib_rCheckTextureNumForName), {"R_TextureNumForName",lib_rTextureNumForName), - {"R_GetTextureName",lib_rGetTextureName}, // s_sound {"S_StartSound",lib_sStartSound}, From df3c6051e870abb6681a9caf985cd63352617075 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Thu, 8 Nov 2018 15:11:22 -0500 Subject: [PATCH 11/11] Make K_FindJawzTarget and K_GetKartDriftSparkValue HUD safe --- src/lua_baselib.c | 4 ++-- src/lua_maplib.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index c69194a5..957ecbbc 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2335,7 +2335,7 @@ static int lib_kFindJawzTarget(lua_State *L) { mobj_t *actor = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); player_t *source = *((player_t **)luaL_checkudata(L, 2, META_PLAYER)); - NOHUD + //HUDSAFE if (!actor) return LUA_ErrInvalid(L, "mobj_t"); if (!source) @@ -2347,7 +2347,7 @@ static int lib_kFindJawzTarget(lua_State *L) static int lib_kGetKartDriftSparkValue(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - NOHUD + //HUDSAFE if (!player) return LUA_ErrInvalid(L, "player_t"); lua_pushinteger(L, K_GetKartDriftSparkValue(player)); diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 2e342278..f78f4731 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -729,7 +729,7 @@ static int side_set(lua_State *L) side->midtexture = luaL_checkinteger(L, 3); break; case side_repeatcnt: - side->repeatcnt = luaL_checkinteger(L, 3); + side->repeatcnt = luaL_checkinteger(L, 3); break; } return 0;