// Evil and Nasty Configuration File Reader for KenBuild // by Jonathon Fowler #include "compat.h" #include "build.h" #include "editor.h" #include "osd.h" #include "baselayer.h" #include "renderlayer.h" static int32_t vesares[13][2] = {{320,200},{360,200},{320,240},{360,240},{320,400}, {360,400},{640,350},{640,400},{640,480},{800,600}, {1024,768},{1280,1024},{1600,1200} }; static double clampd(double d, double mind, double maxd) { if (d != d || dmaxd) d = maxd; return d; } static int32_t readconfig(BFILE *fp, const char *key, char *value, uint32_t len) { char buf[1000], *k, *v, *eq; int32_t x=0; if (len < 1) return 0; Brewind(fp); while (1) { if (!Bfgets(buf, 1000, fp)) return 0; if (buf[0] == ';') continue; eq = Bstrchr(buf, '='); if (!eq) continue; k = buf; v = eq+1; while (*k == ' ' || *k == '\t') k++; *(eq--) = 0; while ((*eq == ' ' || *eq == '\t') && eq>=k) *(eq--) = 0; if (Bstrcasecmp(k, key)) continue; while (*v == ' ' || *k == '\t') v++; eq = v + Bstrlen(v)-1; while ((*eq == ' ' || *eq == '\t' || *eq == '\r' || *eq == '\n') && eq>=v) *(eq--) = 0; value[--len] = 0; do value[x] = v[x]; while (v[x++] != 0 && len-- > 0); return x-1; } } extern int16_t brightness; #ifdef USE_OPENGL extern int32_t vsync; #endif extern char game_executable[BMAX_PATH]; extern int32_t fullscreen; extern char default_buildkeys[NUMBUILDKEYS]; static char *const keys = default_buildkeys; static int32_t default_grid=3; extern int32_t AmbienceToggle, MixRate; extern int32_t ParentalLock; /* * SETUP.DAT * 0 = video mode (0:chained 1:vesa 2:screen buffered 3/4/5:tseng/paradise/s3 6:red-blue) * 1 = sound (0:none) * 2 = music (0:none) * 3 = input (0:keyboard 1:+mouse) * 4 = multiplayer (0:single 1-4:com 5-11:ipx) * 5&0xf0 = com speed * 5&0x0f = com irq * 6&0xf0 = chained y-res * 6&0x0f = chained x-res or vesa mode * 7&0xf0 = sound samplerate * 7&0x01 = sound quality * 7&0x02 = 8/16 bit * 7&0x04 = mono/stereo * * bytes 8 to 26 are key settings: * 0 = Forward (0xc8) * 1 = Backward (0xd0) * 2 = Turn left (0xcb) * 3 = Turn right (0xcd) * 4 = Run (0x2a) * 5 = Strafe (0x9d) * 6 = Fire (0x1d) * 7 = Use (0x39) * 8 = Stand high (0x1e) * 9 = Stand low (0x2c) * 10 = Look up (0xd1) * 11 = Look down (0xc9) * 12 = Strafe left (0x33) * 13 = Strafe right (0x34) * 14 = 2D/3D switch (0x9c) * 15 = View cycle (0x1c) * 16 = 2D Zoom in (0xd) * 17 = 2D Zoom out (0xc) * 18 = Chat (0xf) */ 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); #ifdef USE_OPENGL if (readconfig(fp, "vsync", val, VL) > 0) vsync = !!atoi_safe(val); #endif 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); if (readconfig(fp, "r_usetileshades", val, VL) > 0) r_usetileshades = !!atoi_safe(val); # ifdef POLYMER if (readconfig(fp, "r_pr_artmapping", val, VL) > 0) pr_artmapping = !!atoi_safe(val); # endif #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