From 116ab2ed9964a111271bb3be1deb57414139874c Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 16 Jun 2011 19:39:22 +0000 Subject: [PATCH] Fix mapster's command-line parsing and copy over some of the 'custom mod dir' logic, currently used in the sound board to also find files outside of GRPs. git-svn-id: https://svn.eduke32.com/eduke32@1904 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/editor.h | 4 +- polymer/eduke32/build/src/build.c | 13 +- polymer/eduke32/build/src/hightile.c | 4 +- polymer/eduke32/source/astub.c | 443 ++++++++++++---------- polymer/eduke32/source/sounds_mapster32.c | 4 +- 5 files changed, 248 insertions(+), 220 deletions(-) diff --git a/polymer/eduke32/build/include/editor.h b/polymer/eduke32/build/include/editor.h index c28fb07f3..7840ba673 100644 --- a/polymer/eduke32/build/include/editor.h +++ b/polymer/eduke32/build/include/editor.h @@ -91,7 +91,7 @@ extern int32_t editorgridextent; // in engine.c extern char game_executable[BMAX_PATH]; extern char program_origcwd[BMAX_PATH]; -extern char *mapster32_fullpath; +extern const char *mapster32_fullpath; extern char *testplay_addparam; extern const char *g_namesFileName; @@ -114,6 +114,8 @@ extern int32_t autogray; int32_t yax_is121(int16_t bunchnum, int16_t getfloor); #endif +extern int32_t kopen4loadfrommod(const char *filename, char searchfirst); + extern int32_t map_revision; extern int32_t map_undoredo(int32_t dir); extern void map_undoredo_free(void); diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 7e8365968..a141703ab 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -110,7 +110,7 @@ int32_t revertCTRL=0,scrollamount=3; int32_t unrealedlook=1, quickmapcycling=1; //PK char program_origcwd[BMAX_PATH]; -char *mapster32_fullpath; +const char *mapster32_fullpath; char *testplay_addparam = 0; static char boardfilename[BMAX_PATH], selectedboardfilename[BMAX_PATH]; @@ -8483,8 +8483,8 @@ int32_t loadnames(const char *namesfile) } number = p; - while (*p != 0) p++; - if (*p != 0) *p = 0; + while (*p != 0 && *p != 32) p++; + *p = 0; // add to list num = Bstrtol(number, &endptr, 10); @@ -8509,7 +8509,6 @@ int32_t loadnames(const char *namesfile) syms++; continue; - } else // #define_NAME with no number { @@ -8526,9 +8525,11 @@ int32_t loadnames(const char *namesfile) } else if (*p == '*' && p[1] == '/') { - comment--; continue; + comment--; + continue; } - else if (comment)continue; + else if (comment) + continue; badline: initprintf("Error: Invalid statement found at character %d on line %d\n", (int32_t)(p-buffer), line-1); } diff --git a/polymer/eduke32/build/src/hightile.c b/polymer/eduke32/build/src/hightile.c index c05b268a6..5fd5c5ada 100644 --- a/polymer/eduke32/build/src/hightile.c +++ b/polymer/eduke32/build/src/hightile.c @@ -167,13 +167,13 @@ int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float if (tilesizx[picnum]<=0 || tilesizy[picnum]<=0) { static int32_t first=1; - initprintf("Warning: defined hightile replacement for empty tile %d.", picnum); if (first) { + initprintf("Warning: defined hightile replacement for empty tile %d.", picnum); initprintf(" Maybe some tilesXXX.art are not loaded?"); + initprintf("\n"); first = 0; } - initprintf("\n"); } //printf("Replacement [%d,%d]: %s\n", picnum, palnum, hicreplc[i]->filename); diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 9176ecba7..0a918f869 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -59,6 +59,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static int32_t floor_over_floor; static int32_t g_fillCurSector = 0; +static char g_modDir[BMAX_PATH]; + // static char *startwin_labeltext = "Starting Mapster32..."; static char setupfilename[]= "mapster32.cfg"; static char defaultduke3dgrp[BMAX_PATH] = "duke3d.grp"; @@ -669,6 +671,23 @@ static const char *Help3d[]= " END = PGUP/PGDN MODIFIER (512 UNITS)", }; +int32_t kopen4loadfrommod(const char *filename, char searchfirst) +{ + static char fn[BMAX_PATH]; + int32_t r=-1; + + if (g_modDir[0]) + { + Bsnprintf(fn,sizeof(fn),"%s/%s",g_modDir,filename); + r = kopen4load(fn,searchfirst); + } + + if (r < 0) + r = kopen4load(filename,searchfirst); + + return r; +} + static void clearfilenames(void) { klistfree(finddirs); @@ -8355,260 +8374,266 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) int32_t i = 1, j, maxlen=0, *lengths; char *c, *k; - mapster32_fullpath = (char *)argv[0]; + mapster32_fullpath = argv[0]; - if (argc > 1) + if (argc <= 1) + return; + + lengths = Bmalloc(argc*sizeof(int32_t)); + for (j=1; j i+1) { - if (argc > i+1) - { - G_AddGroup(argv[i+1]); - COPYARG(i); - COPYARG(i+1); - i++; - } + G_AddGroup(argv[i+1]); + COPYARG(i); + COPYARG(i+1); i++; - continue; } + i++; + continue; + } - if (!Bstrcasecmp(c+1,"game_dir")) + if (!Bstrcasecmp(c+1,"game_dir")) + { + if (argc > i+1) { - if (argc > i+1) - { #ifdef USE_OPENGL - extern char TEXCACHEFILE[BMAX_PATH]; + extern char TEXCACHEFILE[BMAX_PATH]; - Bsprintf(tempbuf,"%s/%s",argv[i+1],TEXCACHEFILE); - Bstrcpy(TEXCACHEFILE,tempbuf); + Bsnprintf(tempbuf,sizeof(tempbuf),"%s/%s",argv[i+1],TEXCACHEFILE); + Bstrncpy(TEXCACHEFILE,tempbuf, sizeof(TEXCACHEFILE)); + TEXCACHEFILE[sizeof(TEXCACHEFILE)-1] = 0; #endif - AddGamePath(argv[i+1]); + Bstrncpy(g_modDir, argv[i+1], sizeof(g_modDir)); + g_modDir[sizeof(g_modDir)-1] = 0; + AddGamePath(argv[i+1]); + + COPYARG(i); + COPYARG(i+1); + i++; + } + i++; + continue; + } + if (!Bstrcasecmp(c+1,"cachesize")) + { + if (argc > i+1) + { + int32_t sz = atoi_safe(argv[i+1]); + if (sz >= 16<<10 && sz <= 1024<<10) + { + g_maxCacheSize = sz<<10; + initprintf("Cache size: %dkB\n",sz); COPYARG(i); COPYARG(i+1); - i++; } i++; - continue; } - if (!Bstrcasecmp(c+1,"cachesize")) + i++; + continue; + } + if (!Bstrcasecmp(c+1,"cfg")) + { + if (argc > i+1) { - if (argc > i+1) - { - int32_t sz = atoi_safe(argv[i+1]); - if (sz >= 16<<10 && sz <= 1024<<10) - { - g_maxCacheSize = sz<<10; - initprintf("Cache size: %dkB\n",sz); - - COPYARG(i); - COPYARG(i+1); - } - i++; - } + Bstrcpy(setupfilename,argv[i+1]); i++; - continue; } - if (!Bstrcasecmp(c+1,"cfg")) + i++; + continue; + } + if (!Bstrcasecmp(c+1,"gamegrp")) + { + if (argc > i+1) { - if (argc > i+1) - { - Bstrcpy(setupfilename,argv[i+1]); - i++; - } - i++; - continue; - } - if (!Bstrcasecmp(c+1,"gamegrp")) - { - if (argc > i+1) - { - Bstrcpy(defaultduke3dgrp,argv[i+1]); - COPYARG(i); - COPYARG(i+1); - i++; - } - i++; - continue; - } - if (!Bstrcasecmp(c+1,"nam")) - { - Bstrcpy(g_grpNamePtr, "nam.grp"); + Bstrcpy(defaultduke3dgrp,argv[i+1]); COPYARG(i); + COPYARG(i+1); i++; - continue; - } - if (!Bstrcasecmp(c+1,"namesfile")) - { - g_namesFileName = argv[i+1]; - i++; - continue; - } - if (!Bstrcasecmp(c+1,"-nm") || Bstrcasecmp(c+1,"-ns")) - { - COPYARG(i); - i++; - continue; - } - if (!Bstrcasecmp(c+1,"ww2gi")) - { - Bstrcpy(g_grpNamePtr, "ww2gi.grp"); - COPYARG(i); - i++; - continue; - } - if (!Bstrcasecmp(c+1,"check")) - { - initprintf("Map pointer checking on saving enabled\n"); - fixmapbeforesaving = 1; - i++; - continue; - } - if (!Bstrcasecmp(c+1,"nocheck")) - { - initprintf("Map pointer checking disabled\n"); - fixmapbeforesaving = 0; - i++; - continue; - } - if (!Bstrcasecmp(c+1,"noautoload")) - { - initprintf("Autoload disabled\n"); - NoAutoLoad = 1; - COPYARG(i); - i++; - continue; } + i++; + continue; + } + if (!Bstrcasecmp(c+1,"nam")) + { + Bstrcpy(g_grpNamePtr, "nam.grp"); + COPYARG(i); + i++; + continue; + } + if (!Bstrcasecmp(c+1,"namesfile")) + { + g_namesFileName = argv[i+1]; + i++; + continue; + } + if (!Bstrcasecmp(c+1,"nm") || !Bstrcasecmp(c+1,"ns")) + { + COPYARG(i); + i++; + continue; + } + if (!Bstrcasecmp(c+1,"ww2gi")) + { + Bstrcpy(g_grpNamePtr, "ww2gi.grp"); + COPYARG(i); + i++; + continue; + } + if (!Bstrcasecmp(c+1,"check")) + { + initprintf("Map pointer checking on saving enabled\n"); + fixmapbeforesaving = 1; + i++; + continue; + } + if (!Bstrcasecmp(c+1,"nocheck")) + { + initprintf("Map pointer checking disabled\n"); + fixmapbeforesaving = 0; + i++; + continue; + } + if (!Bstrcasecmp(c+1,"noautoload")) + { + initprintf("Autoload disabled\n"); + NoAutoLoad = 1; + COPYARG(i); + i++; + continue; + } #if !defined(_WIN32) - if (!Bstrcasecmp(c+1,"usecwd")) - { - usecwd = 1; - COPYARG(i); - i++; - continue; - } + if (!Bstrcasecmp(c+1,"usecwd")) + { + usecwd = 1; + COPYARG(i); + i++; + continue; + } #endif #if defined(RENDERTYPEWIN) && defined(USE_OPENGL) - if (!Bstrcasecmp(c+1,"forcegl")) - { - forcegl = 1; - i++; - continue; - } -#endif - } - - if ((*c == '-') -#ifdef _WIN32 - || (*c == '/') -#endif -) + if (!Bstrcasecmp(c+1,"forcegl")) { - c++; - switch (*c) - { - case 'h': - case 'H': - c++; - if (*c) - { - defsfilename = c; - COPYARG(i); - initprintf("Using DEF file: %s.\n",defsfilename); - } - break; - case 'j': - case 'J': - c++; - if (!*c) break; - AddGamePath(c); - COPYARG(i); - break; - case 'g': - case 'G': - c++; - if (!*c) break; - G_AddGroup(c); - COPYARG(i); - break; - case 'x': - case 'X': - c++; - if (!*c) break; - gamecon = c; - COPYARG(i); - break; - } + forcegl = 1; + i++; + continue; } - else - { - k = Bstrrchr(c,'.'); - if (k) - { - if (!Bstrcasecmp(k,".grp") || !Bstrcasecmp(k,".zip")) - { - COPYARG(i); - G_AddGroup(argv[i++]); - continue; - } - else if (!Bstrcasecmp(k,".def")) - { - COPYARG(i); - defsfilename = (char *)argv[i++]; - initprintf("Using DEF file: %s.\n",defsfilename); - continue; - } - else if (!Bstrcasecmp(k,".con")) - { - COPYARG(i); - gamecon = (char *)argv[i++]; - continue; - } - } - } - i++; +#endif } - Bfree(lengths); - if (j > 0) + if ((*c == '-') +#ifdef _WIN32 + || (*c == '/') +#endif +) { - testplay_addparam[j-1] = 0; - testplay_addparam = Brealloc(testplay_addparam, j*sizeof(char)); + c++; + switch (*c) + { + case 'h': + case 'H': + c++; + if (*c) + { + defsfilename = c; + COPYARG(i); + initprintf("Using DEF file: %s.\n",defsfilename); + } + break; + case 'j': + case 'J': + c++; + if (!*c) break; + AddGamePath(c); + COPYARG(i); + break; + case 'g': + case 'G': + c++; + if (!*c) break; + G_AddGroup(c); + COPYARG(i); + break; + case 'x': + case 'X': + c++; + if (!*c) break; + gamecon = c; + COPYARG(i); + break; + } } else { - Bfree(testplay_addparam); - testplay_addparam = NULL; + k = Bstrrchr(c,'.'); + if (k) + { + if (!Bstrcasecmp(k,".grp") || !Bstrcasecmp(k,".zip")) + { + COPYARG(i); + G_AddGroup(argv[i++]); + continue; + } + else if (!Bstrcasecmp(k,".def")) + { + COPYARG(i); + defsfilename = (char *)argv[i++]; + initprintf("Using DEF file: %s.\n",defsfilename); + continue; + } + else if (!Bstrcasecmp(k,".con")) + { + COPYARG(i); + gamecon = (char *)argv[i++]; + continue; + } + } } + i++; } + + Bfree(lengths); + + if (j > 0) + { + testplay_addparam[j-1] = 0; + testplay_addparam = Brealloc(testplay_addparam, j*sizeof(char)); + } + else + { + Bfree(testplay_addparam); + testplay_addparam = NULL; + } + } #undef COPYARG diff --git a/polymer/eduke32/source/sounds_mapster32.c b/polymer/eduke32/source/sounds_mapster32.c index e73d5ee05..15b0ec22a 100644 --- a/polymer/eduke32/source/sounds_mapster32.c +++ b/polymer/eduke32/source/sounds_mapster32.c @@ -137,8 +137,8 @@ int32_t S_LoadSound(uint32_t num) return 0; } - if (g_sounds[num].filename1) fp = kopen4load(g_sounds[num].filename1,pathsearchmode); - if (fp == -1) fp = kopen4load(g_sounds[num].filename,pathsearchmode); + if (g_sounds[num].filename1) fp = kopen4loadfrommod(g_sounds[num].filename1,0);//pathsearchmode + if (fp == -1) fp = kopen4loadfrommod(g_sounds[num].filename,0); if (fp == -1) { OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n",g_sounds[num].filename,num);