Replace mainwads with an enum

The mainwads check in G_SetGameModified is replaced by a modifiedgame check
in D_SRB2Main
This commit is contained in:
GenericHeroGuy 2025-03-28 02:21:14 +01:00
parent 721d0f9450
commit c936c24d15
13 changed files with 55 additions and 50 deletions

View file

@ -1625,7 +1625,7 @@ static void Setvalue(consvar_t *var, const char *valstr, boolean stealth)
const char *overridestr = valstr;
if (mainwads == 0 && var->PossibleValue == Color_cons_t)
if (numwadfiles == 0 && var->PossibleValue == Color_cons_t)
{
override = true;
if (!strcmp(valstr, "Blue"))

View file

@ -1482,41 +1482,30 @@ void D_SRB2Main(void)
W_InitMultipleFiles(startupiwads, false);
D_CleanFile(startupiwads);
mainwads = 0;
#ifndef DEVELOP
// Check MD5s of autoloaded files
// Note: Do not add any files that ignore MD5!
W_VerifyFileMD5(mainwads, ASSET_HASH_SRB2_SRB); // srb2.srb
wadfiles[mainwads]->compatmode = true;
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_GFX_KART); // gfx.kart
wadfiles[mainwads]->compatmode = true;
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_TEXTURES_KART); // textures.kart
wadfiles[mainwads]->compatmode = true;
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_CHARS_KART); // chars.kart
wadfiles[mainwads]->compatmode = true;
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_MAPS_KART); // maps.kart
wadfiles[mainwads]->compatmode = true;
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_MAIN_PK3); // main.pk3
W_VerifyFileMD5(MAINWAD_SRB2, ASSET_HASH_SRB2_SRB);
W_VerifyFileMD5(MAINWAD_GFX, ASSET_HASH_GFX_KART);
W_VerifyFileMD5(MAINWAD_TEXTURES, ASSET_HASH_TEXTURES_KART);
W_VerifyFileMD5(MAINWAD_CHARS, ASSET_HASH_CHARS_KART);
W_VerifyFileMD5(MAINWAD_MAPS, ASSET_HASH_MAPS_KART);
W_VerifyFileMD5(MAINWAD_MAIN, ASSET_HASH_MAIN_PK3);
#ifdef USE_PATCH_FILE
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_PK3); // patch.pk3
W_VerifyFileMD5(MAINWAD_PATCH, ASSET_HASH_PATCH_PK3);
#endif
#else
mainwads++; // gfx.kart
wadfiles[mainwads]->compatmode = true;
mainwads++; // textures.kart
wadfiles[mainwads]->compatmode = true;
mainwads++; // chars.kart
wadfiles[mainwads]->compatmode = true;
mainwads++; // maps.kart
wadfiles[mainwads]->compatmode = true;
mainwads++; // main.pk3
#ifdef USE_PATCH_FILE
mainwads++; // patch.pk3
#endif
#endif //ifndef DEVELOP
wadfiles[MAINWAD_SRB2]->compatmode = true;
wadfiles[MAINWAD_GFX]->compatmode = true;
wadfiles[MAINWAD_TEXTURES]->compatmode = true;
wadfiles[MAINWAD_CHARS]->compatmode = true;
wadfiles[MAINWAD_MAPS]->compatmode = true;
wadfiles[MAINWAD_MAIN]->compatmode = false;
#ifdef USE_PATCH_FILE
wadfiles[MAINWAD_PATCH]->compatmode = false;
#endif
R_InitPaletteRemap();
// now do it again for the SOC colors in main.pk3!
@ -1558,7 +1547,10 @@ void D_SRB2Main(void)
timelimits[GT_BATTLE] = 2;
CON_SetLoadingProgress(LOADED_HUINIT);
if (modifiedgame)
I_Error("modifiedgame set during startup!");
CONS_Printf("W_InitMultipleFiles(): Adding external PWADs.\n");
// HACK: Refer to https://git.do.srb2.org/KartKrew/RingRacers/-/merge_requests/29#note_61574

View file

