Home

Awesome

OBSOLETE

tModLoader 0.11+ includes its own version of TerrariaHooks / MonoMod.

Please tell any mod developers which still use this old version to update their mods.

TerrariaHooks

License: MIT


HookGen "recipe" for Terraria, resulting in a TML mod that other mods can depend on.

Built with MonoMod.

Features

For Players

This mod is a helper for other mods. Just install it if a mod needs it, it won't change Terraria on its own.

For Modders

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.

If you need more info, read the MonoMod RuntimeDetour README.

Instructions

If you want to use TerrariaHooks in your mod:

Building TerrariaHooks yourself

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.