Skip to content
Luke edited this page May 29, 2017 · 4 revisions

Hooks

Hook Description
OTAPI.Hooks.Chest.QuickStack
OTAPI.Hooks.Collision.PressurePlate Occurs when an entity triggers a pressure plate.
OTAPI.Hooks.Command.Process Occurs when a console command has been sent and is to be processed
OTAPI.Hooks.Command.StartCommandThread Occurs when the server is to start listening for commands.
OTAPI.Hooks.Console.Write Occurs each time vanilla calls Console.Write
OTAPI.Hooks.Console.WriteLine Occurs each time vanilla calls Console.WriteLine
OTAPI.Hooks.Game.Christmas Occurs when christmas is being checked for.
OTAPI.Hooks.Game.Halloween Occurs when hallowwn is being checked for.
OTAPI.Hooks.Game.PostInitialize Occurs at the end of the games initialize method.
OTAPI.Hooks.Game.PostUpdate Occurs at the end of the games update loop.
OTAPI.Hooks.Game.PreInitialize Occurs at the first point of call when the Initialze method is ran.
OTAPI.Hooks.Game.PreUpdate Occurs at the first point of call when the game is running the update loop.
OTAPI.Hooks.Game.Started Occurs right after server initialisation and before the server loop starts
OTAPI.Hooks.Game.StatusTextUpdate Occurs when Terraria.Main.DedServ is checking if it needs to write console data
OTAPI.Hooks.Game.StatusTextWrite Occurs when the Terraria.Main.statusText variable is written to
OTAPI.Hooks.Item.PostNetDefaults Occurs when the NetDefaults(int) method ends
Arg 1: The item instance
2: Type
OTAPI.Hooks.Item.PostSetDefaultsById Occurs when the SetDefaults(int,bool) method ends
Arg 1: The item instance
2: Type
3: noMatCheck flag
OTAPI.Hooks.Item.PostUpdate Occurs at the end of the UpdateItem method.
Arg 1: item
2: item whoAmI value
OTAPI.Hooks.Item.PreCheckMaterial Occurs at the start of the checkMat() method.
Arg 1: The item instance
OTAPI.Hooks.Item.PreNetDefaults Occurs at the start of the NetDefaults(int) method.
Arg 1: The item instance
2: Type
OTAPI.Hooks.Item.PreSetDefaultsById Occurs at the start of the SetDefaults(int,bool) method
Arg 1: The item instance
2: Type
3: noMatCheck flag
OTAPI.Hooks.Item.PreUpdate Occurs at the start of the UpdateItem method.
Arg 1: item
2: new item whoAmI value
OTAPI.Hooks.Net.AfterBroadcastChatMessage
OTAPI.Hooks.Net.AfterSendChatMessageToClient
OTAPI.Hooks.Net.BeforeBroadcastChatMessage
OTAPI.Hooks.Net.BeforeSendChatMessageToClient
OTAPI.Hooks.Net.CheckBytes
OTAPI.Hooks.Net.ReceiveData
OTAPI.Hooks.Net.RemoteClient.PostReset
OTAPI.Hooks.Net.RemoteClient.PreReset
OTAPI.Hooks.Net.SendBytes Occurs when the server is about to send data to a client
OTAPI.Hooks.Net.SendData
OTAPI.Hooks.Net.SendUnknownPacket Occurs when a unknown packet is required to be written to the BinaryWriter.
OTAPI.Hooks.Net.Socket.Accepted
OTAPI.Hooks.Net.Socket.Create Occurs when the server socket is to be created.
Return null if you wish for default functionality.
OTAPI.Hooks.Npc.BossBagItem Occurs when a boss item is to drop
Arg 1: The npc instance
TODO: the following arguments are vanilla, these need to be documented.

