Decompiled source of SpeedrunTimer v0.0.1

plugins/SpeedrunTimer.dll

Decompiled 8 months ago
using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CellMenu;
using GTFO.API;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using TMPro;
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("SpeedrunTimer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpeedrunTimer")]
[assembly: AssemblyTitle("SpeedrunTimer")]
[assembly: TargetPlatform("Windows7.0")]
[assembly: SupportedOSPlatform("Windows7.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 SpeedrunTimer
{
	internal sealed class BitMoreAccurateTimer : MonoBehaviour
	{
		private Stopwatch _SW = new Stopwatch();

		private bool _TimerRunning = false;

		public static BitMoreAccurateTimer Current { get; private set; }

		public string FormattedTime
		{
			get
			{
				TimeSpan elapsed = _SW.Elapsed;
				return $"{elapsed.Hours:00}:{elapsed.Minutes:00}:{elapsed.Seconds:00}.{elapsed.Milliseconds:000}";
			}
		}

		public static void Init()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			GameObject val = new GameObject("BitMoreAccurateTimer");
			Object.DontDestroyOnLoad((Object)(object)val);
			val.AddComponent<BitMoreAccurateTimer>();
		}

		private void Start()
		{
			Current = this;
		}

		public void StartTimer()
		{
			_SW.Restart();
			_TimerRunning = true;
		}

		public void PauseTimer()
		{
			_SW.Stop();
		}

		public void ClearTimer()
		{
			_SW.Reset();
			_TimerRunning = false;
		}
	}
	[BepInPlugin("SpeedrunTimer", "SpeedrunTimer", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class EntryPoint : BasePlugin
	{
		private Harmony _Harmony = null;

		public override void Load()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			ClassInjector.RegisterTypeInIl2Cpp<BitMoreAccurateTimer>();
			_Harmony = new Harmony("SpeedrunTimer.Harmony");
			_Harmony.PatchAll();
			AssetAPI.OnStartupAssetsLoaded += AssetAPI_OnStartupAssetsLoaded;
			LevelAPI.OnEnterLevel += TimerStart;
			LevelAPI.OnLevelCleanup += TimerReset;
		}

		private void AssetAPI_OnStartupAssetsLoaded()
		{
			BitMoreAccurateTimer.Init();
		}

		private void TimerReset()
		{
			BitMoreAccurateTimer.Current.ClearTimer();
		}

		private void TimerStart()
		{
			BitMoreAccurateTimer.Current.StartTimer();
		}

		public override bool Unload()
		{
			_Harmony.UnpatchSelf();
			return ((BasePlugin)this).Unload();
		}
	}
	internal static class Logger
	{
		private static readonly ManualLogSource _Logger;

		static Logger()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_Logger = new ManualLogSource("SpeedrunTimer");
			Logger.Sources.Add((ILogSource)(object)_Logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(BepInExInfoLogInterpolatedStringHandler handler)
		{
			_Logger.LogInfo(handler);
		}

		public static void Info(string str)
		{
			_Logger.LogMessage((object)str);
		}

		public static void Info(object data)
		{
			_Logger.LogMessage((object)Format(data));
		}

		public static void Debug(BepInExDebugLogInterpolatedStringHandler handler)
		{
			_Logger.LogDebug(handler);
		}

		public static void Debug(string str)
		{
			_Logger.LogDebug((object)str);
		}

		public static void Debug(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}

		public static void Error(BepInExErrorLogInterpolatedStringHandler handler)
		{
			_Logger.LogError(handler);
		}

		public static void Error(string str)
		{
			_Logger.LogError((object)str);
		}

		public static void Error(object data)
		{
			_Logger.LogError((object)Format(data));
		}

		public static void Fatal(BepInExFatalLogInterpolatedStringHandler handler)
		{
			_Logger.LogFatal(handler);
		}

		public static void Fatal(string str)
		{
			_Logger.LogFatal((object)str);
		}

		public static void Fatal(object data)
		{
			_Logger.LogFatal((object)Format(data));
		}

		public static void Warn(BepInExWarningLogInterpolatedStringHandler handler)
		{
			_Logger.LogWarning(handler);
		}

		public static void Warn(string str)
		{
			_Logger.LogWarning((object)str);
		}

		public static void Warn(object data)
		{
			_Logger.LogWarning((object)Format(data));
		}

		[Conditional("DEBUG")]
		public static void DebugOnly(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}
	}
	[GeneratedCode("VersionInfoGenerator", "2.1.3+git35c0c2a-master")]
	[CompilerGenerated]
	internal static class VersionInfo
	{
		public const string RootNamespace = "SpeedrunTimer";

		public const string Version = "1.0.0";

		public const string VersionPrerelease = null;

		public const string VersionMetadata = null;

		public const string SemVer = "1.0.0";

		public const string GitRevShort = null;

		public const string GitRevLong = null;

		public const string GitBranch = null;

		public const string GitTag = null;

		public const int GitCommitsSinceTag = 0;

		public const bool GitIsDirty = false;
	}
}
namespace SpeedrunTimer.Injects
{
	[HarmonyPatch(typeof(CM_PageExpeditionSuccess), "OnEnable")]
	internal static class Inject_CM_Expedition
	{
		private static readonly Regex s_TimerRegEx = new Regex("<size=70%> - [0-9][0-9]:[0-9][0-9]:[0-9][0-9]<\\/size>");

		private static void Postfix(CM_PageExpeditionSuccess __instance)
		{
			string text = ((TMP_Text)__instance.m_expeditionName).text;
			string text2 = s_TimerRegEx.Replace(text, "<size=70%> - " + BitMoreAccurateTimer.Current.FormattedTime + "</size>");
			((TMP_Text)__instance.m_expeditionName).text = text2;
		}
	}
	[HarmonyPatch(typeof(CM_PageObjectives), "Update")]
	internal static class Inject_CM_Objective_Timer
	{
		private static void Postfix(CM_PageObjectives __instance)
		{
			((TMP_Text)__instance.m_expeditionTime).text = BitMoreAccurateTimer.Current.FormattedTime;
		}
	}
	[HarmonyPatch(typeof(WardenObjectiveManager), "OnWinConditionSolved")]
	internal static class Inject_OnWinConditionSolved
	{
		private static void Postfix(LG_LayerType layer)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			if ((int)layer == 0)
			{
				BitMoreAccurateTimer.Current.PauseTimer();
			}
		}
	}
}