Skip to content

Commit

Permalink
add rewriters for Stardew Valley 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Dec 9, 2023
1 parent 8865016 commit 8b3c1db
Show file tree
Hide file tree
Showing 63 changed files with 3,233 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/SMAPI/Framework/ModLoading/Rewriters/IRewriteFacade.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace StardewModdingAPI.Framework.ModLoading.Rewriters
{
/// <summary>Marker class for a rewrite facade used to validate mappings. See comments on <see cref="ReplaceReferencesRewriter"/> for more info.</summary>
internal interface IRewriteFacade { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public ReplaceReferencesRewriter MapMethod(string fromFullName, Type toType, str
/// <typeparam name="TFacade">The facade type to which to point matching references.</typeparam>
/// <param name="mapDefaultConstructor">If the facade has a public constructor with no parameters, whether to rewrite references to empty constructors to use that one. (This is needed because .NET has no way to distinguish between an implicit and explicit constructor.)</param>
public ReplaceReferencesRewriter MapFacade<TFromType, TFacade>(bool mapDefaultConstructor = false)
where TFacade : IRewriteFacade
{
return this.MapFacade(typeof(TFromType).FullName!, typeof(TFacade), mapDefaultConstructor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_5
/// <summary>Maps Harmony 1.x <see cref="AccessTools"/> methods to Harmony 2.x to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See <see cref="HarmonyRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class AccessToolsFacade
public class AccessToolsFacade : IRewriteFacade
{
/*********
** Public methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_5
/// <summary>Maps Harmony 1.x <c>HarmonyInstance</c> methods to Harmony 2.x's <see cref="Harmony"/> to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See <see cref="HarmonyRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class HarmonyInstanceFacade : Harmony
public class HarmonyInstanceFacade : Harmony, IRewriteFacade
{
/*********
** Public methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_5
/// <summary>Maps Harmony 1.x <see cref="HarmonyMethod"/> methods to Harmony 2.x to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See <see cref="HarmonyRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class HarmonyMethodFacade : HarmonyMethod
public class HarmonyMethodFacade : HarmonyMethod, IRewriteFacade
{
/*********
** Public methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_5
/// <summary>Provides <see cref="SpriteBatch"/> method signatures that can be injected into mod code for compatibility with mods written for XNA Framework before Stardew Valley 1.5.5.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class SpriteBatchFacade : SpriteBatch
public class SpriteBatchFacade : SpriteBatch, IRewriteFacade
{
/****
** XNA signatures
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
using StardewValley.Objects;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.

namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <see cref="BedFurniture"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BedFurnitureFacade : BedFurniture, IRewriteFacade
{
/*********
** Public methods
*********/
public static BedFurniture Constructor(int which, Vector2 tile, int initialRotations)
{
return new BedFurniture(which.ToString(), tile, initialRotations);
}

public static BedFurniture Constructor(int which, Vector2 tile)
{
return new BedFurniture(which.ToString(), tile);
}

public bool CanModifyBed(GameLocation location, Farmer who)
{
return this.CanModifyBed(who);
}

public bool IsBeingSleptIn(GameLocation location)
{
return this.IsBeingSleptIn();
}


/*********
** Private methods
*********/
private BedFurnitureFacade()
{
RewriteHelper.ThrowFakeConstructorCalled();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley.Objects;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.

namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Boots"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BootsFacade : Boots, IRewriteFacade
{
/*********
** Public methods
*********/
public static Boots Constructor(int which)
{
return new Boots(which.ToString());
}


/*********
** Private methods
*********/
private BootsFacade()
{
RewriteHelper.ThrowFakeConstructorCalled();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
using StardewValley.Objects;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.

namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <see cref="BreakableContainer"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
public class BreakableContainerFacade : BreakableContainer, IRewriteFacade
{
/*********
** Public methods
*********/
public void releaseContents(GameLocation location, Farmer who)
{
this.releaseContents(who);
}


/*********
** Private methods
*********/
private BreakableContainerFacade()
{
RewriteHelper.ThrowFakeConstructorCalled();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
using StardewValley.Buffs;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.

namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Buff"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "ParameterHidesMember", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
[SuppressMessage("ReSharper", "UnusedParameter.Local", Justification = SuppressReasons.MatchesOriginal)]
public class BuffFacade : Buff, IRewriteFacade
{
/*********
** Public methods
*********/
public static Buff Constructor(string description, int millisecondsDuration, string source, int index)
{
return new Buff(index.ToString(), source, description: description, duration: millisecondsDuration, iconSheetIndex: index);
}

public static Buff Constructor(int which)
{
return new Buff(which.ToString());
}

public static Buff Constructor(int farming, int fishing, int mining, int digging, int luck, int foraging, int crafting, int maxStamina, int magneticRadius, int speed, int defense, int attack, int minutesDuration, string source, string displaySource)
{
return new Buff(
null,
source,
displaySource,
duration: minutesDuration / Game1.realMilliSecondsPerGameMinute,
effects: new BuffEffects { FarmingLevel = { farming }, FishingLevel = { fishing }, MiningLevel = { mining }, LuckLevel = { luck }, ForagingLevel = { foraging }, MaxStamina = { maxStamina }, MagneticRadius = { magneticRadius }, Speed = { speed }, Defense = { defense }, Attack = { attack } }
);
}

public void addBuff()
{
Game1.player.buffs.Apply(this);
}

public void removeBuff()
{
Game1.player.buffs.Remove(this.id);
}


/*********
** Private methods
*********/
private BuffFacade()
: base(null)
{
RewriteHelper.ThrowFakeConstructorCalled();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
using StardewValley.Buildings;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.

namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <c>BuildableGameLocation</c> methods to their newer form on <see cref="GameLocation"/> to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "ParameterHidesMember", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BuildableGameLocationFacade : GameLocation, IRewriteFacade
{
/*********
** Public methods
*********/
public new bool buildStructure(Building b, Vector2 tileLocation, Farmer who, bool skipSafetyChecks = false)
{
return base.buildStructure(b, tileLocation, who, skipSafetyChecks);
}

public new bool destroyStructure(Vector2 tile)
{
return base.destroyStructure(tile);
}

public new bool destroyStructure(Building b)
{
return base.destroyStructure(b);
}

public new Building getBuildingAt(Vector2 tile)
{
return base.getBuildingAt(tile);
}

public new Building getBuildingByName(string name)
{
return base.getBuildingByName(name);
}

public Building? getBuildingUnderConstruction()
{
foreach (Building b in this.buildings)
{
if (b.daysOfConstructionLeft > 0 || b.daysUntilUpgrade > 0)
return b;
}

return null;
}

public int getNumberBuildingsConstructed(string name)
{
return base.getNumberBuildingsConstructed(name);
}

public bool isBuildable(Vector2 tileLocation)
{
return base.isBuildable(tileLocation);
}

public new bool isPath(Vector2 tileLocation)
{
return base.isPath(tileLocation);
}

public new bool isBuildingConstructed(string name)
{
return base.isBuildingConstructed(name);
}

public new bool isThereABuildingUnderConstruction()
{
return base.isThereABuildingUnderConstruction();
}


/*********
** Private methods
*********/
private BuildableGameLocationFacade()
{
RewriteHelper.ThrowFakeConstructorCalled();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Diagnostics.CodeAnalysis;
using Netcode;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6.Internal;
using StardewValley.Buildings;
using StardewValley.Objects;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member: This is internal code to support rewriters and shouldn't be called directly.

namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
{
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Building"/> methods to their newer form to avoid breaking older mods.</summary>
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See remarks on <see cref="ReplaceReferencesRewriter"/> for more info.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
public class BuildingFacade : Building, IRewriteFacade
{
/*********
** Accessors
*********/
public NetRef<Chest> input => NetRefWrapperCache<Chest>.GetCachedWrapperFor(this.GetBuildingChest("Input")); // Mill
public NetRef<Chest> output => NetRefWrapperCache<Chest>.GetCachedWrapperFor(this.GetBuildingChest("Output")); // Mill


/*********
** Private methods
*********/
private BuildingFacade()
{
RewriteHelper.ThrowFakeConstructorCalled();
}
}
}
Loading

0 comments on commit 8b3c1db

Please sign in to comment.