예제 #1
0
        // ~~~~~~~~~ Core internal ~~~~~~~~~

        internal static void OnSaveInstanceSave(SaveInstance __instance)
        {
            try
            {
                if (__instance.CharSave == null || string.IsNullOrEmpty(__instance.CharSave.CharacterUID))
                {
                    return;
                }

                var charUID = __instance.CharSave.CharacterUID;

                bool isHost = !PhotonNetwork.isNonMasterClientInRoom && !(bool)At.GetField(NetworkLevelLoader.Instance, "m_saveOnHostLost") &&
                              CharacterManager.Instance?.GetWorldHostCharacter()?.UID == charUID;

                // Save internal stuff for the host
                if (isHost)
                {
                    SLCharacterSaveManager.SaveCharacters();
                    SLItemSpawnSaveManager.SaveItemSpawns();
                }

                // Save custom extensions from other mods
                PlayerSaveExtension.SaveAllExtensions(CharacterManager.Instance.GetCharacter(charUID), isHost);
            }
            catch (Exception ex)
            {
                SL.LogWarning("Exception on SaveInstance.Save!");
                SL.LogInnerException(ex);
            }
        }
예제 #2
0
        private static void TryLoadStashes(SaveInstance saveInstance)
        {
            var areaName     = SceneManagerHelper.ActiveSceneName;
            var currentStash = ItemManager.Instance.GetItem(StashAreaToStashUID[areaName]) as TreasureChest;

            if (!currentStash)
            {
                Log.LogMessage($"Could not find stash in scene '{areaName}'!");
                return;
            }

            try
            {
                // load items from the other stash scenes
                foreach (var key in StashAreaToStashUID.Keys)
                {
                    // skip if its this scene
                    if (key == areaName)
                    {
                        continue;
                    }

                    LoadItemsFromScene(currentStash, saveInstance, key);
                }

                currentStash.m_hasGeneratedContent = true;
                SaveManager.Instance.Save(true, true);
            }
            catch (Exception ex)
            {
                Log.LogMessage($"Exception sharing stash items: {ex}");
            }
        }
예제 #3
0
        private List <EnvironmentSave> AreasWithExistingStashChests(SaveInstance save, string excludedAreaName = null, bool excludeEmptyStashChests = true)
        {
            if (save == null)
            {
                Debug.LogWarning("Linked Stash Chests: Tried to stash chest area saves from non-existent save. Aborting.");
                return(null);
            }

            var list = new List <EnvironmentSave>();

            foreach (string text in StashAreaToStashUID.Keys)
            {
                if (!string.Equals(text, excludedAreaName) && save.PathToSceneSaves.ContainsKey(text))
                {
                    EnvironmentSave environmentSave = GetEnvironmentSave(save, text);
                    if (excludeEmptyStashChests && GetSavedStashItems(environmentSave).Count == 0)
                    {
                        Debug.Log("Linked Stash Chests: Skipping empty stash chest in " + text);
                    }
                    else
                    {
                        list.Add(environmentSave);
                    }
                }
            }

            return(list);
        }
