using System;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Microsoft.CodeAnalysis;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Shrine_Counter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template Mod")]
[assembly: AssemblyFileVersion("0.1.5.0")]
[assembly: AssemblyInformationalVersion("0.1.5+64f8341b8a25c07fe5eec2609364bf141c3fcb9e")]
[assembly: AssemblyProduct("Shrine_Counter")]
[assembly: AssemblyTitle("Shrine_Counter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.5.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 Shrine_Counter
{
[BepInPlugin("BedlessSleeper_Shrine_Counter", "Shrine_Counter", "0.1.5")]
public class Plugin : BasePlugin
{
[HarmonyPatch]
public static class ChargeShrineStartPatch
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("ChargeShrine");
return AccessTools.Method(type, "Start", (Type[])null, (Type[])null);
}
private static void Postfix()
{
ActiveShrineCount++;
}
}
[HarmonyPatch]
public static class ChargeShrineCompletePatch
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("ChargeShrine");
return AccessTools.Method(type, "Complete", (Type[])null, (Type[])null);
}
private static void Postfix()
{
ActiveShrineCount--;
}
}
[HarmonyPatch]
public static class GameManager_StartPatch
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("GameManager");
return AccessTools.Method(type, "Start", (Type[])null, (Type[])null);
}
private static void Postfix()
{
ActiveShrineCount = 0;
IsRoundActive = true;
}
}
[HarmonyPatch(typeof(GameManager), "OnDied")]
public static class GameManager_OnDiedPatch
{
private static void Postfix()
{
IsRoundActive = false;
ActiveShrineCount = 0;
}
}
[HarmonyPatch(typeof(GameManager), "OnDestroy")]
public static class GameManager_OnDestroyPatch
{
private static void Postfix()
{
IsRoundActive = false;
ActiveShrineCount = 0;
}
}
public class ShrineCounterGUI : MonoBehaviour
{
private Text textObj;
private Canvas canvas;
private int lastCount = -1;
private bool lastRoundActive = false;
private void Awake()
{
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
}
private void Start()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("ShrineCounterCanvas");
canvas = val.AddComponent<Canvas>();
canvas.renderMode = (RenderMode)0;
Object.DontDestroyOnLoad((Object)(object)val);
GameObject val2 = new GameObject("ShrineCounterText");
val2.transform.SetParent(val.transform, false);
textObj = val2.AddComponent<Text>();
textObj.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
textObj.alignment = (TextAnchor)0;
textObj.horizontalOverflow = (HorizontalWrapMode)1;
textObj.verticalOverflow = (VerticalWrapMode)1;
Shadow val3 = val2.AddComponent<Shadow>();
val3.effectColor = Color.black;
val3.effectDistance = new Vector2(2f, -2f);
UpdateTextPositionAndSize();
textObj.text = $"Shrines: {ActiveShrineCount}";
}
private void Update()
{
if (!((Object)(object)textObj == (Object)null))
{
if (ActiveShrineCount != lastCount || IsRoundActive != lastRoundActive)
{
((Behaviour)textObj).enabled = IsRoundActive;
textObj.text = $"Shrines: {ActiveShrineCount}";
lastCount = ActiveShrineCount;
lastRoundActive = IsRoundActive;
}
UpdateTextPositionAndSize();
}
}
private void UpdateTextPositionAndSize()
{
//IL_002b: 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_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)textObj == (Object)null))
{
((Graphic)textObj).rectTransform.anchorMin = new Vector2(0f, 1f);
((Graphic)textObj).rectTransform.anchorMax = new Vector2(0f, 1f);
((Graphic)textObj).rectTransform.pivot = new Vector2(0f, 1f);
float num = (float)Screen.width * 0.64f;
float num2 = (float)Screen.height * 0.039f;
((Graphic)textObj).rectTransform.anchoredPosition = new Vector2(num, 0f - num2);
textObj.fontSize = Mathf.RoundToInt((float)Screen.height * 0.024f);
}
}
private void OnDisable()
{
SafeCleanup();
}
private void OnDestroy()
{
SafeCleanup();
}
}
public const string MODNAME = "Shrine_Counter";
public const string AUTHOR = "BedlessSleeper";
public const string GUID = "BedlessSleeper_Shrine_Counter";
public const string VERSION = "0.1.5";
internal static ManualLogSource log;
private static GameObject shrineCounterGO;
public static int ActiveShrineCount { get; private set; }
public static bool IsRoundActive { get; private set; }
public Plugin()
{
log = ((BasePlugin)this).Log;
}
public override void Load()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
log.LogInfo((object)"Shrine Counter Mod loaded!");
ClassInjector.RegisterTypeInIl2Cpp<ShrineCounterGUI>();
new Harmony("BedlessSleeper_Shrine_Counter").PatchAll();
CreateGUI();
}
private static void CreateGUI()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
if (!((Object)(object)shrineCounterGO != (Object)null))
{
shrineCounterGO = new GameObject("ShrineCounterGUI");
shrineCounterGO.AddComponent<ShrineCounterGUI>();
Object.DontDestroyOnLoad((Object)(object)shrineCounterGO);
}
}
public static void SafeCleanup()
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
try
{
if ((Object)(object)shrineCounterGO != (Object)null)
{
Object.Destroy((Object)(object)shrineCounterGO);
shrineCounterGO = null;
}
ActiveShrineCount = 0;
IsRoundActive = false;
}
catch (Exception ex)
{
ManualLogSource val = log;
if (val != null)
{
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(32, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[ShrineCounter] Cleanup failed: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
}
val.LogError(val2);
}
}
}
}
}