Decompiled source of PinnedNamesEverywhere v1.0.1

PinnedNamesEverywhere.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DysonSphereMods.Shared;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Valoneu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyDescription("Makes pinned star and planet names visible in the normal camera view even at long distances or screen edges.")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+136b45a9c7ce8dcd66a321f5d16f627554f3e64c")]
[assembly: AssemblyProduct("DysonSphereMods")]
[assembly: AssemblyTitle("PinnedNamesEverywhere")]
[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 DysonSphereMods.Shared
{
	public static class Log
	{
		private static ManualLogSource _logger;

		public static void Init(ManualLogSource logger)
		{
			_logger = logger;
		}

		public static void Debug(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogDebug(data);
			}
		}

		public static void Info(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogInfo(data);
			}
		}

		public static void Warning(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogWarning(data);
			}
		}

		public static void Error(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogError(data);
			}
		}

		public static void Fatal(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogFatal(data);
			}
		}

		public static void Message(object data)
		{
			ManualLogSource logger = _logger;
			if (logger != null)
			{
				logger.LogMessage(data);
			}
		}

		public static void LogOnce(string msg, ref bool flag, params object[] args)
		{
			if (flag)
			{
				return;
			}
			flag = true;
			try
			{
				string[] array = ((args == null) ? Array.Empty<string>() : args.Select((object arg) => (arg != null) ? ((!(arg is int) && !(arg is string) && !arg.GetType().IsPrimitive) ? JsonUtility.ToJson(arg) : arg.ToString()) : "null").ToArray());
				object[] args2 = array;
				Info(string.Format(msg, args2));
			}
			catch (Exception arg2)
			{
				Warning($"LogOnce failed to format message: {msg}. Exception: {arg2}");
			}
		}
	}
	public static class MultiplierService
	{
		private static readonly Dictionary<string, float> _multipliers = new Dictionary<string, float>();

		private static bool _isDirty;

		public static event Action OnMultipliersChanged;

		public static void SetMultiplier(string key, float value)
		{
			if (!_multipliers.TryGetValue(key, out var value2) || Math.Abs(value2 - value) > 0.0001f)
			{
				_multipliers[key] = value;
				_isDirty = true;
			}
		}

		public static float GetMultiplier(string key, float defaultValue = 1f)
		{
			if (!_multipliers.TryGetValue(key, out var value))
			{
				return defaultValue;
			}
			return value;
		}

		public static void CommitChanges()
		{
			if (_isDirty)
			{
				_isDirty = false;
				MultiplierService.OnMultipliersChanged?.Invoke();
			}
		}
	}
	public static class TickManager
	{
		private static long _lastSlowTick = -1L;

		private static long _lastLazyTick = -1L;

		private static bool _patched = false;

		public static event Action OnSlowTick;

		public static event Action OnLazyTick;

		public static void Patch(Harmony harmony)
		{
			if (!_patched)
			{
				_patched = true;
				harmony.PatchAll(typeof(TickManager));
			}
		}

		[HarmonyPatch(typeof(GameMain), "Begin")]
		[HarmonyPostfix]
		public static void Init()
		{
			_lastSlowTick = -1L;
			_lastLazyTick = -1L;
		}

		[HarmonyPatch(typeof(GameLogic), "LogicFrame")]
		[HarmonyPostfix]
		public static void GameTick()
		{
			long gameTick = GameMain.gameTick;
			if (gameTick / 60 > _lastSlowTick)
			{
				_lastSlowTick = gameTick / 60;
				TickManager.OnSlowTick?.Invoke();
			}
			if (gameTick / 600 > _lastLazyTick)
			{
				_lastLazyTick = gameTick / 600;
				TickManager.OnLazyTick?.Invoke();
			}
		}
	}
	public abstract class WindowBase
	{
		public Rect WindowRect;

		protected Vector2 ScrollPos;

		private bool _isResizing;

		private Rect _resizeRect = new Rect(0f, 0f, 15f, 15f);

		public Vector2 MinSize = new Vector2(300f, 200f);

		public int WindowId { get; protected set; }

		public string Title { get; set; }

		public bool IsVisible { get; set; }

		protected WindowBase(int windowId, string title, Rect defaultRect)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0049: 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)
			WindowId = windowId;
			Title = title;
			WindowRect = defaultRect;
		}

		public virtual void OnGUI()
		{
			//IL_001d: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//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)
			if (IsVisible)
			{
				GUI.backgroundColor = new Color(0.08f, 0.12f, 0.22f, 0.95f);
				WindowRect = GUILayout.Window(WindowId, WindowRect, new WindowFunction(DrawWindowInternal), Title, Array.Empty<GUILayoutOption>());
				GUI.backgroundColor = Color.white;
				((Rect)(ref WindowRect)).x = Mathf.Clamp(((Rect)(ref WindowRect)).x, 0f - ((Rect)(ref WindowRect)).width + 50f, (float)(Screen.width - 50));
				((Rect)(ref WindowRect)).y = Mathf.Clamp(((Rect)(ref WindowRect)).y, -20f, (float)(Screen.height - 50));
			}
		}

		private void DrawWindowInternal(int id)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00dd: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Invalid comparison between Unknown and I4
			//IL_00f4: 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)
			//IL_0130: Invalid comparison between Unknown and I4
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			DrawWindowHeader();
			ScrollPos = GUILayout.BeginScrollView(ScrollPos, Array.Empty<GUILayoutOption>());
			DrawWindowContent();
			GUILayout.EndScrollView();
			DrawWindowFooter();
			((Rect)(ref _resizeRect)).x = ((Rect)(ref WindowRect)).width - 20f;
			((Rect)(ref _resizeRect)).y = ((Rect)(ref WindowRect)).height - 20f;
			((Rect)(ref _resizeRect)).width = 20f;
			((Rect)(ref _resizeRect)).height = 20f;
			GUI.Label(_resizeRect, "↘", new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				fontSize = 20,
				normal = new GUIStyleState
				{
					textColor = new Color(0.6f, 0.6f, 0.6f, 0.8f)
				}
			});
			Event current = Event.current;
			bool flag = false;
			if ((int)current.type == 0 && ((Rect)(ref _resizeRect)).Contains(current.mousePosition))
			{
				_isResizing = true;
				flag = true;
				current.Use();
			}
			else if ((int)current.type == 1)
			{
				_isResizing = false;
			}
			else if ((int)current.type == 3 && _isResizing)
			{
				ref Rect windowRect = ref WindowRect;
				((Rect)(ref windowRect)).width = ((Rect)(ref windowRect)).width + current.delta.x;
				ref Rect windowRect2 = ref WindowRect;
				((Rect)(ref windowRect2)).height = ((Rect)(ref windowRect2)).height + current.delta.y;
				((Rect)(ref WindowRect)).width = Mathf.Max(MinSize.x, ((Rect)(ref WindowRect)).width);
				((Rect)(ref WindowRect)).height = Mathf.Max(MinSize.y, ((Rect)(ref WindowRect)).height);
				current.Use();
			}
			if ((int)current.type == 0 && !flag)
			{
				GUIUtility.keyboardControl = 0;
			}
			GUI.DragWindow();
		}

		protected virtual void DrawWindowHeader()
		{
		}

		protected abstract void DrawWindowContent();

		protected virtual void DrawWindowFooter()
		{
		}

		public virtual void Toggle()
		{
			IsVisible = !IsVisible;
		}
	}
}
namespace PinnedNamesEverywhere
{
	[BepInPlugin("com.Valoneu.PinnedNamesEverywhere", "PinnedNamesEverywhere", "1.0.1")]
	[BepInProcess("DSPGAME.exe")]
	public class PinnedNamesEverywherePlugin : BaseUnityPlugin
	{
		private class PinnedStateInfo
		{
			public bool IsPinned;

