├── .gitignore
├── DirectXHook.sln
├── DirectXHook.vcxproj
├── DirectXHook.vcxproj.filters
├── DirectXHook.vcxproj.user
├── README.md
├── assets
├── hook_fonts
│ └── OpenSans-22.spritefont
├── hook_textures
│ └── blank.jpg
└── repo_pictures
│ ├── box_struct.png
│ ├── create_files.png
│ ├── dllmain.png
│ ├── er_first_person_souls.png
│ ├── er_pause_the_game.png
│ ├── example_header.png
│ ├── example_source.png
│ ├── rgb_boxes.png
│ ├── rgb_boxes_code.png
│ ├── text.png
│ ├── text_code.png
│ ├── textures.png
│ └── textures_code.png
├── include
├── DirectXHook.h
├── ID3DRenderer.h
├── IRenderCallback.h
├── Logger.h
├── MemoryUtils.h
├── OverlayFramework.h
├── Renderer.h
├── UniversalProxyDLL.h
└── nmd_assembly.h
├── overlays
├── Example
│ ├── Example.cpp
│ └── Example.h
├── PauseTheGame
│ ├── PauseTheGame.cpp
│ └── PauseTheGame.h
└── RiseDpsMeter
│ ├── RiseDpsMeter.cpp
│ └── RiseDpsMeter.h
├── packages.config
└── src
├── DirectXHook.cpp
├── DllMain.cpp
├── Renderer.cpp
└── Shaders.hlsl
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs
2 | packages/
3 | x64/
4 | x86/
5 | Debug/
6 | Release/
7 |
--------------------------------------------------------------------------------
/DirectXHook.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.31205.134
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXHook", "DirectXHook.vcxproj", "{5EB93C8A-65BB-403D-A8B5-A39FCF98F17F}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {5EB93C8A-65BB-403D-A8B5-A39FCF98F17F}.Debug|x64.ActiveCfg = Debug|x64
17 | {5EB93C8A-65BB-403D-A8B5-A39FCF98F17F}.Debug|x64.Build.0 = Debug|x64
18 | {5EB93C8A-65BB-403D-A8B5-A39FCF98F17F}.Debug|x86.ActiveCfg = Debug|Win32
19 | {5EB93C8A-65BB-403D-A8B5-A39FCF98F17F}.Debug|x86.Build.0 = Debug|Win32
20 | {5EB93C8A-65BB-403D-A8B5-A39FCF98F17F}.Release|x64.ActiveCfg = Release|x64
21 | {5EB93C8A-65BB-403D-A8B5-A39FCF98F17F}.Release|x64.Build.0 = Release|x64
22 | {5EB93C8A-65BB-403D-A8B5-A39FCF98F17F}.Release|x86.ActiveCfg = Release|Win32
23 | {5EB93C8A-65BB-403D-A8B5-A39FCF98F17F}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {B1B72F8D-E60B-4269-AC0B-EAC732492566}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/DirectXHook.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 16.0
23 | Win32Proj
24 | {5eb93c8a-65bb-403d-a8b5-a39fcf98f17f}
25 | DirectXHook
26 | 10.0
27 |
28 |
29 |
30 | DynamicLibrary
31 | true
32 | MultiByte
33 | v143
34 |
35 |
36 | DynamicLibrary
37 | false
38 | true
39 | MultiByte
40 | v143
41 |
42 |
43 | DynamicLibrary
44 | true
45 | MultiByte
46 | v143
47 |
48 |
49 | DynamicLibrary
50 | false
51 | true
52 | MultiByte
53 | v143
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | false
74 | dinput8
75 | $(SolutionDir)overlays;$(SolutionDir)include;$(IncludePath)
76 | $(SolutionDir)overlays;$(SolutionDir)src
77 |
78 |
79 | false
80 | dinput8
81 | $(SolutionDir)overlays;$(SolutionDir)include;$(IncludePath)
82 | $(SolutionDir)overlays;$(SolutionDir)src
83 |
84 |
85 | false
86 | $(SolutionDir)overlays;$(SolutionDir)include;$(IncludePath)
87 | $(SolutionDir)overlays;$(SolutionDir)src
88 | dinput8
89 |
90 |
91 | false
92 | $(SolutionDir)overlays;$(SolutionDir)include;$(IncludePath)
93 | $(SolutionDir)overlays;$(SolutionDir)src
94 | .dll
95 | dinput8
96 | true
97 |
98 |
99 |
100 | Level3
101 | true
102 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
103 | true
104 | MultiThreadedDLL
105 | stdcpp17
106 |
107 |
108 | Windows
109 | true
110 |
111 |
112 | d3d11.lib;d3d12.lib;d3dcompiler.lib;%(AdditionalDependencies)
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 | Level3
122 | true
123 | true
124 | true
125 | _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;NDEBUG;_CONSOLE
126 | true
127 | MultiThreadedDLL
128 | stdcpp17
129 |
130 |
131 | Windows
132 | true
133 | true
134 | false
135 |
136 |
137 | d3d11.lib;d3d12.lib;d3dcompiler.lib;%(AdditionalDependencies)
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 | Level3
147 | true
148 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions);_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
149 | true
150 | MultiThreadedDebug
151 | stdcpp17
152 |
153 |
154 | Windows
155 | true
156 |
157 |
158 | d3d11.lib;d3d12.lib;d3dcompiler.lib;%(AdditionalDependencies)
159 |
160 |
161 | COPY "C:\Programming\Github repositories\DirectXHook\x64\Release\dinput8.dll" "G:\SteamLibrary\steamapps\common\MonsterHunterRise\reframework\plugins\RiseDpsMeter.dll"
162 |
163 |
164 |
165 |
166 | Level3
167 | true
168 | true
169 | true
170 | _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;NDEBUG;_CONSOLE
171 | true
172 | MultiThreadedDLL
173 | stdcpp17
174 |
175 |
176 | Windows
177 | true
178 | true
179 | false
180 |
181 |
182 | d3d11.lib;d3d12.lib;d3dcompiler.lib;%(AdditionalDependencies)
183 |
184 |
185 | COPY "C:\Programming\Github repositories\DirectXHook\x64\Release\dinput8.dll" "F:\SteamLibrary\steamapps\common\ELDEN RING\Game\dinput8.dll"
186 | XCOPY /y "C:\Programming\Github repositories\DirectXHook\assets\hook_textures" "F:\SteamLibrary\steamapps\common\ELDEN RING\Game\hook_textures\"
187 | XCOPY /y "C:\Programming\Github repositories\DirectXHook\assets\hook_fonts" "F:\SteamLibrary\steamapps\common\ELDEN RING\Game\hook_fonts\"
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 | false
196 |
197 |
198 | false
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 | true
208 | true
209 | true
210 | true
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 | false
224 |
225 |
226 | false
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
237 |
238 |
239 |
240 |
241 |
--------------------------------------------------------------------------------
/DirectXHook.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {4e722490-89b1-476c-8f11-f855725e5074}
14 |
15 |
16 | {8a12ed8f-5e32-450f-8ec9-985d3e5cde32}
17 |
18 |
19 | {f65c6413-9861-46d0-ac93-cc3206db7958}
20 |
21 |
22 | {49480136-b55a-468a-b6ab-1720b97d7141}
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | Source Files
31 |
32 |
33 | Source Files
34 |
35 |
36 | Source Files
37 |
38 |
39 | Overlays\Example
40 |
41 |
42 | Overlays\PauseTheGame
43 |
44 |
45 | Overlays\RiseDpsMeter
46 |
47 |
48 |
49 |
50 | Source Files
51 |
52 |
53 |
54 |
55 | Header Files
56 |
57 |
58 | Header Files
59 |
60 |
61 | Header Files
62 |
63 |
64 | Header Files
65 |
66 |
67 | Header Files
68 |
69 |
70 | Header Files
71 |
72 |
73 | Overlays\Example
74 |
75 |
76 | Overlays\RiseDpsMeter
77 |
78 |
79 | Overlays\PauseTheGame
80 |
81 |
82 | Header Files
83 |
84 |
85 | Header Files
86 |
87 |
88 |
--------------------------------------------------------------------------------
/DirectXHook.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | G:\SteamLibrary\steamapps\common\ELDEN RING\Game\eldenring.exe
5 | true
6 | WindowsLocalDebugger
7 |
8 |
9 | G:\SteamLibrary\steamapps\common\ELDEN RING\Game\eldenring.exe
10 | true
11 | WindowsLocalDebugger
12 |
13 |
14 | G:\SteamLibrary\steamapps\common\ELDEN RING\Game\eldenring.exe
15 | WindowsLocalDebugger
16 | true
17 |
18 |
19 | G:\SteamLibrary\steamapps\common\ELDEN RING\Game\eldenring.exe
20 | WindowsLocalDebugger
21 | true
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## DirectXHook + Overlay Framework
2 | A DirectX hook that works with DirectX11 and DirectX12 in 32-bit and 64-bit modes.
3 |
4 | Basically this library lets you render your own things inside the game window, as an integrated part of the game rather than as an external overlay. A straightforward but primitive overlay framework is included so you can quickly and easily start creating overlays. Tutorial below.
5 |
6 | ### This library is used in...
7 | #### A mod for Elden Ring, ["First Person Souls - Full Game Conversion found on NexusMods"](https://www.nexusmods.com/eldenring/mods/3266)
8 |
9 | [](https://www.youtube.com/watch?v=nuau_lZ0Imc)
10 |
11 | #### A mod for Elden Ring, ["Pause the game" found on NexusMods](https://www.nexusmods.com/eldenring/mods/43)
12 |
13 | [](https://www.youtube.com/watch?v=xvK1ti_hHh4)
14 |
15 | #### A mod for Monster Hunter Rise, ["Rise DPS Meter" found on NexusMods](https://www.nexusmods.com/monsterhunterrise/mods/289)
16 |
17 | -video to be added-
18 |
19 | #### Example triangle
20 |
21 | -video to be added-
22 |
23 | ## How to create an overlay
24 | First, check the [wiki page](https://github.com/techiew/DirectXHook/wiki/How-to-set-up-the-Visual-Studio-solution) on how to quickly set up the Visual Studio solution.
25 |
26 | When the project is built, "dinput8.dll" will be generated in the project folder. This must be copied next to a game executable which uses DirectX 11 or 12. The game will then load the .dll automatically on startup and will render what you told it to.
27 |
28 | Also note that the "hook_textures" folder containing "blank.jpg" must be present next to dxgi.dll in order for anything to render.
29 |
30 | ### Create files
31 | Create a .cpp and .h file in the Overlays folder (optionally put these inside a parent folder):
32 |
33 | 
34 |
35 | Create a class that inherits from the IRenderCallback interface and includes "OverlayFramework.h":
36 |
37 | 
38 |
39 | Define the Setup() and Render() functions in the .cpp file:
40 |
41 | 
42 |
43 | **Note: Setup() is called once and Render() is called every frame. InitFramework() must be called on the very first line in Setup().**
44 |
45 | Make the hook render your stuff by adding these lines in DllMain.cpp:
46 |
47 | 
48 |
49 | But we have yet to define anything to render...
50 |
51 | ### Boxes
52 | All rendering with the overlay framework is done using Boxes:
53 |
54 | 
55 |
56 | Boxes are a simple struct with data that the framework manages.
57 |
58 | - **pressed** = if the mouse is currently being pressed on this box
59 | - **clicked** = if the mouse was previously pressed and then released on the box this frame
60 | - **hover** = if the mouse is hovering over the box
61 |
62 | The rest are self-explanatory. Do not modify **visible** or **z**.
63 |
64 | Create some boxes and render them:
65 |
66 | 
67 |
68 | Result:
69 |
70 | 
71 |
72 | Boxes can be rendered with either textures or colors:
73 |
74 | 
75 |
76 | **Note: textures should be loaded in Setup().**
77 |
78 | Result:
79 |
80 | 
81 |
82 | Text can be rendered inside Boxes:
83 |
84 | 
85 |
86 | **Note: a font must be set before rendering text.**
87 |
88 | Result:
89 |
90 | 
91 |
92 | ### Contributions
93 | Feel free to create issues or contribute code to the repo.
94 |
95 | ### License
96 | Feel free to use this code for anything and however you like, but if you create something with it then it would be cool if you could show me what you made :)
97 |
98 |
--------------------------------------------------------------------------------
/assets/hook_fonts/OpenSans-22.spritefont:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/hook_fonts/OpenSans-22.spritefont
--------------------------------------------------------------------------------
/assets/hook_textures/blank.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/hook_textures/blank.jpg
--------------------------------------------------------------------------------
/assets/repo_pictures/box_struct.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/box_struct.png
--------------------------------------------------------------------------------
/assets/repo_pictures/create_files.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/create_files.png
--------------------------------------------------------------------------------
/assets/repo_pictures/dllmain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/dllmain.png
--------------------------------------------------------------------------------
/assets/repo_pictures/er_first_person_souls.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/er_first_person_souls.png
--------------------------------------------------------------------------------
/assets/repo_pictures/er_pause_the_game.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/er_pause_the_game.png
--------------------------------------------------------------------------------
/assets/repo_pictures/example_header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/example_header.png
--------------------------------------------------------------------------------
/assets/repo_pictures/example_source.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/example_source.png
--------------------------------------------------------------------------------
/assets/repo_pictures/rgb_boxes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/rgb_boxes.png
--------------------------------------------------------------------------------
/assets/repo_pictures/rgb_boxes_code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/rgb_boxes_code.png
--------------------------------------------------------------------------------
/assets/repo_pictures/text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/text.png
--------------------------------------------------------------------------------
/assets/repo_pictures/text_code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/text_code.png
--------------------------------------------------------------------------------
/assets/repo_pictures/textures.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/textures.png
--------------------------------------------------------------------------------
/assets/repo_pictures/textures_code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiew/DirectXHook/2fcd7487298d772f0e3bbf3ead4441422f58d6ed/assets/repo_pictures/textures_code.png
--------------------------------------------------------------------------------
/include/DirectXHook.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | #include "Renderer.h"
8 | #include "ID3DRenderer.h"
9 | #include "IRenderCallback.h"
10 | #include "Logger.h"
11 | #include "MemoryUtils.h"
12 |
13 | /*
14 | * Here we have typedefs of the functions we want to hook.
15 | * They are defined so we can call the respective functions through pointers to their memory addresses.
16 | *
17 | * Setting the proper calling convention is important (__stdcall).
18 | * It makes it so the function arguments are read/written to/from memory in the correct way.
19 | * 64-bit functions actually use the __fastcall calling convention, but the compiler changes
20 | * __stdcall to __fastcall automatically for 64-bit compilation.
21 | */
22 | typedef HRESULT(__stdcall* Present)(IDXGISwapChain* This, UINT SyncInterval, UINT Flags);
23 | typedef HRESULT(__stdcall* ResizeBuffers)(IDXGISwapChain* This, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags);
24 | typedef void(__stdcall* ExecuteCommandLists)(ID3D12CommandQueue* This, UINT NumCommandLists, const ID3D12CommandList** ppCommandLists);
25 |
26 | // Hooks DirectX 11 and DirectX 12
27 | class DirectXHook
28 | {
29 | public:
30 | ID3DRenderer* renderer;
31 | uintptr_t executeCommandListsAddress = 0;
32 | uintptr_t presentReturnAddress = 0;
33 | uintptr_t resizeBuffersReturnAddress = 0;
34 | uintptr_t executeCommandListsReturnAddress = 0;
35 |
36 | DirectXHook(ID3DRenderer* renderer);
37 | void Hook();
38 | void SetDrawExampleTriangle(bool doDraw);
39 | void AddRenderCallback(IRenderCallback* object);
40 | ID3D12CommandQueue* CreateDummyCommandQueue();
41 | void HookCommandQueue(ID3D12CommandQueue* dummyCommandQueue, uintptr_t executeCommandListsDetourFunction, uintptr_t* executeCommandListsReturnAddress);
42 | void UnhookCommandQueue();
43 |
44 | private:
45 | Logger logger{ "DirectXHook" };
46 |
47 | IDXGISwapChain* CreateDummySwapChain();
48 | void HookSwapChain(IDXGISwapChain* dummySwapChain, uintptr_t presentDetourFunction, uintptr_t resizeBuffersDetourFunction, uintptr_t* presentReturnAddress, uintptr_t* resizeBuffersReturnAddress);
49 | };
--------------------------------------------------------------------------------
/include/ID3DRenderer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include "IRenderCallback.h"
6 |
7 | class ID3DRenderer
8 | {
9 | public:
10 | virtual void OnPresent(IDXGISwapChain* pThis, UINT syncInterval, UINT flags) = 0;
11 | virtual void OnResizeBuffers(IDXGISwapChain* pThis, UINT bufferCount, UINT width, UINT height, DXGI_FORMAT newFormat, UINT swapChainFlags) {};
12 | virtual void AddRenderCallback(IRenderCallback* object) {};
13 | virtual void SetCommandQueue(ID3D12CommandQueue* commandQueue) {};
14 | virtual void SetGetCommandQueueCallback(void (*callback)()) {};
15 | };
--------------------------------------------------------------------------------
/include/IRenderCallback.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | class IRenderCallback
9 | {
10 | public:
11 | virtual void Setup() { };
12 | virtual void Render() = 0;
13 | void Init(
14 | Microsoft::WRL::ComPtr device,
15 | Microsoft::WRL::ComPtr context,
16 | std::shared_ptr spriteBatch,
17 | HWND window)
18 | {
19 | this->device = device;
20 | this->context = context;
21 | this->spriteBatch = spriteBatch;
22 | this->window = window;
23 | }
24 |
25 | protected:
26 | Microsoft::WRL::ComPtr device = nullptr;
27 | Microsoft::WRL::ComPtr context = nullptr;
28 | std::shared_ptr spriteBatch = nullptr;
29 | HWND window = NULL;
30 | };
--------------------------------------------------------------------------------
/include/Logger.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | class Logger
7 | {
8 | public:
9 | Logger(const char* prefix)
10 | {
11 | printPrefix = prefix;
12 |
13 | FILE* logFile = GetLogFile();
14 | if (logFile == nullptr)
15 | {
16 | fopen_s(&logFile, "hook_log.txt", "w");
17 | GetLogFile(logFile);
18 | }
19 | }
20 |
21 | void Log(std::string msg, ...)
22 | {
23 | va_list args;
24 | va_start(args, msg);
25 | vprintf(std::string(printPrefix + " > " + msg + "\n").c_str(), args);
26 | if (GetLogFile() != nullptr)
27 | {
28 | vfprintf(GetLogFile(), std::string(printPrefix + " > " + msg + "\n").c_str(), args);
29 | fflush(GetLogFile());
30 | }
31 | va_end(args);
32 | }
33 |
34 | private:
35 | std::string printPrefix = "";
36 |
37 | static FILE* GetLogFile(FILE* newLogFile = nullptr)
38 | {
39 | static FILE* logFile = nullptr;
40 | if (newLogFile != nullptr)
41 | {
42 | logFile = newLogFile;
43 | }
44 | return logFile;
45 | }
46 | };
--------------------------------------------------------------------------------
/include/MemoryUtils.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include