-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
354 additions
and
659 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,120 @@ | ||
#include "Client.hpp" | ||
#include "Exports.hpp" | ||
#include "./HavokScript/HavokScript.hpp" | ||
#include "./Lua/LuaHook.hpp" | ||
#include "./Misc/ChromaSDK.hpp" | ||
#include "./Variant/Variant.hpp" | ||
|
||
std::mutex consoleMutex; | ||
std::condition_variable cv; | ||
std::atomic<bool> stopThread(false); | ||
std::thread mainThread; | ||
|
||
DWORD WINAPI CreateConsole() | ||
{ | ||
FILE *dummy = nullptr; | ||
AllocConsole(); | ||
AttachConsole(GetCurrentProcessId()); | ||
{ | ||
std::lock_guard<std::mutex> lock(consoleMutex); | ||
if (freopen_s(&dummy, "CONIN$", "r", stdin) != 0 || freopen_s(&dummy, "CONOUT$", "w", stdout) != 0 || | ||
freopen_s(&dummy, "CONOUT$", "w", stderr) != 0) { | ||
std::cerr << "Failed to redirect console streams !" << std::endl; | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
#include "Exports.hpp" | ||
|
||
DWORD WINAPI CreateConsole() { | ||
FILE* dummy = nullptr; | ||
AllocConsole(); | ||
AttachConsole(GetCurrentProcessId()); | ||
{ | ||
std::lock_guard<std::mutex> lock(consoleMutex); | ||
if (freopen_s(&dummy, "CONIN$", "r", stdin) != 0 || | ||
freopen_s(&dummy, "CONOUT$", "w", stdout) != 0 || | ||
freopen_s(&dummy, "CONOUT$", "w", stderr) != 0) { | ||
std::cerr << "Failed to redirect console streams !" << std::endl; | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
DWORD WINAPI DestroyConsole() | ||
{ | ||
if (FreeConsole() == 0) { | ||
std::cerr << "Console failed to close!" << std::endl; | ||
} | ||
|
||
{ | ||
std::lock_guard<std::mutex> lock(consoleMutex); | ||
freopen_s(reinterpret_cast<FILE **>(stdin), "NUL:", "r", stdin); | ||
freopen_s(reinterpret_cast<FILE **>(stdout), "NUL:", "r", stdout); | ||
freopen_s(reinterpret_cast<FILE **>(stderr), "NUL:", "r", stderr); | ||
} | ||
|
||
std::cin.clear(); | ||
std::cout.clear(); | ||
std::cerr.clear(); | ||
return 0; | ||
DWORD WINAPI DestroyConsole() { | ||
if (FreeConsole() == 0) { | ||
std::cerr << "Console failed to close!" << std::endl; | ||
} | ||
|
||
{ | ||
std::lock_guard<std::mutex> lock(consoleMutex); | ||
freopen_s(reinterpret_cast<FILE**>(stdin), "NUL:", "r", stdin); | ||
freopen_s(reinterpret_cast<FILE**>(stdout), "NUL:", "r", stdout); | ||
freopen_s(reinterpret_cast<FILE**>(stderr), "NUL:", "r", stderr); | ||
} | ||
|
||
std::cin.clear(); | ||
std::cout.clear(); | ||
std::cerr.clear(); | ||
return 0; | ||
} | ||
|
||
DWORD WINAPI DestroyHook() | ||
{ | ||
stopThread = true; | ||
cv.notify_all(); | ||
DWORD WINAPI DestroyHook() { | ||
stopThread = true; | ||
cv.notify_all(); | ||
|
||
if (mainThread.joinable()) { | ||
mainThread.join(); | ||
} | ||
if (mainThread.joinable()) { | ||
mainThread.join(); | ||
} | ||
|
||
MH_DisableHook(MH_ALL_HOOKS); | ||
MH_Uninitialize(); | ||
return 0; | ||
} | ||
MH_DisableHook(MH_ALL_HOOKS); | ||
MH_Uninitialize(); | ||
|
||
void ProcessCommands() | ||
{ | ||
while (!stopThread) { | ||
LuaVM::ProcessCommand(); | ||
} | ||
if (hMutex) { | ||
ReleaseMutex(hMutex); | ||
CloseHandle(hMutex); | ||
hMutex = NULL; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
void ProcessCommands() { | ||
{ | ||
std::unique_lock<std::mutex> lock(consoleMutex); | ||
if (cv.wait_for(lock, std::chrono::seconds(10), | ||
[] { return stopThread.load(); })) { | ||
return; // Wait after Steam prints debug info. | ||
} | ||
} | ||
while (!stopThread) { | ||
LuaVM::ProcessCommand(); | ||
} | ||
} | ||
|
||
static DWORD SetupHook() | ||
{ | ||
uintptr_t ModuleBase = 0; | ||
static DWORD SetupHook() { | ||
uintptr_t ModuleBase = 0; | ||
|
||
LPCSTR moduleName = "HaloInfinite.exe"; | ||
ModuleBase = reinterpret_cast<uintptr_t>(GetModuleHandleA(moduleName)); | ||
if (ModuleBase == 0) { | ||
std::cerr << "Failed to get module handle for " << moduleName << std::endl; | ||
return 1; | ||
} | ||
LPCSTR moduleName = "HaloInfinite.exe"; | ||
ModuleBase = reinterpret_cast<uintptr_t>(GetModuleHandleA(moduleName)); | ||
if (ModuleBase == 0) { | ||
std::cerr << "Failed to get module handle for " << moduleName << std::endl; | ||
return 1; | ||
} | ||
|
||
ChromaSDK::HookChroma(ModuleBase); | ||
Hks::HookHavokScript(ModuleBase); | ||
Variant::HookVariant(ModuleBase); | ||
ChromaSDK::HookChroma(ModuleBase); | ||
Hks::HookHavokScript(ModuleBase); | ||
|
||
LuaVM::InitializeLua(); | ||
LuaVM::HookVariantFunctions(); | ||
mainThread = std::thread(ProcessCommands); | ||
return 0; | ||
mainThread = std::thread(ProcessCommands); | ||
return 0; | ||
} | ||
|
||
|
||
DWORD WINAPI MainThread(LPVOID lpParameter) | ||
{ | ||
SetupHook(); | ||
return 0; | ||
DWORD WINAPI MainThread(LPVOID lpParameter) { | ||
SetupHook(); | ||
return 0; | ||
} | ||
|
||
|
||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) | ||
{ | ||
switch (dwReason) { | ||
case DLL_PROCESS_ATTACH: | ||
CreateConsole(); | ||
DisableThreadLibraryCalls(hModule); | ||
CreateThread(nullptr, 0, MainThread, nullptr, 0, nullptr); | ||
break; | ||
case DLL_PROCESS_DETACH: | ||
DestroyHook(); | ||
LuaVM::CleanLua(); | ||
DestroyConsole(); | ||
FreeLibraryAndExitThread(hModule, TRUE); | ||
break; | ||
default: | ||
break; | ||
} | ||
return TRUE; | ||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) { | ||
switch (dwReason) { | ||
case DLL_PROCESS_ATTACH: | ||
hMutex = CreateMutexA(NULL, TRUE, "UniqueDLLInstanceMutex"); | ||
if (hMutex == NULL || GetLastError() == ERROR_ALREADY_EXISTS) { | ||
if (hMutex) { | ||
CloseHandle(hMutex); | ||
hMutex = NULL; | ||
} | ||
return FALSE; // DLL is already loaded | ||
} | ||
CreateConsole(); | ||
DisableThreadLibraryCalls(hModule); | ||
CreateThread(nullptr, 0, MainThread, nullptr, 0, nullptr); | ||
break; | ||
case DLL_PROCESS_DETACH: | ||
DestroyHook(); | ||
DestroyConsole(); | ||
FreeLibraryAndExitThread(hModule, TRUE); | ||
break; | ||
default: | ||
break; | ||
} | ||
return TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,69 @@ | ||
#include "HavokScript.hpp" | ||
#include "../Memory.hpp" | ||
#include "HksCompilerSettings.hpp" | ||
|
||
int Hks::GetGlobalHook(uintptr_t state, char* string) { | ||
LuaState = state; | ||
return GetGlobalA(state, string); | ||
} | ||
|
||
uint64_t Hks::PCallHook(uintptr_t state, int function, uint32_t i, int u) { | ||
__int64 result = PCallA(state, function, i, u); | ||
return result; | ||
} | ||
|
||
/* Declare private variables. */ | ||
Hks::GetGlobal Hks::GetGlobalH = nullptr; | ||
Hks::GetGlobal Hks::GetGlobalA = nullptr; | ||
|
||
int Hks::GetGlobalHook(lua_State *state, char *string) | ||
{ | ||
return GetGlobalA(state, string); | ||
uint64_t Hks::LoadBufferHook(uintptr_t state, | ||
const struct HksCompilerSettings* compilerSettings, | ||
const char* buffer, __int64 length, | ||
const char* unknown1) { | ||
__int64 result = | ||
LoadBufferA(state, compilerSettings, buffer, length, unknown1); | ||
return result; | ||
} | ||
|
||
|
||
void Hks::HookHavokScript(uintptr_t ModuleBase) | ||
{ | ||
const uintptr_t GetGlobalOffset = 0x80CB4C; | ||
GetGlobalH = hook_function<GetGlobal>(ModuleBase, GetGlobalOffset, &GetGlobalHook, &GetGlobalA); | ||
uint64_t Hks::DoString(const char* string) { | ||
|
||
size_t stringLength = std::strlen(string); | ||
if (Hks::LoadBufferHook( | ||
LuaState, | ||
(const struct HksCompilerSettings*)(*((uintptr_t*)LuaState + 2) + | ||
1368), | ||
string, stringLength, string)) { | ||
return 1; | ||
} | ||
|
||
uint64_t call_result = PCallHook(LuaState, 0, 0xFFFFFFFF, 0); | ||
if (call_result) { | ||
return 1; | ||
} | ||
return call_result; | ||
} | ||
|
||
|
||
uint64_t Hks::DoFile(const char* filename) { | ||
std::ifstream file(filename); | ||
if (!file.is_open()) { | ||
std::cerr << "Failed to open file: " << filename << std::endl; | ||
return 1; | ||
} | ||
|
||
std::stringstream buffer; | ||
buffer << file.rdbuf(); | ||
std::string fileContents = buffer.str(); | ||
file.close(); | ||
|
||
return DoString(fileContents.c_str()); | ||
} | ||
|
||
void Hks::HookHavokScript(uintptr_t ModuleBase) { | ||
const uintptr_t GetGlobalOffset = 0x80CB4C; | ||
GetGlobalH = hook_function<GetGlobal>(ModuleBase, GetGlobalOffset, | ||
&GetGlobalHook, &GetGlobalA); | ||
const uintptr_t PCallOffset = 0x764304; | ||
PCallH = hook_function<PCall>(ModuleBase, PCallOffset, &PCallHook, &PCallA); | ||
const uintptr_t LoadBufferOffset = 0xA484C0; | ||
LoadBufferH = hook_function<LoadBuffer>(ModuleBase, LoadBufferOffset, | ||
&LoadBufferHook, &LoadBufferA); | ||
} |
Oops, something went wrong.