ported SM's core to Orange Box

build is broken now in purpose

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401547
This commit is contained in:
Borja Ferrer 2007-10-14 00:04:21 +00:00
parent 36f6a760b5
commit b7d9d487cc
35 changed files with 2240 additions and 164 deletions

View File

@ -36,13 +36,17 @@
#include <IPlayerHelpers.h>
/* :HACKHACK: We can't SH_DECL here because ConCmdManager.cpp does */
#if defined ORANGEBOX_BUILD
extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate1<const CCommand &, void>);
extern int __SourceHook_FHAddConCommandDispatch(void *, ISourceHook::AddHookMode, bool, class fastdelegate::FastDelegate1<const CCommand &, void>);
#else
extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
#if SH_IMPL_VERSION >= 4
extern int __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
#else
extern bool __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
#endif
#endif //SH_IMPL_VERSION >= 4
#endif //ORANGEBOX_BUILD
ChatTriggers g_ChatTriggers;
@ -140,8 +144,14 @@ void ChatTriggers::OnSourceModShutdown()
}
}
#if defined ORANGEBOX_BUILD
void ChatTriggers::OnSayCommand_Pre(const CCommand &command)
{
#else
void ChatTriggers::OnSayCommand_Pre()
{
CCommand command;
#endif
int client = g_ConCmds.GetCommandClient();
m_bIsChatTrigger = false;
@ -151,7 +161,7 @@ void ChatTriggers::OnSayCommand_Pre()
RETURN_META(MRES_IGNORED);
}
const char *args = engine->Cmd_Args();
const char *args = command.ArgS();
if (!args)
{
@ -211,7 +221,11 @@ void ChatTriggers::OnSayCommand_Pre()
RETURN_META(MRES_IGNORED);
}
#if defined ORANGEBOX_BUILD
void ChatTriggers::OnSayCommand_Post(const CCommand &command)
#else
void ChatTriggers::OnSayCommand_Post()
#endif
{
m_bIsChatTrigger = false;
if (m_bWillProcessInPost)

View File

@ -50,8 +50,13 @@ public: //SMGlobalClass
char *error,
size_t maxlength);
private: //ConCommand
#if defined ORANGEBOX_BUILD
void OnSayCommand_Pre(const CCommand &command);
void OnSayCommand_Post(const CCommand &command);
#else
void OnSayCommand_Pre();
void OnSayCommand_Post();
#endif
public:
unsigned int GetReplyTo();
unsigned int SetReplyTo(unsigned int reply);

View File

@ -40,7 +40,12 @@
ConCmdManager g_ConCmds;
SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
#if defined ORANGEBOX_BUILD
SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
#else
SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
#endif
SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, false, int);
struct PlCmdInfo
@ -144,10 +149,15 @@ void ConCmdManager::OnPluginDestroyed(IPlugin *plugin)
delete pList;
}
}
#if defined ORANGEBOX_BUILD
void CommandCallback(const CCommand &command)
{
#else
void CommandCallback()
{
g_ConCmds.InternalDispatch();
CCommand command;
#endif
g_ConCmds.InternalDispatch(command);
}
void ConCmdManager::SetCommandClient(int client)
@ -201,7 +211,7 @@ ResultType ConCmdManager::DispatchClientCommand(int client, const char *cmd, int
return type;
}
void ConCmdManager::InternalDispatch()
void ConCmdManager::InternalDispatch(const CCommand &command)
{
int client = m_CmdClient;
@ -221,7 +231,7 @@ void ConCmdManager::InternalDispatch()
* Whether or not it goes through the callback is determined by FCVAR_GAMEDLL
*/
char cmd[300];
strncopy(cmd, engine->Cmd_Argv(0), sizeof(cmd));
strncopy(cmd, command.Arg(0), sizeof(cmd));
ConCmdInfo *pInfo;
if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
@ -230,7 +240,7 @@ void ConCmdManager::InternalDispatch()
}
cell_t result = Pl_Continue;
int args = engine->Cmd_Argc() - 1;
int args = command.ArgC() - 1;
List<CmdHook *>::iterator iter;
CmdHook *pHook;
@ -725,7 +735,7 @@ void ConCmdManager::RemoveConCmd(ConCmdInfo *info)
if (info->sourceMod)
{
/* Unlink from SourceMM */
g_SMAPI->UnregisterConCmdBase(g_PLAPI, info->pCmd);
g_SMAPI->UnregisterConCommandBase(g_PLAPI, info->pCmd);
/* Delete the command's memory */
char *new_help = const_cast<char *>(info->pCmd->GetHelpText());
char *new_name = const_cast<char *>(info->pCmd->GetName());
@ -822,11 +832,11 @@ ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *descri
return pInfo;
}
void ConCmdManager::OnRootConsoleCommand(const char *command, unsigned int argcount)
void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
{
if (argcount >= 3)
if (command.ArgC() >= 3)
{
const char *text = engine->Cmd_Argv(2);
const char *text = command.Arg(2);
int id = atoi(text);
CPlugin *pPlugin = g_PluginSys.GetPluginByOrder(id);
@ -919,9 +929,15 @@ void _YamState(int state)
g_yam_state = state;
}
#if defined ORANGEBOX_BUILD
void _IntExt_CallYams(const CCommand &cmd)
{
#else
void _IntExt_CallYams()
{
const char *arg = engine->Cmd_Argv(1);
CCommand cmd;
#endif
const char *arg = cmd.Arg(1);
/* should be impossible */
if (!arg || arg[0] == '\0')

View File

@ -96,7 +96,11 @@ class ConCmdManager :
public IRootConsoleCommand,
public IPluginsListener
{
#if defined ORANGEBOX_BUILD
friend void CommandCallback(const CCommand &command);
#else
friend void CommandCallback();
#endif
public:
ConCmdManager();
~ConCmdManager();
@ -106,7 +110,7 @@ public: //SMGlobalClass
public: //IPluginsListener
void OnPluginDestroyed(IPlugin *plugin);
public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *command, unsigned int argcount);
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
public:
bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
@ -122,7 +126,7 @@ public:
bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags);
bool CheckCommandAccess(int client, const char *cmd, FlagBits flags);
private:
void InternalDispatch();
void InternalDispatch(const CCommand &command);
ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
void SetCommandClient(int client);

View File

@ -234,16 +234,17 @@ void ConVarManager::OnHandleDestroy(HandleType_t type, void *object)
delete [] pConVar->GetHelpText();
/* Then unlink it from SourceMM */
g_SMAPI->UnregisterConCmdBase(g_PLAPI, pConVar);
g_SMAPI->UnregisterConCommandBase(g_PLAPI, pConVar);
}
}
void ConVarManager::OnRootConsoleCommand(const char *command, unsigned int argcount)
void ConVarManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
{
int argcount = command.ArgC();
if (argcount >= 3)
{
/* Get plugin index that was passed */
int id = atoi(g_RootMenu.GetArgument(2));
int id = atoi(command.Arg(2));
/* Get plugin object */
CPlugin *plugin = g_PluginSys.GetPluginByOrder(id);
@ -525,10 +526,14 @@ void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar
}
}
#if defined ORANGEBOX_BUILD
void ConVarManager::OnConVarChanged(IConVar *pConVar, const char *oldValue, float flOldValue)
#else
void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue)
#endif
{
/* If the values are the same, exit early in order to not trigger callbacks */
if (strcmp(pConVar->GetString(), oldValue) == 0)
if (strcmp(reinterpret_cast<ConVar *>(pConVar)->GetString(), oldValue) == 0)
{
return;
}
@ -539,19 +544,23 @@ void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue)
/* Find the convar in the lookup trie */
sm_trie_retrieve(pCache, pConVar->GetName(), (void **)&pInfo);
FnChangeCallback origCallback = pInfo->origCallback;
FnChangeCallback_t origCallback = pInfo->origCallback;
IChangeableForward *pForward = pInfo->pChangeForward;
/* If there was a change callback installed previously, call it */
if (origCallback)
{
#if defined ORANGEBOX_BUILD
origCallback(pConVar, oldValue, flOldValue);
#else
origCallback(pConVar, oldValue);
#endif
}
/* Now call forwards in plugins that have hooked this */
pForward->PushCell(pInfo->handle);
pForward->PushString(oldValue);
pForward->PushString(pConVar->GetString());
pForward->PushString(reinterpret_cast<ConVar *>(pConVar)->GetString());
pForward->Execute(NULL);
}
@ -652,10 +661,16 @@ void _YamagramPrinterTwoPointOhOh(int yamagram)
s_YamagramState = yamagram;
}
#if defined ORANGEBOX_BUILD
void _IntExt_CallYamagrams(const CCommand &cmd)
{
#else
void _IntExt_CallYamagrams()
{
CCommand cmd;
#endif
bool correct = false;
const char *arg = engine->Cmd_Args();
const char *arg = cmd.ArgS();
if (!arg || arg[0] == '\0')
{
@ -737,10 +752,14 @@ void _IntExt_EnableYamagrams()
}
}
#if defined ORANGEBOX_BUILD
void _IntExt_OnHostnameChanged(IConVar *pConVar, const char *oldValue, float flOldValue)
#else
void _IntExt_OnHostnameChanged(ConVar *pConVar, char const *oldValue)
#endif
{
if (strcmp(oldValue, "Good morning, DS-san.") == 0
&& strcmp(pConVar->GetString(), "Good night, talking desk lamp.") == 0)
&& strcmp(reinterpret_cast<ConVar *>(pConVar)->GetString(), "Good night, talking desk lamp.") == 0)
{
_IntExt_EnableYamagrams();
}

View File

@ -51,7 +51,7 @@ struct ConVarInfo
Handle_t handle; /**< Handle to convar */
bool sourceMod; /**< Determines whether or not convar was created by a SourceMod plugin */
IChangeableForward *pChangeForward; /**< Forward associated with convar */
FnChangeCallback origCallback; /**< The original callback function */
FnChangeCallback_t origCallback; /**< The original callback function */
#if PLAPI_VERSION < 12
const char *name; /**< Name of convar */
#endif
@ -85,7 +85,7 @@ public: // IHandleTypeDispatch
public: // IPluginsListener
void OnPluginUnloaded(IPlugin *plugin);
public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *command, unsigned int argcount);
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
public:
/**
* Get the 'ConVar' handle type ID.
@ -150,7 +150,11 @@ private:
/**
* Static callback that Valve's ConVar object executes when the convar's value changes.
*/
#if defined ORANGEBOX_BUILD
static void OnConVarChanged(IConVar *pConVar, const char *oldValue, float flOldValue);
#else
static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
#endif
/**
* Callback for when StartQueryCvarValue() has finished.

View File

@ -71,12 +71,13 @@ void CoreConfig::OnSourceModLevelChange(const char *mapName)
g_bConfigsExecd = false;
}
void CoreConfig::OnRootConsoleCommand(const char *command, unsigned int argcount)
void CoreConfig::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
{
int argcount = command.ArgC();
if (argcount >= 4)
{
const char *option = engine->Cmd_Argv(2);
const char *value = engine->Cmd_Argv(3);
const char *option = command.Arg(2);
const char *value = command.Arg(3);
char error[255];

View File

@ -50,7 +50,7 @@ public: // SMGlobalClass
public: // ITextListener_SMC
SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
public: // IRootConsoleCommand
void OnRootConsoleCommand(const char *command, unsigned int argcount);
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
public:
/**
* Initializes CoreConfig by reading from core.cfg file

View File

@ -386,9 +386,9 @@ SMCParseResult CGameConfig::ReadSMC_LeavingSection()
void *addrInBase = NULL;
if (strcmp(s_TempSig.library, "server") == 0)
{
addrInBase = (void *)g_SMAPI->serverFactory(false);
addrInBase = (void *)g_SMAPI->GetServerFactory(false);
} else if (strcmp(s_TempSig.library, "engine") == 0) {
addrInBase = (void *)g_SMAPI->engineFactory(false);
addrInBase = (void *)g_SMAPI->GetEngineFactory(false);
}
void *final_addr = NULL;
if (addrInBase == NULL)

View File

@ -96,16 +96,16 @@ bool CRadioStyle::IsSupported()
return (g_ShowMenuId != -1);
}
bool CRadioStyle::OnClientCommand(int client, const char *cmd)
bool CRadioStyle::OnClientCommand(int client, const char *cmdname, const CCommand &cmd)
{
if (strcmp(cmd, "menuselect") == 0)
if (strcmp(cmdname, "menuselect") == 0)
{
if (!m_players[client].bInMenu)
{
return false;
}
int arg = atoi(engine->Cmd_Argv(1));
int arg = atoi(cmd.Arg(1));
ClientPressedKey(client, arg);
return true;
}

View File

@ -40,6 +40,7 @@
#include <IUserMessages.h>
#include "sm_fastlink.h"
#include <sh_stack.h>
#include <compat_wrappers.h>
using namespace SourceMod;
@ -70,7 +71,7 @@ public: //IUserMessageListener
void OnUserMessageSent(int msg_id);
public:
bool IsSupported();
bool OnClientCommand(int client, const char *cmd);
bool OnClientCommand(int client, const char *cmdname, const CCommand &cmd);
public:
CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL);
void FreeRadioDisplay(CRadioDisplay *display);

View File

@ -53,11 +53,11 @@ CBaseMenuPlayer *ValveMenuStyle::GetMenuPlayer(int client)
return &m_players[client];
}
bool ValveMenuStyle::OnClientCommand(int client, const char *cmd)
bool ValveMenuStyle::OnClientCommand(int client, const char *cmdname, const CCommand &cmd)
{
if (strcmp(cmd, "sm_vmenuselect") == 0)
if (strcmp(cmdname, "sm_vmenuselect") == 0)
{
int key_press = atoi(engine->Cmd_Argv(1));
int key_press = atoi(cmd.Arg(1));
g_ValveMenuStyle.ClientPressedKey(client, key_press);
return true;
}

View File

@ -38,6 +38,7 @@
#include "sourcemm_api.h"
#include "KeyValues.h"
#include "sm_fastlink.h"
#include <compat_wrappers.h>
using namespace SourceMod;
@ -59,7 +60,7 @@ class ValveMenuStyle :
{
public:
ValveMenuStyle();
bool OnClientCommand(int client, const char *cmd);
bool OnClientCommand(int client, const char *cmdname, const CCommand &cmd);
public: //BaseMenuStyle
CBaseMenuPlayer *GetMenuPlayer(int client);
void SendDisplay(int client, IMenuPanel *display);

View File

@ -37,7 +37,11 @@
float g_next_vote = 0.0f;
#if defined ORANGEBOX_BUILD
void OnVoteDelayChange(IConVar *cvar, const char *value, float flOldValue);
#else
void OnVoteDelayChange(ConVar *cvar, const char *value);
#endif
ConVar sm_vote_delay("sm_vote_delay",
"30",
0,
@ -48,7 +52,11 @@ ConVar sm_vote_delay("sm_vote_delay",
0.0,
OnVoteDelayChange);
#if defined ORANGEBOX_BUILD
void OnVoteDelayChange(IConVar *cvar, const char *value, float flOldValue)
#else
void OnVoteDelayChange(ConVar *cvar, const char *value)
#endif
{
/* See if the new vote delay isn't something we need to account for */
if (sm_vote_delay.GetFloat() < 1.0f)

