Hook Annotations
Special keywords that you can use to change or extend the behavior of existing methods and classes in the base game.
Hook annotations allow you to hook into the game functions, monitor or change how they behave and add your own functionality.
If you want to see how to create a hook, check following guide:
How to create a hookIf you don't know what to hook see:
Things to hookAnnotations can't be used on modded methods or classes and native functions (those are marked as native and defined outside of scripts).
@wrapMethod(class)
Hooks into an existing method with the same name and parameters on a specified class.
Your function will execute instead of the original method whenever it is invoked, but you can still access the underlying method by using the wrappedMethod(…) identifier. You would typically invoke the wrapped method in your newly defined function and forward all the arguments unchanged to preserve it's original behavior, but you can also modify the arguments or the final return value if you wish.
Furthermore, this annotation can be applied multiple times to chain multiple functions that modify the same method. Each function in the chain wraps around the previous one. This helps to keep mods compatible even if they alter the same methods. For example, multiple mods can use this annotation to append new buttons to the main menu:
@wrapMethod(SingleplayerMenuGameController)
private func PopulateMenuItemList() {
wrappedMethod(); // This will call the original PopulateMenuItemList
this.AddMenuItem("BUTTON 1", n"OnDebug");
}
// You can use this annotation to chain multiple functions
@wrapMethod(SingleplayerMenuGameController)
private func PopulateMenuItemList() {
wrappedMethod(); // This will run the previous function with this annotation
this.AddMenuItem("BUTTON 2", n"OnDebug");
}
// The result will be two new buttons added to the main menu@addMethod(class)
Creates a new method and adds it to an existing class.
For example, you can write a new method to disassemble all junk items in your backpack and add it to the BackpackMainGameController class:
@replaceMethod(class)
Completely replaces the original method with your own.
If possible you should prefer to use @wrapMethod(class) for compatibility.
You can only use one @replaceMethod for each method. If you define more than one, only one of them will work. If you want to combine multiple changes to the same method, you should use the @wrapMethod annotation instead.
@replaceGlobal()
Completely replaces the original global function with your own.
@addField(class)
Creates a new field and adds it to an existing class. For example, you can add a dummy field of type Int32 to the PlayerPuppet class:
Last updated