PDA

View Full Version : Create a new convar?



The Acid
07-02-2010, 04:29 PM
I am trying to create a new convar, obviously I am doing it wrong because the convar appear fine in console, and I can read the value of the convar but when I try to change it the game crashes.

static ConVar new_convar("new_convar", "0", FCVAR_NONE, "Test");

new_convar.m_pNext = 0;
m_pCvar->RegisterConCommand(&new_convar);

new_convar.SetValue(2); // Crash after a second or two.
Also tried with ConVar_Register(0), hoping that it would create the convars I have defined, but it does not do anything (I could not access it in any way and it does not seem to have been created).

The Acid
07-03-2010, 05:33 AM
I guess I was just retarded, here is how I got it working :)

static ConVar new_convar("new_convar", "0", FCVAR_NONE, "Test");

ConnectTier1Libraries(&g_AppSystemFactory, 1);
ConVar_Register(0);

freax
07-04-2010, 06:29 AM
Thanks for that. Does g_pCvar works for you? Any access (for example FindVar) crashes for me, seems the interface isn't up2date.

The Acid
07-04-2010, 09:35 AM
m_pCvar = (ICvar*) g_AppSystemFactory("VEngineCvar004", NULL);
Works fine on CS:S (FindVar).

freax
07-04-2010, 11:12 AM
Interesting:
pCvar = (ICvar*)this->m_EngineFactory(CVAR_INTERFACE_VERSION, NULL);
Worked fine for me before the update, now it's null (so it's clear why it crashed for me :D).

Your version works well. I wonder why I didn't try that already :D Thanks!

Are there any other interfaces you get through AppSysFactory (excluding the surface and panel stuff of course).

The Acid
07-04-2010, 11:29 AM
m_pEngine = (IVEngineClient*)g_AppSystemFactory("VEngineClient013", NULL);
m_pSurface = (vgui::ISurface*)g_AppSystemFactory("VGUI_Surface030", NULL);
m_pPanel = (vgui::IPanel*)g_AppSystemFactory("VGUI_Panel009", NULL);
m_pEngineVGui = (IEngineVGui*)g_AppSystemFactory("VEngineVGui001", NULL);
m_pEngineTrace = (IEngineTrace*)g_AppSystemFactory("EngineTraceClient003", NULL);
m_pModelInfo = (IVModelInfoClient*)g_AppSystemFactory("VModelInfoClient004", NULL);
m_pModelRender = (IVModelRender*)g_AppSystemFactory("VEngineModel016", NULL);
m_pRenderView = (IVRenderView*)g_AppSystemFactory("VEngineRenderView013", NULL);
m_pMaterialSystem = (IMaterialSystem*)g_AppSystemFactory("VMaterialSystem079", NULL);
I am sure there are more though.

freax
07-04-2010, 12:43 PM
Okay, for those I'm using the original CreateInterfaceFn function in the corresponding DLL:
pClient = (IBaseClientDLL*)this->m_ClientFactory(CLIENT_DLL_INTERFACE_VERSION, NULL);
pEngine = (IVEngineClient*)this->m_EngineFactory(VENGINE_CLIENT_INTERFACE_VERSION, NULL);
pEngineVGUI = (IEngineVGui*)this->m_EngineFactory(VENGINE_VGUI_VERSION, NULL);
pMaterialSystem = (IMaterialSystem*)this->m_MaterialFactory(MATERIAL_SYSTEM_INTERFACE_VERSION, NULL);
pEntList = (IClientEntityList*)this->m_ClientFactory(VCLIENTENTITYLIST_INTERFACE_VERSION, NULL);
pDebugOverlay = (IVDebugOverlay*)this->m_EngineFactory(VDEBUG_OVERLAY_INTERFACE_VERSION, NULL);
pRender = (IVRenderView*)this->m_EngineFactory(VENGINE_RENDERVIEW_INTERFACE_VERSION, NULL);
pFileSystem = (IFileSystem*)this->m_FileSystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL);
pModelRender = (IVModelRender*)this->m_EngineFactory(VENGINE_HUDMODEL_INTERFACE_VERSION, NULL);
pEffects = (IVEfx*)this->m_EngineFactory(VENGINE_EFFECTS_INTERFACE_VERSION, NULL);
pEngineTrace = (IEngineTrace*)this->m_EngineFactory(INTERFACEVERSION_ENGINETRACE_CLIENT, NULL);
pModelInfo = (IVModelInfoClient*)this->m_EngineFactory(VMODELINFO_CLIENT_INTERFACE_VERSION, NULL);
pEventManager = (IGameEventManager2*)this->m_EngineFactory(INTERFACEVERSION_GAMEEVENTSMANAGER2, NULL);
pPhysicsAPI = (IPhysicsSurfaceProps*)this->m_PhysicsFactory(VPHYSICS_SURFACEPROPS_INTERFACE_VERSION, NULL);
pPhysics = (IPhysics*)this->m_PhysicsFactory(VPHYSICS_INTERFACE_VERSION, NULL);
pEngineSound = (IEngineSound*)this->m_EngineFactory(IENGINESOUND_CLIENT_INTERFACE_VERSION, NULL);
pPrediction = (IPrediction*)this->m_ClientFactory(VCLIENT_PREDICTION_INTERFACE_VERSION, NULL);
pRandom = (IUniformRandomStream*)this->m_EngineFactory(VENGINE_CLIENT_RANDOM_INTERFACE_VERSION, NULL);
pShadowMgr = (IShadowMgr*)this->m_EngineFactory(ENGINE_SHADOWMGR_INTERFACE_VERSION, NULL);
pStudioRender = (IStudioRender*)this->m_StudioFactory(STUDIO_RENDER_INTERFACE_VERSION, NULL);

Maybe there's anything interesting for someone.

freax
07-04-2010, 04:47 PM
Also dynamic adding is possible:
ConVar *pVar = new ConVar("my_convar", "0", 0, "this is a help string");
pCvar->RegisterConCommand(pVar);Works without any additional code, connecting to the tier libraries isn't needed :)

syntroniks
07-04-2010, 07:10 PM
That's really cool that you can do that, I think it would also be helpful to perhaps unregister specific cvars at runtime.
I actually ran into problems developing one binary for 3 different games with 3 different featuresets, I ended up having an incredibly ugly preprocessor soup until I realized separate binaries would work better.

The Acid
07-05-2010, 05:46 AM
Dynamic adding crashes for me when I change the value of the convar :)
As far as I can tell it is because RegisterConCommand is not for registering convars, but for concommands only, so trying to change the convar is like trying to change a non-existant value of the concommand.

freax
07-05-2010, 05:55 AM
Don't forget to set m_pNext do zero. Works for me without any problems. RegisterConCommand is for both ConVar and ConCommand since both classes derive from ConCommandBase.