Subversion Repositories WoWGM

Rev

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