From d9fc2620036f5fd7a8e08dd564bfdf4ac7361e63 Mon Sep 17 00:00:00 2001 From: Clansty Date: Wed, 11 Sep 2024 00:26:45 +0800 Subject: [PATCH] [F] Nested types patches without enable --- AquaMai/Main.cs | 15 +++++++++++---- AquaMai/Properties/AssemblyInfo.cs | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/AquaMai/Main.cs b/AquaMai/Main.cs index 62b6e285..24fc01ee 100644 --- a/AquaMai/Main.cs +++ b/AquaMai/Main.cs @@ -21,16 +21,16 @@ public class AquaMai : MelonMod { public static Config AppConfig { get; private set; } - private static void Patch(Type type) + private void Patch(Type type) { MelonLogger.Msg($"> Patching {type}"); - HarmonyLib.Harmony.CreateAndPatchAll(type); + HarmonyInstance.PatchAll(type); } /** * Apply patches using reflection, based on the settings */ - private static void ApplyPatches() + private void ApplyPatches() { // Iterate over all properties of AppConfig foreach (var categoryProp in AppConfig.GetType().GetProperties()) @@ -53,7 +53,14 @@ private static void ApplyPatches() var directiveType = Type.GetType($"AquaMai.{categoryProp.Name}.{settingProp.Name}"); // If the type is found, call the Patch method - if (directiveType != null) Patch(directiveType); + if (directiveType != null) + { + Patch(directiveType); + foreach (var nested in directiveType.GetNestedTypes()) + { + Patch(nested); + } + } else MelonLogger.Error($"Type not found for {categoryProp.Name}.{settingProp.Name}"); } } diff --git a/AquaMai/Properties/AssemblyInfo.cs b/AquaMai/Properties/AssemblyInfo.cs index 7feec092..e566a535 100644 --- a/AquaMai/Properties/AssemblyInfo.cs +++ b/AquaMai/Properties/AssemblyInfo.cs @@ -11,8 +11,9 @@ [assembly: AssemblyFileVersion(AquaMai.BuildInfo.Version)] [assembly: MelonInfo(typeof(AquaMai.AquaMai), AquaMai.BuildInfo.Name, AquaMai.BuildInfo.Version, AquaMai.BuildInfo.Author, AquaMai.BuildInfo.DownloadLink)] [assembly: MelonColor()] +[assembly: HarmonyDontPatchAll] // Create and Setup a MelonGame Attribute to mark a Melon as Universal or Compatible with specific Games. // If no MelonGame Attribute is found or any of the Values for any MelonGame Attribute on the Melon is null or empty it will be assumed the Melon is Universal. // Values for MelonGame Attribute can be found in the Game's app.info file or printed at the top of every log directly beneath the Unity version. -[assembly: MelonGame(null, null)] \ No newline at end of file +[assembly: MelonGame(null, null)]