Subversion Repositories WoWGM

Rev

Rev 3 | Rev 32 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "pch.h"
#pragma hdrstop

#include "GameUI.h"
#include <Console/ConsoleClient.h>
#include <FrameScript/FrameScript.h>

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

#define  CGGAMEUI__INITIALIZE                                   0x0052A980;
#define  CGGAMEUI__CANPERFORMACTION             0x005191C0;
#define  CGGAMEUI__SHUTDOWN                                             0x00528F00;


/****************************************************************************
*
*   Client function pointers
*
***/

void (*InitializePtr)() = *(void(*)())CGGAMEUI__INITIALIZE;

bool (*CanPerformActionPtr)(ACTIONTYPE) = *(bool(*)(ACTIONTYPE))CGGAMEUI__CANPERFORMACTION;

void (*ShutdownPtr2)() = *(void(*)())CGGAMEUI__SHUTDOWN;


/****************************************************************************
*
*   Private
*
***/

static CVar *s_enableTaintEnforcement;

//===========================================================================
void Initialize () {
        InitializePtr();

        s_enableTaintEnforcement = CVar::Register("enableTaintEnforcement",
                                                                                                                                                                                "Enables enforcement of taint in GM clients",
                                                                                                                                                                                NULL,
                                                                                                                                                                                "0",
                                                                                                                                                                                NULL,
                                                                                                                                                                                GAME,
                                                                                                                                                                                false,
                                                                                                                                                                                NULL,
                                                                                                                                                                                false);

        CGGameUI::RegisterScriptFunctions();
        CGGameUI::RegisterConsoleCommands();
}

//===========================================================================
void Shutdown () {
        ShutdownPtr2();

        CGGameUI::UnregisterScriptFunctions();
        CGGameUI::UnregisterConsoleCommands();
}


//===========================================================================
int CCommand_Script (const char* cmd, const char* arguments) {
        FrameScript_Execute(arguments,arguments,NULL);
        return 0; //TODO:
}


/****************************************************************************
*
*   External
*
***/

//===========================================================================
void WowGM::CGGameUI::Initialize () {
        DETOUR_INIT;

        DETOUR_ATTACH(::InitializePtr,::Initialize);
        DETOUR_ATTACH(::CanPerformActionPtr,::CGGameUI::CanPerformAction);
        DETOUR_ATTACH(::ShutdownPtr2,::Shutdown);

        DETOUR_COMMIT;
}

//===========================================================================
void WowGM::CGGameUI::Shutdown () {
        DETOUR_INIT;

        DETOUR_DETACH(::InitializePtr,::Initialize);
        DETOUR_DETACH(::CanPerformActionPtr,::CGGameUI::CanPerformAction);
        DETOUR_DETACH(::ShutdownPtr2,::Shutdown);
        
        DETOUR_COMMIT;
}


/****************************************************************************
*
*   CGGameUI class implementation
*
***/

//===========================================================================
bool CGGameUI::CanPerformAction (ACTIONTYPE action) {
        if (s_enableTaintEnforcement) {
                // Always enable any action
                // if this option is enabled by the client
                if (s_enableTaintEnforcement->m_intValue == 0)
                        return true;
        }
        
        return CanPerformActionPtr(action);
}

//===========================================================================
void CGGameUI::RegisterConsoleCommands () {
        ConsoleCommandRegister("script",CCommand_Script,DEFAULT,NULL);
}

//===========================================================================
void CGGameUI::UnregisterConsoleCommands () {
        ConsoleCommandUnregister("script");
}

//===========================================================================
void CGGameUI::RegisterScriptFunctions () {
        // Register scripts here
}

//===========================================================================
void CGGameUI::UnregisterScriptFunctions () {
        // Unregister scripts here
}