From 9051bca1434465e55882f50717df7ff87d1142c4 Mon Sep 17 00:00:00 2001 From: Norbyte Date: Sun, 27 Oct 2019 10:20:31 +0100 Subject: [PATCH] Clamp vit/armor values before update --- OsiInterface/Functions/CharacterFunctions.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/OsiInterface/Functions/CharacterFunctions.cpp b/OsiInterface/Functions/CharacterFunctions.cpp index 48026431..13c4fcdb 100644 --- a/OsiInterface/Functions/CharacterFunctions.cpp +++ b/OsiInterface/Functions/CharacterFunctions.cpp @@ -37,13 +37,24 @@ namespace osidbg return OsirisPropertyMapGet(gCharacterStatsPropertyMap, character->Stats, args, 1, Type); } - template - void CharacterSetStat(OsiArgumentDesc const & args) + void CharacterSetStatInt(OsiArgumentDesc const & args) { auto character = FindCharacterByNameGuid(args[0].String); + auto stat = args[1].String; + auto value = args[2].Int32; + if (character == nullptr || character->Stats == nullptr) return; - OsirisPropertyMapSet(gCharacterStatsPropertyMap, character->Stats, args, 1, Type); + auto clamped = value; + if (strcmp(stat, "CurrentVitality") == 0) { + clamped = std::clamp(value, 0, (int32_t)character->Stats->MaxVitality); + } else if (strcmp(stat, "CurrentArmor") == 0) { + clamped = std::clamp(value, 0, (int32_t)character->Stats->MaxArmor); + } else if (strcmp(stat, "CurrentMagicArmor") == 0) { + clamped = std::clamp(value, 0, (int32_t)character->Stats->MaxMagicArmor); + } + + gCharacterStatsPropertyMap.setInt(character->Stats, stat, clamped, false, true); } template @@ -136,7 +147,7 @@ namespace osidbg { "Stat", ValueType::String, FunctionArgumentDirection::In }, { "Value", ValueType::Integer, FunctionArgumentDirection::In }, }, - &func::CharacterSetStat + &func::CharacterSetStatInt ); functionMgr.Register(std::move(characterSetStatInt));