View File

@ -54,7 +54,11 @@ const unsigned int *g_NumPlayersToAuth = NULL;
SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char *, const char *, char *, int);
SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, const char *);
SH_DECL_HOOK1_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, edict_t *);
#if defined ORANGEBOX_BUILD
SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
#else
SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
#endif
SH_DECL_HOOK1_void(IServerGameClients, ClientSettingsChanged, SH_NOATTRIB, 0, edict_t *);
SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
@ -565,8 +569,14 @@ void PlayerManager::OnClientDisconnect_Post(edict_t *pEntity)
}
}
#if defined ORANGEBOX_BUILD
void PlayerManager::OnClientCommand(edict_t *pEntity, const CCommand &args)
{
#else
void PlayerManager::OnClientCommand(edict_t *pEntity)
{
CCommand args;
#endif
int client = engine->IndexOfEdict(pEntity);
cell_t res = Pl_Continue;
@ -580,15 +590,15 @@ void PlayerManager::OnClientCommand(edict_t *pEntity)
* We cache this because the engine is not re-entrant.
*/
char cmd[300];
int args = engine->Cmd_Argc() - 1;
strncopy(cmd, engine->Cmd_Argv(0), sizeof(cmd));
int argcount = args.ArgC() - 1;
strncopy(cmd, args.Arg(0), sizeof(cmd));
bool result = g_ValveMenuStyle.OnClientCommand(client, cmd);
bool result = g_ValveMenuStyle.OnClientCommand(client, cmd, args);
if (result)
{
res = Pl_Handled;
} else {
result = g_RadioMenuStyle.OnClientCommand(client, cmd);
result = g_RadioMenuStyle.OnClientCommand(client, cmd, args);
if (result)
{
res = Pl_Handled;
@ -597,7 +607,7 @@ void PlayerManager::OnClientCommand(edict_t *pEntity)
cell_t res2 = Pl_Continue;
m_clcommand->PushCell(client);
m_clcommand->PushCell(args);
m_clcommand->PushCell(argcount);
m_clcommand->Execute(&res2, NULL);
if (res2 > res)
@ -610,7 +620,7 @@ void PlayerManager::OnClientCommand(edict_t *pEntity)
RETURN_META(MRES_SUPERCEDE);
}
res = g_ConCmds.DispatchClientCommand(client, cmd, args, (ResultType)res);
res = g_ConCmds.DispatchClientCommand(client, cmd, argcount, (ResultType)res);
if (res >= Pl_Handled)
{

View File

@ -122,7 +122,11 @@ public:
void OnClientPutInServer(edict_t *pEntity, char const *playername);
void OnClientDisconnect(edict_t *pEntity);
void OnClientDisconnect_Post(edict_t *pEntity);
#if defined ORANGEBOX_BUILD
void OnClientCommand(edict_t *pEntity, const CCommand &args);
#else
void OnClientCommand(edict_t *pEntity);
#endif
void OnClientSettingsChanged(edict_t *pEntity);
//void OnClientSettingsChanged_Pre(edict_t *pEntity);
public: //IPlayerManager

View File

@ -35,7 +35,15 @@
#include "sourcemm_api.h"
#include "frame_hooks.h"
SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallback, SH_NOATTRIB, false, ConVar *, const char *);
#if !defined ORANGEBOX_BUILD
#define CallGlobalChangeCallbacks CallGlobalChangeCallback
#endif
#if defined ORANGEBOX_BUILD
SH_DECL_HOOK3_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *, float);
#else
SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *);
#endif
TimerSystem g_Timers;
float g_fUniversalTime = 0.0f;
@ -107,7 +115,11 @@ public:
mp_timelimit->SetValue(mp_timelimit->GetInt() + extra_time);
}
#if defined ORANGEBOX_BUILD
void GlobalChangeCallback(ConVar *pVar, const char *old_value, float flOldValue)
#else
void GlobalChangeCallback(ConVar *pVar, const char *old_value)
#endif
{
if (pVar != mp_timelimit)
{
@ -125,12 +137,12 @@ public:
private:
void Enable()
{
SH_ADD_HOOK_MEMFUNC(ICvar, CallGlobalChangeCallback, icvar, this, &DefaultMapTimer::GlobalChangeCallback, false);
SH_ADD_HOOK_MEMFUNC(ICvar, CallGlobalChangeCallbacks, icvar, this, &DefaultMapTimer::GlobalChangeCallback, false);
}
void Disable()
{
SH_REMOVE_HOOK_MEMFUNC(ICvar, CallGlobalChangeCallback, icvar, this, &DefaultMapTimer::GlobalChangeCallback, false);
SH_REMOVE_HOOK_MEMFUNC(ICvar, CallGlobalChangeCallbacks, icvar, this, &DefaultMapTimer::GlobalChangeCallback, false);
}
private:

961
core/bitbuf.cpp Normal file
View File

@ -0,0 +1,961 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "bitbuf.h"
#include "coordsize.h"
#include "vector.h"
#include "mathlib/math_base.h"
#include "vstdlib/strtools.h"
// FIXME: Can't use this until we get multithreaded allocations in tier0 working for tools
// This is used by VVIS and fails to link
// NOTE: This must be the last file included!!!
//#include "tier0/memdbgon.h"
#ifdef _XBOX
// mandatory ... wary of above comment and isolating, tier0 is built as MT though
#include "tier0/memdbgon.h"
#endif
static BitBufErrorHandler g_BitBufErrorHandler = 0;
void InternalBitBufErrorHandler( BitBufErrorType errorType, const char *pDebugName )
{
if ( g_BitBufErrorHandler )
g_BitBufErrorHandler( errorType, pDebugName );
}
void SetBitBufErrorHandler( BitBufErrorHandler fn )
{
g_BitBufErrorHandler = fn;
}
// #define BB_PROFILING
// Precalculated bit masks for WriteUBitLong. Using these tables instead of
// doing the calculations gives a 33% speedup in WriteUBitLong.
unsigned long g_BitWriteMasks[32][33];
// (1 << i) - 1
unsigned long g_ExtraMasks[32];
class CBitWriteMasksInit
{
public:
CBitWriteMasksInit()
{
for( unsigned int startbit=0; startbit < 32; startbit++ )
{
for( unsigned int nBitsLeft=0; nBitsLeft < 33; nBitsLeft++ )
{
unsigned int endbit = startbit + nBitsLeft;
g_BitWriteMasks[startbit][nBitsLeft] = (1 << startbit) - 1;
if(endbit < 32)
g_BitWriteMasks[startbit][nBitsLeft] |= ~((1 << endbit) - 1);
}
}
for ( unsigned int maskBit=0; maskBit < 32; maskBit++ )
g_ExtraMasks[maskBit] = (1 << maskBit) - 1;
}
};
CBitWriteMasksInit g_BitWriteMasksInit;
// ---------------------------------------------------------------------------------------- //
// bf_write
// ---------------------------------------------------------------------------------------- //
bf_write::bf_write()
{
m_pData = NULL;
m_nDataBytes = 0;
m_nDataBits = -1; // set to -1 so we generate overflow on any operation
m_iCurBit = 0;
m_bOverflow = false;
m_bAssertOnOverflow = true;
m_pDebugName = NULL;
}
bf_write::bf_write( const char *pDebugName, void *pData, int nBytes, int nBits )
{
m_bAssertOnOverflow = true;
m_pDebugName = pDebugName;
StartWriting( pData, nBytes, 0, nBits );
}
bf_write::bf_write( void *pData, int nBytes, int nBits )
{
m_bAssertOnOverflow = true;
StartWriting( pData, nBytes, 0, nBits );
}
void bf_write::StartWriting( void *pData, int nBytes, int iStartBit, int nBits )
{
// Make sure it's dword aligned and padded.
Assert( (nBytes % 4) == 0 );
Assert(((unsigned long)pData & 3) == 0);
m_pData = (unsigned char*)pData;
m_nDataBytes = nBytes;
if ( nBits == -1 )
{
m_nDataBits = nBytes << 3;
}
else
{
Assert( nBits <= nBytes*8 );
m_nDataBits = nBits;
}
m_iCurBit = iStartBit;
m_bOverflow = false;
}
void bf_write::Reset()
{
m_iCurBit = 0;
m_bOverflow = false;
}
void bf_write::SetAssertOnOverflow( bool bAssert )
{
m_bAssertOnOverflow = bAssert;
}
const char* bf_write::GetDebugName()
{
return m_pDebugName;
}
void bf_write::SetDebugName( const char *pDebugName )
{
m_pDebugName = pDebugName;
}
void bf_write::SeekToBit( int bitPos )
{
m_iCurBit = bitPos;
}
// Sign bit comes first
void bf_write::WriteSBitLong( int data, int numbits )
{
// Do we have a valid # of bits to encode with?
Assert( numbits >= 1 );
// Note: it does this wierdness here so it's bit-compatible with regular integer data in the buffer.
// (Some old code writes direct integers right into the buffer).
if(data < 0)
{
#ifdef _DEBUG
if( numbits < 32 )
{
// Make sure it doesn't overflow.
if( data < 0 )
{
Assert( data >= -(1 << (numbits-1)) );
}
else
{
Assert( data < (1 << (numbits-1)) );
}
}
#endif
WriteUBitLong( (unsigned int)(0x80000000 + data), numbits - 1, false );
WriteOneBit( 1 );
}
else
{
WriteUBitLong((unsigned int)data, numbits - 1);
WriteOneBit( 0 );
}
}
// writes an unsigned integer with variable bit length
void bf_write::WriteUBitVar( unsigned int data )
{
unsigned int bits = 0;
unsigned int base = 0;
while (data > (base<<1))
{
bits++;
base = (1<<bits)-1;
}
// how many bits do we use
if ( bits > 0)
WriteUBitLong( 0, bits );
// end marker
WriteOneBit( 1 );
// write the value
if ( bits > 0)
WriteUBitLong( data - base , bits );
}
void bf_write::WriteBitLong(unsigned int data, int numbits, bool bSigned)
{
if(bSigned)
WriteSBitLong((int)data, numbits);
else
WriteUBitLong(data, numbits);
}
bool bf_write::WriteBits(const void *pInData, int nBits)
{
#if defined( BB_PROFILING )
VPROF( "bf_write::WriteBits" );
#endif
unsigned char *pOut = (unsigned char*)pInData;
int nBitsLeft = nBits;
if((m_iCurBit+nBits) > m_nDataBits)
{
SetOverflowFlag();
CallErrorHandler( BITBUFERROR_BUFFER_OVERRUN, GetDebugName() );
return false;
}
// Get output dword-aligned.
while(((unsigned long)pOut & 3) != 0 && nBitsLeft >= 8)
{
WriteUBitLong( *pOut, 8, false );
++pOut;
nBitsLeft -= 8;
}
// check if we can use fast memcpy if m_iCurBit is byte aligned
if ( (nBitsLeft >= 32) && (m_iCurBit & 7) == 0 )
{
int numbytes = (nBitsLeft >> 3);
int numbits = numbytes << 3;
// Bounds checking..
// TODO: May not need this check anymore
if((m_iCurBit+numbits) > m_nDataBits)
{
m_iCurBit = m_nDataBits;
SetOverflowFlag();
CallErrorHandler( BITBUFERROR_BUFFER_OVERRUN, GetDebugName() );
return false;
}
Q_memcpy( m_pData+(m_iCurBit>>3), pOut, numbytes );
pOut += numbytes;
nBitsLeft -= numbits;
m_iCurBit += numbits;
}
// Read dwords.
while(nBitsLeft >= 32)
{
WriteUBitLong( *((unsigned long*)pOut), 32, false );
pOut += sizeof(unsigned long);
nBitsLeft -= 32;
}
// Read the remaining bytes.
while(nBitsLeft >= 8)
{
WriteUBitLong( *pOut, 8, false );
++pOut;
nBitsLeft -= 8;
}
// Read the remaining bits.
if(nBitsLeft)
{
WriteUBitLong( *pOut, nBitsLeft, false );
}
return !IsOverflowed();
}
bool bf_write::WriteBitsFromBuffer( bf_read *pIn, int nBits )
{
// This could be optimized a little by
while ( nBits > 32 )
{
WriteUBitLong( pIn->ReadUBitLong( 32 ), 32 );
nBits -= 32;
}
WriteUBitLong( pIn->ReadUBitLong( nBits ), nBits );
return !IsOverflowed() && !pIn->IsOverflowed();
}
void bf_write::WriteBitAngle( float fAngle, int numbits )
{
int d;
unsigned int mask;
unsigned int shift;
shift = (1<<numbits);
mask = shift - 1;
d = (int)( (fAngle / 360.0) * shift );
d &= mask;
WriteUBitLong((unsigned int)d, numbits);
}
void bf_write::WriteBitCoord (const float f)
{
#if defined( BB_PROFILING )
VPROF( "bf_write::WriteBitCoord" );
#endif
int signbit = (f <= -COORD_RESOLUTION);
int intval = abs(static_cast<int>(f));
int fractval = abs((int)(f*COORD_DENOMINATOR)) & (COORD_DENOMINATOR-1);
// Send the bit flags that indicate whether we have an integer part and/or a fraction part.
WriteOneBit( intval );
WriteOneBit( fractval );
if ( intval || fractval )
{
// Send the sign bit
WriteOneBit( signbit );
// Send the integer if we have one.
if ( intval )
{
// Adjust the integers from [1..MAX_COORD_VALUE] to [0..MAX_COORD_VALUE-1]
intval--;
WriteUBitLong( (unsigned int)intval, COORD_INTEGER_BITS );
}
// Send the fraction if we have one
if ( fractval )
{
WriteUBitLong( (unsigned int)fractval, COORD_FRACTIONAL_BITS );
}
}
}
void bf_write::WriteBitFloat(float val)
{
long intVal;
Assert(sizeof(long) == sizeof(float));
Assert(sizeof(float) == 4);
void *v = &val;
intVal = *reinterpret_cast<long *>(v);
WriteUBitLong( intVal, 32 );
}
void bf_write::WriteBitVec3Coord( const Vector& fa )
{
int xflag, yflag, zflag;
xflag = (fa[0] >= COORD_RESOLUTION) || (fa[0] <= -COORD_RESOLUTION);
yflag = (fa[1] >= COORD_RESOLUTION) || (fa[1] <= -COORD_RESOLUTION);
zflag = (fa[2] >= COORD_RESOLUTION) || (fa[2] <= -COORD_RESOLUTION);
WriteOneBit( xflag );
WriteOneBit( yflag );
WriteOneBit( zflag );
if ( xflag )
WriteBitCoord( fa[0] );
if ( yflag )
WriteBitCoord( fa[1] );
if ( zflag )
WriteBitCoord( fa[2] );
}
void bf_write::WriteBitNormal( float f )
{
int signbit = (f <= -NORMAL_RESOLUTION);
// NOTE: Since +/-1 are valid values for a normal, I'm going to encode that as all ones
unsigned int fractval = abs( (int)(f*NORMAL_DENOMINATOR) );
// clamp..
if (fractval > NORMAL_DENOMINATOR)
fractval = NORMAL_DENOMINATOR;
// Send the sign bit
WriteOneBit( signbit );
// Send the fractional component
WriteUBitLong( fractval, NORMAL_FRACTIONAL_BITS );
}
void bf_write::WriteBitVec3Normal( const Vector& fa )
{
int xflag, yflag;
xflag = (fa[0] >= NORMAL_RESOLUTION) || (fa[0] <= -NORMAL_RESOLUTION);
yflag = (fa[1] >= NORMAL_RESOLUTION) || (fa[1] <= -NORMAL_RESOLUTION);
WriteOneBit( xflag );
WriteOneBit( yflag );
if ( xflag )
WriteBitNormal( fa[0] );
if ( yflag )
WriteBitNormal( fa[1] );
// Write z sign bit
int signbit = (fa[2] <= -NORMAL_RESOLUTION);
WriteOneBit( signbit );
}
void bf_write::WriteBitAngles( const QAngle& fa )
{
// FIXME:
Vector tmp( fa.x, fa.y, fa.z );
WriteBitVec3Coord( tmp );
}
void bf_write::WriteChar(int val)
{
WriteSBitLong(val, sizeof(char) << 3);
}
void bf_write::WriteByte(int val)
{
WriteUBitLong(val, sizeof(unsigned char) << 3);
}
void bf_write::WriteShort(int val)
{
WriteSBitLong(val, sizeof(short) << 3);
}
void bf_write::WriteWord(int val)
{
WriteUBitLong(val, sizeof(unsigned short) << 3);
}
void bf_write::WriteLong(long val)
{
WriteSBitLong(val, sizeof(long) << 3);
}
void bf_write::WriteFloat(float val)
{
WriteBits(&val, sizeof(val) << 3);
}
bool bf_write::WriteBytes( const void *pBuf, int nBytes )
{
return WriteBits(pBuf, nBytes << 3);
}
bool bf_write::WriteString(const char *pStr)
{
if(pStr)
{
do
{
WriteChar( *pStr );
++pStr;
} while( *(pStr-1) != 0 );
}
else
{
WriteChar( 0 );
}
return !IsOverflowed();
}
// ---------------------------------------------------------------------------------------- //
// bf_read
// ---------------------------------------------------------------------------------------- //
bf_read::bf_read()
{
m_pData = NULL;
m_nDataBytes = 0;
m_nDataBits = -1; // set to -1 so we overflow on any operation
m_iCurBit = 0;
m_bOverflow = false;
m_bAssertOnOverflow = true;
m_pDebugName = NULL;
}
bf_read::bf_read( const void *pData, int nBytes, int nBits )
{
m_bAssertOnOverflow = true;
StartReading( pData, nBytes, 0, nBits );
}
bf_read::bf_read( const char *pDebugName, const void *pData, int nBytes, int nBits )
{
m_bAssertOnOverflow = true;
m_pDebugName = pDebugName;
StartReading( pData, nBytes, 0, nBits );
}
void bf_read::StartReading( const void *pData, int nBytes, int iStartBit, int nBits )
{
// Make sure we're dword aligned.
Assert(((unsigned long)pData & 3) == 0);
m_pData = (unsigned char*)pData;
m_nDataBytes = nBytes;
if ( nBits == -1 )
{
m_nDataBits = m_nDataBytes << 3;
}
else
{
Assert( nBits <= nBytes*8 );
m_nDataBits = nBits;
}
m_iCurBit = iStartBit;
m_bOverflow = false;
}
void bf_read::Reset()
{
m_iCurBit = 0;
m_bOverflow = false;
}
void bf_read::SetAssertOnOverflow( bool bAssert )
{
m_bAssertOnOverflow = bAssert;
}
const char* bf_read::GetDebugName()
{
return m_pDebugName;
}
void bf_read::SetDebugName( const char *pName )
{
m_pDebugName = pName;
}
unsigned int bf_read::CheckReadUBitLong(int numbits)
{
// Ok, just read bits out.
int i, nBitValue;
unsigned int r = 0;
for(i=0; i < numbits; i++)
{
nBitValue = ReadOneBitNoCheck();
r |= nBitValue << i;
}
m_iCurBit -= numbits;
return r;
}
bool bf_read::ReadBits(void *pOutData, int nBits)
{
#if defined( BB_PROFILING )
VPROF( "bf_write::ReadBits" );
#endif
unsigned char *pOut = (unsigned char*)pOutData;
int nBitsLeft = nBits;
// Get output dword-aligned.
while(((unsigned long)pOut & 3) != 0 && nBitsLeft >= 8)
{
*pOut = (unsigned char)ReadUBitLong(8);
++pOut;
nBitsLeft -= 8;
}
// Read dwords.
while(nBitsLeft >= 32)
{
*((unsigned long*)pOut) = ReadUBitLong(32);
pOut += sizeof(unsigned long);
nBitsLeft -= 32;
}
// Read the remaining bytes.
while(nBitsLeft >= 8)
{
*pOut = ReadUBitLong(8);
++pOut;
nBitsLeft -= 8;
}
// Read the remaining bits.
if(nBitsLeft)
{
*pOut = ReadUBitLong(nBitsLeft);
}
return !IsOverflowed();
}
float bf_read::ReadBitAngle( int numbits )
{
float fReturn;
int i;
float shift;
shift = (float)( 1 << numbits );
i = ReadUBitLong( numbits );
fReturn = (float)i * (360.0 / shift);
return fReturn;
}
unsigned int bf_read::PeekUBitLong( int numbits )
{
unsigned int r;
int i, nBitValue;
#ifdef BIT_VERBOSE
int nShifts = numbits;
#endif
bf_read savebf;
savebf = *this; // Save current state info
r = 0;
for(i=0; i < numbits; i++)
{
nBitValue = ReadOneBit();
// Append to current stream
if ( nBitValue )
{
r |= 1 << i;
}
}
*this = savebf;
#ifdef BIT_VERBOSE
Con_Printf( "PeekBitLong: %i %i\n", nShifts, (unsigned int)r );
#endif
return r;
}
// Append numbits least significant bits from data to the current bit stream
int bf_read::ReadSBitLong( int numbits )
{
int r, sign;
r = ReadUBitLong(numbits - 1);
// Note: it does this wierdness here so it's bit-compatible with regular integer data in the buffer.
// (Some old code writes direct integers right into the buffer).
sign = ReadOneBit();
if(sign)
r = -((1 << (numbits-1)) - r);
return r;
}
unsigned int bf_read::ReadUBitVar()
{
int bits = 0; // how many bits are used to encode delta offset
// how many bits do we use
while ( ReadOneBit() == 0 )
bits++;
unsigned int data = (1<<bits)-1;
// read the value
if ( bits > 0)
data += ReadUBitLong( bits );
return data;
}
unsigned int bf_read::ReadBitLong(int numbits, bool bSigned)
{
if(bSigned)
return (unsigned int)ReadSBitLong(numbits);
else
return ReadUBitLong(numbits);
}
// Basic Coordinate Routines (these contain bit-field size AND fixed point scaling constants)
float bf_read::ReadBitCoord (void)
{
#if defined( BB_PROFILING )
VPROF( "bf_write::ReadBitCoord" );
#endif
int intval=0,fractval=0,signbit=0;
float value = 0.0;
// Read the required integer and fraction flags
intval = ReadOneBit();
fractval = ReadOneBit();
// If we got either parse them, otherwise it's a zero.
if ( intval || fractval )
{
// Read the sign bit
signbit = ReadOneBit();
// If there's an integer, read it in
if ( intval )
{
// Adjust the integers from [0..MAX_COORD_VALUE-1] to [1..MAX_COORD_VALUE]
intval = ReadUBitLong( COORD_INTEGER_BITS ) + 1;
}
// If there's a fraction, read it in
if ( fractval )
{
fractval = ReadUBitLong( COORD_FRACTIONAL_BITS );
}
// Calculate the correct floating point value
value = intval + ((float)fractval * COORD_RESOLUTION);
// Fixup the sign if negative.
if ( signbit )
value = -value;
}
return value;
}
void bf_read::ReadBitVec3Coord( Vector& fa )
{
int xflag, yflag, zflag;
// This vector must be initialized! Otherwise, If any of the flags aren't set,
// the corresponding component will not be read and will be stack garbage.
fa.Init( 0, 0, 0 );
xflag = ReadOneBit();
yflag = ReadOneBit();
zflag = ReadOneBit();
if ( xflag )
fa[0] = ReadBitCoord();
if ( yflag )
fa[1] = ReadBitCoord();
if ( zflag )
fa[2] = ReadBitCoord();
}
float bf_read::ReadBitNormal (void)
{
// Read the sign bit
int signbit = ReadOneBit();
// Read the fractional part
unsigned int fractval = ReadUBitLong( NORMAL_FRACTIONAL_BITS );
// Calculate the correct floating point value
float value = (float)fractval * NORMAL_RESOLUTION;
// Fixup the sign if negative.
if ( signbit )
value = -value;
return value;
}
void bf_read::ReadBitVec3Normal( Vector& fa )
{
int xflag = ReadOneBit();
int yflag = ReadOneBit();
if (xflag)
fa[0] = ReadBitNormal();
else
fa[0] = 0.0f;
if (yflag)
fa[1] = ReadBitNormal();
else
fa[1] = 0.0f;
// The first two imply the third (but not its sign)
int znegative = ReadOneBit();
float fafafbfb = fa[0] * fa[0] + fa[1] * fa[1];
if (fafafbfb < 1.0f)
fa[2] = sqrt( 1.0f - fafafbfb );
else
fa[2] = 0.0f;
if (znegative)
fa[2] = -fa[2];
}
void bf_read::ReadBitAngles( QAngle& fa )
{
Vector tmp;
ReadBitVec3Coord( tmp );
fa.Init( tmp.x, tmp.y, tmp.z );
}
int bf_read::ReadChar()
{
return ReadSBitLong(sizeof(char) << 3);
}
int bf_read::ReadByte()
{
return ReadUBitLong(sizeof(unsigned char) << 3);
}
int bf_read::ReadShort()
{
return ReadSBitLong(sizeof(short) << 3);
}
int bf_read::ReadWord()
{
return ReadUBitLong(sizeof(unsigned short) << 3);
}
long bf_read::ReadLong()
{
return ReadSBitLong(sizeof(long) << 3);
}
float bf_read::ReadFloat()
{
float ret;
Assert( sizeof(ret) == 4 );
ReadBits(&ret, 32);
return ret;
}
bool bf_read::ReadBytes(void *pOut, int nBytes)
{
return ReadBits(pOut, nBytes << 3);
}
bool bf_read::ReadString( char *pStr, int maxLen, bool bLine, int *pOutNumChars )
{
Assert( maxLen != 0 );
bool bTooSmall = false;
int iChar = 0;
while(1)
{
char val = ReadChar();
if ( val == 0 )
break;
else if ( bLine && val == '\n' )
break;
if ( iChar < (maxLen-1) )
{
pStr[iChar] = val;
++iChar;
}
else
{
bTooSmall = true;
}
}
// Make sure it's null-terminated.
Assert( iChar < maxLen );
pStr[iChar] = 0;
if ( pOutNumChars )
*pOutNumChars = iChar;
return !IsOverflowed() && !bTooSmall;
}
char* bf_read::ReadAndAllocateString( bool *pOverflow )
{
char str[2048];
int nChars;
bool bOverflow = !ReadString( str, sizeof( str ), false, &nChars );
if ( pOverflow )
*pOverflow = bOverflow;
// Now copy into the output and return it;
char *pRet = new char[ nChars + 1 ];
for ( int i=0; i <= nChars; i++ )
pRet[i] = str[i];
return pRet;
}
bool bf_read::Seek(int iBit)
{
if(iBit < 0)
{
SetOverflowFlag();
m_iCurBit = m_nDataBits;
return false;
}
else if(iBit > m_nDataBits)
{
SetOverflowFlag();
m_iCurBit = m_nDataBits;
return false;
}
else
{
m_iCurBit = iBit;
return true;
}
}
void bf_read::ExciseBits( int startbit, int bitstoremove )
{
int endbit = startbit + bitstoremove;
int remaining_to_end = m_nDataBits - endbit;
bf_write temp;
temp.StartWriting( (void *)m_pData, m_nDataBits << 3, startbit );
Seek( endbit );
for ( int i = 0; i < remaining_to_end; i++ )
{
temp.WriteOneBit( ReadOneBit() );
}
Seek( startbit );
m_nDataBits -= bitstoremove;
m_nDataBytes = m_nDataBits >> 3;
}

709
core/convar_sm_ob.h Normal file
View File

@ -0,0 +1,709 @@
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $Workfile: $
// $Date: $
//
//-----------------------------------------------------------------------------
// $NoKeywords: $
//===========================================================================//
#ifndef CONVAR_H
#define CONVAR_H
#if _WIN32
#pragma once
#endif
#include "tier0/dbg.h"
#include "tier1/iconvar.h"
#include "tier1/utlvector.h"
#include "tier1/utlstring.h"
#include "icvar.h"
#ifdef _WIN32
#define FORCEINLINE_CVAR FORCEINLINE
#elif _LINUX
#define FORCEINLINE_CVAR inline
#else
#error "implement me"
#endif
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class ConVar;
class CCommand;
class ConCommand;
class ConCommandBase;
struct characterset_t;
//-----------------------------------------------------------------------------
// Any executable that wants to use ConVars need to implement one of
// these to hook up access to console variables.
//-----------------------------------------------------------------------------
class IConCommandBaseAccessor
{
public:
// Flags is a combination of FCVAR flags in cvar.h.
// hOut is filled in with a handle to the variable.
virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0;
};
//-----------------------------------------------------------------------------
// Helper method for console development
//-----------------------------------------------------------------------------
#if defined( _X360 ) && !defined( _RETAIL )
void ConVar_PublishToVXConsole();
#endif
//-----------------------------------------------------------------------------
// Called when a ConCommand needs to execute
//-----------------------------------------------------------------------------
typedef void ( *FnCommandCallbackV1_t )( void );
typedef void ( *FnCommandCallback_t )( const CCommand &command );
#define COMMAND_COMPLETION_MAXITEMS 64
#define COMMAND_COMPLETION_ITEM_LENGTH 64
//-----------------------------------------------------------------------------
// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
//-----------------------------------------------------------------------------
typedef int ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
//-----------------------------------------------------------------------------
// Interface version
//-----------------------------------------------------------------------------
class ICommandCallback
{
public:
virtual void CommandCallback( const CCommand &command ) = 0;
};
class ICommandCompletionCallback
{
public:
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0;
};
//-----------------------------------------------------------------------------
// Purpose: The base console invoked command/cvar interface
//-----------------------------------------------------------------------------
class ConCommandBase
{
friend class CCvar;
friend class ConVar;
friend class ConCommand;
friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor );
friend void ConVar_PublishToVXConsole();
// FIXME: Remove when ConVar changes are done
friend class CDefaultCvar;
public:
ConCommandBase( void );
ConCommandBase( const char *pName, const char *pHelpString = 0,
int flags = 0 );
virtual ~ConCommandBase( void );
virtual bool IsCommand( void ) const;
// Check flag
virtual bool IsFlagSet( int flag ) const;
// Set flag
virtual void AddFlags( int flags );
// Return name of cvar
virtual const char *GetName( void ) const;
// Return help text for cvar
virtual const char *GetHelpText( void ) const;
// Deal with next pointer
const ConCommandBase *GetNext( void ) const;
ConCommandBase *GetNext( void );
void SetNext(ConCommandBase *pBase)
{
m_pNext = pBase;
}
virtual bool IsRegistered( void ) const;
// Returns the DLL identifier
virtual CVarDLLIdentifier_t GetDLLIdentifier() const;
protected:
virtual void Create( const char *pName, const char *pHelpString = 0,
int flags = 0 );
// Used internally by OneTimeInit to initialize/shutdown
virtual void Init();
void Shutdown();
// Internal copy routine ( uses new operator from correct module )
char *CopyString( const char *from );
private:
// Next ConVar in chain
// Prior to register, it points to the next convar in the DLL.
// Once registered, though, m_pNext is reset to point to the next
// convar in the global list
ConCommandBase *m_pNext;
// Has the cvar been added to the global list?
bool m_bRegistered;
// Static data
const char *m_pszName;
const char *m_pszHelpString;
// ConVar flags
int m_nFlags;
protected:
// ConVars add themselves to this list for the executable.
// Then ConVar_Register runs through all the console variables
// and registers them into a global list stored in vstdlib.dll
static ConCommandBase *s_pConCommandBases;
// ConVars in this executable use this 'global' to access values.
static IConCommandBaseAccessor *s_pAccessor;
public: // Hackalicous
inline int GetFlags() const
{
return m_nFlags;
}
inline void SetFlags(int flags)
{
m_nFlags = flags;
}
};
//-----------------------------------------------------------------------------
// Command tokenizer
//-----------------------------------------------------------------------------
class CCommand
{
public:
CCommand();
CCommand( int nArgC, const char **ppArgV );
bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL );
void Reset();
int ArgC() const;
const char **ArgV() const;
const char *ArgS() const; // All args that occur after the 0th arg, in string form
const char *GetCommandString() const; // The entire command in string form, including the 0th arg
const char *operator[]( int nIndex ) const; // Gets at arguments
const char *Arg( int nIndex ) const; // Gets at arguments
// Helper functions to parse arguments to commands.
const char* FindArg( const char *pName ) const;
int FindArgInt( const char *pName, int nDefaultVal ) const;
static int MaxCommandLength();
static characterset_t* DefaultBreakSet();
private:
enum
{
COMMAND_MAX_ARGC = 64,
COMMAND_MAX_LENGTH = 512,
};
int m_nArgc;
int m_nArgv0Size;
char m_pArgSBuffer[ COMMAND_MAX_LENGTH ];
char m_pArgvBuffer[ COMMAND_MAX_LENGTH ];
const char* m_ppArgv[ COMMAND_MAX_ARGC ];
};
inline int CCommand::MaxCommandLength()
{
return COMMAND_MAX_LENGTH - 1;
}
inline int CCommand::ArgC() const
{
return m_nArgc;
}
inline const char **CCommand::ArgV() const
{
return m_nArgc ? (const char**)m_ppArgv : NULL;
}
inline const char *CCommand::ArgS() const
{
return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : "";
}
inline const char *CCommand::GetCommandString() const
{
return m_nArgc ? m_pArgSBuffer : "";
}
inline const char *CCommand::Arg( int nIndex ) const
{
// FIXME: Many command handlers appear to not be particularly careful
// about checking for valid argc range. For now, we're going to
// do the extra check and return an empty string if it's out of range
if ( nIndex < 0 || nIndex >= m_nArgc )
return "";
return m_ppArgv[nIndex];
}
inline const char *CCommand::operator[]( int nIndex ) const
{
return Arg( nIndex );
}
//-----------------------------------------------------------------------------
// Purpose: The console invoked command
//-----------------------------------------------------------------------------
class ConCommand : public ConCommandBase
{
friend class CCvar;
public:
typedef ConCommandBase BaseClass;
ConCommand( const char *pName, FnCommandCallbackV1_t callback,
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
ConCommand( const char *pName, FnCommandCallback_t callback,
const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
ConCommand( const char *pName, ICommandCallback *pCallback,
const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
virtual ~ConCommand( void );
virtual bool IsCommand( void ) const;
virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands );
virtual bool CanAutoComplete( void );
// Invoke the function
virtual void Dispatch( const CCommand &command );
private:
// NOTE: To maintain backward compat, we have to be very careful:
// All public virtual methods must appear in the same order always
// since engine code will be calling into this code, which *does not match*
// in the mod code; it's using slightly different, but compatible versions
// of this class. Also: Be very careful about adding new fields to this class.
// Those fields will not exist in the version of this class that is instanced
// in mod code.
// Call this function when executing the command
union
{
FnCommandCallbackV1_t m_fnCommandCallbackV1;
FnCommandCallback_t m_fnCommandCallback;
ICommandCallback *m_pCommandCallback;
};
union
{
FnCommandCompletionCallback m_fnCompletionCallback;
ICommandCompletionCallback *m_pCommandCompletionCallback;
};
bool m_bHasCompletionCallback : 1;
bool m_bUsingNewCommandCallback : 1;
bool m_bUsingCommandCallbackInterface : 1;
public: // Hackalicous
inline FnCommandCallback_t GetCallback() const
{
return m_fnCommandCallback;
}
};
//-----------------------------------------------------------------------------
// Purpose: A console variable
//-----------------------------------------------------------------------------
class ConVar : public ConCommandBase, public IConVar
{
friend class CCvar;
friend class ConVarRef;
public:
typedef ConCommandBase BaseClass;
ConVar( const char *pName, const char *pDefaultValue, int flags = 0);
ConVar( const char *pName, const char *pDefaultValue, int flags,
const char *pHelpString );
ConVar( const char *pName, const char *pDefaultValue, int flags,
const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax );
ConVar( const char *pName, const char *pDefaultValue, int flags,
const char *pHelpString, FnChangeCallback_t callback );
ConVar( const char *pName, const char *pDefaultValue, int flags,
const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax,
FnChangeCallback_t callback );
virtual ~ConVar( void );
virtual bool IsFlagSet( int flag ) const;
virtual const char* GetHelpText( void ) const;
virtual bool IsRegistered( void ) const;
virtual const char *GetName( void ) const;
virtual void AddFlags( int flags );
virtual bool IsCommand( void ) const;
// Install a change callback (there shouldn't already be one....)
void InstallChangeCallback( FnChangeCallback_t callback );
// Retrieve value
FORCEINLINE_CVAR float GetFloat( void ) const;
FORCEINLINE_CVAR int GetInt( void ) const;
FORCEINLINE_CVAR bool GetBool() const { return !!GetInt(); }
FORCEINLINE_CVAR char const *GetString( void ) const;
// Any function that allocates/frees memory needs to be virtual or else you'll have crashes
// from alloc/free across dll/exe boundaries.
// These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
virtual void SetValue( const char *value );
virtual void SetValue( float value );
virtual void SetValue( int value );
// Reset to default value
void Revert( void );
// True if it has a min/max setting
bool GetMin( float& minVal ) const;
bool GetMax( float& maxVal ) const;
const char *GetDefault( void ) const;
private:
// Called by CCvar when the value of a var is changing.
virtual void InternalSetValue(const char *value);
// For CVARs marked FCVAR_NEVER_AS_STRING
virtual void InternalSetFloatValue( float fNewValue );
virtual void InternalSetIntValue( int nValue );
virtual bool ClampValue( float& value );
virtual void ChangeStringValue( const char *tempVal, float flOldValue );
virtual void Create( const char *pName, const char *pDefaultValue, int flags = 0,
const char *pHelpString = 0, bool bMin = false, float fMin = 0.0,
bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 );
// Used internally by OneTimeInit to initialize.
virtual void Init();
private:
// This either points to "this" or it points to the original declaration of a ConVar.
// This allows ConVars to exist in separate modules, and they all use the first one to be declared.
// m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
ConVar *m_pParent;
// Static data
const char *m_pszDefaultValue;
// Value
// Dynamically allocated
char *m_pszString;
int m_StringLength;
// Values
float m_fValue;
int m_nValue;
// Min/Max values
bool m_bHasMin;
float m_fMinVal;
bool m_bHasMax;
float m_fMaxVal;
// Call this function when ConVar changes
FnChangeCallback_t m_fnChangeCallback;
public: // Hackalicous
inline FnChangeCallback_t GetCallback() const
{
return m_fnChangeCallback;
}
inline void SetMin(bool set, float min=0.0)
{
m_bHasMin = set;
m_fMinVal = min;
}
inline void SetMax(bool set, float max=0.0)
{
m_bHasMax = set;
m_fMaxVal = max;
}
};
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as a float
// Output : float
//-----------------------------------------------------------------------------
FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
{
return m_pParent->m_fValue;
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as an int
// Output : int
//-----------------------------------------------------------------------------
FORCEINLINE_CVAR int ConVar::GetInt( void ) const
{
return m_pParent->m_nValue;
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
// Output : const char *
//-----------------------------------------------------------------------------
FORCEINLINE_CVAR const char *ConVar::GetString( void ) const
{
if ( m_nFlags & FCVAR_NEVER_AS_STRING )
return "FCVAR_NEVER_AS_STRING";
return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : "";
}
//-----------------------------------------------------------------------------
// Used to read/write convars that already exist (replaces the FindVar method)
//-----------------------------------------------------------------------------
class ConVarRef
{
public:
ConVarRef( const char *pName );
ConVarRef( const char *pName, bool bIgnoreMissing );
ConVarRef( IConVar *pConVar );
void Init( const char *pName, bool bIgnoreMissing );
bool IsValid() const;
bool IsFlagSet( int nFlags ) const;
IConVar *GetLinkedConVar();
// Get/Set value
float GetFloat( void ) const;
int GetInt( void ) const;
bool GetBool() const { return !!GetInt(); }
const char *GetString( void ) const;
void SetValue( const char *pValue );
void SetValue( float flValue );
void SetValue( int nValue );
void SetValue( bool bValue );
const char *GetName() const;
const char *GetDefault() const;
private:
// High-speed method to read convar data
IConVar *m_pConVar;
ConVar *m_pConVarState;
};
//-----------------------------------------------------------------------------
// Did we find an existing convar of that name?
//-----------------------------------------------------------------------------
FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const
{
return ( m_pConVar->IsFlagSet( nFlags ) != 0 );
}
FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar()
{
return m_pConVar;
}
FORCEINLINE_CVAR const char *ConVarRef::GetName() const
{
return m_pConVar->GetName();
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as a float
//-----------------------------------------------------------------------------
FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const
{
return m_pConVarState->m_fValue;
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as an int
//-----------------------------------------------------------------------------
FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const
{
return m_pConVarState->m_nValue;
}
//-----------------------------------------------------------------------------
// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
//-----------------------------------------------------------------------------
FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const
{
Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
return m_pConVarState->m_pszString;
}
FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue )
{
m_pConVar->SetValue( pValue );
}
FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue )
{
m_pConVar->SetValue( flValue );
}
FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue )
{
m_pConVar->SetValue( nValue );
}
FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue )
{
m_pConVar->SetValue( bValue ? 1 : 0 );
}
FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const
{
return m_pConVarState->m_pszDefaultValue;
}
//-----------------------------------------------------------------------------
// Called by the framework to register ConCommands with the ICVar
//-----------------------------------------------------------------------------
void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL );
void ConVar_Unregister( );
//-----------------------------------------------------------------------------
// Utility methods
//-----------------------------------------------------------------------------
void ConVar_PrintFlags( const ConCommandBase *var );
void ConVar_PrintDescription( const ConCommandBase *pVar );
//-----------------------------------------------------------------------------
// Purpose: Utility class to quickly allow ConCommands to call member methods
//-----------------------------------------------------------------------------
#if defined _MSC_VER
#pragma warning (disable : 4355 )
#endif
template< class T >
class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
{
typedef ConCommand BaseClass;
typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command );
typedef int ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands );
public:
CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0,
int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) :
BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL )
{
m_pOwner = pOwner;
m_Func = callback;
m_CompletionFunc = completionFunc;
}
~CConCommandMemberAccessor()
{
Shutdown();
}
void SetOwner( T* pOwner )
{
m_pOwner = pOwner;
}
virtual void CommandCallback( const CCommand &command )
{
Assert( m_pOwner && m_Func );
(m_pOwner->*m_Func)( command );
}
virtual int CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands )
{
Assert( m_pOwner && m_CompletionFunc );
return (m_pOwner->*m_CompletionFunc)( pPartial, commands );
}
private:
T* m_pOwner;
FnMemberCommandCallback_t m_Func;
FnMemberCommandCompletionCallback_t m_CompletionFunc;
};
#if defined _MSC_VER
#pragma warning ( default : 4355 )
#endif
//-----------------------------------------------------------------------------
// Purpose: Utility macros to quicky generate a simple console command
//-----------------------------------------------------------------------------
#define CON_COMMAND( name, description ) \
static void name( const CCommand &args ); \
static ConCommand name##_command( #name, name, description ); \
static void name( const CCommand &args )
#define CON_COMMAND_F( name, description, flags ) \
static void name( const CCommand &args ); \
static ConCommand name##_command( #name, name, description, flags ); \
static void name( const CCommand &args )
#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \
static void name( const CCommand &args ); \
static ConCommand name##_command( #name, name, description, flags, completion ); \
static void name( const CCommand &args )
#define CON_COMMAND_EXTERN( name, _funcname, description ) \
void _funcname( const CCommand &args ); \
static ConCommand name##_command( #name, _funcname, description ); \
void _funcname( const CCommand &args )
#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \
void _funcname( const CCommand &args ); \
static ConCommand name##_command( #name, _funcname, description, flags ); \
void _funcname( const CCommand &args )
#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \
void _funcname( const CCommand &args ); \
friend class CCommandMemberInitializer_##_funcname; \
class CCommandMemberInitializer_##_funcname \
{ \
public: \
CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags ) \
{ \
m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) ); \
} \
private: \
CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor; \
}; \
\
CCommandMemberInitializer_##_funcname m_##_funcname##_register; \
#endif // CONVAR_H

