Decompiled source of TerminalPingFix v0.1.0

TerminalPingFix.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using CellMenu;
using GTFO.API.Utilities;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("TerminalPingFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TerminalPingFix")]
[assembly: AssemblyTitle("TerminalPingFix")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Andocas.TerminalPingFix
{
	internal static class Config
	{
		internal static readonly ConfigEntry<float> FadeOutDelay;

		internal static readonly ConfigEntry<float> FadeOutDuration;

		static Config()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "TerminalPingFix.cfg"), true);
			FadeOutDelay = val.Bind<float>("Fade-Out", "Fade-Out Delay", 0f, "Seconds until a terminal ping starts to fade out");
			FadeOutDuration = val.Bind<float>("Fade-Out", "Fade-Out Duration", 4f, "After Fade-Out Delay, seconds for a terminal ping to finish fading out");
			if (((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("dev.gtfomodding.gtfo-api"))
			{
				Utils.LogInfo("Creating LiveEdit Listener.");
				SetupLiveEditListener(val);
			}
			else
			{
				Utils.LogInfo("GTFO-API is not loaded. Proceeding without LiveEdit.");
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void SetupLiveEditListener(ConfigFile configFile)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			ConfigFile configFile2 = configFile;
			LiveEditListener val = LiveEdit.CreateListener(Path.GetDirectoryName(configFile2.ConfigFilePath), Path.GetFileName(configFile2.ConfigFilePath), false);
			val.FileChanged += (LiveEditEventHandler)delegate
			{
				configFile2.Reload();
			};
		}
	}
	internal static class Patches
	{
		[CompilerGenerated]
		private sealed class <FadeMarkerAfterDelay>d__3 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public NavMarker marker;

			public float delay;

			public float duration;

			private float <timer>5__1;

			private float <alpha>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <FadeMarkerAfterDelay>d__3(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<timer>5__1 = 0f;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<timer>5__1 <= delay + duration)
				{
					<alpha>5__2 = Mathf.Clamp01(1f - (<timer>5__1 - delay) / duration);
					marker.SetAlpha(<alpha>5__2);
					<timer>5__1 += Clock.Delta;
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				marker.SetVisible(false);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static readonly List<NavMarker> TerminalNavMarkers = new List<NavMarker>();

		[HarmonyPatch(typeof(SyncedNavMarkerWrapper), "OnStateChange")]
		[HarmonyPrefix]
		private static void SyncedNavMarkerWrapper__OnStateChange__Prefix(SyncedNavMarkerWrapper __instance, ref bool __runOriginal, pNavMarkerState oldState, pNavMarkerState newState, bool isDropinState)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			if ((int)newState.style == 15)
			{
				__runOriginal = false;
			}
		}

		[HarmonyPatch(typeof(LG_GenericTerminalItem), "PlayPing")]
		[HarmonyPrefix]
		private static void LG_GenericTerminalItem__PlayPing__Prefix(LG_GenericTerminalItem __instance)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			foreach (NavMarker terminalNavMarker in TerminalNavMarkers)
			{
				if (terminalNavMarker.m_trackingObj.transform.position == __instance.LocatorBeaconPosition)
				{
					terminalNavMarker.SetVisible(false);
					if (terminalNavMarker.m_pingRoutine != null)
					{
						CoroutineManager.StopCoroutine(terminalNavMarker.m_pingRoutine);
					}
					if (terminalNavMarker.m_fadeRoutine != null)
					{
						CoroutineManager.StopCoroutine(terminalNavMarker.m_fadeRoutine);
					}
				}
			}
			NavMarker val = null;
			foreach (NavMarker terminalNavMarker2 in TerminalNavMarkers)
			{
				if (!terminalNavMarker2.IsVisible)
				{
					val = terminalNavMarker2;
					break;
				}
			}
			if (val == null)
			{
				val = GuiManager.NavMarkerLayer.PrepareGenericMarker(new GameObject());
				val.PersistentBetweenRestarts = true;
				val.SetTitle("Terminal Ping");
				val.SetIconScale(0.4f);
				val.SetAlpha(0.4f);
				TerminalNavMarkers.Add(val);
			}
			val.m_trackingObj.transform.position = __instance.LocatorBeaconPosition;
			val.SetStyle((eNavMarkerStyle)15);
			val.SetVisible(true);
			val.Ping(Config.FadeOutDelay.Value + Config.FadeOutDuration.Value);
			val.m_fadeRoutine = CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(FadeMarkerAfterDelay(val, Config.FadeOutDelay.Value, Config.FadeOutDuration.Value)), (Action)null);
			NavMarkerComponent pingSubObj = val.m_pingSubObj;
			NavMarkerPing val2 = ((pingSubObj != null) ? ((Il2CppObjectBase)pingSubObj).TryCast<NavMarkerPing>() : null);
			if (val2 != null)
			{
				val2.m_timeNextPing = 0f;
			}
		}

		[IteratorStateMachine(typeof(<FadeMarkerAfterDelay>d__3))]
		private static IEnumerator FadeMarkerAfterDelay(NavMarker marker, float delay, float duration)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FadeMarkerAfterDelay>d__3(0)
			{
				marker = marker,
				delay = delay,
				duration = duration
			};
		}
	}
	internal static class PluginInfo
	{
		public const string GUID = "Andocas.TerminalPingFix";

		public const string NAME = "TerminalPingFix";

		public const string VERSION = "0.1.0";
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Andocas.TerminalPingFix", "TerminalPingFix", "0.1.0")]
	internal class Plugin : BasePlugin
	{
		public override void Load()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Utils.LogInfo("Andocas.TerminalPingFix is loading...");
			Harmony val = new Harmony("Andocas.TerminalPingFix");
			val.PatchAll(typeof(Patches));
			_ = Config.FadeOutDelay;
			Utils.LogInfo("Andocas.TerminalPingFix is loaded");
		}
	}
	internal static class Utils
	{
		private static readonly ManualLogSource logger = Logger.CreateLogSource("Andocas.TerminalPingFix");

		public static void LogInfo(object? o)
		{
			logger.LogInfo((object)GetMessage(o));
		}

		public static void LogError(object? o)
		{
			logger.LogError((object)GetMessage(o));
		}

		private static string GetMessage(object? o)
		{
			if (o == null)
			{
				return "No string representation for <null>";
			}
			return o.ToString() ?? $"No string representation for <{o.GetType()}>";
		}

		public static void SendLocalMessage(string text)
		{
			LogInfo("SendLocalMessage: " + text);
			GuiManager.PlayerLayer.m_gameEventLog.AddLogItem(text, (eGameEventChatLogType)2);
			CM_PageLoadout.Current.m_gameEventLog.AddLogItem(text, (eGameEventChatLogType)2);
		}

		public static void SendChatMessage(string text)
		{
			LogInfo("SendChatMessage: " + text);
			string text2 = "<#ff0>";
			int num = 50 - text2.Length;
			while (text.Length > num)
			{
				PlayerChatManager.WantToSentTextMessage(PlayerManager.GetLocalPlayerAgent(), text2 + text.Substring(0, num).Trim(), (PlayerAgent)null);
				text = text.Substring(num).Trim();
			}
			PlayerChatManager.WantToSentTextMessage(PlayerManager.GetLocalPlayerAgent(), text2 + text, (PlayerAgent)null);
		}
	}
}