Advertisement
HenryEx

RF4 save checksum correction script

Sep 20th, 2020
2,094
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.68 KB | None | 0 0
  1. //--------------------------------------
  2. //--- 010 Editor v6.0.2 Script File
  3. //
  4. // File: Rune Factory 4 save checksum
  5. // Author: HenryEx
  6. // Revision: 2
  7. // Purpose: Repair checksum on modified save files
  8. //--------------------------------------
  9.  
  10. RequiresFile();  // needs file to run on
  11. OutputPaneClear();  // clear output
  12.  
  13. // Define variables
  14. int64 size, fsize, pad, pos;
  15. uint  savehash, magic;
  16.  
  17. // Initialize variables
  18. fsize = FileSize();
  19. magic = ReadUInt( 0 );
  20. pad = 0xE0; // EoF block not used in hash
  21. pos = 4; // offset after hash
  22.  
  23. // Throw error if file layout has changed
  24.  
  25. switch( fsize ) {
  26.    case 0x1FC:
  27.       Printf( "File size %Ld - File should be RF4 (3DS) save selection \n", fsize );
  28.       break;
  29.    case 0x2458:
  30.       Printf( "File size %Ld - File should be RF4 (Switch) save selection \n", fsize );
  31.       break;
  32.    case 0x22400:
  33.       Printf( "File size %Ld - File should be RF4 (3DS) save file \n", fsize );
  34.       break;
  35.    case 0x22480:
  36.       Printf( "File size %Ld - File should be RF4 (Switch) save file \n", fsize );
  37.       break;
  38.    default:
  39.       Printf( "Unexpected file size %Ld! Script failed!\n", fsize );
  40.       Warning( "File mismatch, script terminated" );
  41.       Exit( -1 );
  42. }
  43.  
  44. // Change vars in case it's the save selector file rf4s.sav
  45. if( magic == 1144276562 ) // string 'RF4D'
  46. {
  47.    Printf( "Calculating system save file hash...\n" );
  48.    pos += 4;
  49.    size = fsize - pos;
  50. }
  51. else {
  52.    Printf( "Calculating save file hash...\n" );
  53.    size = fsize - pad - pos;
  54. }
  55.  
  56. savehash = Checksum( CHECKSUM_CRC32, pos, size, -1, -1 );
  57. Printf( "New checksum: %x \n", savehash );
  58.  
  59. WriteUInt( pos - 4, savehash );
  60. Printf( "Success! Save the file now." );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement