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 Name | Type | Description |
---|
event_name | string | The name of the event to register this callback to. |
event_alias | string | The alias for this callback. |
callback_func | function | The function to invoke when the event is raised. |
Returns |
---|
(boolean) True on success, false otherwise. |
1boolean hook.events.unregister(event_name, event_alias);
Parameter Name | Type | Description |
---|
event_name | string | The name of the event to unregister the existing callback for. |
event_alias | string | The 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 Name | Event Description |
---|
load | Event raised when the addon is being loaded. |
unload | Event raised when the addon is being unloaded. |
command | Event raised when the game client is handling a command. |
message | Event raised when the game client is about to print a message to the chat/combat windows. |
packet_recv | Event raised when the game client receives a packet. |
packet_send | Event raised when the game client sends a packet. |
d3d_prereset | Event raised when the game client is about to reset the graphics device. |
d3d_postreset | Event raised when the game client has finished resetting the graphics device. |
d3d_beginscene | Event raised when the game client is beginning a new scene. |
d3d_endscene | Event raised when the game client is ending a scene. |
d3d_present | Event raised when the game client is presenting the scene. |
d3d_renderstate | Event raised when the game client is setting a render state. |
d3d_dip | Event raised when the game client is about to render a primitive. |
d3d_dipup | Event raised when the game client is about to render a primitive. |
d3d_dp | Event raised when the game client is about to render a primitive. |
d3d_dpup | Event raised when the game client is about to render a primitive. |
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..
1hook.events.registered('load', 'load_cb', function ()
2end);
Argument Name | Type | Description |
---|
None. | — | — |
Event: unload
Event raised when the addon is being unloaded.
Click for more event information..
1hook.events.registered('unload', 'unload_cb', function ()
2end);
Argument Name | Type | Description |
---|
None. | — | — |
Event: command
Event raised when the game client is handling a command.
Click for more event information..
1hook.events.registered('command', 'command_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.mode | number | [Read Only] The command mode. |
e.imode | number | [Read Only] The command input mode. |
e.command | string | [Read Only] The command string. |
e.modified_mode | number | The modified command mode. |
e.modified_imode | number | The modified command input mode. |
e.modified_command | string | The modified command string. |
e.injected | boolean | [Read Only] Flag that states if the event was injected by daochook or another addon. |
e.blocked | boolean | Flag that states if the event has been blocked by daochook or another addon. |
Event: message
Event raised when the game client is about to print a message to the chat/combat windows.
Click for more event information..
1hook.events.registered('message', 'message_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.mode | number | [Read Only] The message mode. |
e.message | string | [Read Only] The message string. |
e.modified_mode | number | The modified message mode. |
e.modified_message | string | The modified message string. |
e.injected | boolean | [Read Only] Flag that states if the event was injected by daochook or another addon. |
e.blocked | boolean | Flag that states if the event has been blocked by daochook or another addon. |
Event: packet_recv
Event raised when the game client receives a packet.
Click for more event information..
1hook.events.registered('packet_recv', 'packet_recv_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.opcode | number | [Read Only] The packet opcode. |
e.unknown | number | [Read Only] Unknown. (Generally zero.) |
e.session_id | number | [Read Only] The client session id. |
e.data | string | [Read Only] The packet data. (As a string literal.) |
e.data_raw | void* | [Read Only] The packet data. (As a raw pointer, for use with FFI.) |
e.data_modified | string | The modified packet data. (As a string literal.) |
e.data_modified_raw | void* | The modified packet data. (As a raw pointer, for use with FFI.) |
e.size | number | [Read Only] The packet size. |
e.state | number | [Read Only] The game state pointer. |
e.injected | boolean | [Read Only] Flag that states if the event was injected by daochook or another addon. |
e.blocked | boolean | Flag that states if the event has been blocked by daochook or another addon. |
Event: packet_send
Event raised when the game client sends a packet.
Click for more event information..
1hook.events.registered('packet_send', 'packet_send_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.opcode | number | [Read Only] The packet opcode. |
e.data | string | [Read Only] The packet data. (As a string literal.) |
e.data_raw | void* | [Read Only] The packet data. (As a raw pointer, for use with FFI.) |
e.data_modified | string | The modified packet data. (As a string literal.) |
e.data_modified_raw | void* | The modified packet data. (As a raw pointer, for use with FFI.) |
e.size | number | [Read Only] The packet size. |
e.parameter | number | [Read Only] The packet parameter. |
e.injected | boolean | [Read Only] Flag that states if the event was injected by daochook or another addon. |
e.blocked | boolean | Flag that states if the event has been blocked by daochook or another addon. |
Event: d3d_prereset
Event raised when the game client is about to reset the graphics device.
Click for more event information..
1hook.events.registered('d3d_prereset', 'd3d_prereset_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.back_buffer_width | number | [Read Only] The back buffer width. |
e.back_buffer_height | number | [Read Only] The back buffer height. |
e.back_buffer_format | number | [Read Only] The back buffer format. |
e.back_buffer_count | number | [Read Only] The back buffer count. |
e.multisample_type | number | [Read Only] The multisample type. |
e.multisample_quality | number | [Read Only] The multisample quality. |
e.swap_effect | number | [Read Only] The swap effect. |
e.device_window | number | [Read Only] The device window handle. |
e.windowed | boolean | [Read Only] The windowed mode flag. |
e.enable_auto_depth_stencil | boolean | [Read Only] The enable auto depth stencil flag. |
e.auto_depth_stencil_format | number | [Read Only] The auto depth stencil format. |
e.flags | number | [Read Only] The flags. |
e.fullscreen_refresh_rate_in_hz | number | [Read Only] The fullscreen refresh rate in hz. |
e.presentation_interval | number | [Read Only] The presentation interval. |
Event: d3d_postreset
Event raised when the game client has finished resetting the graphics device.
Click for more event information..
1hook.events.registered('d3d_postreset', 'd3d_postreset_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.back_buffer_width | number | [Read Only] The back buffer width. |
e.back_buffer_height | number | [Read Only] The back buffer height. |
e.back_buffer_format | number | [Read Only] The back buffer format. |
e.back_buffer_count | number | [Read Only] The back buffer count. |
e.multisample_type | number | [Read Only] The multisample type. |
e.multisample_quality | number | [Read Only] The multisample quality. |
e.swap_effect | number | [Read Only] The swap effect. |
e.device_window | number | [Read Only] The device window handle. |
e.windowed | boolean | [Read Only] The windowed mode flag. |
e.enable_auto_depth_stencil | boolean | [Read Only] The enable auto depth stencil flag. |
e.auto_depth_stencil_format | number | [Read Only] The auto depth stencil format. |
e.flags | number | [Read Only] The flags. |
e.fullscreen_refresh_rate_in_hz | number | [Read Only] The fullscreen refresh rate in hz. |
e.presentation_interval | number | [Read Only] The presentation interval. |
Event: d3d_beginscene
Event raised when the game client is beginning a new scene.
Click for more event information..
1hook.events.registered('d3d_beginscene', 'd3d_beginscene_cb', function ()
2end);
Argument Name | Type | Description |
---|
None. | — | — |
Event: d3d_endscene
Event raised when the game client is ending a scene.
Click for more event information..
1hook.events.registered('d3d_endscene', 'd3d_endscene_cb', function ()
2end);
Argument Name | Type | Description |
---|
None. | — | — |
Event: d3d_present
Event raised when the game client is presenting the scene.
Click for more event information..
1hook.events.registered('d3d_present', 'd3d_present_cb', function ()
2end);
Argument Name | Type | Description |
---|
None. | — | — |
Event: d3d_renderstate
Event raised when the game client is setting a render state.
Click for more event information..
1hook.events.registered('d3d_renderstate', 'd3d_renderstate_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.state | number | [Read Only] The render state id. |
e.value | number | The render state value. |
e.blocked | boolean | Flag that states if the event has been blocked by daochook or another addon. |
Event: d3d_dip
Event raised when the game client is about to render a primitive.
Click for more event information..
1hook.events.registered('d3d_dip', 'd3d_dip_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.primitive_type | number | [Read Only] The primitive type. |
e.base_vertex_index | number | [Read Only] The primitive base vertex index. |
e.min_index | number | [Read Only] The primitive min index. |
e.num_vertices | number | [Read Only] The primitive num vertices. |
e.start_index | number | [Read Only] The primitive start index. |
e.prim_count | number | [Read Only] The primitive primitive count. |
e.blocked | boolean | Flag that states if the event has been blocked by daochook or another addon. |
Event: d3d_dipup
Event raised when the game client is about to render a primitive.
Click for more event information..
1hook.events.registered('d3d_dipup', 'd3d_dipup_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.primitive_type | number | [Read Only] The primitive type. |
e.min_vertex_index | number | [Read Only] The primitive min vertex index. |
e.num_vertex_indices | number | [Read Only] The primitive num vertex indices. |
e.primitive_count | number | [Read Only] The primitive primitive count. |
e.index_data | number | [Read Only] The primitive index data. |
e.index_data_format | number | [Read Only] The primitive index data format. |
e.vertex_stream_zero_data | number | [Read Only] The primitive vertex stream zero data. |
e.vertex_stream_zero_stride | number | [Read Only] The primitive vertex stream zero stride. |
e.blocked | boolean | Flag that states if the event has been blocked by daochook or another addon. |
Event: d3d_dp
Event raised when the game client is about to render a primitive.
Click for more event information..
1hook.events.registered('d3d_dp', 'd3d_dp_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.primitive_type | number | [Read Only] The primitive type. |
e.start_vertex | number | [Read Only] The primitive start vertex. |
e.primitive_count | number | [Read Only] The primitive count. |
e.blocked | boolean | Flag that states if the event has been blocked by daochook or another addon. |
Event: d3d_dpup
Event raised when the game client is about to render a primitive.
Click for more event information..
1hook.events.registered('d3d_dpup', 'd3d_dpup_cb', function (e)
2end);
Argument Name | Type | Description |
---|
e.primitive_type | number | [Read Only] The primitive type. |
e.primitive_count | number | [Read Only] The primitive count. |
e.vertex_stream_zero_data | number | [Read Only] The primitive vertex stream zero data. |
e.vertex_stream_zero_stride | number | [Read Only] The primitive vertex stream zero stride. |
e.blocked | boolean | Flag that states if the event has been blocked by daochook or another addon. |