using 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.5.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.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>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
};
}
}
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 sealed class PanelDragger : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler
{
public RectTransform TargetRectTransform;
private Vector2 _lastMousePosition;
public event EventHandler<Vector3> OnPanelEndDrag;
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;
}
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 targetRectTransform = TargetRectTransform;
((Transform)targetRectTransform).position = ((Transform)targetRectTransform).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.OnPanelEndDrag?.Invoke(this, Vector2.op_Implicit(TargetRectTransform.anchoredPosition));
}
}
}
namespace AlaCarte
{
[BepInPlugin("redseiko.valheim.alacarte", "AlaCarte", "1.5.0")]
public sealed class AlaCarte : BaseUnityPlugin
{
public const string PluginGuid = "redseiko.valheim.alacarte";
public const string PluginName = "AlaCarte";
public const string PluginVersion = "1.5.0";
private void Awake()
{
PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
if (PluginConfig.IsModEnabled.Value)
{
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.alacarte");
}
}
}
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;
PanelDragger panelDragger = ((Component)((Transform)menuTransform).Find("ornament")).gameObject.AddComponent<PanelDragger>();
panelDragger.TargetRectTransform = menuTransform;
panelDragger.OnPanelEndDrag += OnMenuDialogEndDrag;
}
public static void SetupMenuDialogOld(RectTransform menuTransform)
{
MenuDialogOld = menuTransform;
PanelDragger panelDragger = ((Component)menuTransform).gameObject.AddComponent<PanelDragger>();
panelDragger.TargetRectTransform = menuTransform;
panelDragger.OnPanelEndDrag += 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(),
});
}
private static GameObject GetHandlerDefaultElementByType(PluginConfig.DialogType dialogType)
{
return (GameObject)(dialogType switch
{
PluginConfig.DialogType.Vanilla => _handlerDefaultElementVanilla,
PluginConfig.DialogType.Old => _handlerDefaultElementOld,
_ => null,
});
}
}
[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;
}
}
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> 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");
DisableGamePauseOnMenu = config.BindInOrder("Pause", "disableGamePauseOnMenu", defaultValue: false, "Disables the Game 'pause' effect when the Menu is shown.");
}
}
}