Merge remote-tracking branch 'origin/hayaautoload' into Saturn-Next

This commit is contained in:
alufolie91 committed 2023-12-06 23:29:31 +01:00
commit d7cb89a232
9 files changed
+312 -3

No files matched your search

+10
View File
@@ -47,6 +47,7 @@
#include "k_kart.h"
#include "s_sound.h" // sfx_syfail
#include "m_perfstats.h"
#include "d_main.h"
#ifdef CLIENT_LOADINGSCREEN
// cl loading screen
@@ -1901,6 +1902,15 @@ static void CL_LoadReceivedSavegame(void)
demo.title = false;
automapactive = false;
if (!postautoloaded)
{
CONS_Printf("D_AutoloadFile(): Loading autoloaded addons...\n");
if (W_AddAutoloadedLocalFiles(autoloadwadfilespost) == 0)
CONS_Printf("D_AutoloadFile(): Are you sure you put in valid files or what?\n");
D_CleanFile(autoloadwadfilespost);
postautoloaded = true;
}
// load a base level
if (P_LoadNetGame())
{
+141 -2
View File
@@ -66,7 +66,7 @@
#include "fastcmp.h"
#include "r_fps.h" // Frame interpolation/uncapped
#include "keys.h"
#include "filesrch.h" // refreshdirmenu
#include "filesrch.h" // refreshdirmenu, pathisdirectory
#include "d_protocol.h"
#include "m_perfstats.h"
@@ -103,6 +103,13 @@ static const char *pagename = "MAP1PIC";
static char *startupwadfiles[MAX_WADFILES];
static char *startuppwads[MAX_WADFILES];
// autoloading
static char *autoloadwadfiles[MAX_WADFILES];
char *autoloadwadfilespost[MAX_WADFILES];
boolean autoloading;
boolean autoloaded;
boolean postautoloaded;
boolean devparm = false; // started game with -devparm
boolean singletics = false; // timedemo
@@ -883,7 +890,131 @@ static void D_AddFile(const char *file, char **filearray)
filearray[pnumwadfiles] = newfile;
}
static inline void D_CleanFile(char **filearray)
// Taken from TSoURDt3rd
// https://github.com/StarManiaKG/The-Story-of-Uncapped-Revengence-Discord-the-3rd/blob/main/src/STAR/star_functions.c
static INT32 D_DetectFileType(const char* filename)
{
if (pathisdirectory(filename) == 1)
return 1;
else
{
if (!stricmp(&filename[strlen(filename) - 4], ".wad"))
return 2;
else if (!stricmp(&filename[strlen(filename) - 4], ".pk3"))
return 3;
else if (!stricmp(&filename[strlen(filename) - 5], ".kart"))
return 4;
else if (!stricmp(&filename[strlen(filename) - 4], ".lua"))
return 5;
else if (!stricmp(&filename[strlen(filename) - 4], ".soc"))
return 6;
else if (!stricmp(&filename[strlen(filename) - 4], ".cfg"))
return 7;
else if (!stricmp(&filename[strlen(filename) - 4], ".txt"))
return 8;
}
return 0;
}
// autoload that shit
static void D_AutoloadFile(const char *file, char **filearray)
{
size_t pnumwadfiles;
char *newfile;
INT32 fileType = D_DetectFileType(file);
for (pnumwadfiles = 0; filearray[pnumwadfiles]; pnumwadfiles++)
;
newfile = malloc(strlen(file) + 1);
if (!newfile)
I_Error("No more free memory to AutoloadFile %s",file);
if (!fileType)
{
CONS_Printf("D_AutoloadFile: File %s is unknown or invalid\n", file);
return;
}
strcpy(newfile, file);
if (fileType <= 6)
filearray[pnumwadfiles] = newfile;
else
COM_BufAddText(va("exec %s\n", newfile));
}
static char *strremove(char *str, const char *sub) {
char *p, *q, *r;
if (*sub && (q = r = strstr(str, sub)) != NULL) {
size_t len = strlen(sub);
while ((r = strstr(p = r + len, sub)) != NULL) {
while (p < r)
*q++ = *p++;
}
while ((*q++ = *p++) != '\0')
continue;
}
return str;
}
// FIND THEM
static void D_FindAddonsToAutoload(void)
{
FILE *autoloadconfigfile;
const char *autoloadpath;
boolean postload;
INT32 i;
char wadsToAutoload[256] = "", renameAutoloadStrings[256] = "";
// does it exist tho
autoloadpath = va("%s"PATHSEP"%s",srb2home,AUTOLOADCONFIGFILENAME);
autoloadconfigfile = fopen(autoloadpath, "r");
// If the file is found, run our shit
if (!autoloadconfigfile) // nope outta here
return;
while (fgets(wadsToAutoload, sizeof wadsToAutoload, autoloadconfigfile) != NULL)
{
postload = false;
// skip if commented or empty
if ((wadsToAutoload[1] == '\0' || wadsToAutoload[1] == '\n')
|| (wadsToAutoload[0] == '#'))
continue;
// this marks it so that it loads after loading server addons
else if (fastncmp(wadsToAutoload, "postload ", 9)) {
strremove(wadsToAutoload, "postload ");
postload = true;
}
// Remove Any Empty or Skipped Lines
for (i = 0; wadsToAutoload[i] != '\0'; i++)
{
if (wadsToAutoload[i] == '\n')
wadsToAutoload[i] = '\0';
}
// LOAD IT
if (!postload)
D_AutoloadFile(wadsToAutoload, autoloadwadfiles);
else
D_AutoloadFile(wadsToAutoload, autoloadwadfilespost);
// end it here
for (i = 0; wadsToAutoload[i] != '\0'; i++)
wadsToAutoload[i] = '\0';
}
// we dont want memory leaks around here do we?
fclose(autoloadconfigfile);
}
void D_CleanFile(char **filearray)
{
size_t pnumwadfiles;
for (pnumwadfiles = 0; filearray[pnumwadfiles]; pnumwadfiles++)
@@ -1186,6 +1317,9 @@ void D_SRB2Main(void)
if (M_CheckParm("-password") && M_IsNextParm())
D_SetPassword(M_GetNextParm());
// FIND THEM
D_FindAddonsToAutoload();
// add any files specified on the command line with -file wadfile
// to the wad list
if (!(M_CheckParm("-connect") && !M_CheckParm("-server")))
@@ -1310,6 +1444,11 @@ void D_SRB2Main(void)
statdp = true;
}
CONS_Printf("D_AutoloadFile(): Loading autoloaded addons...\n");
if (W_AddAutoloadedLocalFiles(autoloadwadfiles) == 0)
CONS_Printf("D_AutoloadFile(): Are you sure you put in valid files or what?\n");
D_CleanFile(autoloadwadfiles);
//
// search for maps
//
+9
View File
@@ -36,6 +36,13 @@ extern boolean kartzspeedo; //kartZ speedo
extern boolean statdp; //kartZ speedo
extern boolean autoloading;
extern boolean autoloaded;
extern boolean postautoloaded;
extern boolean statdp; //kartZ speedo
extern char *autoloadwadfilespost[MAX_WADFILES];
// the infinite loop of D_SRB2Loop() called from win_main for windows version
void D_SRB2Loop(void) FUNCNORETURN;
@@ -51,6 +58,8 @@ void D_PostEvent(const event_t *ev);
void D_ProcessEvents(void);
void D_CleanFile(char **filearray);
const char *D_Home(void);
//
+17
View File
@@ -337,6 +337,23 @@ size_t dir_on[menudepth];
UINT8 refreshdirmenu = 0;
char *refreshdirname = NULL;
// Checks if the specified path is a directory.
// Returns 1 if so, 0 if not, and -1 if an error occurred.
// direrror is set if there was an error.
INT32 pathisdirectory(const char *path)
{
struct stat fsstat;
if (stat(path, &fsstat) < 0)
{
return -1;
}
else if (S_ISDIR(fsstat.st_mode))
return 1;
return 0;
}
filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, boolean completepath, int maxsearchdepth)
{
filestatus_t retval = FS_NOTFOUND;
+1
View File
@@ -89,6 +89,7 @@ typedef enum
REFRESHDIR_GAMEDATA = 64
} refreshdir_enum;
INT32 pathisdirectory(const char *path);
void closefilemenu(boolean validsize);
void searchfilemenu(char *tempname);
boolean preparefilemenu(boolean samedepth, boolean replayhut);
+106 -1
View File
@@ -6462,6 +6462,64 @@ static void M_AddonExec(INT32 ch)
COM_BufAddText(va("exec \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING));
}
// static void M_AddonAutoLoad(INT32 ch);
// exports mods to a file, which helps in autoloading that file
//
static void M_AddonAutoLoad(INT32 ch)
{
// initalize these variables //
const char *path;
FILE *autoloadconfigfile;
// check our controls //
if (ch != 'y' && ch != KEY_ENTER && ch != KEY_RSHIFT)
{
S_StartSound(NULL, sfx_s26d);
return;
}
// first, find the file //
path = va("%s"PATHSEP"%s", srb2home, AUTOLOADCONFIGFILENAME);
autoloadconfigfile = fopen(path, "a");
// then, execute the addon and store it in our autoload.cfg //
switch (dirmenu[dir_on[menudepthleft]][DIR_TYPE])
{
case EXT_FOLDER:
M_StartMessage(va("%c%s\x80\nAutoloading folders is not supported as of yet. \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING);
break;
case EXT_TXT:
case EXT_CFG:
CONS_Printf("Added the \x82%s\x80 console script to the autoload configuration list.\n", dirmenu[dir_on[menudepthleft]]+DIR_STRING);
fprintf(autoloadconfigfile, "%s\n", dirmenu[dir_on[menudepthleft]]+DIR_STRING);
S_StartSound(NULL, sfx_s221);
break;
case EXT_LUA:
case EXT_SOC:
case EXT_WAD:
case EXT_KART:
case EXT_PK3:
default:
if (!(refreshdirmenu & REFRESHDIR_MAX))
{
CONS_Printf("Added \x82%s\x80 to the autoload configuration list.\n", dirmenu[dir_on[menudepthleft]]+DIR_STRING);
fprintf(autoloadconfigfile, "%s\n", dirmenu[dir_on[menudepthleft]]+DIR_STRING);
S_StartSound(NULL, sfx_s221);
}
else
{
M_StartMessage(va("%c%s\x80\nToo many add-ons are loaded! \nYou need to restart the game to autoload more add-ons and folders. \nYou can still autoload console scripts though. \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING);
S_StartSound(NULL, sfx_s26d);
}
break;
}
// lastly, do some last things and close the autoload config file //
fclose(autoloadconfigfile);
}
#define len menusearch[0]
static boolean M_ChangeStringAddons(INT32 choice)
{
@@ -6650,6 +6708,53 @@ static void M_HandleAddons(INT32 choice)
}
break;
case KEY_RSHIFT:
{
boolean refresh = true;
if (!dirmenu[dir_on[menudepthleft]])
S_StartSound(NULL, sfx_s26d);
else
{
switch (dirmenu[dir_on[menudepthleft]][DIR_TYPE])
{
case EXT_FOLDER:
M_StartMessage(va("%c%s%s\x80\nAutoloading a folder is not yet suppported. \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), M_AddonsHeaderPath(), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING);
S_StartSound(NULL, sfx_s26d);
break;
case EXT_UP:
S_StartSound(NULL, sfx_s224);
M_StartMessage(va("%c%s%s\x80\nNice try. \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), M_AddonsHeaderPath(), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING);
break;
case EXT_TXT:
case EXT_CFG:
if ((strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, CONFIGFILENAME) == 0)
|| (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, AUTOLOADCONFIGFILENAME) == 0)
|| (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartserv.cfg") == 0)
|| (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartexec.cfg") == 0))
{
M_StartMessage(va("%c%s\x80\nYou can't autoload this builds' base console scripts, silly!\n They're already autoloaded on startup! \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING);
S_StartSound(NULL, sfx_s26d);
}
else
M_StartMessage(va("%c%s\x80\nYou're trying to autoload a console script. \nIgnore my warning anyways? \n\n(Press 'Y' to confirm)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),M_AddonAutoLoad,MM_YESNO);
break;
case EXT_LUA:
case EXT_SOC:
case EXT_WAD:
case EXT_KART:
case EXT_PK3:
M_StartMessage(va("%c%s\x80\nYou are trying to mark an addon to autoload\nat startup. This will skip modifiedgame checks. \n\n(Press 'Y' to confirm)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),M_AddonAutoLoad,MM_YESNO);
break;
default:
M_StartMessage(va("%c%s\x80\nIt may be dangerous to autoload this file. \nBut you're the boss, and I'm just hand-written code.\n Proceed? \n\n(Press 'Y' to confirm)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),M_AddonAutoLoad,MM_YESNO);
break;
}
}
if (refresh)
refreshdirmenu |= REFRESHDIR_NORMAL;
}
break;
case KEY_ESCAPE:
exitmenu = true;
break;
@@ -10716,7 +10821,7 @@ static void M_ConnectMenuModChecks(INT32 choice)
(void)choice;
// okay never mind we want to COMMUNICATE to the player pre-emptively instead of letting them try and then get confused when it doesn't work
if (modifiedgame)
if (modifiedgame || autoloaded)
{
M_StartMessage(M_GetText("You have addons loaded.\nYou won't be able to join netgames!\n\nTo play online, restart the game\nand don't load any addons.\nSRB2Kart will automatically add\neverything you need when you join.\n\n(Press a key)\n"),M_ConnectMenu,MM_EVENTHANDLER);
return;
+2
View File
@@ -41,6 +41,8 @@ void M_StopMovie(void);
// the file where game vars and settings are saved
#define CONFIGFILENAME "kartconfig.cfg"
// autoload!
#define AUTOLOADCONFIGFILENAME "autoload.cfg"
INT32 M_MapNumber(char first, char second);
+23
View File
@@ -66,6 +66,7 @@
#include "p_setup.h" // P_ScanThings
#endif
#include "m_misc.h" // M_MapNumber
#include "p_setup.h" // P_PartialAddFile mayb
#ifdef HWRENDER
#include "r_data.h"
@@ -939,6 +940,28 @@ INT32 W_InitMultipleFiles(char **filenames, boolean addons)
return overallrc;
}
INT32 W_AddAutoloadedLocalFiles(char **filenames)
{
UINT16 rc = 1;
INT32 overallrc = 1;
// will be realloced as lumps are added
for (; *filenames; filenames++)
{
rc = P_PartialAddWadFile(*filenames, true);
if (rc == UINT16_MAX)
CONS_Printf(M_GetText("Errors occurred while loading %s; not added.\n"), *filenames);
overallrc &= (rc != UINT16_MAX) ? 1 : 0;
}
if (!numwadfiles)
I_Error("W_AddAutoloadedLocalFiles: no files found");
if (P_PartialAddGetStage() >= 0)
P_MultiSetupWadFiles(true);
return overallrc;
}
/** Make sure a lump number is valid.
* Compiles away to nothing if PARANOIA is not defined.
*/
+3
View File
@@ -145,6 +145,9 @@ void W_UnloadWadFile(UINT16 num);
// so that it stops with a message if a file was not found, but not if all is okay.
INT32 W_InitMultipleFiles(char **filenames, boolean addons);
// Used for autoload. Uses P_AddWadFileLocal instead of W_InitFiles.
INT32 W_AddAutoloadedLocalFiles(char **filenames);
#define W_FileHasFolders(wadfile) ((wadfile)->type == RET_PK3)
const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump);