- Joined
- Jul 10, 2007
- Messages
- 6,306
If you are doing versioned save/load, you'll generally be adding 1 to the max checksum with each version.
checksum = version + checksum base
What this means is that when a player loads up the code, one can retrieve the version of the code assuming that they didn't type it in incorrectly
version = current version - (generated checksum - checksum)
generated checksum - checksum would be how many versions back. Subtract that from current version the map is on and you have the version of the code.
Now the only problem with this is that invalid codes for the code version might load up properly in a later version. For example, the player makes 1 typo in the code and then it loads it up in the incorrect version correctly. By dynamically getting the version from the code using the checksum and expected checksum, there are more chances for checksum collisions.
The Knuth Checksum does protect against patterns: n(n+3)%m, but changing an earlier digit means a big change, and I don't know if the knuth would protect well against this across multiple versions.
Anyways, that's my current thought on dynamic version retrieval. Does anyone else have any interesting ideas that could possibly be better protected? My idea would work 100% of the time if the player never entered invalid codes, but that would never be the case.
Also, do you guys think that my idea of dynamic version retrieval is fine as it is? It would mean that you wouldn't need to do this anymore-
-load version, code
You could have versioned codes without storing the version into the code and without displaying it : ).
edit
Actually, you could initially add 1 to the number and at the end make sure that you have exactly 1 left in the stack. If the stack is not 1, then you know that the code was out of bounds.
Why I say to check for 1 and not 0 is because 1 will check for codes that are too small and too large. 0 only checks for codes that are too large. This would actually remove the need for IsStringLengthInRange checking. Of course, to use this method, you would need to inline things like SaveInventory and load up all data before you actually create anything (like creating player hero and adding inventory items). This complicates the overall save/load process, but it does give great code range checking and allows you to do dynamic version retrieval (as versions change, the code will be thrown out of bounds if it somehow works).
checksum = version + checksum base
What this means is that when a player loads up the code, one can retrieve the version of the code assuming that they didn't type it in incorrectly
version = current version - (generated checksum - checksum)
generated checksum - checksum would be how many versions back. Subtract that from current version the map is on and you have the version of the code.
Now the only problem with this is that invalid codes for the code version might load up properly in a later version. For example, the player makes 1 typo in the code and then it loads it up in the incorrect version correctly. By dynamically getting the version from the code using the checksum and expected checksum, there are more chances for checksum collisions.
The Knuth Checksum does protect against patterns: n(n+3)%m, but changing an earlier digit means a big change, and I don't know if the knuth would protect well against this across multiple versions.
Anyways, that's my current thought on dynamic version retrieval. Does anyone else have any interesting ideas that could possibly be better protected? My idea would work 100% of the time if the player never entered invalid codes, but that would never be the case.
Also, do you guys think that my idea of dynamic version retrieval is fine as it is? It would mean that you wouldn't need to do this anymore-
-load version, code
You could have versioned codes without storing the version into the code and without displaying it : ).
edit
Actually, you could initially add 1 to the number and at the end make sure that you have exactly 1 left in the stack. If the stack is not 1, then you know that the code was out of bounds.
Why I say to check for 1 and not 0 is because 1 will check for codes that are too small and too large. 0 only checks for codes that are too large. This would actually remove the need for IsStringLengthInRange checking. Of course, to use this method, you would need to inline things like SaveInventory and load up all data before you actually create anything (like creating player hero and adding inventory items). This complicates the overall save/load process, but it does give great code range checking and allows you to do dynamic version retrieval (as versions change, the code will be thrown out of bounds if it somehow works).