private void loadNX2Button_Click(object sender, EventArgs e) { if (File.Exists("nx2save.bin") && File.Exists("nx2rank.bin")) { // Load Data from Files saveBytes = File.ReadAllBytes("nx2save.bin"); uncSave = saveBytes.SubArray(0, Constants.NX2PAD_SAVE); encSave = saveBytes.SubArray(Constants.NX2PAD_SAVE, saveBytes.Length - Constants.NX2PAD_SAVE); rankBytes = File.ReadAllBytes("nx2rank.bin"); // Decode Data Tools.Decode(encSave); Tools.Decode(rankBytes); // Save Decoded File.WriteAllBytes("nx2save.dec", Tools.Combine(uncSave, encSave, new byte[0])); // Fill UI saveName = Encoding.UTF8.GetString(saveBytes.SubArray(Constants.SAVE_NAME1, 8)); saveSerial = Encoding.UTF8.GetString(encSave.SubArray(Constants.SAVE_SERIAL, 24)); saveAvatar = encSave.SubArray(Constants.SAVE_AVATAR, 1)[0]; avatarNumberSelect.Value = saveAvatar; avatarPictureBox.Image = (Bitmap)Properties.Resources.ResourceManager.GetObject("CH_" + (saveAvatar + 1).ToString("000")); usbNameEdit.Text = saveName; usbSerialLabel.Text = saveSerial; saveButton.Enabled = true; profiledata.Visible = true; NXALoaded = false; debugMessages.Text += "\r\nLoaded NX2 save!"; } else { MessageBox.Show("No save files in folder! (Missing nx2rank.bin or nx2save.bin)"); } }
public void LoadFromBuffer(byte[] data) { byte[] buff = new byte[Marshal.SizeOf(typeof(ReviewAreaStruct))]; int amt = 0; while (amt < buff.Length) { buff[amt] = data[amt]; amt++; } GCHandle handle = GCHandle.Alloc(buff, GCHandleType.Pinned); reviewArea = (ReviewAreaStruct)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(ReviewAreaStruct)); handle.Free(); //buff = new byte[Marshal.SizeOf(typeof(StateAreaStruct)]; buff = data.SubArray(0x144, Marshal.SizeOf(typeof(StateAreaStruct))); Tools.Decode(buff); handle = GCHandle.Alloc(buff, GCHandleType.Pinned); stateArea = (StateAreaStruct)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(StateAreaStruct)); handle.Free(); }
private void saveButton_Click(object sender, EventArgs e) { int serialSize = usbSerialLabel.Text.Length < 24 ? usbSerialLabel.Text.Length : 24; int nameSize = usbNameEdit.Text.Length < 8 ? usbNameEdit.Text.Length : 8; // Backup the files Tools.Encode(encSave); debugMessages.Text += "\r\nCreating backup of the save .bak."; if (NXALoaded) { File.WriteAllBytes("nxasave.bin.bak", Tools.Combine(uncSave, encSave, new byte[0])); } else { File.WriteAllBytes("nx2save.bin.bak", Tools.Combine(uncSave, encSave, new byte[0])); } Tools.Decode(encSave); //Change Serial: for (int i = 0; i < serialSize; i++) { encSave[i + Constants.SAVE_SERIAL] = (byte)usbSerialLabel.Text[i]; } for (int i = serialSize; i < 24; i++) { encSave[i + Constants.SAVE_SERIAL] = 0x00; // Fill remaining bytes if needed } //Change Name1: for (int i = 0; i < nameSize; i++) { uncSave[i + Constants.SAVE_NAME1] = (byte)usbNameEdit.Text[i]; } for (int i = nameSize; i < 8; i++) { uncSave[i + Constants.SAVE_NAME1] = 0x00; // Fill remaining bytes if needed } //Change Name2: for (int i = 0; i < nameSize; i++) { encSave[i + Constants.SAVE_NAME2] = (byte)usbNameEdit.Text[i]; } for (int i = nameSize; i < 8; i++) { encSave[i + Constants.SAVE_NAME2] = 0x00; // Fill remaining bytes if needed } encSave[Constants.SAVE_AVATAR] = (byte)(saveAvatar & 0xFF); // Calculate CRC uint crc = Tools.adler32(encSave, 4, encSave.Length - 4, 1); Console.WriteLine("CRC: {0}", crc); encSave[3] = (byte)((crc & 0x000000FF) >> 0); encSave[2] = (byte)((crc & 0x0000FF00) >> 8); encSave[1] = (byte)((crc & 0x00FF0000) >> 16); encSave[0] = (byte)((crc & 0xFF000000) >> 24); Tools.Encode(encSave); if (NXALoaded) { File.WriteAllBytes("nxasave.bin", Tools.Combine(uncSave, encSave, new byte[0])); } else { File.WriteAllBytes("nx2save.bin", Tools.Combine(uncSave, encSave, new byte[0])); } Tools.Decode(encSave); MessageBox.Show("Saved!"); }