using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using CommonAPI.Systems.ModLocalization;
using FactoryLocator.Compat;
using FactoryLocator.UI;
using HarmonyLib;
using NebulaModel.Networking;
using NebulaModel.Packets.Warning;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using xiaoye97;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.2.3")]
[assembly: AssemblyInformationalVersion("1.2.3")]
[assembly: AssemblyProduct("FactoryLocator")]
[assembly: AssemblyTitle("FactoryLocator")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.3.0")]
[module: UnverifiableCode]
namespace FactoryLocator
{
public class MainLogic
{
private readonly List<PlanetFactory> factories = new List<PlanetFactory>();
private readonly Dictionary<int, int> filterIds = new Dictionary<int, int>();
private readonly List<int> planetIds = new List<int>();
private readonly List<Vector3> localPos = new List<Vector3>();
private readonly List<int> detailIds = new List<int>();
public int SignalId { get; set; } = 401;
public int SetFactories(StarData star, PlanetData planet)
{
factories.Clear();
if (star != null)
{
PlanetData[] planets = star.planets;
foreach (PlanetData val in planets)
{
if (val?.factory != null)
{
factories.Add(val.factory);
}
}
}
else if (planet?.factory != null)
{
factories.Add(planet.factory);
}
List<float> list = new List<float>();
List<int> list2 = new List<int>();
foreach (PlanetFactory factory in factories)
{
if (factory.powerSystem == null)
{
continue;
}
for (int j = 1; j < factory.powerSystem.netCursor; j++)
{
PowerNetwork val2 = factory.powerSystem.netPool[j];
if (val2 != null && val2.id == j)
{
list.Add((float)val2.consumerRatio);
list2.Add(val2.consumers.Count);
}
}
}
Plugin.mainWindow.SetStatusTipText(list.ToArray(), list2.ToArray());
return factories.Count;
}
public void PickBuilding(int _)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
RefreshBuilding(-1);
UIentryCount.OnOpen((ESignalType)1, filterIds);
UIItemPickerExtension.Popup(new Vector2(-300f, 250f), (Action<ItemProto>)OnBuildingPickReturn, (Func<ItemProto, bool>)((ItemProto itemProto) => filterIds.ContainsKey(((Proto)itemProto).ID)));
UIRoot.instance.uiGame.itemPicker.OnTypeButtonClick(2);
}
public void OnBuildingPickReturn(ItemProto itemProto)
{
if (itemProto != null)
{
int iD = ((Proto)itemProto).ID;
RefreshBuilding(iD);
WarningSystemPatch.AddWarningData(SignalId, iD, planetIds, localPos);
UIentryCount.OnClose();
}
}
public void PickVein(int _)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
RefreshVein(-1);
UIentryCount.OnOpen((ESignalType)1, filterIds);
UIItemPickerExtension.Popup(new Vector2(-300f, 250f), (Action<ItemProto>)OnVeinPickReturn, true, (Func<ItemProto, bool>)((ItemProto itemProto) => filterIds.ContainsKey(((Proto)itemProto).ID)));
UIRoot.instance.uiGame.itemPicker.OnTypeButtonClick(1);
}
public void OnVeinPickReturn(ItemProto itemProto)
{
if (itemProto != null)
{
int iD = ((Proto)itemProto).ID;
RefreshVein(iD);
WarningSystemPatch.AddWarningData(SignalId, iD, planetIds, localPos);
UIentryCount.OnClose();
}
}
public void PickAssembler(int _)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
RefreshAssemblers(-1);
UIentryCount.OnOpen((ESignalType)2, filterIds);
UIRecipePickerExtension.Popup(new Vector2(-300f, 250f), (Action<RecipeProto>)OnAssemblerPickReturn, (Func<RecipeProto, bool>)((RecipeProto recipeProto) => filterIds.ContainsKey(((Proto)recipeProto).ID)));
}
public void OnAssemblerPickReturn(RecipeProto recipeProto)
{
if (recipeProto != null)
{
int iD = ((Proto)recipeProto).ID;
RefreshAssemblers(iD);
WarningSystemPatch.AddWarningData(SignalId, SignalProtoSet.SignalId((ESignalType)2, iD), planetIds, localPos);
UIentryCount.OnClose();
}
}
public void PickWarning(int _)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
RefreshSignal(-1);
UIentryCount.OnOpen((ESignalType)0, filterIds);
UISignalPickerExtension.Popup(new Vector2(-300f, 250f), (Action<int>)OnWarningPickReturn, (Func<int, bool>)((int signalId) => filterIds.ContainsKey(signalId)));
UIRoot.instance.uiGame.signalPicker.OnTypeButtonClick(1);
}
public void OnWarningPickReturn(int signalId)
{
if (signalId > 0)
{
RefreshSignal(signalId);
WarningSystemPatch.AddWarningData(SignalId, signalId, planetIds, localPos, detailIds);
UIentryCount.OnClose();
}
}
public void PickStorage(int _)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
RefreshStorage(-1);
UIentryCount.OnOpen((ESignalType)1, filterIds);
UIItemPickerExtension.Popup(new Vector2(-300f, 250f), (Action<ItemProto>)OnStoragePickReturn, (Func<ItemProto, bool>)((ItemProto itemProto) => filterIds.ContainsKey(((Proto)itemProto).ID)));
}
public void OnStoragePickReturn(ItemProto itemProto)
{
if (itemProto != null)
{
int iD = ((Proto)itemProto).ID;
RefreshStorage(iD);
WarningSystemPatch.AddWarningData(SignalId, iD, planetIds, localPos);
UIentryCount.OnClose();
}
}
public void PickStation(int _)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
RefreshStation(-1);
UIentryCount.OnOpen((ESignalType)1, filterIds);
UIItemPickerExtension.Popup(new Vector2(-300f, 250f), (Action<ItemProto>)OnStationPickReturn, (Func<ItemProto, bool>)((ItemProto itemProto) => filterIds.ContainsKey(((Proto)itemProto).ID)));
}
public void OnStationPickReturn(ItemProto itemProto)
{
if (itemProto != null)
{
int iD = ((Proto)itemProto).ID;
RefreshStation(iD);
WarningSystemPatch.AddWarningData(SignalId, iD, planetIds, localPos);
UIentryCount.OnClose();
}
}
public void RefreshBuilding(int itemId)
{
//IL_00d1: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
filterIds.Clear();
localPos.Clear();
planetIds.Clear();
foreach (PlanetFactory factory in factories)
{
for (int i = 0; i < factory.entityCursor; i++)
{
if (i != factory.entityPool[i].id)
{
continue;
}
if (itemId == -1)
{
int protoId = factory.entityPool[i].protoId;
if (filterIds.ContainsKey(protoId))
{
Dictionary<int, int> dictionary = filterIds;
int key = protoId;
int value = dictionary[key] + 1;
dictionary[key] = value;
}
else
{
filterIds[protoId] = 1;
}
}
else if (itemId == factory.entityPool[i].protoId)
{
localPos.Add(factory.entityPool[i].pos + ((Vector3)(ref factory.entityPool[i].pos)).normalized * 0.5f);
planetIds.Add(factory.planetId);
}
}
}
}
public void RefreshVein(int itemId)
{
//IL_0022: 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_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: 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: Invalid comparison between Unknown and I4
//IL_0117: 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_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Expected I4, but got Unknown
filterIds.Clear();
localPos.Clear();
planetIds.Clear();
EVeinType val = (EVeinType)0;
if (itemId > 0)
{
val = LDB.veins.GetVeinTypeByItemId(itemId);
}
foreach (PlanetFactory factory in factories)
{
for (int i = 1; i < factory.veinGroups.Length; i++)
{
if ((int)factory.veinGroups[i].type == 0)
{
continue;
}
if (itemId == -1)
{
int num = (((int)factory.veinGroups[i].type != 7) ? ((ProtoSet<VeinProto>)(object)LDB.veins).Select((int)factory.veinGroups[i].type).MiningItem : 1007);
if (filterIds.ContainsKey(num))
{
Dictionary<int, int> dictionary = filterIds;
int key = num;
int value = dictionary[key] + 1;
dictionary[key] = value;
}
else
{
filterIds[num] = 1;
}
}
else if (val == factory.veinGroups[i].type)
{
localPos.Add(((Vector3)(ref factory.veinGroups[i].pos)).normalized * (factory.planet.realRadius + 0.5f));
planetIds.Add(factory.planetId);
}
}
}
}
public void RefreshAssemblers(int recipeId)
{
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: 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_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: 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_0229: 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)
filterIds.Clear();
localPos.Clear();
planetIds.Clear();
foreach (PlanetFactory factory in factories)
{
for (int i = 1; i < factory.factorySystem.assemblerCursor; i++)
{
if (i != factory.factorySystem.assemblerPool[i].id)
{
continue;
}
if (recipeId == -1)
{
int recipeId2 = factory.factorySystem.assemblerPool[i].recipeId;
if (filterIds.ContainsKey(recipeId2))
{
Dictionary<int, int> dictionary = filterIds;
int key = recipeId2;
int value = dictionary[key] + 1;
dictionary[key] = value;
}
else
{
filterIds[recipeId2] = 1;
}
}
else if (recipeId == factory.factorySystem.assemblerPool[i].recipeId)
{
ref EntityData reference = ref factory.entityPool[factory.factorySystem.assemblerPool[i].entityId];
localPos.Add(reference.pos + ((Vector3)(ref reference.pos)).normalized * 0.5f);
planetIds.Add(factory.planetId);
}
}
for (int j = 1; j < factory.factorySystem.labCursor; j++)
{
if (j != factory.factorySystem.labPool[j].id)
{
continue;
}
if (recipeId == -1)
{
int recipeId3 = factory.factorySystem.labPool[j].recipeId;
if (filterIds.ContainsKey(recipeId3))
{
Dictionary<int, int> dictionary2 = filterIds;
int value = recipeId3;
int key = dictionary2[value] + 1;
dictionary2[value] = key;
}
else
{
filterIds[recipeId3] = 1;
}
}
else if (recipeId == factory.factorySystem.labPool[j].recipeId)
{
ref EntityData reference2 = ref factory.entityPool[factory.factorySystem.labPool[j].entityId];
localPos.Add(reference2.pos + ((Vector3)(ref reference2.pos)).normalized * 0.5f);
planetIds.Add(factory.planetId);
}
}
}
}
public void RefreshSignal(int signalId)
{
//IL_0105: 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_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
filterIds.Clear();
localPos.Clear();
planetIds.Clear();
detailIds.Clear();
foreach (PlanetFactory factory in factories)
{
for (int i = 1; i < factory.entityCursor; i++)
{
if (i != factory.entityPool[i].id)
{
continue;
}
if (signalId == -1)
{
if (factory.entitySignPool[i].signType != 0)
{
int num = (int)(factory.entitySignPool[i].signType + 500);
if (filterIds.ContainsKey(num))
{
Dictionary<int, int> dictionary = filterIds;
int key = num;
int value = dictionary[key] + 1;
dictionary[key] = value;
}
else
{
filterIds[num] = 1;
}
}
}
else if (signalId == (int)(factory.entitySignPool[i].signType + 500))
{
localPos.Add(factory.entityPool[i].pos + ((Vector3)(ref factory.entityPool[i].pos)).normalized * 0.5f);
detailIds.Add(factory.entityPool[i].protoId);
planetIds.Add(factory.planetId);
}
}
}
}
public void RefreshStorage(int itemId)
{
//IL_0271: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: 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)
filterIds.Clear();
localPos.Clear();
planetIds.Clear();
foreach (PlanetFactory factory in factories)
{
for (int i = 1; i < factory.factoryStorage.storageCursor; i++)
{
StorageComponent val = factory.factoryStorage.storagePool[i];
if (val == null || val.id != i)
{
continue;
}
if (itemId == -1)
{
for (int j = 0; j < val.size; j++)
{
if (val.grids[j].count > 0)
{
int itemId2 = val.grids[j].itemId;
if (!filterIds.ContainsKey(itemId2))
{
filterIds[itemId2] = val.grids[j].count;
}
else
{
filterIds[itemId2] += val.grids[j].count;
}
}
}
continue;
}
bool flag = false;
for (int k = 0; k < val.size; k++)
{
if (val.grids[k].itemId == itemId && val.grids[k].count > 0)
{
ref EntityData reference = ref factory.entityPool[val.entityId];
localPos.Add(reference.pos + ((Vector3)(ref reference.pos)).normalized * 0.5f);
planetIds.Add(factory.planetId);
flag = true;
}
if (flag)
{
break;
}
}
}
for (int l = 1; l < factory.factoryStorage.tankCursor; l++)
{
ref TankComponent reference2 = ref factory.factoryStorage.tankPool[l];
if (reference2.id != l)
{
continue;
}
if (itemId == -1)
{
int fluidId = reference2.fluidId;
if (filterIds.ContainsKey(fluidId))
{
filterIds[fluidId] += reference2.fluidCount;
}
else
{
filterIds[fluidId] = reference2.fluidCount;
}
}
else if (itemId == reference2.fluidId)
{
ref EntityData reference3 = ref factory.entityPool[reference2.entityId];
localPos.Add(reference3.pos + ((Vector3)(ref reference3.pos)).normalized * 0.5f);
planetIds.Add(factory.planetId);
}
}
}
}
public void RefreshStation(int itemId)
{
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: 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_015a: Unknown result type (might be due to invalid IL or missing references)
filterIds.Clear();
localPos.Clear();
planetIds.Clear();
foreach (PlanetFactory factory in factories)
{
for (int i = 1; i < factory.transport.stationCursor; i++)
{
StationComponent val = factory.transport.stationPool[i];
if (val == null || val.id != i || val.storage == null)
{
continue;
}
if (itemId == -1)
{
for (int j = 0; j < val.storage.Length; j++)
{
int itemId2 = val.storage[j].itemId;
if (filterIds.ContainsKey(itemId2))
{
filterIds[itemId2] += val.storage[j].count;
}
else
{
filterIds[itemId2] = val.storage[j].count;
}
}
continue;
}
bool flag = false;
for (int k = 0; k < val.storage.Length; k++)
{
if (val.storage[k].itemId == itemId)
{
ref EntityData reference = ref factory.entityPool[val.entityId];
localPos.Add(reference.pos + ((Vector3)(ref reference.pos)).normalized * 0.5f);
planetIds.Add(factory.planetId);
flag = true;
}
if (flag)
{
break;
}
}
}
}
}
}
[BepInPlugin("starfi5h.plugin.FactoryLocator", "FactoryLocator", "1.2.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[CommonAPISubmoduleDependency(new string[] { "LocalizationModule", "CustomKeyBindSystem", "PickerExtensionsSystem" })]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "starfi5h.plugin.FactoryLocator";
public const string NAME = "FactoryLocator";
public const string VERSION = "1.2.3";
public static UILocatorWindow mainWindow;
public static MainLogic mainLogic;
public static Harmony harmony;
public void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
Log.LogSource = ((BaseUnityPlugin)this).Logger;
harmony = new Harmony("starfi5h.plugin.FactoryLocator");
harmony.PatchAll(typeof(WarningSystemPatch));
harmony.PatchAll(typeof(UIentryCount));
harmony.PatchAll(typeof(Plugin));
BuiltinKey val = default(BuiltinKey);
val.key = new CombineKey(102, (byte)2, (ECombineKeyAction)0, false);
val.conflictGroup = 2052;
val.name = "ShowFactoryLocator";
val.canOverride = true;
CustomKeyBindSystem.RegisterKeyBind<PressKeyBind>(val);
RegisterTranslation("KEYShowFactoryLocator", "Show Factory Locator Window", "打开FactoryLocator窗口");
RegisterTranslation("Building", "Building", "建筑");
RegisterTranslation("Vein", "Vein", "矿脉");
RegisterTranslation("Recipe", "Recipe", "配方");
RegisterTranslation("Warning", "Warning", "警报");
RegisterTranslation("Storage", "Storage", "储物仓");
RegisterTranslation("Station", "Station", "物流塔");
RegisterTranslation("Signal Icon", "Signal Icon", "信号图标");
RegisterTranslation("Clear All", "Clear All", "清空");
RegisterTranslation("Display All Warning", "Display All Warning", "显示所有警报提示");
RegisterTranslation("Auto Clear Query", "Auto Clear Query", "自动清除搜寻结果");
RegisterTranslation("Power Network Status", "Power Network Status", "电网状态");
RegisterTranslation("Satisfaction - Consumer Count", "Satisfaction - Consumer Count", "供电率 - 消耗者数量");
BetterWarningIconsCompat.Preload();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
internal static void Init()
{
if (mainLogic == null)
{
Log.Debug("Initing...");
mainLogic = new MainLogic();
mainWindow = UILocatorWindow.CreateWindow();
NebulaCompat.Init();
DSPMoreRecipesCompat.Init();
GenesisBookCompat.Init();
BetterWarningIconsCompat.Postload();
}
}
private static void RegisterTranslation(string key, string enTrans, string cnTrans)
{
LocalizationModule.RegisterTranslation(key, enTrans, cnTrans, enTrans);
}
public void Update()
{
if (CustomKeyBindSystem.GetKeyBind("ShowFactoryLocator").keyValue)
{
if (!((ManualBehaviour)mainWindow).active)
{
mainWindow.OpenWindow();
}
else
{
((ManualBehaviour)mainWindow)._Close();
}
}
else if ((Object)(object)mainWindow != (Object)null && ((ManualBehaviour)mainWindow).active)
{
((ManualBehaviour)mainWindow)._OnUpdate();
if (VFInput.escape)
{
VFInput.UseEscape();
((ManualBehaviour)mainWindow)._Close();
}
}
}
public void OnDestroy()
{
harmony.UnpatchSelf();
if ((Object)(object)mainWindow != (Object)null)
{
Object.Destroy((Object)(object)((Component)mainWindow).gameObject);
mainWindow = null;
}
UIentryCount.OnDestory();
}
}
public static class Log
{
public static ManualLogSource LogSource;
public static void Error(object obj)
{
LogSource.LogError(obj);
}
public static void Warn(object obj)
{
LogSource.LogWarning(obj);
}
public static void Info(object obj)
{
LogSource.LogInfo(obj);
}
public static void Debug(object obj)
{
LogSource.LogDebug(obj);
}
}
public class UIentryCount
{
private static Dictionary<int, int> filterIds;
private static Text[] countArray;
private const int ARRAYLENGTH = 112;
public static int ItemCol { get; set; } = 14;
public static int RecipeCol { get; set; } = 14;
public static int SignalCol { get; set; } = 14;
public static void OnOpen(ESignalType signalType, Dictionary<int, int> filters)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
filterIds = filters;
if (countArray == null)
{
countArray = (Text[])(object)new Text[112];
}
for (int i = 0; i < 112; i++)
{
Init(ref countArray[i], signalType, i);
}
}
public static void OnClose()
{
if (countArray != null)
{
for (int i = 0; i < 112; i++)
{
((Component)countArray[i]).gameObject.SetActive(false);
}
}
}
public static void OnDestory()
{
if (countArray != null)
{
for (int i = 0; i < 112; i++)
{
Object.DestroyImmediate((Object)(object)countArray[i]);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIItemPicker), "OnTypeButtonClick")]
private static void OnTypeButtonClick1(UIItemPicker __instance)
{
if (countArray != null)
{
for (int i = 0; i < 112; i++)
{
int protoId = ((Proto)(__instance.protoArray[i]?)).ID ?? (-1);
SetNumber(countArray[i], protoId);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIRecipePicker), "OnTypeButtonClick")]
private static void OnTypeButtonClick2(UIRecipePicker __instance)
{
if (countArray != null)
{
for (int i = 0; i < 112; i++)
{
int protoId = ((Proto)(__instance.protoArray[i]?)).ID ?? (-1);
SetNumber(countArray[i], protoId);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UISignalPicker), "OnTypeButtonClick")]
private static void OnTypeButtonClick3(UISignalPicker __instance)
{
if (countArray != null)
{
for (int i = 0; i < 112; i++)
{
int protoId = __instance.signalArray[i];
SetNumber(countArray[i], protoId);
}
}
}
public static void Init(ref Text text, ESignalType signalType, int index)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected I4, but got Unknown
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)text == (Object)null)
{
text = Object.Instantiate<Text>(UIRoot.instance.uiGame.warningWindow.itemPrefab.countText);
}
switch ((int)signalType)
{
case 1:
((Component)text).gameObject.transform.SetParent(((Component)UIRoot.instance.uiGame.itemPicker.iconImage).transform);
break;
case 2:
((Component)text).gameObject.transform.SetParent(((Component)UIRoot.instance.uiGame.recipePicker.iconImage).transform);
break;
case 0:
((Component)text).gameObject.transform.SetParent(((Component)UIRoot.instance.uiGame.signalPicker.iconImage).transform);
break;
}
((Component)text).gameObject.transform.localScale = Vector3.one;
text.text = "";
SetPosition(text, index, signalType);
}
private static void SetPosition(Text text, int hoveredIndex, ESignalType signalType)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Expected I4, but got Unknown
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
int num = 14;
switch ((int)signalType)
{
case 1:
num = ItemCol;
break;
case 2:
num = RecipeCol;
break;
case 0:
num = SignalCol;
break;
}
int num2 = hoveredIndex % num;
int num3 = hoveredIndex / num;
((Transform)((Graphic)text).rectTransform).localPosition = Vector2.op_Implicit(new Vector2((float)(num2 * 46 + 41), (float)(-num3 * 46 - 15)));
}
private static void SetNumber(Text text, int protoId)
{
((Component)text).gameObject.SetActive(filterIds.TryGetValue(protoId, out var value));
if (value < 10000)
{
text.text = value.ToString();
}
else if (value < 10000000)
{
text.text = $"{(float)value / 1000f:F1}K";
}
else
{
text.text = $"{(float)value / 1000f / 1000f:F1}M";
}
}
}
public class UIwarningTip
{
private static UIButtonTip tip;
public static void Create(UIWarningItemEntry itemEntry, int signalId)
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)tip != (Object)null)
{
Object.Destroy((Object)(object)((Component)tip).gameObject);
}
int signalId2 = itemEntry.signalId;
string text = ((signalId2 < 20000) ? LDB.ItemName(signalId2) : LDB.RecipeName(signalId2 - 20000));
string text2 = GetText(signalId, signalId2);
Transform transform = ((Component)itemEntry).transform;
tip = UIButtonTip.Create(true, text, text2, 2, new Vector2(0f, -10f), 0, transform, "", "");
}
public static void Destory()
{
if ((Object)(object)tip != (Object)null)
{
Object.Destroy((Object)(object)((Component)tip).gameObject);
}
tip = null;
}
private static string GetText(int signalId, int detailId)
{
Dictionary<int, int> dictionary = new Dictionary<int, int>();
WarningSystem warningSystem = GameMain.data.warningSystem;
if (signalId > 0)
{
for (int i = 1; i < warningSystem.warningCursor; i++)
{
ref WarningData reference = ref warningSystem.warningPool[i];
if (reference.id == i && reference.state > 0 && reference.signalId == signalId && reference.detailId == detailId)
{
if (dictionary.ContainsKey(reference.astroId))
{
int astroId = reference.astroId;
int value = dictionary[astroId] + 1;
dictionary[astroId] = value;
}
else
{
dictionary[reference.astroId] = 1;
}
}
}
}
string text = "";
foreach (KeyValuePair<int, int> item in dictionary)
{
PlanetData val = GameMain.galaxy.PlanetById(item.Key);
if (val != null)
{
text = text + val.displayName + " (" + item.Value + ")\n";
}
}
return text;
}
}
public class WarningSystemPatch
{
private const int INDEXUPPERBOND = -20000;
private static int tmpSigalId = 0;
private static int tick = 3;
public static bool Enable { get; set; } = true;
[HarmonyPostfix]
[HarmonyPatch(typeof(WarningSystem), "Import")]
internal static void Import(WarningSystem __instance)
{
for (int i = 1; i < __instance.warningCursor; i++)
{
if (__instance.warningPool[i].factoryId <= -20000)
{
__instance.warningPool[i].detailId = -__instance.warningPool[i].factoryId + -20000;
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(UIWarningWindow), "Determine")]
internal static void Determine(ref bool open)
{
open &= Enable;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIWarningWindow), "_OnClose")]
internal static void OnClose()
{
UIwarningTip.Destory();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIWarningWindow), "_OnLateUpdate")]
internal static void OnLateUpdate(UIWarningWindow __instance)
{
//IL_005e: 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_0073: Expected O, but got Unknown
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
if (tmpSigalId != 0)
{
__instance.selectedSignalId = tmpSigalId;
if (--tick <= 0)
{
tmpSigalId = 0;
}
}
if (!Input.GetKeyDown((KeyCode)323) && !Input.GetKeyDown((KeyCode)324))
{
return;
}
Camera worldCamera = UIRoot.instance.overlayCanvas.worldCamera;
if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)((Component)__instance.itemGroup).transform, Vector2.op_Implicit(Input.mousePosition), worldCamera))
{
for (int i = 0; i < __instance.itemCount; i++)
{
if (RectTransformUtility.RectangleContainsScreenPoint(__instance.itemEntries[i].rectTrans, Vector2.op_Implicit(Input.mousePosition), worldCamera))
{
if (Input.GetKeyDown((KeyCode)323))
{
UIwarningTip.Create(__instance.itemEntries[i], __instance.selectedSignalId);
}
else
{
HideGroup(__instance.selectedSignalId, __instance.itemEntries[i].signalId);
}
break;
}
}
}
else
{
UIwarningTip.Destory();
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlanetFactory), "RemoveEntityWithComponents")]
internal static void RemoveWarningByEntity(PlanetFactory __instance, int id)
{
//IL_003a: 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_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)
int planetId = __instance.planetId;
WarningSystem warningSystem = GameMain.data.warningSystem;
for (int i = 1; i < warningSystem.warningCursor; i++)
{
ref WarningData reference = ref warningSystem.warningPool[i];
if (reference.factoryId <= -20000 && reference.astroId == planetId)
{
Vector3 val = reference.localPos - __instance.entityPool[id].pos;
if (((Vector3)(ref val)).sqrMagnitude < 1f)
{
warningSystem.RemoveWarningData(i);
Log.Debug($"Remove {i} on {planetId}");
}
}
}
}
public static void AddWarningData(int signalId, int detailId, List<int> planetIds, List<Vector3> localPos, List<int> detailIds = null)
{
//IL_014a: 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)
if (planetIds.Count != localPos.Count || (detailIds != null && detailIds.Count != localPos.Count))
{
Log.Warn($"Length mismatch! planetIds:{planetIds.Count} pos:{localPos.Count}");
return;
}
WarningSystem warningSystem = GameMain.data.warningSystem;
int num = warningSystem.warningTotalCount + localPos.Count;
int num2 = warningSystem.warningCapacity;
while (num >= num2)
{
num2 *= 2;
}
if (num2 > warningSystem.warningCapacity)
{
warningSystem.SetWarningCapacity(num2);
}
for (int i = 0; i < localPos.Count; i++)
{
int num3 = warningSystem.warningCursor;
if (warningSystem.warningRecycleCursor > 0)
{
num3 = warningSystem.warningRecycle[--warningSystem.warningRecycleCursor];
}
else
{
warningSystem.warningCursor++;
}
int num4 = detailIds?[i] ?? detailId;
if (num4 < 0)
{
Log.Warn($"warningDetailId {num4} < 0");
return;
}
ref WarningData reference = ref warningSystem.warningPool[num3];
reference.id = num3;
reference.state = 1;
reference.signalId = signalId;
reference.detailId = num4;
reference.factoryId = -20000 - reference.detailId;
reference.astroId = planetIds[i];
reference.localPos = localPos[i];
}
UIRoot.instance.uiGame.warningWindow.selectedSignalId = signalId;
tmpSigalId = signalId;
tick = 3;
Log.Debug($"Add {localPos.Count}. Cursor = {warningSystem.warningCursor} RecycleCursor = {warningSystem.warningRecycleCursor} Capacity = {warningSystem.warningCapacity}");
}
public static void ClearAll()
{
int num = 0;
WarningSystem warningSystem = GameMain.data.warningSystem;
for (int num2 = warningSystem.warningCursor - 1; num2 > 0; num2--)
{
ref WarningData reference = ref warningSystem.warningPool[num2];
if (reference.factoryId <= -20000)
{
((WarningData)(ref reference)).SetEmpty();
if (num2 == warningSystem.warningCursor - 1)
{
warningSystem.warningCursor--;
}
else
{
int[] warningRecycle = warningSystem.warningRecycle;
int warningRecycleCursor = warningSystem.warningRecycleCursor;
warningSystem.warningRecycleCursor = warningRecycleCursor + 1;
warningRecycle[warningRecycleCursor] = num2;
}
num++;
}
int num3 = warningSystem.warningCapacity;
while (num3 / 2 > warningSystem.warningCursor)
{
num3 /= 2;
}
if (num3 != warningSystem.warningCapacity)
{
warningSystem.SetWarningCapacity(num3);
}
}
if (num > 0)
{
Log.Debug($"Remove {num}. Cursor = {warningSystem.warningCursor} RecycleCursor = {warningSystem.warningRecycleCursor} Capacity = {warningSystem.warningCapacity}");
}
}
public static void HideGroup(int signalId, int detailId)
{
WarningSystem warningSystem = GameMain.data.warningSystem;
if (signalId <= 0)
{
return;
}
for (int i = 1; i < warningSystem.warningCursor; i++)
{
ref WarningData reference = ref warningSystem.warningPool[i];
if (reference.id == i && reference.state > 0 && reference.signalId == signalId && reference.detailId == detailId && reference.factoryId <= -20000)
{
int factoryId = reference.factoryId;
((WarningData)(ref reference)).SetEmpty();
reference.factoryId = factoryId;
}
}
}
public static void Debug()
{
//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)
Log.Info(UIRoot.instance.uiGame.warningWindow.selectedSignalId);
WarningSystem warningSystem = GameMain.data.warningSystem;
for (int i = 1; i < warningSystem.warningCursor; i++)
{
ref WarningData reference = ref warningSystem.warningPool[i];
if (reference.factoryId < -20000)
{
string text = $"[{i}] {reference.signalId} - {reference.factoryId}:";
Vector3 localPos = reference.localPos;
Log.Debug(text + ((object)(Vector3)(ref localPos)).ToString());
}
}
}
}
}
namespace FactoryLocator.UI
{
public class MyCheckBox : MonoBehaviour
{
public UIButton uiButton;
public Image checkImage;
public RectTransform rectTrans;
public Text labelText;
public bool enable;
public static MyCheckBox CreateCheckBox(bool startingState, string label = "", int fontSize = 17)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: 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)
GameObject val = Object.Instantiate<GameObject>(((Component)UIRoot.instance.uiGame.buildMenu.uxFacilityCheck).gameObject);
((Object)val).name = "my-checkbox";
MyCheckBox myCheckBox = val.AddComponent<MyCheckBox>();
myCheckBox.enable = startingState;
ref RectTransform reference = ref myCheckBox.rectTrans;
Transform transform = val.transform;
RectTransform val2 = (reference = (RectTransform)(object)((transform is RectTransform) ? transform : null));
val2.anchorMax = Vector2.zero;
val2.anchorMin = Vector2.zero;
val2.anchoredPosition3D = new Vector3(0f, 0f, 0f);
myCheckBox.uiButton = val.GetComponent<UIButton>();
Transform obj = val.transform.Find("checked");
myCheckBox.checkImage = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
Transform val3 = val.transform.Find("text");
if ((Object)(object)val3 != (Object)null)
{
Object.DestroyImmediate((Object)(object)((Component)val3).GetComponent<Localizer>());
myCheckBox.labelText = ((Component)val3).GetComponent<Text>();
myCheckBox.labelText.fontSize = fontSize;
myCheckBox.SetLabelText(label);
}
myCheckBox.uiButton.onClick += myCheckBox.OnClick;
((Behaviour)myCheckBox.checkImage).enabled = myCheckBox.enable;
return myCheckBox;
}
public void SetLabelText(string val)
{
if ((Object)(object)labelText != (Object)null)
{
labelText.text = val;
}
}
public void OnClick(int obj)
{
enable = !enable;
((Behaviour)checkImage).enabled = enable;
}
}
public static class MyWindowCtl
{
public static List<ManualBehaviour> _windows = new List<ManualBehaviour>(2);
internal static bool _created = false;
public static T CreateWindow<T>(string name, string title = "") where T : Component
{
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
UITankWindow tankWindow = UIRoot.instance.uiGame.tankWindow;
GameObject val = Object.Instantiate<GameObject>(((Component)tankWindow).gameObject, ((Component)tankWindow).transform.parent);
((Object)val).name = name;
val.SetActive(false);
Object.Destroy((Object)(object)val.GetComponent<UITankWindow>());
object obj = val.AddComponent<T>();
ManualBehaviour val2 = (ManualBehaviour)((obj is ManualBehaviour) ? obj : null);
for (int i = 0; i < val.transform.childCount; i++)
{
GameObject gameObject = ((Component)val.transform.GetChild(i)).gameObject;
if (((Object)gameObject).name == "panel-bg")
{
Button componentInChildren = gameObject.GetComponentInChildren<Button>();
if ((Object)(object)componentInChildren != (Object)null)
{
((UnityEvent)componentInChildren.onClick).AddListener(new UnityAction(val2._Close));
}
}
else if (((Object)gameObject).name != "shadow" && ((Object)gameObject).name != "panel-bg")
{
Object.Destroy((Object)(object)gameObject);
}
}
SetTitle(val2, title);
val2._Create();
val2._Init(val2.data);
_windows.Add(val2);
return (T)(object)((val2 is T) ? val2 : null);
}
public static void SetTitle(ManualBehaviour win, string title)
{
Text titleText = GetTitleText(win);
if (Object.op_Implicit((Object)(object)titleText))
{
titleText.text = title;
}
}
public static Text GetTitleText(ManualBehaviour win)
{
Transform obj = ((Component)win).gameObject.transform.Find("panel-bg/title-text");
if (obj == null)
{
return null;
}
return ((Component)obj).gameObject.GetComponent<Text>();
}
public static RectTransform GetRectTransform(ManualBehaviour win)
{
return ((Component)win).GetComponent<RectTransform>();
}
public static void OpenWindow(ManualBehaviour win)
{
win._Open();
((Component)win).transform.SetAsLastSibling();
}
public static void CloseWindow(ManualBehaviour win)
{
win._Close();
}
}
public class UILocatorWindow : ManualBehaviour
{
public RectTransform windowTrans;
private RectTransform tab1;
private Text nameText;
private UIButton[] queryBtns;
private UIButton clearAllBtn;
private Text iconText;
private UIButton iconBtn;
private Image iconImage;
private MyCheckBox warningCheckBox;
private MyCheckBox autoclearCheckBox;
private PlanetData veiwPlanet;
private StarData veiwStar;
private bool initialized;
private UIButtonTip statusTip;
private string statusText = "";
private bool autoclear_enable = true;
private int currentLanguageLCID;
public static UILocatorWindow CreateWindow()
{
return MyWindowCtl.CreateWindow<UILocatorWindow>("FactoryLocator Window", "Factory Locator");
}
public void OpenWindow()
{
MyWindowCtl.OpenWindow((ManualBehaviour)(object)this);
}
public override void _OnCreate()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
windowTrans = MyWindowCtl.GetRectTransform((ManualBehaviour)(object)this);
windowTrans.sizeDelta = new Vector2(260f, 290f);
CreateUI();
}
internal void CreateUI()
{
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
RectTransform base_ = windowTrans;
float y_ = 54f;
float x_ = 36f;
int tabIndex_ = 1;
tab1 = AddTab("General");
base_ = tab1;
y_ = 0f;
x_ = 0f;
nameText = Util.CreateText("Name", 16, (TextAnchor)4);
((Graphic)nameText).rectTransform.sizeDelta = new Vector2(180f, 20f);
Transform transform = ((Component)nameText).transform;
AddElement((RectTransform)(object)((transform is RectTransform) ? transform : null), 0f, 0f);
x_ = 0f;
queryBtns = (UIButton[])(object)new UIButton[6];
queryBtns[0] = Util.CreateButton("Building", 90f, 24f);
Transform transform2 = ((Component)queryBtns[0]).transform;
AddElement((RectTransform)(object)((transform2 is RectTransform) ? transform2 : null), 0f, 30f);
queryBtns[0].onClick += delegate
{
OnQueryClick(0);
};
queryBtns[1] = Util.CreateButton("Vein", 90f, 24f);
Transform transform3 = ((Component)queryBtns[1]).transform;
AddElement((RectTransform)(object)((transform3 is RectTransform) ? transform3 : null), 98f, 0f);
queryBtns[1].onClick += delegate
{
OnQueryClick(1);
};
queryBtns[2] = Util.CreateButton("Recipe", 90f, 24f);
Transform transform4 = ((Component)queryBtns[2]).transform;
AddElement((RectTransform)(object)((transform4 is RectTransform) ? transform4 : null), -98f, 32f);
queryBtns[2].onClick += delegate
{
OnQueryClick(2);
};
queryBtns[3] = Util.CreateButton("Warning", 90f, 24f);
Transform transform5 = ((Component)queryBtns[3]).transform;
AddElement((RectTransform)(object)((transform5 is RectTransform) ? transform5 : null), 98f, 0f);
queryBtns[3].onClick += delegate
{
OnQueryClick(3);
};
queryBtns[4] = Util.CreateButton("Storage", 90f, 24f);
Transform transform6 = ((Component)queryBtns[4]).transform;
AddElement((RectTransform)(object)((transform6 is RectTransform) ? transform6 : null), -98f, 32f);
queryBtns[4].onClick += delegate
{
OnQueryClick(4);
};
queryBtns[5] = Util.CreateButton("Station", 90f, 24f);
Transform transform7 = ((Component)queryBtns[5]).transform;
AddElement((RectTransform)(object)((transform7 is RectTransform) ? transform7 : null), 98f, 0f);
queryBtns[5].onClick += delegate
{
OnQueryClick(5);
};
x_ = 0f;
iconText = CreateTitleText("Signal Icon");
Transform transform8 = ((Component)iconText).transform;
AddElement((RectTransform)(object)((transform8 is RectTransform) ? transform8 : null), 0f, 34f);
Util.CreateSignalIcon(out iconBtn, out iconImage);
Transform transform9 = ((Component)iconBtn).transform;
AddElement((RectTransform)(object)((transform9 is RectTransform) ? transform9 : null), 70f, -3f);
iconBtn.onClick += OnIconBtnClick;
clearAllBtn = Util.CreateButton("Clear All", 70f, 24f);
Transform transform10 = ((Component)clearAllBtn).transform;
AddElement((RectTransform)(object)((transform10 is RectTransform) ? transform10 : null), 48f, 7f);
clearAllBtn.onClick += delegate
{
WarningSystemPatch.ClearAll();
};
x_ = 0f;
warningCheckBox = MyCheckBox.CreateCheckBox(WarningSystemPatch.Enable, "Display All Warning");
AddElement(warningCheckBox.rectTrans, 0f, 30f);
warningCheckBox.uiButton.onClick += OnWarningCheckboxClick;
x_ = 0f;
autoclearCheckBox = MyCheckBox.CreateCheckBox(autoclear_enable, "Auto Clear Query");
AddElement(autoclearCheckBox.rectTrans, 0f, 26f);
autoclearCheckBox.uiButton.onClick += OnAutoClearCheckoxClick;
void AddElement(RectTransform rect_, float deltaX, float deltaY)
{
x_ += deltaX;
y_ += deltaY;
if ((Object)(object)rect_ != (Object)null)
{
Util.NormalizeRectWithTopLeft((Component)(object)rect_, x_, y_, (Transform)(object)base_);
}
}
RectTransform AddTab(string label)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
GameObject val2 = new GameObject();
RectTransform val3 = val2.AddComponent<RectTransform>();
Util.NormalizeRectWithMargin((Component)(object)val3, 52f, 36f, 0f, 0f, (Transform)(object)windowTrans);
((Object)val2).name = "tab-" + tabIndex_;
return val3;
}
Text CreateTitleText(string label_)
{
//IL_003d: 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)
Text val = Object.Instantiate<Text>(MyWindowCtl.GetTitleText((ManualBehaviour)(object)this));
((Object)((Component)val).gameObject).name = "label";
val.text = label_;
((Graphic)val).color = new Color(1f, 1f, 1f, 0.5f);
Transform transform11 = ((Component)val).transform;
((RectTransform)((transform11 is RectTransform) ? transform11 : null)).sizeDelta = new Vector2(val.preferredWidth + 40f, 30f);
return val;
}
}
public override void _OnOpen()
{
if (!initialized)
{
OnSignalPickReturn(401);
initialized = true;
}
SetText();
SetViewingTarget();
NebulaCompat.OnOpen();
}
public override void _OnClose()
{
if ((Object)(object)statusTip != (Object)null)
{
Object.Destroy((Object)(object)((Component)statusTip).gameObject);
}
if (autoclear_enable)
{
WarningSystemPatch.ClearAll();
}
UIentryCount.OnClose();
NebulaCompat.OnClose();
}
public void SetText()
{
if (currentLanguageLCID != Localization.CurrentLanguageLCID)
{
currentLanguageLCID = Localization.CurrentLanguageLCID;
((Component)((Component)queryBtns[0]).transform.Find("Text")).GetComponent<Text>().text = Localization.Translate("Building");
((Component)((Component)queryBtns[1]).transform.Find("Text")).GetComponent<Text>().text = Localization.Translate("Vein");
((Component)((Component)queryBtns[2]).transform.Find("Text")).GetComponent<Text>().text = Localization.Translate("Recipe");
((Component)((Component)queryBtns[3]).transform.Find("Text")).GetComponent<Text>().text = Localization.Translate("Warning");
((Component)((Component)queryBtns[4]).transform.Find("Text")).GetComponent<Text>().text = Localization.Translate("Storage");
((Component)((Component)queryBtns[5]).transform.Find("Text")).GetComponent<Text>().text = Localization.Translate("Station");
iconText.text = Localization.Translate("Signal Icon");
((Component)((Component)clearAllBtn).transform.Find("Text")).GetComponent<Text>().text = Localization.Translate("Clear All");
warningCheckBox.labelText.text = Localization.Translate("Display All Warning");
autoclearCheckBox.labelText.text = Localization.Translate("Auto Clear Query");
}
}
public void SetViewingTarget()
{
veiwStar = null;
veiwPlanet = null;
if (((ManualBehaviour)UIRoot.instance.uiGame.planetDetail).active)
{
veiwPlanet = UIRoot.instance.uiGame.planetDetail.planet;
}
else if (((ManualBehaviour)UIRoot.instance.uiGame.starDetail).active)
{
veiwStar = UIRoot.instance.uiGame.starDetail.star;
}
else
{
veiwPlanet = GameMain.localPlanet;
}
if (veiwStar != null)
{
nameText.text = veiwStar.displayName + Localization.Translate("空格行星系");
}
else
{
Text obj = nameText;
PlanetData obj2 = veiwPlanet;
obj.text = ((obj2 != null) ? obj2.displayName : null) ?? Localization.Translate("外太空");
}
int num = Plugin.mainLogic.SetFactories(veiwStar, veiwPlanet);
for (int i = 0; i < queryBtns.Length; i++)
{
((Behaviour)queryBtns[i].button).enabled = num > 0;
}
}
public void SetStatusTipText(float[] consumerRatio, int[] consumerCount)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine(Localization.Translate("Satisfaction - Consumer Count"));
for (int i = 0; i < consumerCount.Length; i++)
{
stringBuilder.AppendLine($"{consumerRatio[i],-3:P0} - {consumerCount[i]}");
}
statusText = stringBuilder.ToString();
if ((Object)(object)statusTip != (Object)null)
{
statusTip.subTextComp.text = statusText;
}
}
public override void _OnUpdate()
{
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Expected O, but got Unknown
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
if (((ManualBehaviour)UIRoot.instance.uiGame.starDetail).active)
{
if (UIRoot.instance.uiGame.starDetail.star != veiwStar)
{
SetViewingTarget();
}
}
else if (((ManualBehaviour)UIRoot.instance.uiGame.planetDetail).active)
{
if (UIRoot.instance.uiGame.planetDetail.planet != veiwPlanet)
{
SetViewingTarget();
}
}
else if (GameMain.localPlanet != veiwPlanet)
{
SetViewingTarget();
}
Transform transform = ((Component)nameText).transform;
if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)transform, Vector2.op_Implicit(Input.mousePosition), UIRoot.instance.overlayCanvas.worldCamera))
{
if ((Object)(object)statusTip == (Object)null)
{
SetViewingTarget();
statusTip = UIButtonTip.Create(true, Localization.Translate("Power Network Status"), statusText, 1, new Vector2(0f, -10f), 0, transform, "", "");
}
}
else if ((Object)(object)statusTip != (Object)null)
{
Object.Destroy((Object)(object)((Component)statusTip).gameObject);
statusTip = null;
}
NebulaCompat.OnUpdate();
}
private void OnQueryClick(int queryType)
{
if (autoclear_enable)
{
WarningSystemPatch.ClearAll();
}
switch (queryType)
{
case 0:
Plugin.mainLogic.PickBuilding(0);
break;
case 1:
Plugin.mainLogic.PickVein(0);
break;
case 2:
Plugin.mainLogic.PickAssembler(0);
break;
case 3:
Plugin.mainLogic.PickWarning(0);
break;
case 4:
Plugin.mainLogic.PickStorage(0);
break;
case 5:
Plugin.mainLogic.PickStation(0);
break;
}
}
private void OnIconBtnClick(int _)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
UISignalPicker.Popup(new Vector2(-300f, 250f), (Action<int>)OnSignalPickReturn);
}
private void OnSignalPickReturn(int signalId)
{
Sprite val = LDB.signals.IconSprite(signalId);
if ((Object)(object)val != (Object)null)
{
Plugin.mainLogic.SignalId = signalId;
iconImage.sprite = val;
}
}
private void OnWarningCheckboxClick(int _)
{
WarningSystemPatch.Enable = !WarningSystemPatch.Enable;
}
private void OnAutoClearCheckoxClick(int _)
{
autoclear_enable = !autoclear_enable;
}
}
public class Util
{
public static RectTransform NormalizeRectWithTopLeft(Component cmp, float left, float top, Transform parent = null)
{
//IL_0028: 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_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
Transform transform = cmp.transform;
RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
if ((Object)(object)parent != (Object)null)
{
((Transform)val).SetParent(parent, false);
}
val.anchorMax = new Vector2(0f, 1f);
val.anchorMin = new Vector2(0f, 1f);
val.pivot = new Vector2(0f, 1f);
val.anchoredPosition3D = new Vector3(left, 0f - top, 0f);
return val;
}
public static RectTransform NormalizeRectWithMargin(Component cmp, float top, float left, float bottom, float right, Transform parent = null)
{
//IL_0020: 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_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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)
Transform transform = cmp.transform;
RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
if ((Object)(object)parent != (Object)null)
{
((Transform)val).SetParent(parent, false);
}
val.anchoredPosition3D = Vector3.zero;
((Transform)val).localScale = Vector3.one;
val.anchorMax = Vector2.one;
val.anchorMin = Vector2.zero;
val.pivot = new Vector2(0.5f, 0.5f);
val.offsetMax = new Vector2(0f - right, 0f - top);
val.offsetMin = new Vector2(left, bottom);
return val;
}
public static Text CreateText(string label, int fontSize = 14, TextAnchor anchor = 3)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
Text obj = Object.Instantiate<Text>(UIRoot.instance.uiGame.assemblerWindow.stateText);
((Object)((Component)obj).gameObject).name = "txt_" + label;
obj.text = label;
((Graphic)obj).color = new Color(1f, 1f, 1f, 0.4f);
obj.alignment = anchor;
obj.fontSize = fontSize;
return obj;
}
public static UIButton CreateButton(string label, float width = 0f, float height = 0f)
{
//IL_006b: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
UIButton val = Object.Instantiate<UIButton>(UIRoot.instance.uiGame.dysonEditor.controlPanel.hierarchy.swarmPanel.orbitAddButton);
((Object)((Component)val).gameObject).name = "btn_" + label;
if (val.transitions.Length >= 1)
{
val.transitions[0].target.color = new Color(0.2392f, 0.6f, 0.9f, 0.078f);
}
Text component = ((Component)((Component)val).transform.Find("Text")).GetComponent<Text>();
component.text = label;
component.fontSize = 17;
Object.Destroy((Object)(object)((Component)((Component)val).transform.Find("Text")).GetComponent<Localizer>());
Transform transform = ((Component)val).transform;
RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
if (width == 0f || height == 0f)
{
val2.sizeDelta = new Vector2(component.preferredWidth + 14f, 24f);
}
else
{
val2.sizeDelta = new Vector2(width, height);
}
return val;
}
public static void CreateSignalIcon(out UIButton iconButton, out Image iconImage)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
GameObject obj = Object.Instantiate<GameObject>(((Component)((Component)UIRoot.instance.uiGame.beltWindow.iconTagButton).transform).gameObject);
((Object)obj).name = "signal-button";
obj.SetActive(true);
RectTransform val = (RectTransform)obj.transform;
for (int num = ((Transform)val).childCount - 1; num >= 0; num--)
{
Object.Destroy((Object)(object)((Component)((Transform)val).GetChild(num)).gameObject);
}
iconButton = ((Component)val).GetComponent<UIButton>();
iconButton.tips.tipTitle = Localization.Translate("Signal Icon");
iconButton.tips.tipText = Localization.Translate("Select a signal to display.");
iconImage = ((Component)val).GetComponent<Image>();
}
}
}
namespace FactoryLocator.Compat
{
public static class BetterWarningIconsCompat
{
private const string GUID = "dev.raptor.dsp.BetterWarningIcons";
private const int InsufficientInputSignalId = 531;
public static void Preload()
{
//IL_0014: 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_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: 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_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
if (Chainloader.PluginInfos.TryGetValue("dev.raptor.dsp.BetterWarningIcons", out var _))
{
LDBTool.PreAddProto((Proto)new SignalProto
{
ID = 531,
IconPath = "",
Name = "Insufficient Input",
GridIndex = 3601,
description = "Building does not have sufficient inputs to work"
});
}
}
public static void Postload()
{
if (!Chainloader.PluginInfos.TryGetValue("dev.raptor.dsp.BetterWarningIcons", out var _))
{
return;
}
try
{
SetIcon();
}
catch (Exception obj)
{
Log.Warn("BetterWarningIcons compat fail! Last target version: 0.0.5");
Log.Debug(obj);
}
}
private static void SetIcon()
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
SignalProto obj = ((ProtoSet<SignalProto>)(object)LDB.signals).Select(531);
obj._iconSprite = (Sprite)AccessTools.TypeByName("DysonSphereProgram.Modding.BetterWarningIcons.InsufficientInputIconPatch").GetField("iconSprite").GetValue(null);
((Proto)obj).Name = "Insufficient Input";
((Proto)obj).name = Localization.Translate("Insufficient Input");
Log.Debug(((Proto)obj).name);
}
}
public static class DSPMoreRecipesCompat
{
private const string GUID = "Appun.DSP.plugin.MoreRecipes";
public static void Init()
{
if (!Chainloader.PluginInfos.TryGetValue("Appun.DSP.plugin.MoreRecipes", out var _))
{
return;
}
try
{
UIentryCount.RecipeCol = 17;
Log.Debug("DSPMoreRecipes compat - OK");
}
catch (Exception obj)
{
Log.Warn("DSPMoreRecipesCompat fail! Last target version: 1.0.3");
Log.Debug(obj);
}
}
}
public static class GenesisBookCompat
{
private const string GUID = "org.LoShin.GenesisBook";
public static void Init()
{
if (!Chainloader.PluginInfos.TryGetValue("org.LoShin.GenesisBook", out var _))
{
return;
}
try
{
UIentryCount.ItemCol = 17;
UIentryCount.RecipeCol = 17;
UIentryCount.SignalCol = 17;
Log.Debug("GenesisBook compat - OK");
}
catch (Exception obj)
{
Log.Warn("GenesisBook compat fail! Last target version: 2.9.12");
Log.Debug(obj);
}
}
}
public static class NebulaCompat
{
private const string GUID = "dsp.nebula-multiplayer";
private static bool isPatched;
public static bool IsClient { get; private set; }
public static bool SyncWarning { get; set; } = true;
public static void Init()
{
if (!Chainloader.PluginInfos.TryGetValue("dsp.nebula-multiplayer", out var value))
{
return;
}
try
{
Patch();
Log.Debug("Nebula compat - OK");
}
catch (Exception obj)
{
Log.Warn("Nebula hotfix patch fail! Current version: " + value.Metadata.Version);
Log.Debug(obj);
}
}
public static void OnOpen()
{
if (!IsClient)
{
return;
}
SyncWarning = false;
WarningSystem warningSystem = GameMain.data.warningSystem;
warningSystem.warningRecycleCursor = 0;
for (int i = 1; i < warningSystem.warningCursor; i++)
{
if (warningSystem.warningPool[i].id != i)
{
int[] warningRecycle = warningSystem.warningRecycle;
int warningRecycleCursor = warningSystem.warningRecycleCursor;
warningSystem.warningRecycleCursor = warningRecycleCursor + 1;
warningRecycle[warningRecycleCursor] = i;
}
}
}
public static void OnClose()
{
if (IsClient)
{
SyncWarning = true;
}
}
public static void OnUpdate()
{
if (!IsClient)
{
return;
}
WarningSystem warningSystem = GameMain.data.warningSystem;
Array.Clear(warningSystem.warningCounts, 0, warningSystem.warningCounts.Length);
Array.Clear(warningSystem.warningSignals, 0, warningSystem.warningSignals.Length);
warningSystem.warningSignalCount = 0;
for (int i = 1; i < warningSystem.warningCursor; i++)
{
if (warningSystem.warningPool[i].id == i && warningSystem.warningPool[i].state > 0)
{
int signalId = warningSystem.warningPool[i].signalId;
if (warningSystem.warningCounts[signalId] == 0)
{
int[] warningSignals = warningSystem.warningSignals;
int warningSignalCount = warningSystem.warningSignalCount;
warningSystem.warningSignalCount = warningSignalCount + 1;
warningSignals[warningSignalCount] = signalId;
}
warningSystem.warningCounts[signalId]++;
}
}
for (int j = 0; j < warningSystem.warningSignalCount - 1; j++)
{
for (int k = j + 1; k < warningSystem.warningSignalCount; k++)
{
if (warningSystem.warningSignals[j] > warningSystem.warningSignals[k])
{
int num = warningSystem.warningSignals[k];
warningSystem.warningSignals[k] = warningSystem.warningSignals[j];
warningSystem.warningSignals[j] = num;
}
}
}
}
public static void Patch()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Expected O, but got Unknown
Type type = AccessTools.TypeByName("NebulaWorld.Multiplayer");
Plugin.harmony.Patch((MethodBase)AccessTools.Method(type, "JoinGame", (Type[])null, (Type[])null), new HarmonyMethod(typeof(NebulaCompat).GetMethod("BeforeJoinGame")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.harmony.Patch((MethodBase)AccessTools.Method(type, "LeaveGame", (Type[])null, (Type[])null), new HarmonyMethod(typeof(NebulaCompat).GetMethod("BeforeLeaveGame")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
type = AccessTools.TypeByName("NebulaPatcher.Patches.Dynamic.WarningSystem_Patch");
MethodInfo methodInfo = AccessTools.Method(type, "CalcFocusDetail_Prefix", (Type[])null, (Type[])null);
if (methodInfo != null)
{
Plugin.harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(NebulaCompat).GetMethod("Guard")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
public static void BeforeJoinGame()
{
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected O, but got Unknown
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Expected O, but got Unknown
if (!isPatched)
{
isPatched = true;
try
{
foreach (Assembly item in AccessTools.AllAssemblies())
{
_ = item;
}
MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("NebulaNetwork.PacketProcessors.Warning.WarningDataProcessor"), "ProcessPacket", new Type[2]
{
typeof(WarningDataPacket),
typeof(NebulaConnection)
}, (Type[])null);
Plugin.harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(NebulaCompat).GetMethod("Guard")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
methodInfo = AccessTools.Method(AccessTools.TypeByName("NebulaNetwork.PacketProcessors.Warning.WarningSignalProcessor"), "ProcessPacket", new Type[2]
{
typeof(WarningSignalPacket),
typeof(NebulaConnection)
}, (Type[])null);
Plugin.harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(NebulaCompat).GetMethod("Guard")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Log.Info("PacketProcessors patch success!");
}
catch (Exception obj)
{
Log.Warn("PacketProcessors patch fail!");
Log.Warn(obj);
}
}
IsClient = true;
}
public static void BeforeLeaveGame()
{
IsClient = false;
}
public static bool Guard()
{
return SyncWarning;
}
}
}