From d56226aac5a5039bdced61c7aea04ef237a79dea Mon Sep 17 00:00:00 2001 From: Spoike Date: Fri, 20 Apr 2018 19:09:14 +0000 Subject: [PATCH] more comprehensive attempt at fixing the qccgui bug reported by shpuld. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5247 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/pr_csqc.c | 4 ++-- engine/client/pr_menu.c | 2 +- engine/common/pr_bgcmd.c | 2 +- engine/qclib/gui.h | 2 +- engine/qclib/packager.c | 2 +- engine/qclib/pr_edict.c | 6 +++--- engine/qclib/progslib.h | 2 +- engine/qclib/qcc_cmdlib.c | 21 +++++++++++++++++---- engine/qclib/qcc_pr_comp.c | 5 +++-- engine/qclib/qccgui.c | 5 ++++- engine/qclib/qccguistuff.c | 2 +- engine/qclib/qccmain.c | 32 +++++++++++++++++++++++++++----- engine/server/pr_cmds.c | 2 +- 13 files changed, 63 insertions(+), 24 deletions(-) diff --git a/engine/client/pr_csqc.c b/engine/client/pr_csqc.c index 94b35e8a2..adc053156 100644 --- a/engine/client/pr_csqc.c +++ b/engine/client/pr_csqc.c @@ -94,7 +94,7 @@ extern sfx_t *cl_sfx_ric2; extern sfx_t *cl_sfx_ric3; extern sfx_t *cl_sfx_r_exp3; -#define ENDLIST +#define ENDLIST //clarifies \ in list macros. #ifdef NOLEGACY #define legacycsqcglobals #else @@ -6887,7 +6887,7 @@ void CSQC_Shutdown(void) } //when the qclib needs a file, it calls out to this function. -void *PDECL CSQC_PRLoadFile (const char *path, unsigned char *(PDECL *buf_get)(void *ctx, size_t len), void *buf_ctx, size_t *sz) +void *PDECL CSQC_PRLoadFile (const char *path, unsigned char *(PDECL *buf_get)(void *ctx, size_t len), void *buf_ctx, size_t *sz, pbool issource) { extern cvar_t sv_demo_write_csqc; qbyte *file = NULL; diff --git a/engine/client/pr_menu.c b/engine/client/pr_menu.c index 5d2a554c3..fac3a9ae6 100644 --- a/engine/client/pr_menu.c +++ b/engine/client/pr_menu.c @@ -2485,7 +2485,7 @@ pbool PDECL Menu_CheckHeaderCrc(pubprogfuncs_t *inst, progsnum_t idx, int crc) return false; } -static void *PDECL MP_PRReadFile (const char *path, qbyte *(PDECL *buf_get)(void *buf_ctx, size_t size), void *buf_ctx, size_t *size) +static void *PDECL MP_PRReadFile (const char *path, qbyte *(PDECL *buf_get)(void *buf_ctx, size_t size), void *buf_ctx, size_t *size, pbool issource) { flocation_t loc; if (FS_FLocateFile(path, FSLF_IFFOUND|FSLF_SECUREONLY, &loc)) diff --git a/engine/common/pr_bgcmd.c b/engine/common/pr_bgcmd.c index 5b95490a2..13057bcf0 100644 --- a/engine/common/pr_bgcmd.c +++ b/engine/common/pr_bgcmd.c @@ -15,7 +15,7 @@ static char *cvargroup_progs = "Progs variables"; cvar_t sv_gameplayfix_nolinknonsolid = CVARD("sv_gameplayfix_nolinknonsolid", "1", "When 0, setorigin et al will not link the entity into the collision nodes (which is faster, especially if you have a lot of non-solid entities. When 1, allows entities to freely switch between .solid values (except for SOLID_BSP) without relinking. A lot of DP mods assume a value of 1 and will bug out otherwise, while 0 will restore a bugs present in various mods."); -cvar_t sv_gameplayfix_blowupfallenzombies = CVARD("sv_gameplayfix_blowupfallenzombies", "0", "Allow findradius to find non-solid entities. This may break certain mods."); +cvar_t sv_gameplayfix_blowupfallenzombies = CVARD("sv_gameplayfix_blowupfallenzombies", "0", "Allow findradius to find non-solid entities. This may break certain mods. It is better for mods to use FL_FINDABLE_NONSOLID instead."); cvar_t dpcompat_findradiusarealinks = CVARD("dpcompat_findradiusarealinks", "0", "Use the world collision info to accelerate findradius instead of looping through every single entity. May actually be slower for large radiuses, or fail to find entities which have not been linked properly with setorigin."); #ifndef NOLEGACY cvar_t dpcompat_strcat_limit = CVARD("dpcompat_strcat_limit", "", "When set, cripples strcat (and related function) string lengths to the value specified.\nSet to 16383 to replicate DP's limit, otherwise leave as 0 to avoid limits."); diff --git a/engine/qclib/gui.h b/engine/qclib/gui.h index 8c7b329b9..8a2a1d854 100644 --- a/engine/qclib/gui.h +++ b/engine/qclib/gui.h @@ -10,7 +10,7 @@ int QCC_RawFileSize (const char *fname); pbool QCC_WriteFile (const char *name, void *data, int len); void GUI_DialogPrint(char *title, char *text); -void *GUIReadFile(const char *fname, unsigned char *(*buf_get)(void *ctx, size_t len), void *buf_ctx, size_t *out_size); +void *GUIReadFile(const char *fname, unsigned char *(*buf_get)(void *ctx, size_t len), void *buf_ctx, size_t *out_size, pbool issourcefile); int GUIFileSize(const char *fname); int GUI_ParseCommandLine(char *args, pbool keepsrcanddir); //0=gui, 1=commandline diff --git a/engine/qclib/packager.c b/engine/qclib/packager.c index fee7f6416..82da85ee1 100644 --- a/engine/qclib/packager.c +++ b/engine/qclib/packager.c @@ -1625,7 +1625,7 @@ void Packager_ParseText(struct pkgctx_s *ctx, char *scripttext) void Packager_ParseFile(struct pkgctx_s *ctx, char *scriptname) { size_t remaining = 0; - char *file = qccprogfuncs->funcs.parms->ReadFile(scriptname, NULL, NULL, &remaining); + char *file = qccprogfuncs->funcs.parms->ReadFile(scriptname, NULL, NULL, &remaining, true); strcpy(ctx->gamepath, scriptname); strcpy(ctx->sourcepath, scriptname); Packager_ParseText(ctx, file); diff --git a/engine/qclib/pr_edict.c b/engine/qclib/pr_edict.c index e36242e27..2e96b73cc 100644 --- a/engine/qclib/pr_edict.c +++ b/engine/qclib/pr_edict.c @@ -2564,7 +2564,7 @@ int PR_ReallyLoadProgs (progfuncs_t *progfuncs, const char *filename, progstate_ retry: hmark = PRHunkMark(progfuncs); - pr_progs = externs->ReadFile(filename, PR_GetHeapBuffer, progfuncs, &fsz); + pr_progs = externs->ReadFile(filename, PR_GetHeapBuffer, progfuncs, &fsz, false); if (!pr_progs) { if (externs->autocompile == PR_COMPILENEXIST || externs->autocompile == PR_COMPILECHANGED) //compile if file is not found (if 2, we have already tried, so don't bother) @@ -2574,7 +2574,7 @@ retry: printf("couldn't open progs %s. Attempting to compile.\n", filename); CompileFile(progfuncs, filename); } - pr_progs = externs->ReadFile(filename, PR_GetHeapBuffer, progfuncs, &fsz); + pr_progs = externs->ReadFile(filename, PR_GetHeapBuffer, progfuncs, &fsz, false); if (!pr_progs) { printf("Couldn't find or compile file %s\n", filename); @@ -2824,7 +2824,7 @@ retry: strcpy(lnoname, filename); StripExtension(lnoname); strcat(lnoname, ".lno"); - file = externs->ReadFile(lnoname, PR_GetHeapBuffer, progfuncs, &fsz); + file = externs->ReadFile(lnoname, PR_GetHeapBuffer, progfuncs, &fsz, false); if (file) { if ( file[0] != lnotype diff --git a/engine/qclib/progslib.h b/engine/qclib/progslib.h index f60cd272c..1f9fe86ac 100644 --- a/engine/qclib/progslib.h +++ b/engine/qclib/progslib.h @@ -202,7 +202,7 @@ struct pubprogfuncs_s typedef struct progexterns_s { int progsversion; //PROGSTRUCT_VERSION - void *(PDECL *ReadFile) (const char *fname, unsigned char *(PDECL *buf_get)(void *ctx, size_t len), void *buf_ctx, size_t *out_size); + void *(PDECL *ReadFile) (const char *fname, unsigned char *(PDECL *buf_get)(void *ctx, size_t len), void *buf_ctx, size_t *out_size, pbool issourcefile); int (PDECL *FileSize) (const char *fname); //-1 if file does not exist pbool (PDECL *WriteFile) (const char *name, void *data, int len); int (VARGS *Printf) (const char *, ...) LIKEPRINTF(1); diff --git a/engine/qclib/qcc_cmdlib.c b/engine/qclib/qcc_cmdlib.c index b90748a79..35c460102 100644 --- a/engine/qclib/qcc_cmdlib.c +++ b/engine/qclib/qcc_cmdlib.c @@ -592,7 +592,7 @@ Returns the argument number (1 to argc-1) or 0 if not present */ int QCC_CheckParm (char *check) { - int i; + int i; for (i = 1;iReadFile(filename, QCC_LoadFileHunk, NULL, &len); + mem = externs->ReadFile(filename, QCC_LoadFileHunk, NULL, &len, true); if (!mem) { QCC_Error(ERR_COULDNTOPENFILE, "Couldn't open file %s", filename); @@ -1274,7 +1287,7 @@ void QCC_AddFile (char *filename) char *mem; size_t len; - mem = externs->ReadFile(filename, QCC_LoadFileHunk, NULL, &len); + mem = externs->ReadFile(filename, QCC_LoadFileHunk, NULL, &len, false); if (!mem) externs->Abort("failed to find file %s", filename); sfile = (qcc_cachedsourcefile_t*)(mem-sizeof(qcc_cachedsourcefile_t)); @@ -1299,7 +1312,7 @@ static unsigned char *PDECL FS_ReadToMem_Alloc(void *ctx, size_t size) void *FS_ReadToMem(char *filename, size_t *len) { progfuncs_t *progfuncs = qccprogfuncs; - return externs->ReadFile(filename, FS_ReadToMem_Alloc, NULL, len); + return externs->ReadFile(filename, FS_ReadToMem_Alloc, NULL, len, false); } void FS_CloseFromMem(void *mem) diff --git a/engine/qclib/qcc_pr_comp.c b/engine/qclib/qcc_pr_comp.c index bcc75dd55..00a4cfe72 100644 --- a/engine/qclib/qcc_pr_comp.c +++ b/engine/qclib/qcc_pr_comp.c @@ -12132,7 +12132,7 @@ QCC_function_t *QCC_PR_GenerateBuiltinFunction (QCC_def_t *def, int builtinnum, { QCC_function_t *func; if (numfunctions >= MAX_FUNCTIONS) - QCC_PR_ParseError(ERR_INTERNAL, "Too many functions - %i\nAdd \"MAX_FUNCTIONS\" \"%i\" to qcc.cfg", numfunctions, (numfunctions+4096)&~4095); + QCC_PR_ParseError(ERR_INTERNAL, "Too many functions - %i\nAdd '-max_functions %i' to the commandline", numfunctions, (numfunctions+4096)&~4095); func = &functions[numfunctions++]; func->filen = s_filen; func->s_filed = s_filed; @@ -12155,7 +12155,7 @@ static QCC_function_t *QCC_PR_GenerateQCFunction (QCC_def_t *def, QCC_type_t *ty { QCC_function_t *func = NULL; if (numfunctions >= MAX_FUNCTIONS) - QCC_PR_ParseError(ERR_INTERNAL, "Too many functions - %i\nAdd \"MAX_FUNCTIONS\" \"%i\" to qcc.cfg", numfunctions, (numfunctions+4096)&~4095); + QCC_PR_ParseError(ERR_INTERNAL, "Too many functions - %i\nAdd '-max_functions %i' to the commandline", numfunctions, (numfunctions+4096)&~4095); if (!pif_flags) ; @@ -15344,6 +15344,7 @@ void QCC_Cleanup(void) pr_cases = NULL; pr_casesref = NULL; pr_casesref2 = NULL; + *compilingrootfile = 0; #ifdef _DEBUG OpAssignsTo_Debug(); diff --git a/engine/qclib/qccgui.c b/engine/qclib/qccgui.c index 3538245fa..3a6b2a3e5 100644 --- a/engine/qclib/qccgui.c +++ b/engine/qclib/qccgui.c @@ -3350,7 +3350,7 @@ static unsigned char *buf_get_malloc(void *ctx, size_t len) { return malloc(len); } -void *GUIReadFile(const char *fname, unsigned char *(*buf_get)(void *ctx, size_t len), void *buf_ctx, size_t *out_size) +void *GUIReadFile(const char *fname, unsigned char *(*buf_get)(void *ctx, size_t len), void *buf_ctx, size_t *out_size, pbool issourcefile) { editor_t *e; size_t blen; @@ -3410,6 +3410,9 @@ void *GUIReadFile(const char *fname, unsigned char *(*buf_get)(void *ctx, size_t } } + if (issourcefile) + AddSourceFile(compilingrootfile, fname); + return QCC_ReadFile(fname, buf_get, buf_ctx, out_size); } diff --git a/engine/qclib/qccguistuff.c b/engine/qclib/qccguistuff.c index c18341374..93835814f 100644 --- a/engine/qclib/qccguistuff.c +++ b/engine/qclib/qccguistuff.c @@ -32,7 +32,7 @@ int Grep(char *filename, char *string) if (!filename) return foundcount; - raw = GUIReadFile(filename, NULL, NULL, &sz); + raw = GUIReadFile(filename, NULL, NULL, &sz, false); if (!raw) return foundcount; if (raw[sz] != 0) diff --git a/engine/qclib/qccmain.c b/engine/qclib/qccmain.c index 5eac46532..d2092413a 100644 --- a/engine/qclib/qccmain.c +++ b/engine/qclib/qccmain.c @@ -431,6 +431,7 @@ Runs qbsp and light on all of the models with a .bsp extension ================= */ int QCC_CheckParm (char *check); +const char *QCC_ReadParm (char *check); void QCC_BspModels (void) { @@ -1364,10 +1365,10 @@ pbool QCC_WriteData (int crc) progs.blockscompressed=0; if (numstatements > MAX_STATEMENTS) - QCC_Error(ERR_TOOMANYSTATEMENTS, "Too many statements - %i\nAdd \"MAX_STATEMENTS\" \"%i\" to qcc.cfg", numstatements, (numstatements+32768)&~32767); + QCC_Error(ERR_TOOMANYSTATEMENTS, "Too many statements - %i\nAdd '-max_statements %i' to the commandline", numstatements, (numstatements+32768)&~32767); if (strofs > MAX_STRINGS) - QCC_Error(ERR_TOOMANYSTRINGS, "Too many strings - %i\nAdd \"MAX_STRINGS\" \"%i\" to qcc.cfg", strofs, (strofs+32768)&~32767); + QCC_Error(ERR_TOOMANYSTRINGS, "Too many strings - %i\nAdd '-max_strings %i' to the commandline", strofs, (strofs+32768)&~32767); //part of how compilation works. This def is always present, and never used. def = QCC_PR_GetDef(NULL, "end_sys_globals", NULL, false, 0, false); @@ -1909,7 +1910,7 @@ pbool QCC_WriteData (int crc) } if (numglobaldefs > MAX_GLOBALS) - QCC_Error(ERR_TOOMANYGLOBALS, "Too many globals - %i\nAdd \"MAX_GLOBALS\" \"%i\" to qcc.cfg", numglobaldefs, (numglobaldefs+32768)&~32767); + QCC_Error(ERR_TOOMANYGLOBALS, "Too many globals - %i\nAdd '-max_globals %i' to the commandline", numglobaldefs, (numglobaldefs+32768)&~32767); dupewarncount = 0; @@ -2781,7 +2782,7 @@ void QCC_ImportProgs(const char *filename) //FIXME: find temps. strip them. you get the idea. //FIXME: find immediates. set up hash tables for them for reuse. HAH! - prog = externs->ReadFile(filename, QCC_LoadFileHunkAlloc, NULL, &flen); + prog = externs->ReadFile(filename, QCC_LoadFileHunkAlloc, NULL, &flen, false); if (!prog) { QCC_Error(ERR_COULDNTOPENFILE, "Couldn't open file %s", filename); @@ -4615,6 +4616,7 @@ pbool QCC_main (int argc, char **argv) //as part of the quake engine size_t p; extern int qccpersisthunk; + const char *arg; char *s; @@ -4667,7 +4669,27 @@ pbool QCC_main (int argc, char **argv) //as part of the quake engine strcpy(destfile, ""); compressoutput = 0; - s = externs->ReadFile("qcc.cfg", QCC_LoadFileHunkAlloc, NULL, &p); + if ((arg = QCC_ReadParm("-max_regs"))) + MAX_REGS = max(100, atoi(arg)); + if ((arg = QCC_ReadParm("-max_strings"))) + MAX_STRINGS = max(100, atoi(arg)); + if ((arg = QCC_ReadParm("-max_globals"))) + MAX_GLOBALS = max(64, atoi(arg)); + if ((arg = QCC_ReadParm("-max_fields"))) + MAX_FIELDS = max(0, atoi(arg)); + if ((arg = QCC_ReadParm("-max_statements"))) + MAX_STATEMENTS = max(1, atoi(arg)); + if ((arg = QCC_ReadParm("-max_functions"))) + MAX_FUNCTIONS = max(1, atoi(arg)); + if ((arg = QCC_ReadParm("-max_types"))) + maxtypeinfos = max(100, atoi(arg)); + if ((arg = QCC_ReadParm("-max_temps"))) + max_temps = max(100, atoi(arg)); + if ((arg = QCC_ReadParm("-max_macros"))) + MAX_CONSTANTS = max(100, atoi(arg)); + + //FIXME: strip this. + s = externs->ReadFile("qcc.cfg", QCC_LoadFileHunkAlloc, NULL, &p, false); if (s) { while(1) diff --git a/engine/server/pr_cmds.c b/engine/server/pr_cmds.c index 96655d09f..e7a0a713e 100644 --- a/engine/server/pr_cmds.c +++ b/engine/server/pr_cmds.c @@ -622,7 +622,7 @@ pbool PDECL PR_SSQC_CheckHeaderCrc(pubprogfuncs_t *inst, progsnum_t idx, int crc return false; return true; } -static void *PDECL SSQC_PRReadFile (const char *path, qbyte *(PDECL *buf_get)(void *buf_ctx, size_t size), void *buf_ctx, size_t *size) +static void *PDECL SSQC_PRReadFile (const char *path, qbyte *(PDECL *buf_get)(void *buf_ctx, size_t size), void *buf_ctx, size_t *size, pbool issource) { flocation_t loc; if (FS_FLocateFile(path, FSLF_IFFOUND, &loc))