ported SM's core to Orange Box
authorBorja Ferrer <faluco@alliedmods.net>
Sun Oct 14 00:04:21 2007 +0000 (2007-10-14)
changeset 1541e46ad208b9b4
parent 1540 2228ef062ddc
child 1542 a7fb7373989a
ported SM's core to Orange Box
build is broken now in purpose
core/ChatTriggers.cpp
core/ChatTriggers.h
core/ConCmdManager.cpp
core/ConCmdManager.h
core/ConVarManager.cpp
core/ConVarManager.h
core/CoreConfig.cpp
core/CoreConfig.h
core/GameConfigs.cpp
core/MenuStyle_Radio.cpp
core/MenuStyle_Radio.h
core/MenuStyle_Valve.cpp
core/MenuStyle_Valve.h
core/MenuVoting.cpp
core/PlayerManager.cpp
core/PlayerManager.h
core/TimerSys.cpp
core/bitbuf.cpp
core/convar_sm_ob.h
core/msvc8/sourcemod_mm.sln
core/msvc8/sourcemod_mm.vcproj
core/sm_srvcmds.cpp
core/sm_srvcmds.h
core/smn_console.cpp
core/smn_usermsgs.cpp
core/smn_vector.cpp
core/sourcemm_api.cpp
core/sourcemm_api.h
core/systems/ExtensionSys.cpp
core/systems/ExtensionSys.h
core/systems/PluginSys.cpp
core/systems/PluginSys.h
public/IRootConsoleMenu.h
public/compat_wrappers.h
public/metamod_wrappers.h
     1.1 --- a/core/ChatTriggers.cpp	Sat Oct 13 22:13:43 2007 +0000
     1.2 +++ b/core/ChatTriggers.cpp	Sun Oct 14 00:04:21 2007 +0000
     1.3 @@ -36,13 +36,17 @@
     1.4  #include <IPlayerHelpers.h>
     1.5  
     1.6  /* :HACKHACK: We can't SH_DECL here because ConCmdManager.cpp does */
     1.7 +#if defined ORANGEBOX_BUILD
     1.8 +extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate1<const CCommand &, void>);
     1.9 +extern int __SourceHook_FHAddConCommandDispatch(void *, ISourceHook::AddHookMode, bool, class fastdelegate::FastDelegate1<const CCommand &, void>);
    1.10 +#else
    1.11  extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
    1.12 -
    1.13  #if SH_IMPL_VERSION >= 4
    1.14  extern int __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
    1.15  #else
    1.16  extern bool __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
    1.17 -#endif
    1.18 +#endif //SH_IMPL_VERSION >= 4
    1.19 +#endif //ORANGEBOX_BUILD
    1.20  
    1.21  ChatTriggers g_ChatTriggers;
    1.22  
    1.23 @@ -140,8 +144,14 @@
    1.24  	}
    1.25  }
    1.26  
    1.27 +#if defined ORANGEBOX_BUILD
    1.28 +void ChatTriggers::OnSayCommand_Pre(const CCommand &command)
    1.29 +{
    1.30 +#else
    1.31  void ChatTriggers::OnSayCommand_Pre()
    1.32  {
    1.33 +	CCommand command;
    1.34 +#endif
    1.35  	int client = g_ConCmds.GetCommandClient();
    1.36  	m_bIsChatTrigger = false;
    1.37  
    1.38 @@ -151,7 +161,7 @@
    1.39  		RETURN_META(MRES_IGNORED);
    1.40  	}
    1.41  
    1.42 -	const char *args = engine->Cmd_Args();
    1.43 +	const char *args = command.ArgS();
    1.44  	
    1.45  	if (!args)
    1.46  	{
    1.47 @@ -211,7 +221,11 @@
    1.48  	RETURN_META(MRES_IGNORED);
    1.49  }
    1.50  
    1.51 +#if defined ORANGEBOX_BUILD
    1.52 +void ChatTriggers::OnSayCommand_Post(const CCommand &command)
    1.53 +#else
    1.54  void ChatTriggers::OnSayCommand_Post()
    1.55 +#endif
    1.56  {
    1.57  	m_bIsChatTrigger = false;
    1.58  	if (m_bWillProcessInPost)
     2.1 --- a/core/ChatTriggers.h	Sat Oct 13 22:13:43 2007 +0000
     2.2 +++ b/core/ChatTriggers.h	Sun Oct 14 00:04:21 2007 +0000
     2.3 @@ -50,8 +50,13 @@
     2.4  		char *error, 
     2.5  		size_t maxlength);
     2.6  private: //ConCommand
     2.7 +#if defined ORANGEBOX_BUILD
     2.8 +	void OnSayCommand_Pre(const CCommand &command);
     2.9 +	void OnSayCommand_Post(const CCommand &command);
    2.10 +#else
    2.11  	void OnSayCommand_Pre();
    2.12  	void OnSayCommand_Post();
    2.13 +#endif
    2.14  public:
    2.15  	unsigned int GetReplyTo();
    2.16  	unsigned int SetReplyTo(unsigned int reply);
     3.1 --- a/core/ConCmdManager.cpp	Sat Oct 13 22:13:43 2007 +0000
     3.2 +++ b/core/ConCmdManager.cpp	Sun Oct 14 00:04:21 2007 +0000
     3.3 @@ -40,7 +40,12 @@
     3.4  
     3.5  ConCmdManager g_ConCmds;
     3.6  
     3.7 -SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
     3.8 +#if defined ORANGEBOX_BUILD
     3.9 +	SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
    3.10 +#else
    3.11 +	SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
    3.12 +#endif
    3.13 +
    3.14  SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, false, int);
    3.15  
    3.16  struct PlCmdInfo
    3.17 @@ -144,10 +149,15 @@
    3.18  		delete pList;
    3.19  	}
    3.20  }
    3.21 -
    3.22 +#if defined ORANGEBOX_BUILD
    3.23 +void CommandCallback(const CCommand &command)
    3.24 +{
    3.25 +#else
    3.26  void CommandCallback()
    3.27  {
    3.28 -	g_ConCmds.InternalDispatch();
    3.29 +	CCommand command;
    3.30 +#endif
    3.31 +	g_ConCmds.InternalDispatch(command);
    3.32  }
    3.33  
    3.34  void ConCmdManager::SetCommandClient(int client)
    3.35 @@ -201,7 +211,7 @@
    3.36  	return type;
    3.37  }
    3.38  
    3.39 -void ConCmdManager::InternalDispatch()
    3.40 +void ConCmdManager::InternalDispatch(const CCommand &command)
    3.41  {
    3.42  	int client = m_CmdClient;
    3.43  
    3.44 @@ -221,7 +231,7 @@
    3.45  	 * Whether or not it goes through the callback is determined by FCVAR_GAMEDLL
    3.46  	 */
    3.47  	char cmd[300];
    3.48 -	strncopy(cmd, engine->Cmd_Argv(0), sizeof(cmd));
    3.49 +	strncopy(cmd, command.Arg(0), sizeof(cmd));
    3.50  
    3.51  	ConCmdInfo *pInfo;
    3.52  	if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
    3.53 @@ -230,7 +240,7 @@
    3.54  	}
    3.55  
    3.56  	cell_t result = Pl_Continue;
    3.57 -	int args = engine->Cmd_Argc() - 1;
    3.58 +	int args = command.ArgC() - 1;
    3.59  
    3.60  	List<CmdHook *>::iterator iter;
    3.61  	CmdHook *pHook;
    3.62 @@ -725,7 +735,7 @@
    3.63  		if (info->sourceMod)
    3.64  		{
    3.65  			/* Unlink from SourceMM */
    3.66 -			g_SMAPI->UnregisterConCmdBase(g_PLAPI, info->pCmd);
    3.67 +			g_SMAPI->UnregisterConCommandBase(g_PLAPI, info->pCmd);
    3.68  			/* Delete the command's memory */
    3.69  			char *new_help = const_cast<char *>(info->pCmd->GetHelpText());
    3.70  			char *new_name = const_cast<char *>(info->pCmd->GetName());
    3.71 @@ -822,11 +832,11 @@
    3.72  	return pInfo;
    3.73  }
    3.74  
    3.75 -void ConCmdManager::OnRootConsoleCommand(const char *command, unsigned int argcount)
    3.76 +void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
    3.77  {
    3.78 -	if (argcount >= 3)
    3.79 +	if (command.ArgC() >= 3)
    3.80  	{
    3.81 -		const char *text = engine->Cmd_Argv(2);
    3.82 +		const char *text = command.Arg(2);
    3.83  
    3.84  		int id = atoi(text);
    3.85  		CPlugin *pPlugin = g_PluginSys.GetPluginByOrder(id);
    3.86 @@ -919,9 +929,15 @@
    3.87  	g_yam_state = state;
    3.88  }
    3.89  
    3.90 +#if defined ORANGEBOX_BUILD
    3.91 +void _IntExt_CallYams(const CCommand &cmd)
    3.92 +{
    3.93 +#else
    3.94  void _IntExt_CallYams()
    3.95  {
    3.96 -	const char *arg = engine->Cmd_Argv(1);
    3.97 +	CCommand cmd;
    3.98 +#endif
    3.99 +	const char *arg = cmd.Arg(1);
   3.100  
   3.101  	/* should be impossible */
   3.102  	if (!arg || arg[0] == '\0')
     4.1 --- a/core/ConCmdManager.h	Sat Oct 13 22:13:43 2007 +0000
     4.2 +++ b/core/ConCmdManager.h	Sun Oct 14 00:04:21 2007 +0000
     4.3 @@ -96,7 +96,11 @@
     4.4  	public IRootConsoleCommand,
     4.5  	public IPluginsListener
     4.6  {
     4.7 +#if defined ORANGEBOX_BUILD
     4.8 +	friend void CommandCallback(const CCommand &command);
     4.9 +#else
    4.10  	friend void CommandCallback();
    4.11 +#endif
    4.12  public:
    4.13  	ConCmdManager();
    4.14  	~ConCmdManager();
    4.15 @@ -106,7 +110,7 @@
    4.16  public: //IPluginsListener
    4.17  	void OnPluginDestroyed(IPlugin *plugin);
    4.18  public: //IRootConsoleCommand
    4.19 -	void OnRootConsoleCommand(const char *command, unsigned int argcount);
    4.20 +	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
    4.21  public:
    4.22  	bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    4.23  	bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
    4.24 @@ -122,7 +126,7 @@
    4.25  	bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags);
    4.26  	bool CheckCommandAccess(int client, const char *cmd, FlagBits flags);
    4.27  private:
    4.28 -	void InternalDispatch();
    4.29 +	void InternalDispatch(const CCommand &command);
    4.30  	ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
    4.31  	ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
    4.32  	void SetCommandClient(int client);
     5.1 --- a/core/ConVarManager.cpp	Sat Oct 13 22:13:43 2007 +0000
     5.2 +++ b/core/ConVarManager.cpp	Sun Oct 14 00:04:21 2007 +0000
     5.3 @@ -234,16 +234,17 @@
     5.4  		delete [] pConVar->GetHelpText();
     5.5  
     5.6  		/* Then unlink it from SourceMM */
     5.7 -		g_SMAPI->UnregisterConCmdBase(g_PLAPI, pConVar);
     5.8 +		g_SMAPI->UnregisterConCommandBase(g_PLAPI, pConVar);
     5.9  	}
    5.10  }
    5.11  
    5.12 -void ConVarManager::OnRootConsoleCommand(const char *command, unsigned int argcount)
    5.13 +void ConVarManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
    5.14  {
    5.15 +	int argcount = command.ArgC();
    5.16  	if (argcount >= 3)
    5.17  	{
    5.18  		/* Get plugin index that was passed */
    5.19 -		int id = atoi(g_RootMenu.GetArgument(2));
    5.20 +		int id = atoi(command.Arg(2));
    5.21  		
    5.22  		/* Get plugin object */
    5.23  		CPlugin *plugin = g_PluginSys.GetPluginByOrder(id);
    5.24 @@ -525,10 +526,14 @@
    5.25  	}
    5.26  }
    5.27  
    5.28 +#if defined ORANGEBOX_BUILD
    5.29 +void ConVarManager::OnConVarChanged(IConVar *pConVar, const char *oldValue, float flOldValue)
    5.30 +#else
    5.31  void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue)
    5.32 +#endif
    5.33  {
    5.34  	/* If the values are the same, exit early in order to not trigger callbacks */
    5.35 -	if (strcmp(pConVar->GetString(), oldValue) == 0)
    5.36 +	if (strcmp(reinterpret_cast<ConVar *>(pConVar)->GetString(), oldValue) == 0)
    5.37  	{
    5.38  		return;
    5.39  	}
    5.40 @@ -539,19 +544,23 @@
    5.41  	/* Find the convar in the lookup trie */
    5.42  	sm_trie_retrieve(pCache, pConVar->GetName(), (void **)&pInfo);
    5.43  
    5.44 -	FnChangeCallback origCallback = pInfo->origCallback;
    5.45 +	FnChangeCallback_t origCallback = pInfo->origCallback;
    5.46  	IChangeableForward *pForward = pInfo->pChangeForward;
    5.47  
    5.48  	/* If there was a change callback installed previously, call it */
    5.49  	if (origCallback)
    5.50  	{
    5.51 +#if defined ORANGEBOX_BUILD
    5.52 +		origCallback(pConVar, oldValue, flOldValue);
    5.53 +#else
    5.54  		origCallback(pConVar, oldValue);
    5.55 +#endif
    5.56  	}
    5.57  
    5.58  	/* Now call forwards in plugins that have hooked this */
    5.59  	pForward->PushCell(pInfo->handle);
    5.60  	pForward->PushString(oldValue);
    5.61 -	pForward->PushString(pConVar->GetString());
    5.62 +	pForward->PushString(reinterpret_cast<ConVar *>(pConVar)->GetString());
    5.63  	pForward->Execute(NULL);
    5.64  }
    5.65  
    5.66 @@ -652,10 +661,16 @@
    5.67  	s_YamagramState = yamagram;
    5.68  }
    5.69  
    5.70 +#if defined ORANGEBOX_BUILD
    5.71 +void _IntExt_CallYamagrams(const CCommand &cmd)
    5.72 +{
    5.73 +#else
    5.74  void _IntExt_CallYamagrams()
    5.75  {
    5.76 +	CCommand cmd;
    5.77 +#endif
    5.78  	bool correct = false;
    5.79 -	const char *arg = engine->Cmd_Args();
    5.80 +	const char *arg = cmd.ArgS();
    5.81  
    5.82  	if (!arg || arg[0] == '\0')
    5.83  	{
    5.84 @@ -737,10 +752,14 @@
    5.85  	}
    5.86  }
    5.87  
    5.88 +#if defined ORANGEBOX_BUILD
    5.89 +void _IntExt_OnHostnameChanged(IConVar *pConVar, const char *oldValue, float flOldValue)
    5.90 +#else
    5.91  void _IntExt_OnHostnameChanged(ConVar *pConVar, char const *oldValue)
    5.92 +#endif
    5.93  {
    5.94  	if (strcmp(oldValue, "Good morning, DS-san.") == 0
    5.95 -		&& strcmp(pConVar->GetString(), "Good night, talking desk lamp.") == 0)
    5.96 +		&& strcmp(reinterpret_cast<ConVar *>(pConVar)->GetString(), "Good night, talking desk lamp.") == 0)
    5.97  	{
    5.98  		_IntExt_EnableYamagrams();
    5.99  	}
     6.1 --- a/core/ConVarManager.h	Sat Oct 13 22:13:43 2007 +0000
     6.2 +++ b/core/ConVarManager.h	Sun Oct 14 00:04:21 2007 +0000
     6.3 @@ -51,7 +51,7 @@
     6.4  	Handle_t handle;					/**< Handle to convar */
     6.5  	bool sourceMod;						/**< Determines whether or not convar was created by a SourceMod plugin */
     6.6  	IChangeableForward *pChangeForward;	/**< Forward associated with convar */
     6.7 -	FnChangeCallback origCallback;		/**< The original callback function */
     6.8 +	FnChangeCallback_t origCallback;		/**< The original callback function */
     6.9  #if PLAPI_VERSION < 12
    6.10  	const char *name;					/**< Name of convar */
    6.11  #endif
    6.12 @@ -85,7 +85,7 @@
    6.13  public: // IPluginsListener
    6.14  	void OnPluginUnloaded(IPlugin *plugin);
    6.15  public: //IRootConsoleCommand
    6.16 -	void OnRootConsoleCommand(const char *command, unsigned int argcount);
    6.17 +	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
    6.18  public:
    6.19  	/**
    6.20  	 * Get the 'ConVar' handle type ID.
    6.21 @@ -150,7 +150,11 @@
    6.22  	/**
    6.23  	 * Static callback that Valve's ConVar object executes when the convar's value changes.
    6.24  	 */
    6.25 +#if defined ORANGEBOX_BUILD
    6.26 +	static void OnConVarChanged(IConVar *pConVar, const char *oldValue, float flOldValue);
    6.27 +#else
    6.28  	static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
    6.29 +#endif
    6.30  
    6.31  	/**
    6.32  	 * Callback for when StartQueryCvarValue() has finished.
     7.1 --- a/core/CoreConfig.cpp	Sat Oct 13 22:13:43 2007 +0000
     7.2 +++ b/core/CoreConfig.cpp	Sun Oct 14 00:04:21 2007 +0000
     7.3 @@ -71,12 +71,13 @@
     7.4  	g_bConfigsExecd = false;
     7.5  }
     7.6  
     7.7 -void CoreConfig::OnRootConsoleCommand(const char *command, unsigned int argcount)
     7.8 +void CoreConfig::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
     7.9  {
    7.10 +	int argcount = command.ArgC();
    7.11  	if (argcount >= 4)
    7.12  	{
    7.13 -		const char *option = engine->Cmd_Argv(2);
    7.14 -		const char *value = engine->Cmd_Argv(3);
    7.15 +		const char *option = command.Arg(2);
    7.16 +		const char *value = command.Arg(3);
    7.17  
    7.18  		char error[255];
    7.19  
     8.1 --- a/core/CoreConfig.h	Sat Oct 13 22:13:43 2007 +0000
     8.2 +++ b/core/CoreConfig.h	Sun Oct 14 00:04:21 2007 +0000
     8.3 @@ -50,7 +50,7 @@
     8.4  public: // ITextListener_SMC
     8.5  	SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
     8.6  public: // IRootConsoleCommand
     8.7 -	void OnRootConsoleCommand(const char *command, unsigned int argcount);
     8.8 +	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
     8.9  public:
    8.10  	/**
    8.11  	 * Initializes CoreConfig by reading from core.cfg file
     9.1 --- a/core/GameConfigs.cpp	Sat Oct 13 22:13:43 2007 +0000
     9.2 +++ b/core/GameConfigs.cpp	Sun Oct 14 00:04:21 2007 +0000
     9.3 @@ -386,9 +386,9 @@
     9.4  			void *addrInBase = NULL;
     9.5  			if (strcmp(s_TempSig.library, "server") == 0)
     9.6  			{
     9.7 -				addrInBase = (void *)g_SMAPI->serverFactory(false);
     9.8 +				addrInBase = (void *)g_SMAPI->GetServerFactory(false);
     9.9  			} else if (strcmp(s_TempSig.library, "engine") == 0) {
    9.10 -				addrInBase = (void *)g_SMAPI->engineFactory(false);
    9.11 +				addrInBase = (void *)g_SMAPI->GetEngineFactory(false);
    9.12  			}
    9.13  			void *final_addr = NULL;
    9.14  			if (addrInBase == NULL)
    10.1 --- a/core/MenuStyle_Radio.cpp	Sat Oct 13 22:13:43 2007 +0000
    10.2 +++ b/core/MenuStyle_Radio.cpp	Sun Oct 14 00:04:21 2007 +0000
    10.3 @@ -96,16 +96,16 @@
    10.4  	return (g_ShowMenuId != -1);
    10.5  }
    10.6  
    10.7 -bool CRadioStyle::OnClientCommand(int client, const char *cmd)
    10.8 +bool CRadioStyle::OnClientCommand(int client, const char *cmdname, const CCommand &cmd)
    10.9  {
   10.10 -	if (strcmp(cmd, "menuselect") == 0)
   10.11 +	if (strcmp(cmdname, "menuselect") == 0)
   10.12  	{
   10.13  		if (!m_players[client].bInMenu)
   10.14  		{
   10.15  			return false;
   10.16  		}
   10.17  
   10.18 -		int arg = atoi(engine->Cmd_Argv(1));
   10.19 +		int arg = atoi(cmd.Arg(1));
   10.20  		ClientPressedKey(client, arg);
   10.21  		return true;
   10.22  	}
    11.1 --- a/core/MenuStyle_Radio.h	Sat Oct 13 22:13:43 2007 +0000
    11.2 +++ b/core/MenuStyle_Radio.h	Sun Oct 14 00:04:21 2007 +0000
    11.3 @@ -40,6 +40,7 @@
    11.4  #include <IUserMessages.h>
    11.5  #include "sm_fastlink.h"
    11.6  #include <sh_stack.h>
    11.7 +#include <compat_wrappers.h>
    11.8  
    11.9  using namespace SourceMod;
   11.10  
   11.11 @@ -70,7 +71,7 @@
   11.12  	void OnUserMessageSent(int msg_id);
   11.13  public:
   11.14  	bool IsSupported();
   11.15 -	bool OnClientCommand(int client, const char *cmd);
   11.16 +	bool OnClientCommand(int client, const char *cmdname, const CCommand &cmd);
   11.17  public:
   11.18  	CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL);
   11.19  	void FreeRadioDisplay(CRadioDisplay *display);
    12.1 --- a/core/MenuStyle_Valve.cpp	Sat Oct 13 22:13:43 2007 +0000
    12.2 +++ b/core/MenuStyle_Valve.cpp	Sun Oct 14 00:04:21 2007 +0000
    12.3 @@ -53,11 +53,11 @@
    12.4  	return &m_players[client];
    12.5  }
    12.6  
    12.7 -bool ValveMenuStyle::OnClientCommand(int client, const char *cmd)
    12.8 +bool ValveMenuStyle::OnClientCommand(int client, const char *cmdname, const CCommand &cmd)
    12.9  {
   12.10 -	if (strcmp(cmd, "sm_vmenuselect") == 0)
   12.11 +	if (strcmp(cmdname, "sm_vmenuselect") == 0)
   12.12  	{
   12.13 -		int key_press = atoi(engine->Cmd_Argv(1));
   12.14 +		int key_press = atoi(cmd.Arg(1));
   12.15  		g_ValveMenuStyle.ClientPressedKey(client, key_press);
   12.16  		return true;
   12.17  	}
    13.1 --- a/core/MenuStyle_Valve.h	Sat Oct 13 22:13:43 2007 +0000
    13.2 +++ b/core/MenuStyle_Valve.h	Sun Oct 14 00:04:21 2007 +0000
    13.3 @@ -38,6 +38,7 @@
    13.4  #include "sourcemm_api.h"
    13.5  #include "KeyValues.h"
    13.6  #include "sm_fastlink.h"
    13.7 +#include <compat_wrappers.h>
    13.8  
    13.9  using namespace SourceMod;
   13.10  
   13.11 @@ -59,7 +60,7 @@
   13.12  {
   13.13  public:
   13.14  	ValveMenuStyle();
   13.15 -	bool OnClientCommand(int client, const char *cmd);
   13.16 +	bool OnClientCommand(int client, const char *cmdname, const CCommand &cmd);
   13.17  public: //BaseMenuStyle
   13.18  	CBaseMenuPlayer *GetMenuPlayer(int client);
   13.19  	void SendDisplay(int client, IMenuPanel *display);
    14.1 --- a/core/MenuVoting.cpp	Sat Oct 13 22:13:43 2007 +0000
    14.2 +++ b/core/MenuVoting.cpp	Sun Oct 14 00:04:21 2007 +0000
    14.3 @@ -37,7 +37,11 @@
    14.4  
    14.5  float g_next_vote = 0.0f;
    14.6  
    14.7 +#if defined ORANGEBOX_BUILD
    14.8 +void OnVoteDelayChange(IConVar *cvar, const char *value, float flOldValue);
    14.9 +#else
   14.10  void OnVoteDelayChange(ConVar *cvar, const char *value);
   14.11 +#endif
   14.12  ConVar sm_vote_delay("sm_vote_delay",
   14.13  					 "30",
   14.14  					 0,
   14.15 @@ -48,7 +52,11 @@
   14.16  					 0.0,
   14.17  					 OnVoteDelayChange);
   14.18  
   14.19 +#if defined ORANGEBOX_BUILD
   14.20 +void OnVoteDelayChange(IConVar *cvar, const char *value, float flOldValue)
   14.21 +#else
   14.22  void OnVoteDelayChange(ConVar *cvar, const char *value)
   14.23 +#endif
   14.24  {
   14.25  	/* See if the new vote delay isn't something we need to account for */
   14.26  	if (sm_vote_delay.GetFloat() < 1.0f)
    15.1 --- a/core/PlayerManager.cpp	Sat Oct 13 22:13:43 2007 +0000
    15.2 +++ b/core/PlayerManager.cpp	Sun Oct 14 00:04:21 2007 +0000
    15.3 @@ -54,7 +54,11 @@
    15.4  SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char *, const char *, char *, int);
    15.5  SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, const char *);
    15.6  SH_DECL_HOOK1_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, edict_t *);
    15.7 +#if defined ORANGEBOX_BUILD
    15.8 +SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
    15.9 +#else
   15.10  SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
   15.11 +#endif
   15.12  SH_DECL_HOOK1_void(IServerGameClients, ClientSettingsChanged, SH_NOATTRIB, 0, edict_t *);
   15.13  SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
   15.14  
   15.15 @@ -565,8 +569,14 @@
   15.16  	}
   15.17  }
   15.18  
   15.19 +#if defined ORANGEBOX_BUILD
   15.20 +void PlayerManager::OnClientCommand(edict_t *pEntity, const CCommand &args)
   15.21 +{
   15.22 +#else
   15.23  void PlayerManager::OnClientCommand(edict_t *pEntity)
   15.24  {
   15.25 +	CCommand args;
   15.26 +#endif
   15.27  	int client = engine->IndexOfEdict(pEntity);
   15.28  	cell_t res = Pl_Continue;
   15.29  
   15.30 @@ -580,15 +590,15 @@
   15.31  	 * We cache this because the engine is not re-entrant.
   15.32  	 */
   15.33  	char cmd[300];
   15.34 -	int args = engine->Cmd_Argc() - 1;
   15.35 -	strncopy(cmd, engine->Cmd_Argv(0), sizeof(cmd));
   15.36 +	int argcount = args.ArgC() - 1;
   15.37 +	strncopy(cmd, args.Arg(0), sizeof(cmd));
   15.38  
   15.39 -	bool result = g_ValveMenuStyle.OnClientCommand(client, cmd);
   15.40 +	bool result = g_ValveMenuStyle.OnClientCommand(client, cmd, args);
   15.41  	if (result)
   15.42  	{
   15.43  		res = Pl_Handled;
   15.44  	} else {
   15.45 -		result = g_RadioMenuStyle.OnClientCommand(client, cmd);
   15.46 +		result = g_RadioMenuStyle.OnClientCommand(client, cmd, args);
   15.47  		if (result)
   15.48  		{
   15.49  			res = Pl_Handled;
   15.50 @@ -597,7 +607,7 @@
   15.51  
   15.52  	cell_t res2 = Pl_Continue;
   15.53  	m_clcommand->PushCell(client);
   15.54 -	m_clcommand->PushCell(args);
   15.55 +	m_clcommand->PushCell(argcount);
   15.56  	m_clcommand->Execute(&res2, NULL);
   15.57  
   15.58  	if (res2 > res)
   15.59 @@ -610,7 +620,7 @@
   15.60  		RETURN_META(MRES_SUPERCEDE);
   15.61  	}
   15.62  
   15.63 -	res = g_ConCmds.DispatchClientCommand(client, cmd, args, (ResultType)res);
   15.64 +	res = g_ConCmds.DispatchClientCommand(client, cmd, argcount, (ResultType)res);
   15.65  
   15.66  	if (res >= Pl_Handled)
   15.67  	{
    16.1 --- a/core/PlayerManager.h	Sat Oct 13 22:13:43 2007 +0000
    16.2 +++ b/core/PlayerManager.h	Sun Oct 14 00:04:21 2007 +0000
    16.3 @@ -122,7 +122,11 @@
    16.4  	void OnClientPutInServer(edict_t *pEntity, char const *playername);
    16.5  	void OnClientDisconnect(edict_t *pEntity);
    16.6  	void OnClientDisconnect_Post(edict_t *pEntity);
    16.7 +#if defined ORANGEBOX_BUILD
    16.8 +	void OnClientCommand(edict_t *pEntity, const CCommand &args);
    16.9 +#else
   16.10  	void OnClientCommand(edict_t *pEntity);
   16.11 +#endif
   16.12  	void OnClientSettingsChanged(edict_t *pEntity);
   16.13  	//void OnClientSettingsChanged_Pre(edict_t *pEntity);
   16.14  public: //IPlayerManager
    17.1 --- a/core/TimerSys.cpp	Sat Oct 13 22:13:43 2007 +0000
    17.2 +++ b/core/TimerSys.cpp	Sun Oct 14 00:04:21 2007 +0000
    17.3 @@ -35,7 +35,15 @@
    17.4  #include "sourcemm_api.h"
    17.5  #include "frame_hooks.h"
    17.6  
    17.7 -SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallback, SH_NOATTRIB, false, ConVar *, const char *);
    17.8 +#if !defined ORANGEBOX_BUILD
    17.9 +#define CallGlobalChangeCallbacks	CallGlobalChangeCallback
   17.10 +#endif
   17.11 +
   17.12 +#if defined ORANGEBOX_BUILD
   17.13 +SH_DECL_HOOK3_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *, float);
   17.14 +#else
   17.15 +SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *);
   17.16 +#endif
   17.17  
   17.18  TimerSystem g_Timers;
   17.19  float g_fUniversalTime = 0.0f;
   17.20 @@ -107,7 +115,11 @@
   17.21  		mp_timelimit->SetValue(mp_timelimit->GetInt() + extra_time);
   17.22  	}
   17.23  
   17.24 +#if defined ORANGEBOX_BUILD
   17.25 +	void GlobalChangeCallback(ConVar *pVar, const char *old_value, float flOldValue)
   17.26 +#else
   17.27  	void GlobalChangeCallback(ConVar *pVar, const char *old_value)
   17.28 +#endif
   17.29  	{
   17.30  		if (pVar != mp_timelimit)
   17.31  		{
   17.32 @@ -125,12 +137,12 @@
   17.33  private:
   17.34  	void Enable()
   17.35  	{
   17.36 -		SH_ADD_HOOK_MEMFUNC(ICvar, CallGlobalChangeCallback, icvar, this, &DefaultMapTimer::GlobalChangeCallback, false);
   17.37 +		SH_ADD_HOOK_MEMFUNC(ICvar, CallGlobalChangeCallbacks, icvar, this, &DefaultMapTimer::GlobalChangeCallback, false);
   17.38  	}
   17.39  
   17.40  	void Disable()
   17.41  	{
   17.42 -		SH_REMOVE_HOOK_MEMFUNC(ICvar, CallGlobalChangeCallback, icvar, this, &DefaultMapTimer::GlobalChangeCallback, false);
   17.43 +		SH_REMOVE_HOOK_MEMFUNC(ICvar, CallGlobalChangeCallbacks, icvar, this, &DefaultMapTimer::GlobalChangeCallback, false);
   17.44  	}
   17.45  
   17.46  private:
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/core/bitbuf.cpp	Sun Oct 14 00:04:21 2007 +0000
    18.3 @@ -0,0 +1,961 @@
    18.4 +//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
    18.5 +//
    18.6 +// Purpose: 
    18.7 +//
    18.8 +// $NoKeywords: $
    18.9 +//
   18.10 +//=============================================================================//
   18.11 +
   18.12 +#include "bitbuf.h"
   18.13 +#include "coordsize.h"
   18.14 +#include "vector.h"
   18.15 +#include "mathlib/math_base.h"
   18.16 +#include "vstdlib/strtools.h"
   18.17 +
   18.18 +
   18.19 +// FIXME: Can't use this until we get multithreaded allocations in tier0 working for tools
   18.20 +// This is used by VVIS and fails to link
   18.21 +// NOTE: This must be the last file included!!!
   18.22 +//#include "tier0/memdbgon.h"
   18.23 +
   18.24 +#ifdef _XBOX
   18.25 +// mandatory ... wary of above comment and isolating, tier0 is built as MT though
   18.26 +#include "tier0/memdbgon.h"
   18.27 +#endif
   18.28 +
   18.29 +static BitBufErrorHandler g_BitBufErrorHandler = 0;
   18.30 +
   18.31 +
   18.32 +void InternalBitBufErrorHandler( BitBufErrorType errorType, const char *pDebugName )
   18.33 +{
   18.34 +	if ( g_BitBufErrorHandler )
   18.35 +		g_BitBufErrorHandler( errorType, pDebugName );
   18.36 +}
   18.37 +
   18.38 +
   18.39 +void SetBitBufErrorHandler( BitBufErrorHandler fn )
   18.40 +{
   18.41 +	g_BitBufErrorHandler = fn;
   18.42 +}
   18.43 +
   18.44 +
   18.45 +// #define BB_PROFILING
   18.46 +
   18.47 +
   18.48 +// Precalculated bit masks for WriteUBitLong. Using these tables instead of 
   18.49 +// doing the calculations gives a 33% speedup in WriteUBitLong.
   18.50 +unsigned long g_BitWriteMasks[32][33];
   18.51 +
   18.52 +// (1 << i) - 1
   18.53 +unsigned long g_ExtraMasks[32];
   18.54 +
   18.55 +class CBitWriteMasksInit
   18.56 +{
   18.57 +public:
   18.58 +	CBitWriteMasksInit()
   18.59 +	{
   18.60 +		for( unsigned int startbit=0; startbit < 32; startbit++ )
   18.61 +		{
   18.62 +			for( unsigned int nBitsLeft=0; nBitsLeft < 33; nBitsLeft++ )
   18.63 +			{
   18.64 +				unsigned int endbit = startbit + nBitsLeft;
   18.65 +				g_BitWriteMasks[startbit][nBitsLeft] = (1 << startbit) - 1;
   18.66 +				if(endbit < 32)
   18.67 +					g_BitWriteMasks[startbit][nBitsLeft] |= ~((1 << endbit) - 1);
   18.68 +			}
   18.69 +		}
   18.70 +
   18.71 +		for ( unsigned int maskBit=0; maskBit < 32; maskBit++ )
   18.72 +			g_ExtraMasks[maskBit] = (1 << maskBit) - 1;
   18.73 +	}
   18.74 +};
   18.75 +CBitWriteMasksInit g_BitWriteMasksInit;
   18.76 +
   18.77 +
   18.78 +// ---------------------------------------------------------------------------------------- //
   18.79 +// bf_write
   18.80 +// ---------------------------------------------------------------------------------------- //
   18.81 +
   18.82 +bf_write::bf_write()
   18.83 +{
   18.84 +	m_pData = NULL;
   18.85 +	m_nDataBytes = 0;
   18.86 +	m_nDataBits = -1; // set to -1 so we generate overflow on any operation
   18.87 +	m_iCurBit = 0;
   18.88 +	m_bOverflow = false;
   18.89 +	m_bAssertOnOverflow = true;
   18.90 +	m_pDebugName = NULL;
   18.91 +}
   18.92 +
   18.93 +bf_write::bf_write( const char *pDebugName, void *pData, int nBytes, int nBits )
   18.94 +{
   18.95 +	m_bAssertOnOverflow = true;
   18.96 +	m_pDebugName = pDebugName;
   18.97 +	StartWriting( pData, nBytes, 0, nBits );
   18.98 +}
   18.99 +
  18.100 +bf_write::bf_write( void *pData, int nBytes, int nBits )
  18.101 +{
  18.102 +	m_bAssertOnOverflow = true;
  18.103 +	StartWriting( pData, nBytes, 0, nBits );
  18.104 +}
  18.105 +
  18.106 +void bf_write::StartWriting( void *pData, int nBytes, int iStartBit, int nBits )
  18.107 +{
  18.108 +	// Make sure it's dword aligned and padded.
  18.109 +	Assert( (nBytes % 4) == 0 );
  18.110 +	Assert(((unsigned long)pData & 3) == 0);
  18.111 +
  18.112 +	m_pData = (unsigned char*)pData;
  18.113 +	m_nDataBytes = nBytes;
  18.114 +
  18.115 +	if ( nBits == -1 )
  18.116 +	{
  18.117 +		m_nDataBits = nBytes << 3;
  18.118 +	}
  18.119 +	else
  18.120 +	{
  18.121 +		Assert( nBits <= nBytes*8 );
  18.122 +		m_nDataBits = nBits;
  18.123 +	}
  18.124 +
  18.125 +	m_iCurBit = iStartBit;
  18.126 +	m_bOverflow = false;
  18.127 +}
  18.128 +
  18.129 +void bf_write::Reset()
  18.130 +{
  18.131 +	m_iCurBit = 0;
  18.132 +	m_bOverflow = false;
  18.133 +}
  18.134 +
  18.135 +
  18.136 +void bf_write::SetAssertOnOverflow( bool bAssert )
  18.137 +{
  18.138 +	m_bAssertOnOverflow = bAssert;
  18.139 +}
  18.140 +
  18.141 +
  18.142 +const char* bf_write::GetDebugName()
  18.143 +{
  18.144 +	return m_pDebugName;
  18.145 +}
  18.146 +
  18.147 +
  18.148 +void bf_write::SetDebugName( const char *pDebugName )
  18.149 +{
  18.150 +	m_pDebugName = pDebugName;
  18.151 +}
  18.152 +
  18.153 +
  18.154 +void bf_write::SeekToBit( int bitPos )
  18.155 +{
  18.156 +	m_iCurBit = bitPos;
  18.157 +}
  18.158 +
  18.159 +
  18.160 +// Sign bit comes first
  18.161 +void bf_write::WriteSBitLong( int data, int numbits )
  18.162 +{
  18.163 +	// Do we have a valid # of bits to encode with?
  18.164 +	Assert( numbits >= 1 );
  18.165 +
  18.166 +	// Note: it does this wierdness here so it's bit-compatible with regular integer data in the buffer.
  18.167 +	// (Some old code writes direct integers right into the buffer).
  18.168 +	if(data < 0)
  18.169 +	{
  18.170 +#ifdef _DEBUG
  18.171 +	if( numbits < 32 )
  18.172 +	{
  18.173 +		// Make sure it doesn't overflow.
  18.174 +
  18.175 +		if( data < 0 )
  18.176 +		{
  18.177 +			Assert( data >= -(1 << (numbits-1)) );
  18.178 +		}
  18.179 +		else
  18.180 +		{
  18.181 +			Assert( data < (1 << (numbits-1)) );
  18.182 +		}
  18.183 +	}
  18.184 +#endif
  18.185 +
  18.186 +		WriteUBitLong( (unsigned int)(0x80000000 + data), numbits - 1, false );
  18.187 +		WriteOneBit( 1 );
  18.188 +	}
  18.189 +	else
  18.190 +	{
  18.191 +		WriteUBitLong((unsigned int)data, numbits - 1);
  18.192 +		WriteOneBit( 0 );
  18.193 +	}
  18.194 +}
  18.195 +
  18.196 +// writes an unsigned integer with variable bit length
  18.197 +void bf_write::WriteUBitVar( unsigned int data )
  18.198 +{
  18.199 +	unsigned int bits = 0;
  18.200 +	unsigned int base = 0;
  18.201 +
  18.202 +	while (data > (base<<1))
  18.203 +	{
  18.204 +		bits++;
  18.205 +		base = (1<<bits)-1;
  18.206 +	}
  18.207 +
  18.208 +	// how many bits do we use
  18.209 +	if ( bits > 0)
  18.210 +		WriteUBitLong( 0, bits );
  18.211 +
  18.212 +	// end marker
  18.213 +	WriteOneBit( 1 );  
  18.214 +
  18.215 +	// write the value
  18.216 +	if ( bits > 0)
  18.217 +		WriteUBitLong( data - base , bits );
  18.218 +}
  18.219 +
  18.220 +void bf_write::WriteBitLong(unsigned int data, int numbits, bool bSigned)
  18.221 +{
  18.222 +	if(bSigned)
  18.223 +		WriteSBitLong((int)data, numbits);
  18.224 +	else
  18.225 +		WriteUBitLong(data, numbits);
  18.226 +}
  18.227 +
  18.228 +bool bf_write::WriteBits(const void *pInData, int nBits)
  18.229 +{
  18.230 +#if defined( BB_PROFILING )
  18.231 +	VPROF( "bf_write::WriteBits" );
  18.232 +#endif
  18.233 +
  18.234 +	unsigned char *pOut = (unsigned char*)pInData;
  18.235 +	int nBitsLeft = nBits;
  18.236 +
  18.237 +	if((m_iCurBit+nBits) > m_nDataBits)
  18.238 +	{
  18.239 +		SetOverflowFlag();
  18.240 +		CallErrorHandler( BITBUFERROR_BUFFER_OVERRUN, GetDebugName() );
  18.241 +		return false;
  18.242 +	}
  18.243 +
  18.244 +	// Get output dword-aligned.
  18.245 +	while(((unsigned long)pOut & 3) != 0 && nBitsLeft >= 8)
  18.246 +	{
  18.247 +
  18.248 +		WriteUBitLong( *pOut, 8, false );
  18.249 +		++pOut;
  18.250 +		nBitsLeft -= 8;
  18.251 +	}
  18.252 +	
  18.253 +	// check if we can use fast memcpy if m_iCurBit is byte aligned
  18.254 +	if ( (nBitsLeft >= 32) && (m_iCurBit & 7) == 0 )
  18.255 +	{
  18.256 +		int numbytes = (nBitsLeft >> 3); 
  18.257 +		int numbits = numbytes << 3;
  18.258 +		
  18.259 +		// Bounds checking..
  18.260 +		// TODO: May not need this check anymore
  18.261 +		if((m_iCurBit+numbits) > m_nDataBits)
  18.262 +		{
  18.263 +			m_iCurBit = m_nDataBits;
  18.264 +			SetOverflowFlag();
  18.265 +			CallErrorHandler( BITBUFERROR_BUFFER_OVERRUN, GetDebugName() );
  18.266 +			return false;
  18.267 +		}
  18.268 +		
  18.269 +		Q_memcpy( m_pData+(m_iCurBit>>3), pOut, numbytes );
  18.270 +		pOut += numbytes;
  18.271 +		nBitsLeft -= numbits;
  18.272 +		m_iCurBit += numbits;
  18.273 +	}
  18.274 +
  18.275 +	// Read dwords.
  18.276 +	while(nBitsLeft >= 32)
  18.277 +	{
  18.278 +		WriteUBitLong( *((unsigned long*)pOut), 32, false );
  18.279 +		pOut += sizeof(unsigned long);
  18.280 +		nBitsLeft -= 32;
  18.281 +	}
  18.282 +
  18.283 +	// Read the remaining bytes.
  18.284 +	while(nBitsLeft >= 8)
  18.285 +	{
  18.286 +		WriteUBitLong( *pOut, 8, false );
  18.287 +		++pOut;
  18.288 +		nBitsLeft -= 8;
  18.289 +	}
  18.290 +	
  18.291 +	// Read the remaining bits.
  18.292 +	if(nBitsLeft)
  18.293 +	{
  18.294 +		WriteUBitLong( *pOut, nBitsLeft, false );
  18.295 +	}
  18.296 +
  18.297 +	return !IsOverflowed();
  18.298 +}
  18.299 +
  18.300 +
  18.301 +bool bf_write::WriteBitsFromBuffer( bf_read *pIn, int nBits )
  18.302 +{
  18.303 +	// This could be optimized a little by
  18.304 +	while ( nBits > 32 )
  18.305 +	{
  18.306 +		WriteUBitLong( pIn->ReadUBitLong( 32 ), 32 );
  18.307 +		nBits -= 32;
  18.308 +	}
  18.309 +
  18.310 +	WriteUBitLong( pIn->ReadUBitLong( nBits ), nBits );
  18.311 +	return !IsOverflowed() && !pIn->IsOverflowed();
  18.312 +}
  18.313 +
  18.314 +
  18.315 +void bf_write::WriteBitAngle( float fAngle, int numbits )
  18.316 +{
  18.317 +	int d;
  18.318 +	unsigned int mask;
  18.319 +	unsigned int shift;
  18.320 +
  18.321 +	shift = (1<<numbits);
  18.322 +	mask = shift - 1;
  18.323 +
  18.324 +	d = (int)( (fAngle / 360.0) * shift );
  18.325 +	d &= mask;
  18.326 +
  18.327 +	WriteUBitLong((unsigned int)d, numbits);
  18.328 +}
  18.329 +
  18.330 +void bf_write::WriteBitCoord (const float f)
  18.331 +{
  18.332 +#if defined( BB_PROFILING )
  18.333 +	VPROF( "bf_write::WriteBitCoord" );
  18.334 +#endif
  18.335 +	int		signbit = (f <= -COORD_RESOLUTION);
  18.336 +	int		intval = abs(static_cast<int>(f));
  18.337 +	int		fractval = abs((int)(f*COORD_DENOMINATOR)) & (COORD_DENOMINATOR-1);
  18.338 +
  18.339 +
  18.340 +	// Send the bit flags that indicate whether we have an integer part and/or a fraction part.
  18.341 +	WriteOneBit( intval );
  18.342 +	WriteOneBit( fractval );
  18.343 +
  18.344 +	if ( intval || fractval )
  18.345 +	{
  18.346 +		// Send the sign bit
  18.347 +		WriteOneBit( signbit );
  18.348 +
  18.349 +		// Send the integer if we have one.
  18.350 +		if ( intval )
  18.351 +		{
  18.352 +			// Adjust the integers from [1..MAX_COORD_VALUE] to [0..MAX_COORD_VALUE-1]
  18.353 +			intval--;
  18.354 +			WriteUBitLong( (unsigned int)intval, COORD_INTEGER_BITS );
  18.355 +		}
  18.356 +		
  18.357 +		// Send the fraction if we have one
  18.358 +		if ( fractval )
  18.359 +		{
  18.360 +			WriteUBitLong( (unsigned int)fractval, COORD_FRACTIONAL_BITS );
  18.361 +		}
  18.362 +	}
  18.363 +}
  18.364 +
  18.365 +void bf_write::WriteBitFloat(float val)
  18.366 +{
  18.367 +	long intVal;
  18.368 +
  18.369 +	Assert(sizeof(long) == sizeof(float));
  18.370 +	Assert(sizeof(float) == 4);
  18.371 +
  18.372 +	void *v = &val;
  18.373 +	intVal = *reinterpret_cast<long *>(v);
  18.374 +	WriteUBitLong( intVal, 32 );
  18.375 +}
  18.376 +
  18.377 +void bf_write::WriteBitVec3Coord( const Vector& fa )
  18.378 +{
  18.379 +	int		xflag, yflag, zflag;
  18.380 +
  18.381 +	xflag = (fa[0] >= COORD_RESOLUTION) || (fa[0] <= -COORD_RESOLUTION);
  18.382 +	yflag = (fa[1] >= COORD_RESOLUTION) || (fa[1] <= -COORD_RESOLUTION);
  18.383 +	zflag = (fa[2] >= COORD_RESOLUTION) || (fa[2] <= -COORD_RESOLUTION);
  18.384 +
  18.385 +	WriteOneBit( xflag );
  18.386 +	WriteOneBit( yflag );
  18.387 +	WriteOneBit( zflag );
  18.388 +
  18.389 +	if ( xflag )
  18.390 +		WriteBitCoord( fa[0] );
  18.391 +	if ( yflag )
  18.392 +		WriteBitCoord( fa[1] );
  18.393 +	if ( zflag )
  18.394 +		WriteBitCoord( fa[2] );
  18.395 +}
  18.396 +
  18.397 +void bf_write::WriteBitNormal( float f )
  18.398 +{
  18.399 +	int	signbit = (f <= -NORMAL_RESOLUTION);
  18.400 +
  18.401 +	// NOTE: Since +/-1 are valid values for a normal, I'm going to encode that as all ones
  18.402 +	unsigned int fractval = abs( (int)(f*NORMAL_DENOMINATOR) );
  18.403 +
  18.404 +	// clamp..
  18.405 +	if (fractval > NORMAL_DENOMINATOR)
  18.406 +		fractval = NORMAL_DENOMINATOR;
  18.407 +
  18.408 +	// Send the sign bit
  18.409 +	WriteOneBit( signbit );
  18.410 +
  18.411 +	// Send the fractional component
  18.412 +	WriteUBitLong( fractval, NORMAL_FRACTIONAL_BITS );
  18.413 +}
  18.414 +
  18.415 +void bf_write::WriteBitVec3Normal( const Vector& fa )
  18.416 +{
  18.417 +	int		xflag, yflag;
  18.418 +
  18.419 +	xflag = (fa[0] >= NORMAL_RESOLUTION) || (fa[0] <= -NORMAL_RESOLUTION);
  18.420 +	yflag = (fa[1] >= NORMAL_RESOLUTION) || (fa[1] <= -NORMAL_RESOLUTION);
  18.421 +
  18.422 +	WriteOneBit( xflag );
  18.423 +	WriteOneBit( yflag );
  18.424 +
  18.425 +	if ( xflag )
  18.426 +		WriteBitNormal( fa[0] );
  18.427 +	if ( yflag )
  18.428 +		WriteBitNormal( fa[1] );
  18.429 +	
  18.430 +	// Write z sign bit
  18.431 +	int	signbit = (fa[2] <= -NORMAL_RESOLUTION);
  18.432 +	WriteOneBit( signbit );
  18.433 +}
  18.434 +
  18.435 +void bf_write::WriteBitAngles( const QAngle& fa )
  18.436 +{
  18.437 +	// FIXME:
  18.438 +	Vector tmp( fa.x, fa.y, fa.z );
  18.439 +	WriteBitVec3Coord( tmp );
  18.440 +}
  18.441 +
  18.442 +void bf_write::WriteChar(int val)
  18.443 +{
  18.444 +	WriteSBitLong(val, sizeof(char) << 3);
  18.445 +}
  18.446 +
  18.447 +void bf_write::WriteByte(int val)
  18.448 +{
  18.449 +	WriteUBitLong(val, sizeof(unsigned char) << 3);
  18.450 +}
  18.451 +
  18.452 +void bf_write::WriteShort(int val)
  18.453 +{
  18.454 +	WriteSBitLong(val, sizeof(short) << 3);
  18.455 +}
  18.456 +
  18.457 +void bf_write::WriteWord(int val)
  18.458 +{
  18.459 +	WriteUBitLong(val, sizeof(unsigned short) << 3);
  18.460 +}
  18.461 +
  18.462 +void bf_write::WriteLong(long val)
  18.463 +{
  18.464 +	WriteSBitLong(val, sizeof(long) << 3);
  18.465 +}
  18.466 +
  18.467 +void bf_write::WriteFloat(float val)
  18.468 +{
  18.469 +	WriteBits(&val, sizeof(val) << 3);
  18.470 +}
  18.471 +
  18.472 +bool bf_write::WriteBytes( const void *pBuf, int nBytes )
  18.473 +{
  18.474 +	return WriteBits(pBuf, nBytes << 3);
  18.475 +}
  18.476 +
  18.477 +bool bf_write::WriteString(const char *pStr)
  18.478 +{
  18.479 +	if(pStr)
  18.480 +	{
  18.481 +		do
  18.482 +		{
  18.483 +			WriteChar( *pStr );
  18.484 +			++pStr;
  18.485 +		} while( *(pStr-1) != 0 );
  18.486 +	}
  18.487 +	else
  18.488 +	{
  18.489 +		WriteChar( 0 );
  18.490 +	}
  18.491 +
  18.492 +	return !IsOverflowed();
  18.493 +}
  18.494 +
  18.495 +// ---------------------------------------------------------------------------------------- //
  18.496 +// bf_read
  18.497 +// ---------------------------------------------------------------------------------------- //
  18.498 +
  18.499 +bf_read::bf_read()
  18.500 +{
  18.501 +	m_pData = NULL;
  18.502 +	m_nDataBytes = 0;
  18.503 +	m_nDataBits = -1; // set to -1 so we overflow on any operation
  18.504 +	m_iCurBit = 0;
  18.505 +	m_bOverflow = false;
  18.506 +	m_bAssertOnOverflow = true;
  18.507 +	m_pDebugName = NULL;
  18.508 +}
  18.509 +
  18.510 +bf_read::bf_read( const void *pData, int nBytes, int nBits )
  18.511 +{
  18.512 +	m_bAssertOnOverflow = true;
  18.513 +	StartReading( pData, nBytes, 0, nBits );
  18.514 +}
  18.515 +
  18.516 +bf_read::bf_read( const char *pDebugName, const void *pData, int nBytes, int nBits )
  18.517 +{
  18.518 +	m_bAssertOnOverflow = true;
  18.519 +	m_pDebugName = pDebugName;
  18.520 +	StartReading( pData, nBytes, 0, nBits );
  18.521 +}
  18.522 +
  18.523 +void bf_read::StartReading( const void *pData, int nBytes, int iStartBit, int nBits )
  18.524 +{
  18.525 +	// Make sure we're dword aligned.
  18.526 +	Assert(((unsigned long)pData & 3) == 0);
  18.527 +
  18.528 +	m_pData = (unsigned char*)pData;
  18.529 +	m_nDataBytes = nBytes;
  18.530 +
  18.531 +	if ( nBits == -1 )
  18.532 +	{
  18.533 +		m_nDataBits = m_nDataBytes << 3;
  18.534 +	}
  18.535 +	else
  18.536 +	{
  18.537 +		Assert( nBits <= nBytes*8 );
  18.538 +		m_nDataBits = nBits;
  18.539 +	}
  18.540 +
  18.541 +	m_iCurBit = iStartBit;
  18.542 +	m_bOverflow = false;
  18.543 +}
  18.544 +
  18.545 +void bf_read::Reset()
  18.546 +{
  18.547 +	m_iCurBit = 0;
  18.548 +	m_bOverflow = false;
  18.549 +}
  18.550 +
  18.551 +void bf_read::SetAssertOnOverflow( bool bAssert )
  18.552 +{
  18.553 +	m_bAssertOnOverflow = bAssert;
  18.554 +}
  18.555 +
  18.556 +const char* bf_read::GetDebugName()
  18.557 +{
  18.558 +	return m_pDebugName;
  18.559 +}
  18.560 +
  18.561 +void bf_read::SetDebugName( const char *pName )
  18.562 +{
  18.563 +	m_pDebugName = pName;
  18.564 +}
  18.565 +
  18.566 +unsigned int bf_read::CheckReadUBitLong(int numbits)
  18.567 +{
  18.568 +	// Ok, just read bits out.
  18.569 +	int i, nBitValue;
  18.570 +	unsigned int r = 0;
  18.571 +
  18.572 +	for(i=0; i < numbits; i++)
  18.573 +	{
  18.574 +		nBitValue = ReadOneBitNoCheck();
  18.575 +		r |= nBitValue << i;
  18.576 +	}
  18.577 +	m_iCurBit -= numbits;
  18.578 +	
  18.579 +	return r;
  18.580 +}
  18.581 +
  18.582 +bool bf_read::ReadBits(void *pOutData, int nBits)
  18.583 +{
  18.584 +#if defined( BB_PROFILING )
  18.585 +	VPROF( "bf_write::ReadBits" );
  18.586 +#endif
  18.587 +
  18.588 +	unsigned char *pOut = (unsigned char*)pOutData;
  18.589 +	int nBitsLeft = nBits;
  18.590 +
  18.591 +	
  18.592 +	// Get output dword-aligned.
  18.593 +	while(((unsigned long)pOut & 3) != 0 && nBitsLeft >= 8)
  18.594 +	{
  18.595 +		*pOut = (unsigned char)ReadUBitLong(8);
  18.596 +		++pOut;
  18.597 +		nBitsLeft -= 8;
  18.598 +	}
  18.599 +
  18.600 +	// Read dwords.
  18.601 +	while(nBitsLeft >= 32)
  18.602 +	{
  18.603 +		*((unsigned long*)pOut) = ReadUBitLong(32);
  18.604 +		pOut += sizeof(unsigned long);
  18.605 +		nBitsLeft -= 32;
  18.606 +	}
  18.607 +
  18.608 +	// Read the remaining bytes.
  18.609 +	while(nBitsLeft >= 8)
  18.610 +	{
  18.611 +		*pOut = ReadUBitLong(8);
  18.612 +		++pOut;
  18.613 +		nBitsLeft -= 8;
  18.614 +	}
  18.615 +	
  18.616 +	// Read the remaining bits.
  18.617 +	if(nBitsLeft)
  18.618 +	{
  18.619 +		*pOut = ReadUBitLong(nBitsLeft);
  18.620 +	}
  18.621 +
  18.622 +	return !IsOverflowed();
  18.623 +}
  18.624 +
  18.625 +float bf_read::ReadBitAngle( int numbits )
  18.626 +{
  18.627 +	float fReturn;
  18.628 +	int i;
  18.629 +	float shift;
  18.630 +
  18.631 +	shift = (float)( 1 << numbits );
  18.632 +
  18.633 +	i = ReadUBitLong( numbits );
  18.634 +	fReturn = (float)i * (360.0 / shift);
  18.635 +
  18.636 +	return fReturn;
  18.637 +}
  18.638 +
  18.639 +unsigned int bf_read::PeekUBitLong( int numbits )
  18.640 +{
  18.641 +	unsigned int r;
  18.642 +	int i, nBitValue;
  18.643 +#ifdef BIT_VERBOSE
  18.644 +	int nShifts = numbits;
  18.645 +#endif
  18.646 +
  18.647 +	bf_read savebf;
  18.648 +
  18.649 +	savebf = *this;  // Save current state info
  18.650 +
  18.651 +	r = 0;
  18.652 +	for(i=0; i < numbits; i++)
  18.653 +	{
  18.654 +		nBitValue = ReadOneBit();
  18.655 +
  18.656 +		// Append to current stream
  18.657 +		if ( nBitValue )
  18.658 +		{
  18.659 +			r |= 1 << i;
  18.660 +		}
  18.661 +	}
  18.662 +	
  18.663 +	*this = savebf;
  18.664 +
  18.665 +#ifdef BIT_VERBOSE
  18.666 +	Con_Printf( "PeekBitLong:  %i %i\n", nShifts, (unsigned int)r );
  18.667 +#endif
  18.668 +
  18.669 +	return r;
  18.670 +}
  18.671 +
  18.672 +// Append numbits least significant bits from data to the current bit stream
  18.673 +int bf_read::ReadSBitLong( int numbits )
  18.674 +{
  18.675 +	int r, sign;
  18.676 +
  18.677 +	r = ReadUBitLong(numbits - 1);
  18.678 +
  18.679 +	// Note: it does this wierdness here so it's bit-compatible with regular integer data in the buffer.
  18.680 +	// (Some old code writes direct integers right into the buffer).
  18.681 +	sign = ReadOneBit();
  18.682 +	if(sign)
  18.683 +		r = -((1 << (numbits-1)) - r);
  18.684 +
  18.685 +	return r;
  18.686 +}
  18.687 +
  18.688 +unsigned int bf_read::ReadUBitVar()
  18.689 +{
  18.690 +	int bits = 0; // how many bits are used to encode delta offset
  18.691 +
  18.692 +		// how many bits do we use
  18.693 +	while ( ReadOneBit() == 0 )
  18.694 +		bits++;
  18.695 +
  18.696 +	unsigned int data = (1<<bits)-1;
  18.697 +	
  18.698 +	// read the value
  18.699 +	if ( bits > 0)
  18.700 +		data += ReadUBitLong( bits );
  18.701 +
  18.702 +	return data;
  18.703 +}
  18.704 +
  18.705 +
  18.706 +unsigned int bf_read::ReadBitLong(int numbits, bool bSigned)
  18.707 +{
  18.708 +	if(bSigned)
  18.709 +		return (unsigned int)ReadSBitLong(numbits);
  18.710 +	else
  18.711 +		return ReadUBitLong(numbits);
  18.712 +}
  18.713 +
  18.714 +
  18.715 +// Basic Coordinate Routines (these contain bit-field size AND fixed point scaling constants)
  18.716 +float bf_read::ReadBitCoord (void)
  18.717 +{
  18.718 +#if defined( BB_PROFILING )
  18.719 +	VPROF( "bf_write::ReadBitCoord" );
  18.720 +#endif
  18.721 +	int		intval=0,fractval=0,signbit=0;
  18.722 +	float	value = 0.0;
  18.723 +
  18.724 +
  18.725 +	// Read the required integer and fraction flags
  18.726 +	intval = ReadOneBit();
  18.727 +	fractval = ReadOneBit();
  18.728 +
  18.729 +	// If we got either parse them, otherwise it's a zero.
  18.730 +	if ( intval || fractval )
  18.731 +	{
  18.732 +		// Read the sign bit
  18.733 +		signbit = ReadOneBit();
  18.734 +
  18.735 +		// If there's an integer, read it in
  18.736 +		if ( intval )
  18.737 +		{
  18.738 +			// Adjust the integers from [0..MAX_COORD_VALUE-1] to [1..MAX_COORD_VALUE]
  18.739 +			intval = ReadUBitLong( COORD_INTEGER_BITS ) + 1;
  18.740 +		}
  18.741 +
  18.742 +		// If there's a fraction, read it in
  18.743 +		if ( fractval )
  18.744 +		{
  18.745 +			fractval = ReadUBitLong( COORD_FRACTIONAL_BITS );
  18.746 +		}
  18.747 +
  18.748 +		// Calculate the correct floating point value
  18.749 +		value = intval + ((float)fractval * COORD_RESOLUTION);
  18.750 +
  18.751 +		// Fixup the sign if negative.
  18.752 +		if ( signbit )
  18.753 +			value = -value;
  18.754 +	}
  18.755 +
  18.756 +	return value;
  18.757 +}
  18.758 +
  18.759 +void bf_read::ReadBitVec3Coord( Vector& fa )
  18.760 +{
  18.761 +	int		xflag, yflag, zflag;
  18.762 +
  18.763 +	// This vector must be initialized! Otherwise, If any of the flags aren't set, 
  18.764 +	// the corresponding component will not be read and will be stack garbage.
  18.765 +	fa.Init( 0, 0, 0 );
  18.766 +
  18.767 +	xflag = ReadOneBit();
  18.768 +	yflag = ReadOneBit(); 
  18.769 +	zflag = ReadOneBit();
  18.770 +
  18.771 +	if ( xflag )
  18.772 +		fa[0] = ReadBitCoord();
  18.773 +	if ( yflag )
  18.774 +		fa[1] = ReadBitCoord();
  18.775 +	if ( zflag )
  18.776 +		fa[2] = ReadBitCoord();
  18.777 +}
  18.778 +
  18.779 +float bf_read::ReadBitNormal (void)
  18.780 +{
  18.781 +	// Read the sign bit
  18.782 +	int	signbit = ReadOneBit();
  18.783 +
  18.784 +	// Read the fractional part
  18.785 +	unsigned int fractval = ReadUBitLong( NORMAL_FRACTIONAL_BITS );
  18.786 +
  18.787 +	// Calculate the correct floating point value
  18.788 +	float value = (float)fractval * NORMAL_RESOLUTION;
  18.789 +
  18.790 +	// Fixup the sign if negative.
  18.791 +	if ( signbit )
  18.792 +		value = -value;
  18.793 +
  18.794 +	return value;
  18.795 +}
  18.796 +
  18.797 +void bf_read::ReadBitVec3Normal( Vector& fa )
  18.798 +{
  18.799 +	int xflag = ReadOneBit();
  18.800 +	int yflag = ReadOneBit(); 
  18.801 +
  18.802 +	if (xflag)
  18.803 +		fa[0] = ReadBitNormal();
  18.804 +	else
  18.805 +		fa[0] = 0.0f;
  18.806 +
  18.807 +	if (yflag)
  18.808 +		fa[1] = ReadBitNormal();
  18.809 +	else
  18.810 +		fa[1] = 0.0f;
  18.811 +
  18.812 +	// The first two imply the third (but not its sign)
  18.813 +	int znegative = ReadOneBit();
  18.814 +
  18.815 +	float fafafbfb = fa[0] * fa[0] + fa[1] * fa[1];
  18.816 +	if (fafafbfb < 1.0f)
  18.817 +		fa[2] = sqrt( 1.0f - fafafbfb );
  18.818 +	else
  18.819 +		fa[2] = 0.0f;
  18.820 +
  18.821 +	if (znegative)
  18.822 +		fa[2] = -fa[2];
  18.823 +}
  18.824 +
  18.825 +void bf_read::ReadBitAngles( QAngle& fa )
  18.826 +{
  18.827 +	Vector tmp;
  18.828 +	ReadBitVec3Coord( tmp );
  18.829 +	fa.Init( tmp.x, tmp.y, tmp.z );
  18.830 +}
  18.831 +
  18.832 +int bf_read::ReadChar()
  18.833 +{
  18.834 +	return ReadSBitLong(sizeof(char) << 3);
  18.835 +}
  18.836 +
  18.837 +int bf_read::ReadByte()
  18.838 +{
  18.839 +	return ReadUBitLong(sizeof(unsigned char) << 3);
  18.840 +}
  18.841 +
  18.842 +int bf_read::ReadShort()
  18.843 +{
  18.844 +	return ReadSBitLong(sizeof(short) << 3);
  18.845 +}
  18.846 +
  18.847 +int bf_read::ReadWord()
  18.848 +{
  18.849 +	return ReadUBitLong(sizeof(unsigned short) << 3);
  18.850 +}
  18.851 +
  18.852 +long bf_read::ReadLong()
  18.853 +{
  18.854 +	return ReadSBitLong(sizeof(long) << 3);
  18.855 +}
  18.856 +
  18.857 +float bf_read::ReadFloat()
  18.858 +{
  18.859 +	float ret;
  18.860 +	Assert( sizeof(ret) == 4 );
  18.861 +	ReadBits(&ret, 32);
  18.862 +	return ret;
  18.863 +}
  18.864 +
  18.865 +bool bf_read::ReadBytes(void *pOut, int nBytes)
  18.866 +{
  18.867 +	return ReadBits(pOut, nBytes << 3);
  18.868 +}
  18.869 +
  18.870 +bool bf_read::ReadString( char *pStr, int maxLen, bool bLine, int *pOutNumChars )
  18.871 +{
  18.872 +	Assert( maxLen != 0 );
  18.873 +
  18.874 +	bool bTooSmall = false;
  18.875 +	int iChar = 0;
  18.876 +	while(1)
  18.877 +	{
  18.878 +		char val = ReadChar();
  18.879 +		if ( val == 0 )
  18.880 +			break;
  18.881 +		else if ( bLine && val == '\n' )
  18.882 +			break;
  18.883 +
  18.884 +		if ( iChar < (maxLen-1) )
  18.885 +		{
  18.886 +			pStr[iChar] = val;
  18.887 +			++iChar;
  18.888 +		}
  18.889 +		else
  18.890 +		{
  18.891 +			bTooSmall = true;
  18.892 +		}
  18.893 +	}
  18.894 +
  18.895 +	// Make sure it's null-terminated.
  18.896 +	Assert( iChar < maxLen );
  18.897 +	pStr[iChar] = 0;
  18.898 +
  18.899 +	if ( pOutNumChars )
  18.900 +		*pOutNumChars = iChar;
  18.901 +
  18.902 +	return !IsOverflowed() && !bTooSmall;
  18.903 +}
  18.904 +
  18.905 +
  18.906 +char* bf_read::ReadAndAllocateString( bool *pOverflow )
  18.907 +{
  18.908 +	char str[2048];
  18.909 +	
  18.910 +	int nChars;
  18.911 +	bool bOverflow = !ReadString( str, sizeof( str ), false, &nChars );
  18.912 +	if ( pOverflow )
  18.913 +		*pOverflow = bOverflow;
  18.914 +
  18.915 +	// Now copy into the output and return it;
  18.916 +	char *pRet = new char[ nChars + 1 ];
  18.917 +	for ( int i=0; i <= nChars; i++ )
  18.918 +		pRet[i] = str[i];
  18.919 +
  18.920 +	return pRet;
  18.921 +}
  18.922 +
  18.923 +	
  18.924 +bool bf_read::Seek(int iBit)
  18.925 +{
  18.926 +	if(iBit < 0)
  18.927 +	{
  18.928 +		SetOverflowFlag();
  18.929 +		m_iCurBit = m_nDataBits;
  18.930 +		return false;
  18.931 +	}
  18.932 +	else if(iBit > m_nDataBits)
  18.933 +	{
  18.934 +		SetOverflowFlag();
  18.935 +		m_iCurBit = m_nDataBits;
  18.936 +		return false;
  18.937 +	}
  18.938 +	else
  18.939 +	{
  18.940 +		m_iCurBit = iBit;
  18.941 +		return true;
  18.942 +	}
  18.943 +}
  18.944 +
  18.945 +void bf_read::ExciseBits( int startbit, int bitstoremove )
  18.946 +{
  18.947 +	int endbit = startbit + bitstoremove;
  18.948 +	int remaining_to_end = m_nDataBits - endbit;
  18.949 +
  18.950 +	bf_write temp;
  18.951 +	temp.StartWriting( (void *)m_pData, m_nDataBits << 3, startbit );
  18.952 +
  18.953 +	Seek( endbit );
  18.954 +
  18.955 +	for ( int i = 0; i < remaining_to_end; i++ )
  18.956 +	{
  18.957 +		temp.WriteOneBit( ReadOneBit() );
  18.958 +	}
  18.959 +
  18.960 +	Seek( startbit );
  18.961 +	
  18.962 +	m_nDataBits -= bitstoremove;
  18.963 +	m_nDataBytes = m_nDataBits >> 3;
  18.964 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/core/convar_sm_ob.h	Sun Oct 14 00:04:21 2007 +0000
    19.3 @@ -0,0 +1,709 @@
    19.4 +//===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
    19.5 +//
    19.6 +// Purpose: 
    19.7 +//
    19.8 +// $Workfile:     $
    19.9 +// $Date:         $
   19.10 +//
   19.11 +//-----------------------------------------------------------------------------
   19.12 +// $NoKeywords: $
   19.13 +//===========================================================================//
   19.14 +
   19.15 +#ifndef CONVAR_H
   19.16 +#define CONVAR_H
   19.17 +
   19.18 +#if _WIN32
   19.19 +#pragma once
   19.20 +#endif
   19.21 +
   19.22 +#include "tier0/dbg.h"
   19.23 +#include "tier1/iconvar.h"
   19.24 +#include "tier1/utlvector.h"
   19.25 +#include "tier1/utlstring.h"
   19.26 +#include "icvar.h"
   19.27 +
   19.28 +#ifdef _WIN32
   19.29 +#define FORCEINLINE_CVAR FORCEINLINE
   19.30 +#elif _LINUX
   19.31 +#define FORCEINLINE_CVAR inline
   19.32 +#else
   19.33 +#error "implement me"
   19.34 +#endif
   19.35 +
   19.36 +
   19.37 +//-----------------------------------------------------------------------------
   19.38 +// Forward declarations
   19.39 +//-----------------------------------------------------------------------------
   19.40 +class ConVar;
   19.41 +class CCommand;
   19.42 +class ConCommand;
   19.43 +class ConCommandBase;
   19.44 +struct characterset_t;
   19.45 +
   19.46 +
   19.47 +
   19.48 +//-----------------------------------------------------------------------------
   19.49 +// Any executable that wants to use ConVars need to implement one of
   19.50 +// these to hook up access to console variables.
   19.51 +//-----------------------------------------------------------------------------
   19.52 +class IConCommandBaseAccessor
   19.53 +{
   19.54 +public:
   19.55 +	// Flags is a combination of FCVAR flags in cvar.h.
   19.56 +	// hOut is filled in with a handle to the variable.
   19.57 +	virtual bool RegisterConCommandBase( ConCommandBase *pVar ) = 0;
   19.58 +};
   19.59 +
   19.60 +
   19.61 +//-----------------------------------------------------------------------------
   19.62 +// Helper method for console development
   19.63 +//-----------------------------------------------------------------------------
   19.64 +#if defined( _X360 ) && !defined( _RETAIL )
   19.65 +void ConVar_PublishToVXConsole();
   19.66 +#endif
   19.67 +
   19.68 +
   19.69 +//-----------------------------------------------------------------------------
   19.70 +// Called when a ConCommand needs to execute
   19.71 +//-----------------------------------------------------------------------------
   19.72 +typedef void ( *FnCommandCallbackV1_t )( void );
   19.73 +typedef void ( *FnCommandCallback_t )( const CCommand &command );
   19.74 +
   19.75 +#define COMMAND_COMPLETION_MAXITEMS		64
   19.76 +#define COMMAND_COMPLETION_ITEM_LENGTH	64
   19.77 +
   19.78 +//-----------------------------------------------------------------------------
   19.79 +// Returns 0 to COMMAND_COMPLETION_MAXITEMS worth of completion strings
   19.80 +//-----------------------------------------------------------------------------
   19.81 +typedef int  ( *FnCommandCompletionCallback )( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
   19.82 +
   19.83 +
   19.84 +//-----------------------------------------------------------------------------
   19.85 +// Interface version
   19.86 +//-----------------------------------------------------------------------------
   19.87 +class ICommandCallback
   19.88 +{
   19.89 +public:
   19.90 +	virtual void CommandCallback( const CCommand &command ) = 0;
   19.91 +};
   19.92 +
   19.93 +class ICommandCompletionCallback
   19.94 +{
   19.95 +public:
   19.96 +	virtual int  CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands ) = 0;
   19.97 +};
   19.98 +
   19.99 +//-----------------------------------------------------------------------------
  19.100 +// Purpose: The base console invoked command/cvar interface
  19.101 +//-----------------------------------------------------------------------------
  19.102 +class ConCommandBase
  19.103 +{
  19.104 +	friend class CCvar;
  19.105 +	friend class ConVar;
  19.106 +	friend class ConCommand;
  19.107 +	friend void ConVar_Register( int nCVarFlag, IConCommandBaseAccessor *pAccessor );
  19.108 +	friend void ConVar_PublishToVXConsole();
  19.109 +
  19.110 +	// FIXME: Remove when ConVar changes are done
  19.111 +	friend class CDefaultCvar;
  19.112 +
  19.113 +public:
  19.114 +								ConCommandBase( void );
  19.115 +								ConCommandBase( const char *pName, const char *pHelpString = 0, 
  19.116 +									int flags = 0 );
  19.117 +
  19.118 +	virtual						~ConCommandBase( void );
  19.119 +
  19.120 +	virtual	bool				IsCommand( void ) const;
  19.121 +
  19.122 +	// Check flag
  19.123 +	virtual bool				IsFlagSet( int flag ) const;
  19.124 +	// Set flag
  19.125 +	virtual void				AddFlags( int flags );
  19.126 +
  19.127 +	// Return name of cvar
  19.128 +	virtual const char			*GetName( void ) const;
  19.129 +
  19.130 +	// Return help text for cvar
  19.131 +	virtual const char			*GetHelpText( void ) const;
  19.132 +
  19.133 +	// Deal with next pointer
  19.134 +	const ConCommandBase		*GetNext( void ) const;
  19.135 +	ConCommandBase				*GetNext( void );
  19.136 +
  19.137 +	void SetNext(ConCommandBase *pBase)
  19.138 +	{
  19.139 +		m_pNext = pBase;
  19.140 +	}
  19.141 +	
  19.142 +	virtual bool				IsRegistered( void ) const;
  19.143 +
  19.144 +	// Returns the DLL identifier
  19.145 +	virtual CVarDLLIdentifier_t	GetDLLIdentifier() const;
  19.146 +
  19.147 +protected:
  19.148 +	virtual void				Create( const char *pName, const char *pHelpString = 0, 
  19.149 +									int flags = 0 );
  19.150 +
  19.151 +	// Used internally by OneTimeInit to initialize/shutdown
  19.152 +	virtual void				Init();
  19.153 +	void						Shutdown();
  19.154 +
  19.155 +	// Internal copy routine ( uses new operator from correct module )
  19.156 +	char						*CopyString( const char *from );
  19.157 +
  19.158 +private:
  19.159 +	// Next ConVar in chain
  19.160 +	// Prior to register, it points to the next convar in the DLL.
  19.161 +	// Once registered, though, m_pNext is reset to point to the next
  19.162 +	// convar in the global list
  19.163 +	ConCommandBase				*m_pNext;
  19.164 +
  19.165 +	// Has the cvar been added to the global list?
  19.166 +	bool						m_bRegistered;
  19.167 +
  19.168 +	// Static data
  19.169 +	const char 					*m_pszName;
  19.170 +	const char 					*m_pszHelpString;
  19.171 +	
  19.172 +	// ConVar flags
  19.173 +	int							m_nFlags;
  19.174 +
  19.175 +protected:
  19.176 +	// ConVars add themselves to this list for the executable. 
  19.177 +	// Then ConVar_Register runs through  all the console variables 
  19.178 +	// and registers them into a global list stored in vstdlib.dll
  19.179 +	static ConCommandBase		*s_pConCommandBases;
  19.180 +
  19.181 +	// ConVars in this executable use this 'global' to access values.
  19.182 +	static IConCommandBaseAccessor	*s_pAccessor;
  19.183 +public: // Hackalicous
  19.184 +	inline int GetFlags() const
  19.185 +	{
  19.186 +		return m_nFlags;
  19.187 +	}
  19.188 +	inline void SetFlags(int flags)	
  19.189 +	{ 
  19.190 +		m_nFlags = flags; 
  19.191 +	}
  19.192 +};
  19.193 +
  19.194 +
  19.195 +//-----------------------------------------------------------------------------
  19.196 +// Command tokenizer
  19.197 +//-----------------------------------------------------------------------------
  19.198 +class CCommand
  19.199 +{
  19.200 +public:
  19.201 +	CCommand();
  19.202 +	CCommand( int nArgC, const char **ppArgV );
  19.203 +	bool Tokenize( const char *pCommand, characterset_t *pBreakSet = NULL );
  19.204 +	void Reset();
  19.205 +
  19.206 +	int ArgC() const;
  19.207 +	const char **ArgV() const;
  19.208 +	const char *ArgS() const;					// All args that occur after the 0th arg, in string form
  19.209 +	const char *GetCommandString() const;		// The entire command in string form, including the 0th arg
  19.210 +	const char *operator[]( int nIndex ) const;	// Gets at arguments
  19.211 +	const char *Arg( int nIndex ) const;		// Gets at arguments
  19.212 +	
  19.213 +	// Helper functions to parse arguments to commands.
  19.214 +	const char* FindArg( const char *pName ) const;
  19.215 +	int FindArgInt( const char *pName, int nDefaultVal ) const;
  19.216 +
  19.217 +	static int MaxCommandLength();
  19.218 +	static characterset_t* DefaultBreakSet();
  19.219 +
  19.220 +private:
  19.221 +	enum
  19.222 +	{
  19.223 +		COMMAND_MAX_ARGC = 64,
  19.224 +		COMMAND_MAX_LENGTH = 512,
  19.225 +	};
  19.226 +
  19.227 +	int		m_nArgc;
  19.228 +	int		m_nArgv0Size;
  19.229 +	char	m_pArgSBuffer[ COMMAND_MAX_LENGTH ];
  19.230 +	char	m_pArgvBuffer[ COMMAND_MAX_LENGTH ];
  19.231 +	const char*	m_ppArgv[ COMMAND_MAX_ARGC ];
  19.232 +};
  19.233 +
  19.234 +inline int CCommand::MaxCommandLength()
  19.235 +{
  19.236 +	return COMMAND_MAX_LENGTH - 1;
  19.237 +}
  19.238 +
  19.239 +inline int CCommand::ArgC() const
  19.240 +{
  19.241 +	return m_nArgc;
  19.242 +}
  19.243 +
  19.244 +inline const char **CCommand::ArgV() const
  19.245 +{
  19.246 +	return m_nArgc ? (const char**)m_ppArgv : NULL;
  19.247 +}
  19.248 +
  19.249 +inline const char *CCommand::ArgS() const
  19.250 +{
  19.251 +	return m_nArgv0Size ? &m_pArgSBuffer[m_nArgv0Size] : "";
  19.252 +}
  19.253 +
  19.254 +inline const char *CCommand::GetCommandString() const
  19.255 +{
  19.256 +	return m_nArgc ? m_pArgSBuffer : "";
  19.257 +}
  19.258 +
  19.259 +inline const char *CCommand::Arg( int nIndex ) const
  19.260 +{
  19.261 +	// FIXME: Many command handlers appear to not be particularly careful
  19.262 +	// about checking for valid argc range. For now, we're going to
  19.263 +	// do the extra check and return an empty string if it's out of range
  19.264 +	if ( nIndex < 0 || nIndex >= m_nArgc )
  19.265 +		return "";
  19.266 +	return m_ppArgv[nIndex];
  19.267 +}
  19.268 +
  19.269 +inline const char *CCommand::operator[]( int nIndex ) const
  19.270 +{
  19.271 +	return Arg( nIndex );
  19.272 +}
  19.273 +
  19.274 +
  19.275 +//-----------------------------------------------------------------------------
  19.276 +// Purpose: The console invoked command
  19.277 +//-----------------------------------------------------------------------------
  19.278 +class ConCommand : public ConCommandBase
  19.279 +{
  19.280 +friend class CCvar;
  19.281 +
  19.282 +public:
  19.283 +	typedef ConCommandBase BaseClass;
  19.284 +
  19.285 +	ConCommand( const char *pName, FnCommandCallbackV1_t callback, 
  19.286 +		const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
  19.287 +	ConCommand( const char *pName, FnCommandCallback_t callback, 
  19.288 +		const char *pHelpString = 0, int flags = 0, FnCommandCompletionCallback completionFunc = 0 );
  19.289 +	ConCommand( const char *pName, ICommandCallback *pCallback, 
  19.290 +		const char *pHelpString = 0, int flags = 0, ICommandCompletionCallback *pCommandCompletionCallback = 0 );
  19.291 +
  19.292 +	virtual ~ConCommand( void );
  19.293 +
  19.294 +	virtual	bool IsCommand( void ) const;
  19.295 +
  19.296 +	virtual int AutoCompleteSuggest( const char *partial, CUtlVector< CUtlString > &commands );
  19.297 +
  19.298 +	virtual bool CanAutoComplete( void );
  19.299 +
  19.300 +	// Invoke the function
  19.301 +	virtual void Dispatch( const CCommand &command );
  19.302 +
  19.303 +private:
  19.304 +	// NOTE: To maintain backward compat, we have to be very careful:
  19.305 +	// All public virtual methods must appear in the same order always
  19.306 +	// since engine code will be calling into this code, which *does not match*
  19.307 +	// in the mod code; it's using slightly different, but compatible versions
  19.308 +	// of this class. Also: Be very careful about adding new fields to this class.
  19.309 +	// Those fields will not exist in the version of this class that is instanced
  19.310 +	// in mod code.
  19.311 +
  19.312 +	// Call this function when executing the command
  19.313 +	union
  19.314 +	{
  19.315 +		FnCommandCallbackV1_t m_fnCommandCallbackV1;
  19.316 +		FnCommandCallback_t m_fnCommandCallback;
  19.317 +		ICommandCallback *m_pCommandCallback; 
  19.318 +	};
  19.319 +
  19.320 +	union
  19.321 +	{
  19.322 +		FnCommandCompletionCallback	m_fnCompletionCallback;
  19.323 +		ICommandCompletionCallback *m_pCommandCompletionCallback;
  19.324 +	};
  19.325 +
  19.326 +	bool m_bHasCompletionCallback : 1;
  19.327 +	bool m_bUsingNewCommandCallback : 1;
  19.328 +	bool m_bUsingCommandCallbackInterface : 1;
  19.329 +public: // Hackalicous
  19.330 +	inline FnCommandCallback_t GetCallback() const
  19.331 +	{ 
  19.332 +		return m_fnCommandCallback; 
  19.333 +	}
  19.334 +};
  19.335 +
  19.336 +
  19.337 +//-----------------------------------------------------------------------------
  19.338 +// Purpose: A console variable
  19.339 +//-----------------------------------------------------------------------------
  19.340 +class ConVar : public ConCommandBase, public IConVar
  19.341 +{
  19.342 +friend class CCvar;
  19.343 +friend class ConVarRef;
  19.344 +
  19.345 +public:
  19.346 +	typedef ConCommandBase BaseClass;
  19.347 +
  19.348 +								ConVar( const char *pName, const char *pDefaultValue, int flags = 0);
  19.349 +
  19.350 +								ConVar( const char *pName, const char *pDefaultValue, int flags, 
  19.351 +									const char *pHelpString );
  19.352 +								ConVar( const char *pName, const char *pDefaultValue, int flags, 
  19.353 +									const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax );
  19.354 +								ConVar( const char *pName, const char *pDefaultValue, int flags, 
  19.355 +									const char *pHelpString, FnChangeCallback_t callback );
  19.356 +								ConVar( const char *pName, const char *pDefaultValue, int flags, 
  19.357 +									const char *pHelpString, bool bMin, float fMin, bool bMax, float fMax,
  19.358 +									FnChangeCallback_t callback );
  19.359 +
  19.360 +	virtual						~ConVar( void );
  19.361 +
  19.362 +	virtual bool				IsFlagSet( int flag ) const;
  19.363 +	virtual const char*			GetHelpText( void ) const;
  19.364 +	virtual bool				IsRegistered( void ) const;
  19.365 +	virtual const char			*GetName( void ) const;
  19.366 +	virtual void				AddFlags( int flags );
  19.367 +	virtual	bool				IsCommand( void ) const;
  19.368 +
  19.369 +	// Install a change callback (there shouldn't already be one....)
  19.370 +	void InstallChangeCallback( FnChangeCallback_t callback );
  19.371 +
  19.372 +	// Retrieve value
  19.373 +	FORCEINLINE_CVAR float			GetFloat( void ) const;
  19.374 +	FORCEINLINE_CVAR int			GetInt( void ) const;
  19.375 +	FORCEINLINE_CVAR bool			GetBool() const {  return !!GetInt(); }
  19.376 +	FORCEINLINE_CVAR char const	   *GetString( void ) const;
  19.377 +
  19.378 +	// Any function that allocates/frees memory needs to be virtual or else you'll have crashes
  19.379 +	//  from alloc/free across dll/exe boundaries.
  19.380 +	
  19.381 +	// These just call into the IConCommandBaseAccessor to check flags and set the var (which ends up calling InternalSetValue).
  19.382 +	virtual void				SetValue( const char *value );
  19.383 +	virtual void				SetValue( float value );
  19.384 +	virtual void				SetValue( int value );
  19.385 +	
  19.386 +	// Reset to default value
  19.387 +	void						Revert( void );
  19.388 +
  19.389 +	// True if it has a min/max setting
  19.390 +	bool						GetMin( float& minVal ) const;
  19.391 +	bool						GetMax( float& maxVal ) const;
  19.392 +	const char					*GetDefault( void ) const;
  19.393 +
  19.394 +private:
  19.395 +	// Called by CCvar when the value of a var is changing.
  19.396 +	virtual void				InternalSetValue(const char *value);
  19.397 +	// For CVARs marked FCVAR_NEVER_AS_STRING
  19.398 +	virtual void				InternalSetFloatValue( float fNewValue );
  19.399 +	virtual void				InternalSetIntValue( int nValue );
  19.400 +
  19.401 +	virtual bool				ClampValue( float& value );
  19.402 +	virtual void				ChangeStringValue( const char *tempVal, float flOldValue );
  19.403 +
  19.404 +	virtual void				Create( const char *pName, const char *pDefaultValue, int flags = 0,
  19.405 +									const char *pHelpString = 0, bool bMin = false, float fMin = 0.0,
  19.406 +									bool bMax = false, float fMax = false, FnChangeCallback_t callback = 0 );
  19.407 +
  19.408 +	// Used internally by OneTimeInit to initialize.
  19.409 +	virtual void				Init();
  19.410 +
  19.411 +private:
  19.412 +
  19.413 +	// This either points to "this" or it points to the original declaration of a ConVar.
  19.414 +	// This allows ConVars to exist in separate modules, and they all use the first one to be declared.
  19.415 +	// m_pParent->m_pParent must equal m_pParent (ie: m_pParent must be the root, or original, ConVar).
  19.416 +	ConVar						*m_pParent;
  19.417 +
  19.418 +	// Static data
  19.419 +	const char					*m_pszDefaultValue;
  19.420 +	
  19.421 +	// Value
  19.422 +	// Dynamically allocated
  19.423 +	char						*m_pszString;
  19.424 +	int							m_StringLength;
  19.425 +
  19.426 +	// Values
  19.427 +	float						m_fValue;
  19.428 +	int							m_nValue;
  19.429 +
  19.430 +	// Min/Max values
  19.431 +	bool						m_bHasMin;
  19.432 +	float						m_fMinVal;
  19.433 +	bool						m_bHasMax;
  19.434 +	float						m_fMaxVal;
  19.435 +	
  19.436 +	// Call this function when ConVar changes
  19.437 +	FnChangeCallback_t			m_fnChangeCallback;
  19.438 +public: // Hackalicous
  19.439 +	inline FnChangeCallback_t GetCallback() const
  19.440 +	{
  19.441 +		return m_fnChangeCallback;
  19.442 +	}
  19.443 +	inline void SetMin(bool set, float min=0.0)
  19.444 +	{ 
  19.445 +		m_bHasMin = set; 
  19.446 +		m_fMinVal = min; 
  19.447 +	}
  19.448 +	inline void SetMax(bool set, float max=0.0)
  19.449 +	{
  19.450 +		m_bHasMax = set;
  19.451 +		m_fMaxVal = max; 
  19.452 +	}
  19.453 +};
  19.454 +
  19.455 +
  19.456 +//-----------------------------------------------------------------------------
  19.457 +// Purpose: Return ConVar value as a float
  19.458 +// Output : float
  19.459 +//-----------------------------------------------------------------------------
  19.460 +FORCEINLINE_CVAR float ConVar::GetFloat( void ) const
  19.461 +{
  19.462 +	return m_pParent->m_fValue;
  19.463 +}
  19.464 +
  19.465 +//-----------------------------------------------------------------------------
  19.466 +// Purpose: Return ConVar value as an int
  19.467 +// Output : int
  19.468 +//-----------------------------------------------------------------------------
  19.469 +FORCEINLINE_CVAR int ConVar::GetInt( void ) const 
  19.470 +{
  19.471 +	return m_pParent->m_nValue;
  19.472 +}
  19.473 +
  19.474 +
  19.475 +//-----------------------------------------------------------------------------
  19.476 +// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
  19.477 +// Output : const char *
  19.478 +//-----------------------------------------------------------------------------
  19.479 +FORCEINLINE_CVAR const char *ConVar::GetString( void ) const 
  19.480 +{
  19.481 +	if ( m_nFlags & FCVAR_NEVER_AS_STRING )
  19.482 +		return "FCVAR_NEVER_AS_STRING";
  19.483 +
  19.484 +	return ( m_pParent->m_pszString ) ? m_pParent->m_pszString : "";
  19.485 +}
  19.486 +
  19.487 +
  19.488 +//-----------------------------------------------------------------------------
  19.489 +// Used to read/write convars that already exist (replaces the FindVar method)
  19.490 +//-----------------------------------------------------------------------------
  19.491 +class ConVarRef
  19.492 +{
  19.493 +public:
  19.494 +	ConVarRef( const char *pName );
  19.495 +	ConVarRef( const char *pName, bool bIgnoreMissing );
  19.496 +	ConVarRef( IConVar *pConVar );
  19.497 +
  19.498 +	void Init( const char *pName, bool bIgnoreMissing );
  19.499 +	bool IsValid() const;
  19.500 +	bool IsFlagSet( int nFlags ) const;
  19.501 +	IConVar *GetLinkedConVar();
  19.502 +
  19.503 +	// Get/Set value
  19.504 +	float GetFloat( void ) const;
  19.505 +	int GetInt( void ) const;
  19.506 +	bool GetBool() const { return !!GetInt(); }
  19.507 +	const char *GetString( void ) const;
  19.508 +
  19.509 +	void SetValue( const char *pValue );
  19.510 +	void SetValue( float flValue );
  19.511 +	void SetValue( int nValue );
  19.512 +	void SetValue( bool bValue );
  19.513 +
  19.514 +	const char *GetName() const;
  19.515 +
  19.516 +	const char *GetDefault() const;
  19.517 +
  19.518 +private:
  19.519 +	// High-speed method to read convar data
  19.520 +	IConVar *m_pConVar;
  19.521 +	ConVar *m_pConVarState;
  19.522 +};
  19.523 +
  19.524 +
  19.525 +//-----------------------------------------------------------------------------
  19.526 +// Did we find an existing convar of that name?
  19.527 +//-----------------------------------------------------------------------------
  19.528 +FORCEINLINE_CVAR bool ConVarRef::IsFlagSet( int nFlags ) const
  19.529 +{
  19.530 +	return ( m_pConVar->IsFlagSet( nFlags ) != 0 );
  19.531 +}
  19.532 +
  19.533 +FORCEINLINE_CVAR IConVar *ConVarRef::GetLinkedConVar()
  19.534 +{
  19.535 +	return m_pConVar;
  19.536 +}
  19.537 +
  19.538 +FORCEINLINE_CVAR const char *ConVarRef::GetName() const
  19.539 +{
  19.540 +	return m_pConVar->GetName();
  19.541 +}
  19.542 +
  19.543 +
  19.544 +//-----------------------------------------------------------------------------
  19.545 +// Purpose: Return ConVar value as a float
  19.546 +//-----------------------------------------------------------------------------
  19.547 +FORCEINLINE_CVAR float ConVarRef::GetFloat( void ) const
  19.548 +{
  19.549 +	return m_pConVarState->m_fValue;
  19.550 +}
  19.551 +
  19.552 +//-----------------------------------------------------------------------------
  19.553 +// Purpose: Return ConVar value as an int
  19.554 +//-----------------------------------------------------------------------------
  19.555 +FORCEINLINE_CVAR int ConVarRef::GetInt( void ) const 
  19.556 +{
  19.557 +	return m_pConVarState->m_nValue;
  19.558 +}
  19.559 +
  19.560 +//-----------------------------------------------------------------------------
  19.561 +// Purpose: Return ConVar value as a string, return "" for bogus string pointer, etc.
  19.562 +//-----------------------------------------------------------------------------
  19.563 +FORCEINLINE_CVAR const char *ConVarRef::GetString( void ) const 
  19.564 +{
  19.565 +	Assert( !IsFlagSet( FCVAR_NEVER_AS_STRING ) );
  19.566 +	return m_pConVarState->m_pszString;
  19.567 +}
  19.568 +
  19.569 +
  19.570 +FORCEINLINE_CVAR void ConVarRef::SetValue( const char *pValue )
  19.571 +{
  19.572 +	m_pConVar->SetValue( pValue );
  19.573 +}
  19.574 +
  19.575 +FORCEINLINE_CVAR void ConVarRef::SetValue( float flValue )
  19.576 +{
  19.577 +	m_pConVar->SetValue( flValue );
  19.578 +}
  19.579 +
  19.580 +FORCEINLINE_CVAR void ConVarRef::SetValue( int nValue )
  19.581 +{
  19.582 +	m_pConVar->SetValue( nValue );
  19.583 +}
  19.584 +
  19.585 +FORCEINLINE_CVAR void ConVarRef::SetValue( bool bValue )
  19.586 +{
  19.587 +	m_pConVar->SetValue( bValue ? 1 : 0 );
  19.588 +}
  19.589 +
  19.590 +FORCEINLINE_CVAR const char *ConVarRef::GetDefault() const
  19.591 +{
  19.592 +	return m_pConVarState->m_pszDefaultValue;
  19.593 +}
  19.594 +
  19.595 +
  19.596 +//-----------------------------------------------------------------------------
  19.597 +// Called by the framework to register ConCommands with the ICVar
  19.598 +//-----------------------------------------------------------------------------
  19.599 +void ConVar_Register( int nCVarFlag = 0, IConCommandBaseAccessor *pAccessor = NULL );
  19.600 +void ConVar_Unregister( );
  19.601 +
  19.602 +
  19.603 +//-----------------------------------------------------------------------------
  19.604 +// Utility methods 
  19.605 +//-----------------------------------------------------------------------------
  19.606 +void ConVar_PrintFlags( const ConCommandBase *var );
  19.607 +void ConVar_PrintDescription( const ConCommandBase *pVar );
  19.608 +
  19.609 +
  19.610 +//-----------------------------------------------------------------------------
  19.611 +// Purpose: Utility class to quickly allow ConCommands to call member methods
  19.612 +//-----------------------------------------------------------------------------
  19.613 +#if defined _MSC_VER
  19.614 +#pragma warning (disable : 4355 )
  19.615 +#endif
  19.616 +
  19.617 +template< class T >
  19.618 +class CConCommandMemberAccessor : public ConCommand, public ICommandCallback, public ICommandCompletionCallback
  19.619 +{
  19.620 +	typedef ConCommand BaseClass;
  19.621 +	typedef void ( T::*FnMemberCommandCallback_t )( const CCommand &command );
  19.622 +	typedef int  ( T::*FnMemberCommandCompletionCallback_t )( const char *pPartial, CUtlVector< CUtlString > &commands );
  19.623 +
  19.624 +public:
  19.625 +	CConCommandMemberAccessor( T* pOwner, const char *pName, FnMemberCommandCallback_t callback, const char *pHelpString = 0,
  19.626 +		int flags = 0, FnMemberCommandCompletionCallback_t completionFunc = 0 ) :
  19.627 +		BaseClass( pName, this, pHelpString, flags, ( completionFunc != 0 ) ? this : NULL )
  19.628 +	{
  19.629 +		m_pOwner = pOwner;
  19.630 +		m_Func = callback;
  19.631 +		m_CompletionFunc = completionFunc;
  19.632 +	}
  19.633 +
  19.634 +	~CConCommandMemberAccessor()
  19.635 +	{
  19.636 +		Shutdown();
  19.637 +	}
  19.638 +
  19.639 +	void SetOwner( T* pOwner )
  19.640 +	{
  19.641 +		m_pOwner = pOwner;
  19.642 +	}
  19.643 +
  19.644 +	virtual void CommandCallback( const CCommand &command )
  19.645 +	{
  19.646 +		Assert( m_pOwner && m_Func );
  19.647 +		(m_pOwner->*m_Func)( command );
  19.648 +	}
  19.649 +
  19.650 +	virtual int  CommandCompletionCallback( const char *pPartial, CUtlVector< CUtlString > &commands )
  19.651 +	{
  19.652 +		Assert( m_pOwner && m_CompletionFunc );
  19.653 +		return (m_pOwner->*m_CompletionFunc)( pPartial, commands );
  19.654 +	}
  19.655 +
  19.656 +private:
  19.657 +	T* m_pOwner;
  19.658 +	FnMemberCommandCallback_t m_Func;
  19.659 +	FnMemberCommandCompletionCallback_t m_CompletionFunc;
  19.660 +};
  19.661 +
  19.662 +#if defined _MSC_VER
  19.663 +#pragma warning ( default : 4355 )
  19.664 +#endif
  19.665 +
  19.666 +
  19.667 +//-----------------------------------------------------------------------------
  19.668 +// Purpose: Utility macros to quicky generate a simple console command
  19.669 +//-----------------------------------------------------------------------------
  19.670 +#define CON_COMMAND( name, description ) \
  19.671 +   static void name( const CCommand &args ); \
  19.672 +   static ConCommand name##_command( #name, name, description ); \
  19.673 +   static void name( const CCommand &args )
  19.674 +
  19.675 +#define CON_COMMAND_F( name, description, flags ) \
  19.676 +   static void name( const CCommand &args ); \
  19.677 +   static ConCommand name##_command( #name, name, description, flags ); \
  19.678 +   static void name( const CCommand &args )
  19.679 +
  19.680 +#define CON_COMMAND_F_COMPLETION( name, description, flags, completion ) \
  19.681 +	static void name( const CCommand &args ); \
  19.682 +	static ConCommand name##_command( #name, name, description, flags, completion ); \
  19.683 +	static void name( const CCommand &args )
  19.684 +
  19.685 +#define CON_COMMAND_EXTERN( name, _funcname, description ) \
  19.686 +	void _funcname( const CCommand &args ); \
  19.687 +	static ConCommand name##_command( #name, _funcname, description ); \
  19.688 +	void _funcname( const CCommand &args )
  19.689 +
  19.690 +#define CON_COMMAND_EXTERN_F( name, _funcname, description, flags ) \
  19.691 +	void _funcname( const CCommand &args ); \
  19.692 +	static ConCommand name##_command( #name, _funcname, description, flags ); \
  19.693 +	void _funcname( const CCommand &args )
  19.694 +
  19.695 +#define CON_COMMAND_MEMBER_F( _thisclass, name, _funcname, description, flags ) \
  19.696 +	void _funcname( const CCommand &args );						\
  19.697 +	friend class CCommandMemberInitializer_##_funcname;			\
  19.698 +	class CCommandMemberInitializer_##_funcname					\
  19.699 +	{															\
  19.700 +	public:														\
  19.701 +		CCommandMemberInitializer_##_funcname() : m_ConCommandAccessor( NULL, name, &_thisclass::_funcname, description, flags )	\
  19.702 +		{														\
  19.703 +			m_ConCommandAccessor.SetOwner( GET_OUTER( _thisclass, m_##_funcname##_register ) );	\
  19.704 +		}														\
  19.705 +	private:													\
  19.706 +		CConCommandMemberAccessor< _thisclass > m_ConCommandAccessor;	\
  19.707 +	};															\
  19.708 +																\
  19.709 +	CCommandMemberInitializer_##_funcname m_##_funcname##_register;		\
  19.710 +
  19.711 +
  19.712 +#endif // CONVAR_H
    20.1 --- a/core/msvc8/sourcemod_mm.sln	Sat Oct 13 22:13:43 2007 +0000
    20.2 +++ b/core/msvc8/sourcemod_mm.sln	Sun Oct 14 00:04:21 2007 +0000
    20.3 @@ -6,14 +6,20 @@
    20.4  Global
    20.5  	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    20.6  		CrazyDebug|Win32 = CrazyDebug|Win32
    20.7 +		Debug - Orange Box|Win32 = Debug - Orange Box|Win32
    20.8  		Debug|Win32 = Debug|Win32
    20.9 +		Release - Orange Box|Win32 = Release - Orange Box|Win32
   20.10  		Release|Win32 = Release|Win32
   20.11  	EndGlobalSection
   20.12  	GlobalSection(ProjectConfigurationPlatforms) = postSolution
   20.13  		{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.CrazyDebug|Win32.ActiveCfg = CrazyDebug|Win32
   20.14  		{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.CrazyDebug|Win32.Build.0 = CrazyDebug|Win32
   20.15 +		{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Debug - Orange Box|Win32.ActiveCfg = Debug - Orange Box|Win32
   20.16 +		{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Debug - Orange Box|Win32.Build.0 = Debug - Orange Box|Win32
   20.17  		{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Debug|Win32.ActiveCfg = Debug|Win32
   20.18  		{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Debug|Win32.Build.0 = Debug|Win32
   20.19 +		{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Release - Orange Box|Win32.ActiveCfg = Release - Orange Box|Win32
   20.20 +		{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Release - Orange Box|Win32.Build.0 = Release - Orange Box|Win32
   20.21  		{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Release|Win32.ActiveCfg = Release|Win32
   20.22  		{E39527CD-7CAB-4420-97CC-DA1B93B260BC}.Release|Win32.Build.0 = Release|Win32
   20.23  	EndGlobalSection
    21.1 --- a/core/msvc8/sourcemod_mm.vcproj	Sat Oct 13 22:13:43 2007 +0000
    21.2 +++ b/core/msvc8/sourcemod_mm.vcproj	Sun Oct 14 00:04:21 2007 +0000
    21.3 @@ -1,7 +1,7 @@
    21.4  <?xml version="1.0" encoding="Windows-1252"?>
    21.5  <VisualStudioProject
    21.6  	ProjectType="Visual C++"
    21.7 -	Version="8.00"
    21.8 +	Version="8,00"
    21.9  	Name="sourcemod_mm"
   21.10  	ProjectGUID="{E39527CD-7CAB-4420-97CC-DA1B93B260BC}"
   21.11  	RootNamespace="sourcemod_mm"
   21.12 @@ -254,6 +254,166 @@
   21.13  				Name="VCPostBuildEventTool"
   21.14  			/>
   21.15  		</Configuration>
   21.16 +		<Configuration
   21.17 +			Name="Release - Orange Box|Win32"
   21.18 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
   21.19 +			IntermediateDirectory="$(ConfigurationName)"
   21.20 +			ConfigurationType="2"
   21.21 +			CharacterSet="2"
   21.22 +			WholeProgramOptimization="1"
   21.23 +			>
   21.24 +			<Tool
   21.25 +				Name="VCPreBuildEventTool"
   21.26 +			/>
   21.27 +			<Tool
   21.28 +				Name="VCCustomBuildTool"
   21.29 +			/>
   21.30 +			<Tool
   21.31 +				Name="VCXMLDataGeneratorTool"
   21.32 +			/>
   21.33 +			<Tool
   21.34 +				Name="VCWebServiceProxyGeneratorTool"
   21.35 +			/>
   21.36 +			<Tool
   21.37 +				Name="VCMIDLTool"
   21.38 +			/>
   21.39 +			<Tool
   21.40 +				Name="VCCLCompilerTool"
   21.41 +				FavorSizeOrSpeed="1"
   21.42 +				AdditionalIncludeDirectories="..\;..\systems;..\..\public;..\..\public\sourcepawn"
   21.43 +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;SM_DEFAULT_THREADER;ORANGEBOX_BUILD"
   21.44 +				RuntimeLibrary="0"
   21.45 +				EnableEnhancedInstructionSet="1"
   21.46 +				RuntimeTypeInfo="false"
   21.47 +				UsePrecompiledHeader="0"
   21.48 +				WarningLevel="3"
   21.49 +				Detect64BitPortabilityProblems="false"
   21.50 +				DebugInformationFormat="3"
   21.51 +			/>
   21.52 +			<Tool
   21.53 +				Name="VCManagedResourceCompilerTool"
   21.54 +			/>
   21.55 +			<Tool
   21.56 +				Name="VCResourceCompilerTool"
   21.57 +			/>
   21.58 +			<Tool
   21.59 +				Name="VCPreLinkEventTool"
   21.60 +			/>
   21.61 +			<Tool
   21.62 +				Name="VCLinkerTool"
   21.63 +				AdditionalDependencies="tier0.lib tier1.lib vstdlib.lib mathlib.lib"
   21.64 +				LinkIncremental="1"
   21.65 +				GenerateDebugInformation="true"
   21.66 +				SubSystem="2"
   21.67 +				OptimizeReferences="2"
   21.68 +				EnableCOMDATFolding="2"
   21.69 +				TargetMachine="1"
   21.70 +			/>
   21.71 +			<Tool
   21.72 +				Name="VCALinkTool"
   21.73 +			/>
   21.74 +			<Tool
   21.75 +				Name="VCManifestTool"
   21.76 +			/>
   21.77 +			<Tool
   21.78 +				Name="VCXDCMakeTool"
   21.79 +			/>
   21.80 +			<Tool
   21.81 +				Name="VCBscMakeTool"
   21.82 +			/>
   21.83 +			<Tool
   21.84 +				Name="VCFxCopTool"
   21.85 +			/>
   21.86 +			<Tool
   21.87 +				Name="VCAppVerifierTool"
   21.88 +			/>
   21.89 +			<Tool
   21.90 +				Name="VCWebDeploymentTool"
   21.91 +			/>
   21.92 +			<Tool
   21.93 +				Name="VCPostBuildEventTool"
   21.94 +			/>
   21.95 +		</Configuration>
   21.96 +		<Configuration
   21.97 +			Name="Debug - Orange Box|Win32"
   21.98 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
   21.99 +			IntermediateDirectory="$(ConfigurationName)"
  21.100 +			ConfigurationType="2"
  21.101 +			CharacterSet="2"
  21.102 +			>
  21.103 +			<Tool
  21.104 +				Name="VCPreBuildEventTool"
  21.105 +			/>
  21.106 +			<Tool
  21.107 +				Name="VCCustomBuildTool"
  21.108 +			/>
  21.109 +			<Tool
  21.110 +				Name="VCXMLDataGeneratorTool"
  21.111 +			/>
  21.112 +			<Tool
  21.113 +				Name="VCWebServiceProxyGeneratorTool"
  21.114 +			/>
  21.115 +			<Tool
  21.116 +				Name="VCMIDLTool"
  21.117 +			/>
  21.118 +			<Tool
  21.119 +				Name="VCCLCompilerTool"
  21.120 +				Optimization="0"
  21.121 +				AdditionalIncludeDirectories="..\;..\systems;..\..\public;..\..\public\sourcepawn"
  21.122 +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;SM_DEFAULT_THREADER;ORANGEBOX_BUILD"
  21.123 +				MinimalRebuild="true"
  21.124 +				BasicRuntimeChecks="3"
  21.125 +				RuntimeLibrary="1"
  21.126 +				EnableEnhancedInstructionSet="1"
  21.127 +				RuntimeTypeInfo="false"
  21.128 +				UsePrecompiledHeader="0"
  21.129 +				WarningLevel="3"
  21.130 +				Detect64BitPortabilityProblems="false"
  21.131 +				DebugInformationFormat="4"
  21.132 +			/>
  21.133 +			<Tool
  21.134 +				Name="VCManagedResourceCompilerTool"
  21.135 +			/>
  21.136 +			<Tool
  21.137 +				Name="VCResourceCompilerTool"
  21.138 +			/>
  21.139 +			<Tool
  21.140 +				Name="VCPreLinkEventTool"
  21.141 +			/>
  21.142 +			<Tool
  21.143 +				Name="VCLinkerTool"
  21.144 +				AdditionalDependencies="tier0.lib tier1.lib vstdlib.lib mathlib.lib"
  21.145 +				LinkIncremental="2"
  21.146 +				IgnoreDefaultLibraryNames="LIBCMT"
  21.147 +				GenerateDebugInformation="true"
  21.148 +				SubSystem="2"
  21.149 +				TargetMachine="1"
  21.150 +			/>
  21.151 +			<Tool
  21.152 +				Name="VCALinkTool"
  21.153 +			/>
  21.154 +			<Tool
  21.155 +				Name="VCManifestTool"
  21.156 +			/>
  21.157 +			<Tool
  21.158 +				Name="VCXDCMakeTool"
  21.159 +			/>
  21.160 +			<Tool
  21.161 +				Name="VCBscMakeTool"
  21.162 +			/>
  21.163 +			<Tool
  21.164 +				Name="VCFxCopTool"
  21.165 +			/>
  21.166 +			<Tool
  21.167 +				Name="VCAppVerifierTool"
  21.168 +			/>
  21.169 +			<Tool
  21.170 +				Name="VCWebDeploymentTool"
  21.171 +			/>
  21.172 +			<Tool
  21.173 +				Name="VCPostBuildEventTool"
  21.174 +			/>
  21.175 +		</Configuration>
  21.176  	</Configurations>
  21.177  	<References>
  21.178  	</References>
  21.179 @@ -272,6 +432,10 @@
  21.180  				>
  21.181  			</File>
  21.182  			<File
  21.183 +				RelativePath="..\bitbuf.cpp"
  21.184 +				>
  21.185 +			</File>
  21.186 +			<File
  21.187  				RelativePath="..\CDataPack.cpp"
  21.188  				>
  21.189  			</File>
  21.190 @@ -316,6 +480,15 @@
  21.191  						AssemblerOutput="0"
  21.192  					/>
  21.193  				</FileConfiguration>
  21.194 +				<FileConfiguration
  21.195 +					Name="Release - Orange Box|Win32"
  21.196 +					>
  21.197 +					<Tool
  21.198 +						Name="VCCLCompilerTool"
  21.199 +						ExpandAttributedSource="true"
  21.200 +						AssemblerOutput="4"
  21.201 +					/>
  21.202 +				</FileConfiguration>
  21.203  			</File>
  21.204  			<File
  21.205  				RelativePath="..\DebugReporter.cpp"
    22.1 --- a/core/sm_srvcmds.cpp	Sat Oct 13 22:13:43 2007 +0000
    22.2 +++ b/core/sm_srvcmds.cpp	Sun Oct 14 00:04:21 2007 +0000
    22.3 @@ -57,11 +57,18 @@
    22.4  	m_Menu.clear();
    22.5  }
    22.6  
    22.7 -extern void _IntExt_OnHostnameChanged(ConVar *pConVar, char const *oldValue);
    22.8 +#if defined ORANGEBOX_BUILD
    22.9 +	extern void _IntExt_OnHostnameChanged(IConVar *var, const char *pOldValue, float flOldValue);
   22.10 +#else
   22.11 +	extern void _IntExt_OnHostnameChanged(ConVar *pConVar, char const *oldValue);
   22.12 +#endif
   22.13  
   22.14  void RootConsoleMenu::OnSourceModStartup(bool late)
   22.15  {
   22.16 -	ConCommandBaseMgr::OneTimeInit(this);
   22.17 +#if defined ORANGEBOX_BUILD
   22.18 +	ICvar *g_pCVar = icvar;
   22.19 +#endif
   22.20 +	CONVAR_REGISTER(this);
   22.21  	AddRootConsoleCommand("version", "Display version information", this);
   22.22  	AddRootConsoleCommand("credits", "Display credits listing", this);
   22.23  
   22.24 @@ -201,28 +208,28 @@
   22.25  
   22.26  extern void _IntExt_EnableYams();
   22.27  
   22.28 -void RootConsoleMenu::GotRootCmd()
   22.29 +void RootConsoleMenu::GotRootCmd(const CCommand &cmd)
   22.30  {
   22.31 -	unsigned int argnum = GetArgumentCount();
   22.32 +	unsigned int argnum = cmd.ArgC();
   22.33  
   22.34  	if (argnum >= 2)
   22.35  	{
   22.36 -		const char *cmd = GetArgument(1);
   22.37 -		if (strcmp(cmd, "text") == 0)
   22.38 +		const char *cmdname = cmd.Arg(1);
   22.39 +		if (strcmp(cmdname, "text") == 0)
   22.40  		{
   22.41  			_IntExt_EnableYams();
   22.42  			return;
   22.43 -		} else if (strcmp(cmd, "internal") == 0) {
   22.44 +		} else if (strcmp(cmdname, "internal") == 0) {
   22.45  			if (argnum >= 3)
   22.46  			{
   22.47 -				const char *arg = GetArgument(2);
   22.48 +				const char *arg = cmd.Arg(2);
   22.49  				if (strcmp(arg, "1") == 0)
   22.50  				{
   22.51  					SM_ConfigsExecuted_Global();
   22.52  				} else if (strcmp(arg, "2") == 0) {
   22.53  					if (argnum >= 4)
   22.54  					{
   22.55 -						SM_ConfigsExecuted_Plugin(atoi(GetArgument(3)));
   22.56 +						SM_ConfigsExecuted_Plugin(atoi(cmd.Arg(3)));
   22.57  					}
   22.58  				}
   22.59  			}
   22.60 @@ -230,9 +237,9 @@
   22.61  		}
   22.62  
   22.63  		IRootConsoleCommand *pHandler;
   22.64 -		if (sm_trie_retrieve(m_pCommands, cmd, (void **)&pHandler))
   22.65 +		if (sm_trie_retrieve(m_pCommands, cmdname, (void **)&pHandler))
   22.66  		{
   22.67 -			pHandler->OnRootConsoleCommand(cmd, argnum);
   22.68 +			pHandler->OnRootConsoleCommand(cmdname, cmd);
   22.69  			return;
   22.70  		}
   22.71  	}
   22.72 @@ -249,24 +256,9 @@
   22.73  	}
   22.74  }
   22.75  
   22.76 -const char *RootConsoleMenu::GetArgument(unsigned int argno)
   22.77 -{
   22.78 -	return engine->Cmd_Argv(argno);
   22.79 -}
   22.80 -
   22.81 -const char *RootConsoleMenu::GetArguments()
   22.82 +void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
   22.83  {
   22.84 -	return engine->Cmd_Args();
   22.85 -}
   22.86 -
   22.87 -unsigned int RootConsoleMenu::GetArgumentCount()
   22.88 -{
   22.89 -	return engine->Cmd_Argc();
   22.90 -}
   22.91 -
   22.92 -void RootConsoleMenu::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
   22.93 -{
   22.94 -	if (strcmp(cmd, "credits") == 0)
   22.95 +	if (strcmp(cmdname, "credits") == 0)
   22.96  	{
   22.97  		ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
   22.98  		ConsolePrint(" Development would not have been possible without the following people:");
   22.99 @@ -277,7 +269,7 @@
  22.100  		ConsolePrint(" Special thanks to Viper of GameConnect");
  22.101  		ConsolePrint(" Special thanks to Mani of Mani-Admin-Plugin");
  22.102  		ConsolePrint(" http://www.sourcemod.net/");
  22.103 -	} else if (strcmp(cmd, "version") == 0) {
  22.104 +	} else if (strcmp(cmdname, "version") == 0) {
  22.105  		ConsolePrint(" SourceMod Version Information:");
  22.106  		ConsolePrint("    SourceMod Version: %s", SVN_FULL_VERSION);
  22.107  		ConsolePrint("    JIT Version: %s, %s", g_pVM->GetVMName(), g_pVM->GetVersionString());
  22.108 @@ -288,18 +280,24 @@
  22.109  
  22.110  CON_COMMAND(sm, "SourceMod Menu")
  22.111  {
  22.112 -	g_RootMenu.GotRootCmd();
  22.113 +#if !defined ORANGEBOX_BUILD
  22.114 +	CCommand args;
  22.115 +#endif
  22.116 +	g_RootMenu.GotRootCmd(args);
  22.117  }
  22.118  
  22.119  CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle leaks")
  22.120  {
  22.121 -	if (engine->Cmd_Argc() < 2)
  22.122 +#if !defined ORANGEBOX_BUILD
  22.123 +	CCommand args;
  22.124 +#endif
  22.125 +	if (args.ArgC() < 2)
  22.126  	{
  22.127  		g_RootMenu.ConsolePrint("Usage: sm_dump_handles <file>");
  22.128  		return;
  22.129  	}
  22.130  
  22.131 -	const char *arg = engine->Cmd_Argv(1);
  22.132 +	const char *arg = args.Arg(1);
  22.133  	FILE *fp = fopen(arg, "wt");
  22.134  	if (!fp)
  22.135  	{
    23.1 --- a/core/sm_srvcmds.h	Sat Oct 13 22:13:43 2007 +0000
    23.2 +++ b/core/sm_srvcmds.h	Sun Oct 14 00:04:21 2007 +0000
    23.3 @@ -64,17 +64,14 @@
    23.4  	void OnSourceModStartup(bool late);
    23.5  	void OnSourceModShutdown();
    23.6  public: //IRootConsoleCommand
    23.7 -	void OnRootConsoleCommand(const char *cmd, unsigned int argcount);
    23.8 +	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
    23.9  public: //IRootConsole
   23.10  	bool AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler);
   23.11  	bool RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler);
   23.12  	void ConsolePrint(const char *fmt, ...);
   23.13 -	const char *GetArgument(unsigned int argno);
   23.14 -	unsigned int GetArgumentCount();
   23.15 -	const char *GetArguments();
   23.16  	void DrawGenericOption(const char *cmd, const char *text);
   23.17  public:
   23.18 -	void GotRootCmd();
   23.19 +	void GotRootCmd(const CCommand &cmd);
   23.20  private:
   23.21  	bool m_CfgExecDone;
   23.22  	Trie *m_pCommands;
    24.1 --- a/core/smn_console.cpp	Sat Oct 13 22:13:43 2007 +0000
    24.2 +++ b/core/smn_console.cpp	Sun Oct 14 00:04:21 2007 +0000
    24.3 @@ -107,7 +107,7 @@
    24.4  {
    24.5  	IGameEvent *pEvent = gameevents->CreateEvent("server_cvar");
    24.6  	pEvent->SetString("cvarname", pConVar->GetName());
    24.7 -	if (pConVar->IsBitSet(FCVAR_PROTECTED))
    24.8 +	if (IsFlagSet(pConVar, FCVAR_PROTECTED))
    24.9  	{
   24.10  		pEvent->SetString("cvarvalue", "***PROTECTED***");
   24.11  	} else {
   24.12 @@ -250,13 +250,13 @@
   24.13  	pConVar->SetValue(params[2]);
   24.14  
   24.15  	/* Should we replicate it? */
   24.16 -	if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED))
   24.17 +	if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
   24.18  	{
   24.19  		ReplicateConVar(pConVar);
   24.20  	}
   24.21  
   24.22  	/* Should we notify clients? */
   24.23 -	if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY))
   24.24 +	if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
   24.25  	{
   24.26  		NotifyConVar(pConVar);
   24.27  	}
   24.28 @@ -297,13 +297,13 @@
   24.29  	pConVar->SetValue(value);
   24.30  
   24.31  	/* Should we replicate it? */
   24.32 -	if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED))
   24.33 +	if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
   24.34  	{
   24.35  		ReplicateConVar(pConVar);
   24.36  	}
   24.37  
   24.38  	/* Should we notify clients? */
   24.39 -	if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY))
   24.40 +	if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
   24.41  	{
   24.42  		NotifyConVar(pConVar);
   24.43  	}
   24.44 @@ -346,13 +346,13 @@
   24.45  	pConVar->SetValue(value);
   24.46  
   24.47  	/* Should we replicate it? */
   24.48 -	if (params[3] && pConVar->IsBitSet(FCVAR_REPLICATED))
   24.49 +	if (params[3] && IsFlagSet(pConVar, FCVAR_REPLICATED))
   24.50  	{
   24.51  		ReplicateConVar(pConVar);
   24.52  	}
   24.53  
   24.54  	/* Should we notify clients? */
   24.55 -	if (params[4] && pConVar->IsBitSet(FCVAR_NOTIFY))
   24.56 +	if (params[4] && IsFlagSet(pConVar, FCVAR_NOTIFY))
   24.57  	{
   24.58  		NotifyConVar(pConVar);
   24.59  	}
   24.60 @@ -375,13 +375,13 @@
   24.61  	pConVar->Revert();
   24.62  	
   24.63  	/* Should we replicate it? */
   24.64 -	if (params[2] && pConVar->IsBitSet(FCVAR_REPLICATED))
   24.65 +	if (params[2] && IsFlagSet(pConVar, FCVAR_REPLICATED))
   24.66  	{
   24.67  		ReplicateConVar(pConVar);
   24.68  	}
   24.69  
   24.70  	/* Should we notify clients? */
   24.71 -	if (params[3] && pConVar->IsBitSet(FCVAR_NOTIFY))
   24.72 +	if (params[3] && IsFlagSet(pConVar, FCVAR_NOTIFY))
   24.73  	{
   24.74  		NotifyConVar(pConVar);
   24.75  	}
   24.76 @@ -625,22 +625,22 @@
   24.77  
   24.78  static cell_t sm_GetCmdArgs(IPluginContext *pContext, const cell_t *params)
   24.79  {
   24.80 -	return engine->Cmd_Argc() - 1;
   24.81 +	return 4 :O;//engine->Cmd_Argc() - 1;
   24.82  }
   24.83  
   24.84  static cell_t sm_GetCmdArg(IPluginContext *pContext, const cell_t *params)
   24.85  {
   24.86 -	const char *arg = engine->Cmd_Argv(params[1]);
   24.87 +	//const char *arg = //engine->Cmd_Argv(params[1]);
   24.88  	size_t length;
   24.89  	
   24.90 -	pContext->StringToLocalUTF8(params[2], params[3], arg, &length);
   24.91 +	//pContext->StringToLocalUTF8(params[2], params[3], arg, &length);
   24.92  
   24.93  	return (cell_t)length;
   24.94  }
   24.95  
   24.96  static cell_t sm_GetCmdArgString(IPluginContext *pContext, const cell_t *params)
   24.97  {
   24.98 -	const char *args = engine->Cmd_Args();
   24.99 +	const char *args = NULL;//engine->Cmd_Args();
  24.100  	size_t length;
  24.101  
  24.102  	if (!args)
  24.103 @@ -751,7 +751,7 @@
  24.104  	buffer[len++] = '\n';
  24.105  	buffer[len] = '\0';
  24.106  
  24.107 -	engine->InsertServerCommand(buffer);
  24.108 +	InsertServerCommand(buffer);
  24.109  
  24.110  	return 1;
  24.111  }
    25.1 --- a/core/smn_usermsgs.cpp	Sat Oct 13 22:13:43 2007 +0000
    25.2 +++ b/core/smn_usermsgs.cpp	Sun Oct 14 00:04:21 2007 +0000
    25.3 @@ -60,7 +60,7 @@
    25.4  	void OnPluginUnloaded(IPlugin *plugin);
    25.5  public:
    25.6  	MsgListenerWrapper *CreateListener(IPluginContext *pCtx);
    25.7 -	MsgWrapperIter FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept);
    25.8 +	bool FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept, MsgWrapperIter *iter);
    25.9  	bool DeleteListener(IPluginContext *pCtx, MsgWrapperIter iter);
   25.10  private:
   25.11  	CStack<MsgListenerWrapper *> m_FreeListeners;
   25.12 @@ -156,30 +156,31 @@
   25.13  	return pListener;
   25.14  }
   25.15  
   25.16 -MsgWrapperIter UsrMessageNatives::FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept)
   25.17 +bool UsrMessageNatives::FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept, MsgWrapperIter *iter)
   25.18  {
   25.19  	MsgWrapperList *pList;
   25.20 -	MsgWrapperIter iter;
   25.21 +	MsgWrapperIter _iter;
   25.22  	MsgListenerWrapper *pListener;
   25.23  	IPlugin *pl = g_PluginSys.FindPluginByContext(pCtx->GetContext());
   25.24  
   25.25  	if (!pl->GetProperty("MsgListeners", reinterpret_cast<void **>(&pList)))
   25.26  	{
   25.27 -		return NULL;
   25.28 +		return false;
   25.29  	}
   25.30  
   25.31 -	for (iter=pList->begin(); iter!=pList->end(); iter++)
   25.32 +	for (_iter=pList->begin(); _iter!=pList->end(); _iter++)
   25.33  	{
   25.34 -		pListener = (*iter);
   25.35 +		pListener = (*_iter);
   25.36  		if ((msgid == pListener->GetMessageId()) 
   25.37  			&& (intercept == pListener->IsInterceptHook()) 
   25.38  			&& (pHook == pListener->GetHookedFunction()))
   25.39  		{
   25.40 -			return iter;
   25.41 +			*iter = _iter;
   25.42 +			return true;
   25.43  		}
   25.44  	}
   25.45  
   25.46 -	return NULL;
   25.47 +	return false;
   25.48  }
   25.49  
   25.50  bool UsrMessageNatives::DeleteListener(IPluginContext *pCtx, MsgWrapperIter iter)
   25.51 @@ -467,8 +468,7 @@
   25.52  	}
   25.53  	intercept = (params[3]) ? true : false;
   25.54  
   25.55 -	iter = s_UsrMessageNatives.FindListener(msgid, pCtx, pFunc, intercept);
   25.56 -	if (iter == NULL)
   25.57 +	if (!s_UsrMessageNatives.FindListener(msgid, pCtx, pFunc, intercept, &iter))
   25.58  	{
   25.59  		return pCtx->ThrowNativeError("Unable to unhook the current user message");
   25.60  	}
    26.1 --- a/core/smn_vector.cpp	Sat Oct 13 22:13:43 2007 +0000
    26.2 +++ b/core/smn_vector.cpp	Sun Oct 14 00:04:21 2007 +0000
    26.3 @@ -31,7 +31,7 @@
    26.4  
    26.5  #include "sm_globals.h"
    26.6  #include <vector.h>
    26.7 -#include <mathlib.h>
    26.8 +#include <mathlib/math_base.h>
    26.9  
   26.10  #define SET_VECTOR(addr, vec) \
   26.11  	addr[0] = sp_ftoc(vec.x); \
   26.12 @@ -181,6 +181,16 @@
   26.13  	return sp_ftoc(length);
   26.14  }
   26.15  
   26.16 +//:TODO: OMG remove this when we get the OB SDK!!1
   26.17 +// as well as bitbuf.cpp (i write it here just to remind it)
   26.18 +#if defined ORANGEBOX_BUILD
   26.19 +float ham(float _X)
   26.20 +{
   26.21 +	return sqrt(_X); 
   26.22 +}
   26.23 +float (*pfSqrt)(float x)  = ham;
   26.24 +#endif
   26.25 +
   26.26  REGISTER_NATIVES(vectorNatives)
   26.27  {
   26.28  	{"GetAngleVectors",			GetAngleVectors},
    27.1 --- a/core/sourcemm_api.cpp	Sat Oct 13 22:13:43 2007 +0000
    27.2 +++ b/core/sourcemm_api.cpp	Sun Oct 14 00:04:21 2007 +0000
    27.3 @@ -29,10 +29,9 @@
    27.4   * Version: $Id$
    27.5   */
    27.6  
    27.7 -#include <oslink.h>
    27.8 +#include "sourcemod.h"
    27.9  #include "sourcemm_api.h"
   27.10  #include "sm_version.h"
   27.11 -#include "sourcemod.h"
   27.12  #include "Logger.h"
   27.13  #include "ConVarManager.h"
   27.14  
   27.15 @@ -58,18 +57,18 @@
   27.16  {
   27.17  	PLUGIN_SAVEVARS();
   27.18  
   27.19 -	GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
   27.20 -	GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
   27.21 -	GET_V_IFACE_CURRENT(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
   27.22 -	GET_V_IFACE_CURRENT(engineFactory, icvar, ICvar, VENGINE_CVAR_INTERFACE_VERSION);
   27.23 -	GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
   27.24 -	GET_V_IFACE_CURRENT(engineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
   27.25 -	GET_V_IFACE_CURRENT(fileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
   27.26 -	GET_V_IFACE_CURRENT(engineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
   27.27 -	GET_V_IFACE_CURRENT(engineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
   27.28 +	GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
   27.29 +	GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
   27.30 +	GET_V_IFACE_CURRENT(GetServerFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
   27.31 +	GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
   27.32 +	GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
   27.33 +	GET_V_IFACE_CURRENT(GetEngineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
   27.34 +	GET_V_IFACE_CURRENT(GetFileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
   27.35 +	GET_V_IFACE_CURRENT(GetEngineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
   27.36 +	GET_V_IFACE_CURRENT(GetEngineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
   27.37  
   27.38  	/* :TODO: Make this optional and... make it find earlier versions [?] */
   27.39 -	GET_V_IFACE_CURRENT(serverFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
   27.40 +	GET_V_IFACE_CURRENT(GetServerFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
   27.41  
   27.42  	if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
   27.43  	{
   27.44 @@ -80,7 +79,7 @@
   27.45  		return false;
   27.46  	}
   27.47  
   27.48 -	gpGlobals = ismm->pGlobals();
   27.49 +	gpGlobals = ismm->GetCGlobals();
   27.50  	
   27.51  	ismm->AddListener(this, this);
   27.52  	ismm->EnableVSPListener();
    28.1 --- a/core/sourcemm_api.h	Sat Oct 13 22:13:43 2007 +0000
    28.2 +++ b/core/sourcemm_api.h	Sun Oct 14 00:04:21 2007 +0000
    28.3 @@ -32,7 +32,11 @@
    28.4  #ifndef _INCLUDE_SOURCEMOD_MM_API_H_
    28.5  #define _INCLUDE_SOURCEMOD_MM_API_H_
    28.6  
    28.7 -#include "convar_sm.h"
    28.8 +#if defined ORANGEBOX_BUILD
    28.9 +	#include "convar_sm_ob.h"
   28.10 +#else
   28.11 +	#include "convar_sm.h"
   28.12 +#endif
   28.13  #include <ISmmPlugin.h>
   28.14  #include <eiface.h>
   28.15  #include <igameevents.h>
   28.16 @@ -41,6 +45,10 @@
   28.17  #include <filesystem.h>
   28.18  #include <IEngineSound.h>
   28.19  
   28.20 +#ifndef METAMOD_PLAPI_VERSION
   28.21 +	#include <metamod_wrappers.h>
   28.22 +#endif
   28.23 +
   28.24  /**
   28.25   * @file Contains wrappers around required Metamod:Source API exports
   28.26   */
    29.1 --- a/core/systems/ExtensionSys.cpp	Sat Oct 13 22:13:43 2007 +0000
    29.2 +++ b/core/systems/ExtensionSys.cpp	Sun Oct 14 00:04:21 2007 +0000
    29.3 @@ -813,11 +813,12 @@
    29.4  	}
    29.5  }
    29.6  
    29.7 -void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
    29.8 +void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
    29.9  {
   29.10 +	int argcount = command.ArgC();
   29.11  	if (argcount >= 3)
   29.12  	{
   29.13 -		const char *cmd = g_RootMenu.GetArgument(2);
   29.14 +		const char *cmd = command.Arg(2);
   29.15  		if (strcmp(cmd, "list") == 0)
   29.16  		{
   29.17  			List<CExtension *>::iterator iter;
   29.18 @@ -869,7 +870,7 @@
   29.19  				return;
   29.20  			}
   29.21  
   29.22 -			const char *sId = g_RootMenu.GetArgument(3);
   29.23 +			const char *sId = command.Arg(3);
   29.24  			unsigned int id = atoi(sId);
   29.25  			if (id <= 0)
   29.26  			{
   29.27 @@ -936,7 +937,7 @@
   29.28  				return;
   29.29  			}
   29.30  
   29.31 -			const char *arg = g_RootMenu.GetArgument(3);
   29.32 +			const char *arg = command.Arg(3);
   29.33  			unsigned int num = atoi(arg);
   29.34  			CExtension *pExt = FindByOrder(num);
   29.35  
   29.36 @@ -948,7 +949,7 @@
   29.37  
   29.38  			if (argcount > 4 && pExt->unload_code)
   29.39  			{
   29.40 -				const char *unload = g_RootMenu.GetArgument(4);
   29.41 +				const char *unload = command.Arg(4);
   29.42  				if (pExt->unload_code == (unsigned)atoi(unload))
   29.43  				{
   29.44  					char filename[PLATFORM_MAX_PATH];
    30.1 --- a/core/systems/ExtensionSys.h	Sat Oct 13 22:13:43 2007 +0000
    30.2 +++ b/core/systems/ExtensionSys.h	Sun Oct 14 00:04:21 2007 +0000
    30.3 @@ -121,7 +121,7 @@
    30.4  public: //IPluginsListener
    30.5  	void OnPluginDestroyed(IPlugin *plugin);
    30.6  public: //IRootConsoleCommand
    30.7 -	void OnRootConsoleCommand(const char *cmd, unsigned int argcount);
    30.8 +	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
    30.9  public:
   30.10  	IExtension *LoadAutoExtension(const char *path);
   30.11  	void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);
    31.1 --- a/core/systems/PluginSys.cpp	Sat Oct 13 22:13:43 2007 +0000
    31.2 +++ b/core/systems/PluginSys.cpp	Sun Oct 14 00:04:21 2007 +0000
    31.3 @@ -1961,11 +1961,12 @@
    31.4  	}
    31.5  }
    31.6  
    31.7 -void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argcount)
    31.8 +void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
    31.9  {
   31.10 +	int argcount = command.ArgC();
   31.11  	if (argcount >= 3)
   31.12  	{
   31.13 -		const char *cmd = g_RootMenu.GetArgument(2);
   31.14 +		const char *cmd = command.Arg(2);
   31.15  		if (strcmp(cmd, "list") == 0)
   31.16  		{
   31.17  			char buffer[256];
   31.18 @@ -2016,7 +2017,7 @@
   31.19  
   31.20  			char error[128];
   31.21  			bool wasloaded;
   31.22 -			const char *filename = g_RootMenu.GetArgument(3);
   31.23 +			const char *filename = command.Arg(3);
   31.24  
   31.25  			char pluginfile[256];
   31.26  			const char *ext = g_LibSys.GetFileExtension(filename) ? "" : ".smx";
   31.27 @@ -2047,7 +2048,7 @@
   31.28  
   31.29  			CPlugin *pl;
   31.30  			char *end;
   31.31 -			const char *arg = g_RootMenu.GetArgument(3);
   31.32 +			const char *arg = command.Arg(3);
   31.33  			int id = strtol(arg, &end, 10);
   31.34  
   31.35  			if (*end == '\0')
   31.36 @@ -2089,7 +2090,7 @@
   31.37  				return;
   31.38  			}
   31.39  
   31.40 -			int num = atoi(g_RootMenu.GetArgument(3));
   31.41 +			int num = atoi(command.Arg(3));
   31.42  			if (num < 1 || num > (int)GetPluginCount())
   31.43  			{
   31.44  				g_RootMenu.ConsolePrint("[SM] Plugin index not found.");
   31.45 @@ -2166,7 +2167,7 @@
   31.46  				return;
   31.47  			}
   31.48  
   31.49 -			int num = atoi(g_RootMenu.GetArgument(3));
   31.50 +			int num = atoi(command.Arg(3));
   31.51  			if (num < 1 || num > (int)GetPluginCount())
   31.52  			{
   31.53  				g_RootMenu.ConsolePrint("[SM] Plugin index not found.");
   31.54 @@ -2174,7 +2175,7 @@
   31.55  			}
   31.56  
   31.57  			int res;
   31.58 -			const char *mode = g_RootMenu.GetArgument(4);
   31.59 +			const char *mode = command.Arg(4);
   31.60  			if ((res=strcmp("on", mode)) && strcmp("off", mode))
   31.61  			{
   31.62  				g_RootMenu.ConsolePrint("[SM] The only possible options are \"on\" and \"off.\"");
   31.63 @@ -2218,7 +2219,7 @@
   31.64  
   31.65  			CPlugin *pl;
   31.66  			char *end;
   31.67 -			const char *arg = g_RootMenu.GetArgument(3);
   31.68 +			const char *arg = command.Arg(3);
   31.69  			int id = strtol(arg, &end, 10);
   31.70  
   31.71  			if (*end == '\0')
    32.1 --- a/core/systems/PluginSys.h	Sat Oct 13 22:13:43 2007 +0000
    32.2 +++ b/core/systems/PluginSys.h	Sun Oct 14 00:04:21 2007 +0000
    32.3 @@ -48,7 +48,11 @@
    32.4  #include "sm_trie.h"
    32.5  #include "sourcemod.h"
    32.6  #include <IRootConsoleMenu.h>
    32.7 +#if defined ORANGEBOX_BUILD
    32.8 +#include "convar_sm_ob.h"
    32.9 +#else
   32.10  #include "convar_sm.h"
   32.11 +#endif
   32.12  
   32.13  using namespace SourceHook;
   32.14  
   32.15 @@ -351,7 +355,7 @@
   32.16  public: //IHandleTypeDispatch
   32.17  	void OnHandleDestroy(HandleType_t type, void *object);
   32.18  public: //IRootConsoleCommand
   32.19 -	void OnRootConsoleCommand(const char *command, unsigned int argcount);
   32.20 +	void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
   32.21  public:
   32.22  	/**
   32.23  	 * Loads all plugins not yet loaded
    33.1 --- a/public/IRootConsoleMenu.h	Sat Oct 13 22:13:43 2007 +0000
    33.2 +++ b/public/IRootConsoleMenu.h	Sun Oct 14 00:04:21 2007 +0000
    33.3 @@ -32,6 +32,8 @@
    33.4  #ifndef _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_H_
    33.5  #define _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_H_
    33.6  
    33.7 +#include <compat_wrappers.h>
    33.8 +
    33.9  /**
   33.10   * @file IRootConsoleMenu.h
   33.11   * @brief Defines the interface for adding options to the "sm" console command.
   33.12 @@ -51,7 +53,7 @@
   33.13  	class IRootConsoleCommand
   33.14  	{
   33.15  	public:
   33.16 -		virtual void OnRootConsoleCommand(const char *command, unsigned int argcount) =0;
   33.17 +		virtual void OnRootConsoleCommand(const char *cmdname, const CCommand &command) =0;
   33.18  	};
   33.19  
   33.20  	/**
   33.21 @@ -88,28 +90,6 @@
   33.22  		virtual void ConsolePrint(const char *fmt, ...) =0;
   33.23  
   33.24  		/**
   33.25 -		 * @brief Returns the string of an argument.
   33.26 -		 *
   33.27 -		 * @param argno			The index of the argument.
   33.28 -		 * @return				A string containing the argument, or nothing if invalid.
   33.29 -		 */
   33.30 -		virtual const char *GetArgument(unsigned int argno) =0;
   33.31 -
   33.32 -		/**
   33.33 -		 * @brief Returns the number of arguments.
   33.34 -		 *
   33.35 -		 * @return				Number of arguments.
   33.36 -		 */
   33.37 -		virtual unsigned int GetArgumentCount() =0;
   33.38 -
   33.39 -		/** 
   33.40 -		 * @brief Returns the entire argument string.
   33.41 -		 *
   33.42 -		 * @return				String containing all arguments.
   33.43 -		 */
   33.44 -		virtual const char *GetArguments() =0;
   33.45 -
   33.46 -		/**
   33.47  		 * @brief Draws a generic command/description pair.
   33.48  		 * NOTE: The pair is currently four spaces indented and 16-N spaces of separation,
   33.49  		 * N being the length of the command name.  This is subject to change in case we
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/public/compat_wrappers.h	Sun Oct 14 00:04:21 2007 +0000
    34.3 @@ -0,0 +1,82 @@
    34.4 +/**
    34.5 + * vim: set ts=4 :
    34.6 + * =============================================================================
    34.7 + * SourceMod
    34.8 + * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
    34.9 + * =============================================================================
   34.10 + *
   34.11 + * This program is free software; you can redistribute it and/or modify it under
   34.12 + * the terms of the GNU General Public License, version 3.0, as published by the
   34.13 + * Free Software Foundation.
   34.14 + * 
   34.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
   34.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   34.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
   34.18 + * details.
   34.19 + *
   34.20 + * You should have received a copy of the GNU General Public License along with
   34.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
   34.22 + *
   34.23 + * As a special exception, AlliedModders LLC gives you permission to link the
   34.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
   34.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
   34.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
   34.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
   34.28 + * this exception to all derivative works.  AlliedModders LLC defines further
   34.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
   34.30 + * or <http://www.sourcemod.net/license.php>.
   34.31 + *
   34.32 + * Version: $Id$
   34.33 + */
   34.34 +
   34.35 +#ifndef _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
   34.36 +#define _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
   34.37 +
   34.38 +#if defined ORANGEBOX_BUILD
   34.39 +	#include "convar_sm_ob.h"
   34.40 +	#include "sourcemm_api.h"
   34.41 +
   34.42 +	#define CONVAR_REGISTER(object)				ConVar_Register(0, object)
   34.43 +
   34.44 +	inline bool IsFlagSet(ConCommandBase *cmd, int flag)
   34.45 +	{
   34.46 +		return cmd->IsFlagSet(flag);
   34.47 +	}
   34.48 +	inline void InsertServerCommand(const char *buf)
   34.49 +	{
   34.50 +		engine->ServerCommand(buf);
   34.51 +	}
   34.52 +#else
   34.53 +	#include "sourcemm_api.h"
   34.54 +
   34.55 +	class CCommand
   34.56 +	{
   34.57 +	public:
   34.58 +		inline const char *ArgS() const
   34.59 +		{
   34.60 +			return engine->Cmd_Args();
   34.61 +		}
   34.62 +		inline int ArgC() const
   34.63 +		{
   34.64 +			return engine->Cmd_Argc();
   34.65 +		}
   34.66 +		inline const char *Arg(int index) const
   34.67 +		{
   34.68 +			return engine->Cmd_Argv(index);
   34.69 +		}
   34.70 +	};
   34.71 +
   34.72 +	inline bool IsFlagSet(ConCommandBase *cmd, int flag)
   34.73 +	{
   34.74 +		return cmd->IsBitSet(flag);
   34.75 +	}
   34.76 +	inline void InsertServerCommand(const char *buf)
   34.77 +	{
   34.78 +		engine->InsertServerCommand(buf);
   34.79 +	}
   34.80 +
   34.81 +	#define CONVAR_REGISTER(object)				ConCommandBaseMgr::OneTimeInit(object)
   34.82 +	typedef FnChangeCallback					FnChangeCallback_t;
   34.83 +#endif //ORANGEBOX_BUILD
   34.84 +
   34.85 +#endif //_INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/public/metamod_wrappers.h	Sun Oct 14 00:04:21 2007 +0000
    35.3 @@ -0,0 +1,48 @@
    35.4 +/**
    35.5 + * vim: set ts=4 :
    35.6 + * =============================================================================
    35.7 + * SourceMod
    35.8 + * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
    35.9 + * =============================================================================
   35.10 + *
   35.11 + * This program is free software; you can redistribute it and/or modify it under
   35.12 + * the terms of the GNU General Public License, version 3.0, as published by the
   35.13 + * Free Software Foundation.
   35.14 + * 
   35.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
   35.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   35.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
   35.18 + * details.
   35.19 + *
   35.20 + * You should have received a copy of the GNU General Public License along with
   35.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
   35.22 + *
   35.23 + * As a special exception, AlliedModders LLC gives you permission to link the
   35.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
   35.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
   35.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
   35.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
   35.28 + * this exception to all derivative works.  AlliedModders LLC defines further
   35.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
   35.30 + * or <http://www.sourcemod.net/license.php>.
   35.31 + *
   35.32 + * Version: $Id$
   35.33 + */
   35.34 +
   35.35 +#ifndef _INCLUDE_METAMOD_WRAPPERS_H_
   35.36 +#define _INCLUDE_METAMOD_WRAPPERS_H_
   35.37 +
   35.38 +/* Get iface wrappers */
   35.39 +#define	GetEngineFactory		engineFactory
   35.40 +#define GetServerFactory		serverFactory
   35.41 +#define GetPhysicsFactory		physicsFactory
   35.42 +#define	GetFileSystemFactory	fileSystemFactory
   35.43 +
   35.44 +#define	GetCGlobals				pGlobals
   35.45 +
   35.46 +#define UnregisterConCommandBase	UnregisterConCmdBase
   35.47 +
   35.48 +/* Valve interface wrappers */
   35.49 +#define CVAR_INTERFACE_VERSION	VENGINE_CVAR_INTERFACE_VERSION
   35.50 +
   35.51 +#endif //_INCLUDE_METAMOD_WRAPPERS_H_