Decompiled source of VoidFiendBeam v2.5.0

BepInEx/plugins/Voidfiendbeam.dll

Decompiled 14 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.VoidSurvivor.Weapon;
using On.EntityStates.VoidSurvivor.Weapon;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Voidfiendbeam")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+16c9ea0c5bae6252d66a4714973faed6215f62cb")]
[assembly: AssemblyProduct("Voidfiendbeam")]
[assembly: AssemblyTitle("Voidfiendbeam")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace VoidFiendBeam
{
	[BepInPlugin("com.YourName.VoidFiendBeam", "Void Fiend Beam", "2.3.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class VoidFiendBeam : BaseUnityPlugin
	{
		public static ConfigEntry<float> BeamRange;

		public static ConfigEntry<float> BeamVfxXScale;

		public static ConfigEntry<float> BeamVfxYScale;

		public static ConfigEntry<float> BeamVfxZScale;

		public static ConfigEntry<bool> LazerBeamModeRegular;

		public static ConfigEntry<bool> LazerBeamModeCorrupt;

		public static ConfigEntry<bool> EnableDebugLogging;

		public static ConfigEntry<float> VfxSurfaceOffset;

		public static ManualLogSource StaticLogger;

		public static bool isCorruptHandBeamActive;

		public static bool isRegularHandBeamActive;

		private static bool LaserModeEnabledForRegular => LazerBeamModeRegular.Value;

		private static bool LaserModeEnabledForCorrupt => LazerBeamModeCorrupt.Value;

		public void Awake()
		{
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Expected O, but got Unknown
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Expected O, but got Unknown
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Expected O, but got Unknown
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Expected O, but got Unknown
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Expected O, but got Unknown
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Expected O, but got Unknown
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Expected O, but got Unknown
			StaticLogger = ((BaseUnityPlugin)this).Logger;
			BeamRange = ((BaseUnityPlugin)this).Config.Bind<float>("Beam Settings", "Beam Range", 75f, "The effective range of the Corrupt Hand Beam. Base game default is 40.");
			BeamVfxXScale = ((BaseUnityPlugin)this).Config.Bind<float>("Beam Settings", "Beam VFX Width Scale", 1f, "The scale of the beam's visual effects (VFX) on the X-axis. Base game default is 1.");
			BeamVfxYScale = ((BaseUnityPlugin)this).Config.Bind<float>("Beam Settings", "Beam VFX Height Scale", 1f, "The scale of the beam's visual effects (VFX) on the Y-axis. Base game default is 1.");
			BeamVfxZScale = ((BaseUnityPlugin)this).Config.Bind<float>("Beam Settings", "Beam VFX Length Scale", 3.25f, "The scale of the beam's visual effects (VFX) on the Z-axis. Base game default is 1.");
			LazerBeamModeRegular = ((BaseUnityPlugin)this).Config.Bind<bool>("Laser Mode", "Enable Laser Mode (Regular Beam)", false, "Eliminates randomization for the regular hand beam, making it behave like a precise laser.");
			LazerBeamModeCorrupt = ((BaseUnityPlugin)this).Config.Bind<bool>("Laser Mode", "Enable Laser Mode (Corrupt Beam)", false, "Eliminates randomization for the corrupt hand beam, making it behave like a precise laser.");
			EnableDebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Enable Debug Logging", false, "Enable detailed logging for troubleshooting.");
			VfxSurfaceOffset = ((BaseUnityPlugin)this).Config.Bind<float>("VFX Settings", "Surface Offset", 0.2f, "How far to push VFX out from terrain surfaces to prevent clipping. Base: 0.2");
			ModSettingsManager.AddOption((BaseOption)new SliderOption(BeamVfxXScale, new SliderConfig
			{
				min = 0.1f,
				max = 20f,
				FormatString = "{0:0.0}"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(BeamVfxYScale, new SliderConfig
			{
				min = 0.1f,
				max = 20f,
				FormatString = "{0:0.0}"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(BeamVfxZScale, new SliderConfig
			{
				min = 0.1f,
				max = 20f,
				FormatString = "{0:0.0}"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(BeamRange, new SliderConfig
			{
				min = 10f,
				max = 300f,
				FormatString = "{0:0}"
			}));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(LazerBeamModeRegular));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(LazerBeamModeCorrupt));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(EnableDebugLogging));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(VfxSurfaceOffset, new SliderConfig
			{
				min = 0f,
				max = 1f,
				FormatString = "{0:0.00}"
			}));
			SetModIcon();
			ApplyMMHookPatches();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Void Fiend Beam has awakened with Enhanced Laser Mode (MMHook version)!");
		}

		private void SetModIcon()
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string text = null;
				string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
				foreach (string text2 in manifestResourceNames)
				{
					if (text2.EndsWith("icon.png", StringComparison.OrdinalIgnoreCase))
					{
						text = text2;
						break;
					}
				}
				if (text == null)
				{
					return;
				}
				using Stream stream = executingAssembly.GetManifestResourceStream(text);
				if (stream == null)
				{
					return;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val, array))
				{
					return;
				}
				Sprite modIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
				try
				{
					ModSettingsManager.SetModIcon(modIcon);
					((BaseUnityPlugin)this).Logger.LogInfo((object)"VoidFiendBeam: Mod icon set successfully via SetModIcon().");
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("VoidFiendBeam: ModSettingsManager.SetModIcon failed: " + ex.Message));
				}
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("VoidFiendBeam: failed to load mod icon: " + ex2.Message));
			}
		}

		private void ApplyMMHookPatches()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			try
			{
				CharacterBody.AddSpreadBloom += new hook_AddSpreadBloom(DisableBloomAccumulation_Hook);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ Bloom elimination hook applied");
				BulletAttack.Fire += new hook_Fire(BulletAttack_Fire_Hook);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ BulletAttack Fire hook applied");
				FireCorruptHandBeam.OnEnter += new hook_OnEnter(FireCorruptHandBeam_OnEnter_Tracking);
				FireCorruptHandBeam.OnExit += new hook_OnExit(FireCorruptHandBeam_OnExit_Tracking);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ Corrupt hand beam tracking hooks applied");
				FireHandBeam.OnEnter += new hook_OnEnter(FireHandBeam_OnEnter_Tracking);
				FireHandBeam.OnExit += new hook_OnExit(FireHandBeam_OnExit_Tracking);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ Regular hand beam tracking hooks applied");
				FireCorruptHandBeam.OnEnter += new hook_OnEnter(FireCorruptHandBeam_OnEnter_Modifications);
				FireCorruptHandBeam.FireBullet += new hook_FireBullet(FireCorruptHandBeam_FireBullet_Hook);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ Corrupt hand beam modification hooks applied");
				((BaseUnityPlugin)this).Logger.LogInfo((object)"\ud83c\udfaf All MMHook patches applied successfully!");
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"❌ Failed to apply MMHook patches: {arg}");
			}
		}

		private void DisableBloomAccumulation_Hook(orig_AddSpreadBloom orig, CharacterBody self, float bloom)
		{
			//IL_0027: 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)
			if (((LaserModeEnabledForCorrupt && isCorruptHandBeamActive) || (LaserModeEnabledForRegular && isRegularHandBeamActive)) && self.bodyIndex == BodyCatalog.FindBodyIndex("VoidSurvivorBody"))
			{
				if (EnableDebugLogging.Value)
				{
					StaticLogger.LogInfo((object)$"\ud83c\udfaf BLOCKING bloom during active HandBeam ({bloom})");
				}
			}
			else
			{
				orig.Invoke(self, bloom);
			}
		}

		private void BulletAttack_Fire_Hook(orig_Fire orig, BulletAttack self)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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)
			if ((Object)(object)self.owner != (Object)null)
			{
				CharacterBody component = self.owner.GetComponent<CharacterBody>();
				if ((Object)(object)component != (Object)null && component.bodyIndex == BodyCatalog.FindBodyIndex("VoidSurvivorBody"))
				{
					HitCallback originalCallback = self.hitCallback;
					self.hitCallback = (HitCallback)delegate(BulletAttack attack, ref BulletHit hitInfo)
					{
						//IL_0032: 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_0060: Unknown result type (might be due to invalid IL or missing references)
						//IL_006f: Unknown result type (might be due to invalid IL or missing references)
						//IL_0074: Unknown result type (might be due to invalid IL or missing references)
						//IL_0079: Unknown result type (might be due to invalid IL or missing references)
						//IL_009b: Unknown result type (might be due to invalid IL or missing references)
						//IL_009e: Unknown result type (might be due to invalid IL or missing references)
						//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
						if ((Object)(object)hitInfo.collider == (Object)null)
						{
							HitCallback obj = originalCallback;
							return obj == null || obj.Invoke(attack, ref hitInfo);
						}
						bool flag = (LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.world)).mask) & (1 << ((Component)hitInfo.collider).gameObject.layer)) != 0;
						Vector3 val = hitInfo.point + hitInfo.surfaceNormal * VfxSurfaceOffset.Value;
						if (flag)
						{
							if ((Object)(object)attack.hitEffectPrefab != (Object)null)
							{
								EffectManager.SimpleEffect(attack.hitEffectPrefab, val, Quaternion.LookRotation(hitInfo.surfaceNormal), true);
							}
							return false;
						}
						HitCallback obj2 = originalCallback;
						return obj2 == null || obj2.Invoke(attack, ref hitInfo);
					};
					self.hitMask = LayerMask.op_Implicit(LayerMask.op_Implicit(self.hitMask) | LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.world)).mask));
					if ((LaserModeEnabledForCorrupt && isCorruptHandBeamActive) || (LaserModeEnabledForRegular && isRegularHandBeamActive))
					{
						self.minSpread = 0f;
						self.maxSpread = 0f;
					}
				}
			}
			orig.Invoke(self);
		}

		private void FireCorruptHandBeam_OnEnter_Tracking(orig_OnEnter orig, FireCorruptHandBeam self)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!LaserModeEnabledForCorrupt)
			{
				return;
			}
			CharacterBody characterBody = ((EntityState)self).characterBody;
			if (!((Object)(object)characterBody != (Object)null) || characterBody.bodyIndex != BodyCatalog.FindBodyIndex("VoidSurvivorBody"))
			{
				return;
			}
			VoidSurvivorController component = ((Component)characterBody).GetComponent<VoidSurvivorController>();
			if ((Object)(object)component != (Object)null && component.isCorrupted)
			{
				isCorruptHandBeamActive = true;
				if (EnableDebugLogging.Value)
				{
					StaticLogger.LogInfo((object)"\ud83d\udfe2 Corrupt FireHandBeam STARTED");
				}
			}
		}

		private void FireCorruptHandBeam_OnExit_Tracking(orig_OnExit orig, FireCorruptHandBeam self)
		{
			orig.Invoke(self);
			if (isCorruptHandBeamActive)
			{
				isCorruptHandBeamActive = false;
				if (EnableDebugLogging.Value)
				{
					StaticLogger.LogInfo((object)"\ud83d\udd34 Corrupt FireHandBeam ENDED");
				}
			}
		}

		private void FireHandBeam_OnEnter_Tracking(orig_OnEnter orig, FireHandBeam self)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (LaserModeEnabledForRegular)
			{
				CharacterBody characterBody = ((EntityState)self).characterBody;
				if ((Object)(object)characterBody != (Object)null && characterBody.bodyIndex == BodyCatalog.FindBodyIndex("VoidSurvivorBody"))
				{
					VoidSurvivorController component = ((Component)characterBody).GetComponent<VoidSurvivorController>();
					if ((Object)(object)component != (Object)null && !component.isCorrupted && !isRegularHandBeamActive)
					{
						isRegularHandBeamActive = true;
						if (EnableDebugLogging.Value)
						{
							StaticLogger.LogInfo((object)"\ud83d\udfe2 Regular FireHandBeam STARTED (Pre-Bloom)");
						}
					}
				}
			}
			orig.Invoke(self);
		}

		private void FireHandBeam_OnExit_Tracking(orig_OnExit orig, FireHandBeam self)
		{
			orig.Invoke(self);
			if (LaserModeEnabledForRegular && isRegularHandBeamActive)
			{
				isRegularHandBeamActive = false;
				if (EnableDebugLogging.Value)
				{
					StaticLogger.LogInfo((object)"\ud83d\udd34 Regular FireHandBeam ENDED");
				}
			}
		}

		private void FireCorruptHandBeam_OnEnter_Modifications(orig_OnEnter orig, FireCorruptHandBeam self)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody characterBody = ((EntityState)self).characterBody;
			if ((Object)(object)characterBody != (Object)null && characterBody.bodyIndex == BodyCatalog.FindBodyIndex("VoidSurvivorBody"))
			{
				VoidSurvivorController component = ((Component)characterBody).GetComponent<VoidSurvivorController>();
				if ((Object)(object)component != (Object)null && component.isCorrupted)
				{
					self.maxDistance = BeamRange.Value;
					if ((Object)(object)self.beamVfxPrefab != (Object)null)
					{
						VoidFiendVFXBeam.ScaleBeamVFX(self.beamVfxPrefab, BeamVfxXScale.Value, BeamVfxYScale.Value, BeamVfxZScale.Value);
					}
				}
			}
			orig.Invoke(self);
		}

		private void FireCorruptHandBeam_FireBullet_Hook(orig_FireBullet orig, FireCorruptHandBeam self)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody characterBody = ((EntityState)self).characterBody;
			if ((Object)(object)characterBody != (Object)null && characterBody.bodyIndex == BodyCatalog.FindBodyIndex("VoidSurvivorBody"))
			{
				VoidSurvivorController component = ((Component)characterBody).GetComponent<VoidSurvivorController>();
				if ((Object)(object)component != (Object)null && component.isCorrupted)
				{
					self.minDistance = self.maxDistance;
				}
			}
			orig.Invoke(self);
		}
	}
	public static class VoidFiendVFXBeam
	{
		public static void ScaleBeamVFX(GameObject beamVfxPrefab, float newVfxXScale, float newVfxYScale, float newVfxZScale)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)beamVfxPrefab == (Object)null))
			{
				beamVfxPrefab.transform.localScale = new Vector3(newVfxXScale, newVfxYScale, newVfxZScale);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}