Skip to content

Commit

Permalink
doom: add sideload support for Sigil II
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeday0 committed Dec 23, 2023
1 parent 19459a7 commit 53cc8b8
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/crispy.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ typedef struct
char *havenerve;
char *havemaster;
char *havesigil;
char *havesigil2;

const char *sdlversion;
const char *platform;
Expand Down
2 changes: 1 addition & 1 deletion src/doom/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ void D_DoomMain (void)
gamevariant != freedoom &&
strncasecmp(M_BaseName(iwadfile), "rekkr", 5))
{
D_LoadSigilWad();
D_LoadSigilWads();
}

if (gamemission == doom2)
Expand Down
180 changes: 155 additions & 25 deletions src/doom/d_pwad.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@
#include "m_misc.h"
#include "w_main.h"
#include "w_wad.h"
#include "w_merge.h" // [crispy] W_MergeFile()

extern char *iwadfile;

// [crispy] auto-load SIGIL.WAD (and SIGIL_SHREDS.WAD) if available
void D_LoadSigilWad (void)
static boolean LoadSigilWad (const char *iwaddir, boolean pwadtexture)

Check warning on line 36 in src/doom/d_pwad.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

src/doom/d_pwad.c:36:16 [readability-function-cognitive-complexity]

function 'LoadSigilWad' has cognitive complexity of 27 (threshold 25)
{
int i, j;
char *sigil_shreds = NULL;
const char *sigil_basename;
char *dirname, *autoload_dir;
char *autoload_dir;

Check warning on line 41 in src/doom/d_pwad.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

src/doom/d_pwad.c:41:8 [cppcoreguidelines-init-variables]

variable 'autoload_dir' is not initialized

const char *const sigil_wads[] = {
"SIGIL_v1_21.wad",
Expand All @@ -61,12 +62,6 @@ void D_LoadSigilWad (void)
{"D_INTRO", "D_SIGTIT"},
};

const char *const texture_files[] = {
"PNAMES",
"TEXTURE1",
"TEXTURE2",
};

// [crispy] don't load SIGIL.WAD if another PWAD already provides E5M1
i = W_CheckNumForName("E5M1");
if (i != -1)
Expand All @@ -76,34 +71,27 @@ void D_LoadSigilWad (void)
{
crispy->havesigil = (char *)-1;
}
return;
return false;
}

// [crispy] don't load SIGIL.WAD if SIGIL_COMPAT.WAD is already loaded
i = W_CheckNumForName("E3M1");
if (i != -1 && !strncasecmp(W_WadNameForLump(lumpinfo[i]), "SIGIL_COMPAT", 12))
{
return;
return false;
}

// [crispy] don't load SIGIL.WAD if another PWAD already modifies the texture files
for (i = 0; i < arrlen(texture_files); i++)
if (pwadtexture)
{
j = W_CheckNumForName(texture_files[i]);

if (j != -1 && !W_IsIWADLump(lumpinfo[j]))
{
return;
}
return false;
}

dirname = M_DirName(iwadfile);
sigil_shreds = M_StringJoin(dirname, DIR_SEPARATOR_S, "SIGIL_SHREDS.WAD", NULL);
sigil_shreds = M_StringJoin(iwaddir, DIR_SEPARATOR_S, "SIGIL_SHREDS.WAD", NULL);

// [crispy] load SIGIL.WAD
for (i = 0; i < arrlen(sigil_wads); i++)
{
crispy->havesigil = M_StringJoin(dirname, DIR_SEPARATOR_S, sigil_wads[i], NULL);
crispy->havesigil = M_StringJoin(iwaddir, DIR_SEPARATOR_S, sigil_wads[i], NULL);

if (M_FileExists(crispy->havesigil))
{
Expand All @@ -118,12 +106,11 @@ void D_LoadSigilWad (void)
break;
}
}
free(dirname);

if (crispy->havesigil == NULL)
{
free(sigil_shreds);
return;
return false;
}

printf(" [Sigil] adding %s\n", crispy->havesigil);
Expand Down Expand Up @@ -183,8 +170,151 @@ void D_LoadSigilWad (void)
}
}

// [crispy] regenerate the hashtable
W_GenerateHashTable();
return true;
}