예제 #4
0
    public void LoadPlayerInventory()
    {
        if (File.Exists(Application.persistentDataPath + "/PlayerItems.save"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/PlayerItems.save", FileMode.Open);
            SaveInstance    save = (SaveInstance)bf.Deserialize(file);
            file.Close();

            inventory.OriginalPlayerItems.Clear();

            if (save.AllItems.Count > 0)
            {
                foreach (Item item in save.AllItems)
                {
                    inventory.OriginalPlayerItems.Add(item);
                    Debug.Log("Loading " + item.ItemName);
                }
                Debug.Log("Player Inventory Loaded");
                inventory.SetRefreshItemList(true); // Display the items
            }
            else
            {
                Debug.Log("No loaded items found!");
            }
        }
        else
        {
            Debug.Log("No game saved! New game inventory ?");
        }
    }
예제 #5
0
 void _GatherKey(SaveInstance obj)
 {
     if (!objKeyList.Contains(obj.Key))
     {
         objKeyList.Add(obj.Key);
     }
 }
예제 #6
0
            static void Override(SaveInstance __instance)
            {
                if (!__instance.m_isValid)
                {
                    return;
                }

                __instance.InitSaveInstance();

                if (!__instance.CharSave.LoadFromFile(__instance.SavePath))
                {
                    Debug.LogError("Could not load Character Save at " + __instance.SavePath);
                    __instance.m_isValid = false;
                    return;
                }

                if (!__instance.WorldSave.LoadFromFile(__instance.SavePath))
                {
                    Debug.LogError("Could not load World Save at " + __instance.SavePath);
                    __instance.m_isValid = false;
                    return;
                }

                // Our change: comment out these warnings.

                if (!__instance.LegacyChestSave.LoadFromFile(__instance.SavePath))
                {
                    __instance.LegacyChestSave = new();
                    //Debug.LogError("Could not load Legacy Save at " + __instance.SavePath);
                }

                if (!__instance.MapSave.LoadFromFile(__instance.SavePath))
                {
                    __instance.MapSave = new();
                    //Debug.LogError("Could not load Map Save at " + __instance.SavePath);
                }

                string fileExtension = EnvironmentSave.FileExtension;

                string[] files = Directory.GetFiles(__instance.SavePath, "*" + EnvironmentSave.FileExtension + "*");

                for (int i = 0; i < files.Length; i++)
                {
                    int    num    = files[i].LastIndexOf("/");
                    string text   = files[i].Substring(num + 1);
                    int    length = text.IndexOf(fileExtension);
                    string text2  = text.Substring(0, length);

                    if (__instance.m_invalidAreas.Contains(text2))
                    {
                        Debug.LogErrorFormat("{0} was marked as invalid and was skipped from loading.", new object[] { text2 });
                    }
                    else
                    {
                        __instance.PathToSceneSaves.Add(text2, files[i]);
                    }
                }
            }
예제 #7
0
        void _MapKeyToDict(SaveInstance obj)
        {
            if (!objDict.ContainsKey(obj.Key))
            {
                objDict.Add(obj.Key, new List <SaveInstance>());
            }

            objDict[obj.Key].Add(obj);
        }
예제 #8
0
    public void SavePlayerInventory(List <Item> items)
    {
        SaveInstance save = InstanceInventoryItems(items); // Acquire items

        // save em !
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + "/PlayerItems.save");

        bf.Serialize(file, save);
        file.Close();

        Debug.Log("Game Saved");
    }
예제 #9
0
        private static EnvironmentSave GetEnvironmentSave(SaveInstance save, string areaName)
        {
            var environmentSave = new EnvironmentSave {
                AreaName = areaName
            };

            if (!environmentSave.LoadFromFile(save.SavePath))
            {
                Debug.LogWarning($"Linked Stash Chests: Tried load non-existent area save '{areaName}'. Aborting.");
                return(null);
            }

            return(environmentSave);
        }
예제 #10
0
    SaveInstance InstanceInventoryItems(List <Item> items)
    {
        SaveInstance save = new SaveInstance();
        int          i    = 0;

        foreach (Item item in items)
        {
            if (item != null)
            {
                save.AllItems.Add(item);
                i++;
            }
        }
        return(save);
    }
