Decompiled source of Walkie Talkies v1.1.2

WalkieTalkiePlugin.dll

Decompiled 3 days 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using WalkieTalkiePlugin.Controllers;
using WalkieTalkiePlugin.Helpers;
using WalkieTalkiePlugin.Patches;
using WalkieTalkiePlugin.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("WalkieTalkiePlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4aefc53736a3ceac4a34de7f53be8366ff5fa011")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("WalkieTalkiePlugin")]
[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;
		}
	}
}
public class ConfigManager
{
	public static ConfigEntry<bool> rechargeBattery;

	public static ConfigEntry<int> maxWalkieTalkieBattery;

	public static ConfigEntry<string> useWalkieTalkieKey;

	public static ConfigEntry<bool> enemiesShouldHearWalkieTalkie;

	private static readonly string[] validKeys = (from KeyCode key in Enum.GetValues(typeof(KeyCode))
		where (int)key < 323
		select ((object)(KeyCode)(ref key)).ToString()).ToArray();

	public static void Setup(BaseUnityPlugin plugin)
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		rechargeBattery = plugin.Config.Bind<bool>("Battery (host only)", "Recharge battery", true, "Should the battery recharge during the level?");
		maxWalkieTalkieBattery = plugin.Config.Bind<int>("Battery (host only)", "Max Walkie Talkie Battery", 40, new ConfigDescription("Max battery for the walkie talkie. Default is 40.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 200), Array.Empty<object>()));
		enemiesShouldHearWalkieTalkie = plugin.Config.Bind<bool>("Enemies (host only)", "Enemies should hear walkie talkie", true, "Should the enemies hear the walkie talkie?");
		useWalkieTalkieKey = plugin.Config.Bind<string>("Controls", "Use Walkie Talkie Key", "F", new ConfigDescription("Key to use the walkie talkie.", (AcceptableValueBase)(object)new AcceptableValueList<string>(validKeys), Array.Empty<object>()));
	}

	public static KeyCode GetWalkieTalkieKey()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		if (Enum.TryParse<KeyCode>(useWalkieTalkieKey.Value, out KeyCode result))
		{
			return result;
		}
		return (KeyCode)102;
	}
}
namespace WalkieTalkiePlugin
{
	[BepInPlugin("com.surfknasen.WalkieTalkieMod", "Walkie Talkie Mod", "1.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private readonly Harmony __harmony = new Harmony("org.surfknasen.WalkieTalkieMod");

		private void Awake()
		{
			ConfigManager.Setup((BaseUnityPlugin)(object)this);
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin Walkie Talkie is loaded!");
			__harmony.PatchAll(typeof(PlayerAvatarPatch));
			__harmony.PatchAll(typeof(CustomPosePatch));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "WalkieTalkiePlugin";

		public const string PLUGIN_NAME = "My first plugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace WalkieTalkiePlugin.UI
{
	public class PlayerAvatarUI : MonoBehaviour
	{
		private Transform topHeadImg;

		private Transform bottomHeadImg;

		private PlayerAvatar playerAvatar;

		public AudioSource speakerAudioSource;

		public float loudnessAmplifier = 2000f;

		public bool isTalking = false;

		public float clipLoudness = 0f;

		private float[] audioSpectrum = new float[1024];

		private Vector2 originalPosition;

		private void Awake()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			originalPosition = ((Component)this).GetComponent<RectTransform>().anchoredPosition;
		}

		public void Init(Transform _topHeadImg, Transform _bottomHeadImg, PlayerAvatar _playerAvatar)
		{
			topHeadImg = _topHeadImg;
			bottomHeadImg = _bottomHeadImg;
			playerAvatar = _playerAvatar;
			HideHead();
			((MonoBehaviour)this).StartCoroutine(WaitForVoiceChat(playerAvatar));
		}

		private IEnumerator WaitForVoiceChat(PlayerAvatar avatar)
		{
			FieldInfo field = typeof(PlayerAvatar).GetField("voiceChat", BindingFlags.Instance | BindingFlags.NonPublic);
			PlayerVoiceChat vc;
			while (true)
			{
				object? value = field.GetValue(avatar);
				vc = (PlayerVoiceChat)((value is PlayerVoiceChat) ? value : null);
				if ((Object)(object)vc != (Object)null)
				{
					break;
				}
				yield return (object)new WaitForSeconds(0.5f);
			}
			speakerAudioSource = ((Component)vc).GetComponent<AudioSource>();
		}

		public int GetViewId()
		{
			return playerAvatar.photonView.ViewID;
		}

		public void SetPositionBasedOnIndex(int index)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = ((Component)this).GetComponent<RectTransform>();
			component.anchoredPosition = new Vector2(originalPosition.x, ((Component)GoalUI.instance).transform.localPosition.y - 80f - (float)(index * 35));
		}

		public void ShowHead()
		{
			Debug.Log((object)"showing head!!");
			((Component)topHeadImg).gameObject.SetActive(true);
			((Component)bottomHeadImg).gameObject.SetActive(true);
			isTalking = true;
		}

		public void HideHead()
		{
			((Component)topHeadImg).gameObject.SetActive(false);
			((Component)bottomHeadImg).gameObject.SetActive(false);
			isTalking = false;
		}

		private void Update()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)speakerAudioSource != (Object)null)
			{
				speakerAudioSource.GetSpectrumData(audioSpectrum, 0, (FFTWindow)5);
				clipLoudness = Mathf.Max(audioSpectrum);
				topHeadImg.localEulerAngles = new Vector3(0f, 0f, clipLoudness * loudnessAmplifier);
			}
		}
	}
	public class WalkieEnergyUI : SemiUI
	{
		private TextMeshProUGUI Text;

		public static WalkieEnergyUI instance;

		private TextMeshProUGUI textEnergyMax;

		public override void Start()
		{
			((SemiUI)this).Start();
			Text = ((Component)this).GetComponent<TextMeshProUGUI>();
			instance = this;
			textEnergyMax = ((Component)((Component)this).transform.Find("EnergyMax")).GetComponent<TextMeshProUGUI>();
		}

		public void SetWalkieStamina(float stamina, float maxStamina)
		{
			if (!((Object)(object)Text == (Object)null) && !((Object)(object)textEnergyMax == (Object)null))
			{
				((TMP_Text)Text).text = Mathf.Ceil(stamina).ToString();
				((TMP_Text)textEnergyMax).text = "<b>/</b>" + Mathf.Ceil(maxStamina);
			}
		}
	}
}
namespace WalkieTalkiePlugin.Patches
{
	[HarmonyPatch(typeof(PlayerAvatarRightArm), "Update")]
	public static class CustomPosePatch
	{
		private static bool Prefix(PlayerAvatarRightArm __instance)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (WalkieTalkieController.playerIdsUsingWalkie.Contains(__instance.playerAvatar.photonView.ViewID))
				{
					__instance.SetPose(WalkieTalkieController.walkieTalkiePos);
					__instance.HeadAnimate(false);
					__instance.AnimatePose();
					return false;
				}
			}
			catch (Exception)
			{
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal class PlayerAvatarPatch
	{
		[HarmonyPatch(typeof(PlayerVoiceChat), "Awake")]
		[HarmonyPostfix]
		private static void PlayerVoiceChatToggleLobbyPatch(PlayerVoiceChat __instance)
		{
			if (!((Object)(object)((Component)__instance).gameObject.GetComponent<WalkieTalkieController>() != (Object)null))
			{
				((Component)__instance).gameObject.AddComponent<WalkieTalkieController>();
			}
		}
	}
}
namespace WalkieTalkiePlugin.Controllers
{
	public class PlayerAvatarController : MonoBehaviour
	{
		private List<PlayerAvatarUI> playerAvatars = new List<PlayerAvatarUI>();

		private List<PlayerAvatarUI> shownAvatars = new List<PlayerAvatarUI>();

		private void Start()
		{
			PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
			Debug.Log((object)$"[WalkieTalkiePlugin] Found {array.Length} players in the scene.");
			PlayerAvatar[] array2 = array;
			foreach (PlayerAvatar val in array2)
			{
				if (!val.photonView.IsMine)
				{
					CreateAvatarHead(val);
				}
			}
		}

		private void CreateAvatarHead(PlayerAvatar playerAvatar)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0073: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("PlayerAvatar");
			val.transform.SetParent(((Component)this).transform, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.anchorMin = new Vector2(1f, 0f);
			val2.anchorMax = new Vector2(1f, 0f);
			val2.pivot = new Vector2(1f, 0f);
			val2.offsetMax = new Vector2(620f, -5f);
			val2.offsetMin = new Vector2(0f, 0f);
			GameObject val3 = new GameObject("TopHead");
			val3.transform.SetParent(val.transform, false);
			RectTransform val4 = val3.AddComponent<RectTransform>();
			val4.sizeDelta = new Vector2(30f, 20f);
			val4.pivot = new Vector2(0f, 0f);
			val4.anchoredPosition = new Vector2(-15f, 10f);
			GameObject val5 = new GameObject("BottomHead");
			val5.transform.SetParent(val.transform, false);
			RectTransform val6 = val5.AddComponent<RectTransform>();
			val6.sizeDelta = new Vector2(30f, 8f);
			val6.anchoredPosition = new Vector2(0f, 5f);
			val3.AddComponent<CanvasRenderer>();
			val5.AddComponent<CanvasRenderer>();
			Image val7 = val3.AddComponent<Image>();
			Image val8 = val5.AddComponent<Image>();
			val7.sprite = AssetBundleHelper.GetSprite("player_top");
			val8.sprite = AssetBundleHelper.GetSprite("player_bot");
			FieldInfo field = typeof(PlayerAvatarVisuals).GetField("color", BindingFlags.Instance | BindingFlags.NonPublic);
			Color color = (((Graphic)val7).color = (Color)field.GetValue(playerAvatar.playerAvatarVisuals));
			((Graphic)val8).color = color;
			PlayerAvatarUI playerAvatarUI = val.AddComponent<PlayerAvatarUI>();
			playerAvatarUI.Init(val3.transform, val5.transform, playerAvatar);
			playerAvatars.Add(playerAvatarUI);
		}

