Decompiled source of GameTimer v1.0.1

GameTimer.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Extensions;
using CSync.Lib;
using GameTimer.NetcodePatcher;
using GameTimerPlugin.GameTimerObject;
using GameTimerPlugin.Patches;
using HarmonyLib;
using LethalModDataLib.Attributes;
using LethalModDataLib.Features;
using LethalModDataLib.Helpers;
using TMPro;
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: AssemblyTitle("GameTimer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GameTimer")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("104678a0-040f-4243-b51c-da828b9e5090")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace GameTimerPlugin
{
	[BepInPlugin("ta-xao.gametimer", "GameTimer", "1.0.1")]
	[BepInDependency("com.sigurd.csync", "5.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class GameTimerPlugin : BaseUnityPlugin
	{
		public const string modGUID = "ta-xao.gametimer";

		private const string modName = "GameTimer";

		private const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("ta-xao.gametimer");

		private static GameTimerPlugin Instance;

		internal static ManualLogSource mls;

		internal static ConfigEntry<bool> EnableTimer;

		internal static ConfigEntry<bool> SaveElapsedTime;

		internal static ConfigEntry<bool> DisplayHours;

		internal static ConfigEntry<bool> DisplayMinutes;

		internal static ConfigEntry<bool> DisplaySeconds;

		internal static ConfigEntry<bool> DisplayMilliseconds;

		internal static ConfigEntry<bool> DisplayAlways;

		internal static ConfigEntry<float> DisplayColorR;

		internal static ConfigEntry<float> DisplayColorG;

		internal static ConfigEntry<float> DisplayColorB;

		internal static ConfigEntry<int> DisplayPositionX;

		internal static ConfigEntry<int> DisplayPositionY;

		internal static ConfigEntry<bool> ResetNow;

		internal static ConfigEntry<float> SyncInterval;

		internal static ConfigEntry<bool> DebugV;

		internal static AssetBundle Bundle;

		internal static ConfigSyncer SConfig;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("ta-xao.gametimer");
			mls.LogInfo((object)"[GameTimer] 1.0.1 is loaded!");
			EnableTimer = ((BaseUnityPlugin)this).Config.Bind<bool>("General settings", "Enable timer", true, "Enable or disable the game timer. Disabling it while it's running will pause the timer.");
			SaveElapsedTime = ((BaseUnityPlugin)this).Config.Bind<bool>("General settings", "Save elapsed time", true, "Save the elapsed time for this specific save file with each automatic game save (each time the ship enters orbit). \nDisabling will also reset the time elapsed in this save file upon reloading the save file.");
			DisplayHours = ((BaseUnityPlugin)this).Config.Bind<bool>("Time display settings", "Display hours", true, "Display hours in the timer.");
			DisplayMinutes = ((BaseUnityPlugin)this).Config.Bind<bool>("Time display settings", "Display minutes", true, "Display minutes in the timer.");
			DisplaySeconds = ((BaseUnityPlugin)this).Config.Bind<bool>("Time display settings", "Display seconds", true, "Display seconds in the timer.");
			DisplayMilliseconds = ((BaseUnityPlugin)this).Config.Bind<bool>("Time display settings", "Display milliseconds", true, "Display milliseconds in the timer.");
			DisplayAlways = ((BaseUnityPlugin)this).Config.Bind<bool>("Display settings", "Display always", true, "If true, tries to always displays the timer, no matter the circumstance. \nIf false, the timer will be displayed whenever the weight of the items you're carrying is (so mostly while you're alive).");
			DisplayPositionX = ((BaseUnityPlugin)this).Config.Bind<int>("Display settings", "Display position X", 0, "X position of the timer on the UI.");
			DisplayPositionY = ((BaseUnityPlugin)this).Config.Bind<int>("Display settings", "Display position Y", 220, "Y position of the timer on the UI.");
			DisplayColorR = ((BaseUnityPlugin)this).Config.Bind<float>("Display settings", "Display color R", 255f, "Red component of the timer text color. \nRange: 0-255.");
			DisplayColorG = ((BaseUnityPlugin)this).Config.Bind<float>("Display settings", "Display color G", 255f, "Green component of the timer text color. \nRange: 0-255.");
			DisplayColorB = ((BaseUnityPlugin)this).Config.Bind<float>("Display settings", "Display color B", 255f, "Blue component of the timer text color. \nRange: 0-255.");
			SConfig = new ConfigSyncer(((BaseUnityPlugin)this).Config);
			ResetNow = ((BaseUnityPlugin)this).Config.Bind<bool>("Reset", "Reset timer now", false, "Resets the timer upon being set to true and applied. Will immediately jump back to being false once the reset was applied.");
			SyncInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Networking", "Syncing interval", 10f, "How often the host syncs their elapsed time with the clients in seconds. Minimum 1.");
			DebugV = ((BaseUnityPlugin)this).Config.Bind<bool>("Debugging", "Verbose debugging messages", false, "Setting this to true will print more information about the state of the timer to the console.");
			harmony.PatchAll(typeof(HUDManagerPatch));
			harmony.PatchAll(typeof(RoundManagerPatch));
			harmony.PatchAll(typeof(QuickMenuManagerPatch));
			harmony.PatchAll(typeof(NetworkObjectManager));
			harmony.PatchAll(typeof(GameNetworkManagerPatch));
			mls = ((BaseUnityPlugin)this).Logger;
			string location = ((BaseUnityPlugin)Instance).Info.Location;
			location = location.TrimEnd("GameTimer.dll".ToCharArray());
			mls.LogInfo((object)("[GameTimer] Trying to load " + location + "gtnetworkhandler."));
			Bundle = AssetBundle.LoadFromFile(location + "gtnetworkhandler");
			if ((Object)(object)Bundle != (Object)null)
			{
				mls.LogInfo((object)"[GameTimer] Asset bundle loaded successfully.");
			}
			else
			{
				mls.LogError((object)"[GameTimer] Failed to load asset bundle.");
			}
			NetcodePatcher();
			mls.LogInfo((object)"[GameTimer] Initialized successfully.");
		}

		private static void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public class ConfigSyncer : SyncedConfig2<ConfigSyncer>
	{
		[SyncedEntryField]
		public SyncedEntry<float> PauseTimerAtTime;

		[SyncedEntryField]
		public SyncedEntry<int> PauseTimerAtQuota;

		[SyncedEntryField]
		public SyncedEntry<bool> PauseTimerInOrbit;

		public ConfigSyncer(ConfigFile cfg)
			: base("ta-xao.gametimer")
		{
			PauseTimerAtTime = SyncedBindingExtensions.BindSyncedEntry<float>(cfg, "Pause", "Pause timer at this time", 0f, "Timer will be paused at this minute mark. \nSet to 0 to disable pausing.");
			PauseTimerAtQuota = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Pause", "Pause timer at this quota", 0, "Timer will be paused at this quota mark. \nSet to 0 to disable pausing.");
			PauseTimerInOrbit = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Pause", "Pause while in orbit", false, "Timer will be paused while in orbit.");
			ConfigManager.Register<ConfigSyncer>((SyncedConfig2<ConfigSyncer>)this);
		}
	}
}
namespace GameTimerPlugin.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	public class HUDManagerPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void AppendUpdateLogic()
		{
			global::GameTimerPlugin.GameTimerObject.GameTimer.UpdateLogic();
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch("GenerateNewLevelClientRpc")]
		[HarmonyPostfix]
		private static void BeginTimeCalcWithNLCR()
		{
			if (GameTimerPlugin.DebugV.Value)
			{
				GameTimerPlugin.mls.LogInfo((object)"Attempting to initialize time calculation with GNLCR.");
			}
			BeginTimeCalc();
		}

		[HarmonyPatch("GenerateNewFloor")]
		[HarmonyPostfix]
		private static void BeginTimeCalcWithGNF()
		{
			if (GameTimerPlugin.DebugV.Value)
			{
				GameTimerPlugin.mls.LogInfo((object)"Attempting to initialize time calculation with GNF.");
			}
			BeginTimeCalc();
		}

		private static void BeginTimeCalc()
		{
			if (!global::GameTimerPlugin.GameTimerObject.GameTimer.StartTimeInit && !global::GameTimerPlugin.GameTimerObject.GameTimer.ClientFlag)
			{
				global::GameTimerPlugin.GameTimerObject.GameTimer.InitializeTimeCalculation();
				if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
				{
					global::GameTimerPlugin.GameTimerObject.GameTimer.ClientFlag = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager))]
	internal class QuickMenuManagerPatch
	{
		[HarmonyPatch("LeaveGameConfirm")]
		[HarmonyPostfix]
		private static void CleanupOnGameLeave()
		{
			if (GameTimerPlugin.DebugV.Value)
			{
				GameTimerPlugin.mls.LogInfo((object)"Attempting clean up on game leave.");
			}
			global::GameTimerPlugin.GameTimerObject.GameTimer.CleanUp();
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatch
	{
		[HarmonyPatch("Disconnect")]
		[HarmonyPostfix]
		private static void CleanupOnDisconnect()
		{
			if (GameNetworkManager.Instance.isDisconnecting)
			{
				if (GameTimerPlugin.DebugV.Value)
				{
					GameTimerPlugin.mls.LogInfo((object)"Attempting clean up on disconnect.");
				}
				global::GameTimerPlugin.GameTimerObject.GameTimer.CleanUp();
			}
		}
	}
	[HarmonyPatch]
	public class NetworkObjectManager
	{
		private static GameObject networkPrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void Init()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			GameTimerPlugin.mls.LogInfo((object)"Attempting to register network prefab.");
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				networkPrefab = (GameObject)GameTimerPlugin.Bundle.LoadAsset("GTNetworkHandler");
				networkPrefab.AddComponent<GTNetworkHandler>();
				NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void SpawnNetworkHandler()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			GameTimerPlugin.mls.LogInfo((object)"Attempting to spawn network handler.");
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(networkPrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(true);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
		private static void SubscribeToHandler()
		{
			GameTimerPlugin.mls.LogInfo((object)"Attempting to subscribe to network handler.");
			GTNetworkHandler.OnElapsedTimeReceived += ReceivedEventFromServer;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
		private static void UnsubscribeFromHandler()
		{
			GameTimerPlugin.mls.LogInfo((object)"Attempting to unsubscribe from network handler.");
			GTNetworkHandler.OnElapsedTimeReceived -= ReceivedEventFromServer;
		}

		private static void ReceivedEventFromServer(float elapsedTime)
		{
			//IL_0045: 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)
			if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
			{
				if (GameTimerPlugin.DebugV.Value)
				{
					GameTimerPlugin.mls.LogInfo((object)"Received updated timer values from server.");
				}
				NetworkTime serverTime = global::GameTimerPlugin.GameTimerObject.GameTimer.GTNetworkManager.ServerTime;
				global::GameTimerPlugin.GameTimerObject.GameTimer.StartTime = (float)((NetworkTime)(ref serverTime)).Time - elapsedTime;
			}
		}

		public static void SendEventToClients(float elapsedTime)
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				if (GameTimerPlugin.DebugV.Value)
				{
					GameTimerPlugin.mls.LogInfo((object)"Sending updated timer values to clients.");
				}
				GTNetworkHandler.Instance.ReceiveElapsedTimeClientRpc(elapsedTime);
			}
		}
	}
}
namespace GameTimerPlugin.GameTimerObject
{
	public class GameTimer
	{
		public static GameTimer Instance;

		private GameObject TimerObject;

		private static HUDManager GTHudManager;

		private static TextMeshProUGUI TimerText;

		public static NetworkManager GTNetworkManager;

		public static float StartTime = 0f;

		public static bool StartTimeInit = false;

		private static int Hours = 0;

		private static int Minutes = 0;

		private static int Seconds = 0;

		private static int Milliseconds = 0;

		private static List<int> TimeParts;

		private static float PastElapsedTimeOffset = 0f;

		private static bool DisplayAlways = GameTimerPlugin.DisplayAlways.Value;

		public static float LastClientSync = 0f;

		public static bool ClientFlag = false;

		[ModData(/*Could not decode attribute arguments.*/)]
		public static float ElapsedTime { get; private set; } = 0f;


		public GameTimer()
		{
			GameTimerPlugin.mls.LogInfo((object)"GameTimer constructor called.");
			if (Instance == null)
			{
				Instance = this;
				GTHudManager = HUDManager.Instance;
				GTNetworkManager = ((Component)GameNetworkManager.Instance).GetComponent<NetworkManager>();
				InstantiateTimerObject();
			}
			else
			{
				GameTimerPlugin.mls.LogInfo((object)"GameTimer instance already exists.");
			}
		}

		public static void UpdateLogic()
		{
			//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)
			if ((!StartTimeInit || !GameNetworkManager.Instance.gameHasStarted) && !ClientFlag)
			{
				return;
			}
			if (!GameTimerPlugin.EnableTimer.Value)
			{
				if ((Object)(object)TimerText != (Object)null)
				{
					((TMP_Text)TimerText).text = "";
				}
				PauseTimeCalculation();
				return;
			}
			if (Instance == null)
			{
				new GameTimer();
			}
			if ((Object)(object)Instance.TimerObject == (Object)null)
			{
				Instance.InstantiateTimerObject();
			}
			if (GameTimerPlugin.ResetNow.Value)
			{
				NetworkTime serverTime = GTNetworkManager.ServerTime;
				StartTime = (float)((NetworkTime)(ref serverTime)).Time;
				ElapsedTime = 0f;
				GameTimerPlugin.ResetNow.Value = false;
			}
			UpdateClientTime();
			if (GameTimerPlugin.DisplayAlways.Value != DisplayAlways)
			{
				DisplayAlways = GameTimerPlugin.DisplayAlways.Value;
				if (DisplayAlways)
				{
					((Transform)((TMP_Text)TimerText).rectTransform).SetParent(GameObject.Find("Canvas").transform);
				}
				else if ((Object)(object)GameObject.Find("WeightUI") != (Object)null)
				{
					((Transform)((TMP_Text)TimerText).rectTransform).SetParent(GameObject.Find("WeightUI").transform);
				}
				else
				{
					GameTimerPlugin.mls.LogWarning((object)"WeightUI could not be found. DisplayAlways setting will not be changed. Please report this to the mod author.");
					DisplayAlways = true;
					GameTimerPlugin.DisplayAlways.Value = true;
				}
			}
			if ((GameTimerPlugin.SConfig.PauseTimerAtTime.Value <= 0f || (float)Minutes < GameTimerPlugin.SConfig.PauseTimerAtTime.Value) && (GameTimerPlugin.SConfig.PauseTimerAtQuota.Value <= 0 || GameTimerPlugin.SConfig.PauseTimerAtQuota.Value > TimeOfDay.Instance.profitQuota) && (!StartOfRound.Instance.inShipPhase || !GameTimerPlugin.SConfig.PauseTimerInOrbit.Value))
			{
				Instance.SetText();
			}
			else
			{
				PauseTimeCalculation();
			}
		}

		public static void InitializeTimeCalculation()
		{
			//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)
			if (!StartTimeInit && GameNetworkManager.Instance.gameHasStarted)
			{
				if (Instance == null)
				{
					new GameTimer();
				}
				StartTimeInit = true;
				if (GameTimerPlugin.SaveElapsedTime.Value)
				{
					LoadElapsedTime();
					PastElapsedTimeOffset = ElapsedTime;
					ElapsedTime = 0f;
				}
				else
				{
					SaveElapsedTime();
				}
				NetworkTime serverTime = GTNetworkManager.ServerTime;
				StartTime = (float)((NetworkTime)(ref serverTime)).Time - PastElapsedTimeOffset;
				PastElapsedTimeOffset = 0f;
			}
		}

		public static void PauseTimeCalculation()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			NetworkTime serverTime = GTNetworkManager.ServerTime;
			StartTime = (float)((NetworkTime)(ref serverTime)).Time - ElapsedTime;
		}

		public void SetText()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)TimerText).color = new Color(GameTimerPlugin.DisplayColorR.Value / 255f, GameTimerPlugin.DisplayColorG.Value / 255f, GameTimerPlugin.DisplayColorB.Value / 255f);
			((TMP_Text)TimerText).rectTransform.anchoredPosition = new Vector2((float)GameTimerPlugin.DisplayPositionX.Value, (float)GameTimerPlugin.DisplayPositionY.Value);
			NetworkTime serverTime = GTNetworkManager.ServerTime;
			ElapsedTime = (float)((NetworkTime)(ref serverTime)).Time - StartTime;
			TimeParts = new List<int>();
			if (GameTimerPlugin.DisplayHours.Value)
			{
				Hours = (int)(ElapsedTime / 3600f);
				TimeParts.Add(Hours);
			}
			if (GameTimerPlugin.DisplayMinutes.Value)
			{
				Minutes = (int)(ElapsedTime / 60f % 60f);
				TimeParts.Add(Minutes);
			}
			if (GameTimerPlugin.DisplaySeconds.Value)
			{
				Seconds = (int)(ElapsedTime % 60f);
				TimeParts.Add(Seconds);
			}
			if (GameTimerPlugin.DisplayMilliseconds.Value)
			{
				Milliseconds = (int)((ElapsedTime - Mathf.Floor(ElapsedTime)) * 1000f);
				TimeParts.Add(Milliseconds);
			}
			((TMP_Text)TimerText).text = "";
			for (int i = 0; i < TimeParts.Count; i++)
			{
				TextMeshProUGUI timerText = TimerText;
				((TMP_Text)timerText).text = ((TMP_Text)timerText).text + $"{TimeParts[i]}".PadLeft(2, '0');
				if (i < TimeParts.Count - 1)
				{
					if (i == TimeParts.Count - 2 && GameTimerPlugin.DisplayMilliseconds.Value)
					{
						TextMeshProUGUI timerText2 = TimerText;
						((TMP_Text)timerText2).text = ((TMP_Text)timerText2).text + ".";
						TextMeshProUGUI timerText3 = TimerText;
						((TMP_Text)timerText3).text = ((TMP_Text)timerText3).text + $"{TimeParts[i + 1]}".PadLeft(3, '0');
						break;
					}
					TextMeshProUGUI timerText4 = TimerText;
					((TMP_Text)timerText4).text = ((TMP_Text)timerText4).text + ":";
				}
			}
		}

		public void InstantiateTimerObject()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0071: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			TimerObject = new GameObject("GameTimerObject");
			TimerObject.AddComponent<RectTransform>();
			TimerText = TimerObject.AddComponent<TextMeshProUGUI>();
			((Transform)((TMP_Text)TimerText).rectTransform).SetParent(GameObject.Find("Canvas").transform);
			((TMP_Text)TimerText).rectTransform.anchoredPosition3D = new Vector3((float)GameTimerPlugin.DisplayPositionX.Value, (float)GameTimerPlugin.DisplayPositionY.Value, 0f);
			((Transform)((TMP_Text)TimerText).rectTransform).localScale = new Vector3(1f, 1f, 1f);
			((TMP_Text)TimerText).rectTransform.sizeDelta = new Vector2(140f, 50f);
			((TMP_Text)TimerText).font = ((TMP_Text)GTHudManager.controlTipLines[0]).font;
			((TMP_Text)TimerText).fontSize = 15f;
			((Graphic)TimerText).color = new Color(GameTimerPlugin.DisplayColorR.Value / 255f, GameTimerPlugin.DisplayColorG.Value / 255f, GameTimerPlugin.DisplayColorB.Value / 255f);
			((TMP_Text)TimerText).alignment = (TextAlignmentOptions)514;
			((TMP_Text)TimerText).alignment = (TextAlignmentOptions)258;
			((TMP_Text)TimerText).overflowMode = (TextOverflowModes)0;
			((Behaviour)TimerText).enabled = true;
			((TMP_Text)TimerText).text = "";
			GameTimerPlugin.mls.LogInfo((object)"TimerObject instantiated.");
		}

		public static void SaveElapsedTime()
		{
			SaveLoadHandler.SaveData(ModDataHelper.GetModDataKey((object)typeof(GameTimer), "ElapsedTime"));
			if (GameTimerPlugin.DebugV.Value)
			{
				GameTimerPlugin.mls.LogInfo((object)$"Saved elapsed time: {ElapsedTime}");
			}
		}

		public static void LoadElapsedTime()
		{
			SaveLoadHandler.LoadData(ModDataHelper.GetModDataKey((object)typeof(GameTimer), "ElapsedTime"));
			if (GameTimerPlugin.DebugV.Value)
			{
				GameTimerPlugin.mls.LogInfo((object)$"Loaded elapsed time: {ElapsedTime}");
			}
		}

		public static void UpdateClientTime()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			if (GameTimerPlugin.SyncInterval.Value < 1f)
			{
				GameTimerPlugin.SyncInterval.Value = 1f;
			}
			float value = GameTimerPlugin.SyncInterval.Value;
			NetworkTime serverTime = GTNetworkManager.ServerTime;
			if (value < (float)((NetworkTime)(ref serverTime)).Time - LastClientSync)
			{
				serverTime = GTNetworkManager.ServerTime;
				LastClientSync = (float)((NetworkTime)(ref serverTime)).Time;
				NetworkObjectManager.SendEventToClients(ElapsedTime);
			}
		}

		public static void CleanUp()
		{
			if (GameTimerPlugin.DebugV.Value)
			{
				GameTimerPlugin.mls.LogInfo((object)"Attempting clean up on game leave.");
			}
			ClientFlag = false;
			StartTimeInit = false;
			LastClientSync = 0f;
			Instance = null;
		}
	}
	public class GTNetworkHandler : NetworkBehaviour
	{
		public static GTNetworkHandler Instance { get; private set; }

		public static event Action<float> OnElapsedTimeReceived;

		public override void OnNetworkSpawn()
		{
			GTNetworkHandler.OnElapsedTimeReceived = null;
			if ((NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer) && (Object)(object)Instance != (Object)null)
			{
				((Component)Instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
			}
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		[ClientRpc]
		public void ReceiveElapsedTimeClientRpc(float elapsedTime)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3242791706u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref elapsedTime, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3242791706u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					GTNetworkHandler.OnElapsedTimeReceived?.Invoke(elapsedTime);
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_GTNetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3242791706u, new RpcReceiveHandler(__rpc_handler_3242791706));
		}

		private static void __rpc_handler_3242791706(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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				float elapsedTime = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref elapsedTime, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((GTNetworkHandler)(object)target).ReceiveElapsedTimeClientRpc(elapsedTime);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "GTNetworkHandler";
		}
	}
}
namespace GameTimer.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}