using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using FMODUnity;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using VMM;
using VMM.ModRegistry;
using VMM.ModRegistry.Settings;
using VMM.ModRegistry.Settings.Types;
using VMM.Patches;
using VMM.UI;
using VMM.UI.Components;
using VMM.UI.Helpers;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "VigilModManager", "1.0.1", "Exil_S", "https://github.com/ExilProductions/VigilModManager")]
[assembly: MelonGame("Singularity Studios", "Vigil")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("VigilModManager")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8c15600fa98f431c8e9ada65c1d7a03e1e0bb9e7")]
[assembly: AssemblyProduct("VigilModManager")]
[assembly: AssemblyTitle("VigilModManager")]
[assembly: NeutralResourcesLanguage("en-US")]
[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 VMM
{
internal class Core : MelonMod
{
[CompilerGenerated]
private sealed class <HandleSceneLoad>d__5 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public int buildIndex;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <HandleSceneLoad>d__5(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
if (buildIndex != 0)
{
return false;
}
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if (UIManager.Instance != null)
{
UIManager.Instance = null;
}
UIManager.Instance = new UIManager();
UIManager.Instance.Initialize();
if (ModManager.Instance != null)
{
return false;
}
ModManager.Instance = new ModManager();
ModManager.Instance.LoadMods();
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static Instance _logger;
public static Instance Logger
{
get
{
if (_logger != null)
{
return _logger;
}
throw new Exception("Logger instance is not initialized yet.");
}
}
public override void OnInitializeMelon()
{
_logger = ((MelonBase)this).LoggerInstance;
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
MelonCoroutines.Start(HandleSceneLoad(buildIndex));
}
[IteratorStateMachine(typeof(<HandleSceneLoad>d__5))]
private IEnumerator HandleSceneLoad(int buildIndex)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <HandleSceneLoad>d__5(0)
{
buildIndex = buildIndex
};
}
public override void OnApplicationQuit()
{
Cleanup();
}
private void Cleanup()
{
_ = ModManager.Instance;
}
}
internal class ModInfo
{
public const string Name = "VigilModManager";
public const string Version = "1.0.1";
public const string Author = "Exil_S";
public const string DownloadLink = "https://github.com/ExilProductions/VigilModManager";
}
}
namespace VMM.UI
{
internal class UIManager
{
private RectTransform modsListTab;
private RectTransform modSettingsTab;
private RectTransform mainMenu;
private RectTransform mainMenuTitle;
private RectTransform modWindowRect;
private RectTransform modInfoWindowRect;
public static UIManager Instance { get; set; }
public UIManager()
{
if (Instance == null)
{
Instance = this;
}
else
{
Core.Logger.Warning("Duplicate UIManager Detected");
}
}
public void Initialize()
{
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
Core.Logger.Msg("Initializing UI...");
CacheUIReferences();
modsListTab = UIBuilder.CreateTab("Mods List", 700f, 500f);
SetupModsListTab();
modSettingsTab = UIBuilder.CreateTab("Mod Settings", 700f, 500f);
SetupModSettingsTab();
((Transform)mainMenuTitle).localScale = new Vector3(0.9f, 0.9f, 0.9f);
((Component)UIBuilder.CreateButton("Mods Button", mainMenu, "Mods", new UnityAction(OpenModsMenu))).transform.SetSiblingIndex(2);
Core.Logger.Msg("Created Mods Button.");
}
private void CacheUIReferences()
{
GameObject val = GameObject.Find("Canvas");
if ((Object)(object)val == (Object)null)
{
Core.Logger.Error("UIManager: Canvas not found in scene.");
return;
}
Transform val2 = val.transform.Find("Margins");
if ((Object)(object)val2 == (Object)null)
{
Core.Logger.Error("UIManager: Canvas/Margins not found.");
return;
}
Transform val3 = val2.Find("Main Menu");
if ((Object)(object)val3 == (Object)null)
{
Core.Logger.Error("UIManager: Main Menu not found under Canvas/Margins.");
return;
}
mainMenu = ((Component)val3).GetComponent<RectTransform>();
mainMenuTitle = ((Component)((Transform)mainMenu).Find("Title")).GetComponent<RectTransform>();
}
private void SetupModsListTab()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
RectTransform parent = UIBuilder.CreateHorizontalLayoutArea("Window Content", modsListTab, 100f, null, (TextAnchor)4, controlChildSize: false);
modWindowRect = UIBuilder.CreateWindow("Mods List Window", parent, "Installed Mods", out var _, 500f, new UnityAction(OpenMainMenu));
modInfoWindowRect = UIBuilder.CreateWindow("Mod Info Window", parent, "Mod Info", out var _, 500f, null);
RectTransform parent2 = UIBuilder.CreateVerticalLayoutArea("Content", modInfoWindowRect, 10f, null, (TextAnchor)4, controlChildSize: true, forceExpand: true);
UIBuilder.CreateText("Mod Name", parent2, "Name: N/A", Color.yellow, out var textMesh, 40);
((TMP_Text)textMesh).alignment = (TextAlignmentOptions)514;
UIBuilder.CreateText("Mod Author", parent2, "Author: N/A", Color.yellow, out var textMesh2, 40);
((TMP_Text)textMesh2).alignment = (TextAlignmentOptions)514;
UIBuilder.CreateText("Mod Version", parent2, "Version: N/A", Color.yellow, out var textMesh3, 40);
((TMP_Text)textMesh3).alignment = (TextAlignmentOptions)514;
Button component = ((Component)UIBuilder.CreateButton("Settings Button", parent2, "Settings", null)).GetComponent<Button>();
ModInfoDisplayer modInfoDisplayer = ((Component)modInfoWindowRect).gameObject.AddComponent<ModInfoDisplayer>();
modInfoDisplayer.modName = textMesh;
modInfoDisplayer.modAuthor = textMesh2;
modInfoDisplayer.modVersion = textMesh3;
modInfoDisplayer.settingsButton = component;
}
private void SetupModSettingsTab()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
TextMeshProUGUI titleText;
RectTransform parent = UIBuilder.CreateWindow("Settings Window", modSettingsTab, "Mod Settings", out titleText, 1000f, new UnityAction(OpenModsMenu));
RectTransform val = UIBuilder.CreateTab("Content", parent, 700f, 500f);
UIBuilder.CreateVerticalLayoutArea("Settings Container", val, 30f, null, (TextAnchor)1, controlChildSize: false);
ModSettingsManager modSettingsManager = ((Component)val).gameObject.AddComponent<ModSettingsManager>();
modSettingsManager.titleText = titleText;
modSettingsManager.Init();
}
public void AddModButton(ModEntry mod)
{
((Component)UIBuilder.CreateButton("Mod Button", modWindowRect, mod.Name, null)).gameObject.AddComponent<ModEntryButton>().mod = mod;
}
public void OpenSettings()
{
MainMenuManager.instance.OpenTab(((Component)modSettingsTab).gameObject);
}
public void OpenMainMenu()
{
MainMenuManager.instance.OpenTab(((Component)mainMenu).gameObject);
ModInfoDisplayer.Instance.HandleClose();
}
public void OpenModsMenu()
{
MainMenuManager.instance.OpenTab(((Component)modsListTab).gameObject);
}
}
}
namespace VMM.UI.Helpers
{
internal static class UIBuilder
{
private const string TABS_CONTAINER_PATH = "Canvas/Margins";
private const string BUTTON_PATH = "Canvas/Margins/Main Menu/Play Button";
private const string OPTIONS_PATH = "Canvas/Margins/Options";
private const string DIVIDER_PATH = "Canvas/Margins/Options/Divider";
private const string SLIDER_PATH = "Canvas/Margins/Options/Master Volume";
public static RectTransform CreateTab(string name, float x, float y)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
return null;
}
GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
val.transform.SetParent(GameObject.Find("Canvas/Margins").transform, false);
val.layer = LayerMask.NameToLayer("UI");
val.SetActive(false);
RectTransform component = val.GetComponent<RectTransform>();
component.sizeDelta = new Vector2(x, y);
return component;
}
public static RectTransform CreateTab(string name, RectTransform parent, float x, float y)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: 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)
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
return null;
}
GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
val.transform.SetParent((Transform)(object)parent, false);
val.layer = LayerMask.NameToLayer("UI");
RectTransform component = val.GetComponent<RectTransform>();
component.sizeDelta = new Vector2(x, y);
return component;
}
public static RectTransform CreateButton(string name, RectTransform parent, string buttonText, UnityAction callback)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
return null;
}
GameObject obj = Object.Instantiate<GameObject>(GameObject.Find("Canvas/Margins/Main Menu/Play Button"), (Transform)(object)parent);
((Object)obj).name = name;
Button component = obj.GetComponent<Button>();
component.onClick = new ButtonClickedEvent();
if (callback != null)
{
((UnityEvent)component.onClick).AddListener(callback);
}
((TMP_Text)((Component)obj.transform.Find("Selected Text")).GetComponent<TextMeshProUGUI>()).text = "[ " + buttonText + " ] ";
((TMP_Text)((Component)obj.transform.Find("Unselected Text")).GetComponent<TextMeshProUGUI>()).text = buttonText;
obj.AddComponent<UILayoutRebuilder>();
return obj.GetComponent<RectTransform>();
}
public static RectTransform CreateText(string name, RectTransform parent, string text, Color color, out TextMeshProUGUI textMesh, int fontSize = 14)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
textMesh = null;
return null;
}
GameObject obj = Object.Instantiate<GameObject>(GameObject.Find("Canvas/Margins/Main Menu/Play Button/Unselected Text"), (Transform)(object)parent);
((Object)obj).name = name;
Object.DestroyImmediate((Object)(object)obj.GetComponent<ContentSizeFitter>());
TextMeshProUGUI component = obj.GetComponent<TextMeshProUGUI>();
((TMP_Text)component).text = text;
if (color != Color.yellow)
{
((Graphic)component).color = color;
}
((TMP_Text)component).fontSize = fontSize;
textMesh = component;
obj.AddComponent<UILayoutRebuilder>();
return obj.GetComponent<RectTransform>();
}
public static RectTransform CreateWindow(string name, RectTransform parent, string title, out TextMeshProUGUI titleText, float width, UnityAction onClose)
{
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Expected O, but got Unknown
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
titleText = null;
return null;
}
GameObject val = Object.Instantiate<GameObject>(GameObject.Find("Canvas/Margins/Options"), (Transform)(object)parent);
((Object)val).name = name;
for (int i = 0; i < val.transform.childCount; i++)
{
Transform child = val.transform.GetChild(i);
if (((Object)child).name != "Header")
{
Object.Destroy((Object)(object)((Component)child).gameObject);
}
}
TextMeshProUGUI component = ((Component)val.transform.GetChild(0).GetChild(0)).GetComponent<TextMeshProUGUI>();
((TMP_Text)component).text = title;
titleText = component;
Button component2 = ((Component)val.transform.GetChild(0).GetChild(1).GetChild(0)).GetComponent<Button>();
component2.onClick = new ButtonClickedEvent();
if (onClose != null)
{
((UnityEvent)component2.onClick).AddListener(onClose);
}
else
{
((Component)component2).gameObject.SetActive(false);
}
RectTransform component3 = ((Component)val.transform.GetChild(0)).GetComponent<RectTransform>();
component3.sizeDelta = new Vector2(width, component3.sizeDelta.y);
RectTransform component4 = ((Component)((Transform)component3).GetChild(1)).GetComponent<RectTransform>();
component4.anchorMin = new Vector2(1f, 0.5f);
component4.anchorMax = new Vector2(1f, 0.5f);
component4.pivot = new Vector2(1f, 0.5f);
component4.anchoredPosition = new Vector2(10f, 10f);
RectTransform component5 = ((Component)((Transform)component4).GetChild(0)).GetComponent<RectTransform>();
component5.anchorMin = new Vector2(0.5f, 0.5f);
component5.anchorMax = new Vector2(0.5f, 0.5f);
component5.pivot = new Vector2(0.5f, 0.5f);
component5.anchoredPosition = Vector2.zero;
RectTransform component6 = val.GetComponent<RectTransform>();
if (!val.activeSelf)
{
val.SetActive(true);
}
val.AddComponent<UILayoutRebuilder>();
return component6;
}
public static RectTransform CreateDivider(string name, RectTransform parent, Color color)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
return null;
}
GameObject val = Object.Instantiate<GameObject>(GameObject.Find("Canvas/Margins/Options/Divider"), (Transform)(object)parent);
((Object)val).name = name;
TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
StringBuilder stringBuilder = new StringBuilder();
int num = Mathf.FloorToInt(parent.sizeDelta.x / 10f);
for (int i = 0; i < num; i++)
{
stringBuilder.Append("-");
}
((TMP_Text)component).text = stringBuilder.ToString();
((Graphic)component).color = color;
RectTransform component2 = val.GetComponent<RectTransform>();
component2.anchorMin = new Vector2(0f, component2.anchorMin.y);
component2.anchorMax = new Vector2(1f, component2.anchorMax.y);
component2.offsetMin = new Vector2(0f, component2.offsetMin.y);
component2.offsetMax = new Vector2(0f, component2.offsetMax.y);
val.AddComponent<UILayoutRebuilder>();
return component2;
}
public static RectTransform CreateVerticalLayoutArea(string name, RectTransform parent, float spacing = 8f, RectOffset padding = null, TextAnchor alignment = 4, bool controlChildSize = true, bool forceExpand = false)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: 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)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
return null;
}
GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
val.transform.SetParent((Transform)(object)parent, false);
val.layer = LayerMask.NameToLayer("UI");
RectTransform component = val.GetComponent<RectTransform>();
component.sizeDelta = Vector2.zero;
VerticalLayoutGroup obj = val.AddComponent<VerticalLayoutGroup>();
((LayoutGroup)obj).childAlignment = alignment;
((HorizontalOrVerticalLayoutGroup)obj).spacing = spacing;
((LayoutGroup)obj).padding = (RectOffset)(((object)padding) ?? ((object)new RectOffset(0, 0, 0, 0)));
((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = controlChildSize;
((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = controlChildSize;
((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = forceExpand;
((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = forceExpand;
ContentSizeFitter obj2 = val.AddComponent<ContentSizeFitter>();
obj2.verticalFit = (FitMode)2;
obj2.horizontalFit = (FitMode)2;
val.AddComponent<UILayoutRebuilder>();
return component;
}
public static RectTransform CreateHorizontalLayoutArea(string name, RectTransform parent, float spacing = 8f, RectOffset padding = null, TextAnchor alignment = 4, bool controlChildSize = true, bool forceExpand = false)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: 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)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
return null;
}
GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
val.transform.SetParent((Transform)(object)parent, false);
val.layer = LayerMask.NameToLayer("UI");
RectTransform component = val.GetComponent<RectTransform>();
component.sizeDelta = Vector2.zero;
HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>();
((LayoutGroup)obj).childAlignment = alignment;
((HorizontalOrVerticalLayoutGroup)obj).spacing = spacing;
((LayoutGroup)obj).padding = (RectOffset)(((object)padding) ?? ((object)new RectOffset(0, 0, 0, 0)));
((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = controlChildSize;
((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = controlChildSize;
((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = forceExpand;
((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = forceExpand;
ContentSizeFitter obj2 = val.AddComponent<ContentSizeFitter>();
obj2.verticalFit = (FitMode)2;
obj2.horizontalFit = (FitMode)2;
val.AddComponent<UILayoutRebuilder>();
return component;
}
public static RectTransform CreateSlider(string name, RectTransform parent, string sliderText, float maxValue, float minValue, float value, UnityAction<float> onValueChanged)
{
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Expected O, but got Unknown
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
return null;
}
GameObject obj = Object.Instantiate<GameObject>(GameObject.Find("Canvas/Margins/Options/Master Volume"), (Transform)(object)parent);
((Object)obj).name = name;
Object.Destroy((Object)(object)obj.GetComponent<UIVolumeSlider>());
((TMP_Text)((Component)obj.transform.GetChild(0)).GetComponent<TextMeshProUGUI>()).text = sliderText;
Slider component = ((Component)obj.transform.GetChild(2)).GetComponent<Slider>();
component.minValue = minValue;
component.maxValue = maxValue;
component.value = value;
component.onValueChanged = new SliderEvent();
((UnityEvent<float>)(object)component.onValueChanged).AddListener(onValueChanged);
RectTransform component2 = obj.GetComponent<RectTransform>();
obj.AddComponent<UILayoutRebuilder>();
return component2;
}
public static RectTransform CreateToggle(string name, RectTransform parent, string toggleText, bool value, UnityAction<bool> onValueChanged)
{
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
return null;
}
RectTransform val = CreateHorizontalLayoutArea(name, parent, 15f, null, (TextAnchor)3, controlChildSize: false, forceExpand: true);
GameObject val2 = new GameObject("ToggleContainer", new Type[1] { typeof(RectTransform) });
val2.transform.SetParent(((Component)val).transform, false);
val2.layer = LayerMask.NameToLayer("UI");
val2.GetComponent<RectTransform>().sizeDelta = new Vector2(40f, 40f);
GameObject val3 = new GameObject("ToggleShadow", new Type[1] { typeof(RectTransform) });
val3.transform.SetParent(val2.transform, false);
val3.layer = LayerMask.NameToLayer("UI");
val3.GetComponent<RectTransform>().sizeDelta = new Vector2(40f, 40f);
Image val4 = val3.AddComponent<Image>();
((Graphic)val4).color = Color.black;
GameObject val5 = new GameObject("ToggleGraphic", new Type[1] { typeof(RectTransform) });
val5.transform.SetParent(val3.transform, false);
val5.layer = LayerMask.NameToLayer("UI");
val5.GetComponent<RectTransform>().sizeDelta = new Vector2(30f, 30f);
Image val6 = val5.AddComponent<Image>();
((Graphic)val6).color = Color.yellow;
Toggle obj = val2.AddComponent<Toggle>();
((Selectable)obj).transition = (Transition)0;
((Selectable)obj).targetGraphic = (Graphic)(object)val4;
obj.graphic = (Graphic)(object)val6;
obj.isOn = value;
((UnityEvent<bool>)(object)obj.onValueChanged).AddListener(onValueChanged);
CreateText("ToggleText", val, toggleText, Color.yellow, out var textMesh, 28);
((TMP_Text)textMesh).alignment = (TextAlignmentOptions)2049;
return val;
}
public static RectTransform CreateVerticalScrollView(string name, RectTransform parent, float width, float height, out RectTransform contentRect, float contentPadding = 8f)
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Expected O, but got Unknown
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
//IL_030d: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Unknown result type (might be due to invalid IL or missing references)
//IL_0321: Unknown result type (might be due to invalid IL or missing references)
//IL_0327: Unknown result type (might be due to invalid IL or missing references)
if (!InMainMenu())
{
Core.Logger.Warning("Tried Creating UI outside Main Menu, Aborting.");
contentRect = null;
return null;
}
GameObject val = new GameObject(name, new Type[3]
{
typeof(RectTransform),
typeof(ScrollRect),
typeof(Image)
});
val.transform.SetParent((Transform)(object)parent, false);
val.layer = LayerMask.NameToLayer("UI");
RectTransform component = val.GetComponent<RectTransform>();
component.sizeDelta = new Vector2(width, height);
((Graphic)val.GetComponent<Image>()).color = Color.clear;
GameObject val2 = new GameObject("Viewport", new Type[3]
{
typeof(RectTransform),
typeof(Mask),
typeof(Image)
});
val2.transform.SetParent(val.transform, false);
val2.layer = LayerMask.NameToLayer("UI");
RectTransform component2 = val2.GetComponent<RectTransform>();
component2.anchorMin = Vector2.zero;
component2.anchorMax = Vector2.one;
component2.offsetMin = Vector2.zero;
component2.offsetMax = Vector2.zero;
((Graphic)val2.GetComponent<Image>()).color = Color.clear;
val2.GetComponent<Mask>().showMaskGraphic = false;
GameObject val3 = new GameObject("Content", new Type[3]
{
typeof(RectTransform),
typeof(VerticalLayoutGroup),
typeof(ContentSizeFitter)
});
val3.transform.SetParent(val2.transform, false);
val3.layer = LayerMask.NameToLayer("UI");
RectTransform component3 = val3.GetComponent<RectTransform>();
component3.anchorMin = new Vector2(0f, 1f);
component3.anchorMax = new Vector2(1f, 1f);
component3.pivot = new Vector2(0.5f, 1f);
component3.anchoredPosition = Vector2.zero;
component3.sizeDelta = new Vector2(0f, 0f);
VerticalLayoutGroup component4 = val3.GetComponent<VerticalLayoutGroup>();
((LayoutGroup)component4).childAlignment = (TextAnchor)1;
((HorizontalOrVerticalLayoutGroup)component4).spacing = contentPadding;
((HorizontalOrVerticalLayoutGroup)component4).childForceExpandHeight = false;
((HorizontalOrVerticalLayoutGroup)component4).childForceExpandWidth = true;
ContentSizeFitter component5 = val3.GetComponent<ContentSizeFitter>();
component5.verticalFit = (FitMode)2;
component5.horizontalFit = (FitMode)0;
ScrollRect component6 = val.GetComponent<ScrollRect>();
component6.content = component3;
component6.viewport = component2;
component6.horizontal = false;
component6.vertical = true;
component6.verticalScrollbarVisibility = (ScrollbarVisibility)2;
GameObject val4 = new GameObject("Scrollbar", new Type[3]
{
typeof(RectTransform),
typeof(Scrollbar),
typeof(Image)
});
val4.transform.SetParent(val.transform, false);
val4.layer = LayerMask.NameToLayer("UI");
RectTransform component7 = val4.GetComponent<RectTransform>();
component7.anchorMin = new Vector2(1f, 0f);
component7.anchorMax = new Vector2(1f, 1f);
component7.pivot = new Vector2(1f, 1f);
component7.sizeDelta = new Vector2(20f, 0f);
component7.anchoredPosition = Vector2.zero;
((Graphic)val4.GetComponent<Image>()).color = Color.yellow;
Scrollbar component8 = val4.GetComponent<Scrollbar>();
component8.direction = (Direction)2;
component6.verticalScrollbar = component8;
val.AddComponent<UILayoutRebuilder>();
contentRect = component3;
return component;
}
private static bool InMainMenu()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
return ((Scene)(ref activeScene)).buildIndex == 0;
}
}
}
namespace VMM.UI.Components
{
internal class ModEntryButton : MonoBehaviour
{
public ModEntry mod;
private Button button;
private EventReference buttonPress;
private void Awake()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
button = ((Component)this).GetComponent<Button>();
((UnityEvent)button.onClick).AddListener(new UnityAction(ShowModInfo));
buttonPress = MainMenuManager.GetButtonPress(MainMenuManager.instance);
}
private void ShowModInfo()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
ModInfoDisplayer.Instance.UpdateModInfo(mod);
AudioManager.instance.PlayOneShot(buttonPress, ((Component)this).transform.position);
}
}
internal class ModInfoDisplayer : MonoBehaviour
{
internal static ModInfoDisplayer Instance;
internal TextMeshProUGUI modName;
internal TextMeshProUGUI modAuthor;
internal TextMeshProUGUI modVersion;
internal Button settingsButton;
internal ModEntry currentMod;
private void Awake()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
((UnityEvent)settingsButton.onClick).AddListener(new UnityAction(OnSettingsButtonPressed));
((Component)((Component)this).transform).gameObject.SetActive(false);
}
else
{
Object.Destroy((Object)(object)this);
Core.Logger.Warning("For some reason there were two Intances of ModInfoDisplayer???");
}
}
public void UpdateModInfo(ModEntry mod)
{
if (mod.Settings == null)
{
((Component)settingsButton).gameObject.SetActive(false);
}
else if (mod.Settings != null && !((Component)settingsButton).gameObject.activeSelf)
{
((Component)settingsButton).gameObject.SetActive(true);
}
((Component)((Component)this).transform).gameObject.SetActive(true);
((TMP_Text)modName).text = "Name: " + mod.Name;
((TMP_Text)modAuthor).text = "Author: " + mod.Author;
((TMP_Text)modVersion).text = "Version: " + mod.Version;
currentMod = mod;
}
public void HandleClose()
{
if (((Component)this).gameObject.activeSelf)
{
((Component)this).gameObject.SetActive(false);
}
}
private void OnSettingsButtonPressed()
{
if (currentMod != null)
{
ModSettingsManager.Instance.OpenSettings(currentMod);
}
}
}
internal class ModSettingsManager : MonoBehaviour
{
public static ModSettingsManager Instance;
public TextMeshProUGUI titleText;
private RectTransform settingsContainer;
public void Init()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
settingsContainer = ((Component)((Component)this).transform.GetChild(0)).GetComponent<RectTransform>();
((Component)settingsContainer).gameObject.SetActive(false);
}
else
{
Core.Logger.Warning("Form some reason there's a second instance for the ModSettingsManager");
Object.Destroy((Object)(object)this);
}
}
private void OnDisable()
{
ClearSettings();
}
private void ClearSettings()
{
for (int i = 0; i < ((Transform)settingsContainer).childCount; i++)
{
Object.Destroy((Object)(object)((Component)((Transform)settingsContainer).GetChild(i)).gameObject);
}
}
public void OpenSettings(ModEntry mod)
{
if (mod.Settings == null)
{
Core.Logger.Warning("Mod '" + mod.Name + "' Does not Contain Any Settings");
return;
}
ClearSettings();
IEnumerable<ISettingsElement> allSettings = mod.Settings.GetAllSettings();
if (allSettings != null && allSettings.Count() <= 0)
{
Core.Logger.Warning("Settings Reference of '" + mod.Name + "' were found but no Settings were found inside List");
return;
}
((TMP_Text)titleText).text = mod.Name + " Settings";
foreach (ISettingsElement item in allSettings)
{
SliderSetting slider = item as SliderSetting;
if (slider != null)
{
UIBuilder.CreateSlider("Slider Setting", settingsContainer, slider.Name, slider.Max, slider.Min, slider.Value, delegate(float value)
{
slider.OnChanged(value);
});
}
ToggleSetting toggle = item as ToggleSetting;
if (toggle != null)
{
UIBuilder.CreateToggle("Toggle Setting", settingsContainer, toggle.Name, toggle.Value, delegate(bool value)
{
toggle.OnChanged(value);
});
}
}
((Component)settingsContainer).gameObject.SetActive(true);
UIManager.Instance.OpenSettings();
}
}
internal class UILayoutRebuilder : MonoBehaviour
{
private RectTransform parentRect;
private void OnEnable()
{
if ((Object)(object)parentRect == (Object)null)
{
parentRect = ((Component)((Component)this).transform.parent).GetComponent<RectTransform>();
}
LayoutRebuilder.ForceRebuildLayoutImmediate(parentRect);
}
}
}
namespace VMM.Patches
{
internal static class MainMenuManager
{
private static readonly FieldInfo field = AccessTools.Field(typeof(MainMenuManager), "buttonPress");
public static EventReference GetButtonPress(MainMenuManager instance)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: 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)
if ((Object)(object)instance == (Object)null)
{
throw new ArgumentNullException("instance");
}
if (field == null)
{
Core.Logger.Error("Could not find field 'buttonPress' in MainMenuManager!");
return default(EventReference);
}
return (EventReference)field.GetValue(instance);
}
}
}
namespace VMM.ModRegistry
{
public class ModEntry
{
public string Name { get; set; }
public string Version { get; set; }
public string Author { get; set; }
public ModSettings Settings { get; set; }
internal Assembly assembly { get; set; }
}
public class ModManager
{
public Action onFinishedLoading;
internal List<ModEntry> LoadedMods = new List<ModEntry>();
public static ModManager Instance { get; internal set; }
public ModManager()
{
if (Instance == null)
{
Instance = this;
}
else
{
Core.Logger.Warning("Duplicate ModManager Detected");
}
}
internal void LoadMods()
{
Core.Logger.Msg("=== Installed Melon Mods ===");
foreach (MelonMod item in MelonTypeBase<MelonMod>.RegisteredMelons.OrderBy((MelonMod m) => ((MelonBase)m).Info.Name))
{
Core.Logger.Msg("Name: " + ((MelonBase)item).Info.Name + " | Version: " + ((MelonBase)item).Info.Version + " | Author: " + ((MelonBase)item).Info.Author);
ModEntry modEntry = new ModEntry
{
Name = ((MelonBase)item).Info.Name,
Version = ((MelonBase)item).Info.Version,
Author = ((MelonBase)item).Info.Author,
assembly = ((object)item).GetType().Assembly,
Settings = null
};
LoadedMods.Add(modEntry);
UIManager.Instance.AddModButton(modEntry);
}
Core.Logger.Msg("============================");
onFinishedLoading?.Invoke();
}
public ModEntry GetModEntryByName(string modName)
{
return LoadedMods.FirstOrDefault((ModEntry m) => m.Name.Equals(modName, StringComparison.OrdinalIgnoreCase));
}
public List<ModEntry> GetLoadedMods()
{
return LoadedMods;
}
public void RegisterSettings(Assembly modAssembly, ModSettings settings)
{
ModEntry modEntry = LoadedMods.Find((ModEntry m) => m.assembly == modAssembly);
if (modEntry != null)
{
modEntry.Settings = new ModSettings();
modEntry.Settings = settings;
Core.Logger.Msg("Registered settings for mod: " + modEntry.Name);
}
else
{
Core.Logger.Error("Mod not found for the provided assembly.");
}
}
}
}
namespace VMM.ModRegistry.Settings
{
public interface ISettingsElement
{
string Name { get; set; }
object GetValue();
void SetValue(object value);
}
public class ModSettings
{
private readonly List<ISettingsElement> settings = new List<ISettingsElement>();
public void AddSetting(ISettingsElement newSetting)
{
settings.Add(newSetting);
}
public T GetSetting<T>(string name) where T : class, ISettingsElement
{
foreach (ISettingsElement setting in settings)
{
if (setting.Name == name && setting is T result)
{
return result;
}
}
return null;
}
public IEnumerable<ISettingsElement> GetAllSettings()
{
return settings;
}
}
public abstract class SettingsElement<T> : ISettingsElement
{
public string Name { get; set; }
public T Value { get; set; }
public Action<T> OnChanged { get; set; }
public object GetValue()
{
return Value;
}
public void SetValue(object value)
{
if (value is T val)
{
Value = val;
OnChanged?.Invoke(val);
return;
}
throw new InvalidCastException($"Invalid value type. Expected {typeof(T)}, got {value?.GetType()}");
}
}
}
namespace VMM.ModRegistry.Settings.Types
{
public class SliderSetting : SettingsElement<float>
{
public float Min { get; set; }
public float Max { get; set; }
}
public class ToggleSetting : SettingsElement<bool>
{
}
}