			public int LastCheckFrame;
		}

		public static ConfigEntry<bool> AlwaysShowPinnedNames;

		public static ConfigEntry<bool> AlwaysShowPinnedDistances;

		public static ConfigEntry<float> PinnedNamesMinimumAlpha;

		private static readonly ConditionalWeakTable<UISpaceGuideEntry, PinnedStateInfo> _pinnedCache = new ConditionalWeakTable<UISpaceGuideEntry, PinnedStateInfo>();

		private void Awake()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			AlwaysShowPinnedNames = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AlwaysShowPinnedNames", true, "If true, names of pinned stars/planets will always be visible, even when at the edge of the screen or far away.");
			AlwaysShowPinnedDistances = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AlwaysShowPinnedDistances", false, "If true, distances of pinned stars/planets will also be always visible.");
			PinnedNamesMinimumAlpha = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PinnedNamesMinimumAlpha", 0.8f, "Minimum alpha for pinned names and distances (0.0 to 1.0).");
			Log.Init(((BaseUnityPlugin)this).Logger);
			new Harmony("com.Valoneu.PinnedNamesEverywhere").PatchAll(typeof(PinnedNamesEverywherePlugin));
			Log.Info("PinnedNamesEverywhere v1.0.1 loaded!");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UISpaceGuideEntry), "_OnLateUpdate")]
		public static void UISpaceGuideEntry__OnLateUpdate_Postfix(UISpaceGuideEntry __instance)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			if (!AlwaysShowPinnedNames.Value || (int)UIGame.viewMode == 4 || (int)UIGame.viewMode == 3)
			{
				return;
			}
			int frameCount = Time.frameCount;
			if (!_pinnedCache.TryGetValue(__instance, out var value) || frameCount - value.LastCheckFrame > 60)
			{
				if (value == null)
				{
					value = new PinnedStateInfo();
					_pinnedCache.Add(__instance, value);
				}
				value.IsPinned = CheckIfPinned(__instance);
				value.LastCheckFrame = frameCount;
			}
			if (!value.IsPinned)
			{
				return;
			}
			if (!((Behaviour)__instance.nameText).enabled)
			{
				((Behaviour)__instance.nameText).enabled = true;
			}
			if (((Behaviour)__instance.distText).enabled != AlwaysShowPinnedDistances.Value)
			{
				((Behaviour)__instance.distText).enabled = AlwaysShowPinnedDistances.Value;
			}
			float value2 = PinnedNamesMinimumAlpha.Value;
			if (!(value2 > 0f))
			{
				return;
			}
			Color color = ((Graphic)__instance.nameText).color;
			if (color.a < value2)
			{
				color.a = value2;
				((Graphic)__instance.nameText).color = color;
			}
			if (((Behaviour)__instance.distText).enabled)
			{
				Color color2 = ((Graphic)__instance.distText).color;
				if (color2.a < value2)
				{
					color2.a = value2;
					((Graphic)__instance.distText).color = color2;
				}
			}
		}

		private static bool CheckIfPinned(UISpaceGuideEntry entry)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_0047: Expected I4, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Invalid comparison between Unknown and I4
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Invalid comparison between Unknown and I4
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Invalid comparison between Unknown and I4
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Invalid comparison between Unknown and I4
			GameHistoryData val = entry.parent?.history;
			if (val == null)
			{
				return false;
			}
			ESpaceGuideType guideType = entry.guideType;
			switch (guideType - 1)
			{
			case 0:
				return (int)val.GetStarPin(entry.objId) == 1;
			case 1:
				return (int)val.GetPlanetPin(entry.objId) == 1;
			case 5:
				return (int)val.GetHivePin(entry.objId - 1000000) == 1;
			case 4:
			case 7:
				return (int)val.GetMessagePin(entry.objId) == 1;
			default:
				return false;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UISpaceGuide), "ClipEntryPool")]
		public static void UISpaceGuide_ClipEntryPool_Prefix(UISpaceGuide __instance, ref int _guidecnt, bool all)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			//IL_003f: 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_0046: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Invalid comparison between Unknown and I4
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Invalid comparison between Unknown and I4
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Invalid comparison between Unknown and I4
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: 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_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Invalid comparison between Unknown and I4
			//IL_020b: 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_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			if (all || !AlwaysShowPinnedNames.Value || (int)UIGame.viewMode == 4 || (int)UIGame.viewMode == 3)
			{
				return;
			}
			GameHistoryData val = GameMain.data?.history;
			if (val == null || __instance.galaxy == null)
			{
				return;
			}
			VectorLF3 relPos = __instance.relPos;
			Quaternion relRot = __instance.relRot;
			MethodInfo method = typeof(UISpaceGuide).GetMethod("SetEntry", BindingFlags.Instance | BindingFlags.NonPublic);
			HashSet<int> hashSet = new HashSet<int>();
			HashSet<int> hashSet2 = new HashSet<int>();
			for (int i = 0; i < _guidecnt; i++)
			{
				if (__instance.entryPool == null)
				{
					break;
				}
				if (i >= __instance.entryPool.Count)
				{
					break;
				}
				UISpaceGuideEntry val2 = __instance.entryPool[i];
				if ((int)val2.guideType == 1)
				{
					hashSet.Add(val2.objId);
				}
				else if ((int)val2.guideType == 2)
				{
					hashSet2.Add(val2.objId);
				}
			}
			for (int j = 1; j <= __instance.galaxy.starCount; j++)
			{
				if ((int)val.GetStarPin(j) == 1 && !hashSet.Contains(j))
				{
					StarData val3 = __instance.galaxy.StarById(j);
					if (val3 != null)
					{
						Vector3 val4 = VectorLF3.op_Implicit(Maths.QInvRotateLF(relRot, val3.uPosition - relPos));
						object[] array = new object[6]
						{
							_guidecnt,
							(object)(ESpaceGuideType)1,
							j,
							0,
							val4,
							0f
						};
						method?.Invoke(__instance, array);
						_guidecnt = (int)array[0];
					}
				}
			}
			for (int k = 0; k < __instance.galaxy.starCount; k++)
			{
				StarData val5 = __instance.galaxy.stars[k];
				if (val5 == null)
				{
					continue;
				}
				for (int l = 0; l < val5.planetCount; l++)
				{
					PlanetData val6 = val5.planets[l];
					if (val6 != null && val6.id != 0 && (int)val.GetPlanetPin(val6.id) == 1 && !hashSet2.Contains(val6.id))
					{
						Vector3 val7 = VectorLF3.op_Implicit(Maths.QInvRotateLF(relRot, val6.uPosition - relPos));
						object[] array2 = new object[6]
						{
							_guidecnt,
							(object)(ESpaceGuideType)2,
							val6.id,
							0,
							val7,
							val6.realRadius
						};
						method?.Invoke(__instance, array2);
						_guidecnt = (int)array2[0];
					}
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.Valoneu.PinnedNamesEverywhere";

		public const string PLUGIN_NAME = "PinnedNamesEverywhere";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}