ArgumentException on getting bytes of an ecrypted file

Discussion and help for Easy Save 3
Post Reply
fur
Posts: 9
Joined: Fri Jul 28, 2017 6:12 am

ArgumentException on getting bytes of an ecrypted file

Post by fur »

I have an ecrypted file for game save, when I load its bytes and try to use and read it back (so I can upload/download game save to Google Play and iCloud saved game). I got an ArgumentException. Not sure if that's a bug or anything I did wrong.

Code: Select all

ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
ES3Internal.ES3Stream.CreateStream (System.IO.Stream stream, ES3Settings settings, ES3Internal.ES3FileMode fileMode) (at Assets/Plugins/Easy Save 3/Scripts/Streams/ES3Stream.cs:102)
ES3Reader.Create (System.Byte[] bytes, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:364)
ES3File.SaveRaw (System.Byte[] bytes, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3File.cs:170)
ES3File..ctor (System.Byte[] bytes, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3File.cs:83)
Code I use is very simple:

Code: Select all

byte[] bytes = ES3.LoadRawBytes(ES3Settings.defaultSettings); // Using the default setting with AES

ES3File newFile = new ES3File(bytes);

System.DateTime serverFileDateTime = serverFile.Load<System.DateTime>("Timestamp"); // Try to read the Timestamp variable saved in the file but it causes ArguementException
Same if I simple saved it back as original file:

Code: Select all

...
ES3File newFile = ES3File(bytes, ES3Settings.defaultSettings);
... // Still giving ArguementException
However, I can hack it by saving it as a tmp file first:

Code: Select all

...
string tmpPath = ES3Settings.defaultSettings.path;
var tmpSetting = new ES3Settings(tmpPath, ES3Settings.defaultSettings);
ES3.SaveRaw(bytes, tmpPath);
ES3File newFile = new ES3File(tmpSetting);

System.DateTime serverFileDateTime = serverFile.Load<System.DateTime>("Timestamp"); // No ArgumentException, all good!
Is that intended? I simply want to read the bytes (and compare to the original bytes) and don't really want to save as a tmp file until I want to.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: ArgumentException on getting bytes of an ecrypted file

Post by Joel »

Hi there,

The issue is likely to be because ES3.LoadRawBytes will decrypt the data, but ES3File is expecting encrypted data.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply