Decompiled source of ObjectDropLaser v1.0.1

ObjectDropLaserMod.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ObjectDropLaserMod.Components;
using ObjectDropLaserMod.GrabDetection;
using ObjectDropLaserMod.Patches;
using ObjectDropLaserMod.Systems;
using ObjectDropLaserMod.Utils;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ObjectDropLaserMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4f92da6b47ffa6b5d33569678d54d3aea1dacbe6")]
[assembly: AssemblyProduct("ObjectDropLaserMod")]
[assembly: AssemblyTitle("ObjectDropLaserMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 ObjectDropLaserMod
{
	[BepInPlugin("com.repo.droplaser", "Drop Laser Mod", "1.0.9")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource log;

		public static ConfigEntry<bool> EnableLogging;

		public static ConfigEntry<bool> EnableLaser;

		public static ConfigEntry<bool> UseCustomColor;

		public static ConfigEntry<Color> CustomLaserColor;

		public static ConfigEntry<float> LaserStartWidth;

		public static ConfigEntry<float> LaserEndWidth;

		public static ConfigEntry<float> LaserMaxDistance;

		public static ConfigEntry<float> LaserLightIntensity;

		public static ConfigEntry<float> LaserLightRange;

		public static ConfigEntry<string> ToggleLaserKey;

		public static ConfigEntry<bool> AutoEnableOnGrab;

		private void Awake()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, (string)null);
			log.LogInfo((object)"[DropLaser] Harmony patches applied.");
			EnableLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableLogging", false, "Enable detailed log output (disable for cleaner console)");
			EnableLaser = ((BaseUnityPlugin)this).Config.Bind<bool>("Laser Settings", "EnableLaser", true, "Master toggle for enabling/disabling the laser.");
			UseCustomColor = ((BaseUnityPlugin)this).Config.Bind<bool>("Laser Settings", "UseCustomColor", false, "If true, forces the laser to use a custom color instead of copying the beam's color.");
			CustomLaserColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Laser Settings", "CustomLaserColor", Color.red, "The color the laser will use if UseCustomColor is true.");
			LaserStartWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Laser Settings", "LaserStartWidth", 0.025f, "The width of the laser at its start.");
			LaserEndWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Laser Settings", "LaserEndWidth", 0.005f, "The width of the laser at its end.");
			LaserMaxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Laser Settings", "LaserMaxDistance", 100f, "Maximum distance the laser can scan downward.");
			LaserLightIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Laser Settings", "LaserLightIntensity", 4f, "Intensity (brightness) of the laser glow light.");
			LaserLightRange = ((BaseUnityPlugin)this).Config.Bind<float>("Laser Settings", "LaserLightRange", 0.8f, "Range (radius) of the laser glow light.");
			ToggleLaserKey = ((BaseUnityPlugin)this).Config.Bind<string>("Laser Settings", "ToggleLaserKey", "L", "Key to press for toggling the laser on/off.");
			AutoEnableOnGrab = ((BaseUnityPlugin)this).Config.Bind<bool>("Laser Settings", "AutoEnableOnGrab", false, "If true, the laser will automatically enable when the player grabs an object.");
		}
	}
}
namespace ObjectDropLaserMod.Utils
{
	public static class DropLaserLogger
	{
		public static void Info(string message)
		{
			if (Plugin.EnableLogging.Value)
			{
				Plugin.log.LogInfo((object)"message");
			}
		}

		public static void Warning(string message)
		{
			if (Plugin.EnableLogging.Value)
			{
				Plugin.log.LogWarning((object)message);
			}
		}

		public static void Error(string message)
		{
			Plugin.log.LogError((object)message);
		}
	}
	public static class PhysGrabberAccessors
	{
		private static readonly FieldInfo grabbedObjField = AccessTools.Field(typeof(PhysGrabber), "grabbedPhysGrabObject");

		private static readonly FieldInfo beamField = AccessTools.Field(typeof(PhysGrabber), "physGrabBeam");

		public static PhysGrabObject GetGrabbedObject(this PhysGrabber instance)
		{
			object? value = grabbedObjField.GetValue(instance);
			return (PhysGrabObject)((value is PhysGrabObject) ? value : null);
		}

		public static GameObject GetBeamObject(this PhysGrabber instance)
		{
			object? value = beamField.GetValue(instance);
			return (GameObject)((value is GameObject) ? value : null);
		}
	}
}
namespace ObjectDropLaserMod.Systems
{
	public class DropLaserManager
	{
		private static DropLaserManager _inst;

		private DropLaserController _ctrl;

		public static DropLaserManager Instance => _inst ?? (_inst = new DropLaserManager());

		public void ToggleLaser()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if ((Object)(object)_ctrl == (Object)null)
			{
				GameObject val = new GameObject("DropLaserController");
				_ctrl = val.AddComponent<DropLaserController>();
			}
			_ctrl.Toggle();
		}

		public void ForceDisableLaser()
		{
			if ((Object)(object)_ctrl == (Object)null)
			{
				DropLaserLogger.Info("[DropLaserManager] ForceDisableLaser called but _ctrl is NULL!");
			}
			else if ((Object)(object)((Component)_ctrl).gameObject == (Object)null)
			{
				DropLaserLogger.Info("[DropLaserManager] ForceDisableLaser: _ctrl exists but its GameObject is DESTROYED!");
			}
			else
			{
				DropLaserLogger.Info($"[DropLaserManager] ForceDisableLaser: _ctrl OK. GameObject name: {((Object)((Component)_ctrl).gameObject).name}, Active: {((Component)_ctrl).gameObject.activeSelf}");
			}
			if ((Object)(object)_ctrl != (Object)null)
			{
				_ctrl.DisableLaser();
				DropLaserLogger.Info("[DropLaserManager] Laser force-disabled after item release.");
			}
			else
			{
				DropLaserLogger.Warning("[DropLaserManager] ForceDisableLaser called, but controller was null.");
			}
		}

		public bool HasController()
		{
			if ((Object)(object)_ctrl != (Object)null)
			{
				return (Object)(object)((Component)_ctrl).gameObject != (Object)null;
			}
			return false;
		}
	}
}
namespace ObjectDropLaserMod.Patches
{
	[HarmonyPatch(typeof(PhysGrabber), "Update")]
	public static class DropLaserInputPatch
	{
		private static bool Prefix(PhysGrabber __instance)
		{
			PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
			bool flag = PhotonNetwork.PlayerList.Length < 1;
			if (!flag && (Object)(object)component != (Object)null && !component.IsMine)
			{
				return true;
			}
			if (Input.GetKeyDown(Plugin.ToggleLaserKey.Value.ToLower()))
			{
				DropLaserLogger.Info("[DropLaserInputPatch] Local player pressed L (singleplayer: " + flag + ").");
				DropLaserLogger.Info("[DropLaserInputPatch] Number on PlayerList = ) " + PhotonNetwork.PlayerList.Length);
				if (!GrabDetectionState.IsHoldingObject)
				{
					DropLaserLogger.Info("[DropLaserInputPatch] L pressed but not holding object — ignoring toggle.");
					return false;
				}
				SimulateKeyPress();
			}
			return true;
		}

		public static void SimulateKeyPress()
		{
			DropLaserManager instance = DropLaserManager.Instance;
			if (instance != null)
			{
				instance.ToggleLaser();
			}
			else
			{
				Plugin.log.LogWarning((object)"[DropLaserInputPatch] DropLaserManager instance missing during SimulateKeyPress.");
			}
		}
	}
}
namespace ObjectDropLaserMod.GrabDetection
{
	[HarmonyPatch(typeof(PhysGrabber), "ReleaseObject")]
	public static class DropLaserReleasePatch
	{
		private static void Postfix(PhysGrabber __instance)
		{
			string arg = (((Object)(object)__instance != (Object)null) ? ((Object)__instance).name : "null");
			int num = (((Object)(object)__instance != (Object)null) ? ((Object)__instance).GetInstanceID() : (-1));
			DropLaserLogger.Info($"[DropLaserReleasePatch] ReleaseObject called on PhysGrabber: {arg} (InstanceID: {num})");
			if (DropLaserManager.Instance != null)
			{
				DropLaserLogger.Info("[DropLaserReleasePatch] DropLaserManager.Instance exists. _ctrl == " + (DropLaserManager.Instance.HasController() ? "Alive" : "NULL/DEAD"));
			}
			else
			{
				Plugin.log.LogWarning((object)"[DropLaserReleasePatch] DropLaserManager.Instance is NULL during ReleaseObject!");
			}
			if (DropLaserManager.Instance != null)
			{
				DropLaserManager.Instance.ForceDisableLaser();
				DropLaserLogger.Info("[DropLaserReleasePatch] ForceDisableLaser() called.");
			}
			else
			{
				DropLaserLogger.Info("[DropLaserReleasePatch] DropLaserManager.Instance was null during ReleaseObject!");
			}
		}
	}
	public static class GrabDetectionState
	{
		public static bool IsHoldingObject;
	}
	[HarmonyPatch(typeof(PhysGrabber), "ReleaseObject")]
	public static class GrabReleasePatch
	{
		private static void Postfix(PhysGrabber __instance)
		{
			string arg = (((Object)(object)__instance != (Object)null) ? ((Object)__instance).name : "null");
			int num = (((Object)(object)__instance != (Object)null) ? ((Object)__instance).GetInstanceID() : (-1));
			DropLaserLogger.Info($"[GrabReleasePatch] ReleaseObject called on PhysGrabber: {arg} (InstanceID: {num})");
			GrabDetectionState.IsHoldingObject = false;
			DropLaserLogger.Info("[GrabReleasePatch] IsHoldingObject = false");
		}
	}
	[HarmonyPatch(typeof(PhysGrabber), "RayCheck")]
	public static class GrabStartPatch
	{
		private static void Postfix(PhysGrabber __instance, bool _grab)
		{
			if (_grab && __instance.grabbed)
			{
				GrabDetectionState.IsHoldingObject = true;
				DropLaserLogger.Info("[GrabStartPatch] Grab confirmed — IsHoldingObject = true");
				if (Plugin.AutoEnableOnGrab.Value)
				{
					DropLaserLogger.Info("[GrabStartPatch] Auto-enabling laser due to object grab.");
					DropLaserInputPatch.SimulateKeyPress();
				}
			}
		}
	}
}
namespace ObjectDropLaserMod.Components
{
	public class DropLaserBeam
	{
		private readonly LineRenderer lr;

		private readonly Light laserLight;

		private readonly GameObject beamGO;

		private readonly LineRenderer grabBeamLine;

		private readonly PhysGrabber playerGrabber;

		private readonly HashSet<string> ignoredCartParts;

		public DropLaserBeam(LineRenderer lr, Light laserLight, GameObject beamGO, LineRenderer grabBeamLine, PhysGrabber playerGrabber, HashSet<string> ignoredCartParts)
		{
			this.lr = lr;
			this.laserLight = laserLight;
			this.beamGO = beamGO;
			this.grabBeamLine = grabBeamLine;
			this.playerGrabber = playerGrabber;
			this.ignoredCartParts = ignoredCartParts;
		}

