| 3 |
tristanc |
1 |
/****************************************************************************
|
|
|
2 |
*
|
|
|
3 |
* Client.cpp
|
|
|
4 |
*
|
|
|
5 |
* Program entry point (DllMain)
|
|
|
6 |
*
|
|
|
7 |
***/
|
|
|
8 |
|
|
|
9 |
#include "pch.h"
|
|
|
10 |
#pragma hdrstop
|
|
|
11 |
|
|
|
12 |
#include "Client.h"
|
|
|
13 |
#include "ClientCommands.h"
|
|
|
14 |
#include "ClientDebugCommands.h"
|
|
|
15 |
#include <WowSvcs/ClientServices.h>
|
|
|
16 |
#include <Glue/CGlueMgr.h>
|
|
|
17 |
#include <Ui/GameUI.h>
|
|
|
18 |
#include <FrameScript/FrameScript.h>
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
/****************************************************************************
|
|
|
22 |
*
|
|
|
23 |
* Memory addresses
|
|
|
24 |
*
|
|
|
25 |
***/
|
|
|
26 |
#define CLIENTREGISTERCONSOLECOMMANDS 0x00401B60;
|
|
|
27 |
#define CLIENTUNREGISTERCONSOLECOMMANDS 0x00402910;
|
|
|
28 |
#define DESTROYHANDLERPLAYER 0x004066D0;
|
|
|
29 |
#define INITIALIZEHANDLERPLAYER 0x004047E0;
|
|
|
30 |
#define SCRIPT_GETBUILDINFO_PTR 0x004DBE60;
|
|
|
31 |
#define WOWCLIENTINIT_PTR 0x00404130;
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
/****************************************************************************
|
|
|
35 |
*
|
|
|
36 |
* Function pointers
|
|
|
37 |
*
|
|
|
38 |
***/
|
|
|
39 |
|
|
|
40 |
void (*ClientRegisterConsoleCommandsPtr)() = *(void(*)())CLIENTREGISTERCONSOLECOMMANDS;
|
|
|
41 |
void (*ClientUnregisterConsoleCommandsPtr)()= *(void(*)())CLIENTUNREGISTERCONSOLECOMMANDS;
|
|
|
42 |
void (*DestroyHandlerPlayerPtr)() = *(void(*)())DESTROYHANDLERPLAYER;
|
|
|
43 |
void (*InitializeHandlerPlayerPtr)() = *(void(*)())INITIALIZEHANDLERPLAYER;
|
|
|
44 |
int (*Script_GetBuildInfoPtr)(lua_State* L) = *(int(*)(lua_State *))SCRIPT_GETBUILDINFO_PTR;
|
|
|
45 |
void (*WowClientInitPtr)() = *(void(*)())WOWCLIENTINIT_PTR;
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
/****************************************************************************
|
|
|
49 |
*
|
|
|
50 |
* Program entry point
|
|
|
51 |
*
|
|
|
52 |
***/
|
|
|
53 |
|
|
|
54 |
//===========================================================================
|
|
|
55 |
extern "C" BOOL WINAPI DllMain(HINSTANCE const instance,
|
|
|
56 |
DWORD const reason,
|
|
|
57 |
LPVOID const reserved)
|
|
|
58 |
{
|
|
|
59 |
switch (reason) {
|
|
|
60 |
case DLL_PROCESS_ATTACH: {
|
|
|
61 |
WowGM::Initialize();
|
|
|
62 |
ConsoleCommandInitialize();
|
|
|
63 |
WowGM::InitializeHandlerPlayer();
|
|
|
64 |
WowGM::ClientRegisterConsoleCommands();
|
|
|
65 |
WowGM::CGlueMgr::Initialize();
|
|
|
66 |
WowGM::CGGameUI::Initialize();
|
|
|
67 |
//ClientServices_Initialize();
|
|
|
68 |
WowGM::InstallGameConsoleCommands();
|
|
|
69 |
ConsoleAccessSetEnabled(TRUE);
|
|
|
70 |
break;
|
|
|
71 |
}
|
|
|
72 |
case DLL_THREAD_ATTACH:
|
|
|
73 |
case DLL_THREAD_DETACH:
|
|
|
74 |
break;
|
|
|
75 |
case DLL_PROCESS_DETACH: {
|
|
|
76 |
WowGM::DestroyHandlerPlayer();
|
|
|
77 |
WowGM::ClientUnregisterConsoleCommands();
|
|
|
78 |
WowGM::CGlueMgr::Shutdown();
|
|
|
79 |
WowGM::CGGameUI::Shutdown();
|
|
|
80 |
//ClientServices_Destroy();
|
|
|
81 |
WowGM::UninstallGameConsoleCommands();
|
|
|
82 |
break;
|
|
|
83 |
}
|
|
|
84 |
}
|
|
|
85 |
return TRUE;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
/****************************************************************************
|
|
|
90 |
*
|
|
|
91 |
* Private functions
|
|
|
92 |
*
|
|
|
93 |
***/
|
|
|
94 |
|
|
|
95 |
//===========================================================================
|
|
|
96 |
void WowGM::Initialize()
|
|
|
97 |
{
|
|
|
98 |
DetourRestoreAfterWith();
|
|
|
99 |
FixInvalidPtrCheck();
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
//===========================================================================
|
|
|
103 |
void WowGM::FixInvalidPtrCheck()
|
|
|
104 |
{
|
|
|
105 |
// Allow callbacks outside of the .text section
|
|
|
106 |
*((int*)0x00D415B8) = 0x00000001;
|
|
|
107 |
*((int*)0x00D415BC) = 0x7FFFFFFF;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
//===========================================================================
|
|
|
111 |
void InitializeHandlerPlayer()
|
|
|
112 |
{
|
|
|
113 |
InitializeHandlerPlayerPtr();
|
|
|
114 |
|
|
|
115 |
ConsoleCommandExecute("run autoexec.wtf",FALSE);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
//===========================================================================
|
|
|
119 |
void ClientRegisterConsoleCommands()
|
|
|
120 |
{
|
|
|
121 |
ClientRegisterConsoleCommandsPtr();
|
|
|
122 |
|
|
|
123 |
g_password = CVar::Register("password",
|
|
|
124 |
"stored password for blizzcon, dev, qa, etc.",
|
|
|
125 |
NULL,
|
|
|
126 |
"",
|
|
|
127 |
NULL,
|
|
|
128 |
GAME,
|
|
|
129 |
false,
|
|
|
130 |
NULL,
|
|
|
131 |
false);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
//===========================================================================
|
|
|
135 |
void DestroyHandlerPlayer()
|
|
|
136 |
{
|
|
|
137 |
DestroyHandlerPlayerPtr();
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
//===========================================================================
|
|
|
141 |
void ClientUnregisterConsoleCommands()
|
|
|
142 |
{
|
|
|
143 |
ClientUnregisterConsoleCommandsPtr();
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
//===========================================================================
|
|
|
147 |
int Script_GetBuildInfo(lua_State* L)
|
|
|
148 |
{
|
|
|
149 |
char* version = FrameScript_GetText("VERSION", -1, GENDER_NONE);
|
|
|
150 |
_lua_pushstring(L, version);
|
|
|
151 |
#ifdef _DEBUG
|
|
|
152 |
_lua_pushstring(L,"Debug");
|
|
|
153 |
#else
|
|
|
154 |
_lua_pushstring(L, "GM");
|
|
|
155 |
#endif // #ifdef _DEBUG
|
|
|
156 |
_lua_pushstring(L, "3.3.5");
|
|
|
157 |
_lua_pushstring(L, "12340");
|
|
|
158 |
_lua_pushstring(L, __DATE__);
|
|
|
159 |
return 5; // TODO: automatically return the number of arguments returned by Lua
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
//===========================================================================
|
|
|
163 |
void WowClientInit()
|
|
|
164 |
{
|
|
|
165 |
WowClientInitPtr();
|
|
|
166 |
|
| 7 |
tristanc |
167 |
WowGM::CGlueMgr::SetLoginPassword();
|
| 3 |
tristanc |
168 |
ConsoleCommandExecute("run autoexec.wtf",FALSE);
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
/****************************************************************************
|
|
|
173 |
*
|
|
|
174 |
* Detours setup (external functions)
|
|
|
175 |
*
|
|
|
176 |
***/
|
|
|
177 |
|
|
|
178 |
//===========================================================================
|
|
|
179 |
void WowGM::InitializeHandlerPlayer()
|
|
|
180 |
{
|
|
|
181 |
DETOUR_INIT;
|
|
|
182 |
DETOUR_ATTACH(WowClientInitPtr,WowClientInit);
|
|
|
183 |
DETOUR_ATTACH(InitializeHandlerPlayerPtr,::InitializeHandlerPlayer);
|
|
|
184 |
DETOUR_ATTACH(Script_GetBuildInfoPtr, Script_GetBuildInfo);
|
|
|
185 |
DETOUR_ATTACH(DestroyHandlerPlayerPtr,::DestroyHandlerPlayer);
|
|
|
186 |
DETOUR_COMMIT;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
//===========================================================================
|
|
|
190 |
void WowGM::ClientRegisterConsoleCommands()
|
|
|
191 |
{
|
|
|
192 |
DETOUR_INIT;
|
|
|
193 |
DETOUR_ATTACH(ClientRegisterConsoleCommandsPtr,::ClientRegisterConsoleCommands);
|
|
|
194 |
DETOUR_ATTACH(ClientUnregisterConsoleCommandsPtr,::ClientUnregisterConsoleCommands);
|
|
|
195 |
DETOUR_COMMIT;
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
//===========================================================================
|
|
|
199 |
void WowGM::DestroyHandlerPlayer()
|
|
|
200 |
{
|
|
|
201 |
DETOUR_INIT;
|
|
|
202 |
DETOUR_DETACH(WowClientInitPtr,WowClientInit);
|
|
|
203 |
DETOUR_DETACH(InitializeHandlerPlayerPtr,::InitializeHandlerPlayer);
|
|
|
204 |
DETOUR_DETACH(DestroyHandlerPlayerPtr,::DestroyHandlerPlayer);
|
|
|
205 |
DETOUR_DETACH(Script_GetBuildInfoPtr, Script_GetBuildInfo);
|
|
|
206 |
DETOUR_COMMIT;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
//===========================================================================
|
|
|
210 |
void WowGM::ClientUnregisterConsoleCommands()
|
|
|
211 |
{
|
|
|
212 |
DETOUR_INIT;
|
|
|
213 |
DETOUR_DETACH(ClientRegisterConsoleCommandsPtr,::ClientRegisterConsoleCommands);
|
|
|
214 |
DETOUR_DETACH(ClientUnregisterConsoleCommandsPtr,::ClientUnregisterConsoleCommands);
|
|
|
215 |
DETOUR_COMMIT;
|
|
|
216 |
}
|