Decompiled source of BlastFurnaceFix AllOresPatch v1.0.4

BlastFurnaceFix.dll

Decompiled 2 weeks ago
using System;
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 BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BlastFurnaceFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BlastFurnaceFix")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a2593121-5cf1-470c-aee4-2f969f458c0e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BlastFurnaceFix;

[BepInPlugin("com.github.zimmaster7.spacedrive.bffix", "Blast Furnace Fix - All Ores Patch", "1.0.4")]
[BepInProcess("valheim.exe")]
[BepInProcess("valheim_server.exe")]
[HarmonyPatch]
public class BFFix : BaseUnityPlugin
{
	private const string GUID = "com.github.zimmaster7.spacedrive.bffix";

	private const string VERSION = "1.0.4";

	private static Dictionary<string, ItemDrop> metals = new Dictionary<string, ItemDrop>(StringComparer.OrdinalIgnoreCase)
	{
		{ "copperore", null },
		{ "copperscrap", null },
		{ "Copper", null },
		{ "bronzescrap", null },
		{ "Bronze", null },
		{ "ironscrap", null },
		{ "ironore", null },
		{ "Iron", null },
		{ "tinore", null },
		{ "Tin", null },
		{ "silverore", null },
		{ "Silver", null }
	};

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("com.github.zimmaster7.spacedrive.bffix").PatchAll();
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Smelter), "Awake")]
	private static void BlastFurnacePatch(ref Smelter __instance)
	{
		if (__instance.m_name != "$piece_blastfurnace")
		{
			return;
		}
		ObjectDB instance = ObjectDB.instance;
		if ((Object)(object)instance == (Object)null || instance.m_items == null)
		{
			return;
		}
		foreach (GameObject item in instance.m_items)
		{
			if ((Object)(object)item == (Object)null)
			{
				continue;
			}
			ItemDrop component = item.GetComponent<ItemDrop>();
			if (!((Object)(object)component == (Object)null))
			{
				string name = ((Object)item).name;
				if (metals.ContainsKey(name))
				{
					metals[name] = component;
				}
			}
		}
		List<ItemConversion> list = new List<ItemConversion>();
		AddSafeConversion(list, "copperore", "Copper");
		AddSafeConversion(list, "copperscrap", "Copper");
		AddSafeConversion(list, "bronzescrap", "Bronze");
		AddSafeConversion(list, "tinore", "Tin");
		AddSafeConversion(list, "ironscrap", "Iron");
		AddSafeConversion(list, "ironore", "Iron");
		AddSafeConversion(list, "silverore", "Silver");
		foreach (ItemConversion conversion in list)
		{
			if (!__instance.m_conversion.Any((ItemConversion c) => (Object)(object)c.m_from == (Object)(object)conversion.m_from))
			{
				__instance.m_conversion.Add(conversion);
			}
		}
	}

	private static void AddSafeConversion(List<ItemConversion> list, string fromKey, string toKey)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_006d: Expected O, but got Unknown
		if (metals.ContainsKey(fromKey) && (Object)(object)metals[fromKey] != (Object)null && metals.ContainsKey(toKey) && (Object)(object)metals[toKey] != (Object)null)
		{
			list.Add(new ItemConversion
			{
				m_from = metals[fromKey],
				m_to = metals[toKey]
			});
		}
	}
}