		public void UpdateBeam()
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)playerGrabber == (Object)null || (Object)(object)grabBeamLine == (Object)null || (Object)(object)beamGO == (Object)null)
			{
				Plugin.log.LogWarning((object)"[DropLaser] Critical references lost. Cannot update beam.");
			}
			else
			{
				if ((Object)(object)beamGO == (Object)null || (Object)(object)grabBeamLine == (Object)null || (Object)(object)playerGrabber == (Object)null)
				{
					return;
				}
				Material material = ((Renderer)grabBeamLine).material;
				Material material2 = ((Renderer)lr).material;
				if (material.HasProperty("_MainTex"))
				{
					material2.SetTexture("_MainTex", material.GetTexture("_MainTex"));
				}
				material2.mainTextureOffset = material.mainTextureOffset;
				material2.mainTextureScale = material.mainTextureScale;
				Color finalLaserColor = DropLaserColorManager.GetFinalLaserColor(material);
				lr.startColor = new Color(finalLaserColor.r, finalLaserColor.g, finalLaserColor.b, lr.startColor.a);
				lr.endColor = new Color(finalLaserColor.r, finalLaserColor.g, finalLaserColor.b, lr.endColor.a);
				material2.SetColor("_Color", finalLaserColor);
				material2.shaderKeywords = material.shaderKeywords;
				PhysGrabObject grabbedObject = playerGrabber.GetGrabbedObject();
				if ((Object)(object)grabbedObject == (Object)null)
				{
					((Renderer)lr).enabled = false;
					((Behaviour)laserLight).enabled = false;
					return;
				}
				float num = 0.05f;
				Collider componentInChildren = ((Component)grabbedObject).GetComponentInChildren<Collider>();
				Vector3 val;
				if ((Object)(object)componentInChildren != (Object)null)
				{
					Bounds bounds = componentInChildren.bounds;
					val = ((Bounds)(ref bounds)).center;
					val.y += num;
					val.y -= ((Bounds)(ref bounds)).extents.y;
				}
				else
				{
					val = ((Component)grabbedObject).transform.position;
				}
				Vector3 val2 = val + Vector3.down * 50f;
				RaycastHit[] array = Physics.RaycastAll(val, Vector3.down, Plugin.LaserMaxDistance.Value, -5, (QueryTriggerInteraction)2);
				float num2 = float.MaxValue;
				RaycastHit[] array2 = array;
				for (int i = 0; i < array2.Length; i++)
				{
					RaycastHit val3 = array2[i];
					GameObject gameObject = ((Component)((RaycastHit)(ref val3)).collider).gameObject;
					if (!ignoredCartParts.Contains(((Object)gameObject).name) && !IsPartOfHeldObject(gameObject, ((Component)grabbedObject).gameObject) && ((RaycastHit)(ref val3)).distance < num2)
					{
						num2 = ((RaycastHit)(ref val3)).distance;
						val2 = ((RaycastHit)(ref val3)).point;
					}
				}
				((Renderer)lr).enabled = true;
				lr.SetPosition(0, val);
				lr.SetPosition(1, val2);
				((Component)laserLight).transform.position = val2;
				laserLight.color = new Color(finalLaserColor.r, finalLaserColor.g, finalLaserColor.b, 1f);
				((Behaviour)laserLight).enabled = true;
			}
		}

		private bool IsPartOfHeldObject(GameObject hitObject, GameObject heldObject)
		{
			if ((Object)(object)hitObject == (Object)null || (Object)(object)heldObject == (Object)null)
			{
				return false;
			}
			Transform val = hitObject.transform;
			while ((Object)(object)val != (Object)null)
			{
				if ((Object)(object)((Component)val).gameObject == (Object)(object)heldObject)
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}
	}
	public static class DropLaserColorManager
	{
		public static Color GetFinalLaserColor(Material beamMat)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.UseCustomColor.Value)
			{
				return ClampColor(Plugin.CustomLaserColor.Value);
			}
			Color val = Color.white;
			Color val2 = Color.black;
			if ((Object)(object)beamMat != (Object)null)
			{
				if (beamMat.HasProperty("_Color"))
				{
					val = beamMat.GetColor("_Color");
				}
				if (beamMat.HasProperty("_EmissionColor"))
				{
					val2 = beamMat.GetColor("_EmissionColor");
				}
			}
			return ClampColor(val + val2);
		}

		private static Color ClampColor(Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			color.r = Mathf.Clamp01(color.r);
			color.g = Mathf.Clamp01(color.g);
			color.b = Mathf.Clamp01(color.b);
			color.a = Mathf.Clamp01(color.a);
			return color;
		}
	}
	public class DropLaserController : MonoBehaviour
	{
		private LineRenderer lr;

		private bool active;

		private GameObject beamGO;

		private LineRenderer grabBeamLine;

		private PhysGrabber playerGrabber;

		private Light laserLight;

		private DropLaserBeam laserBeam;

		private static readonly HashSet<string> ignoredCartParts = new HashSet<string> { "In Cart", "Capsule Mid", "Capsule Left", "Capsule Right" };

		private void Awake()
		{
			if (!Plugin.EnableLaser.Value)
			{
				Plugin.log.LogWarning((object)"[DropLaser] Laser system disabled via config. Destroying DropLaserController...");
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			DropLaserLogger.Info("[DropLaser] Awake called");
			SetupLineRenderer();
			SetupLaserLight();
			SceneManager.sceneLoaded += HandleSceneLoaded;
		}

		private void Start()
		{
			DropLaserLogger.Info("[DropLaser] Start called");
			TryFindBeam();
			if ((Object)(object)beamGO != (Object)null && (Object)(object)grabBeamLine != (Object)null && (Object)(object)playerGrabber != (Object)null)
			{
				laserBeam = new DropLaserBeam(lr, laserLight, beamGO, grabBeamLine, playerGrabber, ignoredCartParts);
			}
		}

		private void Update()
		{
			if (active && laserBeam != null)
			{
				laserBeam.UpdateBeam();
			}
		}

		public void Toggle()
		{
			active = !active;
			((Renderer)lr).enabled = active;
			((Behaviour)laserLight).enabled = active;
			DropLaserLogger.Info("[DropLaser] Laser toggled " + (active ? "ON" : "OFF"));
		}

		public void DisableLaser()
		{
			((Renderer)lr).enabled = false;
			((Behaviour)laserLight).enabled = false;
			active = false;
		}

		private void SetupLineRenderer()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			lr = ((Component)this).gameObject.AddComponent<LineRenderer>();
			lr.positionCount = 2;
			Material val = new Material(Shader.Find("Particles/Standard Unlit"));
			val.SetFloat("_Mode", 2f);
			val.SetInt("_SrcBlend", 5);
			val.SetInt("_DstBlend", 10);
			val.SetInt("_ZWrite", 0);
			val.DisableKeyword("_ALPHATEST_ON");
			val.EnableKeyword("_ALPHABLEND_ON");
			val.DisableKeyword("_ALPHAPREMULTIPLY_ON");
			val.renderQueue = 3000;
			((Renderer)lr).material = val;
			lr.startWidth = Plugin.LaserStartWidth.Value;
			lr.endWidth = Plugin.LaserEndWidth.Value;
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(1f, 0f, 0f, 1f);
			lr.startColor = val2;
			lr.endColor = val2;
			((Renderer)lr).enabled = false;
		}

		private void SetupLaserLight()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			laserLight = new GameObject("DropLaserLight").AddComponent<Light>();
			laserLight.type = (LightType)2;
			laserLight.range = Plugin.LaserLightRange.Value;
			laserLight.intensity = Plugin.LaserLightIntensity.Value;
			((Behaviour)laserLight).enabled = false;
		}

		private void TryFindBeam()
		{
			bool flag = PhotonNetwork.PlayerList.Length < 1;
			PhysGrabber[] array = Object.FindObjectsOfType<PhysGrabber>();
			foreach (PhysGrabber val in array)
			{
				PhotonView component = ((Component)val).GetComponent<PhotonView>();
				if (flag)
				{
					playerGrabber = val;
					DropLaserLogger.Info("[DropLaser] Singleplayer detected — attaching to first PhysGrabber.");
					break;
				}
				if ((Object)(object)component != (Object)null && component.IsMine)
				{
					playerGrabber = val;
					DropLaserLogger.Info("[DropLaser] Multiplayer detected — attached to local player's PhysGrabber.");
					break;
				}
			}
			if ((Object)(object)playerGrabber == (Object)null)
			{
				Plugin.log.LogWarning((object)"[DropLaser] Could not find local player's PhysGrabber!");
				return;
			}
			beamGO = playerGrabber.GetBeamObject();
			if ((Object)(object)beamGO != (Object)null)
			{
				DropLaserLogger.Info("[DropLaser] Beam GameObject found!");
				grabBeamLine = beamGO.GetComponent<LineRenderer>();
				if ((Object)(object)grabBeamLine != (Object)null)
				{
					DropLaserLogger.Info("[DropLaser] GrabBeam LineRenderer found!");
				}
				else
				{
					Plugin.log.LogWarning((object)"[DropLaser] GrabBeam has no LineRenderer!");
				}
			}
			else
			{
				Plugin.log.LogWarning((object)"[DropLaser] Beam GameObject is null!");
			}
		}

		private void HandleSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			DropLaserLogger.Info("[DropLaser] New scene loaded — destroying old DropLaserController instance.");
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= HandleSceneLoaded;
			DropLaserLogger.Info("[DropLaser] OnDestroy called — DropLaserController cleaned up.");
		}
	}
}