Subversion Repositories WoWGM

Rev

Rev 7 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
*	Global variables
37
*
38
***/
39
CVar* g_password = NULL;
40
 
41
 
42
/****************************************************************************
43
*
44
*	Function pointers
45
*
46
***/
47
 
48
void (*ClientRegisterConsoleCommandsPtr)()	= *(void(*)())CLIENTREGISTERCONSOLECOMMANDS;
49
void (*ClientUnregisterConsoleCommandsPtr)()= *(void(*)())CLIENTUNREGISTERCONSOLECOMMANDS;
50
void (*DestroyHandlerPlayerPtr)()			= *(void(*)())DESTROYHANDLERPLAYER;
51
void (*InitializeHandlerPlayerPtr)()		= *(void(*)())INITIALIZEHANDLERPLAYER;
52
int (*Script_GetBuildInfoPtr)(lua_State* L) = *(int(*)(lua_State *))SCRIPT_GETBUILDINFO_PTR;
53
void (*WowClientInitPtr)()					= *(void(*)())WOWCLIENTINIT_PTR;
54
 
55
 
56
/****************************************************************************
57
*
58
*	Program entry point
59
*
60
***/
61
 
62
//===========================================================================
63
extern "C" BOOL WINAPI DllMain(HINSTANCE const	instance,
64
							   DWORD const		reason,
65
							   LPVOID const		reserved)
66
{
67
	switch (reason) {
68
		case DLL_PROCESS_ATTACH: {
69
			WowGM::Initialize();
70
			ConsoleCommandInitialize();
71
			WowGM::InitializeHandlerPlayer();
72
			WowGM::ClientRegisterConsoleCommands();
73
			WowGM::CGlueMgr::Initialize();
74
			WowGM::CGGameUI::Initialize();
75
			//ClientServices_Initialize();
76
			WowGM::InstallGameConsoleCommands();
77
			ConsoleAccessSetEnabled(TRUE);
78
			break;
79
								 }
80
		case DLL_THREAD_ATTACH:
81
		case DLL_THREAD_DETACH:
82
			break;
83
		case DLL_PROCESS_DETACH: {
84
			WowGM::DestroyHandlerPlayer();
85
			WowGM::ClientUnregisterConsoleCommands();
86
			WowGM::CGlueMgr::Shutdown();
87
			WowGM::CGGameUI::Shutdown();
88
			//ClientServices_Destroy();
89
			WowGM::UninstallGameConsoleCommands();
90
			break;
91
								 }
92
	}
93
	return TRUE;
94
}
95
 
96
 
97
/****************************************************************************
98
*
99
*	Private functions
100
*
101
***/
102
 
103
//===========================================================================
104
void WowGM::Initialize()
105
{
106
	DetourRestoreAfterWith();
107
	FixInvalidPtrCheck();
108
}
109
 
110
//===========================================================================
111
void WowGM::FixInvalidPtrCheck()
112
{
113
	// Allow callbacks outside of the .text section
114
	*((int*)0x00D415B8) = 0x00000001;
115
	*((int*)0x00D415BC) = 0x7FFFFFFF;
116
}
117
 
118
//===========================================================================
119
inline void SetLoginPassword()
120
{
121
	char command[256] = {};
122
 
123
	// TODO: Call SStrPrintF here
124
	sprintf_s(command,
125
			  sizeof(command),
126
			  "AccountLoginPasswordEdit:SetText(\"%s\")",
127
			  g_password->m_stringValue.m_string);
128
	FrameScript_Execute(command,command,NULL);
129
}
130
 
131
//===========================================================================
132
void InitializeHandlerPlayer()
133
{
134
	InitializeHandlerPlayerPtr();
135
 
136
	ConsoleCommandExecute("run autoexec.wtf",FALSE);
137
}
138
 
139
//===========================================================================
140
void ClientRegisterConsoleCommands()
141
{
142
	ClientRegisterConsoleCommandsPtr();
143
 
144
	g_password = CVar::Register("password",
145
								"stored password for blizzcon, dev, qa, etc.",
146
								NULL,
147
								"",
148
								NULL,
149
								GAME,
150
								false,
151
								NULL,
152
								false);
153
}
154
 
155
//===========================================================================
156
void DestroyHandlerPlayer()
157
{
158
	DestroyHandlerPlayerPtr();
159
}
160
 
161
//===========================================================================
162
void ClientUnregisterConsoleCommands()
163
{
164
	ClientUnregisterConsoleCommandsPtr();
165
}
166
 
167
//===========================================================================
168
int Script_GetBuildInfo(lua_State* L)
169
{
170
	char* version = FrameScript_GetText("VERSION", -1, GENDER_NONE);
171
	_lua_pushstring(L, version);
172
#ifdef _DEBUG
173
	_lua_pushstring(L,"Debug");
174
#else
175
	_lua_pushstring(L, "GM");
176
#endif // #ifdef _DEBUG
177
	_lua_pushstring(L, "3.3.5");
178
	_lua_pushstring(L, "12340");
179
	_lua_pushstring(L, __DATE__);
180
	return 5;	// TODO: automatically return the number of arguments returned by Lua
181
}
182
 
183
//===========================================================================
184
void WowClientInit()
185
{
186
	WowClientInitPtr();
187
 
188
	SetLoginPassword();
189
	ConsoleCommandExecute("run autoexec.wtf",FALSE);
190
}
191
 
192
 
193
/****************************************************************************
194
*
195
*	Detours setup (external functions)
196
*
197
***/
198
 
199
//===========================================================================
200
void WowGM::InitializeHandlerPlayer()
201
{
202
	DETOUR_INIT;
203
	DETOUR_ATTACH(WowClientInitPtr,WowClientInit);
204
	DETOUR_ATTACH(InitializeHandlerPlayerPtr,::InitializeHandlerPlayer);
205
	DETOUR_ATTACH(Script_GetBuildInfoPtr, Script_GetBuildInfo);
206
	DETOUR_ATTACH(DestroyHandlerPlayerPtr,::DestroyHandlerPlayer);
207
	DETOUR_COMMIT;
208
}
209
 
210
//===========================================================================
211
void WowGM::ClientRegisterConsoleCommands()
212
{
213
	DETOUR_INIT;
214
	DETOUR_ATTACH(ClientRegisterConsoleCommandsPtr,::ClientRegisterConsoleCommands);
215
	DETOUR_ATTACH(ClientUnregisterConsoleCommandsPtr,::ClientUnregisterConsoleCommands);
216
	DETOUR_COMMIT;
217
}
218
 
219
//===========================================================================
220
void WowGM::DestroyHandlerPlayer()
221
{
222
	DETOUR_INIT;
223
	DETOUR_DETACH(WowClientInitPtr,WowClientInit);
224
	DETOUR_DETACH(InitializeHandlerPlayerPtr,::InitializeHandlerPlayer);
225
	DETOUR_DETACH(DestroyHandlerPlayerPtr,::DestroyHandlerPlayer);
226
	DETOUR_DETACH(Script_GetBuildInfoPtr, Script_GetBuildInfo);
227
	DETOUR_COMMIT;
228
}
229
 
230
//===========================================================================
231
void WowGM::ClientUnregisterConsoleCommands()
232
{
233
	DETOUR_INIT;
234
	DETOUR_DETACH(ClientRegisterConsoleCommandsPtr,::ClientRegisterConsoleCommands);
235
	DETOUR_DETACH(ClientUnregisterConsoleCommandsPtr,::ClientUnregisterConsoleCommands);
236
	DETOUR_COMMIT;
237
}