@ -32,6 +32,20 @@ extern "C" {
#define GRAPHICSNAME "gfx.kart"
#define SOUNDSNAME "sounds.kart"
typedef enum
{
MAINWAD_SRB2,
MAINWAD_GFX,
MAINWAD_TEXTURES,
MAINWAD_CHARS,
MAINWAD_MAPS,
MAINWAD_MAIN,
#ifdef USE_PATCH_FILE
MAINWAD_PATCH,
#endif
NUMMAINWADS
} mainwad_t;
// make sure not to write back the config until it's been correctly loaded
extern tic_t rendergametic;

View file

@ -4782,7 +4782,7 @@ static void Command_ListWADS_f(void)
nameonly(tempname = va("%s", wadfiles[i]->filename));
if (!i)
CONS_Printf("\x82 IWAD\x80: %s\n", tempname);
else if (i <= mainwads)
else if (i < NUMMAINWADS)
CONS_Printf("\x82 * %.2d\x80: %s\n", i, tempname);
else if (!wadfiles[i]->important)
CONS_Printf("\x86 %.2d: %s\n", i, tempname);

View file

@ -158,13 +158,13 @@ UINT8 *PutFileNeeded(UINT16 firstfile)
#ifdef DEVELOP
i = 0;
#else
i = mainwads + 1;
i = NUMMAINWADS;
#endif
for (; i < numwadfiles; i++) //mainwads+1, otherwise we start on the first mainwad
{
// If it has only music/sound lumps, don't put it in the list
if (i > mainwads && !wadfiles[i]->important)
if (i >= NUMMAINWADS && !wadfiles[i]->important)
continue;
if (firstfile)
@ -190,7 +190,7 @@ UINT8 *PutFileNeeded(UINT16 firstfile)
/* don't send mainwads!! */
#ifdef DEVELOP
if (i <= mainwads)
if (i < NUMMAINWADS)
filestatus += (2 << 4);
#endif
@ -555,7 +555,7 @@ INT32 CL_CheckFiles(void)
#ifdef DEVELOP
j = 0;
#else
j = mainwads + 1;
j = NUMMAINWADS;
#endif
for (i = 0; i < fileneedednum || j < numwadfiles;)
{
@ -605,7 +605,7 @@ INT32 CL_CheckFiles(void)
#ifdef DEVELOP
j = 0;
#else
j = mainwads + 1;
j = NUMMAINWADS;
#endif
for (; wadfiles[j]; j++)
{

View file

@ -1133,7 +1133,7 @@ void readlevelheader(MYFILE *f, char * name)
{
P_AllocMapHeader((INT16)(num = nummapheaders));
}
else if (f->wad > mainwads)
else if (f->wad >= NUMMAINWADS)
{
// only mark as a major mod if it replaces an already-existing mapheaderinfo
G_SetGameModified(multiplayer, true);

View file

@ -325,7 +325,7 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
i = get_mobjtype(word2); // find a thing by name
if (i < NUMMOBJTYPES && i >= 0)
{
if (i < (MT_FIRSTFREESLOT+freeslotusage[1][1]))
if (!mainfile && i < (MT_FIRSTFREESLOT+freeslotusage[1][1]))
{
G_SetGameModified(multiplayer, true); // Only a major mod if editing stuff that isn't your own!
}
@ -444,7 +444,7 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
i = get_state(word2); // find a state by name
if (i < NUMSTATES && i >= 0)
{
if (i < (S_FIRSTFREESLOT+freeslotusage[0][1]))
if (!mainfile && i < (S_FIRSTFREESLOT+freeslotusage[0][1]))
{
G_SetGameModified(multiplayer, true); // Only a major mod if editing stuff that isn't your own!
}
@ -529,7 +529,7 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
while (cup)
{
if (hash == cup->namehash && fastcmp(cup->name, word2))
if (!mainfile && hash == cup->namehash && fastcmp(cup->name, word2))
{
// Only a major mod if editing stuff that isn't your own!
G_SetGameModified(multiplayer, true);

View file

@ -127,7 +127,6 @@ struct recorddata_t
// Set if homebrew PWAD stuff has been added.
extern boolean modifiedgame;
extern boolean majormods;
extern UINT16 mainwads;
extern boolean savemoddata; // This mod saves time/emblem data.
extern boolean imcontinuing; // Temporary flag while continuing
extern boolean metalrecording;

View file

@ -2149,7 +2149,7 @@ void G_BeginRecording(void)
demobuf.p += 1;
totalfiles = 0;
for (i = mainwads; ++i < numwadfiles; )
for (i = NUMMAINWADS-1; ++i < numwadfiles; )
if (wadfiles[i]->important)
{
nameonly(( filename = va("%s", wadfiles[i]->filename) ));
@ -2516,7 +2516,7 @@ static UINT8 G_CheckDemoExtraFiles(UINT8 **pp, boolean quick)
for (j = 0; j < numwadfiles; ++j)
{
if (wadfiles[j]->important && j > mainwads)
if (wadfiles[j]->important && j >= NUMMAINWADS)
nmusfilecount++;
else
continue;
@ -2552,7 +2552,7 @@ static UINT8 G_CheckDemoExtraFiles(UINT8 **pp, boolean quick)
nmusfilecount = 0;
for (j = 0; j < numwadfiles; ++j)
if (wadfiles[j]->important && j > mainwads)
if (wadfiles[j]->important && j >= NUMMAINWADS)
nmusfilecount++;
if (!error && filesloaded < nmusfilecount)

View file

@ -126,7 +126,6 @@ tic_t marathontime = 0;
UINT8 numgameovers = 0; // for startinglives balance
SINT8 startinglivesbalance[maxgameovers+1] = {3, 5, 7, 9, 12, 15, 20, 25, 30, 40, 50, 75, 99, 0x7F};
UINT16 mainwads = 0;
boolean modifiedgame = false; // Set if homebrew PWAD stuff has been added.
boolean majormods = false; // Set if Lua/Gameplay SOC/replacement map has been added.
boolean savemoddata = false;
@ -632,7 +631,7 @@ static void G_SetSaveGameModified(void)
// for consistency among messages: this modifies the game and removes savemoddata.
void G_SetGameModified(boolean silent, boolean major)
{
if ((majormods && modifiedgame) || !mainwads || (refreshdirmenu & REFRESHDIR_GAMEDATA)) // new gamedata amnesty?
if ((majormods && modifiedgame) || (refreshdirmenu & REFRESHDIR_GAMEDATA)) // new gamedata amnesty?
return;
modifiedgame = true;

View file

@ -3064,13 +3064,13 @@ void M_DrawAddons(void)
else
V_DrawCenteredString(BASEVIDWIDTH/2, 5, 0, (recommendedflags == V_SKYMAP ? LOCATIONSTRING2 : LOCATIONSTRING1));
if (numwadfiles <= mainwads+1)
if (numwadfiles <= NUMMAINWADS)
y = 0;
else if (numwadfiles >= MAX_WADFILES)
y = FRACUNIT;
else
{
y = FixedDiv(((ssize_t)(numwadfiles) - (ssize_t)(mainwads+1))<<FRACBITS, ((ssize_t)MAX_WADFILES - (ssize_t)(mainwads+1))<<FRACBITS);
y = FixedDiv(((ssize_t)(numwadfiles) - (ssize_t)(NUMMAINWADS))<<FRACBITS, ((ssize_t)MAX_WADFILES - (ssize_t)(NUMMAINWADS))<<FRACBITS);
if (y > FRACUNIT) // happens because of how we're shrinkin' it a little
y = FRACUNIT;
}

View file

@ -27,6 +27,7 @@
#include "p_local.h"
#include "dehacked.h" // get_number (for thok)
#include "m_cond.h"
#include "d_main.h" // MAINWAD_CHARS
#if 0
#include "k_kart.h" // K_KartResetPlayerColor
#endif
@ -153,7 +154,7 @@ void R_InitSkins(void)
for (i = 0; i < numwadfiles; i++)
{
if (i == 3) // chars.kart
if (i == MAINWAD_CHARS)
R_IHateThatHedgehog((UINT16)i);
R_AddSkins((UINT16)i);
if (!wadfiles[i]->compatmode)

View file

@ -1667,7 +1667,7 @@ void S_InitMusicDefs(void)
for (i = 0; i < numwadfiles; i++)
{
nameonly(tempname = va("%s", wadfiles[i]->filename));
if (wadfiles[i]->filename && !stricmp(tempname, "music.kart"))
if (wadfiles[i]->filename && !stricmp(tempname, MUSICNAME))
{
// Awful hack but what can you do?
continue;