Decompiled source of ObjectVolumeController v1.1.1

ObjectVolumeController.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using ObjectVolumeController.AudioPlayers;
using ObjectVolumeController.Compatibility;
using ObjectVolumeController.Config;
using ObjectVolumeController.Input;
using ObjectVolumeController.Patcher;
using TMPro;
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: AssemblyTitle("ObjectVolumeController")]
[assembly: AssemblyDescription("Mod made by flipf17")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ObjectVolumeController")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("49ff2710-6c88-48c4-989a-32b79f0ddd6a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ObjectVolumeController
{
	[BepInPlugin("FlipMods.ObjectVolumeController", "ObjectVolumeController", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin instance;

		private Harmony _harmony;

		private static ManualLogSource logger;

		private void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			instance = this;
			CreateCustomLogger();
			ConfigSettings.BindConfigSettings();
			Keybinds.InitKeybinds();
			_harmony = new Harmony("ObjectVolumeController");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ObjectVolumeController loaded");
		}

		private void PatchAll()
		{
			IEnumerable<Type> enumerable;
			try
			{
				enumerable = Assembly.GetExecutingAssembly().GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				enumerable = ex.Types.Where((Type t) => t != null);
			}
			foreach (Type item in enumerable)
			{
				_harmony.PatchAll(item);
			}
		}

		private void CreateCustomLogger()
		{
			try
			{
				logger = Logger.CreateLogSource($"{((BaseUnityPlugin)this).Info.Metadata.Name}-{((BaseUnityPlugin)this).Info.Metadata.Version}");
			}
			catch
			{
				logger = ((BaseUnityPlugin)this).Logger;
			}
		}

		public static void Log(string message)
		{
			logger.LogInfo((object)message);
		}

		public static void LogError(string message)
		{
			logger.LogError((object)message);
		}

		public static void LogWarning(string message)
		{
			logger.LogWarning((object)message);
		}

		public static bool IsModLoaded(string guid)
		{
			return Chainloader.PluginInfos.ContainsKey(guid);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FlipMods.ObjectVolumeController";

		public const string PLUGIN_NAME = "ObjectVolumeController";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace ObjectVolumeController.Patcher
{
	[HarmonyPatch]
	public static class RomanticTablePatcher
	{
		[HarmonyPatch(typeof(AutoParentToShip), "Awake")]
		[HarmonyPostfix]
		public static void Init(AutoParentToShip __instance)
		{
			if (!((Object)__instance).name.ToLower().StartsWith("romantictable"))
			{
				return;
			}
			AudioSource componentInChildren = ((Component)__instance).GetComponentInChildren<AudioSource>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				ObjectsManager.romanticTable.audioSources.Add(componentInChildren);
				if (ObjectsManager.romanticTable.defaultVolume == 0f)
				{
					ObjectsManager.romanticTable.defaultVolume = componentInChildren.volume;
					Plugin.Log("RomanticTable Volume: " + ObjectsManager.romanticTable.defaultVolume);
				}
				ObjectsManager.romanticTable.UpdateVolumes();
			}
		}
	}
	[HarmonyPatch]
	public static class DiscoBallPatcher
	{
		[HarmonyPatch(typeof(AutoParentToShip), "Awake")]
		[HarmonyPostfix]
		public static void Init(AutoParentToShip __instance)
		{
			if (!((Object)__instance).name.ToLower().StartsWith("disco"))
			{
				return;
			}
			AudioSource component = ((Component)__instance).GetComponent<AudioSource>();
			if ((Object)(object)component != (Object)null)
			{
				ObjectsManager.discoBall.audioSources.Add(component);
				if (ObjectsManager.discoBall.defaultVolume == 0f)
				{
					ObjectsManager.discoBall.defaultVolume = component.volume;
					Plugin.Log("DiscoBall Volume: " + ObjectsManager.discoBall.defaultVolume);
				}
				ObjectsManager.discoBall.UpdateVolumes();
			}
		}
	}
	[HarmonyPatch]
	public static class ShowerPatcher
	{
		[HarmonyPatch(typeof(AutoParentToShip), "Awake")]
		[HarmonyPostfix]
		public static void Init(AutoParentToShip __instance)
		{
			if (!((Object)__instance).name.ToLower().StartsWith("shower"))
			{
				return;
			}
			AudioSource componentInChildren = ((Component)__instance).GetComponentInChildren<AudioSource>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				ObjectsManager.showers.audioSources.Add(componentInChildren);
				if (ObjectsManager.showers.defaultVolume == 0f)
				{
					ObjectsManager.showers.defaultVolume = componentInChildren.volume;
					Plugin.Log("Shower Volume: " + ObjectsManager.showers.defaultVolume);
				}
				ObjectsManager.showers.UpdateVolumes();
			}
		}
	}
	[HarmonyPatch]
	public static class WalkmanPatcher
	{
		[HarmonyPatch(typeof(GrabbableObject), "Start")]
		[HarmonyPostfix]
		public static void Init(GrabbableObject __instance)
		{
			if ((Object)(object)__instance?.itemProperties == (Object)null || !__instance.itemProperties.itemName.ToLower().StartsWith("walkman"))
			{
				return;
			}
			AudioSource componentInChildren = ((Component)__instance).GetComponentInChildren<AudioSource>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				Plugin.LogError("Walkman audio source null!");
				return;
			}
			ObjectsManager.walkmanItems.audioSources.Add(componentInChildren);
			ObjectsManager.walkmanItems.items.Add(__instance);
			__instance.itemProperties.canBeGrabbedBeforeGameStart = true;
			if (ObjectsManager.walkmanItems.defaultVolume == 0f)
			{
				ObjectsManager.walkmanItems.defaultVolume = componentInChildren.volume;
				Plugin.Log("Walkman volume: " + componentInChildren.volume);
			}
			ObjectsManager.boomboxItems.UpdateVolumes();
		}
	}
	[HarmonyPatch]
	public static class ShipSpeakerPatcher
	{
		public static Transform shipSpeaker;

		public static AudioSource shipSpeakerAudioSource;

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPrefix]
		public static void Init(StartOfRound __instance)
		{
			shipSpeakerAudioSource = StartOfRound.Instance.speakerAudioSource;
			shipSpeaker = ((Component)shipSpeakerAudioSource).transform;
			ObjectsManager.shipSpeaker.audioSources.Add(shipSpeakerAudioSource);
			if (ObjectsManager.shipSpeaker.defaultVolume == 0f)
			{
				ObjectsManager.shipSpeaker.defaultVolume = shipSpeakerAudioSource.volume;
				Plugin.Log("ShipSpeaker volume: " + ObjectsManager.shipSpeaker.defaultVolume);
			}
			ObjectsManager.shipSpeaker.UpdateVolumes();
		}
	}
	[HarmonyPatch]
	public static class TelevisionPatcher
	{
		[HarmonyPatch(typeof(TVScript), "OnEnable")]
		[HarmonyPostfix]
		public static void Init(TVScript __instance)
		{
			if (!((Object)(object)__instance?.tvSFX == (Object)null) && !ObjectsManager.televisions.audioSources.Contains(__instance.tvSFX))
			{
				ObjectsManager.televisions.audioSources.Add(__instance.tvSFX);
				if (ObjectsManager.televisions.defaultVolume == 0f)
				{
					ObjectsManager.televisions.defaultVolume = __instance.tvSFX.volume;
					Plugin.Log("Television volume: " + ObjectsManager.televisions.defaultVolume);
				}
				ObjectsManager.televisions.UpdateVolumes();
			}
		}
	}
	[HarmonyPatch]
	public static class RecordPlayerPatcher
	{
		[HarmonyPatch(typeof(AutoParentToShip), "Awake")]
		[HarmonyPostfix]
		public static void Init(AutoParentToShip __instance)
		{
			if (!((Object)__instance).name.Contains("RecordPlayerContainer"))
			{
				return;
			}
			AudioSource val = ((Component)__instance).GetComponentInChildren<AnimatedObjectTrigger>()?.thisAudioSource;
			if ((Object)(object)val != (Object)null)
			{
				ObjectsManager.recordPlayers.audioSources.Add(val);
				if (ObjectsManager.recordPlayers.defaultVolume == 0f)
				{
					ObjectsManager.recordPlayers.defaultVolume = val.volume;
					Plugin.Log("RecordPlayer Volume: " + ObjectsManager.recordPlayers.defaultVolume);
				}
				ObjectsManager.recordPlayers.UpdateVolumes();
			}
		}
	}
	[HarmonyPatch]
	public static class BoomboxPatcher
	{
		[HarmonyPatch(typeof(BoomboxItem), "Start")]
		[HarmonyPostfix]
		public static void Init(BoomboxItem __instance)
		{
			ObjectsManager.boomboxItems.audioSources.Add(__instance.boomboxAudio);
			ObjectsManager.boomboxItems.items.Add((GrabbableObject)(object)__instance);
			((GrabbableObject)__instance).itemProperties.canBeGrabbedBeforeGameStart = true;
			if (ObjectsManager.boomboxItems.defaultVolume == 0f)
			{
				ObjectsManager.boomboxItems.defaultVolume = __instance.boomboxAudio.volume;
				Plugin.Log("Boombox volume: " + ObjectsManager.boomboxItems.defaultVolume);
			}
			ObjectsManager.boomboxItems.UpdateVolumes();
		}
	}
	[HarmonyPatch]
	public static class ObjectsManager
	{
		public static List<AudioPlayerTypeBase> audioPlayerTypes = new List<AudioPlayerTypeBase>();

		public static AudioPlayerGrabbable boomboxItems = new AudioPlayerGrabbable("boombox");

		public static AudioPlayerGrabbable walkmanItems = new AudioPlayerGrabbable("walkman");

		public static AudioPlayerPlaceable recordPlayers = new AudioPlayerPlaceable("record_player");

		public static AudioPlayerPlaceable televisions = new AudioPlayerPlaceable("television");

		public static AudioPlayerPlaceable shipSpeaker = new AudioPlayerPlaceable("ship_speaker");

		public static AudioPlayerPlaceable discoBall = new AudioPlayerPlaceable("disco_ball");

		public static AudioPlayerPlaceable showers = new AudioPlayerPlaceable("shower");

		public static AudioPlayerPlaceable romanticTable = new AudioPlayerPlaceable("romantic_table");

		public static AudioPlayerTypeBase lookingAtObjectType = null;

		public static AudioPlayerGrabbable grabbingObjectType = null;

		public static float maxVolumeMultiplier = 1.5f;

		internal static PlayerControllerB localPlayerController => StartOfRound.Instance?.localPlayerController;

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPrefix]
		private static void Init()
		{
			if (!NetworkManager.Singleton.IsClient)
			{
				return;
			}
			audioPlayerTypes.Clear();
			audioPlayerTypes.Add(boomboxItems);
			audioPlayerTypes.Add(recordPlayers);
			audioPlayerTypes.Add(televisions);
			audioPlayerTypes.Add(shipSpeaker);
			audioPlayerTypes.Add(walkmanItems);
			lookingAtObjectType = null;
			foreach (AudioPlayerTypeBase audioPlayerType in audioPlayerTypes)
			{
				audioPlayerType.LoadPreferences();
				audioPlayerType.audioSources.Clear();
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "SaveLocalPlayerValues")]
		[HarmonyPostfix]
		private static void SaveLocalPlayerValues()
		{
			if (!NetworkManager.Singleton.IsClient)
			{
				return;
			}
			foreach (AudioPlayerTypeBase audioPlayerType in audioPlayerTypes)
			{
				audioPlayerType.SavePreferences();
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "SetHoverTipAndCurrentInteractTrigger")]
		[HarmonyPostfix]
		public static void UpdateObjectTypeLookingAt(PlayerControllerB __instance)
		{
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkManager.Singleton.IsClient || (Object)(object)__instance != (Object)(object)localPlayerController)
			{
				return;
			}
			lookingAtObjectType = null;
			grabbingObjectType = null;
			if (localPlayerController.inTerminalMenu || localPlayerController.isTypingChat || localPlayerController.isPlayerDead)
			{
				return;
			}
			InteractTrigger hoveringOverTrigger = localPlayerController.hoveringOverTrigger;
			object obj;
			if (hoveringOverTrigger == null)
			{
				obj = null;
			}
			else
			{
				Transform transform = ((Component)hoveringOverTrigger).transform;
				if (transform == null)
				{
					obj = null;
				}
				else
				{
					Transform parent = transform.parent;
					obj = ((parent != null) ? ((Component)parent).gameObject : null);
				}
			}
			GameObject val = (GameObject)obj;
			if (Object.op_Implicit((Object)(object)val))
			{
				string text = ((Object)hoveringOverTrigger).name.ToLower();
				string text2 = ((Object)val).name.ToLower();
				if (ConfigSettings.enableVolumeControllerRecordPlayer.Value && (text.Contains("recordplayer") || text2.Contains("recordplayer")))
				{
					lookingAtObjectType = recordPlayers;
				}
				else if (ConfigSettings.enableVolumeControllerTv.Value && (text.Contains("television") || text2.Contains("television")))
				{
					lookingAtObjectType = televisions;
				}
				else if (ConfigSettings.enableVolumeControllerShipSpeaker.Value && (Object)(object)ShipSpeakerPatcher.shipSpeaker.parent == (Object)(object)val.transform)
				{
					lookingAtObjectType = shipSpeaker;
				}
				else if (ConfigSettings.enableVolumeControllerShower.Value && (text.StartsWith("shower") || text2.StartsWith("shower")))
				{
					lookingAtObjectType = showers;
				}
				else if (ConfigSettings.enableVolumeControllerRomanticTable.Value && (text.StartsWith("romantictable") || text2.StartsWith("romantictable")))
				{
					lookingAtObjectType = romanticTable;
				}
				else if (ConfigSettings.enableVolumeControllerDisco.Value && (text.StartsWith("disco") || text2.StartsWith("disco")))
				{
					lookingAtObjectType = discoBall;
				}
			}
			if (lookingAtObjectType == null)
			{
				Ray val2 = default(Ray);
				((Ray)(ref val2))..ctor(((Component)localPlayerController.gameplayCamera).transform.position, ((Component)localPlayerController.gameplayCamera).transform.forward);
				RaycastHit val3 = default(RaycastHit);
				if (Physics.Raycast(val2, ref val3, localPlayerController.grabDistance, 832) && ((Component)((RaycastHit)(ref val3)).collider).gameObject.layer != 8)
				{
					Collider collider = ((RaycastHit)(ref val3)).collider;
					GrabbableObject val4 = ((collider != null) ? ((Component)collider).GetComponent<GrabbableObject>() : null);
					if (Object.op_Implicit((Object)(object)val4) && (Object)(object)val4.playerHeldBy == (Object)null)
					{
						string text3 = val4.itemProperties.itemName.ToLower();
						if (ConfigSettings.enableVolumeControllerBoombox.Value && text3.Contains("boombox"))
						{
							lookingAtObjectType = boomboxItems;
						}
						else if (ConfigSettings.enableVolumeControllerWalkman.Value && text3.Contains("walkman"))
						{
							lookingAtObjectType = walkmanItems;
						}
					}
				}
			}
			if (lookingAtObjectType != null)
			{
				if (((TMP_Text)localPlayerController.cursorTip).text.Contains("% Volume"))
				{
					int num = ((TMP_Text)localPlayerController.cursorTip).text.IndexOf("% Volume");
					int num2 = -1;
					for (int num3 = num; num3 >= 0; num3--)
					{
						if (((TMP_Text)localPlayerController.cursorTip).text[num3] == '\n')
						{
							num2 = num3 + 1;
						}
						else if (num3 == 0)
						{
							num2 = 0;
						}
						if (num2 >= 0)
						{
							((TMP_Text)localPlayerController.cursorTip).text = ((TMP_Text)localPlayerController.cursorTip).text.Replace(((TMP_Text)localPlayerController.cursorTip).text.Substring(num2, num - num2), Mathf.RoundToInt(lookingAtObjectType.currentVolumeMultiplier * 100f).ToString());
							break;
						}
					}
				}
				else
				{
					TextMeshProUGUI cursorTip = localPlayerController.cursorTip;
					((TMP_Text)cursorTip).text = ((TMP_Text)cursorTip).text + $"\n{Mathf.RoundToInt(lookingAtObjectType.currentVolumeMultiplier * 100f)}% Volume\nAdjust Volume [{KeybindDisplayNames.GetKeybindDisplayName(Keybinds.VolumeDownAction)}/{KeybindDisplayNames.GetKeybindDisplayName(Keybinds.VolumeUpAction)}]";
				}
				return;
			}
			GrabbableObject val5 = localPlayerController.ItemSlots[localPlayerController.currentItemSlot];
			if ((Object)(object)val5?.itemProperties == (Object)null)
			{
				return;
			}
			string text4 = val5.itemProperties.itemName.ToLower();
			if (ConfigSettings.enableVolumeControllerBoombox.Value && val5 is BoomboxItem)
			{
				grabbingObjectType = boomboxItems;
			}
			else if (ConfigSettings.enableVolumeControllerWalkman.Value && text4.StartsWith("walkman"))
			{
				grabbingObjectType = walkmanItems;
			}
			if (grabbingObjectType == null || HUDManager.Instance.controlTipLines == null || HUDManager.Instance.controlTipLines.Length == 0 || (val5.itemProperties.toolTips != null && val5.itemProperties.toolTips.Length > 2 && !(((TMP_Text)HUDManager.Instance.controlTipLines[0]).text == val5.itemProperties.toolTips[0])))
			{
				return;
			}
			bool flag = false;
			int num4 = -1;
			for (int i = 0; i < HUDManager.Instance.controlTipLines.Length; i++)
			{
				TextMeshProUGUI val6 = HUDManager.Instance.controlTipLines[i];
				string text5 = ((TMP_Text)val6).text;
				if (text5.Contains("% Volume"))
				{
					flag = true;
					int length = text5.IndexOf("% Volume");
					((TMP_Text)val6).text = ((TMP_Text)val6).text.Replace(((TMP_Text)val6).text.Substring(0, length), Mathf.RoundToInt(grabbingObjectType.currentVolumeMultiplier * 100f).ToString());
					break;
				}
				if (text5 == "" && num4 < 0)
				{
					num4 = i;
				}
			}
			if (!flag && num4 >= 0 && num4 < HUDManager.Instance.controlTipLines.Length - 1)
			{
				((TMP_Text)HUDManager.Instance.controlTipLines[num4++]).text = Mathf.RoundToInt(grabbingObjectType.currentVolumeMultiplier * 100f) + "% Volume";
				((TMP_Text)HUDManager.Instance.controlTipLines[num4]).text = $"Adjust Volume [{KeybindDisplayNames.GetKeybindDisplayName(Keybinds.VolumeDownAction)}/{KeybindDisplayNames.GetKeybindDisplayName(Keybinds.VolumeUpAction)}]";
			}
		}

		public static void OnPressVolumeKey(bool volumeUp)
		{
			if (localPlayerController.inTerminalMenu || localPlayerController.isTypingChat || localPlayerController.isPlayerDead || (lookingAtObjectType == null && grabbingObjectType == null))
			{
				return;
			}
			float num = ConfigSettings.volumeIncrementMultiplier * (float)(volumeUp ? 1 : (-1));
			if (num == 0f)
			{
				return;
			}
			if (lookingAtObjectType != null)
			{
				float num2 = Mathf.Clamp(lookingAtObjectType.currentVolumeMultiplier + num, 0f, maxVolumeMultiplier);
				if (num2 != lookingAtObjectType.currentVolumeMultiplier)
				{
					Plugin.Log("[" + lookingAtObjectType.name + "] Updating volume from " + lookingAtObjectType.currentVolumeMultiplier + " to " + num2);
					lookingAtObjectType.currentVolumeMultiplier = num2;
					lookingAtObjectType.UpdateVolumes();
				}
			}
			else if (grabbingObjectType != null)
			{
				float num3 = Mathf.Clamp(grabbingObjectType.currentVolumeMultiplier + num, 0f, maxVolumeMultiplier);
				if (num3 != grabbingObjectType.currentVolumeMultiplier)
				{
					Plugin.Log("[" + grabbingObjectType.name + "] Updating volume from " + grabbingObjectType.currentVolumeMultiplier + " to " + num3);
					grabbingObjectType.currentVolumeMultiplier = num3;
					grabbingObjectType.UpdateVolumes();
				}
			}
		}
	}
}
namespace ObjectVolumeController.Input
{
	internal class IngameKeybinds : LcInputActions
	{
		internal static IngameKeybinds Instance = new IngameKeybinds();

		[InputAction("<Keyboard>/minus", GamepadPath = "", Name = "Object Volume Down")]
		public InputAction VolumeDownHotkey { get; set; }

		[InputAction("<Keyboard>/equals", GamepadPath = "", Name = "Object Volume Up")]
		public InputAction VolumeUpHotkey { get; set; }

		internal static InputActionAsset GetAsset()
		{
			return ((LcInputActions)Instance).Asset;
		}
	}
	[HarmonyPatch]
	public static class KeybindDisplayNames
	{
		public static bool usingControllerPrevious = false;

		public static string[] keyboardKeywords = new string[2] { "keyboard", "mouse" };

		public static string[] controllerKeywords = new string[2] { "gamepad", "controller" };

		public static bool usingController => StartOfRound.Instance.localPlayerUsingController;

		[HarmonyPatch(typeof(HUDManager), "Update")]
		[HarmonyPostfix]
		public static void CheckForInputSourceUpdate()
		{
			if (usingController != usingControllerPrevious)
			{
				usingControllerPrevious = usingController;
				UpdateControlTipLines();
			}
		}

		[HarmonyPatch(typeof(KepRemapPanel), "OnDisable")]
		[HarmonyPostfix]
		public static void OnCloseRemapPanel()
		{
			UpdateControlTipLines();
		}

		public static void UpdateControlTipLines()
		{
		}

		public static string GetKeybindDisplayName(InputAction inputAction)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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)
			if (inputAction == null || !inputAction.enabled)
			{
				return "";
			}
			int num = (usingController ? 1 : 0);
			InputBinding val = inputAction.bindings[num];
			string effectivePath = ((InputBinding)(ref val)).effectivePath;
			return GetKeybindDisplayName(effectivePath);
		}

		public static string GetKeybindDisplayName(string controlPath)
		{
			if (controlPath.Length <= 1)
			{
				return "";
			}
			string text = controlPath.ToLower();
			int num = text.IndexOf(">/");
			text = ((num >= 0) ? text.Substring(num + 2) : text);
			if (text.Contains("not-bound"))
			{
				return "";
			}
			text = text.Replace("minus", "-");
			text = text.Replace("equals", "+");
			text = text.Replace("leftalt", "Alt");
			text = text.Replace("rightalt", "Alt");
			text = text.Replace("leftctrl", "Ctrl");
			text = text.Replace("rightctrl", "Ctrl");
			text = text.Replace("leftshift", "Shift");
			text = text.Replace("rightshift", "Shift");
			text = text.Replace("leftbutton", "LMB");
			text = text.Replace("rightbutton", "RMB");
			text = text.Replace("middlebutton", "MMB");
			text = text.Replace("lefttrigger", "LT");
			text = text.Replace("righttrigger", "RT");
			text = text.Replace("leftshoulder", "LB");
			text = text.Replace("rightshoulder", "RB");
			text = text.Replace("leftstickpress", "LS");
			text = text.Replace("rightstickpress", "RS");
			text = text.Replace("dpad/", "DPad-");
			text = text.Replace("scroll/up", "Scroll Up");
			text = text.Replace("scroll/down", "Scroll Down");
			text = text.Replace("backquote", "`");
			try
			{
				text = char.ToUpper(text[0]) + text.Substring(1);
			}
			catch
			{
			}
			return text;
		}
	}
	[HarmonyPatch]
	internal static class Keybinds
	{
		public static InputActionAsset Asset;

		public static InputActionMap ActionMap;

		public static InputAction VolumeDownAction;

		public static InputAction VolumeUpAction;

		public static void InitKeybinds()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log("Initializing hotkeys.");
			if (InputUtils_Compat.Enabled)
			{
				Asset = InputUtils_Compat.Asset;
				ActionMap = Asset.actionMaps[0];
				VolumeDownAction = InputUtils_Compat.VolumeDownHotkey;
				VolumeUpAction = InputUtils_Compat.VolumeUpHotkey;
			}
			else
			{
				Asset = ScriptableObject.CreateInstance<InputActionAsset>();
				ActionMap = new InputActionMap("ObjectVolumeController");
				InputActionSetupExtensions.AddActionMap(Asset, ActionMap);
				VolumeDownAction = InputActionSetupExtensions.AddAction(ActionMap, "ObjectVolumeController.VolumeDown", (InputActionType)0, "<Keyboard>/-", "Press", (string)null, (string)null, (string)null);
				InputActionSetupExtensions.AddBinding(VolumeDownAction, "", (string)null, (string)null, (string)null);
				VolumeUpAction = InputActionSetupExtensions.AddAction(ActionMap, "ObjectVolumeController.VolumeUp", (InputActionType)0, "<Keyboard>/+", "Press", (string)null, (string)null, (string)null);
				InputActionSetupExtensions.AddBinding(VolumeUpAction, "", (string)null, (string)null, (string)null);
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "OnEnable")]
		[HarmonyPostfix]
		public static void OnEnable()
		{
			if (NetworkManager.Singleton.IsClient)
			{
				Asset.Enable();
				VolumeDownAction.performed += OnPressVolumeDown;
				VolumeUpAction.performed += OnPressVolumeUp;
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDisable")]
		[HarmonyPostfix]
		public static void OnDisable()
		{
			if (NetworkManager.Singleton.IsClient)
			{
				Asset.Disable();
				VolumeDownAction.performed -= OnPressVolumeDown;
				VolumeUpAction.performed -= OnPressVolumeUp;
			}
		}

		public static void OnPressVolumeDown(CallbackContext context)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			OnPressVolumeKey(context, -1f);
		}

		public static void OnPressVolumeUp(CallbackContext context)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			OnPressVolumeKey(context, 1f);
		}

		private static void OnPressVolumeKey(CallbackContext context, float value)
		{
			if (NetworkManager.Singleton.IsClient && ((CallbackContext)(ref context)).performed)
			{
				ObjectsManager.OnPressVolumeKey(value > 0f);
			}
		}
	}
}
namespace ObjectVolumeController.Config
{
	public static class ConfigSettings
	{
		public static ConfigEntry<bool> enableVolumeControllerBoombox;

