public GBAGameSave(string filePath, GameTypes gameType = GameTypes.Any, bool japanese = false) { this.gameType = gameType; this.japanese = japanese; //try { this.raw = File.ReadAllBytes(filePath); this.saveData = new GBASaveData[2]; if (raw.Length == 131072 || raw.Length == 139264) { if (!ByteHelper.CompareBytes(0, ByteHelper.SubByteArray(4092, raw, 4))) { saveData[0] = new GBASaveData(this, ByteHelper.SubByteArray(0, raw, 57344)); } if (!ByteHelper.CompareBytes(0, ByteHelper.SubByteArray(57344 + 4092, raw, 4))) { saveData[1] = new GBASaveData(this, ByteHelper.SubByteArray(57344, raw, 57344)); } is128KbSave = true; } else if (raw.Length == 65536) { saveData[0] = new GBASaveData(this, ByteHelper.SubByteArray(0, raw, 57344)); is128KbSave = false; } if (this.gameType == GameTypes.Any) { // The User will pick the proper game type later if (MostRecentSave.BlockDataCollection.GameCode == GameCodes.RubySapphire) { this.gameType = GameTypes.Ruby; } else if (MostRecentSave.BlockDataCollection.GameCode == GameCodes.Emerald) { this.gameType = GameTypes.Emerald; } else if (MostRecentSave.BlockDataCollection.GameCode == GameCodes.FireRedLeafGreen) { this.gameType = GameTypes.FireRed; } } PokePC.ApplyGameType(this.gameType); loaded = true; //} //catch (Exception) { //throw new Exception("An error occurred with the save file. It seems that the program cannot read the supplied save file. Please load a 128KB save file for Generation 3 pokemon games."); //} }
public PokemonBoxGameSave(string filePath, bool japanese = false) { byte[] data = File.ReadAllBytes(filePath); this.loaded = false; this.hasGCIData = false; this.japanese = japanese; if (data.Length == 483328 || data.Length == 483392) { if (data.Length == 483392) { this.hasGCIData = true; } } else { throw new Exception("Pokemon Box saves must be either 483,328 or 483,392 bytes in length"); } int start = 0x2000 + (hasGCIData ? 64 : 0); this.saveData = new PokemonBoxSaveData[2]; List <PokemonBoxBlockData> blocks = new List <PokemonBoxBlockData>(); for (int i = 0; start + 0x2000 * (i + 1) <= data.Length; i++) { //blocks.Add(new PokemonBoxBlockData(ByteHelper.SubByteArray(start + 0x2000 * i, data, 0x2E000))); } if (BigEndian.ToSInt32(data, start + 0x8) != 0) { this.saveData[0] = new PokemonBoxSaveData(this, ByteHelper.SubByteArray(start, data, 0x2E000)); } if (BigEndian.ToSInt32(data, start + 0x2E000 + 0x8) != 0) { this.saveData[1] = new PokemonBoxSaveData(this, ByteHelper.SubByteArray(start + 0x2E000, data, 0x2E000)); } PokePC.ApplyGameType(GameTypes.PokemonBox); this.raw = data; this.loaded = true; }
public GCGameSave(string filePath, bool japanese = false) { byte[] data = File.ReadAllBytes(filePath); this.hasGCIData = false; this.gameType = GameTypes.Any; this.japanese = japanese; // GCI Data is 64 bytes in length if (data.Length == 393216 || data.Length == 393280) { if (data.Length == 393280) { hasGCIData = true; } gameType = GameTypes.Colosseum; } else if (data.Length == 352256 || data.Length == 352320) { if (data.Length == 352320) { hasGCIData = true; } gameType = GameTypes.XD; } else { throw new Exception("GameCube save data must be 393,216 or 393,280 bytes in length for Colosseum, and 352,256 or 352,320 bytes in length for XD"); } // First 24,576 bytes are for the gamecube memory card manager, such as name and icon int start = 24576 + (hasGCIData ? 64 : 0); if (gameType == GameTypes.Colosseum) { this.saveData = new GCSaveData[3]; if (!ByteHelper.CompareBytes(255, ByteHelper.SubByteArray(start + 0x1dfec, data, 20))) { this.saveData[0] = new GCSaveData(this, ByteHelper.SubByteArray(start, data, 122880)); } if (!ByteHelper.CompareBytes(255, ByteHelper.SubByteArray(start + 122880 + 0x1dfec, data, 20))) { this.saveData[1] = new GCSaveData(this, ByteHelper.SubByteArray(start + 122880, data, 122880)); } if (!ByteHelper.CompareBytes(255, ByteHelper.SubByteArray(start + 122880 * 2 + 0x1dfec, data, 20))) { this.saveData[2] = new GCSaveData(this, ByteHelper.SubByteArray(start + 122880 * 2, data, 122880)); } PokePC.ApplyGameType(gameType); } else { this.saveData = new GCSaveData[2]; if (!ByteHelper.CompareBytes(0, ByteHelper.SubByteArray(start + 0x10, data, 16))) { this.saveData[0] = new GCSaveData(this, ByteHelper.SubByteArray(start, data, 163840)); } if (!ByteHelper.CompareBytes(0, ByteHelper.SubByteArray(start + 163840 + 0x10, data, 16))) { this.saveData[1] = new GCSaveData(this, ByteHelper.SubByteArray(start + 163840, data, 163840)); } PokePC.ApplyGameType(gameType); } this.raw = data; loaded = true; }