		public void ShowHead(int viewId, bool isTalking)
		{
			foreach (PlayerAvatarUI playerAvatar in playerAvatars)
			{
				if (playerAvatar.GetViewId() != viewId)
				{
					continue;
				}
				if (isTalking)
				{
					playerAvatar.ShowHead();
					if (!shownAvatars.Contains(playerAvatar))
					{
						shownAvatars.Add(playerAvatar);
						playerAvatar.SetPositionBasedOnIndex(shownAvatars.Count - 1);
					}
					continue;
				}
				playerAvatar.HideHead();
				if (shownAvatars.Contains(playerAvatar))
				{
					shownAvatars.Remove(playerAvatar);
					for (int i = 0; i < shownAvatars.Count; i++)
					{
						shownAvatars[i].SetPositionBasedOnIndex(i);
					}
				}
			}
		}
	}
	public class WalkieTalkieController : MonoBehaviourPun
	{
		private float currentWalkieStamina;

		private float maxWalkieStamina = 40f;

		private bool rechargeBattery = true;

		private bool enemyShouldHearWalkie = true;

		private bool first = false;

		public static bool usingWalkieTalkie = false;

		private bool canUseWalkieTalkie = true;

		public WalkieEnergyUI walkieEnergyUI;

		private PlayerAvatarController playerAvatarsController;

		private PlayerAvatar localPlayerAvatar;

		private GameObject walkieTalkieObj;

		private GameObject walkieTalkieArm;

		public static Vector3 walkieTalkiePos = new Vector3(0f, -30f, 0f);

		public static List<int> playerIdsUsingWalkie = new List<int>();

		private AudioSource walkieSoundOn;

		private AudioSource walkieSoundOnIdle;

