Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • STJr/SRB2
  • Sryder/SRB2
  • wolfy852/SRB2
  • Alpha2244/SRB2
  • Inuyasha/SRB2
  • yoshibot/SRB2
  • TehRealSalt/SRB2
  • PrisimaTF/SRB2
  • Hatninja/SRB2
  • SteelT/SRB2
  • james/SRB2
  • ShaderWraith/SRB2
  • SinnamonLat/SRB2
  • mazmazz_/SRB2
  • filpAM/SRB2
  • chaoloveicemdboy/SRB2
  • Whooa21/SRB2
  • Machturne/SRB2
  • Golden/SRB2
  • Tatsuru/SRB2
  • Snu/SRB2
  • Zwip-Zwap_Zapony/SRB2
  • fickleheart/SRB2
  • alphaRexJames/SRB2
  • JJK/SRB2
  • diskpoppy/SRB2
  • Hannu_Hanhi/SRB2
  • ZipperQR/SRB2
  • kays/SRB2
  • spherallic/SRB2
  • Zippy_Zolton/SRB2
  • namiishere/SRB2
  • Ors/SRB2
  • SMS_Alfredo/SRB2
  • sonic_edge/SRB2
  • lavla/SRB2
  • ashi/SRB2
  • X.organic/SRB2
  • Fafabis/SRB2
  • Meziu/SRB2
  • v-rob/SRB2
  • tertu/SRB2
  • bitten2up/SRB2
  • flarn2006/SRB2
  • Krabs/SRB2
  • clairebun/SRB2
  • Lactozilla/SRB2
  • thehackstack/SRB2
  • Spice/SRB2
  • win8linux/SRB2
  • JohnFrostFox/SRB2
  • talktoneon726/SRB2
  • Wane/SRB2
  • Lamibe/SRB2
  • spectrumuk2/srb-2
  • nerdyminer18/srb-2
  • 256nil/SRB2
  • ARJr/SRB2
  • Alam/SRB2
  • Zenya/srb-2-marathon-demos
  • Acelite/srb-2-archivedmodifications
  • MIDIMan/SRB2
  • Lach/SRB2
  • Frostiikin/bounce-tweaks
  • Jaden/SRB2
  • Tyron/SRB2
  • Astronight/SRB2
  • Mari0shi06/SRB2
  • aiire/SRB2
  • Galactice/SRB2
  • srb2-ports/srb2-dreamcast
  • sdasdas/SRB2
  • chreas/srb-2-vr
  • StarManiaKG/the-story-of-sinically-rocketing-and-botching-the-2nd
  • LoganAir/SRB2
  • NepDisk/srb-2
  • alufolie91/SRB2
  • Felicia.iso/SRB2
  • twi/SRB2
  • BarrelsOFun/SRB2
  • Speed2411/SRB2
  • Leather_Realms/SRB2
  • Ayemar/SRB2
  • Acelite/SRB2
  • VladDoc/SRB2
  • kaldrum/model-features
  • strawberryfox417/SRB2
  • Lugent/SRB2
  • Rem/SRB2
  • Refrag/SRB2
  • Henry_3230/srb-3230
  • TehPuertoRicanSpartan2/tprs-srb2
  • Leminn/srb-2-marathon-stuff
  • chromaticpipe2/SRB2
  • MiguelGustavo15/SRB2
  • Maru/srb-2-tests
  • SilicDev/SRB2
  • UnmatchedBracket/SRB2
  • HybridDog/SRB2
  • xordspar0/SRB2
  • jsjhbewfhh/SRB2
  • Fancy2209/SRB2
  • Lorsoen/SRB2
  • shindoukin/SRB2
  • GamerOfDays/SRB2
  • Craftyawesome/SRB2
  • tenshi-tensai-tennoji/SRB2
  • Scarfdudebalder/SRB2
  • luigi-budd/srb-2-fix-interplag-lockon
  • mskluesner/SRB2
  • johnpetersa19/SRB2
  • Pheazant/SRB2
  • chromaticpipe2/srb2classic
  • romoney5/SRB2
  • PAS/SRB2Classic
  • BlueStaggo/SRB2
  • Jisk/srb-2-beef-jerky
