Decompiled source of greatestmod v0.1.3

plugins/GreatestmodPlugin/R0B0.GreatestMod.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
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.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
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("R0B0.GreatestMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2")]
[assembly: AssemblyProduct("GreatestMod")]
[assembly: AssemblyTitle("R0B0.GreatestMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.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.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]
	[Microsoft.CodeAnalysis.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]
	[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 R0B0.GreatestMod
{
	[BepInPlugin("R0B0.GreatestMod", "GreatestMod", "0.1.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static AssetBundle MyCustomAssets;

		public static AudioClip carLights;

		public static Plugin Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			MyCustomAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "greatestmod"));
			if ((Object)(object)MyCustomAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			carLights = MyCustomAssets.LoadAsset<AudioClip>("Assets/GreatestMod/CompanyCruiserToy/Cruiser_HeadlightsOn.ogg");
			int num = 30;
			Item val = MyCustomAssets.LoadAsset<Item>("Assets/GreatestMod/CompanyCruiserToy/CompanyCruiserToy.asset");
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, num, (LevelTypes)4096);
			Item val2 = MyCustomAssets.LoadAsset<Item>("Assets/GreatestMod/PortableCharger/PortableCharger.asset");
			NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
			int num2 = 100;
			TerminalNode val3 = MyCustomAssets.LoadAsset<TerminalNode>("Assets/GreatestMod/TerminalNodes/iTerminalNode.asset");
			Items.RegisterShopItem(val2, (TerminalNode)null, (TerminalNode)null, val3, num2);
			int num3 = 30;
			Item val4 = MyCustomAssets.LoadAsset<Item>("Assets/GreatestMod/BrokenCamera/BrokenCamera.asset");
			NetworkPrefabs.RegisterNetworkPrefab(val4.spawnPrefab);
			Items.RegisterScrap(val4, num3, (LevelTypes)(-1));
			Patch();
			Logger.LogInfo((object)"R0B0.GreatestMod v0.1.2 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("R0B0.GreatestMod");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "R0B0.GreatestMod";

		public const string PLUGIN_NAME = "GreatestMod";

		public const string PLUGIN_VERSION = "0.1.2";
	}
}
namespace R0B0.GreatestMod.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB), "Update")]
	internal class ExhaustionPatch
	{
		[HarmonyPostfix]
		private static void PlayerControllerB_Update(PlayerControllerB __instance)
		{
			if (!__instance.isExhausted)
			{
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "Interact_performed")]
	internal class PlayerInteractionPatch
	{
		[HarmonyPostfix]
		private static void PlayerControllerB_Interact_performed(PlayerControllerB __instance, CallbackContext context)
		{
			if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerDead && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject))
			{
				if (!StartOfRound.Instance.overrideSpectateCamera && (Object)(object)__instance.spectatedPlayerScript != (Object)null && !__instance.spectatedPlayerScript.isPlayerDead)
				{
					__instance.SpectateNextPlayer(false);
				}
			}
			else
			{
				if (((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer) || !((CallbackContext)(ref context)).performed || __instance.timeSinceSwitchingSlots < 0.2f || __instance.inSpecialMenu)
				{
					return;
				}
				ShipBuildModeManager.Instance.CancelBuildMode(true);
				if (!__instance.isGrabbingObjectAnimation && !__instance.isTypingChat && !__instance.inTerminalMenu && !__instance.throwingObject && !__instance.IsInspectingItem && !((Object)(object)__instance.inAnimationWithEnemy != (Object)null) && !__instance.jetpackControls && !__instance.disablingJetpackControls && !StartOfRound.Instance.suckingPlayersOutOfShip)
				{
					if (!__instance.activatingItem && !__instance.waitingToDropItem)
					{
						__instance.BeginGrabObject();
					}
					if (!((Object)(object)__instance.hoveringOverTrigger == (Object)null) && !__instance.hoveringOverTrigger.holdInteraction && (!__instance.isHoldingObject || __instance.hoveringOverTrigger.oneHandedItemAllowed) && (!__instance.twoHanded || (__instance.hoveringOverTrigger.twoHandedItemAllowed && !__instance.hoveringOverTrigger.specialCharacterAnimation) || (__instance.hoveringOverTrigger.twoHandedItemAllowed && __instance.hoveringOverTrigger.hoverTip == "Charge item : [LMB]")) && __instance.InteractTriggerUseConditionsMet())
					{
						__instance.hoveringOverTrigger.Interact(__instance.thisPlayerBody);
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(ItemCharger))]
	internal class PowerOutletStun
	{
		private const int DAMAGEAMOUNT = 50;

		private const float BODYTHROWMULTIPLIER = 0.5f;

		private const int DAMAGEDISTRIBUTION = 3;

		[HarmonyPatch("ChargeItem")]
		[HarmonyPrefix]
		private static void ItemCharger_ChargeItem(ItemCharger __instance)
		{
			Plugin.Logger.LogDebug((object)"------------- Charged item!! ------------------------");
			GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
			if (!((Object)(object)currentlyHeldObjectServer == (Object)null) && (currentlyHeldObjectServer.itemProperties.requiresBattery || currentlyHeldObjectServer.itemProperties.isConductiveMetal))
			{
				__instance.PlayChargeItemEffectServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId);
				if (__instance.chargeItemCoroutine != null)
				{
					((MonoBehaviour)__instance).StopCoroutine(__instance.chargeItemCoroutine);
				}
				if (currentlyHeldObjectServer.itemProperties.requiresBattery)
				{
					__instance.chargeItemCoroutine = ((MonoBehaviour)__instance).StartCoroutine(__instance.chargeItemDelayed(currentlyHeldObjectServer));
				}
				else if (currentlyHeldObjectServer.itemProperties.isConductiveMetal && !currentlyHeldObjectServer.itemProperties.twoHanded)
				{
					__instance.chargeItemCoroutine = ((MonoBehaviour)__instance).StartCoroutine(chargeItemDelayedButBetter(currentlyHeldObjectServer, __instance.zapAudio, __instance.chargeStationAnimator, 1f));
				}
				else if (currentlyHeldObjectServer.itemProperties.isConductiveMetal && currentlyHeldObjectServer.itemProperties.twoHanded)
				{
					__instance.chargeItemCoroutine = ((MonoBehaviour)__instance).StartCoroutine(chargeItemDelayedButBetter(currentlyHeldObjectServer, __instance.zapAudio, __instance.chargeStationAnimator, 2f));
				}
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void ItemCharger_Update(ItemCharger __instance)
		{
			if (__instance.updateInterval == 0f)
			{
				__instance.updateInterval = 0f;
				if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					__instance.triggerScript.interactable = (Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer != (Object)null && (GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer.itemProperties.isConductiveMetal || GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer.itemProperties.requiresBattery);
				}
			}
		}

		private static IEnumerator chargeItemDelayedButBetter(GrabbableObject itemToCharge, AudioSource zapAudio, Animator chargeStationAnimator, float damageMultiplier)
		{
			zapAudio.Play();
			yield return (object)new WaitForSeconds(0.6f);
			chargeStationAnimator.SetTrigger("zap");
			if ((Object)(object)itemToCharge != (Object)null)
			{
				for (int i = 0; i < 3; i++)
				{
					GameNetworkManager.Instance.localPlayerController.DamagePlayer(Mathf.RoundToInt(16f * damageMultiplier), true, true, (CauseOfDeath)11, 0, false, default(Vector3));
					yield return (object)new WaitForSeconds(0.1f);
				}
			}
		}
	}
}
namespace R0B0.GreatestMod.Monobehaviours
{
	public class BrokenCamera : GrabbableObject
	{
		[Header("Stun grenade settings")]
		public float TimeToExplode = 2.25f;

		public bool DestroyGrenade;

		public string playerAnimation = "PullGrenadePin";

		[Space(5f)]
		public bool explodeOnCollision;

		public bool dontRequirePullingPin;

		public float chanceToExplode = 100f;

		public bool spawnDamagingShockwave;

		private bool explodeOnThrow;

		private bool gotExplodeOnThrowRPC;

		private bool hasCollided;

		[Space(3f)]
		public string throwString = "Throw grenade: [RMB]";

		private Coroutine pullPinCoroutine;

		public Animator itemAnimator;

		public AudioSource itemAudio;

		public AudioClip pullPinSFX;

		public AudioClip explodeSFX;

		private int stunGrenadeMask = 268437761;

		public GameObject stunGrenadeExplosion;

		private PlayerControllerB playerThrownBy;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			ExplodeStunGrenade();
		}

		private void ExplodeStunGrenade(bool destroy = false)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			if (base.insertedBattery.charge < 1f || base.insertedBattery.empty)
			{
				return;
			}
			base.insertedBattery.charge = 0f;
			base.insertedBattery.empty = true;
			((GrabbableObject)this).SyncBatteryServerRpc(0);
			if ((chanceToExplode < 100f && !explodeOnThrow) || (explodeOnCollision && !StartOfRound.Instance.currentLevel.spawnEnemiesAndScrap && (Object)(object)base.parentObject == (Object)(object)Object.FindObjectOfType<DepositItemsDesk>().deskObjectsContainer))
			{
				if ((Object)(object)playerThrownBy != (Object)null)
				{
					playerThrownBy.activatingItem = false;
				}
				return;
			}
			Transform val = ((!base.isInElevator) ? RoundManager.Instance.mapPropsContainer.transform : StartOfRound.Instance.elevatorTransform);
			StunFlash(((Component)this).transform.position, affectAudio: false, 1.25f, 5f, 0.8f, isHeldItem: false, base.playerHeldBy, playerThrownBy);
			Object.Instantiate<GameObject>(stunGrenadeExplosion, ((Component)this).transform.position, Quaternion.identity, val);
			itemAudio.PlayOneShot(explodeSFX);
			WalkieTalkie.TransmitOneShotAudio(itemAudio, explodeSFX, 1f);
			if (DestroyGrenade)
			{
				((GrabbableObject)this).DestroyObjectInHand(playerThrownBy);
			}
		}

		public void StunFlash(Vector3 explosionPosition, bool affectAudio, float flashSeverityMultiplier, float enemyStunTime, float flashSeverityDistanceRolloff = 1f, bool isHeldItem = false, PlayerControllerB playerHeldBy = null, PlayerControllerB playerThrownBy = null, float addToFlashSeverity = 0f)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: 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_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: 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)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = GameNetworkManager.Instance.localPlayerController;
			if (GameNetworkManager.Instance.localPlayerController.isPlayerDead && (Object)(object)GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript != (Object)null)
			{
				val = GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript;
			}
			float num = Vector3.Distance(((Component)val).transform.position, explosionPosition);
			float num2 = 7f / (num * flashSeverityDistanceRolloff);
			if (Physics.Linecast(explosionPosition + Vector3.up * 0.5f, ((Component)val.gameplayCamera).transform.position, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				num2 /= 13f;
			}
			else if (num < 2f)
			{
				num2 = 1f;
			}
			else if (!val.HasLineOfSightToPosition(explosionPosition, 60f, 15, 2f))
			{
				num2 = Mathf.Clamp(num2 / 3f, 0f, 1f);
			}
			if (isHeldItem && (Object)(object)playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				num2 = 1f;
				GameNetworkManager.Instance.localPlayerController.DamagePlayer(20, false, true, (CauseOfDeath)3, 0, false, default(Vector3));
			}
			num2 = Mathf.Clamp(num2 * flashSeverityMultiplier, 0f, 1f);
			if (num2 > 0.6f)
			{
				num2 += addToFlashSeverity;
			}
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)(object)playerHeldBy)
			{
				HUDManager.Instance.flashFilter = num2;
			}
			if (affectAudio)
			{
				SoundManager.Instance.earsRingingTimer = num2;
			}
			if (enemyStunTime <= 0f)
			{
				return;
			}
			Collider[] array = Physics.OverlapSphere(explosionPosition, 12f, 524288);
			if (array.Length == 0)
			{
				return;
			}
			for (int i = 0; i < array.Length; i++)
			{
				EnemyAICollisionDetect component = ((Component)array[i]).GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				Vector3 val2 = ((Component)component.mainScript).transform.position + Vector3.up * 0.5f;
				if (component.mainScript.CheckLineOfSightForPosition(explosionPosition + Vector3.up * 0.5f, 120f, 23, 7f, (Transform)null) || (!Physics.Linecast(explosionPosition + Vector3.up * 0.5f, ((Component)component.mainScript).transform.position + Vector3.up * 0.5f, 256) && Vector3.Distance(explosionPosition, val2) < 11f))
				{
					if ((Object)(object)playerThrownBy != (Object)null)
					{
						component.mainScript.SetEnemyStunned(true, enemyStunTime, playerThrownBy);
					}
					else
					{
						component.mainScript.SetEnemyStunned(true, enemyStunTime, (PlayerControllerB)null);
					}
				}
			}
		}
	}
	public class CompanyCruiserToy : GrabbableObject
	{
		[Space(15f)]
		public int flashlightInterferenceLevel;

		public static int globalFlashlightInterferenceLevel;

		public bool changeMaterial = true;

		public Light flashlightBulb { get; set; }

		public Light flashlightBulbGlow { get; set; }

		public AudioSource flashlightAudio { get; set; }

		public AudioClip[] flashlightClips { get; set; }

		public AudioClip outOfBatteriesClip { get; set; }

		public AudioClip flashlightFlicker { get; set; }

		public Material bulbLight { get; set; }

		public Material bulbDark { get; set; }

		public MeshRenderer flashlightMesh { get; set; }

		public int flashlightTypeID { get; set; }

		private float initialIntensity { get; set; }

		private PlayerControllerB previousPlayerHeldBy { get; set; }

		public void Awake()
		{
			base.grabbable = true;
			base.isInFactory = true;
			base.grabbableToEnemies = true;
			changeMaterial = false;
			flashlightBulb = ((Component)this).GetComponentsInChildren<Light>()[0];
			flashlightBulbGlow = ((Component)this).GetComponentsInChildren<Light>()[1];
			flashlightAudio = ((Component)this).GetComponent<AudioSource>();
			flashlightClips = (AudioClip[])(object)new AudioClip[1];
			flashlightClips[0] = Plugin.carLights;
			base.insertedBattery.empty = false;
			base.insertedBattery.charge = 100f;
		}

		public override void Start()
		{
			((GrabbableObject)this).Start();
			initialIntensity = flashlightBulb.intensity;
		}

		public override void UseUpBatteries()
		{
			((GrabbableObject)this).UseUpBatteries();
			SwitchFlashlight(on: false);
		}

		public override void PocketItem()
		{
			Plugin.Logger.LogError((object)"Truck pocketed");
			if (!((NetworkBehaviour)this).IsOwner)
			{
				((GrabbableObject)this).PocketItem();
				return;
			}
			if ((Object)(object)previousPlayerHeldBy != (Object)null)
			{
				((Behaviour)flashlightBulb).enabled = false;
				((Behaviour)flashlightBulbGlow).enabled = false;
				if (base.isBeingUsed && ((Object)(object)previousPlayerHeldBy.ItemSlots[previousPlayerHeldBy.currentItemSlot] == (Object)null || previousPlayerHeldBy.ItemSlots[previousPlayerHeldBy.currentItemSlot].itemProperties.itemId != 1 || previousPlayerHeldBy.ItemSlots[previousPlayerHeldBy.currentItemSlot].itemProperties.itemId != 6))
				{
					previousPlayerHeldBy.pocketedFlashlight = (GrabbableObject)(object)this;
					PocketFlashlightServerRpc(stillUsingFlashlight: true);
				}
				else
				{
					base.isBeingUsed = false;
					((Behaviour)flashlightBulbGlow).enabled = false;
					SwitchFlashlight(on: false);
					PocketFlashlightServerRpc();
				}
			}
			else
			{
				Debug.Log((object)"Could not find what player was holding this flashlight item");
			}
			((GrabbableObject)this).PocketItem();
		}

		[ServerRpc]
		public void PocketFlashlightServerRpc(bool stillUsingFlashlight = false)
		{
			PocketFlashlightClientRpc(stillUsingFlashlight);
		}

		[ClientRpc]
		public void PocketFlashlightClientRpc(bool stillUsingFlashlight)
		{
			if (((NetworkBehaviour)this).IsOwner)
			{
				return;
			}
			((Behaviour)flashlightBulb).enabled = false;
			((Behaviour)flashlightBulbGlow).enabled = false;
			if (stillUsingFlashlight)
			{
				if (!((Object)(object)previousPlayerHeldBy == (Object)null))
				{
					previousPlayerHeldBy.pocketedFlashlight = (GrabbableObject)(object)this;
				}
			}
			else
			{
				base.isBeingUsed = false;
				((Behaviour)flashlightBulbGlow).enabled = false;
				SwitchFlashlight(on: false);
			}
		}

		public override void DiscardItem()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).DiscardItem();
			RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 25f, 0.95f, 0, base.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
		}

		public override void EquipItem()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			previousPlayerHeldBy = base.playerHeldBy;
			SwitchFlashlight(on: true);
			RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 15f, 0.65f, 0, base.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
			((GrabbableObject)this).EquipItem();
		}

		public void SwitchFlashlight(bool on)
		{
			base.isBeingUsed = on;
			if (!((NetworkBehaviour)this).IsOwner)
			{
				Debug.Log((object)$"Flashlight click. playerheldby null?: {(Object)(object)base.playerHeldBy != (Object)null}");
				Debug.Log((object)$"Flashlight being disabled or enabled: {on}");
				Plugin.Logger.LogInfo((object)"If not owner or something?");
			}
			else
			{
				((Behaviour)flashlightBulb).enabled = on;
				((Behaviour)flashlightBulbGlow).enabled = on;
			}
			if (changeMaterial)
			{
				Material[] sharedMaterials = ((Renderer)flashlightMesh).sharedMaterials;
				if (on)
				{
					sharedMaterials[1] = bulbLight;
				}
				else
				{
					sharedMaterials[1] = bulbDark;
				}
				((Renderer)flashlightMesh).sharedMaterials = sharedMaterials;
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			int num = ((flashlightInterferenceLevel <= globalFlashlightInterferenceLevel) ? globalFlashlightInterferenceLevel : flashlightInterferenceLevel);
			if (num >= 2)
			{
				flashlightBulb.intensity = 0f;
			}
			else if (num == 1)
			{
				flashlightBulb.intensity = Random.Range(0f, 200f);
			}
			else
			{
				flashlightBulb.intensity = initialIntensity;
			}
		}
	}
	public class PortableItemCharger : NetworkBehaviour
	{
		private const float CHARGEBATTERYAMOUNT = 0.1f;

		public PortableItemChargerItem itemThing;

		public InteractTrigger triggerScript;

		public Animator chargeStationAnimator;

		private Coroutine chargeItemCoroutine;

		public AudioSource zapAudio;

		private float updateInterval;

		public void ChargeItem()
		{
			GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
			if (!((Object)(object)currentlyHeldObjectServer == (Object)null) && !((Object)(object)currentlyHeldObjectServer == (Object)null) && currentlyHeldObjectServer.itemProperties.requiresBattery && ((GrabbableObject)itemThing).insertedBattery.charge >= 0.1f)
			{
				PlayChargeItemEffectServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId);
				if (chargeItemCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(chargeItemCoroutine);
				}
				chargeItemCoroutine = ((MonoBehaviour)this).StartCoroutine(chargeItemDelayed(currentlyHeldObjectServer));
			}
		}

		private void Update()
		{
			if ((Object)(object)NetworkManager.Singleton == (Object)null)
			{
				return;
			}
			if (updateInterval > 1f)
			{
				updateInterval = 0f;
				if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					if (((GrabbableObject)itemThing).heldByPlayerOnServer)
					{
						triggerScript.interactable = false;
						triggerScript.disabledHoverTip = "This item is currently not in use. Please put the item down to use it";
					}
					else if (((GrabbableObject)itemThing).insertedBattery.charge < 0.1f)
					{
						triggerScript.interactable = false;
						triggerScript.disabledHoverTip = "(It's empty. Why would I even try)";
					}
					else if ((Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer == (Object)(object)itemThing)
					{
						triggerScript.interactable = false;
						triggerScript.disabledHoverTip = "You can't charge the battery with itself >:(";
					}
					else
					{
						triggerScript.disabledHoverTip = "(Requires battery-powered item)";
						triggerScript.interactable = (Object)(object)GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer != (Object)null && GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer.itemProperties.requiresBattery;
					}
				}
			}
			else
			{
				updateInterval += Time.deltaTime;
			}
		}

		private IEnumerator chargeItemDelayed(GrabbableObject itemToCharge)
		{
			zapAudio.Play();
			yield return (object)new WaitForSeconds(0.05f);
			chargeStationAnimator.SetTrigger("zap");
			if ((Object)(object)itemToCharge != (Object)null)
			{
				itemToCharge.insertedBattery = new Battery(false, 1f);
				itemToCharge.SyncBatteryServerRpc(100);
				Battery insertedBattery = ((GrabbableObject)itemThing).insertedBattery;
				insertedBattery.charge -= 0.1f;
				Debug.Log((object)Mathf.RoundToInt(((GrabbableObject)itemThing).insertedBattery.charge * 10f));
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void PlayChargeItemEffectServerRpc(int playerChargingItem)
		{
			PlayChargeItemEffectClientRpc(playerChargingItem);
		}

		[ClientRpc]
		public void PlayChargeItemEffectClientRpc(int playerChargingItem)
		{
			if (!((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && (int)GameNetworkManager.Instance.localPlayerController.playerClientId != playerChargingItem)
			{
				if (chargeItemCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(chargeItemCoroutine);
				}
				chargeItemCoroutine = ((MonoBehaviour)this).StartCoroutine(chargeItemDelayed(null));
			}
		}
	}
	public class PortableItemChargerItem : GrabbableObject
	{
		public Collider ItemChargerInterractCollider;

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (base.heldByPlayerOnServer)
			{
				ItemChargerInterractCollider.enabled = false;
			}
			else
			{
				ItemChargerInterractCollider.enabled = true;
			}
			if ((double)base.insertedBattery.charge < 0.1 && (double)base.insertedBattery.charge > 0.01 && !base.insertedBattery.empty)
			{
				base.insertedBattery.charge = 0.1f;
			}
			else if (base.insertedBattery.charge == 0f)
			{
				base.insertedBattery.empty = true;
			}
		}
	}
}