Decompiled source of SmelterQueue v1.0.2

SmelterQueue.dll

Decompiled 13 hours ago
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 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("SmelterQueue")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SmelterQueue")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7a4e200a-49d4-4905-9fc5-86d8f9fc46b6")]
[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 SmelterQueue;

[BepInPlugin("andrew.smelterqueue", "Smelter Queue", "1.0.2")]
public class SmelterQueuePlugin : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("andrew.smelterqueue").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Smelter Queue mod loaded OK");
	}

	private void Update()
	{
		if (!Input.GetKeyDown((KeyCode)103))
		{
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer == (Object)null))
		{
			Smelter hoveredSmelter = GetHoveredSmelter();
			if (!((Object)(object)hoveredSmelter == (Object)null))
			{
				FilterTools.CycleFilter(hoveredSmelter, localPlayer);
			}
		}
	}

	public static Smelter GetHoveredSmelter()
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return null;
		}
		GameObject hoverObject = ((Humanoid)localPlayer).GetHoverObject();
		if ((Object)(object)hoverObject == (Object)null)
		{
			return null;
		}
		return hoverObject.GetComponentInParent<Smelter>();
	}

	public static Smelter GetHoveredOreIntake()
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return null;
		}
		GameObject hoverObject = ((Humanoid)localPlayer).GetHoverObject();
		if ((Object)(object)hoverObject == (Object)null)
		{
			return null;
		}
		Smelter componentInParent = hoverObject.GetComponentInParent<Smelter>();
		if ((Object)(object)componentInParent == (Object)null)
		{
			return null;
		}
		Switch componentInParent2 = hoverObject.GetComponentInParent<Switch>();
		if ((Object)(object)componentInParent2 == (Object)null)
		{
			return null;
		}
		if ((Object)(object)componentInParent2 != (Object)(object)componentInParent.m_addOreSwitch)
		{
			return null;
		}
		return componentInParent;
	}

	private void OnGUI()
	{
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Expected O, but got Unknown
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: 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_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: 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)
		Smelter hoveredOreIntake = GetHoveredOreIntake();
		if ((Object)(object)hoveredOreIntake == (Object)null)
		{
			return;
		}
		ZDO zDO = FilterTools.GetZDO(hoveredOreIntake);
		if (zDO == null)
		{
			return;
		}
		int num = zDO.GetInt("queued", 0);
		int num2 = 10;
		int num3 = 40;
		int num4 = 4;
		int num5 = 8;
		int num6 = 22;
		int num7 = num5 * 2 + num2 * num3 + (num2 - 1) * num4;
		int num8 = num5 * 2 + num3 + num6;
		float num9 = (float)(Screen.width - num7) / 2f;
		float num10 = (float)Screen.height * 0.66f;
		GUI.Box(new Rect(num9, num10, (float)num7, (float)num8), "");
		string text = "Mode: " + FilterTools.FilterDisplayName(FilterTools.GetFilter(hoveredOreIntake)) + "   [G to change]";
		GUIStyle val = new GUIStyle(GUI.skin.label);
		val.alignment = (TextAnchor)4;
		GUI.Label(new Rect(num9, num10 + 4f, (float)num7, (float)num6), text, val);
		Rect val2 = default(Rect);
		Rect val3 = default(Rect);
		Rect val4 = default(Rect);
		for (int i = 0; i < num2; i++)
		{
			float num11 = num9 + (float)num5 + (float)(i * (num3 + num4));
			float num12 = num10 + (float)num5 + (float)num6;
			((Rect)(ref val2))..ctor(num11, num12, (float)num3, (float)num3);
			GUI.Box(val2, "");
			if (i < num)
			{
				string prefabName = zDO.GetString("item" + i, "");
				Sprite icon = GetIcon(prefabName);
				if ((Object)(object)icon != (Object)null)
				{
					Texture2D texture = icon.texture;
					Rect textureRect = icon.textureRect;
					((Rect)(ref val3))..ctor(((Rect)(ref textureRect)).x / (float)((Texture)texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)texture).height);
					((Rect)(ref val4))..ctor(((Rect)(ref val2)).x + 3f, ((Rect)(ref val2)).y + 3f, ((Rect)(ref val2)).width - 6f, ((Rect)(ref val2)).height - 6f);
					GUI.DrawTextureWithTexCoords(val4, (Texture)(object)texture, val3);
				}
			}
		}
	}

	private static Sprite GetIcon(string prefabName)
	{
		if ((Object)(object)ZNetScene.instance == (Object)null)
		{
			return null;
		}
		GameObject prefab = ZNetScene.instance.GetPrefab(prefabName);
		if ((Object)(object)prefab == (Object)null)
		{
			return null;
		}
		ItemDrop component = prefab.GetComponent<ItemDrop>();
		if ((Object)(object)component == (Object)null)
		{
			return null;
		}
		Sprite[] icons = component.m_itemData.m_shared.m_icons;
		if (icons == null || icons.Length == 0)
		{
			return null;
		}
		return icons[0];
	}
}
public static class FilterTools
{
	public static ZDO GetZDO(Smelter smelter)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		ZNetView val = (ZNetView)AccessTools.Field(typeof(Smelter), "m_nview").GetValue(smelter);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		return val.GetZDO();
	}

	public static string GetFilter(Smelter smelter)
	{
		ZDO zDO = GetZDO(smelter);
		if (zDO == null)
		{
			return "";
		}
		return zDO.GetString("SQ_Filter", "");
	}

	public static void SetFilter(Smelter smelter, string value)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		ZNetView val = (ZNetView)AccessTools.Field(typeof(Smelter), "m_nview").GetValue(smelter);
		if (!((Object)(object)val == (Object)null) && val.GetZDO() != null)
		{
			if (!val.IsOwner())
			{
				val.ClaimOwnership();
			}
			val.GetZDO().Set("SQ_Filter", value);
		}
	}

	public static void CycleFilter(Smelter smelter, Player player)
	{
		string filter = GetFilter(smelter);
		List<ItemConversion> conversion = smelter.m_conversion;
		if (conversion == null || conversion.Count == 0)
		{
			return;
		}
		List<string> list = new List<string>();
		list.Add("");
		foreach (ItemConversion item in conversion)
		{
			string name = ((Object)((Component)item.m_from).gameObject).name;
			if (!(name == "IronOre"))
			{
				list.Add(name);
			}
		}
		int num = list.IndexOf(filter);
		if (num < 0)
		{
			num = 0;
		}
		int index = (num + 1) % list.Count;
		string text = list[index];
		SetFilter(smelter, text);
		((Character)player).Message((MessageType)2, "Mode: " + FilterDisplayName(text), 0, (Sprite)null);
	}

	public static string FilterDisplayName(string filter)
	{
		if (filter == "")
		{
			return "All ores";
		}
		return NiceName(filter) + " only";
	}

	public static string NiceName(string prefabName)
	{
		GameObject prefab = ZNetScene.instance.GetPrefab(prefabName);
		if ((Object)(object)prefab == (Object)null)
		{
			return prefabName;
		}
		ItemDrop component = prefab.GetComponent<ItemDrop>();
		if ((Object)(object)component == (Object)null)
		{
			return prefabName;
		}
		return Localization.instance.Localize(component.m_itemData.m_shared.m_name);
	}
}
[HarmonyPatch(typeof(Smelter), "OnAddOre")]
public static class SmelterAddOrePatch
{
	private static bool Prefix(Smelter __instance, Humanoid user, ref ItemData item, ref bool __result)
	{
		string filter = FilterTools.GetFilter(__instance);
		if (filter == "")
		{
			return true;
		}
		if (item == null)
		{
			foreach (ItemData allItem in user.GetInventory().GetAllItems())
			{
				if ((Object)(object)allItem.m_dropPrefab != (Object)null && ((Object)allItem.m_dropPrefab).name == filter)
				{
					item = allItem;
					return true;
				}
			}
			((Character)user).Message((MessageType)2, "This smelter only accepts " + FilterTools.NiceName(filter), 0, (Sprite)null);
			__result = false;
			return false;
		}
		if ((Object)(object)item.m_dropPrefab == (Object)null || ((Object)item.m_dropPrefab).name != filter)
		{
			((Character)user).Message((MessageType)2, "This smelter only accepts " + FilterTools.NiceName(filter), 0, (Sprite)null);
			__result = false;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(Smelter), "RPC_AddOre")]
public static class SmelterRpcAddOrePatch
{
	private static bool Prefix(Smelter __instance, string name)
	{
		//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_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_0065: 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)
		//IL_0079: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		string filter = FilterTools.GetFilter(__instance);
		if (filter == "")
		{
			return true;
		}
		if (name == filter)
		{
			return true;
		}
		GameObject prefab = ZNetScene.instance.GetPrefab(name);
		if ((Object)(object)prefab != (Object)null)
		{
			Vector3 val = ((Component)__instance).transform.position + Vector3.up * 1.5f + Random.insideUnitSphere * 0.3f;
			Object.Instantiate<GameObject>(prefab, val, Quaternion.identity);
		}
		return false;
	}
}