Loading Binary Data

Discussion and help for Easy Save 3
Post Reply
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Loading Binary Data

Post 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!
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Re: Loading Binary Data

Post 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?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Loading Binary Data

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Re: Loading Binary Data

Post 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.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Loading Binary Data

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Re: Loading Binary Data

Post 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.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Loading Binary Data

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mdeim
Posts: 27
Joined: Sat May 09, 2020 7:31 pm

Re: Loading Binary Data

Post by mdeim »

Thank you 🙏
Post Reply