1111#include < Psapi.h>
1212
1313#define RESHADE_API_VERSION 1
14- #define RESHADE_API_VERSION_IMGUI IMGUI_VERSION_NUM
1514
1615namespace reshade
1716{
18- // / <summary>
19- // / Gets the handle to the ReShade module in the current process.
20- // / </summary>
21- inline HMODULE &get_reshade_module_handle ()
17+ namespace internal
2218 {
23- static HMODULE handle = nullptr ;
24- if (handle == nullptr )
19+ // / <summary>
20+ // / Gets the handle to the ReShade module in the current process.
21+ // / </summary>
22+ inline HMODULE &get_reshade_module_handle ()
2523 {
26- // Use the kernel32 variant of module enumeration functions so it can be safely called from 'DllMain'
27- HMODULE modules[1024 ]; DWORD num = 0 ;
28- if (K32EnumProcessModules (GetCurrentProcess (), modules, sizeof (modules), &num))
24+ static HMODULE handle = nullptr ;
25+ if (handle == nullptr )
2926 {
30- if (num > sizeof (modules))
31- num = sizeof (modules);
32-
33- for (DWORD i = 0 ; i < num / sizeof (HMODULE); ++i)
27+ // Use the kernel32 variant of module enumeration functions so it can be safely called from 'DllMain'
28+ HMODULE modules[1024 ]; DWORD num = 0 ;
29+ if (K32EnumProcessModules (GetCurrentProcess (), modules, sizeof (modules), &num))
3430 {
35- if (GetProcAddress (modules[i], " ReShadeRegisterAddon" ) &&
36- GetProcAddress (modules[i], " ReShadeUnregisterAddon" ))
31+ if (num > sizeof (modules))
32+ num = sizeof (modules);
33+
34+ for (DWORD i = 0 ; i < num / sizeof (HMODULE); ++i)
3735 {
38- handle = modules[i];
39- break ;
36+ if (GetProcAddress (modules[i], " ReShadeRegisterAddon" ) &&
37+ GetProcAddress (modules[i], " ReShadeUnregisterAddon" ))
38+ {
39+ handle = modules[i];
40+ break ;
41+ }
4042 }
4143 }
4244 }
45+ return handle;
4346 }
44- return handle;
45- }
46- // / <summary>
47- // / Gets the handle to the current add-on module.
48- // / </summary>
49- inline HMODULE &get_current_module_handle ()
50- {
51- static HMODULE handle = nullptr ;
52- return handle;
47+
48+ // / <summary>
49+ // / Gets the handle to the current add-on module.
50+ // / </summary>
51+ inline HMODULE &get_current_module_handle ()
52+ {
53+ static HMODULE handle = nullptr ;
54+ return handle;
55+ }
56+
57+ #if defined(IMGUI_VERSION_NUM)
58+ // / <summary>
59+ // / Gets a pointer to the Dear ImGui function table.
60+ // / </summary>
61+ inline const imgui_function_table *get_imgui_function_table ()
62+ {
63+ static const auto func = reinterpret_cast <const imgui_function_table *(*)(uint32_t )>(
64+ GetProcAddress (get_reshade_module_handle (), " ReShadeGetImGuiFunctionTable" ));
65+ if (func != nullptr )
66+ return func (IMGUI_VERSION_NUM);
67+ return nullptr ;
68+ }
69+ #endif
5370 }
5471
5572 // / <summary>
@@ -60,8 +77,8 @@ namespace reshade
6077 inline void log_message (int level, const char *message)
6178 {
6279 static const auto func = reinterpret_cast <void (*)(HMODULE, int , const char *)>(
63- GetProcAddress (get_reshade_module_handle (), " ReShadeLogMessage" ));
64- func (get_current_module_handle (), level, message);
80+ GetProcAddress (internal:: get_reshade_module_handle (), " ReShadeLogMessage" ));
81+ func (internal:: get_current_module_handle (), level, message);
6582 }
6683
6784 // / <summary>
@@ -71,9 +88,9 @@ namespace reshade
7188 // / <param name="module">Handle of the current add-on module.</param>
7289 inline bool register_addon (HMODULE module )
7390 {
74- get_current_module_handle () = module ;
91+ internal:: get_current_module_handle () = module ;
7592
76- const HMODULE reshade_module = get_reshade_module_handle ();
93+ const HMODULE reshade_module = internal:: get_reshade_module_handle ();
7794 if (reshade_module == nullptr )
7895 return false ;
7996
@@ -83,18 +100,10 @@ namespace reshade
83100 if (!func (module , RESHADE_API_VERSION))
84101 return false ;
85102
86- #if defined(IMGUI_VERSION)
87- // Check that the ReShade module was built with Dear ImGui support
88- const auto imgui_func = reinterpret_cast <const imgui_function_table *(*)(uint32_t )>(
89- GetProcAddress (reshade_module, " ReShadeGetImGuiFunctionTable" ));
90- if (imgui_func == nullptr )
91- return false ;
92-
93- // Check that the ReShade module supports the used Dear ImGui version
94- const imgui_function_table *const imgui_table = imgui_func (RESHADE_API_VERSION_IMGUI);
95- if (imgui_table == nullptr )
103+ #if defined(IMGUI_VERSION_NUM)
104+ // Check that the ReShade module was built with Dear ImGui support and supports the used Dear ImGui version
105+ if (!internal::get_imgui_function_table ())
96106 return false ;
97- g_imgui_function_table = *imgui_table;
98107#endif
99108
100109 return true ;
@@ -105,7 +114,7 @@ namespace reshade
105114 // / <param name="module">Handle of the current add-on module.</param>
106115 inline void unregister_addon (HMODULE module )
107116 {
108- const HMODULE reshade_module = get_reshade_module_handle ();
117+ const HMODULE reshade_module = internal:: get_reshade_module_handle ();
109118 if (reshade_module == nullptr )
110119 return ;
111120
@@ -123,7 +132,7 @@ namespace reshade
123132 inline void register_event (typename reshade::addon_event_traits<ev>::decl callback)
124133 {
125134 static const auto func = reinterpret_cast <void (*)(reshade::addon_event, void *)>(
126- GetProcAddress (get_reshade_module_handle (), " ReShadeRegisterEvent" ));
135+ GetProcAddress (internal:: get_reshade_module_handle (), " ReShadeRegisterEvent" ));
127136 func (ev, static_cast <void *>(callback));
128137 }
129138 // / <summary>
@@ -134,7 +143,7 @@ namespace reshade
134143 inline void unregister_event (typename reshade::addon_event_traits<ev>::decl callback)
135144 {
136145 static const auto func = reinterpret_cast <void (*)(reshade::addon_event, void *)>(
137- GetProcAddress (get_reshade_module_handle (), " ReShadeUnregisterEvent" ));
146+ GetProcAddress (internal:: get_reshade_module_handle (), " ReShadeUnregisterEvent" ));
138147 func (ev, static_cast <void *>(callback));
139148 }
140149
@@ -144,23 +153,21 @@ namespace reshade
144153 // / </summary>
145154 // / <param name="title">A null-terminated title string, or <see langword="nullptr"/> to register a settings overlay for this add-on.</param>
146155 // / <param name="callback">Pointer to the callback function.</param>
147- inline void register_overlay (const char *title, void (*callback)(reshade::api::effect_runtime *runtime, void *imgui_context ))
156+ inline void register_overlay (const char *title, void (*callback)(reshade::api::effect_runtime *runtime))
148157 {
149- static const auto func = reinterpret_cast <void (*)(const char *, void (*)(reshade::api::effect_runtime *, void *))>(
150- GetProcAddress (get_reshade_module_handle (), " ReShadeRegisterOverlay" ));
151- if (func != nullptr ) // May not exist if ReShade was built without "RESHADE_GUI" defined
152- func (title, callback);
158+ static const auto func = reinterpret_cast <void (*)(const char *, void (*)(reshade::api::effect_runtime *))>(
159+ GetProcAddress (internal::get_reshade_module_handle (), " ReShadeRegisterOverlay" ));
160+ func (title, callback);
153161 }
154162 // / <summary>
155163 // / Unregisters an overlay that was previously registered via <see cref="register_overlay"/>.
156164 // / </summary>
157165 // / <param name="title">A null-terminated title string.</param>
158166 // / <param name="callback">Pointer to the callback function.</param>
159- inline void unregister_overlay (const char *title, void (*callback)(reshade::api::effect_runtime *runtime, void *imgui_context ))
167+ inline void unregister_overlay (const char *title, void (*callback)(reshade::api::effect_runtime *runtime))
160168 {
161- static const auto func = reinterpret_cast <void (*)(const char *, void (*)(reshade::api::effect_runtime *, void *))>(
162- GetProcAddress (get_reshade_module_handle (), " ReShadeUnregisterOverlay" ));
163- if (func != nullptr )
164- func (title, callback);
169+ static const auto func = reinterpret_cast <void (*)(const char *, void (*)(reshade::api::effect_runtime *))>(
170+ GetProcAddress (internal::get_reshade_module_handle (), " ReShadeUnregisterOverlay" ));
171+ func (title, callback);
165172 }
166173}
0 commit comments