From 3c218846ef1ec573d83d2b60bc55d1050a3e6026 Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Sun, 25 Oct 2020 18:12:45 -0700 Subject: [PATCH] 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. --- 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 506ee5cf3ba..228a0b557c8 100644 --- a/code/modules/client/preferences_savefile.dm +++ b/code/modules/client/preferences_savefile.dm @@ -235,7 +235,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))