Skip to content

Commit 8b3c1db

Browse files
committed
add rewriters for Stardew Valley 1.6
1 parent 8865016 commit 8b3c1db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3233
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters
2+
{
3+
/// <summary>Marker class for a rewrite facade used to validate mappings. See comments on <see cref="ReplaceReferencesRewriter"/> for more info.</summary>
4+
internal interface IRewriteFacade { }
5+
}

src/SMAPI/Framework/ModLoading/Rewriters/ReplaceReferencesRewriter.cs

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public ReplaceReferencesRewriter MapMethod(string fromFullName, Type toType, str
188188
/// <typeparam name="TFacade">The facade type to which to point matching references.</typeparam>
189189
/// <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>
190190
public ReplaceReferencesRewriter MapFacade<TFromType, TFacade>(bool mapDefaultConstructor = false)
191+
where TFacade : IRewriteFacade
191192
{
192193
return this.MapFacade(typeof(TFromType).FullName!, typeof(TFacade), mapDefaultConstructor);
193194
}

src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_5/AccessToolsFacade.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_5
1212
/// <summary>Maps Harmony 1.x <see cref="AccessTools"/> methods to Harmony 2.x to avoid breaking older mods.</summary>
1313
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See <see cref="HarmonyRewriter"/> for more info.</remarks>
1414
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
15-
public class AccessToolsFacade
15+
public class AccessToolsFacade : IRewriteFacade
1616
{
1717
/*********
1818
** Public methods

src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_5/HarmonyInstanceFacade.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_5
1313
/// <summary>Maps Harmony 1.x <c>HarmonyInstance</c> methods to Harmony 2.x's <see cref="Harmony"/> to avoid breaking older mods.</summary>
1414
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See <see cref="HarmonyRewriter"/> for more info.</remarks>
1515
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
16-
public class HarmonyInstanceFacade : Harmony
16+
public class HarmonyInstanceFacade : Harmony, IRewriteFacade
1717
{
1818
/*********
1919
** Public methods

src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_5/HarmonyMethodFacade.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_5
1111
/// <summary>Maps Harmony 1.x <see cref="HarmonyMethod"/> methods to Harmony 2.x to avoid breaking older mods.</summary>
1212
/// <remarks>This is public to support SMAPI rewriting and should never be referenced directly by mods. See <see cref="HarmonyRewriter"/> for more info.</remarks>
1313
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
14-
public class HarmonyMethodFacade : HarmonyMethod
14+
public class HarmonyMethodFacade : HarmonyMethod, IRewriteFacade
1515
{
1616
/*********
1717
** Public methods

src/SMAPI/Framework/ModLoading/Rewriters/StardewValley_1_5/SpriteBatchFacade.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_5
1111
/// <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>
1212
/// <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>
1313
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
14-
public class SpriteBatchFacade : SpriteBatch
14+
public class SpriteBatchFacade : SpriteBatch, IRewriteFacade
1515
{
1616
/****
1717
** XNA signatures
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Microsoft.Xna.Framework;
3+
using StardewModdingAPI.Framework.ModLoading.Framework;
4+
using StardewValley;
5+
using StardewValley.Objects;
6+
7+
#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.
8+
9+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
10+
{
11+
/// <summary>Maps Stardew Valley 1.5.6's <see cref="BedFurniture"/> methods to their newer form to avoid breaking older mods.</summary>
12+
/// <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>
13+
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
14+
public class BedFurnitureFacade : BedFurniture, IRewriteFacade
15+
{
16+
/*********
17+
** Public methods
18+
*********/
19+
public static BedFurniture Constructor(int which, Vector2 tile, int initialRotations)
20+
{
21+
return new BedFurniture(which.ToString(), tile, initialRotations);
22+
}
23+
24+
public static BedFurniture Constructor(int which, Vector2 tile)
25+
{
26+
return new BedFurniture(which.ToString(), tile);
27+
}
28+
29+
public bool CanModifyBed(GameLocation location, Farmer who)
30+
{
31+
return this.CanModifyBed(who);
32+
}
33+
34+
public bool IsBeingSleptIn(GameLocation location)
35+
{
36+
return this.IsBeingSleptIn();
37+
}
38+
39+
40+
/*********
41+
** Private methods
42+
*********/
43+
private BedFurnitureFacade()
44+
{
45+
RewriteHelper.ThrowFakeConstructorCalled();
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using StardewModdingAPI.Framework.ModLoading.Framework;
3+
using StardewValley.Objects;
4+
5+
#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.
6+
7+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
8+
{
9+
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Boots"/> methods to their newer form to avoid breaking older mods.</summary>
10+
/// <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>
11+
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
12+
public class BootsFacade : Boots, IRewriteFacade
13+
{
14+
/*********
15+
** Public methods
16+
*********/
17+
public static Boots Constructor(int which)
18+
{
19+
return new Boots(which.ToString());
20+
}
21+
22+
23+
/*********
24+
** Private methods
25+
*********/
26+
private BootsFacade()
27+
{
28+
RewriteHelper.ThrowFakeConstructorCalled();
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using StardewModdingAPI.Framework.ModLoading.Framework;
3+
using StardewValley;
4+
using StardewValley.Objects;
5+
6+
#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.
7+
8+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
9+
{
10+
/// <summary>Maps Stardew Valley 1.5.6's <see cref="BreakableContainer"/> methods to their newer form to avoid breaking older mods.</summary>
11+
/// <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>
12+
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
13+
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
14+
public class BreakableContainerFacade : BreakableContainer, IRewriteFacade
15+
{
16+
/*********
17+
** Public methods
18+
*********/
19+
public void releaseContents(GameLocation location, Farmer who)
20+
{
21+
this.releaseContents(who);
22+
}
23+
24+
25+
/*********
26+
** Private methods
27+
*********/
28+
private BreakableContainerFacade()
29+
{
30+
RewriteHelper.ThrowFakeConstructorCalled();
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using StardewModdingAPI.Framework.ModLoading.Framework;
3+
using StardewValley;
4+
using StardewValley.Buffs;
5+
6+
#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.
7+
8+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
9+
{
10+
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Buff"/> methods to their newer form to avoid breaking older mods.</summary>
11+
/// <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>
12+
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
13+
[SuppressMessage("ReSharper", "ParameterHidesMember", Justification = SuppressReasons.MatchesOriginal)]
14+
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
15+
[SuppressMessage("ReSharper", "UnusedParameter.Local", Justification = SuppressReasons.MatchesOriginal)]
16+
public class BuffFacade : Buff, IRewriteFacade
17+
{
18+
/*********
19+
** Public methods
20+
*********/
21+
public static Buff Constructor(string description, int millisecondsDuration, string source, int index)
22+
{
23+
return new Buff(index.ToString(), source, description: description, duration: millisecondsDuration, iconSheetIndex: index);
24+
}
25+
26+
public static Buff Constructor(int which)
27+
{
28+
return new Buff(which.ToString());
29+
}
30+
31+
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)
32+
{
33+
return new Buff(
34+
null,
35+
source,
36+
displaySource,
37+
duration: minutesDuration / Game1.realMilliSecondsPerGameMinute,
38+
effects: new BuffEffects { FarmingLevel = { farming }, FishingLevel = { fishing }, MiningLevel = { mining }, LuckLevel = { luck }, ForagingLevel = { foraging }, MaxStamina = { maxStamina }, MagneticRadius = { magneticRadius }, Speed = { speed }, Defense = { defense }, Attack = { attack } }
39+
);
40+
}
41+
42+
public void addBuff()
43+
{
44+
Game1.player.buffs.Apply(this);
45+
}
46+
47+
public void removeBuff()
48+
{
49+
Game1.player.buffs.Remove(this.id);
50+
}
51+
52+
53+
/*********
54+
** Private methods
55+
*********/
56+
private BuffFacade()
57+
: base(null)
58+
{
59+
RewriteHelper.ThrowFakeConstructorCalled();
60+
}
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Microsoft.Xna.Framework;
3+
using StardewModdingAPI.Framework.ModLoading.Framework;
4+
using StardewValley;
5+
using StardewValley.Buildings;
6+
7+
#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.
8+
9+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
10+
{
11+
/// <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>
12+
/// <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>
13+
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
14+
[SuppressMessage("ReSharper", "ParameterHidesMember", Justification = SuppressReasons.MatchesOriginal)]
15+
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
16+
public class BuildableGameLocationFacade : GameLocation, IRewriteFacade
17+
{
18+
/*********
19+
** Public methods
20+
*********/
21+
public new bool buildStructure(Building b, Vector2 tileLocation, Farmer who, bool skipSafetyChecks = false)
22+
{
23+
return base.buildStructure(b, tileLocation, who, skipSafetyChecks);
24+
}
25+
26+
public new bool destroyStructure(Vector2 tile)
27+
{
28+
return base.destroyStructure(tile);
29+
}
30+
31+
public new bool destroyStructure(Building b)
32+
{
33+
return base.destroyStructure(b);
34+
}
35+
36+
public new Building getBuildingAt(Vector2 tile)
37+
{
38+
return base.getBuildingAt(tile);
39+
}
40+
41+
public new Building getBuildingByName(string name)
42+
{
43+
return base.getBuildingByName(name);
44+
}
45+
46+
public Building? getBuildingUnderConstruction()
47+
{
48+
foreach (Building b in this.buildings)
49+
{
50+
if (b.daysOfConstructionLeft > 0 || b.daysUntilUpgrade > 0)
51+
return b;
52+
}
53+
54+
return null;
55+
}
56+
57+
public int getNumberBuildingsConstructed(string name)
58+
{
59+
return base.getNumberBuildingsConstructed(name);
60+
}
61+
62+
public bool isBuildable(Vector2 tileLocation)
63+
{
64+
return base.isBuildable(tileLocation);
65+
}
66+
67+
public new bool isPath(Vector2 tileLocation)
68+
{
69+
return base.isPath(tileLocation);
70+
}
71+
72+
public new bool isBuildingConstructed(string name)
73+
{
74+
return base.isBuildingConstructed(name);
75+
}
76+
77+
public new bool isThereABuildingUnderConstruction()
78+
{
79+
return base.isThereABuildingUnderConstruction();
80+
}
81+
82+
83+
/*********
84+
** Private methods
85+
*********/
86+
private BuildableGameLocationFacade()
87+
{
88+
RewriteHelper.ThrowFakeConstructorCalled();
89+
}
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using Netcode;
3+
using StardewModdingAPI.Framework.ModLoading.Framework;
4+
using StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6.Internal;
5+
using StardewValley.Buildings;
6+
using StardewValley.Objects;
7+
8+
#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.
9+
10+
namespace StardewModdingAPI.Framework.ModLoading.Rewriters.StardewValley_1_6
11+
{
12+
/// <summary>Maps Stardew Valley 1.5.6's <see cref="Building"/> methods to their newer form to avoid breaking older mods.</summary>
13+
/// <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>
14+
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = SuppressReasons.MatchesOriginal)]
15+
[SuppressMessage("ReSharper", "UnusedMember.Global", Justification = SuppressReasons.UsedViaRewriting)]
16+
public class BuildingFacade : Building, IRewriteFacade
17+
{
18+
/*********
19+
** Accessors
20+
*********/
21+
public NetRef<Chest> input => NetRefWrapperCache<Chest>.GetCachedWrapperFor(this.GetBuildingChest("Input")); // Mill
22+
public NetRef<Chest> output => NetRefWrapperCache<Chest>.GetCachedWrapperFor(this.GetBuildingChest("Output")); // Mill
23+
24+
25+
/*********
26+
** Private methods
27+
*********/
28+
private BuildingFacade()
29+
{
30+
RewriteHelper.ThrowFakeConstructorCalled();
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)