|
| 1 | +/** |
| 2 | + * CoHModSDK - The lightweight modding SDK for Company of Heroes |
| 3 | + * Copyright (c) 2026 Tosox |
| 4 | + * |
| 5 | + * This project is licensed under the Creative Commons |
| 6 | + * Attribution-NonCommercial-NoDerivatives 4.0 International License |
| 7 | + * (CC BY-NC-ND 4.0) with additional permissions. |
| 8 | + * |
| 9 | + * Independent mods using this project only through its public interfaces |
| 10 | + * are not required to use CC BY-NC-ND 4.0. |
| 11 | + * |
| 12 | + * See the repository root LICENSE file for the full license text and |
| 13 | + * additional permissions. |
| 14 | + */ |
| 15 | + |
1 | 16 | #pragma once |
2 | 17 |
|
3 | 18 | #include <Windows.h> |
4 | 19 | #include <cstddef> |
5 | 20 | #include <cstdint> |
6 | 21 |
|
7 | 22 | extern "C" { |
8 | | - // Called once when ModSDK loads the mod |
| 23 | + /** |
| 24 | + * @brief Called once when the SDK loads the mod DLL. |
| 25 | + * |
| 26 | + * Perform any early setup required for the mod here (e.g., install hooks, patch memory). |
| 27 | + */ |
9 | 28 | __declspec(dllexport) void OnSDKLoad(); |
10 | 29 |
|
11 | | - // Called when the game is starting (after mod load) |
| 30 | + /** |
| 31 | + * @brief Called when the game is starting (after all mods have been loaded). |
| 32 | + * |
| 33 | + * Use this to initialize features that require the game to be fully running. |
| 34 | + */ |
12 | 35 | __declspec(dllexport) void OnGameStart(); |
13 | 36 |
|
14 | | - // Called when the game is shutting down |
| 37 | + /** |
| 38 | + * @brief Called when the game is shutting down. |
| 39 | + * |
| 40 | + * Use this to clean up any hooks, memory patches, or resources before unloading. |
| 41 | + */ |
15 | 42 | __declspec(dllexport) void OnGameShutdown(); |
16 | 43 |
|
17 | | - // Mod metadata |
| 44 | + /** |
| 45 | + * @brief Returns the display name of the mod. |
| 46 | + * |
| 47 | + * @return const char* - Name of the mod. |
| 48 | + */ |
18 | 49 | __declspec(dllexport) const char* GetModName(); |
| 50 | + |
| 51 | + /** |
| 52 | + * @brief Returns the version string of the mod. |
| 53 | + * |
| 54 | + * @return const char* - Version of the mod. |
| 55 | + */ |
19 | 56 | __declspec(dllexport) const char* GetModVersion(); |
| 57 | + |
| 58 | + /** |
| 59 | + * @brief Returns the author name(s) of the mod. |
| 60 | + * |
| 61 | + * @return const char* - Author or team name. |
| 62 | + */ |
20 | 63 | __declspec(dllexport) const char* GetModAuthor(); |
21 | 64 | } |
22 | 65 |
|
23 | 66 | namespace ModSDK { |
24 | 67 | namespace Memory { |
25 | | - std::uintptr_t FindPattern(const char* moduleName, const char* signature, bool reportError = true); |
| 68 | + /** |
| 69 | + * @brief Returns a handle to the module that contains the original game code. |
| 70 | + * |
| 71 | + * @return HMODULE - Handle to `WW2Mod.original.dll` with fallback to `WW2Mod.dll`. |
| 72 | + */ |
| 73 | + HMODULE GetGameModuleHandle(); |
| 74 | + |
| 75 | + /** |
| 76 | + * @brief Scans a module for a byte pattern signature. |
| 77 | + * |
| 78 | + * Use `GetGameModuleHandle()` when you want to scan the original game module. |
| 79 | + * |
| 80 | + * @param moduleHandle Handle to the module to scan. |
| 81 | + * @param signature Pattern string (e.g., "48 8B ?? ?? ?? ?? ?? 48 8B"). |
| 82 | + * @param reportError Whether to show an error if the pattern is not found. |
| 83 | + * @return std::uintptr_t Address where the pattern was found or 0 if not found. |
| 84 | + */ |
| 85 | + std::uintptr_t FindPattern(HMODULE moduleHandle, const char* signature, bool reportError = true); |
| 86 | + |
| 87 | + /** |
| 88 | + * @brief Patches memory by copying bytes to a destination address. |
| 89 | + * |
| 90 | + * Automatically changes memory protection to allow writing. |
| 91 | + * |
| 92 | + * @param destination Target address to patch. |
| 93 | + * @param source Bytes to write. |
| 94 | + * @param size Number of bytes to copy. |
| 95 | + */ |
26 | 96 | void PatchMemory(void* destination, const void* source, std::size_t size); |
27 | 97 | } |
28 | 98 |
|
29 | 99 | namespace Hooks { |
| 100 | + /** |
| 101 | + * @brief Creates a hook from a target function to a detour function. |
| 102 | + * |
| 103 | + * @param targetFunction Pointer to the function to hook. |
| 104 | + * @param detourFunction Pointer to the custom function (your detour). |
| 105 | + * @param originalFunction Out parameter; will store the pointer to call original later. |
| 106 | + * @return true if the hook was created successfully, false otherwise. |
| 107 | + */ |
30 | 108 | bool CreateHook(void* targetFunction, void* detourFunction, void** originalFunction); |
| 109 | + |
| 110 | + /** |
| 111 | + * @brief Enables an individual installed hook. |
| 112 | + * |
| 113 | + * @param targetFunction Pointer to the function where a hook was created. |
| 114 | + * @return true if successfully enabled, false otherwise. |
| 115 | + */ |
31 | 116 | bool EnableHook(void* targetFunction); |
| 117 | + |
| 118 | + /** |
| 119 | + * @brief Enables all hooks created by the SDK. |
| 120 | + * |
| 121 | + * @return true if successful, false otherwise. |
| 122 | + */ |
32 | 123 | bool EnableAllHooks(); |
| 124 | + |
| 125 | + /** |
| 126 | + * @brief Disables an individual hook. |
| 127 | + * |
| 128 | + * @param targetFunction Pointer to the hooked function. |
| 129 | + * @return true if successfully disabled, false otherwise. |
| 130 | + */ |
33 | 131 | bool DisableHook(void* targetFunction); |
| 132 | + |
| 133 | + /** |
| 134 | + * @brief Disables all active hooks created by the SDK. |
| 135 | + * |
| 136 | + * @return true if successful, false otherwise. |
| 137 | + */ |
34 | 138 | bool DisableAllHooks(); |
35 | 139 | } |
36 | 140 | } |
0 commit comments