@@ -179,7 +179,7 @@ CON_COMMAND(dump_schema, "dump schema symbols")
179179 output << std::setw (2 ) << j << std::endl;
180180}
181181
182- SH_DECL_HOOK3_void (ICvar, DispatchConCommand, SH_NOATTRIB, 0 , ConCommandHandle , const CCommandContext&, const CCommand&);
182+ SH_DECL_HOOK3_void (ICvar, DispatchConCommand, SH_NOATTRIB, 0 , ConCommandRef , const CCommandContext&, const CCommand&);
183183
184184ConCommandInfo::ConCommandInfo ()
185185{
@@ -222,45 +222,31 @@ void UnlockConVars()
222222{
223223 int unhiddenConVars = 0 ;
224224
225- ConVar* currentCvar = nullptr ;
226- ConVarHandle currentCvarHandle;
227- currentCvarHandle.Set (0 );
228-
229- do
225+ for (ConVarRefAbstract ref (ConVarRef ((uint16)0 )); ref.IsValidRef (); ref = ConVarRefAbstract (ConVarRef (ref.GetAccessIndex () + 1 )))
230226 {
231- currentCvar = globals::cvars->GetConVar (currentCvarHandle);
232-
233- currentCvarHandle.Set (currentCvarHandle.Get () + 1 );
234-
235- if (!currentCvar) continue ;
236-
237- if (!(currentCvar->flags & flagsToRemove)) continue ;
227+ if (!ref.IsFlagSet (flagsToRemove)) continue ;
238228
239- currentCvar-> flags &= ~ flagsToRemove;
229+ ref. RemoveFlags ( flagsToRemove) ;
240230 unhiddenConVars++;
241- } while (currentCvar);
231+ }
242232}
243233
244234void UnlockConCommands ()
245235{
246236 int unhiddenConCommands = 0 ;
247237
248- ConCommand* currentConCommand = nullptr ;
249- ConCommand* invalidConCommand = globals::cvars->GetCommand (ConCommandHandle ());
250- ConCommandHandle conCommandHandle;
251- conCommandHandle.Set (0 );
238+ ConCommandData* currentConCommand = nullptr ;
239+ ConCommandData* invalidConCommand = globals::cvars->GetConCommandData (ConCommandRef ());
240+ ConCommandRef ref = ConCommandRef ((uint16)0 );
252241
253- do
242+ ConCommandData* data = g_pCVar->GetConCommandData (ConCommandRef ());
243+ for (ConCommandRef ref = ConCommandRef ((uint16)0 ); ref.GetRawData () != data; ref = ConCommandRef (ref.GetAccessIndex () + 1 ))
254244 {
255- currentConCommand = globals::cvars->GetCommand (conCommandHandle);
256-
257- conCommandHandle.Set (conCommandHandle.Get () + 1 );
245+ if (!ref.IsFlagSet (flagsToRemove)) continue ;
258246
259- if (!currentConCommand || currentConCommand == invalidConCommand || !(currentConCommand->GetFlags () & flagsToRemove)) continue ;
260-
261- currentConCommand->RemoveFlags (flagsToRemove);
247+ ref.RemoveFlags (flagsToRemove);
262248 unhiddenConCommands++;
263- } while (currentConCommand && currentConCommand != invalidConCommand);
249+ }
264250}
265251
266252void ConCommandManager::OnShutdown ()
@@ -301,10 +287,10 @@ void ConCommandManager::AddCommandListener(const char* name, CallbackT callback,
301287 pInfo = new ConCommandInfo ();
302288 m_cmd_lookup[strName] = pInfo;
303289
304- ConCommandHandle hExistingCommand = globals::cvars->FindCommand (name);
305- if (hExistingCommand.IsValid ())
290+ ConCommandRef hExistingCommand = globals::cvars->FindConCommand (name);
291+ if (hExistingCommand.IsValidRef ())
306292 {
307- pInfo->command = globals::cvars->GetCommand (hExistingCommand);
293+ pInfo->command = globals::cvars->GetConCommandData (hExistingCommand);
308294 }
309295 }
310296
@@ -353,11 +339,10 @@ void ConCommandManager::RemoveCommandListener(const char* name, CallbackT callba
353339
354340bool ConCommandManager::AddValveCommand (const char * name, const char * description, bool server_only, int flags)
355341{
356- ConCommandHandle hExistingCommand = globals::cvars->FindCommand (name);
357- if (hExistingCommand.IsValid ()) return false ;
342+ ConCommandRef hExistingCommand = globals::cvars->FindConCommand (name);
343+ if (hExistingCommand.IsValidRef ()) return false ;
358344
359- ConCommandRefAbstract conCommandRefAbstract;
360- auto conCommand = new ConCommand (&conCommandRefAbstract, strdup (name), CommandCallback, description ? strdup (description) : " " , flags);
345+ auto conCommand = new ConCommand (strdup (name), CommandCallback, description ? strdup (description) : " " , flags);
361346
362347 ConCommandInfo* pInfo = m_cmd_lookup[std::string (name)];
363348
@@ -367,23 +352,22 @@ bool ConCommandManager::AddValveCommand(const char* name, const char* descriptio
367352 m_cmd_lookup[std::string (name)] = pInfo;
368353 }
369354
370- pInfo->p_cmd = conCommandRefAbstract;
371- pInfo->command = conCommand;
355+ pInfo->command = conCommand->GetRawData ();
372356 pInfo->server_only = server_only;
373357
374358 return true ;
375359}
376360
377361bool ConCommandManager::RemoveValveCommand (const char * name)
378362{
379- auto hFoundCommand = globals::cvars->FindCommand (name);
363+ auto hFoundCommand = globals::cvars->FindConCommand (name);
380364
381- if (!hFoundCommand.IsValid ())
365+ if (!hFoundCommand.IsValidRef ())
382366 {
383367 return false ;
384368 }
385369
386- globals::cvars->UnregisterConCommand (hFoundCommand);
370+ globals::cvars->UnregisterConCommandCallbacks (hFoundCommand);
387371
388372 auto pInfo = m_cmd_lookup[std::string (name)];
389373 if (!pInfo)
@@ -474,7 +458,7 @@ HookResult ConCommandManager::ExecuteCommandCallbacks(
474458 return result;
475459}
476460
477- void ConCommandManager::Hook_DispatchConCommand (ConCommandHandle cmd, const CCommandContext& ctx, const CCommand& args)
461+ void ConCommandManager::Hook_DispatchConCommand (ConCommandRef cmd, const CCommandContext& ctx, const CCommand& args)
478462{
479463 const char * name = args.Arg (0 );
480464
@@ -486,7 +470,7 @@ void ConCommandManager::Hook_DispatchConCommand(ConCommandHandle cmd, const CCom
486470 RETURN_META (MRES_SUPERCEDE);
487471 }
488472}
489- void ConCommandManager::Hook_DispatchConCommand_Post (ConCommandHandle cmd, const CCommandContext& ctx, const CCommand& args)
473+ void ConCommandManager::Hook_DispatchConCommand_Post (ConCommandRef cmd, const CCommandContext& ctx, const CCommand& args)
490474{
491475 const char * name = args.Arg (0 );
492476
@@ -498,8 +482,8 @@ void ConCommandManager::Hook_DispatchConCommand_Post(ConCommandHandle cmd, const
498482}
499483bool ConCommandManager::IsValidValveCommand (const char * name)
500484{
501- ConCommandHandle pCmd = globals::cvars->FindCommand (name);
502- return pCmd.IsValid ();
485+ ConCommandRef pCmd = globals::cvars->FindConCommand (name);
486+ return pCmd.IsValidRef ();
503487}
504488
505489CommandCallingContext ConCommandManager::GetCommandCallingContext (CCommand* args) { return m_cmd_contexts[args]; }
0 commit comments