using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EquinoxsModUtils;
using HarmonyLib;
using UnityEngine;
using WormholeChests.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("WormholeChests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WormholeChests")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("26642608-65d3-4265-83a5-3c4d54dd4660")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace WormholeChests
{
public static class ChestGUI
{
public static bool shouldShowGUI;
public static uint currentChestID;
public static bool showLinkedLabel;
public static string lastChannel;
public static string channel;
private static Texture2D textBoxNormal;
private static Texture2D textBoxHover;
public static bool freeChests => WormholeChestsPlugin.freeWormholeChests.Value;
public static float channelBoxXOffset => WormholeChestsPlugin.channelBoxXOffset.Value;
public static float channelBoxYOffset => WormholeChestsPlugin.channelBoxYOffset.Value;
public static float channelBoxWidth => WormholeChestsPlugin.channelBoxWidth.Value;
public static float createButtonXOffset => WormholeChestsPlugin.createButtonXOffset.Value;
public static float xPos => (float)Screen.width / 2f + channelBoxXOffset;
public static float yPos => (float)Screen.height / 2f + channelBoxYOffset;
public static void LoadImages()
{
LoadImage("WormholeChests.Images.Border240x40.png", ref textBoxNormal);
LoadImage("WormholeChests.Images.BorderHover240x40.png", ref textBoxHover);
LoadImage("WormholeChests.Images.Void.png", ref WormholeChestsPlugin.wormholeTexture);
}
public static void DrawChestGUI()
{
HandleKeyPresses();
DrawChannelBox();
if (!(channel == ""))
{
DrawCreateButton();
DrawLinkedLabel();
lastChannel = channel;
}
}
private static void LoadImage(string path, ref Texture2D output)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
Assembly executingAssembly = Assembly.GetExecutingAssembly();
using Stream stream = executingAssembly.GetManifestResourceStream(path);
if (stream == null)
{
Debug.LogError((object)"Could not find button background image");
return;
}
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
byte[] array = memoryStream.ToArray();
output = new Texture2D(2, 2);
ImageConversion.LoadImage(output, array);
}
private static void HandleKeyPresses()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Invalid comparison between Unknown and I4
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Invalid comparison between Unknown and I4
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Invalid comparison between Unknown and I4
if (((int)Event.current.keyCode == 9 || Event.current.character == '\t') && (int)Event.current.type != 7 && (int)Event.current.type != 8)
{
Event.current.Use();
}
if (UnityInput.Current.GetKey((KeyCode)27) || UnityInput.Current.GetKey((KeyCode)9))
{
((MachineMenuUI<ChestInstance>)(object)UIManager.instance.inventoryAndStorageMenu).Close();
}
InputHandler.instance.uiInputBlocked = true;
}
private static void DrawChannelBox()
{
//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_000f: 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_001d: 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_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: 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)
//IL_007a: Expected O, but got Unknown
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: 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_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Expected O, but got Unknown
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
GUIStyle val = new GUIStyle
{
fontSize = 16,
alignment = (TextAnchor)3
};
val.normal.textColor = Color.white;
val.normal.background = textBoxNormal;
val.hover.textColor = Color.white;
val.hover.background = textBoxHover;
GUIStyle val2 = val;
GUIStyle val3 = new GUIStyle
{
fontSize = 16,
padding = new RectOffset(10, 0, 0, 0),
alignment = (TextAnchor)3
};
val3.normal.textColor = Color.gray;
val3.normal.background = null;
GUIStyle val4 = val3;
channel = GUI.TextField(new Rect(xPos, yPos, channelBoxWidth, 40f), channel, val2);
if (channel == "")
{
GUI.Label(new Rect(xPos + 2f, yPos, channelBoxWidth - 10f, 40f), "Channel", val4);
}
}
private static void DrawCreateButton()
{
//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_000f: 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_001f: Expected O, but got Unknown
//IL_0020: 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)
//IL_0043: 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_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Expected O, but got Unknown
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: 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_0182: 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_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
GUIStyle val = new GUIStyle
{
fontSize = 16,
padding = new RectOffset(10, 0, 0, 0),
alignment = (TextAnchor)(freeChests ? 4 : 3)
};
val.normal.textColor = Color.white;
val.normal.background = textBoxNormal;
val.hover.textColor = Color.white;
val.hover.background = textBoxHover;
GUIStyle val2 = val;
ChestInstance aimedAtChest = WormholeManager.GetAimedAtChest();
bool flag = WormholeManager.DoesChannelExist(channel);
if (flag && WormholeManager.chestChannelMap.ContainsKey(aimedAtChest.commonInfo.instanceId))
{
showLinkedLabel = true;
}
string text = (flag ? "Link" : "Create");
if (GUI.Button(new Rect(xPos + createButtonXOffset, yPos, channelBoxWidth, 40f), text, val2))
{
if (!freeChests)
{
CheckAndRemoveCores();
}
Inventory inventory = ((ChestInstance)(ref aimedAtChest)).GetInventory();
if (!flag)
{
Inventory inventory2 = default(Inventory);
((Inventory)(ref inventory2)).CopyFrom(ref inventory);
WormholeManager.AddWormhole(new Wormhole
{
channel = channel,
inventory = inventory2
});
}
else
{
Inventory inventory3 = ((ChestInstance)(ref aimedAtChest)).GetInventory();
aimedAtChest.commonInfo.inventories[0] = WormholeManager.GetWormhole(channel).inventory;
ResourceStack[] myStacks = inventory3.myStacks;
int num = default(int);
for (int i = 0; i < myStacks.Length; i++)
{
ResourceStack val3 = myStacks[i];
if (!((ResourceStack)(ref val3)).isEmpty)
{
ChestInstance.AddResources(ref aimedAtChest, ((UniqueIdScriptableObject)((ResourceStack)(ref val3)).info).uniqueId, ref num, val3.count);
}
}
}
showLinkedLabel = true;
WormholeManager.chestChannelMap[currentChestID] = channel;
GUI.SetNextControlName(" ");
GUI.Label(new Rect(-100f, -100f, 1f, 1f), "");
GUI.FocusControl(" ");
}
if (!freeChests)
{
DrawCostGUI();
}
}
private static void CheckAndRemoveCores()
{
float num = WormholeManager.GetCostToCreateOrLink();
if (!((float)TechTreeState.instance.NumCoresAvailable((CoreType)2) >= num))
{
((FMODAudioSource)(ref Player.instance.audio.buildError)).PlayRandomClip(true);
return;
}
((FMODAudioSource)(ref Player.instance.audio.buildClick)).PlayRandomClip(true);
TechTreeState.instance.usedResearchCores[2] += WormholeManager.GetCostToCreateOrLink();
}
private static void DrawCostGUI()
{
//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_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
//IL_006b: 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)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: 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_00be: 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_00da: Expected O, but got Unknown
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
float num = WormholeManager.GetCostToCreateOrLink();
bool flag = (float)TechTreeState.instance.NumCoresAvailable((CoreType)2) >= num;
string text = $"Cost: {num}";
GUIStyle val = new GUIStyle
{
fontSize = 16,
alignment = (TextAnchor)5
};
val.normal.textColor = (flag ? Color.green : Color.red);
val.normal.background = null;
GUIStyle val2 = val;
GUIStyle val3 = new GUIStyle();
val3.normal.background = null;
val3.hover.background = null;
val3.active.background = null;
val3.focused.background = null;
val3.onNormal.background = null;
val3.onHover.background = null;
val3.onActive.background = null;
val3.onFocused.background = null;
GUIStyle val4 = val3;
GUI.Box(new Rect(xPos + createButtonXOffset + channelBoxWidth - 35f, yPos + 5f, 30f, 30f), (Texture)(object)ModUtils.GetImageForResource("Research Core 480nm (Blue)", false), val4);
GUI.Label(new Rect(xPos + createButtonXOffset + 10f, yPos + 5f, channelBoxWidth - 50f, 30f), text, val2);
}
private static void DrawLinkedLabel()
{
//IL_0033: 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)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: 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_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
if (!string.IsNullOrEmpty(lastChannel) && lastChannel != channel)
{
showLinkedLabel = false;
}
if (showLinkedLabel)
{
GUIStyle val = new GUIStyle
{
fontSize = 16,
fontStyle = (FontStyle)1,
alignment = (TextAnchor)4
};
val.normal.textColor = Color.green;
val.normal.background = textBoxNormal;
GUIStyle val2 = val;
GUI.Box(new Rect(xPos + createButtonXOffset, yPos, channelBoxWidth, 40f), "Linked!", val2);
}
}
}
public static class WormholeManager
{
public static Dictionary<string, Wormhole> wormholes = new Dictionary<string, Wormhole>();
public static Dictionary<uint, string> chestChannelMap = new Dictionary<uint, string>();
private static string dataFolder => Application.persistentDataPath + "/WormholeChests";
public static void AddWormhole(Wormhole wormhole)
{
wormholes.Add(wormhole.channel, wormhole);
}
public static void UpdateWormhole(Wormhole wormhole)
{
wormholes[wormhole.channel] = wormhole;
}
public static Wormhole GetWormhole(string channel)
{
return wormholes[channel];
}
public static Inventory GetInventoryForChest(uint chestID)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: 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)
return GetWormhole(chestChannelMap[chestID]).inventory;
}
public static Inventory GetInventoryForChest(ChestInstance chestInstance)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: 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_0014: Unknown result type (might be due to invalid IL or missing references)
return GetInventoryForChest(chestInstance.commonInfo.instanceId);
}
public static List<Wormhole> GetAllWormholes()
{
return wormholes.Values.ToList();
}
public static void CheckForEmptyChannels()
{
int num = 0;
while (num < wormholes.Count)
{
string text = wormholes.Keys.ToList()[num];
if (GetNumChestsInChannel(text) == 0)
{
wormholes.Remove(text);
}
else
{
num++;
}
}
}
public static bool DoesChannelExist(string channel)
{
return wormholes.ContainsKey(channel);
}
public static ChestInstance GetAimedAtChest()
{
//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_002d: 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_0035: Unknown result type (might be due to invalid IL or missing references)
GenericMachineInstanceRef val = (GenericMachineInstanceRef)ModUtils.GetPrivateField<PlayerInteraction>("targetMachineRef", Player.instance.interaction);
return MachineManager.instance.Get<ChestInstance, ChestDefinition>(((GenericMachineInstanceRef)(ref val)).index, (MachineTypeEnum)3);
}
public static bool IsChestWormholeChest(ChestInstance chest)
{
//IL_0006: 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)
return chestChannelMap.ContainsKey(chest.commonInfo.instanceId);
}
public static int GetCostToCreateOrLink()
{
return Mathf.CeilToInt(100f * Mathf.Pow(1.05f, (float)chestChannelMap.Count));
}
public static int GetNumChestsInChannel(string channel)
{
int num = 0;
foreach (string value in chestChannelMap.Values)
{
if (value.Equals(channel))
{
num++;
}
}
return num;
}
public static void SaveData(string worldName)
{
Directory.CreateDirectory(dataFolder);
Directory.CreateDirectory(dataFolder + "/" + worldName);
string path = dataFolder + "/" + worldName + "/Wormholes.txt";
List<string> list = new List<string>();
foreach (Wormhole allWormhole in GetAllWormholes())
{
list.Add(allWormhole.Serialise());
}
File.WriteAllLines(path, list);
string path2 = dataFolder + "/" + worldName + "/ChestChannelMap.txt";
List<string> list2 = new List<string>();
foreach (KeyValuePair<uint, string> item in chestChannelMap)
{
list2.Add($"{item.Key}|{item.Value}");
}
File.WriteAllLines(path2, list2);
}
public static void LoadData(string worldName)
{
string path = dataFolder + "/" + worldName + "/Wormholes.txt";
if (File.Exists(path))
{
wormholes.Clear();
string[] array = File.ReadAllLines(path);
string[] array2 = array;
foreach (string serial in array2)
{
AddWormhole(new Wormhole(serial));
}
string path2 = dataFolder + "/" + worldName + "/ChestChannelMap.txt";
chestChannelMap.Clear();
string[] array3 = File.ReadAllLines(path2);
string[] array4 = array3;
foreach (string text in array4)
{
uint key = uint.Parse(text.Split(new char[1] { '|' })[0]);
string value = text.Split(new char[1] { '|' })[1];
chestChannelMap.Add(key, value);
}
}
}
}
public class Wormhole
{
public string channel;
public Inventory inventory = new Inventory
{
myStacks = (ResourceStack[])(object)new ResourceStack[56],
numSlots = 56
};
public string Serialise()
{
//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)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
string text = channel;
if (inventory.myStacks != null)
{
ResourceStack[] myStacks = inventory.myStacks;
for (int i = 0; i < myStacks.Length; i++)
{
ResourceStack val = myStacks[i];
if (!((ResourceStack)(ref val)).isEmpty)
{
text += $"|{((UniqueIdScriptableObject)((ResourceStack)(ref val)).info).uniqueId},{val.count}";
}
}
}
else
{
text += "|null,null";
}
return text;
}
public Wormhole()
{
}//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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)
public Wormhole(string serial)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < 56; i++)
{
inventory.myStacks[i] = ResourceStack.CreateEmptyStack();
}
string[] array = serial.Split(new char[1] { '|' });
channel = array[0];
for (int j = 1; j < array.Count(); j++)
{
string[] array2 = array[j].Split(new char[1] { ',' });
string text = array2[0];
string text2 = array2[1];
if (!(text == "null") && !(text2 == "null"))
{
int num = int.Parse(text);
int num2 = int.Parse(text2);
((Inventory)(ref inventory)).AddResources(num, num2, true);
}
}
}
}
[BepInPlugin("com.equinox.WormholeChests", "WormholeChests", "2.0.0")]
public class WormholeChestsPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.equinox.WormholeChests";
private const string PluginName = "WormholeChests";
private const string VersionString = "2.0.0";
private static readonly Harmony Harmony = new Harmony("com.equinox.WormholeChests");
public static ManualLogSource Log = new ManualLogSource("WormholeChests");
public static Texture2D wormholeTexture;
public static ConfigEntry<bool> freeWormholeChests;
public static ConfigEntry<float> channelBoxXOffset;
public static ConfigEntry<float> channelBoxYOffset;
public static ConfigEntry<float> channelBoxWidth;
public static ConfigEntry<float> createButtonXOffset;
private void Awake()
{
//IL_007a: 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_0099: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: WormholeChests, VersionString: 2.0.0 is loading...");
Harmony.PatchAll();
ModUtils.GameDefinesLoaded += OnGameDefinesLoaded;
ModUtils.MachineManagerLoaded += OnMachineManagerLoaded;
CreateConfigEntries();
ApplyPatches();
ChestGUI.LoadImages();
Sprite sprite = Sprite.Create(wormholeTexture, new Rect(0f, 0f, (float)((Texture)wormholeTexture).width, (float)((Texture)wormholeTexture).height), new Vector2(0f, 0f), 512f);
NewUnlockDetails val = new NewUnlockDetails
{
category = (TechCategory)5,
coreTypeNeeded = (CoreType)2,
coreCountNeeded = 2000,
description = "Allow chests on the same channel to share inventories.",
displayName = "Wormhole Chests",
numScansNeeded = 0,
requiredTier = (ResearchTier)2,
treePosition = 0,
sprite = sprite
};
ModUtils.AddNewUnlock(val, false);
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: WormholeChests, VersionString: 2.0.0 is loaded.");
Log = ((BaseUnityPlugin)this).Logger;
}
private void OnGUI()
{
if (ChestGUI.shouldShowGUI)
{
ChestGUI.DrawChestGUI();
}
}
private void OnGameDefinesLoaded(object sender, EventArgs e)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
Unlock unlockByName = ModUtils.GetUnlockByName("Core Boost (Threshing)", false);
Unlock unlockByName2 = ModUtils.GetUnlockByName("Core Boost (Mining)", false);
ModUtils.UpdateUnlockTier("Wormhole Chests", unlockByName.requiredTier, false);
ModUtils.UpdateUnlockTreePosition("Wormhole Chests", unlockByName2.treePosition, false);
}
private void OnMachineManagerLoaded(object sender, EventArgs e)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: 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)
//IL_0062: 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_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
WormholeManager.LoadData(SaveState.instance.metadata.worldName);
Log.LogInfo((object)"WormholeChests Loaded");
MachineInstanceList<ChestInstance, ChestDefinition> machineList = MachineManager.instance.GetMachineList<ChestInstance, ChestDefinition>((MachineTypeEnum)3);
for (int i = 0; i < machineList.myArray.Length; i++)
{
ChestInstance val = machineList.myArray[i];
uint instanceId = val.commonInfo.instanceId;
if (WormholeManager.chestChannelMap.ContainsKey(instanceId))
{
val.commonInfo.inventories[0] = WormholeManager.GetInventoryForChest(instanceId);
}
}
}
private void CreateConfigEntries()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Expected O, but got Unknown
freeWormholeChests = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Free Wormhole Chests", false, new ConfigDescription("Disables the cost of creating Wormhole Chests. Cheat, not recommended.", (AcceptableValueBase)null, Array.Empty<object>()));
channelBoxXOffset = ((BaseUnityPlugin)this).Config.Bind<float>("GUI Layout", "Channel Box X Offset", 32f, new ConfigDescription("Controls the horizontal position of the Channel box in a Chest's GUI.", (AcceptableValueBase)null, Array.Empty<object>()));
channelBoxYOffset = ((BaseUnityPlugin)this).Config.Bind<float>("GUI Layout", "Channel Box Y Offset", -355f, new ConfigDescription("Controls the vertical position of the Channel box in a Chest's GUI.", (AcceptableValueBase)null, Array.Empty<object>()));
channelBoxWidth = ((BaseUnityPlugin)this).Config.Bind<float>("GUI Layout", "Channel Box Width", 240f, new ConfigDescription("Controls the width of the Channel box in a Chest's GUI.", (AcceptableValueBase)null, Array.Empty<object>()));
createButtonXOffset = ((BaseUnityPlugin)this).Config.Bind<float>("GUI Layout", "Create Button X Offset", 444f, new ConfigDescription("Controls the horizontal position of the Create / Link button in a Chest's GUI.", (AcceptableValueBase)null, Array.Empty<object>()));
}
private void ApplyPatches()
{
Harmony.CreateAndPatchAll(typeof(ChestDefinitionPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(ChestInstancePatch), (string)null);
Harmony.CreateAndPatchAll(typeof(InventoryNavigatorPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(SaveStatePatch), (string)null);
}
}
}
namespace WormholeChests.Patches
{
internal class ChestDefinitionPatch
{
[HarmonyPatch(typeof(MachineDefinition<ChestInstance, ChestDefinition>), "OnDeconstruct")]
[HarmonyPostfix]
private static void UpdateChestMap(ChestDefinition __instance, ref ChestInstance erasedInstance)
{
//IL_005b: 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_008a: Unknown result type (might be due to invalid IL or missing references)
uint instanceId = erasedInstance.commonInfo.instanceId;
if (!WormholeManager.chestChannelMap.ContainsKey(instanceId))
{
return;
}
int numChestsInChannel = WormholeManager.GetNumChestsInChannel(WormholeManager.chestChannelMap[erasedInstance.commonInfo.instanceId]);
if (numChestsInChannel > 1)
{
ResourceStack[] myStacks = ((ChestInstance)(ref erasedInstance)).GetInventory().myStacks;
for (int i = 0; i < myStacks.Length; i++)
{
ResourceStack val = myStacks[i];
if (!((ResourceStack)(ref val)).isEmpty)
{
((InventoryWrapper)Player.instance.inventory).TryRemoveResources(((UniqueIdScriptableObject)((ResourceStack)(ref val)).info).uniqueId, val.count);
}
}
}
WormholeManager.chestChannelMap.Remove(instanceId);
WormholeManager.CheckForEmptyChannels();
}
}
internal class ChestInstancePatch
{
private static bool hasLogged;
[HarmonyPatch(typeof(ChestInstance), "GetInventory")]
[HarmonyPrefix]
private static void GetWormholeInsteadOfInventory(ChestInstance __instance)
{
//IL_0001: 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_000d: 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_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)
if (WormholeManager.IsChestWormholeChest(__instance))
{
__instance.commonInfo.inventories[0] = WormholeManager.GetInventoryForChest(__instance);
}
}
}
internal class InventoryNavigatorPatch
{
[HarmonyPatch(typeof(InventoryNavigator), "OnOpen")]
[HarmonyPrefix]
private static void ShowGUI(InventoryNavigator __instance)
{
//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_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
Unlock unlockByName = ModUtils.GetUnlockByName("Wormhole Chests", false);
if (TechTreeState.instance.IsUnlockActive(((UniqueIdScriptableObject)unlockByName).uniqueId))
{
ChestGUI.shouldShowGUI = true;
ChestInstance aimedAtChest = WormholeManager.GetAimedAtChest();
uint num = (ChestGUI.currentChestID = MACHINE_INSTANCE_HELPER_EXTENSIONS.GetCommonInfo<ChestInstance>(ref aimedAtChest).instanceId);
WormholeChestsPlugin.Log.LogInfo((object)$"Opened Chest {num}");
if (WormholeManager.chestChannelMap.ContainsKey(num))
{
ChestGUI.channel = WormholeManager.chestChannelMap[num];
aimedAtChest.commonInfo.inventories[0] = WormholeManager.GetWormhole(ChestGUI.channel).inventory;
}
}
}
[HarmonyPatch(typeof(InventoryNavigator), "OnClose")]
[HarmonyPrefix]
private static void HideGui()
{
InputHandler.instance.uiInputBlocked = false;
ChestGUI.shouldShowGUI = false;
ChestGUI.channel = "";
}
}
internal class SaveStatePatch
{
[HarmonyPatch(typeof(SaveState), "SaveToFile")]
[HarmonyPostfix]
private static void SaveWormholes()
{
WormholeManager.SaveData(SaveState.instance.metadata.worldName);
WormholeChestsPlugin.Log.LogInfo((object)"WormholeChests Saved");
}
}
}