Subversion Repositories WoWGM

Rev

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)
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"
34 tristanc 18
#include "ClientGMCommands.h"
3 tristanc 19
#include <WowSvcs/ClientServices.h>
20
#include <Glue/CGlueMgr.h>
21
#include <Ui/GameUI.h>
22
#include <FrameScript/FrameScript.h>
19 tristanc 23
#include <Object/ObjectClient/Player_C.h>
3 tristanc 24
 
25
 
26
/****************************************************************************
27
*
31 tristanc 28
*   Client memory addresses
3 tristanc 29
*
30
***/
31
 
32 tristanc 32
#define  CLIENTREGISTERCONSOLECOMMANDS    0x00401B60
33
#define  COMMONMAINDESTROY                0x004066D0
34
#define  COMMONMAININITIALIZE             0x004047E0
34 tristanc 35
#define  INSTALLGAMECONSOLECOMMANDSPTR    0x00407870
36
#define  UNINSTALLGAMECONSOLECOMMANDSPTR  0x00406EF0
32 tristanc 37
#define  SCRIPT_GETBUILDINFO              0x004DBE60
38
#define  WOWCLIENTDESTROY                 0x00402910
39
#define  WOWCLIENTINIT                    0x00404130
3 tristanc 40
 
31 tristanc 41
 
3 tristanc 42
/****************************************************************************
43
*
31 tristanc 44
*   Client function pointers
3 tristanc 45
*
46
***/
47
 
32 tristanc 48
void  (*ClientRegisterConsoleCommands)()  = *(void(*)())CLIENTREGISTERCONSOLECOMMANDS;
49
void  (*CommonMainDestroy)()              = *(void(*)())COMMONMAINDESTROY;
50
void  (*CommonMainInitialize)()           = *(void(*)())COMMONMAININITIALIZE;
34 tristanc 51
void  (*InstallGameConsoleCommands)()     = *(void(*)())INSTALLGAMECONSOLECOMMANDSPTR;
32 tristanc 52
int   (*Script_GetBuildInfo)(lua_State*)  = *(int(*)(lua_State *))SCRIPT_GETBUILDINFO;
34 tristanc 53
void  (*UninstallGameConsoleCommands)()   = *(void(*)())UNINSTALLGAMECONSOLECOMMANDSPTR;
32 tristanc 54
void  (*WowClientDestroy)()               = *(void(*)())WOWCLIENTDESTROY;
55
void  (*WowClientInit)()                  = *(void(*)())WOWCLIENTINIT;
31 tristanc 56
 
3 tristanc 57
 
58
/****************************************************************************
59
*
32 tristanc 60
*   Callbacks
3 tristanc 61
*
62
***/
63
 
64
//===========================================================================
32 tristanc 65
void ClientRegisterConsoleCommandsProc () {
66
	ClientRegisterConsoleCommands();
31 tristanc 67
 
3 tristanc 68
	g_password = CVar::Register("password",
31 tristanc 69
                              "stored password for blizzcon, dev, qa, etc.",
70
                              NULL,
71
                              "",
72
                              NULL,
73
                              GAME,
74
                              false,
75
                              NULL,
76
                              false);
30 tristanc 77
 
78
  ConsoleCommandRegister("Bug", CCommand_Bug, DEBUG, NOHELP);
79
  ConsoleCommandRegister("Suggestion", CCommand_Bug, DEBUG, NOHELP);
3 tristanc 80
}
81
 
82
//===========================================================================
32 tristanc 83
void CommonMainDestroyProc () {
84
	CommonMainDestroy();
3 tristanc 85
}
86
//===========================================================================
32 tristanc 87
void CommonMainInitializeProc () {
88
  ConsoleAccessSetEnabled(TRUE);
89
	CommonMainInitialize();
3 tristanc 90
}
91
 
92
//===========================================================================
34 tristanc 93
void InstallGameConsoleCommandsProc () {
94
  InstallGameConsoleCommands();
95
 
96
  // Register our own commands
97
  ConsoleCommandRegister("godmode",CCommand_Godmode,GAME,NOHELP);
98
  ConsoleCommandRegister("beastmaster",CCommand_Beastmaster,GAME,NOHELP);
99
 
100
  DebugClientCommands::Install();
101
  GMClientCommands::Install();
102
}
103
 
104
//===========================================================================
32 tristanc 105
static int Script_GetBuildInfoProc (lua_State* L) {
3 tristanc 106
	char* version = FrameScript_GetText("VERSION", -1, GENDER_NONE);
107
	_lua_pushstring(L, version);
108
#ifdef _DEBUG
109
	_lua_pushstring(L,"Debug");
110
#else
111
	_lua_pushstring(L, "GM");
112
#endif // #ifdef _DEBUG
113
	_lua_pushstring(L, "3.3.5");
114
	_lua_pushstring(L, "12340");
115
	_lua_pushstring(L, __DATE__);
32 tristanc 116
	return 5;
3 tristanc 117
}
118
 
119
//===========================================================================
34 tristanc 120
void UninstallGameConsoleCommandsProc () {
121
  UninstallGameConsoleCommands();
122
 
123
  // Unregister our own commands
124
  ConsoleCommandUnregister("godmode");
125
  ConsoleCommandUnregister("beastmaster");
126
 
127
  DebugClientCommands::Uninstall();
128
  GMClientCommands::Uninstall();
129
}
130
 
131
//===========================================================================
32 tristanc 132
void WowClientDestroyProc () {
133
  ConsoleCommandUnregister("Bug");
134
  ConsoleCommandUnregister("Suggestion");
135
  WowClientDestroy();
136
}
3 tristanc 137
 
32 tristanc 138
//===========================================================================
139
void WowClientInitProc () {
140
	WowClientInit();
141
  WowGM::CGlueMgr::SetLoginPassword();
142
  ConsoleCommandExecute("run autoexec.wtf",FALSE);
3 tristanc 143
}
144
 
145
 
146
//===========================================================================
32 tristanc 147
void RegisterClientCallbacks () {
148
  DETOUR_INIT;
149
  DETOUR_ATTACH(CommonMainDestroy, CommonMainDestroyProc);
150
  DETOUR_ATTACH(CommonMainInitialize, CommonMainInitializeProc);
151
  DETOUR_ATTACH(ClientRegisterConsoleCommands, ClientRegisterConsoleCommandsProc);
152
  DETOUR_ATTACH(Script_GetBuildInfo, Script_GetBuildInfoProc);
153
  DETOUR_ATTACH(WowClientDestroy, WowClientDestroyProc);
154
  DETOUR_ATTACH(WowClientInit, WowClientInitProc);
34 tristanc 155
  DETOUR_ATTACH(InstallGameConsoleCommands, InstallGameConsoleCommandsProc);
156
  DETOUR_ATTACH(UninstallGameConsoleCommands, UninstallGameConsoleCommandsProc);
32 tristanc 157
  DETOUR_COMMIT;
3 tristanc 158
}
159
 
160
//===========================================================================
32 tristanc 161
void UnregisterClientCallbacks () {
162
  DETOUR_INIT;
163
  DETOUR_DETACH(CommonMainDestroy, CommonMainDestroyProc);
164
  DETOUR_DETACH(CommonMainInitialize, CommonMainInitializeProc);
165
  DETOUR_DETACH(ClientRegisterConsoleCommands, ClientRegisterConsoleCommandsProc);
166
  DETOUR_DETACH(Script_GetBuildInfo, Script_GetBuildInfoProc);
167
  DETOUR_DETACH(WowClientDestroy, WowClientDestroyProc);
168
  DETOUR_DETACH(WowClientInit, WowClientInitProc);
34 tristanc 169
  DETOUR_DETACH(InstallGameConsoleCommands, InstallGameConsoleCommandsProc);
170
  DETOUR_DETACH(UninstallGameConsoleCommands, UninstallGameConsoleCommandsProc);
32 tristanc 171
  DETOUR_COMMIT;
3 tristanc 172
}
173
 
32 tristanc 174
 
175
/****************************************************************************
176
*
177
*   Program entry point (DllMain)
178
*
179
***/
180
 
3 tristanc 181
//===========================================================================
32 tristanc 182
extern "C" BOOL WINAPI DllMain (HINSTANCE const instance,
183
                                DWORD const     reason,
184
                                LPVOID const    reserved) {
185
 
186
	switch (reason) {
187
		case DLL_PROCESS_ATTACH:
188
    {
189
      // Allow callbacks outside of the .text section
190
      *((int*)0x00D415B8) = 0x00000001;
191
      *((int*)0x00D415BC) = 0x7FFFFFFF;
192
 
193
      // Initialize the Detour library
194
      DetourRestoreAfterWith();
195
 
196
      RegisterClientCallbacks();
197
			ConsoleCommandInitialize();
198
			CGlueMgr::Initialize();
199
			CGGameUI::Initialize();
200
      //TODO:
201
			//ClientServices_Initialize();
202
			break;
203
		}
204
		case DLL_THREAD_ATTACH:
205
		case DLL_THREAD_DETACH:
206
			break;
207
		case DLL_PROCESS_DETACH:
208
    {
209
      UnregisterClientCallbacks();
210
      //TODO:
211
      WowGM::CGlueMgr::Shutdown();
212
			CGGameUI::Shutdown();
213
			//ClientServices_Destroy();
214
			break;
215
		}
216
	}
217
 
218
	return TRUE;
3 tristanc 219
}