Skip to content

HookModule

UserR00T edited this page Aug 9, 2021 · 1 revision

HookModule

This module is used to inject a reference to your method from the target method. By decorating your method with the HookAttribute you will allow UniversalUnityHooks to inject your source method into the target method. This is useful for patching target methods and hooking into the method at various places. This is the most common usecase for UniversalUnityHooks.

Example

// Source (plugin)
[HookAttribute(typeof(ExampleType), "ExampleMethod")]
public static void HookedMethod(ExampleType exampleType, ref string str)
{
    Debug.Log($"This is the hooked method. str: {str}"); // Console.log for non Unity applications.
    str = "This is now a different string";
}

// Target _before_ injecting (Assembly-CSharp.dll)
public class ExampleType
{
    public void ExampleMethod(string str)
    {
        Debug.Log($"This the original method: {str}"); // Console.log for non Unity applications.
    }
}
// Output: ExampleMethod("some random string");
// This the original method: some random string

// Target _after_ injecting (Assembly-CSharp.dll)
public class ExampleType
{
    public void ExampleMethod(string str)
    {
        HookedType.HookedMethod(this, ref str);
        Debug.Log($"This the original method: {str}"); // Console.log for non Unity applications.
    }
}
// Output: ExampleMethod("some random string");
// This is the hooked method. str: some random string
// This the original method: This is now a different string

Attribute arguments

Name Description Default
FullPath
Type
Method
Flags
StartCode
Token
Direction
Clone this wiki locally