9 #include "reshade_overlay.hpp"
14 #define RESHADE_API_VERSION 12
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);
50 extern "C" BOOL WINAPI
K32EnumProcessModules(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded);
59 static HMODULE handle = reshade_module;
60 if (handle ==
nullptr)
62 HMODULE modules[1024]; DWORD num = 0;
65 if (num >
sizeof(modules))
66 num =
sizeof(modules);
68 for (DWORD i = 0; i < num /
sizeof(HMODULE); ++i)
70 if (GetProcAddress(modules[i],
"ReShadeRegisterAddon") &&
71 GetProcAddress(modules[i],
"ReShadeUnregisterAddon"))
87 static HMODULE handle = addon_module;
126 #if defined(RESHADE_API_LIBRARY)
127 ReShadeLogMessage(
nullptr,
static_cast<int>(level), message);
129 static const auto func =
reinterpret_cast<void(*)(HMODULE,
int,
const char *)
>(
142 #if defined(RESHADE_API_LIBRARY)
143 ReShadeGetBasePath(path, path_size);
145 static const auto func =
reinterpret_cast<bool(*)(
char *,
size_t *)
>(
147 func(path, path_size);
163 #if defined(RESHADE_API_LIBRARY)
164 return ReShadeGetConfigValue(
nullptr, runtime, section, key, value, value_size);
166 static const auto func =
reinterpret_cast<bool(*)(HMODULE,
api::effect_runtime *,
const char *,
const char *,
char *,
size_t *)
>(
172 template <
typename T>
173 inline bool get_config_value(api::effect_runtime *runtime,
const char *section,
const char *key, T &value)
175 char value_string[32];
size_t value_length =
sizeof(value_string) - 1;
178 return std::from_chars(value_string, value_string + value_length, value).ec == std::errc {};
181 inline bool get_config_value<bool>(api::effect_runtime *runtime,
const char *section,
const char *key,
bool &value)
184 if (!get_config_value<int>(runtime, section, key, value_int))
186 value = (value_int != 0);
201 #if defined(RESHADE_API_LIBRARY)
202 ReShadeSetConfigValue(
nullptr, runtime, section, key, value);
204 static const auto func =
reinterpret_cast<void(*)(HMODULE,
api::effect_runtime *,
const char *,
const char *,
const char *)
>(
210 template <
typename T>
211 inline void set_config_value(api::effect_runtime *runtime,
const char *section,
const char *key,
const T &value)
213 char value_string[32] =
"";
214 std::to_chars(value_string, value_string +
sizeof(value_string) - 1, value);
215 set_config_value(runtime, section, key,
static_cast<const char *
>(value_string));
218 inline void set_config_value<bool>(api::effect_runtime *runtime,
const char *section,
const char *key,
const bool &value)
220 set_config_value<int>(runtime, section, key, value ? 1 : 0);
225 #if defined(RESHADE_API_LIBRARY)
226 ReShadeSetConfigArray(
nullptr, runtime, section, key, value, value_size);
228 static const auto func =
reinterpret_cast<void(*)(HMODULE,
api::effect_runtime *,
const char *,
const char *,
const char *,
size_t)
>(
240 inline bool register_addon(HMODULE addon_module, [[maybe_unused]] HMODULE reshade_module =
nullptr)
242 #if defined(RESHADE_API_LIBRARY)
248 if (reshade_module ==
nullptr)
251 const auto func =
reinterpret_cast<bool(*)(HMODULE, uint32_t)
>(
252 GetProcAddress(reshade_module,
"ReShadeRegisterAddon"));
257 #if defined(IMGUI_VERSION_NUM)
258 const auto imgui_func =
reinterpret_cast<const imgui_function_table *(*)(uint32_t)
>(
259 GetProcAddress(reshade_module,
"ReShadeGetImGuiFunctionTable"));
261 if (imgui_func ==
nullptr || !(imgui_function_table_instance() = imgui_func(IMGUI_VERSION_NUM)))
274 inline void unregister_addon(HMODULE addon_module, [[maybe_unused]] HMODULE reshade_module =
nullptr)
276 #if defined(RESHADE_API_LIBRARY)
277 ReShadeUnregisterAddon(addon_module);
282 if (reshade_module ==
nullptr)
285 const auto func =
reinterpret_cast<bool(*)(HMODULE)
>(
286 GetProcAddress(reshade_module,
"ReShadeUnregisterAddon"));
298 template <addon_event ev>
301 #if defined(RESHADE_API_LIBRARY)
302 ReShadeRegisterEvent(ev,
static_cast<void *
>(callback));
304 static const auto func =
reinterpret_cast<void(*)(
addon_event,
void *)
>(
307 func(ev,
static_cast<void *
>(callback));
315 template <addon_event ev>
318 #if defined(RESHADE_API_LIBRARY)
319 ReShadeUnregisterEvent(ev,
static_cast<void *
>(callback));
321 static const auto func =
reinterpret_cast<void(*)(
addon_event,
void *)
>(
324 func(ev,
static_cast<void *
>(callback));
336 #if defined(RESHADE_API_LIBRARY)
337 ReShadeRegisterOverlay(title, callback);
339 static const auto func =
reinterpret_cast<void(*)(
const char *,
void(*)(
api::effect_runtime *))
>(
342 func(title, callback);
352 #if defined(RESHADE_API_LIBRARY)
353 ReShadeUnregisterOverlay(title, callback);
355 static const auto func =
reinterpret_cast<void(*)(
const char *,
void(*)(
api::effect_runtime *))
>(
358 func(title, callback);
374 #if defined(RESHADE_API_LIBRARY)
375 return ReShadeCreateEffectRuntime(api, device, command_queue, swapchain, config_path, out_runtime);
381 *out_runtime =
nullptr;
384 return func(api, device, command_queue, swapchain, config_path, out_runtime);
393 #if defined(RESHADE_API_LIBRARY)
394 ReShadeDestroyEffectRuntime(runtime);
408 #if defined(RESHADE_API_LIBRARY)
409 ReShadeUpdateAndPresentEffectRuntime(runtime);
device_api
The underlying render API a device is using, as returned by device::get_api.
Definition: reshade_api_device.hpp:16
HMODULE get_reshade_module_handle(HMODULE reshade_module=nullptr)
Gets the handle to the ReShade module.
Definition: reshade.hpp:57
HMODULE get_current_module_handle(HMODULE addon_module=nullptr)
Gets the handle to the current add-on module.
Definition: reshade.hpp:85
Definition: reshade.hpp:52
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:316
void register_event(typename addon_event_traits< ev >::decl callback)
Registers a callback for the specified event with ReShade.
Definition: reshade.hpp:299
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:161
void get_reshade_base_path(char *path, size_t *path_size)
Gets the base path ReShade uses to resolve relative paths.
Definition: reshade.hpp:140
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:372
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:274
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:406
log_level
Available log severity levels.
Definition: reshade.hpp:100
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:199
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:240
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:350
void log_message(log_level level, const char *message)
Writes a message to ReShade's log.
Definition: reshade.hpp:124
void destroy_effect_runtime(api::effect_runtime *runtime)
Instantly destroys an effect runtime that was previously created via create_effect_runtime....
Definition: reshade.hpp:391
void register_overlay(const char *title, void(*callback)(api::effect_runtime *runtime))
Registers an overlay with ReShade.
Definition: reshade.hpp:334
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