Subversion Repositories WoWGM

Rev

Rev 31 | Rev 34 | 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)
32 tristanc 6
*
7
*   Written by Tristan Cormier
8
*   11.20.24
3 tristanc 9
* 
10
***/
11
 
12
#include "pch.h"
13
#pragma hdrstop
14
 
15
#include "Client.h"
16
#include "ClientCommands.h"
17
#include "ClientDebugCommands.h"
18
#include <WowSvcs/ClientServices.h>
19
#include <Glue/CGlueMgr.h>
20
#include <Ui/GameUI.h>
21
#include <FrameScript/FrameScript.h>
19 tristanc 22
#include <Object/ObjectClient/Player_C.h>
3 tristanc 23
 
24
 
32 tristanc 25
//===========================================================================
26
BOOL CCommand_Bug(char const* command, char const* args);
27
 
28
 
3 tristanc 29
/****************************************************************************
30
*
31 tristanc 31
*   Client memory addresses
3 tristanc 32
*
33
***/
34
 
32 tristanc 35
#define  CLIENTREGISTERCONSOLECOMMANDS    0x00401B60
36
#define  COMMONMAINDESTROY                0x004066D0
37
#define  COMMONMAININITIALIZE             0x004047E0
38
#define  SCRIPT_GETBUILDINFO              0x004DBE60
39
#define  WOWCLIENTDESTROY                 0x00402910
40
#define  WOWCLIENTINIT                    0x00404130
3 tristanc 41
 
31 tristanc 42
 
3 tristanc 43
/****************************************************************************
44
*
31 tristanc 45
*   Client function pointers
3 tristanc 46
*
47
***/
48
 
32 tristanc 49
void  (*ClientRegisterConsoleCommands)()  = *(void(*)())CLIENTREGISTERCONSOLECOMMANDS;
50
void  (*CommonMainDestroy)()              = *(void(*)())COMMONMAINDESTROY;
51
void  (*CommonMainInitialize)()           = *(void(*)())COMMONMAININITIALIZE;
52
int   (*Script_GetBuildInfo)(lua_State*)  = *(int(*)(lua_State *))SCRIPT_GETBUILDINFO;
53
void  (*WowClientDestroy)()               = *(void(*)())WOWCLIENTDESTROY;
54
void  (*WowClientInit)()                  = *(void(*)())WOWCLIENTINIT;
31 tristanc 55
 
3 tristanc 56
 
57
/****************************************************************************
58
*
32 tristanc 59
*   Callbacks
3 tristanc 60
*
61
***/
62
 
63
//===========================================================================
32 tristanc 64
void ClientRegisterConsoleCommandsProc () {
65
	ClientRegisterConsoleCommands();
31 tristanc 66
 
3 tristanc 67
	g_password = CVar::Register("password",
31 tristanc 68
                              "stored password for blizzcon, dev, qa, etc.",
69
                              NULL,
70
                              "",
71
                              NULL,
72
                              GAME,
73
                              false,
74
                              NULL,
75
                              false);
30 tristanc 76
 
77
  ConsoleCommandRegister("Bug", CCommand_Bug, DEBUG, NOHELP);
78
  ConsoleCommandRegister("Suggestion", CCommand_Bug, DEBUG, NOHELP);
3 tristanc 79
}
80
 
81
//===========================================================================
32 tristanc 82
void CommonMainDestroyProc () {
83
	CommonMainDestroy();
3 tristanc 84
}
85
//===========================================================================
32 tristanc 86
void CommonMainInitializeProc () {
87
  ConsoleAccessSetEnabled(TRUE);
88
	CommonMainInitialize();
3 tristanc 89
}
90
 
91
//===========================================================================
32 tristanc 92
static int Script_GetBuildInfoProc (lua_State* L) {
3 tristanc 93
	char* version = FrameScript_GetText("VERSION", -1, GENDER_NONE);
94
	_lua_pushstring(L, version);
95
#ifdef _DEBUG
96
	_lua_pushstring(L,"Debug");
97
#else
98
	_lua_pushstring(L, "GM");
99
#endif // #ifdef _DEBUG
100
	_lua_pushstring(L, "3.3.5");
101
	_lua_pushstring(L, "12340");
102
	_lua_pushstring(L, __DATE__);
32 tristanc 103
	return 5;
3 tristanc 104
}
105
 
106
//===========================================================================
32 tristanc 107
void WowClientDestroyProc () {
108
  ConsoleCommandUnregister("Bug");
109
  ConsoleCommandUnregister("Suggestion");
110
  WowClientDestroy();
111
}
3 tristanc 112
 
32 tristanc 113
//===========================================================================
114
void WowClientInitProc () {
115
	WowClientInit();
116
  WowGM::CGlueMgr::SetLoginPassword();
117
  ConsoleCommandExecute("run autoexec.wtf",FALSE);
3 tristanc 118
}
119
 
120
 
121
/****************************************************************************
122
*
32 tristanc 123
*   Private
3 tristanc 124
*
125
***/
126
 
127
//===========================================================================
32 tristanc 128
void RegisterClientCallbacks () {
129
  DETOUR_INIT;
130
  DETOUR_ATTACH(CommonMainDestroy, CommonMainDestroyProc);
131
  DETOUR_ATTACH(CommonMainInitialize, CommonMainInitializeProc);
132
  DETOUR_ATTACH(ClientRegisterConsoleCommands, ClientRegisterConsoleCommandsProc);
133
  DETOUR_ATTACH(Script_GetBuildInfo, Script_GetBuildInfoProc);
134
  DETOUR_ATTACH(WowClientDestroy, WowClientDestroyProc);
135
  DETOUR_ATTACH(WowClientInit, WowClientInitProc);
136
  DETOUR_COMMIT;
3 tristanc 137
}
138
 
139
//===========================================================================
32 tristanc 140
void UnregisterClientCallbacks () {
141
  DETOUR_INIT;
142
  DETOUR_DETACH(CommonMainDestroy, CommonMainDestroyProc);
143
  DETOUR_DETACH(CommonMainInitialize, CommonMainInitializeProc);
144
  DETOUR_DETACH(ClientRegisterConsoleCommands, ClientRegisterConsoleCommandsProc);
145
  DETOUR_DETACH(Script_GetBuildInfo, Script_GetBuildInfoProc);
146
  DETOUR_DETACH(WowClientDestroy, WowClientDestroyProc);
147
  DETOUR_DETACH(WowClientInit, WowClientInitProc);
148
  DETOUR_COMMIT;
3 tristanc 149
}
150
 
151
//===========================================================================
32 tristanc 152
BOOL CCommand_Bug (char const* command, char const* args) {
153
  //TODO:
154
  //ASSERT(command);
155
 
156
  unsigned int category;
157
 
158
  if (!SStrCmpI(command, "bug"))
159
    category = 0;
160
  else if (!SStrCmpI(command, "suggestion"))
161
    category = 1;
162
 
163
  if (ClientServices_Report(category, args))
164
    ConsolePrintf("%s submitted", command);
165
  else
166
    ConsolePrintf("%s submission failed", command);
167
 
168
  return TRUE;
3 tristanc 169
}
170
 
32 tristanc 171
 
172
/****************************************************************************
173
*
174
*   Program entry point (DllMain)
175
*
176
***/
177
 
3 tristanc 178
//===========================================================================
32 tristanc 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();
199
			WowGM::InstallGameConsoleCommands();
200
			break;
201
		}
202
		case DLL_THREAD_ATTACH:
203
		case DLL_THREAD_DETACH:
204
			break;
205
		case DLL_PROCESS_DETACH:
206
    {
207
      UnregisterClientCallbacks();
208
      //TODO:
209
      WowGM::CGlueMgr::Shutdown();
210
			CGGameUI::Shutdown();
211
			//ClientServices_Destroy();
212
			WowGM::UninstallGameConsoleCommands();
213
			break;
214
		}
215
	}
216
 
217
	return TRUE;
3 tristanc 218
}