public bool checkCRC() { uint crc = Tools.adler32(StateAreaBytes, 4, Marshal.SizeOf(typeof(StateAreaStruct)) - 4, 1); Console.WriteLine("CRC: {0} - Expected: {1}", crc, stateArea.crc); return(crc == stateArea.crc); }
public void updateCRC() { stateArea.crc = Tools.adler32(StateAreaBytes, 4, Marshal.SizeOf(typeof(StateAreaStruct)) - 4, 1); }
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!"); }