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 AlaCarte v1.6.0
AlaCarte.dll
Decompiled 4 months agousing System; using System.Collections.Generic; using System.Diagnostics; 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 UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("AlaCarte")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("AlaCarte")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("33773053-20a8-4803-8b21-1f2ac61ef480")] [assembly: AssemblyFileVersion("1.6.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.6.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 ComfyLib { 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, 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, acceptableValues, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = null, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } 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>)(object)((SettingChangedEventArgs)eventArgs).ChangedSetting); }; } } 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; } } } namespace AlaCarte { [BepInPlugin("redseiko.valheim.alacarte", "AlaCarte", "1.6.0")] public sealed class AlaCarte : BaseUnityPlugin { public const string PluginGuid = "redseiko.valheim.alacarte"; public const string PluginName = "AlaCarte"; public const string PluginVersion = "1.6.0"; private void Awake() { PluginConfig.BindConfig(((BaseUnityPlugin)this).Config); if (PluginConfig.IsModEnabled.Value) { Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.alacarte"); } } } public sealed class MenuDialogDragger : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler { public RectTransform MenuRectTransform; private Vector2 _lastMousePosition; public event EventHandler<Vector3> OnMenuDragEnd; public void OnBeginDrag(PointerEventData eventData) { //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) _lastMousePosition = eventData.position; if (!PluginConfig.MenuDialogCanDragPanel.Value) { eventData.pointerDrag = null; } } public void OnDrag(PointerEventData eventData) { //IL_0001: 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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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) Vector2 val = eventData.position - _lastMousePosition; RectTransform menuRectTransform = MenuRectTransform; ((Transform)menuRectTransform).position = ((Transform)menuRectTransform).position + new Vector3(val.x, val.y, 0f); _lastMousePosition = eventData.position; } public void OnEndDrag(PointerEventData eventData) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) this.OnMenuDragEnd?.Invoke(this, Vector2.op_Implicit(MenuRectTransform.anchoredPosition)); } } public static class PluginConfig { public enum DialogType { Vanilla, Old } public static ConfigEntry<bool> IsModEnabled { get; private set; } public static ConfigEntry<DialogType> MenuDialogType { get; private set; } public static ConfigEntry<Vector2> MenuDialogPosition { get; private set; } public static ConfigEntry<bool> MenuDialogCanDragPanel { get; private set; } public static ConfigEntry<bool> DisableGamePauseOnMenu { get; private set; } public static void BindConfig(ConfigFile config) { //IL_0057: 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 (restart required)."); MenuDialogType = config.BindInOrder("MenuDialog", "menuDialogType", DialogType.Vanilla, "Which Menu.m_menuDialog GameObject to display."); MenuDialogPosition = config.BindInOrder<Vector2>("MenuDialog", "menuDialogPosition", new Vector2(0f, 212f), "Menu.m_menuDialog.position"); MenuDialogCanDragPanel = config.BindInOrder("MenuDialog", "menuDialogCanDragPanel", defaultValue: true, "If enabled, Menu.m_menuDialog can be moved using mouse drag-and-drop."); DisableGamePauseOnMenu = config.BindInOrder("Pause", "disableGamePauseOnMenu", defaultValue: false, "Disables the Game 'pause' effect when the Menu is shown."); } } public static class MenuUtils { private static UIGroupHandler _menuUIGroupDefaultHandler; private static GameObject _handlerDefaultElementVanilla; private static GameObject _handlerDefaultElementOld; public static RectTransform MenuDialogVanilla { get; private set; } public static RectTransform MenuDialogOld { get; private set; } public static void SetupMenuDialogs(Menu menu) { SetupMenuDialogVanilla(((Component)menu.m_menuDialog).GetComponent<RectTransform>()); SetupMenuDialogOld(((Component)menu.m_root.Find("OLD_menu")).GetComponent<RectTransform>()); _menuUIGroupDefaultHandler = ((Component)menu.m_root).GetComponentInChildren<UIGroupHandler>(); _handlerDefaultElementVanilla = _menuUIGroupDefaultHandler.m_defaultElement; _handlerDefaultElementOld = ((Component)((Transform)MenuDialogOld).Find("Button_close")).gameObject; } public static void SetupMenuDialogVanilla(RectTransform menuTransform) { MenuDialogVanilla = menuTransform; ((Graphic)((Component)((Transform)menuTransform).Find("darken")).GetComponent<Image>()).raycastTarget = false; Transform val = ((Transform)menuTransform).Find("ornament"); MenuDialogDragger menuDialogDragger = default(MenuDialogDragger); if (!((Component)val).TryGetComponent<MenuDialogDragger>(ref menuDialogDragger)) { menuDialogDragger = ((Component)val).gameObject.AddComponent<MenuDialogDragger>(); menuDialogDragger.MenuRectTransform = menuTransform; menuDialogDragger.OnMenuDragEnd += OnMenuDialogEndDrag; } } public static void SetupMenuDialogOld(RectTransform menuTransform) { MenuDialogOld = menuTransform; MenuDialogDragger menuDialogDragger = default(MenuDialogDragger); if (!((Component)menuTransform).TryGetComponent<MenuDialogDragger>(ref menuDialogDragger)) { menuDialogDragger = ((Component)menuTransform).gameObject.AddComponent<MenuDialogDragger>(); menuDialogDragger.MenuRectTransform = menuTransform; menuDialogDragger.OnMenuDragEnd += OnMenuDialogEndDrag; } } private static void OnMenuDialogEndDrag(object sender, Vector3 position) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) PluginConfig.MenuDialogPosition.Value = Vector2.op_Implicit(position); } public static void ShowMenuDialog(Menu menu) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) RectTransform menuDialogByType = GetMenuDialogByType(PluginConfig.MenuDialogType.Value); if ((Object)(object)menu.m_menuDialog != (Object)(object)menuDialogByType) { ((Component)menu.m_menuDialog).gameObject.SetActive(false); menu.m_menuDialog = (Transform)(object)menuDialogByType; } menuDialogByType.anchoredPosition = PluginConfig.MenuDialogPosition.Value; _menuUIGroupDefaultHandler.m_defaultElement = GetHandlerDefaultElementByType(PluginConfig.MenuDialogType.Value); } public static RectTransform GetMenuDialogByType(PluginConfig.DialogType dialogType) { return (RectTransform)(dialogType switch { PluginConfig.DialogType.Vanilla => MenuDialogVanilla, PluginConfig.DialogType.Old => MenuDialogOld, _ => throw new NotImplementedException($"DialogType {dialogType:F} not supported."), }); } private static GameObject GetHandlerDefaultElementByType(PluginConfig.DialogType dialogType) { return (GameObject)(dialogType switch { PluginConfig.DialogType.Vanilla => _handlerDefaultElementVanilla, PluginConfig.DialogType.Old => _handlerDefaultElementOld, _ => throw new NotImplementedException($"DialogType {dialogType:F} not supported."), }); } } [HarmonyPatch(typeof(Game))] internal static class GamePatch { [HarmonyPostfix] [HarmonyPatch("Pause")] private static void PausePostfix() { if (PluginConfig.IsModEnabled.Value && PluginConfig.DisableGamePauseOnMenu.Value) { Game.m_pause = false; } } } [HarmonyPatch(typeof(Menu))] internal static class MenuPatch { [HarmonyPostfix] [HarmonyPatch("Start")] private static void StartPostfix(Menu __instance) { MenuUtils.SetupMenuDialogs(__instance); } [HarmonyPrefix] [HarmonyPatch("Show")] private static void ShowPrefix(Menu __instance) { MenuUtils.ShowMenuDialog(__instance); } [HarmonyPrefix] [HarmonyPatch("UpdateNavigation")] private static bool UpdateNavigationPrefix(Menu __instance) { if ((Object)(object)__instance.m_menuDialog == (Object)(object)MenuUtils.MenuDialogOld) { return false; } return true; } } }