backport harmony_summary command to Harmony 1.x (#711)
This commit is contained in:
parent
c41b92f721
commit
aeab19f4ac
|
@ -1,10 +1,11 @@
|
|||
← [README](README.md)
|
||||
|
||||
# Release notes
|
||||
<!--
|
||||
## Upcoming release + 1
|
||||
* For modders:
|
||||
* Migrated to Harmony 2.0 (see [_migrate to Harmony 2.0_](https://stardewvalleywiki.com/Modding:Migrate_to_Harmony_2.0) for more info).
|
||||
* Added `harmony_summary` console command which lists all current Harmony patches, optionally with a search filter.
|
||||
-->
|
||||
|
||||
## Upcoming release
|
||||
* For players:
|
||||
|
@ -25,6 +26,7 @@
|
|||
* Added [event priorities](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Events#Custom_priority) (thanks to spacechase0!).
|
||||
* Added [update subkeys](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Update_checks#Update_subkeys).
|
||||
* Added `Multiplayer.PeerConnected` event.
|
||||
* Added `harmony_summary` console command which lists all current Harmony patches, optionally with a search filter.
|
||||
* Added ability to override update keys from the compatibility list.
|
||||
* Harmony mods which use the `[HarmonyPatch(type)]` attribute now work crossplatform. Previously SMAPI couldn't rewrite types in custom attributes for compatibility.
|
||||
* Improved mod rewriting for compatibility:
|
||||
|
|
|
@ -1,16 +1,27 @@
|
|||
#if HARMONY_2
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
#if HARMONY_2
|
||||
using HarmonyLib;
|
||||
#else
|
||||
using Harmony;
|
||||
#endif
|
||||
|
||||
namespace StardewModdingAPI.Framework.Commands
|
||||
{
|
||||
/// <summary>The 'harmony_summary' SMAPI console command.</summary>
|
||||
internal class HarmonySummaryCommand : IInternalCommand
|
||||
{
|
||||
#if !HARMONY_2
|
||||
/*********
|
||||
** Fields
|
||||
*********/
|
||||
/// <summary>The Harmony instance through which to fetch patch info.</summary>
|
||||
private readonly HarmonyInstance HarmonyInstance = HarmonyInstance.Create($"SMAPI.{nameof(HarmonySummaryCommand)}");
|
||||
#endif
|
||||
|
||||
/*********
|
||||
** Accessors
|
||||
*********/
|
||||
|
@ -45,7 +56,16 @@ namespace StardewModdingAPI.Framework.Commands
|
|||
foreach (var ownerGroup in match.PatchTypesByOwner.OrderBy(p => p.Key))
|
||||
{
|
||||
var sortedTypes = ownerGroup.Value
|
||||
.OrderBy(p => p switch { PatchType.Prefix => 0, PatchType.Postfix => 1, PatchType.Finalizer => 2, PatchType.Transpiler => 3, _ => 4 });
|
||||
.OrderBy(p => p switch
|
||||
{
|
||||
PatchType.Prefix => 0,
|
||||
PatchType.Postfix => 1,
|
||||
#if HARMONY_2
|
||||
PatchType.Finalizer => 2,
|
||||
#endif
|
||||
PatchType.Transpiler => 3,
|
||||
_ => 4
|
||||
});
|
||||
|
||||
result.AppendLine($" - {ownerGroup.Key} ({string.Join(", ", sortedTypes).ToLower()})");
|
||||
}
|
||||
|
@ -91,15 +111,26 @@ namespace StardewModdingAPI.Framework.Commands
|
|||
/// <summary>Get all current Harmony patches.</summary>
|
||||
private IEnumerable<SearchResult> GetAllPatches()
|
||||
{
|
||||
#if HARMONY_2
|
||||
foreach (MethodBase method in Harmony.GetAllPatchedMethods())
|
||||
#else
|
||||
foreach (MethodBase method in this.HarmonyInstance.GetPatchedMethods())
|
||||
#endif
|
||||
{
|
||||
// get metadata for method
|
||||
#if HARMONY_2
|
||||
HarmonyLib.Patches patchInfo = Harmony.GetPatchInfo(method);
|
||||
#else
|
||||
Harmony.Patches patchInfo = this.HarmonyInstance.GetPatchInfo(method);
|
||||
#endif
|
||||
|
||||
IDictionary<PatchType, IReadOnlyCollection<Patch>> patchGroups = new Dictionary<PatchType, IReadOnlyCollection<Patch>>
|
||||
{
|
||||
[PatchType.Prefix] = patchInfo.Prefixes,
|
||||
[PatchType.Postfix] = patchInfo.Postfixes,
|
||||
#if HARMONY_2
|
||||
[PatchType.Finalizer] = patchInfo.Finalizers,
|
||||
#endif
|
||||
[PatchType.Transpiler] = patchInfo.Transpilers
|
||||
};
|
||||
|
||||
|
@ -129,8 +160,10 @@ namespace StardewModdingAPI.Framework.Commands
|
|||
/// <summary>A postfix patch.</summary>
|
||||
Postfix,
|
||||
|
||||
#if HARMONY_2
|
||||
/// <summary>A finalizer patch.</summary>
|
||||
Finalizer,
|
||||
#endif
|
||||
|
||||
/// <summary>A transpiler patch.</summary>
|
||||
Transpiler
|
||||
|
@ -167,4 +200,3 @@ namespace StardewModdingAPI.Framework.Commands
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -511,9 +511,7 @@ namespace StardewModdingAPI.Framework
|
|||
this.Monitor.Log("Type 'help' for help, or 'help <cmd>' for a command's usage", LogLevel.Info);
|
||||
this.GameInstance.CommandManager
|
||||
.Add(new HelpCommand(this.GameInstance.CommandManager), this.Monitor)
|
||||
#if HARMONY_2
|
||||
.Add(new HarmonySummaryCommand(), this.Monitor)
|
||||
#endif
|
||||
.Add(new ReloadI18nCommand(this.ReloadTranslations), this.Monitor);
|
||||
|
||||
// start handling command line input
|
||||
|
|
Loading…
Reference in New Issue