private void load_blocks() { byte[] decrypt1 = new byte[ML_BLOCK1.Size]; byte[] decrypt2 = new byte[ML_BLOCK2.Size]; decrypt1 = SAV5.cryptoArray(getData(0, ML_BLOCK1.Size), 0xC, 0x364, 0x374 - 4); decrypt2 = SAV5.cryptoArray(getData(0x400, ML_BLOCK1.Size), 0xC, 0x364, 0x374 - 4); block1 = new ML_BLOCK1(decrypt1); block1_mirror = new ML_BLOCK1(decrypt2); block2 = new ML_BLOCK2(getData(0x800, ML_BLOCK2.Size)); //Not encrypted, but has CRC }
void Import_bw1Click(object sender, EventArgs e) { byte[] bw1 = new byte[SAV5.SIZERAW + 122]; string path = null; int filesize = FileIO.load_file(ref bw1, ref path, "NDS save data|*.sav;*.dsv|All Files (*.*)|*.*"); if (filesize == SAV5.SIZERAW || filesize == SAV5.SIZERAW + 122) { //Convert DSV to SAV if (filesize == SAV5.SIZERAW + 122) { Array.Resize(ref bw1, SAV5.SIZERAW); } SAV5 bw1save = new SAV5(bw1); if (bw1save.B2W2 == false) { ml.block2.name_fromarray(bw1.Skip(0x19404).Take(0xF).ToArray()); ml.block2.TID = BitConverter.ToUInt16(bw1, 0x19414); ml.block2.SID = BitConverter.ToUInt16(bw1, 0x19416); ml.block2.STARTER = bw1save.Data[0x20160]; ml.block2.set_hof(bw1.Skip(0x23B00).Take(0x168).ToArray()); ml.block2.set_props(bw1.Skip(0x1F958).Take(0x13).ToArray()); UInt32 newseed = (UInt32)(rand.Next(0xFFFF + 1) << 16); ml.block1.crypt_seed = newseed; ml.block1_mirror.crypt_seed = newseed; //Reload all data load_data(); MessageBox.Show("Imported: Trainer Name, TID, SID, Starter, Hall of Fame, Props"); } else { MessageBox.Show("Not a valid savegame!"); } } }
public void set_blocks() { //Block 1 //Recrypt byte[] encrypt1 = new byte[ML_BLOCK1.Size]; encrypt1 = SAV5.cryptoArray(block1.Data, 0xC, 0x364, 0x374 - 4); //Recalculate CRC ushort crc = SAV5.ccitt16(encrypt1.Skip(0xC).Take(0x368).ToArray()); BitConverter.GetBytes(crc).CopyTo(encrypt1, 0x8); //Set new data setData(encrypt1, 0); //Block 1 Mirror //Just put block 1 for now as mirror setData(encrypt1, 0x400); /* * //Recrypt * byte[] encrypt_mirror = new byte[ML_BLOCK1.Size]; * encrypt_mirror = SAV5.cryptoArray(block1_mirror.Data, 0xC, 0x364, 0x374-4); * //Recalculate CRC * ushort crc_mirror = SAV5.ccitt16(encrypt_mirror.Skip(0xC).Take(0x368).ToArray()); * BitConverter.GetBytes(crc_mirror).CopyTo(encrypt_mirror, 0x8); * //Set new data * setData(encrypt_mirror, 0x400); */ //Block 2 //Recalculate CRC ushort crc2 = SAV5.ccitt16(block2.Data.Skip(0xC).Take(0x214).ToArray()); block2.crc = crc2; //Set new data setData(block2.Data, 0x800); }
void load_savegame(string filepath) { string path = filepath; int filesize = FileIO.load_file(ref savebuffer, ref path, dsfilter); versiontext.Text = ""; if (filesize == SAV5.SIZERAW || filesize == SAV5.SIZERAW + 122) { //Convert DSV to SAV if (filesize == SAV5.SIZERAW + 122) { Array.Resize(ref savebuffer, SAV5.SIZERAW); } savegamename.Text = path; save = new SAV5(savebuffer); if (save.B2W2) { versiontext.Text = "Black/White 2"; dumper_but.Enabled = true; chk_but.Enabled = true; chk_updt_but.Enabled = true; save_but.Enabled = true; grotto_but.Enabled = true; trainer_records_but.Enabled = true; medal_but.Enabled = true; forest_but.Enabled = true; key_but.Enabled = true; join_but.Enabled = true; trainer_but.Enabled = true; memory_but.Enabled = true; dlc_but.Enabled = true; dr_but.Enabled = true; } else if (save.BW) { versiontext.Text = "Black/White 1"; dumper_but.Enabled = true; chk_but.Enabled = true; chk_updt_but.Enabled = true; save_but.Enabled = true; grotto_but.Enabled = false; trainer_records_but.Enabled = false; medal_but.Enabled = false; forest_but.Enabled = true; key_but.Enabled = false; join_but.Enabled = false; trainer_but.Enabled = true; memory_but.Enabled = false; dlc_but.Enabled = true; dr_but.Enabled = false; } else { versiontext.Text = "Invalid file"; } } else { MessageBox.Show("Invalid file."); savegamename.Text = ""; dumper_but.Enabled = false; chk_but.Enabled = false; chk_updt_but.Enabled = false; save_but.Enabled = false; grotto_but.Enabled = false; trainer_records_but.Enabled = false; medal_but.Enabled = false; forest_but.Enabled = false; key_but.Enabled = false; join_but.Enabled = false; trainer_but.Enabled = false; memory_but.Enabled = false; dlc_but.Enabled = false; dr_but.Enabled = false; } }