		private AudioSource walkieSoundOff;

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			Debug.Log((object)("[WalkieTalkiePlugin] Scene loaded: " + ((Scene)(ref scene)).name));
			bool flag = (int)GameDirector.instance.currentState == 2 && SemiFunc.RunIsLevel();
			Debug.Log((object)$"[WalkieTalkiePlugin] Is in game: {flag}");
			if (!flag)
			{
				first = false;
				if (SemiFunc.IsMasterClientOrSingleplayer())
				{
					rechargeBattery = ConfigManager.rechargeBattery.Value;
					maxWalkieStamina = ConfigManager.maxWalkieTalkieBattery.Value;
					enemyShouldHearWalkie = ConfigManager.enemiesShouldHearWalkieTalkie.Value;
					((MonoBehaviourPun)this).photonView.RPC("SyncSettings", (RpcTarget)0, new object[3] { maxWalkieStamina, rechargeBattery, enemyShouldHearWalkie });
					Debug.Log((object)$"[WalkieTalkiePlugin] Syncing settings: maxWalkieStamina: {maxWalkieStamina}, rechargeBattery: {rechargeBattery}, enemyShouldHearWalkie: {enemyShouldHearWalkie}");
				}
			}
		}

		private void Init()
		{
			currentWalkieStamina = maxWalkieStamina;
			PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
			PlayerAvatar[] array2 = array;
			foreach (PlayerAvatar val in array2)
			{
				if (val.photonView.IsMine)
				{
					localPlayerAvatar = val;
					Console.WriteLine($"[WalkieTalkiePlugin] Found local player: {val.photonView.ViewID}");
				}
			}
			CreateStaminaUI();
			CreatePlayerAvatarsContainer();
			((MonoBehaviourPun)this).photonView.RPC("GetLocalPlayerAvatar", (RpcTarget)0, new object[1] { localPlayerAvatar.photonView.ViewID });
			CreateWalkieTalkieLocal();
			((MonoBehaviourPun)this).photonView.RPC("CreateWalkieTalkieOthers", (RpcTarget)1, Array.Empty<object>());
		}

		[PunRPC]
		public void SyncSettings(float _maxBattery, bool _rechargeBattery, bool _enemyShouldHearWalkie)
		{
			maxWalkieStamina = _maxBattery;
			rechargeBattery = _rechargeBattery;
			enemyShouldHearWalkie = _enemyShouldHearWalkie;
			if ((Object)(object)walkieEnergyUI != (Object)null)
			{
				if (currentWalkieStamina > maxWalkieStamina)
				{
					currentWalkieStamina = maxWalkieStamina;
				}
				walkieEnergyUI.SetWalkieStamina(currentWalkieStamina, maxWalkieStamina);
			}
		}

		[PunRPC]
		public void GetLocalPlayerAvatar(int viewId)
		{
			PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
			PlayerAvatar[] array2 = array;
			foreach (PlayerAvatar val in array2)
			{
				if (val.photonView.ViewID == viewId)
				{
					localPlayerAvatar = val;
					Console.WriteLine($"[WalkieTalkiePlugin] Found local player: {val.photonView.ViewID}");
				}
			}
		}

		private void CreateStaminaUI()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Energy");
			GameObject val2 = Object.Instantiate<GameObject>(val, val.transform.parent);
			((Object)val2).name = "WalkieEnergy";
			Transform transform = val2.transform;
			transform.localPosition -= new Vector3(0f, 33f, 0f);
			EnergyUI component = val2.GetComponent<EnergyUI>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			TextMeshProUGUI[] componentsInChildren = val2.GetComponentsInChildren<TextMeshProUGUI>();
			TextMeshProUGUI[] array = componentsInChildren;
			foreach (TextMeshProUGUI val3 in array)
			{
				((Graphic)val3).color = new Color(0.88f, 0.69f, 1f, 1f);
			}
			((Behaviour)((Component)val2.transform).gameObject.GetComponentInChildren<Image>()).enabled = false;
			walkieEnergyUI = val2.AddComponent<WalkieEnergyUI>();
			walkieEnergyUI.SetWalkieStamina(maxWalkieStamina, maxWalkieStamina);
		}

