Exemplo n.º 1
0
Arquivo: ECTD.cs Projeto: Cuber01/ECTD
        public static bool Unlocks_AddNuggets(int numNuggets)
        {
            SessionDataBig session = GameController.gameController.sessionDataBig;

            int previous = session.nuggets;

            session.nuggets += numNuggets;
            if (!GameController.gameController.challenges.Contains("ECTD-NoLimitNuggets") && session.nuggets > 99 && previous <= 99)
            {
                session.nuggets = 99;
            }
            plugin.nuggetsDictionary[session.saveSlot] = session.nuggets;
            plugin.SaveNuggets();

            GameController.gameController.unlocks.SaveUnlockData(true);
            return(false);
        }
Exemplo n.º 2
0
Arquivo: ECTD.cs Projeto: Cuber01/ECTD
        public void LoadConfigFile()
        {
            try
            {
                nuggetsDictionary = new Dictionary <int, int>();
                if (!File.Exists(nuggetsPath))
                {
                    File.WriteAllText(nuggetsPath, "1:-1\n2:-1\n3:-1\n4:-1\n5:-1");
                }
                string   data  = File.ReadAllText(nuggetsPath);
                string[] lines = data.Split('\n');
                foreach (string line in lines)
                {
                    string[] parts = line.Split(':');
                    if (parts.Length != 2)
                    {
                        return;
                    }
                    if (!int.TryParse(parts[0], out int slot) || !int.TryParse(parts[1], out int nuggets))
                    {
                        return;
                    }
                    nuggetsDictionary.Add(slot, nuggets);
                }
            }
            catch (Exception e)
            {
                Logger.LogError("Error parsing " + nuggetsPath + "!");
                Logger.LogError(e);
            }

            SessionDataBig session = GameController.gameController.sessionDataBig;

            if (session == null)
            {
                Logger.LogWarning("Could not read sessionDataBig!");
                return;
            }

            if (!nuggetsDictionary.ContainsKey(session.saveSlot))
            {
                nuggetsDictionary.Add(session.saveSlot, session.nuggets);
            }
            int ectdNuggets = nuggetsDictionary[session.saveSlot];

            if (session.nuggets == 99 && ectdNuggets > 99)
            {
                session.nuggets = ectdNuggets;
            }
            else if (session.nuggets != ectdNuggets)
            {
                if (ectdNuggets != -1)
                {
                    session.nuggets = nuggetsDictionary[session.saveSlot] = Mathf.Min(session.nuggets, ectdNuggets);
                }
                else
                {
                    nuggetsDictionary[session.saveSlot] = session.nuggets;
                }
            }

            SaveNuggets();
        }
