Merge branch 'master' into hardcoding-time-again

This commit is contained in:
Monster Iestyn 2018-02-13 21:21:30 +00:00
commit df95e2175f
13 changed files with 299 additions and 142 deletions

View file

@ -79,7 +79,7 @@
# SRB2 data files # SRB2 data files
D_DIR?=../bin/Resources D_DIR?=../bin/Resources
D_FILES=$(D_DIR)/srb2.srb \ D_FILES=$(D_DIR)/srb2.pk3 \
$(D_DIR)/player.dta \ $(D_DIR)/player.dta \
$(D_DIR)/rings.wpn \ $(D_DIR)/rings.wpn \
$(D_DIR)/drill.dta \ $(D_DIR)/drill.dta \

View file

@ -11,7 +11,7 @@
#ifdef CMAKECONFIG #ifdef CMAKECONFIG
#define ASSET_HASH_SRB2_SRB "${SRB2_ASSET_srb2.srb_HASH}" #define ASSET_HASH_SRB2_PK3 "${SRB2_ASSET_srb2.pk3_HASH}"
#define ASSET_HASH_PLAYER_DTA "${SRB2_ASSET_player.dta_HASH}" #define ASSET_HASH_PLAYER_DTA "${SRB2_ASSET_player.dta_HASH}"
#define ASSET_HASH_RINGS_DTA "${SRB2_ASSET_rings.dta_HASH}" #define ASSET_HASH_RINGS_DTA "${SRB2_ASSET_rings.dta_HASH}"
#define ASSET_HASH_ZONES_DTA "${SRB2_ASSET_zones.dta_HASH}" #define ASSET_HASH_ZONES_DTA "${SRB2_ASSET_zones.dta_HASH}"
@ -31,7 +31,7 @@
/* Manually defined asset hashes for non-CMake builds /* Manually defined asset hashes for non-CMake builds
* Last updated 2015 / 05 / 03 * Last updated 2015 / 05 / 03
*/ */
#define ASSET_HASH_SRB2_SRB "c1b9577687f8a795104aef4600720ea7" #define ASSET_HASH_SRB2_PK3 "c1b9577687f8a795104aef4600720ea7"
#define ASSET_HASH_ZONES_DTA "303838c6c534d9540288360fa49cca60" #define ASSET_HASH_ZONES_DTA "303838c6c534d9540288360fa49cca60"
#define ASSET_HASH_PLAYER_DTA "cfca0f1c73023cbbd8f844f45480f799" #define ASSET_HASH_PLAYER_DTA "cfca0f1c73023cbbd8f844f45480f799"
#define ASSET_HASH_RINGS_DTA "85901ad4bf94637e5753d2ac2c03ea26" #define ASSET_HASH_RINGS_DTA "85901ad4bf94637e5753d2ac2c03ea26"

View file

@ -784,7 +784,7 @@ static inline void D_CleanFile(void)
static void IdentifyVersion(void) static void IdentifyVersion(void)
{ {
char *srb2wad1, *srb2wad2; char *srb2wad;
const char *srb2waddir = NULL; const char *srb2waddir = NULL;
#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL)
@ -813,31 +813,24 @@ static void IdentifyVersion(void)
srb2waddir = I_GetWadDir(); srb2waddir = I_GetWadDir();
#endif #endif
// Commercial. // Commercial.
srb2wad1 = malloc(strlen(srb2waddir)+1+8+1); srb2wad = malloc(strlen(srb2waddir)+1+8+1);
srb2wad2 = malloc(strlen(srb2waddir)+1+8+1); if (srb2wad == NULL)
if (srb2wad1 == NULL && srb2wad2 == NULL)
I_Error("No more free memory to look in %s", srb2waddir); I_Error("No more free memory to look in %s", srb2waddir);
if (srb2wad1 != NULL) else
sprintf(srb2wad1, pandf, srb2waddir, "srb2.pk3"); sprintf(srb2wad, pandf, srb2waddir, "srb2.pk3");
if (srb2wad2 != NULL)
sprintf(srb2wad2, pandf, srb2waddir, "srb2.wad");
// will be overwritten in case of -cdrom or unix/win home // will be overwritten in case of -cdrom or unix/win home
snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, srb2waddir); snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, srb2waddir);
configfile[sizeof configfile - 1] = '\0'; configfile[sizeof configfile - 1] = '\0';
// Load the IWAD // Load the IWAD
if (srb2wad2 != NULL && FIL_ReadFileOK(srb2wad2)) if (srb2wad != NULL && FIL_ReadFileOK(srb2wad))
D_AddFile(srb2wad2); D_AddFile(srb2wad);
else if (srb2wad1 != NULL && FIL_ReadFileOK(srb2wad1))
D_AddFile(srb2wad1);
else else
I_Error("SRB2.SRB/SRB2.WAD not found! Expected in %s, ss files: %s and %s\n", srb2waddir, srb2wad1, srb2wad2); I_Error("srb2.pk3 not found! Expected in %s, ss file: %s\n", srb2waddir, srb2wad);
if (srb2wad1) if (srb2wad)
free(srb2wad1); free(srb2wad);
if (srb2wad2)
free(srb2wad2);
// if you change the ordering of this or add/remove a file, be sure to update the md5 // if you change the ordering of this or add/remove a file, be sure to update the md5
// checking in D_SRB2Main // checking in D_SRB2Main
@ -1132,7 +1125,7 @@ void D_SRB2Main(void)
#ifndef DEVELOP // md5s last updated 12/14/14 #ifndef DEVELOP // md5s last updated 12/14/14
// Check MD5s of autoloaded files // Check MD5s of autoloaded files
//W_VerifyFileMD5(0, ASSET_HASH_SRB2_SRB); // srb2.srb/srb2.wad //W_VerifyFileMD5(0, ASSET_HASH_SRB2_PK3); // srb2.pk3
//W_VerifyFileMD5(1, ASSET_HASH_ZONES_DTA); // zones.dta //W_VerifyFileMD5(1, ASSET_HASH_ZONES_DTA); // zones.dta
//W_VerifyFileMD5(2, ASSET_HASH_PLAYER_DTA); // player.dta //W_VerifyFileMD5(2, ASSET_HASH_PLAYER_DTA); // player.dta
#ifdef USE_PATCH_DTA #ifdef USE_PATCH_DTA