예제 #11
0
 void _DeleteSaveGame(bool forceDelete = false)
 {
     if (!forceDelete)
     {
         var isConfirm = EditorUtility.DisplayDialog("Delete SaveGame", "Are you sure to delete a save file?", "Delete", "Cancel");
         if (isConfirm)
         {
             SaveInstance.DeleteSave();
             EditorUtility.DisplayDialog("Generate ID : Success", "SaveGame has been deleted..", "OK");
         }
     }
     else
     {
         SaveInstance.DeleteSave();
     }
 }
    public void Save(bool overridePassword = false) //Send save data
    {
        if (!overridePassword)
        {
            ContentManager.active.LocalClient.CheckForPassword(ID, this, "save");
            return;
        }
        //string fp = filePrefix;
        //string FileName = fp + CharacterName;
        //ContentManager.active.Save(true, FileName, "CharacterData", this, true);
        ContentManager.active.SaveCharacter(ID, CharacterName, ISNPC);

        SaveInstance.data_struct send_data;

        send_data.name  = CharacterName;
        send_data.isNPC = ISNPC;

        List <string> tempList = new List <string>();

        foreach (Sheet_string v in CustomStrings)
        {
            tempList.Add(SaveInstance.Format(new object[] { v.VariableName, v.Value }));
        }
        send_data.strings = tempList.ToArray();
        tempList.Clear();
        foreach (Sheet_float v in CustomFloats)
        {
            tempList.Add(SaveInstance.Format(new object[] { v.VariableName, v.Value }));
        }
        send_data.floats = tempList.ToArray();
        tempList.Clear();
        foreach (Sheet_bool v in CustomBools)
        {
            tempList.Add(SaveInstance.Format(new object[] { v.VariableName, v.Value }));
        }
        send_data.bools = tempList.ToArray();
        tempList.Clear();
        foreach (Sheet_stat v in CustomStats)
        {
            tempList.Add(SaveInstance.Format(new object[] { v.VariableName, v.Value.x, v.Value.y }));
        }
        send_data.stats = tempList.ToArray();
        ContentManager.active.SaveVariables(ID, SaveInstance.active.TurnToJson(send_data, false));
    }
예제 #13
0
        void _GUIHandler()
        {
            titleContent.text = "SaveSetting";

            GUILayout.Label("ID Setting", EditorStyles.boldLabel);
            EditorGUILayout.Space();

            toggleSetID = EditorGUILayout.Toggle("Edit:", toggleSetID);

            if (toggleSetID)
            {
                initID = EditorGUILayout.IntField("Start ID: ", initID);
            }
            else
            {
                initID = 0;
            }

            if (GUILayout.Button("Generate ID"))
            {
                _UpdateAllSaveAbleObject();
                _GenerateIDPerKey();
                _DeleteSaveGame(true);
                _ReportGenerateResult();
            }

            if (GUILayout.Button("Check Duplicate ID"))
            {
                _UpdateAllSaveAbleObject();
                _CheckDuplicateIDPerKey();
            }

            if (SaveInstance.IsSaveFileExists())
            {
                if (GUILayout.Button("Delete SaveFile"))
                {
                    _DeleteSaveGame();
                }
            }
        }
