Skip to content

Conversation

roflmuffin
Copy link
Owner

@roflmuffin roflmuffin commented Jul 14, 2025

This PR adds Convar<T> which is a strongly typed variant of ConVar which provides better safety (no raw pointer accesses), as well as the ability to create real-convars that exist within the engine (and can be found using find foo in the console) amongst other things.

TODO:

  • Add BasePlugin based registration so that convars are automatically unloaded (similar to FakeConvar). Should the .Create static be restricted?

@roflmuffin roflmuffin force-pushed the feature/real-convars branch from f7cd192 to 8d9ea3f Compare July 20, 2025 11:17
Copy link

@ubbemir ubbemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome. Would be great to also have a list of known ConVars that utilize this to reduce mistake of accidentally using the wrong type with a ConVar. This however would be fitting in another PR I suppose.

ScriptContext.GlobalScriptContext.Reset();
ScriptContext.GlobalScriptContext.Push(convar);
ScriptContext.GlobalScriptContext.Push(flags);
ScriptContext.GlobalScriptContext.SetIdentifier(0xB2BDCCBF);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic numbers should not be written by themselves. Maybe make them a constant with a name to clarify?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are hash calculated native identifiers

@KillStr3aK
Copy link
Contributor

This looks awesome. Would be great to also have a list of known ConVars that utilize this to reduce mistake of accidentally using the wrong type with a ConVar. This however would be fitting in another PR I suppose.

https://cs2.poggu.me/dumped-data/convar-list

@ubbemir
Copy link

ubbemir commented Jul 31, 2025

This looks awesome. Would be great to also have a list of known ConVars that utilize this to reduce mistake of accidentally using the wrong type with a ConVar. This however would be fitting in another PR I suppose.

https://cs2.poggu.me/dumped-data/convar-list

Yes I know of that. But implement some of these at least into C# as statically typed to make use of the strength of static typing and static code analysis to reduce mistakes and catch erronous usage at compile time.

For example would it be suitable to do something similar to this?

public static class KnownConVars
{
    public static ConVar<bool> SvCheats = new ConVar<bool>("sv_cheats");
    public static ConVar<int> MpWarmupTime = new ConVar<int>("mp_warmuptime");
    public static ConVar<float> MaxSpeed = new ConVar<float>("sv_maxspeed");

    // Example: Add other ConVars here...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants