### Boxed Value Handling Example Source: https://harmony.pardeike.net/api/HarmonyLib.MethodInvoker.html An example demonstrating how boxed value types are passed to a fast invocation handler. ```csharp var val = 5; var box = (object)val; var arr = new object[] { box }; handler(arr); // for a method with parameter signature: ref/out/in int ``` -------------------------------- ### Start Method Source: https://harmony.pardeike.net/api/HarmonyLib.CodeMatcher.html Resets the current position of the matcher to the beginning. ```csharp public CodeMatcher Start() ``` -------------------------------- ### FileLog Environment Configuration Source: https://harmony.pardeike.net/articles/utilities.html Example usage of environment variables to configure logging behavior. ```bash # Disable logging export HARMONY_NO_LOG=1 # Or specify a custom log file path export HARMONY_LOG_FILE=/path/to/custom/harmony.log.txt ``` -------------------------------- ### Patching with Harmony Annotations Source: https://harmony.pardeike.net/articles/intro.html Applies patches to the original game code using Harmony annotations. Ensure DoPatching() is called at the start. This example modifies the 'isRunning' field and the 'counter' variable, and doubles the result. ```csharp // your code, most likely in your own dll using HarmonyLib; using Intro_SomeGame; public class MyPatcher { // make sure DoPatching() is called at start either by // the mod loader or by your injector public static void DoPatching() { var harmony = new Harmony("com.example.patch"); harmony.PatchAll(); } } [HarmonyPatch(typeof(SomeGameClass))] [HarmonyPatch("DoSomething")] // if possible use nameof() here class Patch01 { static AccessTools.FieldRef isRunningRef = AccessTools.FieldRefAccess("isRunning"); static bool Prefix(SomeGameClass __instance, ref int ___counter) { isRunningRef(__instance) = true; if (___counter > 100) return false; ___counter = 0; return true; } static void Postfix(ref int __result) => __result *= 2; } ``` -------------------------------- ### Implement a Typical Transpiler Source: https://harmony.pardeike.net/articles/patching-transpiler.html An example of a transpiler that iterates through instructions to find a specific field store operation and injects a method call before it. ```csharp static FieldInfo f_someField = AccessTools.Field(typeof(SomeType), nameof(SomeType.someField)); static MethodInfo m_MyExtraMethod = SymbolExtensions.GetMethodInfo(() => Tools.MyExtraMethod()); // looks for STDFLD someField and inserts CALL MyExtraMethod before it static IEnumerable Transpiler(IEnumerable instructions) { var found = false; foreach (var instruction in instructions) { if (instruction.StoresField(f_someField)) { yield return new CodeInstruction(OpCodes.Call, m_MyExtraMethod); found = true; } yield return instruction; } if (found is false) ReportError("Cannot find in OriginalType.OriginalMethod"); } ``` -------------------------------- ### TryGetSwitch Source: https://harmony.pardeike.net/api/HarmonyLib.Harmony.html Tries to get a MonoMod switch value. ```APIDOC ## GET /api/harmony/TryGetSwitch ### Description Tries to get a MonoMod switch value. ### Method GET ### Endpoint /api/harmony/TryGetSwitch #### Query Parameters - **name** (string) - Required - The switch name. ### Response #### Success Response (200) - **value** (object) - The switch value if found. - **found** (bool) - True if the switch was found, false otherwise. ``` -------------------------------- ### Constructor Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for a constructor by searching the type and all its super types. ```APIDOC ## Constructor(Type, Type[], bool) ### Description Gets the reflection information for a constructor by searching the type and all its super types. ### Parameters - **type** (Type) - Required - The class/type where the constructor is declared - **parameters** (Type[]) - Optional - Optional parameters to target a specific overload of the method - **searchForStatic** (bool) - Optional - Optional parameters to only consider static constructors ### Returns - **ConstructorInfo** - A constructor info or null when type is null or when the method cannot be found ``` -------------------------------- ### Harmony Patch Execution Flow Example Source: https://harmony.pardeike.net/articles/execution.html Illustrates the execution order of Prefix, Original, and Postfix patches. Prefixes can conditionally skip the original method's execution. ```csharp static R ReplacementMethod(T optionalThisArgument, params object[] arguments) { R result = default; var run = true; // Harmony separates all Prefix patches into those that change the // original methods result/execution and those who have no side efects // Lets call all prefixes with no side effect "SimplePrefix" and add // a number to them that indicates their sort order after applying // priorities to them: SimplePrefix1(arguments); if (run) run = Prefix2(); SimplePrefix3(arguments); SimplePrefix4(arguments); if (run) Prefix5(ref someArgument, ref result); // ... if (run) result = ModifiedOriginal(arguments); Postfix1(ref result); result = Postfix2(result, arguments); Postfix3(); // ... return result; } ``` -------------------------------- ### Get Method by Module and Token Source: https://harmony.pardeike.net/api/HarmonyLib.AccessTools.html Finds a System.Reflection.MethodInfo using its module ID and token. This is an advanced method for precise method identification. ```csharp public static MethodInfo GetMethodByModuleAndToken(string moduleGUID, int token) ``` -------------------------------- ### GetDeclaredFields Source: https://harmony.pardeike.net/api/HarmonyLib.AccessTools.html Gets reflection information for all declared fields. ```APIDOC ## GetDeclaredFields ### Description Gets reflection information for all declared fields. ### Method `public static List GetDeclaredFields(Type type)` ### Parameters #### Path Parameters - **type** (Type) - Required - The class/type where the fields are declared ### Returns #### Success Response (200) - **List** - A list of field infos ``` -------------------------------- ### Do Source: https://harmony.pardeike.net/api/HarmonyLib.CodeMatcher.html Executes an action on the current CodeMatcher instance. ```APIDOC ## Do(Action) ### Description Runs some code when chaining CodeMatcher at the current position. ### Parameters #### Path Parameters - **action** (Action) - Required - The System.Action to run ### Response - **CodeMatcher** - The same code matcher ``` -------------------------------- ### Constructor IL Representation Source: https://harmony.pardeike.net/articles/patching-edgecases.html Example of the IL instruction used for object instantiation, which explains why constructor return types cannot be modified. ```il newobj instance void Test::.ctor(); ``` -------------------------------- ### GetDeclaredConstructors Source: https://harmony.pardeike.net/api/HarmonyLib.AccessTools.html Gets reflection information for all declared constructors. ```APIDOC ## GetDeclaredConstructors ### Description Gets reflection information for all declared constructors. ### Method `public static List GetDeclaredConstructors(Type type, bool? searchForStatic = null)` ### Parameters #### Path Parameters - **type** (Type) - Required - The class/type where the constructors are declared - **searchForStatic** (bool?) - Optional - Optional parameters to only consider static constructors ### Returns #### Success Response (200) - **List** - A list of constructor infos ``` -------------------------------- ### Finalizer(Type) Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for a finalizer. ```APIDOC ## Finalizer(Type) ### Description Gets the reflection information for a finalizer. ### Method static MethodInfo ### Parameters #### Path Parameters - **type** (Type) - Required - The class/type that defines the finalizer ### Returns #### Success Response (200) - **MethodInfo** (MethodInfo) - A method or null when type is null or when the finalizer cannot be found ``` -------------------------------- ### Create Call Instructions Source: https://harmony.pardeike.net/api/HarmonyLib.CodeInstruction.html Static factory methods to generate CALL instructions using expressions, strings, or types. ```csharp public static CodeInstruction Call(Expression expression) ``` ```csharp public static CodeInstruction Call(LambdaExpression expression) ``` ```csharp public static CodeInstruction Call(string typeColonMethodname, Type[] parameters = null, Type[] generics = null) ``` ```csharp public static CodeInstruction Call(Type type, string name, Type[] parameters = null, Type[] generics = null) ``` ```csharp public static CodeInstruction CallClosure(T closure) where T : Delegate ``` ```csharp public static CodeInstruction Call(Expression> expression) ``` ```csharp public static CodeInstruction Call(Expression>) ``` -------------------------------- ### Traverse Usage Example Source: https://harmony.pardeike.net/articles/utilities.html Demonstrates accessing private members of a class hierarchy using the Traverse utility. ```csharp class Foo { struct Bar { static string secret = "hello"; public string ModifiedSecret() => secret.ToUpper(); } Bar MyBar { get { return new Bar(); } } public string GetSecret() => MyBar.ModifiedSecret(); Foo() { } static Foo MakeFoo() => new(); } void Test() { var foo = Traverse.Create().Method("MakeFoo").GetValue(); Traverse.Create(foo).Property("MyBar").Field("secret").SetValue("world"); Console.WriteLine(foo.GetSecret()); // outputs WORLD } ``` -------------------------------- ### InsertAfter Methods Source: https://harmony.pardeike.net/api/HarmonyLib.CodeMatcher.html Inserts instructions immediately after the current position. ```csharp public CodeMatcher InsertAfter(params CodeInstruction[] instructions) ``` ```csharp public CodeMatcher InsertAfter(IEnumerable instructions) ``` -------------------------------- ### DeclaredProperty Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for a directly declared property. ```APIDOC ## DeclaredProperty(Type, string) ### Description Gets the reflection information for a directly declared property. ### Method `public static PropertyInfo DeclaredProperty(this Type type, string name)` ### Parameters #### Path Parameters - **type** (Type) - Required - The class/type where the property is declared - **name** (string) - Required - The name of the property (case sensitive) ### Returns #### Success Response (200) - **PropertyInfo** (PropertyInfo) - A property or null when type/name is null or when the property cannot be found ``` -------------------------------- ### DeclaredMethod Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for a directly declared method. ```APIDOC ## DeclaredMethod(Type, string, Type[], Type[]) ### Description Gets the reflection information for a directly declared method. ### Method `public static MethodInfo DeclaredMethod(this Type type, string name, Type[] parameters = null, Type[] generics = null)` ### Parameters #### Path Parameters - **type** (Type) - Required - The class/type where the method is declared - **name** (string) - Required - The name of the method (case sensitive) - **parameters** (Type[]) - Optional - Optional parameters to target a specific overload of the method - **generics** (Type[]) - Optional - Optional list of types that define the generic version of the method ### Returns #### Success Response (200) - **MethodInfo** (MethodInfo) - A method or null when type/name is null or when the method cannot be found ``` -------------------------------- ### GetInstructions Method Source: https://harmony.pardeike.net/api/HarmonyLib.HarmonyException.html Retrieves a list of IL instructions without their associated offsets. ```csharp public List GetInstructions() ``` -------------------------------- ### DeclaredFinalizer Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for a directly declared finalizer. ```APIDOC ## DeclaredFinalizer(Type) ### Description Gets the reflection information for a directly declared finalizer. ### Parameters - **type** (Type) - Required - The class/type that defines the finalizer ### Returns - **MethodInfo** - A method or null when type is null or when the finalizer cannot be found ``` -------------------------------- ### Do Method Source: https://harmony.pardeike.net/api/HarmonyLib.CodeMatcher.html Executes an action on the current CodeMatcher instance. ```csharp public CodeMatcher Do(Action action) ``` -------------------------------- ### EventAdder Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for the add method of an event by searching the type and all its super types. ```APIDOC ## EventAdder(Type, string) ### Description Gets the reflection information for the add method of an event by searching the type and all its super types. ### Method `public static MethodInfo EventAdder(this Type type, string name)` ### Parameters #### Path Parameters - **type** (Type) - Required - The class/type - **name** (string) - Required - The name ### Returns #### Success Response (200) - **MethodInfo** (MethodInfo) - A method or null when type/name is null or when the event cannot be found ``` -------------------------------- ### DeclaredField Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for a field by index or name. ```APIDOC ## DeclaredField(Type, int) ### Description Gets the reflection information for a field by index. ### Parameters - **type** (Type) - Required - The class/type where the field is declared - **idx** (int) - Required - The zero-based index of the field inside the class definition ### Returns - **FieldInfo** - A field or null when type is null or when the field cannot be found ## DeclaredField(Type, string) ### Description Gets the reflection information for a directly declared field by name. ### Parameters - **type** (Type) - Required - The class/type where the field is defined - **name** (string) - Required - The name of the field ### Returns - **FieldInfo** - A field or null when type/name is null or when the field cannot be found ``` -------------------------------- ### Using HarmonyLib Code for CIL Instructions Source: https://harmony.pardeike.net/api/HarmonyLib.Code.html Demonstrates how to use the HarmonyLib Code class for generating CIL instructions. Add the 'using static HarmonyLib.Code;' statement to use shorthand like 'Ldarg_1' instead of 'new CodeMatch(OpCodes.Ldarg_1)'. ```csharp using static HarmonyLib.Code; // Example usage: // Instead of: new CodeMatch(OpCodes.Ldarg_1) var instruction = Ldarg_1; // Instead of: new CodeMatch(OpCodes.Call, myMethodInfo) var callInstruction = Call[myMethodInfo]; ``` -------------------------------- ### DeclaredEvent Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for a directly declared event. ```APIDOC ## DeclaredEvent(Type, string) ### Description Gets the reflection information for a directly declared event. ### Parameters - **type** (Type) - Required - The class/type where the event is declared - **name** (string) - Required - The name of the event (case sensitive) ### Returns - **EventInfo** - An event or null when type/name is null or when the event cannot be found ``` -------------------------------- ### Prepare Method for Patching Source: https://harmony.pardeike.net/articles/patching-auxiliary.html Implement the Prepare method to control patching execution. Returning false skips patching for the class. It's called twice: once before patching starts (original is null) and once for each method being patched. ```csharp static void Prepare(...) static void Prepare(MethodBase original, ...) static bool Prepare(MethodBase original, ...) ``` ```csharp [HarmonyPrepare] static void MyInitializer(...) static void MyInitializer(MethodBase original, ...) static bool MyInitializer(MethodBase original, ...) ``` -------------------------------- ### DeclaredConstructor Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for a directly declared constructor. ```APIDOC ## DeclaredConstructor(Type, Type[], bool) ### Description Gets the reflection information for a directly declared constructor. ### Parameters - **type** (Type) - Required - The class/type where the constructor is declared - **parameters** (Type[]) - Optional - Optional parameters to target a specific overload of the constructor - **searchForStatic** (bool) - Optional - Optional parameters to only consider static constructors ### Returns - **ConstructorInfo** - A constructor info or null when type is null or when the constructor cannot be found ``` -------------------------------- ### InstructionsInRange Source: https://harmony.pardeike.net/api/HarmonyLib.CodeMatcher.html Retrieves a list of instructions within a specified index range. ```APIDOC ## InstructionsInRange ### Description Gets all instructions within a range. ### Parameters #### Query Parameters - **start** (int) - Required - The start index. - **end** (int) - Required - The end index. ### Response - **Returns** (List) - A list of instructions. ``` -------------------------------- ### GetInstructionsWithOffsets Method Source: https://harmony.pardeike.net/api/HarmonyLib.HarmonyException.html Retrieves a list of IL instructions paired with their respective offsets. ```csharp public List> GetInstructionsWithOffsets() ``` -------------------------------- ### GetPatchInfo Source: https://harmony.pardeike.net/api/HarmonyLib.PatchProcessor.html Gets patch information for a specific original method. ```APIDOC ## GetPatchInfo(MethodBase) ### Description Gets patch information on an original. ### Parameters #### Method Parameters - **method** (MethodBase) - Required - The original method/constructor ### Response - **Patches** - The patch information as Patches ``` -------------------------------- ### CreateProcessor Method Source: https://harmony.pardeike.net/api/HarmonyLib.Harmony.html Creates an empty patch processor for an original method. Use this to manually build patch instructions. ```csharp public PatchProcessor CreateProcessor(MethodBase original) ``` -------------------------------- ### Get Property Names Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Retrieves the names of all properties declared in a type. ```csharp public static List GetPropertyNames(this Type type) ``` -------------------------------- ### Import Harmony Library Source: https://harmony.pardeike.net/articles/basics.html Add this using statement to access Harmony API features and enable code completion. ```csharp using HarmonyLib; ``` -------------------------------- ### Get Method Names Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Retrieves the names of all methods declared in a type. ```csharp public static List GetMethodNames(this Type type) ``` -------------------------------- ### HarmonyBefore Constructor Source: https://harmony.pardeike.net/api/HarmonyLib.HarmonyBefore.html The constructor takes an array of strings, where each string is the harmony ID of a patch that this patch should precede. This defines the execution order. ```csharp public HarmonyBefore(params string[] before) ``` -------------------------------- ### Get Field Names Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Retrieves the names of all fields declared in a type. ```csharp public static List GetFieldNames(this Type type) ``` -------------------------------- ### Creating CodeInstruction with operand and name Source: https://harmony.pardeike.net/api/HarmonyLib.html Demonstrates using array notation with static imports to specify an operand and name for a CodeInstruction. This is a shorthand for `new CodeMatch(OpCodes.Call, myMethodInfo)`. ```csharp Call[myMethodInfo] ``` -------------------------------- ### Get Default Value Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Retrieves the default value for a specific type. ```csharp public static object GetDefaultValue(this Type type) ``` -------------------------------- ### Get Declared Properties Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Retrieves reflection information for all declared properties. ```csharp public static List GetDeclaredProperties(this Type type) ``` -------------------------------- ### Insert Methods Source: https://harmony.pardeike.net/api/HarmonyLib.CodeMatcher.html Inserts instructions at the current position using either params or IEnumerable. ```csharp public CodeMatcher Insert(params CodeInstruction[] instructions) ``` ```csharp public CodeMatcher Insert(IEnumerable instructions) ``` -------------------------------- ### HarmonyTargetMethod Constructor Source: https://harmony.pardeike.net/api/HarmonyLib.HarmonyTargetMethod.html Initializes a new instance of the HarmonyTargetMethod attribute. No specific setup or parameters are required for its basic usage. ```csharp public HarmonyTargetMethod() ``` -------------------------------- ### Get Declared Methods Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Retrieves reflection information for all declared methods. ```csharp public static List GetDeclaredMethods(this Type type) ``` -------------------------------- ### Initialize HarmonyPrefix Constructor Source: https://harmony.pardeike.net/api/HarmonyLib.HarmonyPrefix.html Constructor for the HarmonyPrefix attribute. ```csharp public HarmonyPrefix() ``` -------------------------------- ### Get Declared Fields Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Retrieves reflection information for all declared fields. ```csharp public static List GetDeclaredFields(this Type type) ``` -------------------------------- ### InsertAfter Source: https://harmony.pardeike.net/api/HarmonyLib.CodeMatcher.html Inserts instructions immediately after the current position. ```APIDOC ## InsertAfter(params CodeInstruction[]) ### Description Inserts instructions immediately after the current position. ### Parameters #### Path Parameters - **instructions** (CodeInstruction[]) - Required - The instructions ### Response - **CodeMatcher** - The same code matcher ``` -------------------------------- ### DeclaredIndexer Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for a directly declared indexer property. ```APIDOC ## DeclaredIndexer(Type, Type[]) ### Description Gets the reflection information for a directly declared indexer property. ### Method `public static PropertyInfo DeclaredIndexer(this Type type, Type[] parameters = null)` ### Parameters #### Path Parameters - **type** (Type) - Required - The class/type where the indexer property is declared - **parameters** (Type[]) - Optional - Optional parameters to target a specific overload of multiple indexers ### Returns #### Success Response (200) - **PropertyInfo** (PropertyInfo) - An indexer property or null when type is null or when it cannot be found ``` -------------------------------- ### CodeMatch Constructors Source: https://harmony.pardeike.net/api/HarmonyLib.CodeMatch.html Details the different ways to create a CodeMatch instance, allowing for matching based on specific instructions, predicates, expressions, or opcode/operand combinations. ```APIDOC ## CodeMatch Constructors ### CodeMatch(CodeInstruction, string) Creates a code match. #### Parameters - **instruction** (CodeInstruction) - Required - The CodeInstruction. - **name** (string) - Optional - An optional name. ### CodeMatch(Func, string) Creates a code match. #### Parameters - **predicate** (Func) - Required - The predicate. - **name** (string) - Optional - An optional name. ### CodeMatch(Expression, string) Creates a code match that calls a method. #### Parameters - **expression** (Expression) - Required - The lambda expression using the method. - **name** (string) - Optional - The optional name. ### CodeMatch(LambdaExpression, string) Creates a code match that calls a method. #### Parameters - **expression** (LambdaExpression) - Required - The lambda expression using the method. - **name** (string) - Optional - The optional name. ### CodeMatch(OpCode?, object, string) Creates a code match. #### Parameters - **opcode** (OpCode?) - Optional - The optional opcode. - **operand** (object) - Optional - The optional operand. - **name** (string) - Optional - The optional name. ``` -------------------------------- ### GetMethodInfo from LambdaExpression Source: https://harmony.pardeike.net/api/HarmonyLib.SymbolExtensions.html Use this method to get MethodInfo from a generic LambdaExpression. ```csharp public static MethodInfo GetMethodInfo(LambdaExpression expression) ``` -------------------------------- ### FileLog Method Declarations Source: https://harmony.pardeike.net/api/HarmonyLib.FileLog.html Methods for logging, buffer management, and IL instruction tracking. ```csharp public static void ChangeIndent(int delta) ``` ```csharp public static void Debug(string str) ``` ```csharp public static void FlushBuffer() ``` ```csharp public static List GetBuffer(bool clear) ``` ```csharp public static void Log(string str) ``` ```csharp public static void LogBuffered(List strings) ``` ```csharp public static void LogBuffered(string str) ``` ```csharp public static void LogBytes(long ptr, int len) ``` ```csharp public static void LogIL(int codePos, Label label) ``` ```csharp public static void LogIL(int codePos, OpCode opcode) ``` ```csharp public static void LogIL(int codePos, OpCode opcode, object arg) ``` -------------------------------- ### CodeMatcher Constructors Source: https://harmony.pardeike.net/api/HarmonyLib.CodeMatcher.html Methods to initialize a new CodeMatcher instance. ```APIDOC ## Constructor CodeMatcher() ### Description Creates an empty code matcher. ## Constructor CodeMatcher(IEnumerable, ILGenerator) ### Description Creates a code matcher from an enumeration of instructions. ### Parameters - **instructions** (IEnumerable) - Required - The instructions (transpiler argument) - **generator** (ILGenerator) - Optional - An optional IL generator ``` -------------------------------- ### Category Property Source: https://harmony.pardeike.net/api/HarmonyLib.PatchClassProcessor.html Gets or sets the category name for the patch class. ```csharp public string Category { get; set; } ``` -------------------------------- ### Creating CodeInstruction with operand Source: https://harmony.pardeike.net/api/HarmonyLib.html Shows how to use array notation with static imports to specify an operand for a CodeInstruction. This is a shorthand for `new CodeMatch(OpCodes.Ldarg_1)`. ```csharp Ldarg_1 ``` -------------------------------- ### Property Reflection Source: https://harmony.pardeike.net/api/HarmonyLib.AccessTools.html Methods to get reflection information for property getters and setters. ```APIDOC ## DeclaredPropertyGetter(string) ### Description Gets the reflection information for the getter method of a directly declared property. ### Method GET ### Endpoint N/A (Static method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **MethodInfo** (MethodInfo) - A method or null when the property cannot be found. #### Response Example ```json { "example": "MethodInfo object or null" } ``` ## DeclaredPropertyGetter(Type, string) ### Description Gets the reflection information for the getter method of a directly declared property. ### Method GET ### Endpoint N/A (Static method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **MethodInfo** (MethodInfo) - A method or null when type/name is null or when the property cannot be found. #### Response Example ```json { "example": "MethodInfo object or null" } ``` ## DeclaredPropertySetter(string) ### Description Gets the reflection information for the Setter method of a directly declared property. ### Method GET ### Endpoint N/A (Static method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **MethodInfo** (MethodInfo) - A method or null when the property cannot be found. #### Response Example ```json { "example": "MethodInfo object or null" } ``` ## DeclaredPropertySetter(Type, string) ### Description Gets the reflection information for the setter method of a directly declared property. ### Method GET ### Endpoint N/A (Static method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **MethodInfo** (MethodInfo) - A method or null when type/name is null or when the property cannot be found. #### Response Example ```json { "example": "MethodInfo object or null" } ``` ``` -------------------------------- ### Unity MissingMethodException Example Source: https://harmony.pardeike.net/articles/patching-edgecases.html Patching methods that call external Unity methods too early can cause MissingMethodException. Ensure Unity has finished startup before patching. ```csharp class SomeGameObject { GameObject gameObject; void SomeMethod() => UnityEngine.Object.DontDestroyOnLoad(gameObject); void SomeOtherMethod() => SomeMethod(); } ``` -------------------------------- ### Delayed Patching in Unity using SceneManager Source: https://harmony.pardeike.net/articles/patching-edgecases.html This example demonstrates how to delay Harmony patching until after Unity has loaded the first scene, preventing MissingMethodException. ```csharp public static class Patcher { private static bool patched = false; public static void Main() => //DoPatch(); <-- Do not execute patching on assembly entry point SceneManager.sceneLoaded += SceneLoaded; private static void DoPatch() { var harmony = new Harmony("test"); harmony.PatchAll(); patched = true; } private static void SceneLoaded(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode loadSceneMode) { // Execute patching after unity has finished it's startup and loaded at least the first game scene if (!patched) DoPatch(); } } ``` -------------------------------- ### Member and Instance Utilities Source: https://harmony.pardeike.net/api/HarmonyLib.AccessTools.html Methods for inspecting members and testing instance properties. ```APIDOC ## IsDeclaredMember(T) ### Description Test if a class member is actually a concrete implementation. ### Parameters #### Path Parameters - **member** (T) - Required - A member ### Response #### Success Response (200) - **bool** - True if the member is a declared ## IsOfNullableType(T) ### Description Test whether an instance is of a nullable type. ### Parameters #### Path Parameters - **instance** (T) - Required - An instance to test ### Response #### Success Response (200) - **bool** - True if instance is of nullable type, false if not ## IsStatic(MemberInfo) ### Description Tests whether a type or member is static, as defined in C#. ### Parameters #### Path Parameters - **member** (MemberInfo) - Required - The type or member ### Response #### Success Response (200) - **bool** - True if the type or member is static ``` -------------------------------- ### Get Finalizer Method Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Retrieves the reflection information for the finalizer of a given type. ```csharp public static MethodInfo Finalizer(this Type type) ``` -------------------------------- ### Construct CodeInstruction Source: https://harmony.pardeike.net/api/HarmonyLib.CodeInstruction.html Constructors for creating new instruction instances or copying existing ones. ```csharp public CodeInstruction(CodeInstruction instruction) ``` ```csharp public CodeInstruction(OpCode opcode, object operand = null) ``` -------------------------------- ### Event Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for an event by searching the type and all its super types. ```APIDOC ## Event(Type, string) ### Description Gets the reflection information for an event by searching the type and all its super types. ### Method `public static EventInfo Event(this Type type, string name)` ### Parameters #### Path Parameters - **type** (Type) - Required - The class/type - **name** (string) - Required - The name ### Returns #### Success Response (200) - **EventInfo** (EventInfo) - An event or null when type/name is null or when the event cannot be found ``` -------------------------------- ### DeclaredPropertySetter Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for the setter method of a directly declared property. ```APIDOC ## DeclaredPropertySetter(Type, string) ### Description Gets the reflection information for the setter method of a directly declared property. ### Method `public static MethodInfo DeclaredPropertySetter(this Type type, string name)` ### Parameters #### Path Parameters - **type** (Type) - Required - The class/type where the property is declared - **name** (string) - Required - The name of the property (case sensitive) ### Returns #### Success Response (200) - **MethodInfo** (MethodInfo) - A method or null when type/name is null or when the property cannot be found ``` -------------------------------- ### Find Method Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Returns the first method matching a predicate. ```csharp public static MethodInfo FirstMethod(this Type type, Func predicate) ``` -------------------------------- ### CreateInstance Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Creates an (possibly uninitialized) instance of a given type. ```APIDOC ## CreateInstance(Type) ### Description Creates an (possibly uninitialized) instance of a given type. ### Parameters - **type** (Type) - Required - The class/type ### Returns - **object** - The new instance ``` -------------------------------- ### DeclaredPropertyGetter Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for the getter method of a directly declared property. ```APIDOC ## DeclaredPropertyGetter(Type, string) ### Description Gets the reflection information for the getter method of a directly declared property. ### Method `public static MethodInfo DeclaredPropertyGetter(this Type type, string name)` ### Parameters #### Path Parameters - **type** (Type) - Required - The class/type where the property is declared - **name** (string) - Required - The name of the property (case sensitive) ### Returns #### Success Response (200) - **MethodInfo** (MethodInfo) - A method or null when type/name is null or when the property cannot be found ``` -------------------------------- ### Patch Factory Methods for Manual Patching Source: https://harmony.pardeike.net/articles/patching.html When using manual patching, factory methods can return `MethodInfo` or `DynamicMethod` instances. These methods, marked with attributes like `[HarmonyPrefix]`, allow for more control over patch creation. ```csharp [HarmonyPatch(...)] class Patch { // the return type of factory methods can be either MethodInfo or DynamicMethod [HarmonyPrefix] static MethodInfo PrefixFactory(MethodBase originalMethod) { // return an instance of MethodInfo or an instance of DynamicMethod } [HarmonyPostfix] static MethodInfo PostfixFactory(MethodBase originalMethod) { // return an instance of MethodInfo or an instance of DynamicMethod } } ``` -------------------------------- ### Get Event Reflection Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Retrieves EventInfo for an event by searching the type and its hierarchy. ```csharp public static EventInfo Event(this Type type, string name) ``` -------------------------------- ### Declare Initblk Source: https://harmony.pardeike.net/api/HarmonyLib.Code.html Represents a block initialization operation. ```csharp public static Code.Initblk_ Initblk { get; } ``` -------------------------------- ### DeclaredEventRemover Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for the remove method of a directly declared event. ```APIDOC ## DeclaredEventRemover(Type, string) ### Description Gets the reflection information for the remove method of a directly declared event. ### Parameters - **type** (Type) - Required - The class/type where the event is declared - **name** (string) - Required - The name of the event (case sensitive) ### Returns - **MethodInfo** - A method or null when type/name is null or when the event cannot be found ``` -------------------------------- ### DeclaredEventAdder Source: https://harmony.pardeike.net/api/HarmonyLib.AccessToolsExtensions.html Gets the reflection information for the add method of a directly declared event. ```APIDOC ## DeclaredEventAdder(Type, string) ### Description Gets the reflection information for the add method of a directly declared event. ### Parameters - **type** (Type) - Required - The class/type where the event is declared - **name** (string) - Required - The name of the event (case sensitive) ### Returns - **MethodInfo** - A method or null when type/name is null or when the event cannot be found ``` -------------------------------- ### CodeMatcher Navigation and Manipulation Source: https://harmony.pardeike.net/api/HarmonyLib.CodeMatcher.html Methods for advancing position, cloning, and managing labels within the instruction sequence. ```APIDOC ## Method Advance(int) ### Description Advances the current position by the specified offset. ### Parameters - **offset** (int) - Optional - The offset (default: 1) ## Method Clone() ### Description Makes a clone of this instruction matcher. ## Method AddLabels(IEnumerable