// [crispy] auto-load Sigil II
static boolean LoadSigil2Wad (const char *iwaddir, boolean pwadtexture)
{
int i, j;

Check warning on line 179 in src/doom/d_pwad.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

src/doom/d_pwad.c:179:5 [readability-isolate-declaration]

multiple declarations in a single statement reduces readability

Check warning on line 179 in src/doom/d_pwad.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

src/doom/d_pwad.c:179:9 [cppcoreguidelines-init-variables]

variable 'i' is not initialized

Check warning on line 179 in src/doom/d_pwad.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

src/doom/d_pwad.c:179:9 [readability-identifier-length]

variable name 'i' is too short, expected at least 3 characters

Check warning on line 179 in src/doom/d_pwad.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

src/doom/d_pwad.c:179:12 [cppcoreguidelines-init-variables]

variable 'j' is not initialized

Check warning on line 179 in src/doom/d_pwad.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

src/doom/d_pwad.c:179:12 [readability-identifier-length]

variable name 'j' is too short, expected at least 3 characters
const char *sigil2_basename;

Check warning on line 180 in src/doom/d_pwad.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

src/doom/d_pwad.c:180:17 [cppcoreguidelines-init-variables]

variable 'sigil2_basename' is not initialized
char *autoload_dir;

Check warning on line 181 in src/doom/d_pwad.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

src/doom/d_pwad.c:181:11 [cppcoreguidelines-init-variables]

variable 'autoload_dir' is not initialized

const char *const sigil2_wads[] = {
"SIGIL_II_MP3_V1_0.WAD",
"SIGIL_II_V1_0.WAD",
};

static const struct {
const char *name;
const char new_name[8];
} sigil2_lumps [] = {
{"CREDIT", "SG2CREDI"},
{"HELP1", "SG2HELP1"},
{"TITLEPIC", "SG2TITLE"},
{"SIGILEND", "SGL2END"},
{"DEHACKED", "SG2_DEH"},
{"DEMO1", "SG2DEMO1"},
{"DEMO2", "SG2DEMO2"},
{"DEMO3", "SG2DEMO3"},
{"DEMO4", "SG2DEMO4"},
{"D_INTER", "D_SG2INT"},
{"D_INTRO", "D_SG2TIT"},
};

// [crispy] don't load Sigil II if another PWAD already provides E6M1
i = W_CheckNumForName("E6M1");
if (i != -1)
{
// [crispy] indicate that SIGIL_II_*.WAD is already loaded as a PWAD
if (!strncasecmp(W_WadNameForLump(lumpinfo[i]), "SIGIL_II", 8))
{
crispy->havesigil2 = (char *)-1;

Check warning on line 212 in src/doom/d_pwad.c

View workflow job for this annotation

GitHub Actions / cpp-linter (clang)

src/doom/d_pwad.c:212:34 [performance-no-int-to-ptr]

integer to pointer cast pessimizes optimization opportunities
}

return false;
}

// [crispy] don't load Sigil II if another PWAD already modifies the
// texture files
if (pwadtexture)
{
return false;
}

// [crispy] load Sigil II
for (i = 0; i < arrlen(sigil2_wads); i++)
{
crispy->havesigil2 = M_StringJoin(iwaddir, DIR_SEPARATOR_S,
sigil2_wads[i], NULL);

if (M_FileExists(crispy->havesigil2))
{
break;
}

free(crispy->havesigil2);
crispy->havesigil2 = D_FindWADByName(sigil2_wads[i]);

if (crispy->havesigil2)
{
break;
}
}

if (crispy->havesigil2 == NULL)
{
return false;
}

printf(" [Sigil II] adding %s\n", crispy->havesigil2);
W_MergeFile(crispy->havesigil2);
sigil2_basename = M_BaseName(crispy->havesigil2);

// [crispy] rename intrusive Sigil II graphics, demos and music lumps out
// of the way
for (i = 0; i < arrlen(sigil2_lumps); i++)
{
j = W_CheckNumForName(sigil2_lumps[i].name);

if (j != -1 && !strcasecmp(W_WadNameForLump(lumpinfo[j]), sigil2_basename))
{
memcpy(lumpinfo[j]->name, sigil2_lumps[i].new_name, 8);
}
}

// [crispy] load WAD and DEH files from autoload directories
if (!M_ParmExists("-noautoload"))
{
if ((autoload_dir = M_GetAutoloadDir(sigil2_basename, false)))
{
W_AutoLoadWADs(autoload_dir);
DEH_AutoLoadPatches(autoload_dir);
free(autoload_dir);
}
}

return true;
}

