Esempio n. 1
0
        public static StageData GetStageData(string zoneName)
        {
            PlayerData playerProfile = PlayerSave.GetPlayerData();

            if (File.Exists(Application.persistentDataPath + "/" + EasyMD5.Hash(playerProfile.playerName + zoneName) + ".bin"))
            {
                try
                {
                    byte[]          key        = Convert.FromBase64String(Crypto.cryptoKey);
                    BinaryFormatter binFormat  = new BinaryFormatter();
                    FileStream      fileStream = new FileStream(Application.persistentDataPath + "/" + EasyMD5.Hash(playerProfile.playerName + zoneName) + ".bin", FileMode.Open);

                    using (CryptoStream cryptoStream = Crypto.CreateDecryptionStream(key, fileStream))
                    {
                        return((StageData)binFormat.Deserialize(cryptoStream));
                    }
                }
                catch
                {
                    Debug.Log("You trying to change data!");
                    StageManager stManager = Resources.Load("Scriptable/Stage/Stage Manager") as StageManager;
                    foreach (Stage stage in stManager.listStages)
                    {
                        StageData stageData = new StageData(stage.zone, stage.levels);
                        StageSave.CreateStageData(stageData, true);
                    }

                    return(GetStageData(zoneName));
                }
            }

            return(null);
        }
Esempio n. 2
0
        public static void CreateStageData(StageData stageData, bool force = false)
        {
            //Debug.Log("Create " + stageData.zone.zoneName);
            PlayerData playerProfile = PlayerSave.GetPlayerData();

            if (force)
            {
                byte[]          key        = Convert.FromBase64String(Crypto.cryptoKey);
                BinaryFormatter binFormat  = new BinaryFormatter();
                FileStream      fileStream = new FileStream(Application.persistentDataPath + "/" + EasyMD5.Hash(playerProfile.playerName + stageData.zone.zoneName) + ".bin", FileMode.Create);

                using (CryptoStream cryptoStream = Crypto.CreateEncryptionStream(key, fileStream))
                {
                    binFormat.Serialize(cryptoStream, stageData);
                }
            }
            else
            {
                if (!File.Exists(Application.persistentDataPath + "/" + EasyMD5.Hash(playerProfile.playerName + stageData.zone.zoneName) + ".bin"))
                {
                    byte[]          key        = Convert.FromBase64String(Crypto.cryptoKey);
                    BinaryFormatter binFormat  = new BinaryFormatter();
                    FileStream      fileStream = new FileStream(Application.persistentDataPath + "/" + EasyMD5.Hash(playerProfile.playerName + stageData.zone.zoneName) + ".bin", FileMode.Create);

                    using (CryptoStream cryptoStream = Crypto.CreateEncryptionStream(key, fileStream))
                    {
                        binFormat.Serialize(cryptoStream, stageData);
                    }
                }
            }
        }
Esempio n. 3
0
        public static void CreatePlayerData(PlayerData playerData)
        {
            Debug.Log(Application.persistentDataPath);
            if (!File.Exists(Application.persistentDataPath + "/" + EasyMD5.Hash(fileName) + ".bin"))
            {
                byte[]          key        = Convert.FromBase64String(Crypto.cryptoKey);
                BinaryFormatter binFormat  = new BinaryFormatter();
                FileStream      fileStream = new FileStream(Application.persistentDataPath + "/" + EasyMD5.Hash(fileName) + ".bin", FileMode.Create);

                using (CryptoStream cryptoStream = Crypto.CreateEncryptionStream(key, fileStream))
                {
                    binFormat.Serialize(cryptoStream, playerData);
                }
            }
        }
Esempio n. 4
0
        public static PlayerData GetPlayerData(string playerName = fileName)
        {
            if (File.Exists(Application.persistentDataPath + "/" + EasyMD5.Hash(playerName) + ".bin"))
            {
                byte[]          key        = Convert.FromBase64String(Crypto.cryptoKey);
                BinaryFormatter binFormat  = new BinaryFormatter();
                FileStream      fileStream = new FileStream(Application.persistentDataPath + "/" + EasyMD5.Hash(playerName) + ".bin", FileMode.Open);

                using (CryptoStream cryptoStream = Crypto.CreateDecryptionStream(key, fileStream))
                {
                    return((PlayerData)binFormat.Deserialize(cryptoStream));
                }
            }

            return(null);
        }
Esempio n. 5
0
        public static void UpdateStageData(StageData stageData)
        {
            PlayerData playerProfile = PlayerSave.GetPlayerData();

            byte[] key = Convert.FromBase64String(Crypto.cryptoKey);

            BinaryFormatter binFormat  = new BinaryFormatter();
            FileStream      fileStream = new FileStream(Application.persistentDataPath + "/" + EasyMD5.Hash(playerProfile.playerName + stageData.zone.zoneName) + ".bin", FileMode.Create);

            using (CryptoStream cryptoStream = Crypto.CreateEncryptionStream(key, fileStream))
            {
                binFormat.Serialize(cryptoStream, stageData);
            }
        }