		public static ConfigEntry<bool> enableVolumeControllerRecordPlayer;

		public static ConfigEntry<bool> enableVolumeControllerTv;

		public static ConfigEntry<bool> enableVolumeControllerShipSpeaker;

		public static ConfigEntry<bool> enableVolumeControllerWalkman;

		public static ConfigEntry<bool> enableVolumeControllerDisco;

		public static ConfigEntry<bool> enableVolumeControllerShower;

		public static ConfigEntry<bool> enableVolumeControllerRomanticTable;

		public static ConfigEntry<int> volumeIncrement;

		public static Dictionary<string, ConfigEntryBase> currentConfigEntries = new Dictionary<string, ConfigEntryBase>();

		public static float volumeIncrementMultiplier => (float)volumeIncrement.Value / 100f;

		public static void BindConfigSettings()
		{
			Plugin.Log("BindingConfigs");
			volumeIncrement = AddConfigEntry<int>(((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Audio", "VolumeIncrement", 10, "Volume increment when changing volume."));
			enableVolumeControllerBoombox = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Audio", "EnableVolumeControllerBoombox", true, "Enable volume control for the Boombox."));
			enableVolumeControllerRecordPlayer = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Audio", "EnableVolumeControllerRecordPlayer", true, "Enable volume control for the Record Player."));
			enableVolumeControllerTv = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Audio", "EnableVolumeControllerTv", true, "Enable volume control for the TV."));
			enableVolumeControllerShipSpeaker = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Audio", "EnableVolumeControllerShipSpeaker", true, "Enable volume control for the Ship Speaker."));
			enableVolumeControllerWalkman = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Audio", "EnableVolumeControllerWalkman", true, "[Lootable Music Tapes] Enable volume control for the Walkman. Only applies if the related mod is enabled."));
			enableVolumeControllerDisco = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Others", "EnableVolumeControllerDisco", false, "Enable volume control for the Disco."));
			enableVolumeControllerShower = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Others", "EnableVolumeControllerShower", false, "Enable volume control for the Shower."));
			enableVolumeControllerRomanticTable = AddConfigEntry<bool>(((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Others", "EnableVolumeControllerRomanticTableCandles", false, "Enable volume control for the Candles on the Romantic Table."));
			if (volumeIncrement.Value < 1)
			{
				volumeIncrement.Value = 1;
				((BaseUnityPlugin)Plugin.instance).Config.Save();
			}
			else if (volumeIncrement.Value > 100)
			{
				volumeIncrement.Value = 100;
				((BaseUnityPlugin)Plugin.instance).Config.Save();
			}
			TryRemoveOldConfigSettings();
		}

		public static ConfigEntry<T> AddConfigEntry<T>(ConfigEntry<T> configEntry)
		{
			currentConfigEntries.Add(((ConfigEntryBase)configEntry).Definition.Key, (ConfigEntryBase)(object)configEntry);
			return configEntry;
		}

		public static void TryRemoveOldConfigSettings()
		{
			HashSet<string> hashSet = new HashSet<string>();
			HashSet<string> hashSet2 = new HashSet<string>();
			foreach (ConfigEntryBase value in currentConfigEntries.Values)
			{
				hashSet.Add(value.Definition.Section);
				hashSet2.Add(value.Definition.Key);
			}
			try
			{
				ConfigFile config = ((BaseUnityPlugin)Plugin.instance).Config;
				string configFilePath = config.ConfigFilePath;
				if (!File.Exists(configFilePath))
				{
					return;
				}
				string text = File.ReadAllText(configFilePath);
				string[] array = File.ReadAllLines(configFilePath);
				string text2 = "";
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = array[i].Replace("\n", "");
					if (array[i].Length <= 0)
					{
						continue;
					}
					if (array[i].StartsWith("["))
					{
						if (text2 != "" && !hashSet.Contains(text2))
						{
							text2 = "[" + text2 + "]";
							int num = text.IndexOf(text2);
							int num2 = text.IndexOf(array[i]);
							text = text.Remove(num, num2 - num);
						}
						text2 = array[i].Replace("[", "").Replace("]", "").Trim();
					}
					else
					{
						if (!(text2 != ""))
						{
							continue;
						}
						if (i <= array.Length - 4 && array[i].StartsWith("##"))
						{
							int j;
							for (j = 1; i + j < array.Length && array[i + j].Length > 3; j++)
							{
							}
							if (hashSet.Contains(text2))
							{
								int num3 = array[i + j - 1].IndexOf("=");
								string item = array[i + j - 1].Substring(0, num3 - 1);
								if (!hashSet2.Contains(item))
								{
									int num4 = text.IndexOf(array[i]);
									int num5 = text.IndexOf(array[i + j - 1]) + array[i + j - 1].Length;
									text = text.Remove(num4, num5 - num4);
								}
							}
							i += j - 1;
						}
						else if (array[i].Length > 3)
						{
							text = text.Replace(array[i], "");
						}
					}
				}
				if (!hashSet.Contains(text2))
				{
					text2 = "[" + text2 + "]";
					int num6 = text.IndexOf(text2);
					text = text.Remove(num6, text.Length - num6);
				}
				while (text.Contains("\n\n\n"))
				{
					text = text.Replace("\n\n\n", "\n\n");
				}
				File.WriteAllText(configFilePath, text);
				config.Reload();
			}
			catch
			{
			}
		}
	}
}
namespace ObjectVolumeController.Compatibility
{
	public static class InputUtils_Compat
	{
		internal static InputActionAsset Asset => IngameKeybinds.GetAsset();

		internal static bool Enabled => Plugin.IsModLoaded("com.rune580.LethalCompanyInputUtils");

		public static InputAction VolumeDownHotkey => IngameKeybinds.Instance.VolumeDownHotkey;

		public static InputAction VolumeUpHotkey => IngameKeybinds.Instance.VolumeUpHotkey;
	}
}
namespace ObjectVolumeController.AudioPlayers
{
	public class AudioPlayerPlaceable : AudioPlayerTypeBase
	{
		public AudioPlayerPlaceable(string name)
			: base(name)
		{
		}
	}
	public class AudioPlayerGrabbable : AudioPlayerTypeBase
	{
		public List<GrabbableObject> items;

		public AudioPlayerGrabbable(string name)
			: base(name)
		{
			items = new List<GrabbableObject>();
		}
	}
	public abstract class AudioPlayerTypeBase
	{
		public string name = "default";

		public List<AudioSource> audioSources;

		public float defaultVolume = 0f;

		public float currentVolumeMultiplier = 0.8f;

		public AudioPlayerTypeBase(string name)
		{
			this.name = name;
			audioSources = new List<AudioSource>();
		}

		public void UpdateVolumes()
		{
			for (int i = 0; i < audioSources.Count; i++)
			{
				if ((Object)(object)audioSources[i] != (Object)null)
				{
					audioSources[i].volume = Mathf.Clamp(currentVolumeMultiplier, 0f, ObjectsManager.maxVolumeMultiplier) * defaultVolume;
				}
			}
		}

		public void SavePreferences()
		{
			if (!string.IsNullOrEmpty(name))
			{
				ES3.Save<float>("ObjectVolumeController.Volume." + name, currentVolumeMultiplier);
			}
		}

		public void LoadPreferences()
		{
			if (string.IsNullOrEmpty(name))
			{
				return;
			}
			try
			{
				currentVolumeMultiplier = ES3.Load<float>("ObjectVolumeController.Volume." + name, 0.8f);
			}
			catch
			{
				ES3.DeleteKey("ObjectVolumeController.Volume." + name);
			}
		}
	}
}