Advertisement
Guest User

Isaac Rebirth Save Checksum

a guest
Dec 30th, 2014
2,716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. private uint CalcChecksum(byte[] data)
  2. {
  3. byte[] save = new byte[0x4EF];
  4. Array.Copy(data, save, save.Length); //steam cloud saves are bigger than I care about
  5. uint seed = BitConverter.ToUInt32(save, 0x4E7);
  6. uint desired = BitConverter.ToUInt32(save, 0x4EB);
  7. uint chksum = 0;
  8. int ofs = 0x14;
  9. chksum = seed + 2137939259;
  10. uint magic = BitConverter.ToUInt32(save, 0x10);
  11. uint[] SectData = new uint[3];
  12. int[] entrylens = new int[] { 1, 4, 4, 1, 1, 1, 1, 4, 4 };
  13. for (int i = 0; i < 9; i++)
  14. {
  15. for (int j = 0; j < 3; j++)
  16. {
  17. SectData[j] = BitConverter.ToUInt32(save, ofs);
  18. chksum = Update(SectData[j], chksum);
  19. }
  20. for (int j = 0; j < SectData[2]; j++)
  21. {
  22. uint val = 0;
  23. if (entrylens[i] == 1)
  24. {
  25. val = save[ofs];
  26. }
  27. else if (entrylens[i] == 4)
  28. {
  29. val = BitConverter.ToUInt32(save, ofs);
  30. }
  31. chksum = Update(val, chksum);
  32. ofs += entrylens[i];
  33. }
  34.  
  35. }
  36. chksum = Update(magic, chksum);
  37. chksum ^= 0x96696996;
  38. return chksum;
  39. }
  40.  
  41. private uint Update(uint val, uint chksum)
  42. {
  43. return (val + ((chksum << 31) + (chksum >> 1)));
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement