Subversion Repositories WoWGM

Rev

Rev 34 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34 Rev 36
Line 1... Line 1...
1
/****************************************************************************
1
/******************************************************************************
2
*
2
*
3
*   Client.cpp
3
*   Client.cpp
4
*
4
*
5
*   Program entry point (DllMain)
-
 
6
*
5
*
7
*   Written by Tristan Cormier
6
*   By Tristan Cormier - 11/20/2024
8
*   11.20.24
-
 
9
* 
7
* 
10
***/
8
***/
11
 
9
 
-
 
10
 
12
#include "pch.h"
11
#include "pch.h"
13
#pragma hdrstop
12
#pragma hdrstop
14
 
13
 
15
#include "Client.h"
-
 
16
#include "ClientCommands.h"
14
#include "ClientCommands.h"
17
#include "ClientDebugCommands.h"
15
#include "ClientDebugCommands.h"
18
#include "ClientGMCommands.h"
16
#include "ClientGMCommands.h"
-
 
17
#include <Console/ConsoleClient.h>
19
#include <WowSvcs/ClientServices.h>
18
#include <WowSvcs/ClientServices.h>
20
#include <Glue/CGlueMgr.h>
19
#include <Glue/CGlueMgr.h>
21
#include <Ui/GameUI.h>
20
#include <Ui/GameUI.h>
22
#include <FrameScript/FrameScript.h>
21
#include <FrameScript/FrameScript.h>
23
#include <Object/ObjectClient/Player_C.h>
-
 
24
 
22
 
25
 
23
 
26
/****************************************************************************
24
/******************************************************************************
27
*
25
*
28
*   Client memory addresses
26
*   Private
29
*
27
*
30
***/
28
***/
31
 
29
 
32
#define  CLIENTREGISTERCONSOLECOMMANDS    0x00401B60
30
void (*ClientRegisterConsoleCommands)() = *(void(*)())0x401B60;
33
#define  COMMONMAINDESTROY                0x004066D0
-
 
34
#define  COMMONMAININITIALIZE             0x004047E0
-
 
35
#define  INSTALLGAMECONSOLECOMMANDSPTR    0x00407870
-
 
36
#define  UNINSTALLGAMECONSOLECOMMANDSPTR  0x00406EF0
-
 
37
#define  SCRIPT_GETBUILDINFO              0x004DBE60
-
 
38
#define  WOWCLIENTDESTROY                 0x00402910
-
 
39
#define  WOWCLIENTINIT                    0x00404130
-
 
40
 
31
 
-
 
32
void (*CommonMainInitialize)() = *(void(*)())0x4047E0;
-
 
33
void (*CommonMainDestroy)() = *(void(*)())0x4066D0;
41
 
34
 
42
/****************************************************************************
35
void (*InstallGameConsoleCommands)() = *(void(*)())0x407870;
43
*
-
 
44
*   Client function pointers
36
void (*UninstallGameConsoleCommands)() = *(void(*)())0x406EF0;
45
*
-
 
46
***/
-
 
47
 
37
 
48
void  (*ClientRegisterConsoleCommands)()  = *(void(*)())CLIENTREGISTERCONSOLECOMMANDS;
-
 
49
void  (*CommonMainDestroy)()              = *(void(*)())COMMONMAINDESTROY;
-
 
50
void  (*CommonMainInitialize)()           = *(void(*)())COMMONMAININITIALIZE;
-
 
51
void  (*InstallGameConsoleCommands)()     = *(void(*)())INSTALLGAMECONSOLECOMMANDSPTR;
-
 
52
int   (*Script_GetBuildInfo)(lua_State*)  = *(int(*)(lua_State *))SCRIPT_GETBUILDINFO;
-
 
53
void  (*UninstallGameConsoleCommands)()   = *(void(*)())UNINSTALLGAMECONSOLECOMMANDSPTR;
-
 
