From f10119318271ea94f42cc82fb6b70c8be543eeab Mon Sep 17 00:00:00 2001 From: Marek Kulik Date: Fri, 12 May 2017 18:49:49 +0200 Subject: [PATCH] Clamp rain level in setRainLevel --- .../mods/deathmatch/logic/lua/CLuaFunctionDefs.World.cpp | 9 ++++++--- Server/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.World.cpp b/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.World.cpp index 4ce36e58760..a9f96f094f3 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.World.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.World.cpp @@ -1416,14 +1416,17 @@ int CLuaFunctionDefs::GetRainLevel ( lua_State* luaVM ) int CLuaFunctionDefs::SetRainLevel ( lua_State* luaVM ) { // bool setRainLevel ( float amount ) - float fAmount; + float fRainLevel; CScriptArgReader argStream ( luaVM ); - argStream.ReadNumber ( fAmount ); + argStream.ReadNumber ( fRainLevel ); if ( !argStream.HasErrors () ) { - g_pGame->GetWeather ()->SetAmountOfRain ( fAmount ); + // Clamp amount of rain to avoid game freezing/crash + fRainLevel = Clamp( 0.0f, fRainLevel, 10.0f ); + + g_pGame->GetWeather ()->SetAmountOfRain ( fRainLevel ); lua_pushboolean ( luaVM, true ); return 1; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp index 4969e05f8ef..e9a9dff2629 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp @@ -849,6 +849,9 @@ int CLuaWorldDefs::setRainLevel ( lua_State* luaVM ) if ( !argStream.HasErrors ( ) ) { + // Clamp amount of rain to avoid game freezing/crash + fRainLevel = Clamp( 0.0f, fRainLevel, 10.0f ); + if ( CStaticFunctionDefinitions::SetRainLevel ( fRainLevel ) ) { lua_pushboolean ( luaVM, true );