Decompiled source of GeneratorFuelRate v1.0.1

GeneratorFuelRate.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 GeneratorFuelRate
{
	public enum Language
	{
		English,
		Chinese,
		Turkish
	}
	[BepInPlugin("bug.dsp.generatorfuelrate", "GeneratorFuelRate", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private static Text rateText;

		private static ConfigEntry<bool> showCurrent;

		private static ConfigEntry<bool> showMax;

		private static ConfigEntry<Language> language;

		private static readonly string[] perMin = new string[3] { "/ min", "/ 分钟", "/ dk" };

		private static readonly string[] maxWord = new string[3] { "max", "最大", "maks" };

		private void Awake()
		{
			showCurrent = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowCurrent", true, "Show fuel items per minute at the plant's current output.");
			showMax = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowMax", true, "Show fuel items per minute the plant would burn at full load (max).");
			language = ((BaseUnityPlugin)this).Config.Bind<Language>("General", "Language", Language.English, "Text language: English, Chinese or Turkish.");
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		public static double FuelPerMinute(in PowerGeneratorComponent g, long energy, long heatValue)
		{
			if (heatValue <= 0 || g.genEnergyPerTick <= 0)
			{
				return 0.0;
			}
			return (g.productive ? ((double)energy * (double)g.useFuelPerTick * 40.0 / ((double)g.genEnergyPerTick * (double)Cargo.incFastDivisionNumerator[g.fuelIncLevel])) : ((double)energy * (double)g.useFuelPerTick / (double)g.genEnergyPerTick)) * 3600.0 / (double)heatValue;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIPowerGeneratorWindow), "_OnUpdate")]
		private static void OnUpdate(UIPowerGeneratorWindow __instance)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.generatorId != 0 && __instance.powerSystem != null && ((Component)__instance.group2).gameObject.activeSelf)
			{
				if ((Object)(object)rateText == (Object)null)
				{
					rateText = Object.Instantiate<Text>(__instance.fuelText2, ((Component)__instance.fuelText2).transform.parent.parent);
					((Object)rateText).name = "fuel-rate-text";
					rateText.alignment = (TextAnchor)3;
					rateText.horizontalOverflow = (HorizontalWrapMode)1;
					((Graphic)rateText).raycastTarget = false;
					RectTransform rectTransform = ((Graphic)rateText).rectTransform;
					Vector2 val = default(Vector2);
					((Vector2)(ref val))..ctor(0.5f, 0.5f);
					rectTransform.anchorMax = val;
					rectTransform.anchorMin = val;
					rectTransform.pivot = new Vector2(0f, 0.5f);
					rectTransform.sizeDelta = new Vector2(180f, 20f);
					rectTransform.anchoredPosition = new Vector2(-40f, -70f);
				}
				ref PowerGeneratorComponent reference = ref __instance.powerSystem.genPool[__instance.generatorId];
				ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)((reference.curFuelId != 0) ? reference.curFuelId : reference.fuelId));
				if (val2 == null)
				{
					rateText.text = "";
					return;
				}
				string text = FuelPerMinute(in reference, reference.generateCurrentTick, val2.HeatValue).ToString("0.##");
				string text2 = FuelPerMinute(in reference, reference.capacityCurrentTick, val2.HeatValue).ToString("0.##");
				int value = (int)language.Value;
				rateText.text = ((showCurrent.Value && showMax.Value) ? (text + " " + perMin[value] + "  (" + maxWord[value] + " " + text2 + ")") : (showCurrent.Value ? (text + " " + perMin[value]) : (showMax.Value ? (maxWord[value] + " " + text2 + " " + perMin[value]) : "")));
			}
		}
	}
}