|
9 | 9 | #include "DetourModKit/async_logger.hpp" |
10 | 10 |
|
11 | 11 | #include <functional> |
| 12 | +#include <span> |
12 | 13 | #include <string> |
13 | 14 | #include <string_view> |
14 | 15 |
|
@@ -125,6 +126,81 @@ namespace DetourModKit |
125 | 126 | * after on_dll_detach(). |
126 | 127 | */ |
127 | 128 | [[nodiscard]] HMODULE module_handle() noexcept; |
| 129 | + |
| 130 | + /** |
| 131 | + * @brief Drops the per-Logic-DLL state owned by the caller. |
| 132 | + * @details Composes HookManager::remove_hook for every entry in |
| 133 | + * @p hook_names and InputManager::remove_binding_by_name |
| 134 | + * for every entry in @p binding_names. Names that do not |
| 135 | + * exist are skipped (logged at Debug). Idempotent: a |
| 136 | + * second call with the same names is a no-op. |
| 137 | + * |
| 138 | + * Does NOT touch Logger or Config: callers that share a |
| 139 | + * host process across multiple Logic-DLL incarnations |
| 140 | + * want those subsystems to outlive the unload. Use |
| 141 | + * DMK_Shutdown() for whole-process teardown. |
| 142 | + * |
| 143 | + * Safe to call from any thread except: must NOT be |
| 144 | + * called from the InputPoller thread (would self-join) |
| 145 | + * and must NOT be called from a HookManager mutator |
| 146 | + * callback (would deadlock on m_mutator_gate). |
| 147 | + * |
| 148 | + * Marked noexcept because consumers may invoke it from a |
| 149 | + * DllMain detach path. Internal allocations performed |
| 150 | + * while iterating the name spans (vector growth, log |
| 151 | + * formatting) may throw; every throw site is caught and |
| 152 | + * logged so no exception propagates to the caller. |
| 153 | + * |
| 154 | + * @param hook_names Names of hooks installed via HookManager. |
| 155 | + * @param binding_names Names of input bindings registered via |
| 156 | + * InputManager (or via Config::register_press_combo). |
| 157 | + */ |
| 158 | + void on_logic_dll_unload(std::span<const std::string_view> hook_names, |
| 159 | + std::span<const std::string_view> binding_names) noexcept; |
| 160 | + |
| 161 | + /** |
| 162 | + * @brief Drops every hook and binding registered through the |
| 163 | + * process-wide singletons. |
| 164 | + * @details Composes HookManager::remove_all_hooks with |
| 165 | + * InputManager::clear_bindings under the same |
| 166 | + * loader-lock-safe, idempotent, exception-swallowing |
| 167 | + * contract as the named-list overload. Use when the |
| 168 | + * caller does not maintain an explicit registry of |
| 169 | + * hook or binding names. |
| 170 | + * |
| 171 | + * Logger, Config, and the ConfigWatcher are |
| 172 | + * intentionally left running, matching the named-list |
| 173 | + * overload's partition between per-Logic-DLL state and |
| 174 | + * host-owned infrastructure. Use DMK_Shutdown() for |
| 175 | + * whole-process teardown. |
| 176 | + * |
| 177 | + * The HookManager teardown call is remove_all_hooks(), |
| 178 | + * not shutdown(): both perform the same two-phase |
| 179 | + * drain, but remove_all_hooks() resets the shutdown |
| 180 | + * flag at the end so subsequent create_*_hook() calls |
| 181 | + * succeed for the next Logic-DLL incarnation. The |
| 182 | + * binding teardown call is clear_bindings(), not |
| 183 | + * shutdown(): the poller keeps running idle and is |
| 184 | + * ready to accept fresh bindings on the next attach. |
| 185 | + * |
| 186 | + * Safe to call from any thread except: must NOT be |
| 187 | + * called from the InputPoller thread (would self-join) |
| 188 | + * and must NOT be called from a HookManager mutator |
| 189 | + * callback (would deadlock on m_mutator_gate). |
| 190 | + * |
| 191 | + * Marked noexcept because consumers may invoke it from |
| 192 | + * a DllMain detach path. Internal allocations performed |
| 193 | + * while logging or rebuilding active_states_ may throw; |
| 194 | + * every throw site is caught and logged so no exception |
| 195 | + * propagates to the caller. |
| 196 | + * |
| 197 | + * @warning In a host that loads multiple Logic DLLs sharing one |
| 198 | + * process-wide DMK instance, calling this from one |
| 199 | + * Logic DLL's Shutdown() rips out the other Logic DLLs' |
| 200 | + * hooks and bindings as well. The named-list overload |
| 201 | + * is the correct choice in that topology. |
| 202 | + */ |
| 203 | + void on_logic_dll_unload_all() noexcept; |
128 | 204 | } // namespace Bootstrap |
129 | 205 | } // namespace DetourModKit |
130 | 206 |
|
|
0 commit comments