Decompiled source of Better Blast Furnaces v1.0.0

BetterBlastFurnaces.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BetterBlastFurnaces")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Turns Blast Furnaces into a proper smelter upgrade.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterBlastFurnaces")]
[assembly: AssemblyTitle("BetterBlastFurnaces")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BlastFurnace
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BetterBlastFurnaces";

		public const string PLUGIN_NAME = "BetterBlastFurnaces";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace BetterBlastFurnaces
{
	[BepInPlugin("com.joryjuky.betterblastfurnaces", "BetterBlastFurnaces", "1.0.0")]
	public class BetterBlastFurnaces : BaseUnityPlugin
	{
		private const string pluginGUID = "com.joryjuky.betterblastfurnaces";

		private const string pluginName = "BetterBlastFurnaces";

		private const string pluginVersion = "1.0.0";

		private ConfigEntry<float> speedMultiplier;

		private static float baseSmeltSpeed = 30f;

		private static float fastSmeltSpeed;

		private static List<ItemConversion> newConversions;

		private static List<string> spedUpOres;

		private void Awake()
		{
			speedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Smelt Speed Multiplier", 2f, "Smelting speed multiplier for lower-tier (under blackmetal) ores. Defaults to 2.");
			fastSmeltSpeed = baseSmeltSpeed / speedMultiplier.Value;
			Harmony.CreateAndPatchAll(typeof(BetterBlastFurnaces), (string)null);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private static void GetBaseSmelterConversions(ref ZNetScene __instance)
		{
			if (newConversions != null)
			{
				return;
			}
			GameObject val = __instance.m_prefabs.Find((GameObject prefab) => ((Object)prefab).name == "smelter");
			if (!((Object)(object)val == (Object)null))
			{
				newConversions = val.GetComponent<Smelter>().m_conversion;
				spedUpOres = newConversions.Select((ItemConversion conv) => ((Object)((Component)conv.m_from).gameObject).name).ToList();
			}
		}

		private static void SetProcessingTime(ref Smelter smelter)
		{
			string queuedOre = smelter.GetQueuedOre();
			if (!(queuedOre == ""))
			{
				smelter.m_secPerProduct = (spedUpOres.Contains(queuedOre) ? fastSmeltSpeed : baseSmeltSpeed);
			}
		}

		private static bool IsBlastFurnace(ref Smelter smelter)
		{
			return smelter.m_name == "$piece_blastfurnace";
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Smelter), "Awake")]
		private static void AwakePatch(ref Smelter __instance)
		{
			if (IsBlastFurnace(ref __instance))
			{
				__instance.m_conversion.AddRange(newConversions);
				SetProcessingTime(ref __instance);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Smelter), "QueueOre")]
		private static void QueueOrePatch(ref Smelter __instance)
		{
			if (IsBlastFurnace(ref __instance) && __instance.GetQueueSize() == 1)
			{
				SetProcessingTime(ref __instance);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Smelter), "RemoveOneOre")]
		private static void RemoveOneOrePatch(ref Smelter __instance)
		{
			if (IsBlastFurnace(ref __instance))
			{
				SetProcessingTime(ref __instance);
			}
		}
	}
}