int32_t texcache_loadoffsets(void) { int32_t foffset, fsize, i; char *fname; scriptfile *script; Bstrcpy(ptempbuf,TEXCACHEFILE); Bstrcat(ptempbuf,".cache"); script = scriptfile_fromfile(ptempbuf); if (!script) return -1; while (!scriptfile_eof(script)) { if (scriptfile_getstring(script, &fname)) break; // hashed filename if (scriptfile_getnumber(script, &foffset)) break; // offset in cache if (scriptfile_getnumber(script, &fsize)) break; // size i = hash_find(&texcache.hashes,fname); if (i > -1) { // update an existing entry texcacheindex *t = texcache.iptrs[i]; t->offset = foffset; t->len = fsize; /*initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, fname,foffset);*/ } else { Bstrncpyz(texcache.currentindex->name, fname, BMAX_PATH); texcache.currentindex->offset = foffset; texcache.currentindex->len = fsize; texcache.currentindex->next = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex)); hash_add(&texcache.hashes, fname, texcache.numentries, 1); if (++texcache.numentries > texcache.iptrcnt) { texcache.iptrcnt += 512; texcache.iptrs = (texcacheindex **) Xrealloc(texcache.iptrs, sizeof(intptr_t) * texcache.iptrcnt); } texcache.iptrs[texcache.numentries-1] = texcache.currentindex; texcache.currentindex = texcache.currentindex->next; } } scriptfile_close(script); return 0; }
int32_t startwin_run(void) { if (!gtkenabled) return 1; if (!stwidgets.startwin) return 1; SetPage(TAB_CONFIG); settings.xdim3d = ud.config.ScreenWidth; settings.ydim3d = ud.config.ScreenHeight; settings.bpp3d = ud.config.ScreenBPP; settings.fullscreen = ud.config.ScreenMode; settings.usemouse = ud.config.UseMouse; settings.usejoy = ud.config.UseJoystick; settings.custommoddir = g_modDir; settings.forcesetup = ud.config.ForceSetup; settings.game = g_gameType; Bstrncpyz(settings.selectedgrp, G_GrpFile(), BMAX_PATH); if (ud.config.NoAutoLoad) settings.autoload = FALSE; else settings.autoload = TRUE; #ifdef POLYMER if (glrendmode == REND_POLYMER) { if (settings.bpp3d == 8) settings.bpp3d = 32; settings.polymer = TRUE; } #endif PopulateForm(ALL); gtk_main(); SetPage(TAB_MESSAGES); if (retval) // launch the game with these parameters { ud.config.ScreenWidth = settings.xdim3d; ud.config.ScreenHeight = settings.ydim3d; ud.config.ScreenBPP = settings.bpp3d; ud.config.ScreenMode = settings.fullscreen; ud.config.UseMouse = settings.usemouse; ud.config.UseJoystick = settings.usejoy; ud.config.ForceSetup = settings.forcesetup; clearGrpNamePtr(); g_grpNamePtr = dup_filename(settings.selectedgrp); g_gameType = settings.game; if (settings.custommoddir != NULL) Bstrcpy(g_modDir, settings.custommoddir); else Bsprintf(g_modDir, "/"); if (settings.autoload) ud.config.NoAutoLoad = FALSE; else ud.config.NoAutoLoad = TRUE; { struct grpfile *grp; for (grp = listgrps; grp; grp=grp->next) if (settings.crcval == grp->crcval) break; if (grp) { g_gameNamePtr = grp->name; g_dependencyCRC = grp->dependency; if (grp->scriptname && g_scriptNamePtr == NULL) g_scriptNamePtr = dup_filename(grp->scriptname); if (grp->defname && g_defNamePtr == NULL) g_defNamePtr = dup_filename(grp->defname); } } } return retval; }
static void setErrorMessage(const char *msg) { Bstrncpyz(errorMessage, msg, sizeof(errorMessage)); }
int32_t startwin_run(void) { MSG msg; if (!startupdlg) return 1; done = -1; #ifdef JFAUD EnumAudioDevs(&wavedevs, NULL, NULL); #endif SetPage(TAB_CONFIG); EnableConfig(1); settings.flags = 0; if (ud.config.ScreenMode) settings.flags |= 1; #ifdef POLYMER if (glrendmode == REND_POLYMER) settings.flags |= 2; #endif if (ud.config.NoAutoLoad) settings.flags |= 4; settings.xdim = ud.config.ScreenWidth; settings.ydim = ud.config.ScreenHeight; settings.bpp = ud.config.ScreenBPP; settings.forcesetup = ud.config.ForceSetup; settings.usemouse = ud.config.UseMouse; settings.usejoy = ud.config.UseJoystick; settings.game = g_gameType; // settings.crcval = 0; Bstrncpyz(settings.selectedgrp, G_GrpFile(), BMAX_PATH); settings.gamedir = g_modDir; PopulateForm(-1); while (done < 0) { switch (GetMessage(&msg, NULL, 0,0)) { case 0: done = 1; break; case -1: return -1; default: if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break; TranslateMessage(&msg); DispatchMessage(&msg); break; } } SetPage(TAB_MESSAGES); EnableConfig(0); if (done) { ud.config.ScreenMode = (settings.flags&1); #ifdef POLYMER if (settings.flags & 2) glrendmode = REND_POLYMER; else glrendmode = REND_POLYMOST; #endif if (settings.flags & 4) ud.config.NoAutoLoad = 1; else ud.config.NoAutoLoad = 0; ud.config.ScreenWidth = settings.xdim; ud.config.ScreenHeight = settings.ydim; ud.config.ScreenBPP = settings.bpp; ud.config.ForceSetup = settings.forcesetup; ud.config.UseMouse = settings.usemouse; ud.config.UseJoystick = settings.usejoy; clearGrpNamePtr(); g_grpNamePtr = dup_filename(settings.selectedgrp); g_gameType = settings.game; if (g_noSetup == 0 && settings.gamedir != NULL) Bstrcpy(g_modDir,settings.gamedir); else Bsprintf(g_modDir,"/"); { struct grpfile *grp; for (grp = listgrps; grp; grp=grp->next) if (settings.crcval == grp->crcval) break; if (grp) { g_gameNamePtr = grp->name; g_dependencyCRC = grp->dependency; if (grp->scriptname && g_scriptNamePtr == NULL) g_scriptNamePtr = dup_filename(grp->scriptname); if (grp->defname && g_defNamePtr == NULL) g_defNamePtr = dup_filename(grp->defname); } } } if (wavedevs) { struct audioenumdev *d, *e; Bfree(wavedevs->drvs); for (e=wavedevs->devs; e; e=d) { d = e->next; if (e->devs) Bfree(e->devs); Bfree(e); } Bfree(wavedevs); } return done; }
int32_t loadsetup(const char *fn) { BFILE *fp; #define VL 1024 char val[VL]; int32_t i; if ((fp = Bfopen(fn, "rt")) == NULL) return -1; if (readconfig(fp, "forcesetup", val, VL) > 0) { if (atoi_safe(val) != 0) forcesetup = 1; else forcesetup = 0; } if (readconfig(fp, "fullscreen", val, VL) > 0) { if (atoi_safe(val) != 0) fullscreen = 1; else fullscreen = 0; } if (readconfig(fp, "resolution", val, VL) > 0) { i = atoi_safe(val) & 0x0f; if ((unsigned)i<13) { xdimgame = xdim2d = vesares[i][0]; ydimgame = ydim2d = vesares[i][1]; } } if (readconfig(fp, "2dresolution", val, VL) > 0) { i = atoi_safe(val) & 0x0f; if ((unsigned)i<13) { xdim2d = vesares[i][0]; ydim2d = vesares[i][1]; } } if (readconfig(fp, "xdim2d", val, VL) > 0) xdim2d = atoi_safe(val); if (readconfig(fp, "ydim2d", val, VL) > 0) ydim2d = atoi_safe(val); if (readconfig(fp, "xdim3d", val, VL) > 0) xdimgame = atoi_safe(val); if (readconfig(fp, "ydim3d", val, VL) > 0) ydimgame = atoi_safe(val); // if (readconfig(fp, "samplerate", val, VL) > 0) option[7] = (atoi_safe(val) & 0x0f) << 4; // if (readconfig(fp, "music", val, VL) > 0) { if (atoi_safe(val) != 0) option[2] = 1; else option[2] = 0; } // if (readconfig(fp, "mouse", val, VL) > 0) { if (atoi_safe(val) != 0) option[3] = 1; else option[3] = 0; } if (readconfig(fp, "bpp", val, VL) > 0) bppgame = atoi_safe(val); if (readconfig(fp, "vsync", val, VL) > 0) vsync = !!atoi_safe(val); if (readconfig(fp, "editorgridextent", val, VL) > 0) { int32_t tmp = atoi_safe(val); editorgridextent = clamp(tmp, 65536, BXY_MAX); } if (readconfig(fp, "grid", val, VL) > 0) { grid = atoi_safe(val); default_grid = grid; autogrid = (grid==9); grid = clamp(grid, 0, 8); } #ifdef POLYMER if (readconfig(fp, "rendmode", val, VL) > 0) { i = atoi_safe(val); glrendmode = i; } #endif if (readconfig(fp, "vid_gamma", val, VL) > 0) vid_gamma = clampd(Bstrtod(val, NULL), 0.0, 10.0); if (readconfig(fp, "vid_brightness", val, VL) > 0) vid_brightness = clampd(Bstrtod(val, NULL), 0.0, 10.0); if (readconfig(fp, "vid_contrast", val, VL) > 0) vid_contrast = clampd(Bstrtod(val, NULL), 0.0, 10.0); #ifdef RENDERTYPEWIN if (readconfig(fp, "maxrefreshfreq", val, VL) > 0) maxrefreshfreq = atoi_safe(val); #endif #ifdef USE_OPENGL if (readconfig(fp, "usemodels", val, VL) > 0) usemodels = !!atoi_safe(val); if (readconfig(fp, "usehightile", val, VL) > 0) usehightile = !!atoi_safe(val); if (readconfig(fp, "lazytileselector", val, VL) > 0) g_lazy_tileselector = !!atoi_safe(val); glusetexcache = -1; if (readconfig(fp, "glusetexcache", val, VL) > 0) { glusetexcache = clamp(atoi_safe(val), 0, 2); } if (readconfig(fp, "glusememcache", val, VL) > 0) { glusememcache = !!atoi_safe(val); } if (readconfig(fp, "gltexfiltermode", val, VL) > 0) { gltexfiltermode = atoi_safe(val); } if (readconfig(fp, "glanisotropy", val, VL) > 0) { glanisotropy = atoi_safe(val); } if (readconfig(fp, "r_downsize", val, VL) > 0) { r_downsize = atoi_safe(val); r_downsize = clamp(r_downsize, 0, 5); r_downsizevar = r_downsize; } if (readconfig(fp, "r_texcompr", val, VL) > 0) glusetexcompr = !!atoi_safe(val); if (readconfig(fp, "r_shadescale", val, VL) > 0) shadescale = clampd(Bstrtod(val, NULL), 0.0, 10.0); if (readconfig(fp, "r_usenewshading", val, VL) > 0) r_usenewshading = clamp(atoi_safe(val), 0, 2); #endif if (readconfig(fp, "r_usenewaspect", val, VL) > 0) r_usenewaspect = !!atoi_safe(val); #ifndef RENDERTYPEWIN if (readconfig(fp, "r_screenxy", val, VL) > 0) { r_screenxy = clamp(atoi_safe(val), 0, 9999); if (r_screenxy/100==0 || r_screenxy%100==0) r_screenxy = 403; } #endif if (readconfig(fp, "gameexecutable", val, VL) > 0) Bstrcpy(game_executable, val); // option[0] = 1; // vesa all the way... // option[1] = 1; // sound all the way... // option[4] = 0; // no multiplayer // option[5] = 0; #if 1 if (readconfig(fp, "keyforward", val, VL) > 0) keys[0] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keybackward", val, VL) > 0) keys[1] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyturnleft", val, VL) > 0) keys[2] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyturnright", val, VL) > 0) keys[3] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyrun", val, VL) > 0) keys[4] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keystrafe", val, VL) > 0) keys[5] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyfire", val, VL) > 0) keys[6] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyuse", val, VL) > 0) keys[7] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keystandhigh", val, VL) > 0) keys[8] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keystandlow", val, VL) > 0) keys[9] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keylookup", val, VL) > 0) keys[10] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keylookdown", val, VL) > 0) keys[11] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keystrafeleft", val, VL) > 0) keys[12] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keystraferight", val, VL) > 0) keys[13] = Bstrtol(val, NULL, 16); if (readconfig(fp, "key2dmode", val, VL) > 0) keys[14] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keyviewcycle", val, VL) > 0) keys[15] = Bstrtol(val, NULL, 16); if (readconfig(fp, "key2dzoomin", val, VL) > 0) keys[16] = Bstrtol(val, NULL, 16); if (readconfig(fp, "key2dzoomout", val, VL) > 0) keys[17] = Bstrtol(val, NULL, 16); if (readconfig(fp, "keychat", val, VL) > 0) keys[18] = Bstrtol(val, NULL, 16); #endif #ifdef RENDERTYPEWIN if (readconfig(fp, "windowpositioning", val, VL) > 0) windowpos = atoi_safe(val); windowx = -1; if (readconfig(fp, "windowposx", val, VL) > 0) windowx = atoi_safe(val); windowy = -1; if (readconfig(fp, "windowposy", val, VL) > 0) windowy = atoi_safe(val); #endif if (readconfig(fp, "keyconsole", val, VL) > 0) { keys[19] = Bstrtol(val, NULL, 16); OSD_CaptureKey(keys[19]); } if (readconfig(fp, "mousesensitivity", val, VL) > 0) msens = Bstrtod(val, NULL); if (readconfig(fp, "mousenavigation", val, VL) > 0) unrealedlook = !!atoi_safe(val); if (readconfig(fp, "mousenavigationaccel", val, VL) > 0) pk_uedaccel = atoi_safe(val); if (readconfig(fp, "quickmapcycling", val, VL) > 0) quickmapcycling = !!atoi_safe(val); if (readconfig(fp, "sideview_reversehorizrot", val, VL) > 0) sideview_reversehrot = !!atoi_safe(val); if (readconfig(fp, "revertCTRL", val, VL) > 0) revertCTRL = !!atoi_safe(val); if (readconfig(fp, "scrollamount", val, VL) > 0) scrollamount = atoi_safe(val); if (readconfig(fp, "turnaccel", val, VL) > 0) pk_turnaccel = atoi_safe(val); if (readconfig(fp, "turndecel", val, VL) > 0) pk_turndecel = atoi_safe(val); if (readconfig(fp, "autosavesec", val, VL) > 0) autosave = max(0, atoi_safe(val)); if (readconfig(fp, "autocorruptchecksec", val, VL) > 0) autocorruptcheck = max(0, atoi_safe(val)); if (readconfig(fp, "corruptcheck_noalreadyrefd", val, VL) > 0) corruptcheck_noalreadyrefd = !!atoi_safe(val); if (readconfig(fp, "fixmaponsave_sprites", val, VL) > 0) fixmaponsave_sprites = !!atoi_safe(val); if (readconfig(fp, "keeptexturestretch", val, VL) > 0) keeptexturestretch = !!atoi_safe(val); if (readconfig(fp, "showheightindicators", val, VL) > 0) showheightindicators = clamp(atoi_safe(val), 0, 2); if (readconfig(fp, "showambiencesounds", val, VL) > 0) showambiencesounds = clamp(atoi_safe(val), 0, 2); if (readconfig(fp, "autogray", val, VL) > 0) autogray = !!atoi_safe(val); // if (readconfig(fp, "showinnergray", val, VL) > 0) // showinnergray = !!atoi_safe(val); if (readconfig(fp, "graphicsmode", val, VL) > 0) graphicsmode = clamp(atoi_safe(val), 0, 2); if (readconfig(fp, "samplerate", val, VL) > 0) MixRate = clamp(atoi_safe(val), 8000, 48000); if (readconfig(fp, "ambiencetoggle", val, VL) > 0) AmbienceToggle = !!atoi_safe(val); if (readconfig(fp, "parlock", val, VL) > 0) ParentalLock = !!atoi_safe(val); if (readconfig(fp, "osdtryscript", val, VL) > 0) m32_osd_tryscript = !!atoi_safe(val); for (i=0; i<256; i++) remap[i]=i; remapinit=1; if (readconfig(fp, "remap", val, VL) > 0) { char *p=val; int32_t v1,v2; while (*p) { if (!sscanf(p,"%x",&v1))break; if ((p=strchr(p,'-'))==0)break; p++; if (!sscanf(p,"%x",&v2))break; remap[v1]=v2; initprintf("Remap %X key to %X\n",v1,v2); if ((p=strchr(p,','))==0)break; p++; } } // load m32script history for (i=0; i<SCRIPTHISTSIZ; i++) { Bsprintf(val, "hist%d", i); if (readconfig(fp, val, val, VL) <= 0) break; scripthist[i] = Bstrdup(val); } scripthistend = i; // copy script history into OSD history for (i=0; i<min(scripthistend, OSD_HISTORYDEPTH); i++) { Bstrncpyz(osdhistorybuf[i], scripthist[scripthistend-1-i], OSD_EDITLENGTH+1); osdhistorysize++; osdhistorytotal++; } scripthistend %= SCRIPTHISTSIZ; Bfclose(fp); return 0; }
int32_t CONFIG_ReadSetup(void) { int32_t dummy, i = 0; char commmacro[] = "CommbatMacro# "; char tempbuf[1024]; CONTROL_ClearAssignments(); CONFIG_SetDefaults(); ud.config.setupread = 1; pathsearchmode = 1; #ifndef EDUKE32_TOUCH_DEVICES if (SafeFileExists(setupfilename) && ud.config.scripthandle < 0) // JBF 20031211 ud.config.scripthandle = SCRIPT_Load(setupfilename); else if (SafeFileExists(SETUPFILENAME) && ud.config.scripthandle < 0) { i=wm_ynbox("Import Configuration Settings", "The configuration file \"%s\" was not found. " "Import configuration data from \"%s\"?",setupfilename,SETUPFILENAME); if (i) ud.config.scripthandle = SCRIPT_Load(SETUPFILENAME); } else if (SafeFileExists("duke3d.cfg") && ud.config.scripthandle < 0) { i=wm_ynbox("Import Configuration Settings", "The configuration file \"%s\" was not found. " "Import configuration data from \"duke3d.cfg\"?",setupfilename); if (i) ud.config.scripthandle = SCRIPT_Load("duke3d.cfg"); } #endif pathsearchmode = 0; if (ud.config.scripthandle < 0) return -1; if (ud.config.scripthandle >= 0) { char dummybuf[64]; for (dummy = 0; dummy < MAXRIDECULE; dummy++) { commmacro[13] = dummy+'0'; SCRIPT_GetString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]); } Bmemset(tempbuf, 0, sizeof(tempbuf)); // Bmemset(dummybuf, 0, sizeof(dummybuf)); SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]); while (Bstrlen(OSD_StripColors(dummybuf,tempbuf)) > 10) tempbuf[Bstrlen(tempbuf)-1] = '\0'; Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName)); if (g_rtsNamePtr == NULL) SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]); SCRIPT_GetNumber(ud.config.scripthandle, "Setup","ConfigVersion",&ud.configversion); SCRIPT_GetNumber(ud.config.scripthandle, "Setup","ForceSetup",&ud.config.ForceSetup); SCRIPT_GetNumber(ud.config.scripthandle, "Setup","NoAutoLoad",&ud.config.NoAutoLoad); // #ifdef _WIN32 if (g_noSetup == 0 && g_modDir[0] == '/') { struct Bstat st; SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]); if (Bstat(g_modDir, &st)) { if ((st.st_mode & S_IFDIR) != S_IFDIR) { initprintf("Invalid mod dir in cfg!\n"); Bsprintf(g_modDir,"/"); } } } // #endif if (g_grpNamePtr == NULL && g_usingAddon == 0) { SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup","SelectedGRP",&g_grpNamePtr); if (g_grpNamePtr && !Bstrlen(g_grpNamePtr)) g_grpNamePtr = dup_filename(G_DefaultGrpFile()); } if (!NAM) { SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out",&ud.lockout); SCRIPT_GetString(ud.config.scripthandle, "Screen Setup","Password",&ud.pwlockout[0]); } SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",&ud.config.ScreenHeight); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",&ud.config.ScreenMode); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",&ud.config.ScreenWidth); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos); windowx = -1; SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx); windowy = -1; SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy); #ifdef RENDERTYPEWIN SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq); #endif SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.config.ScreenBPP); if (ud.config.ScreenBPP < 8) ud.config.ScreenBPP = 32; #ifdef POLYMER SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &dummy); if (dummy > 0 && ud.config.ScreenBPP >= 16) glrendmode = REND_POLYMER; else glrendmode = REND_POLYMOST; #endif /* SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Color",&ud.color); G_CheckPlayerColor((int32_t *)&ud.color,-1); g_player[0].ps->palookup = g_player[0].pcolor = ud.color; tempbuf[0] = 0; */ SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions",&ud.executions); #ifdef _WIN32 SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates); SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck); #endif } //CONFIG_SetupMouse(ud.config.scripthandle); //CONFIG_SetupJoystick(ud.config.scripthandle); ud.config.setupread = 1; return 0; }