From 9d725276ac979b93fe55b97de2dce1a86bc80bba Mon Sep 17 00:00:00 2001 From: Kaelan Date: Tue, 15 Oct 2024 12:12:33 -0600 Subject: [PATCH] Add manual config saving to CVar struct Allows for calling to save custom cvars manually to ensure they're reliably stored. As is, the only way to ensure that cvars are saved is to safely/manually close out GZDoom, meaning if a crash occurs, that data is lost. THis is very detrimental to mods/standalone projects that rely on CVars for storing custom data, and or data that transcends save games. --- src/common/scripting/interface/vmnatives.cpp | 6 ++++++ wadsrc/static/zscript/engine/base.zs | 1 + 2 files changed, 7 insertions(+) diff --git a/src/common/scripting/interface/vmnatives.cpp b/src/common/scripting/interface/vmnatives.cpp index 2b57ceb25..1b2b749aa 100644 --- a/src/common/scripting/interface/vmnatives.cpp +++ b/src/common/scripting/interface/vmnatives.cpp @@ -41,6 +41,7 @@ #include "c_cvars.h" #include "c_bind.h" #include "c_dispatch.h" +#include "m_misc.h" #include "menu.h" #include "vm.h" @@ -1032,6 +1033,11 @@ DEFINE_ACTION_FUNCTION(_CVar, FindCVar) ACTION_RETURN_POINTER(FindCVar(name.GetChars(), nullptr)); } +DEFINE_ACTION_FUNCTION(_CVar, SaveConfig) +{ + ACTION_RETURN_BOOL(M_SaveDefaults(nullptr)); +} + //============================================================================= // // diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index 18fe1b363..69f5d66fe 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -689,6 +689,7 @@ struct CVar native }; native static CVar FindCVar(Name name); + native static bool SaveConfig(); bool GetBool() { return GetInt(); } native int GetInt(); native double GetFloat();