-
Notifications
You must be signed in to change notification settings - Fork 2
/
dllmain.c
119 lines (106 loc) · 2.49 KB
/
dllmain.c
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
/**
* @file dllmain.c
* @brief Entry point of alien shooter multiplayer client.
*
*/
#include <stdbool.h>
#include <windows.h>
#include "utils/console/console.h"
#include "utils/hook/hook.h"
#include "multiplayer.h"
#include "gameutils.h"
#include "game/api.h"
static HINSTANCE instance_handle = 0;
/**
* @brief Entry point into a DLL.
*
* @param[in] hinst Base address of the DLL.
* @param[in] reason The reason for calling the DLL entry point.
* @param[in] reserved For reason = DLL_PROCESS_ATTACH: NULL for dynamic loads
* and non-NULL for static loads.
* For reason = DLL_PROCESS_DETACH: NULL if FreeLibrary has
* been called or the DLL load failed and non-NULL if the
* process is terminating.
*
* @return Injection/uninjection result.
*/
BOOL WINAPI DllMain(HMODULE hinst, DWORD reason, LPVOID reserved);
/**
* @brief Initialization of the components required for the DLL to work.
*
* @return true
* @return false
*/
static bool dllmain_init(void);
/**
* @brief Cleanup logic before DLL unloading.
*/
static void dllmain_destroy(void);
/**
* @brief Main loop of the DLL.
*/
static void dllmain_loop(void);
/**
* @brief Main thread of the DLL.
*/
static void dllmain_entry(void);
static bool dllmain_init(void)
{
if (console_init())
{
if (hook_init())
{
if (multiplayer_init())
{
return true;
}
hook_destroy();
}
console_destroy();
}
return false;
}
static void dllmain_destroy(void)
{
multiplayer_destroy();
hook_destroy();
console_destroy();
}
static void dllmain_loop(void)
{
while (1)
{
Sleep(100);
if (GetAsyncKeyState(VK_F6))
{
gameutils_spawn_weapons();
Sleep(1000);
}
if (GetAsyncKeyState(VK_F12))
{
break;
}
}
}
static void dllmain_entry(void)
{
if (dllmain_init())
{
console_log("dllmain_entry()\n");
dllmain_loop();
dllmain_destroy();
}
FreeLibraryAndExitThread(instance_handle, 0);
}
BOOL WINAPI DllMain(HMODULE hinst, DWORD reason, LPVOID reserved)
{
(void)reserved;
instance_handle = hinst;
if (reason == DLL_PROCESS_ATTACH)
{
DWORD thread_id = 0;
CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)dllmain_entry,
0x0, 0, &thread_id));
}
return TRUE;
}