Exemple #1
0
        internal static int GetSlugcatSeed(int slugcat, int slot)
        {
            // Load from currently loaded save if available and valid
            SaveState save = OptionScript.rw?.progression?.currentSaveState;

            if (save != null && save.saveStateNumber == slugcat)
            {
                return(save.seed);
            }
            // Load from slugbase custom save file
            if (OptionScript.SlugBaseExists && IsSlugBaseSlugcat(slugcat))
            {
                return(GetSlugBaseSeed(slugcat, slot));
            }
            // Load from vanilla save file
            if (OptionScript.rw.progression.IsThereASavedGame(slugcat))
            {
                string[] progLines = OptionScript.rw.progression.GetProgLines();
                if (progLines.Length != 0)
                {
                    for (int i = 0; i < progLines.Length; i++)
                    {
                        string[] data = Regex.Split(progLines[i], "<progDivB>");
                        if (data.Length == 2 && data[0] == "SAVE STATE" && int.Parse(data[1][21].ToString()) == slugcat)
                        {
                            List <SaveStateMiner.Target> query = new List <SaveStateMiner.Target>()
                            {
                                new SaveStateMiner.Target(">SEED", "<svB>", "<svA>", 20)
                            };
                            List <SaveStateMiner.Result> result = SaveStateMiner.Mine(OptionScript.rw, data[1], query);
                            if (result.Count == 0)
                            {
                                break;
                            }
                            try
                            {
                                return(int.Parse(result[0].data));
                            }
                            catch (Exception)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(-1);
        }
Exemple #2
0
        // Read the shelter name from a separate file
        private static string PlayerProgression_ShelterOfSaveGame(On.PlayerProgression.orig_ShelterOfSaveGame orig, PlayerProgression self, int saveStateNumber)
        {
            SlugBaseCharacter ply = PlayerManager.GetCustomPlayer(saveStateNumber);

            if (ply == null)
            {
                return(orig(self, saveStateNumber));
            }

            if (self.currentSaveState != null && self.currentSaveState.saveStateNumber == saveStateNumber)
            {
                return(self.currentSaveState.denPosition);
            }

            string startRoom = ply.StartRoom;

            int slot = self.rainWorld.options.saveSlot;

            if (!HasCustomSaveData(ply.Name, slot) && startRoom != null)
            {
                return(startRoom);
            }

            string saveText = File.ReadAllText(GetSaveFilePath(ply.Name, slot));

            List <SaveStateMiner.Target> targets = new List <SaveStateMiner.Target>();

            targets.Add(new SaveStateMiner.Target(">DENPOS", "<svB>", "<svA>", 20));

            List <SaveStateMiner.Result> results = SaveStateMiner.Mine(self.rainWorld, saveText, targets);

            if (results.Count > 0 && results[0].data != null)
            {
                return(results[0].data);
            }

            return(startRoom ?? "SU_S01");
        }
Exemple #3
0
        private static int GetSlugBaseSeed(int slugcat, int slot)
        {
            SlugBase.SlugBaseCharacter ply = SlugBase.PlayerManager.GetCustomPlayer(slugcat);
            if (ply == null || !SlugBase.SaveManager.HasCustomSaveData(ply.Name, slot))
            {
                return(-1);
            }
            string saveData = File.ReadAllText(SlugBase.SaveManager.GetSaveFilePath(ply.Name, slot));
            List <SaveStateMiner.Target> query = new List <SaveStateMiner.Target>()
            {
                new SaveStateMiner.Target(">SEED", "<svB>", "<svA>", 20)
            };
            List <SaveStateMiner.Result> result = SaveStateMiner.Mine(OptionScript.rw, saveData, query);

            if (result.Count != 0)
            {
                try
                {
                    return(int.Parse(result[0].data));
                }
                catch (Exception) { }
            }
            return(-1);
        }
Exemple #4
0
        /// <summary>
        /// Gets a summary of the content in a SlugBase character's save file.
        /// </summary>
        /// <param name="rainWorld">The current <see cref="RainWorld"/> instance.</param>
        /// <param name="name">The name of the SlugBase character.</param>
        /// <param name="slot">The game's current save slot.</param>
        /// <returns>A summary of the given character's save file.</returns>
        public static SlugcatSelectMenu.SaveGameData GetCustomSaveData(RainWorld rainWorld, string name, int slot)
        {
            if (!HasCustomSaveData(name, slot))
            {
                return(null);
            }

            string saveData = File.ReadAllText(GetSaveFilePath(name, slot));

            List <SaveStateMiner.Target> targets = new List <SaveStateMiner.Target>();

            targets.Add(new SaveStateMiner.Target(">DENPOS", "<svB>", "<svA>", 20));
            targets.Add(new SaveStateMiner.Target(">CYCLENUM", "<svB>", "<svA>", 50));
            targets.Add(new SaveStateMiner.Target(">FOOD", "<svB>", "<svA>", 20));
            targets.Add(new SaveStateMiner.Target(">HASTHEGLOW", null, "<svA>", 20));
            targets.Add(new SaveStateMiner.Target(">REINFORCEDKARMA", "<dpB>", "<dpA>", 20));
            targets.Add(new SaveStateMiner.Target(">KARMA", "<dpB>", "<dpA>", 20));
            targets.Add(new SaveStateMiner.Target(">KARMACAP", "<dpB>", "<dpA>", 20));
            targets.Add(new SaveStateMiner.Target(">HASTHEMARK", null, "<dpA>", 20));
            targets.Add(new SaveStateMiner.Target(">REDEXTRACYCLES", null, "<svA>", 20));
            targets.Add(new SaveStateMiner.Target(">ASCENDED", null, "<dpA>", 20));

            List <SaveStateMiner.Result> results = SaveStateMiner.Mine(rainWorld, saveData, targets);

            SlugcatSelectMenu.SaveGameData saveGameData = new SlugcatSelectMenu.SaveGameData();

            for (int i = 0; i < results.Count; i++)
            {
                string targetName = results[i].name;
                try
                {
                    switch (targetName)
                    {
                    case ">DENPOS":
                        saveGameData.shelterName = results[i].data;
                        break;

                    case ">CYCLENUM":
                        saveGameData.cycle = int.Parse(results[i].data);
                        break;

                    case ">FOOD":
                        saveGameData.food = int.Parse(results[i].data);
                        break;

                    case ">HASTHEGLOW":
                        saveGameData.hasGlow = true;
                        break;

                    case ">REINFORCEDKARMA":
                        saveGameData.karmaReinforced = (results[i].data == "1");
                        break;

                    case ">KARMA":
                        saveGameData.karma = int.Parse(results[i].data);
                        break;

                    case ">KARMACAP":
                        saveGameData.karmaCap = int.Parse(results[i].data);
                        break;

                    case ">HASTHEMARK":
                        saveGameData.hasMark = true;
                        break;

                    case ">REDEXTRACYCLES":
                        saveGameData.redsExtraCycles = true;
                        break;

                    case ">REDSDEATH":
                        saveGameData.redsDeath = true;
                        break;

                    case ">ASCENDED":
                        saveGameData.ascended = true;
                        break;
                    }
                }
                catch (Exception e)
                {
                    Debug.LogException(new Exception($"Failed to parse value from slugbase save (\"{name}\") for \"{targetName}\"!", e));
                }
            }
            return(saveGameData);
        }