Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SinZ163 committed Mar 26, 2024
1 parent da4e95f commit 1f42190
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 9 deletions.
41 changes: 35 additions & 6 deletions SinZational Several Spouse Spots/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
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<Building>();
var unallocatedSpouses = new List<string>(spouses);

// TODO: Handle divorce

Utility.ForEachBuilding(b =>
{
if (b.buildingType.Value != SpousePatioBuildingId) return true;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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"))
{
Expand Down Expand Up @@ -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<CodeInstruction> PolyNPC__NullifyNPCPatch(ILGenerator generator, IEnumerable<CodeInstruction> instructions)
{
monitor.Log("Gutting PolyamorySweetLove.NPCPatches:NPC_setUpForOutdoorPatioActivity_Prefix");
return new CodeInstruction[]
{
new CodeInstruction(OpCodes.Ldc_I4_1),
new CodeInstruction(OpCodes.Ret)
};
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PropertyGroup>
<Name>SinZational Several Spouse Spots</Name>
<Authors>SinZ</Authors>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<Description>A mod that implements multiplayer spouse patios</Description>
<UniqueId>SinZ.SeveralSpouseSpots</UniqueId>
<MinimumApiVersion>4.0</MinimumApiVersion>
Expand Down
57 changes: 56 additions & 1 deletion SinZational Shared Spaces/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
*
Expand Down Expand Up @@ -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))));
Expand All @@ -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<CodeInstruction> GameLocation__performAction__Transpiler(ILGenerator generator, IEnumerable<CodeInstruction> instructions)
{
var output = new List<CodeInstruction>();
Expand Down
2 changes: 1 addition & 1 deletion SinZational Shared Spaces/SinZational Shared Spaces.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PropertyGroup>
<Name>SinZational Shared Spaces</Name>
<Authors>SinZ</Authors>
<Version>1.0.0</Version>
<Version>1.0.2</Version>
<Description>A mod that implements multiplayer stacked cabins</Description>
<UniqueId>SinZ.SharedSpaces</UniqueId>
<MinimumApiVersion>4.0</MinimumApiVersion>
Expand Down

0 comments on commit 1f42190

Please sign in to comment.