From 1f42190df004ccba3a7d09e38cfe5ff2c027acf8 Mon Sep 17 00:00:00 2001 From: SinZ Date: Tue, 26 Mar 2024 21:24:38 +1100 Subject: [PATCH] Updates --- SinZational Several Spouse Spots/ModEntry.cs | 41 +++++++++++-- .../SinZational Several Spouse Spots.csproj | 2 +- SinZational Shared Spaces/ModEntry.cs | 57 ++++++++++++++++++- .../SinZational Shared Spaces.csproj | 2 +- 4 files changed, 93 insertions(+), 9 deletions(-) diff --git a/SinZational Several Spouse Spots/ModEntry.cs b/SinZational Several Spouse Spots/ModEntry.cs index 9850ddc..78b5c92 100644 --- a/SinZational Several Spouse Spots/ModEntry.cs +++ b/SinZational Several Spouse Spots/ModEntry.cs @@ -39,13 +39,26 @@ public void RecalculateSpousePatioAllocations() var spousePatioCount = 0; SpousePatioAllocations.Clear(); SpousePatioStandingSpots.Clear(); - var spouses = Game1.getAllFarmers().Where(f => f != Game1.MasterPlayer).Select(f => f.spouse).Where(s => s != null); + var spouses = new HashSet(); + foreach (var farmer in Game1.getAllFarmers()) + { + foreach (var npc in farmer.friendshipData.Keys) + { + if (farmer.friendshipData[npc].IsMarried()) + { + spouses.Add(npc); + } + } + } + // MasterPlayer spouse is handled via vanilla logic, let it stand. + if (Game1.MasterPlayer.spouse != null) + { + spouses.Remove(Game1.MasterPlayer.spouse); + } var unallocatedPatios = new List(); var unallocatedSpouses = new List(spouses); - // TODO: Handle divorce - Utility.ForEachBuilding(b => { if (b.buildingType.Value != SpousePatioBuildingId) return true; @@ -73,7 +86,7 @@ public void RecalculateSpousePatioAllocations() SpousePatioAllocations[spouse] = patio; } // Force Farm to be reloaded - Monitor.Log("Invalidating Farm: " + Game1.getFarm().Map.assetPath, LogLevel.Alert); + Monitor.Log("Invalidating Farm: " + Game1.getFarm().Map.assetPath); Helper.GameContent.InvalidateCache(Game1.getFarm().Map.assetPath); } @@ -110,7 +123,7 @@ public void ApplyMapModifications() } } - private void World_BuildingListChanged(object sender, StardewModdingAPI.Events.BuildingListChangedEventArgs e) + private void World_BuildingListChanged(object sender, BuildingListChangedEventArgs e) { var addedSpousePatios = e.Added.Where(b => b.buildingType.Value == SpousePatioBuildingId); var removedSpousePatios = e.Removed.Where(b => b.buildingType.Value == SpousePatioBuildingId); @@ -120,7 +133,7 @@ private void World_BuildingListChanged(object sender, StardewModdingAPI.Events.B } } - private void Content_AssetRequested(object sender, StardewModdingAPI.Events.AssetRequestedEventArgs e) + private void Content_AssetRequested(object sender, AssetRequestedEventArgs e) { if (e.NameWithoutLocale.IsEquivalentTo("Data/Buildings")) { @@ -186,6 +199,22 @@ public static void Setup(IMonitor monitor, Harmony harmony) harmony.Patch(AccessTools.Method(typeof(Farm), nameof(Farm.OnMapLoad)), postfix: new HarmonyMethod(typeof(HarmonyPatches).GetMethod(nameof(OnMapLoad__Postfix)))); harmony.Patch(AccessTools.Method(typeof(Farmer), nameof(Farmer.doDivorce)), prefix: new HarmonyMethod(typeof(HarmonyPatches).GetMethod(nameof(doDivorce__Prefix))), postfix: new HarmonyMethod(typeof(HarmonyPatches).GetMethod(nameof(doDivorce__Postfix)))); harmony.Patch(AccessTools.Method(typeof(Game1), nameof(Game1.OnDayStarted)), prefix: new HarmonyMethod(typeof(HarmonyPatches).GetMethod(nameof(OnDayStarted__Prefix)))); + + var polyNPCPatch = AccessTools.Method("PolyamorySweetLove.NPCPatches:NPC_setUpForOutdoorPatioActivity_Prefix"); + if (polyNPCPatch != null) + { + harmony.Patch(polyNPCPatch, transpiler: new HarmonyMethod(typeof(HarmonyPatches).GetMethod(nameof(PolyNPC__NullifyNPCPatch)))); + } + } + + public static IEnumerable PolyNPC__NullifyNPCPatch(ILGenerator generator, IEnumerable instructions) + { + monitor.Log("Gutting PolyamorySweetLove.NPCPatches:NPC_setUpForOutdoorPatioActivity_Prefix"); + return new CodeInstruction[] + { + new CodeInstruction(OpCodes.Ldc_I4_1), + new CodeInstruction(OpCodes.Ret) + }; } /// diff --git a/SinZational Several Spouse Spots/SinZational Several Spouse Spots.csproj b/SinZational Several Spouse Spots/SinZational Several Spouse Spots.csproj index 578b56e..3b4cdbb 100644 --- a/SinZational Several Spouse Spots/SinZational Several Spouse Spots.csproj +++ b/SinZational Several Spouse Spots/SinZational Several Spouse Spots.csproj @@ -7,7 +7,7 @@ SinZational Several Spouse Spots SinZ - 1.0.0 + 1.1.0 A mod that implements multiplayer spouse patios SinZ.SeveralSpouseSpots 4.0 diff --git a/SinZational Shared Spaces/ModEntry.cs b/SinZational Shared Spaces/ModEntry.cs index dfb18a1..7440e80 100644 --- a/SinZational Shared Spaces/ModEntry.cs +++ b/SinZational Shared Spaces/ModEntry.cs @@ -11,6 +11,7 @@ using StardewValley.Network; using System.Reflection; using System.Reflection.Emit; +using System.Xml.Linq; using xTile.Dimensions; using static StardewValley.Minigames.MineCart; @@ -33,7 +34,6 @@ public override void Entry(IModHelper helper) Patches.Init(harmony, helper, Monitor); /** * TODO: - * Changes to farmhouse front door to allow elevator style selection of which interior to go to * * Allow stable buildings up to player instance count * @@ -114,6 +114,14 @@ public static void Init(Harmony harmony, IModHelper helper, IMonitor monitor) { Patches.monitor = monitor; + var stardewLocationsName = AccessTools.Method("StardewLocations.StardewLocations:getLocationName"); + if (stardewLocationsName != null) + { + harmony.Patch(stardewLocationsName, prefix: new HarmonyMethod(typeof(Patches).GetMethod(nameof(StardewLocations__getLocationName__Prefix)))); + } + + harmony.Patch(AccessTools.Method(typeof(Farm), nameof(Farm.UnsetFarmhouseValues)), postfix: new HarmonyMethod(typeof(Patches).GetMethod(nameof(Farm__UnsetFarmhouseValues__Postfix)))); + harmony.Patch(AccessTools.Method(typeof(GameLocation), nameof(GameLocation.updateWarps)), postfix: new HarmonyMethod(typeof(Patches).GetMethod(nameof(GameLocation__updateWarps__Postfix)))); harmony.Patch(AccessTools.Method(typeof(GameLocation), nameof(GameLocation.performAction), new Type[] { typeof(string[]), typeof(Farmer), typeof(Location) }), transpiler: new HarmonyMethod(typeof(Patches).GetMethod(nameof(GameLocation__performAction__Transpiler)))); harmony.Patch(AccessTools.Method(typeof(Building), nameof(Building.OnUseHumanDoor)), postfix: new HarmonyMethod(typeof(Patches).GetMethod(nameof(Building__OnUseHumanDoor__Postfix)))); harmony.Patch(AccessTools.Method(typeof(FarmhandMenu.FarmhandSlot), nameof(FarmhandMenu.FarmhandSlot.Activate)), transpiler: new HarmonyMethod(typeof(Patches).GetMethod(nameof(FarmhandSlot__Activate__Transpiler)))); @@ -124,6 +132,53 @@ public static void Init(Harmony harmony, IModHelper helper, IMonitor monitor) harmony.Patch(AccessTools.Method(typeof(SaveGame), nameof(SaveGame.loadDataToLocations)), transpiler: new HarmonyMethod(typeof(Patches).GetMethod(nameof(SaveGame__loadDataToLocations__Transpiler)))); } + public static void StardewLocations__getLocationName__Prefix(ref string name, ref GameLocation loc) + { + if (loc is Cabin) + { + name = "Cabin"; + } + } + + public static void Farm__UnsetFarmhouseValues__Postfix() + { + if (Game1.IsClient) return; + foreach (var location in Game1.locations) + { + if (location is Cabin) + { + foreach (var warp in location.warps) + { + if (warp.TargetName == "Farm") + { + var coords = Game1.getFarm().GetMainFarmHouseEntry(); + warp.TargetX = coords.X; + warp.TargetY = coords.Y; + } + } + } + } + } + + public static void GameLocation__updateWarps__Postfix(GameLocation __instance) + { + if (Game1.IsClient) return; + // If the farm isn't loaded, then don't handle it. It is done anyway via Farm.UnsetFarmhouseValues in loading usecases + if (Game1.getLocationFromNameInLocationsList("Farm") == null) return; + if (__instance is Cabin) + { + foreach (var warp in __instance.warps) + { + if (warp.TargetName == "Farm") + { + var coords = Game1.getFarm().GetMainFarmHouseEntry(); + warp.TargetX = coords.X; + warp.TargetY = coords.Y; + } + } + } + } + public static IEnumerable GameLocation__performAction__Transpiler(ILGenerator generator, IEnumerable instructions) { var output = new List(); diff --git a/SinZational Shared Spaces/SinZational Shared Spaces.csproj b/SinZational Shared Spaces/SinZational Shared Spaces.csproj index 7bd75ed..fa022a5 100644 --- a/SinZational Shared Spaces/SinZational Shared Spaces.csproj +++ b/SinZational Shared Spaces/SinZational Shared Spaces.csproj @@ -9,7 +9,7 @@ SinZational Shared Spaces SinZ - 1.0.0 + 1.0.2 A mod that implements multiplayer stacked cabins SinZ.SharedSpaces 4.0