Decompiled source of MegaRayReceiver v1.1.4

MegaRayReceiver.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MegaRayReceiver")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.4.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 MegaRayReceiver
{
	[BepInPlugin("Rokumaehn.plugin.MegaRayReceiver", "MegaRayReceiver", "1.1.4")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "Rokumaehn.plugin.MegaRayReceiver";

		public const string NAME = "MegaRayReceiver";

		public const string VERSION = "1.1.4";

		public static ConfigEntry<int> EnergyCapMultiplier;

		public static ConfigEntry<int> EnergyEfficiency;

		public static ConfigEntry<bool> AlwaysOn;

		public static ManualLogSource Log;

		private static Harmony harmony;

		public void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			UIPowerPanelPatch.Log = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("Rokumaehn.plugin.MegaRayReceiver");
			EnergyCapMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("RayReceiver", "EnergyCapMultiplier", 10, new ConfigDescription("Requestable Energy Multiplier", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			EnergyEfficiency = ((BaseUnityPlugin)this).Config.Bind<int>("RayReceiver", "EnergyEfficiency", 1, new ConfigDescription("Requestable Energy Efficiency", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			AlwaysOn = ((BaseUnityPlugin)this).Config.Bind<bool>("RayReceiver", "AlwaysOn", false, new ConfigDescription("Always use full power, ignoring the current strength of the ray receiver", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { false, true }), Array.Empty<object>()));
			UIPowerPanelPatch.Multiplier = EnergyCapMultiplier.Value;
			UIPowerPanelPatch.Efficiency = EnergyEfficiency.Value;
			UIPowerPanelPatch.AlwaysOn = AlwaysOn.Value;
			harmony.PatchAll(typeof(UIPowerPanelPatch));
			harmony.PatchAll(typeof(RayReceiverPatch));
		}
	}
	public class RayReceiverPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(PowerGeneratorComponent), "MaxOutputCurrent_Gamma")]
		private static void MegaRayStuff1(ref long __result)
		{
			__result *= UIPowerPanelPatch.Multiplier;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PowerGeneratorComponent), "EnergyCap_Gamma_Req")]
		private static bool MegaRayStuff2pre(ref PowerGeneratorComponent __instance, ref long __result, float sx, float sy, float sz, float increase, float eta)
		{
			float num;
			if (UIPowerPanelPatch.AlwaysOn)
			{
				num = (__instance.currentStrength = 1f);
			}
			else
			{
				num = (sx * __instance.x + sy * __instance.y + sz * __instance.z + increase * 0.8f + ((__instance.catalystPoint > 0) ? __instance.ionEnhance : 0f)) * 6f + 0.5f;
				num = (__instance.currentStrength = ((num > 1f) ? 1f : ((num < 0f) ? 0f : num)));
			}
			float num2 = (float)Cargo.accTableMilli[((PowerGeneratorComponent)(ref __instance)).catalystIncLevel];
			__instance.capacityCurrentTick = (long)(__instance.currentStrength * (1f + __instance.warmup * 1.5f) * ((__instance.catalystPoint > 0) ? (2f * (1f + num2)) : 1f) * ((__instance.productId > 0) ? 8f : 1f) * (float)__instance.genEnergyPerTick);
			eta = ((UIPowerPanelPatch.Efficiency <= 10) ? (1f - (1f - eta) * (1f - __instance.warmup * __instance.warmup * 0.4f)) : ((float)UIPowerPanelPatch.Efficiency * 0.01f));
			__instance.warmupSpeed = (num - 0.75f) * 4f * 1.3888889E-05f;
			__result = (long)((double)__instance.capacityCurrentTick / (double)eta + 0.49999999);
			__instance.capacityCurrentTick *= UIPowerPanelPatch.Multiplier;
			__result *= UIPowerPanelPatch.Multiplier;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PowerGeneratorComponent), "RequiresCurrent_Gamma")]
		private static bool MegaRayStuff3post(ref PowerGeneratorComponent __instance, ref long __result, float eta)
		{
			float num = (float)Cargo.accTableMilli[((PowerGeneratorComponent)(ref __instance)).catalystIncLevel];
			long num2 = (long)(__instance.currentStrength * (1f + __instance.warmup * 1.5f) * ((__instance.catalystPoint > 0) ? (2f * (1f + num)) : 1f) * ((__instance.productId > 0) ? 8f : 1f) * (float)(__instance.genEnergyPerTick * UIPowerPanelPatch.Multiplier));
			eta = ((UIPowerPanelPatch.Efficiency <= 10) ? (1f - (1f - eta) * (1f - __instance.warmup * __instance.warmup * 0.4f)) : ((float)UIPowerPanelPatch.Efficiency * 0.01f));
			__result = (long)((double)num2 / (double)eta + 0.49999999);
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PowerGeneratorComponent), "EtaCurrent_Gamma")]
		private static void MegaRayStuff4post(ref PowerGeneratorComponent __instance, ref float __result, float eta)
		{
			if (UIPowerPanelPatch.Efficiency > 10)
			{
				__result = (float)UIPowerPanelPatch.Efficiency * 0.01f;
			}
		}
	}
	internal class UIPowerPanelPatch
	{
		public static bool AlwaysOn = false;

		public static int Multiplier = 10;

		public static int SliderMax = 19;

		public static int Efficiency = 1;

		public static ManualLogSource Log;

		private static bool initialized;

		private static GameObject group;

		private static InputField inputMultiplier;

		private static InputField inputEfficiency;

		private static Slider sliderMultiplier;

		private static Slider sliderEfficiency;

		private static UISwitch toggleAlwaysOn;

		private static Text text_factory;

		private static bool eventLock;

		private static UITooltip tipInputMultiplier;

		private static UITooltip tipSliderMultiplier;

		private static UITooltip tipInputEfficiency;

		private static UITooltip tipSliderEfficiency;

		private static UITooltip tipToggleAlwaysOn;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIStatisticsWindow), "_OnOpen")]
		public static void Init()
		{
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a5: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)group == (Object)null))
			{
				return;
			}
			try
			{
				Slider slider = UIRoot.instance.uiGame.dysonEditor.controlPanel.inspector.layerInfo.slider0;
				InputField input = UIRoot.instance.uiGame.dysonEditor.controlPanel.inspector.layerInfo.input0;
				Text cpuValueText = UIRoot.instance.uiGame.statWindow.performancePanelUI.cpuValueText1;
				GameObject gameObject = ((Component)((Component)UIRoot.instance.uiGame.statWindow.powerAstroBox).gameObject.transform.parent).gameObject;
				RectTransform component = ((Component)UIRoot.instance.uiGame.statWindow.powerAstroBox).gameObject.GetComponent<RectTransform>();
				UISwitch autoConstructSwitch = UIRoot.instance.uiGame.dysonEditor.controlPanel.inspector.overview.autoConstructSwitch;
				group = new GameObject("RayReceiver_Group");
				group.transform.SetParent(gameObject.transform);
				group.AddComponent<RectTransform>();
				group.transform.localPosition = new Vector3(((Transform)component).localPosition.x, ((Transform)component).localPosition.y);
				group.transform.localScale = ((Transform)component).localScale;
				group.GetComponent<RectTransform>().anchorMin = new Vector2(0f, 0.5f);
				group.GetComponent<RectTransform>().anchorMax = new Vector2(0f, 0.5f);
				group.GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, 0f);
				GameObject obj = Object.Instantiate<GameObject>(((Component)cpuValueText).gameObject, group.transform);
				((Object)obj).name = "text_rayrecmul";
				obj.transform.localPosition = new Vector3(-50f, 19f);
				text_factory = obj.GetComponent<Text>();
				text_factory.text = Localization.Translate("Ray Multiplier");
				GameObject obj2 = Object.Instantiate<GameObject>(((Component)input).gameObject, group.transform);
				((Object)obj2).name = "input_rayrecmul";
				obj2.transform.localPosition = new Vector3(155f, 11f);
				obj2.GetComponent<RectTransform>().sizeDelta = new Vector2(36f, 20f);
				inputMultiplier = obj2.GetComponent<InputField>();
				inputMultiplier.characterValidation = (CharacterValidation)1;
				inputMultiplier.contentType = (ContentType)2;
				((UnityEvent<string>)(object)inputMultiplier.onEndEdit).AddListener((UnityAction<string>)OnInputMulEnd);
				tipInputMultiplier = obj2.AddComponent<UITooltip>();
				tipInputMultiplier.Title = Localization.Translate("Energy Cap Multiplier");
				tipInputMultiplier.Text = Localization.Translate("Multiplies the ray receiver's energy cap by the given amount.");
				GameObject obj3 = Object.Instantiate<GameObject>(((Component)slider).gameObject, group.transform);
				((Object)obj3).name = "slider_rayrecmul";
				obj3.transform.localPosition = new Vector3(60f, -10f, -2f);
				sliderMultiplier = obj3.GetComponent<Slider>();
				sliderMultiplier.minValue = 1f;
				sliderMultiplier.maxValue = SliderMax;
				sliderMultiplier.wholeNumbers = true;
				((UnityEvent<float>)(object)sliderMultiplier.onValueChanged).AddListener((UnityAction<float>)OnSliderMulChange);
				tipSliderMultiplier = obj3.AddComponent<UITooltip>();
				tipSliderMultiplier.Title = Localization.Translate("Energy Cap Multiplier");
				tipSliderMultiplier.Text = Localization.Translate("Multiplies the ray receiver's energy cap by the given amount.");
				GameObject obj4 = Object.Instantiate<GameObject>(((Component)cpuValueText).gameObject, group.transform);
				((Object)obj4).name = "text_rayreceff";
				obj4.transform.localPosition = new Vector3(100f, 19f);
				text_factory = obj4.GetComponent<Text>();
				text_factory.text = Localization.Translate("Ray Efficiency");
				GameObject obj5 = Object.Instantiate<GameObject>(((Component)input).gameObject, group.transform);
				((Object)obj5).name = "input_rayreceff";
				obj5.transform.localPosition = new Vector3(305f, 11f);
				obj5.GetComponent<RectTransform>().sizeDelta = new Vector2(36f, 20f);
				inputEfficiency = obj5.GetComponent<InputField>();
				inputEfficiency.characterValidation = (CharacterValidation)1;
				inputEfficiency.contentType = (ContentType)2;
				((UnityEvent<string>)(object)inputEfficiency.onEndEdit).AddListener((UnityAction<string>)OnInputEffEnd);
				tipInputEfficiency = obj5.AddComponent<UITooltip>();
				tipInputEfficiency.Title = Localization.Translate("Energy Efficiency");
				tipInputEfficiency.Text = Localization.Translate("Ray Receiver Efficiency in percent.");
				GameObject obj6 = Object.Instantiate<GameObject>(((Component)slider).gameObject, group.transform);
				((Object)obj6).name = "slider_rayreceff";
				obj6.transform.localPosition = new Vector3(210f, -10f, -2f);
				sliderEfficiency = obj6.GetComponent<Slider>();
				sliderEfficiency.minValue = 1f;
				sliderEfficiency.maxValue = 10f;
				sliderEfficiency.wholeNumbers = true;
				((UnityEvent<float>)(object)sliderEfficiency.onValueChanged).AddListener((UnityAction<float>)OnSliderEffChange);
				tipSliderEfficiency = obj6.AddComponent<UITooltip>();
				tipSliderEfficiency.Title = Localization.Translate("Energy Cap Efficiency");
				tipSliderEfficiency.Text = Localization.Translate("Multiplies the ray receiver's energy cap by the given amount.");
				GameObject obj7 = Object.Instantiate<GameObject>(((Component)autoConstructSwitch).gameObject, group.transform);
				((Object)obj7).name = "toggle_rayrecaon";
				obj7.transform.localPosition = new Vector3(370f, 11f);
				obj7.GetComponent<RectTransform>().sizeDelta = new Vector2(36f, 20f);
				toggleAlwaysOn = obj7.GetComponent<UISwitch>();
				toggleAlwaysOn.onToggle += delegate(bool val)
				{
					if (!eventLock)
					{
						AlwaysOn = val;
						Plugin.AlwaysOn.Value = val;
					}
				};
				tipToggleAlwaysOn = obj7.AddComponent<UITooltip>();
				tipToggleAlwaysOn.Title = Localization.Translate("Always On");
				tipToggleAlwaysOn.Text = Localization.Translate("When enabled, the ray receiver will always operate at maximum capacity.");
				initialized = true;
				RefreshUI();
			}
			catch
			{
				Log.LogError((object)"UI component initial fail!");
			}
		}

		public static void OnDestory()
		{
			Object.Destroy((Object)(object)group);
			tipSliderMultiplier?.OnDestory();
			initialized = false;
		}

		public static void RefreshUI()
		{
			eventLock = true;
			if (initialized)
			{
				inputMultiplier.text = Multiplier.ToString();
				if (Multiplier <= 10)
				{
					sliderMultiplier.value = Multiplier;
				}
				else
				{
					sliderMultiplier.value = 10 + (Multiplier - 10) / 10;
				}
				inputEfficiency.text = Efficiency.ToString();
				sliderEfficiency.value = (float)Efficiency * 0.1f;
				toggleAlwaysOn.isOn = AlwaysOn;
			}
			eventLock = false;
		}

		public static void OnSliderMulChange(float val)
		{
			if (!eventLock)
			{
				val = Mathf.Round(val / 1f) * 1f;
				sliderMultiplier.value = val;
				if (val <= 10f)
				{
					Multiplier = (int)val;
				}
				else
				{
					Multiplier = 10 + (int)(val - 10f) * 10;
				}
				Plugin.EnergyCapMultiplier.Value = Multiplier;
				RefreshUI();
			}
		}

		public static void OnSliderEffChange(float val)
		{
			if (!eventLock)
			{
				val = Mathf.Round(val / 1f) * 1f;
				sliderEfficiency.value = val;
				Efficiency = (int)val * 10;
				Plugin.EnergyEfficiency.Value = Efficiency;
				RefreshUI();
			}
		}

		public static void OnInputMulEnd(string val)
		{
			if (eventLock)
			{
				return;
			}
			if (int.TryParse(val, out var result))
			{
				if (result < 1)
				{
					result = 1;
				}
				else if (result > 100)
				{
					result = 100;
				}
				Multiplier = result;
				Plugin.EnergyCapMultiplier.Value = Multiplier;
			}
			RefreshUI();
		}

		public static void OnInputEffEnd(string val)
		{
			if (eventLock)
			{
				return;
			}
			if (int.TryParse(val, out var result))
			{
				if (result < 1)
				{
					result = 1;
				}
				else if (result > 100)
				{
					result = 100;
				}
				Efficiency = result;
				Plugin.EnergyEfficiency.Value = Efficiency;
			}
			RefreshUI();
		}
	}
	public class UITooltip : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
	{
		public string Title;

		public string Text;

		private UIButtonTip tip;

		public void OnPointerEnter(PointerEventData eventData)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			tip = UIButtonTip.Create(true, Title, Text, 3, new Vector2(0f, 20f), 180, ((Component)this).gameObject.transform.parent, "", "");
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			if ((Object)(object)tip != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)tip).gameObject);
			}
			tip = null;
		}

		public void OnDisable()
		{
			if ((Object)(object)tip != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)tip).gameObject);
			}
			tip = null;
		}

		public void OnDestory()
		{
			if ((Object)(object)tip != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)tip).gameObject);
			}
			tip = null;
		}
	}
}