Please tell any mod developers which still use this old version to update their mods.
HookGen "recipe" for Terraria, resulting in a TML mod that other mods can depend on.
Built with MonoMod.
This mod is a helper for other mods. Just install it if a mod needs it, it won't change Terraria on its own.
On.Terraria.Player.CheckMana += (orig, player, amount, pay, blockQuickMana) => {
// We can either make this act as a method replacement
// or just call our code around the original code.
// Let's double the mana cost of everything.
// We can pass on custom values.
bool spendable = orig(player, amount * 2, pay, blockQuickMana);
// ... but give back half of it if it was spent.
if (spendable && pay) {
player.statMana += amount / 2;
}
// We can return custom values.
return spendable;
}
For an extended example, take a look at this gist.
Use "hooks" to detect when a method runs, change how it runs or even replace it.
"Hooks" are automatically undone whenever your mod unloads. This is handled by TerrariaHooks for you.
Manipulate any method at runtime via IL... += (...) => {...} using Cecil and many helpers.
Special thanks to Chicken-Bones for the great ideas and feedback along the way!
Use RuntimeDetour to quickly port your existing "method swapping" code.
Note that this requires you to undo your detours on unload.
If you need more info, read the MonoMod RuntimeDetour README.
If you want to use TerrariaHooks in your mod:
TerrariaHooks.dll
from the latest release.lib
folder.build.txt
, add modReferences = TerrariaHooks
Load
method.git clone --recursive https://github.com/0x0ade/TerrariaHookGen.git
_input
./TerrariaHookGen/bin/Debug/TerrariaHookGen.exe _input .
./tModLoaderServer.exe -build 'path/to/TerrariaHooks' -eac
This repository overcomplicates the entire procedure. It boils down to:
./MonoMod.RuntimeDetour.HookGen.exe --private Terraria.exe TerrariaHooksPre.dll
./ILRepack.exe /out:TerrariaHooks.dll TerrariaHooksPre.dll MonoMod.*.dll MonoMod.exe
When running the above two lines in the Terraria directory (with all dependencies present), it generates TerrariaHooks.dll
for your Terraria.exe
.
The sole purpose of this repository is to automate the process entirely, and to allow publishing TerrariaHooks.dll
as a TML mod.