From 12a676a858dbf37b96e18d181fe15e13ceb972f5 Mon Sep 17 00:00:00 2001 From: Baoulettes Date: Sat, 23 Apr 2022 04:47:38 +0200 Subject: [PATCH] Add int variant of CVar_ Get/Set/Register --- libultraship/libultraship/Cvar.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libultraship/libultraship/Cvar.cpp b/libultraship/libultraship/Cvar.cpp index 91788fd48..605b17941 100644 --- a/libultraship/libultraship/Cvar.cpp +++ b/libultraship/libultraship/Cvar.cpp @@ -47,6 +47,17 @@ extern "C" char* CVar_GetString(const char* name, char* defaultValue) { return defaultValue; } +extern "C" int CVar_GetInt(const char* name, int defaultValue) { + CVar* cvar = CVar_Get(name); + + if (cvar != nullptr) { + if (cvar->type == CVAR_TYPE_INT) + return cvar->value.valueInt; + } + + return defaultValue; +} + extern "C" void CVar_SetS32(const char* name, s32 value) { CVar* cvar = CVar_Get(name); if (!cvar) { @@ -77,6 +88,15 @@ void CVar_SetString(const char* name, char* value) { cvar->value.valueStr = value; } +void CVar_SetInt(const char* name, int value) { + CVar* cvar = CVar_Get(name); + if (!cvar) { + cvar = new CVar; + cvars[std::string(name)] = cvar; + } + cvar->type = CVAR_TYPE_INT; + cvar->value.valueInt = value; +} extern "C" void CVar_RegisterS32(const char* name, s32 defaultValue) { CVar* cvar = CVar_Get(name); @@ -98,3 +118,10 @@ extern "C" void CVar_RegisterString(const char* name, char* defaultValue) { if (cvar == nullptr) CVar_SetString(name, defaultValue); } + +extern "C" void CVar_RegisterInt(const char* name, int defaultValue) { + CVar* cvar = CVar_Get(name); + + if (cvar == nullptr) + CVar_SetInt(name, defaultValue); +}