Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of StatusQuo v1.0.0
StatusQuo.dll
Decompiled 8 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using ComfyLib; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("StatusQuo")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("StatusQuo")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("27d29148-22fd-44ec-86d4-3fc6015dc4f8")] [assembly: AssemblyFileVersion("1.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace StatusQuo { public static class PluginConfig { public static ConfigEntry<bool> IsModEnabled { get; private set; } public static ConfigEntry<Vector2> StatusEffectListRectPosition { get; private set; } public static ConfigEntry<int> StatusEffectMaxRows { get; private set; } public static ConfigEntry<Vector2> StatusEffectRectSizeDelta { get; private set; } public static ConfigEntry<Color> StatusEffectBackgroundColor { get; private set; } public static ConfigEntry<Color> StatusEffectNameFontColor { get; private set; } public static ConfigEntry<float> StatusEffectNameFontSize { get; private set; } public static ConfigEntry<bool> StatusEffectNameFontAutoSizing { get; private set; } public static ConfigEntry<TextOverflowModes> StatusEffectNameTextOverflowMode { get; set; } public static ConfigEntry<TextWrappingModes> StatusEffectNameTextWrappingMode { get; set; } public static ConfigEntry<Color> StatusEffectTimeFontColor { get; private set; } public static ConfigEntry<float> StatusEffectTimeFontSize { get; private set; } public static ConfigEntry<bool> StatusEffectTimeFontAutoSizing { get; private set; } public static ConfigEntry<TextOverflowModes> StatusEffectTimeTextOverflowMode { get; private set; } public static ConfigEntry<TextWrappingModes> StatusEffectTimeTextWrappingMode { get; private set; } public static void BindConfig(ConfigFile config) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod."); IsModEnabled.OnSettingChanged<bool>(HudUtils.ToggleHudSetup); StatusEffectListRectPosition = config.BindInOrder<Vector2>("StatusEffectList", "rectPosition", new Vector2(-250f, -40f), "StatusEffectListRoot<RectTransform>.anchoredPosition value."); StatusEffectListRectPosition.OnSettingChanged<Vector2>(HandleStatusEffectListConfigChange); StatusEffectMaxRows = config.BindInOrder("StatusEffect", "maxRows", 8, "StatusEffect max-rows per column; if 0, then max-rows is unlimited.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20)); StatusEffectMaxRows.OnSettingChanged<int>(HandleStatusEffectConfigChange); StatusEffectRectSizeDelta = config.BindInOrder<Vector2>("StatusEffect", "rectSizeDelta", new Vector2(225f, 30f), "StatusEffect<RectTransform>.sizeDelta value."); StatusEffectRectSizeDelta.OnSettingChanged<Vector2>(HandleStatusEffectConfigChange); StatusEffectBackgroundColor = config.BindInOrder<Color>("StatusEffect", "backgroundColor", new Color(0f, 0f, 0f, 0.3f), "StatusEffect<Image>.color value."); StatusEffectBackgroundColor.OnSettingChanged<Color>(HandleStatusEffectConfigChange); StatusEffectNameFontColor = config.BindInOrder<Color>("StatusEffect.Name", "fontColor", Color.white, "StatusEffect.Name<TextMeshProUGUI>.color value."); StatusEffectNameFontColor.OnSettingChanged<Color>(HandleStatusEffectConfigChange); StatusEffectNameFontSize = config.BindInOrder("StatusEffect.Name", "fontSize", 16f, "StatusEffect.Name<TextMeshProUGUI>.fontSize value.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 48f)); StatusEffectNameFontSize.OnSettingChanged<float>(HandleStatusEffectConfigChange); StatusEffectNameFontAutoSizing = config.BindInOrder("StatusEffect.Name", "fontAutoSizing", defaultValue: false, "StatusEffect.Name<TextMeshProUGUI>.enableAutoSizing value."); StatusEffectNameFontAutoSizing.OnSettingChanged<bool>(HandleStatusEffectConfigChange); StatusEffectNameTextOverflowMode = config.BindInOrder<TextOverflowModes>("StatusEffect.Name", "textOverflowMode", (TextOverflowModes)1, "StatusEffect.Name<TextMeshProUGUI>.overflowMode value.", (AcceptableValueBase)(object)new AcceptableValueEnumList<TextOverflowModes>((TextOverflowModes)1, default(TextOverflowModes), (TextOverflowModes)3)); StatusEffectNameTextOverflowMode.OnSettingChanged<TextOverflowModes>(HandleStatusEffectConfigChange); StatusEffectNameTextWrappingMode = config.BindInOrder<TextWrappingModes>("StatusEffect.Name", "textWrappingMode", (TextWrappingModes)1, "StatusEffect.Name<TextMeshProUGUI>.textWrappingMode value.", (AcceptableValueBase)(object)new AcceptableValueEnumList<TextWrappingModes>((TextWrappingModes)1, default(TextWrappingModes))); StatusEffectNameTextWrappingMode.OnSettingChanged<TextWrappingModes>(HandleStatusEffectConfigChange); StatusEffectTimeFontColor = config.BindInOrder<Color>("StatusEffect.Time", "fontColor", new Color(1f, 0.717f, 0.36f, 1f), "StatusEffect.Time<TextMeshProUGUI>.color value."); StatusEffectTimeFontColor.OnSettingChanged<Color>(HandleStatusEffectConfigChange); StatusEffectTimeFontSize = config.BindInOrder("StatusEffect.Time", "fontSize", 18f, "StatusEffect.Time<TextMeshProUGUI>.fontSize value.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 48f)); StatusEffectTimeFontSize.OnSettingChanged<float>(HandleStatusEffectConfigChange); StatusEffectTimeFontAutoSizing = config.BindInOrder("StatusEffect.Time", "fontAutoSizing", defaultValue: false, "StatusEffect.Time<TextMeshProUGUI>.enableAutoSizing value."); StatusEffectTimeFontAutoSizing.OnSettingChanged<bool>(HandleStatusEffectConfigChange); StatusEffectTimeTextOverflowMode = config.BindInOrder<TextOverflowModes>("StatusEffect.Time", "textOverflowMode", (TextOverflowModes)0, "StatusEffect.Time<TextMeshProUGUI>.overflowMode value.", (AcceptableValueBase)(object)new AcceptableValueEnumList<TextOverflowModes>((TextOverflowModes)1, default(TextOverflowModes), (TextOverflowModes)3)); StatusEffectTimeTextOverflowMode.OnSettingChanged<TextOverflowModes>(HandleStatusEffectConfigChange); StatusEffectTimeTextWrappingMode = config.BindInOrder<TextWrappingModes>("StatusEffect.Time", "textWrappingMode", (TextWrappingModes)0, "StatusEffect.Time<TextMeshProUGUI>.textWrappingMode value.", (AcceptableValueBase)(object)new AcceptableValueEnumList<TextWrappingModes>((TextWrappingModes)1, default(TextWrappingModes))); StatusEffectTimeTextWrappingMode.OnSettingChanged<TextWrappingModes>(HandleStatusEffectConfigChange); } private static void HandleStatusEffectListConfigChange() { if (IsModEnabled.Value && Object.op_Implicit((Object)(object)Hud.m_instance)) { HudUtils.SetupStatusEffectListRoot(Hud.m_instance, toggleOn: true); } } private static void HandleStatusEffectConfigChange() { if (IsModEnabled.Value && Object.op_Implicit((Object)(object)Hud.m_instance)) { HudUtils.SetupStatusEffects(Hud.m_instance); } } } public static class HudUtils { public static void ToggleHudSetup(bool toggleOn) { if (!Object.op_Implicit((Object)(object)Hud.m_instance)) { return; } SetupStatusEffectListRoot(Hud.m_instance, toggleOn); foreach (RectTransform statusEffect in Hud.m_instance.m_statusEffects) { Object.Destroy((Object)(object)((Component)statusEffect).gameObject); } Hud.m_instance.m_statusEffects.Clear(); } public static void SetupStatusEffectListRoot(Hud hud, bool toggleOn) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) hud.m_statusEffectListRoot.SetAnchorMin(Vector2.one).SetAnchorMax(Vector2.one).SetPivot(Vector2.one); if (toggleOn) { hud.m_statusEffectListRoot.SetSizeDelta(Vector2.zero).SetPosition(PluginConfig.StatusEffectListRectPosition.Value); } else { hud.m_statusEffectListRoot.SetSizeDelta(new Vector2(431.47f, 55f)).SetPosition(new Vector2(-271f, -45f)); } } public static void SetupStatusEffects(Hud hud) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) Vector2 value = PluginConfig.StatusEffectRectSizeDelta.Value; float y = value.y; int num = ((PluginConfig.StatusEffectMaxRows.Value > 0) ? PluginConfig.StatusEffectMaxRows.Value : int.MaxValue); int num2 = 0; int num3 = 0; List<RectTransform> statusEffects = hud.m_statusEffects; int i = 0; for (int count = statusEffects.Count; i < count; i++) { RectTransform obj = statusEffects[i]; SetupEffect(obj, value, num2, num3); SetupEffectName(((Transform)obj).Find("Name"), y); SetupEffectCooldown(((Transform)obj).Find("Cooldown"), y); SetupEffectIcon(((Transform)obj).Find("Icon"), y); SetupEffectTime(((Transform)obj).Find("TimeText")); num2++; if (num2 >= num) { num2 = 0; num3++; } } } private static void SetupEffect(RectTransform effectRectTransform, Vector2 sizeDelta, int row, int column) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) effectRectTransform.SetAnchorMin(Vector2.up).SetAnchorMax(Vector2.up).SetPivot(Vector2.one) .SetSizeDelta(sizeDelta) .SetPosition(new Vector2((float)column * (0f - sizeDelta.x - 5f), (float)row * (0f - sizeDelta.y - 2.5f))); Image image = default(Image); if (!((Component)effectRectTransform).gameObject.TryGetComponent<Image>(ref image)) { image = ((Component)effectRectTransform).gameObject.AddComponent<Image>(); } image.SetSprite(UIResources.GetSprite("UISprite")).SetType((Type)1).SetColor(PluginConfig.StatusEffectBackgroundColor.Value); } private static void SetupEffectName(Transform nameTransform, float height) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) ((Component)nameTransform).GetComponent<RectTransform>().SetAnchorMin(Vector2.zero).SetAnchorMax(Vector2.one) .SetPivot(new Vector2(0f, 0.5f)) .SetSizeDelta(new Vector2(0f - height - 15f - 50f, 0f)) .SetPosition(new Vector2(height + 15f, 0f)); ((Component)nameTransform).GetComponent<TextMeshProUGUI>().SetAlignment<TextMeshProUGUI>((TextAlignmentOptions)513).SetColor<TextMeshProUGUI>(PluginConfig.StatusEffectNameFontColor.Value) .SetEnableAutoSizing<TextMeshProUGUI>(PluginConfig.StatusEffectNameFontAutoSizing.Value) .SetOverflowMode<TextMeshProUGUI>(PluginConfig.StatusEffectNameTextOverflowMode.Value) .SetTextWrappingMode<TextMeshProUGUI>(PluginConfig.StatusEffectNameTextWrappingMode.Value) .SetFontSizeMin<TextMeshProUGUI>(8f) .SetFontSizeMax<TextMeshProUGUI>(PluginConfig.StatusEffectNameFontSize.Value) .SetFontSize<TextMeshProUGUI>(PluginConfig.StatusEffectNameFontSize.Value); } private static void SetupEffectCooldown(Transform cooldownTransform, float height) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) ((Component)cooldownTransform).GetComponent<RectTransform>().SetAnchorMin(new Vector2(0f, 0.5f)).SetAnchorMax(new Vector2(0f, 0.5f)) .SetPivot(new Vector2(0.5f, 0.5f)) .SetSizeDelta(new Vector2(height, height)) .SetPosition(new Vector2(height / 2f + 5f, 0f)); ((Component)cooldownTransform).GetComponent<Image>().SetPreserveAspect(preserveAspect: true); } private static void SetupEffectIcon(Transform iconTransform, float height) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) ((Component)iconTransform).GetComponent<RectTransform>().SetAnchorMin(new Vector2(0f, 0.5f)).SetAnchorMax(new Vector2(0f, 0.5f)) .SetPivot(new Vector2(0.5f, 0.5f)) .SetSizeDelta(new Vector2(height, height)) .SetPosition(new Vector2(height / 2f + 5f, 0f)); ((Component)iconTransform).GetComponent<Image>().SetPreserveAspect(preserveAspect: true); } private static void SetupEffectTime(Transform timeTransform) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) ((Component)timeTransform).GetComponent<RectTransform>().SetAnchorMin(Vector2.zero).SetAnchorMax(Vector2.one) .SetPivot(new Vector2(0f, 0.5f)) .SetSizeDelta(new Vector2(-10f, 0f)) .SetPosition(Vector2.zero); ((Component)timeTransform).GetComponent<TextMeshProUGUI>().SetAlignment<TextMeshProUGUI>((TextAlignmentOptions)516).SetColor<TextMeshProUGUI>(PluginConfig.StatusEffectTimeFontColor.Value) .SetEnableAutoSizing<TextMeshProUGUI>(PluginConfig.StatusEffectTimeFontAutoSizing.Value) .SetOverflowMode<TextMeshProUGUI>(PluginConfig.StatusEffectTimeTextOverflowMode.Value) .SetTextWrappingMode<TextMeshProUGUI>(PluginConfig.StatusEffectTimeTextWrappingMode.Value) .SetFontSizeMin<TextMeshProUGUI>(8f) .SetFontSizeMax<TextMeshProUGUI>(PluginConfig.StatusEffectTimeFontSize.Value) .SetFontSize<TextMeshProUGUI>(PluginConfig.StatusEffectTimeFontSize.Value); } } [HarmonyPatch(typeof(Hud))] internal static class HudPatch { [HarmonyPostfix] [HarmonyPatch("Awake")] private static void AwakePostfix(Hud __instance) { if (PluginConfig.IsModEnabled.Value) { HudUtils.SetupStatusEffectListRoot(__instance, toggleOn: true); } } [HarmonyPrefix] [HarmonyPatch("UpdateStatusEffects")] private static void UpdateStatusEffectsPrefix(Hud __instance, List<StatusEffect> statusEffects, ref bool __state) { __state = PluginConfig.IsModEnabled.Value && __instance.m_statusEffects.Count != statusEffects.Count; } [HarmonyPostfix] [HarmonyPatch("UpdateStatusEffects")] private static void UpdateStatusEffectsPostfix(Hud __instance, bool __state) { if (__state) { HudUtils.SetupStatusEffects(__instance); } } } [BepInPlugin("redseiko.valheim.statusquo", "StatusQuo", "1.0.0")] [BepInIncompatibility("randyknapp.mods.minimalstatuseffects")] public sealed class StatusQuo : BaseUnityPlugin { public const string PluginGuid = "redseiko.valheim.statusquo"; public const string PluginName = "StatusQuo"; public const string PluginVersion = "1.0.0"; private void Awake() { PluginConfig.BindConfig(((BaseUnityPlugin)this).Config); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.statusquo"); } } } namespace ComfyLib { public sealed class AcceptableValueEnumList<T> : AcceptableValueBase where T : Enum { public T[] AcceptableValues { get; } public AcceptableValueEnumList(params T[] acceptableValues) : base(typeof(T)) { if (acceptableValues == null) { throw new ArgumentNullException("acceptableValues"); } if (acceptableValues.Length == 0) { throw new ArgumentException("At least one acceptable value is needed.", "acceptableValues"); } AcceptableValues = acceptableValues; } public override object Clamp(object value) { if (((AcceptableValueBase)this).IsValid(value)) { return value; } return AcceptableValues[0]; } public override bool IsValid(object value) { if (!(value is T)) { return false; } for (int i = 0; i < AcceptableValues.Length; i++) { if (AcceptableValues[i].Equals(value)) { return true; } } return false; } public override string ToDescriptionString() { return "# Acceptable values: " + string.Join(", ", AcceptableValues.Select(GetEnumName)); } public string GetEnumName(T value) { return Enum.GetName(typeof(T), value); } } public static class ConfigFileExtensions { internal sealed class ConfigurationManagerAttributes { public Action<ConfigEntryBase> CustomDrawer; public bool? Browsable; public bool? HideDefaultButton; public bool? HideSettingName; public bool? IsAdvanced; public int? Order; public bool? ReadOnly; } private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>(); private static int GetSettingOrder(string section) { if (!_sectionToSettingOrder.TryGetValue(section, out var value)) { value = 0; } _sectionToSettingOrder[section] = value - 1; return value; } public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1] { new ConfigurationManagerAttributes { Order = GetSettingOrder(section) } })); } public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = customDrawer, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler) { configEntry.SettingChanged += delegate { settingChangedHandler(); }; } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue); }; } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((ConfigEntry<T>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue); }; } } public static class ComponentExtensions { public static bool TryGetComponentInChildren<T>(this Component rootComponent, out T component) where T : Component { component = rootComponent.GetComponentInChildren<T>(true); return Object.op_Implicit((Object)(object)component); } } public static class ObjectExtensions { public static T FirstByNameOrThrow<T>(this T[] unityObjects, string name) where T : Object { foreach (T val in unityObjects) { if (((Object)val).name == name) { return val; } } throw new InvalidOperationException($"Could not find Unity object of type {typeof(T)} with name: {name}"); } public static T Ref<T>(this T unityObject) where T : Object { if (!Object.op_Implicit((Object)(object)unityObject)) { return default(T); } return unityObject; } } public static class CanvasGroupExtensions { public static CanvasGroup SetAlpha(this CanvasGroup canvasGroup, float alpha) { canvasGroup.alpha = alpha; return canvasGroup; } public static CanvasGroup SetBlocksRaycasts(this CanvasGroup canvasGroup, bool blocksRaycasts) { canvasGroup.blocksRaycasts = blocksRaycasts; return canvasGroup; } } public static class ColorExtensions { public static Color SetAlpha(this Color color, float alpha) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) color.a = alpha; return color; } } public static class ContentSizeFitterExtensions { public static ContentSizeFitter SetHorizontalFit(this ContentSizeFitter fitter, FitMode fitMode) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) fitter.horizontalFit = fitMode; return fitter; } public static ContentSizeFitter SetVerticalFit(this ContentSizeFitter fitter, FitMode fitMode) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) fitter.verticalFit = fitMode; return fitter; } } public static class LayoutGroupExtensions { public static T SetChildAlignment<T>(this T layoutGroup, TextAnchor alignment) where T : HorizontalOrVerticalLayoutGroup { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((LayoutGroup)(object)layoutGroup).childAlignment = alignment; return layoutGroup; } public static T SetChildControl<T>(this T layoutGroup, bool? width = null, bool? height = null) where T : HorizontalOrVerticalLayoutGroup { if (!width.HasValue && !height.HasValue) { throw new ArgumentException("Value for width or height must be provided."); } if (width.HasValue) { ((HorizontalOrVerticalLayoutGroup)layoutGroup).childControlWidth = width.Value; } if (height.HasValue) { ((HorizontalOrVerticalLayoutGroup)layoutGroup).childControlHeight = height.Value; } return layoutGroup; } public static T SetChildForceExpand<T>(this T layoutGroup, bool? width = null, bool? height = null) where T : HorizontalOrVerticalLayoutGroup { if (!width.HasValue && !height.HasValue) { throw new ArgumentException("Value for width or height must be provided."); } if (width.HasValue) { ((HorizontalOrVerticalLayoutGroup)layoutGroup).childForceExpandWidth = width.Value; } if (height.HasValue) { ((HorizontalOrVerticalLayoutGroup)layoutGroup).childForceExpandHeight = height.Value; } return layoutGroup; } public static T SetPadding<T>(this T layoutGroup, int? left = null, int? right = null, int? top = null, int? bottom = null) where T : HorizontalOrVerticalLayoutGroup { if (!left.HasValue && !right.HasValue && !top.HasValue && !bottom.HasValue) { throw new ArgumentException("Value for left, right, top or bottom must be provided."); } if (left.HasValue) { ((LayoutGroup)(object)layoutGroup).padding.left = left.Value; } if (right.HasValue) { ((LayoutGroup)(object)layoutGroup).padding.right = right.Value; } if (top.HasValue) { ((LayoutGroup)(object)layoutGroup).padding.top = top.Value; } if (bottom.HasValue) { ((LayoutGroup)(object)layoutGroup).padding.bottom = bottom.Value; } return layoutGroup; } public static T SetSpacing<T>(this T layoutGroup, float spacing) where T : HorizontalOrVerticalLayoutGroup { ((HorizontalOrVerticalLayoutGroup)layoutGroup).spacing = spacing; return layoutGroup; } } public static class ImageExtensions { public static Image SetColor(this Image image, Color color) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) ((Graphic)image).color = color; return image; } public static Image SetFillAmount(this Image image, float amount) { image.fillAmount = amount; return image; } public static Image SetFillCenter(this Image image, bool fillCenter) { image.fillCenter = fillCenter; return image; } public static Image SetFillMethod(this Image image, FillMethod fillMethod) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) image.fillMethod = fillMethod; return image; } public static Image SetFillOrigin(this Image image, OriginHorizontal origin) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected I4, but got Unknown image.fillOrigin = (int)origin; return image; } public static Image SetFillOrigin(this Image image, OriginVertical origin) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected I4, but got Unknown image.fillOrigin = (int)origin; return image; } public static Image SetMaskable(this Image image, bool maskable) { ((MaskableGraphic)image).maskable = maskable; return image; } public static Image SetMaterial(this Image image, Material material) { ((Graphic)image).material = material; return image; } public static Image SetPixelsPerUnitMultiplier(this Image image, float pixelsPerUnitMultiplier) { image.pixelsPerUnitMultiplier = pixelsPerUnitMultiplier; return image; } public static Image SetPreserveAspect(this Image image, bool preserveAspect) { image.preserveAspect = preserveAspect; return image; } public static Image SetRaycastTarget(this Image image, bool raycastTarget) { ((Graphic)image).raycastTarget = raycastTarget; return image; } public static Image SetSprite(this Image image, Sprite sprite) { image.sprite = sprite; return image; } public static Image SetType(this Image image, Type type) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) image.type = type; return image; } } public static class LayoutElementExtensions { public static LayoutElement SetFlexible(this LayoutElement layoutElement, float? width = null, float? height = null) { if (!width.HasValue && !height.HasValue) { throw new ArgumentException("Value for width or height must be provided."); } if (width.HasValue) { layoutElement.flexibleWidth = width.Value; } if (height.HasValue) { layoutElement.flexibleHeight = height.Value; } return layoutElement; } public static LayoutElement SetIgnoreLayout(this LayoutElement layoutElement, bool ignoreLayout) { layoutElement.ignoreLayout = ignoreLayout; return layoutElement; } public static LayoutElement SetMinimum(this LayoutElement layoutElement, float? width = null, float? height = null) { if (!width.HasValue && !height.HasValue) { throw new ArgumentException("Value for width or height must be provided."); } if (width.HasValue) { layoutElement.minWidth = width.Value; } if (height.HasValue) { layoutElement.minHeight = height.Value; } return layoutElement; } public static LayoutElement SetPreferred(this LayoutElement layoutElement, float? width = null, float? height = null) { if (!width.HasValue && !height.HasValue) { throw new ArgumentException("Value for width or height must be provided."); } if (width.HasValue) { layoutElement.preferredWidth = width.Value; } if (height.HasValue) { layoutElement.preferredHeight = height.Value; } return layoutElement; } } public static class RectMask2DExtensions { public static RectMask2D SetSoftness(this RectMask2D rectMask2d, Vector2Int softness) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectMask2d.softness = softness; return rectMask2d; } } public static class RectTransformExtensions { public static RectTransform OffsetPosition(this RectTransform rectTransform, Vector2 offset) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) rectTransform.anchoredPosition += offset; return rectTransform; } public static RectTransform OffsetSizeDelta(this RectTransform rectTransform, Vector2 offset) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) rectTransform.sizeDelta += offset; return rectTransform; } public static RectTransform SetAnchorMin(this RectTransform rectTransform, Vector2 anchorMin) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectTransform.anchorMin = anchorMin; return rectTransform; } public static RectTransform SetAnchorMax(this RectTransform rectTransform, Vector2 anchorMax) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectTransform.anchorMax = anchorMax; return rectTransform; } public static RectTransform SetPivot(this RectTransform rectTransform, Vector2 pivot) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectTransform.pivot = pivot; return rectTransform; } public static RectTransform SetPosition(this RectTransform rectTransform, Vector2 position) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectTransform.anchoredPosition = position; return rectTransform; } public static RectTransform SetSizeDelta(this RectTransform rectTransform, Vector2 sizeDelta) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) rectTransform.sizeDelta = sizeDelta; return rectTransform; } } public static class SelectableExtensions { public static T SetColors<T>(this T selectable, ColorBlock colors) where T : Selectable { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Selectable)selectable).colors = colors; return selectable; } public static T SetImage<T>(this T selectable, Image image) where T : Selectable { ((Selectable)selectable).image = image; return selectable; } public static T SetInteractable<T>(this T selectable, bool interactable) where T : Selectable { ((Selectable)selectable).interactable = interactable; return selectable; } public static T SetSpriteState<T>(this T selectable, SpriteState spriteState) where T : Selectable { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Selectable)selectable).spriteState = spriteState; return selectable; } public static T SetTargetGraphic<T>(this T selectable, Graphic graphic) where T : Selectable { ((Selectable)selectable).targetGraphic = graphic; return selectable; } public static T SetTransition<T>(this T selectable, Transition transition) where T : Selectable { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Selectable)selectable).transition = transition; return selectable; } public static T SetNavigationMode<T>(this T selectable, Mode mode) where T : Selectable { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) Navigation navigation = ((Selectable)selectable).navigation; ((Navigation)(ref navigation)).mode = mode; ((Selectable)selectable).navigation = navigation; return selectable; } } public static class ShadowExtensions { public static Shadow SetEffectColor(this Shadow shadow, Color effectColor) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) shadow.effectColor = effectColor; return shadow; } public static Shadow SetEffectDistance(this Shadow shadow, Vector2 effectDistance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) shadow.effectDistance = effectDistance; return shadow; } } public static class ScrollRectExtensions { public static T SetContent<T>(this T scrollRect, RectTransform content) where T : ScrollRect { ((ScrollRect)scrollRect).content = content; return scrollRect; } public static T SetHorizontal<T>(this T scrollRect, bool horizontal) where T : ScrollRect { ((ScrollRect)scrollRect).horizontal = horizontal; return scrollRect; } public static T SetMovementType<T>(this T scrollRect, MovementType movementType) where T : ScrollRect { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((ScrollRect)scrollRect).movementType = movementType; return scrollRect; } public static T SetScrollSensitivity<T>(this T scrollRect, float sensitivity) where T : ScrollRect { ((ScrollRect)scrollRect).scrollSensitivity = sensitivity; return scrollRect; } public static T SetVertical<T>(this T scrollRect, bool vertical) where T : ScrollRect { ((ScrollRect)scrollRect).vertical = vertical; return scrollRect; } public static T SetVerticalScrollbar<T>(this T scrollRect, Scrollbar verticalScrollbar) where T : ScrollRect { ((ScrollRect)scrollRect).verticalScrollbar = verticalScrollbar; return scrollRect; } public static T SetVerticalScrollPosition<T>(this T scrollRect, float position) where T : ScrollRect { ((ScrollRect)scrollRect).verticalNormalizedPosition = position; return scrollRect; } public static T SetVerticalScrollbarVisibility<T>(this T scrollRect, ScrollbarVisibility visibility) where T : ScrollRect { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((ScrollRect)scrollRect).verticalScrollbarVisibility = visibility; return scrollRect; } public static T SetViewport<T>(this T scrollRect, RectTransform viewport) where T : ScrollRect { ((ScrollRect)scrollRect).viewport = viewport; return scrollRect; } } public static class TextMeshProExtensions { public static T SetAlignment<T>(this T tmpText, TextAlignmentOptions alignment) where T : TMP_Text { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((TMP_Text)tmpText).alignment = alignment; return tmpText; } public static T SetColor<T>(this T tmpText, Color color) where T : TMP_Text { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((Graphic)(object)tmpText).color = color; return tmpText; } public static T SetEnableAutoSizing<T>(this T tmpText, bool enableAutoSizing) where T : TMP_Text { ((TMP_Text)tmpText).enableAutoSizing = enableAutoSizing; return tmpText; } public static T SetFont<T>(this T tmpText, TMP_FontAsset font) where T : TMP_Text { ((TMP_Text)tmpText).font = font; return tmpText; } public static T SetFontSize<T>(this T tmpText, float fontSize) where T : TMP_Text { ((TMP_Text)tmpText).fontSize = fontSize; return tmpText; } public static T SetFontSizeMax<T>(this T tmpText, float fontSizeMax) where T : TMP_Text { ((TMP_Text)tmpText).fontSizeMax = fontSizeMax; return tmpText; } public static T SetFontSizeMin<T>(this T tmpText, float fontSizeMin) where T : TMP_Text { ((TMP_Text)tmpText).fontSizeMax = fontSizeMin; return tmpText; } public static T SetFontMaterial<T>(this T tmpText, Material fontMaterial) where T : TMP_Text { ((TMP_Text)tmpText).fontMaterial = fontMaterial; return tmpText; } public static T SetMargin<T>(this T tmpText, Vector4 margin) where T : TMP_Text { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((TMP_Text)tmpText).margin = margin; return tmpText; } public static T SetOverflowMode<T>(this T tmpText, TextOverflowModes overflowMode) where T : TMP_Text { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((TMP_Text)tmpText).overflowMode = overflowMode; return tmpText; } public static T SetRichText<T>(this T tmpText, bool richText) where T : TMP_Text { ((TMP_Text)tmpText).richText = richText; return tmpText; } public static T SetTextWrappingMode<T>(this T tmpText, TextWrappingModes textWrappingMode) where T : TMP_Text { //IL_0006: Unknown result type (might be due to invalid IL or missing references) ((TMP_Text)tmpText).textWrappingMode = textWrappingMode; return tmpText; } } public static class Texture2DExtensions { public static Texture2D SetFilterMode(this Texture2D texture, FilterMode filterMode) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) ((Texture)texture).filterMode = filterMode; return texture; } public static Texture2D SetWrapMode(this Texture2D texture, TextureWrapMode wrapMode) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) ((Texture)texture).wrapMode = wrapMode; return texture; } } public static class UIResources { public static readonly ResourceCache<Sprite> SpriteCache = new ResourceCache<Sprite>(); public static readonly ResourceCache<Material> MaterialCache = new ResourceCache<Material>(); public static Sprite GetSprite(string spriteName) { return SpriteCache.GetResource(spriteName); } public static Material GetMaterial(string materialName) { return MaterialCache.GetResource(materialName); } } public sealed class ResourceCache<T> where T : Object { private readonly Dictionary<string, T> _cache = new Dictionary<string, T>(); public T GetResource(string resourceName) { if (!_cache.TryGetValue(resourceName, out var value)) { value = Resources.FindObjectsOfTypeAll<T>().FirstByNameOrThrow(resourceName); _cache[resourceName] = value; } return value; } } }