using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using PowerNetworkManager.Data;
using PowerNetworkManager.UI;
using PowerNetworkStructures;
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("Power Network Manager")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Power Network Manager")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8a09a11f-d17a-4562-a1ba-9a3f43a6662b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PowerNetworkManager
{
[BepInPlugin("testpostpleaseignore.dsp.powernetworkmanager", "Power_Network_Manager", "0.0.7")]
[BepInProcess("DSPGame.exe")]
public class PowerNetworkManager : BaseUnityPlugin
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static UnityAction <>9__15_0;
internal void <GameMain_Begin_Prefix>b__15_0()
{
ButtonClick();
}
}
public const string pluginGuid = "testpostpleaseignore.dsp.powernetworkmanager";
public const string pluginName = "Power_Network_Manager";
public const string pluginVersion = "0.0.7";
private Harmony harmony;
public static PowerNetworkManager instance;
public static PowerDataCalc powerData = new PowerDataCalc();
internal static ManualLogSource logger;
internal static ConfigFile Config;
private static bool ignoreFirstReverseButtonOnPointerEnter = true;
public static RectTransform launchButton;
public static Sprite launchSprite;
public static PowerWindow powerWindow;
private void Awake()
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
logger = ((BaseUnityPlugin)this).Logger;
Config = ((BaseUnityPlugin)this).Config;
Assert.Null((object)instance, "An instance of PowerNetworkManager has already been created!");
instance = this;
powerWindow = new PowerWindow(powerData);
harmony = new Harmony("testpostpleaseignore.dsp.powernetworkmanager");
try
{
harmony.PatchAll(typeof(PowerNetworkManager));
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Harmony patching failed: " + ex.Message));
}
logger.LogInfo((object)"Load Complete");
}
private void OnDestroy()
{
if ((Object)(object)launchButton != (Object)null)
{
Object.Destroy((Object)(object)((Component)launchButton).gameObject);
Object.Destroy((Object)(object)launchSprite);
}
harmony.UnpatchSelf();
instance = null;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UIButton), "OnPointerEnter")]
public static bool UIButton_OnPointerEnter_Prefix(UIButton __instance)
{
if ((Object)(object)launchButton != (Object)null && (Object)(object)__instance == (Object)(object)((Component)launchButton).GetComponent<UIButton>() && ignoreFirstReverseButtonOnPointerEnter)
{
ignoreFirstReverseButtonOnPointerEnter = false;
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameMain), "Begin")]
public static void GameMain_Begin_Prefix()
{
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Expected O, but got Unknown
ignoreFirstReverseButtonOnPointerEnter = true;
if (!((Object)(object)GameMain.instance != (Object)null) || !Object.op_Implicit((Object)(object)GameObject.Find("Game Menu/button-1-bg")) || Object.op_Implicit((Object)(object)GameObject.Find("pnm-launch-button")))
{
return;
}
launchButton = Object.Instantiate<RectTransform>(GameObject.Find("Game Menu/button-1-bg").GetComponent<RectTransform>());
((Object)((Component)launchButton).gameObject).name = "pnm-launch-button";
UIButton component = ((Component)launchButton).GetComponent<UIButton>();
component.tips.tipTitle = "Power Network Manager";
component.tips.tipText = "Click to launch the Power Network Manager window for this network.";
component.tips.delay = 0f;
((Component)((Component)launchButton).transform.Find("button-1/icon")).GetComponent<Image>().sprite = GetSprite();
((Transform)launchButton).SetParent(((Component)UIRoot.instance.uiGame.nodeWindow).transform);
((Transform)launchButton).localScale = new Vector3(0.5f, 0.5f, 0.5f);
((Transform)launchButton).localPosition = new Vector3(30f, -100f, 0f);
component.OnPointerDown((PointerEventData)null);
component.OnPointerEnter((PointerEventData)null);
ButtonClickedEvent onClick = component.button.onClick;
object obj = <>c.<>9__15_0;
if (obj == null)
{
UnityAction val = delegate
{
ButtonClick();
};
<>c.<>9__15_0 = val;
obj = (object)val;
}
((UnityEvent)onClick).AddListener((UnityAction)obj);
}
public static Sprite GetSprite()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(48, 48, (TextureFormat)4, false);
Color val2 = default(Color);
((Color)(ref val2))..ctor(1f, 1f, 1f, 1f);
int num = 10;
for (int i = 0; i < 48; i++)
{
for (int j = 0; j < 48; j++)
{
if ((i >= 7 && i <= 39 && j >= num + 10 && j <= num + 16) || (i == 33 && j >= num + 1 && j <= num + 25) || (i == 34 && j >= num + 2 && j <= num + 24) || (i == 35 && j >= num + 3 && j <= num + 23) || (i == 36 && j >= num + 4 && j <= num + 22) || (i == 37 && j >= num + 5 && j <= num + 21) || (i == 38 && j >= num + 6 && j <= num + 20) || (i == 39 && j >= num + 7 && j <= num + 19) || (i == 40 && j >= num + 8 && j <= num + 18) || (i == 41 && j >= num + 9 && j <= num + 17) || (i == 42 && j >= num + 10 && j <= num + 16) || (i == 43 && j >= num + 11 && j <= num + 15) || (i == 44 && j >= num + 12 && j <= num + 14) || (i == 45 && j == num + 13))
{
val.SetPixel(i, j, val2);
}
else
{
val.SetPixel(i, j, new Color(0f, 0f, 0f, 0f));
}
}
}
((Object)val).name = "power-manager-launch-icon";
val.Apply();
return Sprite.Create(val, new Rect(0f, 0f, 48f, 48f), new Vector2(0f, 0f), 1000f);
}
private static void ButtonClick()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
UIPowerNodeWindow nodeWindow = UIRoot.instance.uiGame.nodeWindow;
PowerSystem powerSystem = nodeWindow.powerSystem;
int nodeId = nodeWindow.nodeId;
PowerDataCalc.currentPowerNetworkID = powerSystem.nodePool[nodeId].networkId;
PowerWindow.Show = true;
}
private void Update()
{
}
private void OnGUI()
{
if (PowerWindow.Show)
{
powerWindow.OnGUI();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameData), "GameTick")]
public static void GameData_GameTick(long time, GameData __instance)
{
if (PowerWindow.Show)
{
powerData.onGameData_GameTick(time, __instance);
}
}
}
}
namespace PowerNetworkManager.UI
{
public class UITheme
{
public static GUIStyle TextAlignStyle;
public static GUIStyle layoutBackgroundColor;
public static GUILayoutOption[] VeinIconLayoutSmallOptions;
public static void Init()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
TextAlignStyle = new GUIStyle(GUI.skin.label);
TextAlignStyle.alignment = (TextAnchor)3;
layoutBackgroundColor = new GUIStyle(GUI.skin.box);
layoutBackgroundColor.normal.background = Texture2D.whiteTexture;
VeinIconLayoutSmallOptions = (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Height(30f),
GUILayout.MaxWidth(30f)
};
}
}
public class PowerWindow
{
private const string WindowName = "Network Power Info";
public PowerDataCalc powerData;
public static bool HighlightButton = false;
public static bool Show = false;
private static Rect winRect = new Rect(0f, 0f, 1015f, 650f);
private const float FixedSizeAdjustOriginal = 0.9f;
private static Vector2 sv;
private static bool isInit = false;
public const int valueBoxWidth = 300;
public static int UILayoutHeight { get; set; } = 1080;
public static int ScaledScreenWidth { get; set; } = 1920;
public static int ScaledScreenHeight { get; set; } = 1080;
public static float ScaleRatio { get; set; } = 1f;
public static float FixedSizeAdjust { get; set; } = 0.9f;
public PowerWindow(PowerDataCalc powerData)
{
this.powerData = powerData;
}
public void OnGUI()
{
//IL_00dd: 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_00fd: Expected O, but got Unknown
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: 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_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Invalid comparison between Unknown and I4
UIGame uiGame = BGMController.instance.uiGame;
if (DSPGame.GameDesc != null && (Object)(object)uiGame != (Object)null && uiGame.gameData != null && uiGame.guideComplete && !DSPGame.IsMenuDemo && DSPGame.Game.running && ((int)UIGame.viewMode == 0 || (int)UIGame.viewMode == 2) && !((ManualBehaviour)uiGame.techTree).active && !((ManualBehaviour)uiGame.dysonEditor).active && !((ManualBehaviour)uiGame.starmap).active && !((ManualBehaviour)uiGame.escMenu).active && !uiGame.hideAllUI0 && !uiGame.hideAllUI1 && ((ManualBehaviour)uiGame.gameMenu).active)
{
if (!isInit && GameMain.isRunning)
{
UITheme.Init();
PowerDataCalc.Init();
isInit = true;
}
AutoResize(UILayoutHeight);
if (Show)
{
winRect = GUILayout.Window(6549813, winRect, new WindowFunction(WindowFunc), "Network Power Info", Array.Empty<GUILayoutOption>());
EatInputInRect(winRect);
}
}
}
public static void AutoResize(int designScreenHeight, bool applyCustomScale = true)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: 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)
if (applyCustomScale)
{
designScreenHeight = (int)Math.Round((float)designScreenHeight / FixedSizeAdjust);
}
ScaledScreenHeight = designScreenHeight;
ScaleRatio = (float)Screen.height / (float)designScreenHeight;
ScaledScreenWidth = (int)Math.Round((float)Screen.width / ScaleRatio);
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(ScaleRatio, ScaleRatio, 1f));
}
public void WindowFunc(int id)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: 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_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_09d0: Unknown result type (might be due to invalid IL or missing references)
//IL_09d7: Invalid comparison between Unknown and I4
GUILayout.BeginArea(new Rect(((Rect)(ref winRect)).width - 22f, 2f, 20f, 17f));
if (GUILayout.Button("X", Array.Empty<GUILayoutOption>()))
{
Show = false;
}
GUILayout.EndArea();
GUILayout.BeginArea(new Rect(((Rect)(ref winRect)).width - 45f, 2f, 20f, 17f));
if (GUILayout.Button("+", Array.Empty<GUILayoutOption>()))
{
FixedSizeAdjust = Mathf.Min(1.7f, FixedSizeAdjust + 0.1f);
}
GUILayout.EndArea();
GUILayout.BeginArea(new Rect(((Rect)(ref winRect)).width - 64f, 2f, 20f, 17f));
if (GUILayout.Button("1", Array.Empty<GUILayoutOption>()))
{
FixedSizeAdjust = 0.9f;
}
GUILayout.EndArea();
GUILayout.BeginArea(new Rect(((Rect)(ref winRect)).width - 83f, 2f, 20f, 17f));
if (GUILayout.Button("-", Array.Empty<GUILayoutOption>()))
{
FixedSizeAdjust = Mathf.Max(0.39999998f, FixedSizeAdjust - 0.1f);
}
GUILayout.EndArea();
GUILayout.BeginVertical(UITheme.layoutBackgroundColor, Array.Empty<GUILayoutOption>());
sv = GUILayout.BeginScrollView(sv, GUI.skin.box);
GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.Label("<b>Max Power Usage for Network: " + PowerDataCalc.maxNetworkPowerUsageString + "</b>", UITheme.TextAlignStyle, Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.Label("<b>Max Power Usage for Network (sans transport stations): " + PowerDataCalc.maxNetworkPowerUsageSansTransportsString + "</b>", UITheme.TextAlignStyle, Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.Label("<b>Consumption Demand: " + PowerDataCalc.powerDemandString + "</b>", UITheme.TextAlignStyle, Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.Label($"<b>Consumer ratio: {Math.Round(PowerDataCalc.consumerRatio, 3)}; Generator ratio: {Math.Round(PowerDataCalc.generatorRatio, 3)}</b>", UITheme.TextAlignStyle, Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.Space(20f);
GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.Label("<b>Exchangers</b>", UITheme.TextAlignStyle, Array.Empty<GUILayoutOption>());
GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
foreach (int key in PowerDataCalc.curDischExchangersPerType.Keys)
{
ItemProto obj = ((ProtoSet<ItemProto>)(object)LDB.items).Select(key);
PowerExcData powerExcData = PowerDataCalc.curDischExchangersPerType[key];
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Box((Texture)(object)obj.iconSprite.texture, UITheme.VeinIconLayoutSmallOptions);
GUILayout.Label(Localization.Translate(((Proto)obj).name) + " (Discharging)", Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Box("Max Rated Power: " + powerExcData.ratedPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.Box("Max Active Power: " + powerExcData.maxPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.Box("Current Power: " + powerExcData.curPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.EndHorizontal();
}
foreach (int key2 in PowerDataCalc.curChargingExchangersPerType.Keys)
{
ItemProto obj2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(key2);
PowerExcData powerExcData2 = PowerDataCalc.curChargingExchangersPerType[key2];
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Box((Texture)(object)obj2.iconSprite.texture, UITheme.VeinIconLayoutSmallOptions);
GUILayout.Label(Localization.Translate(((Proto)obj2).name) + " (Charging)", Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Box("Max Rated Power: " + powerExcData2.ratedPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.Box("Max Active Power: " + powerExcData2.maxPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.Box("Current Power: " + powerExcData2.curPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
GUILayout.EndVertical();
GUILayout.Space(20f);
GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.Label("<b>Generators</b>", UITheme.TextAlignStyle, Array.Empty<GUILayoutOption>());
foreach (KeyValuePair<string, ItemProto> item in PowerDataCalc.protosInAlphaOrder)
{
int iD = ((Proto)item.Value).ID;
if (PowerDataCalc.curGenerationData.ContainsKey(iD))
{
PowerGenData powerGenData = PowerDataCalc.curGenerationData[iD];
GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Box((Texture)(object)item.Value.iconSprite.texture, UITheme.VeinIconLayoutSmallOptions);
GUILayout.Label(Localization.Translate(item.Key) ?? "", Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Box("Max Power: " + powerGenData.maxPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.Box("Current Power: " + powerGenData.genPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.Box("Power Being Used: " + powerGenData.curPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
}
GUILayout.EndVertical();
GUILayout.Space(20f);
GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.Label("<b>Accumulators</b>", UITheme.TextAlignStyle, Array.Empty<GUILayoutOption>());
GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
foreach (int key3 in PowerDataCalc.curAccPerType.Keys)
{
ItemProto obj3 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(key3);
PowerAccData powerAccData = PowerDataCalc.curAccPerType[key3];
string text = ((powerAccData.curPower < 0) ? "Discharging" : ((powerAccData.curPower > 0) ? "Charging" : ((PowerDataCalc.currentAccumulatedEnergy == 0L) ? "Empty" : "Full")));
string text2 = ((powerAccData.curPower < 0) ? powerAccData.maxDiscPowerString : ((powerAccData.curPower > 0) ? powerAccData.maxChgPowerString : powerAccData.maxDiscPowerString));
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Box((Texture)(object)obj3.iconSprite.texture, UITheme.VeinIconLayoutSmallOptions);
GUILayout.Label(Localization.Translate(((Proto)obj3).name) + " (" + text + ")", Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Box("Max Power: " + text2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.Box("Current Power: " + powerAccData.curPowerAbsString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
GUILayout.EndVertical();
GUILayout.Space(20f);
GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.Label("<b>Consumers</b>", UITheme.TextAlignStyle, Array.Empty<GUILayoutOption>());
foreach (KeyValuePair<string, ItemProto> item2 in PowerDataCalc.protosInAlphaOrder)
{
int iD2 = ((Proto)item2.Value).ID;
if (PowerDataCalc.curConsPerType.ContainsKey(iD2))
{
PowerConsData powerConsData = PowerDataCalc.curConsPerType[iD2];
GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Box((Texture)(object)item2.Value.iconSprite.texture, UITheme.VeinIconLayoutSmallOptions);
GUILayout.Label(Localization.Translate(item2.Key) ?? "", Array.Empty<GUILayoutOption>());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Box("Max Power: " + powerConsData.maxPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.Box("Current Power: " + powerConsData.currPowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.Box("Minimum (Idle) Power: " + powerConsData.idlePowerString, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(300f) });
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
GUILayout.EndVertical();
GUI.DragWindow();
if (Event.current.isKey && (int)Event.current.keyCode == 27)
{
Show = false;
}
}
public static void EatInputInRect(Rect eatRect)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: 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_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: 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)
Matrix4x4 matrix = GUI.matrix;
float num = ((Matrix4x4)(ref matrix)).lossyScale.x * ((Rect)(ref eatRect)).x;
matrix = GUI.matrix;
float num2 = ((Matrix4x4)(ref matrix)).lossyScale.y * ((Rect)(ref eatRect)).y;
matrix = GUI.matrix;
float num3 = ((Matrix4x4)(ref matrix)).lossyScale.x * ((Rect)(ref eatRect)).width;
matrix = GUI.matrix;
Rect val = default(Rect);
((Rect)(ref val))..ctor(num, num2, num3, ((Matrix4x4)(ref matrix)).lossyScale.y * ((Rect)(ref eatRect)).height);
if (((Rect)(ref val)).Contains(new Vector2(Input.mousePosition.x, (float)Screen.height - Input.mousePosition.y)) && (Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.mouseScrollDelta.y != 0f))
{
Input.ResetInputAxes();
}
}
}
}
namespace PowerNetworkManager.Data
{
public class HelperMethods
{
public static string convertPowerToString(long power)
{
if ((double)power / 1000000000.0 >= 1.0)
{
return $"{SetSigFigs((double)power / 1000000000.0, 3)} GW";
}
if ((double)power / 1000000.0 >= 1.0)
{
return $"{SetSigFigs((double)power / 1000000.0, 3)} MW";
}
if ((double)power / 1000.0 >= 1.0)
{
return $"{SetSigFigs((double)power / 1000.0, 3)} kW";
}
return $"{power} W";
}
public static double SetSigFigs(double d, int digits)
{
if (d == 0.0)
{
return 0.0;
}
decimal num = (decimal)Math.Pow(10.0, Math.Floor(Math.Log10(Math.Abs(d))) + 1.0);
return (double)(num * Math.Round((decimal)d / num, digits));
}
}
public class PowerAccData : PowerData
{
public long maxDiscPower;
public string maxDiscPowerString;
public long maxChgPower;
public string maxChgPowerString;
public long curPower;
public string curPowerString;
public long curPowerAbs;
public string curPowerAbsString;
public override void generateStrings()
{
maxDiscPowerString = HelperMethods.convertPowerToString(maxDiscPower);
maxChgPowerString = HelperMethods.convertPowerToString(maxChgPower);
curPowerString = HelperMethods.convertPowerToString(curPower);
curPowerAbsString = HelperMethods.convertPowerToString(curPowerAbs);
}
}
public class PowerConsData : PowerData
{
public long idlePower;
public string idlePowerString;
public long maxPower;
public string maxPowerString;
public long currPower;
public string currPowerString;
public override void generateStrings()
{
idlePowerString = HelperMethods.convertPowerToString(idlePower);
maxPowerString = HelperMethods.convertPowerToString(maxPower);
currPowerString = HelperMethods.convertPowerToString(currPower);
}
}
public abstract class PowerData
{
public abstract void generateStrings();
}
public class PowerExcData : PowerData
{
public long maxPower;
public string maxPowerString;
public long curPower;
public string curPowerString;
public long ratedPower;
public string ratedPowerString;
public override void generateStrings()
{
maxPowerString = HelperMethods.convertPowerToString(maxPower);
curPowerString = HelperMethods.convertPowerToString(curPower);
ratedPowerString = HelperMethods.convertPowerToString(ratedPower);
}
}
public class PowerGenData : PowerData
{
public long maxPower;
public string maxPowerString;
public long genPower;
public string genPowerString;
public long curPower;
public string curPowerString;
public override void generateStrings()
{
maxPowerString = HelperMethods.convertPowerToString(maxPower);
genPowerString = HelperMethods.convertPowerToString(genPower);
curPowerString = HelperMethods.convertPowerToString(curPower);
}
}
public class PowerDataCalc
{
private static long lastTime = 0L;
private const long refreshRateSec = 2L;
public const int sigFigs = 3;
public GameDesc lastGameDesc;
public static SortedList<string, ItemProto> protosInAlphaOrder;
public static int currentPowerNetworkID = 1;
public static long maxNetworkPowerUsage;
public static string maxNetworkPowerUsageString;
public static long maxNetworkPowerUsageSansTransports;
public static string maxNetworkPowerUsageSansTransportsString;
public static long powerDemand;
public static string powerDemandString;
public static double consumerRatio;
public static double generatorRatio;
public static long generatorOutputCapacity;
public static int generatorCount;
public static Dictionary<int, PowerGenData> curGenerationData = new Dictionary<int, PowerGenData>();
public static long exchangerMaxPower;
public static Dictionary<int, PowerExcData> curDischExchangersPerType = new Dictionary<int, PowerExcData>();
public static Dictionary<int, PowerExcData> curChargingExchangersPerType = new Dictionary<int, PowerExcData>();
public static Dictionary<int, PowerAccData> curAccPerType = new Dictionary<int, PowerAccData>();
public static long currentAccumulatedEnergy;
public static long consumerMaxPower;
public static Dictionary<int, PowerConsData> curConsPerType = new Dictionary<int, PowerConsData>();
public static void Init()
{
protosInAlphaOrder = new SortedList<string, ItemProto>();
ItemProto[] dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
foreach (ItemProto val in dataArray)
{
protosInAlphaOrder.Add(Localization.Translate(((Proto)val).name), val);
}
}
public void onGameData_GameTick(long time, GameData __instance)
{
if (IsDifferentGame())
{
Reset();
}
if (__instance != null && __instance.localPlanet != null && time - lastTime >= 120)
{
lastTime = time;
updatePowerUsage(__instance);
}
}
private void updatePowerUsage(GameData __instance)
{
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: 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_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Unknown result type (might be due to invalid IL or missing references)
//IL_026a: Unknown result type (might be due to invalid IL or missing references)
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_036d: Unknown result type (might be due to invalid IL or missing references)
//IL_0372: Unknown result type (might be due to invalid IL or missing references)
//IL_037f: Unknown result type (might be due to invalid IL or missing references)
//IL_039b: Unknown result type (might be due to invalid IL or missing references)
//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0405: Unknown result type (might be due to invalid IL or missing references)
//IL_040d: Unknown result type (might be due to invalid IL or missing references)
//IL_0509: Unknown result type (might be due to invalid IL or missing references)
//IL_050e: Unknown result type (might be due to invalid IL or missing references)
//IL_051b: Unknown result type (might be due to invalid IL or missing references)
//IL_055f: Unknown result type (might be due to invalid IL or missing references)
//IL_0582: 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)
//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
//IL_05e3: Unknown result type (might be due to invalid IL or missing references)
//IL_0675: Unknown result type (might be due to invalid IL or missing references)
//IL_067a: Unknown result type (might be due to invalid IL or missing references)
//IL_0687: Unknown result type (might be due to invalid IL or missing references)
//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
//IL_0711: Unknown result type (might be due to invalid IL or missing references)
//IL_077c: Unknown result type (might be due to invalid IL or missing references)
//IL_0781: Unknown result type (might be due to invalid IL or missing references)
//IL_078e: Unknown result type (might be due to invalid IL or missing references)
//IL_07a1: Unknown result type (might be due to invalid IL or missing references)
//IL_07af: Unknown result type (might be due to invalid IL or missing references)
//IL_07ec: Unknown result type (might be due to invalid IL or missing references)
//IL_080f: Unknown result type (might be due to invalid IL or missing references)
//IL_0832: Unknown result type (might be due to invalid IL or missing references)
PlanetFactory factory = __instance.localPlanet.factory;
PowerSystem powerSystem = factory.powerSystem;
PowerNetwork val = powerSystem.netPool[currentPowerNetworkID];
maxNetworkPowerUsage = val.consumers.Sum((int x) => powerSystem.consumerPool[x].workEnergyPerTick * 60);
maxNetworkPowerUsageSansTransports = val.consumers.Where((int x) => factory.entityPool[powerSystem.consumerPool[x].entityId].stationId == 0).Sum((int x) => powerSystem.consumerPool[x].workEnergyPerTick * 60);
consumerRatio = val.consumerRatio;
generatorRatio = val.generaterRatio;
powerDemand = val.energyRequired * 60;
exchangerMaxPower = val.energyExchanged * -1 * 60;
curDischExchangersPerType.Clear();
curChargingExchangersPerType.Clear();
foreach (int exchanger in val.exchangers)
{
PowerExchangerComponent val2 = powerSystem.excPool[exchanger];
int protoId = factory.entityPool[val2.entityId].protoId;
if (val2.state <= -1f)
{
if (!curDischExchangersPerType.ContainsKey(protoId))
{
curDischExchangersPerType.Add(protoId, new PowerExcData());
}
curDischExchangersPerType[protoId].ratedPower += val2.energyPerTick * 60;
curDischExchangersPerType[protoId].maxPower += val2.capsCurrentTick * 60;
curDischExchangersPerType[protoId].curPower += val2.currEnergyPerTick * 60;
}
else if (val2.state >= 1f)
{
if (!curChargingExchangersPerType.ContainsKey(protoId))
{
curChargingExchangersPerType.Add(protoId, new PowerExcData());
}
curChargingExchangersPerType[protoId].ratedPower += val2.energyPerTick * 60;
maxNetworkPowerUsage += val2.energyPerTick * 60;
maxNetworkPowerUsageSansTransports += val2.energyPerTick * 60;
curChargingExchangersPerType[protoId].maxPower += val2.capsCurrentTick * 60;
curChargingExchangersPerType[protoId].curPower += val2.currEnergyPerTick * 60;
powerDemand += val2.currEnergyPerTick * 60;
}
}
foreach (PowerExcData value in curDischExchangersPerType.Values)
{
value.generateStrings();
}
foreach (PowerExcData value2 in curChargingExchangersPerType.Values)
{
value2.generateStrings();
}
generatorOutputCapacity = val.energyCapacity * 60;
generatorCount = val.generators.Count;
curGenerationData.Clear();
foreach (int generator in val.generators)
{
PowerGeneratorComponent val3 = powerSystem.genPool[generator];
int protoId2 = factory.entityPool[val3.entityId].protoId;
if (protoId2 != 2208 || val3.productId == 0)
{
if (!curGenerationData.ContainsKey(protoId2))
{
curGenerationData.Add(protoId2, new PowerGenData());
}
curGenerationData[protoId2].maxPower += (val3.gamma ? maxGammaPower(val3) : (val3.capacityCurrentTick * 60));
long num = (val3.gamma ? ((PowerGeneratorComponent)(ref val3)).MaxOutputCurrent_Gamma() : ((long)Math.Round((double)val3.genEnergyPerTick * (double)val3.currentStrength))) * 60;
curGenerationData[protoId2].genPower += num;
curGenerationData[protoId2].curPower += ((powerDemand > exchangerMaxPower) ? ((long)Math.Round((double)num * val.generaterRatio)) : 0);
}
}
foreach (PowerGenData value3 in curGenerationData.Values)
{
value3.generateStrings();
}
curAccPerType.Clear();
currentAccumulatedEnergy = 0L;
foreach (int accumulator in val.accumulators)
{
PowerAccumulatorComponent val4 = powerSystem.accPool[accumulator];
int protoId3 = factory.entityPool[val4.entityId].protoId;
if (!curAccPerType.ContainsKey(protoId3))
{
curAccPerType.Add(protoId3, new PowerAccData());
}
curAccPerType[protoId3].maxDiscPower += val4.outputEnergyPerTick * 60;
curAccPerType[protoId3].maxChgPower += val4.inputEnergyPerTick * 60;
curAccPerType[protoId3].curPower += val4.curPower * 60;
curAccPerType[protoId3].curPowerAbs += Math.Abs(val4.curPower * 60);
currentAccumulatedEnergy += val4.curEnergy;
}
foreach (PowerAccData value4 in curAccPerType.Values)
{
value4.generateStrings();
}
curConsPerType.Clear();
foreach (int consumer in val.consumers)
{
PowerConsumerComponent val5 = powerSystem.consumerPool[consumer];
int protoId4 = factory.entityPool[val5.entityId].protoId;
if (!curConsPerType.ContainsKey(protoId4))
{
curConsPerType.Add(protoId4, new PowerConsData());
}
curConsPerType[protoId4].idlePower += val5.idleEnergyPerTick * 60;
curConsPerType[protoId4].maxPower += val5.workEnergyPerTick * 60;
curConsPerType[protoId4].currPower += (long)Math.Floor(Convert.ToDouble(val5.requiredEnergy * 60) * consumerRatio);
}
foreach (Node node in val.nodes)
{
int id = node.id;
PowerNodeComponent val6 = powerSystem.nodePool[id];
int protoId5 = factory.entityPool[val6.entityId].protoId;
if (val6.id == id && val6.isCharger)
{
if (!curConsPerType.ContainsKey(protoId5))
{
curConsPerType.Add(protoId5, new PowerConsData());
}
curConsPerType[protoId5].idlePower += val6.idleEnergyPerTick * 60;
curConsPerType[protoId5].maxPower += val6.workEnergyPerTick * 60;
curConsPerType[protoId5].currPower += (long)Math.Floor(Convert.ToDouble(val6.requiredEnergy * 60) * consumerRatio);
}
}
foreach (PowerConsData value5 in curConsPerType.Values)
{
value5.generateStrings();
}
maxNetworkPowerUsageString = HelperMethods.convertPowerToString(maxNetworkPowerUsage);
maxNetworkPowerUsageSansTransportsString = HelperMethods.convertPowerToString(maxNetworkPowerUsageSansTransports);
powerDemandString = HelperMethods.convertPowerToString(powerDemand);
}
public bool IsDifferentGame()
{
if (DSPGame.GameDesc != lastGameDesc)
{
lastGameDesc = DSPGame.GameDesc;
return true;
}
return false;
}
public void Reset()
{
lastTime = 0L;
}
public long maxGammaPower(PowerGeneratorComponent receiver)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: 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)
if (!receiver.gamma)
{
return -1L;
}
return (long)((float)(receiver.genEnergyPerTick * 60) * 2.5f) * ((receiver.catalystPoint <= 0) ? 1 : 2) * ((receiver.productId <= 0) ? 1 : 5);
}
}
}