54
void  (*WowClientDestroy)()               = *(void(*)())WOWCLIENTDESTROY;
38
void (*WowClientInit)() = *(void(*)())0x404130;
55
void  (*WowClientInit)()                  = *(void(*)())WOWCLIENTINIT;
39
void (*WowClientDestroy)() = *(void(*)())0x402910;
56
 
40
 
-
 
41
int (*Script_GetBuildInfo)(lua_State *) = *(int(*)(lua_State *))0x4DBE60;
57
 
42
 
58
/****************************************************************************
-
 
59
*
-
 
60
*   Callbacks
-
 
61
*
-
 
62
***/
-
 
63
 
43
 
64
//===========================================================================
44
//=============================================================================
65
void ClientRegisterConsoleCommandsProc () {
45
void ClientRegisterConsoleCommandsProc () {
66
	ClientRegisterConsoleCommands();
46
    ClientRegisterConsoleCommands();
-
 
47
    
-
 
48
    g_password = CVar::Register(
-
 
49
        "password",
-
 
50
        "stored password for blizzcon, dev, qa, etc.",
-
 
51
        NULL,
-
 
52
        "",
-
 
53
        NULL,
-
 
54
        GAME,
-
 
55
        false,
-
 
56
        NULL,
-
 
57
        false
-
 
58
    );
67
 
59
 
68
	g_password = CVar::Register("password",
60
    ConsoleCommandRegister("Bug", CCommand_Bug, DEBUG, NOHELP);
69
                              "stored password for blizzcon, dev, qa, etc.",
61
    ConsoleCommandRegister("Suggestion", CCommand_Bug, DEBUG, NOHELP);
70
                              NULL,
-
 
71
                              "",
-
 
72
                              NULL,
-
 
73
                              GAME,
-
 
74
                              false,
-
 
75
                              NULL,
-
 
76
                              false);
-
 
-
 
62
}
77
 
63
 
-
 
64
//=============================================================================
78
  ConsoleCommandRegister("Bug", CCommand_Bug, DEBUG, NOHELP);
65
void CommonMainInitializeProc () {
79
  ConsoleCommandRegister("Suggestion", CCommand_Bug, DEBUG, NOHELP);
66
    ConsoleAccessSetEnabled(TRUE);
-
 
67
 
-
 
68
    CommonMainInitialize();
80
}
69
}
81
 
70
 
82
//===========================================================================
71
//=============================================================================
83
void CommonMainDestroyProc () {
72
void CommonMainDestroyProc () {
84
	CommonMainDestroy();
73
    CommonMainDestroy();
85
}
-
 
86
//===========================================================================
-
 
87
void CommonMainInitializeProc () {
-
 
88
  ConsoleAccessSetEnabled(TRUE);
-
 
89
	CommonMainInitialize();
-
 
90
}
74
}
91
 
75
 
92
//===========================================================================
76
//=============================================================================
93
void InstallGameConsoleCommandsProc () {
77
void InstallGameConsoleCommandsProc () {
94
  InstallGameConsoleCommands();
78
    InstallGameConsoleCommands();
95
 
79
 
96
  // Register our own commands
-
 
97
  ConsoleCommandRegister("godmode",CCommand_Godmode,GAME,NOHELP);
80
    ConsoleCommandRegister("godmode", CCommand_Godmode, GAME, NOHELP);
98
  ConsoleCommandRegister("beastmaster",CCommand_Beastmaster,GAME,NOHELP);
81
    ConsoleCommandRegister("beastmaster", CCommand_Beastmaster, GAME, NOHELP);
99
 
82
 
100
  DebugClientCommands::Install();
83
    DebugClientCommands::Install();
101
  GMClientCommands::Install();
84
    GMClientCommands::Install();
102
}
85
}
103
 
86
 
104
//===========================================================================
87
//=============================================================================
105
static int Script_GetBuildInfoProc (lua_State* L) {
88
void UninstallGameConsoleCommandsProc () {
106
	char* version = FrameScript_GetText("VERSION", -1, GENDER_NONE);
-
 
107
	_lua_pushstring(L, version);
89
    UninstallGameConsoleCommands();
108
#ifdef _DEBUG
-
 
109
	_lua_pushstring(L,"Debug");
-
 
110
#else
90
 
111
	_lua_pushstring(L, "GM");
91
    ConsoleCommandUnregister("godmode");
112
#endif // #ifdef _DEBUG
-
 
113
	_lua_pushstring(L, "3.3.5");
92
    ConsoleCommandUnregister("beastmaster");
-
 
93
 
114
	_lua_pushstring(L, "12340");
94
    DebugClientCommands::Uninstall();
115
	_lua_pushstring(L, __DATE__);
95
    GMClientCommands::Uninstall();
116
	return 5;
-
 
117
}
96
}
118
 
97
 
119
//===========================================================================
98
//=============================================================================
120
void UninstallGameConsoleCommandsProc () {
99
void WowClientInitProc () {
121
  UninstallGameConsoleCommands();
100
    WowClientInit();
122
 
101
 
123
  // Unregister our own commands
102
    // HACK:
124
  ConsoleCommandUnregister("godmode");
103
    // The login password should be set via GlueXML but we do it in code
125
  ConsoleCommandUnregister("beastmaster");
104
    WowGM::CGlueMgr::SetLoginPassword();
126
 
105
 
127
  DebugClientCommands::Uninstall();
-
 
128
  GMClientCommands::Uninstall();
106
    ConsoleCommandExecute("run autoexec.wtf", FALSE);
129
}
107
}
130
 
108
 
131
//===========================================================================
109
//=============================================================================
132
void WowClientDestroyProc () {
110
void WowClientDestroyProc () {
133
  ConsoleCommandUnregister("Bug");
111
    ConsoleCommandUnregister("Bug");
134
  ConsoleCommandUnregister("Suggestion");
112
    ConsoleCommandUnregister("Suggestion");
-
 
113
    
135
  WowClientDestroy();
114
    WowClientDestroy();
136
}
115
}
137
 
116
 
138
//===========================================================================
117
//=============================================================================
139
void WowClientInitProc () {
118
static int Script_GetBuildInfoProc (lua_State* L) {
-
 
119
    char* version = FrameScript_GetText("VERSION", -1, GENDER_NONE);
-
 
120
    _lua_pushstring(L, version);
140
	WowClientInit();
121
#ifdef _DEBUG
-
 
122
    _lua_pushstring(L, "Debug");
-
 
123
#else
141
  WowGM::CGlueMgr::SetLoginPassword();
124
    _lua_pushstring(L, "GM");
-
 
125
#endif
142
  ConsoleCommandExecute("run autoexec.wtf",FALSE);
126
    _lua_pushstring(L, "3.3.5");
-
 
127
    _lua_pushstring(L, "12340");
-
 
128
    _lua_pushstring(L, __DATE__);
-
 
129
    return 5;
143
}
130
}
144
 
131
 
145
 
132
 
