Decompiled source of NailgunFix v1.0.1

NailgunFix.dll

Decompiled 3 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.Bootstrap;
using BepInEx.Configuration;
using EntityStates;
using EntityStates.Toolbot;
using IL.EntityStates.Toolbot;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.EntityStates.Toolbot;
using RiskyMod.Survivors;
using RiskyMod.Survivors.Toolbot;
using RoR2;
using UnityEngine;

[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("NailgunFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NailgunFix")]
[assembly: AssemblyTitle("NailgunFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace NailgunFix
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.Moffein.NailgunFix", "NailgunFix", "1.0.0")]
	public class NailgunFix : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

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

			public static Func<BulletAttack, BulletAttack> <>9__0_2;

			public static Manipulator <>9__0_0;

			public static hook_OnExit <>9__0_1;

			internal void <Awake>b__0_0(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);
				if (val.TryGotoNext(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchCallvirt<BulletAttack>(x, "Fire")
				}))
				{
					val.EmitDelegate<Func<BulletAttack, BulletAttack>>((Func<BulletAttack, BulletAttack>)delegate(BulletAttack bulletAttack)
					{
						bulletAttack.radius = 0.2f;
						bulletAttack.smartCollision = true;
						return bulletAttack;
					});
				}
				else
				{
					Debug.LogError((object)"NailgunFix: Radius IL Hook failed");
				}
			}

			internal bool <Awake>b__0_3(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallvirt<BulletAttack>(x, "Fire");
			}

			internal BulletAttack <Awake>b__0_2(BulletAttack bulletAttack)
			{
				bulletAttack.radius = 0.2f;
				bulletAttack.smartCollision = true;
				return bulletAttack;
			}

			internal void <Awake>b__0_1(orig_OnExit orig, FireNailgun self)
			{
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: 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)
				orig.Invoke(self);
				if (((BaseSkillState)self).IsKeyDownAuthority() && (!Object.op_Implicit((Object)(object)((EntityState)self).characterBody) || !((EntityState)self).characterBody.isSprinting))
				{
					if (Object.op_Implicit((Object)(object)((EntityState)self).characterBody))
					{
						((EntityState)self).characterBody.SetSpreadBloom(1f, false);
					}
					Ray aimRay = ((BaseState)self).GetAimRay();
					((BaseNailgunState)self).FireBullet(((BaseState)self).GetAimRay(), NailgunFinalBurst.finalBurstBulletCount, BaseNailgunState.spreadPitchScale, BaseNailgunState.spreadYawScale);
					Util.PlaySound(NailgunFinalBurst.burstSound, ((EntityState)self).gameObject);
					if (((EntityState)self).isAuthority)
					{
						float num = NailgunFinalBurst.selfForce * (((EntityState)self).characterMotor.isGrounded ? 0.5f : 1f) * ((EntityState)self).characterMotor.mass;
						((EntityState)self).characterMotor.ApplyForce(((Ray)(ref aimRay)).direction * (0f - num), false, false);
					}
					Util.PlaySound(BaseNailgunState.fireSoundString, ((EntityState)self).gameObject);
					Util.PlaySound(BaseNailgunState.fireSoundString, ((EntityState)self).gameObject);
					Util.PlaySound(BaseNailgunState.fireSoundString, ((EntityState)self).gameObject);
				}
			}
		}

		public void Awake()
		{
			//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_0042: 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)
			//IL_005d: Expected O, but got Unknown
			//IL_005d: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			bool value = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("General", "Fix Shot Radius"), true, new ConfigDescription("Increases shot radius from 0 to 0.2 (same as Commando)", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			bool value2 = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("General", "Fix Burst"), true, new ConfigDescription("Fixes Nailgun Burst not triggering when cancelled by most actions.", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			bool flag = true;
			if (Chainloader.PluginInfos.ContainsKey("com.RiskyLives.RiskyMod"))
			{
				flag = !RiskyModAppliedFix();
			}
			if (!flag)
			{
				Debug.LogError((object)"NailgunFix: RiskyMod already applied fix. Code will not be run.");
				return;
			}
			if (value)
			{
				object obj = <>c.<>9__0_0;
				if (obj == null)
				{
					Manipulator val = 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 val3 = new ILCursor(il);
						if (val3.TryGotoNext(new Func<Instruction, bool>[1]
						{
							(Instruction x) => ILPatternMatchingExt.MatchCallvirt<BulletAttack>(x, "Fire")
						}))
						{
							val3.EmitDelegate<Func<BulletAttack, BulletAttack>>((Func<BulletAttack, BulletAttack>)delegate(BulletAttack bulletAttack)
							{
								bulletAttack.radius = 0.2f;
								bulletAttack.smartCollision = true;
								return bulletAttack;
							});
						}
						else
						{
							Debug.LogError((object)"NailgunFix: Radius IL Hook failed");
						}
					};
					<>c.<>9__0_0 = val;
					obj = (object)val;
				}
				BaseNailgunState.FireBullet += (Manipulator)obj;
			}
			if (!value2)
			{
				return;
			}
			object obj2 = <>c.<>9__0_1;
			if (obj2 == null)
			{
				hook_OnExit val2 = delegate(orig_OnExit orig, FireNailgun self)
				{
					//IL_005e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0063: Unknown result type (might be due to invalid IL or missing references)
					//IL_0066: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d1: 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)
					orig.Invoke(self);
					if (((BaseSkillState)self).IsKeyDownAuthority() && (!Object.op_Implicit((Object)(object)((EntityState)self).characterBody) || !((EntityState)self).characterBody.isSprinting))
					{
						if (Object.op_Implicit((Object)(object)((EntityState)self).characterBody))
						{
							((EntityState)self).characterBody.SetSpreadBloom(1f, false);
						}
						Ray aimRay = ((BaseState)self).GetAimRay();
						((BaseNailgunState)self).FireBullet(((BaseState)self).GetAimRay(), NailgunFinalBurst.finalBurstBulletCount, BaseNailgunState.spreadPitchScale, BaseNailgunState.spreadYawScale);
						Util.PlaySound(NailgunFinalBurst.burstSound, ((EntityState)self).gameObject);
						if (((EntityState)self).isAuthority)
						{
							float num = NailgunFinalBurst.selfForce * (((EntityState)self).characterMotor.isGrounded ? 0.5f : 1f) * ((EntityState)self).characterMotor.mass;
							((EntityState)self).characterMotor.ApplyForce(((Ray)(ref aimRay)).direction * (0f - num), false, false);
						}
						Util.PlaySound(BaseNailgunState.fireSoundString, ((EntityState)self).gameObject);
						Util.PlaySound(BaseNailgunState.fireSoundString, ((EntityState)self).gameObject);
						Util.PlaySound(BaseNailgunState.fireSoundString, ((EntityState)self).gameObject);
					}
				};
				<>c.<>9__0_1 = val2;
				obj2 = (object)val2;
			}
			FireNailgun.OnExit += (hook_OnExit)obj2;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private bool RiskyModAppliedFix()
		{
			return SurvivorsCore.enabled && ToolbotCore.enabled && ToolbotCore.enableNailgunChanges;
		}
	}
}
namespace R2API.Utils
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class ManualNetworkRegistrationAttribute : Attribute
	{
	}
}