diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 1d9044dc9..172977b17 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -771,6 +771,7 @@ set (PCH_SOURCES common/inputstate.cpp common/searchpaths.cpp common/initfs.cpp + common/openaudio.cpp common/2d/v_2ddrawer.cpp common/2d/v_draw.cpp diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 94e05fc18..5ff36ce71 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -1254,8 +1254,6 @@ int app_main() I_Error("app_main: There was a problem initializing the Build engine: %s\n", engineerrstr); } - ScanINIFiles(); - initprintf("Initializing OSD...\n"); OSD_SetVersion("Blood", 10, 0); @@ -1298,8 +1296,6 @@ int app_main() ThrowError("TILES###.ART files not found"); } - LoadExtraArts(); - levelLoadDefaults(); loaddefinitionsfile(BLOODWIDESCREENDEF); @@ -2119,96 +2115,6 @@ int loaddefinitions_game(const char *fileName, int32_t firstPass) return 0; } -INICHAIN *pINIChain; -INICHAIN const*pINISelected; -int nINICount = 0; - -const char *pzCrypticArts[] = { - "CPART07.AR_", "CPART15.AR_" -}; - -INIDESCRIPTION gINIDescription[] = { - { "BLOOD: One Unit Whole Blood", "BLOOD.INI", NULL, 0 }, - { "Cryptic passage", "CRYPTIC.INI", pzCrypticArts, ARRAY_SSIZE(pzCrypticArts) }, -}; - -bool AddINIFile(const char *pzFile, bool bForce = false) -{ - char *pzFN; - struct Bstat st; - static INICHAIN *pINIIter = NULL; - if (!bForce) - { - if (findfrompath(pzFile, &pzFN)) return false; // failed to resolve the filename - if (Bstat(pzFN, &st)) - { - Bfree(pzFN); - return false; - } // failed to stat the file - Bfree(pzFN); - IniFile *pTempIni = new IniFile(pzFile); - if (!pTempIni->FindSection("Episode1")) - { - delete pTempIni; - return false; - } - delete pTempIni; - } - if (!pINIChain) - pINIIter = pINIChain = new INICHAIN; - else - pINIIter = pINIIter->pNext = new INICHAIN; - pINIIter->pNext = NULL; - pINIIter->pDescription = NULL; - Bstrncpy(pINIIter->zName, pzFile, BMAX_PATH); - for (int i = 0; i < ARRAY_SSIZE(gINIDescription); i++) - { - if (!Bstrncasecmp(pINIIter->zName, gINIDescription[i].pzFilename, BMAX_PATH)) - { - pINIIter->pDescription = &gINIDescription[i]; - break; - } - } - return true; -} - -void ScanINIFiles(void) -{ - nINICount = 0; - BUILDVFS_FIND_REC *pINIList = klistpath("/", "*.ini", BUILDVFS_FIND_FILE); - pINIChain = NULL; - - if (bINIOverride || !pINIList) - { - AddINIFile(BloodIniFile, true); - } - - for (auto pIter = pINIList; pIter; pIter = pIter->next) - { - AddINIFile(pIter->name); - } - klistfree(pINIList); - pINISelected = pINIChain; - for (auto pIter = pINIChain; pIter; pIter = pIter->pNext) - { - if (!Bstrncasecmp(BloodIniFile, pIter->zName, BMAX_PATH)) - { - pINISelected = pIter; - break; - } - } -} - -void LoadExtraArts(void) -{ - if (!pINISelected->pDescription) - return; - for (int i = 0; i < pINISelected->pDescription->nArts; i++) - { - TileFiles.LoadArtFile(pINISelected->pDescription->pzArts[i]); - } -} - bool DemoRecordStatus(void) { return gDemo.at0; } diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index a4b05fda3..846809ad9 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -42,7 +42,7 @@ struct INICHAIN { }; extern INICHAIN *pINIChain; -extern INICHAIN const*pINISelected; + enum INPUT_MODE { kInputGame = 0, @@ -77,7 +77,6 @@ void PreloadCache(void); void StartLevel(GAMEOPTIONS *gameOptions); void ProcessFrame(void); void ScanINIFiles(void); -void LoadExtraArts(void); bool DemoRecordStatus(void); bool VanillaMode(void); bool fileExistsRFF(int id, const char* ext); diff --git a/source/blood/src/common.cpp b/source/blood/src/common.cpp index 06449b4d2..30a9c658d 100644 --- a/source/blood/src/common.cpp +++ b/source/blood/src/common.cpp @@ -34,19 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "palette.h" #include "gamecvars.h" -#ifdef _WIN32 -# define NEED_SHLWAPI_H -# include "windows_inc.h" -# include "win32/winbits.h" -# ifndef KEY_WOW64_64KEY -# define KEY_WOW64_64KEY 0x0100 -# endif -# ifndef KEY_WOW64_32KEY -# define KEY_WOW64_32KEY 0x0200 -# endif -#elif defined __APPLE__ -# include "osxbits.h" -#endif #include "common.h" #include "common_game.h" @@ -73,114 +60,5 @@ void G_SetupGlobalPsky(void) } -////////// - -#ifdef FORMAT_UPGRADE_ELIGIBLE - -static FileReader S_TryFormats(char * const testfn, char * const fn_suffix, char const searchfirst) -{ -#ifdef HAVE_FLAC - { - Bstrcpy(fn_suffix, ".flac"); - auto fp = kopenFileReader(testfn, searchfirst); - if (fp.isOpen()) - return fp; - } -#endif - -#ifdef HAVE_VORBIS - { - Bstrcpy(fn_suffix, ".ogg"); - auto fp = kopenFileReader(testfn, searchfirst); - if (fp.isOpen()) - return fp; - } -#endif - - return FileReader(); -} - -static FileReader S_TryExtensionReplacements(char * const testfn, char const searchfirst, uint8_t const ismusic) -{ - char * extension = Bstrrchr(testfn, '.'); - char * const fn_end = Bstrchr(testfn, '\0'); - - // ex: grabbag.voc --> grabbag_voc.* - if (extension != NULL) - { - *extension = '_'; - - auto fp = S_TryFormats(testfn, fn_end, searchfirst); - if (fp.isOpen()) - return fp; - } - else - { - extension = fn_end; - } - - // ex: grabbag.mid --> grabbag.* - if (ismusic) - { - auto fp = S_TryFormats(testfn, extension, searchfirst); - if (fp.isOpen()) - return fp; - } - - return FileReader(); -} - -FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic) -{ - auto origfp = kopenFileReader(fn, searchfirst); - char const* const origparent = origfp.isOpen() ? kfileparent(origfp) : NULL; - uint32_t const parentlength = origparent != NULL ? Bstrlen(origparent) : 0; - - auto testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + parentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0' - - // look in ./ - // ex: ./grabbag.mid - Bstrcpy(testfn, fn); - auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); - if (fp.isOpen()) - { - Bfree(testfn); - return fp; - } - - // look in ./music// - // ex: ./music/duke3d/grabbag.mid - // ex: ./music/nwinter/grabbag.mid - if (origparent != NULL) - { - char const * const parentextension = Bstrrchr(origparent, '.'); - uint32_t const namelength = parentextension != NULL ? (unsigned)(parentextension - origparent) : parentlength; - - Bsprintf(testfn, "music/%.*s/%s", namelength, origparent, fn); - auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); - if (fp.isOpen()) - { - Bfree(testfn); - return fp; - } - } - - // look in ./music/ - // ex: ./music/grabbag.mid - { - Bsprintf(testfn, "music/%s", fn); - auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); - if (fp.isOpen()) - { - Bfree(testfn); - return fp; - } - } - - Bfree(testfn); - return origfp; -} - -#endif END_BLD_NS diff --git a/source/blood/src/common_game.h b/source/blood/src/common_game.h index 1a5e46008..8ca7e8890 100644 --- a/source/blood/src/common_game.h +++ b/source/blood/src/common_game.h @@ -528,9 +528,6 @@ static inline int gameHandleEvents(void) return handleevents(); } -# define FORMAT_UPGRADE_ELIGIBLE -extern FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t ismusic); - #pragma pack(push,1) #if 0 diff --git a/source/blood/src/levels.cpp b/source/blood/src/levels.cpp index 1946a0c9d..17db5a5bf 100644 --- a/source/blood/src/levels.cpp +++ b/source/blood/src/levels.cpp @@ -226,7 +226,7 @@ void levelLoadDefaults(void) { char buffer[64]; char buffer2[16]; - levelInitINI(pINISelected->zName); + levelInitINI(G_ConFile()); // This doubles for the INI in the global code. memset(gEpisodeInfo, 0, sizeof(gEpisodeInfo)); strncpy(gEpisodeInfo[MUS_INTRO/kMaxLevels].at28[MUS_INTRO%kMaxLevels].atd0, "PESTIS", BMAX_PATH); int i; @@ -275,7 +275,6 @@ void levelLoadDefaults(void) void levelAddUserMap(const char *pzMap) { char buffer[BMAX_PATH]; - //strcpy(buffer, g_modDir); strncpy(buffer, pzMap, BMAX_PATH); ChangeExtension(buffer, ".DEF"); diff --git a/source/blood/src/osdcmd.cpp b/source/blood/src/osdcmd.cpp index 9e63ae341..4a94dff4b 100644 --- a/source/blood/src/osdcmd.cpp +++ b/source/blood/src/osdcmd.cpp @@ -524,7 +524,6 @@ int32_t registerosdcommands(void) OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god); // OSD_RegisterFunction("activatecheat","activatecheat : activates a cheat code", osdcmd_activatecheat); // -// OSD_RegisterFunction("initgroupfile","initgroupfile : adds a grp file into the game filesystem", osdcmd_initgroupfile); //#ifdef DEBUGGINGAIDS // OSD_RegisterFunction("inittimer","debug", osdcmd_inittimer); //#endif diff --git a/source/blood/src/sound.cpp b/source/blood/src/sound.cpp index 0daeaaf40..114e02e0b 100644 --- a/source/blood/src/sound.cpp +++ b/source/blood/src/sound.cpp @@ -33,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "sound.h" #include "renderlayer.h" #include "al_midi.h" +#include "openaudio.h" BEGIN_BLD_NS diff --git a/source/build/include/cache1d.h b/source/build/include/cache1d.h index 380f91742..8bf9aa2e1 100644 --- a/source/build/include/cache1d.h +++ b/source/build/include/cache1d.h @@ -15,55 +15,15 @@ #include "vfs.h" extern char *kpzbuf; -extern int32_t kpzbufsiz; -extern int32_t kpzbufload(const char *); -void cacheInitBuffer(int32_t dacachesize); void cacheAllocateBlock(intptr_t *newhandle, int32_t newbytes, uint8_t *newlockptr); -void cacheAgeEntries(void); using buildvfs_kfd = int32_t; -#define buildvfs_kfd_invalid (-1) extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode) -char *listsearchpath(int32_t initp); -int32_t addsearchpath_user(const char *p, int32_t user); -#define addsearchpath(a) addsearchpath_user(a, 0) -int32_t removesearchpath(const char *p); -void removesearchpaths_withuser(int32_t usermask); -int32_t findfrompath(const char *fn, char **where); -buildvfs_kfd openfrompath(const char *fn, int32_t flags, int32_t mode); -buildvfs_FILE fopenfrompath(const char *fn, const char *mode); extern char g_modDir[BMAX_PATH]; -extern int32_t numgroupfiles; -int initgroupfile(const char *filename); -void uninitgroupfile(void); -buildvfs_kfd kopen4load(const char *filename, char searchfirst); // searchfirst: 0 = anywhere, 1 = first group, 2 = any group -buildvfs_kfd kopen4loadfrommod(const char *filename, char searchfirst); -int32_t kread(buildvfs_kfd handle, void *buffer, int32_t leng); -#define kread_and_test(handle, buffer, leng) EDUKE32_PREDICT_FALSE(kread((handle), (buffer), (leng)) != (leng)) -int32_t klseek(buildvfs_kfd handle, int32_t offset, int32_t whence); -#define klseek_and_test(handle, offset, whence) EDUKE32_PREDICT_FALSE(klseek((handle), (offset), (whence)) < 0) -int32_t kfilelength(buildvfs_kfd handle); -int32_t ktell(buildvfs_kfd handle); -void kclose(buildvfs_kfd handle); -void krename(int32_t crcval, int32_t filenum, const char *newname); -char const * kfileparent(int32_t handle); - -extern int32_t kpzbufloadfil(buildvfs_kfd); - -#ifdef WITHKPLIB -int32_t cache1d_file_fromzip(buildvfs_kfd fil); -#endif - -typedef struct -{ - intptr_t *hand; - int32_t leng; - uint8_t * lock; -} cactype; enum { CACHE1D_FIND_FILE = 1, @@ -95,101 +55,64 @@ int32_t klistaddentry(CACHE1D_FIND_REC **rec, const char *name, int32_t type, in void klistfree(CACHE1D_FIND_REC *rec); CACHE1D_FIND_REC *klistpath(const char *path, const char *mask, int type); -extern int32_t lz4CompressionLevel; -int32_t kdfread_LZ4(void *buffer, int dasizeof, int count, buildvfs_kfd fil); -int32_t kdfread_LZ4(void* buffer, int dasizeof, int count, FileReader& fil); -void dfwrite_LZ4(const void *buffer, int dasizeof, int count, buildvfs_FILE fil); +// compression disabled pending a better process for saving. Per-block compression as done here was not that great. +int32_t kdfread_LZ4(void* buffer, int dasizeof, int count, buildvfs_kfd fil) = delete; -class KFileReaderInterface : public FileReaderInterface +inline int32_t kdfread_LZ4(void* buffer, int dasizeof, int count, FileReader& fil) { - buildvfs_kfd khandle = buildvfs_kfd_invalid; -public: + return fil.Read(buffer, dasizeof * count); +} - KFileReaderInterface(int handle) - { - khandle = handle; - Length = 0; - if (khandle != buildvfs_kfd_invalid) - { - klseek(khandle, 0, SEEK_END); - Length = ktell(khandle); - klseek(khandle, 0, SEEK_SET); - } - } - ~KFileReaderInterface() - { - if (khandle != buildvfs_kfd_invalid) - { - kclose(khandle); - } - } - virtual long Tell() const - { - return ktell(khandle); - } - virtual long Seek(long offset, int origin) - { - return klseek(khandle, offset, origin); - } - virtual long Read(void* buffer, long len) - { - return kread(khandle, buffer, (int32_t)len); - } - virtual char* Gets(char* strbuf, int len) - { - // Not supported by the underlying system, so we do not need it anyway. - // Gross hack alert: Abuse this function to return the container's name until we have a better resource management in place. - // Right now there is no way to cleanly pass this through and this function is the most convenient workaround. - return (char*)kfileparent(khandle); - } +inline void dfwrite_LZ4(const void* buffer, int dasizeof, int count, buildvfs_FILE fil) +{ + fwrite(buffer, dasizeof, count, fil); +} -}; -FileReader openFromBaseResource(const char* name); +#include "filesystem/filesystem.h" + // Wrappers for the handle based API to get rid of the direct calls without any actual changes to the implementation. +// These are now getting redirected to the file system so that the implementation here can be gutted without making changes to the calling code. inline FileReader kopenFileReader(const char* name, int where) { - int handle = where == 0 ? kopen4loadfrommod(name, 0) : kopen4load(name, where); - if (handle != buildvfs_kfd_invalid) return FileReader(new KFileReaderInterface(handle)); - return openFromBaseResource(name); + auto lump = fileSystem.FindFile(name); + if (lump < 0) return FileReader(); + else return fileSystem.OpenFileReader(lump); } // This is only here to mark a file as not being part of the game assets (e.g. savegames) // These should be handled differently (e.g read from a userdata directory or similar things.) inline FileReader fopenFileReader(const char* name, int where) { - return kopenFileReader(name, 0); + FileReader fr; + fr.OpenFile(name); + return fr; } inline bool testkopen(const char* name, int where) { - int handle = where == 0 ? kopen4loadfrommod(name, 0) : kopen4load(name, where); - if (handle != buildvfs_kfd_invalid) kclose(handle); - return handle != buildvfs_kfd_invalid; + // todo: if backed by a single file, we must actually open it to make sure. + return fileSystem.FindFile(name) >= 0; } inline TArray kloadfile(const char* name, int where) { - auto fr = kopenFileReader(name, where); - return fr.isOpen() ? fr.Read() : TArray (); + auto lump = fileSystem.FindFile(name); + if (lump < 0) return TArray(); + return fileSystem.GetFileData(lump); } inline int32_t kfilesize(const char* name, int where) { - int handle = where == 0 ? kopen4loadfrommod(name, 0) : kopen4load(name, where); - if (handle != buildvfs_kfd_invalid) - { - auto fs = kfilelength(handle); - kclose(handle); - return fs; - } - return -1; + auto lump = fileSystem.FindFile(name); + if (lump < 0) return -1; + return fileSystem.FileLength(lump); } -inline char const* kfileparent(FileReader &fr) +// checks from path and in ZIPs, returns 1 if NOT found +inline int32_t check_file_exist(const char* fn) { - // This is by no means a good implementation. Its only advantage is that it can be done without hacking in something more invasive. - return fr.Gets(nullptr, 0); + return fileSystem.FindFile(fn) >= 0; } #endif // cache1d_h_ diff --git a/source/build/include/common.h b/source/build/include/common.h index 5e98894fc..b3700cfef 100644 --- a/source/build/include/common.h +++ b/source/build/include/common.h @@ -77,8 +77,6 @@ int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens); int32_t G_CheckCmdSwitch(int32_t argc, char const * const * argv, const char *str); -int32_t check_file_exist(const char *fn); // findfrompath with pathsearchmode=1 / search in zips - void fnlist_clearnames(fnlist_t *fnl); int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern, int32_t dirflags, int32_t fileflags); diff --git a/source/build/src/cache1d.cpp b/source/build/src/cache1d.cpp index 18ebb951d..488f32dcd 100644 --- a/source/build/src/cache1d.cpp +++ b/source/build/src/cache1d.cpp @@ -40,37 +40,7 @@ static intptr_t kzipopen(const char *filnam) #endif char *kpzbuf = NULL; -int32_t kpzbufsiz; -int32_t kpzbufloadfil(buildvfs_kfd const handle) -{ - int32_t const leng = kfilelength(handle); - if (leng > kpzbufsiz) - { - kpzbuf = (char *) Xrealloc(kpzbuf, leng+1); - kpzbufsiz = leng; - if (!kpzbuf) - return 0; - } - - kpzbuf[leng] = 0; // FIXME: buf[leng] read in kpegrend(), see BUF_LENG_READ - kread(handle, kpzbuf, leng); - - return leng; -} - -int32_t kpzbufload(char const * const filnam) -{ - buildvfs_kfd const handle = kopen4load(filnam, 0); - if (handle == buildvfs_kfd_invalid) - return 0; - - int32_t const leng = kpzbufloadfil(handle); - - kclose(handle); - - return leng; -} // This module keeps track of a standard linear cacheing system. // To use this module, here's all you need to do: @@ -151,942 +121,10 @@ static searchpath_t *searchpathhead = NULL; static size_t maxsearchpathlen = 0; int32_t pathsearchmode = 0; -#ifndef USE_PHYSFS - -char *listsearchpath(int32_t initp) -{ - static searchpath_t *sp; - - if (initp) - sp = searchpathhead; - else if (sp != NULL) - sp = sp->next; - - return sp ? sp->path : NULL; -} - -int32_t addsearchpath_user(const char *p, int32_t user) -{ - struct Bstat st; - char *s; - searchpath_t *srch; - char *path = Xstrdup(p); - - if (path[Bstrlen(path)-1] == '\\') - path[Bstrlen(path)-1] = 0; // hack for stat() returning ENOENT on paths ending in a backslash - - if (Bstat(path, &st) < 0) - { - Xfree(path); - if (errno == ENOENT) return -2; - return -1; - } - if (!(st.st_mode & BS_IFDIR)) - { - Xfree(path); - return -1; - } - - srch = (searchpath_t *)Xmalloc(sizeof(searchpath_t)); - - srch->next = searchpathhead; - srch->pathlen = Bstrlen(path)+1; - srch->path = (char *)Xmalloc(srch->pathlen + 1); - - Bstrcpy(srch->path, path); - for (s=srch->path; *s; s++) { } - s--; - - if (spath || toupperlookup[*s] != '/') - Bstrcat(srch->path, "/"); - - searchpathhead = srch; - if (srch->pathlen > maxsearchpathlen) - maxsearchpathlen = srch->pathlen; - - Bcorrectfilename(srch->path,0); - - srch->user = user; - - initprintf("Using %s for game data\n", srch->path); - - Xfree(path); - return 0; -} - -int32_t removesearchpath(const char *p) -{ - searchpath_t *srch; - char *s; - char *path = (char *)Xmalloc(Bstrlen(p) + 2); - - Bstrcpy(path, p); - - if (path[Bstrlen(path)-1] == '\\') - path[Bstrlen(path)-1] = 0; - - for (s=path; *s; s++) { } - s--; - - if (snext) - { - if (!Bstrncmp(path, srch->path, srch->pathlen)) - { -// initprintf("Removing %s from path stack\n", path); - - if (srch == searchpathhead) - searchpathhead = srch->next; - else - { - searchpath_t *sp; - - for (sp = searchpathhead; sp; sp = sp->next) - { - if (sp->next == srch) - { -// initprintf("matched %s\n", srch->path); - sp->next = srch->next; - break; - } - } - } - - Xfree(srch->path); - Xfree(srch); - break; - } - } - - Xfree(path); - return 0; -} - -void removesearchpaths_withuser(int32_t usermask) -{ - searchpath_t *next; - - for (searchpath_t *srch = searchpathhead; srch; srch = next) - { - next = srch->next; - - if (srch->user & usermask) - { - - if (srch == searchpathhead) - searchpathhead = srch->next; - else - { - searchpath_t *sp; - - for (sp = searchpathhead; sp; sp = sp->next) - { - if (sp->next == srch) - { - sp->next = srch->next; - break; - } - } - } - - Xfree(srch->path); - Xfree(srch); - } - } -} - -int32_t findfrompath(const char *fn, char **where) -{ - // pathsearchmode == 0: tests current dir and then the dirs of the path stack - // pathsearchmode == 1: tests fn without modification, then like for pathsearchmode == 0 - - if (pathsearchmode) - { - // test unmolested filename first - if (buildvfs_exists(fn)) - { - *where = Xstrdup(fn); - return 0; - } -#ifndef _WIN32 - else - { - char *tfn = Bstrtolower(Xstrdup(fn)); - - if (buildvfs_exists(tfn)) - { - *where = tfn; - return 0; - } - - Bstrupr(tfn); - - if (buildvfs_exists(tfn)) - { - *where = tfn; - return 0; - } - - Xfree(tfn); - } -#endif - } - - char const *cpfn; - - for (cpfn = fn; toupperlookup[*cpfn] == '/'; cpfn++) { } - char *ffn = Xstrdup(cpfn); - - Bcorrectfilename(ffn,0); // compress relative paths - - int32_t allocsiz = max(maxsearchpathlen, 2); // "./" (aka. curdir) - allocsiz += strlen(ffn); - allocsiz += 1; // a nul - - char *pfn = (char *)Xmalloc(allocsiz); - - strcpy(pfn, "./"); - strcat(pfn, ffn); - if (buildvfs_exists(pfn)) - { - *where = pfn; - Xfree(ffn); - return 0; - } - - for (searchpath_t *sp = searchpathhead; sp; sp = sp->next) - { - char *tfn = Xstrdup(ffn); - - strcpy(pfn, sp->path); - strcat(pfn, ffn); - //initprintf("Trying %s\n", pfn); - if (buildvfs_exists(pfn)) - { - *where = pfn; - Xfree(ffn); - Xfree(tfn); - return 0; - } - -#ifndef _WIN32 - //Check with all lowercase - strcpy(pfn, sp->path); - Bstrtolower(tfn); - strcat(pfn, tfn); - if (buildvfs_exists(pfn)) - { - *where = pfn; - Xfree(ffn); - Xfree(tfn); - return 0; - } - - //Check again with uppercase - strcpy(pfn, sp->path); - Bstrupr(tfn); - strcat(pfn, tfn); - if (buildvfs_exists(pfn)) - { - *where = pfn; - Xfree(ffn); - Xfree(tfn); - return 0; - } -#endif - Xfree(tfn); - } - - Xfree(pfn); Xfree(ffn); - return -1; -} - -#if defined(_WIN32) && defined(DEBUGGINGAIDS) -# define FILENAME_CASE_CHECK -#endif - -static buildvfs_kfd openfrompath_internal(const char *fn, char **where, int32_t flags, int32_t mode) -{ - if (findfrompath(fn, where) < 0) - return -1; - - return Bopen(*where, flags, mode); -} - -buildvfs_kfd openfrompath(const char *fn, int32_t flags, int32_t mode) -{ - char *pfn = NULL; - - buildvfs_kfd h = openfrompath_internal(fn, &pfn, flags, mode); - - Xfree(pfn); - - return h; -} - -buildvfs_FILE fopenfrompath(const char *fn, const char *mode) -{ - int32_t fh; - buildvfs_FILE h; - int32_t bmode = 0, smode = 0; - const char *c; - - for (c=mode; c[0];) - { - if (c[0] == 'r' && c[1] == '+') { bmode = BO_RDWR; smode = BS_IREAD|BS_IWRITE; c+=2; } - else if (c[0] == 'r') { bmode = BO_RDONLY; smode = BS_IREAD; c+=1; } - else if (c[0] == 'w' && c[1] == '+') { bmode = BO_RDWR|BO_CREAT|BO_TRUNC; smode = BS_IREAD|BS_IWRITE; c+=2; } - else if (c[0] == 'w') { bmode = BO_WRONLY|BO_CREAT|BO_TRUNC; smode = BS_IREAD|BS_IWRITE; c+=2; } - else if (c[0] == 'a' && c[1] == '+') { bmode = BO_RDWR|BO_CREAT; smode=BS_IREAD|BS_IWRITE; c+=2; } - else if (c[0] == 'a') { bmode = BO_WRONLY|BO_CREAT; smode=BS_IREAD|BS_IWRITE; c+=1; } - else if (c[0] == 'b') { bmode |= BO_BINARY; c+=1; } - else if (c[1] == 't') { bmode |= BO_TEXT; c+=1; } - else c++; - } - fh = openfrompath(fn,bmode,smode); - if (fh < 0) return NULL; - - h = fdopen(fh,mode); - if (!h) close(fh); - - return h; -} - -#define MAXGROUPFILES 8 // Warning: Fix groupfil if this is changed -#define MAXOPENFILES 64 // Warning: Fix filehan if this is changed - -enum { - GRP_RESERVED_ID_START = 254, - - GRP_ZIP = GRP_RESERVED_ID_START, - GRP_FILESYSTEM = GRP_RESERVED_ID_START + 1, -}; - -EDUKE32_STATIC_ASSERT(MAXGROUPFILES <= GRP_RESERVED_ID_START); - -int32_t numgroupfiles = 0; -static int32_t gnumfiles[MAXGROUPFILES]; -static intptr_t groupfil[MAXGROUPFILES] = {-1,-1,-1,-1,-1,-1,-1,-1}; -static int32_t groupfilpos[MAXGROUPFILES]; -static uint8_t groupfilgrp[MAXGROUPFILES]; -static char *gfilelist[MAXGROUPFILES]; -static char *groupname[MAXGROUPFILES]; -static int32_t *gfileoffs[MAXGROUPFILES]; - -static uint8_t filegrp[MAXOPENFILES]; -static int32_t filepos[MAXOPENFILES]; -static intptr_t filehan[MAXOPENFILES] = -{ - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -}; - -#ifdef WITHKPLIB -static char filenamsav[MAXOPENFILES][260]; -static int32_t kzcurhand = -1; - -int32_t cache1d_file_fromzip(buildvfs_kfd fil) -{ - return (filegrp[fil] == GRP_ZIP); -} -#endif - -static int32_t kopen_internal(const char *filename, char **lastpfn, char searchfirst, char checkcase, char tryzip, int32_t newhandle, uint8_t *arraygrp, intptr_t *arrayhan, int32_t *arraypos); -static int32_t kread_grp(int32_t handle, void *buffer, int32_t leng); -static int32_t klseek_grp(int32_t handle, int32_t offset, int32_t whence); -static void kclose_grp(int32_t handle); - -static bool alreadycalled; -extern FString progdir; -int initgroupfile(const char *filename) -{ - char buf[70]; - - // translate all backslashes (0x5c) to forward slashes (0x2f) - toupperlookup[0x5c] = 0x2f; - - if (filename == NULL) - return -1; - - // Technically you should be able to load more zips even if your GRPs are maxed out, - // but this system is already enough of a disaster. - if (numgroupfiles >= MAXGROUPFILES) - return -1; - - char *zfn = NULL; - - if (kopen_internal(filename, &zfn, 0, 0, 0, numgroupfiles, groupfilgrp, groupfil, groupfilpos) < 0) - return -1; - -#ifdef WITHKPLIB - // check if ZIP - if (zfn) - { - kread_grp(numgroupfiles, buf, 4); - if (buf[0] == 0x50 && buf[1] == 0x4B && buf[2] == 0x03 && buf[3] == 0x04) - { - kclose_grp(numgroupfiles); - - kzaddstack(zfn); - Xfree(zfn); - return MAXGROUPFILES; - } - klseek_grp(numgroupfiles,0,BSEEK_SET); - - Xfree(zfn); - } -#else - Xfree(zfn); -#endif - - // check if GRP - kread_grp(numgroupfiles,buf,16); - if (!Bmemcmp(buf, "KenSilverman", 12)) - { - gnumfiles[numgroupfiles] = B_LITTLE32(*((int32_t *)&buf[12])); - - gfilelist[numgroupfiles] = (char *)Xmalloc(gnumfiles[numgroupfiles]<<4); - gfileoffs[numgroupfiles] = (int32_t *)Xmalloc((gnumfiles[numgroupfiles]+1)<<2); - - kread_grp(numgroupfiles,gfilelist[numgroupfiles],gnumfiles[numgroupfiles]<<4); - - int32_t j = (gnumfiles[numgroupfiles]+1)<<4; - for (bssize_t i=0; i 31) // 32 bytes allocated for the string - break; - // seek to the end of the string - klseek_grp(numgroupfiles, temp, BSEEK_CUR); - // verify everything remaining is a null terminator - temp = 32 - temp; - kread_grp(numgroupfiles, buf, temp); - if (Bmemcmp(buf, zerobuf, temp)) - break; - - if (version == 2) - { - // get the string length - kread_grp(numgroupfiles, &temp, 1); - if (temp > 11) // 12 bytes allocated for the string - break; - // seek to the end of the string - klseek_grp(numgroupfiles, temp, BSEEK_CUR); - // verify everything remaining is a null terminator - temp = 12 - temp; - kread_grp(numgroupfiles, buf, temp); - if (Bmemcmp(buf, zerobuf, temp)) - break; - } - - temp2 = 0; - for (int i=0;i<3;i++) - { - // get the string length - kread_grp(numgroupfiles, &temp, 1); - if (temp > 70) // 70 bytes allocated for the string - { - temp2 = 1; - break; - } - // seek to the end of the string - klseek_grp(numgroupfiles, temp, BSEEK_CUR); - // verify everything remaining is a null terminator - temp = 70 - temp; - if (temp == 0) - continue; - kread_grp(numgroupfiles, buf, temp); - temp2 |= !!Bmemcmp(buf, zerobuf, temp); - } - if (temp2) - break; - - // Passed all the tests: read data. - - gnumfiles[numgroupfiles] = numfiles; - - gfilelist[numgroupfiles] = (char *)Xmalloc(gnumfiles[numgroupfiles]<<4); - gfileoffs[numgroupfiles] = (int32_t *)Xmalloc((gnumfiles[numgroupfiles]+1)<<2); - - int32_t j = (version == 2 ? 267 : 254) + (numfiles * 121), k; - for (bssize_t i = 0; i < numfiles; i++) - { - // get the string length - kread_grp(numgroupfiles, &temp, 1); - if (temp > 12) - temp = 12; - // read the file name - kread_grp(numgroupfiles, &gfilelist[numgroupfiles][i<<4], temp); - gfilelist[numgroupfiles][(i<<4)+temp] = 0; - - // skip to the end of the 12 bytes - klseek_grp(numgroupfiles, 12-temp, BSEEK_CUR); - - // get the file size - kread_grp(numgroupfiles, &k, 4); - k = B_LITTLE32(k); - - // record the offset of the file in the SSI - gfileoffs[numgroupfiles][i] = j; - j += k; - - // skip unknown data - klseek_grp(numgroupfiles, 104, BSEEK_CUR); - } - gfileoffs[numgroupfiles][gnumfiles[numgroupfiles]] = j; - groupname[numgroupfiles] = Xstrdup(filename); - return numgroupfiles++; - } - - kclose_grp(numgroupfiles); - return -1; -} - -void uninitgroupfile(void) -{ - int32_t i; - - for (i=numgroupfiles-1; i>=0; i--) - if (groupfil[i] != -1) - { - DO_FREE_AND_NULL(gfilelist[i]); - DO_FREE_AND_NULL(gfileoffs[i]); - DO_FREE_AND_NULL(groupname[i]); - - Bclose(groupfil[i]); - groupfil[i] = -1; - } - numgroupfiles = 0; - - // JBF 20040111: "close" any files open in groups - for (i=0; i= 0) - { -#ifdef FILENAME_CASE_CHECK - if (checkcase && check_filename_casing_fn && check_filename_casing_fn()) - { - int32_t status; - char *cp, *lastslash; - - // convert all slashes to backslashes because SHGetFileInfo() - // complains else! - lastslash = *lastpfn; - for (cp=*lastpfn; *cp; cp++) - if (*cp=='/') - { - *cp = '\\'; - lastslash = cp; - } - if (lastslash != *lastpfn) - lastslash++; - - status = check_filename_mismatch(*lastpfn, lastslash-*lastpfn); - - if (status == -1) - { -// initprintf("SHGetFileInfo failed with error code %lu\n", GetLastError()); - } - else if (status == 1) - { - initprintf("warning: case mismatch: passed \"%s\", real \"%s\"\n", - lastslash, fnbuf+fnofs); - } - } -#else - UNREFERENCED_PARAMETER(checkcase); -#endif - arraygrp[newhandle] = GRP_FILESYSTEM; - arrayhan[newhandle] = fil; - arraypos[newhandle] = 0; - return newhandle; - } - - for (; toupperlookup[*filename] == '/'; filename++) { } - -#ifdef WITHKPLIB - if (tryzip) - { - intptr_t i; - if ((kzcurhand != newhandle) && (kztell() >= 0)) - { - if (kzcurhand >= 0) arraypos[kzcurhand] = kztell(); - kzclose(); - kzcurhand = -1; - } - if (searchfirst != 1 && (i = kzipopen(filename)) != 0) - { - kzcurhand = newhandle; - arraygrp[newhandle] = GRP_ZIP; - arrayhan[newhandle] = i; - arraypos[newhandle] = 0; - strcpy(filenamsav[newhandle],filename); - return newhandle; - } - } -#else - UNREFERENCED_PARAMETER(tryzip); -#endif - - for (bssize_t k = searchfirst != 1 ? numgroupfiles-1 : 0; k >= 0; --k) - { - if (groupfil[k] < 0) - continue; - - for (bssize_t i = gnumfiles[k]-1; i >= 0; --i) - { - char const * const gfileptr = (char *)&gfilelist[k][i<<4]; - - unsigned int j; - for (j = 0; j < 13; ++j) - { - if (!filename[j]) break; - if (toupperlookup[filename[j]] != toupperlookup[gfileptr[j]]) - goto gnumfiles_continue; - } - if (j<13 && gfileptr[j]) continue; // JBF: because e1l1.map might exist before e1l1 - if (j==13 && filename[j]) continue; // JBF: long file name - - arraygrp[newhandle] = k; - arrayhan[newhandle] = i; - arraypos[newhandle] = 0; - return newhandle; - -gnumfiles_continue: ; - } - } - - return -1; -} - -void krename(int32_t crcval, int32_t filenum, const char *newname) -{ - Bstrncpy((char *)&gfilelist[crcval][filenum<<4], newname, 12); -} - -char const * kfileparent(int32_t const handle) -{ - int32_t const groupnum = filegrp[handle]; - - if ((unsigned)groupnum >= MAXGROUPFILES || groupfil[groupnum] == -1) - return NULL; - - return groupname[groupnum]; -} - -int32_t kopen4load(const char *filename, char searchfirst) -{ - int32_t newhandle = MAXOPENFILES-1; - - if (filename==NULL) - return -1; - - while (filehan[newhandle] != -1) - { - newhandle--; - if (newhandle < 0) - { - initprintf("TOO MANY FILES OPEN IN FILE GROUPING SYSTEM!"); - Bexit(EXIT_SUCCESS); - } - } - - char *lastpfn = NULL; - - int32_t h = kopen_internal(filename, &lastpfn, searchfirst, 1, 1, newhandle, filegrp, filehan, filepos); - - Xfree(lastpfn); - - return h; -} char g_modDir[BMAX_PATH] = "/"; -buildvfs_kfd kopen4loadfrommod(const char *fileName, char searchfirst) -{ - buildvfs_kfd kFile = buildvfs_kfd_invalid; - if (g_modDir[0] != '/' || g_modDir[1] != 0) - { - static char staticFileName[BMAX_PATH]; - Bsnprintf(staticFileName, sizeof(staticFileName), "%s/%s", g_modDir, fileName); - kFile = kopen4load(staticFileName, searchfirst); - } - - return (kFile == buildvfs_kfd_invalid) ? kopen4load(fileName, searchfirst) : kFile; -} - -int32_t kread_internal(int32_t handle, void *buffer, int32_t leng, const uint8_t *arraygrp, const intptr_t *arrayhan, int32_t *arraypos) -{ - int32_t filenum = arrayhan[handle]; - int32_t groupnum = arraygrp[handle]; - - if (groupnum == GRP_FILESYSTEM) return Bread(filenum,buffer,leng); -#ifdef WITHKPLIB - else if (groupnum == GRP_ZIP) - { - if (kzcurhand != handle) - { - if (kztell() >= 0) { arraypos[kzcurhand] = kztell(); kzclose(); } - kzcurhand = handle; - kzipopen(filenamsav[handle]); - kzseek(arraypos[handle],SEEK_SET); - } - return kzread(buffer,leng); - } -#endif - - if (EDUKE32_PREDICT_FALSE(groupfil[groupnum] == -1)) - return 0; - - int32_t rootgroupnum = groupnum; - int32_t i = 0; - while (groupfilgrp[rootgroupnum] != GRP_FILESYSTEM) - { - i += gfileoffs[groupfilgrp[rootgroupnum]][groupfil[rootgroupnum]]; - rootgroupnum = groupfilgrp[rootgroupnum]; - } - if (EDUKE32_PREDICT_TRUE(groupfil[rootgroupnum] != -1)) - { - i += gfileoffs[groupnum][filenum]+arraypos[handle]; - if (i != groupfilpos[rootgroupnum]) - { - Blseek(groupfil[rootgroupnum],i,BSEEK_SET); - groupfilpos[rootgroupnum] = i; - } - leng = min(leng,(gfileoffs[groupnum][filenum+1]-gfileoffs[groupnum][filenum])-arraypos[handle]); - leng = Bread(groupfil[rootgroupnum],buffer,leng); - arraypos[handle] += leng; - groupfilpos[rootgroupnum] += leng; - return leng; - } - - return 0; -} - -int32_t klseek_internal(int32_t handle, int32_t offset, int32_t whence, const uint8_t *arraygrp, intptr_t *arrayhan, int32_t *arraypos) -{ - int32_t const groupnum = arraygrp[handle]; - - if (groupnum == GRP_FILESYSTEM) return Blseek(arrayhan[handle],offset,whence); -#ifdef WITHKPLIB - else if (groupnum == GRP_ZIP) - { - if (kzcurhand != handle) - { - if (kztell() >= 0) { arraypos[kzcurhand] = kztell(); kzclose(); } - kzcurhand = handle; - kzipopen(filenamsav[handle]); - kzseek(arraypos[handle],SEEK_SET); - } - return kzseek(offset,whence); - } -#endif - - if (groupfil[groupnum] != -1) - { - switch (whence) - { - case BSEEK_SET: - arraypos[handle] = offset; break; - case BSEEK_END: - { - int32_t const i = arrayhan[handle]; - arraypos[handle] = (gfileoffs[groupnum][i+1]-gfileoffs[groupnum][i])+offset; - break; - } - case BSEEK_CUR: - arraypos[handle] += offset; break; - } - return arraypos[handle]; - } - return -1; -} - -int32_t kfilelength_internal(int32_t handle, const uint8_t *arraygrp, intptr_t *arrayhan, int32_t *arraypos) -{ - int32_t const groupnum = arraygrp[handle]; - if (groupnum == GRP_FILESYSTEM) - { - return buildvfs_length(arrayhan[handle]); - } -#ifdef WITHKPLIB - else if (groupnum == GRP_ZIP) - { - if (kzcurhand != handle) - { - if (kztell() >= 0) { arraypos[kzcurhand] = kztell(); kzclose(); } - kzcurhand = handle; - kzipopen(filenamsav[handle]); - kzseek(arraypos[handle],SEEK_SET); - } - return kzfilelength(); - } -#endif - int32_t const i = arrayhan[handle]; - return gfileoffs[groupnum][i+1]-gfileoffs[groupnum][i]; -} - -int32_t ktell_internal(int32_t handle, const uint8_t *arraygrp, intptr_t *arrayhan, int32_t *arraypos) -{ - int32_t groupnum = arraygrp[handle]; - - if (groupnum == GRP_FILESYSTEM) return Blseek(arrayhan[handle],0,BSEEK_CUR); -#ifdef WITHKPLIB - else if (groupnum == GRP_ZIP) - { - if (kzcurhand != handle) - { - if (kztell() >= 0) { arraypos[kzcurhand] = kztell(); kzclose(); } - kzcurhand = handle; - kzipopen(filenamsav[handle]); - kzseek(arraypos[handle],SEEK_SET); - } - return kztell(); - } -#endif - if (groupfil[groupnum] != -1) - return arraypos[handle]; - return -1; -} - -void kclose_internal(int32_t handle, const uint8_t *arraygrp, intptr_t *arrayhan) -{ - if (handle < 0) return; - if (arraygrp[handle] == GRP_FILESYSTEM) Bclose(arrayhan[handle]); -#ifdef WITHKPLIB - else if (arraygrp[handle] == GRP_ZIP) - { - kzclose(); - kzcurhand = -1; - } -#endif - arrayhan[handle] = -1; -} - -int32_t kread(int32_t handle, void *buffer, int32_t leng) -{ - return kread_internal(handle, buffer, leng, filegrp, filehan, filepos); -} -int32_t klseek(int32_t handle, int32_t offset, int32_t whence) -{ - return klseek_internal(handle, offset, whence, filegrp, filehan, filepos); -} -int32_t kfilelength(int32_t handle) -{ - return kfilelength_internal(handle, filegrp, filehan, filepos); -} -int32_t ktell(int32_t handle) -{ - return ktell_internal(handle, filegrp, filehan, filepos); -} -void kclose(int32_t handle) -{ - return kclose_internal(handle, filegrp, filehan); -} - -static int32_t kread_grp(int32_t handle, void *buffer, int32_t leng) -{ - return kread_internal(handle, buffer, leng, groupfilgrp, groupfil, groupfilpos); -} -static int32_t klseek_grp(int32_t handle, int32_t offset, int32_t whence) -{ - return klseek_internal(handle, offset, whence, groupfilgrp, groupfil, groupfilpos); -} -static void kclose_grp(int32_t handle) -{ - return kclose_internal(handle, groupfilgrp, groupfil); -} -#endif int32_t klistaddentry(CACHE1D_FIND_REC **rec, const char *name, int32_t type, int32_t source) { @@ -1215,36 +253,6 @@ CACHE1D_FIND_REC *klistpath(const char *_path, const char *mask, int32_t type) int32_t stackdepth = CACHE1D_SOURCE_CURDIR; -#ifdef USE_PHYSFS - char **rc = PHYSFS_enumerateFiles(""); - char **i; - - for (i = rc; *i != NULL; i++) - { - char * name = *i; - - if ((name[0] == '.' && name[1] == 0) || - (name[0] == '.' && name[1] == '.' && name[2] == 0)) - continue; - - bool const isdir = buildvfs_isdir(name); - if ((type & CACHE1D_FIND_DIR) && !isdir) continue; - if ((type & CACHE1D_FIND_FILE) && isdir) continue; - if (!Bwildmatch(name, mask)) continue; - switch (klistaddentry(&rec, name, - isdir ? CACHE1D_FIND_DIR : CACHE1D_FIND_FILE, - stackdepth)) - { - case -1: goto failure; - //case 1: initprintf("%s:%s dropped for lower priority\n", d,dirent->name); break; - //case 0: initprintf("%s:%s accepted\n", d,dirent->name); break; - default: - break; - } - } - - PHYSFS_freeList(rc); -#else static const char *const CUR_DIR = "./"; // Adjusted for the following "autoload" dir fix - NY00123 searchpath_t *search = NULL; @@ -1307,112 +315,8 @@ next: d = search->path; } while (search); -#endif } -#ifndef USE_PHYSFS -#ifdef WITHKPLIB - if (!(type & CACHE1D_FIND_NOCURDIR)) // TEMP, until we have sorted out fs.listpath() API - if (!pathsearchmode) // next, zip files - { - char buf[BMAX_PATH+4]; - int32_t i, j, ftype; - strcpy(buf,path); - if (*path) strcat(buf,"/"); - strcat(buf,mask); - for (kzfindfilestart(buf); kzfindfile(buf);) - { - if (buf[0] != '|') continue; // local files we don't need - - // scan for the end of the string and shift - // everything left a char in the process - for (i=1; (buf[i-1]=buf[i]); i++) - { - /* do nothing */ - } - i-=2; - if (i < 0) - i = 0; - - // if there's a slash at the end, this is a directory entry - if (toupperlookup[buf[i]] == '/') { ftype = CACHE1D_FIND_DIR; buf[i] = 0; } - else ftype = CACHE1D_FIND_FILE; - - // skip over the common characters at the beginning of the base path and the zip entry - for (j=0; buf[j] && path[j]; j++) - { - if (toupperlookup[ path[j] ] == toupperlookup[ buf[j] ]) continue; - break; - } - // we've now hopefully skipped the common path component at the beginning. - // if that's true, we should be staring at a null byte in path and either any character in buf - // if j==0, or a slash if j>0 - if ((!path[0] && buf[j]) || (!path[j] && toupperlookup[ buf[j] ] == '/')) - { - if (j>0) j++; - - // yep, so now we shift what follows back to the start of buf and while we do that, - // keep an eye out for any more slashes which would mean this entry has sub-entities - // and is useless to us. - for (i = 0; (buf[i] = buf[j]) && toupperlookup[buf[j]] != '/'; i++,j++) ; - if (toupperlookup[buf[j]] == '/') continue; // damn, try next entry - } - else - { - // if we're here it means we have a situation where: - // path = foo - // buf = foobar... - // or - // path = foobar - // buf = foo... - // which would mean the entry is higher up in the directory tree and is also useless - continue; - } - - if ((type & CACHE1D_FIND_DIR) && ftype != CACHE1D_FIND_DIR) continue; - if ((type & CACHE1D_FIND_FILE) && ftype != CACHE1D_FIND_FILE) continue; - - // the entry is in the clear - switch (klistaddentry(&rec, buf, ftype, CACHE1D_SOURCE_ZIP)) - { - case -1: - goto failure; - //case 1: initprintf(":%s dropped for lower priority\n", buf); break; - //case 0: initprintf(":%s accepted\n", buf); break; - default: - break; - } - } - } -#endif - // then, grp files - if (!(type & CACHE1D_FIND_NOCURDIR)) // TEMP, until we have sorted out fs.listpath() API - if (!pathsearchmode && !*path && (type & CACHE1D_FIND_FILE)) - { - char buf[13]; - int32_t i,j; - buf[12] = 0; - for (i=0; i=0; j--) - { - Bmemcpy(buf,&gfilelist[i][j<<4],12); - if (!Bwildmatch(buf,mask)) continue; - switch (klistaddentry(&rec, buf, CACHE1D_FIND_FILE, CACHE1D_SOURCE_GRP)) - { - case -1: - goto failure; - //case 1: initprintf(":%s dropped for lower priority\n", workspace); break; - //case 0: initprintf(":%s accepted\n", workspace); break; - default: - break; - } - } - } - } -#endif - Xfree(path); // XXX: may be NULL if no file was listed, and thus indistinguishable from // an error condition. @@ -1423,92 +327,3 @@ failure: return NULL; } - -static int32_t kdfread_func(intptr_t fil, void *outbuf, int32_t length) -{ - return kread((buildvfs_kfd)fil, outbuf, length); -} - -static void dfwrite_func(intptr_t fp, const void *inbuf, int32_t length) -{ - buildvfs_fwrite(inbuf, length, 1, (buildvfs_FILE)fp); -} - - -// LZ4_COMPRESSION_ACCELERATION_VALUE can be tuned for performance/space trade-off -// (lower number = higher compression ratio, higher number = faster compression speed) -#define LZ4_COMPRESSION_ACCELERATION_VALUE 5 - -static char compressedDataStackBuf[131072]; -int32_t lz4CompressionLevel = LZ4_COMPRESSION_ACCELERATION_VALUE; - -int32_t kdfread_LZ4(void *buffer, int dasizeof, int count, buildvfs_kfd fil) -{ - int32_t leng; - - // read compressed data length - if (kread(fil, &leng, sizeof(leng)) != sizeof(leng)) - return -1; - - leng = B_LITTLE32(leng); - - char *pCompressedData = compressedDataStackBuf; - - if (leng > ARRAY_SSIZE(compressedDataStackBuf)) - pCompressedData = (char *)Xaligned_alloc(16, leng); - - if (kread(fil, pCompressedData, leng) != leng) - return -1; - - int32_t decompressedLength = LZ4_decompress_safe(pCompressedData, (char*) buffer, leng, dasizeof*count); - - if (pCompressedData != compressedDataStackBuf) - Xaligned_free(pCompressedData); - - return decompressedLength/dasizeof; -} - -int32_t kdfread_LZ4(void* buffer, int dasizeof, int count, FileReader &fil) -{ - int32_t leng; - - // read compressed data length - if (fil.Read(&leng, sizeof(leng)) != sizeof(leng)) - return -1; - - leng = B_LITTLE32(leng); - - char* pCompressedData = compressedDataStackBuf; - - if (leng > ARRAY_SSIZE(compressedDataStackBuf)) - pCompressedData = (char*)Xaligned_alloc(16, leng); - - if (fil.Read(pCompressedData, leng) != leng) - return -1; - - int32_t decompressedLength = LZ4_decompress_safe(pCompressedData, (char*)buffer, leng, dasizeof * count); - - if (pCompressedData != compressedDataStackBuf) - Xaligned_free(pCompressedData); - - return decompressedLength / dasizeof; -} - - -void dfwrite_LZ4(const void *buffer, int dasizeof, int count, buildvfs_FILE fil) -{ - char * pCompressedData = compressedDataStackBuf; - int const maxCompressedSize = LZ4_compressBound(dasizeof * count); - - if (maxCompressedSize > ARRAY_SSIZE(compressedDataStackBuf)) - pCompressedData = (char *)Xaligned_alloc(16, maxCompressedSize); - - int const leng = LZ4_compress_fast((const char*) buffer, pCompressedData, dasizeof*count, maxCompressedSize, lz4CompressionLevel); - int const swleng = B_LITTLE32(leng); - - buildvfs_fwrite(&swleng, sizeof(swleng), 1, fil); - buildvfs_fwrite(pCompressedData, leng, 1, fil); - - if (pCompressedData != compressedDataStackBuf) - Xaligned_free(pCompressedData); -} diff --git a/source/build/src/common.cpp b/source/build/src/common.cpp index 8a37cb792..126768bcd 100644 --- a/source/build/src/common.cpp +++ b/source/build/src/common.cpp @@ -71,36 +71,6 @@ int32_t G_CheckCmdSwitch(int32_t argc, char const * const * argv, const char *st return 0; } -// checks from path and in ZIPs, returns 1 if NOT found -int32_t check_file_exist(const char *fn) -{ -#ifdef USE_PHYSFS - return !PHYSFS_exists(fn); -#else - int32_t opsm = pathsearchmode; - char *tfn; - - pathsearchmode = 1; - if (findfrompath(fn,&tfn) < 0) - { - char buf[BMAX_PATH]; - - Bstrcpy(buf,fn); - kzfindfilestart(buf); - if (!kzfindfile(buf)) - { - initprintf("Error: file \"%s\" does not exist\n",fn); - pathsearchmode = opsm; - return 1; - } - } - else Xfree(tfn); - pathsearchmode = opsm; - - return 0; -#endif -} - //// FILE NAME / DIRECTORY LISTS //// void fnlist_clearnames(fnlist_t *fnl) diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index abe59c9ed..a58e9e967 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -1808,10 +1808,6 @@ static int32_t defsparser(scriptfile *script) int32_t basepal=-1, pal=-1; char *fn = NULL; char *highpalend; -#ifdef POLYMER - buildvfs_kfd fd; - char *highpaldata; -#endif static const tokenlist highpaltokens[] = { { "basepal", T_BASEPAL }, diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 7833f0c02..96a19f074 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -7619,11 +7619,11 @@ static int32_t engineLoadTables(void) } #endif // TABLES.DAT format: - //kread(fil,sintable,2048*2); - //kread(fil,radarang,640*2); - //kread(fil,textfont,1024); - //kread(fil,smalltextfont,1024); - //kread(fil,britable,1024); + //fr.Read(sintable,2048*2); + //fr.Read(radarang,640*2); + //fr.Read(textfont,1024); + //fr.Read(smalltextfont,1024); + //fr.Read(britable,1024); calcbritable(); @@ -8262,7 +8262,6 @@ void engineUnInit(void) basepaltable[0] = palette; DO_FREE_AND_NULL(kpzbuf); - kpzbufsiz = 0; uninitsystem(); @@ -9476,7 +9475,7 @@ static FORCE_INLINE int32_t have_maptext(void) return (mapversion >= 10); } -static void enginePrepareLoadBoard(buildvfs_kfd fil, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum) +static void enginePrepareLoadBoard(FileReader & fr, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum) { initspritelists(); @@ -9496,11 +9495,11 @@ static void enginePrepareLoadBoard(buildvfs_kfd fil, vec3_t *dapos, int16_t *daa if (!have_maptext()) { - kread(fil,&dapos->x,4); dapos->x = B_LITTLE32(dapos->x); - kread(fil,&dapos->y,4); dapos->y = B_LITTLE32(dapos->y); - kread(fil,&dapos->z,4); dapos->z = B_LITTLE32(dapos->z); - kread(fil,daang,2); *daang = B_LITTLE16(*daang) & 2047; - kread(fil,dacursectnum,2); *dacursectnum = B_LITTLE16(*dacursectnum); + fr.Read(&dapos->x,4); dapos->x = B_LITTLE32(dapos->x); + fr.Read(&dapos->y,4); dapos->y = B_LITTLE32(dapos->y); + fr.Read(&dapos->z,4); dapos->z = B_LITTLE32(dapos->z); + fr.Read(daang,2); *daang = B_LITTLE16(*daang) & 2047; + fr.Read(dacursectnum,2); *dacursectnum = B_LITTLE16(*dacursectnum); } } @@ -9636,10 +9635,6 @@ static void check_sprite(int32_t i) } } -#ifdef NEW_MAP_FORMAT -// Returns the number of sprites, or <0 on error. -LUNATIC_CB int32_t (*loadboard_maptext)(buildvfs_kfd fil, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum); -#endif #include "md4.h" @@ -9663,13 +9658,12 @@ int32_t engineLoadBoard(const char *filename, char flags, vec3_t *dapos, int16_t flags &= 3; - buildvfs_kfd fil; - if ((fil = kopen4load(filename,flags)) == buildvfs_kfd_invalid) + FileReader fr = kopenFileReader(filename, 0); + if (!fr.isOpen()) { mapversion = 7; return -1; } - if (kread(fil, &mapversion, 4) != 4) + if (fr.Read(&mapversion, 4) != 4) { - kclose(fil); return -2; } @@ -9700,53 +9694,29 @@ int32_t engineLoadBoard(const char *filename, char flags, vec3_t *dapos, int16_t if (!ok) { - kclose(fil); return -2; } } - enginePrepareLoadBoard(fil, dapos, daang, dacursectnum); + enginePrepareLoadBoard(fr, dapos, daang, dacursectnum); -#ifdef NEW_MAP_FORMAT - if (have_maptext()) - { - int32_t ret = klseek(fil, 0, SEEK_SET); - - if (ret == 0) - ret = loadboard_maptext(fil, dapos, daang, dacursectnum); - - if (ret < 0) - { - kclose(fil); - return ret; - } - - numsprites = ret; - goto skip_reading_mapbin; - } -#endif ////////// Read sectors ////////// - kread(fil,&numsectors,2); numsectors = B_LITTLE16(numsectors); + fr.Read(&numsectors,2); numsectors = B_LITTLE16(numsectors); if ((unsigned)numsectors >= MYMAXSECTORS() + 1) { error: numsectors = 0; numwalls = 0; numsprites = 0; - kclose(fil); return -3; } - kread(fil, sector, sizeof(sectortypev7)*numsectors); + fr.Read(sector, sizeof(sectortypev7)*numsectors); for (i=numsectors-1; i>=0; i--) { -#ifdef NEW_MAP_FORMAT - Bmemmove(§or[i], &(((sectortypev7 *)sector)[i]), sizeof(sectortypevx)); - inplace_vx_from_v7_sector(§or[i]); -#endif sector[i].wallptr = B_LITTLE16(sector[i].wallptr); sector[i].wallnum = B_LITTLE16(sector[i].wallnum); sector[i].ceilingz = B_LITTLE32(sector[i].ceilingz); @@ -9760,25 +9730,18 @@ int32_t engineLoadBoard(const char *filename, char flags, vec3_t *dapos, int16_t sector[i].lotag = B_LITTLE16(sector[i].lotag); sector[i].hitag = B_LITTLE16(sector[i].hitag); sector[i].extra = B_LITTLE16(sector[i].extra); -#ifdef NEW_MAP_FORMAT - inplace_vx_tweak_sector(§or[i], mapversion==9); -#endif } ////////// Read walls ////////// - kread(fil,&numwalls,2); numwalls = B_LITTLE16(numwalls); + fr.Read(&numwalls,2); numwalls = B_LITTLE16(numwalls); if ((unsigned)numwalls >= MYMAXWALLS()+1) goto error; - kread(fil, wall, sizeof(walltypev7)*numwalls); + fr.Read( wall, sizeof(walltypev7)*numwalls); for (i=numwalls-1; i>=0; i--) { -#ifdef NEW_MAP_FORMAT - Bmemmove(&wall[i], &(((walltypev7 *)wall)[i]), sizeof(walltypevx)); - inplace_vx_from_v7_wall(&wall[i]); -#endif wall[i].x = B_LITTLE32(wall[i].x); wall[i].y = B_LITTLE32(wall[i].y); wall[i].point2 = B_LITTLE16(wall[i].point2); @@ -9790,31 +9753,23 @@ int32_t engineLoadBoard(const char *filename, char flags, vec3_t *dapos, int16_t wall[i].lotag = B_LITTLE16(wall[i].lotag); wall[i].hitag = B_LITTLE16(wall[i].hitag); wall[i].extra = B_LITTLE16(wall[i].extra); -#ifdef NEW_MAP_FORMAT - inplace_vx_tweak_wall(&wall[i], mapversion==9); -#endif } ////////// Read sprites ////////// - kread(fil,&numsprites,2); numsprites = B_LITTLE16(numsprites); + fr.Read(&numsprites,2); numsprites = B_LITTLE16(numsprites); if ((unsigned)numsprites >= MYMAXSPRITES()+1) goto error; - kread(fil, sprite, sizeof(spritetype)*numsprites); + fr.Read( sprite, sizeof(spritetype)*numsprites); -#ifdef NEW_MAP_FORMAT -skip_reading_mapbin: -#endif - - klseek(fil, 0, SEEK_SET); - int32_t boardsize = kfilelength(fil); + fr.Seek(0, FileReader::SeekSet); + int32_t boardsize = fr.GetLength(); uint8_t *fullboard = (uint8_t*)Xmalloc(boardsize); - kread(fil, fullboard, boardsize); + fr.Read( fullboard, boardsize); md4once(fullboard, boardsize, g_loadedMapHack.md4); Xfree(fullboard); - kclose(fil); // Done reading file. if (!have_maptext()) @@ -9856,13 +9811,14 @@ skip_reading_mapbin: if ((myflags&8)==0) { +#if 0 // No, no! This is absolutely unacceptable. I won't support mods that require this kind of access. char fn[BMAX_PATH]; Bstrcpy(fn, filename); append_ext_UNSAFE(fn, ".cfg"); OSD_Exec(fn); - +#endif system_getcvars(); // Per-map ART @@ -9894,23 +9850,23 @@ int32_t engineLoadBoardV5V6(const char *filename, char fromwhere, vec3_t *dapos, struct walltypev6 v6wall; struct spritetypev6 v6spr; - buildvfs_kfd fil; - if ((fil = kopen4load(filename,fromwhere)) == buildvfs_kfd_invalid) + FileReader fr = kopenFileReader(filename, fromwhere); + if (!fr.isOpen()) { mapversion = 5L; return -1; } - kread(fil,&mapversion,4); mapversion = B_LITTLE32(mapversion); - if (mapversion != 5L && mapversion != 6L) { kclose(fil); return -2; } + fr.Read(&mapversion,4); mapversion = B_LITTLE32(mapversion); + if (mapversion != 5L && mapversion != 6L) { return -2; } - enginePrepareLoadBoard(fil, dapos, daang, dacursectnum); + enginePrepareLoadBoard(fr, dapos, daang, dacursectnum); - kread(fil,&numsectors,2); numsectors = B_LITTLE16(numsectors); - if (numsectors > MAXSECTORS) { kclose(fil); return -1; } + fr.Read(&numsectors,2); numsectors = B_LITTLE16(numsectors); + if (numsectors > MAXSECTORS) { return -1; } for (i=0; i MAXWALLS) { kclose(fil); return -1; } + fr.Read(&numwalls,2); numwalls = B_LITTLE16(numwalls); + if (numwalls > MAXWALLS) { return -1; } for (i=0; i MAXSPRITES) { kclose(fil); return -1; } + fr.Read(&numsprites,2); numsprites = B_LITTLE16(numsprites); + if (numsprites > MAXSPRITES) { return -1; } for (i=0; i= 256) { - static char const * const seekfail = "Warning: klseek() failed in loadpalette()!\n"; + static char const * const seekfail = "Warning: seek failed in loadpalette()!\n"; uint16_t temp; if (read_and_test(fil, &temp, 2)) diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index ab5b33133..f805b498e 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -485,41 +485,8 @@ int main(int argc, char *argv[]) return r; } - -static std::unique_ptr demolition_pk3; - // The resourge manager in cache1d is far too broken to add some arbitrary file without some adjustment. // For now, keep this file here, until the resource management can be redone in a more workable fashion. -extern FString progdir; -extern FString LumpFilter; - -void InitBaseRes() -{ - if (!demolition_pk3) - { - // If we get here for the first time, load the engine-internal data. - FString baseres = progdir + "demolition.pk3"; - demolition_pk3.reset(FResourceFile::OpenResourceFile(baseres, true, true)); - if (!demolition_pk3) - { - I_Error("Engine resources (%s) not found", baseres.GetChars()); - } - } -} - -FileReader openFromBaseResource(const char* fn) -{ - InitBaseRes(); - auto lump = demolition_pk3->FindLump(fn); - if (lump) return lump->NewReader(); - // Also look in game filtered directories. - FStringf filtername("filter/%s/%s", LumpFilter.GetChars(), fn); - lump = demolition_pk3->FindLump(filtername); - if (lump) return lump->NewReader(); - return FileReader(nullptr); - -} - #if SDL_MAJOR_VERSION != 1 int32_t videoSetVsync(int32_t newSync) diff --git a/source/common/gamecvars.cpp b/source/common/gamecvars.cpp index b56ee6fc0..cd58531f3 100644 --- a/source/common/gamecvars.cpp +++ b/source/common/gamecvars.cpp @@ -511,7 +511,6 @@ CUSTOM_CVAR(String, rtsname, "", CVAR_ARCHIVE | CVAR_USERINFO) /* Baselayer CVARs. Some are pointless, some not worth bothering before the backend is swappewd out, the only relevant one was r_voxels. static osdcvardata_t cvars_engine[] = { - { "lz4compressionlevel","adjust LZ4 compression level used for savegames",(void *) &lz4CompressionLevel, CVAR_INT, 1, 32 }, { "r_usenewaspect","enable/disable new screen aspect ratio determination code",(void *) &r_usenewaspect, CVAR_BOOL, 0, 1 }, { "r_screenaspect","if using r_usenewaspect and in fullscreen, screen aspect ratio in the form XXYY, e.g. 1609 for 16:9", (void *) &r_screenxy, SCREENASPECT_CVAR_TYPE, 0, 9999 }, diff --git a/source/common/initfs.cpp b/source/common/initfs.cpp new file mode 100644 index 000000000..597c476da --- /dev/null +++ b/source/common/initfs.cpp @@ -0,0 +1,373 @@ +/* +** initfs.cpp +** +**--------------------------------------------------------------------------- +** Copyright 1999-2016 Randy Heit +** Copyright 2002-2019 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + +#include "filesystem/filesystem.h" +#include "filesystem/resourcefile.h" +#include "cmdlib.h" +#include "zstring.h" +#include "gamecontrol.h" +#include "gameconfigfile.h" +#include "printf.h" +#include "m_argv.h" +#include "../platform/win32/i_findfile.h" // This is a temporary direct path. Needs to be fixed when stuff gets cleaned up. + +#ifndef PATH_MAX +#define PATH_MAX 260 +#endif + +//========================================================================== +// +// BaseFileSearch +// +// If a file does not exist at , looks for it in the directories +// specified in the config file. Returns the path to the file, if found, +// or nullptr if it could not be found. +// +//========================================================================== + +FString BaseFileSearch (const char *file, const char *ext, bool lookfirstinprogdir) +{ + FString wad; + + if (file == nullptr || *file == '\0') + { + return nullptr; + } + if (lookfirstinprogdir) + { + wad.Format("%s%s%s", progdir.GetChars(), progdir.Back() == '/' ? "" : "/", file); + if (DirEntryExists (wad)) + { + return wad; + } + } + + if (DirEntryExists (file)) + { + wad.Format("%s", file); + return wad; + } + + if (GameConfig != nullptr && GameConfig->SetSection ("FileSearch.Directories")) + { + const char *key; + const char *value; + + while (GameConfig->NextInSection (key, value)) + { + if (stricmp (key, "Path") == 0) + { + FString dir; + + dir = NicePath(value); + if (dir.IsNotEmpty()) + { + wad.Format("%s%s%s", dir.GetChars(), dir.Back() == '/' ? "" : "/", file); + if (DirEntryExists (wad)) + { + return wad; + } + } + } + } + } + + // Retry, this time with a default extension + if (ext != nullptr) + { + FString tmp = file; + DefaultExtension (tmp, ext); + return BaseFileSearch (tmp, nullptr, lookfirstinprogdir); + } + return nullptr; +} + +//========================================================================== +// +// D_AddFile +// +//========================================================================== + +bool D_AddFile (TArray &wadfiles, const char *file, bool check = true, int position = -1) +{ + if (file == NULL || *file == '\0') + { + return false; + } + + if (check && !DirEntryExists (file)) + { + const char *f = BaseFileSearch (file, ".wad", false); + if (f == NULL) + { + Printf ("Can't find '%s'\n", file); + return false; + } + file = f; + } + + FString f = file; + f.Substitute("\\", "/"); + if (position == -1) wadfiles.Push(f); + else wadfiles.Insert(position, f); + return true; +} + + //========================================================================== +// +// D_AddWildFile +// +//========================================================================== + +void D_AddWildFile (TArray &wadfiles, const char *value) +{ + if (value == NULL || *value == '\0') + { + return; + } + const char *wadfile = BaseFileSearch (value, ".wad", false); + + if (wadfile != NULL) + { + D_AddFile (wadfiles, wadfile); + } + else + { // Try pattern matching + findstate_t findstate; + char path[260]; + char *sep; + void *handle = I_FindFirst (value, &findstate); + + strcpy (path, value); + sep = strrchr (path, '/'); + if (sep == NULL) + { + sep = strrchr (path, '\\'); +#ifdef _WIN32 + if (sep == NULL && path[1] == ':') + { + sep = path + 1; + } +#endif + } + + if (handle != ((void *)-1)) + { + do + { + if (!(I_FindAttr(&findstate) & FA_DIREC)) + { + if (sep == NULL) + { + D_AddFile (wadfiles, I_FindName (&findstate)); + } + else + { + strcpy (sep+1, I_FindName (&findstate)); + D_AddFile (wadfiles, path, false ); + } + } + } while (I_FindNext (handle, &findstate) == 0); + } + I_FindClose (handle); + } +} + +//========================================================================== +// +// D_AddConfigWads +// +// Adds all files in the specified config file section. +// +//========================================================================== + +void D_AddConfigWads (TArray &wadfiles, const char *section) +{ + if (GameConfig->SetSection (section)) + { + const char *key; + const char *value; + FConfigFile::Position pos; + + while (GameConfig->NextInSection (key, value)) + { + if (stricmp (key, "Path") == 0) + { + // D_AddWildFile resets GameConfig's position, so remember it + GameConfig->GetPosition (pos); + D_AddWildFile (wadfiles, ExpandEnvVars(value)); + // Reset GameConfig's position to get next wad + GameConfig->SetPosition (pos); + } + } + } +} + + //========================================================================== +// +// D_AddDirectory +// +// Add all .wad files in a directory. Does not descend into subdirectories. +// +//========================================================================== + +static void D_AddDirectory (TArray &wadfiles, const char *dir) +{ + char curdir[PATH_MAX]; + + if (getcwd (curdir, PATH_MAX)) + { + char skindir[PATH_MAX]; + findstate_t findstate; + void *handle; + size_t stuffstart; + + stuffstart = strlen (dir); + memcpy (skindir, dir, stuffstart*sizeof(*dir)); + skindir[stuffstart] = 0; + + if (skindir[stuffstart-1] == '/') + { + skindir[--stuffstart] = 0; + } + + if (!chdir (skindir)) + { + skindir[stuffstart++] = '/'; + int savedstart = stuffstart; + const char* validexts[] = { "*.grp", "*.zip", "*.pk3", "*.pk4", "*.7z", "*.pk7" }; + for (auto ext : validexts) + { + stuffstart = savedstart; + if ((handle = I_FindFirst(ext, &findstate)) != (void*)-1) + { + do + { + if (!(I_FindAttr(&findstate) & FA_DIREC)) + { + strcpy(skindir + stuffstart, I_FindName(&findstate)); + D_AddFile(wadfiles, skindir); + } + } while (I_FindNext(handle, &findstate) == 0); + I_FindClose(handle); + } + } + } + chdir (curdir); + } +} + + +void InitFileSystem(TArray& groups) +{ + TArray dependencies; + TArray Files; + + // First comes the engine's own stuff. + FString baseres = progdir + "demolition.pk3"; + D_AddFile(Files, baseres); + + bool insertdirectoriesafter = Args->CheckParm("-insertdirafter"); + + int i = groups.Size()-1; + for (auto &grp : groups) + { + // Add all dependencies, plus the directory of the base dependency. + // Directories of addon content are not added if they differ from the main directory. + // Also, the directory is inserted after the base dependency, allowing the addons to override directory content. + // This can be overridden via command line switch if needed. + if (!grp.FileInfo.loaddirectory) + D_AddFile(Files, grp.FileName); + + auto fn = grp.FileName; + fn.Substitute("\\", "/"); + auto index = fn.LastIndexOf("/"); + fn.Truncate(index+1); // right after the last slash. + for (auto& fname : grp.FileInfo.loadfiles) + { + FString newname = fn + fname; + D_AddFile(Files, newname); + } + + // Add the game's main directory in the proper spot. + if ((i == (insertdirectoriesafter ? 0 : dependencies.Size() - 1)) || grp.FileInfo.loaddirectory) + { + // Build's original 'file system' loads all GRPs before the first external directory. + // Do this only if explicitly requested because this severely limits the usability of GRP files. + if (insertdirectoriesafter && i == 0) for (auto& file : *userConfig.AddFilesPre) + { + D_AddFile(Files, file); + } + + D_AddFile(Files, fn); + } + i--; + } + + if (!insertdirectoriesafter) for (auto& file : *userConfig.AddFilesPre) + { + D_AddFile(Files, file); + } + for (auto& file : *userConfig.AddFiles) + { + D_AddFile(Files, file); + } + + // Finally, if the last entry in the chain is a directory, it's being considered the mod directory, and all GRPs inside need to be loaded, too. + if (userConfig.AddFiles->NumArgs() > 0) + { + auto fn = (*userConfig.AddFiles)[userConfig.AddFiles->NumArgs() - 1]; + bool isdir = false; + if (DirEntryExists(fn, &isdir) && isdir) + { + // Insert the GRPs before this entry itself. + FString lastfn; + Files.Pop(lastfn); + D_AddDirectory(Files, fn); + Files.Push(lastfn); + } + } + + TArray todelete; + fileSystem.InitMultipleFiles(Files, todelete); + + FILE* f = fopen("filesystem.dir", "wb"); + for (int i = 0; i < fileSystem.GetNumEntries(); i++) + { + auto fd = fileSystem.GetFileAt(i); + fprintf(f, "%.50s %60s %d\n", fd->FullName(), fileSystem.GetResourceFileFullName(fileSystem.GetFileContainer(i)), fd->Size()); + } + fclose(f); +} diff --git a/source/common/openaudio.cpp b/source/common/openaudio.cpp new file mode 100644 index 000000000..f57869096 --- /dev/null +++ b/source/common/openaudio.cpp @@ -0,0 +1,119 @@ + +#include "cache1d.h" +#include "openaudio.h" +#include "gamecvars.h" + + +////////// + +#if 0 // disabled pending a rewrite from the ground up. + +static FileReader S_TryFormats(char * const testfn, char * const fn_suffix, char const searchfirst) +{ +#ifdef HAVE_FLAC + { + Bstrcpy(fn_suffix, ".flac"); + auto fp = kopenFileReader(testfn, searchfirst); + if (fp.isOpen()) + return fp; + } +#endif + +#ifdef HAVE_VORBIS + { + Bstrcpy(fn_suffix, ".ogg"); + auto fp = kopenFileReader(testfn, searchfirst); + if (fp.isOpen()) + return fp; + } +#endif + + return FileReader(); +} + +static FileReader S_TryExtensionReplacements(char * const testfn, char const searchfirst, uint8_t const ismusic) +{ + char * extension = Bstrrchr(testfn, '.'); + char * const fn_end = Bstrchr(testfn, '\0'); + + // ex: grabbag.voc --> grabbag_voc.* + if (extension != NULL) + { + *extension = '_'; + + auto fp = S_TryFormats(testfn, fn_end, searchfirst); + if (fp.isOpen()) + return fp; + } + else + { + extension = fn_end; + } + + // ex: grabbag.mid --> grabbag.* + if (ismusic) + { + auto fp = S_TryFormats(testfn, extension, searchfirst); + if (fp.isOpen()) + return fp; + } + + return FileReader(); +} +#endif + +FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic) +{ + auto origfp = kopenFileReader(fn, searchfirst); + if (!snd_tryformats) return origfp; + return origfp; +#if 0 // this needs to be redone + char const* const origparent = origfp.isOpen() ? kfileparent(origfp) : NULL; + uint32_t const parentlength = origparent != NULL ? Bstrlen(origparent) : 0; + + auto testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + parentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0' + + // look in ./ + // ex: ./grabbag.mid + Bstrcpy(testfn, fn); + auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); + if (fp.isOpen()) + { + Bfree(testfn); + return fp; + } + + // look in ./music// + // ex: ./music/duke3d/grabbag.mid + // ex: ./music/nwinter/grabbag.mid + if (origparent != NULL) + { + char const * const parentextension = Bstrrchr(origparent, '.'); + uint32_t const namelength = parentextension != NULL ? (unsigned)(parentextension - origparent) : parentlength; + + Bsprintf(testfn, "music/%.*s/%s", namelength, origparent, fn); + auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); + if (fp.isOpen()) + { + Bfree(testfn); + return fp; + } + } + + // look in ./music/ + // ex: ./music/grabbag.mid + { + Bsprintf(testfn, "music/%s", fn); + auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); + if (fp.isOpen()) + { + Bfree(testfn); + return fp; + } + } + + Bfree(testfn); + return origfp; +#endif +} + diff --git a/source/common/openaudio.h b/source/common/openaudio.h new file mode 100644 index 000000000..e9fee2288 --- /dev/null +++ b/source/common/openaudio.h @@ -0,0 +1,4 @@ +#pragma once + +// This really, really needs to be redone in its entirety, the audio lookup code is hideous. +extern FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t ismusic); diff --git a/source/common/searchpaths.cpp b/source/common/searchpaths.cpp index d8d64282f..78fa3f03b 100644 --- a/source/common/searchpaths.cpp +++ b/source/common/searchpaths.cpp @@ -1114,3 +1114,71 @@ const char* G_ConFile(void) } +#if 0 +// Should this be added to the game data collector? +bool AddINIFile(const char* pzFile, bool bForce = false) +{ + char* pzFN; + struct Bstat st; + static INICHAIN* pINIIter = NULL; + if (!bForce) + { + if (findfrompath(pzFile, &pzFN)) return false; // failed to resolve the filename + if (Bstat(pzFN, &st)) + { + Bfree(pzFN); + return false; + } // failed to stat the file + Bfree(pzFN); + IniFile* pTempIni = new IniFile(pzFile); + if (!pTempIni->FindSection("Episode1")) + { + delete pTempIni; + return false; + } + delete pTempIni; + } + if (!pINIChain) + pINIIter = pINIChain = new INICHAIN; + else + pINIIter = pINIIter->pNext = new INICHAIN; + pINIIter->pNext = NULL; + pINIIter->pDescription = NULL; + Bstrncpy(pINIIter->zName, pzFile, BMAX_PATH); + for (int i = 0; i < ARRAY_SSIZE(gINIDescription); i++) + { + if (!Bstrncasecmp(pINIIter->zName, gINIDescription[i].pzFilename, BMAX_PATH)) + { + pINIIter->pDescription = &gINIDescription[i]; + break; + } + } + return true; +} + +void ScanINIFiles(void) +{ + nINICount = 0; + BUILDVFS_FIND_REC* pINIList = klistpath("/", "*.ini", BUILDVFS_FIND_FILE); + pINIChain = NULL; + + if (bINIOverride || !pINIList) + { + AddINIFile(BloodIniFile, true); + } + + for (auto pIter = pINIList; pIter; pIter = pIter->next) + { + AddINIFile(pIter->name); + } + klistfree(pINIList); + pINISelected = pINIChain; + for (auto pIter = pINIChain; pIter; pIter = pIter->pNext) + { + if (!Bstrncasecmp(BloodIniFile, pIter->zName, BMAX_PATH)) + { + pINISelected = pIter; + break; + } + } +#endif \ No newline at end of file diff --git a/source/duke3d/CMakeLists.txt b/source/duke3d/CMakeLists.txt index 66c64d607..6f160fd10 100644 --- a/source/duke3d/CMakeLists.txt +++ b/source/duke3d/CMakeLists.txt @@ -46,7 +46,6 @@ set( PCH_SOURCES src/gameexec.cpp src/gamevars.cpp src/global.cpp - src/grpscan.cpp src/menus.cpp src/namesdyn.cpp src/network.cpp diff --git a/source/duke3d/src/common.cpp b/source/duke3d/src/common.cpp index 1c69e2333..754834fa0 100644 --- a/source/duke3d/src/common.cpp +++ b/source/duke3d/src/common.cpp @@ -10,7 +10,6 @@ #include "palette.h" #include "gamecvars.h" #include "cmdlib.h" -#include "grpscan.h" #include "rts.h" #include "gamecontrol.h" @@ -140,116 +139,5 @@ void G_LoadLookups(void) } } -////////// - -#ifdef FORMAT_UPGRADE_ELIGIBLE - -static FileReader S_TryFormats(char * const testfn, char * const fn_suffix, char const searchfirst) -{ -#ifdef HAVE_FLAC - { - Bstrcpy(fn_suffix, ".flac"); - auto fp = kopenFileReader(testfn, searchfirst); - if (fp.isOpen()) - return fp; - } -#endif - -#ifdef HAVE_VORBIS - { - Bstrcpy(fn_suffix, ".ogg"); - auto fp = kopenFileReader(testfn, searchfirst); - if (fp.isOpen()) - return fp; - } -#endif - - return FileReader(); -} - -static FileReader S_TryExtensionReplacements(char * const testfn, char const searchfirst, uint8_t const ismusic) -{ - char * extension = Bstrrchr(testfn, '.'); - char * const fn_end = Bstrchr(testfn, '\0'); - - // ex: grabbag.voc --> grabbag_voc.* - if (extension != NULL) - { - *extension = '_'; - - auto fp = S_TryFormats(testfn, fn_end, searchfirst); - if (fp.isOpen()) - return fp; - } - else - { - extension = fn_end; - } - - // ex: grabbag.mid --> grabbag.* - if (ismusic) - { - auto fp = S_TryFormats(testfn, extension, searchfirst); - if (fp.isOpen()) - return fp; - } - - return FileReader(); -} - -FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic) -{ - auto origfp = kopenFileReader(fn, searchfirst); - if (!snd_tryformats) return origfp; - - char const* const origparent = origfp.isOpen() ? kfileparent(origfp) : NULL; - uint32_t const parentlength = origparent != NULL ? Bstrlen(origparent) : 0; - - auto testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + parentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0' - - // look in ./ - // ex: ./grabbag.mid - Bstrcpy(testfn, fn); - auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); - if (fp.isOpen()) - { - Bfree(testfn); - return fp; - } - - // look in ./music// - // ex: ./music/duke3d/grabbag.mid - // ex: ./music/nwinter/grabbag.mid - if (origparent != NULL) - { - char const * const parentextension = Bstrrchr(origparent, '.'); - uint32_t const namelength = parentextension != NULL ? (unsigned)(parentextension - origparent) : parentlength; - - Bsprintf(testfn, "music/%.*s/%s", namelength, origparent, fn); - auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); - if (fp.isOpen()) - { - Bfree(testfn); - return fp; - } - } - - // look in ./music/ - // ex: ./music/grabbag.mid - { - Bsprintf(testfn, "music/%s", fn); - auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); - if (fp.isOpen()) - { - Bfree(testfn); - return fp; - } - } - - Bfree(testfn); - return origfp; -} - -#endif END_DUKE_NS diff --git a/source/duke3d/src/common_game.h b/source/duke3d/src/common_game.h index f8594ee73..fbe435b15 100644 --- a/source/duke3d/src/common_game.h +++ b/source/duke3d/src/common_game.h @@ -8,7 +8,6 @@ #define EDUKE32_COMMON_GAME_H_ #include "collections.h" -#include "grpscan.h" #include "gamecontrol.h" #include "vfs.h" @@ -67,8 +66,5 @@ extern void G_LoadLookups(void); ////////// -# define FORMAT_UPGRADE_ELIGIBLE -extern FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t ismusic); - END_DUKE_NS #endif diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index c7a47f690..31b589b3d 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -4687,20 +4687,6 @@ void G_HandleLocalKeys(void) Demo_PrepareWarp(); } -#if 0 - // Enter a game from within a demo. - if (KB_KeyPressed(sc_Return) && ud.multimode==1) - { - KB_ClearKeyDown(sc_Return); - g_demo_cnt = g_demo_goalCnt = ud.reccnt = ud.pause_on = ud.recstat = ud.m_recstat = 0; - // XXX: probably redundant; this stuff needs an API anyway: - kclose(g_demo_recFilePtr); g_demo_recFilePtr = buildvfs_kfd_invalid; - myplayer.gm = MODE_GAME; - ready2send=1; // TODO: research this weird variable - screenpeek=myconnectindex; -// g_demo_paused=0; - } -#endif } if (SHIFTS_IS_PRESSED || ALT_IS_PRESSED || WIN_IS_PRESSED) @@ -5734,9 +5720,7 @@ void G_Shutdown(void) KB_Shutdown(); engineUnInit(); G_Cleanup(); - FreeGroups(); OSD_Cleanup(); - uninitgroupfile(); Bfflush(NULL); } diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index a67a069c2..94920bdd1 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -1904,7 +1904,7 @@ static int C_CountCaseStatements() static void C_Include(const char *confile) { - auto fp = kopenFileReader(confile,g_loadFromGroupOnly); + auto fp = kopenFileReader(confile,0); if (!fp.isOpen()) { @@ -1956,16 +1956,6 @@ static void C_Include(const char *confile) } #endif // !defined LUNATIC -#ifdef _WIN32 -static void check_filename_case(const char *fn) -{ - // WTF?!? - testkopen(fn, g_loadFromGroupOnly); -} -#else -static void check_filename_case(const char *fn) { UNREFERENCED_PARAMETER(fn); } -#endif - void G_DoGameStartup(const int32_t *params) { auto &p0 = *g_player[0].ps; @@ -2039,7 +2029,6 @@ void C_DefineMusic(int volumeNum, int levelNum, const char *fileName) Xfree(pMapInfo->musicfn); pMapInfo->musicfn = dup_filename(fileName); - check_filename_case(pMapInfo->musicfn); } void C_DefineVolumeFlags(int32_t vol, int32_t flags) @@ -5593,8 +5582,6 @@ repeatcase: } g_sounds[k].filename[i] = '\0'; - check_filename_case(g_sounds[k].filename); - C_GetNextValue(LABEL_DEFINE); g_sounds[k].ps = g_scriptPtr[-1]; C_GetNextValue(LABEL_DEFINE); @@ -6095,7 +6082,7 @@ void C_Compile(const char *fileName) Gv_Init(); C_InitProjectiles(); - auto kFile = kopenFileReader(fileName,g_loadFromGroupOnly); + auto kFile = kopenFileReader(fileName,0); if (!kFile.isOpen()) { diff --git a/source/duke3d/src/grpscan.cpp b/source/duke3d/src/grpscan.cpp deleted file mode 100644 index 105b39e17..000000000 --- a/source/duke3d/src/grpscan.cpp +++ /dev/null @@ -1,689 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2010 EDuke32 developers and contributors - -This file is part of EDuke32. - -EDuke32 is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#include "ns.h" // Must come before everything else! - -#include "baselayer.h" -#include "cache1d.h" -#include "common_game.h" -#include "compat.h" -#include "crc32_.h" -#include "duke3d.h" -#include "grpscan.h" -#include "scriptfile.h" - -#include "vfs.h" - -BEGIN_DUKE_NS - -#ifndef EDUKE32_STANDALONE -static void process_vaca13(int32_t crcval); -static void process_vacapp15(int32_t crcval); - -// custom GRP support for the startup window, file format reflects the structure below -#define GAMELISTFILE "games.list" -// name crc size flags dependency scriptname postprocessing -static internalgrpinfo_t const internalgrpfiles[] = -{ - { "Duke Nukem 3D", DUKE13_CRC, 26524524, GAMEFLAG_DUKE, 0, NULL, NULL}, - { "Duke Nukem 3D (South Korean Censored)", DUKEKR_CRC, 26385383, GAMEFLAG_DUKE, 0, NULL, NULL}, - { "Duke Nukem 3D: Atomic Edition", DUKE15_CRC, 44356548, GAMEFLAG_DUKE, 0, NULL, NULL}, - { "Duke Nukem 3D: Atomic Edition (WT)", DUKEWT_CRC, 44356548, GAMEFLAG_DUKE, 0, NULL, NULL}, - { "Duke Nukem 3D: Plutonium Pak", DUKEPP_CRC, 44348015, GAMEFLAG_DUKE, 0, NULL, NULL}, - { "Duke Nukem 3D Shareware 0.99", DUKE099_CRC, 9690241, GAMEFLAG_DUKE|GAMEFLAG_DUKEBETA, 0, NULL, NULL}, - { "Duke Nukem 3D Shareware 1.0", DUKE10_CRC, 10429258, GAMEFLAG_DUKE|GAMEFLAG_SHAREWARE, 0, NULL, NULL}, - { "Duke Nukem 3D Shareware 1.1", DUKE11_CRC, 10442980, GAMEFLAG_DUKE|GAMEFLAG_SHAREWARE, 0, NULL, NULL}, - { "Duke Nukem 3D Shareware 1.3D", DUKESW_CRC, 11035779, GAMEFLAG_DUKE|GAMEFLAG_SHAREWARE, 0, NULL, NULL}, - { "Duke Nukem 3D Mac Demo", DUKEMD_CRC, 10444391, GAMEFLAG_DUKE|GAMEFLAG_SHAREWARE, 0, NULL, NULL}, - { "Duke Nukem 3D MacUser Demo", DUKEMD2_CRC, 10628573, GAMEFLAG_DUKE|GAMEFLAG_SHAREWARE, 0, NULL, NULL }, - { "Duke it out in D.C. (1.3D)", DUKEDC13_CRC, 7926624, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE13_CRC, NULL, NULL}, - { "Duke it out in D.C.", DUKEDCPP_CRC, 8225517, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, NULL, NULL}, - { "Duke it out in D.C.", DUKEDC_CRC, 8410183, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, NULL, NULL}, - { "Duke it out in D.C.", (int32_t) 0x39A692BF, 8410187, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "DUKEDC.CON", NULL}, - { "Duke Caribbean: Life's a Beach (1.3D)", VACA13_CRC, 23559381, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE13_CRC, NULL, process_vaca13}, - { "Duke Caribbean: Life's a Beach (PPak)", VACAPP_CRC, 22551333, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKEPP_CRC, NULL, process_vacapp15}, - { "Duke Caribbean: Life's a Beach", VACA15_CRC, 22521880, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, NULL, process_vacapp15}, - { "Duke Caribbean: Life's a Beach", DUKECB_CRC, 22213819, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, NULL, NULL}, - { "Duke Caribbean: Life's a Beach", (int32_t) 0x65B5F690, 22397273, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "VACATION.CON", NULL}, - { "Duke: Nuclear Winter", DUKENW_CRC, 16169365, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "NWINTER.CON", NULL}, - { "Duke: Nuclear Winter Demo", (int32_t) 0xC7EFBFA9, 10965909, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "NWINTER.CON", NULL}, - { "Duke!ZONE II (1.3D)", DZ2_13_CRC, 26135388, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE13_CRC, "DZ-GAME.CON", NULL}, - { "Duke!ZONE II", DZ2_PP_CRC, 44100411, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "DZ-GAME.CON", NULL}, - { "Duke!ZONE II", (int32_t) 0x1E9516F1, 3186656, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "DZ-GAME.CON", NULL}, - { "NAM", NAM_CRC, 43448927, GAMEFLAG_NAM, 0, NULL, NULL}, - { "NAPALM", NAPALM_CRC, 44365728, GAMEFLAG_NAM|GAMEFLAG_NAPALM, 0, NULL, NULL}, - { "WWII GI", WW2GI_CRC, 77939508, GAMEFLAG_WW2GI, 0, NULL, NULL}, - { "Platoon Leader", PLATOONL_CRC, 37852572, GAMEFLAG_WW2GI|GAMEFLAG_ADDON, WW2GI_CRC, "PLATOONL.DEF", NULL}, -}; -#endif - -struct grpfile_t *foundgrps = NULL; -struct grpinfo_t *listgrps = NULL; - -static void LoadList(const char * filename) -{ - scriptfile *script = scriptfile_fromfile(filename); - - if (!script) - return; - -#ifndef EDUKE32_STANDALONE - scriptfile_addsymbolvalue("GAMEFLAG_DUKE", GAMEFLAG_DUKE); - scriptfile_addsymbolvalue("GAMEFLAG_ADDON", GAMEFLAG_DUKE|GAMEFLAG_ADDON); - scriptfile_addsymbolvalue("GAMEFLAG_NAM", GAMEFLAG_NAM); - scriptfile_addsymbolvalue("GAMEFLAG_NAPALM", GAMEFLAG_NAM|GAMEFLAG_NAPALM); - scriptfile_addsymbolvalue("GAMEFLAG_WW2GI", GAMEFLAG_NAM|GAMEFLAG_WW2GI); - scriptfile_addsymbolvalue("DUKE15_CRC", DUKE15_CRC); - scriptfile_addsymbolvalue("DUKEPP_CRC", DUKEPP_CRC); - scriptfile_addsymbolvalue("DUKE13_CRC", DUKE13_CRC); - scriptfile_addsymbolvalue("DUKEDC13_CRC", DUKEDC13_CRC); - scriptfile_addsymbolvalue("DUKEDCPP_CRC", DUKEDCPP_CRC); - scriptfile_addsymbolvalue("DUKEDC_CRC", DUKEDC_CRC); - scriptfile_addsymbolvalue("VACA13_CRC", VACA13_CRC); - scriptfile_addsymbolvalue("VACAPP_CRC", VACAPP_CRC); - scriptfile_addsymbolvalue("VACA15_CRC", VACA15_CRC); - scriptfile_addsymbolvalue("DUKECB_CRC", DUKECB_CRC); - scriptfile_addsymbolvalue("DUKENW_CRC", DUKENW_CRC); - scriptfile_addsymbolvalue("DZ2_13_CRC", DZ2_13_CRC); - scriptfile_addsymbolvalue("DZ2_PP_CRC", DZ2_PP_CRC); - scriptfile_addsymbolvalue("NAM_CRC", NAM_CRC); - scriptfile_addsymbolvalue("NAPALM_CRC", NAPALM_CRC); - scriptfile_addsymbolvalue("WW2GI_CRC", WW2GI_CRC); -#endif - - while (!scriptfile_eof(script)) - { - enum - { - T_GRPINFO, - T_GAMENAME, - T_CRC, - T_SIZE, - T_DEPCRC, - T_SCRIPTNAME, - T_DEFNAME, - T_FLAGS, - T_RTSNAME, - }; - - static const tokenlist profiletokens[] = - { - { "grpinfo", T_GRPINFO }, - }; - - int32_t token = getatoken(script,profiletokens,ARRAY_SIZE(profiletokens)); - switch (token) - { - case T_GRPINFO: - { - int32_t gsize = 0, gcrcval = 0, gflags = GAMEFLAG_DUKE, gdepcrc = DUKE15_CRC; - char *gname = NULL, *gscript = NULL, *gdef = NULL; - char *grts = NULL; - char *grpend = NULL; - - static const tokenlist grpinfotokens[] = - { - { "name", T_GAMENAME }, - { "scriptname", T_SCRIPTNAME }, - { "defname", T_DEFNAME }, - { "rtsname", T_RTSNAME }, - { "crc", T_CRC }, - { "dependency", T_DEPCRC }, - { "size", T_SIZE }, - { "flags", T_FLAGS }, - - }; - - if (scriptfile_getbraces(script,&grpend)) break; - - while (script->textptr < grpend) - { - int32_t token = getatoken(script,grpinfotokens,ARRAY_SIZE(grpinfotokens)); - - switch (token) - { - case T_GAMENAME: - scriptfile_getstring(script,&gname); break; - case T_SCRIPTNAME: - scriptfile_getstring(script,&gscript); break; - case T_DEFNAME: - scriptfile_getstring(script,&gdef); break; - case T_RTSNAME: - scriptfile_getstring(script,&grts); break; - - case T_FLAGS: - scriptfile_getsymbol(script,&gflags); gflags &= GAMEFLAGMASK; break; - case T_DEPCRC: - scriptfile_getsymbol(script,&gdepcrc); break; - case T_CRC: - scriptfile_getsymbol(script,&gcrcval); break; - case T_SIZE: - scriptfile_getnumber(script,&gsize); break; - default: - break; - } - - grpinfo_t * const fg = (grpinfo_t *)Xcalloc(1, sizeof(grpinfo_t)); - fg->next = listgrps; - listgrps = fg; - - if (gname) - fg->name = Xstrdup(gname); - - fg->size = gsize; - fg->crcval = gcrcval; - fg->dependency = gdepcrc; - fg->game = gflags; - - if (gscript) - fg->scriptname = dup_filename(gscript); - - if (gdef) - fg->defname = dup_filename(gdef); - - if (grts) - fg->rtsname = dup_filename(grts); - } - break; - } - - default: - break; - } - } - - scriptfile_close(script); - scriptfile_clearsymbols(); -} - -static void LoadGameList(void) -{ -#ifndef EDUKE32_STANDALONE - for (size_t i = 0; i < ARRAY_SIZE(internalgrpfiles); i++) - { - grpinfo_t * const fg = (grpinfo_t *)Xcalloc(1, sizeof(grpinfo_t)); - - fg->name = Xstrdup(internalgrpfiles[i].name); - fg->crcval = internalgrpfiles[i].crcval; - fg->size = internalgrpfiles[i].size; - fg->game = internalgrpfiles[i].game; - fg->dependency = internalgrpfiles[i].dependency; - - if (internalgrpfiles[i].scriptname) - fg->scriptname = dup_filename(internalgrpfiles[i].scriptname); - - fg->postprocessing = internalgrpfiles[i].postprocessing; - - fg->next = listgrps; - listgrps = fg; - } -#endif - -#ifdef USE_PHYSFS - auto const base = PHYSFS_getBaseDir(); -#else - static char const base[] = "/"; -#endif - CACHE1D_FIND_REC * const srch = klistpath(base, "*.grpinfo", CACHE1D_FIND_FILE); - - for (CACHE1D_FIND_REC *sidx = srch; sidx; sidx = sidx->next) - LoadList(sidx->name); - - klistfree(srch); -} - -static void FreeGameList(void) -{ - while (listgrps) - { - Xfree(listgrps->name); - Xfree(listgrps->scriptname); - Xfree(listgrps->defname); - Xfree(listgrps->rtsname); - - grpinfo_t * const fg = listgrps->next; - Xfree(listgrps); - listgrps = fg; - } -} - - -#define GRPCACHEFILE "grpfiles.cache" -static struct grpcache -{ - struct grpcache *next; - int32_t size; - int32_t mtime; - int32_t crcval; - char name[BMAX_PATH]; -} -*grpcache = NULL, *usedgrpcache = NULL; - -static int32_t LoadGroupsCache(void) -{ - struct grpcache *fg; - - int32_t fsize, fmtime, fcrcval; - char *fname; - - scriptfile *script; - - script = scriptfile_fromfile(GRPCACHEFILE); - if (!script) return -1; - - while (!scriptfile_eof(script)) - { - if (scriptfile_getstring(script, &fname)) break; // filename - if (scriptfile_getnumber(script, &fsize)) break; // filesize - if (scriptfile_getnumber(script, &fmtime)) break; // modification time - if (scriptfile_getnumber(script, &fcrcval)) break; // crc checksum - - fg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache)); - fg->next = grpcache; - grpcache = fg; - - Bstrncpy(fg->name, fname, BMAX_PATH); - fg->size = fsize; - fg->mtime = fmtime; - fg->crcval = fcrcval; - } - - scriptfile_close(script); - return 0; -} - -static void FreeGroupsCache(void) -{ - while (grpcache) - { - struct grpcache * const fg = grpcache->next; - Xfree(grpcache); - grpcache = fg; - } -} - -static void RemoveGroup(grpfile_t *igrp) -{ - for (grpfile_t *prev = NULL, *grp = foundgrps; grp; grp=grp->next) - { - if (grp == igrp) - { - if (grp == foundgrps) - foundgrps = grp->next; - else - prev->next = grp->next; - - Xfree((char *)grp->filename); - Xfree(grp); - - return; - } - - prev = grp; - } -} - -grpfile_t * FindGroup(int32_t crcval) -{ - grpfile_t *grp; - - for (grp = foundgrps; grp; grp=grp->next) - { - if (grp->type->crcval == crcval) - return grp; - } - - return NULL; -} - -#ifndef USE_PHYSFS -static grpinfo_t const * FindGrpInfo(int32_t crcval, int32_t size) -{ - grpinfo_t *grpinfo; - - for (grpinfo = listgrps; grpinfo; grpinfo=grpinfo->next) - { - if (grpinfo->crcval == crcval && grpinfo->size == size) - return grpinfo; - } - - return NULL; -} - -static void ProcessGroups(CACHE1D_FIND_REC *srch) -{ - CACHE1D_FIND_REC *sidx; - struct grpcache *fg, *fgg; - char *fn; - struct Bstat st; - - static constexpr int ReadSize = 65536; - - auto buf = (uint8_t *)Xmalloc(ReadSize); - - for (sidx = srch; sidx; sidx = sidx->next) - { - for (fg = grpcache; fg; fg = fg->next) - { - if (!Bstrcmp(fg->name, sidx->name)) break; - } - - if (fg) - { - if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename - if (Bstat(fn, &st)) - { - Xfree(fn); - continue; - } // failed to stat the file - Xfree(fn); - if (fg->size == (int32_t)st.st_size && fg->mtime == (int32_t)st.st_mtime) - { - grpinfo_t const * const grptype = FindGrpInfo(fg->crcval, fg->size); - if (grptype) - { - grpfile_t * const grp = (grpfile_t *)Xcalloc(1, sizeof(grpfile_t)); - grp->filename = Xstrdup(sidx->name); - grp->type = grptype; - grp->next = foundgrps; - foundgrps = grp; - } - - fgg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache)); - strcpy(fgg->name, fg->name); - fgg->size = fg->size; - fgg->mtime = fg->mtime; - fgg->crcval = fg->crcval; - fgg->next = usedgrpcache; - usedgrpcache = fgg; - continue; - } - } - - { - int32_t b, fh; - int32_t crcval = 0; - - fh = openfrompath(sidx->name, BO_RDONLY|BO_BINARY, BS_IREAD); - if (fh < 0) continue; - if (Bfstat(fh, &st)) continue; - - initprintf(" Checksumming %s...", sidx->name); - do - { - b = read(fh, buf, ReadSize); - if (b > 0) crcval = Bcrc32((uint8_t *)buf, b, crcval); - } - while (b == ReadSize); - close(fh); - initprintf(" Done\n"); - - grpinfo_t const * const grptype = FindGrpInfo(crcval, st.st_size); - if (grptype) - { - grpfile_t * const grp = (grpfile_t *)Xcalloc(1, sizeof(grpfile_t)); - grp->filename = Xstrdup(sidx->name); - grp->type = grptype; - grp->next = foundgrps; - foundgrps = grp; - } - - fgg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache)); - Bstrncpy(fgg->name, sidx->name, BMAX_PATH); - fgg->size = st.st_size; - fgg->mtime = st.st_mtime; - fgg->crcval = crcval; - fgg->next = usedgrpcache; - usedgrpcache = fgg; - } - } - - Xfree(buf); -} -#endif - -int32_t ScanGroups(void) -{ -#ifndef USE_PHYSFS - struct grpcache *fg, *fgg; - - initprintf("Searching for game data...\n"); - - LoadGameList(); - LoadGroupsCache(); - - static char const *extensions[] = - { - "*.grp", - "*.ssi", - "*.dat", - }; - - for (char const *extension : extensions) - { - CACHE1D_FIND_REC *srch = klistpath("/", extension, CACHE1D_FIND_FILE); - ProcessGroups(srch); - klistfree(srch); - } - - FreeGroupsCache(); - - for (grpfile_t *grp = foundgrps; grp; grp=grp->next) - { - if (grp->type->dependency) - { - if (FindGroup(grp->type->dependency) == NULL) // couldn't find dependency - { - //initprintf("removing %s\n", grp->name); - RemoveGroup(grp); - grp = foundgrps; - // start from the beginning so we can remove anything that depended on this grp - continue; - } - } - } - - if (usedgrpcache) - { - int32_t i = 0; - buildvfs_FILE fp = buildvfs_fopen_write(GRPCACHEFILE); - if (fp) - { - for (fg = usedgrpcache; fg; fg=fgg) - { - fgg = fg->next; - fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval); - Xfree(fg); - i++; - } - buildvfs_fclose(fp); - } -// initprintf("Found %d recognized GRP %s.\n",i,i>1?"files":"file"); - - return 0; - } - - initprintf("Found no recognized game data!\n"); -#endif - - return 0; -} - - -void FreeGroups(void) -{ - while (foundgrps) - { - Xfree((char *)foundgrps->filename); - grpfile_t * const fg = foundgrps->next; - Xfree(foundgrps); - foundgrps = fg; - } - - FreeGameList(); -} - -#ifndef EDUKE32_STANDALONE -static void process_vaca13(int32_t crcval) -{ - krename(crcval, 0, "ADDREE.VOC"); - krename(crcval, 1, "BALLBOOM.VOC"); - krename(crcval, 2, "BARMUSIC.VOC"); - krename(crcval, 3, "BCHBALL.VOC"); - krename(crcval, 4, "BOING.VOC"); - krename(crcval, 5, "CHACHA.VOC"); - krename(crcval, 6, "CHAINDRV.VOC"); - krename(crcval, 7, "CHEAP01.VOC"); - krename(crcval, 8, "CHEER.VOC"); - krename(crcval, 9, "CHNSQRT.VOC"); - krename(crcval, 10, "COCOANUT.VOC"); - krename(crcval, 11, "CRUSH2.VOC"); - krename(crcval, 12, "DEFLATE2.VOC"); - krename(crcval, 13, "DRAGHURT.VOC"); - krename(crcval, 14, "DRAGROAM.VOC"); - krename(crcval, 15, "DRAGSHOT.VOC"); - krename(crcval, 16, "DUKE01.VOC"); - krename(crcval, 17, "ELEV1.VOC"); - krename(crcval, 18, "GMEOVR05.VOC"); - krename(crcval, 19, "GULLDIE.VOC"); - krename(crcval, 20, "GULLHURT.VOC"); - krename(crcval, 21, "GULLROAM.VOC"); - krename(crcval, 22, "GULLSHIT.VOC"); - krename(crcval, 23, "HELP04.VOC"); - krename(crcval, 24, "ICECONCH.VOC"); - krename(crcval, 25, "IDLEBOAT.VOC"); - krename(crcval, 26, "KICKHEAD.VOC"); - krename(crcval, 27, "LANI05.VOC"); - krename(crcval, 28, "LANI08.VOC"); - krename(crcval, 29, "LANIDUK2.VOC"); - krename(crcval, 30, "MUSCLE01.VOC"); - krename(crcval, 31, "MUSCLE04.VOC"); - krename(crcval, 32, "MUZAK.VOC"); - krename(crcval, 33, "PINEFALL.VOC"); - krename(crcval, 34, "POINT07.VOC"); - krename(crcval, 35, "POINT08.VOC"); - krename(crcval, 36, "RADIO.VOC"); - krename(crcval, 37, "RUIN01.VOC"); - krename(crcval, 38, "SCREAM.VOC"); - krename(crcval, 39, "SCREAM04.VOC"); - krename(crcval, 40, "SCREAM9.VOC"); - krename(crcval, 41, "SHIPHORN.VOC"); - krename(crcval, 42, "SNGLGULL.VOC"); - krename(crcval, 43, "SQRT4.VOC"); - krename(crcval, 44, "SQUIRT1.VOC"); - krename(crcval, 45, "SSCOOL1.VOC"); - krename(crcval, 46, "SSCOOL2.VOC"); - krename(crcval, 47, "SSCOOL3.VOC"); - krename(crcval, 48, "SSDIE1.VOC"); - krename(crcval, 49, "SSDIE2.VOC"); - krename(crcval, 50, "SSNORM01.VOC"); - krename(crcval, 51, "SSNORM02.VOC"); - krename(crcval, 52, "SSNORM03.VOC"); - krename(crcval, 53, "SSNORM04.VOC"); - krename(crcval, 54, "SSNORM05.VOC"); - krename(crcval, 55, "SSNORM06.VOC"); - krename(crcval, 56, "SSNORM07.VOC"); - krename(crcval, 57, "SSNORM08.VOC"); - krename(crcval, 58, "SSNORM10.VOC"); - krename(crcval, 59, "SSNORM11.VOC"); - krename(crcval, 60, "SSNORM12.VOC"); - krename(crcval, 61, "SSNORM13.VOC"); - krename(crcval, 62, "SSNORM14.VOC"); - krename(crcval, 63, "SSNORM15.VOC"); - krename(crcval, 64, "SSNORM16.VOC"); - krename(crcval, 65, "SSNORM17.VOC"); - krename(crcval, 66, "SSNORM18.VOC"); - krename(crcval, 67, "SSNORM19.VOC"); - krename(crcval, 68, "SSNORM20.VOC"); - krename(crcval, 69, "SSTAUNT1.VOC"); - krename(crcval, 70, "SSTAUNT2.VOC"); - krename(crcval, 71, "SSTAUNT3.VOC"); - krename(crcval, 72, "SSTAUNT4.VOC"); - krename(crcval, 73, "SSTAUNT5.VOC"); - krename(crcval, 74, "SSTAUNT6.VOC"); - krename(crcval, 75, "SSTAUNT7.VOC"); - krename(crcval, 76, "SSTAUNT8.VOC"); - krename(crcval, 77, "SURF.VOC"); - krename(crcval, 78, "TAN01.VOC"); - krename(crcval, 79, "TAN04.VOC"); - krename(crcval, 80, "VINESNAP.VOC"); - krename(crcval, 81, "VOODRUMS.VOC"); - krename(crcval, 82, "WIND54.VOC"); - krename(crcval, 83, "DOOMSDAY.MID"); - krename(crcval, 84, "DUKE-O.MID"); - krename(crcval, 85, "IRIEPRTY.MID"); - krename(crcval, 86, "JUNGVEIN.MID"); - krename(crcval, 87, "PRTYCRUZ.MID"); - krename(crcval, 88, "SOL-MAN1.MID"); - krename(crcval, 90, "CINEOV3.ANM"); - krename(crcval, 91, "DUKETEAM.ANM"); - krename(crcval, 92, "BEACHBAB.CON"); - krename(crcval, 93, "BEACHBAL.CON"); - krename(crcval, 94, "BEACHBTH.CON"); - krename(crcval, 95, "DEFS.CON"); - krename(crcval, 96, "DRAGON.CON"); - krename(crcval, 97, "GAME.CON"); - krename(crcval, 98, "SEAGULL.CON"); - krename(crcval, 99, "SOUNDS.CON"); - krename(crcval, 100, "USER.CON"); - krename(crcval, 101, "DEMO1.DMO"); - krename(crcval, 102, "DEMO2.DMO"); - krename(crcval, 103, "DEMO3.DMO"); - krename(crcval, 104, "VACA1.MAP"); - krename(crcval, 105, "VACA2.MAP"); - krename(crcval, 106, "VACA3.MAP"); - krename(crcval, 107, "VACA4.MAP"); - krename(crcval, 108, "VACA5.MAP"); - krename(crcval, 109, "VACA6.MAP"); - krename(crcval, 110, "VACA7.MAP"); - krename(crcval, 111, "VACADM1.MAP"); - krename(crcval, 112, "VACADM2.MAP"); - krename(crcval, 113, "VACADM3.MAP"); - krename(crcval, 114, "VACADM4.MAP"); - krename(crcval, 115, "VACASL.MAP"); - krename(crcval, 120, "TILES000.ART"); - krename(crcval, 121, "TILES001.ART"); - krename(crcval, 122, "TILES003.ART"); - krename(crcval, 123, "TILES005.ART"); - krename(crcval, 124, "TILES006.ART"); - krename(crcval, 125, "TILES007.ART"); - krename(crcval, 126, "TILES008.ART"); - krename(crcval, 127, "TILES009.ART"); - krename(crcval, 128, "TILES010.ART"); - krename(crcval, 129, "TILES012.ART"); - krename(crcval, 130, "TILES014.ART"); -} - -static void process_vacapp15(int32_t crcval) -{ - krename(crcval, 5, "DEFS.CON"); - krename(crcval, 6, "GAME.CON"); - krename(crcval, 7, "USER.CON"); - krename(crcval, 8, "DEMO1.DMO"); - krename(crcval, 9, "DEMO2.DMO"); - krename(crcval, 10, "DEMO3.DMO"); - - initgroupfile("VACATION.PRG"); -} -#endif - -END_DUKE_NS diff --git a/source/duke3d/src/grpscan.h b/source/duke3d/src/grpscan.h deleted file mode 100644 index c5d453f75..000000000 --- a/source/duke3d/src/grpscan.h +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2010 EDuke32 developers and contributors - -This file is part of EDuke32. - -EDuke32 is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#ifndef grpscan_h_ -#define grpscan_h_ - -BEGIN_DUKE_NS - -#define MAXLISTNAMELEN 32 - -// List of internally-known GRP files -#define DUKE13_CRC (int32_t)0xBBC9CE44 -#define DUKEKR_CRC (int32_t)0xAA4F6A40 -#define DUKE15_CRC (int32_t)0xFD3DCFF1 -#define DUKEPP_CRC (int32_t)0xF514A6AC -#define DUKEWT_CRC (int32_t)0x982AFE4A -#define DUKE099_CRC (int32_t)0x02F18900 -#define DUKE10_CRC (int32_t)0xA28AA589 -#define DUKE11_CRC (int32_t)0x912E1E8D -#define DUKESW_CRC (int32_t)0x983AD923 -#define DUKEMD_CRC (int32_t)0xC5F71561 -#define DUKEMD2_CRC (int32_t)0x73A15EE7 -#define DUKEDC13_CRC (int32_t)0xA9242158 -#define DUKEDCPP_CRC (int32_t)0xB79D997F -#define DUKEDC_CRC (int32_t)0xA8CF80DA -#define VACA13_CRC (int32_t)0x4A2DBB62 -#define VACAPP_CRC (int32_t)0x2F4FCCEE -#define VACA15_CRC (int32_t)0xB62B42FD -#define DUKECB_CRC (int32_t)0x18F01C5B -#define DUKENW_CRC (int32_t)0xF1CAE8E4 -#define DZ2_13_CRC (int32_t)0x82C1B47F -#define DZ2_PP_CRC (int32_t)0x7FB6117C -#define NAM_CRC (int32_t)0x75C1F07B -#define NAPALM_CRC (int32_t)0x3DE1589A -#define WW2GI_CRC (int32_t)0x907B82BF -#define PLATOONL_CRC (int32_t)0xD1ED8C0C - -enum addon_t { - ADDON_NONE, - ADDON_DUKEDC, - ADDON_NWINTER, - ADDON_CARIBBEAN, - NUMADDONS -}; - -typedef struct internalgrpinfo_t { - char const *name; - int32_t const crcval; - int32_t const size; - int32_t const game; - int32_t const dependency; - char const *scriptname; - void(*postprocessing)(int32_t); -} internalgrpinfo_t; - -typedef struct grpinfo_t { - char *name; - int32_t crcval; - int32_t size; - int32_t game; - int32_t dependency; - char *scriptname; - char *defname; - char *rtsname; - void (*postprocessing)(int32_t); - struct grpinfo_t *next; -} grpinfo_t; - -typedef struct grpfile_t { - char *filename; - struct grpinfo_t const *type; - struct grpfile_t *next; -} grpfile_t; - -extern grpfile_t *foundgrps; -extern grpinfo_t *listgrps; - -extern grpfile_t * FindGroup(int32_t crcval); - -int32_t ScanGroups(void); -void FreeGroups(void); - -END_DUKE_NS - -#endif diff --git a/source/duke3d/src/osdcmds.cpp b/source/duke3d/src/osdcmds.cpp index a059cae36..59e9b3143 100644 --- a/source/duke3d/src/osdcmds.cpp +++ b/source/duke3d/src/osdcmds.cpp @@ -720,16 +720,6 @@ static int osdcmd_lua(osdcmdptr_t parm) } #endif -static int osdcmd_initgroupfile(osdcmdptr_t parm) -{ - if (parm->numparms != 1) - return OSDCMD_SHOWHELP; - - initgroupfile(parm->parms[0]); - - return OSDCMD_OK; -} - static int osdcmd_cmenu(osdcmdptr_t parm) { if (parm->numparms != 1) @@ -1216,7 +1206,6 @@ int32_t registerosdcommands(void) OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god); OSD_RegisterFunction("activatecheat","activatecheat : activates a cheat code", osdcmd_activatecheat); - OSD_RegisterFunction("initgroupfile","initgroupfile : adds a grp file into the game filesystem", osdcmd_initgroupfile); #ifdef DEBUGGINGAIDS OSD_RegisterFunction("inittimer","debug", osdcmd_inittimer); #endif diff --git a/source/duke3d/src/savegame.cpp b/source/duke3d/src/savegame.cpp index 3033874ea..360737321 100644 --- a/source/duke3d/src/savegame.cpp +++ b/source/duke3d/src/savegame.cpp @@ -1017,7 +1017,7 @@ static int32_t readspecdata(const dataspec_t *spec, FileReader *fil, uint8_t **d OSD_Printf("rsd: spec=%s, idx=%d:\n", (char *)sptr->ptr, (int32_t)(spec-sptr)); if (ksiz!=siz) - OSD_Printf(" kread returned %d, expected %d.\n", ksiz, siz); + OSD_Printf(" file read returned %d, expected %d.\n", ksiz, siz); else OSD_Printf(" sp->ptr and cmpstrbuf not identical!\n"); @@ -2268,67 +2268,6 @@ static uint8_t *dosaveplayer2(buildvfs_FILE fil, uint8_t *mem) return mem; } -#ifdef LUNATIC -char *g_elSavecode = NULL; - -static int32_t El_ReadSaveCode(buildvfs_kfd fil) -{ - // Read Lua code to restore gamevar values from the savegame. - // It will be run from Lua with its state creation later on. - - char header[12]; - int32_t slen; - - if (kread(fil, header, 12) != 12) - { - OSD_Printf("doloadplayer2: failed reading Lunatic gamevar header.\n"); - return -100; - } - - if (Bmemcmp(header, "\0\1LunaGVAR\3\4", 12)) - { - OSD_Printf("doloadplayer2: Lunatic gamevar header doesn't match.\n"); - return -101; - } - - if (kread(fil, &slen, sizeof(slen)) != sizeof(slen)) - { - OSD_Printf("doloadplayer2: failed reading Lunatic gamevar string size.\n"); - return -102; - } - - slen = B_LITTLE32(slen); - if (slen < 0) - { - OSD_Printf("doloadplayer2: invalid Lunatic gamevar string size %d.\n", slen); - return -103; - } - - if (slen > 0) - { - char *svcode = (char *)Xmalloc(slen+1); - - if (kdfread_LZ4(svcode, 1, slen, fil) != slen) // cnt and sz swapped - { - OSD_Printf("doloadplayer2: failed reading Lunatic gamevar restoration code.\n"); - Xfree(svcode); - return -104; - } - - svcode[slen] = 0; - g_elSavecode = svcode; - } - - return 0; -} - -void El_FreeSaveCode(void) -{ - // Free Lunatic gamevar savegame restoration Lua code. - Xfree(g_elSavecode); - g_elSavecode = NULL; -} -#endif static int32_t doloadplayer2(FileReader &fil, uint8_t **memptr) { diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index d47377a49..0f72cfc3f 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "duke3d.h" #include "renderlayer.h" // for win_gethwnd() #include "al_midi.h" +#include "openaudio.h" #include #include "vfs.h" @@ -134,16 +135,12 @@ void S_MusicStartup(void) } MUSIC_SetVolume(mus_volume); - auto const fil = kopen4load("d3dtimbr.tmb", 0); + auto fr = kopenFileReader("d3dtimbr.tmb", 0); - if (fil != buildvfs_kfd_invalid) + if (fr.isOpen()) { - int l = kfilelength(fil); - auto tmb = (uint8_t *)Xmalloc(l); - kread(fil, tmb, l); - AL_RegisterTimbreBank(tmb); - Xfree(tmb); - kclose(fil); + auto tmb = fr.Read(); + AL_RegisterTimbreBank(tmb.Data()); } } @@ -470,7 +467,7 @@ int32_t S_LoadSound(int num) auto &snd = g_sounds[num]; - auto fp = S_OpenAudio(snd.filename, g_loadFromGroupOnly, 0); + auto fp = S_OpenAudio(snd.filename, 0, 0); if (!fp.isOpen()) { diff --git a/source/rr/CMakeLists.txt b/source/rr/CMakeLists.txt index 5bd82ab22..8998801f7 100644 --- a/source/rr/CMakeLists.txt +++ b/source/rr/CMakeLists.txt @@ -43,7 +43,6 @@ set( PCH_SOURCES src/gamedef.cpp src/gameexec.cpp src/global.cpp - src/grpscan.cpp src/menus.cpp src/namesdyn.cpp src/net.cpp diff --git a/source/rr/src/common.cpp b/source/rr/src/common.cpp index d6dd514e9..67af9e974 100644 --- a/source/rr/src/common.cpp +++ b/source/rr/src/common.cpp @@ -8,7 +8,6 @@ #include "baselayer.h" #include "palette.h" #include "cmdlib.h" -#include "grpscan.h" #include "gamecvars.h" #include "rts.h" #include "gamecontrol.h" @@ -183,116 +182,5 @@ void G_LoadLookups(void) } } -////////// - -#ifdef FORMAT_UPGRADE_ELIGIBLE - -static FileReader S_TryFormats(char * const testfn, char * const fn_suffix, char const searchfirst) -{ -#ifdef HAVE_FLAC - { - Bstrcpy(fn_suffix, ".flac"); - auto fp = kopenFileReader(testfn, searchfirst); - if (fp.isOpen()) - return fp; - } -#endif - -#ifdef HAVE_VORBIS - { - Bstrcpy(fn_suffix, ".ogg"); - auto fp = kopenFileReader(testfn, searchfirst); - if (fp.isOpen()) - return fp; - } -#endif - - return FileReader(); -} - -static FileReader S_TryExtensionReplacements(char * const testfn, char const searchfirst, uint8_t const ismusic) -{ - char * extension = Bstrrchr(testfn, '.'); - char * const fn_end = Bstrchr(testfn, '\0'); - - // ex: grabbag.voc --> grabbag_voc.* - if (extension != NULL) - { - *extension = '_'; - - auto fp = S_TryFormats(testfn, fn_end, searchfirst); - if (fp.isOpen()) - return fp; - } - else - { - extension = fn_end; - } - - // ex: grabbag.mid --> grabbag.* - if (ismusic) - { - auto fp = S_TryFormats(testfn, extension, searchfirst); - if (fp.isOpen()) - return fp; - } - - return FileReader(); -} - -FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic) -{ - auto origfp = kopenFileReader(fn, searchfirst); - char const * const origparent = origfp.isOpen() ? kfileparent(origfp) : NULL; - uint32_t const origparentlength = origparent != NULL ? Bstrlen(origparent) : 0; - - char * const testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + origparentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0' - - // look in ./ - // ex: ./grabbag.mid - { - Bstrcpy(testfn, fn); - auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); - if (fp.isOpen()) - { - Bfree(testfn); - return fp; - } - } - - // look in ./music// - // ex: ./music/duke3d/grabbag.mid - // ex: ./music/nwinter/grabbag.mid - if (origparent != NULL) - { - char const * const origparentextension = Bstrrchr(origparent, '.'); - uint32_t namelength = origparentextension != NULL ? (unsigned)(origparentextension - origparent) : origparentlength; - - Bsprintf(testfn, "music/%.*s/%s", namelength, origparent, fn); - auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); - if (fp.isOpen()) - { - Bfree(testfn); - return fp; - } - } - - // look in ./music/ - // ex: ./music/grabbag.mid - { - Bsprintf(testfn, "music/%s", fn); - auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic); - if (fp.isOpen()) - { - Bfree(testfn); - return fp; - } - } - - Bfree(testfn); - return origfp; -} - -#endif END_RR_NS diff --git a/source/rr/src/common_game.h b/source/rr/src/common_game.h index b7b3e057e..a669d5c0b 100644 --- a/source/rr/src/common_game.h +++ b/source/rr/src/common_game.h @@ -8,7 +8,6 @@ #define EDUKE32_COMMON_GAME_H_ #include "collections.h" -#include "grpscan.h" #include "gamecontrol.h" BEGIN_RR_NS @@ -70,9 +69,6 @@ extern void G_LoadLookups(void); ////////// -# define FORMAT_UPGRADE_ELIGIBLE -extern FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t ismusic); - END_RR_NS #endif diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index f55f6fa5a..7386b8ede 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -6203,21 +6203,6 @@ void G_HandleLocalKeys(void) Demo_PrepareWarp(); } - -#if 0 - // Enter a game from within a demo. - if (KB_KeyPressed(sc_Return) && ud.multimode==1) - { - KB_ClearKeyDown(sc_Return); - g_demo_cnt = g_demo_goalCnt = ud.reccnt = ud.pause_on = ud.recstat = ud.m_recstat = 0; - // XXX: probably redundant; this stuff needs an API anyway: - kclose(g_demo_recFilePtr); g_demo_recFilePtr = -1; - g_player[myconnectindex].ps->gm = MODE_GAME; - ready2send=1; // TODO: research this weird variable - screenpeek=myconnectindex; -// g_demo_paused=0; - } -#endif } if (SHIFTS_IS_PRESSED || ALT_IS_PRESSED || WIN_IS_PRESSED) @@ -7099,9 +7084,7 @@ void G_Shutdown(void) G_SetFog(0); engineUnInit(); G_Cleanup(); - FreeGroups(); OSD_Cleanup(); - uninitgroupfile(); Bfflush(NULL); } diff --git a/source/rr/src/gamedef.cpp b/source/rr/src/gamedef.cpp index 34f1b238c..4c642a979 100644 --- a/source/rr/src/gamedef.cpp +++ b/source/rr/src/gamedef.cpp @@ -778,7 +778,7 @@ static int32_t C_CheckEmptyBranch(int32_t tw, intptr_t lastScriptPtr) static void C_Include(const char *confile) { - auto fp = kopenFileReader(confile,g_loadFromGroupOnly); + auto fp = kopenFileReader(confile,0); if (!fp.isOpen()) { @@ -829,16 +829,6 @@ static void C_Include(const char *confile) Bfree(mptr); } -#ifdef _WIN32 -static void check_filename_case(const char *fn) -{ - // WTF?!? - testkopen(fn, g_loadFromGroupOnly); -} -#else -static void check_filename_case(const char *fn) { UNREFERENCED_PARAMETER(fn); } -#endif - void G_DoGameStartup(const int32_t *params) { int j = 0; @@ -898,7 +888,6 @@ void C_DefineMusic(int volumeNum, int levelNum, const char *fileName) Bfree(pMapInfo->musicfn); pMapInfo->musicfn = dup_filename(fileName); - check_filename_case(pMapInfo->musicfn); } void C_DefineVolumeFlags(int32_t vol, int32_t flags) @@ -2160,8 +2149,6 @@ static int32_t C_ParseCommand(int32_t loop) } g_sounds[k].filename[i] = '\0'; - check_filename_case(g_sounds[k].filename); - C_GetNextValue(LABEL_DEFINE); g_sounds[k].ps = *(g_scriptPtr-1); C_GetNextValue(LABEL_DEFINE); @@ -2375,7 +2362,7 @@ void C_Compile(const char *fileName) C_InitHashes(); - auto kFile = kopenFileReader(fileName,g_loadFromGroupOnly); + auto kFile = kopenFileReader(fileName,0); if (!kFile.isOpen()) { diff --git a/source/rr/src/grpscan.cpp b/source/rr/src/grpscan.cpp deleted file mode 100644 index e814526ab..000000000 --- a/source/rr/src/grpscan.cpp +++ /dev/null @@ -1,544 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2010 EDuke32 developers and contributors - -This file is part of EDuke32. - -EDuke32 is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- -#include "ns.h" // Must come before everything else! - -#include "compat.h" -#include "baselayer.h" - -#include "scriptfile.h" -#include "cache1d.h" -#include "crc32_.h" - -#include "duke3d.h" -#include "common_game.h" -#include "grpscan.h" - -BEGIN_RR_NS - -//static void process_vaca13(int32_t crcval); -static void process_vacapp15(int32_t crcval); - -// custom GRP support for the startup window, file format reflects the structure below -#define GAMELISTFILE "games.list" -// name crc size flags dependency scriptname postprocessing -static internalgrpinfo_t const internalgrpfiles[] = -{ - //{ "Duke Nukem 3D", DUKE13_CRC, 26524524, GAMEFLAG_DUKE, 0, NULL, NULL}, - //{ "Duke Nukem 3D (South Korean Censored)", DUKEKR_CRC, 26385383, GAMEFLAG_DUKE, 0, NULL, NULL}, - { "Duke Nukem 3D: Atomic Edition", DUKE15_CRC, 44356548, GAMEFLAG_DUKE, 0, NULL, NULL}, - { "Duke Nukem 3D: Atomic Edition (WT)", DUKEWT_CRC, 44356548, GAMEFLAG_DUKE, 0, NULL, NULL}, - { "Duke Nukem 3D: Plutonium Pak", DUKEPP_CRC, 44348015, GAMEFLAG_DUKE, 0, NULL, NULL}, - //{ "Duke Nukem 3D Shareware 0.99", DUKE099_CRC, 9690241, GAMEFLAG_DUKE|GAMEFLAG_DUKEBETA, 0, NULL, NULL}, - //{ "Duke Nukem 3D Shareware 1.0", DUKE10_CRC, 10429258, GAMEFLAG_DUKE|GAMEFLAG_SHAREWARE, 0, NULL, NULL}, - //{ "Duke Nukem 3D Shareware 1.1", DUKE11_CRC, 10442980, GAMEFLAG_DUKE|GAMEFLAG_SHAREWARE, 0, NULL, NULL}, - //{ "Duke Nukem 3D Shareware 1.3D", DUKESW_CRC, 11035779, GAMEFLAG_DUKE|GAMEFLAG_SHAREWARE, 0, NULL, NULL}, - //{ "Duke Nukem 3D Mac Demo", DUKEMD_CRC, 10444391, GAMEFLAG_DUKE|GAMEFLAG_SHAREWARE, 0, NULL, NULL}, - //{ "Duke Nukem 3D MacUser Demo", DUKEMD2_CRC, 10628573, GAMEFLAG_DUKE|GAMEFLAG_SHAREWARE, 0, NULL, NULL }, - //{ "Duke it out in D.C. (1.3D)", DUKEDC13_CRC, 7926624, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE13_CRC, NULL, NULL}, - { "Duke it out in D.C.", DUKEDCPP_CRC, 8225517, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, NULL, NULL}, - { "Duke it out in D.C.", DUKEDC_CRC, 8410183, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, NULL, NULL}, - { "Duke it out in D.C.", (int32_t) 0x39A692BF, 8410187, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "DUKEDC.CON", NULL}, - //{ "Duke Caribbean: Life's a Beach (1.3D)", VACA13_CRC, 23559381, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE13_CRC, NULL, process_vaca13}, - { "Duke Caribbean: Life's a Beach (PPak)", VACAPP_CRC, 22551333, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKEPP_CRC, NULL, process_vacapp15}, - { "Duke Caribbean: Life's a Beach", VACA15_CRC, 22521880, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, NULL, process_vacapp15}, - { "Duke Caribbean: Life's a Beach", DUKECB_CRC, 22213819, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, NULL, NULL}, - { "Duke Caribbean: Life's a Beach", (int32_t) 0x65B5F690, 22397273, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "VACATION.CON", NULL}, - { "Duke: Nuclear Winter", DUKENW_CRC, 16169365, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "NWINTER.CON", NULL}, - { "Duke: Nuclear Winter Demo", (int32_t) 0xC7EFBFA9, 10965909, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "NWINTER.CON", NULL}, - // { "Duke!ZONE II (1.3D)", DZ2_13_CRC, 26135388, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE13_CRC, "DZ-GAME.CON", NULL}, - { "Duke!ZONE II", DZ2_PP_CRC, 44100411, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "DZ-GAME.CON", NULL}, - { "Duke!ZONE II", (int32_t) 0x1E9516F1, 3186656, GAMEFLAG_DUKE|GAMEFLAG_ADDON, DUKE15_CRC, "DZ-GAME.CON", NULL}, - { "NAM", NAM_CRC, 43448927, GAMEFLAG_NAM, 0, NULL, NULL}, - { "NAPALM", NAPALM_CRC, 44365728, GAMEFLAG_NAM|GAMEFLAG_NAPALM, 0, NULL, NULL}, - //{ "WWII GI", WW2GI_CRC, 77939508, GAMEFLAG_WW2GI, 0, NULL, NULL}, - //{ "Platoon Leader", PLATOONL_CRC, 37852572, GAMEFLAG_WW2GI|GAMEFLAG_ADDON, WW2GI_CRC, "PLATOONL.DEF", NULL}, - { "Redneck Rampage", RR_CRC, 141174222, GAMEFLAG_RR, 0, NULL, NULL }, - { "Redneck Rampage: Rides Again", RRRA_CRC, 191798609, GAMEFLAG_RR|GAMEFLAG_RRRA, 0, NULL, NULL }, -}; - -struct grpfile_t *foundgrps = NULL; -struct grpinfo_t *listgrps = NULL; - -static void LoadList(const char * filename) -{ - scriptfile *script = scriptfile_fromfile(filename); - - if (!script) - return; - - scriptfile_addsymbolvalue("GAMEFLAG_DUKE", GAMEFLAG_DUKE); - scriptfile_addsymbolvalue("GAMEFLAG_ADDON", GAMEFLAG_DUKE|GAMEFLAG_ADDON); - scriptfile_addsymbolvalue("GAMEFLAG_NAM", GAMEFLAG_NAM); - scriptfile_addsymbolvalue("GAMEFLAG_NAPALM", GAMEFLAG_NAM|GAMEFLAG_NAPALM); - scriptfile_addsymbolvalue("GAMEFLAG_RR", GAMEFLAG_RR); - scriptfile_addsymbolvalue("GAMEFLAG_RRRA", GAMEFLAG_RR|GAMEFLAG_RRRA); - scriptfile_addsymbolvalue("DUKE15_CRC", DUKE15_CRC); - scriptfile_addsymbolvalue("DUKEPP_CRC", DUKEPP_CRC); - scriptfile_addsymbolvalue("DUKE13_CRC", DUKE13_CRC); - scriptfile_addsymbolvalue("DUKEDC13_CRC", DUKEDC13_CRC); - scriptfile_addsymbolvalue("DUKEDCPP_CRC", DUKEDCPP_CRC); - scriptfile_addsymbolvalue("DUKEDC_CRC", DUKEDC_CRC); - scriptfile_addsymbolvalue("VACA13_CRC", VACA13_CRC); - scriptfile_addsymbolvalue("VACAPP_CRC", VACAPP_CRC); - scriptfile_addsymbolvalue("VACA15_CRC", VACA15_CRC); - scriptfile_addsymbolvalue("DUKECB_CRC", DUKECB_CRC); - scriptfile_addsymbolvalue("DUKENW_CRC", DUKENW_CRC); - scriptfile_addsymbolvalue("DZ2_13_CRC", DZ2_13_CRC); - scriptfile_addsymbolvalue("DZ2_PP_CRC", DZ2_PP_CRC); - scriptfile_addsymbolvalue("NAM_CRC", NAM_CRC); - scriptfile_addsymbolvalue("NAPALM_CRC", NAPALM_CRC); - scriptfile_addsymbolvalue("WW2GI_CRC", WW2GI_CRC); - - while (!scriptfile_eof(script)) - { - enum - { - T_GRPINFO, - T_GAMENAME, - T_CRC, - T_SIZE, - T_DEPCRC, - T_SCRIPTNAME, - T_DEFNAME, - T_FLAGS, - T_RTSNAME, - }; - - static const tokenlist profiletokens[] = - { - { "grpinfo", T_GRPINFO }, - }; - - int32_t token = getatoken(script,profiletokens,ARRAY_SIZE(profiletokens)); - switch (token) - { - case T_GRPINFO: - { - int32_t gsize = 0, gcrcval = 0, gflags = GAMEFLAG_DUKE, gdepcrc = DUKE15_CRC; - char *gname = NULL, *gscript = NULL, *gdef = NULL; - char *grts = NULL; - char *grpend = NULL; - - static const tokenlist grpinfotokens[] = - { - { "name", T_GAMENAME }, - { "scriptname", T_SCRIPTNAME }, - { "defname", T_DEFNAME }, - { "rtsname", T_RTSNAME }, - { "crc", T_CRC }, - { "dependency", T_DEPCRC }, - { "size", T_SIZE }, - { "flags", T_FLAGS }, - - }; - - if (scriptfile_getbraces(script,&grpend)) break; - - while (script->textptr < grpend) - { - int32_t token = getatoken(script,grpinfotokens,ARRAY_SIZE(grpinfotokens)); - - switch (token) - { - case T_GAMENAME: - scriptfile_getstring(script,&gname); break; - case T_SCRIPTNAME: - scriptfile_getstring(script,&gscript); break; - case T_DEFNAME: - scriptfile_getstring(script,&gdef); break; - case T_RTSNAME: - scriptfile_getstring(script,&grts); break; - - case T_FLAGS: - scriptfile_getsymbol(script,&gflags); gflags &= GAMEFLAGMASK; break; - case T_DEPCRC: - scriptfile_getsymbol(script,&gdepcrc); break; - case T_CRC: - scriptfile_getsymbol(script,&gcrcval); break; - case T_SIZE: - scriptfile_getnumber(script,&gsize); break; - default: - break; - } - - grpinfo_t * const fg = (grpinfo_t *)Xcalloc(1, sizeof(grpinfo_t)); - fg->next = listgrps; - listgrps = fg; - - if (gname) - fg->name = Xstrdup(gname); - - fg->size = gsize; - fg->crcval = gcrcval; - fg->dependency = gdepcrc; - fg->game = gflags; - - if (gscript) - fg->scriptname = dup_filename(gscript); - - if (gdef) - fg->defname = dup_filename(gdef); - - if (grts) - fg->rtsname = dup_filename(grts); - } - break; - } - - default: - break; - } - } - - scriptfile_close(script); - scriptfile_clearsymbols(); -} - -static void LoadGameList(void) -{ - for (size_t i = 0; i < ARRAY_SIZE(internalgrpfiles); i++) - { - grpinfo_t * const fg = (grpinfo_t *)Xcalloc(1, sizeof(grpinfo_t)); - - fg->name = Xstrdup(internalgrpfiles[i].name); - fg->crcval = internalgrpfiles[i].crcval; - fg->size = internalgrpfiles[i].size; - fg->game = internalgrpfiles[i].game; - fg->dependency = internalgrpfiles[i].dependency; - - if (internalgrpfiles[i].scriptname) - fg->scriptname = dup_filename(internalgrpfiles[i].scriptname); - - fg->postprocessing = internalgrpfiles[i].postprocessing; - - fg->next = listgrps; - listgrps = fg; - } - - CACHE1D_FIND_REC * const srch = klistpath("/", "*.grpinfo", CACHE1D_FIND_FILE); - - for (CACHE1D_FIND_REC *sidx = srch; sidx; sidx = sidx->next) - LoadList(sidx->name); - - klistfree(srch); -} - -static void FreeGameList(void) -{ - while (listgrps) - { - Bfree(listgrps->name); - Bfree(listgrps->scriptname); - Bfree(listgrps->defname); - Bfree(listgrps->rtsname); - - grpinfo_t * const fg = listgrps->next; - Bfree(listgrps); - listgrps = fg; - } -} - - -#define GRPCACHEFILE "grpfiles.cache" -static struct grpcache -{ - struct grpcache *next; - int32_t size; - int32_t mtime; - int32_t crcval; - char name[BMAX_PATH]; -} -*grpcache = NULL, *usedgrpcache = NULL; - -static int32_t LoadGroupsCache(void) -{ - struct grpcache *fg; - - int32_t fsize, fmtime, fcrcval; - char *fname; - - scriptfile *script; - - script = scriptfile_fromfile(GRPCACHEFILE); - if (!script) return -1; - - while (!scriptfile_eof(script)) - { - if (scriptfile_getstring(script, &fname)) break; // filename - if (scriptfile_getnumber(script, &fsize)) break; // filesize - if (scriptfile_getnumber(script, &fmtime)) break; // modification time - if (scriptfile_getnumber(script, &fcrcval)) break; // crc checksum - - fg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache)); - fg->next = grpcache; - grpcache = fg; - - Bstrncpy(fg->name, fname, BMAX_PATH); - fg->size = fsize; - fg->mtime = fmtime; - fg->crcval = fcrcval; - } - - scriptfile_close(script); - return 0; -} - -static void FreeGroupsCache(void) -{ - while (grpcache) - { - struct grpcache * const fg = grpcache->next; - Bfree(grpcache); - grpcache = fg; - } -} - -static void RemoveGroup(grpfile_t *igrp) -{ - for (grpfile_t *prev = NULL, *grp = foundgrps; grp; grp=grp->next) - { - if (grp == igrp) - { - if (grp == foundgrps) - foundgrps = grp->next; - else - prev->next = grp->next; - - Bfree((char *)grp->filename); - Bfree(grp); - - return; - } - - prev = grp; - } -} - -grpfile_t * FindGroup(int32_t crcval) -{ - grpfile_t *grp; - - for (grp = foundgrps; grp; grp=grp->next) - { - if (grp->type->crcval == crcval) - return grp; - } - - return NULL; -} - -static grpinfo_t const * FindGrpInfo(int32_t crcval, int32_t size) -{ - grpinfo_t *grpinfo; - - for (grpinfo = listgrps; grpinfo; grpinfo=grpinfo->next) - { - if (grpinfo->crcval == crcval && grpinfo->size == size) - return grpinfo; - } - - return NULL; -} - -static void ProcessGroups(CACHE1D_FIND_REC *srch) -{ - CACHE1D_FIND_REC *sidx; - struct grpcache *fg, *fgg; - char *fn; - struct Bstat st; - -#define BUFFER_SIZE (1024 * 1024 * 8) - uint8_t *buf = (uint8_t *)Xmalloc(BUFFER_SIZE); - - for (sidx = srch; sidx; sidx = sidx->next) - { - for (fg = grpcache; fg; fg = fg->next) - { - if (!Bstrcmp(fg->name, sidx->name)) break; - } - - if (fg) - { - if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename - if (Bstat(fn, &st)) - { - Bfree(fn); - continue; - } // failed to stat the file - Bfree(fn); - if (fg->size == (int32_t)st.st_size && fg->mtime == (int32_t)st.st_mtime) - { - grpinfo_t const * const grptype = FindGrpInfo(fg->crcval, fg->size); - if (grptype) - { - grpfile_t * const grp = (grpfile_t *)Xcalloc(1, sizeof(grpfile_t)); - grp->filename = Xstrdup(sidx->name); - grp->type = grptype; - grp->next = foundgrps; - foundgrps = grp; - } - - fgg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache)); - strcpy(fgg->name, fg->name); - fgg->size = fg->size; - fgg->mtime = fg->mtime; - fgg->crcval = fg->crcval; - fgg->next = usedgrpcache; - usedgrpcache = fgg; - continue; - } - } - - { - int32_t b, fh; - int32_t crcval = 0; - - fh = openfrompath(sidx->name, BO_RDONLY|BO_BINARY, BS_IREAD); - if (fh < 0) continue; - if (Bfstat(fh, &st)) continue; - - initprintf(" Checksumming %s...", sidx->name); - do - { - b = read(fh, buf, BUFFER_SIZE); - if (b > 0) crcval = Bcrc32((uint8_t *)buf, b, crcval); - } - while (b == BUFFER_SIZE); - close(fh); - initprintf(" Done\n"); - - grpinfo_t const * const grptype = FindGrpInfo(crcval, st.st_size); - if (grptype) - { - grpfile_t * const grp = (grpfile_t *)Xcalloc(1, sizeof(grpfile_t)); - grp->filename = Xstrdup(sidx->name); - grp->type = grptype; - grp->next = foundgrps; - foundgrps = grp; - } - - fgg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache)); - Bstrncpy(fgg->name, sidx->name, BMAX_PATH); - fgg->size = st.st_size; - fgg->mtime = st.st_mtime; - fgg->crcval = crcval; - fgg->next = usedgrpcache; - usedgrpcache = fgg; - } - } - - Bfree(buf); -} - -int32_t ScanGroups(void) -{ - struct grpcache *fg, *fgg; - - initprintf("Searching for game data...\n"); - - LoadGameList(); - LoadGroupsCache(); - - static char const *extensions[] = - { - "*.grp", - "*.ssi", - "*.dat", - }; - - for (char const *extension : extensions) - { - CACHE1D_FIND_REC *srch = klistpath("/", extension, CACHE1D_FIND_FILE); - ProcessGroups(srch); - klistfree(srch); - } - - FreeGroupsCache(); - - for (grpfile_t *grp = foundgrps; grp; grp=grp->next) - { - if (grp->type->dependency) - { - if (FindGroup(grp->type->dependency) == NULL) // couldn't find dependency - { - //initprintf("removing %s\n", grp->name); - RemoveGroup(grp); - grp = foundgrps; - // start from the beginning so we can remove anything that depended on this grp - continue; - } - } - } - - if (usedgrpcache) - { - int32_t i = 0; - FILE *fp; - fp = fopen(GRPCACHEFILE, "wt"); - if (fp) - { - for (fg = usedgrpcache; fg; fg=fgg) - { - fgg = fg->next; - fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval); - Bfree(fg); - i++; - } - fclose(fp); - } -// initprintf("Found %d recognized GRP %s.\n",i,i>1?"files":"file"); - - return 0; - } - - initprintf("Found no recognized game data!\n"); - - return 0; -} - - -void FreeGroups(void) -{ - while (foundgrps) - { - Bfree((char *)foundgrps->filename); - grpfile_t * const fg = foundgrps->next; - Bfree(foundgrps); - foundgrps = fg; - } - - FreeGameList(); -} - -static void process_vacapp15(int32_t crcval) -{ - krename(crcval, 5, "DEFS.CON"); - krename(crcval, 6, "GAME.CON"); - krename(crcval, 7, "USER.CON"); - krename(crcval, 8, "DEMO1.DMO"); - krename(crcval, 9, "DEMO2.DMO"); - krename(crcval, 10, "DEMO3.DMO"); - - initgroupfile("VACATION.PRG"); -} - -END_RR_NS diff --git a/source/rr/src/grpscan.h b/source/rr/src/grpscan.h deleted file mode 100644 index bf595dc47..000000000 --- a/source/rr/src/grpscan.h +++ /dev/null @@ -1,106 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2010 EDuke32 developers and contributors - -This file is part of EDuke32. - -EDuke32 is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#ifndef grpscan_h_ -#define grpscan_h_ - -BEGIN_RR_NS - -#define MAXLISTNAMELEN 32 - -// List of internally-known GRP files -#define DUKE13_CRC (int32_t)0xBBC9CE44 -#define DUKEKR_CRC (int32_t)0xAA4F6A40 -#define DUKE15_CRC (int32_t)0xFD3DCFF1 -#define DUKEPP_CRC (int32_t)0xF514A6AC -#define DUKEWT_CRC (int32_t)0x982AFE4A -#define DUKE099_CRC (int32_t)0x02F18900 -#define DUKE10_CRC (int32_t)0xA28AA589 -#define DUKE11_CRC (int32_t)0x912E1E8D -#define DUKESW_CRC (int32_t)0x983AD923 -#define DUKEMD_CRC (int32_t)0xC5F71561 -#define DUKEMD2_CRC (int32_t)0x73A15EE7 -#define DUKEDC13_CRC (int32_t)0xA9242158 -#define DUKEDCPP_CRC (int32_t)0xB79D997F -#define DUKEDC_CRC (int32_t)0xA8CF80DA -#define VACA13_CRC (int32_t)0x4A2DBB62 -#define VACAPP_CRC (int32_t)0x2F4FCCEE -#define VACA15_CRC (int32_t)0xB62B42FD -#define DUKECB_CRC (int32_t)0x18F01C5B -#define DUKENW_CRC (int32_t)0xF1CAE8E4 -#define DZ2_13_CRC (int32_t)0x82C1B47F -#define DZ2_PP_CRC (int32_t)0x7FB6117C -#define NAM_CRC (int32_t)0x75C1F07B -#define NAPALM_CRC (int32_t)0x3DE1589A -#define WW2GI_CRC (int32_t)0x907B82BF -#define PLATOONL_CRC (int32_t)0xD1ED8C0C -#define RR_CRC (int32_t)0x19D9BC79 -#define RRRA_CRC (int32_t)0x958018C6 - -enum addon_t { - ADDON_NONE, - ADDON_DUKEDC, - ADDON_NWINTER, - ADDON_CARIBBEAN, - NUMADDONS -}; - -typedef struct internalgrpinfo_t { - char const *name; - int32_t const crcval; - int32_t const size; - int32_t const game; - int32_t const dependency; - char const *scriptname; - void(*postprocessing)(int32_t); -} internalgrpinfo_t; - -typedef struct grpinfo_t { - char *name; - int32_t crcval; - int32_t size; - int32_t game; - int32_t dependency; - char *scriptname; - char *defname; - char *rtsname; - void (*postprocessing)(int32_t); - struct grpinfo_t *next; -} grpinfo_t; - -typedef struct grpfile_t { - char *filename; - struct grpinfo_t const *type; - struct grpfile_t *next; -} grpfile_t; - -extern grpfile_t *foundgrps; -extern grpinfo_t *listgrps; - -extern grpfile_t * FindGroup(int32_t crcval); - -int32_t ScanGroups(void); -void FreeGroups(void); - -END_RR_NS - -#endif diff --git a/source/rr/src/menus.cpp b/source/rr/src/menus.cpp index a92646658..db4e82364 100644 --- a/source/rr/src/menus.cpp +++ b/source/rr/src/menus.cpp @@ -6085,8 +6085,6 @@ static void Menu_Run(Menu_t *cm, const vec2_t origin) if (dir == object->findhigh[i] && object->currentList == i) status |= MT_Selected; - // pal = dir->source==CACHE1D_SOURCE_ZIP ? 8 : 2 - Menu_Run_AbbreviateNameIntoBuffer(dir->name, USERMAPENTRYLENGTH); const int32_t thisx = object->format[i]->pos.x; diff --git a/source/rr/src/osdcmds.cpp b/source/rr/src/osdcmds.cpp index 5ff57e834..3780464b6 100644 --- a/source/rr/src/osdcmds.cpp +++ b/source/rr/src/osdcmds.cpp @@ -575,16 +575,6 @@ static int osdcmd_spawn(osdcmdptr_t parm) return OSDCMD_OK; } -static int osdcmd_initgroupfile(osdcmdptr_t parm) -{ - if (parm->numparms != 1) - return OSDCMD_SHOWHELP; - - initgroupfile(parm->parms[0]); - - return OSDCMD_OK; -} - static int osdcmd_cmenu(osdcmdptr_t parm) { if (parm->numparms != 1) @@ -996,7 +986,6 @@ int32_t registerosdcommands(void) OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god); OSD_RegisterFunction("activatecheat","activatecheat : activates a cheat code", osdcmd_activatecheat); - OSD_RegisterFunction("initgroupfile","initgroupfile : adds a grp file into the game filesystem", osdcmd_initgroupfile); #ifdef DEBUGGINGAIDS OSD_RegisterFunction("inittimer","debug", osdcmd_inittimer); #endif diff --git a/source/rr/src/savegame.cpp b/source/rr/src/savegame.cpp index 4cdab7a00..1d4495a0f 100644 --- a/source/rr/src/savegame.cpp +++ b/source/rr/src/savegame.cpp @@ -725,7 +725,7 @@ static int32_t readspecdata(const dataspec_t *spec, FileReader *fil, uint8_t **d OSD_Printf("rsd: spec=%s, idx=%d:\n", (char *)sptr->ptr, (int32_t)(spec-sptr)); if (ksiz!=siz) - OSD_Printf(" kread returned %d, expected %d.\n", ksiz, siz); + OSD_Printf(" file read returned %d, expected %d.\n", ksiz, siz); else OSD_Printf(" sp->ptr and cmpstrbuf not identical!\n"); diff --git a/source/rr/src/sounds.cpp b/source/rr/src/sounds.cpp index 001d83bdc..de7625bed 100644 --- a/source/rr/src/sounds.cpp +++ b/source/rr/src/sounds.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "duke3d.h" #include "renderlayer.h" // for win_gethwnd() +#include "openaudio.h" #include BEGIN_RR_NS @@ -432,7 +433,7 @@ int32_t S_LoadSound(int num) auto &snd = g_sounds[num]; - auto fp = S_OpenAudio(snd.filename, g_loadFromGroupOnly, 0); + auto fp = S_OpenAudio(snd.filename, 0, 0); if (!fp.isOpen()) { diff --git a/source/sw/CMakeLists.txt b/source/sw/CMakeLists.txt index 08c5a66c6..45f51b7f5 100644 --- a/source/sw/CMakeLists.txt +++ b/source/sw/CMakeLists.txt @@ -51,7 +51,6 @@ set( PCH_SOURCES src/game.cpp src/girlninj.cpp src/goro.cpp - src/grpscan.cpp src/hornet.cpp src/interp.cpp src/interpsh.cpp diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 52098e8fe..be947262a 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -677,7 +677,6 @@ TerminateGame(void) if (CleanExit) DosScreen(); - uninitgroupfile(); } void @@ -779,7 +778,6 @@ void MultiSharewareCheck(void) engineUnInit(); UnInitSound(); timerUninit(); - uninitgroupfile(); Bexit(0); } } @@ -1859,8 +1857,8 @@ TenScreen(void) if ((fin = k open4load("ten.pal", 0)) != -1) { - kread(fin, pal, PAL_SIZE); - kclose(fin); + k read(fin, pal, PAL_SIZE); + k close(fin); } // palette to black @@ -1912,24 +1910,10 @@ TitleLevel(void) tempbuf[i] = i; palookup[0] = tempbuf; - //GetPaletteFromVESA(pal); - //memcpy(backup_pal, pal, PAL_SIZE); - videoClearViewableArea(0L); videoNextPage(); -// if ((fin = k open4load("title.pal", 0)) != -1) -// { -// kread(fin, pal, PAL_SIZE); -// kclose(fin); -// SetPaletteToVESA(pal); -// } - -// clearview(0); -// nextpage(); - - //FadeOut(0, 0); - ready2send = 0; + ready2send = 0; totalclock = 0; ototalclock = 0; @@ -3101,28 +3085,6 @@ void swexit(int exitval) void DosScreen(void) { -#if 0 -#ifdef SW_SHAREWARE -#define DOS_SCREEN_NAME "SHADSW.BIN" -#else -#define DOS_SCREEN_NAME "SWREG.BIN" -#endif - -#define DOS_SCREEN_SIZE (4000-(80*2)) -#define DOS_SCREEN_PTR ((void *)(0xB8000)) - int i; - char buffer[DOS_SCREEN_SIZE]; - - fin = k open4load(DOS_SCREEN_NAME,0); - if (fin == -1) - return; - - kread(fin, buffer, sizeof(buffer)); - memcpy(DOS_SCREEN_PTR, buffer, DOS_SCREEN_SIZE); - kclose(fin); - move_cursor(23,0); - _displaycursor(_GCURSORON); -#endif } #if 0 //PLOCK_VERSION diff --git a/source/sw/src/grpscan.cpp b/source/sw/src/grpscan.cpp deleted file mode 100644 index 9d3bcb863..000000000 --- a/source/sw/src/grpscan.cpp +++ /dev/null @@ -1,217 +0,0 @@ -//------------------------------------------------------------------------- -/* - Copyright (C) 2007 Jonathon Fowler - - This file is part of JFShadowWarrior - - Shadow Warrior is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -//------------------------------------------------------------------------- - -#include "ns.h" - -#include "build.h" -#include "baselayer.h" - -#include "scriptfile.h" -#include "cache1d.h" -#include "crc32_.h" - -#include "grpscan.h" - -BEGIN_SW_NS - -internalgrpfile grpfiles[numgrpfiles] = -{ - { "Registered Version", 0x7545319Fu, 47536148 }, - { "Shareware Version", 0x08A7FA1Fu, 26056769 }, - { "Wanton Destruction (Addon)", 0xA9AAA7B7u, 48698128 }, -}; -grpfile *foundgrps = NULL; - -#define GRPCACHEFILE "grpfiles.cache" -static struct grpcache -{ - struct grpcache *next; - char name[BMAX_PATH+1]; - int size; - int mtime; - unsigned int crcval; -} *grpcache = NULL, *usedgrpcache = NULL; - -static int LoadGroupsCache(void) -{ - struct grpcache *fg; - - int fsize, fmtime, fcrcval; - char *fname; - - scriptfile *script; - - script = scriptfile_fromfile(GRPCACHEFILE); - if (!script) return -1; - - while (!scriptfile_eof(script)) - { - if (scriptfile_getstring(script, &fname)) break; // filename - if (scriptfile_getnumber(script, &fsize)) break; // filesize - if (scriptfile_getnumber(script, &fmtime)) break; // modification time - if (scriptfile_getnumber(script, &fcrcval)) break; // crc checksum - - fg = (struct grpcache*)calloc(1, sizeof(struct grpcache)); - fg->next = grpcache; - grpcache = fg; - - strncpy(fg->name, fname, BMAX_PATH); - fg->size = fsize; - fg->mtime = fmtime; - fg->crcval = fcrcval; - } - - scriptfile_close(script); - return 0; -} - -static void FreeGroupsCache(void) -{ - struct grpcache *fg; - - while (grpcache) - { - fg = grpcache->next; - free(grpcache); - grpcache = fg; - } -} - -int ScanGroups(void) -{ - CACHE1D_FIND_REC *srch, *sidx; - struct grpcache *fg, *fgg; - struct grpfile *grp; - char *fn; - struct Bstat st; - - buildputs("Scanning for GRP files...\n"); - - LoadGroupsCache(); - - srch = klistpath("/", "*.grp", CACHE1D_FIND_FILE); - - for (sidx = srch; sidx; sidx = sidx->next) - { - for (fg = grpcache; fg; fg = fg->next) - { - if (!Bstrcmp(fg->name, sidx->name)) break; - } - - if (fg) - { - if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename - if (Bstat(fn, &st)) { free(fn); continue; } // failed to stat the file - free(fn); - if (fg->size == st.st_size && fg->mtime == st.st_mtime) - { - grp = (struct grpfile *)calloc(1, sizeof(struct grpfile)); - grp->name = strdup(sidx->name); - grp->crcval = fg->crcval; - grp->size = fg->size; - grp->next = foundgrps; - foundgrps = grp; - - fgg = (struct grpcache *)calloc(1, sizeof(struct grpcache)); - strcpy(fgg->name, fg->name); - fgg->size = fg->size; - fgg->mtime = fg->mtime; - fgg->crcval = fg->crcval; - fgg->next = usedgrpcache; - usedgrpcache = fgg; - continue; - } - } - - { - int b, fh; - unsigned int crcval = 0; - unsigned char buf[16*512]; - - fh = openfrompath(sidx->name, BO_RDONLY|BO_BINARY, BS_IREAD); - if (fh < 0) continue; - if (fstat(fh, &st)) continue; - - buildprintf(" Checksumming %s...", sidx->name); - do - { - b = read(fh, buf, sizeof(buf)); - if (b > 0) crcval = Bcrc32(buf, b, crcval); - } - while (b == sizeof(buf)); - close(fh); - buildputs(" Done\n"); - - grp = (struct grpfile *)calloc(1, sizeof(struct grpfile)); - grp->name = strdup(sidx->name); - grp->crcval = crcval; - grp->size = st.st_size; - grp->next = foundgrps; - foundgrps = grp; - - fgg = (struct grpcache *)calloc(1, sizeof(struct grpcache)); - strncpy(fgg->name, sidx->name, BMAX_PATH); - fgg->size = st.st_size; - fgg->mtime = st.st_mtime; - fgg->crcval = crcval; - fgg->next = usedgrpcache; - usedgrpcache = fgg; - } - } - - klistfree(srch); - FreeGroupsCache(); - - if (usedgrpcache) - { - FILE *fp; - fp = fopen(GRPCACHEFILE, "wt"); - if (fp) - { - for (fg = usedgrpcache; fg; fg=fgg) - { - fgg = fg->next; - fprintf(fp, "\"%s\" %d %d %d\n", fg->name, fg->size, fg->mtime, fg->crcval); - free(fg); - } - fclose(fp); - } - } - - return 0; -} - -void FreeGroups(void) -{ - struct grpfile *fg; - - while (foundgrps) - { - fg = foundgrps->next; - free(foundgrps->name); - free(foundgrps); - foundgrps = fg; - } -} - -END_SW_NS diff --git a/source/sw/src/grpscan.h b/source/sw/src/grpscan.h deleted file mode 100644 index 0ceb938df..000000000 --- a/source/sw/src/grpscan.h +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------- -/* - Copyright (C) 2007 Jonathon Fowler - - This file is part of JFShadowWarrior - - Shadow Warrior is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -//------------------------------------------------------------------------- - -#ifndef grpscan_h__ -#define grpscan_h__ - -BEGIN_SW_NS - -// List of internally-known GRP files -#define numgrpfiles 3 -struct internalgrpfile -{ - const char *name; - unsigned int crcval; - int size; -}; -struct grpfile -{ - char *name; - unsigned int crcval; - int size; - struct grpfile *next; -}; - -extern internalgrpfile grpfiles[numgrpfiles]; -extern grpfile *foundgrps; - -int ScanGroups(void); -void FreeGroups(void); - -END_SW_NS - -#endif diff --git a/wadsrc/static/demolition/demolition.grpinfo b/wadsrc/static/demolition/demolition.grpinfo index 0d0946b07..14ee916b7 100644 --- a/wadsrc/static/demolition/demolition.grpinfo +++ b/wadsrc/static/demolition/demolition.grpinfo @@ -268,8 +268,6 @@ grpinfo name "NAM" size 43448927 crc NAM_CRC - defname "nam.def" //, "napalm.def" - //scriptname "nam.con", "napalm.con" flags GAMEFLAG_NAM dependency 0 gamefilter "Nam.Nam" @@ -280,8 +278,6 @@ grpinfo name "NAPALM" size 44365728 crc NAPALM_CRC - defname "napalm.def" //, "nam.def" - //scriptname "napalm.con", "nam.con" flags GAMEFLAG_NAM|GAMEFLAG_NAPALM dependency 0 gamefilter "Nam.Napalm" @@ -292,8 +288,6 @@ grpinfo name "WWII GI" size 77939508 crc WW2GI_CRC - defname "ww2gi.def" - //scriptname "ww2gi.con" flags GAMEFLAG_WW2GI dependency 0 gamefilter "WW2GI.WW2GI" @@ -335,13 +329,12 @@ grpinfo grpinfo { name "Redneck Rampage: Suckin' Grits on Route 66" - crc 0x30C49F26 // tests carnival.map - size 234898 - loaddirectory "CARNIVAL.MAP" + loaddirectory scriptname "GAME66.CON" + mustcontain "TILESA66.ART", "TILESB66.ART", "CARNIVAL.MAP", "TRUCKSTP.MAP", "GAME66.CON" flags GAMEFLAG_RR|GAMEFLAG_ADDON dependency RR_CRC - loadart "TILESA66.ART", "TILESB66.ART" + loadart "TILESA66.ART", "TILESB66.ART" // replaces TILES009 and TILES023. gamefilter "Redneck.Route66" } @@ -361,13 +354,12 @@ grpinfo grpinfo { name "BLOOD: Cryptic Passage" - crc 0x2144DF1C // tests CP01.MAP - size 327015 - loaddirectory "CP01.MAP" + loaddirectory scriptname "CRYPTIC.INI" + mustcontain "CRYPTIC.INI", "CP01.MAP", "CP02.MAP" flags GAMEFLAG_BLOOD|GAMEFLAG_ADDON dependency BLOOD_CRC - loadart "CPART07.AR_", "CPART15.AR_" + loadart "CPART07.AR_", "CPART15.AR_" // some versions have these file names, some have the real ones instead so these must be listed but cannot be used for checking. gamefilter "Blood.Cryptic" }