Decompiled source of TimeStopTimer v1.1.0

TimeStopTimer.DLL

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BoplFixedMath;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("TimeStopTimer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Displays how long unti Time Stop starts and how long until it ends.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("TimeStopTimer")]
[assembly: AssemblyTitle("TimeStopTimer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace TimeStopTimer;

[BepInPlugin("me.antimality.TimeStopTimer", "TimeStopTimer", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private static Harmony harmony;

	public static string currentScene;

	private void Awake()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"Plugin TimeStopTimer is loaded!");
		harmony = new Harmony("me.antimality.TimeStopTimer");
		harmony.PatchAll(typeof(Patch));
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
		TimerTextbox.DisposeAll();
	}

	private void Update()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//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)
		string text = currentScene;
		Scene activeScene = SceneManager.GetActiveScene();
		if (text != ((Scene)(ref activeScene)).name)
		{
			activeScene = SceneManager.GetActiveScene();
			currentScene = ((Scene)(ref activeScene)).name;
			TimerTextbox.DisposeAll();
		}
	}
}
[HarmonyPatch]
public class Patch
{
	[HarmonyPatch(typeof(CastSpell), "OnEnterAbility")]
	[HarmonyPostfix]
	public static void OnCast(ref GameObject ___spell, ref PlayerInfo ___playerInfo)
	{
		if (((Object)___spell).name == "TimeStopSphere")
		{
			new TimerTextbox(___playerInfo.playerId);
		}
	}

	[HarmonyPatch(typeof(CastSpell), "ExitAbility", new Type[] { typeof(AbilityExitInfo) })]
	[HarmonyPrefix]
	public static void OnExit(ref PlayerInfo ___playerInfo)
	{
		foreach (TimerTextbox textbox in TimerTextbox.Textboxes)
		{
			if (textbox.playerID == ___playerInfo.playerId && (Object)(object)textbox.timeStopInstance == (Object)null)
			{
				textbox.Dispose();
				break;
			}
		}
	}

	[HarmonyPatch(typeof(CastSpell), "UpdateSim")]
	[HarmonyPrefix]
	public static void CastingTimeStop(ref Fix ___castTime, ref Fix ___timeSinceActivation, ref PlayerInfo ___playerInfo)
	{
		//IL_0033: 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)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		foreach (TimerTextbox textbox in TimerTextbox.Textboxes)
		{
			if (textbox.playerID == ___playerInfo.playerId && (Object)(object)textbox.timeStopInstance == (Object)null)
			{
				textbox.Update((float)(___castTime - ___timeSinceActivation) + 1.25f);
				break;
			}
		}
	}

	[HarmonyPatch(typeof(TimeStop), "Init")]
	[HarmonyPostfix]
	public static void StartTimeStop(ref TimeStop __instance, ref int ___casterId)
	{
		new TimerTextbox(___casterId, __instance);
	}

	[HarmonyPatch(typeof(TimeStop), "End")]
	[HarmonyPrefix]
	public static void EndTimeStop(ref TimeStop __instance, ref int ___casterId)
	{
		foreach (TimerTextbox textbox in TimerTextbox.Textboxes)
		{
			if ((Object)(object)textbox.timeStopInstance == (Object)(object)__instance)
			{
				textbox.Dispose();
				break;
			}
		}
	}

	[HarmonyPatch(typeof(TimeStop), "UpdateSim")]
	[HarmonyPrefix]
	public static void DuringTimeStop(ref TimeStop __instance, ref float ___duration, ref float ___secondsElapsed, ref int ___casterId)
	{
		foreach (TimerTextbox textbox in TimerTextbox.Textboxes)
		{
			if ((Object)(object)textbox.timeStopInstance == (Object)(object)__instance)
			{
				textbox.Update(___duration - ___secondsElapsed + 2f);
				break;
			}
		}
	}
}
internal class TimerTextbox
{
	public static List<TimerTextbox> Textboxes = new List<TimerTextbox>();

	public readonly int playerID;

	public readonly TimeStop timeStopInstance;

	private Canvas canvas;

	private GameObject textObj;

	private TextMeshProUGUI textComp;

	private RectTransform location;

	public TimerTextbox(int playerID, TimeStop timeStopInstance = null)
	{
		foreach (TimerTextbox textbox in Textboxes)
		{
			if (textbox.playerID == playerID)
			{
				textbox.Dispose();
				break;
			}
		}
		Textboxes.Add(this);
		this.playerID = playerID;
		this.timeStopInstance = timeStopInstance;
		Summon();
	}

	public void Summon()
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		//IL_00dc: 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_0147: Unknown result type (might be due to invalid IL or missing references)
		canvas = GameObject.Find("AbilitySelectCanvas").GetComponent<Canvas>();
		if ((Object)(object)canvas == (Object)null || !Plugin.currentScene.Contains("Level"))
		{
			Plugin.Log.LogError((object)$"No suitable canvas! Canvas: {canvas}, Scene: {Plugin.currentScene}");
			return;
		}
		textObj = new GameObject("TimeStopTimer", new Type[2]
		{
			typeof(RectTransform),
			typeof(TextMeshProUGUI)
		});
		textObj.transform.SetParent(((Component)canvas).transform);
		textComp = textObj.GetComponent<TextMeshProUGUI>();
		((Graphic)textComp).raycastTarget = false;
		((Graphic)textComp).color = PlayerHandler.Get().GetPlayer(playerID).Color.GetColor("_ShadowColor");
		((TMP_Text)textComp).fontSize = 50f;
		((TMP_Text)textComp).alignment = (TextAlignmentOptions)514;
		((TMP_Text)textComp).font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);
		location = textObj.GetComponent<RectTransform>();
		location.pivot = new Vector2(0f, 1f);
		textObj.SetActive(true);
	}

	public void Update(float time)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		if (time < 1f)
		{
			Dispose();
			return;
		}
		((TMP_Text)textComp).text = ((int)time).ToString();
		Rect rect = ((Component)canvas).GetComponent<RectTransform>().rect;
		float height = ((Rect)(ref rect)).height;
		rect = ((Component)canvas).GetComponent<RectTransform>().rect;
		float width = ((Rect)(ref rect)).width;
		int num = Textboxes.IndexOf(this) * 100;
		location.anchoredPosition = new Vector2(width / 2f - 200f, height / 2f - 100f - (float)num);
	}

	public void Dispose()
	{
		Textboxes.Remove(this);
		Object.Destroy((Object)(object)textObj);
	}

	public static void DisposeAll()
	{
		for (int num = Textboxes.Count - 1; num >= 0; num--)
		{
			Textboxes[num].Dispose();
		}
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "TimeStopTimer";

	public const string PLUGIN_NAME = "TimeStopTimer";

	public const string PLUGIN_VERSION = "1.1.0";
}