Decompiled source of KKA Tweaks v1.0.2

KingKombatArena_Tweaks.dll

Decompiled 7 months ago
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.Configuration;
using EntityStates.CaptainDefenseMatrixItem;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using NS_KingKombatArena;
using NS_KingModUtilities;
using On.EntityStates.CaptainDefenseMatrixItem;
using On.RoR2;
using R2API;
using R2API.Utils;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("KingKombatArena_Tweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KingKombatArena_Tweaks")]
[assembly: AssemblyTitle("KingKombatArena_Tweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace KingKombatArena_Tweaks;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Moffein.KingKombatArena_Tweaks", "KingKombatArena Tweaks", "1.0.2")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[R2APISubmoduleDependency(new string[] { "RecalculateStatsAPI" })]
public class KingKombatArena_Tweaks : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static hook_Start <>9__7_0;

		public static hook_TakeDamage <>9__7_1;

		public static hook_SetStun <>9__7_2;

		public static Func<Instruction, bool> <>9__7_7;

		public static Func<bool, bool> <>9__7_8;

		public static Manipulator <>9__7_3;

		public static StatHookEventHandler <>9__7_4;

		public static hook_DeleteNearbyProjectile <>9__7_5;

		public static hook_RecalculateStats <>9__7_6;

		internal void <Awake>b__7_0(orig_Start orig, Run self)
		{
			orig.Invoke(self);
			duelActive = false;
			((Component)self).gameObject.AddComponent<KombatArenaTracker>();
		}

		internal void <Awake>b__7_1(orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			bool flag2 = false;
			if (NetworkServer.active && duelActive)
			{
				if ((damageInfo.damageType & 0x20) > 0)
				{
					damageInfo.damageType = (DamageType)(damageInfo.damageType & -33);
					flag = true;
				}
				if ((damageInfo.damageType & 0x1000000) > 0)
				{
					damageInfo.damageType = (DamageType)(damageInfo.damageType & -16777217);
					flag2 = true;
				}
			}
			orig.Invoke(self, damageInfo);
			if (NetworkServer.active && !damageInfo.rejected && self.alive && Object.op_Implicit((Object)(object)self.body) && (allowChainStun || !self.body.HasBuff(Buffs.LunarSecondaryRoot)))
			{
				if (flag)
				{
					self.body.AddTimedBuff(Buffs.LunarSecondaryRoot, 1f);
				}
				if (flag2)
				{
					self.body.AddTimedBuff(Buffs.LunarSecondaryRoot, 3f);
				}
			}
		}

		internal void <Awake>b__7_2(orig_SetStun orig, SetStateOnHurt self, float duration)
		{
			if (duelActive)
			{
				CharacterBody component = ((Component)self).gameObject.GetComponent<CharacterBody>();
				if (Object.op_Implicit((Object)(object)component) && (allowChainStun || !component.HasBuff(Buffs.LunarSecondaryRoot)))
				{
					component.AddTimedBuff(Buffs.LunarSecondaryRoot, duration);
					return;
				}
			}
			orig.Invoke(self, duration);
		}

		internal void <Awake>b__7_3(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Buffs), "HiddenInvincibility")
			});
			val.Index += 2;
			val.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool orig) => orig && !duelActive));
		}

		internal bool <Awake>b__7_7(Instruction x)
		{
			return ILPatternMatchingExt.MatchLdsfld(x, typeof(Buffs), "HiddenInvincibility");
		}

		internal bool <Awake>b__7_8(bool orig)
		{
			return orig && !duelActive;
		}

		internal void <Awake>b__7_4(CharacterBody sender, StatHookEventArgs args)
		{
			if (duelActive && sender.HasBuff(Buffs.HiddenInvincibility))
			{
				args.armorAdd += iFrameArmor;
			}
		}

		internal bool <Awake>b__7_5(orig_DeleteNearbyProjectile orig, DefenseMatrixOn self)
		{
			if (!duelActive)
			{
				return orig.Invoke(self);
			}
			return false;
		}

		internal void <Awake>b__7_6(orig_RecalculateStats orig, CharacterBody self)
		{
			orig.Invoke(self);
			if (duelActive)
			{
				self.damage *= damageMult;
			}
		}
	}

	public static bool weakerStun = true;

	public static bool allowChainStun = false;

	public static bool noIFrames = true;

	public static float iFrameArmor = 200f;

	public static float damageMult = 1f;

	public static bool disableMicrobots = true;

	public static bool duelActive = false;

	public void Awake()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//IL_007f: 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_008a: Expected O, but got Unknown
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Expected O, but got Unknown
		//IL_0104: 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_010f: Expected O, but got Unknown
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Expected O, but got Unknown
		ReadConfig();
		object obj = <>c.<>9__7_0;
		if (obj == null)
		{
			hook_Start val = delegate(orig_Start orig, Run self)
			{
				orig.Invoke(self);
				duelActive = false;
				((Component)self).gameObject.AddComponent<KombatArenaTracker>();
			};
			<>c.<>9__7_0 = val;
			obj = (object)val;
		}
		Run.Start += (hook_Start)obj;
		if (weakerStun && Configuration.EnableStunsAndShocksDuringDuels.Value)
		{
			object obj2 = <>c.<>9__7_1;
			if (obj2 == null)
			{
				hook_TakeDamage val2 = delegate(orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo)
				{
					//IL_001a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0021: Unknown result type (might be due to invalid IL or missing references)
					//IL_0023: Invalid comparison between Unknown and I4
					//IL_003d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0047: Unknown result type (might be due to invalid IL or missing references)
					//IL_0049: Invalid comparison between Unknown and I4
					//IL_002c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0033: 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_0054: Unknown result type (might be due to invalid IL or missing references)
					//IL_005e: Unknown result type (might be due to invalid IL or missing references)
					//IL_005f: Unknown result type (might be due to invalid IL or missing references)
					bool flag = false;
					bool flag2 = false;
					if (NetworkServer.active && duelActive)
					{
						if ((damageInfo.damageType & 0x20) > 0)
						{
							damageInfo.damageType = (DamageType)(damageInfo.damageType & -33);
							flag = true;
						}
						if ((damageInfo.damageType & 0x1000000) > 0)
						{
							damageInfo.damageType = (DamageType)(damageInfo.damageType & -16777217);
							flag2 = true;
						}
					}
					orig.Invoke(self, damageInfo);
					if (NetworkServer.active && !damageInfo.rejected && self.alive && Object.op_Implicit((Object)(object)self.body) && (allowChainStun || !self.body.HasBuff(Buffs.LunarSecondaryRoot)))
					{
						if (flag)
						{
							self.body.AddTimedBuff(Buffs.LunarSecondaryRoot, 1f);
						}
						if (flag2)
						{
							self.body.AddTimedBuff(Buffs.LunarSecondaryRoot, 3f);
						}
					}
				};
				<>c.<>9__7_1 = val2;
				obj2 = (object)val2;
			}
			HealthComponent.TakeDamage += (hook_TakeDamage)obj2;
			object obj3 = <>c.<>9__7_2;
			if (obj3 == null)
			{
				hook_SetStun val3 = delegate(orig_SetStun orig, SetStateOnHurt self, float duration)
				{
					if (duelActive)
					{
						CharacterBody component = ((Component)self).gameObject.GetComponent<CharacterBody>();
						if (Object.op_Implicit((Object)(object)component) && (allowChainStun || !component.HasBuff(Buffs.LunarSecondaryRoot)))
						{
							component.AddTimedBuff(Buffs.LunarSecondaryRoot, duration);
							return;
						}
					}
					orig.Invoke(self, duration);
				};
				<>c.<>9__7_2 = val3;
				obj3 = (object)val3;
			}
			SetStateOnHurt.SetStun += (hook_SetStun)obj3;
		}
		if (noIFrames)
		{
			object obj4 = <>c.<>9__7_3;
			if (obj4 == null)
			{
				Manipulator val4 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					ILCursor val8 = new ILCursor(il);
					val8.GotoNext(new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Buffs), "HiddenInvincibility")
					});
					val8.Index += 2;
					val8.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool orig) => orig && !duelActive));
				};
				<>c.<>9__7_3 = val4;
				obj4 = (object)val4;
			}
			HealthComponent.TakeDamage += (Manipulator)obj4;
			object obj5 = <>c.<>9__7_4;
			if (obj5 == null)
			{
				StatHookEventHandler val5 = delegate(CharacterBody sender, StatHookEventArgs args)
				{
					if (duelActive && sender.HasBuff(Buffs.HiddenInvincibility))
					{
						args.armorAdd += iFrameArmor;
					}
				};
				<>c.<>9__7_4 = val5;
				obj5 = (object)val5;
			}
			RecalculateStatsAPI.GetStatCoefficients += (StatHookEventHandler)obj5;
		}
		if (disableMicrobots)
		{
			object obj6 = <>c.<>9__7_5;
			if (obj6 == null)
			{
				hook_DeleteNearbyProjectile val6 = (orig_DeleteNearbyProjectile orig, DefenseMatrixOn self) => !duelActive && orig.Invoke(self);
				<>c.<>9__7_5 = val6;
				obj6 = (object)val6;
			}
			DefenseMatrixOn.DeleteNearbyProjectile += (hook_DeleteNearbyProjectile)obj6;
		}
		object obj7 = <>c.<>9__7_6;
		if (obj7 == null)
		{
			hook_RecalculateStats val7 = delegate(orig_RecalculateStats orig, CharacterBody self)
			{
				orig.Invoke(self);
				if (duelActive)
				{
					self.damage *= damageMult;
				}
			};
			<>c.<>9__7_6 = val7;
			obj7 = (object)val7;
		}
		CharacterBody.RecalculateStats += (hook_RecalculateStats)obj7;
	}

	private void ReadConfig()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_002c: Expected O, but got Unknown
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_0061: Expected O, but got Unknown
		//IL_007b: 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_0096: Expected O, but got Unknown
		//IL_0096: Expected O, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Expected O, but got Unknown
		//IL_00cf: Expected O, but got Unknown
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Expected O, but got Unknown
		//IL_0104: Expected O, but got Unknown
		//IL_011e: 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_013d: Expected O, but got Unknown
		//IL_013d: Expected O, but got Unknown
		weakerStun = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Stuns", "Weaker Stuns"), true, new ConfigDescription("Players can still attack during stuns.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
		allowChainStun = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Stuns", "Allow Chain Stuns"), false, new ConfigDescription("Allow players to be re-stunned while in a stun (requires Weaker Stuns).", (AcceptableValueBase)null, Array.Empty<object>())).Value;
		noIFrames = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("I-Frames", "Disable I-Frames"), true, new ConfigDescription("I-Frames give armor instead.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
		iFrameArmor = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("I-Frames", "I-Frame Armor"), 200f, new ConfigDescription("Armor to give if I-Frames are disabled.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
		disableMicrobots = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("Captain", "Disable Defensive Microbots"), true, new ConfigDescription("Disables Defensive Microbots during duels.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
		damageMult = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Stats", "Damage Multiplier"), 1f, new ConfigDescription("Multiplies player damage during duels.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
	}
}
public class KombatArenaTracker : MonoBehaviour
{
	private float stopwatch = 0f;

	public void FixedUpdate()
	{
		stopwatch += Time.fixedDeltaTime;
		if (!(stopwatch > 1f))
		{
			return;
		}
		stopwatch -= 1f;
		KombatArenaInstance val = KingKombatArenaMainPlugin.AccessCurrentKombatArenaInstance();
		if (val == null)
		{
			return;
		}
		bool duelActive = KingKombatArena_Tweaks.duelActive;
		KingKombatArena_Tweaks.duelActive = ((StateMachine)val.GetKombatArenaStateMachine()).IsInState(typeof(DuelCombatState));
		if (!duelActive || KingKombatArena_Tweaks.duelActive)
		{
			return;
		}
		foreach (CharacterMaster instances in CharacterMaster.instancesList)
		{
			GameObject bodyObject = instances.GetBodyObject();
			if (Object.op_Implicit((Object)(object)bodyObject))
			{
				DotController.RemoveAllDots(bodyObject);
			}
		}
	}
}