Decompiled source of BossGrades v1.1.0

BossGrades.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NineSolsAPI;
using RCGMaker.Core;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BossGrades")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Gives grades based on player's performance in boss fights")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BossGrades")]
[assembly: AssemblyTitle("BossGrades")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BossGrades
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("BossGrades", "BossGrades", "1.0.0")]
	public class BossGrades : BaseUnityPlugin
	{
		public enum GradeType
		{
			D,
			C,
			B,
			A,
			S,
			SS,
			SSS
		}

		private Harmony harmony;

		private MonsterBase boss;

		public static int UnboundedCounterCount;

		public static int PerfectParryCount;

		public static int ImperfectParryCount;

		public static int NumberOfHitsTaken;

		public static int NumberOfWeedSmoke;

		public static int NumberOfBowUsage;

		private float BossKillTimer;

		private TMP_Text Grade;

		private TMP_Text FinalTimer;

		private TMP_Text UCCount;

		private TMP_Text FinalPerfectParryCount;

		private TMP_Text FinalImperfectParryCount;

		private TMP_Text FinalHits;

		private TMP_Text FinalSand;

		private TMP_Text FinalWeed;

		public float duration = 0.3f;

		public GradeType BossGrade;

		private ConfigEntry<KeyCode> skipKey;

		private bool bossDeathHandled;

		public void Awake()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			Log.Init(((BaseUnityPlugin)this).Logger);
			RCGLifeCycle.DontDestroyForever(((Component)this).gameObject);
			harmony = Harmony.CreateAndPatchAll(typeof(BossGrades).Assembly, (string)null);
			Grade = CreateText("Final Grade: " + BossGrade, Color.cyan, 50f);
			FinalTimer = CreateText("Final Time: " + BossKillTimer / 60f + "m & " + BossKillTimer % 60f + "s", Color.white, 50f);
			UCCount = CreateText("Number of Successful Unbounded Counters: " + UnboundedCounterCount, Color.green, 25f);
			FinalPerfectParryCount = CreateText("Number of Perfect Parries: " + PerfectParryCount, Color.green, 25f);
			FinalImperfectParryCount = CreateText("Number of Imperfect Parries: " + ImperfectParryCount, Color.red, 25f);
			FinalHits = CreateText("Number of Hits taken: " + NumberOfHitsTaken, Color.red, 25f);
			FinalSand = CreateText("Number of Bow Shots: " + NumberOfBowUsage, Color.red, 25f);
			FinalWeed = CreateText("Number of Medicine Pipe used: " + NumberOfWeedSmoke, Color.red, 25f);
			((Transform)Grade.rectTransform).position = Vector2.op_Implicit(new Vector2(1100f, 600f));
			((Transform)FinalTimer.rectTransform).position = Vector2.op_Implicit(new Vector2(600f, 600f));
			((Transform)UCCount.rectTransform).position = Vector2.op_Implicit(new Vector2(700f, 350f));
			((Transform)FinalPerfectParryCount.rectTransform).position = Vector2.op_Implicit(new Vector2(900f, 350f));
			((Transform)FinalImperfectParryCount.rectTransform).position = Vector2.op_Implicit(new Vector2(500f, 150f));
			((Transform)FinalHits.rectTransform).position = Vector2.op_Implicit(new Vector2(750f, 150f));
			((Transform)FinalSand.rectTransform).position = Vector2.op_Implicit(new Vector2(950f, 150f));
			((Transform)FinalWeed.rectTransform).position = Vector2.op_Implicit(new Vector2(1150f, 150f));
			DeactivateTexts();
			skipKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ResumeTimeKey", (KeyCode)8, "The key used to resume time when the boss dies");
		}

		private void DeactivateTexts()
		{
			MonoLifeTimeExtension.SetActive((MonoBehaviour)(object)Grade, false);
			MonoLifeTimeExtension.SetActive((MonoBehaviour)(object)FinalTimer, false);
			MonoLifeTimeExtension.SetActive((MonoBehaviour)(object)UCCount, false);
			MonoLifeTimeExtension.SetActive((MonoBehaviour)(object)FinalPerfectParryCount, false);
			MonoLifeTimeExtension.SetActive((MonoBehaviour)(object)FinalImperfectParryCount, false);
			MonoLifeTimeExtension.SetActive((MonoBehaviour)(object)FinalHits, false);
			MonoLifeTimeExtension.SetActive((MonoBehaviour)(object)FinalSand, false);
			MonoLifeTimeExtension.SetActive((MonoBehaviour)(object)FinalWeed, false);
		}

		public void Update()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			if ((Object)(object)SingletonBehaviour<ApplicationCore>.Instance == (Object)null || !ApplicationCore.IsInBossMemoryMode)
			{
				return;
			}
			Player.i.PlayerDeadState.OnReviveEvent.AddListener(new UnityAction(ResetValues));
			boss = GetBossInstance();
			if ((Object)(object)boss != (Object)null)
			{
				if (!CheckForBossDead())
				{
					if (!((Object)(object)boss.currentMonsterState == (Object)(object)boss.FindState((States)131)) && !((Object)(object)boss.currentMonsterState == (Object)(object)boss.FindState((States)146)))
					{
						BossKillTimer += Time.deltaTime;
						if (Input.GetKeyDown((KeyCode)103))
						{
							boss.ChangeState(boss.FindState((States)169));
						}
					}
				}
				else
				{
					((MonoBehaviour)this).StartCoroutine(OnBossDeath());
				}
			}
			else if ((Object)(object)boss == (Object)null)
			{
				ResetValues();
				DeactivateTexts();
			}
		}

		private void UpdateTexts()
		{
			BossGrade = FinalGrade();
			Grade.text = "Final Grade: <br>" + FinalGrade();
			((MonoBehaviour)this).StartCoroutine(FadeIn(Grade));
			FinalTimer.text = "Final Time: <br>" + (BossKillTimer / 60f).ToString("F0") + "m & " + (BossKillTimer % 60f).ToString("F0") + "s";
			((MonoBehaviour)this).StartCoroutine(FadeIn(FinalTimer));
			UCCount.text = "Successful Unbounded Counters: <br>" + UnboundedCounterCount;
			((MonoBehaviour)this).StartCoroutine(FadeIn(UCCount));
			FinalPerfectParryCount.text = "Perfect Parries: " + PerfectParryCount;
			((MonoBehaviour)this).StartCoroutine(FadeIn(FinalPerfectParryCount));
			FinalImperfectParryCount.text = "Imperfect Parries: " + ImperfectParryCount;
			((MonoBehaviour)this).StartCoroutine(FadeIn(FinalImperfectParryCount));
			FinalHits.text = "Hits taken: " + NumberOfHitsTaken;
			((MonoBehaviour)this).StartCoroutine(FadeIn(FinalHits));
			FinalSand.text = "Bow Shots: " + NumberOfBowUsage;
			((MonoBehaviour)this).StartCoroutine(FadeIn(FinalSand));
			FinalWeed.text = "Medicine Pipe used: " + NumberOfWeedSmoke;
			((MonoBehaviour)this).StartCoroutine(FadeIn(FinalWeed));
		}

		public IEnumerator OnBossDeath()
		{
			if (!bossDeathHandled)
			{
				UpdateTexts();
				Time.timeScale = 0f;
				yield return (object)new WaitUntil((Func<bool>)(() => Input.GetKeyDown(skipKey.Value)));
				Time.timeScale = 1f;
				bossDeathHandled = true;
			}
		}

		public GradeType FinalGrade()
		{
			if (BossKillTimer < 150f && ImperfectParryCount == 0 && NumberOfHitsTaken == 0 && NumberOfWeedSmoke == 0 && NumberOfBowUsage == 0 && UnboundedCounterCount > 6)
			{
				return GradeType.SSS;
			}
			if (BossKillTimer < 180f && ImperfectParryCount == 0 && NumberOfHitsTaken == 0 && NumberOfWeedSmoke == 0 && NumberOfBowUsage == 0 && UnboundedCounterCount > 3)
			{
				return GradeType.SS;
			}
			if (BossKillTimer != 0f && ImperfectParryCount == 0 && NumberOfHitsTaken == 0 && NumberOfWeedSmoke == 0 && NumberOfBowUsage == 0 && UnboundedCounterCount > 3)
			{
				return GradeType.S;
			}
			if (BossKillTimer != 0f && ImperfectParryCount < 10 && NumberOfHitsTaken < 2 && NumberOfWeedSmoke == 0 && NumberOfBowUsage < 3 && UnboundedCounterCount > 1)
			{
				return GradeType.A;
			}
			if (BossKillTimer != 0f && ImperfectParryCount < 15 && NumberOfHitsTaken < 6 && NumberOfWeedSmoke < 4 && NumberOfBowUsage < 5 && UnboundedCounterCount > 1)
			{
				return GradeType.B;
			}
			if (BossKillTimer != 0f && ImperfectParryCount < 15 && NumberOfHitsTaken < 10 && NumberOfWeedSmoke < 6 && NumberOfBowUsage < 5 && UnboundedCounterCount > 1)
			{
				return GradeType.C;
			}
			return GradeType.D;
		}

		public bool CheckForBossDead()
		{
			//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)
			States currentState = boss.CurrentState;
			return ((object)(States)(ref currentState)).Equals((object)(States)169);
		}

		public void ResetValues()
		{
			BossKillTimer = 0f;
			UnboundedCounterCount = 0;
			PerfectParryCount = 0;
			ImperfectParryCount = 0;
			NumberOfHitsTaken = 0;
			NumberOfWeedSmoke = 0;
			NumberOfBowUsage = 0;
			bossDeathHandled = false;
		}

		private TMP_Text CreateText(string str, Color color, float fontSize)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)NineSolsAPICore.FullscreenCanvas).transform;
			GameObject val = new GameObject();
			val.transform.SetParent(transform);
			TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).fontSize = fontSize;
			((TMP_Text)obj).text = str;
			((Graphic)obj).color = color;
			return (TMP_Text)(object)obj;
		}

		private MonsterBase GetBossInstance()
		{
			foreach (MonsterBase value in SingletonBehaviour<MonsterManager>.Instance.monsterDict.Values)
			{
				if (((Component)value).tag == "Boss" && ((Object)value).name != "_depre_StealthGameMonster_伏羲 Variant(Clone)" && ((Object)value).name != "StealthGameMonster_新女媧 Variant")
				{
					return value;
				}
			}
			return null;
		}

		public IEnumerator FadeIn(TMP_Text text)
		{
			MonoLifeTimeExtension.SetActive((MonoBehaviour)(object)text, true);
			float elapsedTime = 0f;
			while (elapsedTime < duration)
			{
				elapsedTime += Time.unscaledDeltaTime;
				float num = elapsedTime / duration;
				text.alpha = Mathf.Lerp(0f, 1f, num);
				yield return null;
			}
			text.alpha = 1f;
		}

		public void OnDestroy()
		{
			harmony.UnpatchSelf();
			Object.Destroy((Object)(object)Grade);
			Object.Destroy((Object)(object)FinalTimer);
			Object.Destroy((Object)(object)UCCount);
			Object.Destroy((Object)(object)FinalPerfectParryCount);
			Object.Destroy((Object)(object)FinalImperfectParryCount);
			Object.Destroy((Object)(object)FinalHits);
			Object.Destroy((Object)(object)FinalSand);
			Object.Destroy((Object)(object)FinalWeed);
		}
	}
	internal static class Log
	{
		private static ManualLogSource? logSource;

		internal static void Init(ManualLogSource logSource)
		{
			Log.logSource = logSource;
		}

		internal static void Debug(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogDebug(data);
			}
		}

		internal static void Error(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogError(data);
			}
		}

		internal static void Fatal(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogFatal(data);
			}
		}

		internal static void Info(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogInfo(data);
			}
		}

		internal static void Message(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogMessage(data);
			}
		}

		internal static void Warning(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogWarning(data);
			}
		}
	}
	[HarmonyPatch]
	public class Patches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerHurtState), "OnStateEnter")]
		public static void IncrementNumberOfHits()
		{
			BossGrades.NumberOfHitsTaken++;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerDrinkPotionState), "OnStateEnter")]
		public static void IncrementNumberVials()
		{
			BossGrades.NumberOfWeedSmoke++;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerWeaponState), "OnStateEnter")]
		public static void IncrementNumberOfAzureSand()
		{
			BossGrades.NumberOfBowUsage++;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerCounterAttackState), "OnStateEnter")]
		public static void IncrementUnboundedCounterCounter()
		{
			BossGrades.UnboundedCounterCount++;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerParryState), "AccurateParry")]
		public static void IncrementPerfectParryCounter()
		{
			BossGrades.PerfectParryCount++;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerParryState), "OnStateExit")]
		public static void IncrementImperfectParryCounter(ref PlayerParryState __instance)
		{
			if (__instance.IsParried && !__instance.IsAccurateParried)
			{
				BossGrades.ImperfectParryCount++;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BossGrades";

		public const string PLUGIN_NAME = "BossGrades";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}