static void CommandSetNights(string[] parameters) { try { int map = int.Parse(parameters[0]) - 1; if (map < 0 || map >= NUMMAPS) { Console.WriteLine("Couldn't find the map {0}. Please select a map between 1 and {1}", map + 1, NUMMAPS); return; } byte numMares = byte.Parse(parameters[1]); nightsrecords[map] = new NightsRecord(); nightsrecords[map].nummares = (byte)(numMares); nightsrecords[map].mares = new Mare[numMares + 1]; for (byte i = 0; i < numMares; i++) { nightsrecords[map].mares[i] = new Mare(); Console.WriteLine("Mare {0}:", i); GetUInt32("Score: ", ref nightsrecords[map].mares[i].score); GetByte("Grade (0-6): ", ref nightsrecords[map].mares[i].grade); GetUInt32("Time: ", ref nightsrecords[map].mares[i].time); } Mare emptyMare = new Mare(); emptyMare.score = 0; emptyMare.grade = 0; emptyMare.time = 0; nightsrecords[map].mares[numMares] = emptyMare; } catch (FormatException e) { Console.WriteLine("{0}: {1}", e.Data.GetType().ToString(), e.Message); } }
static void CommandUnlockAll(string[] parameters) { totalplaytime = 0; // total play time (separate from all) modified = 0; SetArray(ref mapvisited, MV_MAX); SetArray(ref emblemlocations, 1); SetArray(ref extraemblems, 1); SetArray(ref unlockables, 1); SetArray(ref conditionSets, 1); timesBeaten = UInt32.MaxValue; timesBeatenWithEmeralds = UInt32.MaxValue; timesBeatenUltimate = UInt32.MaxValue; for (int i = 0; i < NUMMAPS; ++i) { if (mainrecords[i] == null) { mainrecords[i] = new Record(); } mainrecords[i].score = MAXSCORE; mainrecords[i].time = 1; mainrecords[i].rings = 10000; } // Let's assume there aren't any nights maps after 200 for (int i = 0; i < 200; ++i) { if (nightsrecords[i] == null) { nightsrecords[i] = new NightsRecord(); } byte nummares = 4; // 4 at most nightsrecords[i].mares = new Mare[nummares + 1]; for (int curmare = 0; curmare < (nummares + 1); ++curmare) { Mare mare = new Mare(); mare.score = MAXSCORE; mare.grade = GRADE_S; mare.time = 1; nightsrecords[i].mares[curmare] = mare; } nightsrecords[i].nummares = nummares; } }
static void CommandClearAll(string[] parameters) { G_ClearRecords(); // main and nights records M_ClearSecrets(); // emblems, unlocks, maps visited, etc totalplaytime = 0; // total play time (separate from all) modified = 0; SetArray(ref mapvisited, 0); SetArray(ref emblemlocations, 0); SetArray(ref extraemblems, 0); SetArray(ref unlockables, 0); SetArray(ref conditionSets, 0); timesBeaten = 0; timesBeatenWithEmeralds = 0; timesBeatenUltimate = 0; for (int i = 0; i < NUMMAPS; ++i) { //if (recrings > 10000 || recscore > MAXSCORE) if (mainrecords[i] == null) { mainrecords[i] = new Record(); } mainrecords[i].score = 0; mainrecords[i].time = 0; mainrecords[i].rings = 0; } for (int i = 0; i < NUMMAPS; ++i) { if (nightsrecords[i] == null) { nightsrecords[i] = new NightsRecord(); } nightsrecords[i].mares = new Mare[0]; } }
static void CommandRecordInfo(string[] parameters) { Console.WriteLine("mainrecords/nightsrecords: "); for (int i = 0; i < NUMMAPS; i++) { Record record = mainrecords[i]; NightsRecord nightsRecord = nightsrecords[i]; if (record != null && (record.score != 0 || record.time != 0 || record.rings != 0)) { Console.WriteLine("Map {0}: Score: {1}, Time: {2}, Rings: {3}", i + 1, record.score, record.time, record.rings); } if (nightsrecords[i] != null && nightsrecords[i].nummares != 0) { Console.Write("Map: {0}: ", i + 1); for (int j = 0; j < nightsRecord.nummares; j++) { Mare mare = nightsRecord.mares[j]; Console.Write("Mare {0}: Score: {1}, Grade: {2}, Time: {3}, ", j, mare.score, mare.grade, mare.time); } Console.WriteLine(); } } }
static void G_LoadGameData() { int length; Int32 i, j; byte rtemp; //For records UInt32 recscore; UInt32 rectime; UInt16 recrings; byte recmares; Int32 curmare; // Clear things so previously read gamedata doesn't transfer // to new gamedata G_ClearRecords(); // main and nights records M_ClearSecrets(); // emblems, unlocks, maps visited, etc totalplaytime = 0; // total play time (separate from all) byte[] bytes; try { bytes = File.ReadAllBytes(gamedatafilename); } catch (IOException e) { Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message); return; } length = bytes.Length; if (length == 0) // Aw, no game data. Their loss! { return; } SaveBuffer save_p = new SaveBuffer(bytes); // Version check if (save_p.READUINT32() != 0xFCAFE211) { Console.WriteLine("Game data is from another version of SRB2.\nDelete {0} and try again.", gamedatafilename); } totalplaytime = save_p.READUINT32(); modified = save_p.READUINT8(); // Aha! Someone's been screwing with the save file! if ((modified == 1)) { Console.WriteLine("Warning, the game data is modified. If this gamedata doesn't belong to a mod, you're screwed."); } else if (modified != 1 && modified != 0) { goto datacorrupt; } // TODO put another cipher on these things? meh, I don't care... for (i = 0; i < NUMMAPS; i++) { if ((mapvisited[i] = save_p.READUINT8()) > MV_MAX) { goto datacorrupt; } } // To save space, use one bit per collected/achieved/unlocked flag for (i = 0; i < MAXEMBLEMS;) { rtemp = save_p.READUINT8(); for (j = 0; j < 8 && j + i < MAXEMBLEMS; ++j) { emblemlocations[j + i] = (byte)((rtemp >> j) & 1); } i += j; } for (i = 0; i < MAXEXTRAEMBLEMS;) { rtemp = save_p.READUINT8(); for (j = 0; j < 8 && j + i < MAXEXTRAEMBLEMS; ++j) { extraemblems[j + i] = (byte)((rtemp >> j) & 1); } i += j; } for (i = 0; i < MAXUNLOCKABLES;) { rtemp = save_p.READUINT8(); for (j = 0; j < 8 && j + i < MAXUNLOCKABLES; ++j) { unlockables[j + i] = (byte)((rtemp >> j) & 1); } i += j; } for (i = 0; i < MAXCONDITIONSETS;) { rtemp = save_p.READUINT8(); for (j = 0; j < 8 && j + i < MAXCONDITIONSETS; ++j) { conditionSets[j + i] = (byte)((rtemp >> j) & 1); } i += j; } timesBeaten = save_p.READUINT32(); timesBeatenWithEmeralds = save_p.READUINT32(); timesBeatenUltimate = save_p.READUINT32(); // Main records for (i = 0; i < NUMMAPS; ++i) { recscore = save_p.READUINT32(); rectime = save_p.READUINT32(); recrings = save_p.READUINT16(); //save_p++; // compat save_p.READUINT8(); if (recrings > 10000 || recscore > MAXSCORE) { goto datacorrupt; } if (mainrecords[i] == null) { mainrecords[i] = new Record(); } mainrecords[i].score = recscore; mainrecords[i].time = rectime; mainrecords[i].rings = recrings; } // Nights records for (i = 0; i < NUMMAPS; ++i) { if (nightsrecords[i] == null) { nightsrecords[i] = new NightsRecord(); } if ((recmares = save_p.READUINT8()) == 0) { continue; } nightsrecords[i].mares = new Mare[recmares + 1]; for (curmare = 0; curmare < (recmares + 1); ++curmare) { if (nightsrecords[i].mares[curmare] == null) { nightsrecords[i].mares[curmare] = new Mare(); } nightsrecords[i].mares[curmare].score = save_p.READUINT32(); nightsrecords[i].mares[curmare].grade = save_p.READUINT8(); nightsrecords[i].mares[curmare].time = save_p.READUINT32(); if (nightsrecords[i].mares[curmare].grade > GRADE_S) { goto datacorrupt; } } nightsrecords[i].nummares = recmares; } save_p = null; return; // Landing point for corrupt gamedata datacorrupt: { Console.WriteLine("Corrupt game data file.\nDelete {0} and try again.", gamedatafilename); } }