From 7b1fd3e37f49ae307ae074766a9fc57fbb6faa5a Mon Sep 17 00:00:00 2001
From: SamuXarick <43006711+SamuXarick@users.noreply.github.com>
Date: Fri, 3 Feb 2023 20:06:29 +0000
Subject: [PATCH] Fix #10059: [Script] Clamp config item values to int32

Also prevent random_deviation to be below 0.
---
 src/script/script_info.cpp | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/script/script_info.cpp b/src/script/script_info.cpp
index d381ae9c2c..dc4e07dee2 100644
--- a/src/script/script_info.cpp
+++ b/src/script/script_info.cpp
@@ -146,42 +146,42 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
 		} else if (strcmp(key, "min_value") == 0) {
 			SQInteger res;
 			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
-			config.min_value = res;
+			config.min_value = ClampToI32(res);
 			items |= 0x004;
 		} else if (strcmp(key, "max_value") == 0) {
 			SQInteger res;
 			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
-			config.max_value = res;
+			config.max_value = ClampToI32(res);
 			items |= 0x008;
 		} else if (strcmp(key, "easy_value") == 0) {
 			SQInteger res;
 			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
-			config.easy_value = res;
+			config.easy_value = ClampToI32(res);
 			items |= 0x010;
 		} else if (strcmp(key, "medium_value") == 0) {
 			SQInteger res;
 			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
-			config.medium_value = res;
+			config.medium_value = ClampToI32(res);
 			items |= 0x020;
 		} else if (strcmp(key, "hard_value") == 0) {
 			SQInteger res;
 			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
-			config.hard_value = res;
+			config.hard_value = ClampToI32(res);
 			items |= 0x040;
 		} else if (strcmp(key, "random_deviation") == 0) {
 			SQInteger res;
 			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
-			config.random_deviation = res;
+			config.random_deviation = ClampToI32(abs(res));
 			items |= 0x200;
 		} else if (strcmp(key, "custom_value") == 0) {
 			SQInteger res;
 			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
-			config.custom_value = res;
+			config.custom_value = ClampToI32(res);
 			items |= 0x080;
 		} else if (strcmp(key, "step_size") == 0) {
 			SQInteger res;
 			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
-			config.step_size = res;
+			config.step_size = ClampToI32(res);
 		} else if (strcmp(key, "flags") == 0) {
 			SQInteger res;
 			if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;