Skip to content

Commit 54d80c0

Browse files
committed
unwatch events & unregister functions at unload
1 parent a2f12aa commit 54d80c0

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

addon/d3d9_wrapper.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ gw2al_addon_dsc gAddonDsc = {
2727
};
2828

2929
HMODULE custom_d3d9_module;
30+
gw2al_hashed_name eventEnableProcName;
3031

3132
gw2al_core_vtable* instance::api = NULL;
3233

@@ -166,8 +167,11 @@ void d3d9_wrapper_enable_event(d3d9_vtable_method method, vtable_wrap_mode mode)
166167
gw2al_api_ret gw2addon_load(gw2al_core_vtable* core_api)
167168
{
168169
gAPI = core_api;
169-
170+
171+
eventEnableProcName = gAPI->hash_name((wchar_t*)L"D3D_wrapper_enable_event");
172+
170173
gAPI->register_function(&OnD3D9Create, GW2AL_CORE_FUNN_D3DCREATE_HOOK);
174+
gAPI->register_function(&d3d9_wrapper_enable_event, eventEnableProcName);
171175

172176
wrap_InitEvents();
173177

@@ -196,15 +200,27 @@ gw2al_api_ret gw2addon_load(gw2al_core_vtable* core_api)
196200
d3d9_wrapper_enable_event(METH_OBJ_Release, WRAP_CB_POST);
197201
d3d9_wrapper_enable_event(METH_DEV_Release, WRAP_CB_POST);
198202

199-
gAPI->register_function(&d3d9_wrapper_enable_event, gAPI->hash_name((wchar_t*)L"D3D_wrapper_enable_event"));
200-
201203
return GW2AL_OK;
202204
}
203205

204206
gw2al_api_ret gw2addon_unload(int gameExiting)
205207
{
206-
//TODO cleanup
208+
gAPI->unwatch_event(
209+
gAPI->query_event(gAPI->hash_name((wchar_t*)L"D3D9_POST_OBJ_CreateDevice")),
210+
gAPI->hash_name((wchar_t*)L"d3d9 wrapper")
211+
);
212+
213+
gAPI->unwatch_event(
214+
gAPI->query_event(gAPI->hash_name((wchar_t*)L"D3D9_POST_DEV_Release")),
215+
gAPI->hash_name((wchar_t*)L"d3d9 wrapper")
216+
);
217+
218+
gAPI->unwatch_event(
219+
gAPI->query_event(gAPI->hash_name((wchar_t*)L"D3D9_POST_OBJ_Release")),
220+
gAPI->hash_name((wchar_t*)L"d3d9 wrapper")
221+
);
207222

223+
gAPI->unregister_function(eventEnableProcName);
208224
gAPI->unregister_function(GW2AL_CORE_FUNN_D3DCREATE_HOOK);
209225

210226
if (custom_d3d9_module)

0 commit comments

Comments
 (0)