Decompiled source of ScorchWurmFixes v1.0.2

plugins/ScorchWurmFixes.dll

Decompiled a month 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.Scorchling;
using IL.EntityStates.Scorchling;
using Logger;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On;
using On.EntityStates.Scorchling;
using R2API.Utils;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("ItemQualities")]
[assembly: IgnoresAccessChecksTo("ItemQualities.Patcher")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ScorchWurmFixes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+bf65579ca86e259818526ab5c073e02f723be49c")]
[assembly: AssemblyProduct("ScorchWurmFixes")]
[assembly: AssemblyTitle("ScorchWurmFixes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 MonoDetour.HookGen
{
	internal static class DefaultMonoDetourManager
	{
		internal static MonoDetourManager Instance { get; } = New();

		internal static MonoDetourManager New()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			return new MonoDetourManager(typeof(DefaultMonoDetourManager).Assembly.GetName().Name);
		}
	}
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
	internal class MonoDetourTargetsAttribute(Type? targetType = null) : Attribute(), IMonoDetourTargets
	{
		public Type? TargetType { get; } = targetType;

		public bool IncludeNestedTypes { get; set; } = true;

		public string[]? Members { get; set; }

		public string[]? MemberNamePrefixes { get; set; }

		public string[]? MemberNameSuffixes { get; set; }

		public bool GenerateControlFlowVariants { get; set; }
	}
}
namespace ScorchWurmFixes
{
	[BepInPlugin("Onyx.ScorchWurmFixes", "ScorchWurmFixes", "1.0.2")]
	public class ScorchWurmFixes : BaseUnityPlugin
	{
		public const string PluginGUID = "Onyx.ScorchWurmFixes";

		public const string PluginAuthor = "Onyx";

		public const string PluginName = "ScorchWurmFixes";

		public const string PluginVersion = "1.0.2";

		private static Vector3 detectionBounds = new Vector3(0.3f, 2.5f, 0.3f);

		private static Vector3 yOffset = Vector3.up * (detectionBounds.y + 0.5f);

		public void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			AsyncOperationHandle<GameObject> val = AssetAsyncReferenceManager<GameObject>.LoadAsset(new AssetReferenceT<GameObject>(RoR2_DLC2_Scorchling.ScorchlingMaster_prefab), (AsyncReferenceHandleUnloadType)2);
			val.Completed += delegate(AsyncOperationHandle<GameObject> x)
			{
				AISkillDriver[] components = x.Result.GetComponents<AISkillDriver>();
				foreach (AISkillDriver val2 in components)
				{
					if (val2.customName == "Breach")
					{
						((Behaviour)val2).enabled = false;
					}
					if (val2.customName == "ChaseOffNodegraph")
					{
						((Behaviour)val2).enabled = false;
					}
					if (val2.customName == "ChaseOffNodegraphClose")
					{
						val2.maxDistance = 70f;
					}
					if (val2.customName == "FollowNodeGraphToTarget")
					{
						val2.minDistance = 0f;
						val2.driverUpdateTimerOverride = 1f;
					}
				}
			};
			val = AssetAsyncReferenceManager<GameObject>.LoadAsset(new AssetReferenceT<GameObject>(RoR2_DLC2_Scorchling.ScorchlingBody_prefab), (AsyncReferenceHandleUnloadType)2);
			val.Completed += delegate(AsyncOperationHandle<GameObject> x)
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				Transform val2 = x.Result.transform.Find("BurrowedEnemyDetection");
				if (Object.op_Implicit((Object)(object)val2))
				{
					((Component)val2).transform.localScale = new Vector3(4f, 20f, 4f);
					((Component)val2).transform.position = new Vector3(0f, 10f, 0f);
				}
			};
			ScorchlingBreach.OnEnter += new hook_OnEnter(ScorchlingBreach_OnEnter);
			ScorchlingBreach.OnEnter += new Manipulator(IL_ScorchlingBreach_OnEnter);
			EnemyDetection.OnTriggerEnter += new hook_OnTriggerEnter(EnemyDetection_OnTriggerEnter);
		}

		private void EnemyDetection_OnTriggerEnter(orig_OnTriggerEnter orig, EnemyDetection self, Collider other)
		{
			orig.Invoke(self, other);
			BaseAI val = default(BaseAI);
			if (((Component)self.stateMachine).TryGetComponent<BaseAI>(ref val))
			{
				val.SetCustomTargetGameObject(((Component)other).gameObject);
			}
		}

		private void IL_ScorchlingBreach_OnEnter(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(ScorchlingBreach), "enemyCBody"),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)Reflection.GetPropertyGetter(typeof(CharacterBody), "footPosition")),
				(Instruction x) => ILPatternMatchingExt.MatchStfld(x, typeof(ScorchlingBreach), "breachPosition")
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Action<ScorchlingBreach>>((Action<ScorchlingBreach>)disableTeleport);
			}
			else
			{
				Log.Error(((MemberReference)il.Method).Name + "Failed to find patch location");
			}
			static void disableTeleport(ScorchlingBreach self)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				self.breachPosition = ((EntityState)self).characterBody.footPosition;
			}
		}

		private void ScorchlingBreach_OnEnter(orig_OnEnter orig, ScorchlingBreach self)
		{
			//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)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			BaseAI val = default(BaseAI);
			ScorchlingController val2 = default(ScorchlingController);
			if (Physics.CheckBox(((EntityState)self).characterBody.footPosition + yOffset, detectionBounds, Quaternion.identity, LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.world)).mask)) && Object.op_Implicit((Object)(object)((EntityState)self).characterBody) && Object.op_Implicit((Object)(object)((EntityState)self).characterBody.master) && ((Component)((EntityState)self).characterBody.master).TryGetComponent<BaseAI>(ref val) && ((Component)((EntityState)self).characterBody).TryGetComponent<ScorchlingController>(ref val2))
			{
				((EntityState)self).outer.SetNextStateToMain();
				AISkillDriver val3 = null;
				AISkillDriver[] components = ((Component)((EntityState)self).characterBody.master).GetComponents<AISkillDriver>();
				foreach (AISkillDriver val4 in components)
				{
					if (val4.customName == "FollowNodeGraphToTarget")
					{
						val3 = val4;
					}
				}
				if (Object.op_Implicit((Object)(object)val3))
				{
					SkillDriverEvaluation? val5 = val.EvaluateSingleSkillDriver(ref val.skillDriverEvaluation, val3, 1f);
					if (val5.HasValue)
					{
						Log.Info("yay");
						val.BeginSkillDriver(val5.Value);
						val2.enemyDetection.Enable();
					}
				}
			}
			else
			{
				orig.Invoke(self);
			}
		}
	}
}
namespace Logger
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

		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)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}