aboutsummaryrefslogtreecommitdiff
path: root/Hook/Hook.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Hook/Hook.cpp')
-rw-r--r--Hook/Hook.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/Hook/Hook.cpp b/Hook/Hook.cpp
new file mode 100644
index 0000000..201bede
--- /dev/null
+++ b/Hook/Hook.cpp
@@ -0,0 +1,52 @@
+#include "pch.h"
+#include <Windows.h>
+#include <detours.h>
+#include <string>
+#include <fstream>
+#include <intrin.h>
+
+int cvarCallIndex = 0;
+FILE* csvFile;
+
+std::string handleString(char* input)
+{
+ if (input == 0) return ""; // return empty string if it was a nullptr
+ std::string replacement = input;
+ std::size_t found = replacement.find("\"");
+ while (found != std::string::npos) { // escape double quotes by doubling them
+ replacement.replace(found, 1, "\"\"");
+ found = replacement.find("\"", found + 2);
+ }
+ return replacement;
+}
+
+void* CVar__Register = (void*)0x00767fc0;
+UINT32 __cdecl CVar__Register__Hook(char* name, char* description, UINT32 flags, char* defaultValue, PVOID callback, UINT32 category, BYTE saveToWTF, UINT32 param_8, BYTE param_9)
+{
+ void* callAddress = (void*)((uintptr_t)_ReturnAddress() - 5); // subtracting the length of a CALL instruction to find out where we have been called from
+ fprintf_s(csvFile, R"(%s"%i", "%p", "%s", "%s", "%i", "%s", "%p", "%i", "%hhu", "%i", "%hhu")", "\n", cvarCallIndex, callAddress, handleString(name).c_str(), handleString(description).c_str(), flags, defaultValue, callback, category, saveToWTF, param_8, param_9);
+ cvarCallIndex++;
+ return ((decltype(&CVar__Register__Hook))CVar__Register)(name, description, flags, defaultValue, callback, category, saveToWTF, param_8, param_9);
+}
+
+BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
+{
+ if (DetourIsHelperProcess()) return TRUE;
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ fopen_s(&csvFile, "CVar__Register_calls_3.3.5.12340.csv", "w");
+ if (csvFile == 0) return -1;
+ fprintf_s(csvFile, R"("Index", "Call Address", "Name", "Description", "Flags", "Default Value", "Callback Address", "Category", "Save To WTF", "param_8", "param_9")");
+ DetourRestoreAfterWith();
+ DetourTransactionBegin();
+ DetourUpdateThread(GetCurrentThread());
+ DetourAttach(&CVar__Register, CVar__Register__Hook);
+ if (DetourTransactionCommit() != NO_ERROR) MessageBoxA(NULL, "DetourAttach failed", "error", 0);
+ break;
+ case DLL_PROCESS_DETACH:
+ fclose(csvFile);
+ break;
+ }
+ return TRUE;
+}