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
Showing with 2835 additions and 272 deletions
......@@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior.
// Copyright (C) 1999-2025 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
......@@ -93,6 +93,7 @@
#endif
#include "lua_script.h"
#include "lua_hud.h"
// Version numbers for netplay :upside_down_face:
int VERSION;
......@@ -227,6 +228,9 @@ void D_ProcessEvents(void)
}
}
if (CON_PreResponder(ev))
continue;
// Screenshots over everything so that they can be taken anywhere.
if (M_ScreenshotResponder(ev))
continue; // ate the event
......@@ -408,13 +412,11 @@ static void D_Display(void)
case GS_LEVEL:
if (!gametic)
break;
HU_Erase();
AM_Drawer();
break;
case GS_INTERMISSION:
Y_IntermissionDrawer();
HU_Erase();
HU_Drawer();
break;
......@@ -429,13 +431,11 @@ static void D_Display(void)
case GS_ENDING:
F_EndingDrawer();
HU_Erase();
HU_Drawer();
break;
case GS_CUTSCENE:
F_CutsceneDrawer();
HU_Erase();
HU_Drawer();
break;
......@@ -445,7 +445,6 @@ static void D_Display(void)
case GS_EVALUATION:
F_GameEvaluationDrawer();
HU_Erase();
HU_Drawer();
break;
......@@ -455,7 +454,6 @@ static void D_Display(void)
case GS_CREDITS:
F_CreditDrawer();
HU_Erase();
HU_Drawer();
break;
......@@ -465,7 +463,6 @@ static void D_Display(void)
{
// I don't think HOM from nothing drawing is independent...
F_WaitingPlayersDrawer();
HU_Erase();
HU_Drawer();
}
case GS_DEDICATEDSERVER:
......@@ -480,11 +477,21 @@ static void D_Display(void)
{
wipegamestate = gamestate;
// clean up border stuff
// see if the border needs to be initially drawn
if (gamestate == GS_LEVEL || (gamestate == GS_TITLESCREEN && titlemapinaction && curbghide && (!hidetitlemap)))
{
// draw the view directly
if (cv_debug)
{
r_renderwalls = cv_renderwalls.value;
r_renderfloors = cv_renderfloors.value;
r_renderthings = cv_renderthings.value;
}
else
{
r_renderwalls = true;
r_renderfloors = true;
r_renderthings = true;
}
if (!automapactive && !dedicated && cv_renderview.value)
{
......@@ -506,23 +513,21 @@ static void D_Display(void)
// render the second screen
if (splitscreen && players[secondarydisplayplayer].mo)
{
#ifdef HWRENDER
if (rendermode != render_soft)
viewwindowy = vid.height / 2;
#ifdef HWRENDER
if (rendermode == render_opengl)
HWR_RenderPlayerView(1, &players[secondarydisplayplayer]);
else
#endif
#endif
if (rendermode != render_none)
{
viewwindowy = vid.height / 2;
M_Memcpy(ylookup, ylookup2, viewheight*sizeof (ylookup[0]));
topleft = screens[0] + viewwindowy*vid.width + viewwindowx;
R_RenderPlayerView(&players[secondarydisplayplayer]);
viewwindowy = 0;
M_Memcpy(ylookup, ylookup1, viewheight*sizeof (ylookup[0]));
}
viewwindowy = 0;
}
// Image postprocessing effect
......@@ -574,7 +579,7 @@ static void D_Display(void)
V_SetPalette(0);
// draw pause pic
if (paused && cv_showhud.value && (!menuactive || netgame))
if (paused && cv_showhud.value && LUA_HudEnabled(hud_pause) && (!menuactive || netgame))
{
#if 0
INT32 py;
......@@ -678,13 +683,13 @@ static void D_Display(void)
s[sizeof s - 1] = '\0';
snprintf(s, sizeof s - 1, "get %d b/s", getbps);
V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-40, V_YELLOWMAP, s);
V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-40, V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "send %d b/s", sendbps);
V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-30, V_YELLOWMAP, s);
V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-30, V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "GameMiss %.2f%%", gamelostpercent);
V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-20, V_YELLOWMAP, s);
V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-20, V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "SysMiss %.2f%%", lostpercent);
V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-10, V_YELLOWMAP, s);
V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-10, V_YELLOWMAP, s);
}
if (cv_perfstats.value)
......@@ -757,9 +762,9 @@ void D_SRB2Loop(void)
/* Smells like a hack... Don't fade Sonic's ass into the title screen. */
if (gamestate != GS_TITLESCREEN)
{
gstartuplumpnum = W_CheckNumForName("STARTUP");
gstartuplumpnum = W_CheckNumForPatchName("STARTUP");
if (gstartuplumpnum == LUMPERROR)
gstartuplumpnum = W_GetNumForName("MISSING");
gstartuplumpnum = W_GetNumForPatchName("MISSING");
V_DrawScaledPatch(0, 0, 0, W_CachePatchNum(gstartuplumpnum, PU_PATCH));
}
......@@ -982,7 +987,7 @@ void D_StartTitle(void)
emeralds = 0;
memset(&luabanks, 0, sizeof(luabanks));
lastmaploaded = 0;
pickedchar = R_SkinAvailable(cv_defaultskin.string);
pickedchar = R_SkinAvailable(cv_skin.string);
// In case someone exits out at the same time they start a time attack run,
// reset modeattacking
......@@ -1023,7 +1028,7 @@ void D_StartTitle(void)
#define REALLOC_FILE_LIST \
if (list->files == NULL) \
{ \
list->files = calloc(sizeof(list->files), 2); \
list->files = calloc(2, sizeof(list->files)); \
list->numfiles = 1; \
} \
else \
......@@ -1178,8 +1183,8 @@ static void IdentifyVersion(void)
// Add the maps
D_AddFile(&startupwadfiles, va(pandf,srb2waddir, "zones.pk3"));
// Add the players
D_AddFile(&startupwadfiles, va(pandf,srb2waddir, "player.dta"));
// Add the characters
D_AddFile(&startupwadfiles, va(pandf,srb2waddir, "characters.pk3"));
#ifdef USE_PATCH_DTA
// Add our crappy patches to fix our bugs
......@@ -1198,7 +1203,7 @@ static void IdentifyVersion(void)
I_Error("File "str" has been modified with non-music/sound lumps"); \
}
MUSICTEST("music.dta")
MUSICTEST("music.pk3")
//MUSICTEST("patch_music.pk3")
}
#endif
......@@ -1249,7 +1254,7 @@ void D_SRB2Main(void)
// Print GPL notice for our console users (Linux)
CONS_Printf(
"\n\nSonic Robo Blast 2\n"
"Copyright (C) 1998-2023 by Sonic Team Junior\n\n"
"Copyright (C) 1998-2025 by Sonic Team Junior\n\n"
"This program comes with ABSOLUTELY NO WARRANTY.\n\n"
"This is free software, and you are welcome to redistribute it\n"
"and/or modify it under the terms of the GNU General Public License\n"
......@@ -1295,7 +1300,7 @@ void D_SRB2Main(void)
#endif
// for dedicated server
#if !defined (_WINDOWS) //already check in win_main.c
#if !defined (_WINDOWS) && !defined (DEDICATED) //already check in win_main.c
dedicated = M_CheckParm("-dedicated") != 0;
#endif
......@@ -1430,7 +1435,7 @@ void D_SRB2Main(void)
// Make backups of some SOCcable tables.
P_BackupTables();
mainwads = 3; // doesn't include music.dta
mainwads = 3; // doesn't include music.pk3
#ifdef USE_PATCH_DTA
mainwads++;
#endif
......@@ -1445,11 +1450,11 @@ void D_SRB2Main(void)
// Check MD5s of autoloaded files
W_VerifyFileMD5(0, ASSET_HASH_SRB2_PK3); // srb2.pk3
W_VerifyFileMD5(1, ASSET_HASH_ZONES_PK3); // zones.pk3
W_VerifyFileMD5(2, ASSET_HASH_PLAYER_DTA); // player.dta
W_VerifyFileMD5(2, ASSET_HASH_CHARACTERS_PK3); // characters.pk3
#ifdef USE_PATCH_DTA
W_VerifyFileMD5(3, ASSET_HASH_PATCH_PK3); // patch.pk3
#endif
// don't check music.dta because people like to modify it, and it doesn't matter if they do
// don't check music.pk3 because people like to modify it, and it doesn't matter if they do
// ...except it does if they slip maps in there, and that's what W_VerifyNMUSlumps is for.
#endif //ifndef DEVELOP
......@@ -1512,9 +1517,7 @@ void D_SRB2Main(void)
G_LoadGameData(clientGamedata);
M_CopyGameData(serverGamedata, clientGamedata);
#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL)
VID_PrepareModeList(); // Regenerate Modelist according to cv_fullscreen
#endif
// set user default mode or mode set at cmdline
SCR_CheckDefaultMode();
......@@ -1536,7 +1539,7 @@ void D_SRB2Main(void)
I_Error("Cannot find a map remotely named '%s'\n", word);
else
{
if (!M_CheckParm("-server"))
if (!(M_CheckParm("-server") || dedicated))
G_SetUsedCheats(true);
autostart = true;
}
......@@ -1601,7 +1604,7 @@ void D_SRB2Main(void)
{
if (!M_IsNextParm())
I_Error("usage: -room <room_id>\nCheck the Master Server's webpage for room ID numbers.\n");
ms_RoomId = atoi(M_GetNextParm());
CV_SetValue(&cv_masterserver_room_id, atoi(M_GetNextParm()));
#ifdef UPDATE_ALERT
GetMODVersion_Console();
......@@ -1843,17 +1846,21 @@ static boolean check_top_dir(const char **path, const char *top)
return true;
}
static int cmp_strlen_desc(const void *a, const void *b)
static int cmp_strlen_desc(const void *A, const void *B)
{
return ((int)strlen(*(const char*const*)b) - (int)strlen(*(const char*const*)a));
const char *pA = A;
const char *pB = B;
size_t As = strlen(pA);
size_t Bs = strlen(pB);
return ((int)Bs - (int)As);
}
boolean D_IsPathAllowed(const char *path)
{
const char *paths[] = {
char *paths[] = {
srb2home,
srb2path,
cv_addons_folder.string
cv_addons_folder.zstring
};
const size_t n_paths = sizeof paths / sizeof *paths;
......
......@@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior.
// Copyright (C) 1999-2025 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
......@@ -45,14 +45,16 @@ typedef enum
SF_MARIODAMAGE = SF_NOJUMPDAMAGE|SF_STOMPDAMAGE, // The Mario method of being able to damage enemies, etc.
SF_MACHINE = 1<<10, // Beep boop. Are you a robot?
SF_DASHMODE = 1<<11, // Sonic Advance 2 style top speed increase?
SF_FASTEDGE = 1<<12, // Faster edge teeter?
SF_MULTIABILITY = 1<<13, // Revenge of Final Demo.
SF_NONIGHTSROTATION = 1<<14, // Disable sprite rotation for NiGHTS
SF_NONIGHTSSUPER = 1<<15, // Disable super colors for NiGHTS (if you have SF_SUPER)
SF_NOSUPERSPRITES = 1<<16, // Don't use super sprites while super
SF_NOSUPERJUMPBOOST = 1<<17, // Disable the jump boost given while super (i.e. Knuckles)
SF_CANBUSTWALLS = 1<<18, // Can naturally bust walls on contact? (i.e. Knuckles)
SF_NOSHIELDABILITY = 1<<19, // Disable shield abilities
SF_FASTWAIT = 1<<12, // Faster wait animation?
SF_FASTEDGE = 1<<13, // Faster edge teeter?
SF_JETFUME = 1<<14, // Follow item uses Metal Sonic's jet fume behavior
SF_MULTIABILITY = 1<<15, // Revenge of Final Demo.
SF_NONIGHTSROTATION = 1<<16, // Disable sprite rotation for NiGHTS
SF_NONIGHTSSUPER = 1<<17, // Disable super sprites and colors for NiGHTS
SF_NOSUPERSPRITES = 1<<18, // Don't use super sprites while super
SF_NOSUPERJUMPBOOST = 1<<19, // Disable the jump boost given while super (i.e. Knuckles)
SF_CANBUSTWALLS = 1<<20, // Can naturally bust walls on contact? (i.e. Knuckles)
SF_NOSHIELDABILITY = 1<<21, // Disable shield abilities
// free up to and including 1<<31
} skinflags_t;
......@@ -158,10 +160,6 @@ typedef enum
PF_FORCESTRAFE = 1<<28, // Turning inputs are translated into strafing inputs
PF_CANCARRY = 1<<29, // Can carry another player?
PF_FINISHED = 1<<30, // The player finished the level. NOT the same as exiting
// True if shield button down last tic
// This may be the final flag, but 2.3 could free up the others
PF_SHIELDDOWN = 1<<31,
// up to 1<<31 is free
} pflags_t;
......@@ -373,6 +371,16 @@ typedef enum
AI_SPINFOLLOW
} aistatetype_t;
// NiGHTS text
typedef enum
{
NTV_NONE = 0,
NTV_GETSPHERES,
NTV_GETMORESPHERES,
NTV_BONUSTIMESTART,
NTV_BONUSTIMEEND,
} nightstextvar_t;
// ========================================================================
// PLAYER STRUCTURE
......@@ -572,7 +580,8 @@ typedef struct player_s
// Statistical purposes.
tic_t marebegunat; // Leveltime when mare begun
tic_t startedtime; // Time which you started this mare with.
tic_t finishedtime; // Time it took you to finish the mare (used for display)
tic_t finishedtime; // The time it took to destroy the capsule on this mare (used for bonus time display)
tic_t lastmaretime; // The time it took to complete the last mare (used for rank display)
tic_t lapbegunat; // Leveltime when lap begun
tic_t lapstartedtime; // Time which you started this lap with.
INT16 finishedspheres; // The spheres you had left upon finishing the mare
......@@ -587,7 +596,7 @@ typedef struct player_s
UINT8 totalmarebonuslap; // total mare bonus lap
INT32 maxlink; // maximum link obtained
UINT8 texttimer; // nights_texttime should not be local
UINT8 textvar; // which line of NiGHTS text to show -- let's not use cheap hacks
UINT8 textvar; // which line of NiGHTS text to show -- see nightstextvar_t
INT16 lastsidehit, lastlinehit;
......@@ -603,6 +612,7 @@ typedef struct player_s
boolean spectator;
boolean outofcoop;
boolean removing;
boolean muted;
UINT8 bot;
struct player_s *botleader;
UINT16 lastbuttons;
......
......@@ -51,6 +51,8 @@ typedef struct thinker_s
// killough 11/98: count of how many other objects reference
// this one using pointers. Used for garbage collection.
INT32 references;
boolean removing;
boolean cachable;
#ifdef PARANOIA
......
......@@ -26,23 +26,20 @@
// Button/action code definitions.
typedef enum
{
// First 3 bits are weapon change info, DO NOT USE!
BT_WEAPONMASK = 0x07, //our first three bits.
BT_SHIELD = 1<<3, // shield or super action
// First 4 bits are weapon change info, DO NOT USE!
BT_WEAPONMASK = 0x0F, //our first four bits.
BT_WEAPONNEXT = 1<<4, // select next weapon
BT_WEAPONPREV = 1<<5, // select previous weapon
BT_WEAPONNEXT = 1<<4,
BT_WEAPONPREV = 1<<5,
BT_ATTACK = 1<<6, // shoot rings
BT_SPIN = 1<<7,
BT_CAMLEFT = 1<<8, // turn camera left
BT_CAMRIGHT = 1<<9, // turn camera right
BT_TOSSFLAG = 1<<10,
BT_JUMP = 1<<11,
BT_FIRENORMAL = 1<<12, // Fire a normal ring no matter what
BT_ATTACK = 1<<6, // shoot rings
BT_SPIN = 1<<7, // spin action
BT_CAMLEFT = 1<<8, // turn camera left
BT_CAMRIGHT = 1<<9, // turn camera right
BT_TOSSFLAG = 1<<10, // toss flag or emeralds
BT_JUMP = 1<<11, // jump action
BT_FIRENORMAL = 1<<12, // fire a normal ring no matter what
// custom lua buttons
BT_CUSTOM1 = 1<<13,
BT_CUSTOM2 = 1<<14,
BT_CUSTOM3 = 1<<15,
......
i_net.c
i_system.c
i_main.c
i_video.c
i_sound.c
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 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 d_main.c
/// \brief Main program, simply calls D_SRB2Main and D_SRB2Loop, the high level loop.
#include "../doomdef.h"
#include "../m_argv.h"
#include "../d_main.h"
#include "../m_misc.h"/* path shit */
#include "../i_system.h"
#include "../netcode/d_clisrv.h"
#if defined (__GNUC__) || defined (__unix__)
#include <unistd.h>
#endif
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
#include <errno.h>
#endif
#include "time.h" // For log timestamps
#ifdef LOGMESSAGES
FILE *logstream = NULL;
char logfilename[1024];
#endif
#ifndef DOXYGEN
#ifndef O_TEXT
#define O_TEXT 0
#endif
#ifndef O_SEQUENTIAL
#define O_SEQUENTIAL 0
#endif
#endif
#if defined (_WIN32)
#include "../win32/win_dbg.h"
typedef BOOL (WINAPI *p_IsDebuggerPresent)(VOID);
#endif
#ifdef LOGMESSAGES
static void InitLogging(void)
{
const char *logdir = NULL;
time_t my_time;
struct tm * timeinfo;
const char *format;
const char *reldir;
int left;
boolean fileabs;
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
const char *link;
#endif
logdir = D_Home();
my_time = time(NULL);
timeinfo = localtime(&my_time);
if (M_CheckParm("-logfile") && M_IsNextParm())
{
format = M_GetNextParm();
fileabs = M_IsPathAbsolute(format);
}
else
{
format = "log-%Y-%m-%d_%H-%M-%S.txt";
fileabs = false;
}
if (fileabs)
{
strftime(logfilename, sizeof logfilename, format, timeinfo);
}
else
{
if (M_CheckParm("-logdir") && M_IsNextParm())
reldir = M_GetNextParm();
else
reldir = "logs";
if (M_IsPathAbsolute(reldir))
{
left = snprintf(logfilename, sizeof logfilename,
"%s"PATHSEP, reldir);
}
else
#ifdef DEFAULTDIR
if (logdir)
{
left = snprintf(logfilename, sizeof logfilename,
"%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir);
}
else
#endif/*DEFAULTDIR*/
{
left = snprintf(logfilename, sizeof logfilename,
"."PATHSEP"%s"PATHSEP, reldir);
}
strftime(&logfilename[left], sizeof logfilename - left,
format, timeinfo);
}
M_MkdirEachUntil(logfilename,
M_PathParts(logdir) - 1,
M_PathParts(logfilename) - 1, 0755);
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
logstream = fopen(logfilename, "w");
#ifdef DEFAULTDIR
if (logdir)
link = va("%s/"DEFAULTDIR"/latest-log.txt", logdir);
else
#endif/*DEFAULTDIR*/
link = "latest-log.txt";
unlink(link);
if (symlink(logfilename, link) == -1)
{
I_OutputMsg("Error symlinking latest-log.txt: %s\n", strerror(errno));
}
#else/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/
logstream = fopen("latest-log.txt", "wt+");
#endif/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/
}
#endif
/** \brief The main function
\param argc number of arg
\param *argv string table
\return int
*/
#if defined (__GNUC__) && (__GNUC__ >= 4)
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#endif
int main(int argc, char **argv)
{
myargc = argc;
myargv = argv; /// \todo pull out path to exe from this string
dedicated = true;
#ifdef LOGMESSAGES
if (!M_CheckParm("-nolog"))
InitLogging();
#endif/*LOGMESSAGES*/
//I_OutputMsg("I_StartupSystem() ...\n");
I_StartupSystem();
#if defined (_WIN32)
LoadLibraryA("exchndl.dll");
#ifndef __MINGW32__
prevExceptionFilter = SetUnhandledExceptionFilter(RecordExceptionInfo);
#endif
#endif
// startup SRB2
CONS_Printf("Setting up SRB2...\n");
D_SRB2Main();
#ifdef LOGMESSAGES
if (!M_CheckParm("-nolog"))
CONS_Printf("Logfile: %s\n", logfilename);
#endif
CONS_Printf("Entering main game loop...\n");
// never return
D_SRB2Loop();
#ifdef BUGTRAP
// This is safe even if BT didn't start.
ShutdownBugTrap();
#endif
// return to OS
return 0;
}
#include "../netcode/i_net.h"
boolean I_InitNetwork(void)
{
// NOTE: this is no longer used.
return false;
}
#include "../i_sound.h"
UINT8 sound_started = 0;
void *I_GetSfx(sfxinfo_t *sfx)
{
(void)sfx;
return NULL;
}
void I_FreeSfx(sfxinfo_t *sfx)
{
(void)sfx;
}
void I_StartupSound(void){}
void I_ShutdownSound(void){}
void I_UpdateSound(void){};
//
// SFX I/O
//
INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority, INT32 channel)
{
(void)id;
(void)vol;
(void)sep;
(void)pitch;
(void)priority;
(void)channel;
return -1;
}
void I_StopSound(INT32 handle)
{
(void)handle;
}
boolean I_SoundIsPlaying(INT32 handle)
{
(void)handle;
return false;
}
void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep, UINT8 pitch)
{
(void)handle;
(void)vol;
(void)sep;
(void)pitch;
}
void I_SetSfxVolume(UINT8 volume)
{
(void)volume;
}
/// ------------------------
// MUSIC SYSTEM
/// ------------------------
void I_InitMusic(void){}
void I_ShutdownMusic(void){}
/// ------------------------
// MUSIC PROPERTIES
/// ------------------------
musictype_t I_SongType(void)
{
return MU_NONE;
}
boolean I_SongPlaying(void)
{
return false;
}
boolean I_SongPaused(void)
{
return false;
}
/// ------------------------
// MUSIC EFFECTS
/// ------------------------
boolean I_SetSongSpeed(float speed)
{
(void)speed;
return false;
}
/// ------------------------
// MUSIC SEEKING
/// ------------------------
UINT32 I_GetSongLength(void)
{
return 0;
}
boolean I_SetSongLoopPoint(UINT32 looppoint)
{
(void)looppoint;
return false;
}
UINT32 I_GetSongLoopPoint(void)
{
return 0;
}
boolean I_SetSongPosition(UINT32 position)
{
(void)position;
return false;
}
UINT32 I_GetSongPosition(void)
{
return 0;
}
/// ------------------------
// MUSIC PLAYBACK
/// ------------------------
boolean I_LoadSong(char *data, size_t len)
{
(void)data;
(void)len;
return -1;
}
void I_UnloadSong(void)
{
}
boolean I_PlaySong(boolean looping)
{
(void)looping;
return false;
}
void I_StopSong(void)
{
}
void I_PauseSong(void)
{
}
void I_ResumeSong(void)
{
}
void I_SetMusicVolume(UINT8 volume)
{
(void)volume;
}
boolean I_SetSongTrack(INT32 track)
{
(void)track;
return false;
}
/// ------------------------
// MUSIC FADING
/// ------------------------
void I_SetInternalMusicVolume(UINT8 volume)
{
(void)volume;
}
void I_StopFadingSong(void)
{
}
boolean I_FadeSongFromVolume(UINT8 target_volume, UINT8 source_volume, UINT32 ms, void (*callback)(void))
{
(void)target_volume;
(void)source_volume;
(void)ms;
(void)callback;
return false;
}
boolean I_FadeSong(UINT8 target_volume, UINT32 ms, void (*callback)(void))
{
(void)target_volume;
(void)ms;
(void)callback;
return false;
}
boolean I_FadeOutStopSong(UINT32 ms)
{
(void)ms;
return false;
}
boolean I_FadeInPlaySong(UINT32 ms, boolean looping)
{
(void)ms;
(void)looping;
return false;
}
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
//
// Copyright (C) 1993-1996 by id Software, Inc.
// Portions Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 2014-2025 by Sonic Team Junior.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// Changes by Graue <graue@oceanbase.org> are in the public domain.
//
//-----------------------------------------------------------------------------
/// \file
/// \brief SRB2 system stuff for dedicated servers
#include <signal.h>
#ifdef _WIN32
#define RPC_NO_WINDOWS_H
#include <windows.h>
#include "../doomtype.h"
typedef BOOL (WINAPI *p_GetDiskFreeSpaceExA)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
typedef BOOL (WINAPI *p_IsProcessorFeaturePresent) (DWORD);
typedef DWORD (WINAPI *p_timeGetTime) (void);
typedef UINT (WINAPI *p_timeEndPeriod) (UINT);
typedef HANDLE (WINAPI *p_OpenFileMappingA) (DWORD, BOOL, LPCSTR);
typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
// This is for RtlGenRandom.
#define SystemFunction036 NTAPI SystemFunction036
#include <ntsecapi.h>
#undef SystemFunction036
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __GNUC__
#include <unistd.h>
#elif defined (_MSC_VER)
#include <direct.h>
#endif
#if defined (__unix__) || defined (UNIXCOMMON)
#include <fcntl.h>
#endif
#include <stdio.h>
#ifdef _WIN32
#include <conio.h>
#endif
#ifdef _MSC_VER
#pragma warning(disable : 4214 4244)
#endif
#ifdef _MSC_VER
#pragma warning(default : 4214 4244)
#endif
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
#if defined (__linux__) || defined (__HAIKU__)
#include <sys/statvfs.h>
#else
#include <sys/statvfs.h>
#include <sys/param.h>
#include <sys/mount.h>
/*For meminfo*/
#include <sys/types.h>
#ifdef FREEBSD
#include <kvm.h>
#endif
#include <nlist.h>
#include <sys/sysctl.h>
#endif
#endif
#if defined (__linux__) || defined (UNIXCOMMON)
#ifndef NOTERMIOS
#include <termios.h>
#include <sys/ioctl.h> // ioctl
#define HAVE_TERMIOS
#endif
#endif
#if defined(UNIXCOMMON)
#include <poll.h>
#endif
#if defined (__unix__) || (defined (UNIXCOMMON) && !defined (__APPLE__))
#include <errno.h>
#include <sys/wait.h>
#ifndef __HAIKU__ // haiku's crash dialog is just objectively better
#define NEWSIGNALHANDLER
#endif
#endif
#ifndef NOMUMBLE
#ifdef __linux__ // need -lrt
#include <sys/mman.h>
#ifdef MAP_FAILED
#define HAVE_SHM
#endif
#include <wchar.h>
#endif
#ifdef _WIN32
#define HAVE_MUMBLE
#define WINMUMBLE
#elif defined (HAVE_SHM)
#define HAVE_MUMBLE
#endif
#endif // NOMUMBLE
#ifndef O_BINARY
#define O_BINARY 0
#endif
#ifdef __APPLE__
#include "macosx/mac_resources.h"
#endif
#ifndef errno
#include <errno.h>
#endif
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
#ifndef NOEXECINFO
#include <execinfo.h>
#endif
#include <time.h>
#define UNIXBACKTRACE
#endif
// Locations to directly check for srb2.pk3 in
const char *wadDefaultPaths[] = {
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
"/usr/local/share/games/SRB2",
"/usr/local/games/SRB2",
"/usr/share/games/SRB2",
"/usr/games/SRB2",
#elif defined (_WIN32)
"c:\\games\\srb2",
"\\games\\srb2",
#endif
NULL
};
// Folders to recurse through looking for srb2.pk3
const char *wadSearchPaths[] = {
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
"/usr/local/games",
"/usr/games",
"/usr/local",
#elif defined (_WIN32)
"c:\\games",
"\\games",
#endif
NULL
};
/** \brief WAD file to look for
*/
#define WADKEYWORD1 "srb2.pk3"
/** \brief holds wad path
*/
static char returnWadPath[256];
//Alam_GBC: SDL
#include "../doomdef.h"
#include "../m_misc.h"
#include "../i_time.h"
#include "../i_video.h"
#include "../i_sound.h"
#include "../i_system.h"
#include "../i_threads.h"
#include "../screen.h" //vid.WndParent
#include "../netcode/d_net.h"
#include "../netcode/commands.h"
#include "../g_game.h"
#include "../filesrch.h"
#include "../i_joy.h"
#include "../m_argv.h"
#include "../r_main.h" // Frame interpolation/uncapped
#include "../r_fps.h"
#ifdef MAC_ALERT
#include "macosx/mac_alert.h"
#endif
#include "../d_main.h"
#if !defined(NOMUMBLE) && defined(HAVE_MUMBLE)
// Mumble context string
#include "../netcode/d_clisrv.h"
#include "../byteptr.h"
#endif
#define MAX_EXIT_FUNCS 32
// A little more than the minimum sleep duration on Windows.
// May be incorrect for other platforms, but we don't currently have a way to
// query the scheduler granularity. SDL will do what's needed to make this as
// low as possible though.
#define MIN_SLEEP_DURATION_MS 2.1
UINT8 graphics_started = 0;
UINT8 keyboard_started = 0;
static boolean consolevent = false;
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
static boolean framebuffer = false;
#endif
static size_t num_exit_funcs;
static void (*exit_funcs[MAX_EXIT_FUNCS])(void);
static boolean is_quitting = false;
#ifdef __linux__
#define MEMINFO_FILE "/proc/meminfo"
#define MEMTOTAL "MemTotal:"
#define MEMAVAILABLE "MemAvailable:"
#define MEMFREE "MemFree:"
#define CACHED "Cached:"
#define BUFFERS "Buffers:"
#define SHMEM "Shmem:"
/* Parse the contents of /proc/meminfo (in buf), return value of "name"
* (example: MemTotal) */
static long get_entry(const char* name, const char* buf)
{
long val;
char* hit = strstr(buf, name);
if (hit == NULL) {
return -1;
}
errno = 0;
val = strtol(hit + strlen(name), NULL, 10);
if (errno != 0) {
CONS_Alert(CONS_ERROR, M_GetText("get_entry: strtol() failed: %s\n"), strerror(errno));
return -1;
}
return val;
}
#endif
size_t I_GetFreeMem(size_t *total)
{
#ifdef FREEBSD
u_int v_free_count, v_page_size, v_page_count;
size_t size = sizeof(v_free_count);
sysctlbyname("vm.stats.vm.v_free_count", &v_free_count, &size, NULL, 0);
size = sizeof(v_page_size);
sysctlbyname("vm.stats.vm.v_page_size", &v_page_size, &size, NULL, 0);
size = sizeof(v_page_count);
sysctlbyname("vm.stats.vm.v_page_count", &v_page_count, &size, NULL, 0);
if (total)
*total = v_page_count * v_page_size;
return v_free_count * v_page_size;
#elif defined (SOLARIS)
/* Just guess */
if (total)
*total = 32 << 20;
return 32 << 20;
#elif defined (_WIN32)
MEMORYSTATUS info;
info.dwLength = sizeof (MEMORYSTATUS);
GlobalMemoryStatus( &info );
if (total)
*total = (size_t)info.dwTotalPhys;
return (size_t)info.dwAvailPhys;
#elif defined (__linux__)
/* Linux */
char buf[1024];
char *memTag;
size_t freeKBytes;
size_t totalKBytes;
INT32 n;
INT32 meminfo_fd = -1;
long Cached;
long MemFree;
long Buffers;
long Shmem;
long MemAvailable = -1;
meminfo_fd = open(MEMINFO_FILE, O_RDONLY);
n = read(meminfo_fd, buf, 1023);
close(meminfo_fd);
if (n < 0)
{
// Error
if (total)
*total = 0L;
return 0;
}
buf[n] = '\0';
if ((memTag = strstr(buf, MEMTOTAL)) == NULL)
{
// Error
if (total)
*total = 0L;
return 0;
}
memTag += sizeof (MEMTOTAL);
totalKBytes = (size_t)atoi(memTag);
if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL)
{
Cached = get_entry(CACHED, buf);
MemFree = get_entry(MEMFREE, buf);
Buffers = get_entry(BUFFERS, buf);
Shmem = get_entry(SHMEM, buf);
MemAvailable = Cached + MemFree + Buffers - Shmem;
if (MemAvailable == -1)
{
// Error
if (total)
*total = 0L;
return 0;
}
freeKBytes = MemAvailable;
}
else
{
memTag += sizeof (MEMAVAILABLE);
freeKBytes = atoi(memTag);
}
if (total)
*total = totalKBytes << 10;
return freeKBytes << 10;
#else
// Guess 48 MB.
if (total)
*total = 48<<20;
return 48<<20;
#endif
}
void I_Sleep(UINT32 ms)
{
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
struct timespec ts = {
.tv_sec = ms / 1000,
.tv_nsec = ms % 1000 * 1000000,
};
int status;
do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts);
while (status == EINTR);
#elif defined (_WIN32)
Sleep(ms);
#else
(void)ms;
#warning No sleep function for this system!
#endif
}
void I_SleepDuration(precise_t duration)
{
#if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__)
UINT64 precision = I_GetPrecisePrecision();
precise_t dest = I_GetPreciseTime() + duration;
precise_t slack = (precision / 5000); // 0.2 ms slack
if (duration > slack)
{
duration -= slack;
struct timespec ts = {
.tv_sec = duration / precision,
.tv_nsec = duration * 1000000000 / precision % 1000000000,
};
int status;
do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts);
while (status == EINTR);
}
// busy-wait the rest
while (((INT64)dest - (INT64)I_GetPreciseTime()) > 0);
#else
UINT64 precision = I_GetPrecisePrecision();
INT32 sleepvalue = cv_sleep.value;
UINT64 delaygranularity;
precise_t cur;
precise_t dest;
{
double gran = round(((double)(precision / 1000) * sleepvalue * MIN_SLEEP_DURATION_MS));
delaygranularity = (UINT64)gran;
}
cur = I_GetPreciseTime();
dest = cur + duration;
// the reason this is not dest > cur is because the precise counter may wrap
// two's complement arithmetic is our friend here, though!
// e.g. cur 0xFFFFFFFFFFFFFFFE = -2, dest 0x0000000000000001 = 1
// 0x0000000000000001 - 0xFFFFFFFFFFFFFFFE = 3
while ((INT64)(dest - cur) > 0)
{
// If our cv_sleep value exceeds the remaining sleep duration, use the
// hard sleep function.
if (sleepvalue > 0 && (dest - cur) > delaygranularity)
{
I_Sleep(sleepvalue);
}
// Otherwise, this is a spinloop.
cur = I_GetPreciseTime();
}
#endif
}
precise_t I_GetPreciseTime(void)
{
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (precise_t)ts.tv_sec * 1000000000 + ts.tv_nsec;
#elif defined (_WIN32)
LARGE_INTEGER counter;
QueryPerformanceCounter(&counter);
return (precise_t)counter.QuadPart;
#else
return 0;
#endif
}
UINT64 I_GetPrecisePrecision(void)
{
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
return 1000000000;
#elif defined (_WIN32)
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency);
return (UINT64)frequency.QuadPart;
#else
return 1000000;
#endif
}
void I_GetEvent(void){}
static ticcmd_t emptycmd;
ticcmd_t *I_BaseTiccmd(void)
{
return &emptycmd;
}
ticcmd_t *I_BaseTiccmd2(void)
{
// dedicated servers don't do 2 player.
return NULL;
}
FUNCNORETURN static void I_QuitStatus(int status)
{
if (is_quitting)
abort();
is_quitting = true;
M_SaveConfig(NULL); //save game config, cvars..
D_SaveBan(); // save the ban list
G_SaveGameData(clientGamedata); // Tails 12-08-2002
//added:16-02-98: when recording a demo, should exit using 'q' key,
// but sometimes we forget and use 'F10'.. so save here too.
// FIXME: can a dedicated server even record demos?
if (demorecording)
G_CheckDemoStatus();
if (metalrecording)
G_StopMetalRecording(false);
D_QuitNetGame();
CL_AbortDownloadResume();
M_FreePlayerSetupColors();
I_ShutdownSystem();
W_Shutdown();
exit(status);
}
void I_Quit(void)
{
I_QuitStatus(0);
}
void I_Error(const char *error, ...)
{
va_list argptr;
char *buffer;
size_t buflen;
// Display error message in the console before we start shutting it down
va_start(argptr, error);
buflen = vsnprintf(NULL, 0, error, argptr);
va_end(argptr);
// do it proper with an actual malloc
// (stop abusing the stackbuffer ffs ヽ(。_°)ノ)
buffer = malloc(buflen+1);
va_start(argptr, error);
vsprintf(buffer, error, argptr);
va_end(argptr);
I_OutputMsg("\nI_Error(): %s\n", buffer);
free(buffer);
// ---
I_QuitStatus(-1);
}
void I_Tactile(FFType Type, const JoyFF_t *Effect)
{
(void)Type;
(void)Effect;
}
void I_Tactile2(FFType Type, const JoyFF_t *Effect)
{
(void)Type;
(void)Effect;
}
void I_JoyScale(void){}
void I_JoyScale2(void){}
void I_InitJoystick(void){}
void I_InitJoystick2(void){}
INT32 I_NumJoys(void)
{
return 0;
}
const char *I_GetJoyName(INT32 joyindex)
{
(void)joyindex;
return NULL;
}
#ifndef NOMUMBLE
#ifdef HAVE_MUMBLE
// Best Mumble positional audio settings:
// Minimum distance 3.0 m
// Bloom 175%
// Maximum distance 80.0 m
// Minimum volume 50%
#define DEG2RAD (0.017453292519943295769236907684883l) // TAU/360 or PI/180
#define MUMBLEUNIT (64.0f) // FRACUNITS in a Meter
static struct {
UINT32 uiVersion;
#ifdef WINMUMBLE
DWORD uiTick;
#else
UINT32 uiTick;
#endif
float fAvatarPosition[3];
float fAvatarFront[3];
float fAvatarTop[3]; // defaults to Y-is-up (only used for leaning)
wchar_t name[256]; // game name
float fCameraPosition[3];
float fCameraFront[3];
float fCameraTop[3]; // defaults to Y-is-up (only used for leaning)
wchar_t identity[256]; // player id
UINT32 context_len;
unsigned char context[256]; // server/team
wchar_t description[2048]; // game description
} *mumble = NULL;
#endif // HAVE_MUMBLE
static void I_SetupMumble(void)
{
#ifdef WINMUMBLE
HANDLE hMap = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, L"MumbleLink");
if (!hMap)
return;
mumble = MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(*mumble));
if (!mumble)
CloseHandle(hMap);
#elif defined (HAVE_SHM)
int shmfd;
char memname[256];
snprintf(memname, 256, "/MumbleLink.%d", getuid());
shmfd = shm_open(memname, O_RDWR, S_IRUSR | S_IWUSR);
if(shmfd < 0)
return;
mumble = mmap(NULL, sizeof(*mumble), PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0);
if (mumble == MAP_FAILED)
mumble = NULL;
#endif
}
#undef WINMUMBLE
#endif // NOMUMBLE
void I_UpdateMumble(const mobj_t *mobj, const listener_t listener)
{
#ifdef HAVE_MUMBLE
// DO NOT BE DECEIVED BY THIS OLD CODE!
// despite being untouched for years, it still works as intended after testing.
// (i strongly recommend a game of hide & seek with the mumble integration; hilarities are ensured)
double angle;
fixed_t anglef;
if (!mumble)
return;
if(mumble->uiVersion != 2) {
wcsncpy(mumble->name, L"SRB2 "VERSIONSTRINGW, 256);
wcsncpy(mumble->description, L"Sonic Robo Blast 2 with integrated Mumble Link support.", 2048);
mumble->uiVersion = 2;
}
mumble->uiTick++;
if (!netgame || gamestate != GS_LEVEL) { // Zero out, but never delink.
mumble->fAvatarPosition[0] = mumble->fAvatarPosition[1] = mumble->fAvatarPosition[2] = 0.0f;
mumble->fAvatarFront[0] = 1.0f;
mumble->fAvatarFront[1] = mumble->fAvatarFront[2] = 0.0f;
mumble->fCameraPosition[0] = mumble->fCameraPosition[1] = mumble->fCameraPosition[2] = 0.0f;
mumble->fCameraFront[0] = 1.0f;
mumble->fCameraFront[1] = mumble->fCameraFront[2] = 0.0f;
return;
}
{
UINT8 *p = mumble->context;
WRITEMEM(p, server_context, 8);
WRITEINT16(p, gamemap);
mumble->context_len = (UINT32)(p - mumble->context);
}
if (mobj) {
mumble->fAvatarPosition[0] = FIXED_TO_FLOAT(mobj->x) / MUMBLEUNIT;
mumble->fAvatarPosition[1] = FIXED_TO_FLOAT(mobj->z) / MUMBLEUNIT;
mumble->fAvatarPosition[2] = FIXED_TO_FLOAT(mobj->y) / MUMBLEUNIT;
anglef = AngleFixed(mobj->angle);
angle = FIXED_TO_FLOAT(anglef)*DEG2RAD;
mumble->fAvatarFront[0] = (float)cos(angle);
mumble->fAvatarFront[1] = 0.0f;
mumble->fAvatarFront[2] = (float)sin(angle);
} else {
mumble->fAvatarPosition[0] = mumble->fAvatarPosition[1] = mumble->fAvatarPosition[2] = 0.0f;
mumble->fAvatarFront[0] = 1.0f;
mumble->fAvatarFront[1] = mumble->fAvatarFront[2] = 0.0f;
}
mumble->fCameraPosition[0] = FIXED_TO_FLOAT(listener.x) / MUMBLEUNIT;
mumble->fCameraPosition[1] = FIXED_TO_FLOAT(listener.z) / MUMBLEUNIT;
mumble->fCameraPosition[2] = FIXED_TO_FLOAT(listener.y) / MUMBLEUNIT;
anglef = AngleFixed(listener.angle);
angle = FIXED_TO_FLOAT(anglef)*DEG2RAD;
mumble->fCameraFront[0] = (float)cos(angle);
mumble->fCameraFront[1] = 0.0f;
mumble->fCameraFront[2] = (float)sin(angle);
#else
(void)mobj;
(void)listener;
#endif // HAVE_MUMBLE
}
void I_StartupMouse(void){}
void I_StartupMouse2(void){}
INT32 I_GetKey(void)
{
return 0;
}
void I_StartupTimer(void){}
void I_AddExitFunc(void (*func)())
{
I_Assert(num_exit_funcs < sizeof(exit_funcs) / sizeof(exit_funcs[0]));
exit_funcs[num_exit_funcs++] = func;
}
void I_RemoveExitFunc(void (*func)())
{
// NOTE: this isn't even used, so no need implementing this.
(void)func;
}
#ifdef HAVE_TERMIOS
typedef struct
{
size_t cursor;
char buffer[256];
} feild_t;
static feild_t tty_con;
// lock to prevent clearing partial lines, since not everything
// printed ends on a newline.
static boolean ttycon_ateol = true;
// some key codes that the terminal may be using
// TTimo NOTE: I'm not sure how relevant this is
static INT32 tty_erase;
static INT32 tty_eof;
static struct termios tty_tc;
// =============================================================
// tty console routines
// NOTE: if the user is editing a line when something gets printed to the early console then it won't look good
// so we provide tty_Clear and tty_Show to be called before and after a stdout or stderr output
// =============================================================
// flush stdin, I suspect some terminals are sending a LOT of garbage
// FIXME TTimo relevant?
#if 0
static inline void tty_FlushIn(void)
{
char key;
while (read(STDIN_FILENO, &key, 1)!=-1);
}
#endif
// do a backspace
// TTimo NOTE: it seems on some terminals just sending '\b' is not enough
// so for now, in any case we send "\b \b" .. yeah well ..
// (there may be a way to find out if '\b' alone would work though)
// Hanicef NOTE: using \b this way is unreliable because of terminal state,
// it's better to use \r to reset the cursor to the beginning of the
// line and clear from there.
static void tty_Back(void)
{
write(STDOUT_FILENO, "\r", 1);
if (tty_con.cursor>0)
{
write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor);
}
write(STDOUT_FILENO, " \b", 2);
}
static void tty_Clear(void)
{
size_t i;
write(STDOUT_FILENO, "\r", 1);
if (tty_con.cursor>0)
{
for (i=0; i<tty_con.cursor; i++)
{
write(STDOUT_FILENO, " ", 1);
}
write(STDOUT_FILENO, "\r", 1);
}
}
// never exit without calling this, or your terminal will be left in a pretty bad state
static void I_ShutdownConsole(void)
{
if (consolevent)
{
I_OutputMsg("Shutdown tty console\n");
consolevent = false;
tcsetattr (STDIN_FILENO, TCSADRAIN, &tty_tc);
}
}
static void I_StartupConsole(void)
{
struct termios tc;
// TTimo
// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=390 (404)
// then SIGTTIN or SIGTOU is emitted, if not catched, turns into a SIGSTP
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
consolevent = !M_CheckParm("-noconsole");
framebuffer = M_CheckParm("-framebuffer");
if (framebuffer)
consolevent = false;
if (!consolevent) return;
if (isatty(STDIN_FILENO)!=1)
{
I_OutputMsg("stdin is not a tty, tty console mode failed\n");
consolevent = false;
return;
}
memset(&tty_con, 0x00, sizeof(tty_con));
tcgetattr (0, &tty_tc);
tty_erase = tty_tc.c_cc[VERASE];
tty_eof = tty_tc.c_cc[VEOF];
tc = tty_tc;
/*
ECHO: don't echo input characters
ICANON: enable canonical mode. This enables the special
characters EOF, EOL, EOL2, ERASE, KILL, REPRINT,
STATUS, and WERASE, and buffers by lines.
ISIG: when any of the characters INTR, QUIT, SUSP, or
DSUSP are received, generate the corresponding signal
*/
tc.c_lflag &= ~(ECHO | ICANON);
/*
ISTRIP strip off bit 8
INPCK enable input parity checking
*/
tc.c_iflag &= ~(ISTRIP | INPCK);
tc.c_cc[VMIN] = 0; //1?
tc.c_cc[VTIME] = 0;
tcsetattr (0, TCSADRAIN, &tc);
}
static void I_GetConsoleEvents(void)
{
// we use this when sending back commands
event_t ev = {0};
char key = 0;
struct pollfd pfd =
{
.fd = STDIN_FILENO,
.events = POLLIN,
.revents = 0,
};
if (!consolevent)
return;
for (;;)
{
if (poll(&pfd, 1, 0) < 1 || !(pfd.revents & POLLIN))
return;
ev.type = ev_console;
ev.key = 0;
if (read(STDIN_FILENO, &key, 1) == -1 || !key)
return;
// we have something
// backspace?
// NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere
if ((key == tty_erase) || (key == 127) || (key == 8))
{
if (tty_con.cursor > 0)
{
tty_con.cursor--;
tty_con.buffer[tty_con.cursor] = '\0';
tty_Back();
}
ev.key = KEY_BACKSPACE;
}
else if (key < ' ') // check if this is a control char
{
if (key == '\n')
{
tty_Clear();
tty_con.cursor = 0;
ev.key = KEY_ENTER;
}
else if (key == 0x4) // ^D, aka EOF
{
// shut down, most unix programs behave this way
I_Quit();
}
else continue;
}
else if (tty_con.cursor < sizeof(tty_con.buffer))
{
// push regular character
ev.key = tty_con.buffer[tty_con.cursor] = key;
tty_con.cursor++;
// print the current line (this is differential)
write(STDOUT_FILENO, &key, 1);
}
if (ev.key) D_PostEvent(&ev);
//tty_FlushIn();
}
}
#elif defined (_WIN32)
static BOOL I_ReadyConsole(HANDLE ci)
{
DWORD gotinput;
if (ci == INVALID_HANDLE_VALUE) return FALSE;
if (WaitForSingleObject(ci,0) != WAIT_OBJECT_0) return FALSE;
if (GetFileType(ci) != FILE_TYPE_CHAR) return FALSE;
if (!GetConsoleMode(ci, &gotinput)) return FALSE;
return (GetNumberOfConsoleInputEvents(ci, &gotinput) && gotinput);
}
static boolean entering_con_command = false;
static void Impl_HandleKeyboardConsoleEvent(KEY_EVENT_RECORD evt, HANDLE co)
{
event_t event;
CONSOLE_SCREEN_BUFFER_INFO CSBI;
DWORD t;
memset(&event,0x00,sizeof (event));
if (evt.bKeyDown)
{
event.type = ev_console;
entering_con_command = true;
switch (evt.wVirtualKeyCode)
{
case VK_ESCAPE:
case VK_TAB:
event.key = KEY_NULL;
break;
case VK_RETURN:
entering_con_command = false;
/* FALLTHRU */
default:
//event.key = MapVirtualKey(evt.wVirtualKeyCode,2); // convert in to char
event.key = evt.uChar.AsciiChar;
}
if (co != INVALID_HANDLE_VALUE && GetFileType(co) == FILE_TYPE_CHAR && GetConsoleMode(co, &t))
{
if (event.key && event.key != KEY_LSHIFT && event.key != KEY_RSHIFT)
{
#ifdef _UNICODE
WriteConsole(co, &evt.uChar.UnicodeChar, 1, &t, NULL);
#else
WriteConsole(co, &evt.uChar.AsciiChar, 1 , &t, NULL);
#endif
}
if (evt.wVirtualKeyCode == VK_BACK
&& GetConsoleScreenBufferInfo(co,&CSBI))
{
WriteConsoleOutputCharacterA(co, " ",1, CSBI.dwCursorPosition, &t);
}
}
}
if (event.key) D_PostEvent(&event);
}
static void I_GetConsoleEvents(void)
{
HANDLE ci = GetStdHandle(STD_INPUT_HANDLE);
HANDLE co = GetStdHandle(STD_OUTPUT_HANDLE);
INPUT_RECORD input;
DWORD t;
while (I_ReadyConsole(ci) && ReadConsoleInput(ci, &input, 1, &t) && t)
{
switch (input.EventType)
{
case KEY_EVENT:
Impl_HandleKeyboardConsoleEvent(input.Event.KeyEvent, co);
break;
case MOUSE_EVENT:
case WINDOW_BUFFER_SIZE_EVENT:
case MENU_EVENT:
case FOCUS_EVENT:
break;
}
}
}
static void I_StartupConsole(void)
{
HANDLE ci, co;
BOOL gotConsole = AllocConsole();
consolevent = !M_CheckParm("-noconsole");
if (gotConsole)
{
SetConsoleTitleA("SRB2 Console");
consolevent = true;
}
//Let get the real console HANDLE, because Mingw's Bash is bad!
ci = CreateFile(TEXT("CONIN$") , GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
co = CreateFile(TEXT("CONOUT$"), GENERIC_WRITE|GENERIC_READ, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (ci != INVALID_HANDLE_VALUE)
{
const DWORD CM = ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_INPUT;
SetStdHandle(STD_INPUT_HANDLE, ci);
if (GetFileType(ci) == FILE_TYPE_CHAR)
SetConsoleMode(ci, CM); //default mode but no ENABLE_MOUSE_INPUT
}
if (co != INVALID_HANDLE_VALUE)
{
SetStdHandle(STD_OUTPUT_HANDLE, co);
SetStdHandle(STD_ERROR_HANDLE, co);
}
}
static inline void I_ShutdownConsole(void){}
#else
static void I_GetConsoleEvents(void){}
static inline void I_StartupConsole(void)
{
consolevent = !M_CheckParm("-noconsole");
framebuffer = M_CheckParm("-framebuffer");
if (framebuffer)
consolevent = false;
}
static inline void I_ShutdownConsole(void){}
#endif
void I_OutputMsg(const char *fmt, ...)
{
size_t len;
char *txt;
va_list argptr;
va_start(argptr,fmt);
len = vsnprintf(NULL, 0, fmt, argptr);
va_end(argptr);
if (len == 0)
return;
txt = malloc(len+1);
va_start(argptr,fmt);
vsprintf(txt, fmt, argptr);
va_end(argptr);
#if defined (_WIN32) && defined (_MSC_VER)
OutputDebugStringA(txt);
#endif
#ifdef LOGMESSAGES
if (logstream)
{
fwrite(txt, len, 1, logstream);
fflush(logstream);
}
#endif
#if defined (_WIN32)
#ifdef DEBUGFILE
if (debugfile != stderr)
#endif
{
HANDLE co = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD bytesWritten;
if (co == INVALID_HANDLE_VALUE)
{
free(txt);
return;
}
if (GetFileType(co) == FILE_TYPE_CHAR && GetConsoleMode(co, &bytesWritten))
{
static COORD coordNextWrite = {0,0};
LPVOID oldLines = NULL;
INT oldLength;
CONSOLE_SCREEN_BUFFER_INFO csbi;
// Save the lines that we're going to obliterate.
GetConsoleScreenBufferInfo(co, &csbi);
oldLength = csbi.dwSize.X * (csbi.dwCursorPosition.Y - coordNextWrite.Y) + csbi.dwCursorPosition.X - coordNextWrite.X;
if (oldLength > 0)
{
LPVOID blank = malloc(oldLength);
if (!blank)
{
free(txt);
return;
}
memset(blank, ' ', oldLength); // Blank out.
oldLines = malloc(oldLength*sizeof(TCHAR));
if (!oldLines)
{
free(blank);
free(txt);
return;
}
ReadConsoleOutputCharacter(co, oldLines, oldLength, coordNextWrite, &bytesWritten);
// Move to where we what to print - which is where we would've been,
// had console input not been in the way,
SetConsoleCursorPosition(co, coordNextWrite);
WriteConsoleA(co, blank, oldLength, &bytesWritten, NULL);
free(blank);
// And back to where we want to print again.
SetConsoleCursorPosition(co, coordNextWrite);
}
// Actually write the string now!
WriteConsoleA(co, txt, (DWORD)len, &bytesWritten, NULL);
// Next time, output where we left off.
GetConsoleScreenBufferInfo(co, &csbi);
coordNextWrite = csbi.dwCursorPosition;
// Restore what was overwritten.
if (oldLines && entering_con_command)
WriteConsole(co, oldLines, oldLength, &bytesWritten, NULL);
if (oldLines) free(oldLines);
}
else // Redirected to a file.
WriteFile(co, txt, (DWORD)len, &bytesWritten, NULL);
}
#else
#ifdef HAVE_TERMIOS
if (consolevent && ttycon_ateol)
{
tty_Clear();
ttycon_ateol = false;
}
#endif
if (!framebuffer)
fprintf(stderr, "%s", txt);
#ifdef HAVE_TERMIOS
if (consolevent && txt[len-1] == '\n')
{
write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor);
ttycon_ateol = true;
}
#endif
// 2004-03-03 AJR Since not all messages end in newline, some were getting displayed late.
if (!framebuffer)
fflush(stderr);
#endif
free(txt);
}
void I_OsPolling(void)
{
if (consolevent)
I_GetConsoleEvents();
}
FUNCNORETURN static ATTRNORETURN void quit_handler(int num)
{
(void)num;
// FIXME: set a flag to quit later.
// this is risky since some functions can softlock in a signal handler: https://www.unix.com/man-page/posix/7/signal-safety/
I_Quit();
}
static void I_RegisterSignals (void)
{
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
// signal is deprecated, long live sigaction
struct sigaction sig;
sigemptyset(&sig.sa_mask);
sig.sa_flags = 0;
sig.sa_handler = quit_handler;
sigaction(SIGINT, &sig, NULL);
sig.sa_handler = quit_handler;
sigaction(SIGTERM, &sig, NULL);
#else
signal(SIGINT, quit_handler);
signal(SIGBREAK, quit_handler);
signal(SIGTERM, quit_handler);
#endif
}
INT32 I_StartupSystem(void)
{
#ifdef HAVE_THREADS
I_start_threads();
I_AddExitFunc(I_stop_threads);
#endif
I_StartupConsole();
I_RegisterSignals();
#ifndef NOMUMBLE
I_SetupMumble();
#endif
return 0;
}
void I_ShutdownSystem(void)
{
INT32 c;
I_ShutdownConsole();
for (c = MAX_QUIT_FUNCS-1; c >= 0; c--)
if (exit_funcs[c])
(*exit_funcs[c])();
#ifdef LOGMESSAGES
if (logstream)
{
I_OutputMsg("I_ShutdownSystem(): end of logstream.\n");
fclose(logstream);
logstream = NULL;
}
#endif
}
void I_GetDiskFreeSpace(INT64* freespace)
{
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
struct statvfs stfs;
if (statvfs(srb2home, &stfs) == -1)
{
*freespace = INT32_MAX;
return;
}
*freespace = stfs.f_bavail * stfs.f_bsize;
#elif defined (_WIN32)
static p_GetDiskFreeSpaceExA pfnGetDiskFreeSpaceEx = NULL;
static boolean testwin95 = false;
ULARGE_INTEGER usedbytes, lfreespace;
if (!testwin95)
{
pfnGetDiskFreeSpaceEx = (p_GetDiskFreeSpaceExA)(LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetDiskFreeSpaceExA");
testwin95 = true;
}
if (pfnGetDiskFreeSpaceEx)
{
if (pfnGetDiskFreeSpaceEx(srb2home, &lfreespace, &usedbytes, NULL))
*freespace = lfreespace.QuadPart;
else
*freespace = INT32_MAX;
}
else
{
DWORD SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters;
GetDiskFreeSpace(NULL, &SectorsPerCluster, &BytesPerSector,
&NumberOfFreeClusters, &TotalNumberOfClusters);
*freespace = BytesPerSector*SectorsPerCluster*NumberOfFreeClusters;
}
#else // Dummy for platform independent; 1GB should be enough
*freespace = 1024*1024*1024;
#endif
}
char *I_GetUserName(void)
{
static char username[MAXPLAYERNAME+1];
char *p;
#ifdef _WIN32
DWORD i = MAXPLAYERNAME;
if (!GetUserNameA(username, &i))
#endif
{
p = I_GetEnv("USER");
if (!p)
{
p = I_GetEnv("user");
if (!p)
{
p = I_GetEnv("USERNAME");
if (!p)
{
p = I_GetEnv("username");
if (!p)
{
return NULL;
}
}
}
}
strncpy(username, p, MAXPLAYERNAME);
}
if (strcmp(username, "") != 0)
return username;
return NULL; // dummy for platform independent version
}
INT32 I_mkdir(const char *dirname, INT32 unixright)
{
//[segabor]
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) || defined (__CYGWIN__)
return mkdir(dirname, unixright);
#elif defined (_WIN32)
UNREFERENCED_PARAMETER(unixright); /// \todo should implement ntright under nt...
return CreateDirectoryA(dirname, NULL);
#else
(void)dirname;
(void)unixright;
return false;
#endif
}
const CPUInfoFlags *I_CPUInfo(void)
{
return NULL;
}
static boolean isWadPathOk(const char *path)
{
char *wad3path = malloc(256);
if (!wad3path)
return false;
sprintf(wad3path, pandf, path, WADKEYWORD1);
if (FIL_ReadFileOK(wad3path))
{
free(wad3path);
return true;
}
free(wad3path);
return false;
}
static void pathonly(char *s)
{
size_t j;
for (j = strlen(s); j != (size_t)-1; j--)
if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/'))
{
if (s[j] == ':') s[j+1] = 0;
else s[j] = 0;
return;
}
}
static const char *searchWad(const char *searchDir)
{
static char tempsw[256] = "";
filestatus_t fstemp;
strcpy(tempsw, WADKEYWORD1);
fstemp = filesearch(tempsw,searchDir,NULL,true,20);
if (fstemp == FS_FOUND)
{
pathonly(tempsw);
return tempsw;
}
return NULL;
}
#define CHECKWADPATH(ret) \
do { \
I_OutputMsg(",%s", ret); \
if (isWadPathOk(ret)) \
return ret; \
} while (0)
#define SEARCHWAD(str) \
do { \
WadPath = searchWad(str); \
if (WadPath) \
return WadPath; \
} while (0)
static const char *locateWad(void)
{
const char *envstr;
const char *WadPath;
int i;
I_OutputMsg("SRB2WADDIR");
// does SRB2WADDIR exist?
if (((envstr = I_GetEnv("SRB2WADDIR")) != NULL) && isWadPathOk(envstr))
return envstr;
#ifndef NOCWD
// examine current dir
strcpy(returnWadPath, ".");
I_OutputMsg(",%s", returnWadPath);
if (isWadPathOk(returnWadPath))
return NULL;
#endif
#ifdef __APPLE__
OSX_GetResourcesPath(returnWadPath);
CHECKWADPATH(returnWadPath);
#endif
// examine default dirs
for (i = 0; wadDefaultPaths[i]; i++)
{
strcpy(returnWadPath, wadDefaultPaths[i]);
CHECKWADPATH(returnWadPath);
}
#ifndef NOHOME
// find in $HOME
if ((envstr = I_GetEnv("HOME")) != NULL)
{
char *tmp = malloc(strlen(envstr) + 1 + sizeof(DEFAULTDIR));
strcpy(tmp, envstr);
strcat(tmp, "/");
strcat(tmp, DEFAULTDIR);
CHECKWADPATH(tmp);
free(tmp);
}
#endif
// search paths
for (i = 0; wadSearchPaths[i]; i++)
{
I_OutputMsg(", in:%s", wadSearchPaths[i]);
SEARCHWAD(wadSearchPaths[i]);
}
// if nothing was found
return NULL;
}
const char *I_LocateWad(void)
{
const char *waddir;
I_OutputMsg("Looking for WADs in: ");
// FIXME: should we go for a command parameter instead for dedicated servers?
waddir = locateWad();
I_OutputMsg("\n");
if (waddir)
{
// change to the directory where we found srb2.pk3
#if defined (_WIN32)
waddir = _fullpath(NULL, waddir, MAX_PATH);
SetCurrentDirectoryA(waddir);
#else
waddir = realpath(waddir, NULL);
if (chdir(waddir) == -1)
I_OutputMsg("Couldn't change working directory\n");
#endif
}
return waddir;
}
void I_GetJoystickEvents(void){}
void I_GetJoystick2Events(void){}
void I_GetMouseEvents(void){}
void I_UpdateMouseGrab(void){}
char *I_GetEnv(const char *name)
{
return getenv(name);
}
INT32 I_PutEnv(char *name)
{
return putenv(name);
}
INT32 I_ClipboardCopy(const char *data, size_t size)
{
(void)data;
(void)size;
return -1;
}
const char *I_ClipboardPaste(void)
{
return NULL;
}
size_t I_GetRandomBytes(char *destination, size_t count)
{
#if defined (__unix__) || defined (UNIXCOMMON) || defined(__APPLE__)
FILE *rndsource;
size_t actual_bytes;
if (!(rndsource = fopen("/dev/urandom", "r")))
if (!(rndsource = fopen("/dev/random", "r")))
actual_bytes = 0;
if (rndsource)
{
actual_bytes = fread(destination, 1, count, rndsource);
fclose(rndsource);
}
if (actual_bytes == 0)
I_OutputMsg("I_GetRandomBytes(): couldn't get any random bytes");
return actual_bytes;
#elif defined (_WIN32)
if (RtlGenRandom(destination, count))
return count;
I_OutputMsg("I_GetRandomBytes(): couldn't get any random bytes");
return 0;
#else
#warning SDL I_GetRandomBytes is not implemented on this platform.
return 0;
#endif
}
void I_RegisterSysCommands(void){}
char const *I_GetSysName(void)
{
// reference: https://sourceforge.net/p/predef/wiki/OperatingSystems/
#if defined(_WIN32) || defined(__CYGWIN__)
return "Windows";
#elif defined(__APPLE__)
return "Mac OS";
#elif defined(__linux__)
return "Linux";
#elif defined(__FreeBSD__)
return "FreeBSD";
#elif defined(__OpenBSD__)
return "OpenBSD";
#elif defined(__NetBSD__)
return "NetBSD";
#elif defined(__DragonFly__)
return "DragonFly BSD";
#elif defined(__gnu_hurd__)
return "GNU Hurd"; // for anyone mental enough to set up an SRB2 server on GNU Hurd
#elif defined(__hpux)
return "HP-UX";
#elif defined(EPLAN9)
return "Plan 9";
#elif defined(__HAIKU__)
return "Haiku";
#elif defined(__BEOS__)
return "BeOS";
#elif defined(__minix)
return "Minix";
#elif defined(__sun)
#if defined(__SVR4) || defined(__srv4__)
return "Solaris"; // this would be so cursed...
#else
return "SunOS";
#endif
#elif defined(_AIX)
return "AIX";
#elif defined(__SYLLABLE__)
return "SyllableOS"; // RIP SyllableOS, i still miss you ;-;
#else
return "Unknown";
#endif
}
void I_GetCursorPosition(INT32 *x, INT32 *y)
{
(void)x;
(void)y;
}
void I_SetTextInputMode(boolean active)
{
(void)active;
}
boolean I_GetTextInputMode(void)
{
return false;
}
#include "../sdl/dosstr.c"
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2020-2023 by James R.
//
// 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 i_threads.c
/// \brief Multithreading abstraction
#if defined (__unix__) || (!defined(__APPLE__) && defined (UNIXCOMMON))
#include <pthread.h>
#include "../i_threads.h"
#include "../doomdef.h"
#include "../doomtype.h"
typedef struct thread_s thread_t;
struct thread_s
{
thread_t *next;
void *userdata;
I_thread_fn func;
pthread_t thread;
};
// we use a linked list to avoid moving memory blocks when allocating new threads.
static thread_t *thread_list;
static pthread_mutex_t thread_lock = PTHREAD_MUTEX_INITIALIZER;
static void *HandleThread(void *data)
{
thread_t *thread = data;
thread->func(thread->userdata);
pthread_mutex_lock(&thread_lock);
thread->func = NULL;
pthread_mutex_unlock(&thread_lock);
return NULL;
}
void I_spawn_thread(const char *name, I_thread_fn entry, void *userdata)
{
thread_t *thread;
(void)name;
pthread_mutex_lock(&thread_lock);
thread = thread_list;
while (thread != NULL)
{
if (thread->func == NULL)
{
// join with the exited thread to release it's resources.
pthread_join(thread->thread, NULL);
break;
}
thread = thread->next;
}
if (thread == NULL)
{
thread = malloc(sizeof(thread_t));
thread->next = thread_list;
thread_list = thread;
}
thread->func = entry;
thread->userdata = userdata;
pthread_create(&thread->thread, NULL, HandleThread, thread);
pthread_mutex_unlock(&thread_lock);
}
int I_thread_is_stopped(void)
{
thread_t *thread;
pthread_mutex_lock(&thread_lock);
thread = thread_list;
while (thread != NULL)
{
if (thread->func != NULL)
{
pthread_mutex_unlock(&thread_lock);
return false;
}
thread = thread->next;
}
pthread_mutex_unlock(&thread_lock);
return true;
}
void I_start_threads(void)
{
}
void I_stop_threads(void)
{
thread_t *thread = thread_list;
while (thread != NULL)
{
// join with all threads here, since finished threads haven't been awaited yet.
pthread_join(thread->thread, NULL);
thread = thread->next;
}
}
void I_lock_mutex(I_mutex *anchor)
{
pthread_mutex_lock(&thread_lock);
if (*anchor == NULL)
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
// SRB2 relies on lock recursion, so we need a mutex configured for that.
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
*anchor = malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(*anchor, &attr);
pthread_mutexattr_destroy(&attr);
}
pthread_mutex_unlock(&thread_lock);
pthread_mutex_lock(*anchor);
}
void I_unlock_mutex(I_mutex id)
{
pthread_mutex_unlock(id);
}
void I_hold_cond(I_cond *cond_anchor, I_mutex mutex_id)
{
I_Assert(mutex_id != NULL);
pthread_mutex_lock(&thread_lock);
if (*cond_anchor == NULL)
{
*cond_anchor = malloc(sizeof(pthread_cond_t));
pthread_cond_init(*cond_anchor, NULL);
}
pthread_mutex_unlock(&thread_lock);
pthread_cond_wait(*cond_anchor, mutex_id);
}
void I_wake_one_cond(I_cond *anchor)
{
pthread_mutex_lock(&thread_lock);
if (*anchor == NULL)
{
*anchor = malloc(sizeof(pthread_cond_t));
pthread_cond_init(*anchor, NULL);
}
pthread_mutex_unlock(&thread_lock);
pthread_cond_signal(*anchor);
}
void I_wake_all_cond(I_cond *anchor)
{
pthread_mutex_lock(&thread_lock);
if (*anchor == NULL)
{
*anchor = malloc(sizeof(pthread_cond_t));
pthread_cond_init(*anchor, NULL);
}
pthread_mutex_unlock(&thread_lock);
pthread_cond_broadcast(*anchor);
}
#elif defined (_WIN32)
#include <windows.h>
#include "../i_threads.h"
#include "../doomdef.h"
#include "../doomtype.h"
typedef struct thread_s thread_t;
struct thread_s
{
thread_t *next;
void *userdata;
I_thread_fn func;
HANDLE thread;
DWORD thread_id;
};
// we use a linked list to avoid moving memory blocks when allocating new threads.
static thread_t *thread_list;
static CRITICAL_SECTION thread_lock;
static DWORD __stdcall HandleThread(void *data)
{
thread_t *thread = data;
thread->func(thread->userdata);
EnterCriticalSection(&thread_lock);
thread->func = NULL;
LeaveCriticalSection(&thread_lock);
return 0;
}
void I_spawn_thread(const char *name, I_thread_fn entry, void *userdata)
{
thread_t *thread;
(void)name;
EnterCriticalSection(&thread_lock);
thread = thread_list;
while (thread != NULL)
{
if (thread->func == NULL)
{
CloseHandle(thread->thread);
break;
}
thread = thread->next;
}
if (thread == NULL)
{
thread = malloc(sizeof(thread_t));
thread->next = thread_list;
thread_list = thread;
}
thread->func = entry;
thread->userdata = userdata;
thread->thread = CreateThread(NULL, 0, HandleThread, thread, 0, &thread->thread_id);
LeaveCriticalSection(&thread_lock);
}
int I_thread_is_stopped(void)
{
thread_t *thread;
EnterCriticalSection(&thread_lock);
thread = thread_list;
while (thread != NULL)
{
if (thread->func != NULL)
{
LeaveCriticalSection(&thread_lock);
return false;
}
thread = thread->next;
}
LeaveCriticalSection(&thread_lock);
return true;
}
void I_start_threads(void)
{
InitializeCriticalSection(&thread_lock);
}
void I_stop_threads(void)
{
thread_t *thread = thread_list;
while (thread != NULL)
{
WaitForSingleObject(thread->thread, INFINITE);
CloseHandle(thread->thread);
thread = thread->next;
}
DeleteCriticalSection(&thread_lock);
}
void I_lock_mutex(I_mutex *anchor)
{
EnterCriticalSection(&thread_lock);
if (*anchor == NULL)
{
*anchor = malloc(sizeof(CRITICAL_SECTION));
InitializeCriticalSection(*anchor);
}
LeaveCriticalSection(&thread_lock);
EnterCriticalSection(*anchor);
}
void I_unlock_mutex(I_mutex id)
{
LeaveCriticalSection(id);
}
void I_hold_cond(I_cond *cond_anchor, I_mutex mutex_id)
{
I_Assert(mutex_id != NULL);
EnterCriticalSection(&thread_lock);
if (*cond_anchor == NULL)
{
*cond_anchor = malloc(sizeof(CONDITION_VARIABLE));
InitializeConditionVariable(*cond_anchor);
}
LeaveCriticalSection(&thread_lock);
SleepConditionVariableCS(*cond_anchor, mutex_id, INFINITE);
}
void I_wake_one_cond(I_cond *anchor)
{
EnterCriticalSection(&thread_lock);
if (*anchor == NULL)
{
*anchor = malloc(sizeof(CONDITION_VARIABLE));
InitializeConditionVariable(*anchor);
}
LeaveCriticalSection(&thread_lock);
WakeConditionVariable(*anchor);
}
void I_wake_all_cond(I_cond *anchor)
{
EnterCriticalSection(&thread_lock);
if (*anchor == NULL)
{
*anchor = malloc(sizeof(CONDITION_VARIABLE));
InitializeConditionVariable(*anchor);
}
LeaveCriticalSection(&thread_lock);
WakeAllConditionVariable(*anchor);
}
#else
void I_spawn_thread(const char *name, I_thread_fn entry, void *userdata)
{
(void)name;
entry(userdata);
}
int I_thread_is_stopped(void)
{
}
void I_start_threads(void)
{
}
void I_stop_threads(void)
{
}
void I_lock_mutex(I_mutex *anchor)
{
(void)anchor;
}
void I_unlock_mutex(I_mutex id)
{
(void)id;
}
void I_hold_cond(I_cond *cond_anchor, I_mutex mutex_id)
{
(void)cond_anchor;
(void)mutex_id;
}
void I_wake_one_cond(I_cond *anchor)
{
(void)anchor;
}
void I_wake_all_cond(I_cond *anchor)
{
(void)anchor;
}
#endif
#include "../doomdef.h"
#include "../command.h"
#include "../i_video.h"
rendermode_t rendermode = render_none;
rendermode_t chosenrendermode = render_none;
boolean allow_fullscreen = false;
consvar_t cv_vidwait = CVAR_INIT ("vid_wait", "On", CV_SAVE, CV_OnOff, NULL);
void I_StartupGraphics(void){}
void I_ShutdownGraphics(void){}
void VID_StartupOpenGL(void){}
void I_SetPalette(RGBA_t *palette)
{
(void)palette;
}
INT32 VID_NumModes(void)
{
return 0;
}
INT32 VID_GetModeForSize(INT32 w, INT32 h)
{
(void)w;
(void)h;
return 0;
}
void VID_PrepareModeList(void){}
INT32 VID_SetMode(INT32 modenum)
{
(void)modenum;
return 0;
}
boolean VID_CheckRenderer(void)
{
return false;
}
void VID_CheckGLLoaded(rendermode_t oldrender)
{
(void)oldrender;
}
const char *VID_GetModeName(INT32 modenum)
{
(void)modenum;
return NULL;
}
UINT32 I_GetRefreshRate(void) { return 35; }
void I_UpdateNoBlit(void){}
void I_FinishUpdate(void){}
void I_UpdateNoVsync(void) {}
void I_WaitVBL(INT32 count)
{
(void)count;
}
void I_ReadScreen(UINT8 *scr)
{
(void)scr;
}
void I_BeginRead(void){}
void I_EndRead(void){}
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// 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
// terms of the GNU General Public License, version 2.
......@@ -27,6 +27,12 @@ static inline int lib_freeslot(lua_State *L)
if (!lua_lumploading)
return luaL_error(L, "This function cannot be called from within a hook or coroutine!");
if (!deh_loaded)
{
initfreeslots();
deh_loaded = true;
}
while (n-- > 0)
{
s = Z_StrDup(luaL_checkstring(L,1));
......@@ -58,24 +64,19 @@ static inline int lib_freeslot(lua_State *L)
}
else if (fastcmp(type, "SPR"))
{
char wad;
spritenum_t j;
lua_getfield(L, LUA_REGISTRYINDEX, "WAD");
wad = (char)lua_tointeger(L, -1);
lua_pop(L, 1);
if (strlen(word) > MAXSPRITENAME)
return luaL_error(L, "Sprite name is longer than %d characters\n", MAXSPRITENAME);
for (j = SPR_FIRSTFREESLOT; j <= SPR_LASTFREESLOT; j++)
{
if (used_spr[(j-SPR_FIRSTFREESLOT)/8] & (1<<(j%8)))
{
if (!sprnames[j][4] && memcmp(sprnames[j],word,4)==0)
sprnames[j][4] = wad;
if (in_bit_array(used_spr, j - SPR_FIRSTFREESLOT))
continue; // Already allocated, next.
}
// Found a free slot!
CONS_Printf("Sprite SPR_%s allocated.\n",word);
strncpy(sprnames[j],word,4);
//sprnames[j][4] = 0;
used_spr[(j-SPR_FIRSTFREESLOT)/8] |= 1<<(j%8); // Okay, this sprite slot has been named now.
strcpy(sprnames[j], word);
set_bit_array(used_spr, j - SPR_FIRSTFREESLOT); // Okay, this sprite slot has been named now.
// Lua needs to update the value in _G if it exists
LUA_UpdateSprName(word, j);
lua_pushinteger(L, j);
......@@ -454,17 +455,19 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
}
else if (fastncmp("SPR_",word,4)) {
p = word+4;
for (i = 0; i < NUMSPRITES; i++)
if (!sprnames[i][4] && fastncmp(p,sprnames[i],4)) {
// updating overridden sprnames is not implemented for soc parser,
// so don't use cache
if (mathlib)
lua_pushinteger(L, i);
else
CacheAndPushConstant(L, word, i);
return 1;
}
if (mathlib) return luaL_error(L, "sprite '%s' could not be found.\n", word);
i = R_GetSpriteNumByName(p);
if (i != NUMSPRITES)
{
// updating overridden sprnames is not implemented for soc parser,
// so don't use cache
if (mathlib)
lua_pushinteger(L, i);
else
CacheAndPushConstant(L, word, i);
return 1;
}
else if (mathlib)
return luaL_error(L, "sprite '%s' could not be found.\n", word);
return 0;
}
else if (fastncmp("SPR2_",word,5)) {
......@@ -601,7 +604,7 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
{
CacheAndPushConstant(L, word, (lua_Integer)BT_SPIN);
return 1;
}
}
for (i = 0; INT_CONST[i].n; i++)
if (fastcmp(word,INT_CONST[i].n)) {
......@@ -729,18 +732,18 @@ static inline int lib_getenum(lua_State *L)
// If a sprname has been "cached" to _G, update it to a new value.
void LUA_UpdateSprName(const char *name, lua_Integer value)
{
char fullname[9] = "SPR_XXXX";
char fullname[4 + MAXSPRITENAME + 1] = "SPR_";
if (!gL)
return;
strncpy(&fullname[4], name, 4);
strcpy(&fullname[4], name);
lua_pushstring(gL, fullname);
lua_rawget(gL, LUA_GLOBALSINDEX);
if (!lua_isnil(gL, -1))
{
lua_pushstring(gL, name);
lua_pushstring(gL, fullname);
lua_pushinteger(gL, value);
lua_rawset(gL, LUA_GLOBALSINDEX);
}
......
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior.
// Copyright (C) 1999-2025 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
......@@ -286,6 +286,7 @@ void readPlayer(MYFILE *f, INT32 num)
}
if (playertext)
{
// PLAYERTEXT is really weird, so this doesn't use deh_strlcpy.
strlcpy(description[num].notes, playertext, NOTE_SIZE);
strlcat(description[num].notes,
myhashfgets(playertext, NOTE_SIZE, f), NOTE_SIZE);
......@@ -324,7 +325,8 @@ void readPlayer(MYFILE *f, INT32 num)
if (fastcmp(word, "PICNAME"))
{
SLOTFOUND
strncpy(description[num].picname, word2, 8);
deh_strlcpy(description[num].picname, word2, sizeof description[num].picname,
va("Character %d: picname", num));
}
else if (fastcmp(word, "DISPLAYNAME"))
{
......@@ -345,7 +347,8 @@ void readPlayer(MYFILE *f, INT32 num)
cur = strchr(cur, '#');
}
strlcpy(description[num].displayname, stringvalue, sizeof description[num].displayname);
deh_strlcpy(description[num].displayname, stringvalue, sizeof description[num].displayname,
va("Character %d: displayname", num));
}
else if (fastcmp(word, "OPPOSITECOLOR") || fastcmp(word, "OPPOSITECOLOUR"))
{
......@@ -355,7 +358,8 @@ void readPlayer(MYFILE *f, INT32 num)
else if (fastcmp(word, "NAMETAG") || fastcmp(word, "TAGNAME"))
{
SLOTFOUND
strncpy(description[num].nametag, word2, 8);
deh_strlcpy(description[num].nametag, word2, sizeof description[num].nametag,
va("Character %d: nametag", num));
}
else if (fastcmp(word, "TAGTEXTCOLOR") || fastcmp(word, "TAGTEXTCOLOUR"))
{
......@@ -387,7 +391,8 @@ void readPlayer(MYFILE *f, INT32 num)
{
// Send to free slot.
SLOTFOUND
strlcpy(description[num].skinname, word2, sizeof description[num].skinname);
deh_strlcpy(description[num].skinname, word2, sizeof description[num].skinname,
va("Character %d: skinname", num));
strlwr(description[num].skinname);
}
else if (!failure)
......@@ -405,7 +410,6 @@ void readfreeslots(MYFILE *f)
{
char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL);
char *word,*type;
char *tmp;
int i;
do
......@@ -415,10 +419,13 @@ void readfreeslots(MYFILE *f)
if (s[0] == '\n')
break;
tmp = strchr(s, '#');
if (tmp)
*tmp = '\0';
if (s == tmp)
char *hashtag = strchr(s, '#');
char *space = strchr(s, ' ');
if (hashtag)
*hashtag = '\0';
if (space)
*space = '\0';
if (s == hashtag || s == space)
continue; // Skip comment lines, but don't break.
type = strtok(s, "_");
......@@ -440,18 +447,16 @@ void readfreeslots(MYFILE *f)
S_AddSoundFx(word, false, 0, false);
else if (fastcmp(type, "SPR"))
{
if (strlen(word) > MAXSPRITENAME)
I_Error("Sprite name is longer than %d characters\n", MAXSPRITENAME);
for (i = SPR_FIRSTFREESLOT; i <= SPR_LASTFREESLOT; i++)
{
if (used_spr[(i-SPR_FIRSTFREESLOT)/8] & (1<<(i%8)))
{
if (!sprnames[i][4] && memcmp(sprnames[i],word,4)==0)
sprnames[i][4] = (char)f->wad;
if (in_bit_array(used_spr, i - SPR_FIRSTFREESLOT))
continue; // Already allocated, next.
}
// Found a free slot!
strncpy(sprnames[i],word,4);
//sprnames[i][4] = 0;
used_spr[(i-SPR_FIRSTFREESLOT)/8] |= 1<<(i%8); // Okay, this sprite slot has been named now.
strcpy(sprnames[i], word);
set_bit_array(used_spr, i - SPR_FIRSTFREESLOT); // Okay, this sprite slot has been named now.
// Lua needs to update the value in _G if it exists
LUA_UpdateSprName(word, i);
break;
......@@ -1163,7 +1168,7 @@ void readgametype(MYFILE *f, char *gtname)
INT16 newgtrankingstype = -1;
int newgtinttype = 0;
char gtdescription[441];
char gtconst[MAXLINELEN];
char gtconst[MAXLINELEN+1];
// Empty strings.
gtdescription[0] = '\0';
......@@ -1196,6 +1201,7 @@ void readgametype(MYFILE *f, char *gtname)
}
if (descr)
{
// DESCRIPTION is really weird, so this doesn't use deh_strlcpy.
strlcpy(gtdescription, descr, sizeof (gtdescription));
strlcat(gtdescription,
myhashfgets(descr, sizeof (gtdescription), f),
......@@ -1402,7 +1408,7 @@ void readlevelheader(MYFILE *f, INT32 num)
{
deh_strlcpy(mapheaderinfo[num-1]->lvlttl, word2,
sizeof(mapheaderinfo[num-1]->lvlttl), va("Level header %d: levelname", num));
strlcpy(mapheaderinfo[num-1]->selectheading, word2, sizeof(mapheaderinfo[num-1]->selectheading)); // not deh_ so only complains once
strlcpy(mapheaderinfo[num-1]->selectheading, word2, sizeof(mapheaderinfo[num-1]->selectheading)); // not deh_strlcpy so only complains once
continue;
}
// CHEAP HACK: move this over here for lowercase subtitles
......@@ -1445,10 +1451,10 @@ void readlevelheader(MYFILE *f, INT32 num)
// Newly allocated
modoption = &mapheaderinfo[num-1]->customopts[j];
strncpy(modoption->option, word, 31);
modoption->option[31] = '\0';
strncpy(modoption->value, word2, 255);
modoption->value[255] = '\0';
deh_strlcpy(modoption->option, word, sizeof(modoption->option),
va("Level header %d: custom option %d key", num, j));
deh_strlcpy(modoption->value, word2, sizeof(modoption->value),
va("Level header %d: custom option %d value", num, j));
continue;
}
......@@ -1543,6 +1549,12 @@ void readlevelheader(MYFILE *f, INT32 num)
P_AddGradesForMare((INT16)(num-1), mare-1, word2);
}
// NiGHTS time limits (per mare)
else if (fastncmp(word, "NIGHTSTIME", 10))
{
P_AddNiGHTSTimes((INT16)(num-1), word2);
}
// Strings that can be truncated
else if (fastcmp(word, "SELECTHEADING"))
{
......@@ -1620,7 +1632,7 @@ void readlevelheader(MYFILE *f, INT32 num)
else if (fastcmp(word, "KEYWORDS"))
{
deh_strlcpy(mapheaderinfo[num-1]->keywords, word2,
sizeof(mapheaderinfo[num-1]->keywords), va("Level header %d: keywords", num));
sizeof(mapheaderinfo[num-1]->keywords), va("Level header %d: keywords", num));
}
else if (fastcmp(word, "MUSIC"))
{
......@@ -1669,7 +1681,8 @@ void readlevelheader(MYFILE *f, INT32 num)
}
else if (fastcmp(word, "FORCECHARACTER"))
{
strlcpy(mapheaderinfo[num-1]->forcecharacter, word2, SKINNAMESIZE+1);
deh_strlcpy(mapheaderinfo[num-1]->forcecharacter, word2, sizeof mapheaderinfo[num-1]->forcecharacter,
va("Level header %d: forcecharacter", num));
strlwr(mapheaderinfo[num-1]->forcecharacter); // skin names are lowercase
}
else if (fastcmp(word, "WEATHER"))
......@@ -1677,7 +1690,10 @@ void readlevelheader(MYFILE *f, INT32 num)
else if (fastcmp(word, "SKYNUM"))
mapheaderinfo[num-1]->skynum = (INT16)i;
else if (fastcmp(word, "INTERSCREEN"))
strncpy(mapheaderinfo[num-1]->interscreen, word2, 8);
{
deh_strlcpy(mapheaderinfo[num-1]->interscreen, word2, sizeof mapheaderinfo[num-1]->interscreen,
va("Level header %d: interscreen", num));
}
else if (fastcmp(word, "PRECUTSCENENUM"))
mapheaderinfo[num-1]->precutscenenum = (UINT8)i;
else if (fastcmp(word, "CUTSCENENUM"))
......@@ -1979,14 +1995,17 @@ static void readcutscenescene(MYFILE *f, INT32 num, INT32 scenenum)
picid = (UINT8)atoi(word + 3);
if (picid > 8 || picid == 0)
{
deh_warning("CutSceneScene %d: unknown word '%s'", num, word);
deh_warning("Cutscene %d, scene %d: pic number %d out of range (1 - %d)",
num + 1, scenenum + 1, picid, 8);
continue;
}
--picid;
if (fastcmp(word+4, "NAME"))
{
strncpy(cutscenes[num]->scene[scenenum].picname[picid], word2, 8);
deh_strlcpy(cutscenes[num]->scene[scenenum].picname[picid], word2,
sizeof cutscenes[num]->scene[scenenum].picname[picid],
va("Cutscene %d, scene %d, pic %d: name", num + 1, scenenum + 1, picid + 1));
}
else if (fastcmp(word+4, "HIRES"))
{
......@@ -2005,12 +2024,13 @@ static void readcutscenescene(MYFILE *f, INT32 num, INT32 scenenum)
cutscenes[num]->scene[scenenum].ycoord[picid] = usi;
}
else
deh_warning("CutSceneScene %d: unknown word '%s'", num, word);
deh_warning("Cutscene %d, scene %d: unknown word '%s'", num + 1, scenenum + 1, word);
}
else if (fastcmp(word, "MUSIC"))
{
strncpy(cutscenes[num]->scene[scenenum].musswitch, word2, 7);
cutscenes[num]->scene[scenenum].musswitch[6] = 0;
deh_strlcpy(cutscenes[num]->scene[scenenum].musswitch, word2,
sizeof cutscenes[num]->scene[scenenum].musswitch,
va("Cutscene %d, scene %d: music", num + 1, scenenum + 1));
}
else if (fastcmp(word, "MUSICTRACK"))
{
......@@ -2045,7 +2065,7 @@ static void readcutscenescene(MYFILE *f, INT32 num, INT32 scenenum)
cutscenes[num]->scene[scenenum].fadecolor = (UINT8)i;
}
else
deh_warning("CutSceneScene %d: unknown word '%s'", num, word);
deh_warning("Cutscene %d, scene %d: unknown word '%s'", num + 1, scenenum + 1, word);
}
} while (!myfeof(f)); // finish when the line is empty
......@@ -2103,11 +2123,10 @@ void readcutscene(MYFILE *f, INT32 num)
readcutscenescene(f, num, value - 1);
}
else
deh_warning("Scene number %d out of range (1 - 128)", value);
deh_warning("Cutscene %d: scene number %d out of range (1 - 128)", num + 1, value);
}
else
deh_warning("Cutscene %d: unknown word '%s', Scene <num> expected.", num, word);
deh_warning("Cutscene %d: unknown word '%s', Scene <num> expected.", num + 1, word);
}
} while (!myfeof(f)); // finish when the line is empty
......@@ -2228,7 +2247,8 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
for (picid = 0; picid < MAX_PROMPT_PICS; picid++)
{
strncpy(textprompts[num]->page[pagenum].picname[picid], textprompts[num]->page[metapagenum].picname[picid], 8);
// Doesn't use deh_strlcpy because it's not copying input.
strlcpy(textprompts[num]->page[pagenum].picname[picid], textprompts[num]->page[metapagenum].picname[picid], sizeof textprompts[num]->page[pagenum].picname[picid]);
textprompts[num]->page[pagenum].pichires[picid] = textprompts[num]->page[metapagenum].pichires[picid];
textprompts[num]->page[pagenum].picduration[picid] = textprompts[num]->page[metapagenum].picduration[picid];
textprompts[num]->page[pagenum].xcoord[picid] = textprompts[num]->page[metapagenum].xcoord[picid];
......@@ -2241,14 +2261,17 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
picid = (UINT8)atoi(word + 3);
if (picid > MAX_PROMPT_PICS || picid == 0)
{
deh_warning("textpromptscene %d: unknown word '%s'", num, word);
deh_warning("Text prompt %d, page %d: pic number %d out of range (1 - %d)",
num + 1, pagenum + 1, picid, MAX_PROMPT_PICS);
continue;
}
--picid;
if (fastcmp(word+4, "NAME"))
{
strncpy(textprompts[num]->page[pagenum].picname[picid], word2, 8);
deh_strlcpy(textprompts[num]->page[pagenum].picname[picid], word2,
sizeof textprompts[num]->page[pagenum].picname[picid],
va("Text prompt %d, page %d, pic %d: name", num + 1, pagenum + 1, picid + 1));
}
else if (fastcmp(word+4, "HIRES"))
{
......@@ -2267,12 +2290,16 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
textprompts[num]->page[pagenum].ycoord[picid] = usi;
}
else
deh_warning("textpromptscene %d: unknown word '%s'", num, word);
{
deh_warning("Text prompt %d, page %d: unknown word '%s'",
num + 1, pagenum + 1, word);
}
}
else if (fastcmp(word, "MUSIC"))
{
strncpy(textprompts[num]->page[pagenum].musswitch, word2, 7);
textprompts[num]->page[pagenum].musswitch[6] = 0;
deh_strlcpy(textprompts[num]->page[pagenum].musswitch, word2,
sizeof textprompts[num]->page[pagenum].musswitch,
va("Text prompt %d, page %d: music", num + 1, pagenum + 1));
}
else if (fastcmp(word, "MUSICTRACK"))
{
......@@ -2287,30 +2314,35 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
{
if (*word2 != '\0')
{
INT32 j;
size_t j;
// HACK: Add yellow control char now
// so the drawing function doesn't call it repeatedly
char name[34];
char name[32 + 2];
name[0] = '\x82'; // color yellow
name[1] = 0;
strncat(name, word2, 33);
name[33] = 0;
// So that we still get a warning.
deh_strlcpy(name + 1, word2, (sizeof(name)) - 1,
va("Text prompt %d, page %d: name", num + 1, pagenum + 1));
// Replace _ with ' '
for (j = 0; j < 32 && name[j]; j++)
for (j = 1; j < sizeof(name) && name[j]; j++)
{
if (name[j] == '_')
name[j] = ' ';
}
strncpy(textprompts[num]->page[pagenum].name, name, 32);
strlcpy(textprompts[num]->page[pagenum].name, name, sizeof(textprompts[num]->page[pagenum].name));
}
else
*textprompts[num]->page[pagenum].name = '\0';
}
else if (fastcmp(word, "ICON"))
strncpy(textprompts[num]->page[pagenum].iconname, word2, 8);
{
deh_strlcpy(textprompts[num]->page[pagenum].iconname, word2,
sizeof textprompts[num]->page[pagenum].iconname,
va("Text prompt %d, page %d: icon", num + 1, pagenum + 1));
}
else if (fastcmp(word, "ICONALIGN"))
textprompts[num]->page[pagenum].rightside = (i || word2[0] == 'R');
else if (fastcmp(word, "ICONFLIP"))
......@@ -2377,8 +2409,9 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
{
UINT8 metapagenum = usi - 1;
strncpy(textprompts[num]->page[pagenum].name, textprompts[num]->page[metapagenum].name, 32);
strncpy(textprompts[num]->page[pagenum].iconname, textprompts[num]->page[metapagenum].iconname, 8);
// Doesn't use deh_strlcpy because it's not copying input.
strlcpy(textprompts[num]->page[pagenum].name, textprompts[num]->page[metapagenum].name, sizeof textprompts[num]->page[pagenum].name);
strlcpy(textprompts[num]->page[pagenum].iconname, textprompts[num]->page[metapagenum].iconname, sizeof textprompts[num]->page[pagenum].iconname);
textprompts[num]->page[pagenum].rightside = textprompts[num]->page[metapagenum].rightside;
textprompts[num]->page[pagenum].iconflip = textprompts[num]->page[metapagenum].iconflip;
textprompts[num]->page[pagenum].lines = textprompts[num]->page[metapagenum].lines;
......@@ -2393,17 +2426,25 @@ static void readtextpromptpage(MYFILE *f, INT32 num, INT32 pagenum)
}
}
else if (fastcmp(word, "TAG"))
strncpy(textprompts[num]->page[pagenum].tag, word2, 33);
{
deh_strlcpy(textprompts[num]->page[pagenum].tag, word2,
sizeof textprompts[num]->page[pagenum].tag,
va("Text prompt %d, page %d: tag", num + 1, pagenum + 1));
}
else if (fastcmp(word, "NEXTPROMPT"))
textprompts[num]->page[pagenum].nextprompt = usi;
else if (fastcmp(word, "NEXTPAGE"))
textprompts[num]->page[pagenum].nextpage = usi;
else if (fastcmp(word, "NEXTTAG"))
strncpy(textprompts[num]->page[pagenum].nexttag, word2, 33);
{
deh_strlcpy(textprompts[num]->page[pagenum].nexttag, word2,
sizeof textprompts[num]->page[pagenum].nexttag,
va("Text prompt %d, page %d: nexttag", num + 1, pagenum + 1));
}
else if (fastcmp(word, "TIMETONEXT"))
textprompts[num]->page[pagenum].timetonext = get_number(word2);
else
deh_warning("PromptPage %d: unknown word '%s'", num, word);
deh_warning("Text prompt %d, page %d: unknown word '%s'", num + 1, pagenum + 1, word);
}
} while (!myfeof(f)); // finish when the line is empty
......@@ -2463,11 +2504,11 @@ void readtextprompt(MYFILE *f, INT32 num)
readtextpromptpage(f, num, value - 1);
}
else
deh_warning("Page number %d out of range (1 - %d)", value, MAX_PAGES);
deh_warning("Prompt %d: page number %d out of range (1 - %d)", num + 1, value, MAX_PAGES);
}
else
deh_warning("Prompt %d: unknown word '%s', Page <num> expected.", num, word);
deh_warning("Prompt %d: unknown word '%s', Page <num> expected.", num + 1, word);
}
} while (!myfeof(f)); // finish when the line is empty
......@@ -2516,7 +2557,8 @@ void readmenu(MYFILE *f, INT32 num)
if (fastcmp(word, "BACKGROUNDNAME"))
{
strncpy(menupres[num].bgname, word2, 8);
deh_strlcpy(menupres[num].bgname, word2,
sizeof menupres[num].bgname, va("Menu %d: backgroundname", num));
titlechanged = true;
}
else if (fastcmp(word, "HIDEBACKGROUND"))
......@@ -2559,7 +2601,8 @@ void readmenu(MYFILE *f, INT32 num)
}
else if (fastcmp(word, "TITLEPICSNAME"))
{
strncpy(menupres[num].ttname, word2, 9);
deh_strlcpy(menupres[num].ttname, word2,
sizeof menupres[num].ttname, va("Menu %d: titlepicsname", num));
titlechanged = true;
}
else if (fastcmp(word, "TITLEPICSX"))
......@@ -2595,8 +2638,8 @@ void readmenu(MYFILE *f, INT32 num)
}
else if (fastcmp(word, "MUSIC"))
{
strncpy(menupres[num].musname, word2, 7);
menupres[num].musname[6] = 0;
deh_strlcpy(menupres[num].musname, word2,
sizeof menupres[num].musname, va("Menu %d: music", num));
titlechanged = true;
}
else if (fastcmp(word, "MUSICTRACK"))
......@@ -2785,7 +2828,7 @@ void readframe(MYFILE *f, INT32 num)
size_t z;
boolean found = false;
size_t actionlen = strlen(word2) + 1;
char *actiontocompare = calloc(actionlen, 1);
char *actiontocompare = calloc(1, actionlen);
strcpy(actiontocompare, word2);
strupr(actiontocompare);
......@@ -3578,22 +3621,20 @@ void readmaincfg(MYFILE *f)
if (fastcmp(word, "EXECCFG"))
{
if (strchr(word2, '.'))
COM_BufAddText(va("exec %s\n", word2));
COM_ExecFile(word2, COM_LUA, false);
else
{
lumpnum_t lumpnum;
char newname[9];
strncpy(newname, word2, 8);
newname[8] = '\0';
deh_strlcpy(newname, word2, sizeof newname, va("Maincfg: execcfg"));
lumpnum = W_CheckNumForName(newname);
if (lumpnum == LUMPERROR || W_LumpLength(lumpnum) == 0)
CONS_Debug(DBG_SETUP, "SOC Error: script lump %s not found/not valid.\n", newname);
else
COM_BufInsertText(W_CacheLumpNum(lumpnum, PU_CACHE));
COM_BufInsertTextEx(W_CacheLumpNum(lumpnum, PU_CACHE), COM_LUA);
}
}
......@@ -3794,7 +3835,7 @@ void readmaincfg(MYFILE *f)
}
else if (fastcmp(word, "TITLEPICSNAME"))
{
strncpy(ttname, word2, 9);
deh_strlcpy(ttname, word2, sizeof ttname, va("Maincfg: titlepicsname"));
titlechanged = true;
}
else if (fastcmp(word, "TITLEPICSX"))
......@@ -3878,8 +3919,12 @@ void readmaincfg(MYFILE *f)
savemoddata = true;
// Also save a time attack folder
filenamelen = strlen(gamedatafilename)-4; // Strip off the extension
strncpy(timeattackfolder, gamedatafilename, min(filenamelen, sizeof (timeattackfolder)));
filenamelen = strlen(gamedatafilename); // Strip off the extension
if (filenamelen >= 4)
filenamelen -= 4;
if (filenamelen >= sizeof(timeattackfolder))
filenamelen = sizeof(timeattackfolder)-1;
strncpy(timeattackfolder, gamedatafilename, filenamelen);
timeattackfolder[min(filenamelen, sizeof (timeattackfolder) - 1)] = '\0';
strcpy(savegamename, timeattackfolder);
......@@ -3900,7 +3945,7 @@ void readmaincfg(MYFILE *f)
}
else if (fastcmp(word, "CUSTOMVERSION"))
{
strlcpy(customversionstring, word2, sizeof (customversionstring));
deh_strlcpy(customversionstring, word2, sizeof customversionstring, va("Maincfg: customversion"));
//titlechanged = true;
}
else if (fastcmp(word, "BOOTMAP"))
......@@ -3915,6 +3960,7 @@ void readmaincfg(MYFILE *f)
value = get_number(word2);
bootmap = (INT16)value;
bootmapchanged = true;
//titlechanged = true;
}
else if (fastcmp(word, "STARTCHAR"))
......@@ -4172,9 +4218,9 @@ spritenum_t get_sprite(const char *word)
return atoi(word);
if (fastncmp("SPR_",word,4))
word += 4; // take off the SPR_
for (i = 0; i < NUMSPRITES; i++)
if (!sprnames[i][4] && memcmp(word,sprnames[i],4)==0)
return i;
i = R_GetSpriteNumByName(word);
if (i != NUMSPRITES)
return i;
deh_warning("Couldn't find sprite named 'SPR_%s'",word);
return SPR_NULL;
}
......
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior.
// Copyright (C) 1999-2025 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
......@@ -25,13 +25,14 @@
#include "g_game.h" // Joystick axes (for lua)
#include "i_joy.h"
#include "g_input.h" // Game controls (for lua)
#include "p_maputl.h" // P_PathTraverse constants (for lua)
#include "deh_tables.h"
char *FREE_STATES[NUMSTATEFREESLOTS];
char *FREE_MOBJS[NUMMOBJFREESLOTS];
char *FREE_SKINCOLORS[NUMCOLORFREESLOTS];
UINT8 used_spr[(NUMSPRITEFREESLOTS / 8) + 1]; // Bitwise flag for sprite freeslot in use! I would use ceil() here if I could, but it only saves 1 byte of memory anyway.
bitarray_t used_spr[BIT_ARRAY_SIZE(NUMSPRITEFREESLOTS)]; // Sprite freeslots in use
const char NIGHTSGRADE_LIST[] = {
'F', // GRADE_F
......@@ -1081,11 +1082,11 @@ const char *const STATE_LIST[] = { // array length left dynamic for sanity testi
"S_FANG_FIRE1",
"S_FANG_FIRE2",
"S_FANG_FIRE3",
"S_FANG_FIRE4",
"S_FANG_FIREREPEAT",
"S_FANG_LOBSHOT0",
"S_FANG_LOBSHOT1",
"S_FANG_LOBSHOT2",
"S_FANG_LOBSHOT3",
"S_FANG_WAIT1",
"S_FANG_WAIT2",
"S_FANG_WALLHIT",
......@@ -1107,6 +1108,7 @@ const char *const STATE_LIST[] = { // array length left dynamic for sanity testi
"S_FANG_PINCHLOBSHOT2",
"S_FANG_PINCHLOBSHOT3",
"S_FANG_PINCHLOBSHOT4",
"S_FANG_PINCHLOBSHOT5",
"S_FANG_DIE1",
"S_FANG_DIE2",
"S_FANG_DIE3",
......@@ -2245,6 +2247,10 @@ const char *const STATE_LIST[] = { // array length left dynamic for sanity testi
"S_LAMPPOST2", // with snow
"S_HANGSTAR",
"S_MISTLETOE",
"S_SSZTREE",
"S_SSZTREE_BRANCH",
"S_SSZTREE2",
"S_SSZTREE2_BRANCH",
// Xmas GFZ bushes
"S_XMASBLUEBERRYBUSH",
"S_XMASBERRYBUSH",
......@@ -2252,11 +2258,9 @@ const char *const STATE_LIST[] = { // array length left dynamic for sanity testi
// FHZ
"S_FHZICE1",
"S_FHZICE2",
"S_ROSY_IDLE1",
"S_ROSY_IDLE2",
"S_ROSY_IDLE3",
"S_ROSY_IDLE4",
"S_ROSY_IDLE",
"S_ROSY_JUMP",
"S_ROSY_FALL",
"S_ROSY_WALK",
"S_ROSY_HUG",
"S_ROSY_PAIN",
......@@ -2365,6 +2369,9 @@ const char *const STATE_LIST[] = { // array length left dynamic for sanity testi
"S_DBALL5",
"S_DBALL6",
"S_EGGSTATUE2",
"S_GINE",
"S_PPAL",
"S_PPEL",
// Shield Orb
"S_ARMA1",
......@@ -3249,6 +3256,7 @@ const char *const STATE_LIST[] = { // array length left dynamic for sanity testi
"S_MARIOBUSH2",
"S_TOAD",
// Nights-specific stuff
"S_NIGHTSDRONE_MAN1",
"S_NIGHTSDRONE_MAN2",
......@@ -3552,6 +3560,12 @@ const char *const STATE_LIST[] = { // array length left dynamic for sanity testi
"S_YELLOWBRICKDEBRIS",
"S_NAMECHECK",
// LJ Knuckles
"S_OLDK_STND",
"S_OLDK_DIE0",
"S_OLDK_DIE1",
"S_OLDK_DIE2",
};
// RegEx to generate this from info.h: ^\tMT_([^,]+), --> \t"MT_\1",
......@@ -4023,6 +4037,10 @@ const char *const MOBJTYPE_LIST[] = { // array length left dynamic for sanity t
"MT_LAMPPOST2", // with snow
"MT_HANGSTAR",
"MT_MISTLETOE",
"MT_SSZTREE",
"MT_SSZTREE_BRANCH",
"MT_SSZTREE2",
"MT_SSZTREE2_BRANCH",
// Xmas GFZ bushes
"MT_XMASBLUEBERRYBUSH",
"MT_XMASBERRYBUSH",
......@@ -4102,6 +4120,9 @@ const char *const MOBJTYPE_LIST[] = { // array length left dynamic for sanity t
// Misc scenery
"MT_DBALL",
"MT_EGGSTATUE2",
"MT_GINE",
"MT_PPAL",
"MT_PPEL",
// Powerup Indicators
"MT_ELEMENTAL_ORB", // Elemental shield mobj
......@@ -4329,6 +4350,8 @@ const char *const MOBJTYPE_LIST[] = { // array length left dynamic for sanity t
"MT_NAMECHECK",
"MT_RAY",
"MT_OLDK",
};
const char *const MOBJFLAG_LIST[] = {
......@@ -4483,6 +4506,8 @@ const char *const PLAYERFLAG_LIST[] = {
"CANCARRY", // Can carry?
"FINISHED",
"SHIELDDOWN", // Shield has been pressed.
NULL // stop loop here.
};
......@@ -4834,6 +4859,7 @@ const char *const POWERS_LIST[] = {
const char *const HUDITEMS_LIST[] = {
"LIVES",
"INPUT",
"RINGS",
"RINGSNUM",
......@@ -5095,6 +5121,10 @@ struct int_const_s const INT_CONST[] = {
{"RF_SHADOWEFFECTS",RF_SHADOWEFFECTS},
{"RF_DROPSHADOW",RF_DROPSHADOW},
// Animation flags
{"SPR2F_MASK",SPR2F_MASK},
{"SPR2F_SUPER",SPR2F_SUPER},
// Level flags
{"LF_SCRIPTISFILE",LF_SCRIPTISFILE},
{"LF_SPEEDMUSIC",LF_SPEEDMUSIC},
......@@ -5229,7 +5259,9 @@ struct int_const_s const INT_CONST[] = {
{"SF_MARIODAMAGE",SF_MARIODAMAGE},
{"SF_MACHINE",SF_MACHINE},
{"SF_DASHMODE",SF_DASHMODE},
{"SF_FASTWAIT",SF_FASTWAIT},
{"SF_FASTEDGE",SF_FASTEDGE},
{"SF_JETFUME",SF_JETFUME},
{"SF_MULTIABILITY",SF_MULTIABILITY},
{"SF_NONIGHTSROTATION",SF_NONIGHTSROTATION},
{"SF_NONIGHTSSUPER",SF_NONIGHTSSUPER},
......@@ -5577,8 +5609,7 @@ struct int_const_s const INT_CONST[] = {
{"ROTAXIS_Z",ROTAXIS_Z},
// Buttons (ticcmd_t)
{"BT_WEAPONMASK",BT_WEAPONMASK}, //our first three bits.
{"BT_SHIELD",BT_SHIELD},
{"BT_WEAPONMASK",BT_WEAPONMASK}, //our first four bits.
{"BT_WEAPONNEXT",BT_WEAPONNEXT},
{"BT_WEAPONPREV",BT_WEAPONPREV},
{"BT_ATTACK",BT_ATTACK}, // shoot rings
......@@ -5758,7 +5789,9 @@ struct int_const_s const INT_CONST[] = {
{"GC_WEPSLOT5",GC_WEPSLOT5},
{"GC_WEPSLOT6",GC_WEPSLOT6},
{"GC_WEPSLOT7",GC_WEPSLOT7},
{"GC_SHIELD",GC_SHIELD},
{"GC_WEPSLOT8",GC_WEPSLOT8},
{"GC_WEPSLOT9",GC_WEPSLOT9},
{"GC_WEPSLOT10",GC_WEPSLOT10},
{"GC_FIRE",GC_FIRE},
{"GC_FIRENORMAL",GC_FIRENORMAL},
{"GC_TOSSFLAG",GC_TOSSFLAG},
......@@ -5797,6 +5830,15 @@ struct int_const_s const INT_CONST[] = {
{"MB_BUTTON8",MB_BUTTON8},
{"MB_SCROLLUP",MB_SCROLLUP},
{"MB_SCROLLDOWN",MB_SCROLLDOWN},
// P_PathTraverse constants
{"PT_ADDLINES",PT_ADDLINES},
{"PT_ADDTHINGS",PT_ADDTHINGS},
{"PT_EARLYOUT",PT_EARLYOUT},
// screen.h constants
{"BASEVIDWIDTH",BASEVIDWIDTH},
{"BASEVIDHEIGHT",BASEVIDHEIGHT},
{NULL,0}
};
......
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// 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
// terms of the GNU General Public License, version 2.
......@@ -23,13 +23,13 @@
extern char *FREE_STATES[NUMSTATEFREESLOTS];
extern char *FREE_MOBJS[NUMMOBJFREESLOTS];
extern char *FREE_SKINCOLORS[NUMCOLORFREESLOTS];
extern UINT8 used_spr[(NUMSPRITEFREESLOTS / 8) + 1]; // Bitwise flag for sprite freeslot in use! I would use ceil() here if I could, but it only saves 1 byte of memory anyway.
extern bitarray_t used_spr[BIT_ARRAY_SIZE(NUMSPRITEFREESLOTS)]; // Sprite freeslots in use
#define initfreeslots() {\
memset(FREE_STATES,0,sizeof(char *) * NUMSTATEFREESLOTS);\
memset(FREE_MOBJS,0,sizeof(char *) * NUMMOBJFREESLOTS);\
memset(FREE_SKINCOLORS,0,sizeof(char *) * NUMCOLORFREESLOTS);\
memset(used_spr,0,sizeof(UINT8) * ((NUMSPRITEFREESLOTS / 8) + 1));\
memset(FREE_STATES, 0, sizeof(FREE_STATES));\
memset(FREE_MOBJS, 0, sizeof(FREE_MOBJS));\
memset(FREE_SKINCOLORS, 0, sizeof(FREE_SKINCOLORS));\
memset(used_spr, 0, sizeof(used_spr));\
memset(actionsoverridden, LUA_REFNIL, sizeof(actionsoverridden));\
}
......
......@@ -20,6 +20,7 @@ boolean deh_loaded = false;
boolean gamedataadded = false;
boolean titlechanged = false;
boolean introchanged = false;
boolean bootmapchanged = false;
static int dbg_line;
static INT32 deh_num_warning = 0;
......@@ -192,11 +193,14 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
INT32 i;
if (!deh_loaded)
{
initfreeslots();
deh_loaded = true;
}
deh_num_warning = 0;
gamedataadded = titlechanged = introchanged = false;
gamedataadded = titlechanged = introchanged = bootmapchanged = false;
// it doesn't test the version of SRB2 and version of dehacked file
dbg_line = -1; // start at -1 so the first line is 0.
......@@ -587,7 +591,12 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
if (gamestate == GS_TITLESCREEN)
{
if (introchanged)
if (bootmapchanged && bootmap)
{
menuactive = false;
D_MapChange(bootmap, gametype, ultimatemode, true, 0, false, false);
}
else if (introchanged)
{
menuactive = false;
I_UpdateMouseGrab();
......@@ -605,14 +614,10 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
if (deh_num_warning)
{
CONS_Printf(M_GetText("%d warning%s in the SOC lump\n"), deh_num_warning, deh_num_warning == 1 ? "" : "s");
if (devparm) {
if (devparm)
I_Error("%s%s",va(M_GetText("%d warning%s in the SOC lump\n"), deh_num_warning, deh_num_warning == 1 ? "" : "s"), M_GetText("See log.txt for details.\n"));
//while (!I_GetKey())
//I_OsPolling();
}
}
deh_loaded = true;
Z_Free(s);
}
......
......@@ -39,6 +39,7 @@ extern boolean deh_loaded;
extern boolean gamedataadded;
extern boolean titlechanged;
extern boolean introchanged;
extern boolean bootmapchanged;
#define MAX_ACTION_RECURSION 30
extern const char *luaactions[MAX_ACTION_RECURSION];
......
......@@ -75,7 +75,32 @@ enum
typedef struct
{
INT16 x, y;
}ATTRPACK mapvertex_t;
}ATTRPACK mapvertex_t;
typedef enum {
UDMF_TYPE_STRING,
UDMF_TYPE_FIXED,
UDMF_TYPE_NUMERIC,
UDMF_TYPE_BOOLEAN
} udmf_field_type_t;
typedef union { // v added to avoid random compilers cry about nonsense
char* vstring;
fixed_t vfloat;
INT32 vint;
boolean vbool;
} udmf_field_value_t;
// UDMF's Custom Arguments
typedef struct customargs_s
{
char* name;
udmf_field_type_t type;
udmf_field_value_t value;
struct customargs_s* next;
}ATTRPACK customargs_t;
// A SideDef, defining the visual appearance of a wall,
// by setting textures and offsets.
......@@ -218,6 +243,7 @@ typedef struct
fixed_t spritexscale, spriteyscale;
INT32 args[NUMMAPTHINGARGS];
char *stringargs[NUMMAPTHINGSTRINGARGS];
struct customargs_s* customargs;
struct mobj_s *mobj;
} mapthing_t;
......
......@@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// 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
// terms of the GNU General Public License, version 2.
......@@ -82,6 +82,7 @@
#include "version.h"
#include "doomtype.h"
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -167,7 +168,7 @@ extern char logfilename[1024];
// Does this version require an added patch file?
// Comment or uncomment this as necessary.
#define USE_PATCH_DTA
//#define USE_PATCH_DTA
// Enforce a limit of loaded WAD files.
//#define ENFORCE_WAD_LIMIT
......@@ -244,12 +245,12 @@ extern char logfilename[1024];
#define MAXPLAYERNAME 21
#define PLAYERSMASK (MAXPLAYERS-1)
// Don't make MAXSKINS higher than 256, since skin numbers are used with an
// UINT8 in various parts of the codebase. If you do anyway, the data type
// of those variables will have to be changed into at least an UINT16.
// Don't make MAXSKINS higher than 255, since skin numbers are used with an UINT8 in
// various parts of the codebase, and one number is reserved. If you do anyway,
// the data type of those variables will have to be changed into at least an UINT16.
// This change must affect code such as demo recording and playback,
// and the structure of some networking packets and commands.
#define MAXSKINS 256
#define MAXSKINS 255
#define MAXCHARACTERSLOTS (MAXSKINS * 3) // Should be higher than MAXSKINS.
#define COLORRAMPSIZE 16
......@@ -552,7 +553,7 @@ void *M_Memcpy(void* dest, const void* src, size_t n);
char *va(const char *format, ...) FUNCPRINTF;
char *M_GetToken(const char *inputString);
void M_UnGetToken(void);
void M_TokenizerOpen(const char *inputString);
void M_TokenizerOpen(const char *inputString, size_t len);
void M_TokenizerClose(void);
const char *M_TokenizerRead(UINT32 i);
const char *M_TokenizerReadZDoom(UINT32 i);
......@@ -648,6 +649,7 @@ UINT32 quickncasehash (const char *p, size_t n)
#else
#define I_Assert(e) ((void)0)
#endif
#define I_StaticAssert(e) static_assert(e, "Static assertion failed: " #e)
// The character that separates pathnames. Forward slash on
// most systems, but reverse solidus (\) on Windows.
......@@ -709,13 +711,6 @@ extern int
/// Experimental attempts at preventing MF_PAPERCOLLISION objects from getting stuck in walls.
//#define PAPER_COLLISIONCORRECTION
/// FINALLY some real clipping that doesn't make walls dissappear AND speeds the game up
/// (that was the original comment from SRB2CB, sadly it is a lie and actually slows game down)
/// on the bright side it fixes some weird issues with translucent walls
/// \note SRB2CB port.
/// SRB2CB itself ported this from PrBoom+
#define NEWCLIP
/// OpenGL shaders
#define GL_SHADERS
......
......@@ -2,7 +2,7 @@
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior.
// Copyright (C) 1999-2025 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
......@@ -165,7 +165,7 @@ extern boolean exitfadestarted;
typedef struct
{
UINT8 numpics;
char picname[8][8];
char picname[8][8+1];
UINT8 pichires[8];
char *text;
UINT16 xcoord[8];
......@@ -209,19 +209,19 @@ typedef struct
UINT8 picmode; // sequence mode after displaying last pic, 0 = persist, 1 = loop, 2 = destroy
UINT8 pictoloop; // if picmode == loop, which pic to loop to?
UINT8 pictostart; // initial pic number to show
char picname[MAX_PROMPT_PICS][8];
char picname[MAX_PROMPT_PICS][8+1];
UINT8 pichires[MAX_PROMPT_PICS];
UINT16 xcoord[MAX_PROMPT_PICS]; // gfx
UINT16 ycoord[MAX_PROMPT_PICS]; // gfx
UINT16 picduration[MAX_PROMPT_PICS];
char musswitch[7];
char musswitch[6+1];
UINT16 musswitchflags;
UINT8 musicloop;
char tag[33]; // page tag
char name[34]; // narrator name, extra char for color
char iconname[8]; // narrator icon lump
char tag[32+1]; // page tag
char name[32+2]; // narrator name, extra char for color
char iconname[8+1]; // narrator icon lump
boolean rightside; // narrator side, false = left, true = right
boolean iconflip; // narrator flip icon horizontally
UINT8 hidehud; // hide hud, 0 = show all, 1 = hide depending on prompt position (top/bottom), 2 = hide all
......@@ -233,7 +233,7 @@ typedef struct
sfxenum_t textsfx; // sfx_ id for printing text
UINT8 nextprompt; // next prompt to jump to, one-based. 0 = current prompt
UINT8 nextpage; // next page to jump to, one-based. 0 = next page within prompt->numpages
char nexttag[33]; // next tag to jump to. If set, this overrides nextprompt and nextpage.
char nexttag[32+1]; // next tag to jump to. If set, this overrides nextprompt and nextpage.
INT32 timetonext; // time in tics to jump to next page automatically. 0 = don't jump automatically
char *text;
} textpage_t;
......@@ -287,8 +287,8 @@ typedef struct
// (This is not ifdeffed so the map header structure can stay identical, just in case.)
typedef struct
{
char option[32]; // 31 usable characters
char value[256]; // 255 usable characters. If this seriously isn't enough then wtf.
char option[31+1]; // 31 usable characters
char value[255+1]; // 255 usable characters. If this seriously isn't enough then wtf.
} customoption_t;
/** Map header information.
......@@ -296,69 +296,70 @@ typedef struct
typedef struct
{
// The original eight, plus one.
char lvlttl[22]; ///< Level name without "Zone". (21 character limit instead of 32, 21 characters can display on screen max anyway)
char subttl[33]; ///< Subtitle for level
UINT8 actnum; ///< Act number or 0 for none.
UINT32 typeoflevel; ///< Combination of typeoflevel flags.
INT16 nextlevel; ///< Map number of next level, or 1100-1102 to end.
INT16 marathonnext; ///< See nextlevel, but for Marathon mode. Necessary to support hub worlds ala SUGOI.
char keywords[33]; ///< Keywords separated by space to search for. 32 characters.
char musname[7]; ///< Music track to play. "" for no music.
UINT16 mustrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore.
UINT32 muspos; ///< Music position to jump to.
char forcecharacter[17]; ///< (SKINNAMESIZE+1) Skin to switch to or "" to disable.
UINT8 weather; ///< 0 = sunny day, 1 = storm, 2 = snow, 3 = rain, 4 = blank, 5 = thunder w/o rain, 6 = rain w/o lightning, 7 = heat wave.
INT16 skynum; ///< Sky number to use.
INT16 skybox_scalex; ///< Skybox X axis scale. (0 = no movement, 1 = 1:1 movement, 16 = 16:1 slow movement, -4 = 1:4 fast movement, etc.)
INT16 skybox_scaley; ///< Skybox Y axis scale.
INT16 skybox_scalez; ///< Skybox Z axis scale.
char lvlttl[21+1]; ///< Level name without "Zone". (21 character limit instead of 32, 21 characters can display on screen max anyway)
char subttl[32+1]; ///< Subtitle for level
UINT8 actnum; ///< Act number or 0 for none.
UINT32 typeoflevel; ///< Combination of typeoflevel flags.
INT16 nextlevel; ///< Map number of next level, or 1100-1102 to end.
INT16 marathonnext; ///< See nextlevel, but for Marathon mode. Necessary to support hub worlds ala SUGOI.
char keywords[32+1]; ///< Keywords separated by space to search for. 32 characters.
char musname[6+1]; ///< Music track to play. "" for no music.
UINT16 mustrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore.
UINT32 muspos; ///< Music position to jump to.
char forcecharacter[16+1]; ///< (SKINNAMESIZE+1) Skin to switch to or "" to disable.
UINT8 weather; ///< 0 = sunny day, 1 = storm, 2 = snow, 3 = rain, 4 = blank, 5 = thunder w/o rain, 6 = rain w/o lightning, 7 = heat wave.
INT16 skynum; ///< Sky number to use.
INT16 skybox_scalex; ///< Skybox X axis scale. (0 = no movement, 1 = 1:1 movement, 16 = 16:1 slow movement, -4 = 1:4 fast movement, etc.)
INT16 skybox_scaley; ///< Skybox Y axis scale.
INT16 skybox_scalez; ///< Skybox Z axis scale.
// Extra information.
char interscreen[8]; ///< 320x200 patch to display at intermission.
char runsoc[33]; ///< SOC to execute at start of level (32 character limit instead of 63)
char scriptname[33]; ///< Script to use when the map is switched to. (32 character limit instead of 191)
UINT8 precutscenenum; ///< Cutscene number to play BEFORE a level starts.
UINT8 cutscenenum; ///< Cutscene number to use, 0 for none.
INT16 countdown; ///< Countdown until level end?
UINT16 palette; ///< PAL lump to use on this map
UINT8 numlaps; ///< Number of laps in circuit mode, unless overridden.
SINT8 unlockrequired; ///< Is an unlockable required to play this level? -1 if no.
UINT8 levelselect; ///< Is this map available in the level select? If so, which map list is it available in?
SINT8 bonustype; ///< What type of bonus does this level have? (-1 for null.)
SINT8 maxbonuslives; ///< How many bonus lives to award at Intermission? (-1 for unlimited.)
UINT16 levelflags; ///< LF_flags: merged booleans into one UINT16 for space, see below
UINT8 menuflags; ///< LF2_flags: options that affect record attack / nights mode menus
char selectheading[22]; ///< Level select heading. Allows for controllable grouping.
UINT16 startrings; ///< Number of rings players start with.
INT32 sstimer; ///< Timer for special stages.
UINT32 ssspheres; ///< Sphere requirement in special stages.
fixed_t gravity; ///< Map-wide gravity.
char interscreen[8+1]; ///< 320x200 patch to display at intermission.
char runsoc[32+1]; ///< SOC to execute at start of level (32 character limit instead of 63)
char scriptname[32+1]; ///< Script to use when the map is switched to. (32 character limit instead of 191)
UINT8 precutscenenum; ///< Cutscene number to play BEFORE a level starts.
UINT8 cutscenenum; ///< Cutscene number to use, 0 for none.
INT16 countdown; ///< Countdown until level end?
UINT16 palette; ///< PAL lump to use on this map
UINT8 numlaps; ///< Number of laps in circuit mode, unless overridden.
SINT8 unlockrequired; ///< Is an unlockable required to play this level? -1 if no.
UINT8 levelselect; ///< Is this map available in the level select? If so, which map list is it available in?
SINT8 bonustype; ///< What type of bonus does this level have? (-1 for null.)
SINT8 maxbonuslives; ///< How many bonus lives to award at Intermission? (-1 for unlimited.)
UINT16 levelflags; ///< LF_flags: merged booleans into one UINT16 for space, see below
UINT8 menuflags; ///< LF2_flags: options that affect record attack / nights mode menus
char selectheading[21+1]; ///< Level select heading. Allows for controllable grouping.
UINT16 startrings; ///< Number of rings players start with.
INT32 sstimer; ///< Timer for special stages.
UINT32 ssspheres; ///< Sphere requirement in special stages.
fixed_t gravity; ///< Map-wide gravity.
UINT16 nightstimer[8]; ///< Per-mare time limits for NiGHTS stages.
// Title card.
char ltzzpatch[9]; ///< Zig zag patch.
char ltzztext[9]; ///< Zig zag text.
char ltactdiamond[9]; ///< Act diamond.
char ltzzpatch[8+1]; ///< Zig zag patch.
char ltzztext[8+1]; ///< Zig zag text.
char ltactdiamond[8+1]; ///< Act diamond.
// Freed animals stuff.
UINT8 numFlickies; ///< Internal. For freed flicky support.
mobjtype_t *flickies; ///< List of freeable flickies in this level. Allocated dynamically for space reasons. Be careful.
UINT8 numFlickies; ///< Internal. For freed flicky support.
mobjtype_t *flickies; ///< List of freeable flickies in this level. Allocated dynamically for space reasons. Be careful.
// NiGHTS stuff.
UINT8 numGradedMares; ///< Internal. For grade support.
nightsgrades_t *grades; ///< NiGHTS grades. Allocated dynamically for space reasons. Be careful.
UINT8 numGradedMares; ///< Internal. For grade support.
nightsgrades_t *grades; ///< NiGHTS grades. Allocated dynamically for space reasons. Be careful.
// Music stuff.
UINT32 musinterfadeout; ///< Fade out level music on intermission screen in milliseconds
char musintername[7]; ///< Intermission screen music.
UINT32 musinterfadeout; ///< Fade out level music on intermission screen in milliseconds
char musintername[6+1]; ///< Intermission screen music.
char muspostbossname[7]; ///< Post-bossdeath music.
char muspostbossname[6+1]; ///< Post-bossdeath music.
UINT16 muspostbosstrack; ///< Post-bossdeath track.
UINT32 muspostbosspos; ///< Post-bossdeath position
UINT32 muspostbossfadein; ///< Post-bossdeath fade-in milliseconds.
SINT8 musforcereset; ///< Force resetmusic (-1 for default; 0 for force off; 1 for force on)
SINT8 musforcereset; ///< Force resetmusic (-1 for default; 0 for force off; 1 for force on)
// Lua stuff.
// (This is not ifdeffed so the map header structure can stay identical, just in case.)
......@@ -638,6 +639,7 @@ extern boolean singletics;
extern consvar_t cv_timetic; // display high resolution timer
extern consvar_t cv_powerupdisplay; // display powerups
extern consvar_t cv_showinput; // display input viewer outside of time attack
extern consvar_t cv_showinputjoy; // display joystick in time attack
extern consvar_t cv_forceskin; // force clients to use the server's skin
extern consvar_t cv_downloading; // allow clients to downloading WADs.
......