146
//===========================================================================
133
//=============================================================================
147
void RegisterClientCallbacks () {
134
void RegisterClientCallbacks () {
148
  DETOUR_INIT;
135
    DETOUR_INIT;
-
 
136
 
149
  DETOUR_ATTACH(CommonMainDestroy, CommonMainDestroyProc);
137
    DETOUR_ATTACH(
150
  DETOUR_ATTACH(CommonMainInitialize, CommonMainInitializeProc);
138
        ClientRegisterConsoleCommands,
151
  DETOUR_ATTACH(ClientRegisterConsoleCommands, ClientRegisterConsoleCommandsProc);
139
        ClientRegisterConsoleCommandsProc
-
 
140
    );
-
 
141
 
-
 
142
    DETOUR_ATTACH(
-
 
143
        CommonMainInitialize,
152
  DETOUR_ATTACH(Script_GetBuildInfo, Script_GetBuildInfoProc);
144
        CommonMainInitializeProc
-
 
145
    );
-
 
146
    DETOUR_ATTACH(
-
 
147
        CommonMainDestroy,
153
  DETOUR_ATTACH(WowClientDestroy, WowClientDestroyProc);
148
        CommonMainDestroyProc
-
 
149
    );
-
 
150
    
-
 
151
    DETOUR_ATTACH(
-
 
152
        InstallGameConsoleCommands,
154
  DETOUR_ATTACH(WowClientInit, WowClientInitProc);
153
        InstallGameConsoleCommandsProc
-
 
154
    );
-
 
155
    DETOUR_ATTACH(
155
  DETOUR_ATTACH(InstallGameConsoleCommands, InstallGameConsoleCommandsProc);
156
        UninstallGameConsoleCommands,
156
  DETOUR_ATTACH(UninstallGameConsoleCommands, UninstallGameConsoleCommandsProc);
157
        UninstallGameConsoleCommandsProc
-
 
158
    );
-
 
159
 
-
 
160
    DETOUR_ATTACH(
-
 
161
        WowClientInit,
-
 
162
        WowClientInitProc
-
 
163
    );
-
 
164
    DETOUR_ATTACH(
-
 
165
        WowClientDestroy,
-
 
166
        WowClientDestroyProc
-
 
167
    );
-
 
168
 
-
 
169
    DETOUR_ATTACH(
-
 
170
        Script_GetBuildInfo,
-
 
171
        Script_GetBuildInfoProc
-
 
172
    );
-
 
173
 
157
  DETOUR_COMMIT;
174
    DETOUR_COMMIT;
158
}
175
}
159
 
176
 
160
//===========================================================================
177
//=============================================================================
161
void UnregisterClientCallbacks () {
178
void UnregisterClientCallbacks () {
162
  DETOUR_INIT;
179
    DETOUR_INIT;
-
 
180
 
163
  DETOUR_DETACH(CommonMainDestroy, CommonMainDestroyProc);
181
    DETOUR_DETACH(
164
  DETOUR_DETACH(CommonMainInitialize, CommonMainInitializeProc);
182
        ClientRegisterConsoleCommands,
165
  DETOUR_DETACH(ClientRegisterConsoleCommands, ClientRegisterConsoleCommandsProc);
183
        ClientRegisterConsoleCommandsProc
-
 
184
    );
-
 
185
 
-
 
186
    DETOUR_DETACH(
-
 
187
        CommonMainInitialize,
166
  DETOUR_DETACH(Script_GetBuildInfo, Script_GetBuildInfoProc);
188
        CommonMainInitializeProc
-
 
189
    );
-
 
190
    DETOUR_DETACH(
-
 
191
        CommonMainDestroy,
167
  DETOUR_DETACH(WowClientDestroy, WowClientDestroyProc);
192
        CommonMainDestroyProc
-
 
193
    );
-
 
194
 
-
 
195
    DETOUR_DETACH(
-
 
196
        InstallGameConsoleCommands,
168
  DETOUR_DETACH(WowClientInit, WowClientInitProc);
197
        InstallGameConsoleCommandsProc
-
 
198
    );
-
 
199
    DETOUR_DETACH(
169
  DETOUR_DETACH(InstallGameConsoleCommands, InstallGameConsoleCommandsProc);
200
        UninstallGameConsoleCommands,
170
  DETOUR_DETACH(UninstallGameConsoleCommands, UninstallGameConsoleCommandsProc);
201
        UninstallGameConsoleCommandsProc
-
 
202
    );
-
 
203
 
-
 
204
    DETOUR_DETACH(
-
 
205
        WowClientInit,
-
 
206
        WowClientInitProc
-
 
207
    );
-
 
208
    DETOUR_DETACH(
-
 
209
        WowClientDestroy,
-
 
210
        WowClientDestroyProc
-
 
211
    );
-
 
212
 
-
 
213
    DETOUR_DETACH(
-
 
214
        Script_GetBuildInfo,
-
 
215
        Script_GetBuildInfoProc
-
 
216
    );
-
 
217
 
171
  DETOUR_COMMIT;
218
    DETOUR_COMMIT;
172
}
219
}
173
 
