Plugin class structure – Helpful inherited members - TiberiumFusion/TTPlugins GitHub Wiki

Back to the Plugin class structure article.


The HPlugin base type provides several helpful members for you to use.

These are all instance members and thus are not available in your plugin's static stub patch methods.


Method voidCreateHPatchOperation(string targetTypeFullName, string targetMethodName, string stubMethodName, HPatchLocation patchLocation, int patchPriority = -1)

This is the most convenient overload of the method you must use to define HPatchOperations in your plugin. To learn about writing patch methods and defining patch operations, please refer to the Writing stub patch methods article.

Parameters:

  • targetTypeFullName - The full name of the Type that contains the target method. For example, "Terraria.Player".
  • targetMethodName - The name of the target method that will be patched. For example, "UpdateEquips".
  • stubMethodName - The name of the stub patch method in the plugin class that will be patched onto the target method.
  • patchLocation - A value from HPatchLocation, either HPatchLocation.Prefix, HPatchLocation.Postifx, or HPatchLocation.Transpiler. Determines whether your stub patch method will be applied as a prefix, postfix, or transpiler patch.

Example usage:

CreateHPatchOperation("Terraria.Player", "UpdateEquips", "MyPrefixPatch", HPatchLocation.Prefix); // MyPrefixPatch is a static method in the calling class

This method has several overloads. You can view them all here.

Property AssemblyPluginAssembly

Gets the Assembly that contains your plugin class.

Method byte[]GetPluginAssemblyResourceBytes(string resourceName)

Gets the byte[] that constitutes an embedded assembly resource from your plugin's PluginAssembly property. This method is particularly useful under Security Level 3, which prohibits direct use of Streams.

Internally, this method uses GetManifestResourceStream().

Example usage:

byte[] pngBytes = GetPluginAssemblyResourceBytes("CoolTerrariaDude.Plugins.MyCoolWeapon.WeaponSprite.png");

TIP: For information on how to use embedded resources, please refer to the Embedding resources in your plugin article.


Back to the Plugin class structure article.