Decompiled source of FS AI Fix v1.0.0

FS_AI_Fix.dll

Decompiled 2 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.Logging;
using EntityStates;
using EntityStates.FalseSonBoss;
using IL.EntityStates.FalseSonBoss;
using Logger;
using Microsoft.CodeAnalysis;
using MiscFixes.Modules;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.EntityStates.FalseSonBoss;
using RoR2;
using RoR2.CharacterAI;
using RoR2.ContentManagement;
using RoR2BepInExPack.GameAssetPathsBetter;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FS_AI_Fix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f30d354fd0922a86ba2d0df85e61f42a45e75601")]
[assembly: AssemblyProduct("FS_AI_Fix")]
[assembly: AssemblyTitle("FS_AI_Fix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 Logger
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

		internal static void message(object data)
		{
			_logSource.LogInfo(data);
			if (data != null)
			{
				Chat.AddMessage(data.ToString());
			}
			else
			{
				Chat.AddMessage("Null");
			}
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			message(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}
namespace FS_AI_Fix
{
	[BepInPlugin("Onyx.FS_AI_Fix", "FS_AI_Fix", "1.0.0")]
	public class FS_AI_Fix : BaseUnityPlugin
	{
		public const string PluginGUID = "Onyx.FS_AI_Fix";

		public const string PluginAuthor = "Onyx";

		public const string PluginName = "FS_AI_Fix";

		public const string PluginVersion = "1.0.0";

		public void Awake()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			AssetReferenceT<GameObject> val = new AssetReferenceT<GameObject>(RoR2_DLC2_FalseSonBoss.FalseSonBossMaster_prefab);
			AsyncOperationHandle<GameObject> val2 = AssetAsyncReferenceManager<GameObject>.LoadAsset(val, (AsyncReferenceHandleUnloadType)2);
			val2.Completed += delegate(AsyncOperationHandle<GameObject> x)
			{
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				AISkillDriver[] components3 = x.Result.GetComponents<AISkillDriver>();
				AISkillDriver[] array3 = components3;
				foreach (AISkillDriver val7 in array3)
				{
					switch (val7.customName)
					{
					case "FissureSlam":
						val7.aimType = (AimType)0;
						val7.movementType = (MovementType)0;
						val7.driverUpdateTimerOverride = -1f;
						break;
					case "SwatAwayPlayers":
						val7.driverUpdateTimerOverride = -1f;
						break;
					case "TaintedOffering":
						val7.minDistance = 30f;
						break;
					}
				}
			};
			val = new AssetReferenceT<GameObject>(RoR2_DLC2_FalseSonBoss.FalseSonBossLunarShardMaster_prefab);
			val2 = AssetAsyncReferenceManager<GameObject>.LoadAsset(val, (AsyncReferenceHandleUnloadType)2);
			val2.Completed += delegate(AsyncOperationHandle<GameObject> x)
			{
				AISkillDriver[] components2 = x.Result.GetComponents<AISkillDriver>();
				AISkillDriver[] array2 = components2;
				foreach (AISkillDriver val6 in array2)
				{
					switch (val6.customName)
					{
					case "FissureSlam":
						val6.driverUpdateTimerOverride = -1f;
						break;
					case "SwatAwayPlayers":
						val6.driverUpdateTimerOverride = -1f;
						break;
					case "LunarGaze":
						val6.driverUpdateTimerOverride = 6.7f;
						break;
					}
				}
			};
			val = new AssetReferenceT<GameObject>(RoR2_DLC2_FalseSonBoss.FalseSonBossLunarShardBrokenMaster_prefab);
			val2 = AssetAsyncReferenceManager<GameObject>.LoadAsset(val, (AsyncReferenceHandleUnloadType)2);
			val2.Completed += delegate(AsyncOperationHandle<GameObject> x)
			{
				AISkillDriver[] components = x.Result.GetComponents<AISkillDriver>();
				AISkillDriver[] array = components;
				foreach (AISkillDriver val5 in array)
				{
					switch (val5.customName)
					{
					case "FissureSlam":
						val5.driverUpdateTimerOverride = -1f;
						break;
					case "SwatAwayPlayers":
						val5.driverUpdateTimerOverride = -1f;
						break;
					case "LunarGazePlus":
						val5.driverUpdateTimerOverride = 6.7f;
						break;
					}
				}
			};
			AssetReferenceT<EntityStateConfiguration> val3 = new AssetReferenceT<EntityStateConfiguration>(RoR2_DLC2_FalseSonBoss.EntityStates_FalseSonBoss_CorruptedPathsDash_asset);
			AsyncOperationHandle<EntityStateConfiguration> val4 = AssetAsyncReferenceManager<EntityStateConfiguration>.LoadAsset(val3, (AsyncReferenceHandleUnloadType)2);
			val4.Completed += delegate(AsyncOperationHandle<EntityStateConfiguration> x)
			{
				Extensions.TryModifyFieldValue<float>(x.Result, "damageCoefficient", 0f);
			};
			val3 = new AssetReferenceT<EntityStateConfiguration>(RoR2_DLC2_FalseSonBoss.EntityStates_FalseSonBoss_LunarGazeLeap_asset);
			val4 = AssetAsyncReferenceManager<EntityStateConfiguration>.LoadAsset(val3, (AsyncReferenceHandleUnloadType)2);
			val4.Completed += delegate(AsyncOperationHandle<EntityStateConfiguration> x)
			{
				Extensions.TryModifyFieldValue<float>(x.Result, "duration", 1.5f);
			};
			val3 = new AssetReferenceT<EntityStateConfiguration>(RoR2_DLC2_FalseSonBoss.EntityStates_LunarGazeHoldLeap_asset);
			val4 = AssetAsyncReferenceManager<EntityStateConfiguration>.LoadAsset(val3, (AsyncReferenceHandleUnloadType)2);
			val4.Completed += delegate(AsyncOperationHandle<EntityStateConfiguration> x)
			{
				Extensions.TryModifyFieldValue<float>(x.Result, "duration", 3f);
			};
			CorruptedPathsDash.FixedUpdate += new Manipulator(fixDashDistance);
			CorruptedPathsDash.FixedUpdate += new hook_FixedUpdate(fixDashDrones);
			CorruptedPathsDash.OnEnter += new hook_OnEnter(CorruptedPathsDash_OnEnter);
		}

		private void CorruptedPathsDash_OnEnter(orig_OnEnter orig, CorruptedPathsDash self)
		{
			orig.Invoke(self);
			self.overlapAttack.damage = ((BaseState)self).damageStat * 2f;
		}

		private void fixDashDrones(orig_FixedUpdate orig, CorruptedPathsDash self)
		{
			orig.Invoke(self);
			if (self.inHitPause && self.hitPauseTimer == CorruptedPathsDash.hitPauseDuration / ((BaseState)self).attackSpeedStat)
			{
				self.stopwatch -= ((EntityState)self).GetDeltaTime();
			}
		}

		private void fixDashDistance(ILContext il)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			ILLabel label = null;
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(BaseState), "moveSpeedStat")
			}))
			{
				val.Emit(OpCodes.Pop);
				val.Emit(OpCodes.Ldc_R4, 12f);
			}
			else
			{
				Log.Error("IL Hook failed!");
			}
			val.Index = 0;
			ILLabel val2 = default(ILLabel);
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, typeof(OverlapAttack), "Fire")
			}) && val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref label)
			}) && val.TryGotoPrev((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(CorruptedPathsDash), "inHitPause"),
				(Instruction x) => ILPatternMatchingExt.MatchBrtrue(x, ref val2)
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Func<CorruptedPathsDash, bool>>((Func<CorruptedPathsDash, bool>)shortenDashHitbox);
				val.Emit(OpCodes.Brfalse, (object)label);
			}
			else
			{
				Log.Error("IL Hook failed!");
			}
			static bool shortenDashHitbox(CorruptedPathsDash self)
			{
				if (self.stopwatch > CorruptedPathsDash.dashDuration + CorruptedPathsDash.dashPrepDuration - 0.05f)
				{
					self.stopwatch += ((EntityState)self).GetDeltaTime();
					return false;
				}
				return true;
			}
		}
	}
}