aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/core/hooks.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2023-02-23 00:19:48 +0000
committerGitHub <noreply@github.com>2023-02-23 00:19:48 +0000
commit32165afe41c4cf4d3b261ee7a9c69c369253cc13 (patch)
tree156844485e0e463410d76cbb4c4c7a6cd0042786 /NorthstarDLL/core/hooks.cpp
parent6aaac4cd452878acc59d9748bcd2d0e072d2a432 (diff)
downloadNorthstarLauncher-32165afe41c4cf4d3b261ee7a9c69c369253cc13.tar.gz
NorthstarLauncher-32165afe41c4cf4d3b261ee7a9c69c369253cc13.zip
Add `FUNCTION_AT` and `VAR_AT` macros (#416)
* add FUNCTION_AT and VAR_AT macros * fix build issues oops * fix formatting * add PREDEFINED_VAR_AT * change func name * fixup formatting * update to use DEFINED_VAR_AT
Diffstat (limited to 'NorthstarDLL/core/hooks.cpp')
-rw-r--r--NorthstarDLL/core/hooks.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/NorthstarDLL/core/hooks.cpp b/NorthstarDLL/core/hooks.cpp
index 34b48d1d..7c70b0a5 100644
--- a/NorthstarDLL/core/hooks.cpp
+++ b/NorthstarDLL/core/hooks.cpp
@@ -65,6 +65,9 @@ __dllLoadCallback::__dllLoadCallback(
void __fileAutohook::Dispatch()
{
+ for (__autovar* var : vars)
+ var->Dispatch();
+
for (__autohook* hook : hooks)
hook->Dispatch();
}
@@ -114,6 +117,42 @@ bool ManualHook::Dispatch(LPVOID addr, LPVOID* orig)
return false;
}
+uintptr_t ParseDLLOffsetString(const char* pAddrString)
+{
+ // in the format server.dll + 0xDEADBEEF
+ int iDllNameEnd = 0;
+ for (; !isspace(pAddrString[iDllNameEnd]) && pAddrString[iDllNameEnd] != '+'; iDllNameEnd++)
+ ;
+
+ char* pModuleName = new char[iDllNameEnd + 1];
+ memcpy(pModuleName, pAddrString, iDllNameEnd);
+ pModuleName[iDllNameEnd] = '\0';
+
+ // get the module address
+ const HMODULE pModuleAddr = GetModuleHandleA(pModuleName);
+
+ if (!pModuleAddr)
+ return 0;
+
+ // get the offset string
+ uintptr_t iOffset = 0;
+
+ int iOffsetBegin = iDllNameEnd;
+ int iOffsetEnd = strlen(pAddrString);
+
+ // seek until we hit the start of the number offset
+ for (; !(pAddrString[iOffsetBegin] >= '0' && pAddrString[iOffsetBegin] <= '9') && pAddrString[iOffsetBegin]; iOffsetBegin++)
+ ;
+
+ bool bIsHex = pAddrString[iOffsetBegin] == '0' && (pAddrString[iOffsetBegin + 1] == 'X' || pAddrString[iOffsetBegin + 1] == 'x');
+ if (bIsHex)
+ iOffset = std::stoi(pAddrString + iOffsetBegin + 2, 0, 16);
+ else
+ iOffset = std::stoi(pAddrString + iOffsetBegin);
+
+ return ((uintptr_t)pModuleAddr + iOffset);
+}
+
// dll load callback stuff
// this allows for code to register callbacks to be run as soon as a dll is loaded, mainly to allow for patches to be made on dll load
struct DllLoadCallback