Currently only supported using the server API
OTAPI.Hooks.Npc.Create
OTAPI.Hooks.Npc.Killed Occurs when an npc has been killed
OTAPI.Hooks.Npc.PostAI Occurs when the AI() method ends
Arg 1: The projectile instance
OTAPI.Hooks.Npc.PostDropLoot
OTAPI.Hooks.Npc.PostNetDefaults Occurs when the NetDefaults(int) method ends
Arg 1: The npc instance
2: Type
OTAPI.Hooks.Npc.PostSetDefaultsById Occurs when the SetDefaults(int,float) method ends
Arg 1: The npc instance
2: Type
3: ScaleOverride
OTAPI.Hooks.Npc.PostTransform Occurs when an npc transforms
Arg 1: The npc instance
OTAPI.Hooks.Npc.PostUpdate Occurs at the end of the UpdateNPC method.
Arg 1: npc
2: npc whoAmI value
OTAPI.Hooks.Npc.PreAI Occurs at the start of the AI() method.
Arg 1: The projectile instance
OTAPI.Hooks.Npc.PreDropLoot
OTAPI.Hooks.Npc.PreNetDefaults Occurs at the start of the NetDefaults(int) method.
Arg 1: The npc instance
2: Type
OTAPI.Hooks.Npc.PreSetDefaultsById Occurs at the start of the SetDefaults(int,float) method
Arg 1: The npc instance
2: Type
3: ScaleOverride
OTAPI.Hooks.Npc.PreTransform Occurs when an npc transforms
Arg 1: The npc instance
2: The new type that the npc will be transforming to
OTAPI.Hooks.Npc.PreUpdate Occurs at the start of the UpdateNPC method.
Arg 1: npc
2: new npc whoAmI value
OTAPI.Hooks.Npc.Spawn Occurs when an npc is about to be spawned into the world.
OTAPI.Hooks.Npc.Strike Occurs at the start of the NetDefaults(int) method.
Arg 1: The npc instance
2: Value to be returned if the hook cancelled the event
3: damage
4: knock back
5: hit direction
6: Type
7: crit
8: no effect
9: from net
10: entity who may be striking the npc
OTAPI.Hooks.Player.Announce Occurs at the start of the greetPlayer method.
Arg 1: playerid
OTAPI.Hooks.Player.NameCollision Occurs when a connecting player is about to be booted due to having the same name
as a player whom is already playing.
Arg 1: player instance
OTAPI.Hooks.Player.PostGreet Occurs at the end of the greetPlayer method.
Arg 1: playerid
OTAPI.Hooks.Player.PostUpdate
OTAPI.Hooks.Player.PreGreet Occurs at the start of the greetPlayer method.
Arg 1: playerid
OTAPI.Hooks.Player.PreUpdate
OTAPI.Hooks.Projectile.PostAI Occurs when the AI() method ends
Arg 1: The projectile instance
OTAPI.Hooks.Projectile.PostKilled
OTAPI.Hooks.Projectile.PostSetDefaultsById Occurs when the SetDefaults(int) method ends
Arg 1: The projectile instance
2: Type
OTAPI.Hooks.Projectile.PostUpdate Occurs when the Update(int) method ends
Arg 1: The projectile instance
2: The root of whoAmI
OTAPI.Hooks.Projectile.PreAI Occurs at the start of the AI() method.
Arg 1: The projectile instance
OTAPI.Hooks.Projectile.PreKill
OTAPI.Hooks.Projectile.PreSetDefaultsById Occurs at the start of the SetDefaults(int) method.
Arg 1: The projectile instance
2: Type
OTAPI.Hooks.Projectile.PreUpdate Occurs at the start of the Update(int) method.
Arg 1: The projectile instance
2: The root of whoAmI
OTAPI.Hooks.Tile.CreateCollection Occurs on the static constructor of Terraria.Main when
the Terraria.Main.tile field is being initialised.
Use this to create custom tile providers.
OTAPI.Hooks.Tile.CreateTile Occurs whenever a tile instance is to be created
in the Terraria assembly.
OTAPI.Hooks.Tile.CreateTileFrom Occurs whenever a tile instance is to be created
in the Terraria assembly.
OTAPI.Hooks.Wiring.AnnouncementBox
OTAPI.Hooks.World.DropMeteor
OTAPI.Hooks.World.Generate
OTAPI.Hooks.World.HardmodeTileUpdate
OTAPI.Hooks.World.IO.PostLoadWorld
OTAPI.Hooks.World.IO.PostSaveWorld Occurs when the saveWorld(bool,bool) method ends
Arg 1: Flag to save to the "cloud"
2: The root of whoAmIFlag to indicate if the time is to be reset
OTAPI.Hooks.World.IO.PreLoadWorld
OTAPI.Hooks.World.IO.PreSaveWorld Occurs at the start of the saveWorld(bool,bool) method.
Arg 1: Flag to save to the "cloud"
2: The root of whoAmIFlag to indicate if the time is to be reset
OTAPI.Hooks.World.PostHardmode Occurs when the StartHardmode() method ends
OTAPI.Hooks.World.PreHardmode Occurs at the start of the StartHardmode() method.
OTAPI.Hooks.World.SpawnNpc Occurs when the game is to spawn an npc
OTAPI.Hooks.World.SpreadGrass Occurs when the game is attempting to spread grass
OTAPI.Hooks.World.Statue Occurs when the game is to spawn a statue

