Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    // 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);
    }
Ejemplo n.º 4
0
    // 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);
    }