using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using LCSoundTool;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
[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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("LC_SoundTool")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("RadioStatic")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Add a static sound effect to the radio")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RadioStatic")]
[assembly: AssemblyTitle("RadioStatic")]
[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 RadioStatic
{
[BepInPlugin("RadioStatic", "RadioStatic", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
public static class PlayerControllerBPatch
{
public static void Postfix(PlayerControllerB __instance)
{
if (((((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || __instance.isTestingPlayer) && (Object)(object)_staticSource == (Object)null)
{
Debug.Log((object)("Attached static source to PlayerControllerB " + __instance.playerUsername));
_staticSource = ((Component)__instance).gameObject.AddComponent<AudioSource>();
_staticSource.clip = _staticNoise;
_staticSource.loop = true;
_staticSource.volume = 0f;
_staticSource.panStereo = 0.4f;
if ((Object)(object)((Component)_staticSource).GetComponent<AudioLowPassFilter>() == (Object)null && (Object)(object)((Component)_staticSource).GetComponent<OccludeAudio>() == (Object)null)
{
Debug.Log((object)"Instantiating audio filters for static effect");
AudioLowPassFilter val = ((Component)_staticSource).gameObject.AddComponent<AudioLowPassFilter>();
OccludeAudio val2 = ((Component)_staticSource).gameObject.AddComponent<OccludeAudio>();
val.lowpassResonanceQ = 3f;
val2.lowPassOverride = 5000f;
}
}
}
}
[HarmonyPatch(typeof(StartOfRound), "UpdatePlayerVoiceEffects")]
public static class VoiceEffectUpdatePatch
{
public static void Postfix(StartOfRound __instance)
{
//IL_0087: 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)
PlayerControllerB val = ((!GameNetworkManager.Instance.localPlayerController.isPlayerDead || !((Object)(object)GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript != (Object)null)) ? GameNetworkManager.Instance.localPlayerController : GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript);
float num = 0f;
for (int i = 0; i < __instance.allPlayerScripts.Length; i++)
{
PlayerControllerB val2 = __instance.allPlayerScripts[i];
if (val2.speakingToWalkieTalkie && val.holdingWalkieTalkie && (Object)(object)val != (Object)(object)val2)
{
float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)val2).transform.position);
Debug.Log((object)$"Static Scaling: {val2.playerUsername} Player distance: {num2}, setting volume {ScaleVolume(num2)}");
num = Math.Max(num, ScaleVolume(num2));
}
if (num > 0f)
{
_staticSource.volume = num;
if (!_staticSource.isPlaying)
{
_staticSource.Play();
}
}
else
{
_staticSource.volume = 0f;
_staticSource.Pause();
}
}
}
private static float ScaleVolume(float distance)
{
if (!(distance < 50f))
{
if (distance > 700f)
{
return 1f;
}
float val = (distance - 50f) / 650f;
return Math.Max(0.1f, val);
}
return 0.1f;
}
}
private static AudioClip _staticNoise;
private static AudioSource _staticSource;
private static readonly List<AudioSource> StaticSources = new List<AudioSource>();
private void Awake()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin RadioStatic is loaded.");
_staticNoise = SoundTool.GetAudioClip("aRealHumanBean-RadioStatic", "static.mp3");
Harmony val = new Harmony("RadioStatic");
val.PatchAll();
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "RadioStatic";
public const string PLUGIN_NAME = "RadioStatic";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}