ArgumentException when using ES3.CacheFile on an encrypted save file

Discussion and help for Easy Save 3
Post Reply
cyangamer
Posts: 4
Joined: Mon Mar 08, 2021 3:22 am

ArgumentException when using ES3.CacheFile on an encrypted save file

Post by cyangamer »

Hi,

I'm unable to get saving working correctly after turning on AES encryption to my save files (I'm doing this to prevent direct edits to the local save).

Here is the code that is called:

Code: Select all

if (!GameServices.IsInitialized()) {
                try {
                    // Cache a local file and load from it.
					ES3Settings settings = new ES3Settings(ES3.EncryptionType.AES, "<REDACTED>");
			        ES3.CacheFile("progress.dat", settings);
                } catch (System.IO.FileNotFoundException e) {
                    Debug.LogWarning("Could not cache file progress.dat because it does not exist");
                }
            }
Default settings use the File type and AES encyption is enabled by default.

If I start the game fresh (no save files), do some actions in a level, and then save the game, and then reload that level, I get this error:

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:348)
ES3File.SaveRaw (System.Byte[] bytes, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3File.cs:167)
ES3File..ctor (System.Byte[] bytes, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3File.cs:83)
ES3File.CacheFile (ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3File.cs:355)
ES3.CacheFile (ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:1049)
ES3.CacheFile (System.String filePath, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:1039)
VisionBreak.Sunsear.GameCore.GameManager.LoadPlayerDataFromMemory () (at Assets/Raptor Combat/Scripts/Game Manager/GameManager.cs:389)
VisionBreak.Sunsear.Core.StageLoader+<LoadStageAsynchronously>d__27.MoveNext () (at Assets/Sunsear/Scripts/StageLoader.cs:287)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: ArgumentException when using ES3.CacheFile on an encrypted save file

Post by Joel »

Hi there,

This usually means that you're trying to save encrypted data to an unencrypted file. In this case deleting the existing save file normally resolves the issue.

If this doesn't resolve the issue, please could you replicate this in a new project and private message it to me with instructions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
cyangamer
Posts: 4
Joined: Mon Mar 08, 2021 3:22 am

Re: ArgumentException when using ES3.CacheFile on an encrypted save file

Post by cyangamer »

Thanks for the reply

That did make the error go away, but what about data integrity? Outside of save function at the end of a level, there are other parts of the game where additional ES3.Save() calls are made. Deleting the save file affects some of those where the variables had been saved earlier in the game.

Is there a way to make sure the file I'm creating through Easy Save is encrypted? since I have encryption enabled by default.
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: ArgumentException when using ES3.CacheFile on an encrypted save file

Post by Joel »

Hi there,

If encryption is enabled in the default settings then this shouldn't be a problem. However, any data stored to the file before encryption was enabled in the default settings will still be unencrypted, which is likely the cause of your original issue.

If you are still getting issues with the save file after deleting the file and enabling encryption by default, please could you replicate this in a new project and private message it to me.

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