Decompiled source of Dynamo Flashlight Update v0.1.7

VMechLight.dll

Decompiled 4 months ago
using System;
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 GameNetcodeStuff;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using VMechLight.MonoBehaviors;

[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("VMechLight")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A manually power flashlight")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VMechLight")]
[assembly: AssemblyTitle("VMechLight")]
[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 VMechLight
{
	[BepInPlugin("versus.dynamolight", "Dynamo Flashlight", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "versus.dynamolight";

		private const string NAME = "Dynamo Flashlight";

		private const string VERSION = "1.1.0";

		public static Plugin instance;

		public static AudioClip pull1;

		public static AudioClip pull2;

		private void Awake()
		{
			instance = this;
			AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "dynamolight"));
			pull1 = obj.LoadAsset<AudioClip>("Assets/DynamoLight/DynamoLight/pull1.mp3");
			pull2 = obj.LoadAsset<AudioClip>("Assets/DynamoLight/DynamoLight/pull2.mp3");
			Item val = obj.LoadAsset<Item>("Assets/DynamoLight/DynamoLight/DynamoLight.asset");
			DynamoLight dynamoLight = val.spawnPrefab.AddComponent<DynamoLight>();
			((GrabbableObject)dynamoLight).grabbable = true;
			((GrabbableObject)dynamoLight).grabbableToEnemies = true;
			((GrabbableObject)dynamoLight).itemProperties = val;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, 5, (LevelTypes)(-1));
			TerminalNode val2 = ScriptableObject.CreateInstance<TerminalNode>();
			Items.RegisterShopItem(val, (TerminalNode)null, (TerminalNode)null, val2, 50);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Patched Dynamo Flashlight");
		}
	}
}
namespace VMechLight.MonoBehaviors
{
	internal class DynamoLight : GrabbableObject
	{
		public GameObject lightlow;

		public GameObject lightmid;

		public GameObject lighthigh;

		public float battery = 0f;

		public AudioSource source;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			source = ((Component)this).GetComponent<AudioSource>();
			lightlow = ((Component)((Component)this).transform.GetChild(1)).gameObject;
			lightmid = ((Component)((Component)this).transform.GetChild(2)).gameObject;
			lighthigh = ((Component)((Component)this).transform.GetChild(3)).gameObject;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && base.playerHeldBy.sprintMeter >= 0.1f)
			{
				battery += 10f;
				PlayerControllerB playerHeldBy = base.playerHeldBy;
				playerHeldBy.sprintMeter -= 0.1f;
				pullserver();
				RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 20f, 3f, 0, base.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			flashlightserver();
		}

		[ServerRpc]
		public void pullserver()
		{
			pullclient();
		}

		[ClientRpc]
		public void pullclient()
		{
			if (battery <= 10f)
			{
				source.PlayOneShot(Plugin.pull1, 0.2f);
			}
			else if (battery > 10f)
			{
				source.PlayOneShot(Plugin.pull2, 0.2f);
			}
		}

		[ServerRpc]
		public void flashlightserver()
		{
			flashlightclient();
		}

		[ClientRpc]
		public void flashlightclient()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (battery > 0f)
			{
				if (battery <= 20f)
				{
					battery -= 0.015f;
				}
				else if (battery > 20f)
				{
					battery -= 0.0075f;
				}
				RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 10f, 1f, 0, base.isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
			}
			if (battery > 0f && battery < 10f)
			{
				lightlow.SetActive(true);
				lightmid.SetActive(false);
				lighthigh.SetActive(false);
				base.useCooldown = 0.75f;
			}
			else if (battery > 10f && battery < 20f)
			{
				lightlow.SetActive(false);
				lightmid.SetActive(true);
				lighthigh.SetActive(false);
				base.useCooldown = 2f;
			}
			else if (battery > 20f && battery <= 30f)
			{
				lightlow.SetActive(false);
				lightmid.SetActive(false);
				lighthigh.SetActive(true);
				base.useCooldown = 15f;
			}
			else if (battery <= 0f)
			{
				lightlow.SetActive(false);
				lightmid.SetActive(false);
				lighthigh.SetActive(false);
				base.useCooldown = 0f;
			}
			if (battery > 30f)
			{
				battery = 30f;
			}
		}
	}
}