220
 
174
 
221
 
175
/****************************************************************************
222
/******************************************************************************
176
*
223
*
177
*   Program entry point (DllMain)
224
*   Program entry point
178
*
225
*
179
***/
226
***/
180
 
227
 
181
//===========================================================================
228
//=============================================================================
182
extern "C" BOOL WINAPI DllMain (HINSTANCE const instance,
229
extern "C" BOOL WINAPI DllMain (
-
 
230
    HINSTANCE const instance,
183
                                DWORD const     reason,
231
    DWORD const     reason,
184
                                LPVOID const    reserved) {
232
    LPVOID const    reserved
185
 
233
) {
186
	switch (reason) {
234
    switch (reason) {
187
		case DLL_PROCESS_ATTACH:
235
	    case DLL_PROCESS_ATTACH: {
188
    {
-
 
189
      // Allow callbacks outside of the .text section
236
          // Allow callbacks outside of the .text section
190
      *((int*)0x00D415B8) = 0x00000001;
237
          * ((int * )0xD415B8) = 0x00000001;
191
      *((int*)0x00D415BC) = 0x7FFFFFFF;
238
          * ((int * )0xD415BC) = 0x7FFFFFFF;
192
 
239
 
193
      // Initialize the Detour library
240
          // Initialize the Detour library
194
      DetourRestoreAfterWith();
241
          DetourRestoreAfterWith();
195
 
242
 
196
      RegisterClientCallbacks();
243
          RegisterClientCallbacks();
-
 
244
 
197
			ConsoleCommandInitialize();
245
          ConsoleCommandInitialize();
198
			CGlueMgr::Initialize();
246
          CGlueMgr::Initialize();
199
			CGGameUI::Initialize();
247
          CGGameUI::Initialize();
200
      //TODO:
248
          // TODO:
201
			//ClientServices_Initialize();
249
          //ClientServices_Initialize();
202
			break;
250
          break;
203
		}
251
        }
204
		case DLL_THREAD_ATTACH:
252
		case DLL_THREAD_ATTACH:
205
		case DLL_THREAD_DETACH:
253
		case DLL_THREAD_DETACH:
206
			break;
254
			break;
207
		case DLL_PROCESS_DETACH:
255
		case DLL_PROCESS_DETACH: {
208
    {
-
 
209
      UnregisterClientCallbacks();
256
            UnregisterClientCallbacks();
210
      //TODO:
257
            // TODO
-
 
258
            //ClientServices_Destroy();
211
      WowGM::CGlueMgr::Shutdown();
259
            WowGM::CGlueMgr::Shutdown();
212
			CGGameUI::Shutdown();
260
			CGGameUI::Shutdown();
213
			//ClientServices_Destroy();
-
 
214
			break;
261
            break;
215
		}
262
        }
216
	}
263
    }
217
 
264
 
218
	return TRUE;
265
    return TRUE;
219
}
266
}
-
 
267
 
-
 
268
 
-
 
269
//===================================
-
 
270
// MIT License
-
 
271
//
-
 
272
// Copyright (c) 2024 by Tristan Cormier
-
 
273
//
-
 
274
// Permission is hereby granted, free of charge, to any person obtaining a copy
-
 
275
// of this software and associated documentation files (the "Software"), to deal
-
 
276
// in the Software without restriction, including without limitation the rights
-
 
277
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-
 
278
// copies of the Software, and to permit persons to whom the Software is
-
 
279
// furnished to do so, subject to the following conditions:
-
 
280
//
-
 
281
// The above copyright notice and this permission notice shall be included in
-
 
282
// all copies or substantial portions of the Software.
-
 
283
// 
-
 
284
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-
 
285
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-
 
286
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-
 
287
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-
 
288
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-
 
289
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-
 
290
// THE SOFTWARE.
-
 
291
//===================================
220
 
292