// [crispy] auto-load Sigil and Sigil II if available
void D_LoadSigilWads (void)
{
int i, j;
boolean sigilloaded, sigil2loaded;
boolean pwadtexture = false;
char *iwaddir;

const char *const texture_file[] = {
"PNAMES",
"TEXTURE1",
"TEXTURE2",
};

// [crispy] don't load Sigils if another PWAD already modifies the texture
// files
for (i = 0; i < arrlen(texture_file); i++)
{
j = W_CheckNumForName(texture_file[i]);

if (j != -1 && !W_IsIWADLump(lumpinfo[j]))
{
pwadtexture = true;
break;
}
}

iwaddir = M_DirName(iwadfile);
sigilloaded = LoadSigilWad(iwaddir, pwadtexture);
sigil2loaded = LoadSigil2Wad(iwaddir, pwadtexture);

if (sigilloaded || sigil2loaded)
{
// [crispy] regenerate the hashtable
W_GenerateHashTable();
}

free(iwaddir);
}

// [crispy] check if NERVE.WAD is already loaded as a PWAD
Expand Down
2 changes: 1 addition & 1 deletion src/doom/d_pwad.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef __D_PWAD__
#define __D_PWAD__

void D_LoadSigilWad(void);
void D_LoadSigilWads(void);
void D_LoadNerveWad(void);
void D_LoadMasterlevelsWad(void);

Expand Down
14 changes: 13 additions & 1 deletion src/doom/f_finale.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,13 +1013,25 @@ static void F_ArtScreenDrawer(void)
break;
// [crispy] Sigil
case 5:
case 6:
lumpname = "SIGILEND";
if (W_CheckNumForName(DEH_String(lumpname)) == -1)
{
return;
}
break;
// [crispy] Sigil II
case 6:
lumpname = "SGL2END";
if (W_CheckNumForName(DEH_String(lumpname)) == -1)
{
lumpname = "SIGILEND";

if (W_CheckNumForName(DEH_String(lumpname)) == -1)
{
return;
}
}
break;
default:
return;
}
Expand Down
8 changes: 8 additions & 0 deletions src/doom/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,14 @@ G_InitNew

M_ClearRandom ();

// [crispy] Spider Mastermind gets increased health in Sigil II. Normally
// the Sigil II DEH handles this, but we don't load the DEH if the WAD gets
// sideloaded.
if (crispy->havesigil2 && crispy->havesigil2 != (char *)-1)
{
mobjinfo[MT_SPIDER].spawnhealth = (episode == 6) ? 9000 : 3000;
}

if (skill == sk_nightmare || respawnparm )
respawnmonsters = true;
else
Expand Down
4 changes: 2 additions & 2 deletions src/doom/p_enemy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1720,9 +1720,9 @@ static boolean CheckBossEnd(mobjtype_t motype)
case 5:
return (gamemap == 8 && !critical->havesigil);

// [crispy] no trigger for Sigil II E6
// [crispy] no trigger for auto-loaded Sigil II E6
case 6:
return 0;
return (gamemap == 8 && !critical->havesigil2);

default:
return gamemap == 8;
Expand Down
1 change: 1 addition & 0 deletions src/doom/sounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ musicinfo_t S_music[] =
MUSIC("e6m8"),
MUSIC("e6m9"),
MUSIC("sigint"),
MUSIC("sg2int"),
MUSIC("inter"),
MUSIC("intro"),
MUSIC("bunny"),
Expand Down
1 change: 1 addition & 0 deletions src/doom/sounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ typedef enum
mus_e6m8,
mus_e6m9,
mus_sigint,
mus_sg2int,
mus_inter,
mus_intro,
mus_bunny,
Expand Down
3 changes: 3 additions & 0 deletions src/doom/wi_stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,9 @@ void WI_Ticker(void)
// [crispy] Sigil
else if (crispy->haved1e5 && wbs->epsd == 4 && W_CheckNumForName(DEH_String("D_SIGINT")) != -1)
S_ChangeMusic(mus_sigint, true);
// [crispy] Sigil II
else if (crispy->haved1e6 && wbs->epsd == 5 && W_CheckNumForName(DEH_String("D_SG2INT")) != -1)
S_ChangeMusic(mus_sg2int, true);
else
S_ChangeMusic(mus_inter, true);
}
Expand Down

0 comments on commit 53cc8b8

Please sign in to comment.