using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 UndergroundMenuMod
{
[BepInPlugin("de.knusbernd.undergroundmenumod", "Underground Menu Mod", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
internal static ManualLogSource Logger;
public static Sprite ComputerSprite;
private void Awake()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"UndergroundMenuMod loaded!");
LoadAssets();
new Harmony("de.knusbernd.undergroundmenumod").PatchAll();
}
private void LoadAssets()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string name = "UndergroundMenuMod.computer.png";
using Stream stream = executingAssembly.GetManifestResourceStream(name);
if (stream != null)
{
byte[] array = new byte[stream.Length];
stream.Read(array, 0, array.Length);
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
if (ImageConversion.LoadImage(val, array))
{
((Texture)val).filterMode = (FilterMode)1;
ComputerSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
}
}
}
private void Update()
{
if (Input.GetKeyDown((KeyCode)292))
{
DumpUI();
}
}
private void DumpUI()
{
}
}
[HarmonyPatch(typeof(InventoryBook), "Show")]
public static class InventoryBookShowPatch
{
public static void Postfix(InventoryBook __instance)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Expected O, but got Unknown
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_04df: Unknown result type (might be due to invalid IL or missing references)
//IL_0366: Unknown result type (might be due to invalid IL or missing references)
//IL_0370: Expected O, but got Unknown
//IL_03df: Unknown result type (might be due to invalid IL or missing references)
//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
//IL_0428: Unknown result type (might be due to invalid IL or missing references)
//IL_043e: Unknown result type (might be due to invalid IL or missing references)
//IL_0454: Unknown result type (might be due to invalid IL or missing references)
//IL_0460: Unknown result type (might be due to invalid IL or missing references)
//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
//IL_0481: Unknown result type (might be due to invalid IL or missing references)
//IL_0486: Unknown result type (might be due to invalid IL or missing references)
//IL_0497: Unknown result type (might be due to invalid IL or missing references)
//IL_049c: Unknown result type (might be due to invalid IL or missing references)
//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
if (((Scene)(ref activeScene)).name != "TreeHouseLobby")
{
return;
}
string text = "TabletHolder(Clone)/TabletScreen/TextCanvas/Anchor/ScreenContentMask/Home Screen Sidebar/SidebarMask/SidebarContainer/Treehouse Home/Game Mode Control/Mode Select Widget/Prev Button";
Transform val = ((Component)__instance).transform.Find(text);
if ((Object)(object)val == (Object)null)
{
val = ((IEnumerable<Transform>)((Component)__instance).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Prev Button" && ((Object)t.parent).name == "Mode Select Widget"));
}
if ((Object)(object)val == (Object)null)
{
return;
}
TabletButton component = ((Component)val).GetComponent<TabletButton>();
if ((Object)(object)component == (Object)null)
{
return;
}
string text2 = "UndergroundComputerContainer";
Transform parent = ((Component)component).transform.parent;
Transform val2 = parent.Find(text2);
GameObject val3;
if ((Object)(object)val2 == (Object)null)
{
val3 = new GameObject(text2, new Type[1] { typeof(RectTransform) });
val3.transform.SetParent(parent, false);
}
else
{
val3 = ((Component)val2).gameObject;
}
RectTransform component2 = val3.GetComponent<RectTransform>();
((Transform)component2).localScale = new Vector3(0.7f, 0.7f, 1f);
component2.sizeDelta = ((RectTransform)((Component)component).transform).sizeDelta;
component2.anchorMin = ((RectTransform)((Component)component).transform).anchorMin;
component2.anchorMax = ((RectTransform)((Component)component).transform).anchorMax;
component2.pivot = ((RectTransform)((Component)component).transform).pivot;
RectTransform component3 = ((Component)component).GetComponent<RectTransform>();
Rect rect = component3.rect;
float height = ((Rect)(ref rect)).height;
component2.anchoredPosition = component3.anchoredPosition + new Vector2(0f, height);
Transform val4 = val3.transform.Find("UndergroundComputerButton");
GameObject val5;
if ((Object)(object)val4 == (Object)null)
{
val5 = Object.Instantiate<GameObject>(((Component)component).gameObject, val3.transform);
((Object)val5).name = "UndergroundComputerButton";
val5.transform.localScale = Vector3.one;
val5.transform.localPosition = Vector3.zero;
RenameChildren(val5.transform, "_Underground");
MonoBehaviour[] components = val5.GetComponents<MonoBehaviour>();
foreach (MonoBehaviour val6 in components)
{
switch (((object)val6).GetType().Name)
{
case "TabletButton":
case "TabletClickable":
case "TextMeshProUGUI":
case "Image":
case "RawImage":
case "CanvasRenderer":
case "LayoutElement":
case "RectTransform":
continue;
}
Object.Destroy((Object)(object)val6);
}
TextMeshProUGUI[] componentsInChildren = val5.GetComponentsInChildren<TextMeshProUGUI>(true);
foreach (TextMeshProUGUI val7 in componentsInChildren)
{
if ((Object)(object)((Component)val7).gameObject != (Object)(object)val5)
{
Object.Destroy((Object)(object)((Component)val7).gameObject);
}
}
Text[] componentsInChildren2 = val5.GetComponentsInChildren<Text>(true);
foreach (Text val8 in componentsInChildren2)
{
if ((Object)(object)((Component)val8).gameObject != (Object)(object)val5)
{
Object.Destroy((Object)(object)((Component)val8).gameObject);
}
}
TabletButton component4 = val5.GetComponent<TabletButton>();
if ((Object)(object)component4 != (Object)null)
{
component4.clickSound = "UI_Lobby_SnapshotLoader_Select";
component4.OnClick = new TabletButtonEvent();
bool flag = false;
if ((Object)(object)LobbyManager.instance != (Object)null)
{
flag = LobbyManager.instance.IsHost;
}
if (flag)
{
((TabletStyledObject)component4).SetDisabled(false);
((TabletStyledObject)component4).SetInteractable(true);
((UnityEvent<PickCursor>)(object)component4.OnClick).AddListener((UnityAction<PickCursor>)delegate
{
OpenUndergroundMenu(__instance);
});
}
else
{
((TabletStyledObject)component4).SetDisabled(true);
((TabletStyledObject)component4).SetInteractable(false);
}
}
if ((Object)(object)Plugin.ComputerSprite != (Object)null)
{
GameObject val9 = new GameObject("Icon_Computer");
val9.transform.SetParent(val5.transform, false);
Image obj = val9.AddComponent<Image>();
obj.sprite = Plugin.ComputerSprite;
obj.preserveAspect = true;
((Graphic)obj).raycastTarget = false;
RectTransform rectTransform = ((Graphic)obj).rectTransform;
rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
rectTransform.pivot = new Vector2(0.5f, 0.5f);
rectTransform.anchoredPosition = Vector2.zero;
RectTransform component5 = val5.GetComponent<RectTransform>();
if ((Object)(object)component5 != (Object)null)
{
rect = component5.rect;
float num = ((Rect)(ref rect)).width * 0.8f;
rect = component5.rect;
rectTransform.sizeDelta = new Vector2(num, ((Rect)(ref rect)).height * 0.8f);
}
else
{
rectTransform.sizeDelta = new Vector2(100f, 100f);
}
}
}
else
{
val5 = ((Component)val4).gameObject;
}
val5.transform.localScale = Vector3.one;
val5.SetActive(true);
}
private static void RenameChildren(Transform parent, string suffix)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: 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_002c: Expected O, but got Unknown
foreach (Transform item in parent)
{
((Object)item).name = ((Object)item).name + suffix;
RenameChildren(item, suffix);
}
}
private static void OpenUndergroundMenu(InventoryBook book)
{
book.GotoPage(false, (PageTypes)26, true, true);
if ((Object)(object)PickableBuildButton.undergroundComputer != (Object)null)
{
PickableBuildButton.undergroundComputer.OnSelectFeaturedLevelTab(true, true);
}
}
}
}