From 9a867a7e5809243ca4355a110d9ac1ca01b83bd1 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Tue, 29 Dec 2020 00:19:27 +0100 Subject: [PATCH] GUI: Fix not loading numeric and boolean type options properly --- Il2CppInspector.GUI/App.xaml.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Il2CppInspector.GUI/App.xaml.cs b/Il2CppInspector.GUI/App.xaml.cs index a599369..f62c124 100644 --- a/Il2CppInspector.GUI/App.xaml.cs +++ b/Il2CppInspector.GUI/App.xaml.cs @@ -150,10 +150,24 @@ namespace Il2CppInspectorGUI if (savedState.Plugin.Options != null) foreach (var savedOption in savedState.Plugin.Options) if (managedPlugin.Plugin.Options.FirstOrDefault(o => o.Name == savedOption.Name) is IPluginOption option) { - // Ignore invalid values try { - option.Value = savedOption.Value is JsonElement ? savedOption.Value.ToString() : savedOption.Value; - } catch { } + // Ignore validation + var cond = option.If; + option.If = () => false; + if (savedOption.Value == null) + option.Value = null; + else + option.Value = (savedOption.Value, ((JsonElement) savedOption.Value).ValueKind) switch { + (var v, JsonValueKind.String) => v.ToString(), + (var v, JsonValueKind.Number) => Convert.ChangeType(v.ToString(), option.Value.GetType()), + (var v, JsonValueKind.True) => true, + (var v, JsonValueKind.False) => false, + _ => throw new ArgumentException("Unsupported JSON type") + }; + option.If = cond; + } + // Ignore invalid values + catch { } } } }