2727// -----------------------------------------------------------------------------
2828//  Includes
2929// -----------------------------------------------------------------------------
30- //  This is required for accessing m_nFlags without patching convar.h
31- #define  private  public
32- 
3330#include  " utilities/call_python.h" 
3431
3532#include  " boost/unordered_map.hpp" 
@@ -56,8 +53,12 @@ class CPluginConVarAccessor : public IConCommandBaseAccessor
5653public: 
5754	virtual  bool  RegisterConCommandBase (ConCommandBase* pCommand)
5855	{
59- 		g_pCVar->RegisterConCommand (pCommand);
60- 		return  true ;
56+ 		if  (!g_pCVar->FindCommandBase (pCommand->GetName ())) {
57+ 			g_pCVar->RegisterConCommand (pCommand);
58+ 			return  true ;
59+ 		}
60+ 
61+ 		return  false ;
6162	}
6263};
6364
@@ -121,15 +122,17 @@ CServerCommandManager* CServerCommandManager::CreateCommand(const char* szName,
121122	char * szHelpTextCopy = NULL ;
122123
123124	//  FInd if the command already exists
124- 	ConCommand * pConCommand = g_pCVar->FindCommand (szName);
125+ 	ConCommandBase * pConCommand = g_pCVar->FindCommandBase (szName);
125126	if ( pConCommand )
126127	{
127128		//  Store the current command's help text and flags
128129		szHelpTextCopy = strdup (pConCommand->GetHelpText ());
129- 		iFlags = pConCommand-> m_nFlags ;
130+ 		iFlags = GetConCommandFlags ( pConCommand) ;
130131
131132		//  Unregister the old command
132- 		g_pCVar->UnregisterConCommand (pConCommand);
133+ 		if  (pConCommand->IsRegistered ()) {
134+ 			g_pCVar->UnregisterConCommand (pConCommand);
135+ 		}
133136	}
134137	else  if ( szHelpText != NULL  )
135138	{
@@ -144,7 +147,7 @@ CServerCommandManager* CServerCommandManager::CreateCommand(const char* szName,
144147// -----------------------------------------------------------------------------
145148//  CServerCommandManager constructor.
146149// -----------------------------------------------------------------------------
147- CServerCommandManager::CServerCommandManager (ConCommand * pConCommand,
150+ CServerCommandManager::CServerCommandManager (ConCommandBase * pConCommand,
148151		const  char * szName, const  char * szHelpText, int  iFlags):
149152	ConCommand(szName, (FnCommandCallback_t)NULL, szHelpText, iFlags),
150153	m_pOldCommand(pConCommand)
@@ -163,8 +166,8 @@ CServerCommandManager::~CServerCommandManager()
163166	//  Get the ConCommand instance
164167	ConCommand* pConCommand = g_pCVar->FindCommand (m_Name);
165168
166- 	//  Was the command overwritten as a ConVar or by another DLL? 
167- 	if  (pConCommand && pConCommand-> GetDLLIdentifier ()  == CVarDLLIdentifier () )
169+ 	//  Make sure we only unregister ourselves 
170+ 	if  (pConCommand == this )
168171	{
169172		//  Unregister the ConCommand
170173		g_pCVar->UnregisterConCommand (pConCommand);
@@ -236,7 +239,12 @@ void CServerCommandManager::Dispatch( const CCommand& command )
236239	//  Was the command previously registered?
237240	if (m_pOldCommand)
238241	{
239- 		m_pOldCommand->Dispatch (command);
242+ 		if  (m_pOldCommand->IsCommand ()) {
243+ 			static_cast <ConCommand *>(m_pOldCommand)->Dispatch (command);
244+ 		}
245+ 		else  {
246+ 			static_cast <ConVar *>(m_pOldCommand)->SetValue (command.ArgS ());
247+ 		}
240248	}
241249
242250	//  Post hook callbacks
0 commit comments