private uint GetChecksum(byte[] data) { int start = Offset + 4; var span = new ReadOnlySpan <byte>(data, start, ChecksumRegionSize); return(Checksums.CheckSum16BigInvert(span)); }
// Checksums protected override void SetChecksums() { for (int i = 0; i < BLOCK_COUNT; i++) { int ofs = ABO + (i * SIZE_BLOCK); int len = chunkLength[BlockOrder[i]]; ushort chk = Checksums.CRC32(Data, ofs, len); BitConverter.GetBytes(chk).CopyTo(Data, ofs + 0xFF6); } if (BAK.Length < SaveUtil.SIZE_G3RAW) // don't update HoF for half-sizes { return; } // Hall of Fame Checksums { ushort chk = Checksums.CRC32(Data, 0x1C000, SIZE_BLOCK_USED); BitConverter.GetBytes(chk).CopyTo(Data, 0x1CFF4); } { ushort chk = Checksums.CRC32(Data, 0x1D000, SIZE_BLOCK_USED); BitConverter.GetBytes(chk).CopyTo(Data, 0x1DFF4); } }
public static ulong StrToU64(string input, out bool valid) { var chk = Pull(0, 4) >> 4; // first four chars are checksum bits var result = Pull(4, input.Length); // next 12 chars are the 70 value bits Span <byte> temp = stackalloc byte[8]; WriteUInt64LittleEndian(temp, result); var actual = Checksums.CRC16_CCITT(temp); valid = chk == actual; return(result); ulong Pull(int start, int count) { ulong val = 0; for (int i = start; i < count; i++) { var c = input[i]; if (c == '-') { continue; } val <<= 5; val |= Get5BitFromChar(c) & 0b11111; } return(val); } }
public static ulong StrToU64(string input, out bool valid) { var chk = Pull(0, 4) >> 4; // first four chars are checksum bits var result = Pull(4, input.Length); // next 12 chars are the 70 value bits var actual = Checksums.CRC16_CCITT(BitConverter.GetBytes(result)); valid = chk == actual; return(result); ulong Pull(int start, int count) { ulong val = 0; for (int i = start; i < count; i++) { var c = input[i]; if (c == '-') { continue; } val <<= 5; val |= Get5BitFromChar(c) & 0b11111; } return(val); } }
public static byte[] GenerateQRData(PK7 pk7, int box = 0, int slot = 0, int num_copies = 1) { if (box > 31) { box = 31; } if (slot > 29) { slot = 29; } if (box < 0) { box = 0; } if (slot < 0) { slot = 0; } if (num_copies < 0) { num_copies = 1; } byte[] data = new byte[0x1A2]; BitConverter.GetBytes(0x454B4F50).CopyTo(data, 0); // POKE magic data[0x4] = 0xFF; // QR Type BitConverter.GetBytes(box).CopyTo(data, 0x8); BitConverter.GetBytes(slot).CopyTo(data, 0xC); BitConverter.GetBytes(num_copies).CopyTo(data, 0x10); // No need to check max num_copies, payload parser handles it on-console. pk7.EncryptedPartyData.CopyTo(data, 0x30); // Copy in pokemon data GetRawQR(pk7.Species, pk7.AltForm, pk7.IsShiny, pk7.Gender).CopyTo(data, 0x140); BitConverter.GetBytes(Checksums.CRC16(data, 0, 0x1A0)).CopyTo(data, 0x1A0); return(data); }
protected override void SetBoxChecksum(int i) { var boxOfs = GetBoxOffset(i) - ListHeaderSize; const int size = BoxSizeJ - 2; var chk = Checksums.CheckSum16(Data, boxOfs, size); BigEndian.GetBytes(chk).CopyTo(Data, boxOfs + size); }
protected override void SetBoxChecksum(int box) { var boxOfs = GetBoxOffset(box) - ListHeaderSize; const int size = BoxSizeJ - 2; var chk = Checksums.CheckSum16(new ReadOnlySpan <byte>(Data, boxOfs, size)); WriteUInt16BigEndian(Data.AsSpan(boxOfs + size), chk); }
protected override void SetBoxChecksum(int box) { var boxOfs = GetBoxOffset(box) - ListHeaderSizeBox; var size = BoxSize - 2; var chk = Checksums.CheckSum16(new ReadOnlySpan <byte>(Data, boxOfs, size)); BigEndian.GetBytes(chk).CopyTo(Data, boxOfs + size); }
private bool IsChunkValid(int i) { int ofs = ABO + (i * SIZE_BLOCK); int len = chunkLength[BlockOrder[i]]; ushort chk = Checksums.CRC32(Data, ofs, len); return(chk == BitConverter.ToUInt16(Data, ofs + 0xFF6)); }
protected override bool GetIsBoxChecksumValid(int box) { var boxOfs = GetBoxOffset(box) - ListHeaderSizeBox; var size = BoxSize - 2; var chk = Checksums.CheckSum16(new ReadOnlySpan <byte>(Data, boxOfs, size)); var actual = BigEndian.ToUInt16(Data, boxOfs + size); return(chk == actual); }
protected override bool GetIsBoxChecksumValid(int i) { var boxOfs = GetBoxOffset(i) - ListHeaderSize; const int size = BoxSizeJ - 2; var chk = Checksums.CheckSum16(Data, boxOfs, size); var actual = BigEndian.ToUInt16(Data, boxOfs + size); return(chk == actual); }
private bool IsChunkValidHoF(int ofs) { ushort chk = Checksums.CRC32(Data, ofs, SIZE_BLOCK_USED); if (chk != BitConverter.ToUInt16(Data, ofs + 0xFF4)) { return(false); } return(true); }
/// <summary>Checks to see if the data belongs to a Gen5 save</summary> /// <param name="data">Save data of which to determine the type</param> /// <returns>Version Identifier or Invalid if type cannot be determined.</returns> internal static GameVersion GetIsG5SAV(byte[] data) { if (data.Length != SIZE_G5RAW) return Invalid; // check the checksum block validity; nobody would normally modify this region ushort chk1 = BitConverter.ToUInt16(data, SIZE_G5BW - 0x100 + 0x8C + 0xE); ushort actual1 = Checksums.CRC16_CCITT(data, SIZE_G5BW - 0x100, 0x8C); if (chk1 == actual1) return BW; ushort chk2 = BitConverter.ToUInt16(data, SIZE_G5B2W2 - 0x100 + 0x94 + 0xE); ushort actual2 = Checksums.CRC16_CCITT(data, SIZE_G5B2W2 - 0x100, 0x94); if (chk2 == actual2) return B2W2; return Invalid; }
public static string U64ToStr(ulong input, bool insertDash) { uint chk = Checksums.CRC16_CCITT(BitConverter.GetBytes(input)); var buff = new char[16]; int ctr = 15; Push(input, 12); // store value bits Push(chk << 4, 4); // store checksum bits return(!insertDash?string.Concat(buff) : GetStringWithDashesEvery(buff, 4)); void Push(ulong v, int count) { for (int i = 0; i < count; i++) { buff[ctr--] = Set5BitToChar((char)(v & 0b11111)); v >>= 5; } } }
public static string U64ToStr(ulong input, bool insertDash) { Span <byte> temp = stackalloc byte[8]; WriteUInt64LittleEndian(temp, input); uint chk = Checksums.CRC16_CCITT(temp); var buff = new char[16]; int ctr = 15; Push(input, 12); // store value bits Push(chk << 4, 4); // store checksum bits return(!insertDash?string.Concat(buff) : GetStringWithDashesEvery(buff, 4)); void Push(ulong v, int count) { for (int i = 0; i < count; i++) { buff[ctr--] = Set5BitToChar((char)(v & 0b11111)); v >>= 5; } } }
protected override ushort GetChecksum(byte[] data) => Checksums.CRC16NoInvert(new ReadOnlySpan <byte>(data, Offset, Length));
private ushort GetChecksum(byte[] data) => Checksums.CRC16_CCITT(new ReadOnlySpan <byte>(data, Offset, Length));
private ushort GetChecksum(Span <byte> data) => Checksums.CRC16_CCITT(data.Slice(Offset, Length));
private bool IsChunkValidHoF(int ofs) { ushort chk = Checksums.CheckSum32(Data, ofs, SIZE_BLOCK_USED); return(chk == BitConverter.ToUInt16(Data, ofs + 0xFF4)); }
protected override ushort GetChecksum(byte[] data) => Checksums.CRC16NoInvert(data, Offset, Length);
private ushort CalcBlockChecksum(byte[] data) => Checksums.CRC16_CCITT(new ReadOnlySpan <byte>(data, 0, data.Length - FooterSize));
private ushort CalcBlockChecksum(byte[] data) => Checksums.CRC16_CCITT(data, 0, data.Length - FooterSize);
private ushort GetChecksum(byte[] data) => Checksums.CRC16_CCITT(data, Offset, Length);