예제 #14
0
        private bool SaveInstance_ApplyEnvironment(On.SaveInstance.orig_ApplyEnvironment orig, SaveInstance self)
        {
            bool            result      = orig.Invoke(self);
            EnvironmentSave loadedScene = GetPrivatePart <EnvironmentSave, SaveInstance>(self, "m_loadedScene");

            if (loadedScene == null || !StashAreaToStashUID.ContainsKey(loadedScene.AreaName))
            {
                return(result);
            }

            string areaName = loadedScene.AreaName;
            List <EnvironmentSave> otherAreaSaves = AreasWithExistingStashChests(self, areaName);

            if (otherAreaSaves.Count == 0)
            {
                Debug.Log("Linked Stash Chests: No other stash chests to sync with.");
                return(result);
            }

            var treasureChest = (TreasureChest)ItemManager.Instance.GetItem(StashAreaToStashUID[areaName]);

            if (treasureChest == null)
            {
                Debug.LogWarning("Linked Stash Chests: Could not get loaded stash chest in " + areaName + ". Aborting.");
                return(result);
            }

            var bufferedLog = new StringBuilder();

            try
            {
                BasicSaveData basicSaveData     = null;
                var           currentStashItems = new List <BasicSaveData>();
                if (self.PathToSceneSaves.ContainsKey(areaName))
                {
                    basicSaveData     = GetSavedStashChest(loadedScene);
                    currentStashItems = GetSavedStashItems(loadedScene);
                }

                if (basicSaveData == null)
                {
                    basicSaveData = new BasicSaveData(treasureChest.UID, treasureChest.ToSaveData());
                }

                bufferedLog.AppendLine("--------------------------------- Linked Stash Chests ---------------------------------");
                bufferedLog.AppendLine($"{areaName}'s stash chest BEFORE pulling all other stash chest items into it:");
                bufferedLog.AppendLine($"{currentStashItems.Count} items: {basicSaveData.Identifier} {basicSaveData.SyncData}");
                foreach (EnvironmentSave otherAreaSave in otherAreaSaves)
                {
                    BasicSaveData        otherStashChest = GetSavedStashChest(otherAreaSave);
                    List <BasicSaveData> otherStashItems = GetSavedStashItems(otherAreaSave, StashAreaToStashUID[areaName]);
                    bufferedLog.AppendLine();
                    bufferedLog.AppendLine($"{otherAreaSave.AreaName}'s SAVED stash chest BEFORE pulling all its items into {areaName}'s stash chest:");
                    bufferedLog.AppendLine($"{otherStashItems.Count} items: {(otherStashChest == null ? "null" : otherStashChest.Identifier + " " + otherStashChest.SyncData)}");

                    RemoveSavedStashItems(otherAreaSave);
                    ItemManager.Instance.LoadItems(otherStashItems);
                    int savedStashSilver = GetSavedStashSilver(otherStashChest);
                    SetSavedStashSilver(0, otherStashChest);
                    AddSavedStashSilver(savedStashSilver, basicSaveData);
                    ItemManager.Instance.LoadItems(new List <BasicSaveData>(1)
                    {
                        basicSaveData
                    });
                    currentStashItems.AddRange(otherStashItems);
                    otherAreaSave.ProcessSave();

                    otherStashItems = GetSavedStashItems(otherAreaSave, StashAreaToStashUID[areaName]);
                    bufferedLog.AppendLine($"{otherAreaSave.AreaName}'s SAVED stash chest AFTER pulling all its items into {areaName}'s stash chest:");
                    bufferedLog.AppendLine($"{otherStashItems.Count} items): {(otherStashChest == null ? "null" : otherStashChest.Identifier + " " + otherStashChest.SyncData)}");
                }

                bufferedLog.AppendLine();
                bufferedLog.AppendLine($"{areaName}'s stash chest AFTER pulling all other stash chest items into it:");
                bufferedLog.AppendLine($"{currentStashItems.Count} items: {basicSaveData.Identifier + " " + basicSaveData.SyncData}");
                bufferedLog.AppendLine("---------------------------------------------------------------------------------------");
            }
            finally
            {
                Debug.Log(bufferedLog.ToString());
            }

            return(result);
        }
예제 #15
0
 public static void Postfix(SaveInstance __instance)
 {
     SLSaveManager.OnSaveInstanceSave(__instance);
 }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SaveLogic"/> class.
 /// </summary>
 /// <param name="save">init save.</param>
 public SaveLogic(SaveInstance save)
 {
     this.save = save;
 }
예제 #17
0
 static bool Prefix(SaveInstance __instance)
 {
     Override(__instance);
     return(false);
 }
