Author Topic: Need a program to calculate FF7 PC Savegame checksums  (Read 6197 times)

MaTiAz

  • *
  • Posts: 31
    • View Profile
Ok, so I need a program that can calculate the checksum. I've treid to get past the "Data is ruined" message by patching the FF7.exe, but it didn't work. The program doesn't need to be complicated, eg. command line program that just shows the checksum in the window, so it doesn't need to patch the file. I know that it can be made from Jenova sources, but I'm still learning only the basics of C++, so I can't really make it myself, so if someone could make a program to calculate checksum, I'd be very thankful.

Thanks in advance.

Lakeshia-51394

  • Guest
Need a program to calculate FF7 PC Savegame checksums
« Reply #1 on: 2005-08-30 02:01:18 »
Oh, My God!

dziugo

  • *
  • Posts: 1470
    • View Profile
    • A new copy of FF7 thanks to Salk. Pack (zip/rar/etc) your saved game before sending it to me.
Need a program to calculate FF7 PC Savegame checksums
« Reply #2 on: 2005-08-30 08:53:58 »
I know, that this post had been digged from the grave, but... MaTiAz, if you still need help with that checksum, PM me.

dziugo

----------------------------
Edit:
Wanted it, so here it goes:
Checksum calculator

What it does:
Get's a ff7 save-file and writes the correct checksum to every single save game in it.

Usage:
checksum.exe sourcefile.ff7 destinationfile.ff7 //makes a new file
or
checksum.exe file.ff7 //overwrites the original file

Source:
Code: [Select]
#include <stdio.h>
#include <stdlib.h>

using namespace std;

const long FF7_SAVE_GAME_SIZE = 0xFE55;
const long FF7_SAVE_GAME_FIRST_CHECKSUM = 0x09;
const long FF7_SAVE_GAME_SLOT_SIZE = 0x10F4;

int ff7_checksum( void* qw )
{
   int i = 0, t, d;
   long r = 0xFFFF, len = 4336;
   long pbit = 0x8000;
   char* b=(char*)qw;

   while( len-- ) {
      t = b[i++];
      r ^= t << 8;
      for(d=0;d<8;d++) {
         if( r & pbit )
            r = ( r << 1 ) ^ 0x1021;
         else
            r <<= 1;
      }
      r &= ( 1 << 16 ) - 1;
   }
   return (r^0xFFFF)&0xFFFF;
}

int ff7_writechecksums(char *file_name_read, char *file_name_write)
{
    FILE * file;
    void * data;
    long file_size;
   
    if(file_name_read)
    {
       file = fopen(file_name_read, "rb");
       if(file)
       {
          fseek(file, 0, SEEK_END);
          file_size = ftell(file);
          if(file_size == FF7_SAVE_GAME_SIZE)
          {
             rewind(file);
             data = (void*) malloc(file_size);
             if(!data)
             {
                printf("Memory allocation problem.\0");
                return 0;
             }
             fread(data, 1, file_size, file);
             fclose(file);

             for(int i=0, checksum=0; i<15; i++)
             {
                char * data_pointer = ((char*)data + FF7_SAVE_GAME_FIRST_CHECKSUM + \
                   FF7_SAVE_GAME_SLOT_SIZE*i + 0x04);
                checksum = ff7_checksum(data_pointer);
                data_pointer -= 4;
                data_pointer[0] = (char)((checksum)&0xFF);
                data_pointer[1] = (char)((checksum>>8)&0xFF);
                data_pointer[2] = (char)((checksum>>16)&0xFF);
                data_pointer[3] = (char)((checksum>>24)&0xFF);
             }
             if(!file_name_write)
                file_name_write = file_name_read;
             file = fopen(file_name_write, "wb");
             if(file)
             {
                fwrite(data, 1, file_size, file);
                fclose(file);
                free(data);
                return 1;
             }else
             {
                printf("Couldn't open dest-file: %s", file_name_write);
             }
             free(data);
          }
       }else
       {
          printf("Couldn't open source-file: %s", file_name_read);
       }
    }
    return 0;
}

int main(int argc, char *argv[])
{
    int return_value = 0;
    if(argc > 1)
    {
       if(argc == 2)
          return_value = ff7_writechecksums(argv[1], NULL);
       else
          return_value = ff7_writechecksums(argv[1], argv[2]);
    }else
    {
       printf("Not enough parameters.\nUsage: checksum.exe srcfile.ff7 dstfile.ff7\n\n\0");
    }
    if(!return_value)
    {
       printf("There were some errors.\0");
    }
   return EXIT_SUCCESS;
}


That's all folks :P

MaTiAz

  • *
  • Posts: 31
    • View Profile
Need a program to calculate FF7 PC Savegame checksums
« Reply #3 on: 2005-08-30 13:19:19 »
Thanks a lot! :)