Decompiled source of LaserFix v1.0.0

LaserFix.dll

Decompiled 5 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("LaserFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3fd5b105aed33df0de1dc725ef747f0aa881466d")]
[assembly: AssemblyProduct("LaserFix")]
[assembly: AssemblyTitle("LaserFix")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LaserFix
{
	[BepInPlugin("sodmods.laserfix", "Laser Fix", "1.0.0")]
	public class Plugin : BasePlugin
	{
		internal static ManualLogSource Logger;

		private static int glassMask;

		public override void Load()
		{
			//IL_002e: 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_0058: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			int num = LayerMask.NameToLayer("Transparent");
			glassMask = 1 << ((num >= 0) ? num : 25);
			new Harmony("sodmods.laserfix").PatchAll(typeof(Plugin).Assembly);
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(41, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Laser Fix loaded (window glass on layer ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>((num >= 0) ? num : 25);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
			}
			log.LogInfo(val);
		}

		internal static void StopAtGlass(Transform beam, Transform origin, Light glow)
		{
			//IL_0014: 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)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)beam == (Object)null || (Object)(object)origin == (Object)null)
			{
				return;
			}
			float z = beam.lossyScale.z;
			RaycastHit val = default(RaycastHit);
			if (!(z <= 0.05f) && Physics.Raycast(new Ray(origin.position, origin.forward), ref val, z, glassMask, (QueryTriggerInteraction)2) && IsGlass(((RaycastHit)(ref val)).transform))
			{
				Transform parent = beam.parent;
				beam.parent = null;
				beam.localScale = new Vector3(beam.localScale.x, beam.localScale.y, ((RaycastHit)(ref val)).distance);
				beam.parent = parent;
				if ((Object)(object)glow != (Object)null)
				{
					glow.range = ((RaycastHit)(ref val)).distance;
				}
			}
		}

		private static bool IsGlass(Transform t)
		{
			int num = 0;
			while (num < 3 && (Object)(object)t != (Object)null)
			{
				string name = ((Object)t).name;
				if (name.IndexOf("Window", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Glass", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
				num++;
				t = t.parent;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Toolbox), "HandleLaserBehaviour")]
	internal static class CameraLaserPatch
	{
		private static void Postfix(GameObject laser, Light laserLight)
		{
			try
			{
				if ((Object)(object)laser != (Object)null)
				{
					Plugin.StopAtGlass(laser.transform, laser.transform, laserLight);
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)ex);
			}
		}
	}
	[HarmonyPatch(typeof(LaserGridController), "Update")]
	internal static class LaserGridPatch
	{
		private static void Postfix(LaserGridController __instance)
		{
			try
			{
				if ((Object)(object)__instance != (Object)null && (Object)(object)__instance.laser != (Object)null && (Object)(object)__instance.laserParent != (Object)null)
				{
					Plugin.StopAtGlass(__instance.laser, __instance.laserParent, null);
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)ex);
			}
		}
	}
}