예제 #18
0
 private bool SaveInstance_ApplyEnvironment(On.SaveInstance.orig_ApplyEnvironment orig, SaveInstance self, string _areaName)
 {
     try
     {
         Dictionary <string, Recipe> allRecipes = (Dictionary <string, Recipe>)AccessTools.Field(typeof(RecipeManager), "m_recipes").GetValue(RecipeManager.Instance);
         List <Recipe> lstRecipes = allRecipes.Where(r =>
                                                     r.Value.Ingredients != null &&
                                                     r.Value.Results.Length > 0
                                                     ).Select(r => r.Value).ToList();
         List <string> lines = new List <string>();
         lines.Add("Type;Recette;Ing 1;;Value 1;Ing 2;;Value 2;Ing 3;;Value 3;Ing 4;;Value 4");
         string line;
         foreach (var recipe in lstRecipes)
         {
             line = $"{recipe.CraftingStationType};{recipe.hideFlags};{recipe.name}";
             //recipe.RecipeSteps[0].
             foreach (var ingredient in recipe.Ingredients)
             {
                 //line += $";{ingredient.ActionType}";
                 if (ingredient.AddedIngredient)
                 {
                     line += $";{ingredient.AddedIngredient.name};{ingredient.AddedIngredient.Name};{ingredient.AddedIngredient.Value}";
                 }
                 else
                 {
                     line += ";;;";
                 }
             }
             lines.Add(line);
         }
         File.WriteAllLines(@"D:\SteamLibrary\steamapps\common\Outward\recipes.csv", lines.ToArray());
     }
     catch (Exception ex)
     {
         OLogger.Error(ex.Message);
     }
     return(orig(self, _areaName));
 }
예제 #19
0
        private static void LoadItemsFromScene(TreasureChest currentStash, SaveInstance instance, string areaName)
        {
            // Load the save data for the area
            var save = new EnvironmentSave();

            save.AreaName = areaName;
            if (save.LoadFromFile(instance.SavePath))
            {
                var otherStashUID = StashAreaToStashUID[areaName];
                // the expected hierarchy data for items in the stashes
                string oldStashHierarchy = $"Hierarchy>1{otherStashUID}";
                string newStashHierarchy = $"Hierarchy>1{currentStash.UID}";

                // get items in the stash, remove from old save and add to our list
                bool needSaveOtherScene = false;
                var  dataToSync         = new List <BasicSaveData>();
                for (int i = save.ItemList.Count - 1; i >= 0; i--)
                {
                    var data = save.ItemList[i];
                    // if item is in the stash
                    if (data.SyncData.Contains(oldStashHierarchy))
                    {
                        needSaveOtherScene = true;
                        // remove from the old scene save
                        save.ItemList.RemoveAt(i);
                        // change the parent from the old stash to the new one
                        data.SyncData = data.SyncData.Replace(oldStashHierarchy, newStashHierarchy);
                        // add to our data to sync
                        dataToSync.Add(data);
                    }
                    // if item is the stash itself
                    else if ((string)data.Identifier == otherStashUID)
                    {
                        // get the contained silver. could serialize it all and split, but this is a bit more optimized.
                        var sb = new StringBuilder();
                        // index of the silver value (string is 28 chars, plus the '/' separator)
                        int idx = data.SyncData.IndexOf("TreasureChestContainedSilver") + 29;
                        while (idx < data.SyncData.Length)
                        {
                            char c = data.SyncData[idx];
                            if (!char.IsDigit(c))
                            {
                                break;
                            }
                            sb.Append(c);
                            idx++;
                        }
                        int silver = int.Parse(sb.ToString());
                        if (silver > 0)
                        {
                            needSaveOtherScene = true;
                            // remove the silver
                            data.SyncData = data.SyncData.Replace($"TreasureChestContainedSilver/{silver};", "TreasureChestContainedSilver/0;");
                            // add to this scene
                            currentStash.AddSilver(silver);
                        }
                    }
                }

                if (needSaveOtherScene)
                {
                    // save the other scene to finalize removing the items and silver
                    save.ProcessSave();

                    // load the item data into this scene's stash
                    if (dataToSync.Any())
                    {
                        ItemManager.Instance.LoadItems(dataToSync, false);
                    }

                    Log.LogMessage($"Loaded stashed items from {areaName}");
                }
            }
        }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SaveLogic"/> class.
 /// </summary>
 /// <param name="save">init save.</param>
 /// <param name="model">init model.</param>
 public SaveLogic(SaveInstance save, IGameModel model)
 {
     this.save  = save;
     this.model = model;
 }