Page 1 of 1

Save game SV5 checksum calculation

Posted: 27 Nov 2016 03:38
by 2kan
Hi all,

I'm working on a save game editor for fun but I've run across an issue with calculating the checksum of the save game.

I've read that loco uses (more or less) the same save file encoding as RCT2's SV6 files and the RCT Tech Info Depot states that "The last four bytes of the file is a simple checksum - formed by starting with zero and adding each byte of the file to a 32 bit variable."

I'm able to successfully decode and re-encode the save data, however the checksum doesn't actually seem to be the sum of all bytes in the file. I know this because I have a normal save file that has a checksum of 8381400b (2206285835 in decimal) but when I calculate the sum of all the bytes from either the decoded or encoded file, I only end up with 188777170 and 157339111 in decimal -- more than 11 times less than what I expected.

Does anyone have any insight into how the save file checksum is generated? Am I missing something?

Thanks

Re: Save game SV5 checksum calculation

Posted: 27 Nov 2016 22:20
by Greyfox
Hello 2kan, and welcome to the forums.

After using an online search tool, I came up with this: http://www.checksumcalculator.com/

I'm not sure if this will help you, but I hope it does. I cannot offer any further info.

Good luck

Cheers.

Re: Save game SV5 checksum calculation

Posted: 28 Nov 2016 06:59
by 2kan
Thanks Greyfox, but the checksum algorithm in loco wouldn't be something general like what the link provides. I'll try hashing it just in case though.

Given that Chris Sawyer was pretty much the only developer on the game, it'd be a fair bet to say that the checksum was something he thought of and implemented himself.

Re: Save game SV5 checksum calculation

Posted: 29 Nov 2016 07:10
by 2kan
Hashing the sum with MD5 or SHA1 didn't work, nor did hashing the contents.

Bummer.

Re: Save game SV5 checksum calculation

Posted: 29 Nov 2016 08:32
by 2kan
Okay it turns out that I was reading the checksum hash backwards. Instead of that ridiculously large value I posted earlier, it should be 188776835.

Summing the encoded data from each of the chunks (without the header) gives me 188776823 (difference of -12). Performing the same calculation on a different save file with checksum value of 184093318 gives me 184093801 (difference of 483).... so I'm getting closer. I just need to figure out what makes the difference. It can't be the header data as they're only five bytes long and wouldn't contribute to a difference of almost 500 since the second file was an earlier save of the save I'm using to test. Also because tried it with the header and I get much larger values from my checksum calculation.

Re: Save game SV5 checksum calculation

Posted: 29 Nov 2016 08:40
by 2kan
Never mind.

It is the sum of the bytes.

Reading the hex backwards caused me to over think this.

At least this is confirmation that loco uses the same checksum calculation as RCT2 SV6 files.

:|