Decompiled source of FlashlightToggle v1.5.0

FlashlightToggle.dll

Decompiled 5 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.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[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("Control")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f52c854f4eaa270088fff99ac87504ddad49aa16")]
[assembly: AssemblyProduct("Control")]
[assembly: AssemblyTitle("Control")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 Control
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Control";

		public const string PLUGIN_NAME = "Control";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Flashlight
{
	public class FlashButton : LcInputActions
	{
		[InputAction("<Keyboard>/f", Name = "Flashlight")]
		public InputAction FlashKey { get; set; }
	}
	[BepInPlugin("rr.Flashlight", "Flashlight", "1.5.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource logSource;

		internal static FlashButton InputActionInstance = new FlashButton();

		private Harmony _harmony = new Harmony("Flashlight");

		private void Awake()
		{
			_harmony.PatchAll(typeof(Plugin));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"------Flashlight done.------");
			logSource = ((BaseUnityPlugin)this).Logger;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
		[HarmonyPostfix]
		public static void ClearFlashlight(PlayerControllerB __instance)
		{
			__instance.pocketedFlashlight = null;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		public static void ReadInput(PlayerControllerB __instance)
		{
			if (((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer) || __instance.inTerminalMenu || __instance.isTypingChat || !Application.isFocused)
			{
				return;
			}
			if (__instance.currentlyHeldObjectServer is FlashlightItem && (Object)(object)__instance.currentlyHeldObjectServer != (Object)(object)__instance.pocketedFlashlight)
			{
				__instance.pocketedFlashlight = __instance.currentlyHeldObjectServer;
			}
			if ((Object)(object)__instance.pocketedFlashlight == (Object)null || !InputActionInstance.FlashKey.triggered || !(__instance.pocketedFlashlight is FlashlightItem) || !__instance.pocketedFlashlight.isHeld)
			{
				return;
			}
			try
			{
				__instance.pocketedFlashlight.UseItemOnClient(true);
				if (!(__instance.currentlyHeldObjectServer is FlashlightItem))
				{
					GrabbableObject pocketedFlashlight = __instance.pocketedFlashlight;
					((Behaviour)((FlashlightItem)((pocketedFlashlight is FlashlightItem) ? pocketedFlashlight : null)).flashlightBulbGlow).enabled = false;
					GrabbableObject pocketedFlashlight2 = __instance.pocketedFlashlight;
					((Behaviour)((FlashlightItem)((pocketedFlashlight2 is FlashlightItem) ? pocketedFlashlight2 : null)).flashlightBulb).enabled = false;
					GrabbableObject pocketedFlashlight3 = __instance.pocketedFlashlight;
					if (((pocketedFlashlight3 is FlashlightItem) ? pocketedFlashlight3 : null).isBeingUsed)
					{
						((Behaviour)__instance.helmetLight).enabled = true;
						GrabbableObject pocketedFlashlight4 = __instance.pocketedFlashlight;
						((FlashlightItem)((pocketedFlashlight4 is FlashlightItem) ? pocketedFlashlight4 : null)).usingPlayerHelmetLight = true;
						GrabbableObject pocketedFlashlight5 = __instance.pocketedFlashlight;
						((FlashlightItem)((pocketedFlashlight5 is FlashlightItem) ? pocketedFlashlight5 : null)).PocketFlashlightServerRpc(true);
					}
					else
					{
						((Behaviour)__instance.helmetLight).enabled = false;
						GrabbableObject pocketedFlashlight6 = __instance.pocketedFlashlight;
						((FlashlightItem)((pocketedFlashlight6 is FlashlightItem) ? pocketedFlashlight6 : null)).usingPlayerHelmetLight = false;
						GrabbableObject pocketedFlashlight7 = __instance.pocketedFlashlight;
						((FlashlightItem)((pocketedFlashlight7 is FlashlightItem) ? pocketedFlashlight7 : null)).PocketFlashlightServerRpc(false);
					}
				}
			}
			catch
			{
			}
		}
	}
}