1.Fix crash bug

2.Adapt to latest logic
This commit is contained in:
ZaneYork 2020-03-04 21:55:54 +08:00
parent deafe14f1e
commit aed072e926
4 changed files with 22 additions and 80 deletions

View File

@ -36,6 +36,7 @@ using xTile.Layers;
using xTile.ObjectModel;
using SObject = StardewValley.Object;
using xTile.Tiles;
using Microsoft.AppCenter.Crashes;
namespace StardewModdingAPI.Framework
{
@ -1422,9 +1423,8 @@ namespace StardewModdingAPI.Framework
dictionary4["currentLocation"] = str3;
}
Dictionary<string, string> dictionary5 = dictionary1;
// Ignored
//ErrorAttachmentLog[] errorAttachmentLogArray = Array.Empty<ErrorAttachmentLog>();
//Microsoft.AppCenter.Crashes.Crashes.TrackError(ex, (IDictionary<string, string>)dictionary5, errorAttachmentLogArray);
ErrorAttachmentLog[] errorAttachmentLogArray = Array.Empty<ErrorAttachmentLog>();
Microsoft.AppCenter.Crashes.Crashes.TrackError(ex, (IDictionary<string, string>)dictionary5, errorAttachmentLogArray);
}
}
_spriteBatchBeginNextID.SetValue("L16");

View File

@ -1,64 +0,0 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection.Emit;
using Android.OS;
using Harmony;
using MonoMod.RuntimeDetour;
using StardewModdingAPI.Framework.Patching;
using StardewValley;
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

@ -38,6 +38,15 @@
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AppCenter">
<Version>3.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AppCenter.Analytics">
<Version>3.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AppCenter.Crashes">
<Version>3.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Net.Compilers" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
@ -48,10 +57,10 @@
<HintPath>..\..\..\..\..\AndroidStudioProjects\SMAPI Android Installer\app\src\main\assets\Stardew\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Google.Android.Vending.Expansion.Downloader">
<HintPath>..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.5.140\assemblies\Google.Android.Vending.Expansion.Downloader.dll</HintPath>
<HintPath>..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.5.142\assemblies\Google.Android.Vending.Expansion.Downloader.dll</HintPath>
</Reference>
<Reference Include="Google.Android.Vending.Licensing">
<HintPath>..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.5.140\assemblies\Google.Android.Vending.Licensing.dll</HintPath>
<HintPath>..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.5.142\assemblies\Google.Android.Vending.Licensing.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Mono.Android" />
@ -59,7 +68,7 @@
<HintPath>..\..\..\..\..\AndroidStudioProjects\SMAPI Android Installer\app\src\main\assets\Stardew\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="MonoGame.Framework">
<HintPath>..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.5.140\assemblies\MonoGame.Framework.dll</HintPath>
<HintPath>..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.5.142\assemblies\MonoGame.Framework.dll</HintPath>
</Reference>
<Reference Include="MonoMod.RuntimeDetour">
<HintPath>..\..\..\..\..\AndroidStudioProjects\SMAPI Android Installer\app\src\main\assets\Stardew\MonoMod.RuntimeDetour.dll</HintPath>
@ -77,10 +86,10 @@
<HintPath>..\SMAPI.Toolkit.CoreInterfaces\bin\Debug\net4.5\SMAPI.Toolkit.CoreInterfaces.dll</HintPath>
</Reference>
<Reference Include="StardewValley">
<HintPath>..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.5.140\assemblies\StardewValley.dll</HintPath>
<HintPath>..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.5.142\assemblies\StardewValley.dll</HintPath>
</Reference>
<Reference Include="StardewValley.GameData">
<HintPath>..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.5.140\assemblies\StardewValley.GameData.dll</HintPath>
<HintPath>..\..\..\..\..\Downloads\StardewValleyAndroidStuff\base_1.4.5.142\assemblies\StardewValley.GameData.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -361,7 +370,6 @@
<Compile Include="Metadata\CoreAssetPropagator.cs" />
<Compile Include="Metadata\InstructionMetadata.cs" />
<Compile Include="Mod.cs" />
<Compile Include="Patches\AppCenterReportPatch.cs" />
<Compile Include="Patches\DialogueErrorPatch.cs" />
<Compile Include="Patches\EventErrorPatch.cs" />
<Compile Include="Patches\SpriteFontPatch.cs" />

View File

@ -19,6 +19,7 @@ using System.Threading;
using System.Linq;
using System.IO;
using File = Java.IO.File;
using Microsoft.AppCenter;
namespace StardewModdingAPI
{
@ -96,13 +97,8 @@ namespace StardewModdingAPI
string errorLogPath = Path.Combine(this.ExternalCacheDir.AbsolutePath, "error.dat");
SAlertDialogUtil.AlertMessage(System.IO.File.ReadAllText(errorLog.AbsolutePath), "Crash Detected");
}
}
catch { }
Program.Main(null);
// this patch should apply much earlier
try
{
AppCenterReportPatch.ApplyPatch();
Type[] services = new Type[] { typeof(Microsoft.AppCenter.Analytics.Analytics), typeof(Microsoft.AppCenter.Crashes.Crashes) };
AppCenter.Start(Constants.MicrosoftAppSecret, services);
}
catch { }
base.OnCreate(bundle);
@ -115,6 +111,8 @@ namespace StardewModdingAPI
{
new SGameConsole();
Program.Main(null);
this.core = new SCore(System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "StardewValley/Mods"), false);
this.core.RunInteractively();