Hi Joel, hope you are doing well!
I took a break from this for some time... Now I'm back. I did read up on the link you shared (w3schools). It's a good read, thank you!
I also tried it on another phone and I have this new 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 (ES3Settings settings, ES3Internal.ES3FileMode fileMode) (at F:/Desktop/Shark Pew Pew/SharkPewPew/Assets/Settings/Asset Store Packages/Easy Save 3/Scripts/Streams/ES3Stream.cs:65)
ES3Reader.Create (ES3Settings settings) (at F:/Desktop/Shark Pew Pew/SharkPewPew/Assets/Settings/Asset Store Packages/Easy Save 3/Scripts/Readers/ES3Reader.cs:342)
ES3.KeyExists (System.String key, ES3Settings settings) (at F:/Desktop/Shark Pew Pew/SharkPewPew/Assets/Settings/Asset Store Packages/Easy Save 3/Scripts/ES3.cs:1097)
ES3.KeyExists (System.String key) (at F:/Desktop/Shark Pew Pew/SharkPewPew/Assets/Settings/Asset Store Packages/Easy Save 3/Scripts/ES3.cs:1066)
User.LoadUser (System.Boolean newEntrySaveDataLocal, System.Boolean newEntrySaveDataCloud) (at F:/Desktop/Shark Pew Pew/SharkPewPew/Assets/Scripts/Game Data Classes/User/User.cs:63)
GameData.Start () (at F:/Desktop/Shark Pew Pew/SharkPewPew/Assets/Scripts/Photon Networking/GameData.cs:62)
***EDIT01***
Code: Select all
public ES3Settings ES3Settings { get; private set; }
private void SetupEasySaveSettings()
{
// Apply defaults as set within the inspector Runtime Settings of EasySave3.
ES3Settings = new ES3Settings(true);
if (ES3.FileExists())
{
try
{
ES3.KeyExists("test");
}
catch (FormatException)
{
// A FormatException was thrown in EasySave3 from:
// ES3Internal.ES3JSONReader..ctor(System.IO.Stream stream, ES3Settings settings, System.Boolean readHeaderAndFooter)(at Assets / Settings / Asset Store Packages / Easy Save 3 / Scripts / Readers / ES3JSONReader.cs:39)
// The message:
// FormatException("Cannot load from file because the data in it is not JSON data, or the data is encrypted.\nIf 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.");
// Solution:
// Create a new ES3Settings object with password.
Debug.Log($"FormatException - Exception caught. Attempting to load using password.");
ES3Settings = new ES3Settings(ES3.EncryptionType.AES, "JohnnySuperShiningStar");
}
}
}
I managed to handle the FormatException as mentioned in the very first post of this thread. All the loading will be using example:
Code: Select all
playerUserID = ES3.KeyExists("playerUserID", GameData.Instance.ES3Settings) == true ? ES3.Load<string>("playerUserID", GameData.Instance.ES3Settings) : "";
Is this how it should be done?
Is there any way to check if a bytes array was password protected and if it was, what was the password it was protected with (for debugging purposes only)?
But how do I handle the new ArgumentException error mentioned above?
***EDIT02***
As mentioned in EDIT01 on how I handle FormatException there's another issue I encounter on further testing.
Is there a way to open encrypted files and then save it without encryption? Why I'm asking is because I need to know if it's doable.
So what I did:
> clear slate: deleted save file
> inspector runtime settings have aes encryption on with a password
> ran the game
> created a save file normally in-game with save functions "
ES3.Save<string>("playerNickname", playerNickname);"
> stopped the game
> inspector runtime settings set encryption to none
> ran the game
> loading data works fine due to how I handle the FormatException and load data as mentioned in EDIT01
> but I can no longer save using "
ES3.Save<string>("playerNickname", playerNickname);" as it will throw FormatException