Advertisement
Guest User

Ninety Nine Nights 2

a guest
Oct 31st, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. "
  2. Security:
  3. -> Custom XOR Encryption
  4. -> Custom Checksum (2x)
  5. "
  6.  
  7. private void Encrypt(byte[] data, int offset, int size) {
  8.     int next = 0;
  9.     for (int i = offset; i < (offset + size); ++i) {
  10.         next = ((data[i] ^ next) + (i - offset)) ^ 0xBB;
  11.         data[i] = (byte) next;
  12.     }
  13. }
  14.  
  15. private void Decrypt(byte[] data, int offset, int size) {
  16.     int last = 0, next;
  17.     for (int i = offset; i < (offset + size); ++i) {
  18.         next = ((data[i] ^ 0xBB) - (i - offset)) ^ last;
  19.         last = data[i];
  20.         data[i] = (byte) next;
  21.     }
  22. }
  23.  
  24. private int CalculateChecksum(byte[] data, int offset, int size) {
  25.     int sum = 0;
  26.     for (int i = offset; i < (offset + size); ++i)
  27.         sum += data[i] ^ (i - offset);
  28.  
  29.     return sum;
  30. }
  31.  
  32. "
  33. Read Save:
  34. "
  35.  
  36. byte[] data = File.ReadAllBytes(fileName);
  37. Decrypt(data, 0x34, 0x3560);
  38.  
  39. "
  40. Write Save:
  41. "
  42.  
  43. byte[] data = File.ReadAllBytes(fileName);
  44. using (var xIO = new MasterIO(data, Endian.BIG)) {
  45.     xIO.Position = 20;
  46.     xIO.Writer.WriteInt32(CalculateChecksum(data, 0x34, 0x3560));
  47.     xIO.Writer.WriteInt32(0);
  48.  
  49.     xIO.Position -= 4;
  50.     xIO.Writer.WriteInt32(CalculateChecksum(data, 0, 0x34));
  51.     Encrypt(data, 0x34, 0x3560);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement