Exemplo n.º 1
0
 private void ReadSaveFile(string filename, int slot)
 {
     switch (Path.GetExtension(filename).ToLowerInvariant())
     {
         case ".vms":
             if (slot == -1)
             {
                 byte[] vms = File.ReadAllBytes(filename);
                 for (int i = 0; i < 3; i++)
                 {
                     slots[i] = new SaveSlot() { System = Systems.Dreamcast };
                     slots[i].Filename = filename;
                     slots[i].Region = CheckSA1Region(vms);
                     byte[] sl = new byte[SA1Size];
                     Array.Copy(vms, DCSlots[i], sl, 0, SA1Size);
                     int calc = CalcSaveChecksum(sl);
                     int stored = BitConverter.ToInt32(sl, 0);
                     byte[] data = Properties.Resources.PC.CastClone();
                     Array.Copy(sl, 0, data, 0, SA1Size);
                     slots[i].Data = new SaveData(data);
                     if (calc != stored)
                         MessageBox.Show(this, "Checksum in file \"" + filename + "\" slot " + (i + 1).ToInvariantString() + " incorrect!\nCalculated value: 0x" + calc.ToString("X4") + "\nStored value: 0x" + stored.ToString("X4"));
                 }
                 LoadSaveData();
             }
             else
                 using (SA1SlotDialog sa1 = new SA1SlotDialog())
                     if (sa1.ShowDialog(this) == DialogResult.OK)
                     {
                         slots[slot] = new SaveSlot() { System = Systems.Dreamcast };
                         slots[slot].Filename = filename;
                         byte[] vms = File.ReadAllBytes(filename);
                         slots[slot].Region = CheckSA1Region(vms);
                         byte[] sl = new byte[SA1Size];
                         Array.Copy(vms, DCSlots[sa1.Selection], sl, 0, SA1Size);
                         int calc = CalcSaveChecksum(sl);
                         int stored = BitConverter.ToInt32(sl, 0);
                         byte[] data = Properties.Resources.PC.CastClone();
                         Array.Copy(sl, 0, data, 0, SA1Size);
                         slots[slot].Data = new SaveData(data);
                         if (calc != stored)
                             MessageBox.Show(this, "Checksum in file \"" + filename + "\" slot " + (slot + 1).ToInvariantString() + " incorrect!\nCalculated value: 0x" + calc.ToString("X4") + "\nStored value: 0x" + stored.ToString("X4"));
                         if (slotnum == slot)
                             LoadSaveData();
                     }
             break;
         case ".gci":
             if (slot == -1)
             {
                 if (GCFilename.IsMatch(Path.GetFileName(filename)))
                 {
                     string file = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename).TrimEnd('1', '2', '3') + "{0}" + Path.GetExtension(filename));
                     for (int i = 0; i < 3; i++)
                     {
                         string fn = string.Format(CultureInfo.InvariantCulture, file, i + 1);
                         if (File.Exists(fn))
                             LoadGCNSlot(i, fn);
                     }
                     LoadSaveData();
                 }
                 else
                 {
                     LoadGCNSlot(0, filename);
                     if (slotnum == 0)
                         LoadSaveData();
                 }
             }
             else
             {
                 LoadGCNSlot(slot, filename);
                 if (slotnum == slot)
                     LoadSaveData();
             }
             break;
         case ".snc":
             if (slot == -1)
             {
                 if (PCFilename.IsMatch(Path.GetFileName(filename)))
                 {
                     string file = Path.Combine(Path.GetDirectoryName(filename), "SonicDX{0:00}.snc");
                     Match match = PCFilename.Match(Path.GetFileName(filename));
                     byte num = byte.Parse(match.Groups[1].Value, NumberStyles.None, NumberFormatInfo.InvariantInfo);
                     for (int i = 0; i < 3; i++)
                     {
                         string fn = string.Format(CultureInfo.InvariantCulture, file, num + i);
                         if (File.Exists(fn))
                             LoadPCSlot(i, fn);
                     }
                     LoadSaveData();
                 }
                 else
                 {
                     LoadPCSlot(0, filename);
                     if (slotnum == 0)
                         LoadSaveData();
                 }
             }
             else
             {
                 LoadPCSlot(slot, filename);
                 if (slotnum == slot)
                     LoadSaveData();
             }
             break;
         case ".bin":
             if (slot == -1) slot = 0;
             slots[slot] = new SaveSlot() { System = Systems.PC };
             slots[slot].Filename = filename;
             byte[] bin = File.ReadAllBytes(filename);
             byte[] datab = new byte[SADXSize+16];
             Array.Copy(bin, X360Header, datab, 0, SADXSize + 16);
             int calcb = CalcSaveChecksum(datab);
             Byteswap(datab);
             int storedb = BitConverter.ToInt32(datab, 0);
             slots[slot].Data = new SaveData(datab);
             if (calcb != storedb)
                 MessageBox.Show(this, "Checksum in file \"" + filename + "\" incorrect!\nCalculated value: 0x" + calcb.ToString("X4") + "\nStored value: 0x" + storedb.ToString("X4"));
             if (slotnum == slot)
                 LoadSaveData();
             break;
         default:
             throw new ApplicationException("Unknown save type " + Path.GetExtension(filename) + "!");
     }
 }
Exemplo n.º 2
0
 private void newSlot3ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     slots[2] = new SaveSlot();
     if (slotnum == 2)
         LoadSaveData();
 }
Exemplo n.º 3
0
 private void LoadPCSlot(int i, string fn)
 {
     slots[i] = new SaveSlot();
     slots[i].Filename = fn;
     byte[] data = File.ReadAllBytes(fn);
     int calc = CalcSaveChecksum(data);
     int stored = BitConverter.ToInt32(data, 0);
     slots[i].Data = new SaveData(data);
     if (calc != stored)
         MessageBox.Show(this, "Checksum in file \"" + fn + "\" incorrect!\nCalculated value: 0x" + calc.ToString("X4") + "\nStored value: 0x" + stored.ToString("X4"));
 }
Exemplo n.º 4
0
 private void newAllSlotsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < 3; i++)
         slots[i] = new SaveSlot();
     LoadSaveData();
 }
Exemplo n.º 5
0
 private void LoadGCNSlot(int i, string fn)
 {
     slots[i] = new SaveSlot() { System = Systems.GameCube };
     slots[i].Filename = fn;
     byte[] gci = File.ReadAllBytes(fn);
     if (System.Text.Encoding.ASCII.GetString(gci, 0, 6) == "RELSAB")
     {
         slots[i].System = Systems.GameCubePreview;
         slots[i].Region = Regions.Japan;
         byte[] sl = new byte[SA1Size];
         Array.Copy(gci, GCHeader, sl, 0, SA1Size);
         int calc = CalcSaveChecksum(sl);
         Byteswap(sl);
         int stored = BitConverter.ToInt32(sl, 0);
         byte[] data = Properties.Resources.PC.CastClone();
         Array.Copy(sl, 0, data, 0, SA1Size);
         slots[i].Data = new SaveData(data);
         if (calc != stored)
             MessageBox.Show(this, "Checksum in file \"" + fn + "\" incorrect!\nCalculated value: 0x" + calc.ToString("X4") + "\nStored value: 0x" + stored.ToString("X4"));
     }
     else
     {
         switch (char.ToLowerInvariant((char)gci[3]))
         {
             case 'p':
                 slots[i].Region = Regions.Europe;
                 break;
             case 'j':
                 slots[i].Region = Regions.Japan;
                 break;
         }
         byte[] data = new byte[SADXSize];
         Array.Copy(gci, GCHeader, data, 0, SADXSize);
         int calc = CalcSaveChecksum(data);
         Byteswap(data);
         int stored = BitConverter.ToInt32(data, 0);
         slots[i].Data = new SaveData(data);
         if (calc != stored)
             MessageBox.Show(this, "Checksum in file \"" + fn + "\" incorrect!\nCalculated value: 0x" + calc.ToString("X4") + "\nStored value: 0x" + stored.ToString("X4"));
     }
 }