Events

Events are one of the main ways addons can be used to interact with the game client. daochook hooks onto multiple game functions and then creates/raises an event internally when one of those functions is invoked. When this happens, the internal addon manager will raise the event in every loaded addon whom has registered one or more callback functions to the event being raised. Addons can register more than one callback to an event if needed.

Addons are not required to register to any events in order to be considered valid. Events are entirely optional and is best to not register to any event unless you absolutely need information from it. It’s a waste of performance to register to events that you are not actually using.

Event Functions

daochook exposes two main functions for registering and unregistering from events.

1boolean hook.events.register(event_name, event_alias, callback_func);
Parameter NameTypeDescription
event_namestringThe name of the event to register this callback to.
event_aliasstringThe alias for this callback.
callback_funcfunctionThe function to invoke when the event is raised.
Returns
(boolean) True on success, false otherwise.
1boolean hook.events.unregister(event_name, event_alias);
Parameter NameTypeDescription
event_namestringThe name of the event to unregister the existing callback for.
event_aliasstringThe alias for the existing callback to unregister.
Returns
(boolean) True on success, false otherwise.

Event Registration

Addons can register to an event using the hook.events.register(...) function. Similarly, an addon can unregister from an event using the hook.events.unregister(...) function.

When registering to an event, you can write the callback function in multiple formats. The main two formats are considered short-hand and long-hand. Generally, short-hand is the recommended means of writing code as it saves space.

Short-hand Method

1hook.events.register('load', 'load_cb', function ()
2    print('Load event was fired.');
3end);

Long-hand Method

1local function load_callback()
2    print('Load event was fired.');
3end
4hook.events.register('load', 'load_cb', load_callback);

Registering Multiple Callbacks

If you need to register to an event multiple times, then you must pass a unique alias for each time you register to the event. For example:

1hook.events.register('load', 'load_cb1', function ()
2    print('Load event was fired. (1)');
3end);
4hook.events.register('load', 'load_cb2', function ()
5    print('Load event was fired. (2)');
6end);

If you do not pass a unique alias, then the existing registered callback will be overwritten.

Available Events

daochook currently exposes the following list of events. Click the name of the event to navigate to its specific information entry.

Event NameEvent Description
loadEvent raised when the addon is being loaded.
unloadEvent raised when the addon is being unloaded.
commandEvent raised when the game client is handling a command.
messageEvent raised when the game client is about to print a message to the chat/combat windows.
packet_recvEvent raised when the game client receives a packet.
packet_sendEvent raised when the game client sends a packet.
d3d_preresetEvent raised when the game client is about to reset the graphics device.
d3d_postresetEvent raised when the game client has finished resetting the graphics device.
d3d_beginsceneEvent raised when the game client is beginning a new scene.
d3d_endsceneEvent raised when the game client is ending a scene.
d3d_presentEvent raised when the game client is presenting the scene.
d3d_renderstateEvent raised when the game client is setting a render state.
d3d_dipEvent raised when the game client is about to render a primitive.
d3d_dipupEvent raised when the game client is about to render a primitive.
d3d_dpEvent raised when the game client is about to render a primitive.
d3d_dpupEvent raised when the game client is about to render a primitive.

Event Arguments Information

Some of the events that can be raised within an addon have arguments that are passed to their callback functions. These arguments are passed as a single table to help improve performance when calling between the C++ and Lua bounds. This is similar to how C# handles events.

If an event has any arguments, you can find more information for those arguments in the information listed below. The argument information tables explain each of the arguments that the given event has access to. They also mark if the argument is read-only or not. When an argument is read-only, it cannot be modified or the addon will throw an error. Any argument not marked as read-only can be modified.

When an argument is modified, all addons that will receive the event after yours will see the new modified value. They will also be given the ability to further modify the value if they see fit. Once all addons have handled the event, if it was not blocked, the client will process the data using the modified values as if that was the original data to begin with.

Injected Events

Events that have an e.injected argument can determine if the event came from the actual game client, or if it was injected by daochook or another addon.

It is best practice to not block or modify injected data as another addon has deemed it important enough to be injected. You can increase performance if you exit an event callback early if the event was injected and you don’t need to process it.

Blocked Events

Events that have an e.blocked argument can determine if the event has been blocked by daochook or another addon. Once an event has been blocked, it cannot be unblocked. Setting e.blocked to false will not change any previous true value it was set to. If you wish to block the event from reaching the client in your addon, you can set this to true to cause it to be blocked. ie. e.blocked = true;

It is best practice to check if an event is blocked and ignore it if you do not need to further act on it. You can increase performance if you exit an event callback early if the event was already blocked and you have no need to process it.

Event: load

Event raised when the addon is being loaded.

Click for more event information..

Event: unload

Event raised when the addon is being unloaded.

Click for more event information..

Event: command

Event raised when the game client is handling a command.

Click for more event information..

Event: message

Event raised when the game client is about to print a message to the chat/combat windows.

Click for more event information..

Event: packet_recv

Event raised when the game client receives a packet.

Click for more event information..

Event: packet_send

Event raised when the game client sends a packet.

Click for more event information..

Event: d3d_prereset

Event raised when the game client is about to reset the graphics device.

Click for more event information..

Event: d3d_postreset

Event raised when the game client has finished resetting the graphics device.

Click for more event information..

Event: d3d_beginscene

Event raised when the game client is beginning a new scene.

Click for more event information..

Event: d3d_endscene

Event raised when the game client is ending a scene.

Click for more event information..

Event: d3d_present

Event raised when the game client is presenting the scene.

Click for more event information..

Event: d3d_renderstate

Event raised when the game client is setting a render state.

Click for more event information..

Event: d3d_dip

Event raised when the game client is about to render a primitive.

Click for more event information..

Event: d3d_dipup

Event raised when the game client is about to render a primitive.

Click for more event information..

Event: d3d_dp

Event raised when the game client is about to render a primitive.

Click for more event information..

Event: d3d_dpup

Event raised when the game client is about to render a primitive.

Click for more event information..