117 results
Select Git revision
Show changes
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012-2016 by John "JTE" Muniz. // Copyright (C) 2012-2016 by John "JTE" Muniz.
// Copyright (C) 2012-2023 by Sonic Team Junior. // Copyright (C) 2012-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -67,13 +67,17 @@ automatically. ...@@ -67,13 +67,17 @@ automatically.
X (ViewpointSwitch),/* spy mode (no trickstabs) */\ X (ViewpointSwitch),/* spy mode (no trickstabs) */\
X (SeenPlayer),/* MT_NAMECHECK */\ X (SeenPlayer),/* MT_NAMECHECK */\
X (PlayerThink),/* P_PlayerThink */\ X (PlayerThink),/* P_PlayerThink */\
X (GameStart),\
X (GameQuit),\ X (GameQuit),\
X (GameEnd),\
X (PlayerCmd),/* building the player's ticcmd struct (Ported from SRB2Kart) */\ X (PlayerCmd),/* building the player's ticcmd struct (Ported from SRB2Kart) */\
X (MusicChange),\ X (MusicChange),\
X (PlayerHeight),/* override player height */\ X (PlayerHeight),/* override player height */\
X (PlayerCanEnterSpinGaps),\ X (PlayerCanEnterSpinGaps),\
X (AddonLoaded),\
X (KeyDown),\ X (KeyDown),\
X (KeyUp),\ X (KeyUp),\
X (TextInput),\
#define STRING_HOOK_LIST(X) \ #define STRING_HOOK_LIST(X) \
X (BotAI),/* B_BuildTailsTiccmd by skin name */\ X (BotAI),/* B_BuildTailsTiccmd by skin name */\
...@@ -134,6 +138,7 @@ void LUA_HookBool(boolean value, int hook); ...@@ -134,6 +138,7 @@ void LUA_HookBool(boolean value, int hook);
int LUA_HookPlayer(player_t *, int hook); int LUA_HookPlayer(player_t *, int hook);
int LUA_HookTiccmd(player_t *, ticcmd_t *, int hook); int LUA_HookTiccmd(player_t *, ticcmd_t *, int hook);
int LUA_HookKey(event_t *event, int hook); // Hooks for key events int LUA_HookKey(event_t *event, int hook); // Hooks for key events
int LUA_HookText(event_t *event, int hook); // Hooks for text events
void LUA_HookPreThinkFrame(void); void LUA_HookPreThinkFrame(void);
void LUA_HookThinkFrame(void); void LUA_HookThinkFrame(void);
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012-2016 by John "JTE" Muniz. // Copyright (C) 2012-2016 by John "JTE" Muniz.
// Copyright (C) 2012-2023 by Sonic Team Junior. // Copyright (C) 2012-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -498,7 +498,25 @@ static int call_string_hooks(Hook_State *hook) ...@@ -498,7 +498,25 @@ static int call_string_hooks(Hook_State *hook)
static int call_mobj_type_hooks(Hook_State *hook, mobjtype_t mobj_type) static int call_mobj_type_hooks(Hook_State *hook, mobjtype_t mobj_type)
{ {
return call_mapped(hook, &mobjHookIds[mobj_type][hook->hook_type]); int numCalls = call_mapped(hook, &mobjHookIds[mobj_type][hook->hook_type]);
if (numCalls > 0 && mobj_type == MT_NULL && (
hook->hook_type == MOBJ_HOOK(MobjThinker )
|| hook->hook_type == MOBJ_HOOK(MobjCollide )
|| hook->hook_type == MOBJ_HOOK(MobjLineCollide)
|| hook->hook_type == MOBJ_HOOK(MobjMoveCollide)
|| hook->hook_type == MOBJ_HOOK(MobjFuse )
|| hook->hook_type == MOBJ_HOOK(MobjThinker )
|| hook->hook_type == MOBJ_HOOK(BossThinker )
|| hook->hook_type == MOBJ_HOOK(MobjMoveBlocked)
|| hook->hook_type == MOBJ_HOOK(FollowMobj )
))
LUA_UsageWarning(L, va(
"%s hooks not attached to a specific mobj type are deprecated and will be removed.",
mobjHookNames[hook->hook_type])
);
return numCalls;
} }
static void call_hud_hooks static void call_hud_hooks
...@@ -672,6 +690,17 @@ int LUA_HookKey(event_t *event, int hook_type) ...@@ -672,6 +690,17 @@ int LUA_HookKey(event_t *event, int hook_type)
return hook.status; return hook.status;
} }
int LUA_HookText(event_t *event, int hook_type)
{
Hook_State hook;
if (prepare_hook(&hook, false, hook_type))
{
LUA_PushUserdata(gL, event, META_TEXTEVENT);
call_hooks(&hook, 1, res_true);
}
return hook.status;
}
void LUA_HookHUD(int hook_type, huddrawlist_h list) void LUA_HookHUD(int hook_type, huddrawlist_h list)
{ {
Hook_State hook; Hook_State hook;
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2014-2016 by John "JTE" Muniz. // Copyright (C) 2014-2016 by John "JTE" Muniz.
// Copyright (C) 2014-2023 by Sonic Team Junior. // Copyright (C) 2014-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -20,6 +20,10 @@ enum hud { ...@@ -20,6 +20,10 @@ enum hud {
hud_textspectator, hud_textspectator,
hud_crosshair, hud_crosshair,
hud_powerups, hud_powerups,
hud_gameover,
hud_pause,
hud_cecho,
hud_chat,
// Singleplayer / Co-op // Singleplayer / Co-op
hud_score, hud_score,
hud_time, hud_time,
...@@ -30,6 +34,7 @@ enum hud { ...@@ -30,6 +34,7 @@ enum hud {
hud_weaponrings, hud_weaponrings,
hud_powerstones, hud_powerstones,
hud_teamscores, hud_teamscores,
hud_itemhunt,
// NiGHTS mode // NiGHTS mode
hud_nightslink, hud_nightslink,
hud_nightsdrill, hud_nightsdrill,
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2014-2016 by John "JTE" Muniz. // Copyright (C) 2014-2016 by John "JTE" Muniz.
// Copyright (C) 2014-2023 by Sonic Team Junior. // Copyright (C) 2014-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -42,6 +42,10 @@ static const char *const hud_disable_options[] = { ...@@ -42,6 +42,10 @@ static const char *const hud_disable_options[] = {
"textspectator", "textspectator",
"crosshair", "crosshair",
"powerups", "powerups",
"gameover",
"pause",
"cecho",
"chat",
"score", "score",
"time", "time",
...@@ -52,6 +56,7 @@ static const char *const hud_disable_options[] = { ...@@ -52,6 +56,7 @@ static const char *const hud_disable_options[] = {
"weaponrings", "weaponrings",
"powerstones", "powerstones",
"teamscores", "teamscores",
"itemhunt",
"nightslink", "nightslink",
"nightsdrill", "nightsdrill",
...@@ -461,15 +466,29 @@ static int camera_set(lua_State *L) ...@@ -461,15 +466,29 @@ static int camera_set(lua_State *L)
static int libd_patchExists(lua_State *L) static int libd_patchExists(lua_State *L)
{ {
HUDONLY
lua_pushboolean(L, W_LumpExists(luaL_checkstring(L, 1))); lua_pushboolean(L, W_LumpExists(luaL_checkstring(L, 1)));
return 1; return 1;
} }
static int libd_cachePatch(lua_State *L) static int libd_cachePatch(lua_State *L)
{ {
HUDONLY const char *name = luaL_checkstring(L, 1);
LUA_PushUserdata(L, W_CachePatchLongName(luaL_checkstring(L, 1), PU_PATCH), META_PATCH); patch_t *patch = W_CachePatchLongName(name, PU_PATCH);
#ifdef ROTSPRITE
if (lua_isnumber(L, 2))
{
angle_t rollangle = luaL_checkangle(L, 2);
INT32 rot = R_GetRollAngle(rollangle);
if (rot) {
patch_t *rotpatch = Patch_GetRotated(patch, rot, false);
LUA_PushUserdata(L, rotpatch, META_PATCH);
return 1;
}
}
#endif
LUA_PushUserdata(L, patch, META_PATCH);
return 1; return 1;
} }
...@@ -481,7 +500,6 @@ static int libd_getSpritePatch(lua_State *L) ...@@ -481,7 +500,6 @@ static int libd_getSpritePatch(lua_State *L)
UINT8 angle = 0; UINT8 angle = 0;
spritedef_t *sprdef; spritedef_t *sprdef;
spriteframe_t *sprframe; spriteframe_t *sprframe;
HUDONLY
if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR_THOK if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR_THOK
{ {
...@@ -555,7 +573,6 @@ static int libd_getSprite2Patch(lua_State *L) ...@@ -555,7 +573,6 @@ static int libd_getSprite2Patch(lua_State *L)
spritedef_t *sprdef; spritedef_t *sprdef;
spriteframe_t *sprframe; spriteframe_t *sprframe;
boolean super = false; // add SPR2F_SUPER to sprite2 if true boolean super = false; // add SPR2F_SUPER to sprite2 if true
HUDONLY
// get skin first! // get skin first!
if (lua_isnumber(L, 1)) // find skin by number if (lua_isnumber(L, 1)) // find skin by number
...@@ -613,6 +630,10 @@ static int libd_getSprite2Patch(lua_State *L) ...@@ -613,6 +630,10 @@ static int libd_getSprite2Patch(lua_State *L)
if (super) if (super)
j |= SPR2F_SUPER; j |= SPR2F_SUPER;
// If there is no "super" variation of this sprite, try with the normal one.
if (!P_IsValidSprite2(skins[i], j))
j &= ~SPR2F_SUPER;
sprdef = P_GetSkinSpritedef(skins[i], j); sprdef = P_GetSkinSpritedef(skins[i], j);
// set frame number // set frame number
...@@ -871,6 +892,28 @@ static int libd_drawFill(lua_State *L) ...@@ -871,6 +892,28 @@ static int libd_drawFill(lua_State *L)
return 0; return 0;
} }
static int libd_drawFixedFill(lua_State *L)
{
huddrawlist_h list;
INT32 x = luaL_optinteger(L, 1, 0);
INT32 y = luaL_optinteger(L, 2, 0);
INT32 w = luaL_optinteger(L, 3, BASEVIDWIDTH << FRACBITS);
INT32 h = luaL_optinteger(L, 4, BASEVIDHEIGHT << FRACBITS);
INT32 c = luaL_optinteger(L, 5, 31);
HUDONLY
lua_getfield(L, LUA_REGISTRYINDEX, "HUD_DRAW_LIST");
list = (huddrawlist_h) lua_touserdata(L, -1);
lua_pop(L, 1);
if (LUA_HUD_IsDrawListValid(list))
LUA_HUD_AddDrawFixedFill(list, x, y, w, h, c);
else
V_DrawFixedFill(x, y, w, h, c);
return 0;
}
static int libd_drawString(lua_State *L) static int libd_drawString(lua_State *L)
{ {
huddrawlist_h list; huddrawlist_h list;
...@@ -1126,13 +1169,12 @@ static int libd_levelTitleHeight(lua_State *L) ...@@ -1126,13 +1169,12 @@ static int libd_levelTitleHeight(lua_State *L)
static int libd_getColormap(lua_State *L) static int libd_getColormap(lua_State *L)
{ {
HUDONLY
INT32 skinnum = TC_DEFAULT; INT32 skinnum = TC_DEFAULT;
skincolornum_t color = luaL_optinteger(L, 2, 0); skincolornum_t color = luaL_optinteger(L, 2, 0);
UINT8* colormap = NULL; UINT8* colormap = NULL;
int translation_id = -1; int translation_id = -1;
HUDONLY
if (lua_isnoneornil(L, 1)) if (lua_isnoneornil(L, 1))
; // defaults to TC_DEFAULT ; // defaults to TC_DEFAULT
else if (lua_type(L, 1) == LUA_TNUMBER) // skin number else if (lua_type(L, 1) == LUA_TNUMBER) // skin number
...@@ -1172,9 +1214,10 @@ static int libd_getColormap(lua_State *L) ...@@ -1172,9 +1214,10 @@ static int libd_getColormap(lua_State *L)
static int libd_getStringColormap(lua_State *L) static int libd_getStringColormap(lua_State *L)
{ {
HUDONLY
INT32 flags = luaL_checkinteger(L, 1); INT32 flags = luaL_checkinteger(L, 1);
UINT8* colormap = NULL; UINT8* colormap = NULL;
HUDONLY
colormap = V_GetStringColormap(flags & V_CHARCOLORMASK); colormap = V_GetStringColormap(flags & V_CHARCOLORMASK);
if (colormap) { if (colormap) {
LUA_PushUserdata(L, colormap, META_COLORMAP); // push as META_COLORMAP userdata, specifically for patches to use! LUA_PushUserdata(L, colormap, META_COLORMAP); // push as META_COLORMAP userdata, specifically for patches to use!
...@@ -1185,6 +1228,7 @@ static int libd_getStringColormap(lua_State *L) ...@@ -1185,6 +1228,7 @@ static int libd_getStringColormap(lua_State *L)
static int libd_getSectorColormap(lua_State *L) static int libd_getSectorColormap(lua_State *L)
{ {
HUDONLY
boolean has_sector = false; boolean has_sector = false;
sector_t *sector = NULL; sector_t *sector = NULL;
if (!lua_isnoneornil(L, 1)) if (!lua_isnoneornil(L, 1))
...@@ -1260,21 +1304,18 @@ static int libd_fadeScreen(lua_State *L) ...@@ -1260,21 +1304,18 @@ static int libd_fadeScreen(lua_State *L)
static int libd_width(lua_State *L) static int libd_width(lua_State *L)
{ {
HUDONLY
lua_pushinteger(L, vid.width); // push screen width lua_pushinteger(L, vid.width); // push screen width
return 1; return 1;
} }
static int libd_height(lua_State *L) static int libd_height(lua_State *L)
{ {
HUDONLY
lua_pushinteger(L, vid.height); // push screen height lua_pushinteger(L, vid.height); // push screen height
return 1; return 1;
} }
static int libd_dup(lua_State *L) static int libd_dup(lua_State *L)
{ {
HUDONLY
lua_pushinteger(L, vid.dup); // push integral scale (patch scale) lua_pushinteger(L, vid.dup); // push integral scale (patch scale)
lua_pushfixed(L, vid.fdup); // push fixed point scale (position scale) lua_pushfixed(L, vid.fdup); // push fixed point scale (position scale)
return 2; return 2;
...@@ -1282,7 +1323,6 @@ static int libd_dup(lua_State *L) ...@@ -1282,7 +1323,6 @@ static int libd_dup(lua_State *L)
static int libd_renderer(lua_State *L) static int libd_renderer(lua_State *L)
{ {
HUDONLY
switch (rendermode) { switch (rendermode) {
case render_opengl: lua_pushliteral(L, "opengl"); break; // OpenGL renderer case render_opengl: lua_pushliteral(L, "opengl"); break; // OpenGL renderer
case render_soft: lua_pushliteral(L, "software"); break; // Software renderer case render_soft: lua_pushliteral(L, "software"); break; // Software renderer
...@@ -1296,14 +1336,12 @@ static int libd_renderer(lua_State *L) ...@@ -1296,14 +1336,12 @@ static int libd_renderer(lua_State *L)
static int libd_RandomFixed(lua_State *L) static int libd_RandomFixed(lua_State *L)
{ {
HUDONLY
lua_pushfixed(L, M_RandomFixed()); lua_pushfixed(L, M_RandomFixed());
return 1; return 1;
} }
static int libd_RandomByte(lua_State *L) static int libd_RandomByte(lua_State *L)
{ {
HUDONLY
lua_pushinteger(L, M_RandomByte()); lua_pushinteger(L, M_RandomByte());
return 1; return 1;
} }
...@@ -1312,7 +1350,6 @@ static int libd_RandomKey(lua_State *L) ...@@ -1312,7 +1350,6 @@ static int libd_RandomKey(lua_State *L)
{ {
INT32 a = (INT32)luaL_checkinteger(L, 1); INT32 a = (INT32)luaL_checkinteger(L, 1);
HUDONLY
lua_pushinteger(L, M_RandomKey(a)); lua_pushinteger(L, M_RandomKey(a));
return 1; return 1;
} }
...@@ -1322,7 +1359,6 @@ static int libd_RandomRange(lua_State *L) ...@@ -1322,7 +1359,6 @@ static int libd_RandomRange(lua_State *L)
INT32 a = (INT32)luaL_checkinteger(L, 1); INT32 a = (INT32)luaL_checkinteger(L, 1);
INT32 b = (INT32)luaL_checkinteger(L, 2); INT32 b = (INT32)luaL_checkinteger(L, 2);
HUDONLY
lua_pushinteger(L, M_RandomRange(a, b)); lua_pushinteger(L, M_RandomRange(a, b));
return 1; return 1;
} }
...@@ -1330,7 +1366,6 @@ static int libd_RandomRange(lua_State *L) ...@@ -1330,7 +1366,6 @@ static int libd_RandomRange(lua_State *L)
// Macros. // Macros.
static int libd_SignedRandom(lua_State *L) static int libd_SignedRandom(lua_State *L)
{ {
HUDONLY
lua_pushinteger(L, M_SignedRandom()); lua_pushinteger(L, M_SignedRandom());
return 1; return 1;
} }
...@@ -1338,7 +1373,6 @@ static int libd_SignedRandom(lua_State *L) ...@@ -1338,7 +1373,6 @@ static int libd_SignedRandom(lua_State *L)
static int libd_RandomChance(lua_State *L) static int libd_RandomChance(lua_State *L)
{ {
fixed_t p = luaL_checkfixed(L, 1); fixed_t p = luaL_checkfixed(L, 1);
HUDONLY
lua_pushboolean(L, M_RandomChance(p)); lua_pushboolean(L, M_RandomChance(p));
return 1; return 1;
} }
...@@ -1347,7 +1381,6 @@ static int libd_RandomChance(lua_State *L) ...@@ -1347,7 +1381,6 @@ static int libd_RandomChance(lua_State *L)
// Could as well be thrown in global vars for ease of access but I guess it makes sense for it to be a HUD fn // Could as well be thrown in global vars for ease of access but I guess it makes sense for it to be a HUD fn
static int libd_getlocaltransflag(lua_State *L) static int libd_getlocaltransflag(lua_State *L)
{ {
HUDONLY
lua_pushinteger(L, (10-st_translucency)*V_10TRANS); lua_pushinteger(L, (10-st_translucency)*V_10TRANS);
return 1; return 1;
} }
...@@ -1355,7 +1388,6 @@ static int libd_getlocaltransflag(lua_State *L) ...@@ -1355,7 +1388,6 @@ static int libd_getlocaltransflag(lua_State *L)
// Get cv_translucenthud's value for HUD rendering as a normal V_xxTRANS int // Get cv_translucenthud's value for HUD rendering as a normal V_xxTRANS int
static int libd_getusertransflag(lua_State *L) static int libd_getusertransflag(lua_State *L)
{ {
HUDONLY
lua_pushinteger(L, (10-cv_translucenthud.value)*V_10TRANS); // A bit weird that it's called "translucenthud" yet 10 is fully opaque :V lua_pushinteger(L, (10-cv_translucenthud.value)*V_10TRANS); // A bit weird that it's called "translucenthud" yet 10 is fully opaque :V
return 1; return 1;
} }
...@@ -1377,6 +1409,7 @@ static luaL_Reg lib_draw[] = { ...@@ -1377,6 +1409,7 @@ static luaL_Reg lib_draw[] = {
{"drawNum", libd_drawNum}, {"drawNum", libd_drawNum},
{"drawPaddedNum", libd_drawPaddedNum}, {"drawPaddedNum", libd_drawPaddedNum},
{"drawFill", libd_drawFill}, {"drawFill", libd_drawFill},
{"drawFixedFill", libd_drawFixedFill},
{"drawString", libd_drawString}, {"drawString", libd_drawString},
{"drawNameTag", libd_drawNameTag}, {"drawNameTag", libd_drawNameTag},
{"drawScaledNameTag", libd_drawScaledNameTag}, {"drawScaledNameTag", libd_drawScaledNameTag},
...@@ -1448,6 +1481,26 @@ static luaL_Reg lib_hud[] = { ...@@ -1448,6 +1481,26 @@ static luaL_Reg lib_hud[] = {
{"disable", lib_huddisable}, {"disable", lib_huddisable},
{"enabled", lib_hudenabled}, {"enabled", lib_hudenabled},
{"add", lib_hudadd}, {"add", lib_hudadd},
{"patchExists", libd_patchExists},
{"cachePatch", libd_cachePatch},
{"getSpritePatch", libd_getSpritePatch},
{"getSprite2Patch", libd_getSprite2Patch},
{"width", libd_width},
{"height", libd_height},
{"scale", libd_dup},
{"renderer", libd_renderer},
{NULL, NULL}
};
// globalized client_side random functions.
static luaL_Reg lib_randomclient[] = {
// m_random
{"localFixed",libd_RandomFixed},
{"localByte",libd_RandomByte},
{"localKey",libd_RandomKey},
{"localRange",libd_RandomRange},
{"localSignedRandom",libd_SignedRandom}, // MACRO
{"localChance",libd_RandomChance}, // MACRO
{NULL, NULL} {NULL, NULL}
}; };
...@@ -1474,6 +1527,7 @@ int LUA_HudLib(lua_State *L) ...@@ -1474,6 +1527,7 @@ int LUA_HudLib(lua_State *L)
LUA_RegisterGlobalUserdata(L, "hudinfo", lib_getHudInfo, NULL, lib_hudinfolen); LUA_RegisterGlobalUserdata(L, "hudinfo", lib_getHudInfo, NULL, lib_hudinfolen);
luaL_register(L, "hud", lib_hud); luaL_register(L, "hud", lib_hud);
luaL_register(L, "random", lib_randomclient);
return 0; return 0;
} }
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2014-2016 by John "JTE" Muniz. // Copyright (C) 2014-2016 by John "JTE" Muniz.
// Copyright (C) 2014-2023 by Sonic Team Junior. // Copyright (C) 2014-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -25,6 +25,7 @@ enum drawitem_e { ...@@ -25,6 +25,7 @@ enum drawitem_e {
DI_DrawNum, DI_DrawNum,
DI_DrawPaddedNum, DI_DrawPaddedNum,
DI_DrawFill, DI_DrawFill,
DI_DrawFixedFill,
DI_DrawString, DI_DrawString,
DI_DrawNameTag, DI_DrawNameTag,
DI_DrawScaledNameTag, DI_DrawScaledNameTag,
...@@ -180,7 +181,8 @@ static const char *CopyString(huddrawlist_h list, const char* str) ...@@ -180,7 +181,8 @@ static const char *CopyString(huddrawlist_h list, const char* str)
const char *old_offset = list->strbuf; const char *old_offset = list->strbuf;
size_t i; size_t i;
if (list->strbuf_capacity == 0) list->strbuf_capacity = 256; if (list->strbuf_capacity == 0) list->strbuf_capacity = 256;
else list->strbuf_capacity *= 2; while (list->strbuf_capacity <= list->strbuf_len + lenstr + 1)
list->strbuf_capacity *= 2;
list->strbuf = (char*) Z_Realloc(list->strbuf, sizeof(char) * list->strbuf_capacity, PU_STATIC, NULL); list->strbuf = (char*) Z_Realloc(list->strbuf, sizeof(char) * list->strbuf_capacity, PU_STATIC, NULL);
// align the string pointers to make sure old pointers don't point towards invalid addresses // align the string pointers to make sure old pointers don't point towards invalid addresses
...@@ -345,6 +347,25 @@ void LUA_HUD_AddDrawFill( ...@@ -345,6 +347,25 @@ void LUA_HUD_AddDrawFill(
item->c = c; item->c = c;
} }
void LUA_HUD_AddDrawFixedFill(
huddrawlist_h list,
fixed_t x,
fixed_t y,
fixed_t w,
fixed_t h,
INT32 c
)
{
size_t i = AllocateDrawItem(list);
drawitem_t *item = &list->items[i];
item->type = DI_DrawFixedFill;
item->x = x;
item->y = y;
item->w = w;
item->h = h;
item->c = c;
}
void LUA_HUD_AddDrawString( void LUA_HUD_AddDrawString(
huddrawlist_h list, huddrawlist_h list,
fixed_t x, fixed_t x,
...@@ -481,6 +502,9 @@ void LUA_HUD_DrawList(huddrawlist_h list) ...@@ -481,6 +502,9 @@ void LUA_HUD_DrawList(huddrawlist_h list)
case DI_DrawFill: case DI_DrawFill:
V_DrawFill(item->x, item->y, item->w, item->h, item->c); V_DrawFill(item->x, item->y, item->w, item->h, item->c);
break; break;
case DI_DrawFixedFill:
V_DrawFixedFill(item->x, item->y, item->w, item->h, item->c);
break;
case DI_DrawString: case DI_DrawString:
switch(item->align) switch(item->align)
{ {
......
...@@ -98,6 +98,14 @@ void LUA_HUD_AddDrawFill( ...@@ -98,6 +98,14 @@ void LUA_HUD_AddDrawFill(
INT32 h, INT32 h,
INT32 c INT32 c
); );
void LUA_HUD_AddDrawFixedFill(
huddrawlist_h list,
fixed_t x,
fixed_t y,
fixed_t w,
fixed_t h,
INT32 c
);
void LUA_HUD_AddDrawString( void LUA_HUD_AddDrawString(
huddrawlist_h list, huddrawlist_h list,
fixed_t x, fixed_t x,
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012-2016 by John "JTE" Muniz. // Copyright (C) 2012-2016 by John "JTE" Muniz.
// Copyright (C) 2012-2023 by Sonic Team Junior. // Copyright (C) 2012-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -242,17 +242,12 @@ static int lib_getSpriteInfo(lua_State *L) ...@@ -242,17 +242,12 @@ static int lib_getSpriteInfo(lua_State *L)
UINT32 i = NUMSPRITES; UINT32 i = NUMSPRITES;
lua_remove(L, 1); lua_remove(L, 1);
if (lua_isstring(L, 1)) if (lua_type(L, 1) == LUA_TSTRING)
{ {
const char *name = lua_tostring(L, 1); const char *name = lua_tostring(L, 1);
INT32 spr = R_GetSpriteNumByName(name); INT32 spr = R_GetSpriteNumByName(name);
if (spr == NUMSPRITES) if (spr == NUMSPRITES)
{
char *check;
i = strtol(name, &check, 10);
if (check == name || *check != '\0')
return luaL_error(L, "unknown sprite name %s", name); return luaL_error(L, "unknown sprite name %s", name);
}
i = spr; i = spr;
} }
else else
...@@ -1163,6 +1158,7 @@ enum mobjinfo_e ...@@ -1163,6 +1158,7 @@ enum mobjinfo_e
mobjinfo_activesound, mobjinfo_activesound,
mobjinfo_flags, mobjinfo_flags,
mobjinfo_raisestate, mobjinfo_raisestate,
mobjinfo_name,
}; };
const char *const mobjinfo_opt[] = { const char *const mobjinfo_opt[] = {
...@@ -1190,6 +1186,7 @@ const char *const mobjinfo_opt[] = { ...@@ -1190,6 +1186,7 @@ const char *const mobjinfo_opt[] = {
"activesound", "activesound",
"flags", "flags",
"raisestate", "raisestate",
"name",
NULL, NULL,
}; };
...@@ -1204,6 +1201,8 @@ static int mobjinfo_get(lua_State *L) ...@@ -1204,6 +1201,8 @@ static int mobjinfo_get(lua_State *L)
I_Assert(info != NULL); I_Assert(info != NULL);
I_Assert(info >= mobjinfo); I_Assert(info >= mobjinfo);
mobjtype_t id = info-mobjinfo;
switch (field) switch (field)
{ {
case mobjinfo_doomednum: case mobjinfo_doomednum:
...@@ -1278,6 +1277,21 @@ static int mobjinfo_get(lua_State *L) ...@@ -1278,6 +1277,21 @@ static int mobjinfo_get(lua_State *L)
case mobjinfo_raisestate: case mobjinfo_raisestate:
lua_pushinteger(L, info->raisestate); lua_pushinteger(L, info->raisestate);
break; break;
case mobjinfo_name:
if (id < MT_FIRSTFREESLOT)
{
lua_pushstring(L, MOBJTYPE_LIST[id]+3);
return 1;
}
id -= MT_FIRSTFREESLOT;
if (id < NUMMOBJFREESLOTS && FREE_MOBJS[id])
{
lua_pushstring(L, FREE_MOBJS[id]);
return 1;
}
return 0;
default: default:
lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS); lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS);
I_Assert(lua_istable(L, -1)); I_Assert(lua_istable(L, -1));
...@@ -1740,7 +1754,7 @@ static int lib_setSkinColor(lua_State *L) ...@@ -1740,7 +1754,7 @@ static int lib_setSkinColor(lua_State *L)
else if (i == 6 || (str && fastcmp(str,"accessible"))) { else if (i == 6 || (str && fastcmp(str,"accessible"))) {
boolean v = lua_toboolean(L, 3); boolean v = lua_toboolean(L, 3);
if (cnum < FIRSTSUPERCOLOR && v != skincolors[cnum].accessible) if (cnum < FIRSTSUPERCOLOR && v != skincolors[cnum].accessible)
CONS_Alert(CONS_WARNING, "skincolors[] index %d is a standard color; accessibility changes are prohibited.", cnum); CONS_Alert(CONS_WARNING, "skincolors[] index %d is a standard color; accessibility changes are prohibited.\n", cnum);
else else
info->accessible = v; info->accessible = v;
} }
...@@ -1835,7 +1849,7 @@ static int skincolor_set(lua_State *L) ...@@ -1835,7 +1849,7 @@ static int skincolor_set(lua_State *L)
else if (fastcmp(field,"accessible")) { else if (fastcmp(field,"accessible")) {
boolean v = lua_toboolean(L, 3); boolean v = lua_toboolean(L, 3);
if (cnum < FIRSTSUPERCOLOR && v != skincolors[cnum].accessible) if (cnum < FIRSTSUPERCOLOR && v != skincolors[cnum].accessible)
CONS_Alert(CONS_WARNING, "skincolors[] index %d is a standard color; accessibility changes are prohibited.", cnum); CONS_Alert(CONS_WARNING, "skincolors[] index %d is a standard color; accessibility changes are prohibited.\n", cnum);
else else
info->accessible = v; info->accessible = v;
} else } else
......
...@@ -10,16 +10,19 @@ ...@@ -10,16 +10,19 @@
/// \brief input library for Lua scripting /// \brief input library for Lua scripting
#include "doomdef.h" #include "doomdef.h"
#include "doomstat.h"
#include "fastcmp.h" #include "fastcmp.h"
#include "g_input.h" #include "g_input.h"
#include "g_game.h" #include "g_game.h"
#include "hu_stuff.h" #include "hu_stuff.h"
#include "i_system.h" #include "i_system.h"
#include "console.h"
#include "lua_script.h" #include "lua_script.h"
#include "lua_libs.h" #include "lua_libs.h"
boolean mousegrabbedbylua = true; boolean mousegrabbedbylua = true;
boolean textinputmodeenabledbylua = false;
boolean ignoregameinputs = false; boolean ignoregameinputs = false;
/////////////// ///////////////
...@@ -129,6 +132,20 @@ static int lib_getCursorPosition(lua_State *L) ...@@ -129,6 +132,20 @@ static int lib_getCursorPosition(lua_State *L)
return 2; return 2;
} }
static int lib_setTextInputMode(lua_State *L)
{
textinputmodeenabledbylua = luaL_checkboolean(L, 1);
if (!(menuactive || CON_Ready() || chat_on))
I_SetTextInputMode(textinputmodeenabledbylua);
return 0;
}
static int lib_getTextInputMode(lua_State *L)
{
lua_pushinteger(L, textinputmodeenabledbylua);
return 1;
}
static luaL_Reg lib[] = { static luaL_Reg lib[] = {
{"gameControlDown", lib_gameControlDown}, {"gameControlDown", lib_gameControlDown},
{"gameControl2Down", lib_gameControl2Down}, {"gameControl2Down", lib_gameControl2Down},
...@@ -143,6 +160,8 @@ static luaL_Reg lib[] = { ...@@ -143,6 +160,8 @@ static luaL_Reg lib[] = {
{"getMouseGrab", lib_getMouseGrab}, {"getMouseGrab", lib_getMouseGrab},
{"setMouseGrab", lib_setMouseGrab}, {"setMouseGrab", lib_setMouseGrab},
{"getCursorPosition", lib_getCursorPosition}, {"getCursorPosition", lib_getCursorPosition},
{"setTextInputMode", lib_setTextInputMode},
{"getTextInputMode", lib_getTextInputMode},
{NULL, NULL} {NULL, NULL}
}; };
...@@ -220,6 +239,28 @@ static int lib_lenGameKeyDown(lua_State *L) ...@@ -220,6 +239,28 @@ static int lib_lenGameKeyDown(lua_State *L)
return 1; return 1;
} }
////////////////
// TEXT EVENT //
////////////////
static int textevent_get(lua_State *L)
{
event_t *event = *((event_t **)luaL_checkudata(L, 1, META_TEXTEVENT));
const char *field = luaL_checkstring(L, 2);
I_Assert(event != NULL);
if (fastcmp(field,"text"))
{
char s[2] = { event->key, 0 };
lua_pushstring(L, s);
}
else
return luaL_error(L, "textevent_t has no field named %s", field);
return 1;
}
/////////////// ///////////////
// KEY EVENT // // KEY EVENT //
/////////////// ///////////////
...@@ -285,6 +326,7 @@ static int mouse_num(lua_State *L) ...@@ -285,6 +326,7 @@ static int mouse_num(lua_State *L)
int LUA_InputLib(lua_State *L) int LUA_InputLib(lua_State *L)
{ {
LUA_RegisterUserdataMetatable(L, META_TEXTEVENT, textevent_get, NULL, NULL);
LUA_RegisterUserdataMetatable(L, META_KEYEVENT, keyevent_get, NULL, NULL); LUA_RegisterUserdataMetatable(L, META_KEYEVENT, keyevent_get, NULL, NULL);
LUA_RegisterUserdataMetatable(L, META_MOUSE, mouse_get, NULL, mouse_num); LUA_RegisterUserdataMetatable(L, META_MOUSE, mouse_get, NULL, mouse_num);
......
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2024-2024 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file lua_interceptlib.c
/// \brief intercept library for Lua scripting
#include "doomdef.h"
#include "fastcmp.h"
#include "p_local.h"
#include "lua_script.h"
#include "lua_libs.h"
#include "lua_hud.h" // hud_running errors
#define NOHUD if (hud_running)\
return luaL_error(L, "HUD rendering code should not call this function!");
enum intercept_e {
intercept_valid = 0,
intercept_frac,
intercept_thing,
intercept_line
};
static const char *const intercept_opt[] = {
"valid",
"frac",
"thing",
"line",
NULL};
static int intercept_fields_ref = LUA_NOREF;
static boolean Lua_PathTraverser(intercept_t *in)
{
boolean traverse = false;
I_Assert(in != NULL);
lua_settop(gL, 6);
lua_pushcfunction(gL, LUA_GetErrorMessage);
I_Assert(lua_isfunction(gL, -2));
lua_pushvalue(gL, -2);
LUA_PushUserdata(gL, in, META_INTERCEPT);
LUA_Call(gL, 1, 1, -3);
traverse = lua_toboolean(gL, -1);
lua_pop(gL, 1);
return !traverse; // Stay consistent with the MobjMoveCollide hook
}
static int intercept_get(lua_State *L)
{
intercept_t *in = *((intercept_t **)luaL_checkudata(L, 1, META_INTERCEPT));
enum intercept_e field = Lua_optoption(L, 2, intercept_valid, intercept_fields_ref);
if (!in)
{
if (field == intercept_valid) {
lua_pushboolean(L, 0);
return 1;
}
return luaL_error(L, "accessed intercept_t doesn't exist anymore.");
}
switch(field)
{
case intercept_valid: // valid
lua_pushboolean(L, 1);
return 1;
case intercept_frac:
lua_pushfixed(L, in->frac);
return 1;
case intercept_thing:
if (in->isaline)
return 0;
LUA_PushUserdata(L, in->d.thing, META_MOBJ);
return 1;
case intercept_line:
if (!in->isaline)
return 0;
LUA_PushUserdata(L, in->d.line, META_LINE);
return 1;
}
return 0;
}
static int lib_pPathTraverse(lua_State *L)
{
fixed_t px1 = luaL_checkfixed(L, 1);
fixed_t py1 = luaL_checkfixed(L, 2);
fixed_t px2 = luaL_checkfixed(L, 3);
fixed_t py2 = luaL_checkfixed(L, 4);
INT32 flags = (INT32)luaL_checkinteger(L, 5);
luaL_checktype(L, 6, LUA_TFUNCTION);
NOHUD
INLEVEL
lua_pushboolean(L, P_PathTraverse(px1, py1, px2, py2, flags, Lua_PathTraverser));
return 1;
}
int LUA_InterceptLib(lua_State *L)
{
LUA_RegisterUserdataMetatable(L, META_INTERCEPT, intercept_get, NULL, NULL);
intercept_fields_ref = Lua_CreateFieldTable(L, intercept_opt);
lua_register(L, "P_PathTraverse", lib_pPathTraverse);
return 0;
}
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012-2016 by John "JTE" Muniz. // Copyright (C) 2012-2016 by John "JTE" Muniz.
// Copyright (C) 2012-2023 by Sonic Team Junior. // Copyright (C) 2012-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
extern lua_State *gL; extern lua_State *gL;
extern boolean mousegrabbedbylua; extern boolean mousegrabbedbylua;
extern boolean textinputmodeenabledbylua;
extern boolean ignoregameinputs; extern boolean ignoregameinputs;
#define MUTABLE_TAGS #define MUTABLE_TAGS
...@@ -42,8 +43,11 @@ extern boolean ignoregameinputs; ...@@ -42,8 +43,11 @@ extern boolean ignoregameinputs;
#define META_SKIN "SKIN_T*" #define META_SKIN "SKIN_T*"
#define META_POWERS "PLAYER_T*POWERS" #define META_POWERS "PLAYER_T*POWERS"
#define META_SOUNDSID "SKIN_T*SOUNDSID" #define META_SOUNDSID "SKIN_T*SOUNDSID"
#define META_SKINSPRITES "SKIN_T*SPRITES" #define META_SKINSPRITES "SKIN_T*SKINSPRITES"
#define META_SKINSPRITESLIST "SKIN_T*SPRITES[]" #define META_SKINSPRITESLIST "SKIN_T*SKINSPRITES[]"
#define META_SKINSPRITESCOMPAT "SKIN_T*SPRITES" // TODO: 2.3: Delete
#define META_MUSICDEF "MUSICDEF_T*"
#define META_VERTEX "VERTEX_T*" #define META_VERTEX "VERTEX_T*"
#define META_LINE "LINE_T*" #define META_LINE "LINE_T*"
...@@ -68,11 +72,15 @@ extern boolean ignoregameinputs; ...@@ -68,11 +72,15 @@ extern boolean ignoregameinputs;
#ifdef MUTABLE_TAGS #ifdef MUTABLE_TAGS
#define META_SECTORTAGLIST "sector_t.taglist" #define META_SECTORTAGLIST "sector_t.taglist"
#endif #endif
#define META_SECTORCUSTOMARGS "SECTOR_T*CUSTOMARGS"
#define META_SIDENUM "LINE_T*SIDENUM" #define META_SIDENUM "LINE_T*SIDENUM"
#define META_LINEARGS "LINE_T*ARGS" #define META_LINEARGS "LINE_T*ARGS"
#define META_LINESTRINGARGS "LINE_T*STRINGARGS" #define META_LINESTRINGARGS "LINE_T*STRINGARGS"
#define META_LINECUSTOMARGS "LINE_T*CUSTOMARGS"
#define META_SIDECUSTOMARGS "SIDE_T*CUSTOMARGS"
#define META_THINGARGS "MAPTHING_T*ARGS" #define META_THINGARGS "MAPTHING_T*ARGS"
#define META_THINGSTRINGARGS "MAPTHING_T*STRINGARGS" #define META_THINGSTRINGARGS "MAPTHING_T*STRINGARGS"
#define META_THINGCUSTOMARGS "MAPTHING_T*CUSTOMARGS"
#define META_POLYOBJVERTICES "POLYOBJ_T*VERTICES" #define META_POLYOBJVERTICES "POLYOBJ_T*VERTICES"
#define META_POLYOBJLINES "POLYOBJ_T*LINES" #define META_POLYOBJLINES "POLYOBJ_T*LINES"
#ifdef HAVE_LUA_SEGS #ifdef HAVE_LUA_SEGS
...@@ -92,9 +100,12 @@ extern boolean ignoregameinputs; ...@@ -92,9 +100,12 @@ extern boolean ignoregameinputs;
#define META_LUABANKS "LUABANKS[]*" #define META_LUABANKS "LUABANKS[]*"
#define META_TEXTEVENT "TEXTEVENT_T*"
#define META_KEYEVENT "KEYEVENT_T*" #define META_KEYEVENT "KEYEVENT_T*"
#define META_MOUSE "MOUSE_T*" #define META_MOUSE "MOUSE_T*"
#define META_INTERCEPT "INTERCEPT_T*"
boolean luaL_checkboolean(lua_State *L, int narg); boolean luaL_checkboolean(lua_State *L, int narg);
int LUA_EnumLib(lua_State *L); int LUA_EnumLib(lua_State *L);
...@@ -115,3 +126,4 @@ int LUA_BlockmapLib(lua_State *L); ...@@ -115,3 +126,4 @@ int LUA_BlockmapLib(lua_State *L);
int LUA_HudLib(lua_State *L); int LUA_HudLib(lua_State *L);
int LUA_ColorLib(lua_State *L); int LUA_ColorLib(lua_State *L);
int LUA_InputLib(lua_State *L); int LUA_InputLib(lua_State *L);
int LUA_InterceptLib(lua_State *L);
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012-2016 by John "JTE" Muniz. // Copyright (C) 2012-2016 by John "JTE" Muniz.
// Copyright (C) 2012-2023 by Sonic Team Junior. // Copyright (C) 2012-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -69,6 +69,7 @@ enum sector_e { ...@@ -69,6 +69,7 @@ enum sector_e {
sector_triggerer, sector_triggerer,
sector_friction, sector_friction,
sector_gravity, sector_gravity,
sector_customargs
}; };
static const char *const sector_opt[] = { static const char *const sector_opt[] = {
...@@ -112,6 +113,7 @@ static const char *const sector_opt[] = { ...@@ -112,6 +113,7 @@ static const char *const sector_opt[] = {
"triggerer", "triggerer",
"friction", "friction",
"gravity", "gravity",
"customargs",
NULL}; NULL};
static int sector_fields_ref = LUA_NOREF; static int sector_fields_ref = LUA_NOREF;
...@@ -147,6 +149,7 @@ enum line_e { ...@@ -147,6 +149,7 @@ enum line_e {
line_taglist, line_taglist,
line_args, line_args,
line_stringargs, line_stringargs,
line_customargs,
line_sidenum, line_sidenum,
line_frontside, line_frontside,
line_backside, line_backside,
...@@ -173,6 +176,7 @@ static const char *const line_opt[] = { ...@@ -173,6 +176,7 @@ static const char *const line_opt[] = {
"taglist", "taglist",
"args", "args",
"stringargs", "stringargs",
"customargs",
"sidenum", "sidenum",
"frontside", "frontside",
"backside", "backside",
...@@ -213,7 +217,16 @@ enum side_e { ...@@ -213,7 +217,16 @@ enum side_e {
side_sector, side_sector,
side_special, side_special,
side_repeatcnt, side_repeatcnt,
side_text side_light,
side_light_top,
side_light_mid,
side_light_bottom,
side_lightabsolute,
side_lightabsolute_top,
side_lightabsolute_mid,
side_lightabsolute_bottom,
side_text,
side_customargs
}; };
static const char *const side_opt[] = { static const char *const side_opt[] = {
...@@ -241,7 +254,16 @@ static const char *const side_opt[] = { ...@@ -241,7 +254,16 @@ static const char *const side_opt[] = {
"sector", "sector",
"special", "special",
"repeatcnt", "repeatcnt",
"light",
"light_top",
"light_mid",
"light_bottom",
"lightabsolute",
"lightabsolute_top",
"lightabsolute_mid",
"lightabsolute_bottom",
"text", "text",
"customargs",
NULL}; NULL};
static int side_fields_ref = LUA_NOREF; static int side_fields_ref = LUA_NOREF;
...@@ -658,6 +680,73 @@ static int sectorlines_num(lua_State *L) ...@@ -658,6 +680,73 @@ static int sectorlines_num(lua_State *L)
return 1; return 1;
} }
//////////////////
// customargs_t //
//////////////////
FUNCINLINE static ATTRINLINE int customargs_get(lua_State* L, const char* meta)
{
customargs_t *args = *((customargs_t**)luaL_checkudata(L, 1, meta));
const char* field = luaL_checkstring(L, 2);
if (args == NULL) {
lua_pushnil(L);
return 1;
}
customargs_t* current = args;
while (current != NULL)
{
if (!strcmp(current->name, field))
{
switch (current->type)
{
case UDMF_TYPE_STRING:
lua_pushstring(L, current->value.vstring);
break;
case UDMF_TYPE_NUMERIC:
lua_pushinteger(L, current->value.vint);
break;
case UDMF_TYPE_FIXED:
lua_pushfixed(L, current->value.vfloat);
break;
case UDMF_TYPE_BOOLEAN:
lua_pushboolean(L, current->value.vbool);
break;
default:
lua_pushnil(L);
}
return 1;
}
current = current->next;
}
lua_pushnil(L);
return 1;
}
static int sectorcustomargs_get(lua_State* L)
{
return customargs_get(L, META_SECTORCUSTOMARGS);
}
static int sidecustomargs_get(lua_State* L)
{
return customargs_get(L, META_SIDECUSTOMARGS);
}
static int linecustomargs_get(lua_State* L)
{
return customargs_get(L, META_LINECUSTOMARGS);
}
static int thingcustomargs_get(lua_State* L)
{
return customargs_get(L, META_THINGCUSTOMARGS);
}
////////////// //////////////
// sector_t // // sector_t //
////////////// //////////////
...@@ -819,6 +908,9 @@ static int sector_get(lua_State *L) ...@@ -819,6 +908,9 @@ static int sector_get(lua_State *L)
case sector_gravity: // gravity case sector_gravity: // gravity
lua_pushfixed(L, sector->gravity); lua_pushfixed(L, sector->gravity);
return 1; return 1;
case sector_customargs:
LUA_PushUserdata(L, sector->customargs, META_SECTORCUSTOMARGS);
return 1;
} }
return 0; return 0;
} }
...@@ -1114,6 +1206,9 @@ static int line_get(lua_State *L) ...@@ -1114,6 +1206,9 @@ static int line_get(lua_State *L)
case line_stringargs: case line_stringargs:
LUA_PushUserdata(L, line->stringargs, META_LINESTRINGARGS); LUA_PushUserdata(L, line->stringargs, META_LINESTRINGARGS);
return 1; return 1;
case line_customargs:
LUA_PushUserdata(L, line->customargs, META_LINECUSTOMARGS);
return 1;
case line_sidenum: case line_sidenum:
LUA_PushUserdata(L, line->sidenum, META_SIDENUM); LUA_PushUserdata(L, line->sidenum, META_SIDENUM);
return 1; return 1;
...@@ -1311,6 +1406,33 @@ static int side_get(lua_State *L) ...@@ -1311,6 +1406,33 @@ static int side_get(lua_State *L)
case side_repeatcnt: case side_repeatcnt:
lua_pushinteger(L, side->repeatcnt); lua_pushinteger(L, side->repeatcnt);
return 1; return 1;
case side_light:
lua_pushinteger(L, side->light);
return 1;
case side_light_top:
lua_pushinteger(L, side->light_top);
return 1;
case side_light_mid:
lua_pushinteger(L, side->light_mid);
return 1;
case side_light_bottom:
lua_pushinteger(L, side->light_bottom);
return 1;
case side_lightabsolute:
lua_pushboolean(L, side->lightabsolute);
return 1;
case side_lightabsolute_top:
lua_pushboolean(L, side->lightabsolute_top);
return 1;
case side_lightabsolute_mid:
lua_pushboolean(L, side->lightabsolute_mid);
return 1;
case side_lightabsolute_bottom:
lua_pushboolean(L, side->lightabsolute_bottom);
return 1;
case side_customargs:
LUA_PushUserdata(L, side->customargs, META_SIDECUSTOMARGS);
return 1;
// TODO: 2.3: Delete // TODO: 2.3: Delete
case side_text: case side_text:
{ {
...@@ -1330,6 +1452,7 @@ static int side_get(lua_State *L) ...@@ -1330,6 +1452,7 @@ static int side_get(lua_State *L)
return 1; return 1;
} }
} }
return 0; return 0;
} }
...@@ -1413,6 +1536,30 @@ static int side_set(lua_State *L) ...@@ -1413,6 +1536,30 @@ static int side_set(lua_State *L)
case side_repeatcnt: case side_repeatcnt:
side->repeatcnt = luaL_checkinteger(L, 3); side->repeatcnt = luaL_checkinteger(L, 3);
break; break;
case side_light:
side->light = luaL_checkinteger(L, 3);
break;
case side_light_top:
side->light_top = luaL_checkinteger(L, 3);
break;
case side_light_mid:
side->light_mid = luaL_checkinteger(L, 3);
break;
case side_light_bottom:
side->light_bottom = luaL_checkinteger(L, 3);
break;
case side_lightabsolute:
side->lightabsolute = luaL_checkboolean(L, 3);
break;
case side_lightabsolute_top:
side->lightabsolute_top = luaL_checkboolean(L, 3);
break;
case side_lightabsolute_mid:
side->lightabsolute_mid = luaL_checkboolean(L, 3);
break;
case side_lightabsolute_bottom:
side->lightabsolute_bottom = luaL_checkboolean(L, 3);
break;
} }
return 0; return 0;
} }
...@@ -2997,9 +3144,12 @@ int LUA_MapLib(lua_State *L) ...@@ -2997,9 +3144,12 @@ int LUA_MapLib(lua_State *L)
LUA_RegisterUserdataMetatable(L, META_SECTORLINES, sectorlines_get, NULL, sectorlines_num); LUA_RegisterUserdataMetatable(L, META_SECTORLINES, sectorlines_get, NULL, sectorlines_num);
LUA_RegisterUserdataMetatable(L, META_SECTOR, sector_get, sector_set, sector_num); LUA_RegisterUserdataMetatable(L, META_SECTOR, sector_get, sector_set, sector_num);
LUA_RegisterUserdataMetatable(L, META_SUBSECTOR, subsector_get, NULL, subsector_num); LUA_RegisterUserdataMetatable(L, META_SUBSECTOR, subsector_get, NULL, subsector_num);
LUA_RegisterUserdataMetatable(L, META_SECTORCUSTOMARGS, sectorcustomargs_get, NULL, NULL);
LUA_RegisterUserdataMetatable(L, META_LINE, line_get, NULL, line_num); LUA_RegisterUserdataMetatable(L, META_LINE, line_get, NULL, line_num);
LUA_RegisterUserdataMetatable(L, META_LINEARGS, lineargs_get, NULL, lineargs_len); LUA_RegisterUserdataMetatable(L, META_LINEARGS, lineargs_get, NULL, lineargs_len);
LUA_RegisterUserdataMetatable(L, META_LINESTRINGARGS, linestringargs_get, NULL, linestringargs_len); LUA_RegisterUserdataMetatable(L, META_LINESTRINGARGS, linestringargs_get, NULL, linestringargs_len);
LUA_RegisterUserdataMetatable(L, META_LINECUSTOMARGS, linecustomargs_get, NULL, NULL);
LUA_RegisterUserdataMetatable(L, META_SIDECUSTOMARGS, sidecustomargs_get, NULL, NULL);
LUA_RegisterUserdataMetatable(L, META_SIDENUM, sidenum_get, NULL, NULL); LUA_RegisterUserdataMetatable(L, META_SIDENUM, sidenum_get, NULL, NULL);
LUA_RegisterUserdataMetatable(L, META_SIDE, side_get, side_set, side_num); LUA_RegisterUserdataMetatable(L, META_SIDE, side_get, side_set, side_num);
LUA_RegisterUserdataMetatable(L, META_VERTEX, vertex_get, NULL, vertex_num); LUA_RegisterUserdataMetatable(L, META_VERTEX, vertex_get, NULL, vertex_num);
...@@ -3009,6 +3159,7 @@ int LUA_MapLib(lua_State *L) ...@@ -3009,6 +3159,7 @@ int LUA_MapLib(lua_State *L)
LUA_RegisterUserdataMetatable(L, META_VECTOR2, vector2_get, NULL, NULL); LUA_RegisterUserdataMetatable(L, META_VECTOR2, vector2_get, NULL, NULL);
LUA_RegisterUserdataMetatable(L, META_VECTOR3, vector3_get, NULL, NULL); LUA_RegisterUserdataMetatable(L, META_VECTOR3, vector3_get, NULL, NULL);
LUA_RegisterUserdataMetatable(L, META_MAPHEADER, mapheaderinfo_get, NULL, NULL); LUA_RegisterUserdataMetatable(L, META_MAPHEADER, mapheaderinfo_get, NULL, NULL);
LUA_RegisterUserdataMetatable(L, META_THINGCUSTOMARGS, thingcustomargs_get, NULL, NULL);
sector_fields_ref = Lua_CreateFieldTable(L, sector_opt); sector_fields_ref = Lua_CreateFieldTable(L, sector_opt);
subsector_fields_ref = Lua_CreateFieldTable(L, subsector_opt); subsector_fields_ref = Lua_CreateFieldTable(L, subsector_opt);
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012-2016 by John "JTE" Muniz. // Copyright (C) 2012-2016 by John "JTE" Muniz.
// Copyright (C) 2012-2023 by Sonic Team Junior. // Copyright (C) 2012-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -69,6 +69,7 @@ enum mobj_e { ...@@ -69,6 +69,7 @@ enum mobj_e {
mobj_color, mobj_color,
mobj_translation, mobj_translation,
mobj_blendmode, mobj_blendmode,
mobj_alpha,
mobj_bnext, mobj_bnext,
mobj_bprev, mobj_bprev,
mobj_hnext, mobj_hnext,
...@@ -150,6 +151,7 @@ static const char *const mobj_opt[] = { ...@@ -150,6 +151,7 @@ static const char *const mobj_opt[] = {
"color", "color",
"translation", "translation",
"blendmode", "blendmode",
"alpha",
"bnext", "bnext",
"bprev", "bprev",
"hnext", "hnext",
...@@ -196,12 +198,12 @@ static int mobj_get(lua_State *L) ...@@ -196,12 +198,12 @@ static int mobj_get(lua_State *L)
enum mobj_e field = Lua_optoption(L, 2, -1, mobj_fields_ref); enum mobj_e field = Lua_optoption(L, 2, -1, mobj_fields_ref);
lua_settop(L, 2); lua_settop(L, 2);
if (!mo || !ISINLEVEL) { if (P_MobjWasRemoved(mo) || !ISINLEVEL) {
if (field == mobj_valid) { if (field == mobj_valid) {
lua_pushboolean(L, 0); lua_pushboolean(L, 0);
return 1; return 1;
} }
if (!mo) { if (P_MobjWasRemoved(mo)) {
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
} else } else
return luaL_error(L, "Do not access an mobj_t field outside a level!"); return luaL_error(L, "Do not access an mobj_t field outside a level!");
...@@ -354,6 +356,9 @@ static int mobj_get(lua_State *L) ...@@ -354,6 +356,9 @@ static int mobj_get(lua_State *L)
case mobj_blendmode: case mobj_blendmode:
lua_pushinteger(L, mo->blendmode); lua_pushinteger(L, mo->blendmode);
break; break;
case mobj_alpha:
lua_pushfixed(L, mo->alpha);
break;
case mobj_bnext: case mobj_bnext:
if (mo->blocknode && mo->blocknode->bnext) { if (mo->blocknode && mo->blocknode->bnext) {
LUA_PushUserdata(L, mo->blocknode->bnext->mobj, META_MOBJ); LUA_PushUserdata(L, mo->blocknode->bnext->mobj, META_MOBJ);
...@@ -733,6 +738,16 @@ static int mobj_set(lua_State *L) ...@@ -733,6 +738,16 @@ static int mobj_set(lua_State *L)
mo->blendmode = blendmode; mo->blendmode = blendmode;
break; break;
} }
case mobj_alpha:
{
fixed_t alpha = luaL_checkfixed(L, 3);
if (alpha < 0)
alpha = 0;
else if (alpha > FRACUNIT)
alpha = FRACUNIT;
mo->alpha = alpha;
break;
}
case mobj_bnext: case mobj_bnext:
return NOSETPOS; return NOSETPOS;
case mobj_bprev: case mobj_bprev:
...@@ -958,6 +973,7 @@ enum mapthing_e { ...@@ -958,6 +973,7 @@ enum mapthing_e {
mapthing_taglist, mapthing_taglist,
mapthing_args, mapthing_args,
mapthing_stringargs, mapthing_stringargs,
mapthing_customargs,
mapthing_mobj, mapthing_mobj,
}; };
...@@ -979,6 +995,7 @@ const char *const mapthing_opt[] = { ...@@ -979,6 +995,7 @@ const char *const mapthing_opt[] = {
"taglist", "taglist",
"args", "args",
"stringargs", "stringargs",
"customargs",
"mobj", "mobj",
NULL, NULL,
}; };
...@@ -1057,6 +1074,9 @@ static int mapthing_get(lua_State *L) ...@@ -1057,6 +1074,9 @@ static int mapthing_get(lua_State *L)
case mapthing_stringargs: case mapthing_stringargs:
LUA_PushUserdata(L, mt->stringargs, META_THINGSTRINGARGS); LUA_PushUserdata(L, mt->stringargs, META_THINGSTRINGARGS);
break; break;
case mapthing_customargs:
LUA_PushUserdata(L, mt->customargs, META_THINGCUSTOMARGS);
break;
case mapthing_mobj: case mapthing_mobj:
LUA_PushUserdata(L, mt->mobj, META_MOBJ); LUA_PushUserdata(L, mt->mobj, META_MOBJ);
break; break;
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012-2016 by John "JTE" Muniz. // Copyright (C) 2012-2016 by John "JTE" Muniz.
// Copyright (C) 2012-2023 by Sonic Team Junior. // Copyright (C) 2012-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -226,6 +226,7 @@ enum player_e ...@@ -226,6 +226,7 @@ enum player_e
player_quittime, player_quittime,
player_lastinputtime, player_lastinputtime,
player_ping, player_ping,
player_muted,
player_fovadd player_fovadd
}; };
...@@ -374,6 +375,7 @@ static const char *const player_opt[] = { ...@@ -374,6 +375,7 @@ static const char *const player_opt[] = {
"quittime", "quittime",
"lastinputtime", "lastinputtime",
"ping", "ping",
"muted",
"fovadd", "fovadd",
NULL, NULL,
}; };
...@@ -835,6 +837,9 @@ static int player_get(lua_State *L) ...@@ -835,6 +837,9 @@ static int player_get(lua_State *L)
case player_ping: case player_ping:
lua_pushinteger(L, playerpingtable[plr - players]); lua_pushinteger(L, playerpingtable[plr - players]);
break; break;
case player_muted:
lua_pushboolean(L, plr->muted);
break;
case player_fovadd: case player_fovadd:
lua_pushfixed(L, plr->fovadd); lua_pushfixed(L, plr->fovadd);
break; break;
...@@ -1359,6 +1364,9 @@ static int player_set(lua_State *L) ...@@ -1359,6 +1364,9 @@ static int player_set(lua_State *L)
case player_lastinputtime: case player_lastinputtime:
plr->lastinputtime = (tic_t)luaL_checkinteger(L, 3); plr->lastinputtime = (tic_t)luaL_checkinteger(L, 3);
break; break;
case player_muted:
plr->muted = lua_toboolean(L, 3);
break;
case player_fovadd: case player_fovadd:
plr->fovadd = luaL_checkfixed(L, 3); plr->fovadd = luaL_checkfixed(L, 3);
break; break;
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012-2016 by John "JTE" Muniz. // Copyright (C) 2012-2016 by John "JTE" Muniz.
// Copyright (C) 2012-2023 by Sonic Team Junior. // Copyright (C) 2012-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "r_state.h" #include "r_state.h"
#include "r_sky.h" #include "r_sky.h"
#include "g_game.h" #include "g_game.h"
#include "g_demo.h"
#include "g_input.h" #include "g_input.h"
#include "f_finale.h" #include "f_finale.h"
#include "byteptr.h" #include "byteptr.h"
...@@ -62,6 +63,7 @@ static lua_CFunction liblist[] = { ...@@ -62,6 +63,7 @@ static lua_CFunction liblist[] = {
LUA_HudLib, // HUD stuff LUA_HudLib, // HUD stuff
LUA_ColorLib, // general color functions LUA_ColorLib, // general color functions
LUA_InputLib, // inputs LUA_InputLib, // inputs
LUA_InterceptLib, // intercept_t
NULL NULL
}; };
...@@ -394,6 +396,22 @@ int LUA_PushGlobals(lua_State *L, const char *word) ...@@ -394,6 +396,22 @@ int LUA_PushGlobals(lua_State *L, const char *word)
return 0; return 0;
LUA_PushUserdata(L, &players[serverplayer], META_PLAYER); LUA_PushUserdata(L, &players[serverplayer], META_PLAYER);
return 1; return 1;
// demos booleans
} else if (fastcmp(word, "demoplayback")) {
lua_pushboolean(L, demoplayback);
return 1;
} else if (fastcmp(word, "titledemo")) {
lua_pushboolean(L, titledemo);
return 1;
} else if (fastcmp(word, "demorecording")) {
lua_pushboolean(L, demorecording);
return 1;
} else if (fastcmp(word, "timingdemo")) {
lua_pushboolean(L, timingdemo);
return 1;
} else if (fastcmp(word, "demosynced")) {
lua_pushboolean(L, demosynced);
return 1;
} else if (fastcmp(word,"emeralds")) { } else if (fastcmp(word,"emeralds")) {
lua_pushinteger(L, emeralds); lua_pushinteger(L, emeralds);
return 1; return 1;
...@@ -412,6 +430,9 @@ int LUA_PushGlobals(lua_State *L, const char *word) ...@@ -412,6 +430,9 @@ int LUA_PushGlobals(lua_State *L, const char *word)
} else if (fastcmp(word, "token")) { } else if (fastcmp(word, "token")) {
lua_pushinteger(L, token); lua_pushinteger(L, token);
return 1; return 1;
} else if (fastcmp(word, "nummaprings")) {
lua_pushinteger(L, nummaprings);
return 1;
} else if (fastcmp(word, "gamestate")) { } else if (fastcmp(word, "gamestate")) {
lua_pushinteger(L, gamestate); lua_pushinteger(L, gamestate);
return 1; return 1;
...@@ -437,6 +458,14 @@ int LUA_PushGlobals(lua_State *L, const char *word) ...@@ -437,6 +458,14 @@ int LUA_PushGlobals(lua_State *L, const char *word)
} else if (fastcmp(word, "chatactive")) { } else if (fastcmp(word, "chatactive")) {
lua_pushboolean(L, chat_on); lua_pushboolean(L, chat_on);
return 1; return 1;
} else if (fastcmp(word, "currentsaveslot")) {
if (multiplayer)
return 0;
lua_pushinteger(L, cursaveslot);
return 1;
} else if (fastcmp(word, "gamedatafilename")) {
lua_pushstring(L, strcmp(timeattackfolder, "main") ? timeattackfolder : "gamedata");
return 1;
} }
return 0; return 0;
} }
...@@ -460,6 +489,8 @@ int LUA_CheckGlobals(lua_State *L, const char *word) ...@@ -460,6 +489,8 @@ int LUA_CheckGlobals(lua_State *L, const char *word)
emeralds = (UINT16)luaL_checkinteger(L, 2); emeralds = (UINT16)luaL_checkinteger(L, 2);
else if (fastcmp(word, "token")) else if (fastcmp(word, "token"))
token = (UINT32)luaL_checkinteger(L, 2); token = (UINT32)luaL_checkinteger(L, 2);
else if (fastcmp(word, "nummaprings"))
nummaprings = (INT32)luaL_checkinteger(L, 2);
else if (fastcmp(word, "gravity")) else if (fastcmp(word, "gravity"))
gravity = (fixed_t)luaL_checkinteger(L, 2); gravity = (fixed_t)luaL_checkinteger(L, 2);
else if (fastcmp(word, "stoppedclock")) else if (fastcmp(word, "stoppedclock"))
...@@ -1098,7 +1129,7 @@ static UINT8 GetUserdataArchType(int index) ...@@ -1098,7 +1129,7 @@ static UINT8 GetUserdataArchType(int index)
return ARCH_NULL; return ARCH_NULL;
} }
static UINT8 ArchiveValue(int TABLESINDEX, int myindex) static UINT8 ArchiveValue(save_t *save_p, int TABLESINDEX, int myindex)
{ {
if (myindex < 0) if (myindex < 0)
myindex = lua_gettop(gL)+1+myindex; myindex = lua_gettop(gL)+1+myindex;
...@@ -1106,34 +1137,34 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1106,34 +1137,34 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
case LUA_TNONE: case LUA_TNONE:
case LUA_TNIL: case LUA_TNIL:
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
break; break;
// This might be a problem. D: // This might be a problem. D:
case LUA_TLIGHTUSERDATA: case LUA_TLIGHTUSERDATA:
case LUA_TTHREAD: case LUA_TTHREAD:
case LUA_TFUNCTION: case LUA_TFUNCTION:
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
return 2; return 2;
case LUA_TBOOLEAN: case LUA_TBOOLEAN:
WRITEUINT8(save_p, lua_toboolean(gL, myindex) ? ARCH_TRUE : ARCH_FALSE); P_WriteUINT8(save_p, lua_toboolean(gL, myindex) ? ARCH_TRUE : ARCH_FALSE);
break; break;
case LUA_TNUMBER: case LUA_TNUMBER:
{ {
lua_Integer number = lua_tointeger(gL, myindex); lua_Integer number = lua_tointeger(gL, myindex);
if (number >= INT8_MIN && number <= INT8_MAX) if (number >= INT8_MIN && number <= INT8_MAX)
{ {
WRITEUINT8(save_p, ARCH_INT8); P_WriteUINT8(save_p, ARCH_INT8);
WRITESINT8(save_p, number); P_WriteSINT8(save_p, number);
} }
else if (number >= INT16_MIN && number <= INT16_MAX) else if (number >= INT16_MIN && number <= INT16_MAX)
{ {
WRITEUINT8(save_p, ARCH_INT16); P_WriteUINT8(save_p, ARCH_INT16);
WRITEINT16(save_p, number); P_WriteINT16(save_p, number);
} }
else else
{ {
WRITEUINT8(save_p, ARCH_INT32); P_WriteUINT8(save_p, ARCH_INT32);
WRITEFIXED(save_p, number); P_WriteFixed(save_p, number);
} }
break; break;
} }
...@@ -1144,23 +1175,23 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1144,23 +1175,23 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
UINT32 i = 0; UINT32 i = 0;
// if you're wondering why we're writing a string to save_p this way, // if you're wondering why we're writing a string to save_p this way,
// it turns out that Lua can have embedded zeros ('\0') in the strings, // it turns out that Lua can have embedded zeros ('\0') in the strings,
// so we can't use WRITESTRING as that cuts off when it finds a '\0'. // so we can't use P_WriteString as that cuts off when it finds a '\0'.
// Saving the size of the string also allows us to get the size of the string on the other end, // Saving the size of the string also allows us to get the size of the string on the other end,
// fixing the awful crashes previously encountered for reading strings longer than 1024 // fixing the awful crashes previously encountered for reading strings longer than 1024
// (yes I know that's kind of a stupid thing to care about, but it'd be evil to trim or ignore them?) // (yes I know that's kind of a stupid thing to care about, but it'd be evil to trim or ignore them?)
// -- Monster Iestyn 05/08/18 // -- Monster Iestyn 05/08/18
if (len < 255) if (len < 255)
{ {
WRITEUINT8(save_p, ARCH_SMALLSTRING); P_WriteUINT8(save_p, ARCH_SMALLSTRING);
WRITEUINT8(save_p, len); // save size of string P_WriteUINT8(save_p, len); // save size of string
} }
else else
{ {
WRITEUINT8(save_p, ARCH_LARGESTRING); P_WriteUINT8(save_p, ARCH_LARGESTRING);
WRITEUINT32(save_p, len); // save size of string P_WriteUINT32(save_p, len); // save size of string
} }
while (i < len) while (i < len)
WRITECHAR(save_p, s[i++]); // write chars individually, including the embedded zeros P_WriteChar(save_p, s[i++]); // write chars individually, including the embedded zeros
break; break;
} }
case LUA_TTABLE: case LUA_TTABLE:
...@@ -1186,13 +1217,13 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1186,13 +1217,13 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
if (t == 0) if (t == 0)
{ {
CONS_Alert(CONS_ERROR, "Too many tables to archive!\n"); CONS_Alert(CONS_ERROR, "Too many tables to archive!\n");
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
return 0; return 0;
} }
} }
WRITEUINT8(save_p, ARCH_TABLE); P_WriteUINT8(save_p, ARCH_TABLE);
WRITEUINT16(save_p, t); P_WriteUINT16(save_p, t);
if (!found) if (!found)
{ {
...@@ -1208,25 +1239,25 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1208,25 +1239,25 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
case ARCH_MOBJINFO: case ARCH_MOBJINFO:
{ {
mobjinfo_t *info = *((mobjinfo_t **)lua_touserdata(gL, myindex)); mobjinfo_t *info = *((mobjinfo_t **)lua_touserdata(gL, myindex));
WRITEUINT8(save_p, ARCH_MOBJINFO); P_WriteUINT8(save_p, ARCH_MOBJINFO);
WRITEUINT16(save_p, info - mobjinfo); P_WriteUINT16(save_p, info - mobjinfo);
break; break;
} }
case ARCH_STATE: case ARCH_STATE:
{ {
state_t *state = *((state_t **)lua_touserdata(gL, myindex)); state_t *state = *((state_t **)lua_touserdata(gL, myindex));
WRITEUINT8(save_p, ARCH_STATE); P_WriteUINT8(save_p, ARCH_STATE);
WRITEUINT16(save_p, state - states); P_WriteUINT16(save_p, state - states);
break; break;
} }
case ARCH_MOBJ: case ARCH_MOBJ:
{ {
mobj_t *mobj = *((mobj_t **)lua_touserdata(gL, myindex)); mobj_t *mobj = *((mobj_t **)lua_touserdata(gL, myindex));
if (!mobj) if (!mobj)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_MOBJ); P_WriteUINT8(save_p, ARCH_MOBJ);
WRITEUINT32(save_p, mobj->mobjnum); P_WriteUINT32(save_p, mobj->mobjnum);
} }
break; break;
} }
...@@ -1234,10 +1265,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1234,10 +1265,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
player_t *player = *((player_t **)lua_touserdata(gL, myindex)); player_t *player = *((player_t **)lua_touserdata(gL, myindex));
if (!player) if (!player)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_PLAYER); P_WriteUINT8(save_p, ARCH_PLAYER);
WRITEUINT8(save_p, player - players); P_WriteUINT8(save_p, player - players);
} }
break; break;
} }
...@@ -1245,10 +1276,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1245,10 +1276,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
mapthing_t *mapthing = *((mapthing_t **)lua_touserdata(gL, myindex)); mapthing_t *mapthing = *((mapthing_t **)lua_touserdata(gL, myindex));
if (!mapthing) if (!mapthing)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_MAPTHING); P_WriteUINT8(save_p, ARCH_MAPTHING);
WRITEUINT16(save_p, mapthing - mapthings); P_WriteUINT16(save_p, mapthing - mapthings);
} }
break; break;
} }
...@@ -1256,10 +1287,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1256,10 +1287,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
vertex_t *vertex = *((vertex_t **)lua_touserdata(gL, myindex)); vertex_t *vertex = *((vertex_t **)lua_touserdata(gL, myindex));
if (!vertex) if (!vertex)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_VERTEX); P_WriteUINT8(save_p, ARCH_VERTEX);
WRITEUINT16(save_p, vertex - vertexes); P_WriteUINT16(save_p, vertex - vertexes);
} }
break; break;
} }
...@@ -1267,10 +1298,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1267,10 +1298,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
line_t *line = *((line_t **)lua_touserdata(gL, myindex)); line_t *line = *((line_t **)lua_touserdata(gL, myindex));
if (!line) if (!line)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_LINE); P_WriteUINT8(save_p, ARCH_LINE);
WRITEUINT16(save_p, line - lines); P_WriteUINT16(save_p, line - lines);
} }
break; break;
} }
...@@ -1278,10 +1309,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1278,10 +1309,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
side_t *side = *((side_t **)lua_touserdata(gL, myindex)); side_t *side = *((side_t **)lua_touserdata(gL, myindex));
if (!side) if (!side)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_SIDE); P_WriteUINT8(save_p, ARCH_SIDE);
WRITEUINT16(save_p, side - sides); P_WriteUINT16(save_p, side - sides);
} }
break; break;
} }
...@@ -1289,10 +1320,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1289,10 +1320,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
subsector_t *subsector = *((subsector_t **)lua_touserdata(gL, myindex)); subsector_t *subsector = *((subsector_t **)lua_touserdata(gL, myindex));
if (!subsector) if (!subsector)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_SUBSECTOR); P_WriteUINT8(save_p, ARCH_SUBSECTOR);
WRITEUINT16(save_p, subsector - subsectors); P_WriteUINT16(save_p, subsector - subsectors);
} }
break; break;
} }
...@@ -1300,10 +1331,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1300,10 +1331,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
sector_t *sector = *((sector_t **)lua_touserdata(gL, myindex)); sector_t *sector = *((sector_t **)lua_touserdata(gL, myindex));
if (!sector) if (!sector)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_SECTOR); P_WriteUINT8(save_p, ARCH_SECTOR);
WRITEUINT16(save_p, sector - sectors); P_WriteUINT16(save_p, sector - sectors);
} }
break; break;
} }
...@@ -1312,10 +1343,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1312,10 +1343,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
seg_t *seg = *((seg_t **)lua_touserdata(gL, myindex)); seg_t *seg = *((seg_t **)lua_touserdata(gL, myindex));
if (!seg) if (!seg)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_SEG); P_WriteUINT8(save_p, ARCH_SEG);
WRITEUINT16(save_p, seg - segs); P_WriteUINT16(save_p, seg - segs);
} }
break; break;
} }
...@@ -1323,10 +1354,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1323,10 +1354,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
node_t *node = *((node_t **)lua_touserdata(gL, myindex)); node_t *node = *((node_t **)lua_touserdata(gL, myindex));
if (!node) if (!node)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_NODE); P_WriteUINT8(save_p, ARCH_NODE);
WRITEUINT16(save_p, node - nodes); P_WriteUINT16(save_p, node - nodes);
} }
break; break;
} }
...@@ -1335,16 +1366,16 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1335,16 +1366,16 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
ffloor_t *rover = *((ffloor_t **)lua_touserdata(gL, myindex)); ffloor_t *rover = *((ffloor_t **)lua_touserdata(gL, myindex));
if (!rover) if (!rover)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
UINT16 i = P_GetFFloorID(rover); UINT16 i = P_GetFFloorID(rover);
if (i == UINT16_MAX) // invalid ID if (i == UINT16_MAX) // invalid ID
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else else
{ {
WRITEUINT8(save_p, ARCH_FFLOOR); P_WriteUINT8(save_p, ARCH_FFLOOR);
WRITEUINT16(save_p, rover->target - sectors); P_WriteUINT16(save_p, rover->target - sectors);
WRITEUINT16(save_p, i); P_WriteUINT16(save_p, i);
} }
} }
break; break;
...@@ -1353,10 +1384,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1353,10 +1384,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
polyobj_t *polyobj = *((polyobj_t **)lua_touserdata(gL, myindex)); polyobj_t *polyobj = *((polyobj_t **)lua_touserdata(gL, myindex));
if (!polyobj) if (!polyobj)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_POLYOBJ); P_WriteUINT8(save_p, ARCH_POLYOBJ);
WRITEUINT16(save_p, polyobj-PolyObjects); P_WriteUINT16(save_p, polyobj-PolyObjects);
} }
break; break;
} }
...@@ -1364,10 +1395,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1364,10 +1395,10 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
pslope_t *slope = *((pslope_t **)lua_touserdata(gL, myindex)); pslope_t *slope = *((pslope_t **)lua_touserdata(gL, myindex));
if (!slope) if (!slope)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_SLOPE); P_WriteUINT8(save_p, ARCH_SLOPE);
WRITEUINT16(save_p, slope->id); P_WriteUINT16(save_p, slope->id);
} }
break; break;
} }
...@@ -1375,36 +1406,36 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1375,36 +1406,36 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
{ {
mapheader_t *header = *((mapheader_t **)lua_touserdata(gL, myindex)); mapheader_t *header = *((mapheader_t **)lua_touserdata(gL, myindex));
if (!header) if (!header)
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
else { else {
WRITEUINT8(save_p, ARCH_MAPHEADER); P_WriteUINT8(save_p, ARCH_MAPHEADER);
WRITEUINT16(save_p, header - *mapheaderinfo); P_WriteUINT16(save_p, header - *mapheaderinfo);
} }
break; break;
} }
case ARCH_SKINCOLOR: case ARCH_SKINCOLOR:
{ {
skincolor_t *info = *((skincolor_t **)lua_touserdata(gL, myindex)); skincolor_t *info = *((skincolor_t **)lua_touserdata(gL, myindex));
WRITEUINT8(save_p, ARCH_SKINCOLOR); P_WriteUINT8(save_p, ARCH_SKINCOLOR);
WRITEUINT16(save_p, info - skincolors); P_WriteUINT16(save_p, info - skincolors);
break; break;
} }
case ARCH_MOUSE: case ARCH_MOUSE:
{ {
mouse_t *m = *((mouse_t **)lua_touserdata(gL, myindex)); mouse_t *m = *((mouse_t **)lua_touserdata(gL, myindex));
WRITEUINT8(save_p, ARCH_MOUSE); P_WriteUINT8(save_p, ARCH_MOUSE);
WRITEUINT8(save_p, m == &mouse ? 1 : 2); P_WriteUINT8(save_p, m == &mouse ? 1 : 2);
break; break;
} }
case ARCH_SKIN: case ARCH_SKIN:
{ {
skin_t *skin = *((skin_t **)lua_touserdata(gL, myindex)); skin_t *skin = *((skin_t **)lua_touserdata(gL, myindex));
WRITEUINT8(save_p, ARCH_SKIN); P_WriteUINT8(save_p, ARCH_SKIN);
WRITEUINT8(save_p, skin->skinnum); // UINT8 because MAXSKINS must be <= 256 P_WriteUINT8(save_p, skin->skinnum); // UINT8 because MAXSKINS must be <= 256
break; break;
} }
default: default:
WRITEUINT8(save_p, ARCH_NULL); P_WriteUINT8(save_p, ARCH_NULL);
return 2; return 2;
} }
break; break;
...@@ -1412,14 +1443,14 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex) ...@@ -1412,14 +1443,14 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
return 0; return 0;
} }
static void ArchiveExtVars(void *pointer, const char *ptype) static void ArchiveExtVars(save_t *save_p, void *pointer, const char *ptype)
{ {
int TABLESINDEX; int TABLESINDEX;
UINT16 i; UINT16 i;
if (!gL) { if (!gL) {
if (fastcmp(ptype,"player")) // players must always be included, even if no vars if (fastcmp(ptype,"player")) // players must always be included, even if no vars
WRITEUINT16(save_p, 0); P_WriteUINT16(save_p, 0);
return; return;
} }
...@@ -1435,7 +1466,7 @@ static void ArchiveExtVars(void *pointer, const char *ptype) ...@@ -1435,7 +1466,7 @@ static void ArchiveExtVars(void *pointer, const char *ptype)
{ // no extra values table { // no extra values table
lua_pop(gL, 1); lua_pop(gL, 1);
if (fastcmp(ptype,"player")) // players must always be included, even if no vars if (fastcmp(ptype,"player")) // players must always be included, even if no vars
WRITEUINT16(save_p, 0); P_WriteUINT16(save_p, 0);
return; return;
} }
...@@ -1447,20 +1478,20 @@ static void ArchiveExtVars(void *pointer, const char *ptype) ...@@ -1447,20 +1478,20 @@ static void ArchiveExtVars(void *pointer, const char *ptype)
if (i == 0) if (i == 0)
{ {
if (fastcmp(ptype,"player")) // always include players even if they have no extra variables if (fastcmp(ptype,"player")) // always include players even if they have no extra variables
WRITEUINT16(save_p, 0); P_WriteUINT16(save_p, 0);
lua_pop(gL, 1); lua_pop(gL, 1);
return; return;
} }
if (fastcmp(ptype,"mobj")) // mobjs must write their mobjnum as a header if (fastcmp(ptype,"mobj")) // mobjs must write their mobjnum as a header
WRITEUINT32(save_p, ((mobj_t *)pointer)->mobjnum); P_WriteUINT32(save_p, ((mobj_t *)pointer)->mobjnum);
WRITEUINT16(save_p, i); P_WriteUINT16(save_p, i);
lua_pushnil(gL); lua_pushnil(gL);
while (lua_next(gL, -2)) while (lua_next(gL, -2))
{ {
I_Assert(lua_type(gL, -2) == LUA_TSTRING); I_Assert(lua_type(gL, -2) == LUA_TSTRING);
WRITESTRING(save_p, lua_tostring(gL, -2)); P_WriteString(save_p, lua_tostring(gL, -2));
if (ArchiveValue(TABLESINDEX, -1) == 2) if (ArchiveValue(save_p, TABLESINDEX, -1) == 2)
CONS_Alert(CONS_ERROR, "Type of value for %s entry '%s' (%s) could not be archived!\n", ptype, lua_tostring(gL, -2), luaL_typename(gL, -1)); CONS_Alert(CONS_ERROR, "Type of value for %s entry '%s' (%s) could not be archived!\n", ptype, lua_tostring(gL, -2), luaL_typename(gL, -1));
lua_pop(gL, 1); lua_pop(gL, 1);
} }
...@@ -1468,16 +1499,19 @@ static void ArchiveExtVars(void *pointer, const char *ptype) ...@@ -1468,16 +1499,19 @@ static void ArchiveExtVars(void *pointer, const char *ptype)
lua_pop(gL, 1); lua_pop(gL, 1);
} }
// FIXME: remove and pass as local variable
static save_t *lua_save_p;
static int NetArchive(lua_State *L) static int NetArchive(lua_State *L)
{ {
int TABLESINDEX = lua_upvalueindex(1); int TABLESINDEX = lua_upvalueindex(1);
int i, n = lua_gettop(L); int i, n = lua_gettop(L);
for (i = 1; i <= n; i++) for (i = 1; i <= n; i++)
ArchiveValue(TABLESINDEX, i); ArchiveValue(lua_save_p, TABLESINDEX, i);
return n; return n;
} }
static void ArchiveTables(void) static void ArchiveTables(save_t *save_p)
{ {
int TABLESINDEX; int TABLESINDEX;
UINT16 i, n; UINT16 i, n;
...@@ -1496,14 +1530,14 @@ static void ArchiveTables(void) ...@@ -1496,14 +1530,14 @@ static void ArchiveTables(void)
while (lua_next(gL, -2)) while (lua_next(gL, -2))
{ {
// Write key // Write key
e = ArchiveValue(TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. e = ArchiveValue(save_p, TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this.
if (e == 1) if (e == 1)
n++; // the table contained a new table we'll have to archive. :( n++; // the table contained a new table we'll have to archive. :(
else if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) else if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise)
CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -2), luaL_typename(gL, -2), i); CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -2), luaL_typename(gL, -2), i);
// Write value // Write value
e = ArchiveValue(TABLESINDEX, -1); e = ArchiveValue(save_p, TABLESINDEX, -1);
if (e == 1) if (e == 1)
n++; // the table contained a new table we'll have to archive. :( n++; // the table contained a new table we'll have to archive. :(
else if (e == 2) // invalid value type else if (e == 2) // invalid value type
...@@ -1511,7 +1545,7 @@ static void ArchiveTables(void) ...@@ -1511,7 +1545,7 @@ static void ArchiveTables(void)
lua_pop(gL, 1); lua_pop(gL, 1);
} }
WRITEUINT8(save_p, ARCH_TEND); P_WriteUINT8(save_p, ARCH_TEND);
// Write metatable ID // Write metatable ID
if (lua_getmetatable(gL, -1)) if (lua_getmetatable(gL, -1))
...@@ -1520,19 +1554,19 @@ static void ArchiveTables(void) ...@@ -1520,19 +1554,19 @@ static void ArchiveTables(void)
lua_getfield(gL, LUA_REGISTRYINDEX, LREG_METATABLES); lua_getfield(gL, LUA_REGISTRYINDEX, LREG_METATABLES);
lua_pushvalue(gL, -2); lua_pushvalue(gL, -2);
lua_gettable(gL, -2); lua_gettable(gL, -2);
WRITEUINT16(save_p, lua_isnil(gL, -1) ? 0 : lua_tointeger(gL, -1)); P_WriteUINT16(save_p, lua_isnil(gL, -1) ? 0 : lua_tointeger(gL, -1));
lua_pop(gL, 3); lua_pop(gL, 3);
} }
else else
WRITEUINT16(save_p, 0); P_WriteUINT16(save_p, 0);
lua_pop(gL, 1); lua_pop(gL, 1);
} }
} }
static UINT8 UnArchiveValue(int TABLESINDEX) static UINT8 UnArchiveValue(save_t *save_p, int TABLESINDEX)
{ {
UINT8 type = READUINT8(save_p); UINT8 type = P_ReadUINT8(save_p);
switch (type) switch (type)
{ {
case ARCH_NULL: case ARCH_NULL:
...@@ -1545,13 +1579,13 @@ static UINT8 UnArchiveValue(int TABLESINDEX) ...@@ -1545,13 +1579,13 @@ static UINT8 UnArchiveValue(int TABLESINDEX)
lua_pushboolean(gL, false); lua_pushboolean(gL, false);
break; break;
case ARCH_INT8: case ARCH_INT8:
lua_pushinteger(gL, READSINT8(save_p)); lua_pushinteger(gL, P_ReadSINT8(save_p));
break; break;
case ARCH_INT16: case ARCH_INT16:
lua_pushinteger(gL, READINT16(save_p)); lua_pushinteger(gL, P_ReadINT16(save_p));
break; break;
case ARCH_INT32: case ARCH_INT32:
lua_pushinteger(gL, READFIXED(save_p)); lua_pushinteger(gL, P_ReadFixed(save_p));
break; break;
case ARCH_SMALLSTRING: case ARCH_SMALLSTRING:
case ARCH_LARGESTRING: case ARCH_LARGESTRING:
...@@ -1562,23 +1596,23 @@ static UINT8 UnArchiveValue(int TABLESINDEX) ...@@ -1562,23 +1596,23 @@ static UINT8 UnArchiveValue(int TABLESINDEX)
// See my comments in the ArchiveValue function; // See my comments in the ArchiveValue function;
// it's much the same for reading strings as writing them! // it's much the same for reading strings as writing them!
// (i.e. we can't use READSTRING either) // (i.e. we can't use P_ReadString either)
// -- Monster Iestyn 05/08/18 // -- Monster Iestyn 05/08/18
if (type == ARCH_SMALLSTRING) if (type == ARCH_SMALLSTRING)
len = READUINT8(save_p); // length of string, including embedded zeros len = P_ReadUINT8(save_p); // length of string, including embedded zeros
else else
len = READUINT32(save_p); // length of string, including embedded zeros len = P_ReadUINT32(save_p); // length of string, including embedded zeros
value = malloc(len); // make temp buffer of size len value = malloc(len); // make temp buffer of size len
// now read the actual string // now read the actual string
while (i < len) while (i < len)
value[i++] = READCHAR(save_p); // read chars individually, including the embedded zeros value[i++] = P_ReadChar(save_p); // read chars individually, including the embedded zeros
lua_pushlstring(gL, value, len); // push the string (note: this function supports embedded zeros) lua_pushlstring(gL, value, len); // push the string (note: this function supports embedded zeros)
free(value); // free the buffer free(value); // free the buffer
break; break;
} }
case ARCH_TABLE: case ARCH_TABLE:
{ {
UINT16 tid = READUINT16(save_p); UINT16 tid = P_ReadUINT16(save_p);
lua_rawgeti(gL, TABLESINDEX, tid); lua_rawgeti(gL, TABLESINDEX, tid);
if (lua_isnil(gL, -1)) if (lua_isnil(gL, -1))
{ {
...@@ -1591,69 +1625,69 @@ static UINT8 UnArchiveValue(int TABLESINDEX) ...@@ -1591,69 +1625,69 @@ static UINT8 UnArchiveValue(int TABLESINDEX)
break; break;
} }
case ARCH_MOBJINFO: case ARCH_MOBJINFO:
LUA_PushUserdata(gL, &mobjinfo[READUINT16(save_p)], META_MOBJINFO); LUA_PushUserdata(gL, &mobjinfo[P_ReadUINT16(save_p)], META_MOBJINFO);
break; break;
case ARCH_STATE: case ARCH_STATE:
LUA_PushUserdata(gL, &states[READUINT16(save_p)], META_STATE); LUA_PushUserdata(gL, &states[P_ReadUINT16(save_p)], META_STATE);
break; break;
case ARCH_MOBJ: case ARCH_MOBJ:
LUA_PushUserdata(gL, P_FindNewPosition(READUINT32(save_p)), META_MOBJ); LUA_PushUserdata(gL, P_FindNewPosition(P_ReadUINT32(save_p)), META_MOBJ);
break; break;
case ARCH_PLAYER: case ARCH_PLAYER:
LUA_PushUserdata(gL, &players[READUINT8(save_p)], META_PLAYER); LUA_PushUserdata(gL, &players[P_ReadUINT8(save_p)], META_PLAYER);
break; break;
case ARCH_MAPTHING: case ARCH_MAPTHING:
LUA_PushUserdata(gL, &mapthings[READUINT16(save_p)], META_MAPTHING); LUA_PushUserdata(gL, &mapthings[P_ReadUINT16(save_p)], META_MAPTHING);
break; break;
case ARCH_VERTEX: case ARCH_VERTEX:
LUA_PushUserdata(gL, &vertexes[READUINT16(save_p)], META_VERTEX); LUA_PushUserdata(gL, &vertexes[P_ReadUINT16(save_p)], META_VERTEX);
break; break;
case ARCH_LINE: case ARCH_LINE:
LUA_PushUserdata(gL, &lines[READUINT16(save_p)], META_LINE); LUA_PushUserdata(gL, &lines[P_ReadUINT16(save_p)], META_LINE);
break; break;
case ARCH_SIDE: case ARCH_SIDE:
LUA_PushUserdata(gL, &sides[READUINT16(save_p)], META_SIDE); LUA_PushUserdata(gL, &sides[P_ReadUINT16(save_p)], META_SIDE);
break; break;
case ARCH_SUBSECTOR: case ARCH_SUBSECTOR:
LUA_PushUserdata(gL, &subsectors[READUINT16(save_p)], META_SUBSECTOR); LUA_PushUserdata(gL, &subsectors[P_ReadUINT16(save_p)], META_SUBSECTOR);
break; break;
case ARCH_SECTOR: case ARCH_SECTOR:
LUA_PushUserdata(gL, &sectors[READUINT16(save_p)], META_SECTOR); LUA_PushUserdata(gL, &sectors[P_ReadUINT16(save_p)], META_SECTOR);
break; break;
#ifdef HAVE_LUA_SEGS #ifdef HAVE_LUA_SEGS
case ARCH_SEG: case ARCH_SEG:
LUA_PushUserdata(gL, &segs[READUINT16(save_p)], META_SEG); LUA_PushUserdata(gL, &segs[P_ReadUINT16(save_p)], META_SEG);
break; break;
case ARCH_NODE: case ARCH_NODE:
LUA_PushUserdata(gL, &nodes[READUINT16(save_p)], META_NODE); LUA_PushUserdata(gL, &nodes[P_ReadUINT16(save_p)], META_NODE);
break; break;
#endif #endif
case ARCH_FFLOOR: case ARCH_FFLOOR:
{ {
sector_t *sector = &sectors[READUINT16(save_p)]; sector_t *sector = &sectors[P_ReadUINT16(save_p)];
UINT16 id = READUINT16(save_p); UINT16 id = P_ReadUINT16(save_p);
ffloor_t *rover = P_GetFFloorByID(sector, id); ffloor_t *rover = P_GetFFloorByID(sector, id);
if (rover) if (rover)
LUA_PushUserdata(gL, rover, META_FFLOOR); LUA_PushUserdata(gL, rover, META_FFLOOR);
break; break;
} }
case ARCH_POLYOBJ: case ARCH_POLYOBJ:
LUA_PushUserdata(gL, &PolyObjects[READUINT16(save_p)], META_POLYOBJ); LUA_PushUserdata(gL, &PolyObjects[P_ReadUINT16(save_p)], META_POLYOBJ);
break; break;
case ARCH_SLOPE: case ARCH_SLOPE:
LUA_PushUserdata(gL, P_SlopeById(READUINT16(save_p)), META_SLOPE); LUA_PushUserdata(gL, P_SlopeById(P_ReadUINT16(save_p)), META_SLOPE);
break; break;
case ARCH_MAPHEADER: case ARCH_MAPHEADER:
LUA_PushUserdata(gL, mapheaderinfo[READUINT16(save_p)], META_MAPHEADER); LUA_PushUserdata(gL, mapheaderinfo[P_ReadUINT16(save_p)], META_MAPHEADER);
break; break;
case ARCH_SKINCOLOR: case ARCH_SKINCOLOR:
LUA_PushUserdata(gL, &skincolors[READUINT16(save_p)], META_SKINCOLOR); LUA_PushUserdata(gL, &skincolors[P_ReadUINT16(save_p)], META_SKINCOLOR);
break; break;
case ARCH_MOUSE: case ARCH_MOUSE:
LUA_PushUserdata(gL, READUINT16(save_p) == 1 ? &mouse : &mouse2, META_MOUSE); LUA_PushUserdata(gL, P_ReadUINT16(save_p) == 1 ? &mouse : &mouse2, META_MOUSE);
break; break;
case ARCH_SKIN: case ARCH_SKIN:
LUA_PushUserdata(gL, skins[READUINT8(save_p)], META_SKIN); LUA_PushUserdata(gL, skins[P_ReadUINT8(save_p)], META_SKIN);
break; break;
case ARCH_TEND: case ARCH_TEND:
return 1; return 1;
...@@ -1661,10 +1695,10 @@ static UINT8 UnArchiveValue(int TABLESINDEX) ...@@ -1661,10 +1695,10 @@ static UINT8 UnArchiveValue(int TABLESINDEX)
return 0; return 0;
} }
static void UnArchiveExtVars(void *pointer) static void UnArchiveExtVars(save_t *save_p, void *pointer)
{ {
int TABLESINDEX; int TABLESINDEX;
UINT16 field_count = READUINT16(save_p); UINT16 field_count = P_ReadUINT16(save_p);
UINT16 i; UINT16 i;
char field[1024]; char field[1024];
...@@ -1677,8 +1711,8 @@ static void UnArchiveExtVars(void *pointer) ...@@ -1677,8 +1711,8 @@ static void UnArchiveExtVars(void *pointer)
for (i = 0; i < field_count; i++) for (i = 0; i < field_count; i++)
{ {
READSTRING(save_p, field); P_ReadString(save_p, field);
UnArchiveValue(TABLESINDEX); UnArchiveValue(save_p, TABLESINDEX);
lua_setfield(gL, -2, field); lua_setfield(gL, -2, field);
} }
...@@ -1695,11 +1729,11 @@ static int NetUnArchive(lua_State *L) ...@@ -1695,11 +1729,11 @@ static int NetUnArchive(lua_State *L)
int TABLESINDEX = lua_upvalueindex(1); int TABLESINDEX = lua_upvalueindex(1);
int i, n = lua_gettop(L); int i, n = lua_gettop(L);
for (i = 1; i <= n; i++) for (i = 1; i <= n; i++)
UnArchiveValue(TABLESINDEX); UnArchiveValue(lua_save_p, TABLESINDEX);
return n; return n;
} }
static void UnArchiveTables(void) static void UnArchiveTables(save_t *save_p)
{ {
int TABLESINDEX; int TABLESINDEX;
UINT16 i, n; UINT16 i, n;
...@@ -1716,13 +1750,13 @@ static void UnArchiveTables(void) ...@@ -1716,13 +1750,13 @@ static void UnArchiveTables(void)
lua_rawgeti(gL, TABLESINDEX, i); lua_rawgeti(gL, TABLESINDEX, i);
while (true) while (true)
{ {
UINT8 e = UnArchiveValue(TABLESINDEX); // read key UINT8 e = UnArchiveValue(save_p, TABLESINDEX); // read key
if (e == 1) // End of table if (e == 1) // End of table
break; break;
else if (e == 2) // Key contains a new table else if (e == 2) // Key contains a new table
n++; n++;
if (UnArchiveValue(TABLESINDEX) == 2) // read value if (UnArchiveValue(save_p, TABLESINDEX) == 2) // read value
n++; n++;
if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved)
...@@ -1734,7 +1768,7 @@ static void UnArchiveTables(void) ...@@ -1734,7 +1768,7 @@ static void UnArchiveTables(void)
lua_rawset(gL, -3); lua_rawset(gL, -3);
} }
metatableid = READUINT16(save_p); metatableid = P_ReadUINT16(save_p);
if (metatableid) if (metatableid)
{ {
// setmetatable(table, registry.metatables[metatableid]) // setmetatable(table, registry.metatables[metatableid])
...@@ -1758,7 +1792,7 @@ void LUA_Step(void) ...@@ -1758,7 +1792,7 @@ void LUA_Step(void)
lua_gc(gL, LUA_GCSTEP, 1); lua_gc(gL, LUA_GCSTEP, 1);
} }
void LUA_Archive(void) void LUA_Archive(save_t *save_p)
{ {
INT32 i; INT32 i;
thinker_t *th; thinker_t *th;
...@@ -1771,29 +1805,30 @@ void LUA_Archive(void) ...@@ -1771,29 +1805,30 @@ void LUA_Archive(void)
if (!playeringame[i] && i > 0) // dedicated servers... if (!playeringame[i] && i > 0) // dedicated servers...
continue; continue;
// all players in game will be archived, even if they just add a 0. // all players in game will be archived, even if they just add a 0.
ArchiveExtVars(&players[i], "player"); ArchiveExtVars(save_p, &players[i], "player");
} }
for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next)
{ {
if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) if (th->removing)
continue; continue;
// archive function will determine when to skip mobjs, // archive function will determine when to skip mobjs,
// and write mobjnum in otherwise. // and write mobjnum in otherwise.
ArchiveExtVars(th, "mobj"); ArchiveExtVars(save_p, th, "mobj");
} }
WRITEUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. P_WriteUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum.
lua_save_p = save_p;
LUA_HookNetArchive(NetArchive); // call the NetArchive hook in archive mode LUA_HookNetArchive(NetArchive); // call the NetArchive hook in archive mode
ArchiveTables(); ArchiveTables(save_p);
if (gL) if (gL)
lua_pop(gL, 1); // pop tables lua_pop(gL, 1); // pop tables
} }
void LUA_UnArchive(void) void LUA_UnArchive(save_t *save_p)
{ {
UINT32 mobjnum; UINT32 mobjnum;
INT32 i; INT32 i;
...@@ -1806,23 +1841,24 @@ void LUA_UnArchive(void) ...@@ -1806,23 +1841,24 @@ void LUA_UnArchive(void)
{ {
if (!playeringame[i] && i > 0) // dedicated servers... if (!playeringame[i] && i > 0) // dedicated servers...
continue; continue;
UnArchiveExtVars(&players[i]); UnArchiveExtVars(save_p, &players[i]);
} }
do { do {
mobjnum = READUINT32(save_p); // read a mobjnum mobjnum = P_ReadUINT32(save_p); // read a mobjnum
for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next)
{ {
if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) if (th->removing)
continue; continue;
if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj
continue; continue;
UnArchiveExtVars(th); // apply variables UnArchiveExtVars(save_p, th); // apply variables
} }
} while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker.
lua_save_p = save_p;
LUA_HookNetArchive(NetUnArchive); // call the NetArchive hook in unarchive mode LUA_HookNetArchive(NetUnArchive); // call the NetArchive hook in unarchive mode
UnArchiveTables(); UnArchiveTables(save_p);
if (gL) if (gL)
lua_pop(gL, 1); // pop tables lua_pop(gL, 1); // pop tables
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012-2016 by John "JTE" Muniz. // Copyright (C) 2012-2016 by John "JTE" Muniz.
// Copyright (C) 2012-2023 by Sonic Team Junior. // Copyright (C) 2012-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#ifndef LUA_SCRIPT_H #ifndef LUA_SCRIPT_H
#define LUA_SCRIPT_H #define LUA_SCRIPT_H
#include "p_saveg.h"
#include "m_fixed.h" #include "m_fixed.h"
#include "doomtype.h" #include "doomtype.h"
#include "d_player.h" #include "d_player.h"
...@@ -52,8 +53,8 @@ void LUA_DumpFile(const char *filename); ...@@ -52,8 +53,8 @@ void LUA_DumpFile(const char *filename);
#endif #endif
fixed_t LUA_EvalMath(const char *word); fixed_t LUA_EvalMath(const char *word);
void LUA_Step(void); void LUA_Step(void);
void LUA_Archive(void); void LUA_Archive(save_t *save_p);
void LUA_UnArchive(void); void LUA_UnArchive(save_t *save_p);
int LUA_PushGlobals(lua_State *L, const char *word); int LUA_PushGlobals(lua_State *L, const char *word);
int LUA_CheckGlobals(lua_State *L, const char *word); int LUA_CheckGlobals(lua_State *L, const char *word);
void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2014-2016 by John "JTE" Muniz. // Copyright (C) 2014-2016 by John "JTE" Muniz.
// Copyright (C) 2014-2023 by Sonic Team Junior. // Copyright (C) 2014-2025 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -54,7 +54,8 @@ enum skin { ...@@ -54,7 +54,8 @@ enum skin {
skin_contspeed, skin_contspeed,
skin_contangle, skin_contangle,
skin_soundsid, skin_soundsid,
skin_sprites, skin_sprites, // TODO: 2.3: Delete
skin_skinsprites,
skin_supersprites, skin_supersprites,
skin_natkcolor skin_natkcolor
}; };
...@@ -95,7 +96,8 @@ static const char *const skin_opt[] = { ...@@ -95,7 +96,8 @@ static const char *const skin_opt[] = {
"contspeed", "contspeed",
"contangle", "contangle",
"soundsid", "soundsid",
"sprites", "sprites", // TODO: 2.3: Delete
"skinsprites",
"supersprites", "supersprites",
"natkcolor", "natkcolor",
NULL}; NULL};
...@@ -219,7 +221,10 @@ static int skin_get(lua_State *L) ...@@ -219,7 +221,10 @@ static int skin_get(lua_State *L)
case skin_soundsid: case skin_soundsid:
LUA_PushUserdata(L, skin->soundsid, META_SOUNDSID); LUA_PushUserdata(L, skin->soundsid, META_SOUNDSID);
break; break;
case skin_sprites: case skin_sprites: // TODO: 2.3: Delete
LUA_PushUserdata(L, skin->sprites_compat, META_SKINSPRITESCOMPAT);
break;
case skin_skinsprites:
LUA_PushUserdata(L, skin->sprites, META_SKINSPRITES); LUA_PushUserdata(L, skin->sprites, META_SKINSPRITES);
break; break;
case skin_supersprites: case skin_supersprites:
...@@ -338,15 +343,7 @@ static int soundsid_num(lua_State *L) ...@@ -338,15 +343,7 @@ static int soundsid_num(lua_State *L)
return 1; return 1;
} }
enum spritesopt { // skin.skinsprites[i] -> sprites[i]
numframes = 0
};
static const char *const sprites_opt[] = {
"numframes",
NULL};
// skin.sprites[i] -> sprites[i]
static int lib_getSkinSprite(lua_State *L) static int lib_getSkinSprite(lua_State *L)
{ {
spritedef_t *sksprites = *(spritedef_t **)luaL_checkudata(L, 1, META_SKINSPRITES); spritedef_t *sksprites = *(spritedef_t **)luaL_checkudata(L, 1, META_SKINSPRITES);
...@@ -359,13 +356,46 @@ static int lib_getSkinSprite(lua_State *L) ...@@ -359,13 +356,46 @@ static int lib_getSkinSprite(lua_State *L)
return 1; return 1;
} }
// #skin.sprites -> NUMPLAYERSPRITES // #skin.skinsprites -> NUMPLAYERSPRITES
static int lib_numSkinsSprites(lua_State *L) static int lib_numSkinsSprites(lua_State *L)
{ {
lua_pushinteger(L, NUMPLAYERSPRITES); lua_pushinteger(L, NUMPLAYERSPRITES);
return 1; return 1;
} }
// TODO: 2.3: Delete
// skin.sprites[i] -> sprites[i]
static int lib_getSkinSpriteCompat(lua_State *L)
{
spritedef_t *sksprites = *(spritedef_t **)luaL_checkudata(L, 1, META_SKINSPRITESCOMPAT);
INT32 i = luaL_checkinteger(L, 2) & (SPR2F_MASK | SPR2F_SUPER);
if (i & SPR2F_SUPER)
i = (i & ~SPR2F_SUPER) + NUMPLAYERSPRITES;
if (i < 0 || i >= NUMPLAYERSPRITES*2)
return luaL_error(L, "skin sprites index %d out of range (0 - %d)", i, (NUMPLAYERSPRITES*2)-1);
LUA_PushUserdata(L, &sksprites[i], META_SKINSPRITESLIST);
return 1;
}
// TODO: 2.3: Delete
// #skin.sprites -> NUMPLAYERSPRITES*2
static int lib_numSkinsSpritesCompat(lua_State *L)
{
lua_pushinteger(L, NUMPLAYERSPRITES*2);
return 1;
}
enum spritesopt {
numframes = 0
};
static const char *const sprites_opt[] = {
"numframes",
NULL};
static int sprite_get(lua_State *L) static int sprite_get(lua_State *L)
{ {
spritedef_t *sprite = *(spritedef_t **)luaL_checkudata(L, 1, META_SKINSPRITESLIST); spritedef_t *sprite = *(spritedef_t **)luaL_checkudata(L, 1, META_SKINSPRITESLIST);
...@@ -387,6 +417,7 @@ int LUA_SkinLib(lua_State *L) ...@@ -387,6 +417,7 @@ int LUA_SkinLib(lua_State *L)
LUA_RegisterUserdataMetatable(L, META_SOUNDSID, soundsid_get, NULL, soundsid_num); LUA_RegisterUserdataMetatable(L, META_SOUNDSID, soundsid_get, NULL, soundsid_num);
LUA_RegisterUserdataMetatable(L, META_SKINSPRITES, lib_getSkinSprite, NULL, lib_numSkinsSprites); LUA_RegisterUserdataMetatable(L, META_SKINSPRITES, lib_getSkinSprite, NULL, lib_numSkinsSprites);
LUA_RegisterUserdataMetatable(L, META_SKINSPRITESLIST, sprite_get, NULL, NULL); LUA_RegisterUserdataMetatable(L, META_SKINSPRITESLIST, sprite_get, NULL, NULL);
LUA_RegisterUserdataMetatable(L, META_SKINSPRITESCOMPAT, lib_getSkinSpriteCompat, NULL, lib_numSkinsSpritesCompat); // TODO: 2.3: Delete
skin_fields_ref = Lua_CreateFieldTable(L, skin_opt); skin_fields_ref = Lua_CreateFieldTable(L, skin_opt);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2013-2016 by Matthew "Kaito Sinclaire" Walsh. // Copyright (C) 2013-2016 by Matthew "Kaito Sinclaire" Walsh.
// Copyright (C) 2013 by "Ninji". // Copyright (C) 2013 by "Ninji".
// Copyright (C) 2013-2023 by Sonic Team Junior. // Copyright (C) 2013-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team. // Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior. // Copyright (C) 1999-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -562,7 +562,7 @@ void Command_Teleport_f(void) ...@@ -562,7 +562,7 @@ void Command_Teleport_f(void)
for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next)
{ {
if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) if (th->removing)
continue; continue;
mo2 = (mobj_t *)th; mo2 = (mobj_t *)th;
...@@ -1072,7 +1072,7 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c ...@@ -1072,7 +1072,7 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c
for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next)
{ {
if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) if (th->removing)
continue; continue;
mo = (mobj_t *)th; mo = (mobj_t *)th;
...@@ -1110,9 +1110,9 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c ...@@ -1110,9 +1110,9 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c
mt->pitch = mt->roll = 0; mt->pitch = mt->roll = 0;
// Ignore offsets // Ignore offsets
if (mt->type == MT_EMBLEM) if (mt->type == mobjinfo[MT_EMBLEM].doomednum)
mt->args[1] = 1; mt->args[1] = 1;
else else if (!(mt->type == mobjinfo[MT_METALSONIC_RACE].doomednum || mt->type == mobjinfo[MT_ROSY].doomednum))
mt->args[0] = 1; mt->args[0] = 1;
return mt; return mt;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team. // Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior. // Copyright (C) 1999-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
......
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2012-2016 by Matthew "Kaito Sinclaire" Walsh. // Copyright (C) 2012-2016 by Matthew "Kaito Sinclaire" Walsh.
// Copyright (C) 2012-2023 by Sonic Team Junior. // Copyright (C) 2012-2024 by Sonic Team Junior.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
...@@ -494,6 +494,12 @@ UINT8 M_MapLocked(INT32 mapnum, gamedata_t *data) ...@@ -494,6 +494,12 @@ UINT8 M_MapLocked(INT32 mapnum, gamedata_t *data)
UINT8 M_CampaignWarpIsCheat(INT32 gt, INT32 mapnum, gamedata_t *data) UINT8 M_CampaignWarpIsCheat(INT32 gt, INT32 mapnum, gamedata_t *data)
{ {
if (dedicated)
{
// See M_MapLocked; don't make dedicated servers annoying.
return false;
}
if (M_MapLocked(mapnum, data) == true) if (M_MapLocked(mapnum, data) == true)
{ {
// Warping to locked maps is definitely always a cheat // Warping to locked maps is definitely always a cheat
......