Decompiled source of FullClearTimer v0.1.0

Tomatobird.FullClearTimer.dll

Decompiled 12 hours ago
using System;
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.Logging;
using HarmonyLib;
using LC_FullClearTimer.MonoBehaviours;
using LC_FullClearTimer.Network;
using Microsoft.CodeAnalysis;
using TMPro;
using Tomatobird.FullClearTimer.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Tomatobird.FullClearTimer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2df9366fc1c71b4c57065580414a67754d170e57")]
[assembly: AssemblyProduct("LC_FullClearTimer")]
[assembly: AssemblyTitle("Tomatobird.FullClearTimer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
	[CompilerGenerated]
	[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 LC_FullClearTimer
{
	[BepInPlugin("Tomatobird.FullClearTimer", "LC_FullClearTimer", "1.0.0")]
	public class LC_FullClearTimer : BaseUnityPlugin
	{
		internal static HUDTimer? onScreenTimer;

		public static LC_FullClearTimer Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"Tomatobird.FullClearTimer v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: 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_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Tomatobird.FullClearTimer");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Tomatobird.FullClearTimer";

		public const string PLUGIN_NAME = "LC_FullClearTimer";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LC_FullClearTimer.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class AddTimer
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		internal static void Start_Postfix(HUDManager __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_003e: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("FullClearTimer_BaseObject");
			val.transform.parent = __instance.HUDContainer.transform.parent;
			val.transform.position = __instance.HUDContainer.transform.parent.position;
			val.transform.rotation = __instance.HUDContainer.transform.parent.rotation;
			val.transform.localScale = Vector3.one;
			HUDTimer onScreenTimer = val.AddComponent<HUDTimer>();
			LC_FullClearTimer.onScreenTimer = onScreenTimer;
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager))]
	internal class HideTimer
	{
		[HarmonyPatch("OpenQuickMenu")]
		[HarmonyPostfix]
		internal static void OpenQuickMenu_Postfix()
		{
			if ((Object)(object)LC_FullClearTimer.onScreenTimer != (Object)null)
			{
				TextMeshProUGUI val = default(TextMeshProUGUI);
				((Component)((Component)LC_FullClearTimer.onScreenTimer).transform.GetChild(0)).TryGetComponent<TextMeshProUGUI>(ref val);
				((TMP_Text)val).alpha = 0.1f;
			}
		}

		[HarmonyPatch("CloseQuickMenu")]
		[HarmonyPostfix]
		internal static void CloseQuickMenu_Postfix()
		{
			if ((Object)(object)LC_FullClearTimer.onScreenTimer != (Object)null)
			{
				TextMeshProUGUI val = default(TextMeshProUGUI);
				((Component)((Component)LC_FullClearTimer.onScreenTimer).transform.GetChild(0)).TryGetComponent<TextMeshProUGUI>(ref val);
				((TMP_Text)val).alpha = 1f;
			}
		}
	}
	[HarmonyPatch]
	internal class TimerHooks
	{
		[HarmonyPatch(typeof(TimeOfDay), "SetTimeForAdToPlay")]
		[HarmonyPostfix]
		internal static void SetTimeForAdToPlay_Postfix()
		{
			if (NetworkManager.Singleton.IsServer)
			{
				Net.Instance.SetTimerStatusClientRpc(running: true, 0f);
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "SetShipReadyToLand")]
		[HarmonyPostfix]
		internal static void SetShipReadyToLand_Postfix()
		{
			if (NetworkManager.Singleton.IsServer)
			{
				Net.Instance.SetTimerStatusClientRpc(running: false, 0f);
			}
		}

		[HarmonyPatch(typeof(Terminal), "LoadNewNode")]
		[HarmonyPostfix]
		internal static void LoadNewNode_Postfix(Terminal __instance)
		{
			if (NetworkManager.Singleton.IsServer && (StartOfRound.Instance.shipHasLanded || StartOfRound.Instance.shipIsLeaving) && (Object)(object)LC_FullClearTimer.onScreenTimer != (Object)null && __instance.currentText.Contains("There are 0 objects"))
			{
				Net.Instance.SetTimerStatusClientRpc(running: false, LC_FullClearTimer.onScreenTimer.time);
			}
		}
	}
}
namespace LC_FullClearTimer.Network
{
	internal class Net : NetworkBehaviour
	{
		private static GameObject? prefab;

		public static Net Instance { get; private set; }

		internal static void CreateAndRegisterPrefab()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_002b: 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)
			if (!((Object)(object)prefab != (Object)null))
			{
				prefab = new GameObject("Tomatobird.FullClearTimer Prefab");
				GameObject? obj = prefab;
				((Object)obj).hideFlags = (HideFlags)(((Object)obj).hideFlags | 0x3D);
				NetworkObject obj2 = prefab.AddComponent<NetworkObject>();
				FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
				field.SetValue(obj2, GetHash("Tomatobird.FullClearTimer Prefab"));
				prefab.AddComponent<Net>();
				NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(prefab);
				LC_FullClearTimer.Logger.LogInfo((object)"Network object registered.");
			}
		}

		private void Awake()
		{
			Instance = this;
		}

		internal static uint GetHash(string value)
		{
			return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
		}

		internal static void SpawnNetworkHandler()
		{
			if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost)
			{
				GameObject obj = Object.Instantiate<GameObject>(prefab);
				if (obj != null)
				{
					obj.GetComponent<NetworkObject>().Spawn(false);
				}
				LC_FullClearTimer.Logger.LogInfo((object)"Network object spawned.");
			}
		}

		internal static void DespawnNetworkHandler()
		{
			if ((Object)(object)Instance != (Object)null && ((Component)Instance).gameObject.GetComponent<NetworkObject>().IsSpawned && (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost))
			{
				((Component)Instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
				LC_FullClearTimer.Logger.LogInfo((object)"Network object despawned.");
			}
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		public void SetTimerStatusClientRpc(bool running, float currentTime)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1)
			{
				RpcAttributeParams val = default(RpcAttributeParams);
				RpcParams val3 = default(RpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendRpc(247925428u, val3, val, (SendTo)6, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref running, default(ForPrimitives));
				((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref currentTime, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendRpc(ref val2, 247925428u, val3, val, (SendTo)6, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1)
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				if ((Object)(object)LC_FullClearTimer.onScreenTimer != (Object)null)
				{
					LC_FullClearTimer.onScreenTimer.SetTimerStatus(running, currentTime);
				}
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(247925428u, new RpcReceiveHandler(__rpc_handler_247925428), "SetTimerStatusClientRpc");
			((NetworkBehaviour)this).__initializeRpcs();
		}

		private static void __rpc_handler_247925428(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//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_0050: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool running = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref running, default(ForPrimitives));
				float currentTime = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref currentTime, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((Net)(object)target).SetTimerStatusClientRpc(running, currentTime);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "Net";
		}
	}
	[HarmonyPatch]
	internal class NetworkInit
	{
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		[HarmonyPostfix]
		private static void Start_Postfix()
		{
			Net.CreateAndRegisterPrefab();
		}

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPrefix]
		private static void Awake_Prefix()
		{
			Net.SpawnNetworkHandler();
		}

		[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
		[HarmonyPostfix]
		private static void Disconnect_Postfix()
		{
			Net.DespawnNetworkHandler();
		}
	}
}
namespace LC_FullClearTimer.MonoBehaviours
{
	internal class HUDTimer : MonoBehaviour
	{
		private TextMeshProUGUI? timerText;

		public float time;

		public bool running;

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_0103: 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_0131: 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_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI clockNumber = HUDManager.Instance.clockNumber;
			if ((Object)(object)clockNumber == (Object)null)
			{
				LC_FullClearTimer.Logger.LogError((object)"gameclock was null.");
				return;
			}
			GameObject val = new GameObject("CountdownTimerObject");
			val.transform.parent = ((Component)this).gameObject.transform;
			timerText = val.AddComponent<TextMeshProUGUI>();
			TMP_FontAsset font = ((TMP_Text)clockNumber).font;
			Material fontMaterial = ((TMP_Text)clockNumber).fontMaterial;
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)timerText).font = font;
			}
			if ((Object)(object)fontMaterial != (Object)null)
			{
				((TMP_Text)timerText).fontMaterial = fontMaterial;
				((TMP_Text)timerText).fontSharedMaterial = fontMaterial;
			}
			((TMP_Text)timerText).transform.position = ((TMP_Text)clockNumber).transform.position;
			((TMP_Text)timerText).transform.rotation = ((TMP_Text)clockNumber).transform.rotation;
			((TMP_Text)timerText).transform.localScale = Vector3.one;
			((Graphic)timerText).color = ((Graphic)clockNumber).color;
			((TMP_Text)timerText).alignment = ((TMP_Text)clockNumber).alignment;
			((Transform)((TMP_Text)timerText).rectTransform).localEulerAngles = ((Transform)((TMP_Text)clockNumber).rectTransform).localEulerAngles;
			((Transform)((TMP_Text)timerText).rectTransform).localScale = ((Transform)((TMP_Text)clockNumber).rectTransform).localScale;
			((Transform)((TMP_Text)timerText).rectTransform).localPosition = ((Transform)((TMP_Text)clockNumber).rectTransform).localPosition;
			((TMP_Text)timerText).rectTransform.anchorMax = ((TMP_Text)clockNumber).rectTransform.anchorMax;
			((TMP_Text)timerText).rectTransform.anchorMin = ((TMP_Text)clockNumber).rectTransform.anchorMin;
			((TMP_Text)timerText).rectTransform.offsetMin = ((TMP_Text)clockNumber).rectTransform.offsetMin;
			((TMP_Text)timerText).rectTransform.offsetMax = ((TMP_Text)clockNumber).rectTransform.offsetMax;
			((TMP_Text)timerText).enableWordWrapping = false;
			((TMP_Text)timerText).rectTransform.sizeDelta = new Vector2(175f, 50f);
			((TMP_Text)timerText).rectTransform.anchoredPosition = new Vector2(350f, 200f);
			((TMP_Text)timerText).fontSize = ((TMP_Text)clockNumber).fontSize;
			((TMP_Text)timerText).text = "00:00.00";
		}

		private void Start()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)timerText == (Object)null))
			{
				((TMP_Text)timerText).transform.localScale = Vector3.one;
				((TMP_Text)timerText).rectTransform.anchoredPosition = new Vector2(350f, 200f);
			}
		}

		private void Update()
		{
			if (running && (Object)(object)timerText != (Object)null)
			{
				time += Time.deltaTime;
				((TMP_Text)timerText).text = FormatTime(time);
			}
		}

		public void SetTimerStatus(bool running, float time)
		{
			this.time = time;
			this.running = running;
			if ((Object)(object)timerText != (Object)null)
			{
				((TMP_Text)timerText).text = FormatTime(time);
			}
		}

		private string FormatTime(float time)
		{
			int num = (int)(time / 3600f);
			int num2 = (int)(time % 3600f / 60f);
			int num3 = (int)(time % 60f);
			int num4 = (int)(time * 100f % 100f);
			if (num > 0)
			{
				return $"{num:D2}:{num2:D2}:{num3:D2}.{num4:D2}";
			}
			return $"{num2:D2}:{num3:D2}.{num4:D2}";
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace Tomatobird.FullClearTimer.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}