From 3ac910c32d0ab1f9757571a380959d12171dbbe5 Mon Sep 17 00:00:00 2001 From: Shpoike Date: Sat, 10 Jul 2021 20:13:56 +0100 Subject: [PATCH] Try to make use of win32/posix LFS for larger pk3s. Use a couple of other unsigned types for larger bsps too, now that we're supposedly able to exceed the 2gb limit on file sizes. --- Quake/Makefile | 2 ++ Quake/bspfile.h | 2 +- Quake/common.c | 8 ++++---- Quake/common.h | 21 +++++++++++++++++---- Quake/crc.c | 2 +- Quake/crc.h | 6 +++--- Quake/fs_zip.c | 5 +---- Quake/gl_model.c | 2 +- Quake/mdfour.c | 14 +++++++------- Quake/pr_edict.c | 2 +- Quake/sv_main.c | 2 +- Quake/sys.h | 4 ++-- Quake/sys_sdl_unix.c | 9 +++++---- Quake/sys_sdl_win.c | 9 +++++---- Quake/wad.c | 6 +++--- Quake/wad.h | 30 +++++++++++++++--------------- 16 files changed, 69 insertions(+), 55 deletions(-) diff --git a/Quake/Makefile b/Quake/Makefile index 4736a01a..9304ed61 100644 --- a/Quake/Makefile +++ b/Quake/Makefile @@ -103,6 +103,8 @@ endif ifeq ($(USE_SDL2),1) CFLAGS += -DUSE_SDL2 endif +#make use of LFS on 32bit even on systems. +CFLAGS += -D_FILE_OFFSET_BITS=64 ifeq ($(USE_SDL2),1) SDL_CONFIG ?= sdl2-config diff --git a/Quake/bspfile.h b/Quake/bspfile.h index 5d708067..c9fb136d 100644 --- a/Quake/bspfile.h +++ b/Quake/bspfile.h @@ -70,7 +70,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. typedef struct { - int fileofs, filelen; + unsigned int fileofs, filelen; } lump_t; #define LUMP_ENTITIES 0 diff --git a/Quake/common.c b/Quake/common.c index 3f47ffc5..f70f3a44 100644 --- a/Quake/common.c +++ b/Quake/common.c @@ -1896,7 +1896,7 @@ QUAKE FILESYSTEM ============================================================================= */ -int com_filesize; +qofs_t com_filesize; // @@ -1905,14 +1905,14 @@ int com_filesize; typedef struct { char name[56]; - int filepos, filelen; + unsigned int filepos, filelen; } dpackfile_t; typedef struct { char id[4]; - int dirofs; - int dirlen; + unsigned int dirofs; + unsigned int dirlen; } dpackheader_t; #define MAX_FILES_IN_PACK 4096 diff --git a/Quake/common.h b/Quake/common.h index 6385d66d..1e900e7a 100644 --- a/Quake/common.h +++ b/Quake/common.h @@ -222,11 +222,24 @@ char *va (const char *format, ...) FUNC_PRINTF(1,2); //============================================================================ // QUAKEFS +#ifdef _WIN32 + #define qofs_t __int64 //LLP64 sucks and needs clumsy workarounds. + #define fseek _fseeki64 + #define ftell _ftelli64 +#elif _POSIX_C_SOURCE >= 200112L + #define qofs_t off_t //posix has its own LFS support for 32bit systems. + #define fseek fseeko + #define ftell ftello +#else + #define qofs_t long //LP64 just makes more sense. everything just works. +#endif +#define qofs_Make(low,high) ((unsigned int)(low) | ((qofs_t)(high)<<32)) + typedef struct { char name[MAX_QPATH]; - int filepos, filelen; - int deflatedsize; + qofs_t filepos, filelen; + qofs_t deflatedsize; } packfile_t; typedef struct pack_s @@ -252,7 +265,7 @@ typedef struct searchpath_s extern searchpath_t *com_searchpaths; extern searchpath_t *com_base_searchpaths; -extern int com_filesize; +extern qofs_t com_filesize; struct cache_user_s; extern char com_basedir[MAX_OSPATH]; @@ -264,7 +277,7 @@ const char *COM_GetGameNames(qboolean full); qboolean COM_GameDirMatches(const char *tdirs); pack_t *FSZIP_LoadArchive (const char *packfile); -FILE *FSZIP_Deflate(FILE *src, int srcsize, int outsize); +FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize); void COM_WriteFile (const char *filename, const void *data, int len); int COM_OpenFile (const char *filename, int *handle, unsigned int *path_id); diff --git a/Quake/crc.c b/Quake/crc.c index 37696d5c..7d6b7067 100644 --- a/Quake/crc.c +++ b/Quake/crc.c @@ -82,7 +82,7 @@ unsigned short CRC_Value(unsigned short crcvalue) } //johnfitz -- texture crc -unsigned short CRC_Block (const byte *start, int count) +unsigned short CRC_Block (const byte *start, size_t count) { unsigned short crc; diff --git a/Quake/crc.h b/Quake/crc.h index 069bf073..98905ed9 100644 --- a/Quake/crc.h +++ b/Quake/crc.h @@ -27,11 +27,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void CRC_Init(unsigned short *crcvalue); void CRC_ProcessByte(unsigned short *crcvalue, byte data); unsigned short CRC_Value(unsigned short crcvalue); -unsigned short CRC_Block (const byte *start, int count); //johnfitz -- texture crc +unsigned short CRC_Block (const byte *start, size_t count); //johnfitz -- texture crc //additional hash functions... -unsigned Com_BlockChecksum (void *buffer, int length); -void Com_BlockFullChecksum (void *buffer, int len, unsigned char *outbuf); +unsigned Com_BlockChecksum (void *buffer, size_t length); +void Com_BlockFullChecksum (void *buffer, size_t len, unsigned char *outbuf); #endif /* _QUAKE_CRC_H */ diff --git a/Quake/fs_zip.c b/Quake/fs_zip.c index c493a3a0..36e7ae7e 100644 --- a/Quake/fs_zip.c +++ b/Quake/fs_zip.c @@ -24,9 +24,6 @@ //infozip utf-8 name override. //other 'extra' fields. -#define qofs_t long long -#define qofs_Make(low,high) ((unsigned int)(low) | ((qofs_t)(high)<<32)) - struct zipinfo { unsigned int thisdisk; //this disk number @@ -747,7 +744,7 @@ pack_t *FSZIP_LoadArchive (const char *packfile) return pack; } -FILE *FSZIP_Deflate(FILE *src, int srcsize, int outsize) +FILE *FSZIP_Deflate(FILE *src, qofs_t srcsize, qofs_t outsize) { #ifdef USE_ZLIB byte inbuffer[65536]; diff --git a/Quake/gl_model.c b/Quake/gl_model.c index 97319302..ba70a221 100644 --- a/Quake/gl_model.c +++ b/Quake/gl_model.c @@ -974,7 +974,7 @@ void Mod_LoadLighting (lump_t *l) return; } Hunk_FreeToLowMark(mark); - Con_Printf("Outdated .lit file (%s should be %u bytes, not %u)\n", litfilename, 8+l->filelen*3, com_filesize); + Con_Printf("Outdated .lit file (%s should be %u bytes, not %u)\n", litfilename, 8+l->filelen*3, (unsigned)com_filesize); } else { diff --git a/Quake/mdfour.c b/Quake/mdfour.c index cc7e54f9..685d5883 100644 --- a/Quake/mdfour.c +++ b/Quake/mdfour.c @@ -53,9 +53,9 @@ struct mdfour { }; static void mdfour_begin(struct mdfour *md); // old: MD4Init -static void mdfour_update(struct mdfour *md, unsigned char *in, int n); //old: MD4Update +static void mdfour_update(struct mdfour *md, unsigned char *in, size_t n); //old: MD4Update static void mdfour_result(struct mdfour *md, unsigned char *out); // old: MD4Final -static void mdfour(unsigned char *out, unsigned char *in, int n); +static void mdfour(unsigned char *out, unsigned char *in, size_t n); #endif // _MDFOUR_H @@ -160,7 +160,7 @@ static void mdfour_begin(struct mdfour *md) } -static void mdfour_tail(struct mdfour *m, unsigned char *in, int n) +static void mdfour_tail(struct mdfour *m, unsigned char *in, size_t n) { unsigned char buf[128]; uint32 M[16]; @@ -190,7 +190,7 @@ static void mdfour_tail(struct mdfour *m, unsigned char *in, int n) } } -static void mdfour_update(struct mdfour *m, unsigned char *in, int n) +static void mdfour_update(struct mdfour *m, unsigned char *in, size_t n) { uint32 M[16]; @@ -218,7 +218,7 @@ static void mdfour_result(struct mdfour *m, unsigned char *out) } -static void mdfour(unsigned char *out, unsigned char *in, int n) +static void mdfour(unsigned char *out, unsigned char *in, size_t n) { struct mdfour md; mdfour_begin(&md); @@ -234,7 +234,7 @@ static void mdfour(unsigned char *out, unsigned char *in, int n) // Author: Jeff Teunissen // Date: 01 Jan 2000 -unsigned Com_BlockChecksum (void *buffer, int length) +unsigned Com_BlockChecksum (void *buffer, size_t length) { int digest[4]; unsigned val; @@ -246,7 +246,7 @@ unsigned Com_BlockChecksum (void *buffer, int length) return val; } -void Com_BlockFullChecksum (void *buffer, int len, unsigned char *outbuf) +void Com_BlockFullChecksum (void *buffer, size_t len, unsigned char *outbuf) { mdfour ( outbuf, (unsigned char *) buffer, len ); } diff --git a/Quake/pr_edict.c b/Quake/pr_edict.c index df9682d1..d6d5c936 100644 --- a/Quake/pr_edict.c +++ b/Quake/pr_edict.c @@ -1300,7 +1300,7 @@ qboolean PR_LoadProgs (const char *filename, qboolean fatal, unsigned int needcr return false; } } - Con_DPrintf ("%s occupies %iK.\n", filename, com_filesize/1024); + Con_DPrintf ("%s occupies %uK.\n", filename, (unsigned)(com_filesize/1024u)); qcvm->functions = (dfunction_t *)((byte *)qcvm->progs + qcvm->progs->ofs_functions); qcvm->strings = (char *)qcvm->progs + qcvm->progs->ofs_strings; diff --git a/Quake/sv_main.c b/Quake/sv_main.c index cc68c3e8..07bed773 100644 --- a/Quake/sv_main.c +++ b/Quake/sv_main.c @@ -3478,7 +3478,7 @@ void SV_SpawnServer (const char *server) if (csprogs) { Info_SetKey(svs.serverinfo, sizeof(svs.serverinfo), "*csprogs", va("%#x", Com_BlockChecksum(csprogs, com_filesize))); - Info_SetKey(svs.serverinfo, sizeof(svs.serverinfo), "*csprogssize", va("%#x", com_filesize)); + Info_SetKey(svs.serverinfo, sizeof(svs.serverinfo), "*csprogssize", va("%#x", (unsigned)com_filesize)); free(csprogs); } else diff --git a/Quake/sys.h b/Quake/sys.h index fa4f6d56..89ef26d7 100644 --- a/Quake/sys.h +++ b/Quake/sys.h @@ -32,12 +32,12 @@ void Sys_Init (void); // returns the file size or -1 if file is not present. // the file should be in BINARY mode for stupid OSs that care -int Sys_FileOpenRead (const char *path, int *hndl); +qofs_t Sys_FileOpenRead (const char *path, int *hndl); int Sys_FileOpenWrite (const char *path); int Sys_FileOpenStdio (FILE *file); void Sys_FileClose (int handle); -void Sys_FileSeek (int handle, int position); +void Sys_FileSeek (int handle, qofs_t position); int Sys_FileRead (int handle, void *dest, int count); int Sys_FileWrite (int handle,const void *data, int count); int Sys_FileTime (const char *path); diff --git a/Quake/sys_sdl_unix.c b/Quake/sys_sdl_unix.c index d252b7e3..5a84bbd0 100644 --- a/Quake/sys_sdl_unix.c +++ b/Quake/sys_sdl_unix.c @@ -72,7 +72,7 @@ static int findhandle (void) return i; } -long Sys_filelength (FILE *f) +qofs_t Sys_filelength (FILE *f) { long pos, end; @@ -84,10 +84,11 @@ long Sys_filelength (FILE *f) return end; } -int Sys_FileOpenRead (const char *path, int *hndl) +qofs_t Sys_FileOpenRead (const char *path, int *hndl) { FILE *f; - int i, retval; + int i; + qofs_t retval; i = findhandle (); f = fopen(path, "rb"); @@ -136,7 +137,7 @@ void Sys_FileClose (int handle) sys_handles[handle] = NULL; } -void Sys_FileSeek (int handle, int position) +void Sys_FileSeek (int handle, qofs_t position) { fseek (sys_handles[handle], position, SEEK_SET); } diff --git a/Quake/sys_sdl_win.c b/Quake/sys_sdl_win.c index 825b5536..328fb110 100644 --- a/Quake/sys_sdl_win.c +++ b/Quake/sys_sdl_win.c @@ -71,7 +71,7 @@ static int findhandle (void) return i; } -long Sys_filelength (FILE *f) +qofs_t Sys_filelength (FILE *f) { long pos, end; @@ -83,10 +83,11 @@ long Sys_filelength (FILE *f) return end; } -int Sys_FileOpenRead (const char *path, int *hndl) +qofs_t Sys_FileOpenRead (const char *path, int *hndl) { FILE *f; - int i, retval; + int i; + qofs_t retval; i = findhandle (); f = fopen(path, "rb"); @@ -135,7 +136,7 @@ void Sys_FileClose (int handle) sys_handles[handle] = NULL; } -void Sys_FileSeek (int handle, int position) +void Sys_FileSeek (int handle, qofs_t position) { fseek (sys_handles[handle], position, SEEK_SET); } diff --git a/Quake/wad.c b/Quake/wad.c index aceecda4..6b58bdcb 100644 --- a/Quake/wad.c +++ b/Quake/wad.c @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" -int wad_numlumps; +unsigned int wad_numlumps; lumpinfo_t *wad_lumps; byte *wad_base = NULL; @@ -116,13 +116,13 @@ void W_LoadWadFile (void) //johnfitz -- filename is now hard-coded for honesty { if (lump_p->filepos > com_filesize || lump_p->size < 0) { - Con_Printf ("Wad file %s lump \"%.16s\" begins %u bytes beyond end of wad\n",filename, lump_p->name, lump_p->filepos - com_filesize); + Con_Printf ("Wad file %s lump \"%.16s\" begins %u bytes beyond end of wad\n",filename, lump_p->name, (unsigned)(lump_p->filepos - com_filesize)); lump_p->filepos = 0; lump_p->size = q_max(0, lump_p->size-lump_p->filepos); } else { - Con_Printf ("Wad file %s lump \"%.16s\" extends %u bytes beyond end of wad (lump size: %u)\n",filename, lump_p->name, (lump_p->filepos + lump_p->size) - com_filesize, lump_p->size); + Con_Printf ("Wad file %s lump \"%.16s\" extends %u bytes beyond end of wad (lump size: %u)\n",filename, lump_p->name, (unsigned)((lump_p->filepos + lump_p->size) - com_filesize), lump_p->size); lump_p->size = q_max(0, lump_p->size-lump_p->filepos); } } diff --git a/Quake/wad.h b/Quake/wad.h index 6755236e..6d168759 100644 --- a/Quake/wad.h +++ b/Quake/wad.h @@ -44,31 +44,31 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. typedef struct { - int width, height; - byte data[4]; // variably sized + unsigned int width, height; + byte data[4]; // variably sized } qpic_t; typedef struct { - char identification[4]; // should be WAD2 or 2DAW - int numlumps; - int infotableofs; + char identification[4]; // should be WAD2 or 2DAW + unsigned int numlumps; + unsigned int infotableofs; } wadinfo_t; typedef struct { - int filepos; - int disksize; - int size; // uncompressed - char type; - char compression; - char pad1, pad2; - char name[16]; // must be null terminated + unsigned int filepos; + unsigned int disksize; + unsigned int size; // uncompressed + char type; + char compression; + char pad1, pad2; + char name[16]; // must be null terminated } lumpinfo_t; -extern int wad_numlumps; -extern lumpinfo_t *wad_lumps; -extern byte *wad_base; +extern unsigned int wad_numlumps; +extern lumpinfo_t *wad_lumps; +extern byte *wad_base; void W_LoadWadFile (void); //johnfitz -- filename is now hard-coded for honesty void *W_GetLumpName (const char *name, lumpinfo_t **out_info);