#if WORKINGLQUAKE
pointfile = COM_LoadTempFile (name);
#else
- pointfile = (char *)FS_LoadFile(name, tempmempool, true);
+ pointfile = (char *)FS_LoadFile(name, tempmempool, true, NULL);
#endif
if (!pointfile)
{
return;
}
- f = (char *)FS_LoadFile (Cmd_Argv(1), tempmempool, false);
+ f = (char *)FS_LoadFile (Cmd_Argv(1), tempmempool, false, NULL);
if (!f)
{
Con_Printf("couldn't exec %s\n",Cmd_Argv(1));
mempool_t *fs_mempool;
-fs_offset_t fs_filesize;
-
pack_t *packlist = NULL;
searchpath_t *fs_searchpaths = NULL;
*/
qboolean PK3_GetEndOfCentralDir (const char *packfile, int packhandle, pk3_endOfCentralDir_t *eocd)
{
- long filesize, maxsize;
+ fs_offset_t filesize, maxsize;
unsigned char *buffer, *ptr;
int ind;
pfile = &pack->files[pack_ind];
- fs_filesize = 0;
-
// If we don't have the true offset, get it now
if (! (pfile->flags & PACKFILE_FLAG_TRUEOFFS))
if (!PK3_GetTrueFileOffset (pfile, pack))
file->ztk = ztk;
}
- fs_filesize = pfile->realsize;
-
return file;
}
FS_OpenReadFile
Look for a file in the search paths and open it in read-only mode
-
-Sets fs_filesize
===========
*/
qfile_t *FS_OpenReadFile (const char *filename, qboolean quiet, qboolean nonblocking)
// Not found?
if (search == NULL)
- {
- fs_filesize = 0;
return NULL;
- }
// Found in the filesystem?
if (pack_ind < 0)
*/
qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet, qboolean nonblocking)
{
- qfile_t* file;
-
if (FS_CheckNastyPath(filepath))
{
Con_Printf("FS_Open(\"%s\", \"%s\", %s): nasty filename rejected\n", filepath, mode, quiet ? "true" : "false");
return FS_SysOpen (real_path, mode, nonblocking);
}
-
// Else, we look at the various search paths and open the file in read-only mode
- file = FS_OpenReadFile (filepath, quiet, nonblocking);
- if (file != NULL)
- fs_filesize = file->real_length;
-
- return file;
+ else
+ return FS_OpenReadFile (filepath, quiet, nonblocking);
}
Always appends a 0 byte.
============
*/
-unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet)
+unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet, fs_offset_t *filesizepointer)
{
qfile_t *file;
- unsigned char *buf;
+ unsigned char *buf = NULL;
+ fs_offset_t filesize = 0;
file = FS_Open (path, "rb", quiet, false);
- if (!file)
- return NULL;
-
- buf = (unsigned char *)Mem_Alloc (pool, fs_filesize + 1);
- buf[fs_filesize] = '\0';
-
- FS_Read (file, buf, fs_filesize);
- FS_Close (file);
+ if (file)
+ {
+ filesize = file->real_length;
+ buf = (unsigned char *)Mem_Alloc (pool, filesize + 1);
+ buf[filesize] = '\0';
+ FS_Read (file, buf, filesize);
+ FS_Close (file);
+ }
+ if (filesizepointer)
+ *filesizepointer = filesize;
return buf;
}
extern char fs_gamedir [MAX_OSPATH];
extern char fs_basedir [MAX_OSPATH];
-extern fs_offset_t fs_filesize; // set by FS_Open (in "read" mode) and FS_LoadFile
// ------ Main functions ------ //
fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet);
void FS_FreeSearch(fssearch_t *search);
-unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet);
+unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet, fs_offset_t *filesizepointer);
qboolean FS_WriteFile (const char *filename, void *data, fs_offset_t len);
unsigned char buffer[65536][4], *data = NULL;
double random;
- fs_filesize = FONT_FILESIZE;
- data = LoadTGA (concharimage, 256, 256);
- fs_filesize = -1;
+ data = LoadTGA (concharimage, FONT_FILESIZE, 256, 256);
// Gold numbers
for (i = 0;i < 8192;i++)
{
if (l >= 0 && !strcmp(entname + l, ".bsp"))
{
strcpy(entname + l, ".ent");
- if ((entities = (char *)FS_LoadFile(entname, tempmempool, true)))
+ if ((entities = (char *)FS_LoadFile(entname, tempmempool, true, NULL)))
{
CL_ParseEntityLump(entities);
Mem_Free(entities);
cls.demonum = -1; // stop demo loop in case this fails
- t = text = (char *)FS_LoadFile (filename, tempmempool, false);
+ t = text = (char *)FS_LoadFile (filename, tempmempool, false, NULL);
if (!text)
{
Con_Print("ERROR: couldn't open.\n");
LoadPCX
============
*/
-unsigned char* LoadPCX (const unsigned char *f, int matchwidth, int matchheight)
+unsigned char* LoadPCX (const unsigned char *f, int filesize, int matchwidth, int matchheight)
{
pcx_t pcx;
unsigned char *a, *b, *image_rgba, *pbuf;
const unsigned char *palette, *fin, *enddata;
int x, y, x2, dataByte;
- if (fs_filesize < (int)sizeof(pcx) + 768)
+ if (filesize < (int)sizeof(pcx) + 768)
{
Con_Print("Bad pcx file\n");
return NULL;
if ((matchwidth && image_width != matchwidth) || (matchheight && image_height != matchheight))
return NULL;
- palette = f + fs_filesize - 768;
+ palette = f + filesize - 768;
image_rgba = (unsigned char *)Mem_Alloc(tempmempool, image_width*image_height*4);
if (!image_rgba)
LoadTGA
=============
*/
-unsigned char *LoadTGA (const unsigned char *f, int matchwidth, int matchheight)
+unsigned char *LoadTGA (const unsigned char *f, int filesize, int matchwidth, int matchheight)
{
int x, y, row_inc, compressed, readpixelcount, red, green, blue, alpha, runlen, pindex, alphabits;
unsigned char *pixbuf, *image_rgba;
TargaHeader targa_header;
unsigned char palette[256*4];
- if (fs_filesize < 19)
+ if (filesize < 19)
return NULL;
- enddata = f + fs_filesize;
+ enddata = f + filesize;
targa_header.id_length = f[0];
targa_header.colormap_type = f[1];
LoadLMP
============
*/
-unsigned char *LoadLMP (const unsigned char *f, int matchwidth, int matchheight, qboolean loadAs8Bit)
+unsigned char *LoadLMP (const unsigned char *f, int filesize, int matchwidth, int matchheight, qboolean loadAs8Bit)
{
unsigned char *image_buffer;
- if (fs_filesize < 9)
+ if (filesize < 9)
{
Con_Print("LoadLMP: invalid LMP file\n");
return NULL;
if ((matchwidth && image_width != matchwidth) || (matchheight && image_height != matchheight))
return NULL;
- if (fs_filesize < (fs_offset_t)(8 + image_width * image_height))
+ if (filesize < (8 + image_width * image_height))
{
Con_Print("LoadLMP: invalid LMP file\n");
return NULL;
return image_buffer;
}
-static unsigned char *LoadLMPRGBA (const unsigned char *f, int matchwidth, int matchheight)
+static unsigned char *LoadLMPRGBA (const unsigned char *f, int filesize, int matchwidth, int matchheight)
{
- return LoadLMP(f, matchwidth, matchheight, false);
+ return LoadLMP(f, filesize, matchwidth, matchheight, false);
}
int value;
} q2wal_t;
-unsigned char *LoadWAL (const unsigned char *f, int matchwidth, int matchheight)
+unsigned char *LoadWAL (const unsigned char *f, int filesize, int matchwidth, int matchheight)
{
unsigned char *image_rgba;
const q2wal_t *inwal = (const q2wal_t *)f;
- if (fs_filesize < (int) sizeof(q2wal_t))
+ if (filesize < (int) sizeof(q2wal_t))
{
Con_Print("LoadWAL: invalid WAL file\n");
return NULL;
if ((matchwidth && image_width != matchwidth) || (matchheight && image_height != matchheight))
return NULL;
- if ((int) fs_filesize < (int) sizeof(q2wal_t) + (int) LittleLong(inwal->offsets[0]) + image_width * image_height)
+ if (filesize < (int) sizeof(q2wal_t) + (int) LittleLong(inwal->offsets[0]) + image_width * image_height)
{
Con_Print("LoadWAL: invalid WAL file\n");
return NULL;
struct imageformat_s
{
const char *formatstring;
- unsigned char *(*loadfunc)(const unsigned char *f, int matchwidth, int matchheight);
+ unsigned char *(*loadfunc)(const unsigned char *f, int filesize, int matchwidth, int matchheight);
}
imageformats[] =
{
unsigned char *loadimagepixels (const char *filename, qboolean complain, int matchwidth, int matchheight)
{
int i;
+ fs_offset_t filesize;
unsigned char *f, *data = NULL;
char basename[MAX_QPATH], name[MAX_QPATH], *c;
if (developer_memorydebug.integer)
for (i = 0;imageformats[i].formatstring;i++)
{
sprintf (name, imageformats[i].formatstring, basename);
- f = FS_LoadFile(name, tempmempool, true);
+ f = FS_LoadFile(name, tempmempool, true, &filesize);
if (f)
{
- data = imageformats[i].loadfunc(f, matchwidth, matchheight);
+ data = imageformats[i].loadfunc(f, filesize, matchwidth, matchheight);
Mem_Free(f);
if (data)
{
// makes a RGBA mask from RGBA input, in can be the same as out
int image_makemask (const unsigned char *in, unsigned char *out, int size);
-unsigned char *LoadTGA (const unsigned char *f, int matchwidth, int matchheight);
+unsigned char *LoadTGA (const unsigned char *f, int filesize, int matchwidth, int matchheight);
// loads a texture, as pixel data
unsigned char *loadimagepixels (const char *filename, qboolean complain, int matchwidth, int matchheight);
void Image_MipReduce(const unsigned char *in, unsigned char *out, int *width, int *height, int *depth, int destwidth, int destheight, int destdepth, int bytesperpixel);
// only used by menuplyr coloring
-unsigned char *LoadLMP (const unsigned char *f, int matchwidth, int matchheight, qboolean loadAs8Bit);
+unsigned char *LoadLMP (const unsigned char *f, int filesize, int matchwidth, int matchheight, qboolean loadAs8Bit);
void Image_HeightmapToNormalmap(const unsigned char *inpixels, unsigned char *outpixels, int width, int height, int clamp, float bumpscale);
cinfo->src->bytes_in_buffer -= num_bytes;
}
-static void JPEG_MemSrc (j_decompress_ptr cinfo, const unsigned char *buffer)
+static void JPEG_MemSrc (j_decompress_ptr cinfo, const unsigned char *buffer, size_t filesize)
{
cinfo->src = (struct jpeg_source_mgr *)cinfo->mem->alloc_small ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (struct jpeg_source_mgr));
cinfo->src->next_input_byte = buffer;
- cinfo->src->bytes_in_buffer = fs_filesize;
+ cinfo->src->bytes_in_buffer = filesize;
cinfo->src->init_source = JPEG_Noop;
cinfo->src->fill_input_buffer = JPEG_FillInputBuffer;
Load a JPEG image into a RGBA buffer
====================
*/
-unsigned char* JPEG_LoadImage (const unsigned char *f, int matchwidth, int matchheight)
+unsigned char* JPEG_LoadImage (const unsigned char *f, int filesize, int matchwidth, int matchheight)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = qjpeg_std_error (&jerr);
qjpeg_create_decompress (&cinfo);
- JPEG_MemSrc (&cinfo, f);
+ JPEG_MemSrc (&cinfo, f, filesize);
qjpeg_read_header (&cinfo, TRUE);
qjpeg_start_decompress (&cinfo);
qboolean JPEG_OpenLibrary (void);
void JPEG_CloseLibrary (void);
-unsigned char* JPEG_LoadImage (const unsigned char *f, int matchwidth, int matchheight);
+unsigned char* JPEG_LoadImage (const unsigned char *f, int filesize, int matchwidth, int matchheight);
qboolean JPEG_SaveImage_preflipped (const char *filename, int width, int height, unsigned char *data);
if (menuplyr_load)
{
unsigned char *data, *f;
+ fs_offset_t filesize;
menuplyr_load = false;
menuplyr_top = -1;
menuplyr_bottom = -1;
- if ((f = FS_LoadFile("gfx/menuplyr.lmp", tempmempool, true)))
+ if ((f = FS_LoadFile("gfx/menuplyr.lmp", tempmempool, true, &filesize)))
{
- data = LoadLMP (f, 0, 0, true);
+ data = LoadLMP (f, filesize, 0, 0, true);
menuplyr_width = image_width;
menuplyr_height = image_height;
Mem_Free(f);
{
int i, j, index, version, recordsize, numrecords;
int numpnts, numvtxw, numfaces, nummatts, numbones, numrawweights, numanimbones, numanims, numanimkeys;
+ fs_offset_t filesize;
pskpnts_t *pnts;
pskvtxw_t *vtxw;
pskface_t *faces;
FS_StripExtension(loadmodel->name, animname, sizeof(animname));
strlcat(animname, ".psa", sizeof(animname));
- animbuffer = animfilebuffer = FS_LoadFile(animname, loadmodel->mempool, false);
- animbufferend = (void *)((unsigned char*)animbuffer + fs_filesize);
+ animbuffer = animfilebuffer = FS_LoadFile(animname, loadmodel->mempool, false, &filesize);
+ animbufferend = (void *)((unsigned char*)animbuffer + (int)filesize);
if (animbuffer == NULL)
Host_Error("%s: can't find .psa file (%s)\n", loadmodel->name, animname);
int i;
unsigned char *in, *out, *data, d;
char litfilename[1024];
+ fs_offset_t filesize;
loadmodel->brushq1.lightdata = NULL;
if (loadmodel->brush.ishlbsp) // LordHavoc: load the colored lighting data straight
{
strlcpy (litfilename, loadmodel->name, sizeof (litfilename));
FS_StripExtension (litfilename, litfilename, sizeof (litfilename));
strlcat (litfilename, ".lit", sizeof (litfilename));
- data = (unsigned char*) FS_LoadFile(litfilename, tempmempool, false);
+ data = (unsigned char*) FS_LoadFile(litfilename, tempmempool, false, &filesize);
if (data)
{
- if (fs_filesize == (fs_offset_t)(8 + l->filelen * 3) && data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
+ if (filesize == (fs_offset_t)(8 + l->filelen * 3) && data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
{
i = LittleLong(((int *)data)[1]);
if (i == 1)
{
Con_DPrintf("loaded %s\n", litfilename);
- loadmodel->brushq1.lightdata = (unsigned char *)Mem_Alloc(loadmodel->mempool, fs_filesize - 8);
- memcpy(loadmodel->brushq1.lightdata, data + 8, fs_filesize - 8);
+ loadmodel->brushq1.lightdata = (unsigned char *)Mem_Alloc(loadmodel->mempool, filesize - 8);
+ memcpy(loadmodel->brushq1.lightdata, data + 8, filesize - 8);
Mem_Free(data);
return;
}
}
else
{
- if (fs_filesize == 8)
+ if (filesize == 8)
Con_Print("Empty .lit file, ignoring\n");
else
- Con_Printf("Corrupt .lit file (file size %i bytes, should be %i bytes), ignoring\n", fs_filesize, 8 + l->filelen * 3);
+ Con_Printf("Corrupt .lit file (file size %i bytes, should be %i bytes), ignoring\n", filesize, 8 + l->filelen * 3);
Mem_Free(data);
}
}
strlcpy (lightsfilename, loadmodel->name, sizeof (lightsfilename));
FS_StripExtension (lightsfilename, lightsfilename, sizeof(lightsfilename));
strlcat (lightsfilename, ".lights", sizeof (lightsfilename));
- s = lightsstring = (char *) FS_LoadFile(lightsfilename, tempmempool, false);
+ s = lightsstring = (char *) FS_LoadFile(lightsfilename, tempmempool, false, NULL);
if (s)
{
numlights = 0;
char mapfilename[MAX_QPATH];
FS_StripExtension (loadmodel->name, mapfilename, sizeof (mapfilename));
strlcat (mapfilename, ".map", sizeof (mapfilename));
- maptext = (unsigned char*) FS_LoadFile(mapfilename, tempmempool, false);
+ maptext = (unsigned char*) FS_LoadFile(mapfilename, tempmempool, false, NULL);
if (!maptext)
return;
text = maptext;
{
for (i = 0;i < search->numfilenames;i++)
{
- if ((f = (char *)FS_LoadFile(search->filenames[i], tempmempool, false)))
+ if ((f = (char *)FS_LoadFile(search->filenames[i], tempmempool, false, NULL)))
{
text = f;
while (COM_ParseToken(&text, false))
int num;
unsigned int crc;
void *buf;
+ fs_offset_t filesize;
mod->used = true;
{
if (checkdisk && mod->loaded)
Con_DPrintf("checking model %s\n", mod->name);
- buf = FS_LoadFile (mod->name, tempmempool, false);
+ buf = FS_LoadFile (mod->name, tempmempool, false, &filesize);
if (buf)
{
- crc = CRC_Block((unsigned char *)buf, fs_filesize);
+ crc = CRC_Block((unsigned char *)buf, filesize);
if (mod->crc != crc)
mod->loaded = false;
}
if (buf)
{
- char *bufend = (char *)buf + fs_filesize;
+ char *bufend = (char *)buf + filesize;
num = LittleLong(*((int *)buf));
// call the apropriate loader
loadmodel = mod;
*/
memset(tagsets, 0, sizeof(tagsets));
memset(word, 0, sizeof(word));
- for (i = 0;i < MAX_SKINS && (data = text = (char *)FS_LoadFile(va("%s_%i.skin", loadmodel->name, i), tempmempool, true));i++)
+ for (i = 0;i < MAX_SKINS && (data = text = (char *)FS_LoadFile(va("%s_%i.skin", loadmodel->name, i), tempmempool, true, NULL));i++)
{
numtags = 0;
int shirt_start, shirt_end;
int reversed_start, reversed_end;
unsigned char *colormap;
+ fs_offset_t filesize;
- colormap = FS_LoadFile("gfx/colormap.lmp", tempmempool, true);
- if (colormap && fs_filesize >= 16385)
+ colormap = FS_LoadFile("gfx/colormap.lmp", tempmempool, true, NULL);
+ if (colormap && filesize >= 16385)
fullbright_start = 256 - colormap[16384];
else
fullbright_start = 256;
{
int i;
float gamma, scale, base;
+ fs_offset_t filesize;
unsigned char *in, *out, *palfile;
unsigned char texturegammaramp[256];
BuildGammaTable8(1.0f, gamma, scale, base, texturegammaramp);
- palfile = (unsigned char *)FS_LoadFile ("gfx/palette.lmp", tempmempool, false);
- if (palfile && fs_filesize >= 768)
+ palfile = (unsigned char *)FS_LoadFile ("gfx/palette.lmp", tempmempool, false, &filesize);
+ if (palfile && filesize >= 768)
in = palfile;
else
{
void PR_LoadProgs (const char *progsname)
{
int i;
+ fs_offset_t filesize;
dstatement_t *st;
ddef_t *infielddefs;
dfunction_t *dfunctions;
PR_FreeAll();
- progs = (dprograms_t *)FS_LoadFile (progsname, serverprogs_mempool, false);
+ progs = (dprograms_t *)FS_LoadFile (progsname, serverprogs_mempool, false, &filesize);
if (!progs)
Host_Error ("PR_LoadProgs: couldn't load %s", progsname);
- Con_DPrintf("Programs occupy %iK.\n", fs_filesize/1024);
+ Con_DPrintf("Programs occupy %iK.\n", filesize/1024);
- pr_crc = CRC_Block((unsigned char *)progs, fs_filesize);
+ pr_crc = CRC_Block((unsigned char *)progs, filesize);
// byte swap the header
for (i = 0;i < (int) sizeof(*progs) / 4;i++)
pr_stringssize = 0;
for (i = 0;i < progs->numstrings;i++)
{
- if (progs->ofs_strings + pr_stringssize >= fs_filesize)
+ if (progs->ofs_strings + pr_stringssize >= filesize)
Host_Error ("progs.dat strings go past end of file\n");
pr_stringssize += strlen (pr_strings + pr_stringssize) + 1;
}
}
// not conform with VM_fopen
- data = (char *)FS_LoadFile(filename, tempmempool, false);
+ data = (char *)FS_LoadFile(filename, tempmempool, false, NULL);
if (data == NULL)
PRVM_G_FLOAT(OFS_RETURN) = -1;
===============
*/
void PRVM_LoadLNO( const char *progname ) {
+ fs_offset_t filesize;
unsigned char *lno;
unsigned int *header;
char filename[512];
FS_StripExtension( progname, filename, sizeof( filename ) );
strlcat( filename, ".lno", sizeof( filename ) );
- lno = FS_LoadFile( filename, tempmempool, false );
+ lno = FS_LoadFile( filename, tempmempool, false, &filesize );
if( !lno ) {
return;
}
<Spike> SafeWrite (h, &numstatements, sizeof(int));
<Spike> SafeWrite (h, statement_linenums, numstatements*sizeof(int));
*/
- if( (unsigned) fs_filesize < (6 + prog->progs->numstatements) * sizeof( int ) ) {
+ if( (unsigned) filesize < (6 + prog->progs->numstatements) * sizeof( int ) ) {
return;
}
dstatement_t *st;
ddef_t *infielddefs;
dfunction_t *dfunctions;
+ fs_offset_t filesize;
if( prog->loaded ) {
PRVM_ERROR ("PRVM_LoadProgs: there is already a %s program loaded!\n", PRVM_NAME );
}
- prog->progs = (dprograms_t *)FS_LoadFile (filename, prog->progs_mempool, false);
- if (prog->progs == NULL || fs_filesize < (fs_offset_t)sizeof(dprograms_t))
+ prog->progs = (dprograms_t *)FS_LoadFile (filename, prog->progs_mempool, false, &filesize);
+ if (prog->progs == NULL || filesize < (fs_offset_t)sizeof(dprograms_t))
PRVM_ERROR ("PRVM_LoadProgs: couldn't load %s for %s", filename, PRVM_NAME);
- Con_DPrintf("%s programs occupy %iK.\n", PRVM_NAME, fs_filesize/1024);
+ Con_DPrintf("%s programs occupy %iK.\n", PRVM_NAME, filesize/1024);
- prog->filecrc = CRC_Block((unsigned char *)prog->progs, fs_filesize);
+ prog->filecrc = CRC_Block((unsigned char *)prog->progs, filesize);
// byte swap the header
for (i = 0;i < (int) sizeof(*prog->progs) / 4;i++)
prog->stringssize = 0;
for (i = 0;i < prog->progs->numstrings;i++)
{
- if (prog->progs->ofs_strings + prog->stringssize >= (int)fs_filesize)
+ if (prog->progs->ofs_strings + prog->stringssize >= (int)filesize)
PRVM_ERROR ("%s: %s strings go past end of file\n", PRVM_NAME, filename);
prog->stringssize += (int)strlen (prog->strings + prog->stringssize) + 1;
}
int fragstrings_count;
const char *vertstrings_list[SHADERPERMUTATION_COUNT+1];
const char *fragstrings_list[SHADERPERMUTATION_COUNT+1];
- vertstring = (char *)FS_LoadFile("glsl/light.vert", tempmempool, false);
- fragstring = (char *)FS_LoadFile("glsl/light.frag", tempmempool, false);
+ vertstring = (char *)FS_LoadFile("glsl/light.vert", tempmempool, false, NULL);
+ fragstring = (char *)FS_LoadFile("glsl/light.frag", tempmempool, false, NULL);
for (i = 0;i < SHADERPERMUTATION_COUNT;i++)
{
vertstrings_count = 0;
}
FS_StripExtension (r_refdef.worldmodel->name, name, sizeof (name));
strlcat (name, ".rtlights", sizeof (name));
- lightsstring = (char *)FS_LoadFile(name, tempmempool, false);
+ lightsstring = (char *)FS_LoadFile(name, tempmempool, false, NULL);
if (lightsstring)
{
s = lightsstring;
}
FS_StripExtension (r_refdef.worldmodel->name, name, sizeof (name));
strlcat (name, ".lights", sizeof (name));
- lightsstring = (char *)FS_LoadFile(name, tempmempool, false);
+ lightsstring = (char *)FS_LoadFile(name, tempmempool, false, NULL);
if (lightsstring)
{
s = lightsstring;
// try to load a .ent file first
FS_StripExtension (r_refdef.worldmodel->name, key, sizeof (key));
strlcat (key, ".ent", sizeof (key));
- data = entfiledata = (char *)FS_LoadFile(key, tempmempool, true);
+ data = entfiledata = (char *)FS_LoadFile(key, tempmempool, true, NULL);
// and if that is not found, fall back to the bsp file entity string
if (!data)
data = r_refdef.worldmodel->brush.entities;
qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *s)
{
unsigned char *data;
+ fs_offset_t filesize;
ov_decode_t ov_decode;
OggVorbis_File vf;
vorbis_info *vi;
return true;
// Load the file
- data = FS_LoadFile (filename, snd_mempool, false);
+ data = FS_LoadFile (filename, snd_mempool, false, &filesize);
if (data == NULL)
return false;
// Open it with the VorbisFile API
ov_decode.buffer = data;
ov_decode.ind = 0;
- ov_decode.buffsize = fs_filesize;
+ ov_decode.buffsize = filesize;
if (qov_open_callbacks (&ov_decode, &vf, NULL, 0, callbacks) < 0)
{
Con_Printf ("error while opening Ogg Vorbis file \"%s\"\n", filename);
// Decide if we go for a stream or a simple PCM cache
buff_len = ceil (STREAM_BUFFER_DURATION * (shm->format.speed * 2 * vi->channels));
- if (snd_streaming.integer && len > (ogg_int64_t)fs_filesize + 3 * buff_len)
+ if (snd_streaming.integer && len > (ogg_int64_t)filesize + 3 * buff_len)
{
ogg_stream_persfx_t* per_sfx;
per_sfx = (ogg_stream_persfx_t *)Mem_Alloc (snd_mempool, sizeof (*per_sfx));
s->memsize += sizeof (*per_sfx);
per_sfx->file = data;
- per_sfx->filesize = fs_filesize;
- s->memsize += fs_filesize;
+ per_sfx->filesize = filesize;
+ s->memsize += filesize;
per_sfx->format.speed = vi->rate;
per_sfx->format.width = 2; // We always work with 16 bits samples
*/
qboolean S_LoadWavFile (const char *filename, sfx_t *s)
{
+ fs_offset_t filesize;
unsigned char *data;
wavinfo_t info;
int len;
return true;
// Load the file
- data = FS_LoadFile(filename, snd_mempool, false);
+ data = FS_LoadFile(filename, snd_mempool, false, &filesize);
if (!data)
return false;
Con_DPrintf ("Loading WAV file \"%s\"\n", filename);
- info = GetWavinfo (s->name, data, (int)fs_filesize);
+ info = GetWavinfo (s->name, data, (int)filesize);
// Stereo sounds are allowed (intended for music)
if (info.channels < 1 || info.channels > 2)
{
// load replacement entity file if found
entities = NULL;
if (sv_entpatch.integer)
- entities = (char *)FS_LoadFile(va("maps/%s.ent", sv.name), tempmempool, true);
+ entities = (char *)FS_LoadFile(va("maps/%s.ent", sv.name), tempmempool, true, NULL);
if (entities)
{
Con_Printf("Loaded maps/%s.ent\n", sv.name);
void *W_GetLumpName(const char *name)
{
int i;
+ fs_offset_t filesize;
lumpinfo_t *lump;
char clean[16];
wadinfo_t *header;
if (!wad_loaded)
{
wad_loaded = true;
- if ((temp = FS_LoadFile ("gfx.wad", tempmempool, false)))
+ if ((wad_base = FS_LoadFile ("gfx.wad", cl_mempool, false, &filesize)))
{
if (memcmp(temp, "WAD2", 4))
+ {
Con_Print("gfx.wad doesn't have WAD2 id\n");
+ Mem_Free(wad_base);
+ wad_base = NULL;
+ }
else
{
- wad_base = (unsigned char *)Mem_Alloc(cl_mempool, fs_filesize);
-
- memcpy(wad_base, temp, fs_filesize);
- Mem_Free(temp);
-
header = (wadinfo_t *)wad_base;
wad_numlumps = LittleLong(header->numlumps);
infotableofs = LittleLong(header->infotableofs);