Subversion Repositories WoWGM

Rev

Rev 34 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
36 tristanc 1
/******************************************************************************
3 tristanc 2
*
31 tristanc 3
*   Client.cpp
3 tristanc 4
*
32 tristanc 5
*
36 tristanc 6
*   By Tristan Cormier - 11/20/2024
3 tristanc 7
* 
8
***/
9
 
36 tristanc 10
 
3 tristanc 11
#include "pch.h"
12
#pragma hdrstop
13
 
14
#include "ClientCommands.h"
15
#include "ClientDebugCommands.h"
34 tristanc 16
#include "ClientGMCommands.h"
36 tristanc 17
#include <Console/ConsoleClient.h>
3 tristanc 18
#include <WowSvcs/ClientServices.h>
19
#include <Glue/CGlueMgr.h>
20
#include <Ui/GameUI.h>
21
#include <FrameScript/FrameScript.h>
22
 
23
 
36 tristanc 24
/******************************************************************************
3 tristanc 25
*
36 tristanc 26
*   Private
3 tristanc 27
*
28
***/
29
 
36 tristanc 30
void (*ClientRegisterConsoleCommands)() = *(void(*)())0x401B60;
3 tristanc 31
 
36 tristanc 32
void (*CommonMainInitialize)() = *(void(*)())0x4047E0;
33
void (*CommonMainDestroy)() = *(void(*)())0x4066D0;
31 tristanc 34
 
36 tristanc 35
void (*InstallGameConsoleCommands)() = *(void(*)())0x407870;
36
void (*UninstallGameConsoleCommands)() = *(void(*)())0x406EF0;
3 tristanc 37
 
36 tristanc 38
void (*WowClientInit)() = *(void(*)())0x404130;
39
void (*WowClientDestroy)() = *(void(*)())0x402910;
31 tristanc 40
 
36 tristanc 41
int (*Script_GetBuildInfo)(lua_State *) = *(int(*)(lua_State *))0x4DBE60;
3 tristanc 42
 
43
 
36 tristanc 44
//=============================================================================
32 tristanc 45
void ClientRegisterConsoleCommandsProc () {
36 tristanc 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
    );
31 tristanc 59
 
36 tristanc 60
    ConsoleCommandRegister("Bug", CCommand_Bug, DEBUG, NOHELP);
61
    ConsoleCommandRegister("Suggestion", CCommand_Bug, DEBUG, NOHELP);
62
}
30 tristanc 63
 
36 tristanc 64
//=============================================================================
65
void CommonMainInitializeProc () {
66
    ConsoleAccessSetEnabled(TRUE);
67
 
68
    CommonMainInitialize();
3 tristanc 69
}
70
 
36 tristanc 71
//=============================================================================
32 tristanc 72
void CommonMainDestroyProc () {
36 tristanc 73
    CommonMainDestroy();
3 tristanc 74
}
75
 
36 tristanc 76
//=============================================================================
34 tristanc 77
void InstallGameConsoleCommandsProc () {
36 tristanc 78
    InstallGameConsoleCommands();
34 tristanc 79
 
36 tristanc 80
    ConsoleCommandRegister("godmode", CCommand_Godmode, GAME, NOHELP);
81
    ConsoleCommandRegister("beastmaster", CCommand_Beastmaster, GAME, NOHELP);
34 tristanc 82
 
36 tristanc 83
    DebugClientCommands::Install();
84
    GMClientCommands::Install();
34 tristanc 85
}
86
 
36 tristanc 87
//=============================================================================
88
void UninstallGameConsoleCommandsProc () {
89
    UninstallGameConsoleCommands();
90
 
91
    ConsoleCommandUnregister("godmode");
92
    ConsoleCommandUnregister("beastmaster");
93
 
94
    DebugClientCommands::Uninstall();
95
    GMClientCommands::Uninstall();
3 tristanc 96
}
97
 
36 tristanc 98
//=============================================================================
99
void WowClientInitProc () {
100
    WowClientInit();
34 tristanc 101
 
36 tristanc 102
    // HACK:
103
    // The login password should be set via GlueXML but we do it in code
104
    WowGM::CGlueMgr::SetLoginPassword();
34 tristanc 105
 
36 tristanc 106
    ConsoleCommandExecute("run autoexec.wtf", FALSE);
34 tristanc 107
}
108
 
