9 #include "reshade_overlay.hpp"
14 #define RESHADE_API_VERSION 14
17 #if defined(RESHADE_API_LIBRARY) || defined(RESHADE_API_LIBRARY_EXPORT)
19 #if defined(RESHADE_API_LIBRARY_EXPORT)
20 #define RESHADE_API_LIBRARY 1
21 #define RESHADE_API_LIBRARY_DECL extern "C" __declspec(dllexport)
23 #define RESHADE_API_LIBRARY_DECL extern "C" __declspec(dllimport)
26 RESHADE_API_LIBRARY_DECL
void ReShadeLogMessage(HMODULE module,
int level,
const char *
message);
28 RESHADE_API_LIBRARY_DECL
void ReShadeGetBasePath(
char *path,
size_t *path_size);
30 RESHADE_API_LIBRARY_DECL
bool ReShadeGetConfigValue(HMODULE module,
reshade::api::effect_runtime *runtime,
const char *section,
const char *key,
char *value,
size_t *value_size);
31 RESHADE_API_LIBRARY_DECL
void ReShadeSetConfigValue(HMODULE module,
reshade::api::effect_runtime *runtime,
const char *section,
const char *key,
const char *value);
32 RESHADE_API_LIBRARY_DECL
void ReShadeSetConfigArray(HMODULE module,
reshade::api::effect_runtime *runtime,
const char *section,
const char *key,
const char *value,
size_t value_size);
34 RESHADE_API_LIBRARY_DECL
bool ReShadeRegisterAddon(HMODULE module, uint32_t api_version);
35 RESHADE_API_LIBRARY_DECL
void ReShadeUnregisterAddon(HMODULE module);
38 RESHADE_API_LIBRARY_DECL
void ReShadeRegisterEventForAddon(HMODULE module,
reshade::addon_event ev,
void *callback);
40 RESHADE_API_LIBRARY_DECL
void ReShadeUnregisterEventForAddon(HMODULE module,
reshade::addon_event ev,
void *callback);
43 RESHADE_API_LIBRARY_DECL
void ReShadeRegisterOverlayForAddon(HMODULE module,
const char *title,
void(*callback)(
reshade::api::effect_runtime *runtime));
45 RESHADE_API_LIBRARY_DECL
void ReShadeUnregisterOverlayForAddon(HMODULE module,
const char *title,
void(*callback)(
reshade::api::effect_runtime *runtime));
54 extern "C" BOOL WINAPI
K32EnumProcessModules(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded);
63 static HMODULE handle = initial_handle;
64 if (handle ==
nullptr)
66 HMODULE modules[1024]; DWORD num = 0;
69 if (num >
sizeof(modules))
70 num =
sizeof(modules);
72 for (DWORD i = 0; i < num /
sizeof(HMODULE); ++i)
74 if (GetProcAddress(modules[i],
"ReShadeRegisterAddon") &&
75 GetProcAddress(modules[i],
"ReShadeUnregisterAddon"))
91 static HMODULE handle = initial_handle;
100 #if !defined(RESHADE_API_LIBRARY_EXPORT) || defined(BUILTIN_ADDON)
133 #if defined(RESHADE_API_LIBRARY)
134 ReShadeLogMessage(
nullptr,
static_cast<int>(
level),
message);
136 static const auto func =
reinterpret_cast<void(*)(HMODULE,
int,
const char *)
>(
151 #if defined(RESHADE_API_LIBRARY)
152 ReShadeGetBasePath(path, path_size);
154 static const auto func =
reinterpret_cast<bool(*)(
char *,
size_t *)
>(
156 func(path, path_size);
172 #if defined(RESHADE_API_LIBRARY)
173 return ReShadeGetConfigValue(
nullptr, runtime, section, key, value, value_size);
175 static const auto func =
reinterpret_cast<bool(*)(HMODULE,
api::effect_runtime *,
const char *,
const char *,
char *,
size_t *)
>(
181 template <
typename T>
182 inline bool get_config_value(api::effect_runtime *runtime,
const char *section,
const char *key, T &value)
184 char value_string[32];
size_t value_length =
sizeof(value_string) - 1;
187 return std::from_chars(value_string, value_string + value_length, value).ec == std::errc {};
190 inline bool get_config_value<bool>(api::effect_runtime *runtime,
const char *section,
const char *key,
bool &value)
193 if (!get_config_value<int>(runtime, section, key, value_int))
195 value = (value_int != 0);
210 #if defined(RESHADE_API_LIBRARY)
211 ReShadeSetConfigValue(
nullptr, runtime, section, key, value);
213 static const auto func =
reinterpret_cast<void(*)(HMODULE,
api::effect_runtime *,
const char *,
const char *,
const char *)
>(
219 template <
typename T>
220 inline void set_config_value(api::effect_runtime *runtime,
const char *section,
const char *key,
const T &value)
222 char value_string[32] =
"";
223 std::to_chars(value_string, value_string +
sizeof(value_string) - 1, value);
224 set_config_value(runtime, section, key,
static_cast<const char *
>(value_string));
227 inline void set_config_value<bool>(api::effect_runtime *runtime,
const char *section,
const char *key,
const bool &value)
229 set_config_value<int>(runtime, section, key, value ? 1 : 0);
234 #if defined(RESHADE_API_LIBRARY)
235 ReShadeSetConfigArray(
nullptr, runtime, section, key, value, value_size);
237 static const auto func =
reinterpret_cast<void(*)(HMODULE,
api::effect_runtime *,
const char *,
const char *,
const char *,
size_t)
>(
249 inline bool register_addon(HMODULE addon_module, [[maybe_unused]] HMODULE reshade_module =
nullptr)
251 #if defined(RESHADE_API_LIBRARY)
257 if (reshade_module ==
nullptr)
260 const auto func =
reinterpret_cast<bool(*)(HMODULE, uint32_t)
>(
261 GetProcAddress(reshade_module,
"ReShadeRegisterAddon"));
266 #if defined(IMGUI_VERSION_NUM)
267 const auto imgui_func =
reinterpret_cast<const imgui_function_table *(*)(uint32_t)
>(
268 GetProcAddress(reshade_module,
"ReShadeGetImGuiFunctionTable"));
270 if (imgui_func ==
nullptr || !(imgui_function_table_instance() = imgui_func(IMGUI_VERSION_NUM)))
283 inline void unregister_addon(HMODULE addon_module, [[maybe_unused]] HMODULE reshade_module =
nullptr)
285 #if defined(RESHADE_API_LIBRARY)
286 ReShadeUnregisterAddon(addon_module);
291 if (reshade_module ==
nullptr)
294 const auto func =
reinterpret_cast<bool(*)(HMODULE)
>(
295 GetProcAddress(reshade_module,
"ReShadeUnregisterAddon"));
307 template <addon_event ev>
310 #if defined(RESHADE_API_LIBRARY)
311 ReShadeRegisterEvent(ev,
static_cast<void *
>(callback));
313 static const auto func =
reinterpret_cast<void(*)(
addon_event,
void *)
>(
316 func(ev,
static_cast<void *
>(callback));
324 template <addon_event ev>
327 #if defined(RESHADE_API_LIBRARY)
328 ReShadeUnregisterEvent(ev,
static_cast<void *
>(callback));
330 static const auto func =
reinterpret_cast<void(*)(
addon_event,
void *)
>(
333 func(ev,
static_cast<void *
>(callback));
345 #if defined(RESHADE_API_LIBRARY)
346 ReShadeRegisterOverlay(title, callback);
348 static const auto func =
reinterpret_cast<void(*)(
const char *,
void(*)(
api::effect_runtime *))
>(
351 func(title, callback);
361 #if defined(RESHADE_API_LIBRARY)
362 ReShadeUnregisterOverlay(title, callback);
364 static const auto func =
reinterpret_cast<void(*)(
const char *,
void(*)(
api::effect_runtime *))
>(
367 func(title, callback);
383 #if defined(RESHADE_API_LIBRARY)
384 return ReShadeCreateEffectRuntime(api, device, command_queue, swapchain, config_path, out_runtime);
390 *out_runtime =
nullptr;
393 return func(api, device, command_queue, swapchain, config_path, out_runtime);
402 #if defined(RESHADE_API_LIBRARY)
403 ReShadeDestroyEffectRuntime(runtime);
417 #if defined(RESHADE_API_LIBRARY)
418 ReShadeUpdateAndPresentEffectRuntime(runtime);
device_api
Underlying graphics API a device is using.
Definition: reshade_api_device.hpp:17
HMODULE get_current_module_handle(HMODULE initial_handle=nullptr)
Gets the handle to the current add-on module.
Definition: reshade.hpp:89
HMODULE get_reshade_module_handle(HMODULE initial_handle=nullptr)
Gets the handle to the ReShade module.
Definition: reshade.hpp:61
level
Severity levels for logging.
Definition: reshade.hpp:107
void message(level level, const char *message)
Writes a message to ReShade's log.
Definition: reshade.hpp:131
Definition: reshade.hpp:56
void unregister_event(typename addon_event_traits< ev >::decl callback)
Unregisters a callback from the specified event that was previously registered via register_event.
Definition: reshade.hpp:325
void register_event(typename addon_event_traits< ev >::decl callback)
Registers a callback for the specified event with ReShade.
Definition: reshade.hpp:308
addon_event
Definition: reshade_events.hpp:13
bool get_config_value(api::effect_runtime *runtime, const char *section, const char *key, char *value, size_t *value_size)
Gets a value from one of ReShade's config files. This can use either the global config file (ReShade....
Definition: reshade.hpp:170
void get_reshade_base_path(char *path, size_t *path_size)
Gets the base path ReShade uses to resolve relative paths.
Definition: reshade.hpp:149
bool create_effect_runtime(reshade::api::device_api api, void *device, void *command_queue, void *swapchain, const char *config_path, reshade::api::effect_runtime **out_runtime)
Creates a new effect runtime for an existing swapchain, for when it was not already hooked by ReShade...
Definition: reshade.hpp:381
void unregister_addon(HMODULE addon_module, [[maybe_unused]] HMODULE reshade_module=nullptr)
Unregisters this module as an add-on. Call this in 'AddonUninit' or 'DllMain' during process detach,...
Definition: reshade.hpp:283
void update_and_present_effect_runtime(api::effect_runtime *runtime)
Updates and renders an effect runtime onto the current back buffer of the swap chain it was created w...
Definition: reshade.hpp:415
void set_config_value(api::effect_runtime *runtime, const char *section, const char *key, const char *value)
Sets and saves a value in one of ReShade's config files. This can use either the global config file (...
Definition: reshade.hpp:208
bool register_addon(HMODULE addon_module, [[maybe_unused]] HMODULE reshade_module=nullptr)
Registers this module as an add-on with ReShade. Call this in 'AddonInit' or 'DllMain' during process...
Definition: reshade.hpp:249
void unregister_overlay(const char *title, void(*callback)(api::effect_runtime *runtime))
Unregisters an overlay that was previously registered via register_overlay.
Definition: reshade.hpp:359
void destroy_effect_runtime(api::effect_runtime *runtime)
Instantly destroys an effect runtime that was previously created via create_effect_runtime....
Definition: reshade.hpp:400
void register_overlay(const char *title, void(*callback)(api::effect_runtime *runtime))
Registers an overlay with ReShade.
Definition: reshade.hpp:343
BOOL WINAPI K32EnumProcessModules(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded)
#define RESHADE_API_VERSION
Definition: reshade.hpp:14
A post-processing effect runtime, used to control effects.
Definition: reshade_api.hpp:51