		private void CreatePlayerAvatarsContainer()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Game Hud");
			GameObject val2 = new GameObject("PlayerAvatarsContainer");
			val2.transform.SetParent(val.transform, false);
			val2.transform.localPosition = new Vector3(0f, 0f, 0f);
			playerAvatarsController = val2.AddComponent<PlayerAvatarController>();
		}

		private void CreateWalkieTalkieLocal()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)localPlayerAvatar).transform.parent.Find("Local Camera");
			walkieTalkieArm = new GameObject("WalkieTalkieArm");
			walkieTalkieArm.transform.SetParent(((Component)val).transform);
			walkieTalkieArm.transform.localPosition = new Vector3(0f, 0f, 0f);
			GameObject prefab = AssetBundleHelper.GetPrefab("Walkie");
			GameObject val2 = Object.Instantiate<GameObject>(prefab);
			val2.transform.SetParent(walkieTalkieArm.transform);
			val2.transform.localPosition = new Vector3(0.2f, -0.15f, 0.265f);
			val2.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
			val2.transform.localRotation = Quaternion.Euler(17f, 17f, 5f);
			walkieSoundOn = ((Component)val2.transform.Find("OnSound")).gameObject.GetComponent<AudioSource>();
			walkieSoundOff = ((Component)val2.transform.Find("OffSound")).gameObject.GetComponent<AudioSource>();
			walkieSoundOnIdle = ((Component)val2.transform.Find("IdleOnSound")).gameObject.GetComponent<AudioSource>();
			((Component)walkieSoundOn).gameObject.SetActive(false);
			((Component)walkieSoundOff).gameObject.SetActive(false);
			((Component)walkieSoundOnIdle).gameObject.SetActive(false);
			walkieTalkieObj = val2;
		}

		[PunRPC]
		private void CreateWalkieTalkieOthers()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)localPlayerAvatar == (Object)null)
			{
				Debug.LogError((object)"[WalkieTalkiePlugin] Local player avatar not found!");
				return;
			}
			Transform rightArmTransform = ((Component)((Component)localPlayerAvatar).transform.parent).gameObject.GetComponentInChildren<PlayerAvatarRightArm>().rightArmTransform;
			GameObject prefab = AssetBundleHelper.GetPrefab("Walkie");
			GameObject val = Object.Instantiate<GameObject>(prefab);
			val.transform.SetParent(((Component)rightArmTransform).transform);
			val.transform.localPosition = new Vector3(0.05f, -0.034f, 0.479f);
			val.transform.localRotation = Quaternion.Euler(-17.5f, 52.7f, 81f);
			val.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
			walkieTalkieObj = val;
			walkieTalkieObj.SetActive(false);
		}

		private void OnDestroy()
		{
			Debug.Log((object)"[WalkieTalkiePlugin] WalkieTalkieController destroyed.");
			if ((Object)(object)walkieEnergyUI != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)walkieEnergyUI).gameObject);
				Debug.Log((object)"[WalkieTalkiePlugin] WalkieEnergyUI destroyed.");
			}
		}

		private void Update()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			if (!((MonoBehaviourPun)this).photonView.IsMine)
			{
				return;
			}
			bool flag = (int)GameDirector.instance.currentState == 2 && SemiFunc.RunIsLevel();
			if (flag && !first)
			{
				first = true;
				Init();
			}
			else if ((Object)(object)localPlayerAvatar == (Object)null)
			{
				return;
			}
			if (!flag || !first || localPlayerAvatar.spectating)
			{
				if (usingWalkieTalkie)
				{
					EnableWalkieTalkie(enable: false);
				}
				if (localPlayerAvatar.spectating && (Object)(object)walkieEnergyUI != (Object)null && ((Component)walkieEnergyUI).gameObject.activeInHierarchy)
				{
					((Component)walkieEnergyUI).gameObject.SetActive(false);
				}
				return;
			}
			if ((Object)(object)walkieEnergyUI != (Object)null && !((Component)walkieEnergyUI).gameObject.activeInHierarchy && !localPlayerAvatar.spectating)
			{
				((Component)walkieEnergyUI).gameObject.SetActive(true);
			}
			KeyCode walkieTalkieKey = ConfigManager.GetWalkieTalkieKey();
			if (Input.GetKey(walkieTalkieKey))
			{
				EnableWalkieTalkie(enable: true);
			}
			else if (Input.GetKeyUp(walkieTalkieKey))
			{
				EnableWalkieTalkie(enable: false);
			}
			WalkieStamina();
			AnimateLocalWalkieTalkie();
			HandleWalkieSoundEffects();
		}

		private void HandleWalkieSoundEffects()
		{
			float num = (float)DataDirector.instance.SettingValueFetch((Setting)1) * 0.01f * (float)DataDirector.instance.SettingValueFetch((Setting)13) * 0.01f * 0.3f;
			walkieSoundOn.volume = num * 0.5f;
			walkieSoundOff.volume = num * 0.5f;
			walkieSoundOnIdle.volume = num;
			if (usingWalkieTalkie && !((Component)walkieSoundOn).gameObject.activeSelf)
			{
				((Component)walkieSoundOn).gameObject.SetActive(true);
				((Component)walkieSoundOff).gameObject.SetActive(false);
				((Component)walkieSoundOnIdle).gameObject.SetActive(true);
			}
			else if (!usingWalkieTalkie && !((Component)walkieSoundOff).gameObject.activeSelf)
			{
				((Component)walkieSoundOn).gameObject.SetActive(false);
				((Component)walkieSoundOff).gameObject.SetActive(true);
				((Component)walkieSoundOnIdle).gameObject.SetActive(false);
			}
		}

		private void AnimateLocalWalkieTalkie()
		{
			//IL_0042: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)walkieTalkieArm == (Object)null)
			{
				return;
			}
			Quaternion val = (usingWalkieTalkie ? Quaternion.Euler(0f, 0f, 0f) : Quaternion.Euler(70f, 0f, 0f));
			walkieTalkieArm.transform.localRotation = Quaternion.Lerp(walkieTalkieArm.transform.localRotation, val, Time.deltaTime * 10f);
			if (!usingWalkieTalkie && Quaternion.Angle(walkieTalkieArm.transform.localRotation, val) < 1f)
			{
				if (walkieTalkieObj.activeSelf)
				{
					walkieTalkieObj.SetActive(false);
				}
			}
			else if (!walkieTalkieObj.activeSelf)
			{
				walkieTalkieObj.SetActive(true);
			}
		}

		private void EnableWalkieTalkie(bool enable)
		{
			if (enable && currentWalkieStamina > 1f && canUseWalkieTalkie && !usingWalkieTalkie)
			{
				usingWalkieTalkie = true;
				((MonoBehaviourPun)this).photonView.RPC("SetSpeakerRange", (RpcTarget)0, new object[2] { 10000, true });
				((MonoBehaviourPun)this).photonView.RPC("UpdatePlayersTalkingList", (RpcTarget)0, new object[2]
				{
					localPlayerAvatar.photonView.ViewID,
					true
				});
				((MonoBehaviourPun)this).photonView.RPC("ShowHead", (RpcTarget)0, new object[2]
				{
					localPlayerAvatar.photonView.ViewID,
					true
				});
				((MonoBehaviourPun)this).photonView.RPC("ShowWalkieTalkie", (RpcTarget)1, new object[1] { true });
			}
			else if (!enable && usingWalkieTalkie)
			{
				usingWalkieTalkie = false;
				((MonoBehaviourPun)this).photonView.RPC("ShowWalkieTalkie", (RpcTarget)1, new object[1] { false });
				((MonoBehaviourPun)this).photonView.RPC("UpdatePlayersTalkingList", (RpcTarget)0, new object[2]
				{
					localPlayerAvatar.photonView.ViewID,
					false
				});
				((MonoBehaviour)this).StartCoroutine(DisableWalkieTalkieAfterDelay(0.5f));
			}
		}

		private IEnumerator DisableWalkieTalkieAfterDelay(float delay)
		{
			canUseWalkieTalkie = false;
			yield return (object)new WaitForSeconds(delay);
			((MonoBehaviourPun)this).photonView.RPC("SetSpeakerRange", (RpcTarget)0, new object[2] { 25, false });
			((MonoBehaviourPun)this).photonView.RPC("ShowHead", (RpcTarget)0, new object[2]
			{
				localPlayerAvatar.photonView.ViewID,
				false
			});
			canUseWalkieTalkie = true;
		}

		[PunRPC]
		public void ShowWalkieTalkie(bool show)
		{
			if (!((Object)(object)walkieTalkieObj == (Object)null))
			{
				walkieTalkieObj.SetActive(show);
			}
		}

		private void WalkieStamina()
		{
			if (usingWalkieTalkie)
			{
				currentWalkieStamina -= Time.deltaTime * 5f;
				if (currentWalkieStamina <= -1f)
				{
					EnableWalkieTalkie(enable: false);
				}
			}
			else if (rechargeBattery)
			{
				currentWalkieStamina += Time.deltaTime * 1f;
				if (currentWalkieStamina > maxWalkieStamina)
				{
					currentWalkieStamina = maxWalkieStamina;
				}
			}
			if ((Object)(object)walkieEnergyUI != (Object)null)
			{
				walkieEnergyUI.SetWalkieStamina(currentWalkieStamina, maxWalkieStamina);
			}
		}

		[PunRPC]
		public void SetSpeakerRange(int range, bool usingWalkieTalkie)
		{
			AudioSource component = ((Component)this).gameObject.GetComponent<AudioSource>();
			AudioLowPassLogic component2 = ((Component)this).gameObject.GetComponent<AudioLowPassLogic>();
			component2.LogicActive = !usingWalkieTalkie;
			AudioLowPassFilter audioLowpassFilter = component2.AudioLowpassFilter;
			float lowPassMax = component2.LowPassMax;
			audioLowpassFilter.cutoffFrequency = (usingWalkieTalkie ? lowPassMax : 0f);
			AudioHighPassFilter val = ((Component)this).gameObject.GetComponent<AudioHighPassFilter>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)this).gameObject.AddComponent<AudioHighPassFilter>();
			}
			val.cutoffFrequency = (usingWalkieTalkie ? 1000 : 10);
			if ((Object)(object)component != (Object)null)
			{
				component.maxDistance = range;
			}
		}

		[PunRPC]
		public void UpdatePlayersTalkingList(int viewId, bool isSpeaking)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			if (isSpeaking && !playerIdsUsingWalkie.Contains(viewId))
			{
				playerIdsUsingWalkie.Add(viewId);
				if (((MonoBehaviourPun)this).photonView.IsMine || !enemyShouldHearWalkie)
				{
					return;
				}
				WalkieTalkieController[] array = Object.FindObjectsOfType<WalkieTalkieController>();
				foreach (WalkieTalkieController walkieTalkieController in array)
				{
					if (((MonoBehaviourPun)walkieTalkieController).photonView.IsMine)
					{
						Debug.Log((object)$"[WalkieTalkiePlugin] Set investigate at position: {((Component)walkieTalkieController.localPlayerAvatar).transform.position + Vector3.up * 0.2f}");
						EnemyDirector.instance.SetInvestigate(((Component)walkieTalkieController.localPlayerAvatar).transform.position + Vector3.up * 0.2f, 5f);
						break;
					}
				}
			}
			else if (!isSpeaking && playerIdsUsingWalkie.Contains(viewId))
			{
				playerIdsUsingWalkie.Remove(viewId);
			}
		}

		[PunRPC]
		public void ShowHead(int viewId, bool isTalking)
		{
			PlayerAvatarController componentInChildren = GameObject.Find("PlayerAvatarsContainer").GetComponentInChildren<PlayerAvatarController>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				Debug.LogError((object)"[WalkieTalkiePlugin] PlayerAvatarController not found!");
			}
			else
			{
				componentInChildren.ShowHead(viewId, isTalking);
			}
		}
	}
}
namespace WalkieTalkiePlugin.Helpers
{
	public static class AssetBundleHelper
	{
		private static string GetPluginDirectory()
		{
			string location = Assembly.GetExecutingAssembly().Location;
			return Path.GetDirectoryName(location);
		}

		private static T LoadAssetFromBundle<T>(string name, string bundleName) where T : Object
		{
			string text = Path.Combine(GetPluginDirectory(), bundleName);
			AssetBundle val = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)("Failed to load AssetBundle from path: " + text));
				return default(T);
			}
			T val2 = val.LoadAsset<T>(name);
			if ((Object)(object)val2 == (Object)null)
			{
				Debug.LogError((object)("Failed to load " + typeof(T).Name + " from AssetBundle: " + name));
			}
			val.Unload(false);
			return val2;
		}

		public static Sprite GetSprite(string name, string bundleName = "walkietalkie")
		{
			return LoadAssetFromBundle<Sprite>(name, bundleName);
		}

		public static GameObject GetPrefab(string name, string bundleName = "walkietalkie")
		{
			return LoadAssetFromBundle<GameObject>(name, bundleName);
		}
	}
}