36 tristanc 109
//=============================================================================
32 tristanc 110
void WowClientDestroyProc () {
36 tristanc 111
    ConsoleCommandUnregister("Bug");
112
    ConsoleCommandUnregister("Suggestion");
113
 
114
    WowClientDestroy();
32 tristanc 115
}
3 tristanc 116
 
36 tristanc 117
//=============================================================================
118
static int Script_GetBuildInfoProc (lua_State* L) {
119
    char* version = FrameScript_GetText("VERSION", -1, GENDER_NONE);
120
    _lua_pushstring(L, version);
121
#ifdef _DEBUG
122
    _lua_pushstring(L, "Debug");
123
#else
124
    _lua_pushstring(L, "GM");
125
#endif
126
    _lua_pushstring(L, "3.3.5");
127
    _lua_pushstring(L, "12340");
128
    _lua_pushstring(L, __DATE__);
129
    return 5;
3 tristanc 130
}
131
 
132
 
36 tristanc 133
//=============================================================================
32 tristanc 134
void RegisterClientCallbacks () {
36 tristanc 135
    DETOUR_INIT;
136
 
137
    DETOUR_ATTACH(
138
        ClientRegisterConsoleCommands,
139
        ClientRegisterConsoleCommandsProc
140
    );
141
 
142
    DETOUR_ATTACH(
143
        CommonMainInitialize,
144
        CommonMainInitializeProc
145
    );
146
    DETOUR_ATTACH(
147
        CommonMainDestroy,
148
        CommonMainDestroyProc
149
    );
150
 
151
    DETOUR_ATTACH(
152
        InstallGameConsoleCommands,
153
        InstallGameConsoleCommandsProc
154
    );
155
    DETOUR_ATTACH(
156
        UninstallGameConsoleCommands,
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
 
174
    DETOUR_COMMIT;
3 tristanc 175
}
176
 
36 tristanc 177
//=============================================================================
32 tristanc 178
void UnregisterClientCallbacks () {
36 tristanc 179
    DETOUR_INIT;
180
 
181
    DETOUR_DETACH(
182
        ClientRegisterConsoleCommands,
183
        ClientRegisterConsoleCommandsProc
184
    );
185
 
186
    DETOUR_DETACH(
187
        CommonMainInitialize,
188
        CommonMainInitializeProc
189
    );
190
    DETOUR_DETACH(
191
        CommonMainDestroy,
192
        CommonMainDestroyProc
193
    );
194
 
195
    DETOUR_DETACH(
196
        InstallGameConsoleCommands,
197
        InstallGameConsoleCommandsProc
198
    );
199
    DETOUR_DETACH(
200
        UninstallGameConsoleCommands,
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
 
218
    DETOUR_COMMIT;
3 tristanc 219
}
220
 
32 tristanc 221
 
36 tristanc 222
/******************************************************************************
32 tristanc 223
*
36 tristanc 224
*   Program entry point
32 tristanc 225
*
226
***/
227
 
36 tristanc 228
//=============================================================================
229
extern "C" BOOL WINAPI DllMain (
230
    HINSTANCE const instance,
231
    DWORD const     reason,
232
    LPVOID const    reserved
233
) {
234
    switch (reason) {
235
	    case DLL_PROCESS_ATTACH: {
236
          // Allow callbacks outside of the .text section
237
          * ((int * )0xD415B8) = 0x00000001;
238
          * ((int * )0xD415BC) = 0x7FFFFFFF;
32 tristanc 239
 
36 tristanc 240
          // Initialize the Detour library
241
          DetourRestoreAfterWith();
32 tristanc 242
 
36 tristanc 243
          RegisterClientCallbacks();
32 tristanc 244
 
36 tristanc 245
          ConsoleCommandInitialize();
246
          CGlueMgr::Initialize();
247
          CGGameUI::Initialize();
248
          // TODO:
249
          //ClientServices_Initialize();
250
          break;
251
        }
32 tristanc 252
		case DLL_THREAD_ATTACH:
253
		case DLL_THREAD_DETACH:
254
			break;
36 tristanc 255
		case DLL_PROCESS_DETACH: {
256
            UnregisterClientCallbacks();
257
            // TODO
258
            //ClientServices_Destroy();
259
            WowGM::CGlueMgr::Shutdown();
32 tristanc 260
			CGGameUI::Shutdown();
36 tristanc 261
            break;
262
        }
263
    }
32 tristanc 264
 
36 tristanc 265
    return TRUE;
3 tristanc 266
}
36 tristanc 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
//===================================