using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using EquinoxsDebuggingTools;
using EquinoxsModUtils;
using EquinoxsModUtils.Additions;
using HarmonyLib;
using UnityEngine;
using VoidChests.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("VoidChests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VoidChests")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c8dfb882-3b44-4645-a87c-e0937d8b1b91")]
[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 VoidChests
{
public static class ContentAdder
{
public static void AddVoidChest()
{
//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)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: 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_0022: 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_0034: 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_0047: 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_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Expected O, but got Unknown
//IL_0088: 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_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_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: 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_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: 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_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Expected O, but got Unknown
NewResourceDetails val = new NewResourceDetails
{
name = "Void Chest",
description = "Voids all items inserted into it",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
headerTitle = "Logistics",
subHeaderTitle = "Utility",
maxStackCount = 50,
sortPriority = 998,
unlockName = "Basic Logistics",
parentName = "Container",
sprite = Images.LoadSpriteFromFile("VoidChests.Images.VoidChest.png", false)
};
ChestDefinition obj = ScriptableObject.CreateInstance<ChestDefinition>();
((BuilderInfo)obj).inventorySizes = new List<Vector2Int>
{
new Vector2Int(1, 1)
};
obj.numberOfSlots = 1;
EMUAdditions.AddNewMachine<ChestInstance, ChestDefinition>((MachineDefinition<ChestInstance, ChestDefinition>)(object)obj, val, false);
EMUAdditions.AddNewRecipe(new NewRecipeDetails
{
GUID = "com.equinox.VoidChests",
craftingMethod = (CraftingMethod)0,
craftTierRequired = 0,
duration = 0.1f,
ingredients = new List<RecipeResourceInfo>
{
new RecipeResourceInfo
{
name = "Iron Components",
quantity = 8
},
new RecipeResourceInfo
{
name = "Iron Ingot",
quantity = 6
}
},
outputs = new List<RecipeResourceInfo>
{
new RecipeResourceInfo
{
name = "Void Chest",
quantity = 1
}
},
sortPriority = 10,
unlockName = "Basic Logistics"
}, false);
}
}
[BepInPlugin("com.equinox.VoidChests", "VoidChests", "2.1.2")]
public class VoidChestsPlugin : BaseUnityPlugin
{
internal const string MyGUID = "com.equinox.VoidChests";
private const string PluginName = "VoidChests";
private const string VersionString = "2.1.2";
private static readonly Harmony Harmony = new Harmony("com.equinox.VoidChests");
internal static ManualLogSource Log = new ManualLogSource("VoidChests");
internal static List<uint> voidChestIDs = new List<uint>();
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: VoidChests, VersionString: 2.1.2 is loading...");
ApplyPatches();
BindEvents();
ContentAdder.AddVoidChest();
LoadPrefab();
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: VoidChests, VersionString: 2.1.2 has loaded.");
Log = ((BaseUnityPlugin)this).Logger;
}
private void FixedUpdate()
{
//IL_003a: 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)
MachineInstanceRef<ChestInstance> val = default(MachineInstanceRef<ChestInstance>);
foreach (uint voidChestID in voidChestIDs)
{
if (MachineManager.instance.GetRefFromId<ChestInstance>(voidChestID, ref val))
{
ref Inventory inventory = ref val.GetInventory(0);
for (int i = 0; i < inventory.myStacks.Length; i++)
{
inventory.myStacks[i] = ResourceStack.CreateEmptyStack();
}
}
}
}
private void OnGameDefinesLoaded()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: 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_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)
ChestDefinition val = (ChestDefinition)Resources.GetResourceInfoByName("Void Chest", false);
((BuilderInfo)val).inventorySizes = new List<Vector2Int>
{
new Vector2Int(1, 1)
};
((BuilderInfo)val).invSizeOutput = new Vector2Int(1, 1);
}
private void OnSaveStateLoaded(object sender, EventArgs e)
{
sender.ToString();
}
private void OnGameLoaded()
{
}
private void OnGameSaved(object sender, EventArgs e)
{
sender.ToString();
}
private void ApplyPatches()
{
Harmony.CreateAndPatchAll(typeof(FlowManagerPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(MachineDefinitionPatch), (string)null);
}
private void BindEvents()
{
Events.GameDefinesLoaded += OnGameDefinesLoaded;
Events.SaveStateLoaded += OnSaveStateLoaded;
Events.GameLoaded += OnGameLoaded;
Events.GameSaved += OnGameSaved;
Events.GameUnloaded += MachineDefinitionPatch.OnGameUnloaded;
}
private void LoadPrefab()
{
MachineDefinitionPatch.prefab = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("VoidChests.VoidChest")).LoadAsset<GameObject>("assets/void_box.prefab");
}
}
}
namespace VoidChests.Patches
{
internal class FlowManagerPatch
{
[HarmonyPatch(typeof(FlowManager), "SwitchStrataTrampoline")]
[HarmonyPostfix]
private static void RedoVisuals()
{
MachineDefinitionPatch.RedoVisualsOnStrataChanged();
}
}
internal class MachineDefinitionPatch
{
public static GameObject prefab;
private static Dictionary<uint, GameObject> visualsMap = new Dictionary<uint, GameObject>();
[HarmonyPatch(typeof(MachineDefinition<ChestInstance, ChestDefinition>), "OnBuild")]
[HarmonyPostfix]
private static void AddToVoidChestsList(MachineInstanceRef<ChestInstance> instRef)
{
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
if (((ResourceInfo)((ChestInstance)(ref instRef.Get())).myDef).displayName != "Void Chest")
{
return;
}
VoidChestsPlugin.voidChestIDs.Add(instRef.GetCommonInfo().instanceId);
EDT.Log("General", $"Added chest #{instRef.GetCommonInfo().instanceId} to voidChestIDs");
if (instRef.gridInfo.strata == GameState.instance.GetStrata())
{
GameObject val = Object.Instantiate<GameObject>(prefab, ((GridInfo)(ref instRef.gridInfo)).BottomCenter, Quaternion.Euler(0f, (float)instRef.gridInfo.yawRot, 0f));
val.transform.localScale = new Vector3(1.01f, 1.01f, 1.01f);
if (visualsMap.ContainsKey(instRef.instanceId))
{
Object.Destroy((Object)(object)visualsMap[instRef.instanceId]);
}
visualsMap[instRef.instanceId] = val;
}
}
[HarmonyPatch(typeof(MachineDefinition<ChestInstance, ChestDefinition>), "OnDeconstruct")]
[HarmonyPrefix]
private static void RemoveVisuals(ref InserterInstance erasedInstance)
{
if (!(((ResourceInfo)((InserterInstance)(ref erasedInstance)).myDef).displayName != "Void Chest"))
{
Object.Destroy((Object)(object)visualsMap[erasedInstance.commonInfo.instanceId]);
visualsMap.Remove(erasedInstance.commonInfo.instanceId);
}
}
public static void RedoVisualsOnStrataChanged()
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: 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)
if (!LoadingStates.hasGameLoaded)
{
return;
}
ClearVisuals();
IMachineInstanceRef val = default(IMachineInstanceRef);
foreach (uint voidChestID in VoidChestsPlugin.voidChestIDs)
{
if (MachineManager.instance.GetRefFromId(voidChestID, ref val) && val.gridInfo.strata == GameState.instance.GetStrata())
{
GameObject val2 = Object.Instantiate<GameObject>(prefab, ((GridInfo)(ref val.gridInfo)).BottomCenter, Quaternion.Euler(0f, (float)val.gridInfo.yawRot, 0f));
val2.transform.localScale = new Vector3(1.01f, 1.01f, 1.01f);
if (visualsMap.ContainsKey(val.instanceId))
{
Object.Destroy((Object)(object)visualsMap[val.instanceId]);
}
visualsMap[val.instanceId] = val2;
}
}
}
internal static void OnGameUnloaded()
{
ClearVisuals();
}
private static void ClearVisuals()
{
Debug.Log((object)"Clearing Void Chest Visuals");
foreach (GameObject value in visualsMap.Values)
{
Object.Destroy((Object)(object)value);
}
visualsMap.Clear();
}
}
}