using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using Bunburrows;
using Bunject.Computer.Internal;
using Bunject.Internal;
using Bunject.Levels;
using Characters.Bunny.Data;
using Computer;
using HarmonyLib;
using Levels;
using Misc;
using TMPro;
using Tiling.Behaviour;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BunjectComputer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BunjectComputer")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4d448f27-4f13-493c-a71f-9cf366d9a8ab")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Bunject.Computer
{
[BepInPlugin("startup.bunject.computer", "Bunject Computer", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ComputerPlugin : BaseUnityPlugin
{
private void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new Harmony("bunject.computer").PatchAll(Assembly.GetExecutingAssembly());
}
}
}
namespace Bunject.Computer.Internal
{
internal class ModComputerMapDrawer
{
private static ModComputerMapDrawer _instance;
private readonly FieldInfo currentlyHoveredLevel;
private readonly FieldInfo currentlyHoveredBunny;
private readonly FieldInfo currentDepth;
private readonly MethodInfo tryGetCellOnCenter;
public static ModComputerMapDrawer Instance
{
get
{
if ((Object)(object)_instance?.This == (Object)null)
{
_instance = new ModComputerMapDrawer();
Debug.Log((object)"Bunject.Computer: Init Map Drawer");
}
return _instance;
}
}
public ComputerMapDrawer This { get; private set; }
public BunburrowsCompleteListOf<ComputerMapLevelCellsController> LevelCellsControllers { get; private set; }
public RectTransform CellsHolderTransform { get; private set; }
public GameObject DepthInputHelpGameObject { get; private set; }
public TextMeshProUGUI DepthTextComponent { get; private set; }
public LevelIdentity? CurrentlyHoveredLevel => (LevelIdentity?)currentlyHoveredLevel.GetValue(This);
public BunnyIdentity? CurrentlyHoveredBunny => (BunnyIdentity?)currentlyHoveredBunny.GetValue(This);
public int CurrentDepth
{
get
{
return (int)currentDepth.GetValue(This);
}
private set
{
currentDepth.SetValue(This, value);
}
}
public Level OpeningLevel { get; private set; }
public Bunburrow FocussedBurrow { get; private set; }
public ComputerMapLevelCellsController FocussedController { get; private set; }
private ModComputerMapDrawer()
{
Traverse val = Traverse.Create((object)GameManager.UIController.OphelineComputerCanvasController).Field("computerMapDrawer");
This = val.GetValue<ComputerMapDrawer>();
LevelCellsControllers = val.Field<BunburrowsCompleteListOf<ComputerMapLevelCellsController>>("levelCellsControllers").Value;
CellsHolderTransform = val.Field<RectTransform>("cellsHolderTransform").Value;
DepthInputHelpGameObject = val.Field<GameObject>("depthInputHelpGameObject").Value;
DepthTextComponent = val.Field<TextMeshProUGUI>("depthTextComponent").Value;
Type typeFromHandle = typeof(ComputerMapDrawer);
tryGetCellOnCenter = AccessTools.Method(typeFromHandle, "TryGetCellOnCenter", (Type[])null, (Type[])null);
currentlyHoveredLevel = AccessTools.Field(typeFromHandle, "currentlyHoveredLevel");
currentlyHoveredBunny = AccessTools.Field(typeFromHandle, "currentlyHoveredBunny");
currentDepth = AccessTools.Field(typeFromHandle, "currentDepth");
}
public void HandleOpen()
{
//IL_0015: 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_001c: 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_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got I4
//IL_002d->IL002d: Incompatible stack types: O vs I4
//IL_0027->IL002d: Incompatible stack types: I4 vs O
//IL_0027->IL002d: Incompatible stack types: O vs I4
OpeningLevel = GameManager.CurrentLevel;
LevelIdentity levelIdentity = GameManager.LevelStates.CurrentLevelState.LevelIdentity;
object obj = this;
int num;
if (levelIdentity.Depth != 0)
{
obj = levelIdentity.Bunburrow;
num = (int)obj;
}
else
{
num = 2;
obj = num;
num = (int)obj;
}
((ModComputerMapDrawer)num).FocussedBurrow = (Bunburrow)obj;
FocussedController = LevelCellsControllers[(Bunburrow)2];
}
public bool HandleDownFloorInput()
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
bool result = true;
if (TryGetCellOnCenter(out var cell))
{
(int, int) coordinates = cell.Coordinates;
LevelObject levelObject = cell.LevelCellsController.LevelObject;
if ((Object)(object)levelObject != (Object)null)
{
TileLevelData obj = LevelBuilder.BuildNewLevel(levelObject, (BunburrowStyle)null, false).Tiles[coordinates.Item1 * 15 + coordinates.Item2];
BunburrowEntryTile val = (BunburrowEntryTile)(object)((obj is BunburrowEntryTile) ? obj : null);
if (val != null)
{
Bunburrow? bunburrow = val.Bunburrow;
if (bunburrow.HasValue)
{
Bunburrow valueOrDefault = bunburrow.GetValueOrDefault();
CurrentDepth = 0;
FocussedBurrow = valueOrDefault;
result = true;
goto IL_0090;
}
}
result = !levelObject.IsSurface;
}
}
goto IL_0090;
IL_0090:
return result;
}
public void CenterOnStart()
{
//IL_0001: 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)
if (CustomBunburrowExtension.IsCustomBunburrow(FocussedBurrow))
{
CellsHolderTransform.anchoredPosition = LevelCellsControllers[(Bunburrow)2].CenterPosition;
}
}
public void UpdateSelector()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: 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_0030: 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_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: 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)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: 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_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: 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)
if (!CustomBunburrowExtension.IsCustomBunburrow(FocussedBurrow))
{
return;
}
LevelIdentity? val = CurrentlyHoveredLevel;
Bunburrow bunburrow;
int depth;
if (val.HasValue)
{
LevelIdentity valueOrDefault = val.GetValueOrDefault();
bunburrow = valueOrDefault.Bunburrow;
depth = valueOrDefault.Depth;
}
else
{
BunnyIdentity? val2 = CurrentlyHoveredBunny;
if (!val2.HasValue)
{
return;
}
BunnyIdentity valueOrDefault2 = val2.GetValueOrDefault();
bunburrow = valueOrDefault2.Bunburrow;
depth = valueOrDefault2.InitialDepth;
}
TryGetCellOnCenter(out var cell);
if (bunburrow != FocussedBurrow || (Object)(object)FocussedController != (Object)(object)cell.LevelCellsController)
{
if (bunburrow != FocussedBurrow)
{
FocussedBurrow = bunburrow;
DrawMapAtDepth(depth);
}
RectTransform cellsHolderTransform = CellsHolderTransform;
cellsHolderTransform.anchoredPosition -= -cell.LevelCellsController.CenterPosition + LevelCellsControllers[(Bunburrow)2].CenterPosition;
}
}
public bool TryGetCellOnCenter(out ComputerMapCellController cell)
{
ComputerMapCellController[] array = (ComputerMapCellController[])(object)new ComputerMapCellController[1];
MethodInfo methodInfo = tryGetCellOnCenter;
ComputerMapDrawer @this = This;
object[] parameters = array;
bool result = (bool)methodInfo.Invoke(@this, parameters);
cell = array[0];
return result;
}
public bool DrawMapAtDepth(int depth)
{
//IL_0003: 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_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: 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_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Invalid comparison between Unknown and I4
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
bool result = true;
if (CustomBunburrowExtension.IsCustomBunburrow(FocussedBurrow))
{
Dictionary<Bunburrow, LevelsList> dictionary = GenerateMap(FocussedBurrow);
((TMP_Text)DepthTextComponent).text = string.Format("{0} <color=#{1}>{2}</color>", AssetsManager.UILocalizationObject.UIStrings.TryGetValue("computer_map_depth", out var value) ? value : "Depth", ColorUtility.ToHtmlStringRGB(AssetsManager.BunburrowsListOfStyles.Computer.ButtonHoverColor), depth);
LocalizedTextHelper.UpdateFontData(DepthTextComponent, 1, true);
LevelIdentity val = default(LevelIdentity);
foreach (Bunburrow bunburrowsInMapOrder in BunburrowExtension.GetBunburrowsInMapOrderList())
{
if ((Object)(object)dictionary[bunburrowsInMapOrder] != (Object)null)
{
((LevelIdentity)(ref val))..ctor(BunburrowExtension.ToBunburrow(((Object)dictionary[bunburrowsInMapOrder]).name), depth);
if (CollectionExtension.ContainsEquatable<LevelIdentity>((IEnumerable<LevelIdentity>)GameManager.GeneralProgression.LevelsVisited, val))
{
LevelCellsControllers[bunburrowsInMapOrder].DrawMap(dictionary[bunburrowsInMapOrder][depth], val);
continue;
}
}
LevelCellsControllers[bunburrowsInMapOrder].ClearMap();
}
result = false;
}
else if (OpeningLevel.BaseData is ModLevelObject && ((Object)OpeningLevel.BaseData).name.Contains("Surface") && OpeningLevel.BaseData.IsSurface && OpeningLevel.BunburrowEntryTiles.Count > 0)
{
CurrentDepth = 0;
((TMP_Text)DepthTextComponent).text = string.Format("{0} <color=#{1}>{2}</color>", AssetsManager.UILocalizationObject.UIStrings.TryGetValue("computer_map_depth", out var value2) ? value2 : "Depth", ColorUtility.ToHtmlStringRGB(AssetsManager.BunburrowsListOfStyles.Computer.ButtonHoverColor), 0);
LocalizedTextHelper.UpdateFontData(DepthTextComponent, 1, true);
foreach (Bunburrow bunburrowsInMapOrder2 in BunburrowExtension.GetBunburrowsInMapOrderList())
{
if ((int)bunburrowsInMapOrder2 == 2)
{
LevelCellsControllers[bunburrowsInMapOrder2].DrawMap(OpeningLevel.BaseData, default(LevelIdentity));
}
else
{
LevelCellsControllers[bunburrowsInMapOrder2].ClearMap();
}
}
OpeningLevel = null;
result = false;
}
return result;
}
private Dictionary<Bunburrow, LevelsList> GenerateMap(Bunburrow burrow)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
Dictionary<Bunburrow, LevelsList> dictionary = new Dictionary<Bunburrow, LevelsList>();
LevelsList val2 = (dictionary[(Bunburrow)2] = AssetsManager.LevelsLists[BunburrowExtension.ToBunburrowName(burrow)]);
LevelsList val3 = val2;
val2 = (dictionary[(Bunburrow)0] = val3.AdjacentBunburrows[(Direction)0]);
LevelsList val5 = val2;
val2 = (dictionary[(Bunburrow)1] = val3.AdjacentBunburrows[(Direction)2]);
LevelsList val7 = val2;
val2 = (dictionary[(Bunburrow)3] = val3.AdjacentBunburrows[(Direction)3]);
LevelsList val9 = val2;
val2 = (dictionary[(Bunburrow)4] = val3.AdjacentBunburrows[(Direction)1]);
LevelsList val11 = val2;
dictionary[(Bunburrow)5] = GetBurrow(val5, (Direction)2, val7, (Direction)0);
dictionary[(Bunburrow)6] = GetBurrow(val7, (Direction)1, val11, (Direction)2);
dictionary[(Bunburrow)8] = GetBurrow(val11, (Direction)3, val9, (Direction)1);
dictionary[(Bunburrow)7] = GetBurrow(val9, (Direction)0, val5, (Direction)3);
return dictionary;
}
private LevelsList GetBurrow(LevelsList burrow1, Direction dirFrom1, LevelsList burrow2, Direction dirFrom2)
{
//IL_001e: 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_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: 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)
object obj;
if (!((Object)(object)burrow1 != (Object)null) || !((Object)(object)burrow2 != (Object)null))
{
obj = ((burrow1 != null) ? burrow1.AdjacentBunburrows[dirFrom1] : null);
if (obj == null)
{
if (burrow2 == null)
{
return null;
}
return burrow2.AdjacentBunburrows[dirFrom2];
}
}
else
{
if (!((Object)(object)burrow1.AdjacentBunburrows[dirFrom1] == (Object)(object)burrow2.AdjacentBunburrows[dirFrom2]))
{
return null;
}
obj = burrow1.AdjacentBunburrows[dirFrom1];
}
return (LevelsList)obj;
}
}
}
namespace Bunject.Computer.Patches.ComputerMapDrawerPatches
{
[HarmonyPatch(typeof(ComputerMapDrawer), "HandleOpen")]
internal class HandleOpenPatch
{
private static void Prefix()
{
ModComputerMapDrawer.Instance.HandleOpen();
}
}
[HarmonyPatch(typeof(ComputerMapDrawer), "HandleDownFloorInput")]
internal class HandleDownFloorInputPatch
{
private static bool Prefix(bool __runOriginal)
{
if (__runOriginal)
{
return ModComputerMapDrawer.Instance.HandleDownFloorInput();
}
return false;
}
}
[HarmonyPatch(typeof(ComputerMapDrawer), "CenterOnStart")]
internal class CenterOnStartPatch
{
private static void Postfix()
{
ModComputerMapDrawer.Instance.CenterOnStart();
}
}
[HarmonyPatch(typeof(ComputerMapDrawer), "UpdateSelector")]
internal class UpdateSelectorPatch
{
private static void Postfix()
{
ModComputerMapDrawer.Instance.UpdateSelector();
}
}
[HarmonyPatch(typeof(ComputerMapDrawer), "DrawMapAtDepth")]
internal class DrawMapAtDepthPatch
{
public static bool Prefix(bool __runOriginal, int depth)
{
if (__runOriginal)
{
return ModComputerMapDrawer.Instance.DrawMapAtDepth(depth);
}
return false;
}
}
}
namespace Bunject.Computer.Patches.ComputerMapLevelCellsControllerPatches
{
[HarmonyPatch(typeof(ComputerMapLevelCellsController), "DrawMap")]
internal class DrawMapPatch
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
int state = 0;
Type type = typeof(ExitTile);
ConstructorInfo constructor = AccessTools.Constructor(typeof(BunnyIdentity), new Type[4]
{
typeof(Bunburrow),
typeof(int),
typeof(int),
typeof(int)
}, false);
foreach (CodeInstruction code in instructions)
{
yield return code;
switch (state)
{
case 0:
if (CodeInstructionExtensions.Is(code, OpCodes.Isinst, (MemberInfo)type))
{
state = 1;
}
break;
case 1:
yield return new CodeInstruction(OpCodes.Ldloc_S, (object)7);
yield return new CodeInstruction(OpCodes.Isinst, (object)typeof(BunburrowEntryTile));
yield return code;
state = 2;
break;
case 2:
if (code.opcode == OpCodes.Call && code.operand != null && code.operand.Equals(constructor))
{
yield return new CodeInstruction(OpCodes.Ldloc_S, (object)18);
yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(DrawMapPatch), "FixIdentity", (Type[])null, (Type[])null));
yield return new CodeInstruction(OpCodes.Stloc_S, (object)18);
}
break;
}
}
}
private static BunnyIdentity FixIdentity(BunnyIdentity original)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: 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)
//IL_000c: 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)
//IL_0018: 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_003c: Unknown result type (might be due to invalid IL or missing references)
return new BunnyIdentity(original.Bunburrow, original.InitialDepth, original.LevelID, AssetsManager.LevelsLists[BunburrowExtension.ToBunburrowName(original.Bunburrow)][original.InitialDepth].BunburrowStyle.SpriteSheetsID);
}
}
}
namespace Bunject.Computer.Patches.ComputerMapInfoControllerPatches
{
[HarmonyPatch(typeof(ComputerMapInfoController))]
internal class DisplayLevelInfoPatch
{
private static bool _init;
private static TextMeshProUGUI levelNameTextComponent;
private static TextMeshProUGUI levelBunniesTextComponent;
private static TextMeshProUGUI bunnyNameTextComponent;
private static TextMeshProUGUI bunnyStatusTextComponent;
private static void Init(ComputerMapInfoController instance)
{
if (!_init)
{
levelNameTextComponent = Traverse.Create((object)instance).Field<TextMeshProUGUI>("levelNameTextComponent").Value;
levelBunniesTextComponent = Traverse.Create((object)instance).Field<TextMeshProUGUI>("levelBunniesTextComponent").Value;
bunnyNameTextComponent = Traverse.Create((object)instance).Field<TextMeshProUGUI>("bunnyNameTextComponent").Value;
bunnyStatusTextComponent = Traverse.Create((object)instance).Field<TextMeshProUGUI>("bunnyStatusTextComponent").Value;
((TMP_Text)levelNameTextComponent).spriteAsset = ((TMP_Text)levelBunniesTextComponent).spriteAsset;
((TMP_Text)bunnyNameTextComponent).spriteAsset = ((TMP_Text)bunnyStatusTextComponent).spriteAsset;
}
}
[HarmonyPostfix]
[HarmonyPatch("DisplayLevelInfo")]
private static void LevelPatch(ComputerMapInfoController __instance, LevelIdentity levelIdentity, LevelObject levelObject)
{
//IL_0011: 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)
if (levelObject is ModLevelObject)
{
Init(__instance);
if (levelIdentity.Depth == 0)
{
string text = ColorUtility.ToHtmlStringRGB(AssetsManager.BunburrowsListOfStyles[(Bunburrow)0].SkyboxColor);
((TMP_Text)levelNameTextComponent).text = "<color=#" + text + ">Surface</color>";
LocalizedTextHelper.UpdateFontData(levelNameTextComponent, 1, true);
}
else
{
TextMeshProUGUI obj = levelNameTextComponent;
((TMP_Text)obj).text = ((TMP_Text)obj).text + ((TMP_Text)levelBunniesTextComponent).text;
((TMP_Text)levelBunniesTextComponent).text = string.Empty;
LocalizedTextHelper.UpdateFontData(levelBunniesTextComponent, 1, true);
}
}
}
[HarmonyPostfix]
[HarmonyPatch("DisplayBunnyInfo")]
private static void BunnyPatch(ComputerMapInfoController __instance, BunnyIdentity bunnyIdentity)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if (CustomBunburrowExtension.IsCustomBunburrow(bunnyIdentity.Bunburrow))
{
Init(__instance);
TextMeshProUGUI obj = bunnyNameTextComponent;
((TMP_Text)obj).text = ((TMP_Text)obj).text + ((TMP_Text)bunnyStatusTextComponent).text;
((TMP_Text)bunnyStatusTextComponent).text = string.Empty;
LocalizedTextHelper.UpdateFontData(bunnyStatusTextComponent, 1, true);
}
}
}
}