From adc91c3e0a24203c12ca767e5cca83e4934eac55 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Wed, 11 Oct 2023 23:26:21 +0200 Subject: [PATCH] Clip parsed level from debug console to 50 Currently, in givelvl command user can type lvl above 50, which is a level cap. This patch clips it to 50, so we can prevent an accidential freeze of the game caused by NetSendCmd loop if user types a really big number. --- Source/debug.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/debug.cpp b/Source/debug.cpp index 7a66309d6cf..e6bc5812afa 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -565,10 +565,10 @@ std::string DebugCmdLevelUp(const std::string_view parameter) Player &myPlayer = *MyPlayer; std::string cmdLabel = "[givelvl] "; - const int levels = ParseInt(parameter, /*min=*/1).value_or(1); + const int levels = std::min(ParseInt(parameter, /*min=*/1).value_or(1), GetMaximumCharacterLevel() - myPlayer.getCharacterLevel()); for (int i = 0; i < levels; i++) NetSendCmd(true, CMD_CHEAT_EXPERIENCE); - return StrCat(cmdLabel, "New character level: ", myPlayer.getCharacterLevel()); + return StrCat(cmdLabel, "New character level: ", myPlayer.getCharacterLevel() + levels); } std::string DebugCmdMaxStats(const std::string_view parameter)