From f59c4f194b178bcf6526bc66d83f208be190f506 Mon Sep 17 00:00:00 2001 From: yangzhi Date: Tue, 20 Jun 2023 14:48:34 +0800 Subject: [PATCH] Imporve compatibility --- src/Loader/Properties/AndroidManifest.xml | 3 +- src/Loader/Resources/Resource.designer.cs | 4 ++ .../ModLoading/RewriteFacades/Game1Methods.cs | 5 +- src/SMAPI/Framework/SCore.cs | 1 + src/SMAPI/Metadata/InstructionMetadata.cs | 5 +- src/SMAPI/Patches/UIThreadPatch.cs | 64 +++++++++++++++++++ 6 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 src/SMAPI/Patches/UIThreadPatch.cs diff --git a/src/Loader/Properties/AndroidManifest.xml b/src/Loader/Properties/AndroidManifest.xml index 4608458d..56edacde 100644 --- a/src/Loader/Properties/AndroidManifest.xml +++ b/src/Loader/Properties/AndroidManifest.xml @@ -15,6 +15,7 @@ android:allowBackup="true" android:resizeableActivity="false" android:debuggable="true" - android:requestLegacyExternalStorage="true"> + android:requestLegacyExternalStorage="true"> + diff --git a/src/Loader/Resources/Resource.designer.cs b/src/Loader/Resources/Resource.designer.cs index ccff4cdf..9ff77170 100644 --- a/src/Loader/Resources/Resource.designer.cs +++ b/src/Loader/Resources/Resource.designer.cs @@ -26,6 +26,7 @@ namespace Loader public static void UpdateIdValues() { global::StardewModdingAPI.Resource.String.app_name = global::Loader.Resource.String.app_name; + global::StardewModdingAPI.Resource.String.hello = global::Loader.Resource.String.hello; } public partial class Attribute @@ -125,6 +126,9 @@ namespace Loader // aapt resource value: 0x7F040001 public const int app_name = 2130968577; + // aapt resource value: 0x7F040002 + public const int hello = 2130968578; + static String() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); diff --git a/src/SMAPI/Framework/ModLoading/RewriteFacades/Game1Methods.cs b/src/SMAPI/Framework/ModLoading/RewriteFacades/Game1Methods.cs index 7f067081..e15756e1 100644 --- a/src/SMAPI/Framework/ModLoading/RewriteFacades/Game1Methods.cs +++ b/src/SMAPI/Framework/ModLoading/RewriteFacades/Game1Methods.cs @@ -13,10 +13,11 @@ namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades { public static new IList onScreenMenus => Game1.onScreenMenus; + public static new RainDrop[] RainDropsProp => Game1.rainDrops.ToArray(); - public static new IList LocationsGetter(Game1 game1) + public static new IList LocationsGetter() { - return game1._locations; + return Game1.game1._locations; } #if SMAPI_LEGACY_PATCH diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 4a863fa0..4e559a47 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -292,6 +292,7 @@ namespace StardewModdingAPI.Framework #if SMAPI_FOR_MOBILE new StringPatcher(this.Reflection), new ThreadSilenceExitPatch(this.Monitor), + new UIThreadPatch(this.Monitor), #endif new TitleMenuPatcher(this.OnLoadStageChanged) ); diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index 36331087..4d851a77 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -58,7 +58,7 @@ namespace StardewModdingAPI.Metadata #if SMAPI_FOR_MOBILE // module rewrite for .Net 5 runtime assemblies - yield return new ModuleReferenceRewriter("System.*", "System.", new Version(5,0), new[] + yield return new ModuleReferenceRewriter("System.*", "System.", new Version(4,0), new[] { typeof(System.Collections.CollectionBase).Assembly, typeof(System.Collections.Generic.ISet<>).Assembly, @@ -66,7 +66,7 @@ namespace StardewModdingAPI.Metadata typeof(System.Xml.XmlDocument).Assembly, typeof(System.Xml.Linq.XComment).Assembly, typeof(System.Collections.Generic.IReadOnlySet<>).Assembly, - typeof(System.Data.DataTable).Assembly, + typeof(System.Data.DataTable).Assembly }); yield return new TypeFieldToAnotherTypePropertyRewriter(typeof(Game1), typeof(Game1Methods), "onScreenMenus", "onScreenMenus"); @@ -82,6 +82,7 @@ namespace StardewModdingAPI.Metadata // Game1.location fix yield return new TypePropertyToAnotherTypeMethodRewriter(typeof(Game1), typeof(Game1Methods), "locations", "LocationsGetter", null); + yield return new TypeFieldToAnotherTypePropertyRewriter(typeof(Game1), typeof(Game1Methods), "rainDrops", "RainDropsProp"); // Rewrite Missing Type yield return new TypeReferenceRewriter("StardewValley.Menus.CraftingPage", typeof(CraftingPageMobile)); diff --git a/src/SMAPI/Patches/UIThreadPatch.cs b/src/SMAPI/Patches/UIThreadPatch.cs new file mode 100644 index 00000000..ce13a30c --- /dev/null +++ b/src/SMAPI/Patches/UIThreadPatch.cs @@ -0,0 +1,64 @@ +#if SMAPI_FOR_MOBILE +using System; +using System.Diagnostics.CodeAnalysis; +using System.Threading; +using HarmonyLib; +using StardewModdingAPI.Internal.Patching; + +namespace StardewModdingAPI.Patches +{ + /// A Harmony patch for . + /// Patch methods must be static for Harmony to work correctly. See the Harmony documentation before renaming patch arguments. + [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 UIThreadPatch : BasePatcher + { + /********* + ** Fields + *********/ + + /********* + ** Fields + *********/ + /// Writes messages to the console and log file. + private static IMonitor Monitor; + + /********* + ** Accessors + *********/ + /// A unique name for this patch. + public string Name => nameof(UIThreadPatch); + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// Writes messages to the console and log file on behalf of the game. + public UIThreadPatch(IMonitor monitor) + { + Monitor = monitor; + } + + /// Apply the Harmony patch. + /// The Harmony instance. + public override void Apply(Harmony harmony, IMonitor monitor) + { + harmony.Patch( + original: AccessTools.Method(typeof(Microsoft.Xna.Framework.Point).Assembly.GetType("Microsoft.Xna.Framework.Threading"), "EnsureUIThread"), + prefix: this.GetHarmonyMethod(nameof(UIThreadPatch.UIThreadPatch_Prefix)) + ); + } + + /********* + ** Private methods + *********/ + /// The method to call instead of . + /// Returns whether to execute the original method. + private static bool UIThreadPatch_Prefix() + { + return false; + } + } +} +#endif