Rev 31 | 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 bool s_initialized = false;
static CVar *s_enableTaintEnforcement;
//===========================================================================
int CCommand_Script (char const* cmd, char const* arguments) {
FrameScript_Execute(arguments,arguments,NULL);
return 1;
}
/****************************************************************************
*
* CGGameUI class implementation
*
***/
//===========================================================================
bool CGGameUI::CanPerformAction (ACTIONTYPE action) {
if (s_enableTaintEnforcement) {
// Always enable any action if taint enforcement is disabled by the client
if (s_enableTaintEnforcement->m_intValue == 0)
return true;
}
return CanPerformActionPtr(action);
}
//===========================================================================
void CGGameUI::Initialize () {
if (!s_initialized) {
DETOUR_INIT;
DETOUR_ATTACH(InitializePtr,InitializeProc);
DETOUR_ATTACH(CanPerformActionPtr,CanPerformAction);
DETOUR_ATTACH(ShutdownPtr2,ShutdownProc);
DETOUR_COMMIT;
s_initialized = true;
}
}
//===========================================================================
void CGGameUI::InitializeProc () {
InitializePtr();
s_enableTaintEnforcement = CVar::Register("enableTaintEnforcement",
"Enables enforcement of taint in GM clients",
NULL,
"0",
NULL,
GAME,
false,
NULL,
false);
RegisterScriptFunctions();
RegisterConsoleCommands();
}
//===========================================================================
void CGGameUI::RegisterConsoleCommands () {
ConsoleCommandRegister("script",CCommand_Script,DEFAULT,NULL);
}
//===========================================================================
void CGGameUI::RegisterScriptFunctions () {
// Register scripts here
}
//===========================================================================
void CGGameUI::Shutdown () {
if (s_initialized) {
DETOUR_INIT;
DETOUR_DETACH(InitializePtr,Initialize);
DETOUR_DETACH(CanPerformActionPtr,CanPerformAction);
DETOUR_DETACH(ShutdownPtr2,Shutdown);
DETOUR_COMMIT;
s_initialized = false;
}
}
//===========================================================================
void CGGameUI::ShutdownProc () {
ShutdownPtr2();
UnregisterScriptFunctions();
UnregisterConsoleCommands();
}
//===========================================================================
void CGGameUI::UnregisterConsoleCommands () {
ConsoleCommandUnregister("script");
}
//===========================================================================
void CGGameUI::UnregisterScriptFunctions () {
// Unregister scripts here
}