Subversion Repositories WoWGM

Rev

Rev 19 | Rev 31 | 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);
30 tristanc 134
 
135
  ConsoleCommandRegister("Bug", CCommand_Bug, DEBUG, NOHELP);
136
  ConsoleCommandRegister("Suggestion", CCommand_Bug, DEBUG, NOHELP);
3 tristanc 137
}
138
 
139
//===========================================================================
140
void DestroyHandlerPlayer()
141
{
142
	DestroyHandlerPlayerPtr();
143
}
144
 
145
//===========================================================================
146
void ClientUnregisterConsoleCommands()
147
{
148
	ClientUnregisterConsoleCommandsPtr();
30 tristanc 149
 
150
  ConsoleCommandUnregister("Bug");
151
  ConsoleCommandUnregister("Suggestion");
3 tristanc 152
}
153
 
154
//===========================================================================
155
int Script_GetBuildInfo(lua_State* L)
156
{
157
	char* version = FrameScript_GetText("VERSION", -1, GENDER_NONE);
158
	_lua_pushstring(L, version);
159
#ifdef _DEBUG
160
	_lua_pushstring(L,"Debug");
161
#else
162
	_lua_pushstring(L, "GM");
163
#endif // #ifdef _DEBUG
164
	_lua_pushstring(L, "3.3.5");
165
	_lua_pushstring(L, "12340");
166
	_lua_pushstring(L, __DATE__);
167
	return 5;	// TODO: automatically return the number of arguments returned by Lua
168
}
169
 
170
//===========================================================================
171
void WowClientInit()
172
{
173
	WowClientInitPtr();
174
 
7 tristanc 175
	WowGM::CGlueMgr::SetLoginPassword();
3 tristanc 176
	ConsoleCommandExecute("run autoexec.wtf",FALSE);
177
}
178
 
179
 
180
/****************************************************************************
181
*
182
*	Detours setup (external functions)
183
*
184
***/
185
 
186
//===========================================================================
187
void WowGM::InitializeHandlerPlayer()
188
{
189
	DETOUR_INIT;
190
	DETOUR_ATTACH(WowClientInitPtr,WowClientInit);
191
	DETOUR_ATTACH(InitializeHandlerPlayerPtr,::InitializeHandlerPlayer);
192
	DETOUR_ATTACH(Script_GetBuildInfoPtr, Script_GetBuildInfo);
193
	DETOUR_ATTACH(DestroyHandlerPlayerPtr,::DestroyHandlerPlayer);
194
	DETOUR_COMMIT;
195
}
196
 
197
//===========================================================================
198
void WowGM::ClientRegisterConsoleCommands()
199
{
200
	DETOUR_INIT;
201
	DETOUR_ATTACH(ClientRegisterConsoleCommandsPtr,::ClientRegisterConsoleCommands);
202
	DETOUR_ATTACH(ClientUnregisterConsoleCommandsPtr,::ClientUnregisterConsoleCommands);
203
	DETOUR_COMMIT;
204
}
205
 
206
//===========================================================================
207
void WowGM::DestroyHandlerPlayer()
208
{
209
	DETOUR_INIT;
210
	DETOUR_DETACH(WowClientInitPtr,WowClientInit);
211
	DETOUR_DETACH(InitializeHandlerPlayerPtr,::InitializeHandlerPlayer);
212
	DETOUR_DETACH(DestroyHandlerPlayerPtr,::DestroyHandlerPlayer);
213
	DETOUR_DETACH(Script_GetBuildInfoPtr, Script_GetBuildInfo);
214
	DETOUR_COMMIT;
215
}
216
 
217
//===========================================================================
218
void WowGM::ClientUnregisterConsoleCommands()
219
{
220
	DETOUR_INIT;
221
	DETOUR_DETACH(ClientRegisterConsoleCommandsPtr,::ClientRegisterConsoleCommands);
222
	DETOUR_DETACH(ClientUnregisterConsoleCommandsPtr,::ClientUnregisterConsoleCommands);
223
	DETOUR_COMMIT;
224
}