View File

@ -6,14 +6,20 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CrazyDebug|Win32 = CrazyDebug|Win32
Debug - Orange Box|Win32 = Debug - Orange Box|Win32
Debug|Win32 = Debug|Win32
Release - Orange Box|Win32 = Release - Orange Box|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.CrazyDebug|Win32.ActiveCfg = CrazyDebug|Win32
{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.CrazyDebug|Win32.Build.0 = CrazyDebug|Win32
{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Debug - Orange Box|Win32.ActiveCfg = Debug - Orange Box|Win32
{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Debug - Orange Box|Win32.Build.0 = Debug - Orange Box|Win32
{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Debug|Win32.ActiveCfg = Debug|Win32
{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Debug|Win32.Build.0 = Debug|Win32
{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Release - Orange Box|Win32.ActiveCfg = Release - Orange Box|Win32
{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Release - Orange Box|Win32.Build.0 = Release - Orange Box|Win32
{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Release|Win32.ActiveCfg = Release|Win32
{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Version="8,00"
Name="sourcemod_mm"
ProjectGUID="{E39527CD-7CAB-4420-97CC-DA1B93B260BC}"
RootNamespace="sourcemod_mm"
@ -254,6 +254,166 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release - Orange Box|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="..\;..\systems;..\..\public;..\..\public\sourcepawn"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;SM_DEFAULT_THREADER;ORANGEBOX_BUILD"
RuntimeLibrary="0"
EnableEnhancedInstructionSet="1"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="tier0.lib tier1.lib vstdlib.lib mathlib.lib"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug - Orange Box|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\;..\systems;..\..\public;..\..\public\sourcepawn"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;SM_DEFAULT_THREADER;ORANGEBOX_BUILD"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
EnableEnhancedInstructionSet="1"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="tier0.lib tier1.lib vstdlib.lib mathlib.lib"
LinkIncremental="2"
IgnoreDefaultLibraryNames="LIBCMT"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
@ -271,6 +431,10 @@
RelativePath="..\ADTFactory.cpp"
>
</File>
<File
RelativePath="..\bitbuf.cpp"
>
</File>
<File
RelativePath="..\CDataPack.cpp"
>
@ -316,6 +480,15 @@
AssemblerOutput="0"
/>
</FileConfiguration>
<FileConfiguration
Name="Release - Orange Box|Win32"
>
<Tool
Name="VCCLCompilerTool"
ExpandAttributedSource="true"
AssemblerOutput="4"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\DebugReporter.cpp"

View File

@ -57,11 +57,18 @@ RootConsoleMenu::~RootConsoleMenu()
m_Menu.clear();
}
extern void _IntExt_OnHostnameChanged(ConVar *pConVar, char const *oldValue);
#if defined ORANGEBOX_BUILD
extern void _IntExt_OnHostnameChanged(IConVar *var, const char *pOldValue, float flOldValue);
#else
extern void _IntExt_OnHostnameChanged(ConVar *pConVar, char const *oldValue);
#endif
void RootConsoleMenu::OnSourceModStartup(bool late)
{
ConCommandBaseMgr::OneTimeInit(this);
#if defined ORANGEBOX_BUILD
ICvar *g_pCVar = icvar;
#endif
CONVAR_REGISTER(this);
AddRootConsoleCommand("version", "Display version information", this);
AddRootConsoleCommand("credits", "Display credits listing", this);
@ -201,28 +208,28 @@ void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
extern void _IntExt_EnableYams();
void RootConsoleMenu::GotRootCmd()
void RootConsoleMenu::GotRootCmd(const CCommand &cmd)
{
unsigned int argnum = GetArgumentCount();
unsigned int argnum = cmd.ArgC();
if (argnum >= 2)
{
const char *cmd = GetArgument(1);
if (strcmp(cmd, "text") == 0)
const char *cmdname = cmd.Arg(1);
if (strcmp(cmdname, "text") == 0)
{
_IntExt_EnableYams();
return;
} else if (strcmp(cmd, "internal") == 0) {
} else if (strcmp(cmdname, "internal") == 0) {
if (argnum >= 3)
{
const char *arg = GetArgument(2);
const char *arg = cmd.Arg(2);
if (strcmp(arg, "1") == 0)
{
SM_ConfigsExecuted_Global();
} else if (strcmp(arg, "2") == 0) {
if (argnum >= 4)
{
SM_ConfigsExecuted_Plugin(atoi(GetArgument(3)));
SM_ConfigsExecuted_Plugin(atoi(cmd.Arg(3)));
}
}
}
@ -230,9 +237,9 @@ void RootConsoleMenu::GotRootCmd()
}
IRootConsoleCommand *pHandler;
if (sm_trie_retrieve(m_pCommands, cmd, (void **)&pHandler))
if (sm_trie_retrieve(m_pCommands, cmdname, (void **)&pHandler))
{
pHandler->OnRootConsoleCommand(cmd, argnum);
pHandler->OnRootConsoleCommand(cmdname, cmd);
return;
}
}
@ -249,24 +256,9 @@ void RootConsoleMenu::GotRootCmd()
}
}
const char *RootConsoleMenu::GetArgument(unsigned int argno)
void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
{
return engine->Cmd_Argv(argno);
}
const char *RootConsoleMenu::GetArguments()
{
return engine->Cmd_Args();
}
unsigned int RootConsoleMenu::GetArgumentCount()
{
return engine->Cmd_Argc();
}
void RootConsoleMenu::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
{
if (strcmp(cmd, "credits") == 0)
if (strcmp(cmdname, "credits") == 0)
{
ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
ConsolePrint(" Development would not have been possible without the following people:");
@ -277,7 +269,7 @@ void RootConsoleMenu::OnRootConsoleCommand(const char *cmd, unsigned int argcoun
ConsolePrint(" Special thanks to Viper of GameConnect");
ConsolePrint(" Special thanks to Mani of Mani-Admin-Plugin");
ConsolePrint(" http://www.sourcemod.net/");
} else if (strcmp(cmd, "version") == 0) {
} else if (strcmp(cmdname, "version") == 0) {
ConsolePrint(" SourceMod Version Information:");
ConsolePrint(" SourceMod Version: %s", SVN_FULL_VERSION);
ConsolePrint(" JIT Version: %s, %s", g_pVM->GetVMName(), g_pVM->GetVersionString());
@ -288,18 +280,24 @@ void RootConsoleMenu::OnRootConsoleCommand(const char *cmd, unsigned int argcoun
CON_COMMAND(sm, "SourceMod Menu")
{
g_RootMenu.GotRootCmd();
#if !defined ORANGEBOX_BUILD
CCommand args;
#endif
g_RootMenu.GotRootCmd(args);
}
CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle leaks")
{
if (engine->Cmd_Argc() < 2)
#if !defined ORANGEBOX_BUILD
CCommand args;
#endif
if (args.ArgC() < 2)
{
g_RootMenu.ConsolePrint("Usage: sm_dump_handles <file>");
return;
}
const char *arg = engine->Cmd_Argv(1);
const char *arg = args.Arg(1);
FILE *fp = fopen(arg, "wt");
if (!fp)
{

View File

@ -64,17 +64,14 @@ public: //SMGlobalClass
void OnSourceModStartup(bool late);
void OnSourceModShutdown();
public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *cmd, unsigned int argcount);
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
public: //IRootConsole
bool AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler);
bool RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler);
void ConsolePrint(const char *fmt, ...);
const char *GetArgument(unsigned int argno);
unsigned int GetArgumentCount();
const char *GetArguments();
void DrawGenericOption(const char *cmd, const char *text);
public:
void GotRootCmd();
void GotRootCmd(const CCommand &cmd);
private:
bool m_CfgExecDone;
Trie *m_pCommands;

View File

@ -107,7 +107,7 @@ static void NotifyConVar(ConVar *pConVar)
{
IGameEvent *pEvent = gameevents->CreateEvent("server_cvar");
pEvent->SetString("cvarname", pConVar->GetName());
if (pConVar->IsBitSet(FCVAR_PROTECTED))
if (IsFlagSet(pConVar, FCVAR_PROTECTED))
{
pEvent->SetString("cvarvalue", "***PROTECTED***");
} else {
@ -250,13 +250,13 @@ static cell_t sm_SetConVarNum(IPluginContext *pContext, const cell_t *params)
pConVar->SetValue(params[2]);
/* Should we replicate it? */
if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED))
if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
{
ReplicateConVar(pConVar);
}
/* Should we notify clients? */
if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY))
if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
{
NotifyConVar(pConVar);
}
@ -297,13 +297,13 @@ static cell_t sm_SetConVarFloat(IPluginContext *pContext, const cell_t *params)
pConVar->SetValue(value);
/* Should we replicate it? */
if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED))
if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
{
ReplicateConVar(pConVar);
}
/* Should we notify clients? */
if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY))
if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
{
NotifyConVar(pConVar);
}
@ -346,13 +346,13 @@ static cell_t sm_SetConVarString(IPluginContext *pContext, const cell_t *params)
pConVar->SetValue(value);
/* Should we replicate it? */
if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED))
if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
{
ReplicateConVar(pConVar);
}
/* Should we notify clients? */
if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY))
if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
{
NotifyConVar(pConVar);
}
@ -375,13 +375,13 @@ static cell_t sm_ResetConVar(IPluginContext *pContext, const cell_t *params)
pConVar->Revert();
/* Should we replicate it? */
if (params[2] && pConVar->IsBitSet(FCVAR_REPLICATED))
if (params[2] && IsFlagSet(pConVar, FCVAR_REPLICATED))
{
ReplicateConVar(pConVar);
}
/* Should we notify clients? */
if (params[3] && pConVar->IsBitSet(FCVAR_NOTIFY))
if (params[3] && IsFlagSet(pConVar, FCVAR_NOTIFY))
{
NotifyConVar(pConVar);
}
@ -625,22 +625,22 @@ static cell_t sm_RegAdminCmd(IPluginContext *pContext, const cell_t *params)
static cell_t sm_GetCmdArgs(IPluginContext *pContext, const cell_t *params)
{
return engine->Cmd_Argc() - 1;
return 4 :O;//engine->Cmd_Argc() - 1;
}
static cell_t sm_GetCmdArg(IPluginContext *pContext, const cell_t *params)
{
const char *arg = engine->Cmd_Argv(params[1]);
//const char *arg = //engine->Cmd_Argv(params[1]);
size_t length;
pContext->StringToLocalUTF8(params[2], params[3], arg, &length);
//pContext->StringToLocalUTF8(params[2], params[3], arg, &length);
return (cell_t)length;
}
static cell_t sm_GetCmdArgString(IPluginContext *pContext, const cell_t *params)
{
const char *args = engine->Cmd_Args();
const char *args = NULL;//engine->Cmd_Args();
size_t length;
if (!args)
@ -751,7 +751,7 @@ static cell_t sm_InsertServerCommand(IPluginContext *pContext, const cell_t *par
buffer[len++] = '\n';
buffer[len] = '\0';
engine->InsertServerCommand(buffer);
InsertServerCommand(buffer);
return 1;
}

View File

@ -60,7 +60,7 @@ public: //SMGlobalClass, IHandleTypeDispatch, IPluginListener
void OnPluginUnloaded(IPlugin *plugin);
public:
MsgListenerWrapper *CreateListener(IPluginContext *pCtx);
MsgWrapperIter FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept);
bool FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept, MsgWrapperIter *iter);
bool DeleteListener(IPluginContext *pCtx, MsgWrapperIter iter);
private:
CStack<MsgListenerWrapper *> m_FreeListeners;
@ -156,30 +156,31 @@ MsgListenerWrapper *UsrMessageNatives::CreateListener(IPluginContext *pCtx)
return pListener;
}
MsgWrapperIter UsrMessageNatives::FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept)
bool UsrMessageNatives::FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept, MsgWrapperIter *iter)
{
MsgWrapperList *pList;
MsgWrapperIter iter;
MsgWrapperIter _iter;
MsgListenerWrapper *pListener;
IPlugin *pl = g_PluginSys.FindPluginByContext(pCtx->GetContext());
if (!pl->GetProperty("MsgListeners", reinterpret_cast<void **>(&pList)))
{
return NULL;
return false;
}
for (iter=pList->begin(); iter!=pList->end(); iter++)
for (_iter=pList->begin(); _iter!=pList->end(); _iter++)
{
pListener = (*iter);
pListener = (*_iter);
if ((msgid == pListener->GetMessageId())
&& (intercept == pListener->IsInterceptHook())
&& (pHook == pListener->GetHookedFunction()))
{
return iter;
*iter = _iter;
return true;
}
}
return NULL;
return false;
}
bool UsrMessageNatives::DeleteListener(IPluginContext *pCtx, MsgWrapperIter iter)
@ -467,8 +468,7 @@ static cell_t smn_UnhookUserMessage(IPluginContext *pCtx, const cell_t *params)
}
intercept = (params[3]) ? true : false;
iter = s_UsrMessageNatives.FindListener(msgid, pCtx, pFunc, intercept);
if (iter == NULL)
if (!s_UsrMessageNatives.FindListener(msgid, pCtx, pFunc, intercept, &iter))
{
return pCtx->ThrowNativeError("Unable to unhook the current user message");
}

