Redirect bug report to our account.

This commit is contained in:
yangzhi 2020-02-26 21:19:10 +08:00
parent 471d0918d0
commit 7fb4b95c1c
5 changed files with 81 additions and 3 deletions

View File

@ -61,6 +61,9 @@ namespace StardewModdingAPI
/// <summary>The absolute path to the folder containing SMAPI's internal files.</summary> /// <summary>The absolute path to the folder containing SMAPI's internal files.</summary>
internal static readonly string InternalFilesPath = Program.DllSearchPath; internal static readonly string InternalFilesPath = Program.DllSearchPath;
/// <summary>The app secret from AppCenter.</summary>
internal static readonly object MicrosoftAppSecret = "79411636-0bc5-41cc-9889-43a4bca83b9d";
/// <summary>The file path for the SMAPI configuration file.</summary> /// <summary>The file path for the SMAPI configuration file.</summary>
internal static string ApiConfigPath => Path.Combine(Constants.InternalFilesPath, "config.json"); internal static string ApiConfigPath => Path.Combine(Constants.InternalFilesPath, "config.json");

View File

@ -29,7 +29,10 @@ namespace StardewModdingAPI.Framework.Patching
/// <param name="patches">The patches to apply.</param> /// <param name="patches">The patches to apply.</param>
public void Apply(params IHarmonyPatch[] patches) public void Apply(params IHarmonyPatch[] patches)
{ {
HarmonyDetourBridge.Init(); if (!HarmonyDetourBridge.Initialized)
{
HarmonyDetourBridge.Init();
}
HarmonyInstance harmony = HarmonyInstance.Create("io.smapi"); HarmonyInstance harmony = HarmonyInstance.Create("io.smapi");
foreach (IHarmonyPatch patch in patches) foreach (IHarmonyPatch patch in patches)

View File

@ -0,0 +1,68 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using Android.OS;
using Harmony;
using Microsoft.Xna.Framework;
using MonoMod.RuntimeDetour;
using StardewModdingAPI.Framework.Patching;
using StardewValley;
using StardewValley.Buildings;
using StardewValley.Characters;
namespace StardewModdingAPI.Patches
{
/// <summary>A Harmony patch for <see cref="StardewValley.MainActivity.OnCreate(Android.OS.Bundle)"/> to redirect bug report.</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 AppCenterReportPatch : IHarmonyPatch
{
/*********
** Accessors
*********/
/// <summary>A unique name for this patch.</summary>
public string Name => nameof(AppCenterReportPatch);
/// <summary>Apply the Harmony patch.</summary>
/// <param name="harmony">The Harmony instance.</param>
public void Apply(HarmonyInstance harmony)
{
harmony.Patch(
original: AccessTools.Method(typeof(MainActivity), "OnCreate", new System.Type[] { typeof(Android.OS.Bundle)}),
transpiler: new HarmonyMethod(this.GetType(), nameof(AppCenterReportPatch.Modify_MainActivity_OnCreate))
);
}
/*********
** Private methods
*********/
/// <summary>The patch logic <see cref="MainActivity.OnCreate"/>.</summary>
private static IEnumerable<CodeInstruction> Modify_MainActivity_OnCreate(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> codes = new List<CodeInstruction>(instructions);
for (int i = 0; i < codes.Count ; i++)
{
if (codes[i].opcode == OpCodes.Ldstr && (string)codes[i].operand == "5677d40e-f7b3-4ccb-bee4-5dca56d86ade")
{
codes[i].operand = Constants.MicrosoftAppSecret;
break;
}
}
return codes.AsEnumerable();
}
public static void ApplyPatch()
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
{
HarmonyDetourBridge.Init();
HarmonyInstance harmony = HarmonyInstance.Create("io.smapi.mainactivity");
new AppCenterReportPatch().Apply(harmony);
}
}
}
}

View File

@ -361,6 +361,7 @@
<Compile Include="Metadata\CoreAssetPropagator.cs" /> <Compile Include="Metadata\CoreAssetPropagator.cs" />
<Compile Include="Metadata\InstructionMetadata.cs" /> <Compile Include="Metadata\InstructionMetadata.cs" />
<Compile Include="Mod.cs" /> <Compile Include="Mod.cs" />
<Compile Include="Patches\AppCenterReportPatch.cs" />
<Compile Include="Patches\DialogueErrorPatch.cs" /> <Compile Include="Patches\DialogueErrorPatch.cs" />
<Compile Include="Patches\EventErrorPatch.cs" /> <Compile Include="Patches\EventErrorPatch.cs" />
<Compile Include="Patches\SpriteFontPatch.cs" /> <Compile Include="Patches\SpriteFontPatch.cs" />

View File

@ -14,6 +14,7 @@ using StardewValley;
using System.Reflection; using System.Reflection;
using Android.Content.Res; using Android.Content.Res;
using Java.Interop; using Java.Interop;
using StardewModdingAPI.Patches;
namespace StardewModdingAPI namespace StardewModdingAPI
{ {
@ -79,6 +80,10 @@ namespace StardewModdingAPI
} }
this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen); this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn); this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);
Program.Main(null);
// this patch should apply much earlier
AppCenterReportPatch.ApplyPatch();
base.OnCreate(bundle); base.OnCreate(bundle);
this.CheckAppPermissions(); this.CheckAppPermissions();
} }
@ -87,8 +92,6 @@ namespace StardewModdingAPI
{ {
new SGameConsole(); new SGameConsole();
Program.Main(null);
this.core = new SCore(System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "StardewValley/Mods"), false); this.core = new SCore(System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "StardewValley/Mods"), false);
this.core.RunInteractively(); this.core.RunInteractively();