Rev 31 | Rev 34 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/****************************************************************************
*
* Client.cpp
*
* Program entry point (DllMain)
*
* Written by Tristan Cormier
* 11.20.24
*
***/
#include "pch.h"
#pragma hdrstop
#include "Client.h"
#include "ClientCommands.h"
#include "ClientDebugCommands.h"
#include <WowSvcs/ClientServices.h>
#include <Glue/CGlueMgr.h>
#include <Ui/GameUI.h>
#include <FrameScript/FrameScript.h>
#include <Object/ObjectClient/Player_C.h>
//===========================================================================
BOOL CCommand_Bug(char const* command, char const* args);
/****************************************************************************
*
* Client memory addresses
*
***/
#define CLIENTREGISTERCONSOLECOMMANDS 0x00401B60
#define COMMONMAINDESTROY 0x004066D0
#define COMMONMAININITIALIZE 0x004047E0
#define SCRIPT_GETBUILDINFO 0x004DBE60
#define WOWCLIENTDESTROY 0x00402910
#define WOWCLIENTINIT 0x00404130
/****************************************************************************
*
* Client function pointers
*
***/
void (*ClientRegisterConsoleCommands)() = *(void(*)())CLIENTREGISTERCONSOLECOMMANDS;
void (*CommonMainDestroy)() = *(void(*)())COMMONMAINDESTROY;
void (*CommonMainInitialize)() = *(void(*)())COMMONMAININITIALIZE;
int (*Script_GetBuildInfo)(lua_State*) = *(int(*)(lua_State *))SCRIPT_GETBUILDINFO;
void (*WowClientDestroy)() = *(void(*)())WOWCLIENTDESTROY;
void (*WowClientInit)() = *(void(*)())WOWCLIENTINIT;
/****************************************************************************
*
* Callbacks
*
***/
//===========================================================================
void ClientRegisterConsoleCommandsProc () {
ClientRegisterConsoleCommands();
g_password = CVar::Register("password",
"stored password for blizzcon, dev, qa, etc.",
NULL,
"",
NULL,
GAME,
false,
NULL,
false);
ConsoleCommandRegister("Bug", CCommand_Bug, DEBUG, NOHELP);
ConsoleCommandRegister("Suggestion", CCommand_Bug, DEBUG, NOHELP);
}
//===========================================================================
void CommonMainDestroyProc () {
CommonMainDestroy();
}
//===========================================================================
void CommonMainInitializeProc () {
ConsoleAccessSetEnabled(TRUE);
CommonMainInitialize();
}
//===========================================================================
static int Script_GetBuildInfoProc (lua_State* L) {
char* version = FrameScript_GetText("VERSION", -1, GENDER_NONE);
_lua_pushstring(L, version);
#ifdef _DEBUG
_lua_pushstring(L,"Debug");
#else
_lua_pushstring(L, "GM");
#endif // #ifdef _DEBUG
_lua_pushstring(L, "3.3.5");
_lua_pushstring(L, "12340");
_lua_pushstring(L, __DATE__);
return 5;
}
//===========================================================================
void WowClientDestroyProc () {
ConsoleCommandUnregister("Bug");
ConsoleCommandUnregister("Suggestion");
WowClientDestroy();
}
//===========================================================================
void WowClientInitProc () {
WowClientInit();
WowGM::CGlueMgr::SetLoginPassword();
ConsoleCommandExecute("run autoexec.wtf",FALSE);
}
/****************************************************************************
*
* Private
*
***/
//===========================================================================
void RegisterClientCallbacks () {
DETOUR_INIT;
DETOUR_ATTACH(CommonMainDestroy, CommonMainDestroyProc);
DETOUR_ATTACH(CommonMainInitialize, CommonMainInitializeProc);
DETOUR_ATTACH(ClientRegisterConsoleCommands, ClientRegisterConsoleCommandsProc);
DETOUR_ATTACH(Script_GetBuildInfo, Script_GetBuildInfoProc);
DETOUR_ATTACH(WowClientDestroy, WowClientDestroyProc);
DETOUR_ATTACH(WowClientInit, WowClientInitProc);
DETOUR_COMMIT;
}
//===========================================================================
void UnregisterClientCallbacks () {
DETOUR_INIT;
DETOUR_DETACH(CommonMainDestroy, CommonMainDestroyProc);
DETOUR_DETACH(CommonMainInitialize, CommonMainInitializeProc);
DETOUR_DETACH(ClientRegisterConsoleCommands, ClientRegisterConsoleCommandsProc);
DETOUR_DETACH(Script_GetBuildInfo, Script_GetBuildInfoProc);
DETOUR_DETACH(WowClientDestroy, WowClientDestroyProc);
DETOUR_DETACH(WowClientInit, WowClientInitProc);
DETOUR_COMMIT;
}
//===========================================================================
BOOL CCommand_Bug (char const* command, char const* args) {
//TODO:
//ASSERT(command);
unsigned int category;
if (!SStrCmpI(command, "bug"))
category = 0;
else if (!SStrCmpI(command, "suggestion"))
category = 1;
if (ClientServices_Report(category, args))
ConsolePrintf("%s submitted", command);
else
ConsolePrintf("%s submission failed", command);
return TRUE;
}
/****************************************************************************
*
* Program entry point (DllMain)
*
***/
//===========================================================================
extern "C" BOOL WINAPI DllMain (HINSTANCE const instance,
DWORD const reason,
LPVOID const reserved) {
switch (reason) {
case DLL_PROCESS_ATTACH:
{
// Allow callbacks outside of the .text section
*((int*)0x00D415B8) = 0x00000001;
*((int*)0x00D415BC) = 0x7FFFFFFF;
// Initialize the Detour library
DetourRestoreAfterWith();
RegisterClientCallbacks();
ConsoleCommandInitialize();
CGlueMgr::Initialize();
CGGameUI::Initialize();
//TODO:
//ClientServices_Initialize();
WowGM::InstallGameConsoleCommands();
break;
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
{
UnregisterClientCallbacks();
//TODO:
WowGM::CGlueMgr::Shutdown();
CGGameUI::Shutdown();
//ClientServices_Destroy();
WowGM::UninstallGameConsoleCommands();
break;
}
}
return TRUE;
}