View File

@ -31,7 +31,7 @@
#include "sm_globals.h"
#include <vector.h>
#include <mathlib.h>
#include <mathlib/math_base.h>
#define SET_VECTOR(addr, vec) \
addr[0] = sp_ftoc(vec.x); \
@ -181,6 +181,16 @@ static cell_t NormalizeVector(IPluginContext *pContext, const cell_t *params)
return sp_ftoc(length);
}
//:TODO: OMG remove this when we get the OB SDK!!1
// as well as bitbuf.cpp (i write it here just to remind it)
#if defined ORANGEBOX_BUILD
float ham(float _X)
{
return sqrt(_X);
}
float (*pfSqrt)(float x) = ham;
#endif
REGISTER_NATIVES(vectorNatives)
{
{"GetAngleVectors", GetAngleVectors},

View File

@ -29,10 +29,9 @@
* Version: $Id$
*/
#include <oslink.h>
#include "sourcemod.h"
#include "sourcemm_api.h"
#include "sm_version.h"
#include "sourcemod.h"
#include "Logger.h"
#include "ConVarManager.h"
@ -58,18 +57,18 @@ bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen
{
PLUGIN_SAVEVARS();
GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
GET_V_IFACE_CURRENT(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
GET_V_IFACE_CURRENT(engineFactory, icvar, ICvar, VENGINE_CVAR_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
GET_V_IFACE_CURRENT(engineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(fileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(engineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(engineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
GET_V_IFACE_CURRENT(GetServerFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
GET_V_IFACE_CURRENT(GetEngineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetFileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
/* :TODO: Make this optional and... make it find earlier versions [?] */
GET_V_IFACE_CURRENT(serverFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
GET_V_IFACE_CURRENT(GetServerFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
{
@ -80,7 +79,7 @@ bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen
return false;
}
gpGlobals = ismm->pGlobals();
gpGlobals = ismm->GetCGlobals();
ismm->AddListener(this, this);
ismm->EnableVSPListener();

View File

@ -32,7 +32,11 @@
#ifndef _INCLUDE_SOURCEMOD_MM_API_H_
#define _INCLUDE_SOURCEMOD_MM_API_H_
#include "convar_sm.h"
#if defined ORANGEBOX_BUILD
#include "convar_sm_ob.h"
#else
#include "convar_sm.h"
#endif
#include <ISmmPlugin.h>
#include <eiface.h>
#include <igameevents.h>
@ -41,6 +45,10 @@
#include <filesystem.h>
#include <IEngineSound.h>
#ifndef METAMOD_PLAPI_VERSION
#include <metamod_wrappers.h>
#endif
/**
* @file Contains wrappers around required Metamod:Source API exports
*/

View File

@ -813,11 +813,12 @@ void CExtensionManager::AddDependency(IExtension *pSource, const char *file, boo
}
}
void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
{
int argcount = command.ArgC();
if (argcount >= 3)
{
const char *cmd = g_RootMenu.GetArgument(2);
const char *cmd = command.Arg(2);
if (strcmp(cmd, "list") == 0)
{
List<CExtension *>::iterator iter;
@ -869,7 +870,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argco
return;
}
const char *sId = g_RootMenu.GetArgument(3);
const char *sId = command.Arg(3);
unsigned int id = atoi(sId);
if (id <= 0)
{
@ -936,7 +937,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argco
return;
}
const char *arg = g_RootMenu.GetArgument(3);
const char *arg = command.Arg(3);
unsigned int num = atoi(arg);
CExtension *pExt = FindByOrder(num);
@ -948,7 +949,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argco
if (argcount > 4 && pExt->unload_code)
{
const char *unload = g_RootMenu.GetArgument(4);
const char *unload = command.Arg(4);
if (pExt->unload_code == (unsigned)atoi(unload))
{
char filename[PLATFORM_MAX_PATH];

View File

@ -121,7 +121,7 @@ public: //IExtensionManager
public: //IPluginsListener
void OnPluginDestroyed(IPlugin *plugin);
public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *cmd, unsigned int argcount);
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
public:
IExtension *LoadAutoExtension(const char *path);
void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);

View File

@ -1961,11 +1961,12 @@ const char *CPluginManager::GetStatusText(PluginStatus st)
}
}
void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argcount)
void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
{
int argcount = command.ArgC();
if (argcount >= 3)
{
const char *cmd = g_RootMenu.GetArgument(2);
const char *cmd = command.Arg(2);
if (strcmp(cmd, "list") == 0)
{
char buffer[256];
@ -2016,7 +2017,7 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc
char error[128];
bool wasloaded;
const char *filename = g_RootMenu.GetArgument(3);
const char *filename = command.Arg(3);
char pluginfile[256];
const char *ext = g_LibSys.GetFileExtension(filename) ? "" : ".smx";
@ -2047,7 +2048,7 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc
CPlugin *pl;
char *end;
const char *arg = g_RootMenu.GetArgument(3);
const char *arg = command.Arg(3);
int id = strtol(arg, &end, 10);
if (*end == '\0')
@ -2089,7 +2090,7 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc
return;
}
int num = atoi(g_RootMenu.GetArgument(3));
int num = atoi(command.Arg(3));
if (num < 1 || num > (int)GetPluginCount())
{
g_RootMenu.ConsolePrint("[SM] Plugin index not found.");
@ -2166,7 +2167,7 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc
return;
}
int num = atoi(g_RootMenu.GetArgument(3));
int num = atoi(command.Arg(3));
if (num < 1 || num > (int)GetPluginCount())
{
g_RootMenu.ConsolePrint("[SM] Plugin index not found.");
@ -2174,7 +2175,7 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc
}
int res;
const char *mode = g_RootMenu.GetArgument(4);
const char *mode = command.Arg(4);
if ((res=strcmp("on", mode)) && strcmp("off", mode))
{
g_RootMenu.ConsolePrint("[SM] The only possible options are \"on\" and \"off.\"");
@ -2218,7 +2219,7 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc
CPlugin *pl;
char *end;
const char *arg = g_RootMenu.GetArgument(3);
const char *arg = command.Arg(3);
int id = strtol(arg, &end, 10);
if (*end == '\0')

View File

@ -48,7 +48,11 @@
#include "sm_trie.h"
#include "sourcemod.h"
#include <IRootConsoleMenu.h>
#if defined ORANGEBOX_BUILD
#include "convar_sm_ob.h"
#else
#include "convar_sm.h"
#endif
using namespace SourceHook;
@ -351,7 +355,7 @@ public: //SMGlobalClass
public: //IHandleTypeDispatch
void OnHandleDestroy(HandleType_t type, void *object);
public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *command, unsigned int argcount);
void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
public:
/**
* Loads all plugins not yet loaded

View File

@ -32,6 +32,8 @@
#ifndef _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_H_
#define _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_H_
#include <compat_wrappers.h>
/**
* @file IRootConsoleMenu.h
* @brief Defines the interface for adding options to the "sm" console command.
@ -51,7 +53,7 @@ namespace SourceMod
class IRootConsoleCommand
{
public:
virtual void OnRootConsoleCommand(const char *command, unsigned int argcount) =0;
virtual void OnRootConsoleCommand(const char *cmdname, const CCommand &command) =0;
};
/**
@ -87,28 +89,6 @@ namespace SourceMod
*/
virtual void ConsolePrint(const char *fmt, ...) =0;
/**
* @brief Returns the string of an argument.
*
* @param argno The index of the argument.
* @return A string containing the argument, or nothing if invalid.
*/
virtual const char *GetArgument(unsigned int argno) =0;
/**
* @brief Returns the number of arguments.
*
* @return Number of arguments.
*/
virtual unsigned int GetArgumentCount() =0;
/**
* @brief Returns the entire argument string.
*
* @return String containing all arguments.
*/
virtual const char *GetArguments() =0;
/**
* @brief Draws a generic command/description pair.
* NOTE: The pair is currently four spaces indented and 16-N spaces of separation,

82
public/compat_wrappers.h Normal file
View File

@ -0,0 +1,82 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#ifndef _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
#define _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
#if defined ORANGEBOX_BUILD
#include "convar_sm_ob.h"
#include "sourcemm_api.h"
#define CONVAR_REGISTER(object) ConVar_Register(0, object)
inline bool IsFlagSet(ConCommandBase *cmd, int flag)
{
return cmd->IsFlagSet(flag);
}
inline void InsertServerCommand(const char *buf)
{
engine->ServerCommand(buf);
}
#else
#include "sourcemm_api.h"
class CCommand
{
public:
inline const char *ArgS() const
{
return engine->Cmd_Args();
}
inline int ArgC() const
{
return engine->Cmd_Argc();
}
inline const char *Arg(int index) const
{
return engine->Cmd_Argv(index);
}
};
inline bool IsFlagSet(ConCommandBase *cmd, int flag)
{
return cmd->IsBitSet(flag);
}
inline void InsertServerCommand(const char *buf)
{
engine->InsertServerCommand(buf);
}
#define CONVAR_REGISTER(object) ConCommandBaseMgr::OneTimeInit(object)
typedef FnChangeCallback FnChangeCallback_t;
#endif //ORANGEBOX_BUILD
#endif //_INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_

48
public/metamod_wrappers.h Normal file
View File

@ -0,0 +1,48 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#ifndef _INCLUDE_METAMOD_WRAPPERS_H_
#define _INCLUDE_METAMOD_WRAPPERS_H_
/* Get iface wrappers */
#define GetEngineFactory engineFactory
#define GetServerFactory serverFactory
#define GetPhysicsFactory physicsFactory
#define GetFileSystemFactory fileSystemFactory
#define GetCGlobals pGlobals
#define UnregisterConCommandBase UnregisterConCmdBase
/* Valve interface wrappers */
#define CVAR_INTERFACE_VERSION VENGINE_CVAR_INTERFACE_VERSION
#endif //_INCLUDE_METAMOD_WRAPPERS_H_