Decompiled source of ReloadFlashlight v1.0.0

ReloadFlashlight.dll

Decompiled 11 months ago
using System;
using System.Collections;
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.Configuration;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using ReloadFlashlight;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[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("ReloadFlashlight")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ReloadFlashlight")]
[assembly: AssemblyTitle("ReloadFlashlight")]
[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;
		}
	}
}
[HarmonyPatch(typeof(FlashlightItem), "Update")]
public class FlashlightItemUpdate
{
	private static void Postfix(FlashlightItem __instance)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo fieldInfo = AccessTools.Field(typeof(GrabbableObject), "insertedBattery");
		Battery battery = (Battery)fieldInfo.GetValue(__instance);
		if (((ButtonControl)Keyboard.current[Plugin.reloadFlashlightHotkey.Value]).isPressed)
		{
			((MonoBehaviour)__instance).StartCoroutine(reloadCorutine(__instance, battery, ((GrabbableObject)__instance).isBeingUsed));
		}
	}

	private static IEnumerator reloadCorutine(FlashlightItem item, Battery battery, bool turnonafter)
	{
		if (Plugin.unChargeFlashlight.Value)
		{
			battery.charge = 0f;
			item.SwitchFlashlight(false);
		}
		yield return (object)new WaitForSeconds((float)Plugin.reloadTime.Value);
		((GrabbableObject)item).SyncBatteryServerRpc(Plugin.chargeAmount.Value);
		if (turnonafter)
		{
			item.SwitchFlashlight(true);
		}
	}
}
namespace ReloadFlashlight
{
	[BepInPlugin("hu.ebot.flashlight", "Flashlight reload", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<Key> reloadFlashlightHotkey { get; set; }

		public static ConfigEntry<int> reloadTime { get; set; }

		public static ConfigEntry<int> chargeAmount { get; set; }

		public static ConfigEntry<bool> unChargeFlashlight { get; set; }

		private void Awake()
		{
			createConfig();
			patch();
		}

		private void patch()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("hu.ebot.flashlight");
			val.PatchAll();
		}

		private void createConfig()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			//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_019a: Expected O, but got Unknown
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Expected O, but got Unknown
			string text = Paths.ConfigPath + "/ReloadFlashlight.cfg";
			ConfigFile val = new ConfigFile(text, true);
			if (!val.ContainsKey(new ConfigDefinition("Hotkeys", "Flashlight reload")))
			{
				reloadFlashlightHotkey = val.Bind<Key>("Hotkeys", "Flashlight reload", (Key)32, (ConfigDescription)null);
				EnumDropDownConfigItem<Key> val2 = new EnumDropDownConfigItem<Key>(reloadFlashlightHotkey, new EnumDropDownOptions
				{
					Description = "The key to reload the flashlight"
				});
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
			}
			if (!val.ContainsKey(new ConfigDefinition("General", "Reload Time")))
			{
				reloadTime = val.Bind<int>("General", "Reload Time", 15, (ConfigDescription)null);
				ConfigEntry<int> obj = reloadTime;
				IntInputFieldOptions val3 = new IntInputFieldOptions();
				((BaseRangeOptions<int>)val3).Min = 0;
				((BaseOptions)val3).Description = "!IN SECONDS!\nHow long should the reload take";
				IntInputFieldConfigItem val4 = new IntInputFieldConfigItem(obj, val3);
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val4);
			}
			if (!val.ContainsKey(new ConfigDefinition("General", "Charge Amount")))
			{
				chargeAmount = val.Bind<int>("General", "Charge Amount", 100, (ConfigDescription)null);
				ConfigEntry<int> obj2 = chargeAmount;
				IntSliderOptions val5 = new IntSliderOptions();
				((BaseRangeOptions<int>)val5).Min = 1;
				((BaseRangeOptions<int>)val5).Max = 100;
				((BaseOptions)val5).Description = "How much should 1 reload add to the flashlight";
				IntSliderConfigItem val6 = new IntSliderConfigItem(obj2, val5);
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val6);
			}
			if (!val.ContainsKey(new ConfigDefinition("General", "Remove Charge")))
			{
				unChargeFlashlight = val.Bind<bool>("General", "Remove Charge", true, (ConfigDescription)null);
				BoolCheckBoxConfigItem val7 = new BoolCheckBoxConfigItem(unChargeFlashlight, new BoolCheckBoxOptions
				{
					Description = "When checked if you reload the flashlight until it reloades it will remove all charge from the flashlight, making it a bit more creepier"
				});
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val7);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ReloadFlashlight";

		public const string PLUGIN_NAME = "ReloadFlashlight";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}