Subversion Repositories WoWGM

Rev

Rev 32 | 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 "ClientGMCommands.h"
#include <WowSvcs/ClientServices.h>
#include <Glue/CGlueMgr.h>
#include <Ui/GameUI.h>
#include <FrameScript/FrameScript.h>
#include <Object/ObjectClient/Player_C.h>


/****************************************************************************
*
*   Client memory addresses
*
***/

#define  CLIENTREGISTERCONSOLECOMMANDS    0x00401B60
#define  COMMONMAINDESTROY                0x004066D0
#define  COMMONMAININITIALIZE             0x004047E0
#define  INSTALLGAMECONSOLECOMMANDSPTR    0x00407870
#define  UNINSTALLGAMECONSOLECOMMANDSPTR  0x00406EF0
#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;
void  (*InstallGameConsoleCommands)()     = *(void(*)())INSTALLGAMECONSOLECOMMANDSPTR;
int   (*Script_GetBuildInfo)(lua_State*)  = *(int(*)(lua_State *))SCRIPT_GETBUILDINFO;
void  (*UninstallGameConsoleCommands)()   = *(void(*)())UNINSTALLGAMECONSOLECOMMANDSPTR;
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();
}

//===========================================================================
void InstallGameConsoleCommandsProc () {
  InstallGameConsoleCommands();

  // Register our own commands
  ConsoleCommandRegister("godmode",CCommand_Godmode,GAME,NOHELP);
  ConsoleCommandRegister("beastmaster",CCommand_Beastmaster,GAME,NOHELP);

  DebugClientCommands::Install();
  GMClientCommands::Install();
}

//===========================================================================
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 UninstallGameConsoleCommandsProc () {
  UninstallGameConsoleCommands();

  // Unregister our own commands
  ConsoleCommandUnregister("godmode");
  ConsoleCommandUnregister("beastmaster");

  DebugClientCommands::Uninstall();
  GMClientCommands::Uninstall();
}

//===========================================================================
void WowClientDestroyProc () {
  ConsoleCommandUnregister("Bug");
  ConsoleCommandUnregister("Suggestion");
  WowClientDestroy();
}

//===========================================================================
void WowClientInitProc () {
        WowClientInit();
  WowGM::CGlueMgr::SetLoginPassword();
  ConsoleCommandExecute("run autoexec.wtf",FALSE);
}


//===========================================================================
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_ATTACH(InstallGameConsoleCommands, InstallGameConsoleCommandsProc);
  DETOUR_ATTACH(UninstallGameConsoleCommands, UninstallGameConsoleCommandsProc);
  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_DETACH(InstallGameConsoleCommands, InstallGameConsoleCommandsProc);
  DETOUR_DETACH(UninstallGameConsoleCommands, UninstallGameConsoleCommandsProc);
  DETOUR_COMMIT;
}


/****************************************************************************
*
*   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();
                        break;
                }
                case DLL_THREAD_ATTACH:
                case DLL_THREAD_DETACH:
                        break;
                case DLL_PROCESS_DETACH:
    {
      UnregisterClientCallbacks();
      //TODO:
      WowGM::CGlueMgr::Shutdown();
                        CGGameUI::Shutdown();
                        //ClientServices_Destroy();
                        break;
                }
        }

        return TRUE;
}