Subversion Repositories WoWGM

Rev

Rev 30 | Rev 32 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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