Decompiled source of AtlantumReactor v1.0.3

plugins/AtlantumReactor/AtlantumReactor.dll

Decompiled 4 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using AtlantumReactor;
using AtlantumReactor.Patches;
using BepInEx;
using BepInEx.Logging;
using EquinoxsModUtils;
using EquinoxsModUtils.Additions;
using FMOD.Studio;
using FMODUnity;
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("AtlantumReactor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AtlantumReactor")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("28b722e4-d316-4e48-998b-1678719ad5d9")]
[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")]
public static class AudioHelper
{
	public static AudioClip WAVToAudioClip(byte[] wavBytes, string clipName)
	{
		if (wavBytes.Length < 44)
		{
			AtlantumReactorPlugin.Log.LogError((object)"Invalid WAV file: Header too short.");
			return null;
		}
		int num = 0;
		string @string = Encoding.ASCII.GetString(wavBytes, num, 4);
		num += 4;
		if (@string != "RIFF")
		{
			AtlantumReactorPlugin.Log.LogError((object)"Invalid WAV file: No RIFF header.");
			return null;
		}
		num += 4;
		string string2 = Encoding.ASCII.GetString(wavBytes, num, 4);
		num += 4;
		if (string2 != "WAVE")
		{
			AtlantumReactorPlugin.Log.LogError((object)"Invalid WAV file: No WAVE header.");
			return null;
		}
		bool flag = false;
		bool flag2 = false;
		int num2 = 0;
		int num3 = 0;
		int num4 = 0;
		float[] array = null;
		while (num < wavBytes.Length)
		{
			string string3 = Encoding.ASCII.GetString(wavBytes, num, 4);
			int num5 = BitConverter.ToInt32(wavBytes, num + 4);
			num += 8;
			if (string3 == "fmt ")
			{
				flag = true;
				ushort num6 = BitConverter.ToUInt16(wavBytes, num);
				if (num6 != 1)
				{
					AtlantumReactorPlugin.Log.LogError((object)"Invalid WAV file: Only PCM format is supported.");
					return null;
				}
				num3 = BitConverter.ToUInt16(wavBytes, num + 2);
				num2 = BitConverter.ToInt32(wavBytes, num + 4);
				num4 = BitConverter.ToUInt16(wavBytes, num + 14);
				num += num5;
				continue;
			}
			if (string3.StartsWith("data") || string3 == "datapr")
			{
				flag2 = true;
				int num7 = num5 / (num4 / 8);
				array = new float[num7];
				for (int i = 0; i < num7; i++)
				{
					switch (num4)
					{
					case 16:
					{
						short num8 = BitConverter.ToInt16(wavBytes, num);
						array[i] = (float)num8 / 32768f;
						num += 2;
						break;
					}
					case 8:
						array[i] = (float)(wavBytes[num] - 128) / 128f;
						num++;
						break;
					}
				}
				break;
			}
			num += num5;
		}
		if (!flag || !flag2 || array == null)
		{
			AtlantumReactorPlugin.Log.LogError((object)"Failed to find necessary WAV header information.");
			return null;
		}
		AudioClip val = AudioClip.Create(clipName, array.Length, num3, num2, false);
		val.SetData(array, 0);
		return val;
	}
}
namespace AtlantumReactor
{
	[BepInPlugin("com.equinox.AtlantumReactor", "AtlantumReactor", "1.0.3")]
	public class AtlantumReactorPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.equinox.AtlantumReactor";

		private const string PluginName = "AtlantumReactor";

		private const string VersionString = "1.0.3";

		private static readonly Harmony Harmony = new Harmony("com.equinox.AtlantumReactor");

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

		public static SchematicsRecipeData reactorRecipe;

		private static AudioSource audioSource;

		private static bool audioLoaded = false;

		public static GameObject reactorPrefab;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: AtlantumReactor, VersionString: 1.0.3 is loading...");
			Harmony.PatchAll();
			ApplyPatches();
			ReactorGUI.LoadAssets();
			LoadPrefabs();
			AddContentToGame();
			ModUtils.TechTreeStateLoaded += OnTechTreeStateLoaded;
			ModUtils.GameLoaded += OnGameLoaded;
			byte[] embeddedResourceBytes = GetEmbeddedResourceBytes("AtlantumReactor.Assets.Audio.Ignition.wav");
			AudioClip val = AudioHelper.WAVToAudioClip(embeddedResourceBytes, "Ignition");
			if ((Object)(object)val == (Object)null)
			{
				Log.LogError((object)"Failed to load audio clip.");
				return;
			}
			audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
			audioSource.clip = val;
			audioSource.volume = 0.1f;
			audioLoaded = true;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: AtlantumReactor, VersionString: 1.0.3 is loaded.");
			Log = ((BaseUnityPlugin)this).Logger;
		}

		private void Update()
		{
			ReactorGUI.timeSinceClose += Time.deltaTime;
			ReactorGUI.timeSinceIgnition += Time.deltaTime;
			if (ReactorGUI.showGUI && (UnityInput.Current.GetKey((KeyCode)27) || UnityInput.Current.GetKey((KeyCode)9) || UnityInput.Current.GetKey((KeyCode)113) || UnityInput.Current.GetKey((KeyCode)101)))
			{
				ReactorGUI.showGUI = false;
				ReactorGUI.timeSinceClose = 0f;
				ModUtils.FreeCursor(false);
			}
		}

		private void OnGUI()
		{
			if (ReactorGUI.showGUI)
			{
				ReactorGUI.DrawGUI();
			}
		}

		private void OnTechTreeStateLoaded(object sender, EventArgs e)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			Unlock unlockByName = ModUtils.GetUnlockByName("Crank Generator MKII", false);
			Unlock unlockByName2 = ModUtils.GetUnlockByName("HVC Reach IV", false);
			Unlock unlockByName3 = ModUtils.GetUnlockByName("Atlantum Reactor", false);
			unlockByName3.treePosition = unlockByName.treePosition;
			unlockByName3.requiredTier = unlockByName2.requiredTier;
			unlockByName3.unlockedRecipes.Add(reactorRecipe);
		}

		private void OnGameLoaded(object sender, EventArgs e)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			MachineInstanceList<MemoryTreeInstance, MemoryTreeDefinition> machineList = MachineManager.instance.GetMachineList<MemoryTreeInstance, MemoryTreeDefinition>((MachineTypeEnum)30);
			for (int i = 0; i < machineList.myArray.Length; i++)
			{
				MemoryTreeInstance reactor = machineList.myArray[i];
				if ((Object)(object)((MemoryTreeInstance)(ref reactor)).myDef == (Object)null)
				{
					break;
				}
				if (((ResourceInfo)((MemoryTreeInstance)(ref reactor)).myDef).displayName == "Atlantum Reactor")
				{
					ReactorStage customDataForMachine = (ReactorStage)ModUtils.GetCustomDataForMachine<int>(reactor.commonInfo.instanceId, "stage");
					if (ModUtils.NullCheck((object)customDataForMachine, "stage", false))
					{
						MemoryTreeInstancePatch.PlayReactorSound(ref reactor, customDataForMachine);
					}
				}
			}
		}

		public static void PlayReactorIgnition()
		{
			if (!audioLoaded)
			{
				Log.LogError((object)"Cannot play ignite audio, not loaded");
				return;
			}
			if (audioSource.isPlaying)
			{
				audioSource.Pause();
				return;
			}
			audioSource.time = 0f;
			audioSource.Play();
		}

		private void ApplyPatches()
		{
			Harmony.CreateAndPatchAll(typeof(InspectorUIPatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(MemoryTreeDefinitionPatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(MemoryTreeInstancePatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(PlayerInspectorPatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(PlayerInteractionPatch), (string)null);
		}

		private void LoadPrefabs()
		{
			AssetBundle val = LoadAssetBundle("reactorcore");
			reactorPrefab = val.LoadAsset<GameObject>("assets/atlantium_power.prefab");
		}

		private static AssetBundle LoadAssetBundle(string filename)
		{
			Assembly callingAssembly = Assembly.GetCallingAssembly();
			return AssetBundle.LoadFromStream(callingAssembly.GetManifestResourceStream("AtlantumReactor.Assets." + filename));
		}

		private static byte[] GetEmbeddedResourceBytes(string resourceName)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				Log.LogError((object)("Failed to find embedded resource: " + resourceName));
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			return array;
		}

		private void AddContentToGame()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			NewResourceDetails val = new NewResourceDetails();
			val.name = "Atlantum Reactor";
			val.description = string.Format("Consumes {0} and {1} to produce {2} -> {3}MW", "Atlantum Mixture Brick", "Shiverthorn Coolant", ReactorSettings.basePowerMW, (20000f + 500f * ReactorSettings.perCoolantBoost) / 1000f);
			val.craftingMethod = (CraftingMethod)0;
			val.craftTierRequired = 0;
			val.headerTitle = "Production";
			val.subHeaderTitle = "Power";
			val.maxStackCount = 1;
			val.sortPriority = 999;
			val.unlockName = "Atlantum Reactor";
			val.parentName = "Core Composer";
			val.sprite = ModUtils.LoadSpriteFromFile("AtlantumReactor.Assets.Images.Reactor.png", false);
			NewResourceDetails val2 = val;
			MemoryTreeDefinition val3 = ScriptableObject.CreateInstance<MemoryTreeDefinition>();
			EMUAdditions.AddNewMachine<MemoryTreeInstance, MemoryTreeDefinition>((MachineDefinition<MemoryTreeInstance, MemoryTreeDefinition>)(object)val3, val2, false);
			EMUAdditions.AddNewRecipe(new NewRecipeDetails
			{
				GUID = "com.equinox.AtlantumReactor",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				duration = 10f,
				unlockName = "Atlantum Reactor",
				ingredients = new List<RecipeResourceInfo>
				{
					new RecipeResourceInfo("Core Composer", 1),
					new RecipeResourceInfo("Crank Generator MKII", 5),
					new RecipeResourceInfo("Steel Slab", 10)
				},
				outputs = new List<RecipeResourceInfo>
				{
					new RecipeResourceInfo("Atlantum Reactor", 1)
				},
				sortPriority = 10
			}, false);
			NewUnlockDetails val4 = new NewUnlockDetails();
			val4.displayName = "Atlantum Reactor";
			val4.description = string.Format("Consumes {0} and {1} to produce {2} -> {3}MW", "Atlantum Mixture Brick", "Shiverthorn Coolant", ReactorSettings.basePowerMW, (20000f + 500f * ReactorSettings.perCoolantBoost) / 1000f);
			val4.category = (TechCategory)4;
			val4.coreTypeNeeded = (CoreType)2;
			val4.coreCountNeeded = 1000;
			val4.requiredTier = (ResearchTier)1;
			val4.treePosition = 0;
			val4.sprite = ModUtils.LoadSpriteFromFile("AtlantumReactor.Assets.Images.Reactor.png", false);
			EMUAdditions.AddNewUnlock(val4, false);
		}
	}
	public static class ReactorGUI
	{
		public static bool lookingAtReactor;

		public static bool showGUI;

		public static uint currentReactor;

		public static int currentReactorIndex;

		public static float timeSinceClose;

		public static float timeSinceIgnition = 0f;

		private static float windowX = -1f;

		private static float windowY = -1f;

		private static float centerX = -1f;

		private static float centerY = -1f;

		private static float currentSafetyPanelOffset = 0f;

		private static float currentFallSpeed = 2f;

		private static float currentCore1Angle;

		private static float currentCore2Angle;

		private static float currentCore3Angle;

		private static float currentCore4Angle;

		private static float currentCore5Angle;

		private static Vector2 pivotPoint = Vector2.zero;

		private static Texture2D shaderTexture;

		private static Texture2D reactorBackground;

		private static Texture2D reactorButton;

		private static Texture2D safetyPanel;

		private static Texture2D meterCover;

		private static Texture2D shiverMeter;

		private static Texture2D kindleMeter;

		private static Texture2D accumulatorMeter;

		private static Texture2D chargesMeter;

		private static Texture2D shiverBorder;

		private static Texture2D kindleBorder;

		private static Texture2D accumulatorBorder;

		private static Texture2D chargesBorder;

		private static Texture2D genBackground;

		private static Texture2D coreStatic;

		private static Texture2D core1;

		private static Texture2D core2;

		private static Texture2D core3;

		private static Texture2D core4;

		private static Texture2D core5;

		public static void LoadAssets()
		{
			shaderTexture = ModUtils.LoadTexture2DFromFile(GetPath("ShaderTile"), false, (Assembly)null);
			reactorBackground = ModUtils.LoadTexture2DFromFile(GetPath("ReactorControlPanel"), false, (Assembly)null);
			reactorButton = ModUtils.LoadTexture2DFromFile(GetPath("ReactorButton"), false, (Assembly)null);
			safetyPanel = ModUtils.LoadTexture2DFromFile(GetPath("ReactorSafetyPanel"), false, (Assembly)null);
			meterCover = ModUtils.LoadTexture2DFromFile(GetPath("MeterCover"), false, (Assembly)null);
			shiverMeter = ModUtils.LoadTexture2DFromFile(GetPath("ShiverMeter"), false, (Assembly)null);
			kindleMeter = ModUtils.LoadTexture2DFromFile(GetPath("KindleMeter"), false, (Assembly)null);
			accumulatorMeter = ModUtils.LoadTexture2DFromFile(GetPath("AccumulatorMeter"), false, (Assembly)null);
			chargesMeter = ModUtils.LoadTexture2DFromFile(GetPath("ChargesMeter"), false, (Assembly)null);
			shiverBorder = ModUtils.LoadTexture2DFromFile(GetPath("ShiverBorder"), false, (Assembly)null);
			kindleBorder = ModUtils.LoadTexture2DFromFile(GetPath("KindleBorder"), false, (Assembly)null);
			accumulatorBorder = ModUtils.LoadTexture2DFromFile(GetPath("AccumulatorBorder"), false, (Assembly)null);
			chargesBorder = ModUtils.LoadTexture2DFromFile(GetPath("ChargesBorder"), false, (Assembly)null);
			genBackground = ModUtils.LoadTexture2DFromFile(GetPath("ReactorGenBackground"), false, (Assembly)null);
			coreStatic = ModUtils.LoadTexture2DFromFile(GetPath("CoreStatic"), false, (Assembly)null);
			core1 = ModUtils.LoadTexture2DFromFile(GetPath("Core1"), false, (Assembly)null);
			core2 = ModUtils.LoadTexture2DFromFile(GetPath("Core2"), false, (Assembly)null);
			core3 = ModUtils.LoadTexture2DFromFile(GetPath("Core3"), false, (Assembly)null);
			core4 = ModUtils.LoadTexture2DFromFile(GetPath("Core4"), false, (Assembly)null);
			core5 = ModUtils.LoadTexture2DFromFile(GetPath("Core5"), false, (Assembly)null);
		}

		public static void DrawGUI()
		{
			DrawTexture2D(0f, 0f, Screen.width, Screen.height, shaderTexture);
			SetDimensions();
			ReactorStage customDataForMachine = (ReactorStage)ModUtils.GetCustomDataForMachine<int>(currentReactor, "stage");
			if (customDataForMachine != ReactorStage.Ignited)
			{
				DrawTexture2D(windowX, windowY, ((Texture)reactorBackground).width, ((Texture)reactorBackground).height, reactorBackground);
				DrawButton();
				DrawMeter(-170f, "numShiver", shiverMeter, shiverBorder);
				DrawMeter(-50f, "numKindle", kindleMeter, kindleBorder);
				DrawMeter(70f, "capacitorCharge", accumulatorMeter, accumulatorBorder);
				DrawMeter(190f, "numCharges", chargesMeter, chargesBorder);
				DrawSafetyPanel();
			}
			else
			{
				DrawTexture2D(windowX, windowY, ((Texture)genBackground).width, ((Texture)genBackground).height, genBackground);
				DrawTexture2D(windowX + 120f, windowY + 180f, ((Texture)coreStatic).width, ((Texture)coreStatic).height, coreStatic);
				DrawQuantityLabels();
				DrawPowerInfo();
				DrawCore1();
				DrawCore2();
				DrawCore3();
				DrawCore4();
				DrawCore5();
			}
		}

		public static void ResetSafetyPanelHeight()
		{
			currentSafetyPanelOffset = 0f;
			currentFallSpeed = 2f;
		}

		private static string GetPath(string imageName)
		{
			return "AtlantumReactor.Assets.Images." + imageName + ".png";
		}

		private static void DrawTexture2D(Rect rect, Texture2D image)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_007f: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle();
			val.normal.background = image;
			val.hover.background = image;
			val.focused.background = image;
			val.active.background = image;
			val.onNormal.background = image;
			val.onHover.background = image;
			val.onFocused.background = image;
			val.onActive.background = image;
			val.border = new RectOffset(0, 0, 0, 0);
			GUIStyle val2 = val;
			GUI.Box(rect, "", val2);
		}

		private static void DrawTexture2D(float x, float y, float width, float height, Texture2D image)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = default(Rect);
			((Rect)(ref rect))..ctor(x, y, width, height);
			DrawTexture2D(rect, image);
		}

		private static void SetDimensions()
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (windowX < 0f)
			{
				windowX = (float)(Screen.width - ((Texture)reactorBackground).width) / 2f;
			}
			if (windowY < 0f)
			{
				windowY = (float)(Screen.height - ((Texture)reactorBackground).height) / 2f;
			}
			if (centerX < 0f)
			{
				centerX = (float)Screen.width / 2f;
			}
			if (centerY < 0f)
			{
				centerY = (float)Screen.height / 2f;
			}
			pivotPoint = new Vector2(windowX + 370f, windowY + 430f);
		}

		private static int GetNumCoolant()
		{
			MachineInstanceList<MemoryTreeInstance, MemoryTreeDefinition> machineList = MachineManager.instance.GetMachineList<MemoryTreeInstance, MemoryTreeDefinition>((MachineTypeEnum)30);
			return ((Inventory)(ref MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref machineList.GetIndex(currentReactorIndex), 0))).GetResourceCount(ModUtils.GetResourceIDByName("Shiverthorn Coolant", false), false);
		}

		private static void DrawButton()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle();
			val.normal.background = null;
			val.hover.background = null;
			val.focused.background = null;
			val.active.background = null;
			val.onNormal.background = null;
			val.onHover.background = null;
			val.onFocused.background = null;
			val.onActive.background = null;
			GUIStyle val2 = val;
			if (GUI.Button(new Rect(windowX + 152f, windowY + 620f, 100f, 100f), (Texture)(object)reactorButton, val2))
			{
				ModUtils.UpdateCustomDataForMachine<int>(currentReactor, "stage", 6);
				timeSinceIgnition = 0f;
				AtlantumReactorPlugin.PlayReactorIgnition();
			}
		}

		private static void DrawMeter(float height, string dataName, Texture2D meterTexture, Texture2D borderTexture)
		{
			DrawTexture2D(centerX - 466f, centerY + height + 2f, 1130f, 36f, meterTexture);
			int customDataForMachine = ModUtils.GetCustomDataForMachine<int>(currentReactor, dataName);
			float num = ((dataName == "capacitorCharge") ? 10000000 : 5000);
			float num2 = Mathf.Min((float)customDataForMachine / num, 1f);
			float num3 = 1134f * num2;
			if (num2 != 1f)
			{
				DrawTexture2D(centerX - 468f + num3, centerY + height, 1134f - num3, 40f, meterCover);
			}
			DrawTexture2D(centerX - 468f, centerY + height, 1134f, 40f, borderTexture);
		}

		private static void DrawQuantityLabels()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Expected O, but got Unknown
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle
			{
				fontSize = 24,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)1
			};
			val.normal.textColor = Color.yellow;
			val.normal.background = null;
			val.hover.textColor = Color.yellow;
			val.hover.background = null;
			val.active.textColor = Color.yellow;
			val.active.background = null;
			val.focused.textColor = Color.yellow;
			val.focused.background = null;
			val.onNormal.textColor = Color.yellow;
			val.onNormal.background = null;
			val.onHover.textColor = Color.yellow;
			val.onHover.background = null;
			val.onActive.textColor = Color.yellow;
			val.onActive.background = null;
			val.onFocused.textColor = Color.yellow;
			val.onFocused.background = null;
			GUIStyle val2 = val;
			int resourceIDByName = ModUtils.GetResourceIDByName("Atlantum Mixture Brick", false);
			MachineInstanceList<MemoryTreeInstance, MemoryTreeDefinition> machineList = MachineManager.instance.GetMachineList<MemoryTreeInstance, MemoryTreeDefinition>((MachineTypeEnum)30);
			GUIContent val3 = new GUIContent(((Inventory)(ref MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref machineList.GetIndex(currentReactorIndex), 0))).GetResourceCount(resourceIDByName, false).ToString());
			GUIContent val4 = new GUIContent(GetNumCoolant().ToString());
			GUI.Label(new Rect(pivotPoint.x - 50f, pivotPoint.y + 20f, 100f, 100f), val3, val2);
			GUI.Label(new Rect(centerX - 25f, pivotPoint.y + 20f, 50f, 50f), val4, val2);
		}

		private static void DrawPowerInfo()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Expected O, but got Unknown
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle
			{
				fontSize = 16,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)0
			};
			val.normal.textColor = Color.yellow;
			val.normal.background = null;
			val.hover.textColor = Color.yellow;
			val.hover.background = null;
			val.active.textColor = Color.yellow;
			val.active.background = null;
			val.focused.textColor = Color.yellow;
			val.focused.background = null;
			val.onNormal.textColor = Color.yellow;
			val.onNormal.background = null;
			val.onHover.textColor = Color.yellow;
			val.onHover.background = null;
			val.onActive.textColor = Color.yellow;
			val.onActive.background = null;
			val.onFocused.textColor = Color.yellow;
			val.onFocused.background = null;
			GUIStyle val2 = val;
			GUIStyle val3 = new GUIStyle
			{
				fontSize = 16,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)2
			};
			val3.normal.textColor = Color.yellow;
			val3.normal.background = null;
			val3.hover.textColor = Color.yellow;
			val3.hover.background = null;
			val3.active.textColor = Color.yellow;
			val3.active.background = null;
			val3.focused.textColor = Color.yellow;
			val3.focused.background = null;
			val3.onNormal.textColor = Color.yellow;
			val3.onNormal.background = null;
			val3.onHover.textColor = Color.yellow;
			val3.onHover.background = null;
			val3.onActive.textColor = Color.yellow;
			val3.onActive.background = null;
			val3.onFocused.textColor = Color.yellow;
			val3.onFocused.background = null;
			GUIStyle val4 = val3;
			int num = Mathf.FloorToInt(ModUtils.GetCustomDataForMachine<float>(currentReactor, "cycleTimeRemaining"));
			int customDataForMachine = ModUtils.GetCustomDataForMachine<int>(currentReactor, "currentPowerGen");
			int numCoolant = GetNumCoolant();
			int num2 = 20000 + Mathf.CeilToInt((float)numCoolant * ReactorSettings.perCoolantBoost);
			customDataForMachine = Mathf.CeilToInt((float)customDataForMachine * PowerState.instance.powerOutputMultiplier);
			num2 = Mathf.CeilToInt((float)num2 * PowerState.instance.powerOutputMultiplier);
			GUI.Label(new Rect(windowX + 973f, windowY + 275f, 300f, 50f), "Next Cycle:", val2);
			GUI.Label(new Rect(windowX + 973f, windowY + 325f, 300f, 50f), "Power Generation:", val2);
			GUI.Label(new Rect(windowX + 973f, windowY + 375f, 300f, 50f), "Next Power Generation:", val2);
			GUI.Label(new Rect(windowX + 973f, windowY + 275f, 280f, 50f), $"{num}s", val4);
			GUI.Label(new Rect(windowX + 973f, windowY + 325f, 280f, 50f), $"{(float)customDataForMachine / 1000f} MW", val4);
			GUI.Label(new Rect(windowX + 973f, windowY + 375f, 280f, 50f), $"{(float)num2 / 1000f} MW", val4);
		}

		private static void DrawCore1()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			currentCore1Angle += 0.1f;
			GUIUtility.RotateAroundPivot(currentCore1Angle, pivotPoint);
			DrawTexture2D(windowX + 259f, windowY + 319f, ((Texture)core1).width, ((Texture)core1).height, core1);
		}

		private static void DrawCore2()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			currentCore2Angle -= 0.2f;
			GUIUtility.RotateAroundPivot(currentCore2Angle, pivotPoint);
			DrawTexture2D(windowX + 225f, windowY + 285f, ((Texture)core2).width, ((Texture)core2).height, core2);
		}

		private static void DrawCore3()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			currentCore3Angle += 0.3f;
			GUIUtility.RotateAroundPivot(currentCore3Angle, pivotPoint);
			DrawTexture2D(windowX + 168f, windowY + 228f, ((Texture)core3).width, ((Texture)core3).height, core3);
		}

		private static void DrawCore4()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			currentCore4Angle -= 0.4f;
			GUIUtility.RotateAroundPivot(currentCore4Angle, pivotPoint);
			DrawTexture2D(windowX + 137f, windowY + 197f, ((Texture)core4).width, ((Texture)core4).height, core4);
		}

		private static void DrawCore5()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			currentCore5Angle += 0.5f;
			GUIUtility.RotateAroundPivot(currentCore5Angle, pivotPoint);
			DrawTexture2D(windowX + 100f, windowY + 160f, ((Texture)core5).width, ((Texture)core5).height, core5);
		}

		private static void DrawSafetyPanel()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			if (currentSafetyPanelOffset < (float)GetMaxSafetyPanelOffset())
			{
				currentSafetyPanelOffset += currentFallSpeed;
				currentFallSpeed *= 1.025f;
			}
			else
			{
				currentFallSpeed = 2f;
			}
			GUIStyle val = new GUIStyle();
			val.normal.background = safetyPanel;
			GUIStyle val2 = val;
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(windowX - 20f, windowY - 20f, (float)((Texture)safetyPanel).width, (float)(((Texture)reactorBackground).height + 20));
			GUI.BeginScrollView(val3, new Vector2(0f, 0f), val3, false, false);
			GUI.Box(new Rect(windowX - 20f, windowY - 20f + currentSafetyPanelOffset, (float)((Texture)safetyPanel).width, (float)((Texture)safetyPanel).height), "", val2);
			GUI.EndScrollView();
		}

		private static int GetMaxSafetyPanelOffset()
		{
			switch ((ReactorStage)ModUtils.GetCustomDataForMachine<int>(currentReactor, "stage"))
			{
			case ReactorStage.Idle:
			case ReactorStage.Cooling:
				return 260;
			case ReactorStage.Heating:
				return 380;
			case ReactorStage.Charging:
				return 500;
			case ReactorStage.Kickstarting:
				return 620;
			case ReactorStage.Ready:
			case ReactorStage.Ignited:
				return 760;
			default:
				return 740;
			}
		}
	}
	public static class ReactorProperties
	{
		public const string stage = "stage";

		public const string numShiver = "numShiver";

		public const string numKindle = "numKindle";

		public const string capacitorCharge = "capacitorCharge";

		public const string numCharges = "numCharges";

		public const string cycleTimeRemaining = "cycleTimeRemaining";

		public const string currentPowerGen = "currentPowerGen";

		public const string startedRunningSound = "startedRunnnigSound";
	}
	public enum ReactorStage
	{
		Idle,
		Cooling,
		Heating,
		Charging,
		Kickstarting,
		Ready,
		Ignited
	}
}
namespace AtlantumReactor.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	public class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		public static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("AtlantumReactor.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		public static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
}
namespace AtlantumReactor.Patches
{
	internal class GameDefinesPatch
	{
		private static bool hasAdded;

