Decompiled source of MauriceBeamLaser v1.0.0

MauriceBeamLaser.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[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("MauriceBeamLaser")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Maurice Beam Laser")]
[assembly: AssemblyTitle("MauriceBeamLaser")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 MauriceBeamLaser
{
	[BepInPlugin("ultrakill.mauricebeamlaser", "Maurice Beam Laser", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("com.Vhellreap1.mauricebeamlaser").PatchAll();
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin ultrakill.mauricebeamlaser is loaded!");
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)4;
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ultrakill.mauricebeamlaser";

		public const string PLUGIN_NAME = "Maurice Beam Laser";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MauriceBeamLaserMod
{
	[HarmonyPatch(typeof(MaliciousFace), "Start")]
	public static class MaliciousFaceStartPatch
	{
		private static void Postfix(MaliciousFace __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<MauriceLaser>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<MauriceLaser>();
			}
		}
	}
	public class MauriceLaser : MonoBehaviour
	{
		private const bool ShowWhileCharging = true;

		private const float MaxLaserDistance = 200f;

		private const float LaserWidth = 0.1f;

		private static readonly Color LaserColor = ParseColor("#fab534");

		private static readonly FieldInfo CurrentChargeEffectField = AccessTools.Field(typeof(MaliciousFace), "currentCE");

		private static readonly FieldInfo ChargeEndedField = AccessTools.Field(typeof(MaliciousFace), "chargeEnded");

		private static readonly FieldInfo BeamFiringField = AccessTools.Field(typeof(MaliciousFace), "beamFiring");

		private static readonly FieldInfo PredictedPosField = AccessTools.Field(typeof(MaliciousFace), "predictedPlayerPos");

		private MaliciousFace face;

		private EnemyIdentifier eid;

		private LineRenderer line;

		private static Color ParseColor(string hex)
		{
			//IL_0012: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Color val = default(Color);
			return ColorUtility.TryParseHtmlString(hex, ref val) ? val : Color.yellow;
		}

		private void Awake()
		{
			face = ((Component)this).GetComponent<MaliciousFace>();
			eid = ((Component)this).GetComponent<EnemyIdentifier>();
			if (CurrentChargeEffectField == null || ChargeEndedField == null || BeamFiringField == null || PredictedPosField == null)
			{
				Debug.LogError((object)"[MauriceBeamLaser] MaliciousFace files not found.");
				((Behaviour)this).enabled = false;
			}
			else
			{
				CreateLine();
			}
		}

		private void CreateLine()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			GameObject val = new GameObject("MauriceBeamLaser_Line");
			val.transform.SetParent(((Component)this).transform, false);
			line = val.AddComponent<LineRenderer>();
			line.useWorldSpace = true;
			line.positionCount = 2;
			line.startWidth = 0.1f;
			line.endWidth = 0.1f;
			line.startColor = LaserColor;
			line.endColor = LaserColor;
			((Renderer)line).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)line).receiveShadows = false;
			((Renderer)line).enabled = false;
			Shader val2 = Shader.Find("Sprites/Default");
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = Shader.Find("UI/Default");
			}
			if ((Object)(object)val2 != (Object)null)
			{
				((Renderer)line).material = new Material(val2);
			}
			else
			{
				Debug.LogWarning((object)"[MauriceBeamLaser] Error: No shader found.");
			}
		}

		private void OnDisable()
		{
			if ((Object)(object)line != (Object)null)
			{
				((Renderer)line).enabled = false;
			}
		}

		private void LateUpdate()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_005c: 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_0060: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0099: 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)
			if (!ShouldShow(out var locked))
			{
				((Renderer)line).enabled = false;
				return;
			}
			Transform mouth = face.mouth;
			Vector3 position = mouth.position;
			Vector3 val = mouth.forward;
			if (locked)
			{
				Vector3 val2 = (Vector3)PredictedPosField.GetValue(face);
				Vector3 val3 = val2 - position;
				if (((Vector3)(ref val3)).sqrMagnitude > 0.0001f && Vector3.Angle(val3, mouth.forward) <= 20f)
				{
					val = ((Vector3)(ref val3)).normalized;
				}
			}
			Vector3 val4 = position + val * 200f;
			RaycastHit val5 = default(RaycastHit);
			if (Physics.Raycast(position, val, ref val5, 200f, LayerMask.op_Implicit(LayerMaskDefaults.Get((LMD)1))))
			{
				val4 = ((RaycastHit)(ref val5)).point;
			}
			line.SetPosition(0, position);
			line.SetPosition(1, val4);
			((Renderer)line).enabled = true;
		}

		private bool ShouldShow(out bool locked)
		{
			locked = false;
			if ((Object)(object)face == (Object)null || (Object)(object)face.mouth == (Object)null || (Object)(object)eid == (Object)null || eid.dead)
			{
				return false;
			}
			object? value = CurrentChargeEffectField.GetValue(face);
			GameObject val = (GameObject)((value is GameObject) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			bool flag = (bool)ChargeEndedField.GetValue(face);
			if ((bool)BeamFiringField.GetValue(face))
			{
				locked = true;
				return true;
			}
			return !flag;
		}
	}
}