-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuntime.cpp
73 lines (63 loc) · 1.8 KB
/
Runtime.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Runtime.h"
#include "MinHook.h"
#include <iostream>
#include "HavokScript.h"
#pragma comment(lib, "libMinHook.x64.lib")
namespace Runtime {
HMODULE GameCore;
uintptr_t GameCoreAddress;
asmjit::JitRuntime Jit;
// Should only be called once
void Create() {
GameCore = LoadLibrary(TEXT("../../../DLC/Expansion2/Binaries/Win64/GameCore_XP2_FinalRelease.dll"));
if (!GameCore) {
std::cout << "Original GameCore failed to load!\n";
return;
}
GameCoreAddress = reinterpret_cast<uintptr_t>(GameCore);
}
void InitMinHook() {
if (MH_Initialize() != MH_OK) {
std::cout << "MH failed to init\n";
}
std::cout << "MH initialized successfully.\n";
}
// Call on dll exit
void Destroy() {
if (GameCore) {
MH_DisableHook(MH_ALL_HOOKS);
MH_Uninitialize();
FreeLibrary(GameCore);
GameCore = NULL;
GameCoreAddress = 0x0;
}
}
void InitConsole() {
if (!AllocConsole()) {
MessageBoxW(NULL, L"Failed to create the console!", L"Error", MB_ICONERROR);
return;
}
// Redirect standard input/output streams to the console
FILE* fDummy;
freopen_s(&fDummy, "CONIN$", "r", stdin);
freopen_s(&fDummy, "CONOUT$", "w", stderr);
freopen_s(&fDummy, "CONOUT$", "w", stdout);
std::cout << "Console initialized successfully." << std::endl;
}
void CloseConsole() {
if (!FreeConsole()) {
MessageBoxW(NULL, L"Failed to close the console!", L"Error", MB_ICONERROR);
}
else {
std::cout << "Console closed successfully." << std::endl;
}
// Reset standard input/output streams
freopen_s((FILE**)stdin, "NUL:", "r", stdin);
freopen_s((FILE**)stdout, "NUL:", "w", stdout);
freopen_s((FILE**)stderr, "NUL:", "w", stderr);
// Clear the error state for each of the C++ standard streams after redirect.
std::cin.clear();
std::cout.clear();
std::cerr.clear();
}
};