Decompiled source of PowerSmelters v1.0.0

plugins/PowerSmelters.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
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("PowerSmelters")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PowerSmelters")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e04bb637-333a-463f-a50a-7cff3e8033f1")]
[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 PowerSmelters
{
	[BepInPlugin("com.casper.PowerSmelters", "PowerSmelters", "1.0.0")]
	public class PowerSmelters : BaseUnityPlugin
	{
		public static class SharedState
		{
			public static bool IsInspectingSmelter { get; set; }

			public static int CurrentPowerConsumption { get; set; }
		}

		private const string MyGUID = "com.casper.PowerSmelters";

		private const string PluginName = "PowerSmelters";

		private const string VersionString = "1.0.0";

		private static readonly Harmony Harmony = new Harmony("com.casper.PowerSmelters");

		public static ManualLogSource Log = new ManualLogSource("PowerSmelters");

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: PowerSmelters, VersionString: 1.0.0 is loading...");
			Harmony.PatchAll();
		}

		private void OnGUI()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			if (SharedState.IsInspectingSmelter && !UIManager.instance.anyMenuOpen && !Player.instance.builder.HasBuilder)
			{
				GUIStyle val = new GUIStyle(GUI.skin.label);
				val.normal.textColor = Color.white;
				val.fontSize = 24;
				GUIStyle val2 = val;
				string text = $"Current Power Consumption: {SharedState.CurrentPowerConsumption}kW";
				GUI.Label(new Rect(20f, (float)(Screen.height - 100), 560f, 50f), text, val2);
			}
		}
	}
}
namespace PowerSmelters.Patches
{
	[HarmonyPatch(typeof(InspectorUI), "SetInspectingMachine")]
	public static class DisplayCustomGUIForSmelterPatch
	{
		private static bool Prefix(InspectorUI __instance, ref GenericMachineInstanceRef machineHit)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			if (PowerSmelters.SharedState.IsInspectingSmelter = (int)machineHit._typeIndex == 16)
			{
				__instance.ClearInspected();
				PowerSmelters.SharedState.CurrentPowerConsumption = ((GenericMachineInstanceRef)(ref machineHit)).CurPowerConsumption;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(SmelterInstance))]
	[HarmonyPatch("GetPowerInfoRef")]
	internal class SmelterInstance_GetPowerInfoRef_Patch
	{
		private static void Postfix(SmelterInstance __instance, ref PowerInfo __result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (SaveState.GetResInfoFromId(__instance.commonInfo.resId).displayName.Equals("Smelter MKII"))
			{
				((PowerInfo)(ref __instance.powerInfo)).UpdateSimplePowerUsage(true);
				__instance._myDef.usesFuel = false;
				__result.usesPowerSystem = true;
				__result.maxPowerConsumption = 1200;
				__result.hasPowerConnection = true;
			}
			if (SaveState.GetResInfoFromId(__instance.commonInfo.resId).displayName.Equals("Smelter"))
			{
				((PowerInfo)(ref __instance.powerInfo)).UpdateSimplePowerUsage(true);
				__instance._myDef.usesFuel = false;
				__result.usesPowerSystem = true;
				__result.maxPowerConsumption = 200;
				__result.hasPowerConnection = true;
			}
		}
	}
}