-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.cpp
More file actions
243 lines (200 loc) · 7.72 KB
/
Copy pathmain.cpp
File metadata and controls
243 lines (200 loc) · 7.72 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/**
* @file main.cpp
* @brief File with the DllMain function, used for initialization.
*/
#include "backend/backend.hpp"
#include "byte_patch_manager.hpp"
#include "common.hpp"
#include "fiber_pool.hpp"
#include "file_manager.hpp"
#include "gta/big_program.hpp"
#include "gta/joaat.hpp"
#include "hooking/hooking.hpp"
#include "invoker.hpp"
#include "lua/lua_manager.hpp"
#include "native_hooks/native_hooks.hpp"
#include "pointers.hpp"
#include "script_mgr.hpp"
#include "security/ObfVar.hpp"
#include "services/gta_data/gta_data_service.hpp"
#include "services/notifications/notification_service.hpp"
#include "services/players/player_service.hpp"
#include "services/script_patcher/script_patcher_service.hpp"
#include "services/tunables/tunables_service.hpp"
#include "thread_pool.hpp"
#include "util/is_enhanced.hpp"
#ifdef ENABLE_EXCEPTION_HANDLER
#include "logger/exception_handler.hpp"
#endif
#ifdef ENABLE_GUI
#include "gui.hpp"
#include "renderer/renderer.hpp"
#include "renderer/renderer_dx11.hpp"
#include "renderer/renderer_dx12.hpp"
#endif
BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
{
using namespace big;
if (reason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hmod);
g_is_enhanced = big::is_enhanced();
g_hmodule = hmod;
g_main_thread = CreateThread(
nullptr,
0,
[](PVOID) -> DWORD {
#ifdef ENABLE_EXCEPTION_HANDLER
auto handler = exception_handler();
#endif
std::srand(std::chrono::system_clock::now().time_since_epoch().count());
LPCSTR lpClassName = g_is_enhanced ? "sgaWindow" : "grcWindow";
while (!FindWindow(lpClassName, nullptr))
std::this_thread::sleep_for(1s);
std::filesystem::path base_dir = std::getenv("appdata");
base_dir /= PROJECT_NAME;
g_file_manager.init(base_dir);
g_log.initialize(PROJECT_NAME,
g_file_manager.get_project_file("./cout.log")
#ifndef ENABLE_GUI
,
false // Disable log window when GUI is disabled.
#endif
);
try
{
LOG(INFO) << R"kek(
______ _ ______ ______
(____ \(_) (____ \ (_____ \
____) )_ ____ ____) ) ____ ___ ____ _ _ ____) )
| __ (| |/ _ | __ ( / _ |/___)/ _ ) | | /_____/
| |__) ) ( ( | | |__) | ( | |___ ( (/ / \ V /_______
|______/|_|\_|| |______/ \_||_(___/ \____) \_/(_______)
(_____|)kek";
auto thread_pool_instance = std::make_unique<thread_pool>();
LOG(INFO) << "Thread pool initialized.";
g.init(g_file_manager.get_project_file("./settings.json"));
LOG(INFO) << "Settings Loaded.";
auto pointers_instance = std::make_unique<pointers>();
LOG(INFO) << "Pointers initialized.";
bool has_waited = false;
while (g_pointers->m_script_threads->size() == 0)
{
LOG(VERBOSE) << "Natives not initialised yet. Waiting 5s and trying again.";
std::this_thread::sleep_for(5s);
has_waited = true;
}
if (has_waited)
{
std::this_thread::sleep_for(5s);
}
auto byte_patch_manager_instance = std::make_unique<byte_patch_manager>();
LOG(INFO) << "Byte Patch Manager initialized.";
#ifdef ENABLE_GUI
std::unique_ptr<renderer_dx11> dx11_renderer_instance;
std::unique_ptr<renderer_dx12> dx12_renderer_instance;
if (g_is_enhanced)
{
while (!*g_pointers->m_resolution_x)
{
std::this_thread::sleep_for(1s);
}
dx12_renderer_instance = std::make_unique<renderer_dx12>();
}
else
{
dx11_renderer_instance = std::make_unique<renderer_dx11>();
}
LOG(INFO) << "Renderer initialized.";
auto gui_instance = std::make_unique<gui>();
#endif
auto fiber_pool_instance = std::make_unique<fiber_pool>(10);
LOG(INFO) << "Fiber pool initialized.";
auto hooking_instance = std::make_unique<hooking>();
LOG(INFO) << "Hooking initialized.";
auto script_program_instance = std::make_unique<big_program>("BadAPIInternal");
create_script_thread("BadAPIInternal");
LOG(INFO) << "Script Program initialized.";
g_native_invoker.cache_handlers();
LOG(INFO) << "Native handlers cached.";
auto notification_service_instance = std::make_unique<notification_service>();
auto player_service_instance = std::make_unique<player_service>();
auto script_patcher_service_instance = std::make_unique<script_patcher_service>();
auto tunables_service_instance = std::make_unique<tunables_service>();
LOG(INFO) << "Registered service instances...";
g_notification_service.initialise();
LOG(INFO) << "Finished initialising services.";
g_script_mgr.add_script(std::make_unique<script>(&backend::loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::tunables_script));
#ifdef ENABLE_GUI
g_script_mgr.add_script(std::make_unique<script>(&gui::script_func));
#endif
LOG(INFO) << "Scripts registered.";
g_hooking->enable();
LOG(INFO) << "Hooking enabled.";
g_gta_data_service.init();
auto native_hooks_instance = std::make_unique<native_hooks>();
LOG(INFO) << "Dynamic native hooker initialized.";
auto lua_manager_instance =
std::make_unique<lua_manager>(g_file_manager.get_project_folder("scripts"), g_file_manager.get_project_folder("scripts_config"));
LOG(INFO) << "Lua manager initialized.";
while (g_running)
std::this_thread::sleep_for(500ms);
lua_manager_instance.reset();
LOG(INFO) << "Lua manager uninitialized.";
g_script_mgr.remove_all_scripts();
LOG(INFO) << "Scripts unregistered.";
g_hooking->disable();
LOG(INFO) << "Hooking disabled.";
// cleans up the thread responsible for saving settings
g.destroy();
// Make sure that all threads created don't have any blocking loops
// otherwise make sure that they have stopped executing
thread_pool_instance->destroy();
LOG(INFO) << "Destroyed thread pool.";
tunables_service_instance.reset();
LOG(INFO) << "Player Database Service reset.";
script_patcher_service_instance.reset();
LOG(INFO) << "Mobile Service reset.";
player_service_instance.reset();
LOG(INFO) << "Xml Vehicles Service reset.";
notification_service_instance.reset();
LOG(INFO) << "Notification Service reset.";
LOG(INFO) << "Services uninitialized.";
hooking_instance.reset();
LOG(INFO) << "Hooking uninitialized.";
native_hooks_instance.reset();
LOG(INFO) << "Dynamic native hooker uninitialized.";
fiber_pool_instance.reset();
LOG(INFO) << "Fiber pool uninitialized.";
destroy_script_thread();
script_program_instance.reset();
LOG(INFO) << "Script Program uninitialized.";
#ifdef ENABLE_GUI
if (g_is_enhanced)
dx12_renderer_instance.reset();
else
dx11_renderer_instance.reset();
LOG(INFO) << "Renderer uninitialized.";
#endif
byte_patch_manager_instance.reset();
LOG(INFO) << "Byte Patch Manager uninitialized.";
pointers_instance.reset();
LOG(INFO) << "Pointers uninitialized.";
}
catch (std::exception const& ex)
{
LOG(WARNING) << ex.what();
MessageBoxA(nullptr, ex.what(), nullptr, MB_OK | MB_ICONEXCLAMATION);
}
LOG(INFO) << "Farewell!";
g_log.destroy();
CloseHandle(g_main_thread);
FreeLibraryAndExitThread(g_hmodule, 0);
},
nullptr,
0,
&g_main_thread_id);
}
return true;
}