AUTOLOADING HECK YEAH
This commit is contained in:
1 parent
a96fb7d247
commit
088f1800ff
6 files changed
+252
-2
No files matched your search
+123
-1
@@ -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,11 @@ static const char *pagename = "MAP1PIC";
|
||||
static char *startupwadfiles[MAX_WADFILES];
|
||||
static char *startuppwads[MAX_WADFILES];
|
||||
|
||||
// autoloading
|
||||
static char *autoloadwadfiles[MAX_WADFILES];
|
||||
boolean autoloading;
|
||||
boolean autoloaded;
|
||||
|
||||
boolean devparm = false; // started game with -devparm
|
||||
|
||||
boolean singletics = false; // timedemo
|
||||
@@ -883,6 +888,106 @@ static void D_AddFile(const char *file, char **filearray)
|
||||
filearray[pnumwadfiles] = newfile;
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
// FIND THEM
|
||||
static void D_FindAddonsToAutoload(void)
|
||||
{
|
||||
FILE *autoloadconfigfile;
|
||||
const char *autoloadpath;
|
||||
|
||||
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)
|
||||
{
|
||||
// skip if commented or empty
|
||||
if ((wadsToAutoload[1] == '\0' || wadsToAutoload[1] == '\n')
|
||||
|| (wadsToAutoload[0] == '#'))
|
||||
continue;
|
||||
|
||||
// Remove Any Empty or Skipped Lines
|
||||
for (i = 0; wadsToAutoload[i] != '\0'; i++)
|
||||
{
|
||||
if (wadsToAutoload[i] == '\n')
|
||||
wadsToAutoload[i] = '\0';
|
||||
}
|
||||
|
||||
// LOAD IT
|
||||
D_AutoloadFile(wadsToAutoload, autoloadwadfiles);
|
||||
|
||||
// end it here
|
||||
for (i = 0; wadsToAutoload[i] != '\0'; i++)
|
||||
wadsToAutoload[i] = '\0';
|
||||
}
|
||||
|
||||
// we dont want memory leaks around here do we?
|
||||
fclose(autoloadconfigfile);
|
||||
}
|
||||
|
||||
static inline void D_CleanFile(char **filearray)
|
||||
{
|
||||
size_t pnumwadfiles;
|
||||
@@ -1186,6 +1291,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 +1418,20 @@ void D_SRB2Main(void)
|
||||
statdp = true;
|
||||
}
|
||||
|
||||
CONS_Printf("D_AutoloadFile(): Loading autoloaded addons...\n");
|
||||
if (W_InitMultipleFiles(autoloadwadfiles, true))
|
||||
{
|
||||
if (modifiedgame)
|
||||
{
|
||||
autoloaded = true;
|
||||
modifiedgame = false;
|
||||
}
|
||||
autoloading = false;
|
||||
}
|
||||
else // snarky remark
|
||||
CONS_Printf("D_AutoloadFile(): Are you sure you put in valid files or what?\n");
|
||||
D_CleanFile(autoloadwadfiles);
|
||||
|
||||
//
|
||||
// search for maps
|
||||
//
|
||||
|
||||
@@ -36,6 +36,9 @@ extern boolean kartzspeedo; //kartZ speedo
|
||||
extern boolean statdp; //kartZ speedo
|
||||
|
||||
|
||||
extern boolean autoloading;
|
||||
extern boolean autoloaded;
|
||||
|
||||
// the infinite loop of D_SRB2Loop() called from win_main for windows version
|
||||
void D_SRB2Loop(void) FUNCNORETURN;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user