--> Balancing a Checksum

BALANCING A CHECKSUM


A checksum is Petz' defence against file tampering. It adds up all the bytes in a file, and if the total is higher or lower than it expects it will deem the file corrupt and refuse to open it.

To avoid corruption, you must balance any edits you make to a file. If you add bytes during editing, you must take them away somewhere else. Conversely, if you remove bytes during editing, you must add them back as well.

If you are editing a Toy or Breed file, you do not need to balance your edits, just ensure the file length is no bigger than it started. Equally, if you are only editing the LNZ portion of a pet's file, LNZ Pro will balance your edits for you.

Note that the method for big edits will work for all edits, and is both the easiest and best option. If you are completely new to HEX, it is recommended you follow the Editing Personality tutorial first for the basics.

If you are lost at any point, or do not understand the language used, refer to the terminology page.


Index

Tiny Edits
Big Edits


Tiny Edits

This method is for edits that only change a handful of values, an amount that is easy enough to balance by hand.

With the tool found in the next section, there is no real use learning this method. However, it will still be recorded here for posterity.

To prep your file, paste a block of z's into your pet's Adult LNZ with LNZ Pro, like so:

;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
;this pet got edited by "enter your name here"
;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

(This z-method was taken from Reloaded's personality tutorial, whose website seems to be down.)

Ensure you save your prepping. You may now make your desired edits, ensuring you are writing down what each value is before (the 'OG value') and after (the 'New value') you edit it.

The method for balancing is different if your new value is higher or lower than the OG.


For Lower edits:

(E.G. 64 HEX to 00 HEX, B6 to A6, etc)

Calculate how many bytes you have taken away with [OG value - New value], then set one 00 in the Blank Zone to that difference.

Example: OG value was 4A HEX, New value is 04 HEX
4A - 04 = 46, so I set one 00 in the Blank Zone to 46 HEX.


For Higher edits

(E.G. 12 HEX to 25 HEX, 00 HEX to 64 HEX, etc)

Calculate how many bytes you have added, then subtract that difference from one z (7A HEX) with [7A - (New value - OG value)], then set one z in the zzz section to the result.

Example: OG value was 32 HEX, New value is 5B HEX
7A - (5B - 32) =
7A - (29) = 51, so I set one z in the zzz section to 51 HEX.


Big Edits

This method will be for edits that change a large amount of values at once, enough that balancing it by hand is unreasonable. It will also work for edits of any size, the only real reason not to use this is if you cannot install Python, for whatever reason.

Reflet has released a tool called Petzbyte, which you can find on their downloads page by scrolling down. It works on Petz 5, and presumably all versions, and is incredibly useful! The instructions say to drag a pet's file onto it, however your system may require these extra steps:

0) Ensure you have Python 3 (or higher) installed.
1) Create a shortcut of Petzbyte somewhere.
2) Right click your shortcut and open Properties.
3) Under 'Target', paste the file path to your Python.exe before whatever text is already there.
To find your Python's file path, you can locate the Python.exe, open its Properties, and copy the target/location data from there.

For instance, my shortcut's target field contains: C:\Users\XXXXXXXXX\AppData\Local\Programs\Python\Python39\python.exe C:\Users\XXXXXXXXX\Desktop\PetzByte.py
(With the XXXX's being my PC's username. The second path is where the original Petzbyte file is, which in this case is my desktop. The two paths are divided by a single space.)

Once that has been saved, dragging pet files onto the shortcut works as intended!


Note that Petzbyte, the checksum balancing tool, will not work with edits that make the pet's file longer. It will work for shorter edits, but balancing longer ones needs extra preparation:

1) First, prep your file for editing like with tiny edits, but with a high amount of z's (or any other character).
2) Highlight all the bytes in the file to get its length, note down this value.
3) Edit the file as usual.
4) Find your file's length once more, note this down as well.
5) Calculate how many bytes you have added to the file, and delete that amount (or more) from the prep section.
6) Then you can drag the file into Petzbyte to balance it as usual.

It is not clear why adding bytes corrupts the pet's file, where removing them is fine, but that is currently just how it is.