From 8c771e2f4b2934d6bc0dbea4ff584c3c70100bad Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 26 Oct 2020 09:11:44 +0100 Subject: [PATCH] [MIRROR] Properly sanitizes the pixel scaling pref (#1470) * Properly sanitizes the pixel scaling pref (#54592) It was being rounded to 1, which breaks one of the options. I've added a float sanitize proc that accepts a degree to round to, I've set it to 0.5 in this case. * Properly sanitizes the pixel scaling pref Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> --- code/__HELPERS/sanitize_values.dm | 7 +++++++ code/modules/client/preferences_savefile.dm | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/code/__HELPERS/sanitize_values.dm b/code/__HELPERS/sanitize_values.dm index 00f6ddc5cd8..233a511e2e0 100644 --- a/code/__HELPERS/sanitize_values.dm +++ b/code/__HELPERS/sanitize_values.dm @@ -6,6 +6,13 @@ return number return default +/proc/sanitize_float(number, min=0, max=1, accuracy=1, default=0) + if(isnum(number)) + number = round(number, accuracy) + if(min <= number && number <= max) + return number + return default + /proc/sanitize_text(text, default="") if(istext(text)) return text diff --git a/code/modules/client/preferences_savefile.dm b/code/modules/client/preferences_savefile.dm index bb3d20910af..b69491f63a3 100644 --- a/code/modules/client/preferences_savefile.dm +++ b/code/modules/client/preferences_savefile.dm @@ -237,7 +237,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car ambientocclusion = sanitize_integer(ambientocclusion, FALSE, TRUE, initial(ambientocclusion)) auto_fit_viewport = sanitize_integer(auto_fit_viewport, FALSE, TRUE, initial(auto_fit_viewport)) widescreenpref = sanitize_integer(widescreenpref, FALSE, TRUE, initial(widescreenpref)) - pixel_size = sanitize_integer(pixel_size, PIXEL_SCALING_AUTO, PIXEL_SCALING_3X, initial(pixel_size)) + pixel_size = sanitize_float(pixel_size, PIXEL_SCALING_AUTO, PIXEL_SCALING_3X, 0.5, initial(pixel_size)) scaling_method = sanitize_text(scaling_method, initial(scaling_method)) ghost_form = sanitize_inlist(ghost_form, GLOB.ghost_forms, initial(ghost_form)) ghost_orbit = sanitize_inlist(ghost_orbit, GLOB.ghost_orbits, initial(ghost_orbit))