Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONCrush seems to be breaking save files in EVO Idle. #6

Open
tygari opened this issue Mar 11, 2020 · 4 comments
Open

JSONCrush seems to be breaking save files in EVO Idle. #6

tygari opened this issue Mar 11, 2020 · 4 comments

Comments

@tygari
Copy link

@tygari tygari commented Mar 11, 2020

save.set =x=>(localStorage.setItem(x,JSONCrush(JSON.stringify(window[x])))); save.get =x=>(JSON.parse(JSONUncrush(decodeURIComponent(save.chk(x))))); save.del =x=>(localStorage.removeItem(x)); save.chk =x=>(localStorage.getItem(x));
My code for incorporating JSONCrush into my game.
My players are reporting weird errors.

One player sent me their save file. I can not get it to uncompress without throwing a JSON error.
best I can tell it is uncompressing as "".

('V7versiHN.48~daK!1583863249569EJ7num!1~wrd!'Y'~fFatp'~food!10000~atpCaK!2692~mFflagellum'~rushed!53834655~bWed_LMr7Iak!900~bWCauto!245~enviro!45000Eevent7failLMrCmove_echo7strucZbubbIWG~develop-taInts-boost-JZATP'~XG~V-body-cross-RZmoKG~exoLcZUGEQ7XCQlvedCbHusCY_Y7MtacycICMtabolism7FnY')EtwoBthreeBfourBfiveBsixBcombatBcrossBR7blackbluegreenorangepurpIredwhiKyellowSEexoLcBenviro7sun7shift!1~posiLH!99EvirusD1OOO%5DEsize7VCJ_U7whoICparLalN))S~-D%5D~7!('B!(ECN~D!%5BE)~Ftype!'G'%5DHonIleJstageKteLtiMmeN!0O%2C0QevoRKmporalS!falseUproKinVgaMWIssXQluLHYHeZD'_NE%01_ZYXWVUSRQONMLKJIHGFEDCB7-*

The player swears they in no way tried to alter the save file.

I would like to solve this issue and keep using this compression library.

@KilledByAPixel

This comment has been minimized.

Copy link
Owner

@KilledByAPixel KilledByAPixel commented Mar 11, 2020

It looks like for some reason all of the * in your string except for the one at the end have been removed. I manually fixed up the string and I think this is what it should look like...

('V7versiHN.48~daK!1583863249569EJ7num!1~wrd!'Y'~fFatp'~food!10000~atpCaK!2692~mFflagellum'~rushed!53834655~bWed_LMr7Iak!900~bWCauto!245~enviro!45000Eevent7failLMrCmove_echo7strucZbubbIWG~develop-taInts-boost-JZATP'~XG~V-body-cross-RZmoKG~exoLcZUGEQ7XCQlvedCbHusCY_Y7MtacycICMtabolism7FnY')EtwoBthreeBfourBfiveBsixBcombatBcrossBR7black*blue*green*orange*purpI*red*whiK*yellowSEexoLcBenviro7sun7shift!1~posiLH!99EvirusD1OOO%5DEsize7VCJ_U7whoICparLalN))*S~-D%5D~7!('B!(ECN~D!%5BE)~Ftype!'G'%5DHonIleJstageKteLtiMmeN!0O%2C0QevoRKmporalS!falseUproKinVgaMWIssXQluLHYHeZD'_NE%01_ZYXWVUSRQONMLKJIHGFEDCB7-*

resulting in this json...

{"game":{"version":0.48,"date":1583863249569},"stage":{"num":1,"wrd":"one","ftype":"atp","food":10000,"atp":0,"ate":2692,"mtype":"flagellum","rushed":53834655,"blessed":0},"timer":{"leak":900,"bless":0,"auto":245,"enviro":45000},"event":{"failtimer":0,"move":0},"echo":{"struc":["bubbleless"],"develop":[],"talents":[],"boost":[],"stage":["ATP","evolution"],"game":[],"body":[],"cross":[],"temporal":["mote"],"exotic":["protein"]},"evo":{"evolution":0,"evolved":0,"bonus":0,"one":0},"one":{"metacycle":0,"metabolism":{"type":"none"}},"two":{},"three":{},"four":{},"five":{},"six":{},"combat":{},"cross":{},"temporal":{"black":false,"blue":false,"green":false,"orange":false,"purple":false,"red":false,"white":false,"yellow":false},"exotic":{},"enviro":{"sun":{"shift":1,"position":99},"virus":[1,0,0,0]},"size":{"game":0,"stage":0},"protein":{"whole":0,"partial":0}}

Your code looks ok so I am not sure what is causing it. If you could find a way to reproduce it that would help. I really don't think this has anything to do with JSONCrush though.

Also, for your use case, saving to local storage, I would recommend not using JSONCrush. Just saving the json to local storage directly should be fine.

@tygari

This comment has been minimized.

Copy link
Author

@tygari tygari commented Mar 11, 2020

That is a correct decompression.
Why would all the * disappear?
An uncompressed save file is easy to read and alter by cheaters.
This is also my test case before I planned to use it to transmit data to and from the server.
I don't yet have a database system setup so the local storage is the only option.
Do you think local storage is what is removing the *'s?
If so why?

@KilledByAPixel

This comment has been minimized.

Copy link
Owner

@KilledByAPixel KilledByAPixel commented Mar 11, 2020

I am not sure, but I don't think it has anything to do with JSONCrush. Local storage should not remove a * from a string. Are you sending this save file from the server, maybe there is a bug with something in that?

If you want to prevent cheating, there may be a better way, like you could apply a simple cipher to the JSON string.

My advice is for now to disable JSONCrush and see if the problem persists.

@tygari

This comment has been minimized.

Copy link
Author

@tygari tygari commented Mar 11, 2020

I shared all the code associated with JSONCrush. It is not currently working with any code from the server. I am still writing that.
It is currently being used only to compress the save file for local storage and make said save file more undecipherable.
If there is a bug in my part it is in the code I shared.

If you would like to verify my code it can be found here on my GitHub under EVO Idle repository. The functions shared above can be found on file load.js within the /js folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.