MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / OnConVarChanged

Method OnConVarChanged

core/ConVarManager.cpp:625–665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

623}
624
625void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue)
626{
627 /* If the values are the same, exit early in order to not trigger callbacks */
628 if (strcmp(pConVar->GetString(), oldValue) == 0)
629 {
630 return;
631 }
632
633 ConVarInfo *pInfo;
634
635 /* Find the convar in the lookup trie */
636 if (!convar_cache_lookup(pConVar->GetName(), &pInfo))
637 {
638 return;
639 }
640
641 IChangeableForward *pForward = pInfo->pChangeForward;
642
643 if (pInfo->changeListeners.size() != 0)
644 {
645 for (auto i = pInfo->changeListeners.begin(); i != pInfo->changeListeners.end(); i++)
646 (*i)->OnConVarChanged(pConVar, oldValue, flOldValue);
647 }
648
649 if (pForward != NULL)
650 {
651 ConVarReentrancyGuard guard(pConVar);
652
653 /* Copy the new value to a local buffer so it survives reentrant
654 * ChangeStringValue calls that may delete[] + reallocate m_pszString
655 * while the forward is still iterating plugin callbacks. */
656 char newValue[512];
657 ke::SafeStrcpy(newValue, sizeof(newValue), pConVar->GetString());
658
659 /* Now call forwards in plugins that have hooked this */
660 pForward->PushCell(pInfo->handle);
661 pForward->PushString(oldValue);
662 pForward->PushString(newValue);
663 pForward->Execute(NULL);
664 }
665}
666
667bool ConVarManager::IsQueryingSupported()
668{

Callers

nothing calls this directly

Calls 9

convar_cache_lookupFunction · 0.85
PushCellMethod · 0.80
PushStringMethod · 0.80
GetStringMethod · 0.45
GetNameMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
ExecuteMethod · 0.45

Tested by

no test coverage detected