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); } }
protected override void SetChecksums() { BigEndian.GetBytes(FinalCount).CopyTo(Data, FinalCountOffset); // ensure the final data is written if the user screws stuff up var goodlen = (FinalCountOffset + 4); Array.Clear(Data, goodlen, Data.Length - goodlen); // 20 byte SHA checksum at the top of the file, which covers all data that follows. using var hash = SHA1.Create(); var result = hash.ComputeHash(Data, 20, Data.Length - 20); SetData(result, 0); }
public override void SetPouch(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)Items[i].Count).CopyTo(data, Offset + (i * 4) + 2); } }
public 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); }
public byte[] Write() { var result = new byte[4 + (Entries.Count * SIZE_ENTRY)]; BigEndian.GetBytes((short)Entries.Count).CopyTo(result, 0); BigEndian.GetBytes((short)_unk).CopyTo(result, 2); var count = Math.Min(MAX_COUNT, Entries.Count); for (int i = 0; i < count; i++) { Entries[i].Data.CopyTo(result, 4 + (i * SIZE_ENTRY)); } return(result); }
private static byte[] SetChecksums(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); }
public byte[] Write() => BigEndian.GetBytes((short)Entries.Count).Concat(_unk) // count followed by populated entries .Concat(Entries.SelectMany(entry => entry.Data)).ToArray();