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)); }
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); }