Decompiled source of MegaRayReceiver v1.1.2

MegaRayReceiver.dll

Decompiled 2 months 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.2.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.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "Rokumaehn.plugin.MegaRayReceiver";

		public const string NAME = "MegaRayReceiver";

		public const string VERSION = "1.1.2";

		public static ConfigEntry<int> EnergyCapMultiplier;

		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
			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>()));
			UIPowerPanelPatch.Multiplier = EnergyCapMultiplier.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;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PowerGeneratorComponent), "EnergyCap_Gamma_Req")]
		private static void MegaRayStuff2post(ref PowerGeneratorComponent __instance, ref long __result, float sx, float sy, float sz, float increase, float eta)
		{
			__instance.capacityCurrentTick *= UIPowerPanelPatch.Multiplier;
			__result *= UIPowerPanelPatch.Multiplier;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PowerGeneratorComponent), "RequiresCurrent_Gamma")]
		private static void MegaRayStuff3post(ref PowerGeneratorComponent __instance, ref long __result, float eta)
		{
			__result *= UIPowerPanelPatch.Multiplier;
		}
	}
	internal class UIPowerPanelPatch
	{
		public static int Multiplier = 10;

		public static int SliderMax = 19;

		public static ManualLogSource Log;

		private static bool initialized;

		private static GameObject group;

		private static InputField inputMultiplier;

		private static Slider sliderMultiplier;

		private static Text text_factory;

		private static bool eventLock;

		private static UITooltip tipInputMultiplier;

		private static UITooltip tipSliderMultiplier;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIStatisticsWindow), "_OnOpen")]
		public static void Init()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)group == (Object)null)
			{
				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>();
					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>)OnInputValueEnd);
					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>)OnSliderChange);
					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.");
					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;
				}
			}
			eventLock = false;
		}

		public static void OnSliderChange(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 OnInputValueEnd(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 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;
		}
	}
}