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 BepInEx;
using BepInEx.Logging;
using BuildingPosViewer.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BuildingPosViewer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("DSP MOD - BuildingPosViewer")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+b6e8022085a8ef490f48614600f1191f79e70020")]
[assembly: AssemblyProduct("BuildingPosViewer")]
[assembly: AssemblyTitle("BuildingPosViewer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BuildingPosViewer
{
[BepInPlugin("org.fyyy.buildingposviewer", "BuildingPosViewer", "1.0.1")]
public class BuildingPosViewer : BaseUnityPlugin
{
public static readonly ManualLogSource Logger = Logger.CreateLogSource("BuildingPosViewer");
private Harmony _harmony;
private void Awake()
{
_harmony = Harmony.CreateAndPatchAll(typeof(WindowPatches), (string)null);
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
PosDisplayHelper.Cleanup();
}
}
public static class PosDisplayHelper
{
private class CopyButtons
{
public GameObject root;
public Button btnX;
public Button btnY;
public Button btnZ;
public string valX;
public string valY;
public string valZ;
}
private static readonly Dictionary<Text, CopyButtons> ButtonMap = new Dictionary<Text, CopyButtons>();
public static void Show(Text titleText, PlanetFactory factory, int entityId)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)titleText == (Object)null) && factory != null && entityId > 0)
{
Vector3 pos = factory.entityPool[entityId].pos;
Vector3 normalized = ((Vector3)(ref pos)).normalized;
PlanetData planet = factory.planet;
PlanetAuxData aux = planet.aux;
int valueOrDefault = ((aux == null) ? null : aux.activeGrid?.segment).GetValueOrDefault(200);
float latitudeRadPerGrid = BlueprintUtils.GetLatitudeRadPerGrid(valueOrDefault);
float longitudeRadPerGrid = BlueprintUtils.GetLongitudeRadPerGrid(BlueprintUtils.GetLongitudeSegmentCount(normalized, valueOrDefault), valueOrDefault);
float f = BlueprintUtils.GetLongitudeRad(normalized) / longitudeRadPerGrid;
float f2 = BlueprintUtils.GetLatitudeRad(normalized) / latitudeRadPerGrid;
float num = (((Vector3)(ref pos)).magnitude - planet.realRadius - 0.2f) / 1.3333333f;
if (!ButtonMap.TryGetValue(titleText, out var value) || value == null || (Object)(object)value.root == (Object)null)
{
value = CreateButtons(titleText);
ButtonMap[titleText] = value;
}
value.valX = Fmt(f);
value.valY = Fmt(f2);
value.valZ = Fmt(num);
((Component)value.btnZ).gameObject.SetActive(!(num < 0.001f) || !(num > -0.001f));
value.root.SetActive(true);
value.root.GetComponent<RectTransform>().anchoredPosition = new Vector2(titleText.preferredWidth + 8f, 0f);
}
}
public static void Cleanup()
{
foreach (KeyValuePair<Text, CopyButtons> item in ButtonMap)
{
if ((Object)(object)item.Value?.root != (Object)null)
{
Object.Destroy((Object)(object)item.Value.root);
}
}
ButtonMap.Clear();
}
private static string Fmt(float f)
{
return f.ToString("F6").TrimEnd(new char[1] { '0' }).TrimEnd(new char[1] { '.' });
}
private static CopyButtons CreateButtons(Text titleText)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: 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_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Expected O, but got Unknown
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
_ = ((Graphic)titleText).rectTransform;
GameObject val = new GameObject("CopyBtns");
val.transform.SetParent(((Component)titleText).transform, false);
RectTransform obj = val.AddComponent<RectTransform>();
obj.anchorMin = new Vector2(0f, 0.5f);
obj.anchorMax = new Vector2(0f, 0.5f);
obj.pivot = new Vector2(0f, 0.5f);
obj.sizeDelta = new Vector2(80f, 20f);
HorizontalLayoutGroup obj2 = val.AddComponent<HorizontalLayoutGroup>();
((HorizontalOrVerticalLayoutGroup)obj2).spacing = 3f;
((LayoutGroup)obj2).childAlignment = (TextAnchor)3;
((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
((LayoutGroup)obj2).padding = new RectOffset(0, 0, 0, 0);
CopyButtons copyButtons = new CopyButtons
{
root = val
};
copyButtons.btnX = MakeBtn(val.transform, titleText.font, "x", new Color(1f, 0.7f, 0.7f), copyButtons, 0);
copyButtons.btnY = MakeBtn(val.transform, titleText.font, "y", new Color(0.7f, 1f, 0.7f), copyButtons, 1);
copyButtons.btnZ = MakeBtn(val.transform, titleText.font, "z", new Color(0.7f, 0.7f, 1f), copyButtons, 2);
return copyButtons;
}
private static Button MakeBtn(Transform parent, Font font, string label, Color color, CopyButtons btns, int axis)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: 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_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Expected O, but got Unknown
GameObject val = new GameObject("Btn_" + label);
val.transform.SetParent(parent, false);
Image val2 = val.AddComponent<Image>();
((Graphic)val2).color = new Color(0.3f, 0.3f, 0.3f, 0.8f);
LayoutElement obj = val.AddComponent<LayoutElement>();
obj.preferredWidth = 20f;
obj.preferredHeight = 18f;
GameObject val3 = new GameObject("Label");
val3.transform.SetParent(val.transform, false);
Text obj2 = val3.AddComponent<Text>();
obj2.font = font;
obj2.text = label;
obj2.fontSize = 12;
((Graphic)obj2).color = color;
obj2.alignment = (TextAnchor)4;
((Graphic)obj2).raycastTarget = false;
RectTransform rectTransform = ((Graphic)obj2).rectTransform;
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
Button obj3 = val.AddComponent<Button>();
((Selectable)obj3).targetGraphic = (Graphic)(object)val2;
ColorBlock colors = ((Selectable)obj3).colors;
((ColorBlock)(ref colors)).normalColor = new Color(0.3f, 0.3f, 0.3f, 0.8f);
((ColorBlock)(ref colors)).highlightedColor = new Color(0.5f, 0.5f, 0.5f, 0.9f);
((ColorBlock)(ref colors)).pressedColor = new Color(0.6f, 0.6f, 0.6f, 1f);
((Selectable)obj3).colors = colors;
((UnityEvent)obj3.onClick).AddListener((UnityAction)delegate
{
GUIUtility.systemCopyBuffer = axis switch
{
0 => btns.valX,
1 => btns.valY,
_ => btns.valZ,
};
});
return obj3;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "org.fyyy.buildingposviewer";
public const string PLUGIN_NAME = "BuildingPosViewer";
public const string PLUGIN_VERSION = "1.0.1";
}
}
namespace BuildingPosViewer.Patches
{
public static class WindowPatches
{
private static void ShowPos(Text titleText, PlanetFactory factory, int entityId)
{
if (!((Object)(object)titleText == (Object)null) && factory != null && entityId > 0)
{
PosDisplayHelper.Show(titleText, factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIAssemblerWindow), "_OnUpdate")]
public static void UIAssemblerWindow_OnUpdate(UIAssemblerWindow __instance)
{
if (__instance.assemblerId != 0 && __instance.factory != null)
{
int entityId = __instance.factorySystem.assemblerPool[__instance.assemblerId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIMinerWindow), "_OnUpdate")]
public static void UIMinerWindow_OnUpdate(UIMinerWindow __instance)
{
if (__instance.minerId != 0 && __instance.factory != null)
{
int entityId = __instance.factorySystem.minerPool[__instance.minerId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UILabWindow), "_OnUpdate")]
public static void UILabWindow_OnUpdate(UILabWindow __instance)
{
if (__instance.labId != 0 && __instance.factory != null)
{
int entityId = __instance.factorySystem.labPool[__instance.labId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIStorageWindow), "_OnUpdate")]
public static void UIStorageWindow_OnUpdate(UIStorageWindow __instance)
{
if (__instance.storageId != 0 && __instance.factory != null)
{
int entityId = __instance.factoryStorage.storagePool[__instance.storageId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UITankWindow), "_OnUpdate")]
public static void UITankWindow_OnUpdate(UITankWindow __instance)
{
if (__instance.tankId != 0 && __instance.factory != null)
{
int entityId = __instance.storage.tankPool[__instance.tankId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIFractionatorWindow), "_OnUpdate")]
public static void UIFractionatorWindow_OnUpdate(UIFractionatorWindow __instance)
{
if (__instance.fractionatorId != 0 && __instance.factory != null)
{
int entityId = __instance.factorySystem.fractionatorPool[__instance.fractionatorId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIEjectorWindow), "_OnUpdate")]
public static void UIEjectorWindow_OnUpdate(UIEjectorWindow __instance)
{
if (__instance.ejectorId != 0 && __instance.factory != null)
{
int entityId = __instance.factorySystem.ejectorPool[__instance.ejectorId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UISiloWindow), "_OnUpdate")]
public static void UISiloWindow_OnUpdate(UISiloWindow __instance)
{
if (__instance.siloId != 0 && __instance.factory != null)
{
int entityId = __instance.factorySystem.siloPool[__instance.siloId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIInserterWindow), "_OnUpdate")]
public static void UIInserterWindow_OnUpdate(UIInserterWindow __instance)
{
if (__instance.inserterId != 0 && __instance.factory != null)
{
int entityId = __instance.factorySystem.inserterPool[__instance.inserterId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIBeltWindow), "_OnUpdate")]
public static void UIBeltWindow_OnUpdate(UIBeltWindow __instance)
{
if (__instance.beltId != 0 && __instance.factory != null)
{
int entityId = __instance.traffic.beltPool[__instance.beltId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIAccumulatorWindow), "_OnUpdate")]
public static void UIAccumulatorWindow_OnUpdate(UIAccumulatorWindow __instance)
{
if (__instance.accId != 0 && __instance.factory != null)
{
int entityId = __instance.powerSystem.accPool[__instance.accId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIStationWindow), "_OnUpdate")]
public static void UIStationWindow_OnUpdate(UIStationWindow __instance)
{
if (__instance.stationId != 0 && __instance.factory != null)
{
int entityId = __instance.transport.stationPool[__instance.stationId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIDispenserWindow), "_OnUpdate")]
public static void UIDispenserWindow_OnUpdate(UIDispenserWindow __instance)
{
if (__instance.dispenserId != 0 && __instance.factory != null)
{
int entityId = __instance.transport.dispenserPool[__instance.dispenserId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIBattleBaseWindow), "_OnUpdate")]
public static void UIBattleBaseWindow_OnUpdate(UIBattleBaseWindow __instance)
{
if (__instance.battleBaseId != 0 && __instance.factory != null)
{
int entityId = __instance.defenseSystem.battleBases.buffer[__instance.battleBaseId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UITurretWindow), "_OnUpdate")]
public static void UITurretWindow_OnUpdate(UITurretWindow __instance)
{
if (__instance.turretId != 0 && __instance.factory != null)
{
ref TurretComponent reference = ref __instance.defenseSystem.turrets.buffer[__instance.turretId];
ShowPos(__instance.titleText, __instance.factory, reference.entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIPowerGeneratorWindow), "_OnUpdate")]
public static void UIPowerGeneratorWindow_OnUpdate(UIPowerGeneratorWindow __instance)
{
if (__instance.generatorId != 0 && __instance.factory != null)
{
int entityId = __instance.powerSystem.genPool[__instance.generatorId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIPowerNodeWindow), "_OnUpdate")]
public static void UIPowerNodeWindow_OnUpdate(UIPowerNodeWindow __instance)
{
if (__instance.nodeId != 0 && __instance.factory != null)
{
int entityId = __instance.powerSystem.nodePool[__instance.nodeId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIPowerExchangerWindow), "_OnUpdate")]
public static void UIPowerExchangerWindow_OnUpdate(UIPowerExchangerWindow __instance)
{
if (__instance.exchangerId != 0 && __instance.factory != null)
{
int entityId = __instance.powerSystem.excPool[__instance.exchangerId].entityId;
ShowPos(__instance.titleText, __instance.factory, entityId);
}
}
}
}