Skip to content
Lukas22041 edited this page Aug 30, 2026 · 3 revisions

Hooks are a type of patch that attaches to certain parts of an existing method. There are currently three types of hooks:

  • @Before: Run code before the original method call
  • @After: Run code after the original method call
  • @Except: Run code when the targeted method throws an exception

Each hook annotation has a target parameter that can have a method match assigned like target = @MethodMatch(methodName = "example"). You can find out more about each specific hook type on the wiki's sidebar.

Order

The hook annotations also have an optional order parameter. It is set to 0 if you do not explicitly set it. If multiple patches of the same hook type are applied to one method, they will execute in order.

A lower order value (i.e 0) will run before a higher one (i.e 100). If two patches have the same order, they are additionally sorted based on their mods' order, using the same alphabetical name sorting as the base game.

The order can sometimes be important, as a later patch may work with the modified arguments or return value that an earlier patch created. The order parameter can be any negative or positive integer value.

Context

Each hook has a specific type of context that has to be used for its patch handler:

  • @Before > BeforeContext
  • @After > AfterContext
  • @Except > ExceptContext

Every hook context has its own methods, but some are shared and available across all three of them.

  • Object getSelf(): Returns the instance of the object that the method is currently running on.
  • Object getArg(int index): Gets one of the passed-in method arguments.
  • void setArg(int index, Object newValue): Allows replacing a passed-in method argument, making other patches and the original method use the new value. Most relevant to @Before patches.
  • Object[] getArgs(): Gets a mutable array of all passed-in method parameters.
  • boolean isSkipOriginal();: Checks if an @Before patch has skipped the original method's code.
  • getLocal(String key) / setLocal(String key, Object value): Allows storing a value for a single method execution, useful for passing data to another patch that targets the same method.
  • boolean isMostDerivedCall(): Checks whether the method that is executing the patch is the most-derived version possible. See Handling super calls for more information.
  • All other methods that are available across all patch types, i.e. getData() and the reflection utilities.

Clone this wiki locally