1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sourcemm/episode1/console.cpp Fri Sep 28 21:31:02 2007 +0000
1.3 @@ -0,0 +1,111 @@
1.4 +#include "console.h"
1.5 +#include "provider_ep1.h"
1.6 +
1.7 +using namespace SourceHook;
1.8 +
1.9 +SMConVarAccessor g_SMConVarAccessor;
1.10 +
1.11 +class CAlwaysRegisterableCommand : public ConCommandBase
1.12 +{
1.13 +public:
1.14 + CAlwaysRegisterableCommand()
1.15 + {
1.16 + Create("metamod_eternal", NULL, FCVAR_UNREGISTERED|FCVAR_GAMEDLL);
1.17 + }
1.18 + bool IsRegistered( void ) const
1.19 + {
1.20 + return false;
1.21 + }
1.22 + void BringToFront()
1.23 + {
1.24 + // First, let's try to find us!
1.25 + ConCommandBase *pPtr = icvar->GetCommands();
1.26 +
1.27 + if (pPtr == this)
1.28 + {
1.29 + // We are already at the beginning; Nothing to do
1.30 + return;
1.31 + }
1.32 +
1.33 + while (pPtr)
1.34 + {
1.35 + if (pPtr == this)
1.36 + {
1.37 + break;
1.38 + }
1.39 + ConCommandBase *pPrev = NULL;
1.40 + while (pPtr)
1.41 + {
1.42 + if (pPtr == this)
1.43 + {
1.44 + break;
1.45 + }
1.46 + pPrev = pPtr;
1.47 + pPtr = const_cast<ConCommandBase*>(pPtr->GetNext());
1.48 + }
1.49 + if (pPrev && pPtr == this)
1.50 + {
1.51 + pPrev->SetNext(m_pNext); // Remove us from the list
1.52 + }
1.53 + // Now, register us
1.54 + SetNext(NULL);
1.55 + icvar->RegisterConCommandBase(this);
1.56 + }
1.57 + }
1.58 +} s_EternalCommand;
1.59 +
1.60 +bool SMConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand)
1.61 +{
1.62 + m_RegisteredCommands.push_back(pCommand);
1.63 + pCommand->SetNext(NULL);
1.64 + icvar->RegisterConCommandBase(pCommand);
1.65 +
1.66 + return true;
1.67 +}
1.68 +
1.69 +bool SMConVarAccessor::Register(ConCommandBase *pCommand)
1.70 +{
1.71 + pCommand->SetNext(NULL);
1.72 + icvar->RegisterConCommandBase(pCommand);
1.73 +
1.74 + return true;
1.75 +}
1.76 +
1.77 +void SMConVarAccessor::MarkCommandsAsGameDLL()
1.78 +{
1.79 + for (List<ConCommandBase*>::iterator iter = m_RegisteredCommands.begin();
1.80 + iter != m_RegisteredCommands.end(); ++iter)
1.81 + {
1.82 + (*iter)->AddFlags(FCVAR_GAMEDLL);
1.83 + }
1.84 +}
1.85 +
1.86 +void SMConVarAccessor::Unregister(ConCommandBase *pCommand)
1.87 +{
1.88 + ConCommandBase *ptr = icvar->GetCommands();
1.89 +
1.90 + if (ptr == pCommand)
1.91 + {
1.92 + s_EternalCommand.BringToFront();
1.93 + s_EternalCommand.SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
1.94 + }
1.95 + else
1.96 + {
1.97 + /* Find us and unregister us */
1.98 + ConCommandBase *pPrev = NULL;
1.99 + while (ptr)
1.100 + {
1.101 + if (ptr == pCommand)
1.102 + {
1.103 + break;
1.104 + }
1.105 + pPrev = ptr;
1.106 + ptr = const_cast<ConCommandBase *>(ptr->GetNext());
1.107 + }
1.108 + if (pPrev && ptr == pCommand)
1.109 + {
1.110 + pPrev->SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
1.111 + }
1.112 + }
1.113 +}
1.114 +