Exemplo n.º 3
0
#pragma warning disable CS0618 // Type or member is obsolete
        public static void InitializeUnlockWrappers()
        {
            GameController gc  = GameController.gameController;
            SessionDataBig sdb = gc.sessionDataBig;

            foreach (Unlock unlock in sdb.unlocks.ToList())
            {
                // wrapping original unlocks
                if (string.IsNullOrEmpty(gc.unlocks.GetSpecialUnlockInfo(unlock.unlockName, unlock)))
                {
                    unlock.cost = -2;
                    if (RogueFramework.IsDebugEnabled(DebugFlags.Unlocks))
                    {
                        RogueFramework.LogDebug($"\"{unlock.unlockName}\" ({unlock.unlockType}) has special unlock conditions.");
                    }
                }

                UnlockWrapper wrapper;
                if (unlock.unlockType == UnlockTypes.Mutator)
                {
                    unlock.unavailable = false;
                    wrapper            = new MutatorUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Item)
                {
                    if (unlock.onlyInCharacterCreation && !unlock.unavailable)
                    {
                        unlock.unavailable = true;
                    }
                    if (!unlock.unavailable && !unlock.onlyInCharacterCreation && !unlock.freeItem)
                    {
                        unlock.onlyInCharacterCreation = unlock.freeItem = true;
                    }
                    wrapper = new ItemUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Trait)
                {
                    if (unlock.onlyInCharacterCreation && !unlock.unavailable)
                    {
                        unlock.unavailable = true;
                    }
                    wrapper = new TraitUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Ability)
                {
                    if (unlock.onlyInCharacterCreation && !unlock.unavailable)
                    {
                        unlock.unavailable = true;
                    }
                    wrapper = new AbilityUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Floor)
                {
                    wrapper = new FloorUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.BigQuest)
                {
                    wrapper = new BigQuestUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Extra)
                {
                    wrapper = new ExtraUnlock(unlock);
                }
                else if (unlock.unlockType == UnlockTypes.Agent)
                {
                    wrapper = new AgentUnlock(unlock)
                    {
                        IsSSA = unlock.unlockName == VanillaAgents.SuperCop || unlock.unlockName == VanillaAgents.UpperCruster ||
                                unlock.unlockName == VanillaAgents.Supergoon
                    };
                }
                else if (unlock.unlockType == "Achievement")
                {
                    wrapper = new AchievementUnlock(unlock);
                }
                else if (unlock.unlockType == "HomeBase")
                {
                    wrapper = new HomeBaseUnlock(unlock);
                }
                else if (unlock.unlockType == "Loadout")
                {
                    wrapper = new LoadoutUnlock(unlock);
                }
                else
                {
                    RogueFramework.LogError($"Unknown unlock type \"{unlock.unlockName}\" ({unlock.unlockType})");
                    sdb.unlocks.Remove(unlock);
                    continue;
                }
                if (wrapper is IUnlockInCC inCC && !inCC.IsAvailableInCC)
                {
                    inCC.IsAvailableInCC = wrapper.IsAvailable;
                }
                RogueFramework.Unlocks.Add(wrapper);
                AddUnlockFull(wrapper, true);
            }
            FixPrerequisites();
            foreach (UnlockWrapper wrapper in RogueFramework.CustomUnlocks)
            {
                if (RogueFramework.IsDebugEnabled(DebugFlags.Unlocks))
                {
                    RogueFramework.LogDebug($"Initializing custom unlock \"{wrapper.Name}\" ({wrapper.Type}).");
                }
                RogueFramework.Unlocks.Add(wrapper);
                AddUnlockFull(wrapper);
            }
        }
