public void setPouchBigEndian(ref byte[] Data) { if (Items.Length != PouchDataSize) { throw new ArgumentException("Item array length does not match original pouch size."); } for (int i = 0; i < Items.Length; i++) { BigEndian.GetBytes((ushort)Items[i].Index).CopyTo(Data, Offset + i * 4); BigEndian.GetBytes((ushort)((ushort)Items[i].Count ^ (ushort)SecurityKey)).CopyTo(Data, Offset + i * 4 + 2); } }
internal static byte[] EncryptGC(byte[] input, int start, int end, ushort[] keys) { byte[] output = (byte[])input.Clone(); for (int ofs = start; ofs < end; ofs += 8) { for (int i = 0; i < keys.Length; i++) { ushort val = BigEndian.ToUInt16(input, ofs + i * 2); val += keys[i]; BigEndian.GetBytes(val).CopyTo(output, ofs + i * 2); } keys = AdvanceGCKeys(keys); } return(output); }
private static byte[] setXDChecksums(byte[] input, int subOffset0) { if (input.Length != 0x28000) { throw new ArgumentException("Input should be a slot, not the entire save binary."); } byte[] data = (byte[])input.Clone(); const int start = 0xA8; // 0x88 + 0x20 // Header Checksum int newHC = 0; for (int i = 0; i < 8; i++) { newHC += data[i]; } BigEndian.GetBytes(newHC).CopyTo(data, start + subOffset0 + 0x38); // Body Checksum new byte[16].CopyTo(data, 0x10); // Clear old Checksum Data uint[] checksum = new uint[4]; int dt = 8; for (int i = 0; i < 4; i++) { for (int j = 0; j < 0x9FF4; j += 2, dt += 2) { checksum[i] += BigEndian.ToUInt16(data, dt); } } ushort[] newchks = new ushort[8]; for (int i = 0; i < 4; i++) { newchks[i * 2] = (ushort)(checksum[i] >> 16); newchks[i * 2 + 1] = (ushort)checksum[i]; } Array.Reverse(newchks); for (int i = 0; i < newchks.Length; i++) { BigEndian.GetBytes(newchks[i]).CopyTo(data, 0x10 + 2 * i); } return(data); }