/////////////////////////////////////////////////////////////////////////// // // USL_ReadConfig() - Reads the configuration file, if present, and sets // things up accordingly. If it's not present, uses defaults. This file // includes the high scores. // /////////////////////////////////////////////////////////////////////////// static void USL_ReadConfig(void) { boolean gotit; char sig[sizeof(EXT)]; word version; int file; SDMode sd; SMMode sm; ControlType ctl; if ((file = open("CONFIG."EXT,O_BINARY | O_RDONLY)) != -1) { read(file,sig,sizeof(EXT)); read(file,&version,sizeof(version)); if (strcmp(sig,EXT) || (version != ConfigVersion)) { close(file); goto rcfailed; } read(file,Scores,sizeof(HighScore) * MaxScores); read(file,&sd,sizeof(sd)); read(file,&sm,sizeof(sm)); read(file,&ctl,sizeof(ctl)); read(file,&(KbdDefs[0]),sizeof(KbdDefs[0])); read(file,&showscorebox,sizeof(showscorebox)); read(file,&compatability,sizeof(compatability)); #ifdef KEEN read(file,&oldshooting,sizeof(oldshooting)); read(file,&firescan,sizeof(firescan)); #endif close(file); HighScoresDirty = false; gotit = true; } else { rcfailed: sd = sdm_Off; sm = smm_Off; ctl = ctrl_Keyboard; showscorebox = true; #ifdef KEEN oldshooting = false; #endif gotit = false; HighScoresDirty = true; } SD_Default(gotit,sd,sm); IN_Default(gotit,ctl); }
void US_LoadConfig(void) { int16_t inputDevice, configRev; SDMode sd; SMMode sm; bool hadAdlib = false; // Originally this is not set to 0 directly char fileExt[4]; const char *fileName = CAL_AdjustExtension("CONFIG.EXT"); bool configFileLoaded; FILE *f = fopen(fileName, "rb"); if (f) { CK_Cross_freadInt8LE(fileExt, sizeof(fileExt), f); CK_Cross_freadInt16LE(&configRev, 1, f); // FIXME: Dangerous function call comes here (to strcmp) // (but true to the original and effectively safe) if (strcmp(fileExt, ck_currentEpisode->ext) || (configRev != 4)) { fclose(f); f = NULL; } } if (f) { int16_t intVal; // High scores table (an array of structs) for (int i = 0; i < 8; i++) { CK_Cross_freadInt8LE(ck_highScores[i].name, sizeof(ck_highScores[i].name), f); CK_Cross_freadInt32LE(&ck_highScores[i].score, 1, f); CK_Cross_freadInt16LE(&ck_highScores[i].arg4, 1, f); } if (CK_Cross_freadInt16LE(&intVal, 1, f)) sd = (SDMode)intVal; if (CK_Cross_freadInt16LE(&intVal, 1, f)) sm = (SMMode)intVal; CK_Cross_freadInt16LE(&inputDevice, 1, f); // Read most of in_kbdControls one-by-one (it's a struct): // - No fire key for now. CK_Cross_freadInt8LE(&in_kbdControls.jump, 1, f); CK_Cross_freadInt8LE(&in_kbdControls.pogo, 1, f); CK_Cross_freadInt8LE(&in_kbdControls.upLeft, 1, f); CK_Cross_freadInt8LE(&in_kbdControls.up, 1, f); CK_Cross_freadInt8LE(&in_kbdControls.upRight, 1, f); CK_Cross_freadInt8LE(&in_kbdControls.left, 1, f); CK_Cross_freadInt8LE(&in_kbdControls.right, 1, f); CK_Cross_freadInt8LE(&in_kbdControls.downLeft, 1, f); CK_Cross_freadInt8LE(&in_kbdControls.down, 1, f); CK_Cross_freadInt8LE(&in_kbdControls.downRight, 1, f); CK_Cross_freadBoolFrom16LE(&ck_scoreBoxEnabled, 1, f); CK_Cross_freadBoolFrom16LE(&ck_svgaCompatibility, 1, f); CK_Cross_freadBoolFrom16LE(&quiet_sfx, 1, f); CK_Cross_freadBoolFrom16LE(&hadAdlib, 1, f); CK_Cross_freadBoolFrom16LE(&ck_fixJerkyMotion, 1, f); CK_Cross_freadBoolFrom16LE(&ck_twoButtonFiring, 1, f); // Now the fire key comes CK_Cross_freadInt8LE(&in_kbdControls.fire, 1, f); CK_Cross_freadBoolFrom16LE(&ck_gamePadEnabled, 1, f); CK_Cross_freadInt16LE(in_gamepadButtons, 4, f); fclose(f); //ck_highScoresDirty = 0; // Unused? configFileLoaded = true; } else { sd = sdm_Off; sm = smm_Off; inputDevice = 0; ck_scoreBoxEnabled = true; ck_twoButtonFiring = false; configFileLoaded = false; //ck_highScoresDirty = 1; // Unused? } SD_Default(configFileLoaded && (hadAdlib == AdLibPresent), sd, sm); IN_Default(configFileLoaded, inputDevice); }