From 29d364067a2dd691b80c9e3b8d3509ba596ba0f9 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 14 Dec 2025 14:00:47 -0600 Subject: [PATCH] Donut9a: guard against bad donuts moldy donuts yuck --- .../Save Editors/Gen9/DonutEditor9a.cs | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen9/DonutEditor9a.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen9/DonutEditor9a.cs index d5e13fe69..9cdb0dfd4 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen9/DonutEditor9a.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen9/DonutEditor9a.cs @@ -117,9 +117,9 @@ public void LoadDonut(Donut9a donut) { _donut = donut; - NUD_Stars.Value = donut.Stars; - NUD_Calories.Value = donut.Calories; - NUD_LevelBoost.Value = donut.LevelBoost; + LoadClamp(NUD_Stars, donut.Stars); + LoadClamp(NUD_Calories, donut.Calories); + LoadClamp(NUD_LevelBoost, donut.LevelBoost); CB_Donut.SelectedValue = (int)donut.Donut; @@ -142,9 +142,20 @@ public void LoadDonut(Donut9a donut) dt = Epoch; else dt = donut.DateTime1900.Timestamp; - CAL_Date.Value = dt; + try + { + CAL_Date.Value = dt; + } + catch + { + CAL_Date.Value = Epoch; + } TB_Unknown.Text = donut.Unknown.ToString(); + + return; + + static void LoadClamp(NumericUpDown nud, decimal value) => nud.Value = Math.Clamp(value, nud.Minimum, nud.Maximum); } public void SaveDonut() @@ -175,10 +186,21 @@ public void SaveDonut() var dt = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second); // if date is sufficiently equal to the Epoch (zero), set to zero. Can't set a date of 1900/00/00 via the controls... - if (dt is { Year: 1900, Month: 1, Day: 1 } and { Day: 1, Hour: 0, Minute: 0, Second: 0 }) + if (dt is { Year: 1900, Month: <= 1, Day: <= 1 } and { Day: 1, Hour: 0, Minute: 0, Second: 0 }) + { donut.ClearDateTime(); + } else - donut.DateTime1900.Timestamp = dt; + { + try + { + donut.DateTime1900.Timestamp = dt; + } + catch + { + donut.ClearDateTime(); + } + } donut.Unknown = ulong.TryParse(TB_Unknown.Text, out var unk) ? unk : 0; } @@ -195,7 +217,7 @@ private static void LoadDonutFlavorHash(ComboBox cb, ulong flavorHash) private static ulong GetDonutFlavorHash(ComboBox cb) { - if (cb.SelectedIndex == 0) + if (cb.SelectedIndex <= 0) return 0; // No flavor // Grab the internal value (not the localized display value)