View file

@ -3071,7 +3071,7 @@ static void Command_Addfile(void)
// Add file on your client directly if it is trivial, or you aren't in a netgame. // Add file on your client directly if it is trivial, or you aren't in a netgame.
if (!(netgame || multiplayer) || musiconly) if (!(netgame || multiplayer) || musiconly)
{ {
P_AddWadFile(fn, NULL); P_AddWadFile(fn);
return; return;
} }
@ -3240,7 +3240,7 @@ static void Got_Addfilecmd(UINT8 **cp, INT32 playernum)
ncs = findfile(filename,md5sum,true); ncs = findfile(filename,md5sum,true);
if (ncs != FS_FOUND || !P_AddWadFile(filename, NULL)) if (ncs != FS_FOUND || !P_AddWadFile(filename))
{ {
Command_ExitGame_f(); Command_ExitGame_f();
if (ncs == FS_FOUND) if (ncs == FS_FOUND)

View file

@ -333,7 +333,7 @@ INT32 CL_CheckFiles(void)
// return 1; // return 1;
// the first is the iwad (the main wad file) // the first is the iwad (the main wad file)
// we don't care if it's called srb2.srb or srb2.wad. // we don't care if it's called srb2.pk3 or not.
// Never download the IWAD, just assume it's there and identical // Never download the IWAD, just assume it's there and identical
fileneeded[0].status = FS_OPEN; fileneeded[0].status = FS_OPEN;
@ -423,7 +423,7 @@ void CL_LoadServerFiles(void)
continue; // Already loaded continue; // Already loaded
else if (fileneeded[i].status == FS_FOUND) else if (fileneeded[i].status == FS_FOUND)
{ {
P_AddWadFile(fileneeded[i].filename, NULL); P_AddWadFile(fileneeded[i].filename);
G_SetGameModified(true); G_SetGameModified(true);
fileneeded[i].status = FS_OPEN; fileneeded[i].status = FS_OPEN;
} }
@ -754,6 +754,7 @@ void Got_Filetxpak(void)
static INT32 filetime = 0; static INT32 filetime = 0;
if (!(strcmp(filename, "srb2.pk3") if (!(strcmp(filename, "srb2.pk3")
&& strcmp(filename, "srb2.srb")
&& strcmp(filename, "srb2.wad") && strcmp(filename, "srb2.wad")
&& strcmp(filename, "zones.dta") && strcmp(filename, "zones.dta")
&& strcmp(filename, "player.dta") && strcmp(filename, "player.dta")

View file

@ -176,11 +176,16 @@ static inline void LUA_LoadFile(MYFILE *f, char *name)
LUA_ClearState(); LUA_ClearState();
lua_pushinteger(gL, f->wad); lua_pushinteger(gL, f->wad);
lua_setfield(gL, LUA_REGISTRYINDEX, "WAD"); lua_setfield(gL, LUA_REGISTRYINDEX, "WAD");
lua_lumploading = true; // turn on loading flag
if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, 0, 0)) { if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, 0, 0)) {
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1)); CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1));
lua_pop(gL,1); lua_pop(gL,1);
} }
lua_gc(gL, LUA_GCCOLLECT, 0); lua_gc(gL, LUA_GCCOLLECT, 0);
lua_lumploading = false; // turn off again
} }
// Load a script from a lump // Load a script from a lump
@ -188,24 +193,28 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump)
{ {
MYFILE f; MYFILE f;
char *name; char *name;
f.wad = wad; f.wad = wad;
f.size = W_LumpLengthPwad(wad, lump); f.size = W_LumpLengthPwad(wad, lump);
f.data = Z_Malloc(f.size, PU_LUA, NULL); f.data = Z_Malloc(f.size, PU_LUA, NULL);
W_ReadLumpPwad(wad, lump, f.data); W_ReadLumpPwad(wad, lump, f.data);
f.curpos = f.data; f.curpos = f.data;
name = malloc(strlen(wadfiles[wad]->filename)+10); if (wadfiles[wad]->type == RET_LUA)
{
name = malloc(strlen(wadfiles[wad]->filename)+1);
strcpy(name, wadfiles[wad]->filename); strcpy(name, wadfiles[wad]->filename);
if (!fasticmp(&name[strlen(name) - 4], ".lua")) { }
// If it's not a .lua file, copy the lump name in too. else // If it's not a .lua file, copy the lump name in too.
name[strlen(wadfiles[wad]->filename)] = '|'; {
M_Memcpy(name+strlen(wadfiles[wad]->filename)+1, wadfiles[wad]->lumpinfo[lump].name, 8); lumpinfo_t *lump_p = &wadfiles[wad]->lumpinfo[lump];
name[strlen(wadfiles[wad]->filename)+9] = '\0'; size_t length = strlen(wadfiles[wad]->filename) + 1 + strlen(lump_p->name2); // length of file name, '|', and lump name
name = malloc(length + 1);
sprintf(name, "%s|%s", wadfiles[wad]->filename, lump_p->name2);
name[length] = '\0';
} }
lua_lumploading = true; // turn on loading flag
LUA_LoadFile(&f, name); // actually load file! LUA_LoadFile(&f, name); // actually load file!
lua_lumploading = false; // turn off again
free(name); free(name);
Z_Free(f.data); Z_Free(f.data);

View file

@ -497,16 +497,34 @@ static void P_NetArchiveWorld(void)
UINT8 *put; UINT8 *put;
// reload the map just to see difference // reload the map just to see difference
const mapsector_t *ms; mapsector_t *ms;
const mapsidedef_t *msd; mapsidedef_t *msd;
const maplinedef_t *mld; maplinedef_t *mld;
const sector_t *ss = sectors; const sector_t *ss = sectors;
UINT8 diff, diff2; UINT8 diff, diff2;
WRITEUINT32(save_p, ARCHIVEBLOCK_WORLD); WRITEUINT32(save_p, ARCHIVEBLOCK_WORLD);
put = save_p; put = save_p;
if (W_IsLumpWad(lastloadedmaplumpnum)) // welp it's a map wad in a pk3
{ // HACK: Open wad file rather quickly so we can get the data from the relevant lumps
UINT8 *wadData = W_CacheLumpNum(lastloadedmaplumpnum, PU_STATIC);
filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs);
#define retrieve_mapdata(d, f)\
d = Z_Malloc((f)->size, PU_CACHE, NULL); \
M_Memcpy(d, wadData + (f)->filepos, (f)->size)
retrieve_mapdata(ms, fileinfo + ML_SECTORS);
retrieve_mapdata(mld, fileinfo + ML_LINEDEFS);
retrieve_mapdata(msd, fileinfo + ML_SIDEDEFS);
#undef retrieve_mapdata
Z_Free(wadData); // we're done with this now
}
else // phew it's just a WAD
{
ms = W_CacheLumpNum(lastloadedmaplumpnum+ML_SECTORS, PU_CACHE); ms = W_CacheLumpNum(lastloadedmaplumpnum+ML_SECTORS, PU_CACHE);
mld = W_CacheLumpNum(lastloadedmaplumpnum+ML_LINEDEFS, PU_CACHE);
msd = W_CacheLumpNum(lastloadedmaplumpnum+ML_SIDEDEFS, PU_CACHE);
}
for (i = 0; i < numsectors; i++, ss++, ms++) for (i = 0; i < numsectors; i++, ss++, ms++)
{ {
@ -637,8 +655,6 @@ static void P_NetArchiveWorld(void)
WRITEUINT16(put, 0xffff); WRITEUINT16(put, 0xffff);
mld = W_CacheLumpNum(lastloadedmaplumpnum+ML_LINEDEFS, PU_CACHE);
msd = W_CacheLumpNum(lastloadedmaplumpnum+ML_SIDEDEFS, PU_CACHE);
// do lines // do lines
for (i = 0; i < numlines; i++, mld++, li++) for (i = 0; i < numlines; i++, mld++, li++)
{ {

View file

@ -1893,6 +1893,30 @@ static void P_CreateBlockMap(void)
} }
} }
// Split from P_LoadBlockMap for convenience
// -- Monster Iestyn 08/01/18
static void P_ReadBlockMapLump(INT16 *wadblockmaplump, size_t count)
{
size_t i;
blockmaplump = Z_Calloc(sizeof (*blockmaplump) * count, PU_LEVEL, NULL);
// killough 3/1/98: Expand wad blockmap into larger internal one,
// by treating all offsets except -1 as unsigned and zero-extending
// them. This potentially doubles the size of blockmaps allowed,
// because Doom originally considered the offsets as always signed.
blockmaplump[0] = SHORT(wadblockmaplump[0]);
blockmaplump[1] = SHORT(wadblockmaplump[1]);
blockmaplump[2] = (INT32)(SHORT(wadblockmaplump[2])) & 0xffff;
blockmaplump[3] = (INT32)(SHORT(wadblockmaplump[3])) & 0xffff;
for (i = 4; i < count; i++)
{
INT16 t = SHORT(wadblockmaplump[i]); // killough 3/1/98
blockmaplump[i] = t == -1 ? (INT32)-1 : (INT32) t & 0xffff;
}
}
// //
// P_LoadBlockMap // P_LoadBlockMap
// //
@ -1919,37 +1943,19 @@ static boolean P_LoadBlockMap(lumpnum_t lumpnum)
return false; return false;
{ {
size_t i;
INT16 *wadblockmaplump = malloc(count); //INT16 *wadblockmaplump = W_CacheLumpNum (lump, PU_LEVEL); INT16 *wadblockmaplump = malloc(count); //INT16 *wadblockmaplump = W_CacheLumpNum (lump, PU_LEVEL);
if (!wadblockmaplump)
if (wadblockmaplump) W_ReadLump(lumpnum, wadblockmaplump); return false;
else return false; W_ReadLump(lumpnum, wadblockmaplump);
count /= 2; count /= 2;
blockmaplump = Z_Calloc(sizeof (*blockmaplump) * count, PU_LEVEL, 0); P_ReadBlockMapLump(wadblockmaplump, count);
// killough 3/1/98: Expand wad blockmap into larger internal one,
// by treating all offsets except -1 as unsigned and zero-extending
// them. This potentially doubles the size of blockmaps allowed,
// because Doom originally considered the offsets as always signed.
blockmaplump[0] = SHORT(wadblockmaplump[0]);
blockmaplump[1] = SHORT(wadblockmaplump[1]);
blockmaplump[2] = (INT32)(SHORT(wadblockmaplump[2])) & 0xffff;
blockmaplump[3] = (INT32)(SHORT(wadblockmaplump[3])) & 0xffff;
for (i = 4; i < count; i++)
{
INT16 t = SHORT(wadblockmaplump[i]); // killough 3/1/98
blockmaplump[i] = t == -1 ? (INT32)-1 : (INT32) t & 0xffff;
}
free(wadblockmaplump); free(wadblockmaplump);
}
bmaporgx = blockmaplump[0]<<FRACBITS; bmaporgx = blockmaplump[0]<<FRACBITS;
bmaporgy = blockmaplump[1]<<FRACBITS; bmaporgy = blockmaplump[1]<<FRACBITS;
bmapwidth = blockmaplump[2]; bmapwidth = blockmaplump[2];
bmapheight = blockmaplump[3]; bmapheight = blockmaplump[3];
}
// clear out mobj chains // clear out mobj chains
count = sizeof (*blocklinks)* bmapwidth*bmapheight; count = sizeof (*blocklinks)* bmapwidth*bmapheight;
@ -1984,6 +1990,53 @@ static boolean P_LoadBlockMap(lumpnum_t lumpnum)
#endif #endif
} }
// This needs to be a separate function
// because making both the WAD and PK3 loading code use
// the same functions is trickier than it looks for blockmap
// -- Monster Iestyn 09/01/18
static boolean P_LoadRawBlockMap(UINT8 *data, size_t count, const char *lumpname)
{
#if 0
(void)data;
(void)count;
(void)lumpname;
return false;
#else
// Check if the lump is named "BLOCKMAP"
if (!lumpname || memcmp(lumpname, "BLOCKMAP", 8) != 0)
{
CONS_Printf("No blockmap lump found for pk3!\n");
return false;
}
if (!count || count >= 0x20000)
return false;
CONS_Printf("Reading blockmap lump for pk3...\n");
// no need to malloc anything, assume the data is uncompressed for now
count /= 2;
P_ReadBlockMapLump((INT16 *)data, count);
bmaporgx = blockmaplump[0]<<FRACBITS;
bmaporgy = blockmaplump[1]<<FRACBITS;
bmapwidth = blockmaplump[2];
bmapheight = blockmaplump[3];
// clear out mobj chains
count = sizeof (*blocklinks)* bmapwidth*bmapheight;
blocklinks = Z_Calloc(count, PU_LEVEL, NULL);
blockmap = blockmaplump+4;
#ifdef POLYOBJECTS
// haleyjd 2/22/06: setup polyobject blockmap
count = sizeof(*polyblocklinks) * bmapwidth * bmapheight;
polyblocklinks = Z_Calloc(count, PU_LEVEL, NULL);
#endif
return true;
#endif
}
// //
// P_GroupLines // P_GroupLines
// Builds sector line lists and subsector sector numbers. // Builds sector line lists and subsector sector numbers.
@ -2109,6 +2162,30 @@ static void P_LoadReject(lumpnum_t lumpnum)
rejectmatrix = W_CacheLumpNum(lumpnum, PU_LEVEL); rejectmatrix = W_CacheLumpNum(lumpnum, PU_LEVEL);
} }
// PK3 version
// -- Monster Iestyn 09/01/18
static void P_LoadRawReject(UINT8 *data, size_t count, const char *lumpname)
{
// Check if the lump is named "REJECT"
if (!lumpname || memcmp(lumpname, "REJECT\0\0", 8) != 0)
{
rejectmatrix = NULL;
CONS_Debug(DBG_SETUP, "P_LoadRawReject: No valid REJECT lump found\n");
return;
}
if (!count) // zero length, someone probably used ZDBSP
{
rejectmatrix = NULL;
CONS_Debug(DBG_SETUP, "P_LoadRawReject: REJECT lump has size 0, will not be loaded\n");
}
else
{
rejectmatrix = Z_Malloc(count, PU_LEVEL, NULL); // allocate memory for the reject matrix
M_Memcpy(rejectmatrix, data, count); // copy the data into it
}
}
#if 0 #if 0
static char *levellumps[] = static char *levellumps[] =
{ {
@ -2581,7 +2658,6 @@ boolean P_SetupLevel(boolean skipprecip)
// use gamemap to get map number. // use gamemap to get map number.
// 99% of the things already did, so. // 99% of the things already did, so.
// Map header should always be in place at this point // Map header should always be in place at this point
char *lumpfullName;
INT32 i, loadprecip = 1, ranspecialwipe = 0; INT32 i, loadprecip = 1, ranspecialwipe = 0;
INT32 loademblems = 1; INT32 loademblems = 1;
INT32 fromnetsave = 0; INT32 fromnetsave = 0;
@ -2764,14 +2840,26 @@ boolean P_SetupLevel(boolean skipprecip)
// As it is implemented right now, we're assuming an uncompressed WAD. // As it is implemented right now, we're assuming an uncompressed WAD.
// (As in, a normal PWAD, not ZWAD or anything. The lump itself can be compressed.) // (As in, a normal PWAD, not ZWAD or anything. The lump itself can be compressed.)
// We're not accounting for extra lumps and scrambled lump positions. Any additional data will cause an error. // We're not accounting for extra lumps and scrambled lump positions. Any additional data will cause an error.
lumpfullName = (wadfiles[WADFILENUM(lastloadedmaplumpnum)]->lumpinfo + LUMPNUM(lastloadedmaplumpnum))->name2; if (W_IsLumpWad(lastloadedmaplumpnum))
if (!strnicmp(lumpfullName + strlen(lumpfullName) - 4, ".wad", 4))
{ {
// Remember that we're assuming that the WAD will have a specific set of lumps in a specific order. // Remember that we're assuming that the WAD will have a specific set of lumps in a specific order.
UINT8 *wadData = W_CacheLumpNum(lastloadedmaplumpnum, PU_STATIC); UINT8 *wadData = W_CacheLumpNum(lastloadedmaplumpnum, PU_STATIC);
//filelump_t *fileinfo = wadData + ((wadinfo_t *)wadData)->infotableofs; //filelump_t *fileinfo = wadData + ((wadinfo_t *)wadData)->infotableofs;
filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs); filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs);
UINT32 numlumps = ((wadinfo_t *)wadData)->numlumps;
if (numlumps < ML_REJECT) // at least 9 lumps should be in the wad for a map to be loaded
{
I_Error("Bad WAD file for map %s!\n", maplumpname);
}
if (numlumps > ML_BLOCKMAP) // enough room for a BLOCKMAP lump at least
{
loadedbm = P_LoadRawBlockMap(
wadData + (fileinfo + ML_BLOCKMAP)->filepos,
(fileinfo + ML_BLOCKMAP)->size,
(fileinfo + ML_BLOCKMAP)->name);
}
P_LoadRawVertexes(wadData + (fileinfo + ML_VERTEXES)->filepos, (fileinfo + ML_VERTEXES)->size); P_LoadRawVertexes(wadData + (fileinfo + ML_VERTEXES)->filepos, (fileinfo + ML_VERTEXES)->size);
P_LoadRawSectors(wadData + (fileinfo + ML_SECTORS)->filepos, (fileinfo + ML_SECTORS)->size); P_LoadRawSectors(wadData + (fileinfo + ML_SECTORS)->filepos, (fileinfo + ML_SECTORS)->size);
P_LoadRawSideDefs((fileinfo + ML_SIDEDEFS)->size); P_LoadRawSideDefs((fileinfo + ML_SIDEDEFS)->size);
@ -2780,6 +2868,13 @@ boolean P_SetupLevel(boolean skipprecip)
P_LoadRawSubsectors(wadData + (fileinfo + ML_SSECTORS)->filepos, (fileinfo + ML_SSECTORS)->size); P_LoadRawSubsectors(wadData + (fileinfo + ML_SSECTORS)->filepos, (fileinfo + ML_SSECTORS)->size);
P_LoadRawNodes(wadData + (fileinfo + ML_NODES)->filepos, (fileinfo + ML_NODES)->size); P_LoadRawNodes(wadData + (fileinfo + ML_NODES)->filepos, (fileinfo + ML_NODES)->size);
P_LoadRawSegs(wadData + (fileinfo + ML_SEGS)->filepos, (fileinfo + ML_SEGS)->size); P_LoadRawSegs(wadData + (fileinfo + ML_SEGS)->filepos, (fileinfo + ML_SEGS)->size);
if (numlumps > ML_REJECT) // enough room for a REJECT lump at least
{
P_LoadRawReject(
wadData + (fileinfo + ML_REJECT)->filepos,
(fileinfo + ML_REJECT)->size,
(fileinfo + ML_REJECT)->name);
}
// Important: take care of the ordering of the next functions. // Important: take care of the ordering of the next functions.
if (!loadedbm) if (!loadedbm)
@ -3133,7 +3228,7 @@ boolean P_RunSOC(const char *socfilename)
lumpnum_t lump; lumpnum_t lump;
if (strstr(socfilename, ".soc") != NULL) if (strstr(socfilename, ".soc") != NULL)
return P_AddWadFile(socfilename, NULL); return P_AddWadFile(socfilename);
lump = W_CheckNumForName(socfilename); lump = W_CheckNumForName(socfilename);
if (lump == LUMPERROR) if (lump == LUMPERROR)
@ -3163,6 +3258,7 @@ void P_LoadSoundsRange(UINT16 wadnum, UINT16 first, UINT16 num)
CONS_Debug(DBG_SETUP, "Sound %.8s replaced\n", lumpinfo->name); CONS_Debug(DBG_SETUP, "Sound %.8s replaced\n", lumpinfo->name);
I_FreeSfx(&S_sfx[j]); I_FreeSfx(&S_sfx[j]);
break; // there shouldn't be two sounds with the same name, so stop looking
} }
} }
} }
@ -3214,13 +3310,13 @@ static lumpinfo_t* FindFolder(const char *folName, UINT16 *start, UINT16 *end, l
// Add a wadfile to the active wad files, // Add a wadfile to the active wad files,
// replace sounds, musics, patches, textures, sprites and maps // replace sounds, musics, patches, textures, sprites and maps
// //
boolean P_AddWadFile(const char *wadfilename, char **firstmapname) boolean P_AddWadFile(const char *wadfilename)
{ {
size_t i, j, sreplaces = 0, mreplaces = 0, digmreplaces = 0; size_t i, j, sreplaces = 0, mreplaces = 0, digmreplaces = 0;
UINT16 numlumps, wadnum; UINT16 numlumps, wadnum;
INT16 firstmapreplaced = 0, num;
char *name; char *name;
lumpinfo_t *lumpinfo; lumpinfo_t *lumpinfo;
boolean mapsadded = false;
boolean replacedcurrentmap = false; boolean replacedcurrentmap = false;
// Vars to help us with the position start and amount of each resource type. // Vars to help us with the position start and amount of each resource type.
@ -3290,7 +3386,9 @@ boolean P_AddWadFile(const char *wadfilename, char **firstmapname)
name = lumpinfo->name; name = lumpinfo->name;
if (name[0] == 'D') if (name[0] == 'D')
{ {
if (name[1] == 'S') for (j = 1; j < NUMSFX; j++) if (name[1] == 'S')
{
for (j = 1; j < NUMSFX; j++)
{ {
if (S_sfx[j].name && !strnicmp(S_sfx[j].name, name + 2, 6)) if (S_sfx[j].name && !strnicmp(S_sfx[j].name, name + 2, 6))
{ {
@ -3301,6 +3399,8 @@ boolean P_AddWadFile(const char *wadfilename, char **firstmapname)
I_FreeSfx(&S_sfx[j]); I_FreeSfx(&S_sfx[j]);
sreplaces++; sreplaces++;
break; // there shouldn't be two sounds with the same name, so stop looking
}
} }
} }
else if (name[1] == '_') else if (name[1] == '_')
@ -3354,10 +3454,9 @@ boolean P_AddWadFile(const char *wadfilename, char **firstmapname)
for (i = 0; i < numlumps; i++, lumpinfo++) for (i = 0; i < numlumps; i++, lumpinfo++)
{ {
name = lumpinfo->name; name = lumpinfo->name;
num = firstmapreplaced;
if (name[0] == 'M' && name[1] == 'A' && name[2] == 'P') // Ignore the headers if (name[0] == 'M' && name[1] == 'A' && name[2] == 'P') // Ignore the headers
{ {
INT16 num;
if (name[5]!='\0') if (name[5]!='\0')
continue; continue;
num = (INT16)M_MapNumber(name[3], name[4]); num = (INT16)M_MapNumber(name[3], name[4]);
@ -3367,16 +3466,10 @@ boolean P_AddWadFile(const char *wadfilename, char **firstmapname)
replacedcurrentmap = true; replacedcurrentmap = true;
CONS_Printf("%s\n", name); CONS_Printf("%s\n", name);
} mapsadded = true;
if (num && (num < firstmapreplaced || !firstmapreplaced))
{
firstmapreplaced = num;
if (firstmapname)
*firstmapname = name;
} }
} }
if (!firstmapreplaced) if (!mapsadded)
CONS_Printf(M_GetText("No maps added\n")); CONS_Printf(M_GetText("No maps added\n"));
// reload status bar (warning should have valid player!) // reload status bar (warning should have valid player!)

View file

@ -59,7 +59,7 @@ void P_ScanThings(INT16 mapnum, INT16 wadnum, INT16 lumpnum);
#endif #endif
void P_LoadThingsOnly(void); void P_LoadThingsOnly(void);
boolean P_SetupLevel(boolean skipprecip); boolean P_SetupLevel(boolean skipprecip);
boolean P_AddWadFile(const char *wadfilename, char **firstmapname); boolean P_AddWadFile(const char *wadfilename);
boolean P_RunSOC(const char *socfilename); boolean P_RunSOC(const char *socfilename);
void P_LoadSoundsRange(UINT16 wadnum, UINT16 first, UINT16 num); void P_LoadSoundsRange(UINT16 wadnum, UINT16 first, UINT16 num);
void P_LoadMusicsRange(UINT16 wadnum, UINT16 first, UINT16 num); void P_LoadMusicsRange(UINT16 wadnum, UINT16 first, UINT16 num);

View file

@ -6305,9 +6305,21 @@ void P_SpawnSpecials(INT32 fromnetsave)
case 259: // Make-Your-Own FOF! case 259: // Make-Your-Own FOF!
if (lines[i].sidenum[1] != 0xffff) if (lines[i].sidenum[1] != 0xffff)
{ {
UINT8 *data = W_CacheLumpNum(lastloadedmaplumpnum + ML_SIDEDEFS,PU_STATIC); UINT8 *data;
UINT16 b; UINT16 b;
if (W_IsLumpWad(lastloadedmaplumpnum)) // welp it's a map wad in a pk3
{ // HACK: Open wad file rather quickly so we can get the data from the sidedefs lump
UINT8 *wadData = W_CacheLumpNum(lastloadedmaplumpnum, PU_STATIC);
filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs);
fileinfo += ML_SIDEDEFS; // we only need the SIDEDEFS lump
data = Z_Malloc(fileinfo->size, PU_STATIC, NULL);
M_Memcpy(data, wadData + fileinfo->filepos, fileinfo->size); // copy data
Z_Free(wadData); // we're done with this now
}
else // phew it's just a WAD
data = W_CacheLumpNum(lastloadedmaplumpnum + ML_SIDEDEFS,PU_STATIC);
for (b = 0; b < (INT16)numsides; b++) for (b = 0; b < (INT16)numsides; b++)
{ {
register mapsidedef_t *msd = (mapsidedef_t *)data + b; register mapsidedef_t *msd = (mapsidedef_t *)data + b;

View file

@ -124,7 +124,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
#include "macosx/mac_resources.h" #include "macosx/mac_resources.h"
#endif #endif
// Locations for searching the srb2.srb // Locations for searching the srb2.pk3
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) #if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2" #define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2"
#define DEFAULTWADLOCATION2 "/usr/local/games/SRB2" #define DEFAULTWADLOCATION2 "/usr/local/games/SRB2"
@ -143,7 +143,6 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
/** \brief WAD file to look for /** \brief WAD file to look for
*/ */
#define WADKEYWORD1 "srb2.pk3" #define WADKEYWORD1 "srb2.pk3"
#define WADKEYWORD2 "srb2.wad"
/** \brief holds wad path /** \brief holds wad path
*/ */
static char returnWadPath[256]; static char returnWadPath[256];
@ -2511,14 +2510,6 @@ static boolean isWadPathOk(const char *path)
return true; return true;
} }
sprintf(wad3path, pandf, path, WADKEYWORD2);
if (FIL_ReadFileOK(wad3path))
{
free(wad3path);
return true;
}
free(wad3path); free(wad3path);
return false; return false;
} }
@ -2536,7 +2527,7 @@ static void pathonly(char *s)
} }
} }
/** \brief search for srb2.srb in the given path /** \brief search for srb2.pk3 in the given path
\param searchDir starting path \param searchDir starting path
@ -2557,19 +2548,12 @@ static const char *searchWad(const char *searchDir)
return tempsw; return tempsw;
} }
strcpy(tempsw, WADKEYWORD2);
fstemp = filesearch(tempsw, searchDir, NULL, true, 20);
if (fstemp == FS_FOUND)
{
pathonly(tempsw);
return tempsw;
}
return NULL; return NULL;
} }
/** \brief go through all possible paths and look for srb2.srb /** \brief go through all possible paths and look for srb2.pk3
\return path to srb2.srb if any \return path to srb2.pk3 if any
*/ */
static const char *locateWad(void) static const char *locateWad(void)
{ {
@ -2698,7 +2682,7 @@ const char *I_LocateWad(void)
if (waddir) if (waddir)
{ {
// change to the directory where we found srb2.srb // change to the directory where we found srb2.pk3
#if defined (_WIN32) #if defined (_WIN32)
SetCurrentDirectoryA(waddir); SetCurrentDirectoryA(waddir);
#else #else

View file

@ -190,6 +190,7 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum)
if (posStart != INT16_MAX) if (posStart != INT16_MAX)
{ {
posEnd = W_CheckNumForFolderEndPK3("Lua/", wadnum, posStart); posEnd = W_CheckNumForFolderEndPK3("Lua/", wadnum, posStart);
posStart++; // first "lump" will be "Lua/" folder itself, so ignore it
for (; posStart < posEnd; posStart++) for (; posStart < posEnd; posStart++)
LUA_LoadLump(wadnum, posStart); LUA_LoadLump(wadnum, posStart);
} }
@ -197,8 +198,19 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum)
if (posStart != INT16_MAX) if (posStart != INT16_MAX)
{ {
posEnd = W_CheckNumForFolderEndPK3("SOCs/", wadnum, posStart); posEnd = W_CheckNumForFolderEndPK3("SOCs/", wadnum, posStart);
posStart++; // first "lump" will be "SOCs/" folder itself, so ignore it
for(; posStart < posEnd; posStart++) for(; posStart < posEnd; posStart++)
{
lumpinfo_t *lump_p = &wadfiles[wadnum]->lumpinfo[posStart];
size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->name2); // length of file name, '|', and lump name
char *name = malloc(length + 1);
sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->name2);
name[length] = '\0';
CONS_Printf(M_GetText("Loading SOC from %s\n"), name);
DEH_LoadDehackedLumpPwad(wadnum, posStart); DEH_LoadDehackedLumpPwad(wadnum, posStart);
free(name);
}
} }
} }
@ -222,16 +234,14 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum)
for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++) for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++)
if (memcmp(lump_p->name,"SOC_",4)==0) // Check for generic SOC lump if (memcmp(lump_p->name,"SOC_",4)==0) // Check for generic SOC lump
{ // shameless copy+paste of code from LUA_LoadLump { // shameless copy+paste of code from LUA_LoadLump
char *name = malloc(strlen(wadfiles[wadnum]->filename)+10); size_t length = strlen(wadfiles[wadnum]->filename) + 1 + strlen(lump_p->name2); // length of file name, '|', and lump name
strcpy(name, wadfiles[wadnum]->filename); char *name = malloc(length + 1);
if (!fasticmp(&name[strlen(name) - 4], ".soc")) { sprintf(name, "%s|%s", wadfiles[wadnum]->filename, lump_p->name2);
// If it's not a .soc file, copy the lump name in too. name[length] = '\0';
name[strlen(wadfiles[wadnum]->filename)] = '|';
M_Memcpy(name+strlen(wadfiles[wadnum]->filename)+1, lump_p->name, 8);
name[strlen(wadfiles[wadnum]->filename)+9] = '\0';
}
CONS_Printf(M_GetText("Loading SOC from %s\n"), name); CONS_Printf(M_GetText("Loading SOC from %s\n"), name);
DEH_LoadDehackedLumpPwad(wadnum, lump); DEH_LoadDehackedLumpPwad(wadnum, lump);
free(name);
} }
else if (memcmp(lump_p->name,"MAINCFG",8)==0) // Check for MAINCFG else if (memcmp(lump_p->name,"MAINCFG",8)==0) // Check for MAINCFG
{ {
@ -319,7 +329,7 @@ UINT16 W_InitFile(const char *filename)
FILE *handle; FILE *handle;
lumpinfo_t *lumpinfo; lumpinfo_t *lumpinfo;
wadfile_t *wadfile; wadfile_t *wadfile;
enum restype type; restype_t type;
UINT16 numlumps; UINT16 numlumps;
size_t i; size_t i;
INT32 compressed = 0; INT32 compressed = 0;
@ -390,7 +400,7 @@ UINT16 W_InitFile(const char *filename)
// This code emulates a wadfile with one lump name "OBJCTCFG" // This code emulates a wadfile with one lump name "OBJCTCFG"
// at position 0 and size of the whole file. // at position 0 and size of the whole file.
// This allows soc files to be like all wads, copied by network and loaded at the console. // This allows soc files to be like all wads, copied by network and loaded at the console.
type = RET_WAD; type = RET_SOC;
numlumps = 1; numlumps = 1;
lumpinfo = Z_Calloc(sizeof (*lumpinfo), PU_STATIC, NULL); lumpinfo = Z_Calloc(sizeof (*lumpinfo), PU_STATIC, NULL);
@ -411,7 +421,7 @@ UINT16 W_InitFile(const char *filename)
// This code emulates a wadfile with one lump name "LUA_INIT" // This code emulates a wadfile with one lump name "LUA_INIT"
// at position 0 and size of the whole file. // at position 0 and size of the whole file.
// This allows soc files to be like all wads, copied by network and loaded at the console. // This allows soc files to be like all wads, copied by network and loaded at the console.
type = RET_WAD; type = RET_LUA;
numlumps = 1; numlumps = 1;
lumpinfo = Z_Calloc(sizeof (*lumpinfo), PU_STATIC, NULL); lumpinfo = Z_Calloc(sizeof (*lumpinfo), PU_STATIC, NULL);
@ -733,11 +743,24 @@ UINT16 W_InitFile(const char *filename)
numwadfiles++; // must come BEFORE W_LoadDehackedLumps, so any addfile called by COM_BufInsertText called by Lua doesn't overwrite what we just loaded numwadfiles++; // must come BEFORE W_LoadDehackedLumps, so any addfile called by COM_BufInsertText called by Lua doesn't overwrite what we just loaded
// TODO: HACK ALERT - Load Lua & SOC stuff right here. I feel like this should be out of this place, but... Let's stick with this for now. // TODO: HACK ALERT - Load Lua & SOC stuff right here. I feel like this should be out of this place, but... Let's stick with this for now.
if (wadfile->type == RET_WAD) switch (wadfile->type)
{
case RET_WAD:
W_LoadDehackedLumps(numwadfiles - 1); W_LoadDehackedLumps(numwadfiles - 1);
else if (wadfile->type == RET_PK3) break;
case RET_PK3:
W_LoadDehackedLumpsPK3(numwadfiles - 1); W_LoadDehackedLumpsPK3(numwadfiles - 1);
break;
case RET_SOC:
CONS_Printf(M_GetText("Loading SOC from %s\n"), wadfile->filename);
DEH_LoadDehackedLumpPwad(numwadfiles - 1, 0);
break;
case RET_LUA:
LUA_LoadLump(numwadfiles - 1, 0);
break;
default:
break;
}
W_InvalidateLumpnumCache(); W_InvalidateLumpnumCache();
@ -1038,6 +1061,24 @@ size_t W_LumpLength(lumpnum_t lumpnum)
return W_LumpLengthPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum)); return W_LumpLengthPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum));
} }
//
// W_IsLumpWad
// Is the lump a WAD? (presumably in a PK3)
//
boolean W_IsLumpWad(lumpnum_t lumpnum)
{
if (wadfiles[WADFILENUM(lumpnum)]->type == RET_PK3)
{
const char *lumpfullName = (wadfiles[WADFILENUM(lumpnum)]->lumpinfo + LUMPNUM(lumpnum))->name2;
if (strlen(lumpfullName) < 4)
return false; // can't possibly be a WAD can it?
return !strnicmp(lumpfullName + strlen(lumpfullName) - 4, ".wad", 4);
}
return false; // WADs should never be inside non-PK3s as far as SRB2 is concerned
}
/* report a zlib or i/o error */ /* report a zlib or i/o error */
void zerr(int ret) void zerr(int ret)
{ {
@ -1117,30 +1158,30 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
I_Error("wad %d, lump %d: cannot read compressed data", wad, lump); I_Error("wad %d, lump %d: cannot read compressed data", wad, lump);
retval = lzf_decompress(rawData, l->disksize, decData, l->size); retval = lzf_decompress(rawData, l->disksize, decData, l->size);
#ifndef AVOID_ERRNO #ifndef AVOID_ERRNO
if (retval == 0 && errno == E2BIG) // errno is a global var set by the lzf functions when something goes wrong. if (retval == 0) // If this was returned, check if errno was set
{ {
// errno is a global var set by the lzf functions when something goes wrong.
if (errno == E2BIG)
I_Error("wad %d, lump %d: compressed data too big (bigger than %s)", wad, lump, sizeu1(l->size)); I_Error("wad %d, lump %d: compressed data too big (bigger than %s)", wad, lump, sizeu1(l->size));
} else if (errno == EINVAL)
else if (retval == 0 && errno == EINVAL)
I_Error("wad %d, lump %d: invalid compressed data", wad, lump); I_Error("wad %d, lump %d: invalid compressed data", wad, lump);
else }
// Otherwise, fall back on below error (if zero was actually the correct size then ???)
#endif #endif
if (retval != l->size) if (retval != l->size)
{ {
I_Error("wad %d, lump %d: decompressed to wrong number of bytes (expected %s, got %s)", wad, lump, sizeu1(l->size), sizeu2(retval)); I_Error("wad %d, lump %d: decompressed to wrong number of bytes (expected %s, got %s)", wad, lump, sizeu1(l->size), sizeu2(retval));
} }
#else
(void)wad;
(void)lump;
//I_Error("ZWAD files not supported on this platform.");
return NULL;
#endif
if (!decData) // Did we get no data at all? if (!decData) // Did we get no data at all?
return 0; return 0;
M_Memcpy(dest, decData + offset, size); M_Memcpy(dest, decData + offset, size);
Z_Free(rawData); Z_Free(rawData);
Z_Free(decData); Z_Free(decData);
return size; return size;
#else
//I_Error("ZWAD files not supported on this platform.");
return 0;
#endif
} }
case CM_DEFLATE: // Is it compressed via DEFLATE? Very common in ZIPs/PK3s, also what most doom-related editors support. case CM_DEFLATE: // Is it compressed via DEFLATE? Very common in ZIPs/PK3s, also what most doom-related editors support.
{ {

View file

@ -78,12 +78,18 @@ typedef struct
#endif #endif
// Resource type of the WAD. Yeah, I know this sounds dumb, but I'll leave it like this until I clean up the code further. // Resource type of the WAD. Yeah, I know this sounds dumb, but I'll leave it like this until I clean up the code further.
enum restype {RET_WAD, RET_PK3}; typedef enum restype
{
RET_WAD,
RET_SOC,
RET_LUA,
RET_PK3
} restype_t;
typedef struct wadfile_s typedef struct wadfile_s
{ {
char *filename; char *filename;
enum restype type; restype_t type;
lumpinfo_t *lumpinfo; lumpinfo_t *lumpinfo;
lumpcache_t *lumpcache; lumpcache_t *lumpcache;
#ifdef HWRENDER #ifdef HWRENDER
@ -133,6 +139,8 @@ UINT8 W_LumpExists(const char *name); // Lua uses this.
size_t W_LumpLengthPwad(UINT16 wad, UINT16 lump); size_t W_LumpLengthPwad(UINT16 wad, UINT16 lump);
size_t W_LumpLength(lumpnum_t lumpnum); size_t W_LumpLength(lumpnum_t lumpnum);
boolean W_IsLumpWad(lumpnum_t lumpnum); // for loading maps from WADs in PK3s
void zerr(int ret); // zlib error checking void zerr(int ret); // zlib error checking
size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, size_t offset); size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, size_t offset);