		private static MemoryTreeDefinition coreComposerDefinition;

		private static MemoryTreeDefinition reactorDefinition;

		[HarmonyPatch(typeof(GameDefines), "GetMaxResId")]
		[HarmonyPrefix]
		private static void AddReactorToGame()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			if (!hasAdded)
			{
				hasAdded = true;
				coreComposerDefinition = (MemoryTreeDefinition)ModUtils.GetResourceInfoByNameUnsafe("Core Composer", false);
				AddReactor();
				AddReactorRecipe();
				ModUtils.SetPrivateStaticField<GameDefines>("_topResId", GameDefines.instance, (object)(-1));
			}
		}

		private static void AddReactor()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			reactorDefinition = (MemoryTreeDefinition)ScriptableObject.CreateInstance(typeof(MemoryTreeDefinition));
			ModUtils.CloneObject<MemoryTreeDefinition>(coreComposerDefinition, ref reactorDefinition);
			((ResourceInfo)reactorDefinition).description = string.Format("Consumes {0} and {1} to produce {2} -> {3}MW", "Atlantum Mixture Brick", "Shiverthorn Coolant", ReactorSettings.basePowerMW, (20000f + 500f * ReactorSettings.perCoolantBoost) / 1000f);
			((ResourceInfo)reactorDefinition).rawName = "Atlantum Reactor";
			((ResourceInfo)reactorDefinition).rawSprite = ModUtils.LoadSpriteFromFile("AtlantumReactor.Assets.Images.Reactor.png", false);
			((UniqueIdScriptableObject)reactorDefinition).uniqueId = ModUtils.GetNewResourceID(false);
			((BuilderInfo)reactorDefinition).kWPowerConsumption = -20000;
			GameDefines.instance.resources.Add((ResourceInfo)(object)reactorDefinition);
			GameDefines.instance.buildableResources.Add((BuilderInfo)(object)reactorDefinition);
			ResourceNames.SafeResources.Add("Atlantum Reactor");
		}

		private static void AddReactorRecipe()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			NewRecipeDetails val = new NewRecipeDetails
			{
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				duration = 120,
				ingredients = new List<RecipeResourceInfo>
				{
					new RecipeResourceInfo("Core Composer", 1),
					new RecipeResourceInfo("Crank Generator MKII", 5),
					new RecipeResourceInfo("Steel Slab", 10)
				},
				outputs = new List<RecipeResourceInfo>
				{
					new RecipeResourceInfo("Atlantum Reactor", 1)
				},
				sortPriority = 10
			};
			AtlantumReactorPlugin.reactorRecipe = val.ConvertToRecipe();
			((Object)AtlantumReactorPlugin.reactorRecipe).name = "Atlantum Reactor";
			((UniqueIdScriptableObject)AtlantumReactorPlugin.reactorRecipe).uniqueId = ModUtils.GetNewRecipeID(false);
			AtlantumReactorPlugin.reactorRecipe.unlock = ((ResourceInfo)coreComposerDefinition).unlock;
			GameDefines.instance.schematicsRecipeEntries.Add(AtlantumReactorPlugin.reactorRecipe);
		}
	}
	internal class MemoryTreeDefinitionPatch
	{
		public static Dictionary<Vector3, GameObject> myVisualsMap = new Dictionary<Vector3, GameObject>();

		[HarmonyPatch(typeof(MemoryTreeDefinition), "InitInstance")]
		[HarmonyPostfix]
		private static void SetToGenerator(ref MemoryTreeInstance newInstance)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Invalid comparison between Unknown and I4
			if (!(((ResourceInfo)((MemoryTreeInstance)(ref newInstance)).myDef).displayName == "Atlantum Reactor"))
			{
				return;
			}
			newInstance.powerInfo.isGenerator = true;
			newInstance.powerInfo.powerSatisfaction = 1f;
			newInstance.powerInfo.curPowerConsumption = 0;
			newInstance.powerInfo.maxPowerConsumption = 0;
			newInstance.powerInfo.usesPowerSystem = true;
			MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref newInstance, 0).numSlots = 3;
			MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref newInstance, 0).myStacks = (ResourceStack[])(object)new ResourceStack[3];
			bool flag = (int)MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref newInstance, 0).slotSizeMode != 1;
			for (int i = 0; i < 3; i++)
			{
				if (!flag)
				{
					MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref newInstance, 0).myStacks[i].maxStack = MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref newInstance, 0).maxStackSize;
				}
				((ResourceStack)(ref MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref newInstance, 0).myStacks[i])).InitAsEmpty(flag);
			}
		}

		[HarmonyPatch(typeof(MemoryTreeDefinition), "OnBuild")]
		[HarmonyPostfix]
		private static void AddNewMembers(MachineInstanceRef<MemoryTreeInstance> instRef)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			if (!(((ResourceInfo)((MemoryTreeInstance)(ref instRef.Get())).myDef).displayName != "Atlantum Reactor"))
			{
				ModUtils.AddCustomDataForMachine<int>(instRef.instanceId, "stage", 0);
				ModUtils.AddCustomDataForMachine<int>(instRef.instanceId, "numShiver", 0);
				ModUtils.AddCustomDataForMachine<int>(instRef.instanceId, "numKindle", 0);
				ModUtils.AddCustomDataForMachine<int>(instRef.instanceId, "capacitorCharge", 0);
				ModUtils.AddCustomDataForMachine<int>(instRef.instanceId, "numCharges", 0);
				ModUtils.AddCustomDataForMachine<float>(instRef.instanceId, "cycleTimeRemaining", 60f);
				ModUtils.AddCustomDataForMachine<int>(instRef.instanceId, "currentPowerGen", 0);
				ModUtils.AddCustomDataForMachine<bool>(instRef.instanceId, "startedRunnnigSound", false);
				GameObject value = Object.Instantiate<GameObject>(AtlantumReactorPlugin.reactorPrefab, ((GridInfo)(ref instRef.gridInfo)).BottomCenter, Quaternion.Euler(0f, (float)instRef.gridInfo.yawRot, 0f));
				myVisualsMap.Add(((GridInfo)(ref instRef.gridInfo)).BottomCenter, value);
			}
		}

		[HarmonyPatch(typeof(MachineDefinition<MemoryTreeInstance, MemoryTreeDefinition>), "OnDeconstruct")]
		[HarmonyPostfix]
		private static void RemoveAudioPlayer(ref MemoryTreeInstance erasedInstance)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			if (!(((ResourceInfo)((MemoryTreeInstance)(ref erasedInstance)).myDef).displayName != "Atlantum Reactor"))
			{
				if (MemoryTreeInstancePatch.reactorAudioPlayers.ContainsKey(erasedInstance.commonInfo.instanceId))
				{
					EventInstance val = MemoryTreeInstancePatch.reactorAudioPlayers[erasedInstance.commonInfo.instanceId];
					((EventInstance)(ref val)).stop((STOP_MODE)0);
					MemoryTreeInstancePatch.reactorAudioPlayers.Remove(erasedInstance.commonInfo.instanceId);
				}
				if (myVisualsMap.ContainsKey(((GridInfo)(ref erasedInstance.gridInfo)).BottomCenter))
				{
					Object.Destroy((Object)(object)myVisualsMap[((GridInfo)(ref erasedInstance.gridInfo)).BottomCenter]);
					myVisualsMap.Remove(((GridInfo)(ref erasedInstance.gridInfo)).BottomCenter);
				}
			}
		}
	}
	public class InspectorUIPatch
	{
		[HarmonyPatch(typeof(InspectorUI), "SetInspectingMachine")]
		[HarmonyPrefix]
		private static bool ShowReactorGUI(GenericMachineInstanceRef machineHit)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			if ((int)((GenericMachineInstanceRef)(ref machineHit)).typeIndex != 30 || ((ResourceInfo)((MemoryTreeInstance)(ref ((GenericMachineInstanceRef)(ref machineHit)).Get<MemoryTreeInstance>())).myDef).displayName != "Atlantum Reactor")
			{
				return true;
			}
			ModUtils.SetPrivateField<InspectorUI>("inspecting", UIManager.instance.inspectorUI, (object)true);
			ReactorGUI.lookingAtReactor = true;
			if (InputHandler.instance.InteractShortUp && !ReactorGUI.showGUI && ReactorGUI.timeSinceClose >= 0.2f)
			{
				ModUtils.FreeCursor(true);
				ReactorGUI.currentReactor = ((GenericMachineInstanceRef)(ref machineHit)).instanceId;
				ReactorGUI.currentReactorIndex = ((GenericMachineInstanceRef)(ref machineHit)).index;
				ReactorGUI.ResetSafetyPanelHeight();
				ReactorGUI.showGUI = true;
			}
			return false;
		}
	}
	internal class MemoryTreeInstancePatch
	{
		public static Dictionary<uint, EventInstance> reactorAudioPlayers = new Dictionary<uint, EventInstance>();

		private static float timeSinceDrain = 0f;

		[HarmonyPatch(typeof(MemoryTreeInstance), "SimUpdate")]
		[HarmonyPrefix]
		private static bool UpdateReactor(MemoryTreeInstance __instance, float dt)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Invalid comparison between Unknown and I4
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Invalid comparison between Unknown and I4
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: 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)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			if (((ResourceInfo)((MemoryTreeInstance)(ref __instance)).myDef).displayName != "Atlantum Reactor")
			{
				return true;
			}
			RotateCenter(ref __instance);
			ReactorStage customDataForMachine = (ReactorStage)ModUtils.GetCustomDataForMachine<int>(__instance.commonInfo.instanceId, "stage");
			if (customDataForMachine != ReactorStage.Charging && customDataForMachine != ReactorStage.Ignited)
			{
				ConsumeFromInventory(ref __instance);
			}
			if (customDataForMachine == ReactorStage.Charging)
			{
				ConsumePower(ref __instance);
			}
			if (customDataForMachine != ReactorStage.Ready && customDataForMachine != ReactorStage.Ignited)
			{
				CheckForStageUpdate(ref __instance, customDataForMachine);
				customDataForMachine = (ReactorStage)ModUtils.GetCustomDataForMachine<int>(__instance.commonInfo.instanceId, "stage");
			}
			PLAYBACK_STATE val = (PLAYBACK_STATE)2;
			EventInstance val2;
			if (reactorAudioPlayers.ContainsKey(__instance.commonInfo.instanceId))
			{
				val2 = reactorAudioPlayers[__instance.commonInfo.instanceId];
				((EventInstance)(ref val2)).getPlaybackState(ref val);
			}
			if (customDataForMachine == ReactorStage.Kickstarting && (int)val == 2)
			{
				val2 = reactorAudioPlayers[__instance.commonInfo.instanceId];
				((EventInstance)(ref val2)).start();
			}
			if (customDataForMachine == ReactorStage.Ignited)
			{
				SetToProducePower(ref __instance);
				float customDataForMachine2 = ModUtils.GetCustomDataForMachine<float>(__instance.commonInfo.instanceId, "cycleTimeRemaining");
				customDataForMachine2 -= Time.fixedDeltaTime;
				if (customDataForMachine2 < 0f)
				{
					customDataForMachine2 = 60f;
					OnCycleStart(ref __instance);
				}
				ModUtils.UpdateCustomDataForMachine<float>(__instance.commonInfo.instanceId, "cycleTimeRemaining", customDataForMachine2);
				bool customDataForMachine3 = ModUtils.GetCustomDataForMachine<bool>(__instance.commonInfo.instanceId, "startedRunnnigSound");
				if ((ReactorGUI.timeSinceIgnition > 4f && !customDataForMachine3) || ((int)val == 2 && customDataForMachine3))
				{
					PlayReactorSound(ref __instance, customDataForMachine);
				}
			}
			customDataForMachine = (ReactorStage)ModUtils.GetCustomDataForMachine<int>(__instance.commonInfo.instanceId, "stage");
			if (customDataForMachine > ReactorStage.Idle && customDataForMachine < ReactorStage.Ignited)
			{
				SetToConsumePower(ref __instance);
			}
			MachineManager.instance.GetMachineList<MemoryTreeInstance, MemoryTreeDefinition>((MachineTypeEnum)30).myArray[__instance.commonInfo.index].powerInfo = __instance.powerInfo;
			return false;
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool CanAddItem(MemoryTreeInstance __instance, ref bool __result, int resId, int inventoryIndex, out int slotNum, AddResourceValidationType validationType)
		{
			//IL_0026: 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_0043: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Invalid comparison between Unknown and I4
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			slotNum = -1;
			if (((ResourceInfo)((MemoryTreeInstance)(ref __instance)).myDef).displayName != "Atlantum Reactor")
			{
				return true;
			}
			if (ModUtils.GetCustomDataForMachine<int>(__instance.commonInfo.instanceId, "stage") < 6)
			{
				int currentNeededResId = GetCurrentNeededResId(__instance.commonInfo.instanceId);
				if (currentNeededResId == -1 || resId != currentNeededResId)
				{
					__result = false;
					return false;
				}
				if ((int)validationType == 2)
				{
					__result = ((Inventory)(ref __instance.commonInfo.inventories[inventoryIndex])).CanAddResources(resId);
				}
			}
			else
			{
				int resourceIDByName = ModUtils.GetResourceIDByName("Atlantum Mixture Brick", false);
				int resourceIDByName2 = ModUtils.GetResourceIDByName("Shiverthorn Coolant", false);
				if (resId != resourceIDByName && resId != resourceIDByName2)
				{
					__result = false;
					return false;
				}
				int resourceCount = ((Inventory)(ref MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref __instance, 0))).GetResourceCount(resId, false);
				if (resourceCount >= 500)
				{
					__result = false;
					return false;
				}
				__result = true;
			}
			return false;
		}

		private static void RotateCenter(ref MemoryTreeInstance reactor)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = MemoryTreeDefinitionPatch.myVisualsMap[((GridInfo)(ref reactor.gridInfo)).BottomCenter];
			Transform obj = val.transform.Find("reactornew3/centrespin");
			GameObject val2 = ((obj != null) ? ((Component)obj).gameObject : null);
			if ((Object)(object)val2 != (Object)null)
			{
				float num = 200f;
				float num2 = ModUtils.GetCustomDataForMachine<float>(reactor.commonInfo.instanceId, "cycleTimeRemaining") / 60f;
				num2 = Mathf.Max(0.2f, num2);
				val2.transform.Rotate(Vector3.forward, num * num2 * Time.deltaTime, (Space)1);
			}
		}

		private static void ConsumeFromInventory(ref MemoryTreeInstance reactor)
		{
			//IL_0002: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			ModUtils.NullCheck((object)reactor, "reactor", false);
			ModUtils.NullCheck((object)reactor.commonInfo, "reactor.commonInfo", false);
			int currentNeededResId = GetCurrentNeededResId(reactor.commonInfo.instanceId);
			ref Inventory reference = ref reactor.commonInfo.inventories[0];
			ResourceStack[] myStacks = reference.myStacks;
			for (int i = 0; i < myStacks.Length; i++)
			{
				ResourceStack val = myStacks[i];
				if (!((ResourceStack)(ref val)).isEmpty && ((UniqueIdScriptableObject)((ResourceStack)(ref val)).info).uniqueId == currentNeededResId)
				{
					string customDataName = "";
					switch (((ResourceStack)(ref val)).info.displayName)
					{
					case "Shiverthorn Extract":
						customDataName = "numShiver";
						break;
					case "Kindlevine Extract":
						customDataName = "numKindle";
						break;
					case "Mining Charge":
						customDataName = "numCharges";
						break;
					}
					AddToResCount(reactor.commonInfo.instanceId, customDataName, val.count);
					((Inventory)(ref reference)).TryRemoveResources(((UniqueIdScriptableObject)((ResourceStack)(ref val)).info).uniqueId, val.count);
				}
			}
		}

		private static int GetCurrentNeededResId(uint instanceId)
		{
			return (ReactorStage)ModUtils.GetCustomDataForMachine<int>(instanceId, "stage") switch
			{
				ReactorStage.Idle => ModUtils.GetResourceIDByName("Shiverthorn Extract", false), 
				ReactorStage.Cooling => ModUtils.GetResourceIDByName("Shiverthorn Extract", false), 
				ReactorStage.Heating => ModUtils.GetResourceIDByName("Kindlevine Extract", false), 
				ReactorStage.Kickstarting => ModUtils.GetResourceIDByName("Mining Charge", false), 
				_ => -1, 
			};
		}

		private static void AddToResCount(uint instanceId, string customDataName, int amount)
		{
			int customDataForMachine = ModUtils.GetCustomDataForMachine<int>(instanceId, customDataName);
			customDataForMachine += amount;
			ModUtils.UpdateCustomDataForMachine<int>(instanceId, customDataName, customDataForMachine);
		}

		private static void ConsumePower(ref MemoryTreeInstance reactor)
		{
			timeSinceDrain += Time.deltaTime;
			if (!(timeSinceDrain <= 1f))
			{
				timeSinceDrain = 0f;
				PowerNetwork network = PowerNetwork.GetNetwork(reactor.powerInfo.powerNetwork);
				int num = network.totalGenerated - network.totalUsage;
				int customDataForMachine = ModUtils.GetCustomDataForMachine<int>(reactor.commonInfo.instanceId, "capacitorCharge");
				customDataForMachine += num;
				ModUtils.UpdateCustomDataForMachine<int>(reactor.commonInfo.instanceId, "capacitorCharge", customDataForMachine);
			}
		}

		private static void CheckForStageUpdate(ref MemoryTreeInstance reactor, ReactorStage currentStage)
		{
			int customDataForMachine = ModUtils.GetCustomDataForMachine<int>(reactor.commonInfo.instanceId, "numShiver");
			int customDataForMachine2 = ModUtils.GetCustomDataForMachine<int>(reactor.commonInfo.instanceId, "numKindle");
			int customDataForMachine3 = ModUtils.GetCustomDataForMachine<int>(reactor.commonInfo.instanceId, "capacitorCharge");
			int customDataForMachine4 = ModUtils.GetCustomDataForMachine<int>(reactor.commonInfo.instanceId, "numCharges");
			bool customDataForMachine5 = ModUtils.GetCustomDataForMachine<bool>(reactor.commonInfo.instanceId, "startedRunnnigSound");
			switch (currentStage)
			{
			case ReactorStage.Idle:
				if (customDataForMachine != 0)
				{
					SetStage(ref reactor, ReactorStage.Cooling);
				}
				break;
			case ReactorStage.Cooling:
				if (customDataForMachine >= 5000)
				{
					SetStage(ref reactor, ReactorStage.Heating);
				}
				break;
			case ReactorStage.Heating:
				if (customDataForMachine2 >= 5000)
				{
					SetStage(ref reactor, ReactorStage.Charging);
				}
				break;
			case ReactorStage.Charging:
				if (customDataForMachine3 >= 10000000)
				{
					SetStage(ref reactor, ReactorStage.Kickstarting);
				}
				break;
			case ReactorStage.Kickstarting:
				if (customDataForMachine4 >= 5000)
				{
					SetStage(ref reactor, ReactorStage.Ready);
				}
				break;
			case ReactorStage.Ignited:
				if (ReactorGUI.timeSinceIgnition > 4f && !customDataForMachine5)
				{
					PlayReactorSound(ref reactor, currentStage);
				}
				break;
			case ReactorStage.Ready:
				break;
			}
		}

		private static void SetStage(ref MemoryTreeInstance reactor, ReactorStage stage)
		{
			ModUtils.UpdateCustomDataForMachine<int>(reactor.commonInfo.instanceId, "stage", (int)stage);
			PlayReactorSound(ref reactor, stage);
		}

		public static void PlayReactorSound(ref MemoryTreeInstance reactor, ReactorStage stage)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_011b: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			if (!reactorAudioPlayers.ContainsKey(reactor.commonInfo.instanceId))
			{
				EventInstance value = RuntimeManager.CreateInstance("event:/Silence");
				reactorAudioPlayers.Add(reactor.commonInfo.instanceId, value);
			}
			string text = "event:/Silence";
			switch (stage)
			{
			case ReactorStage.Cooling:
				text = "event:/SFX/Machine SFX/Placeholders/Water Wheel Placeholder";
				break;
			case ReactorStage.Heating:
				text = "event:/SFX/Machine SFX/Smelter Active";
				break;
			case ReactorStage.Charging:
				text = "event:/SFX/Machine SFX/Accumulator";
				break;
			case ReactorStage.Kickstarting:
				text = "event:/SFX/Machine SFX/Blast Smelter/Blast Smelter Explosion";
				break;
			case ReactorStage.Ready:
				text = "event:/SFX/Machine SFX/Power Generator";
				break;
			case ReactorStage.Ignited:
				text = "event:/SFX/Tool SFX/Multiplayer Tools/Multiplayer MOLE/Multiplayer MOLE BH";
				ModUtils.UpdateCustomDataForMachine<bool>(reactor.commonInfo.instanceId, "startedRunnnigSound", true);
				break;
			}
			EventInstance val = reactorAudioPlayers[reactor.commonInfo.instanceId];
			((EventInstance)(ref val)).stop((STOP_MODE)0);
			reactorAudioPlayers[reactor.commonInfo.instanceId] = RuntimeManager.CreateInstance(text);
			val = reactorAudioPlayers[reactor.commonInfo.instanceId];
			((EventInstance)(ref val)).set3DAttributes(RuntimeUtils.To3DAttributes(((GridInfo)(ref reactor.gridInfo)).Center));
			val = reactorAudioPlayers[reactor.commonInfo.instanceId];
			((EventInstance)(ref val)).setParameterByName("Volume", 0.2f, false);
			val = reactorAudioPlayers[reactor.commonInfo.instanceId];
			((EventInstance)(ref val)).start();
		}

		public static void PlayReactorSound(int index, ReactorStage stage)
		{
			MachineInstanceList<MemoryTreeInstance, MemoryTreeDefinition> machineList = MachineManager.instance.GetMachineList<MemoryTreeInstance, MemoryTreeDefinition>((MachineTypeEnum)30);
			PlayReactorSound(ref machineList.GetIndex(index), stage);
		}

		private static void SetToConsumePower(ref MemoryTreeInstance reactor)
		{
			reactor.powerInfo.isGenerator = false;
			reactor.powerInfo.powerSatisfaction = 1f;
			reactor.powerInfo.curPowerConsumption = 5000;
			reactor.powerInfo.maxPowerConsumption = 5000;
			reactor.powerInfo.usesPowerSystem = true;
		}

		private static void SetToProducePower(ref MemoryTreeInstance reactor)
		{
			if (!reactor.powerInfo.isGenerator)
			{
				reactor.powerInfo.isGenerator = true;
				reactor.powerInfo.powerSatisfaction = 1f;
				reactor.powerInfo.curPowerConsumption = ModUtils.GetCustomDataForMachine<int>(reactor.commonInfo.instanceId, "currentPowerGen");
				reactor.powerInfo.maxPowerConsumption = ModUtils.GetCustomDataForMachine<int>(reactor.commonInfo.instanceId, "currentPowerGen");
				reactor.powerInfo.usesPowerSystem = true;
			}
		}

		private static void OnCycleStart(ref MemoryTreeInstance reactor)
		{
			int resourceIDByName = ModUtils.GetResourceIDByName("Atlantum Mixture Brick", false);
			int resourceIDByName2 = ModUtils.GetResourceIDByName("Shiverthorn Coolant", false);
			if (((Inventory)(ref MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref reactor, 0))).HasAnyOfResource(resourceIDByName))
			{
				((Inventory)(ref MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref reactor, 0))).TryRemoveResources(resourceIDByName, 1);
				int num = Mathf.Min(((Inventory)(ref MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref reactor, 0))).GetResourceCount(resourceIDByName2, false), 500);
				int num2 = Mathf.CeilToInt((float)num * ReactorSettings.perCoolantBoost);
				((Inventory)(ref MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<MemoryTreeInstance>(ref reactor, 0))).TryRemoveResources(resourceIDByName2, num);
				int num3 = 20000 + num2;
				ModUtils.UpdateCustomDataForMachine<int>(reactor.commonInfo.instanceId, "currentPowerGen", num3);
				reactor.powerInfo.curPowerConsumption = -num3;
				reactor.powerInfo.maxPowerConsumption = -num3;
			}
			else
			{
				reactor.powerInfo.curPowerConsumption = 0;
				reactor.powerInfo.maxPowerConsumption = 0;
			}
		}
	}
	internal class PlayerInspectorPatch
	{
		[HarmonyPatch(typeof(PlayerInspector), "LateUpdate")]
		[HarmonyPrefix]
		private static void SetLookingAtReactor()
		{
			ReactorGUI.lookingAtReactor = false;
		}
	}
	internal class PlayerInteractionPatch
	{
		[HarmonyPatch(typeof(PlayerInteraction), "UpdateUI")]
		[HarmonyPostfix]
		private static void ShowInspectButton()
		{
			if (!((Object)(object)UIManager.instance == (Object)null) && !((Object)(object)UIManager.instance.inspectorUI == (Object)null))
			{
				bool flag = (bool)ModUtils.GetPrivateField<InspectorUI>("inspecting", UIManager.instance.inspectorUI);
				bool flag2 = ReactorGUI.lookingAtReactor && flag;
				string text = (flag2 ? "Inspect" : "");
				UIManager.instance.hud.SetOverrideButtonSetVisible(flag2, text);
			}
		}
	}
	public static class ReactorSettings
	{
		public const string name = "Atlantum Reactor";

		public const int explosionDelay = 5;

		public const int itemLimit = 5000;

		public const int energyLimit = 10000000;

		public const int basePower = 20000;

		public const float coolantMultiplier = 0.025f;

		public static float basePowerMW => 20f;

		public static float perCoolantBoost => 500f;
	}
}