Decompiled source of StackFilterSizes v1.0.0

plugins/StackFilterSizes.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("StackFilterSizes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StackFilterSizes")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0f3e84d1-de20-45f3-9464-e66a2da48dfe")]
[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 StackFilterSizes;

[HarmonyPatch(typeof(PlayerInspector), "LateUpdate")]
public static class PlayerInspectorLateUpdatePatch
{
	private static GameObject lastHitObject;

	private static void Postfix(PlayerInspector __instance)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//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)
		//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_0093: 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_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: 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_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerInspector), "playerCamera");
		Transform val = (Transform)fieldInfo.GetValue(__instance);
		FieldInfo fieldInfo2 = AccessTools.Field(typeof(PlayerInspector), "collisionLayers");
		LayerMask val2 = (LayerMask)fieldInfo2.GetValue(__instance);
		FieldInfo fieldInfo3 = AccessTools.Field(typeof(PlayerInspector), "_machineHit");
		object value = fieldInfo3.GetValue(__instance);
		if ((Object)(object)val != (Object)null && SharedState.ShowDEBUG)
		{
			Ray val3 = default(Ray);
			((Ray)(ref val3))..ctor(val.position, val.forward);
			RaycastHit val4 = default(RaycastHit);
			if (Physics.Raycast(val3, ref val4, 100f, LayerMask.op_Implicit(val2)))
			{
				if (!((Object)(object)((Component)((RaycastHit)(ref val4)).collider).gameObject != (Object)(object)lastHitObject))
				{
					return;
				}
				SharedState.LastHitObjectTag = ((Component)((RaycastHit)(ref val4)).collider).gameObject.tag;
				SharedState.LastHitObjectLayer = LayerMask.LayerToName(((Component)((RaycastHit)(ref val4)).collider).gameObject.layer);
				if (value != null && value is GenericMachineInstanceRef val5)
				{
					if (!((GenericMachineInstanceRef)(ref val5)).IsValid())
					{
						Debug.Log((object)"Machine reference is not valid.");
						return;
					}
					SharedState.LastMachineInfo = $"Machine Hit ID: {val5}\n";
					Inventory[] inventoriesList = ((GenericMachineInstanceRef)(ref val5)).GetInventoriesList();
					if (inventoriesList != null && inventoriesList.Any())
					{
						Inventory val6 = inventoriesList.First();
						SharedState.InventoryDetails lastInventoryDetails = new SharedState.InventoryDetails
						{
							NumSlots = val6.numSlots,
							ItemStacks = (from s in val6.myStacks
								where s.id != -1
								select new SharedState.ItemStack
								{
									ItemID = s.id,
									Count = s.count,
									MaxStack = s.maxStack
								}).ToList()
						};
						SharedState.LastInventoryDetails = lastInventoryDetails;
					}
					else
					{
						Debug.Log((object)"No inventories found in the machine.");
						SharedState.LastInventoryDetails = null;
					}
				}
				lastHitObject = ((Component)((RaycastHit)(ref val4)).collider).gameObject;
			}
			else if ((Object)(object)lastHitObject != (Object)null)
			{
				lastHitObject = null;
				SharedState.LastHitObjectTag = "";
				SharedState.LastHitObjectLayer = "";
				SharedState.LastMachineInfo = "No object in sight.";
				SharedState.LastInventoryDetails = null;
			}
		}
		else if (SharedState.ShowDEBUG)
		{
			Debug.LogWarning((object)"PlayerInspectorLateUpdatePatch: playerCamera or collisionLayers is null.");
		}
	}
}
public static class InserterPatch
{
	[HarmonyPatch(typeof(InserterInstance), "get_maxStackSize")]
	public static class MaxStackSizePatch
	{
		[HarmonyPostfix]
		public static void Postfix(ref int __result, InserterInstance __instance)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (SharedState.PatchEnabled && __instance.isStack)
			{
				__result = SharedState.InserterValue;
			}
		}
	}
}
[BepInPlugin("com.casper.StackFilterSizes", "StackFilterSizes", "1.0.0.0")]
public class InserterModPlugin : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("com.casper.StackFilterSizes");
		val.PatchAll();
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)46))
		{
			SharedState.ShowGUI = !SharedState.ShowGUI;
		}
		if (Input.GetKeyDown((KeyCode)44))
		{
			SharedState.ShowDEBUG = !SharedState.ShowDEBUG;
		}
	}

	private void OnGUI()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: 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_005b: Expected O, but got Unknown
		//IL_0065: 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_0075: Expected O, but got Unknown
		//IL_007b: 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_0098: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		if (SharedState.ShowGUI)
		{
			float num = 640f;
			float num2 = 660f;
			float num3 = ((float)Screen.width - num) / 2f;
			float num4 = ((float)Screen.height - num2) / 2f;
			GUIStyle val = new GUIStyle(GUI.skin.window)
			{
				fontSize = 18,
				alignment = (TextAnchor)1
			};
			GUIStyle val2 = new GUIStyle(GUI.skin.button)
			{
				fontSize = 16
			};
			GUI.Window(0, new Rect(num3, num4, num, num2), new WindowFunction(DrawWindow), "Inserter Stack Size", val);
			DisplayModStatusLabel();
		}
		if (SharedState.ShowDEBUG)
		{
			DisplayMachineDebugInfo();
			DisplayInventoryInfo();
		}
	}

	private void DrawWindow(int windowID)
	{
		if (GUILayout.Button("4", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.InserterValue = 4;
		}
		if (GUILayout.Button("8", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.InserterValue = 8;
		}
		if (GUILayout.Button("12", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.InserterValue = 12;
		}
		if (GUILayout.Button("16", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.InserterValue = 16;
		}
		if (GUILayout.Button("20", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.InserterValue = 20;
		}
		if (GUILayout.Button("40", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.InserterValue = 40;
		}
		if (GUILayout.Button("100", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.InserterValue = 100;
		}
		if (GUILayout.Button("200", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.InserterValue = 200;
		}
		if (GUILayout.Button("400", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.InserterValue = 400;
		}
		if (GUILayout.Button("500", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.InserterValue = 500;
		}
		if (GUILayout.Button("Toggle Mod On/Off", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) }))
		{
			SharedState.PatchEnabled = !SharedState.PatchEnabled;
		}
	}

	private void DisplayModStatusLabel()
	{
		//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_0021: 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_0033: Expected O, but got Unknown
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			fontSize = 24,
			fontStyle = (FontStyle)1
		};
		val.normal.textColor = Color.white;
		GUIStyle val2 = val;
		Rect val3 = default(Rect);
		((Rect)(ref val3))..ctor(10f, (float)(Screen.height - 530), 300f, 30f);
		string text = (SharedState.PatchEnabled ? "Mod is On" : "Mod is Off");
		GUI.Label(val3, text, val2);
	}

	private void DisplayMachineDebugInfo()
	{
		//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_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		GUIStyle val = new GUIStyle(GUI.skin.box)
		{
			fontSize = 24,
			alignment = (TextAnchor)4,
			wordWrap = true
		};
		float num = 650f;
		float num2 = 250f;
		Rect val2 = default(Rect);
		((Rect)(ref val2))..ctor((float)Screen.width - num - 500f, (float)Screen.height - num2 - 600f, num, num2);
		string text = "Hit Object Tag:   " + SharedState.LastHitObjectTag + "\n\nLayer:   " + SharedState.LastHitObjectLayer + "\n\n" + SharedState.LastMachineInfo;
		GUI.Box(val2, text, val);
	}

	private void DisplayInventoryInfo()
	{
		//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_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		GUIStyle val = new GUIStyle(GUI.skin.box)
		{
			fontSize = 20,
			alignment = (TextAnchor)0,
			wordWrap = true
		};
		float num = 500f;
		float num2 = 1000f;
		float num3 = 650f;
		float num4 = (float)Screen.width - num3 - 500f;
		float num5 = num4 + num3 + 20f;
		float num6 = (float)Screen.height - num2 - 50f;
		Rect val2 = default(Rect);
		((Rect)(ref val2))..ctor(num5, num6 - 400f, num, num2);
		StringBuilder stringBuilder = new StringBuilder("Inventory Details:\n");
		if (SharedState.LastInventoryDetails != null)
		{
			int num7 = (from item in SharedState.LastInventoryDetails.ItemStacks
				where item.ItemID > 0
				select item.ItemID).Distinct().Count();
			int num8 = SharedState.LastInventoryDetails.NumSlots - num7;
			stringBuilder.Append($"Num Slots: {SharedState.LastInventoryDetails.NumSlots}\n");
			stringBuilder.Append($"Available Slots: {num8}\n\n");
			var enumerable = (from item in SharedState.LastInventoryDetails.ItemStacks
				where item.ItemID > 0
				group item by item.ItemID).Select(delegate(IGrouping<int, SharedState.ItemStack> group)
			{
				ResourceInfo resInfoFromId = SaveState.GetResInfoFromId(group.Key);
				string itemName = (((Object)(object)resInfoFromId != (Object)null) ? resInfoFromId.displayName : $"Item ID: {group.Key}");
				int totalCount = group.Sum((SharedState.ItemStack item) => item.Count);
				return new
				{
					ItemID = group.Key,
					TotalCount = totalCount,
					ItemName = itemName
				};
			});
			foreach (var item in enumerable)
			{
				stringBuilder.AppendLine($"{item.ItemName}: Total Count: {item.TotalCount}");
			}
		}
		else
		{
			stringBuilder.Append("No inventory details available.");
		}
		GUI.Box(val2, stringBuilder.ToString(), val);
	}
}
public static class SharedState
{
	public class InventoryDetails
	{
		public int NumSlots { get; set; }

		public List<ItemStack> ItemStacks { get; set; } = new List<ItemStack>();


		public int AvailableSlots => NumSlots - ItemStacks.Count;
	}

	public class ItemStack
	{
		public int ItemID { get; set; }

		public int Count { get; set; }

		public int MaxStack { get; set; }
	}

	public static bool ShowGUI = false;

	public static bool ShowDEBUG = false;

	public static int InserterValue = 100;

	public static bool PatchEnabled = false;

	public static bool FuelPatchEnabled = false;

	public static string LastHitObjectTag = "";

	public static string LastHitObjectLayer = "";

	public static string LastMachineInfo = "";

	public static InventoryDetails LastInventoryDetails { get; set; }
}