Decompiled source of WalkieVolume v1.1.0

plugins/WalkieVolume.dll

Decompiled 10 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using UnityEngine;
using WalkieVolume.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("WalkieVolume")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WalkieVolume")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("701e73b2-c2bf-4a50-b930-61df07d52650")]
[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 WalkieVolume
{
	[BepInPlugin("unity.WalkieVolumeMod", "WalkieVolume", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class WalkieVolumeBase : BaseUnityPlugin
	{
		private const string modGUID = "unity.WalkieVolumeMod";

		private const string modName = "WalkieVolume";

		private const string modVersion = "1.1.0";

		public static ConfigEntry<float> WalkieVolume;

		private readonly Harmony harmony = new Harmony("unity.WalkieVolumeMod");

		private static WalkieVolumeBase Instance;

		public static ManualLogSource mls;

		private void Awake()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			mls = Logger.CreateLogSource("unity.WalkieVolumeMod");
			WalkieVolume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "WalkieVolume", 1f, "Volume multiplier. 0.5 for 50%, 0.75 for 75% etc. Default is 100%.");
			FloatSliderConfigItem val = new FloatSliderConfigItem(WalkieVolume, new FloatSliderOptions
			{
				RequiresRestart = false,
				Min = 0f,
				Max = 1f
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
			LethalConfigManager.SetModDescription("Mod for adjusting walkie talkie volume.");
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			harmony.PatchAll(typeof(WalkieVolumeBase));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			mls.LogInfo((object)$"WalkieVolume mod loaded. Walkie volume set to: {WalkieVolume.Value * 100f}%");
		}
	}
}
namespace WalkieVolume.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		public const float DEFAULT_VOLUME_ALIVE = 1f;

		public const float DEFAULT_VOLUME_DEAD = 0.8f;

		[HarmonyPatch("UpdatePlayerVoiceEffects")]
		[HarmonyPostfix]
		public static void PatchUpdatePlayerVoiceEffects()
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return;
			}
			PlayerControllerB val = ((!GameNetworkManager.Instance.localPlayerController.isPlayerDead || !((Object)(object)GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript != (Object)null)) ? GameNetworkManager.Instance.localPlayerController : GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript);
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val2 in allPlayerScripts)
			{
				if ((val2.isPlayerControlled || val2.isPlayerDead) && !((Object)(object)val2 == (Object)(object)GameNetworkManager.Instance.localPlayerController) && val2.voicePlayerState != null && val2.currentVoiceChatIngameSettings._playerState != null && !((Object)(object)val2.currentVoiceChatAudioSource == (Object)null) && !val2.isPlayerDead)
				{
					bool flag = val2.speakingToWalkieTalkie && val.holdingWalkieTalkie && (Object)(object)val2 != (Object)(object)val;
					float num = (GameNetworkManager.Instance.localPlayerController.isPlayerDead ? 0.8f : 1f);
					if (flag)
					{
						val2.voicePlayerState.Volume = num * WalkieVolumeBase.WalkieVolume.Value;
					}
				}
			}
		}
	}
}