Compatibility fix

This commit is contained in:
zhiyang7 2023-02-08 18:04:24 +08:00
parent 48fd5a490b
commit 3c59a5fc6a
6 changed files with 114 additions and 28 deletions

View File

@ -0,0 +1,9 @@
using Microsoft.Xna.Framework.Audio;
using StardewValley;
namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades;
public interface ISoundBankMethods : ISoundBank
{
CueDefinition GetCueDefinition(string name);
}

View File

@ -0,0 +1,16 @@
using Microsoft.Xna.Framework.Graphics;
using StardewValley.Menus;
namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades;
public class OptionsElementMethods : OptionsElement
{
public OptionsElementMethods(string label) : base(label)
{
}
public virtual void draw(SpriteBatch b, int slotX, int slotY, IClickableMenu context = null)
{
base.draw(b, slotX, slotY);
}
}

View File

@ -293,6 +293,10 @@ namespace StardewModdingAPI.Framework
MiniMonoModHotfix.Apply(); MiniMonoModHotfix.Apply();
HarmonyPatcher.Apply("SMAPI", this.Monitor, HarmonyPatcher.Apply("SMAPI", this.Monitor,
new Game1Patcher(this.Reflection, this.OnLoadStageChanged), new Game1Patcher(this.Reflection, this.OnLoadStageChanged),
#if SMAPI_FOR_MOBILE
new StringPatcher(this.Reflection),
new ThreadSilenceExitPatch(this.Monitor),
#endif
new TitleMenuPatcher(this.OnLoadStageChanged) new TitleMenuPatcher(this.OnLoadStageChanged)
); );
// new GamePatcher(this.Monitor).Apply( // new GamePatcher(this.Monitor).Apply(

View File

@ -58,34 +58,6 @@ namespace StardewModdingAPI.Metadata
#if SMAPI_FOR_MOBILE #if SMAPI_FOR_MOBILE
// module rewrite for .Net 5 runtime assemblies // module rewrite for .Net 5 runtime assemblies
// yield return new TypeModuleReferenceRewriter("System",
// new []
// {
// "System.Runtime"
// },
// new []
// {
// "System.Collections.Generic.ISet`1"
// }, typeof(System.Collections.Generic.ISet<>).Assembly);
// yield return new TypeModuleReferenceRewriter("System",
// new []
// {
// "System.Runtime"
// },
// new []
// {
// "System.Collections.Generic.HashSet`1"
// }, typeof(System.Collections.Generic.HashSet<>).Assembly);
// yield return new TypeModuleReferenceRewriter("System.Runtime",
// new []
// {
// "System.Runtime"
// },
// new []
// {
// "System.Collections.Generic.IReadOnlySet`1"
// }, typeof(System.Collections.Generic.IReadOnlySet<>).Assembly);
yield return new ModuleReferenceRewriter("System.*", "System.", new Version(5,0), new[] yield return new ModuleReferenceRewriter("System.*", "System.", new Version(5,0), new[]
{ {
typeof(System.Collections.CollectionBase).Assembly, typeof(System.Collections.CollectionBase).Assembly,
@ -94,6 +66,7 @@ namespace StardewModdingAPI.Metadata
typeof(System.Xml.XmlDocument).Assembly, typeof(System.Xml.XmlDocument).Assembly,
typeof(System.Xml.Linq.XComment).Assembly, typeof(System.Xml.Linq.XComment).Assembly,
typeof(System.Collections.Generic.IReadOnlySet<>).Assembly, typeof(System.Collections.Generic.IReadOnlySet<>).Assembly,
typeof(System.Data.DataTable).Assembly,
}); });
yield return new TypeFieldToAnotherTypePropertyRewriter(typeof(Game1), typeof(Game1Methods), "onScreenMenus", "onScreenMenus"); yield return new TypeFieldToAnotherTypePropertyRewriter(typeof(Game1), typeof(Game1Methods), "onScreenMenus", "onScreenMenus");
@ -119,6 +92,8 @@ namespace StardewModdingAPI.Metadata
yield return new MethodParentRewriter(typeof(IClickableMenu), typeof(IClickableMenuMethods)); yield return new MethodParentRewriter(typeof(IClickableMenu), typeof(IClickableMenuMethods));
yield return new MethodParentRewriter(typeof(SpriteText), typeof(SpriteTextMethods)); yield return new MethodParentRewriter(typeof(SpriteText), typeof(SpriteTextMethods));
yield return new MethodParentRewriter(typeof(Utility), typeof(UtilityMethods)); yield return new MethodParentRewriter(typeof(Utility), typeof(UtilityMethods));
yield return new MethodParentRewriter(typeof(OptionsElement), typeof(OptionsElementMethods));
yield return new MethodParentRewriter(typeof(ISoundBank), typeof(ISoundBankMethods));
//Constructor Rewrites //Constructor Rewrites
yield return new MethodParentRewriter(typeof(MapPage), typeof(MapPageMethods)); yield return new MethodParentRewriter(typeof(MapPage), typeof(MapPageMethods));

View File

@ -0,0 +1,81 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using HarmonyLib;
using StardewModdingAPI.Enums;
using StardewModdingAPI.Framework.Reflection;
using StardewModdingAPI.Internal.Patching;
using StardewValley;
using StardewValley.Menus;
using StardewValley.Minigames;
namespace StardewModdingAPI.Patches
{
/// <summary>Harmony patches for <see cref="Game1"/> which notify SMAPI for save load stages.</summary>
/// <remarks>Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments.</remarks>
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Argument names are defined by Harmony and methods are named for clarity.")]
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = "Argument names are defined by Harmony and methods are named for clarity.")]
internal class StringPatcher : BasePatcher
{
/*********
** Fields
*********/
/// <summary>Simplifies access to private code.</summary>
private static Reflector Reflection = null!; // initialized in constructor
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="reflection">Simplifies access to private code.</param>
/// <param name="onStageChanged">A callback to invoke when the load stage changes.</param>
public StringPatcher(Reflector reflection)
{
StringPatcher.Reflection = reflection;
}
/// <inheritdoc />
public override void Apply(Harmony harmony, IMonitor monitor)
{
// detect CreatedInitialLocations and SaveAddedLocations
harmony.Patch(
original: this.RequireMethod<string>(nameof(string.Split), new []{typeof(char), typeof(StringSplitOptions)}),
prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split))
);
harmony.Patch(
original: this.RequireMethod<string>(nameof(string.Split), new []{typeof(string), typeof(StringSplitOptions)}),
prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split))
);
harmony.Patch(
original: this.RequireMethod<string>(nameof(string.Split), new []{typeof(char), typeof(int), typeof(StringSplitOptions)}),
prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split))
);
harmony.Patch(
original: this.RequireMethod<string>(nameof(string.Split), new []{typeof(string), typeof(int), typeof(StringSplitOptions)}),
prefix: this.GetHarmonyMethod(nameof(StringPatcher.Before_Split))
);
}
/*********
** Private methods
*********/
/// <summary>The method to call before <see cref="string.Split"/>.</summary>
/// <returns>Returns whether to execute the original method.</returns>
/// <remarks>This method must be static for Harmony to work correctly. See the Harmony documentation before renaming arguments.</remarks>
private static bool Before_Split(string __instance, ref StringSplitOptions options)
{
if (3 == (uint)options)
{
options = StringSplitOptions.RemoveEmptyEntries;
}
else if(2 == (uint)options)
{
options = StringSplitOptions.None;
}
return true;
}
}
}

View File

@ -141,6 +141,7 @@
<Reference Include="Mono.Security" /> <Reference Include="Mono.Security" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="0Harmony"> <Reference Include="0Harmony">