From b62a3b623a851fe4af3fb64cc3724156a12e2738 Mon Sep 17 00:00:00 2001
From: James R <justsomejames2@gmail.com>
Date: Mon, 9 Nov 2020 18:54:00 -0800
Subject: [PATCH] Don't let Lua cvar setting functions work on CV_NOLUA vars

---
 src/lua_consolelib.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c
index c6b0829303..32d64b5b53 100644
--- a/src/lua_consolelib.c
+++ b/src/lua_consolelib.c
@@ -440,6 +440,9 @@ static int CVarSetFunction
 ){
 	consvar_t *cvar = (consvar_t *)luaL_checkudata(L, 1, META_CVAR);
 
+	if (cvar->flags & CV_NOLUA)
+		return luaL_error(L, "Variable %s cannot be set from Lua.", cvar->name);
+
 	switch (lua_type(L, 2))
 	{
 		case LUA_TSTRING:
@@ -468,7 +471,12 @@ static int lib_cvStealthSet(lua_State *L)
 static int lib_cvAddValue(lua_State *L)
 {
 	consvar_t *cvar = (consvar_t *)luaL_checkudata(L, 1, META_CVAR);
+
+	if (cvar->flags & CV_NOLUA)
+		return luaL_error(L, "Variable %s cannot be set from Lua.", cvar->name);
+
 	CV_AddValue(cvar, (INT32)luaL_checknumber(L, 2));
+
 	return 0;
 }
 
-- 
GitLab