Remove MonoMod dependency

This commit is contained in:
ZaneYork 2020-05-31 20:09:57 +08:00
parent bd9c1dfcfe
commit 5ee6d5b685
7 changed files with 9 additions and 25 deletions

View File

@ -110,7 +110,7 @@ namespace StardewModdingAPI
/// <summary>The language code for non-translated mod assets.</summary>
internal static LocalizedContentManager.LanguageCode DefaultLanguage { get; } = LocalizedContentManager.LanguageCode.en;
internal static bool MonoModInit { get; set; } = true;
internal static bool HarmonyEnabled { get; set; } = true;
/*********
@ -202,8 +202,6 @@ namespace StardewModdingAPI
{
typeof(StardewValley.Game1).Assembly, // note: includes Netcode types on Linux/Mac
typeof(Microsoft.Xna.Framework.Vector2).Assembly,
typeof(MonoMod.RuntimeDetour.HarmonyDetourBridge).Assembly,
typeof(MonoMod.Utils.Platform).Assembly,
typeof(HarmonyLib.Harmony).Assembly,
typeof(Mono.Cecil.MethodDefinition).Assembly,
typeof(StardewModdingAPI.IManifest).Assembly,

View File

@ -34,7 +34,7 @@ namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades
if (original != null)
original = original.GetDeclaredMember();
if (!Constants.MonoModInit)
if (!Constants.HarmonyEnabled)
return null;
// call Harmony 2.0 and show a detailed exception if it fails
try

View File

@ -14,19 +14,19 @@ namespace StardewModdingAPI.Framework.ModLoading.RewriteFacades
HarmonyMethod transpiler = null,
HarmonyMethod finalizer = null)
{
if (Constants.MonoModInit)
if (Constants.HarmonyEnabled)
return instance.Patch(original, prefix, postfix, transpiler, finalizer);
else
return null;
}
public static void PatchAll(Harmony instance)
{
if (Constants.MonoModInit)
if (Constants.HarmonyEnabled)
instance.PatchAll();
}
public static void PatchAllToAssembly(Harmony instance, Assembly assembly)
{
if (Constants.MonoModInit)
if (Constants.HarmonyEnabled)
instance.PatchAll(assembly);
}
}

View File

@ -29,25 +29,17 @@ namespace StardewModdingAPI.Framework.Patching
/// <param name="patches">The patches to apply.</param>
public void Apply(params IHarmonyPatch[] patches)
{
if (!HarmonyDetourBridge.Initialized && Constants.MonoModInit)
{
try {
HarmonyDetourBridge.Init();
}
catch { Constants.MonoModInit = false; }
}
Harmony harmony = new Harmony("io.smapi");
foreach (IHarmonyPatch patch in patches)
{
try
{
if(Constants.MonoModInit)
if(Constants.HarmonyEnabled)
patch.Apply(harmony);
}
catch (Exception ex)
{
Constants.MonoModInit = false;
Constants.HarmonyEnabled = false;
this.Monitor.Log($"Couldn't apply runtime patch '{patch.Name}' to the game. Some SMAPI features may not work correctly. See log file for details.", LogLevel.Error);
this.Monitor.Log(ex.GetLogSummary(), LogLevel.Trace);
}

View File

@ -126,7 +126,7 @@ namespace StardewModdingAPI.Metadata
yield return new Harmony1AssemblyRewriter();
// MonoMod fix
if (!Constants.MonoModInit)
if (!Constants.HarmonyEnabled)
{
yield return new MethodToAnotherStaticMethodRewriter(typeof(Harmony), (method) => method.Name == "Patch", typeof(HarmonyInstanceMethods), "Patch");
yield return new MethodToAnotherStaticMethodRewriter(typeof(Harmony), (method) => method.Name == "PatchAll" && method.Parameters.Count == 0, typeof(HarmonyInstanceMethods), "PatchAll");

View File

@ -109,12 +109,6 @@
<Reference Include="MonoGame.Framework">
<HintPath>..\Loader\libs\MonoGame.Framework.dll</HintPath>
</Reference>
<Reference Include="MonoMod.RuntimeDetour">
<HintPath>..\Loader\libs\MonoMod.RuntimeDetour.dll</HintPath>
</Reference>
<Reference Include="MonoMod.Utils">
<HintPath>..\Loader\libs\MonoMod.Utils.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Mono.Android" />
<Reference Include="SMAPI.Toolkit">

View File

@ -132,7 +132,7 @@ namespace StardewModdingAPI
{
var settings = JsonConvert.DeserializeObject<Framework.Models.SConfig>(System.IO.File.ReadAllText(Constants.ApiUserConfigPath));
modPath = settings.ModsPath;
Constants.MonoModInit = !settings.DisableMonoMod;
Constants.HarmonyEnabled = !settings.DisableMonoMod;
}
if (string.IsNullOrWhiteSpace(modPath))