Subversion Repositories WoWGM

Rev

Rev 31 | Rev 34 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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