Until garry fixes it...
[url=http://solidfiles.com/d/qjPL][img]http://solidfiles.com/info_imgs/qjPL.jpg[/img][/url]
[B]Usage[/B]
[LUA]
-- Put gmsv_cvarfix.dll into server's lua/includes/modules folder and require it
require( 'cvarfix' )
cvars.AddChangeCallback('sv_cheats' , function(cvarname,oldvar,newvar) print"OMG XIITS!" end)
[/LUA]
Use this fix at your own caution. If it fries your pc I'm not responsible, OK?
And remember to remove it when/if Garry fixes it for real.
[CODE]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <interface.h>
#include "icvar.h"
#include "convar.h"
#include "GMLuaModule.h"
GMOD_MODULE(Load, Unload)
ILuaInterface* gLua;
ICvar **cvarfix;
void FixThatDamnThing(IConVar *var, const char *pOldValue, float flOldValue) {
ILuaObject *cvars = gLua->GetGlobal("cvars");
if(!cvars->isTable()) return;
ILuaObject *func = cvars->GetMember("OnConVarChanged");
cvars->UnReference();
if(!cvarfix || !func->isFunction()) return;
gLua->Push(func);
gLua->Push(var->GetName());
gLua->Push(pOldValue);
ConVar *varz = (*cvarfix)->FindVar(var->GetName());
if(var) gLua->Push(varz->GetString());
else gLua->PushNil();
gLua->Call(3, 1);
func->UnReference();
return;
}
int Load(lua_State* L)
{
gLua = Lua();
Sys_LoadModule("server.dll");
cvarfix = (ICvar **)GetProcAddress(GetModuleHandleA("server.dll"), "cvar");
if(!cvarfix)
gLua->Error("cvarfix interface not loaded.");
(*cvarfix)->InstallGlobalChangeCallback(FixThatDamnThing);
return 0;
}
int Unload(lua_State* L)
{
(*cvarfix)->RemoveGlobalChangeCallback(FixThatDamnThing);
return 0;
}
[/CODE]
By the way, be extremely careful with changing the cvar inside the hook since you might create an epic deadloop :)
Thanks to haza55, ComWalk and whoever else participated in the code directly or indirectly. This wouldn't have been possible without you.
Please reference other peoples work.
Oh yeah, sorry. I just wanted to post this so it wouldn't lie on my server only. And to get Garry fix it faster if people showed the need for this feature. For example PAC2 is using workaround which creates timer for each cvar that needs a callback, which in my opinion is not coding best practices.
Sorry, you need to Log In to post a reply to this thread.