Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private uint CalcChecksum(byte[] data)
- {
- byte[] save = new byte[0x4EF];
- Array.Copy(data, save, save.Length); //steam cloud saves are bigger than I care about
- uint seed = BitConverter.ToUInt32(save, 0x4E7);
- uint desired = BitConverter.ToUInt32(save, 0x4EB);
- uint chksum = 0;
- int ofs = 0x14;
- chksum = seed + 2137939259;
- uint magic = BitConverter.ToUInt32(save, 0x10);
- uint[] SectData = new uint[3];
- int[] entrylens = new int[] { 1, 4, 4, 1, 1, 1, 1, 4, 4 };
- for (int i = 0; i < 9; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- SectData[j] = BitConverter.ToUInt32(save, ofs);
- chksum = Update(SectData[j], chksum);
- }
- for (int j = 0; j < SectData[2]; j++)
- {
- uint val = 0;
- if (entrylens[i] == 1)
- {
- val = save[ofs];
- }
- else if (entrylens[i] == 4)
- {
- val = BitConverter.ToUInt32(save, ofs);
- }
- chksum = Update(val, chksum);
- ofs += entrylens[i];
- }
- }
- chksum = Update(magic, chksum);
- chksum ^= 0x96696996;
- return chksum;
- }
- private uint Update(uint val, uint chksum)
- {
- return (val + ((chksum << 31) + (chksum >> 1)));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement