From de37e4a3b072174a46f5a38866b63f48e60705eb Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Sat, 7 Nov 2026 04:00:56 -0500 Subject: [PATCH] git please stop confusing me --- MiraAPI/GameOptions/ModdedOptionsManager.cs | 38 ++++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/MiraAPI/GameOptions/ModdedOptionsManager.cs b/MiraAPI/GameOptions/ModdedOptionsManager.cs index 98d07606..46335b05 100644 --- a/MiraAPI/GameOptions/ModdedOptionsManager.cs +++ b/MiraAPI/GameOptions/ModdedOptionsManager.cs @@ -38,6 +38,9 @@ public static class ModdedOptionsManager private static readonly Dictionary ConcretisedGetters = []; private static readonly Dictionary ConcretisedSetters = []; + private static readonly Type OptionType = typeof(IModdedOption); + private static readonly Type OptionListType = typeof(IModdedOptionList); + internal static readonly Dictionary CreatedPlayerOptions = []; internal static readonly Dictionary> GameModeOptionGroups = []; internal static readonly Dictionary ModdedOptions = []; @@ -113,30 +116,47 @@ public static class ModdedOptionsManager foreach (var property in type.GetProperties(MiraPluginManager.DeclaredInstanceMembers)) { - if (property.PropertyType.IsAssignableTo(typeof(IModdedOption))) + if (property.GetMethod == null) + { + Error($"Non-ignored option property {property.Name} in {type.Name} must at least have a getter."); + continue; + } + + var propType = property.PropertyType; + + if (propType.IsAssignableTo(OptionType)) { RegisterPropertyOption(type, property, pluginInfo); continue; } - if (property.PropertyType.IsAssignableTo(typeof(IModdedOptionList))) + if (propType.IsAssignableTo(OptionListType)) { RegisterPropertyOptionList(type, property, pluginInfo); continue; } - if (property.TryGetCustomAttribute(out var attribute)) - { - RegisterAttributeOption(type, attribute, property, pluginInfo); - continue; - } + var attributes = property.GetCustomAttributes(false); - if (property.TryGetCustomAttribute(out var listAttr)) + foreach (var attr in attributes) { - RegisterAttributeOptionList(type, listAttr, property, pluginInfo); + if (attr is ModdedOptionAttribute moddedAttr) + { + RegisterAttributeOption(type, moddedAttr, property, pluginInfo, propType, attributes); + break; + } + + if (attr is ModdedOptionListAttribute listAttr) + { + RegisterAttributeOptionList(type, listAttr, property, pluginInfo, propType, attributes); + break; + } } } + if (!pluginInfo.DebugMode) + return true; + foreach (var field in type.GetFields(MiraPluginManager.DeclaredInstanceMembers) .Where(f => !MiraPluginManager.IsAutoPropertyBackingField(f) && (f.FieldType.IsAssignableTo(typeof(IModdedOption)) || f.FieldType.IsAssignableTo(typeof(IModdedOptionList)))))