Decompiled source of GodModeBoss v0.1.1

GodModeBoss.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.CompilerServices;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NineSolsAPI;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("GodModeBoss")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("GodModeBoss")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GodModeBoss")]
[assembly: AssemblyTitle("GodModeBoss")]
[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 GodModeBoss
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("GodModeBoss", "GodModeBoss", "1.0.0")]
	public class GodModeBoss : BaseUnityPlugin
	{
		[StructLayout(LayoutKind.Auto)]
		[CompilerGenerated]
		private struct <CyclePhases>d__26 : IAsyncStateMachine
		{
			public int <>1__state;

			public AsyncUniTaskVoidMethodBuilder <>t__builder;

			public GodModeBoss <>4__this;

			private int <phaseIndex>5__2;

			private CancellationToken <cancellationToken>5__3;

			private Awaiter <>u__1;

			private void MoveNext()
			{
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				GodModeBoss godModeBoss = <>4__this;
				try
				{
					if (num != 0)
					{
						<phaseIndex>5__2 = 0;
						godModeBoss.isCyclingPhases = true;
						<cancellationToken>5__3 = godModeBoss.phaseCycleCancellationTokenSource?.Token ?? CancellationToken.None;
						goto IL_00e1;
					}
					Awaiter awaiter = <>u__1;
					<>u__1 = default(Awaiter);
					num = (<>1__state = -1);
					goto IL_00da;
					IL_00e1:
					if (godModeBoss.isCyclingPhases && !<cancellationToken>5__3.IsCancellationRequested)
					{
						godModeBoss.SetPhase(<phaseIndex>5__2);
						<phaseIndex>5__2 = (<phaseIndex>5__2 + 1) % 3;
						UniTask val = UniTask.Delay((int)(godModeBoss.phaseSecond?.Value ?? 0f) * 1000, false, (PlayerLoopTiming)8, <cancellationToken>5__3);
						awaiter = ((UniTask)(ref val)).GetAwaiter();
						if (!((Awaiter)(ref awaiter)).IsCompleted)
						{
							num = (<>1__state = 0);
							<>u__1 = awaiter;
							((AsyncUniTaskVoidMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<Awaiter, <CyclePhases>d__26>(ref awaiter, ref this);
							return;
						}
						goto IL_00da;
					}
					goto end_IL_000e;
					IL_00da:
					((Awaiter)(ref awaiter)).GetResult();
					goto IL_00e1;
					end_IL_000e:;
				}
				catch (Exception exception)
				{
					<>1__state = -2;
					<cancellationToken>5__3 = default(CancellationToken);
					((AsyncUniTaskVoidMethodBuilder)(ref <>t__builder)).SetException(exception);
					return;
				}
				<>1__state = -2;
				<cancellationToken>5__3 = default(CancellationToken);
				((AsyncUniTaskVoidMethodBuilder)(ref <>t__builder)).SetResult();
			}

			void IAsyncStateMachine.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				this.MoveNext();
			}

			[DebuggerHidden]
			private void SetStateMachine(IAsyncStateMachine stateMachine)
			{
				((AsyncUniTaskVoidMethodBuilder)(ref <>t__builder)).SetStateMachine(stateMachine);
			}

			void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
			{
				//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
				this.SetStateMachine(stateMachine);
			}
		}

		[StructLayout(LayoutKind.Auto)]
		[CompilerGenerated]
		private struct <checkBossActive>d__15 : IAsyncStateMachine
		{
			public int <>1__state;

			public AsyncUniTaskMethodBuilder <>t__builder;

			public GodModeBoss <>4__this;

			private Awaiter <>u__1;

			private void MoveNext()
			{
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: 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_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				GodModeBoss godModeBoss = <>4__this;
				try
				{
					if (num != 0)
					{
						goto IL_0011;
					}
					Awaiter awaiter = <>u__1;
					<>u__1 = default(Awaiter);
					num = (<>1__state = -1);
					goto IL_009f;
					IL_0011:
					MonsterBase bossInstance = godModeBoss.GetBossInstance();
					if (!((Object)(object)bossInstance != (Object)null) || !bossInstance.IsAlive() || !((Behaviour)bossInstance).isActiveAndEnabled || !((Component)bossInstance).gameObject.activeInHierarchy || !((Component)bossInstance).gameObject.activeSelf)
					{
						YieldAwaitable val = UniTask.Yield();
						awaiter = ((YieldAwaitable)(ref val)).GetAwaiter();
						if (!((Awaiter)(ref awaiter)).IsCompleted)
						{
							num = (<>1__state = 0);
							<>u__1 = awaiter;
							((AsyncUniTaskMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<Awaiter, <checkBossActive>d__15>(ref awaiter, ref this);
							return;
						}
						goto IL_009f;
					}
					goto end_IL_000e;
					IL_009f:
					((Awaiter)(ref awaiter)).GetResult();
					goto IL_0011;
					end_IL_000e:;
				}
				catch (Exception exception)
				{
					<>1__state = -2;
					((AsyncUniTaskMethodBuilder)(ref <>t__builder)).SetException(exception);
					return;
				}
				<>1__state = -2;
				((AsyncUniTaskMethodBuilder)(ref <>t__builder)).SetResult();
			}

			void IAsyncStateMachine.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				this.MoveNext();
			}

			[DebuggerHidden]
			private void SetStateMachine(IAsyncStateMachine stateMachine)
			{
				((AsyncUniTaskMethodBuilder)(ref <>t__builder)).SetStateMachine(stateMachine);
			}

			void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
			{
				//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
				this.SetStateMachine(stateMachine);
			}
		}

		private Harmony mainHarmony = new Harmony("GodModeBoss.Harmony");

		private ConfigEntry<bool>[] phaseButtons = new ConfigEntry<bool>[0];

		private ConfigEntry<bool> invincibleButton;

		private ConfigEntry<bool> phaseCycleButton;

		private ConfigEntry<float> phaseSecond;

		public ConfigEntry<bool> isReviveJade;

		public ConfigEntry<bool> isToast;

		private bool isCyclingPhases;

		private CancellationTokenSource? phaseCycleCancellationTokenSource;

		public static GodModeBoss Instance { get; private set; }

		private void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			RCGLifeCycle.DontDestroyForever(((Component)this).gameObject);
			mainHarmony = Harmony.CreateAndPatchAll(typeof(GodModeBoss).Assembly, (string)null);
			InitializeConfigEntries();
			SceneManager.sceneLoaded += OnSceneLoaded;
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin GodModeBoss is loaded!");
		}

		private async void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			StopPhaseCycle();
			if (phaseCycleButton?.Value ?? false)
			{
				await checkBossActive();
				TogglePhaseCycle(enable: true);
			}
			if (invincibleButton?.Value ?? false)
			{
				ToggleInvincibility();
			}
		}

		[AsyncStateMachine(typeof(<checkBossActive>d__15))]
		private UniTask checkBossActive()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			<checkBossActive>d__15 <checkBossActive>d__ = default(<checkBossActive>d__15);
			<checkBossActive>d__.<>t__builder = AsyncUniTaskMethodBuilder.Create();
			<checkBossActive>d__.<>4__this = this;
			<checkBossActive>d__.<>1__state = -1;
			((AsyncUniTaskMethodBuilder)(ref <checkBossActive>d__.<>t__builder)).Start<<checkBossActive>d__15>(ref <checkBossActive>d__);
			return ((AsyncUniTaskMethodBuilder)(ref <checkBossActive>d__.<>t__builder)).Task;
		}

		private MonsterBase GetBossInstance()
		{
			foreach (MonsterBase value in SingletonBehaviour<MonsterManager>.Instance.monsterDict.Values)
			{
				if (((Component)value).tag == "Boss")
				{
					return value;
				}
			}
			return null;
		}

		private void InitializeConfigEntries()
		{
			phaseButtons = new ConfigEntry<bool>[3]
			{
				CreatePhaseButton("Phase 1", 0),
				CreatePhaseButton("Phase 2", 1),
				CreatePhaseButton("Phase 3", 2)
			};
			invincibleButton = ((BaseUnityPlugin)this).Config.Bind<bool>("Actions", "Toggle Invincibility", false, "Toggle invincibility for all bosses");
			invincibleButton.SettingChanged += delegate
			{
				ToggleInvincibility();
			};
			phaseCycleButton = ((BaseUnityPlugin)this).Config.Bind<bool>("Actions", "Cycle Phases 1~3", false, "Automatically cycle phases 1 to 3 every x seconds");
			phaseCycleButton.SettingChanged += delegate
			{
				TogglePhaseCycle(phaseCycleButton?.Value ?? false);
			};
			phaseSecond = ((BaseUnityPlugin)this).Config.Bind<float>("Actions", "Change Phases Every Second", 30f, "");
			isReviveJade = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Revive Jade Unlimit times", false, "");
			isToast = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Is Toast Change Phase", false, "");
			ResetAllButtons();
		}

		private ConfigEntry<bool> CreatePhaseButton(string name, int phaseIndex)
		{
			ConfigEntry<bool> entry = ((BaseUnityPlugin)this).Config.Bind<bool>("Actions", "Goto " + name, false, "Trigger " + name + " for all bosses");
			entry.SettingChanged += delegate
			{
				if (entry.Value)
				{
					SetPhase(phaseIndex);
				}
				entry.Value = false;
			};
			return entry;
		}

		private void ResetAllButtons()
		{
			ConfigEntry<bool>[] array = phaseButtons;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].Value = false;
			}
			invincibleButton.Value = false;
			isReviveJade.Value = false;
			phaseCycleButton.Value = false;
		}

		private void ToggleInvincibility()
		{
			foreach (MonsterBase value in SingletonBehaviour<MonsterManager>.Instance.monsterDict.Values)
			{
				if (((Component)value).tag == "Boss" && TryGetMonsterStat(value, out MonsterStat monsterStat))
				{
					bool flag = invincibleButton?.Value ?? false;
					monsterStat.IsLockPostureInvincible = flag;
					ToastManager.Toast((object)$"Invincible: {flag} Name: {((Object)value).name}");
				}
			}
		}

		private void SetPhase(int phaseIndex)
		{
			bool flag = isToast?.Value ?? false;
			foreach (MonsterBase value in SingletonBehaviour<MonsterManager>.Instance.monsterDict.Values)
			{
				if (((Component)value).tag == "Boss")
				{
					GotoPhase(value, phaseIndex);
					if (flag)
					{
						ToastManager.Toast((object)$"Goto Phase {phaseIndex + 1} Name:{((Object)value).name}");
					}
				}
			}
		}

		private bool TryGetMonsterStat(MonsterBase monster, out MonsterStat monsterStat)
		{
			object? obj = (typeof(MonsterBase).GetField("monsterStat") ?? typeof(MonsterBase).GetField("_monsterStat"))?.GetValue(monster);
			monsterStat = (MonsterStat)((obj is MonsterStat) ? obj : null);
			return (Object)(object)monsterStat != (Object)null;
		}

		private void GotoPhase(MonsterBase monster, int phaseIndex)
		{
			monster.PhaseIndex = phaseIndex;
			((Actor)monster).animator.SetInteger(Animator.StringToHash("PhaseIndex"), phaseIndex);
			monster.postureSystem.RestorePosture();
			monster.monsterCore.EnablePushAway();
			monster.monsterCore.DisablePushAway();
			ClearAllAttackSensors(monster);
		}

		private void ClearAllAttackSensors(MonsterBase monster)
		{
			AttackSensor[] attackSensors = GetAttackSensors(monster);
			foreach (AttackSensor obj in attackSensors)
			{
				if (obj != null)
				{
					obj.ClearQueue();
				}
			}
		}

		private AttackSensor[] GetAttackSensors(MonsterBase monster)
		{
			return (AttackSensor[])(((object)((typeof(MonsterBase).GetField("attackSensors", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeof(MonsterBase).GetField("_attackSensors", BindingFlags.Instance | BindingFlags.NonPublic))?.GetValue(monster) as AttackSensor[])) ?? ((object)new AttackSensor[0]));
		}

		[AsyncStateMachine(typeof(<CyclePhases>d__26))]
		private UniTaskVoid CyclePhases()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			<CyclePhases>d__26 <CyclePhases>d__ = default(<CyclePhases>d__26);
			<CyclePhases>d__.<>t__builder = AsyncUniTaskVoidMethodBuilder.Create();
			<CyclePhases>d__.<>4__this = this;
			<CyclePhases>d__.<>1__state = -1;
			((AsyncUniTaskVoidMethodBuilder)(ref <CyclePhases>d__.<>t__builder)).Start<<CyclePhases>d__26>(ref <CyclePhases>d__);
			return ((AsyncUniTaskVoidMethodBuilder)(ref <CyclePhases>d__.<>t__builder)).Task;
		}

		private void TogglePhaseCycle(bool enable)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (enable && !isCyclingPhases)
			{
				phaseCycleCancellationTokenSource?.Cancel();
				phaseCycleCancellationTokenSource = new CancellationTokenSource();
				UniTaskVoid val = CyclePhases();
				((UniTaskVoid)(ref val)).Forget();
			}
			else if (!enable && isCyclingPhases)
			{
				phaseCycleCancellationTokenSource?.Cancel();
				isCyclingPhases = false;
			}
		}

		private void StopPhaseCycle()
		{
			if (phaseCycleCancellationTokenSource != null)
			{
				phaseCycleCancellationTokenSource.Cancel();
				isCyclingPhases = false;
			}
		}

		private void OnDestroy()
		{
			StopPhaseCycle();
			mainHarmony.UnpatchSelf();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"GodModeBoss plugin unpatched.");
		}
	}
	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
	{
		[HarmonyPatch(typeof(PlayerAbilityData), "CanUseCheck")]
		[HarmonyPrefix]
		private static bool PatchCanUseCheck(ref PlayerAbilityData __instance, ref object effectProvider)
		{
			if (((Object)__instance).name.Contains("Revive Jade"))
			{
				GodModeBoss instance = GodModeBoss.Instance;
				if (instance != null && instance.isReviveJade?.Value == true)
				{
					return false;
				}
			}
			return true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "GodModeBoss";

		public const string PLUGIN_NAME = "GodModeBoss";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}