Hooks

From Heroes of Hammerwatch Wiki
Revision as of 16:27, 15 December 2025 by Thyraxxvoid (talk | contribs)
Jump to navigation Jump to search

ATTENTION: it's possible a hook won't work, due to the parameters not matching, if you find one, report it to the modders channel or the hoh2 wiki discussion.

Hooks are script functions that are called at specific moments. This way, you can insert code into the game.

They are specified in script files and tagged with the Hook specifier. They also must be placed within a namespace to avoid ambiguity between multiple mods.

The following is an example of such a file:

namespace MyTestMod
{
   [Hook]
   void BaseGameModeConstructor(BaseGameMode@ baseGameMode){
       print("Hello World");
   }
}

GetGeneratedAttributes

void GetGeneratedAttributes(PlayerStatsDetail@ stats, array<string>@ strArray, array<string>@ icons, bool isHandHeld)

PlayerDamagedActor

void PlayerDamagedActor(Player@ player, Actor@ actor, DamageInfo di)

PlayerDamageActor

void PlayerDamageActor(PlayerBase@ playerBase, Actor@ actor, DamageInfo@ damageInfo, Skills::Skill@ skill)

PlayerDamageActorNoWeapon

void PlayerDamageActorNoWeapon(PlayerBase@ playerBase, Actor@ actor, DamageInfo@ damageInfo)

PlayerDamage

void PlayerDamage(Player@ player, DamageInfo di)

PlayerDamageTaken

void PlayerDamageTaken(Player@ player, DamageInfo di)

PlayerInitialize

void PlayerInitialize(PlayerBase@ playerBase)

PlayerRefreshScene

void PlayerRefreshScene(PlayerBase@ playerBase)

PlayerRecordConstructor

void PlayerRecordConstructor(PlayerRecord@ record)

PickedCharacter

void PickedCharacter(PlayerRecord@ record)

CreateCharacter

void CreateCharacter(PlayerRecord@ record)

PlayerRecordSave

void PlayerRecordSave(PlayerRecord@ record, SValueBuilder &builder)

PlayerRecordLoad

void PlayerRecordLoad(PlayerRecord@ record, SValue@ data)

PlayerRecordRefreshModifiers

void PlayerRecordRefreshModifiers(PlayerRecord@ record)

LevelupCharacter

void LevelupCharacter(PlayerRecord@ record)

GameModeStart

void GameModeStart(AGameplayGameMode@ aGameplayGameMode, SValue@ save)

GameModePostStart

void GameModePostStart(AGameplayGameMode@ aGameplayGameMode)

GameModePreRenderFrame

void GameModePreRenderFrame(AGameplayGameMode@ aGameplayGameMode, int idt)

GameModeRenderFrame

void GameModeRenderFrame(AGameplayGameMode@ aGameplayGameMode, int idt, SpriteBatch& sb)

GameModeSpawnPlayer

void GameModeSpawnPlayer(AGameplayGameMode@ aGameplayGameMode, PlayerRecord@ record)

GameModeSpawnPlayerCorpse

void GameModeSpawnPlayerCorpse(AGameplayGameMode@ aGameplayGameMode, PlayerRecord@ record)

BaseGameModeConstructor

void BaseGameModeConstructor(BaseGameMode@ baseGameMode)

GameModeUpdatePaused

void GameModeUpdatePaused(BaseGameMode@ baseGameMode, int ms, GameInput& gameInput, MenuInput& menuInput)

GameModeUpdate

void GameModeUpdate(BaseGameMode@ baseGameMode, int ms, GameInput& gameInput, MenuInput& menuInput)

LoadWidgetProducers

void LoadWidgetProducers(GUIBuilder@ builder)

HUDConstructor

void HUDConstructor(HUD@ hud, GUIBuilder@ b)

TownRecordConstructor

void TownRecordConstructor(TownRecord@ townRecord)

TownRecordSave

void TownRecordSave(TownRecord@ townRecord, SValueBuilder& builder)

TownRecordLoad

void TownRecordLoad(TownRecord@ townRecord, SValue@ save)

TownRecordSpawnTown

void TownRecordSpawnTown(TownRecord@ townRecord)

TownRecordRefreshHeroTitles

void TownRecordRefreshHeroTitles(TownRecord@ townRecord)

TownRecordRefreshDonationTitles

void TownRecordRefreshDonationTitles(TownRecord@ townRecord)







How does the game know the hooks?

In specific parts of the game a 'Hook' call is added which automatically looks up the hook that matches and executes it at that point in the code. Every hook call in the game code itself is defined as Hooks::Call("NameOfHook", arguments1, arguments2)

Hooks usually have 1 or even multiple arguments, these must match if you want to use the hook. To give an example, let's take a look at Hooks::Call("BaseGameModeConstructor", @this); inside BaseGameMode class (BaseGameMode.as). For us to use this hook we must use the name BaseGameModeConstructor, with the argument @this. In this case @this refers to the class itself. The class this is in is BaseGameMode. This means that the argument is the class BaseGameMode.

So we know the name and the argument to use this hook, to use it we use this:

namespace MyTestMod // Be sure to always put it inside a namespace, conflicts or other things may occur if you don't
{
   // This is executed when the game comes along to Hooks::Call("BaseGameModeConstructor", @this);
   [Hook] // [Hook] means for the game that this is an hook we use, if you don't put this on top of the hook we are using, the game doesn't recognize it.
   void BaseGameModeConstructor(BaseGameMode@ baseGameMode){ // void BaseGameModeConstructoris the name from Hooks::Call("BaseGameModeConstructor"... the argument @this refers to the BaseGameMode as we found.
       print("Hello World"); // Prints hello world in the console
   }
}

If the arguments do not match in the hook, it will either not execute or returns an error in the console