// Save Options/Settings public static async Task SaveOptionsAsync(GameSettings gameSettings) { if (SelectedProfileManager.selectedProfile == null) { return; } string fullProfileName = SelectedProfileManager.selectedProfile.fullProfileName; if (gameSettings == null) { return; } string path = Path.Combine(MainDirectoryPath, fullProfileName, "Settings.dat"); string json = JsonUtility.ToJson(gameSettings); // Creates the unique Encryption key per profile string jsonEncryptedKey = "AhExy6ntHa>zkh+r@M;b^jM|=D=~!S{c"; // If the value is longer then 32 characters it will make it 32 characters if (jsonEncryptedKey.Length > 32) { jsonEncryptedKey = jsonEncryptedKey.Truncate(32); } // Encryption process Rijndael crypto = new Rijndael(); byte[] soup = crypto.Encrypt(json, jsonEncryptedKey); await AsyncHelperExtensions.WriteBytesAsync(path, soup); SaveManagerEvents.current.SaveOptions(gameSettings, SelectedProfileManager.selectedProfile); }
private async void OnPostRender() { if (SelectedProfileManager.selectedProfile == null) { return; } if (!takeScreenshotOnNextFrame) { return; } takeScreenshotOnNextFrame = false; RenderTexture renderTexture = myCamera.targetTexture; Texture2D renderResult = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false); Rect rect = new Rect(0, 0, renderTexture.width, renderTexture.height); renderResult.ReadPixels(rect, 0, 0); byte[] byteArray = renderResult.EncodeToPNG(); string path = Path.Combine(Application.persistentDataPath, "Profiles", SelectedProfileManager.selectedProfile.fullProfileName, "ProfilePicture.png"); await AsyncHelperExtensions.WriteBytesAsync(path, byteArray); Debug.Log("Saved Profile Picture."); RenderTexture.ReleaseTemporary(renderTexture); myCamera.targetTexture = null; }
public static async Task <ProfileData> LoadProfileAsync(string path, string profileName, string profileId) { // This is the encrypted input from the file byte[] soupBackIn = await AsyncHelperExtensions.ReadBytesAsync(path); // Creates the unique Encryption key per profile string jsonEncryptedKey = $"{profileName}BXRB98y-h^4^.ct^]~8|Cmn5([]+/+{profileName}@&"; // If the key is shorter then 32 characters it will make it longer if (jsonEncryptedKey.Length < 33) { while (jsonEncryptedKey.Length < 33) { jsonEncryptedKey = $"{profileName}BXRB98y-h^4^.ct^]~8|Cmn5([-+/{profileName}@&{profileName}"; } } // If the value is longer then 32 characters it will make it 32 characters if (jsonEncryptedKey.Length > 32) { jsonEncryptedKey = jsonEncryptedKey.Truncate(32); } // Decrypting process Rijndael crypto = new Rijndael(); string jsonFromFile = crypto.Decrypt(soupBackIn, jsonEncryptedKey); // Creates a ProfileData object with the information from the json file ProfileData profile = JsonUtility.FromJson <ProfileData>(jsonFromFile); // Checks if the decrypted Profile Data is null or not if (profile == null) { Debug.Log("Failed to load profile"); return(null); } if (profile.fullProfileName != profileName) { Debug.Log("Profile Name's are not matching"); return(null); } if (profile.profileId != profileId) { Debug.Log("Profile ID's are not matching"); return(null); } SaveManagerEvents.current.ProfileLoaded(profile); return(profile); }
public static async Task LoadAllProfilesAsync(string path) { // This is the encrypted input from the file byte[] soupBackIn = await AsyncHelperExtensions.ReadBytesAsync(path); // Decrypting process Rijndael crypto = new Rijndael(); string jsonFromFile = crypto.Decrypt(soupBackIn, JsonEncryptedKeyProfiles); ProfilesListWrapper profiles = JsonUtility.FromJson <ProfilesListWrapper>(jsonFromFile); SaveManager.profiles = profiles == null ? new List <ProfilesData>() : profiles.Profiles; SaveManagerEvents.current.AllProfilesLoaded(SaveManager.profiles); }
// Load Game public static async Task <GameData> LoadGameAsync() { if (SelectedProfileManager.selectedProfile == null) { return(null); } string fullProfileName = SelectedProfileManager.selectedProfile.fullProfileName; string path = Path.Combine(MainDirectoryPath, fullProfileName, "Save", "data.dat"); if (!File.Exists(path)) { return(null); } // This is the encrypted input from the file byte[] soupBackIn = await AsyncHelperExtensions.ReadBytesAsync(path); // Creates the unique Encryption key per profile string jsonEncryptedKey = "|9{Ajia:p,g<ae&)9KsLy7;<t9G5sJ>G"; // If the value is longer then 32 characters it will make it 32 characters if (jsonEncryptedKey.Length > 32) { jsonEncryptedKey = jsonEncryptedKey.Truncate(32); } // Decrypting process Rijndael crypto = new Rijndael(); string jsonFromFile = crypto.Decrypt(soupBackIn, jsonEncryptedKey); // Creates a ProfileData object with the information from the json file GameData gameData = JsonUtility.FromJson <GameData>(jsonFromFile); // Checks if the decrypted Profile Data is null or not if (gameData == null) { Debug.Log("Failed to load game data."); return(null); } SaveManagerEvents.current.LoadGame(gameData, SelectedProfileManager.selectedProfile); return(gameData); }
public static async Task SaveAllProfilesAsync(string path) { ProfilesListWrapper profiles = new ProfilesListWrapper() { Profiles = SaveManager.profiles }; string json = JsonUtility.ToJson(profiles); // Encrypting process Rijndael crypto = new Rijndael(); byte[] soup = crypto.Encrypt(json, JsonEncryptedKeyProfiles); await AsyncHelperExtensions.WriteBytesAsync(path, soup); SaveManagerEvents.current.AllProfilesSaved(SaveManager.profiles); }
public static async Task SaveProfileAsync(string path, string profileImage, string profileName, string profileId, string fullProfileName) { ProfileData profile = CreateProfile(profileId, profileImage, profileName, fullProfileName, false); if (profile == null) { return; } string json = JsonUtility.ToJson(profile); // Creates the unique Encryption key per profile string jsonEncryptedKey = $"{fullProfileName}BXRB98y-h^4^.ct^]~8|Cmn5([]+/+{fullProfileName}@&"; // If the key is shorter then 32 characters it will make it longer if (jsonEncryptedKey.Length < 33) { while (jsonEncryptedKey.Length < 33) { jsonEncryptedKey = $"{fullProfileName}BXRB98y-h^4^.ct^]~8|Cmn5([-+/{fullProfileName}@&{fullProfileName}"; } } // If the value is longer then 32 characters it will make it 32 characters if (jsonEncryptedKey.Length > 32) { jsonEncryptedKey = jsonEncryptedKey.Truncate(32); } // Encryption process Rijndael crypto = new Rijndael(); byte[] soup = crypto.Encrypt(json, jsonEncryptedKey); await AsyncHelperExtensions.WriteBytesAsync(path, soup); ProfilesData profiles = CreateProfilesData(profileId, profileName, fullProfileName); await LoadAllProfilesAsync(ProfilesPath); SaveManager.profiles.Add(profiles); await SaveAllProfilesAsync(ProfilesPath); SaveManagerEvents.current.ProfileSaved(profile); }
// Load Options/Settings public static async Task <GameSettings> LoadOptionsAsync() { if (SelectedProfileManager.selectedProfile == null) { return(null); } string fullProfileName = SelectedProfileManager.selectedProfile.fullProfileName; string path = Path.Combine(MainDirectoryPath, fullProfileName, "Settings.dat"); if (!File.Exists(path)) { return(null); } // This is the encrypted input from the file byte[] soupBackIn = await AsyncHelperExtensions.ReadBytesAsync(path); // Creates the unique Encryption key per profile string jsonEncryptedKey = "AhExy6ntHa>zkh+r@M;b^jM|=D=~!S{c"; // If the value is longer then 32 characters it will make it 32 characters if (jsonEncryptedKey.Length > 32) { jsonEncryptedKey = jsonEncryptedKey.Truncate(32); } // Decrypting process Rijndael crypto = new Rijndael(); string jsonFromFile = crypto.Decrypt(soupBackIn, jsonEncryptedKey); // Creates a ProfileData object with the information from the json file GameSettings gameSettings = JsonUtility.FromJson <GameSettings>(jsonFromFile); // Checks if the decrypted Game Settings is null or not if (gameSettings != null) { SaveManagerEvents.current.LoadOptions(gameSettings, SelectedProfileManager.selectedProfile); return(gameSettings); } Debug.Log("Failed to load game Settings."); return(null); }
// Save Game public static async Task SaveGameAsync(bool hasPlayed, int balance, Vector3 playerPosition, Quaternion playerRotation, Vector3 cameraPosition, Quaternion cameraRotation) { if (SelectedProfileManager.selectedProfile == null) { return; } string fullProfileName = SelectedProfileManager.selectedProfile.fullProfileName; GameData gameData = CreateGameData(hasPlayed, balance, playerPosition, playerRotation, cameraPosition, cameraRotation); if (gameData == null) { return; } string path = Path.Combine(MainDirectoryPath, fullProfileName, "Save", "data.dat"); string dirPath = Path.Combine(MainDirectoryPath, fullProfileName, "Save"); if (!Directory.Exists(dirPath)) { FileManagerExtension.CreateDirectory(dirPath); } string json = JsonUtility.ToJson(gameData); // Creates the unique Encryption key per profile string jsonEncryptedKey = "|9{Ajia:p,g<ae&)9KsLy7;<t9G5sJ>G"; // If the value is longer then 32 characters it will make it 32 characters if (jsonEncryptedKey.Length > 32) { jsonEncryptedKey = jsonEncryptedKey.Truncate(32); } // Encryption process Rijndael crypto = new Rijndael(); byte[] soup = crypto.Encrypt(json, jsonEncryptedKey); await AsyncHelperExtensions.WriteBytesAsync(path, soup); SaveManagerEvents.current.SaveGame(gameData, SelectedProfileManager.selectedProfile); }
private async Task LoadProfile(string profilePath) { string profileConfigPath = profilePath + "/config.dat"; string loadProfileName = profilePath.Split('\\').Last(); // Deletes Directory if config file doesn't exist if (!Directory.Exists(profilePath) || !File.Exists(profileConfigPath)) { Debug.Log("Failed to load " + loadProfileName + " could not locate needed information"); } else if (!SaveManager.profiles.Exists(p => p.profileId.ToString().Equals(loadProfileName.Split(' ').Last()))) { Debug.Log(loadProfileName + " not found in profiles.dat file profile will not be loaded"); } else { // Loads the profile and it's content ProfileData profile = await SaveManager.LoadProfileAsync(profileConfigPath, loadProfileName, loadProfileName.Split(' ').Last()); if (profile != null) { string profileImagePath = Path.Combine(profilePath, "ProfilePicture.png"); // Creates the stuff needed for the Profiles UI GameObject profilesUiClone = Instantiate(profilesUi) as GameObject; profilesUiClone.transform.SetParent(GameObject.Find("Profiles").transform.Find("Viewport").Find("Content").transform, false); profilesUiClone.AddComponent <SelectProfileData>(); profilesUiClone.GetComponent <SelectProfileData>().profileName = profile.profileName; profilesUiClone.GetComponent <SelectProfileData>().profileId = profile.profileId; profilesUiClone.GetComponent <SelectProfileData>().profileImage = profile.profileImage; profilesUiClone.GetComponent <SelectProfileData>().fullProfileName = profile.fullProfileName; profilesUiClone.transform.Find("ProfileInformation").transform.Find("ProfileName").GetComponentInChildren <Text>().text = profile.profileName; profilesUiClone.transform.Find("ProfileInformation").transform.Find("FullProfileName").GetComponentInChildren <Text>().text = profile.fullProfileName; if (profilesUiClone.transform.Find("ProfileImages").transform.Find(profile.profileImage) != null) { profilesUiClone.transform.Find("ProfileImages").transform.Find(profile.profileImage).gameObject.SetActive(true); } else if (File.Exists(profileImagePath)) { GameObject profileImage = profilesUiClone.transform.Find("ProfileImages").transform.Find("ProfileImage").gameObject; Texture2D tempPic = await AsyncHelperExtensions.LoadTexture2DAsync(profileImagePath); profileImage.GetComponent <RawImage>().texture = tempPic; profileImage.transform.SetParent(profilesUiClone.transform.Find("ProfileImages").transform, false); } else { Sprite defaultProfilePicture = Resources.Load <Sprite>("Sprites/DefaultProfilePicture"); if (defaultProfilePicture == null) { Debug.Log("Failed to load any profile pictures."); return; } GameObject profileImage = profilesUiClone.transform.Find("ProfileImages").transform .Find("ProfileImage").gameObject; profileImage.GetComponent <RawImage>().texture = defaultProfilePicture.texture; profileImage.transform.SetParent(profilesUiClone.transform.Find("ProfileImages").transform, false); } profilesUiClone.name = profile.fullProfileName; profilesUiClone.tag = "ProfileUI(Clone)"; if (SaveManager.profiles.Where(p => p.profileName.Equals(profile.profileName)).ToList().Count > 1) { profilesUiClone.transform.Find("ProfileInformation").gameObject.transform.Find("ProfileName").gameObject.SetActive(false); profilesUiClone.transform.Find("ProfileInformation").transform.Find("FullProfileName").gameObject.SetActive(true); } if (profile.profileName.Equals("eirik", StringComparison.OrdinalIgnoreCase)) { if (ColorUtility.TryParseHtmlString("#EFB366", out Color backgroundColor) && ColorUtility.TryParseHtmlString("#23404B", out Color textColor)) { profilesUiClone.transform.Find("ProfileInformation").GetComponent <Image>().color = backgroundColor; profilesUiClone.transform.Find("ProfileImages").GetComponent <Image>().color = backgroundColor; profilesUiClone.transform.Find("ProfileInformation").Find("ProfileName").GetComponent <Text>().color = textColor; profilesUiClone.transform.Find("ProfileInformation").Find("FullProfileName").GetComponent <Text>().color = textColor; } } profilesUiClone.SetActive(true); } } }