using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("PeakLevelTimer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PeakLevelTimer")]
[assembly: AssemblyTitle("PeakLevelTimer")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 PeakLevelTimer
{
[BepInPlugin("com.yourname.peakleveltimer", "PeakLevelTimer", "2.0.0")]
public class PeakLevelTimerPlugin : BaseUnityPlugin
{
private ConfigEntry<string> cfgFontPattern;
private ConfigEntry<string> cfgLevelPattern;
private ConfigEntry<int> cfgFontSize;
private ConfigEntry<Color> cfgFontColor;
private ConfigEntry<float> cfgPosX;
private ConfigEntry<float> cfgPosY;
private ConfigEntry<bool> cfgResetOnEachLevel;
private static TMP_FontAsset cachedFont;
private static bool fontSearched;
private TextMeshProUGUI timerText;
private float timerStart = -1f;
private bool inLevel;
private void Awake()
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
cfgFontPattern = ((BaseUnityPlugin)this).Config.Bind<string>("Visual", "FontAssetNamePattern", "Daruma", (ConfigDescription)null);
cfgFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Visual", "FontSize", 36, (ConfigDescription)null);
cfgFontColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Visual", "FontColor", Color.white, (ConfigDescription)null);
cfgPosX = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "PositionX", 24f, (ConfigDescription)null);
cfgPosY = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "PositionY", -20f, (ConfigDescription)null);
cfgLevelPattern = ((BaseUnityPlugin)this).Config.Bind<string>("General", "LevelScenePattern", "^Level_", (ConfigDescription)null);
cfgResetOnEachLevel = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ResetOnEachLevelEntry", true, (ConfigDescription)null);
BuildUI();
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void BuildUI()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
//IL_00c1: 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_0145: 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_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("PeakLevelTimer_Canvas");
Object.DontDestroyOnLoad((Object)(object)val);
Canvas val2 = val.AddComponent<Canvas>();
val2.renderMode = (RenderMode)0;
val2.sortingOrder = 32767;
CanvasScaler val3 = val.AddComponent<CanvasScaler>();
val3.uiScaleMode = (ScaleMode)1;
val3.referenceResolution = new Vector2(1920f, 1080f);
GameObject val4 = new GameObject("TimerText", new Type[2]
{
typeof(RectTransform),
typeof(TextMeshProUGUI)
});
val4.transform.SetParent(val.transform, false);
timerText = val4.GetComponent<TextMeshProUGUI>();
((TMP_Text)timerText).fontSize = cfgFontSize.Value;
((Graphic)timerText).color = cfgFontColor.Value;
((TMP_Text)timerText).alignment = (TextAlignmentOptions)257;
((Graphic)timerText).raycastTarget = false;
((TMP_Text)timerText).textWrappingMode = (TextWrappingModes)0;
((TMP_Text)timerText).outlineWidth = 0.2f;
((TMP_Text)timerText).outlineColor = new Color32((byte)0, (byte)0, (byte)0, (byte)200);
RectTransform rectTransform = ((TMP_Text)timerText).rectTransform;
Vector2 val5 = default(Vector2);
((Vector2)(ref val5))..ctor(0f, 1f);
rectTransform.pivot = val5;
Vector2 anchorMin = (rectTransform.anchorMax = val5);
rectTransform.anchorMin = anchorMin;
rectTransform.anchoredPosition = new Vector2(cfgPosX.Value, cfgPosY.Value);
rectTransform.sizeDelta = new Vector2(400f, 100f);
((Component)timerText).gameObject.SetActive(false);
if ((Object)(object)cachedFont != (Object)null)
{
((TMP_Text)timerText).font = cachedFont;
}
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (!fontSearched)
{
FindFont();
}
if ((Object)(object)cachedFont != (Object)null && (Object)(object)((TMP_Text)timerText).font != (Object)(object)cachedFont)
{
((TMP_Text)timerText).font = cachedFont;
}
bool flag = false;
try
{
flag = Regex.IsMatch(((Scene)(ref scene)).name, cfgLevelPattern.Value, RegexOptions.IgnoreCase);
}
catch
{
}
if (flag)
{
if (cfgResetOnEachLevel.Value || (!inLevel && timerStart < 0f))
{
timerStart = Time.realtimeSinceStartup;
}
inLevel = true;
((Component)timerText).gameObject.SetActive(true);
}
else
{
inLevel = false;
((Component)timerText).gameObject.SetActive(false);
}
}
private void FindFont()
{
fontSearched = true;
cachedFont = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => (Object)(object)f != (Object)null && ((Object)f).name.IndexOf(cfgFontPattern.Value, StringComparison.OrdinalIgnoreCase) >= 0));
}
private void Update()
{
if (inLevel && !(timerStart < 0f))
{
TimeSpan timeSpan = TimeSpan.FromSeconds(Time.realtimeSinceStartup - timerStart);
((TMP_Text)timerText).text = ((timeSpan.Hours > 0) ? timeSpan.ToString("hh\\:mm\\:ss") : timeSpan.ToString("mm\\:ss"));
}
}
}
}