3 * ======================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC and authors.
7 * ======================================================
9 * This software is provided 'as-is', without any express or implied warranty.
10 * In no event will the authors be held liable for any damages arising from
11 * the use of this software.
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software in a
19 * product, an acknowledgment in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
29 #include "provider_ep1.h"
31 using namespace SourceHook;
33 SMConVarAccessor g_SMConVarAccessor;
35 class CAlwaysRegisterableCommand : public ConCommandBase
38 CAlwaysRegisterableCommand()
40 Create("metamod_eternal", NULL, FCVAR_UNREGISTERED|FCVAR_GAMEDLL);
42 bool IsRegistered( void ) const
48 // First, let's try to find us!
49 ConCommandBase *pPtr = icvar->GetCommands();
53 // We are already at the beginning; Nothing to do
63 ConCommandBase *pPrev = NULL;
71 pPtr = const_cast<ConCommandBase*>(pPtr->GetNext());
73 if (pPrev && pPtr == this)
75 pPrev->SetNext(m_pNext); // Remove us from the list
79 icvar->RegisterConCommandBase(this);
84 bool SMConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand)
86 m_RegisteredCommands.push_back(pCommand);
87 pCommand->SetNext(NULL);
88 icvar->RegisterConCommandBase(pCommand);
93 bool SMConVarAccessor::Register(ConCommandBase *pCommand)
95 pCommand->SetNext(NULL);
96 icvar->RegisterConCommandBase(pCommand);
101 void SMConVarAccessor::MarkCommandsAsGameDLL()
103 for (List<ConCommandBase*>::iterator iter = m_RegisteredCommands.begin();
104 iter != m_RegisteredCommands.end(); ++iter)
106 (*iter)->AddFlags(FCVAR_GAMEDLL);
110 void SMConVarAccessor::UnregisterGameDLLCommands()
112 ConCommandBase *begin = icvar->GetCommands();
113 ConCommandBase *iter = begin;
114 ConCommandBase *prev = NULL;
117 /* Watch out for the ETERNAL COMMAND! */
118 if (iter != &s_EternalCommand && iter->IsBitSet(FCVAR_GAMEDLL))
123 s_EternalCommand.BringToFront();
124 iter = const_cast<ConCommandBase*>(iter->GetNext());
125 s_EternalCommand.SetNext(iter);
126 prev = &s_EternalCommand;
131 iter = const_cast<ConCommandBase*>(iter->GetNext());
137 iter = const_cast<ConCommandBase*>(iter->GetNext());
141 void SMConVarAccessor::Unregister(ConCommandBase *pCommand)
143 ConCommandBase *ptr = icvar->GetCommands();
147 s_EternalCommand.BringToFront();
148 s_EternalCommand.SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
152 /* Find us and unregister us */
153 ConCommandBase *pPrev = NULL;
161 ptr = const_cast<ConCommandBase *>(ptr->GetNext());
163 if (pPrev && ptr == pCommand)
165 pPrev->SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));