{
Con_Printf("Downloaded \"%s\" (%i bytes, %i CRC)\n", name, size, crc);
FS_WriteFile(name, cls.qw_downloadmemory, cls.qw_downloadmemorycursize);
+ if(!strcmp(cls.qw_downloadname, csqc_progname.string))
+ {
+ if(cls.caughtcsprogsdata)
+ Mem_Free(cls.caughtcsprogsdata);
+ cls.caughtcsprogsdata = Mem_Alloc(cls.permanentmempool, cls.qw_downloadmemorycursize);
+ memcpy(cls.caughtcsprogsdata, cls.qw_downloadmemory, cls.qw_downloadmemorycursize);
+ cls.caughtcsprogsdatasize = cls.qw_downloadmemorycursize;
+ Con_DPrintf("Buffered \"%s\"\n", name);
+ }
}
}
}
int proquake_servermod; // 0 = not proquake, 1 = proquake
int proquake_serverversion; // actual proquake server version * 10 (3.40 = 34, etc)
int proquake_serverflags; // 0 (PQF_CHEATFREE not supported)
+
+ // don't write-then-read csprogs.dat (useful for demo playback)
+ unsigned char *caughtcsprogsdata;
+ fs_offset_t caughtcsprogsdatasize;
}
client_static_t;
if (!cls.demoplayback || csqc_usedemoprogs.integer)
{
csprogsfn = va(vabuf, sizeof(vabuf), "dlcache/%s.%i.%i", csqc_progname.string, requiredsize, requiredcrc);
- csprogsdata = FS_LoadFile(csprogsfn, tempmempool, true, &csprogsdatasize);
+ if(cls.caughtcsprogsdata && cls.caughtcsprogsdatasize == requiredsize && CRC_Block(cls.caughtcsprogsdata, (size_t)cls.caughtcsprogsdatasize) == requiredcrc)
+ {
+ Con_DPrintf("Using buffered \"%s\"\n", csprogsfn);
+ csprogsdata = cls.caughtcsprogsdata;
+ csprogsdatasize = cls.caughtcsprogsdatasize;
+ cls.caughtcsprogsdata = NULL;
+ cls.caughtcsprogsdatasize = 0;
+ }
+ else
+ {
+ Con_DPrintf("Not using buffered \"%s\" (buffered: %p, %d)\n", csprogsfn, cls.caughtcsprogsdata, (int) cls.caughtcsprogsdatasize);
+ csprogsdata = FS_LoadFile(csprogsfn, tempmempool, true, &csprogsdatasize);
+ }
}
if (!csprogsdata)
{
prog->error_cmd = Host_Error;
prog->ExecuteProgram = CLVM_ExecuteProgram;
- PRVM_Prog_Load(prog, csprogsfn, cl_numrequiredfunc, cl_required_func, CL_REQFIELDS, cl_reqfields, CL_REQGLOBALS, cl_reqglobals);
+ PRVM_Prog_Load(prog, csprogsfn, csprogsdata, csprogsdatasize, cl_numrequiredfunc, cl_required_func, CL_REQFIELDS, cl_reqfields, CL_REQGLOBALS, cl_reqglobals);
if (!prog->loaded)
{
// allocate the mempools
prog->progs_mempool = Mem_AllocPool(M_PROG_FILENAME, 0, NULL);
- PRVM_Prog_Load(prog, M_PROG_FILENAME, m_numrequiredfunc, m_required_func, m_numrequiredfields, m_required_fields, m_numrequiredglobals, m_required_globals);
+ PRVM_Prog_Load(prog, M_PROG_FILENAME, NULL, 0, m_numrequiredfunc, m_required_func, m_numrequiredfields, m_required_fields, m_numrequiredglobals, m_required_globals);
// note: OP_STATE is not supported by menu qc, we don't even try to detect
// it here
*/
// Load expects to be called right after Init
void PRVM_Prog_Init(prvm_prog_t *prog);
-void PRVM_Prog_Load(prvm_prog_t *prog, const char *filename, int numrequiredfunc, const char **required_func, int numrequiredfields, prvm_required_field_t *required_field, int numrequiredglobals, prvm_required_field_t *required_global);
+void PRVM_Prog_Load(prvm_prog_t *prog, const char *filename, unsigned char *data, fs_offset_t size, int numrequiredfunc, const char **required_func, int numrequiredfields, prvm_required_field_t *required_field, int numrequiredglobals, prvm_required_field_t *required_global);
void PRVM_Prog_Reset(prvm_prog_t *prog);
void PRVM_StackTrace(prvm_prog_t *prog);
PRVM_LoadProgs
===============
*/
-void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, int numrequiredfunc, const char **required_func, int numrequiredfields, prvm_required_field_t *required_field, int numrequiredglobals, prvm_required_field_t *required_global)
+void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * data, fs_offset_t size, int numrequiredfunc, const char **required_func, int numrequiredfields, prvm_required_field_t *required_field, int numrequiredglobals, prvm_required_field_t *required_global)
{
int i;
dprograms_t *dprograms;
Host_LockSession(); // all progs can use the session cvar
Crypto_LoadKeys(); // all progs might use the keys at init time
- dprograms = (dprograms_t *)FS_LoadFile (filename, prog->progs_mempool, false, &filesize);
+ if (data)
+ {
+ dprograms = (dprograms_t *) data;
+ filesize = size;
+ }
+ else
+ dprograms = (dprograms_t *)FS_LoadFile (filename, prog->progs_mempool, false, &filesize);
if (dprograms == NULL || filesize < (fs_offset_t)sizeof(dprograms_t))
prog->error_cmd("PRVM_LoadProgs: couldn't load %s for %s", filename, prog->name);
// TODO bounds check header fields (e.g. numstatements), they must never go behind end of file
}
// we're done with the file now
- Mem_Free(dprograms);
+ if(!data)
+ Mem_Free(dprograms);
dprograms = NULL;
// check required functions
prog->error_cmd = Host_Error;
prog->ExecuteProgram = SVVM_ExecuteProgram;
- PRVM_Prog_Load(prog, sv_progs.string, SV_REQFUNCS, sv_reqfuncs, SV_REQFIELDS, sv_reqfields, SV_REQGLOBALS, sv_reqglobals);
+ PRVM_Prog_Load(prog, sv_progs.string, NULL, 0, SV_REQFUNCS, sv_reqfuncs, SV_REQFIELDS, sv_reqfields, SV_REQGLOBALS, sv_reqglobals);
// some mods compiled with scrambling compilers lack certain critical
// global names and field names such as "self" and "time" and "nextthink"