Exemplo n.º 4
0
        public static IEnumerator SaveEnumerator(Unlocks __instance)
        {
            yield return(null);

            __instance.savingUnlockData = false;
            if (curSaving)
            {
                saveOnNext = true;
                yield break;
            }
            curSaving = true;
            try
            {
                string text = Application.persistentDataPath;
                if (!GameController.gameController.consoleVersion || GameController.gameController.fakeConsole)
                {
                    if (GameController.gameController.usingMyDocuments && !GameController.gameController.macVersion && !GameController.gameController.linuxVersion && !GameController.gameController.usingUWP && !GameController.gameController.usingUWP)
                    {
                        text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/" + GameController.gameController.dataFolder;
                    }
                    Directory.CreateDirectory(text + "/CloudData/");
                }
                SessionDataBig sdb            = GameController.gameController.sessionDataBig;
                UnlockSaveData unlockSaveData = new UnlockSaveData
                {
                    unlocks              = sdb.unlocks,
                    highScores           = sdb.highScores,
                    customCharacterSlots = sdb.customCharacterSlots,
                    storedItem           = sdb.storedItem,
                    storedItem2          = sdb.storedItem2,
                    storedItem3          = sdb.storedItem3,
                    storedItem4          = sdb.storedItem4,
                    storedItem5          = sdb.storedItem5,
                    totalDeaths          = sdb.totalDeaths,
                    totalWins            = sdb.totalWins,
                    totalGamesPlayed     = sdb.totalGamesPlayed,
                    nuggets              = sdb.nuggets + sdb.loadoutNuggetsSpent,
                    lastDailyRun         = sdb.lastDailyRun,
                    finishedTutorial     = sdb.finishedTutorial,
                    viewedReadThis       = sdb.viewedReadThis,
                    currentVersion       = GameController.gameController.version,
                };
                try
                {
                    unlockSaveData.loadoutList = new List <Unlock> [30];
                    for (int i = 0; i < sdb.loadoutList.Length; i++)
                    {
                        unlockSaveData.loadoutList[i] = new List <Unlock>();
                        if (sdb.loadoutList[i] != null)
                        {
                            for (int j = 0; j < sdb.loadoutList[i].Count; j++)
                            {
                                Unlock item = sdb.loadoutList[i][j];
                                unlockSaveData.loadoutList[i].Add(item);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("LoadoutList Save Error");
                    Debug.LogError(e);
                }
                if (GameController.gameController.consoleVersion)
                {
                    try
                    {
                        unlockSaveData.rewardConfigConsoleList  = new List <string> [10];
                        unlockSaveData.traitConfigConsoleList   = new List <string> [10];
                        unlockSaveData.mutatorConfigConsoleList = new List <string> [10];
                        for (int k = 0; k < sdb.rewardConfigConsoleList.Length; k++)
                        {
                            unlockSaveData.rewardConfigConsoleList[k] = new List <string>();
                            if (sdb.rewardConfigConsoleList[k] != null)
                            {
                                for (int l = 0; l < sdb.rewardConfigConsoleList[k].Count; l++)
                                {
                                    string item2 = sdb.rewardConfigConsoleList[k][l];
                                    unlockSaveData.rewardConfigConsoleList[k].Add(item2);
                                }
                            }
                        }
                        for (int m = 0; m < sdb.traitConfigConsoleList.Length; m++)
                        {
                            unlockSaveData.traitConfigConsoleList[m] = new List <string>();
                            if (sdb.traitConfigConsoleList[m] != null)
                            {
                                for (int n = 0; n < sdb.traitConfigConsoleList[m].Count; n++)
                                {
                                    string item3 = sdb.traitConfigConsoleList[m][n];
                                    unlockSaveData.traitConfigConsoleList[m].Add(item3);
                                }
                            }
                        }
                        for (int num = 0; num < sdb.mutatorConfigConsoleList.Length; num++)
                        {
                            unlockSaveData.mutatorConfigConsoleList[num] = new List <string>();
                            if (sdb.mutatorConfigConsoleList[num] != null)
                            {
                                for (int num2 = 0; num2 < sdb.mutatorConfigConsoleList[num].Count; num2++)
                                {
                                    string item4 = sdb.mutatorConfigConsoleList[num][num2];
                                    unlockSaveData.mutatorConfigConsoleList[num].Add(item4);
                                }
                            }
                        }
                    }
                    catch
                    {
                        Debug.LogError("ConfigList Save Error");
                    }
                }
                Debug.Log("SAVE UNLOCK DATA");
                string saveSlotText = sdb.GetSaveSlotText();
                if (GameController.gameController.consoleVersion && !GameController.gameController.fakeConsole)
                {
                    GameController.gameController.consoleFunctions.SaveData(unlockSaveData, saveSlotText + "GameUnlocks");
                }
                else if (GameController.gameController.usingUWP)
                {
                    GameController.gameController.uwpFunctions.SaveData(unlockSaveData, saveSlotText + "GameUnlocks");
                }
                else
                {
                    if (GameController.gameController.usingUWP)
                    {
                        BinaryFormatter binaryFormatter = new BinaryFormatter();
                        FileStream      fileStream      = File.Create(text + "/CloudData/" + saveSlotText + "GameUnlocks.dat");
                        binaryFormatter.Serialize(fileStream, unlockSaveData);
                        fileStream.Close();
                    }
                    else
                    {
                        BinaryFormatter binaryFormatter2 = new BinaryFormatter();
                        FileStream      fileStream2      = File.Create(text + "/CloudData/Temp.dat");
                        if (!File.Exists(text + "/CloudData/" + saveSlotText + "GameUnlocks.dat"))
                        {
                            File.Create(text + "/CloudData/" + saveSlotText + "GameUnlocks.dat").Close();
                        }
                        binaryFormatter2.Serialize(fileStream2, unlockSaveData);
                        fileStream2.Close();
                        File.Replace(text + "/CloudData/Temp.dat", text + "/CloudData/" + saveSlotText + "GameUnlocks.dat", text + "/BackupData/" + saveSlotText + "BackupGameUnlocks.dat");
                        if (GameController.gameController.usingGDK)
                        {
                            GameController.gameController.gdkFunctions.SaveData(unlockSaveData, saveSlotText + "GameUnlocks", binaryFormatter2);
                        }
                    }
                    __instance.StartCoroutine((IEnumerator)unlocksBackupMethod.Invoke(__instance, new object[] { text, saveSlotText, unlockSaveData }));
                    GameController.gameController.steamGog.CloudSave(text + "/CloudData/" + saveSlotText + "GameUnlocks.dat");
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Couldn't save unlock data!");
                Debug.LogError(e);
            }
            if (saveOnNext)
            {
                saveOnNext = false;
                __instance.StartCoroutine(__instance.SaveUnlockData2());
            }
            curSaving = false;
        }