Page 1 of 1

Loading Binary Data

Posted: Thu Aug 20, 2020 2:19 am
by mdeim
Hi Joel,

Currently, I've programmed the game to save data as an ES3 cache JSON file and then I sync to persistence data path while in development and not encrypted for the ease of developing the game and knowing what's in my save file.

We're now setting up the game for production so we would have to add in encryption and since the game is for mobile we have to make these JSON ES3 cached files as a binary blob, since from what I'm reading, it's the only thing Google Drive accepts.

So far encrypting the JSON files is very easy, I just added encryption types and pass in the editor, also I can make data as bytes easily with:

Code: Select all

                byte[] FileInBytes = CachedFile.LoadRawBytes();
                ES3.SaveRaw(FileInBytes, Path);
But when I load the data, I first check if the key exists via

Code: Select all

ES3.KeyExists(MyKey, PathToSaveFile)
which in turn creates this error:

Code: Select all

FormatException: Cannot load from file because the data in it is not JSON data, or the data is encrypted.
If the save data is encrypted, please ensure that encryption is enabled when you load, and that you are using the same password used to encrypt the data.
ES3Internal.ES3JSONReader..ctor (System.IO.Stream stream, ES3Settings settings, System.Boolean readHeaderAndFooter) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:39)
So I have two questions.
1. Is there a way for me to check if a key exists with a binary file( hopefully ES3.Load should work fine too)?
2. Is there a method that loads binary data back to it's JSON form, that could be one way to fix this. Creating this myself would be so time-consuming since the file is huge, which is one reason I bought this asset as a time saver, unfortunately I didn't see this in your API? Let me know if I'm mistaken.

Thanks so much for your help!

Re: Loading Binary Data

Posted: Thu Aug 20, 2020 2:27 am
by mdeim
By the way, this is only happening if I encrypt the binary data, otherwise yes the KeyExists and Load work fine. Is there no way to encrypt binary data?

Re: Loading Binary Data

Posted: Thu Aug 20, 2020 6:18 am
by Joel
Hi there,

You are getting this error because by turning it into binary the data is no longer JSON or encrypted JSON.

As far as I can tell there would be no benefit to converting it to binary if you are encrypting it. Instead you should simply store the cached file using ES3.StoreCachedFile with encryption enabled.

All the best,
Joel

Re: Loading Binary Data

Posted: Thu Aug 20, 2020 4:27 pm
by mdeim
Hi,

Thanks for the reply.
I'm a little bit confused why you say there is no use. Correct me if I'm wrong, but everywhere I'm reading mobile storage like Google drive only accept a binary blob. Isn't a binary blob only made out of bytes? And what if you have sensitive information in the save file, the bytes file should still be encrypted.

If I just save the cache file then it would still save as JSON and I wouldn't be able to save it in Google Drive.

Re: Loading Binary Data

Posted: Thu Aug 20, 2020 4:42 pm
by Joel
Hi there,

Google Drive accepts a byte array, but this doesn't need to be in binary format. If you want to get your encrypted JSON data as byte array, you can simply store the data to cache with encryption enabled and use ES3.LoadRawBytes to get it as a byte array:

Code: Select all

var settings = new ES3Settings(ES3.EncryptionType.AES, ES3.Location.Cache);
ES3.Save("mykey", 123, settings);
byte[] bytes = ES3.LoadRawBytes(settings);
All the best,
Joel

Re: Loading Binary Data

Posted: Thu Aug 20, 2020 5:09 pm
by mdeim
Ok thank you. But then when I get the files as bytes from Google again would there be any problems/errors like I have now with authenticator, or does EasySave3 Handle this too since now it would be in bytes and encrypted?

And do I need to enter encryption within the script to make this all work, because right now I have it in the editor.

Re: Loading Binary Data

Posted: Thu Aug 20, 2020 5:37 pm
by Joel
Hi there,

As long as the bytes you get back from Google are the same as the ones you sent there, Easy Save will have no issues loading from them.

Just to confirm, having encryption set in the Editor will also work.

All the best,
Joel

Re: Loading Binary Data

Posted: Thu Aug 20, 2020 5:40 pm
by mdeim
Thank you 🙏