question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TerrariaHooks should be generated from tModLoader, rather than vanilla

See original GitHub issue

As far as I can tell by looking at the code for the setup tool, right now the TerrariaHooks.dll included in tModLoader is generated from the vanilla version of Terraria.exe.

This can lead to problems with methods, who’s signature is changed by tModLoader. For Instance:

https://github.com/tModLoader/tModLoader/blob/8415545c33ac7f4aad4530d684decbf868ee88fb/patches/tModLoader/Terraria/Chest.cs.patch#L44-L45

The generated “On” hook looks like this:

.event On.Terraria.Chest/hook_AddShop AddShop
{
	.addon void On.Terraria.Chest::add_AddShop(class On.Terraria.Chest/hook_AddShop)
	.removeon void On.Terraria.Chest::remove_AddShop(class On.Terraria.Chest/hook_AddShop)
}

.method public hidebysig specialname static 
	void add_AddShop (
		class On.Terraria.Chest/hook_AddShop ''
	) cil managed 
{
	// Header Size: 1 byte
	// Code Size: 17 (0x11) bytes
	.maxstack 8

	/* 0x0002C615 D0E509000A   */ IL_0000: ldtoken   method instance void [Terraria]Terraria.Chest::AddShop(class [Terraria]Terraria.Item)
	/* 0x0002C61A 280200000A   */ IL_0005: call      class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
	/* 0x0002C61F 02           */ IL_000A: ldarg.0
	/* 0x0002C620 285327002B   */ IL_000B: call      void [MonoMod.RuntimeDetour]MonoMod.RuntimeDetour.HookGen.HookEndpointManager::Add<class On.Terraria.Chest/hook_AddShop>(class [mscorlib]System.Reflection.MethodBase, class [mscorlib]System.Delegate)
	/* 0x0002C625 2A           */ IL_0010: ret
} // end of method Chest::add_AddShop

.method public hidebysig specialname static 
	void remove_AddShop (
		class On.Terraria.Chest/hook_AddShop ''
	) cil managed 
{
	// Header Size: 1 byte
	// Code Size: 17 (0x11) bytes
	.maxstack 8

	/* 0x0002C627 D0E509000A   */ IL_0000: ldtoken   method instance void [Terraria]Terraria.Chest::AddShop(class [Terraria]Terraria.Item)
	/* 0x0002C62C 280200000A   */ IL_0005: call      class [mscorlib]System.Reflection.MethodBase [mscorlib]System.Reflection.MethodBase::GetMethodFromHandle(valuetype [mscorlib]System.RuntimeMethodHandle)
	/* 0x0002C631 02           */ IL_000A: ldarg.0
	/* 0x0002C632 285427002B   */ IL_000B: call      void [MonoMod.RuntimeDetour]MonoMod.RuntimeDetour.HookGen.HookEndpointManager::Remove<class On.Terraria.Chest/hook_AddShop>(class [mscorlib]System.Reflection.MethodBase, class [mscorlib]System.Delegate)
	/* 0x0002C637 2A           */ IL_0010: ret
} // end of method Chest::remove_AddShop

Trying to use this will immediately trigger a System.MissingMethodException, since method instance void [Terraria]Terraria.Chest::AddShop(class [Terraria]Terraria.Item) does not actually exist anymore.

I’m not entirely sure how many methods this actually affects. There might not be too many, but it would be nice to have this sorted out.

I’m guessing hooks are generated this way to stop hooks from being made for internal tModLoader stuff? If that is the case, it shouldn’t be too hard to just modify HookGen to ignore certain namespaces.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DRKV333commented, Dec 24, 2019

If the HookGen was set up to ignore tModLoader specific namespaces, it would only need to be run when a vanilla method got changed. Which I’d imagine does not happen too frequently.

As for the automatic approach, It might be possible to create the hooks during the build, with something like Fody.

0reactions
Chicken-Bonescommented, Dec 24, 2019

Done be2c20251757ce5bf956d3853ebfafbe3e419eb6

Read more comments on GitHub >

github_iconTop Results From Across the Web

tModLoader - HELP: question about modded/vanilla worlds ...
Yes, you can. In your tModLoader Worlds folder (Documents/My Games/Terraria/ModLoader/Worlds), every world has four files: the modded world and ...
Read more >
Swapping Between Mods and Vanilla with tModLoader
I want to keep my vanilla characters and worlds so I was hoping I could swap between the two or have two desktop...
Read more >
How do I run TModloader as a different client than Vanilla?
I tried launching Tmodloading and everything was fine. I tried launching Terraria from steam and It crashed. Any help?
Read more >
tModLoader Mod Browser Mirror
Display Name Version | Size Author Last Updated tModLo... niol's Buffed Accessories Download v3.1.2 (53.9 KB) niol one year ago tModLo... Litho's Armory Download v3.1.1.3...
Read more >
Hooks - Terraria Wiki - Fandom
A hook is an essential tool which offers significant freedom from terrain height restrictions as well as being a fast movement option, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found