Stats

Hook Count
Total hooks in OTAPI v2 82
OTAPI.Hooks.Chest 1
OTAPI.Hooks.Collision 1
OTAPI.Hooks.Command 2
OTAPI.Hooks.Console 2
OTAPI.Hooks.Game 9
OTAPI.Hooks.Item 7
OTAPI.Hooks.Net 9
OTAPI.Hooks.Net.RemoteClient 2
OTAPI.Hooks.Net.Socket 2
OTAPI.Hooks.Npc 17
OTAPI.Hooks.Player 6
OTAPI.Hooks.Projectile 8
OTAPI.Hooks.Tile 3
OTAPI.Hooks.Wiring 1
OTAPI.Hooks.World 8
OTAPI.Hooks.World.IO 4

Page generated using LINQPad 5 + Jolt.NET + App.Config

void Main()
{
  	XmlDocCommentReader reader = new XmlDocCommentReader(typeof(OTAPI.Hooks).Assembly);
	
	var hooks = GetAllTypes(typeof(OTAPI.Hooks))
		.SelectMany(x => x.GetFields())
	;
  
  	(
		(
			"## Hooks\n" +
			"Hook | Description\n" +
			"---- | -----------\n" + 
			String.Join("\n", hooks
				.Select(x => new
				{
					Field = x.DeclaringType.FullName.Replace("+", ".") + "." + x.Name,
					Comments = reader.GetComments(x)?.Value ?? ""
				})
				.OrderBy(x => x.Field)
				.Select(x => x.Field + " | " + String.Join("<br>", 
							x.Comments
								.Trim()
								.Split(new [] {'\n'}, StringSplitOptions.RemoveEmptyEntries)
								.Select(l => l.Trim())
						)
					)
			)
		)
		+ "\n\n## Stats\n" +
		(
			"Hook | Count\n" +
			"---- | -----------\n" + 
			"Total hooks in OTAPI v2 | " + hooks.Count() + "\n" + 
			String.Join("\n",
				hooks
					.Select(x => x.DeclaringType.FullName)
					.OrderBy(x => x)
					.Distinct()
					.Select(x => x.Replace("+", ".") + " | " + hooks.Where(y => y.DeclaringType.FullName == x).Count())
			)
		)
		+ "\n\n### Page generated using LINQPad 5 + Jolt.NET + App.Config\n```C#\n```"
	)
		.Dump()
	;
}

static IEnumerable<Type> GetAllTypes(Type parent)
{
	return parent.GetNestedTypes().SelectMany(nested => new [] {nested}.Concat(GetAllTypes(nested)));
}