private bool HasAtLeastOneValidSave(byte[] bytes) { for (int i = 0; i < 15; i++) { if (Savegame.IsValidPSPGame(bytes, (int)(i * Savegame.saveFileSize))) { return(true); } } return(false); }
private void TryReadFile(byte[] bytes) { try { bool validGameFound = false; for (int i = 0; (i < 15) && (((i + 1) * Savegame.saveFileSize) < bytes.Length); i++) { if (Savegame.IsValidPSPGame(bytes, (int)(i * Savegame.saveFileSize))) { usingGME = false; validGameFound = true; byte[] saveData = new byte[Savegame.saveFileSize]; Array.Copy(bytes, i * Savegame.saveFileSize, saveData, 0, Savegame.saveFileSize); games[i] = new Savegame(saveData); gameSelector.Items.Add(games[i]); } else { games[i] = null; } } //if (!validGameFound) // TODO: fix GME importing if (false) { // Try GME... usingGME = true; foreach (int i in ValidateGMEFile(bytes)) { byte[] saveData = new byte[0x2000]; if ((bytes.Length + 1) < 0x2F40 + i * 0x2000) { break; } Array.Copy(bytes, 0x2F40 + i * 0x2000, saveData, 0, 0x2000); games[i] = new Savegame(saveData); gameSelector.Items.Add(games[i]); } } } catch (Exception) { // Fail silently!! } }
public static GMEFile ReadGMEFile(byte[] bytes) { // TODO: check validity of GME file GMEFile result = new GMEFile(); foreach (int i in ValidateGMEFile(bytes)) //for (int i = 0; i < 15; i++) { try { List <Character> characters = new List <Character>(20); for (int j = 0; j < 20; j++) { byte[] character = new byte[0xE0]; Savegame.CopyArray(bytes, character, (0x2F40 + 0x2000 * i) + (0x484 + 0xE0 * j), 0xE0); characters.Add(new Character(character, j));; } string gameName = BuildSaveGameString(bytes, i); result.gameNames.Add(gameName); result.games.Add(characters); } catch (Exception) { // Ignore saves in this file that can't be processed } } if ((result.games.Count == 0) || (result.gameNames.Count == 0)) { return(null); } else { return(result); } }
private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e) { if (e.Button == openButton) { DialogResult result = openFileDialog.ShowDialog(this); if (result == DialogResult.OK) { System.IO.FileStream stream = new System.IO.FileStream(openFileDialog.FileName, System.IO.FileMode.Open); byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); stream.Close(); games = new List <List <Character> >(); gameNames = new List <string>(); gameSelector.Items.Clear(); try { bool validGameFound = false; for (int i = 0; (i < 15) && (((i + 1) * Savegame.saveFileSize) < bytes.Length); i++) { if (Savegame.IsValidPSPGame(bytes, (int)(i * Savegame.saveFileSize))) { validGameFound = true; byte[] saveData = new byte[Savegame.saveFileSize]; Array.Copy(bytes, i * Savegame.saveFileSize, saveData, 0, Savegame.saveFileSize); Savegame g = new Savegame(saveData); gameNames.Add(g.ToString()); games.Add(g.Characters); } } if (!validGameFound) { // Try GME... foreach (int i in MainForm.ValidateGMEFile(bytes)) { byte[] saveData = new byte[0x2000]; if ((bytes.Length + 1) < 0x2F40 + i * 0x2000) { break; } Array.Copy(bytes, 0x2F40 + i * 0x2000, saveData, 0, 0x2000); Savegame g = new Savegame(saveData); gameNames.Add(g.ToString()); games.Add(g.Characters); } } } catch (Exception) { // Fail silently!! } gameSelector.Items.AddRange(gameNames.ToArray()); if (gameSelector.Items.Count > 0) { gameSelector.SelectedIndex = 0; } gameSelector.Enabled = true; } } }
private void TryReadFile(byte[] bytes) { try { bool validGameFound = false; for (int i = 0; (i < 15) && (((i+1) * Savegame.saveFileSize) < bytes.Length); i++) { if (Savegame.IsValidPSPGame(bytes, (int)(i * Savegame.saveFileSize))) { usingGME = false; validGameFound = true; byte[] saveData = new byte[Savegame.saveFileSize]; Array.Copy(bytes, i * Savegame.saveFileSize, saveData, 0, Savegame.saveFileSize); games[i] = new Savegame(saveData); gameSelector.Items.Add(games[i]); } else { games[i] = null; } } //if (!validGameFound) // TODO: fix GME importing if (false) { // Try GME... usingGME = true; foreach (int i in ValidateGMEFile(bytes)) { byte[] saveData = new byte[0x2000]; if ((bytes.Length + 1) < 0x2F40 + i * 0x2000) { break; } Array.Copy(bytes, 0x2F40 + i * 0x2000, saveData, 0, 0x2000); games[i] = new Savegame(saveData); gameSelector.Items.Add(games[i]); } } } catch (Exception) { // Fail silently!! } }
private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e) { if (e.Button == openButton) { DialogResult result = openFileDialog.ShowDialog(this); if (result == DialogResult.OK) { System.IO.FileStream stream = new System.IO.FileStream(openFileDialog.FileName, System.IO.FileMode.Open); byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); stream.Close(); games = new List<List<Character>>(); gameNames = new List<string>(); gameSelector.Items.Clear(); try { bool validGameFound = false; for( int i = 0; (i < 15) && (((i + 1) * Savegame.saveFileSize) < bytes.Length); i++ ) { if( Savegame.IsValidPSPGame( bytes, (int)(i * Savegame.saveFileSize) ) ) { validGameFound = true; byte[] saveData = new byte[Savegame.saveFileSize]; Array.Copy( bytes, i * Savegame.saveFileSize, saveData, 0, Savegame.saveFileSize ); Savegame g = new Savegame( saveData ); gameNames.Add( g.ToString() ); games.Add( g.Characters ); } } if (!validGameFound) { // Try GME... foreach( int i in MainForm.ValidateGMEFile( bytes ) ) { byte[] saveData = new byte[0x2000]; if( (bytes.Length + 1) < 0x2F40 + i * 0x2000 ) { break; } Array.Copy( bytes, 0x2F40 + i * 0x2000, saveData, 0, 0x2000 ); Savegame g = new Savegame( saveData ); gameNames.Add( g.ToString() ); games.Add( g.Characters ); } } } catch( Exception ) { // Fail silently!! } gameSelector.Items.AddRange(gameNames.ToArray()); if (gameSelector.Items.Count > 0) { gameSelector.SelectedIndex = 0; } gameSelector.Enabled = true; } } }