Decompiled source of Michaels Company v1.0.2

SoundboardRadio.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using SoundboardRadio.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SoundboardRadio")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Soundboard Radio")]
[assembly: AssemblyTitle("SoundboardRadio")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 SoundboardRadio
{
	[HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")]
	internal static class DevCommand
	{
		private const string Keyword = "blowod";

		[HarmonyPrefix]
		private static bool Prefix(Terminal __instance, ref TerminalNode __result)
		{
			try
			{
				if (!Plugin.EnableDevCommand.Value)
				{
					return true;
				}
				string text = __instance.screenText.text;
				int num = Math.Min(__instance.textAdded, text.Length);
				string text2 = text.Substring(text.Length - num).Trim().ToLowerInvariant();
				if (!text2.StartsWith("blowod"))
				{
					return true;
				}
				string arg = text2.Substring("blowod".Length).Trim();
				__result = Reply(Run(__instance, arg));
				return false;
			}
			catch (Exception arg2)
			{
				Plugin.Log.LogError((object)$"Dev command failed: {arg2}");
				return true;
			}
		}

		private static string Run(Terminal terminal, string arg)
		{
			if ((Object)(object)NetworkManager.Singleton == (Object)null || !NetworkManager.Singleton.IsServer)
			{
				return "Dev commands only work for the host.\n\n";
			}
			if (arg == null || arg.Length != 0)
			{
				if (!(arg == "money"))
				{
					if (arg == "sounds")
					{
						return SoundLibrary.StatusReport() + "\n";
					}
					return "Unknown dev command.\n\n";
				}
				terminal.groupCredits += 1000;
				terminal.SyncGroupCreditsServerRpc(terminal.groupCredits, terminal.numberOfItemsInDropship);
				return "+1000 credits.\n\n";
			}
			return SpawnRadio();
		}

		private static string SpawnRadio()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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)
			Item radioDefinition = Plugin.RadioDefinition;
			if ((Object)(object)radioDefinition == (Object)null || (Object)(object)radioDefinition.spawnPrefab == (Object)null)
			{
				return "Radio is not registered.\n\n";
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			Vector3 val = ((Component)localPlayerController).transform.position + ((Component)localPlayerController).transform.forward * 1f + Vector3.up * 0.6f;
			Transform val2 = (((Object)(object)RoundManager.Instance != (Object)null) ? RoundManager.Instance.spawnedScrapContainer : null);
			Object.Instantiate<GameObject>(radioDefinition.spawnPrefab, val, Quaternion.identity, val2).GetComponent<NetworkObject>().Spawn(false);
			return "Radio spawned at your feet.\n\n";
		}

		private static TerminalNode Reply(string message)
		{
			TerminalNode obj = ScriptableObject.CreateInstance<TerminalNode>();
			obj.displayText = message;
			obj.clearPreviousText = true;
			return obj;
		}
	}
	[BepInPlugin("BloWodDess.MichaelsCompany", "Michael's Company", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		public static ConfigEntry<int> ShopPrice;

		public static ConfigEntry<bool> SpawnAsScrap;

		public static ConfigEntry<int> ScrapRarity;

		public static ConfigEntry<int> ScrapMinValue;

		public static ConfigEntry<int> ScrapMaxValue;

		public static ConfigEntry<float> Volume;

		public static ConfigEntry<float> NoiseRange;

		public static ConfigEntry<bool> AlertEnemies;

		public static ConfigEntry<Vector3> HoldPosition;

		public static ConfigEntry<Vector3> HoldRotation;

		public static ConfigEntry<bool> EnableDevCommand;

		public static ConfigEntry<Key> PrevKey;

		public static ConfigEntry<Key> NextKey;

		public static Item RadioDefinition;

		public static Plugin Instance { get; private set; }

		public static string PluginDir => Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location);

		public static string SoundsDir => Path.Combine(PluginDir, "sounds");

		private void Awake()
		{
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			ShopPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "Price", 25, "Credits to buy the radio from the terminal (0 = free)");
			SpawnAsScrap = ((BaseUnityPlugin)this).Config.Bind<bool>("Scrap", "SpawnAsScrap", true, "Also spawn the radio as scrap inside facilities on every moon");
			ScrapRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "Rarity", 15, "Spawn weight. Vanilla items go from ~5 (rare) to ~100 (very common)");
			ScrapMinValue = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "MinValue", 20, "Minimum scrap value when found on a moon");
			ScrapMaxValue = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "MaxValue", 60, "Maximum scrap value when found on a moon");
			Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "Volume", 1f, "Playback volume 0.0 - 1.0");
			NoiseRange = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "NoiseRange", 25f, "How far (meters) the sound can be heard");
			AlertEnemies = ((BaseUnityPlugin)this).Config.Bind<bool>("Audio", "AlertEnemies", true, "Whether playing a sound counts as noise that can attract monsters");
			HoldPosition = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Held", "PositionOffset", new Vector3(-0.12f, 0.04f, 0.06f), "Where the radio sits in your hand (x, y, z). Restart the game after changing.");
			HoldRotation = ((BaseUnityPlugin)this).Config.Bind<Vector3>("Held", "RotationOffset", new Vector3(0f, 90f, 0f), "How the radio is rotated in your hand (degrees). Restart the game after changing.");
			PrevKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "PreviousClipKey", (Key)31, "Key for the previous clip while holding the radio");
			NextKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "NextClipKey", (Key)19, "Key for the next clip while holding the radio");
			EnableDevCommand = ((BaseUnityPlugin)this).Config.Bind<bool>("Dev", "EnableCommand", false, "Hidden terminal test command (host only). Set to true to test.");
			Harmony.CreateAndPatchAll(typeof(DevCommand), "BloWodDess.MichaelsCompany");
			InitializeNetcode();
			SoundLibrary.LoadAll(SoundsDir);
			RegisterRadio();
			Log.LogInfo((object)("Michael's Company 1.0.2 loaded. Sounds folder: " + SoundsDir));
		}

		private static void InitializeNetcode()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			for (int i = 0; i < types.Length; i++)
			{
				MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}

		private static void RegisterRadio()
		{
			Item val = (RadioDefinition = RadioPrefabBuilder.BuildItem());
			TerminalNode val2 = ScriptableObject.CreateInstance<TerminalNode>();
			val2.displayText = "A battered handheld radio with a few pre-recorded clips.\n\nPress the use button to play the selected clip, Q / E to change clip.\n\n";
			val2.clearPreviousText = true;
			val2.maxCharactersToType = 25;
			Items.RegisterShopItem(val, (TerminalNode)null, (TerminalNode)null, val2, ShopPrice.Value);
			if (SpawnAsScrap.Value)
			{
				Items.RegisterScrap(val, ScrapRarity.Value, (LevelTypes)(-1));
			}
			Log.LogInfo((object)$"Registered '{val.itemName}' (shop price {ShopPrice.Value}, scrap={SpawnAsScrap.Value}, rarity={ScrapRarity.Value})");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BloWodDess.MichaelsCompany";

		public const string PLUGIN_NAME = "Michael's Company";

		public const string PLUGIN_VERSION = "1.0.2";
	}
	public class RadioItem : PhysicsProp
	{
		public AudioSource audioSource;

		private int selectedIndex;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			if ((Object)(object)audioSource == (Object)null)
			{
				audioSource = ((Component)this).GetComponent<AudioSource>();
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown)
			{
				if (SoundLibrary.Count == 0)
				{
					HUDManager.Instance.DisplayTip("Radio", "No sounds installed (sounds/ folder is empty)", false, false, "LC_Tip1");
				}
				else
				{
					PlaySoundServerRpc(SoundLibrary.NameAt(selectedIndex));
				}
			}
		}

		public override void Update()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Update();
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null || (Object)(object)localPlayerController.currentlyHeldObjectServer != (Object)(object)this || localPlayerController.inTerminalMenu || localPlayerController.isTypingChat)
			{
				return;
			}
			Keyboard current = Keyboard.current;
			if (current != null)
			{
				if (((ButtonControl)current[Plugin.PrevKey.Value]).wasPressedThisFrame)
				{
					ChangeClip(-1);
				}
				if (((ButtonControl)current[Plugin.NextKey.Value]).wasPressedThisFrame)
				{
					ChangeClip(1);
				}
			}
		}

		private void ChangeClip(int direction)
		{
			if (SoundLibrary.Count != 0)
			{
				selectedIndex += direction;
				selectedIndex = (selectedIndex % SoundLibrary.Count + SoundLibrary.Count) % SoundLibrary.Count;
				RefreshControlTips();
			}
		}

		public override void SetControlTipsForItem()
		{
			RefreshControlTips();
		}

		public override void EquipItem()
		{
			((PhysicsProp)this).EquipItem();
			RefreshControlTips();
		}

		public override void PocketItem()
		{
			((GrabbableObject)this).PocketItem();
			if ((Object)(object)audioSource != (Object)null)
			{
				audioSource.Stop();
			}
		}

		private void RefreshControlTips()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)HUDManager.Instance == (Object)null))
			{
				PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
				if (!((Object)(object)localPlayerController == (Object)null) && !((Object)(object)localPlayerController.currentlyHeldObjectServer != (Object)(object)this))
				{
					string text = ((SoundLibrary.Count == 0) ? "none" : $"{SoundLibrary.NameAt(selectedIndex)} ({selectedIndex + 1}/{SoundLibrary.Count})");
					string[] array = new string[3]
					{
						"Play : [LMB]",
						$"Prev : [{Plugin.PrevKey.Value}]   Next : [{Plugin.NextKey.Value}]",
						"Clip : " + text
					};
					HUDManager.Instance.ChangeControlTipMultiple(array, true, ((GrabbableObject)this).itemProperties);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		private void PlaySoundServerRpc(string clipName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val2 = default(ServerRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(806875220u, val2, (RpcDelivery)0);
				bool flag = clipName != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(clipName, false);
				}
				((NetworkBehaviour)this).__endSendServerRpc(ref val, 806875220u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				PlaySoundClientRpc(clipName);
			}
		}

		[ClientRpc]
		private void PlaySoundClientRpc(string clipName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2702167081u, val2, (RpcDelivery)0);
				bool flag = clipName != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(clipName, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 2702167081u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				PlayLocal(clipName);
			}
		}

		private void PlayLocal(string clipName)
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			AudioClip val = SoundLibrary.Get(clipName);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)("Received clip '" + clipName + "' that this client does not have. Everyone needs the same sounds/ folder."));
				return;
			}
			float num = Mathf.Clamp01(Plugin.Volume.Value);
			audioSource.Stop();
			audioSource.maxDistance = Plugin.NoiseRange.Value;
			audioSource.PlayOneShot(val, num);
			WalkieTalkie.TransmitOneShotAudio(audioSource, val, num);
			if (Plugin.AlertEnemies.Value && (Object)(object)RoundManager.Instance != (Object)null)
			{
				bool flag = ((GrabbableObject)this).isInShipRoom && (Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.hangarDoorsClosed;
				RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, Plugin.NoiseRange.Value, 0.9f, 0, flag, 5);
			}
		}

		protected override void __initializeVariables()
		{
			((PhysicsProp)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(806875220u, new RpcReceiveHandler(__rpc_handler_806875220), "PlaySoundServerRpc");
			((NetworkBehaviour)this).__registerRpc(2702167081u, new RpcReceiveHandler(__rpc_handler_2702167081), "PlaySoundClientRpc");
			((PhysicsProp)this).__initializeRpcs();
		}

		private static void __rpc_handler_806875220(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string clipName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref clipName, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RadioItem)(object)target).PlaySoundServerRpc(clipName);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2702167081(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string clipName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref clipName, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RadioItem)(object)target).PlaySoundClientRpc(clipName);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "RadioItem";
		}
	}
	internal static class RadioPrefabBuilder
	{
		private const float ScrapMultiplier = 0.4f;

		public static Item BuildItem()
		{
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = BuildPrefab();
			Item val2 = ScriptableObject.CreateInstance<Item>();
			((Object)val2).name = "SoundboardRadioItem";
			val2.itemName = "Radio";
			val2.spawnPrefab = val;
			((GrabbableObject)val.GetComponent<RadioItem>()).itemProperties = val2;
			val2.isScrap = true;
			val2.minValue = Mathf.RoundToInt((float)Plugin.ScrapMinValue.Value / 0.4f);
			val2.maxValue = Mathf.RoundToInt((float)Plugin.ScrapMaxValue.Value / 0.4f);
			val2.weight = 1.05f;
			val2.twoHanded = false;
			val2.requiresBattery = false;
			val2.canBeGrabbedBeforeGameStart = true;
			val2.itemSpawnsOnGround = true;
			val2.isConductiveMetal = true;
			val2.allowDroppingAheadOfPlayer = true;
			val2.saveItemVariable = false;
			val2.itemIcon = MakeIcon();
			val2.grabSFX = Silence("radio_grab");
			val2.dropSFX = Silence("radio_drop");
			val2.pocketSFX = Silence("radio_pocket");
			val2.positionOffset = Plugin.HoldPosition.Value;
			val2.rotationOffset = Plugin.HoldRotation.Value;
			val2.restingRotation = new Vector3(0f, 0f, 0f);
			val2.verticalOffset = 0.1f;
			return val2;
		}

		private static GameObject BuildPrefab()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = NetworkPrefabs.CreateNetworkPrefab("SoundboardRadio");
			val.tag = "PhysicsProp";
			val.layer = LayerMask.NameToLayer("Props");
			NetworkObject component = val.GetComponent<NetworkObject>();
			if ((Object)(object)component != (Object)null)
			{
				component.AutoObjectParentSync = false;
			}
			BoxCollider obj = val.AddComponent<BoxCollider>();
			obj.size = new Vector3(0.34f, 0.2f, 0.12f);
			obj.center = new Vector3(0f, 0.1f, 0f);
			AudioSource val2 = val.AddComponent<AudioSource>();
			val2.spatialBlend = 1f;
			val2.rolloffMode = (AudioRolloffMode)1;
			val2.minDistance = 2f;
			val2.maxDistance = Plugin.NoiseRange.Value;
			val2.playOnAwake = false;
			val2.dopplerLevel = 0f;
			RadioItem radioItem = val.AddComponent<RadioItem>();
			radioItem.audioSource = val2;
			((GrabbableObject)radioItem).grabbable = true;
			((GrabbableObject)radioItem).grabbableToEnemies = true;
			((GrabbableObject)radioItem).mainObjectRenderer = BuildVisuals(val.transform);
			GameObject val3 = new GameObject("ScanNode")
			{
				layer = LayerMask.NameToLayer("ScanNode")
			};
			val3.transform.SetParent(val.transform, false);
			val3.transform.localPosition = new Vector3(0f, 0.1f, 0f);
			BoxCollider obj2 = val3.AddComponent<BoxCollider>();
			obj2.size = new Vector3(0.45f, 0.3f, 0.25f);
			((Collider)obj2).isTrigger = true;
			ScanNodeProperties obj3 = val3.AddComponent<ScanNodeProperties>();
			obj3.maxRange = 13;
			obj3.minRange = 1;
			obj3.headerText = "Radio";
			obj3.subText = "";
			obj3.nodeType = 2;
			obj3.scrapValue = 0;
			((GrabbableObject)radioItem).scrapValue = 0;
			return val;
		}

		private static MeshRenderer BuildVisuals(Transform parent)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			Material mat = MakeMaterial(new Color(0.12f, 0.35f, 0.27f));
			Material mat2 = MakeMaterial(new Color(0.06f, 0.06f, 0.07f));
			Material mat3 = MakeMaterial(new Color(0.7f, 0.7f, 0.72f));
			Material mat4 = MakeMaterial(new Color(0.9f, 0.55f, 0.1f));
			MeshRenderer result = Part((PrimitiveType)3, parent, "Body", new Vector3(0f, 0.1f, 0f), new Vector3(0.34f, 0.2f, 0.12f), mat);
			Part((PrimitiveType)3, parent, "Grill", new Vector3(-0.06f, 0.1f, 0.061f), new Vector3(0.18f, 0.14f, 0.004f), mat2);
			Part((PrimitiveType)2, parent, "KnobA", new Vector3(0.11f, 0.14f, 0.065f), new Vector3(0.05f, 0.012f, 0.05f), mat4, (Vector3?)new Vector3(90f, 0f, 0f));
			Part((PrimitiveType)2, parent, "KnobB", new Vector3(0.11f, 0.06f, 0.065f), new Vector3(0.05f, 0.012f, 0.05f), mat3, (Vector3?)new Vector3(90f, 0f, 0f));
			Part((PrimitiveType)2, parent, "Antenna", new Vector3(0.14f, 0.3f, 0f), new Vector3(0.012f, 0.1f, 0.012f), mat3);
			Part((PrimitiveType)3, parent, "Handle", new Vector3(0f, 0.215f, 0f), new Vector3(0.2f, 0.02f, 0.03f), mat2);
			return result;
		}

		private static MeshRenderer Part(PrimitiveType type, Transform parent, string name, Vector3 pos, Vector3 scale, Material mat, Vector3? euler = null)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive(type);
			((Object)val).name = name;
			Object.Destroy((Object)(object)val.GetComponent<Collider>());
			val.transform.SetParent(parent, false);
			val.transform.localPosition = pos;
			val.transform.localScale = scale;
			if (euler.HasValue)
			{
				val.transform.localEulerAngles = euler.Value;
			}
			val.layer = ((Component)parent).gameObject.layer;
			MeshRenderer component = val.GetComponent<MeshRenderer>();
			((Renderer)component).sharedMaterial = mat;
			return component;
		}

		private static Material MakeMaterial(Color color)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			Material val = new Material(Shader.Find("HDRP/Lit") ?? Shader.Find("Standard"));
			val.SetColor("_BaseColor", color);
			val.color = color;
			val.SetFloat("_Smoothness", 0.35f);
			return val;
		}

		private static Sprite MakeIcon()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0068: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					val.SetPixel(j, i, val2);
				}
			}
			Fill(val, 8, 14, 56, 44, new Color(0.12f, 0.35f, 0.27f));
			Fill(val, 12, 18, 36, 40, new Color(0.06f, 0.06f, 0.07f));
			Fill(val, 42, 36, 50, 42, new Color(0.9f, 0.55f, 0.1f));
			Fill(val, 42, 20, 50, 26, new Color(0.7f, 0.7f, 0.72f));
			Fill(val, 50, 44, 52, 60, new Color(0.7f, 0.7f, 0.72f));
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
		}

		private static void Fill(Texture2D tex, int x0, int y0, int x1, int y1, Color c)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			for (int i = y0; i < y1; i++)
			{
				for (int j = x0; j < x1; j++)
				{
					tex.SetPixel(j, i, c);
				}
			}
		}

		private static AudioClip Silence(string name)
		{
			AudioClip obj = AudioClip.Create(name, 441, 1, 44100, false);
			obj.SetData(new float[441], 0);
			return obj;
		}
	}
	public static class SoundLibrary
	{
		private class Runner : MonoBehaviour
		{
		}

		public static readonly List<string> Names = new List<string>();

		public static readonly Dictionary<string, AudioClip> Clips = new Dictionary<string, AudioClip>(StringComparer.OrdinalIgnoreCase);

		public static readonly List<string> Errors = new List<string>();

		public static bool Ready { get; private set; }

		public static string FolderPath { get; private set; } = "(not set)";

		public static int FilesFound { get; private set; }

		public static int Count => Names.Count;

		public static AudioClip Get(string name)
		{
			if (name == null || !Clips.TryGetValue(name, out var value))
			{
				return null;
			}
			return value;
		}

		public static string NameAt(int index)
		{
			if (Names.Count == 0)
			{
				return null;
			}
			index = (index % Names.Count + Names.Count) % Names.Count;
			return Names[index];
		}

		public static int IndexOf(string name)
		{
			if (name != null)
			{
				return Names.FindIndex((string n) => string.Equals(n, name, StringComparison.OrdinalIgnoreCase));
			}
			return -1;
		}

		public static string StatusReport()
		{
			string text = $"Folder: {FolderPath}\nFiles found: {FilesFound}\nLoaded: {Names.Count}\nFinished: {Ready}\n";
			if (Names.Count > 0)
			{
				text = text + "Clips: " + string.Join(", ", Names) + "\n";
			}
			if (Errors.Count > 0)
			{
				text = text + "Errors:\n" + string.Join("\n", Errors) + "\n";
			}
			return text;
		}

		public static void LoadAll(string folder)
		{
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Expected O, but got Unknown
			FolderPath = folder;
			try
			{
				if (!Directory.Exists(folder))
				{
					Plugin.Log.LogWarning((object)("Sounds folder not found, creating it: " + folder));
					Directory.CreateDirectory(folder);
				}
				Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
				try
				{
					string text = Path.Combine(Paths.CachePath, "BloWodDess.MichaelsCompany", "sounds");
					Directory.CreateDirectory(text);
					Assembly assembly = typeof(SoundLibrary).Assembly;
					string[] manifestResourceNames = assembly.GetManifestResourceNames();
					foreach (string text2 in manifestResourceNames)
					{
						if (!text2.StartsWith("sound:"))
						{
							continue;
						}
						string text3 = text2.Substring("sound:".Length);
						string text4 = Path.Combine(text, text3);
						using (Stream stream = assembly.GetManifestResourceStream(text2))
						{
							if (!File.Exists(text4) || new FileInfo(text4).Length != stream.Length)
							{
								using FileStream destination = File.Create(text4);
								stream.CopyTo(destination);
							}
						}
						dictionary[Path.GetFileNameWithoutExtension(text3)] = text4;
					}
					Plugin.Log.LogInfo((object)$"Built-in sounds: {dictionary.Count}");
				}
				catch (Exception ex)
				{
					Fail("built-in sounds", ex.ToString());
				}
				foreach (string item in from f in Directory.GetFiles(folder)
					where HasSupportedExtension(f)
					select f)
				{
					dictionary[Path.GetFileNameWithoutExtension(item)] = item;
				}
				List<string> list = (from kv in dictionary.OrderBy<KeyValuePair<string, string>, string>((KeyValuePair<string, string> kv) => kv.Key, StringComparer.OrdinalIgnoreCase)
					select kv.Value).ToList();
				FilesFound = list.Count;
				Plugin.Log.LogInfo((object)$"Sound loader: found {list.Count} file(s) in {folder}");
				if (list.Count == 0)
				{
					Plugin.Log.LogWarning((object)"No sound files found. Drop .wav/.ogg/.mp3 files into the sounds/ folder.");
					Ready = true;
					return;
				}
				GameObject val = new GameObject("MichaelsCompany_SoundLoader")
				{
					hideFlags = (HideFlags)61
				};
				Object.DontDestroyOnLoad((Object)val);
				((MonoBehaviour)val.AddComponent<Runner>()).StartCoroutine(LoadRoutine(list));
			}
			catch (Exception ex2)
			{
				Fail("startup", ex2.ToString());
				Ready = true;
			}
		}

		private static bool HasSupportedExtension(string path)
		{
			string text = Path.GetExtension(path).ToLowerInvariant();
			if (!(text == ".wav") && !(text == ".ogg"))
			{
				return text == ".mp3";
			}
			return true;
		}

		private static AudioType TypeFor(string path)
		{
			string text = Path.GetExtension(path).ToLowerInvariant();
			if (!(text == ".ogg"))
			{
				if (text == ".mp3")
				{
					return (AudioType)13;
				}
				return (AudioType)20;
			}
			return (AudioType)14;
		}

		private static void Fail(string what, string message)
		{
			string text = what + ": " + message;
			Errors.Add(text);
			Plugin.Log.LogError((object)("Sound loader error - " + text));
		}

		private static IEnumerator LoadRoutine(List<string> files)
		{
			foreach (string file in files)
			{
				yield return Safe(LoadOne(file), Path.GetFileName(file));
			}
			Ready = true;
			Plugin.Log.LogInfo((object)string.Format("Soundboard ready with {0} clip(s): {1}", Names.Count, string.Join(", ", Names)));
		}

		private static IEnumerator Safe(IEnumerator inner, string label)
		{
			while (true)
			{
				object current;
				try
				{
					if (!inner.MoveNext())
					{
						break;
					}
					current = inner.Current;
				}
				catch (Exception ex)
				{
					Fail(label, ex.ToString());
					break;
				}
				yield return current;
			}
		}

		private static IEnumerator LoadOne(string file)
		{
			string name = Path.GetFileNameWithoutExtension(file);
			string absoluteUri = new Uri(file).AbsoluteUri;
			UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(absoluteUri, TypeFor(file));
			try
			{
				yield return req.SendWebRequest();
				if ((int)req.result != 1)
				{
					Fail(name, "request failed: " + req.error);
					yield break;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(req);
				if ((Object)(object)content == (Object)null)
				{
					Fail(name, "decoded clip is null");
					yield break;
				}
				((Object)content).name = name;
				Clips[name] = content;
				Names.Add(name);
				Plugin.Log.LogInfo((object)$"Loaded sound '{name}' ({content.length:0.0}s)");
			}
			finally
			{
				((IDisposable)req)?.Dispose();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SoundboardRadio";

		public const string PLUGIN_NAME = "Soundboard Radio";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace SoundboardRadio.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}