Decompiled source of FrequencyWalkie v1.1.0

FrequencyWalkie.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("FrequencyWalkie")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FrequencyWalkie")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("35C861E5-B445-4C78-8068-886EDD23D8E3")]
[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 FrequencyWalkie;

public static class Assets
{
	private static Dictionary<string, Object> _assets = new Dictionary<string, Object>();

	public static T GetResource<T>(string objName) where T : Object
	{
		if (_assets.TryGetValue(objName, out var value))
		{
			return (T)(object)value;
		}
		T[] array = Resources.FindObjectsOfTypeAll<T>();
		T[] array2 = array;
		foreach (T val in array2)
		{
			if (((Object)val).name == objName)
			{
				_assets.Add(objName, (Object)(object)val);
				return val;
			}
		}
		return default(T);
	}
}
internal enum RpcExecStage
{
	None,
	Server,
	Client
}
[BepInPlugin("larko.frequencywalkie", "FrequencyWalkie", "1.3.1")]
public class FrequencyWalkie : BaseUnityPlugin
{
	public static Dictionary<int, int> walkieTalkieFrequencies = new Dictionary<int, int>();

	public static List<string> frequencies = new List<string>
	{
		"Al.l", "1", "2", "3", "4", "5", "6", "7", "8", "9",
		"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
		"20", "21", "22", "23", "24"
	};

	public static string tooltip = "[N] Increase frequency\n[M] Decrease frequency";

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony harmony = new Harmony("larko.frequencywalkie");
		Patches.ApplyPatches(harmony);
	}

	public static T GetResource<T>(string objName) where T : Object
	{
		T[] array = Resources.FindObjectsOfTypeAll<T>();
		T[] array2 = array;
		foreach (T val in array2)
		{
			if (((Object)val).name == objName)
			{
				return val;
			}
		}
		return default(T);
	}

	public static IEnumerator OnFrequencyChanged(WalkieTalkie walkie, bool increased)
	{
		Canvas canvas = ((Component)walkie).gameObject.GetComponent<Canvas>();
		Text text = ((Component)canvas).GetComponentInChildren<Text>();
		text.text = "<b><size=40>" + frequencies[walkieTalkieFrequencies[((Object)walkie).GetInstanceID()]] + "</size><i><size=30>BEn</size></i></b>";
		MethodInfo SendWalkieTalkieStartTransmissionSFX = AccessTools.Method(typeof(WalkieTalkie), "SendWalkieTalkieStartTransmissionSFX", (Type[])null, (Type[])null);
		SendWalkieTalkieStartTransmissionSFX.Invoke(walkie, new object[1] { (int)((GrabbableObject)walkie).playerHeldBy.playerClientId });
		if (walkieTalkieFrequencies[((Object)walkie).GetInstanceID()] == 0)
		{
			((Component)((Component)canvas).transform.GetChild(((Component)canvas).transform.childCount - 4)).gameObject.SetActive(true);
		}
		else
		{
			((Component)((Component)canvas).transform.GetChild(((Component)canvas).transform.childCount - 4)).gameObject.SetActive(false);
		}
		if (increased)
		{
			((Component)((Component)canvas).transform.GetChild(((Component)canvas).transform.childCount - 2)).gameObject.SetActive(false);
		}
		else
		{
			((Component)((Component)canvas).transform.GetChild(((Component)canvas).transform.childCount - 1)).gameObject.SetActive(false);
		}
		yield return (object)new WaitForSeconds(0.5f);
		((Component)((Component)canvas).transform.GetChild(((Component)canvas).transform.childCount - 1)).gameObject.SetActive(true);
		((Component)((Component)canvas).transform.GetChild(((Component)canvas).transform.childCount - 2)).gameObject.SetActive(true);
	}

	public static void SetPlayerSpeakingOnWalkieTalkieServerRpc(WalkieTalkie instance, int playerId, int frequency)
	{
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: 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_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Invalid comparison between Unknown and I4
		NetworkManager networkManager = ((NetworkBehaviour)instance).NetworkManager;
		if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening)
		{
			return;
		}
		int num = (int)AccessTools.Field(typeof(WalkieTalkie), "__rpc_exec_stage").GetValue(instance);
		MethodInfo methodInfo = AccessTools.Method(typeof(WalkieTalkie), "__beginSendServerRpc", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(WalkieTalkie), "__endSendServerRpc", (Type[])null, (Type[])null);
		if (num != 1 && (networkManager.IsClient || networkManager.IsHost))
		{
			if (((NetworkBehaviour)instance).OwnerClientId != networkManager.LocalClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
				return;
			}
			ServerRpcParams val = default(ServerRpcParams);
			FastBufferWriter val2 = (FastBufferWriter)methodInfo.Invoke(instance, new object[3]
			{
				64994802u,
				val,
				(object)(RpcDelivery)0
			});
			BytePacker.WriteValueBitPacked(val2, playerId);
			BytePacker.WriteValueBitPacked(val2, frequency);
			methodInfo2.Invoke(instance, new object[4]
			{
				val2,
				64994802u,
				val,
				(object)(RpcDelivery)0
			});
		}
		if (num == 1 && (networkManager.IsServer || networkManager.IsHost))
		{
			SetPlayerSpeakingOnWalkieTalkieClientRpc(instance, playerId, frequency);
		}
	}

	public static void SetPlayerSpeakingOnWalkieTalkieClientRpc(WalkieTalkie instance, int playerId, int frequency)
	{
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)instance).NetworkManager;
		if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening)
		{
			return;
		}
		int num = (int)AccessTools.Field(typeof(WalkieTalkie), "__rpc_exec_stage").GetValue(instance);
		MethodInfo methodInfo = AccessTools.Method(typeof(WalkieTalkie), "__beginSendClientRpc", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(WalkieTalkie), "__endSendClientRpc", (Type[])null, (Type[])null);
		MethodInfo methodInfo3 = AccessTools.Method(typeof(WalkieTalkie), "SendWalkieTalkieStartTransmissionSFX", (Type[])null, (Type[])null);
		if (num != 2 && (networkManager.IsServer || networkManager.IsHost))
		{
			ClientRpcParams val = default(ClientRpcParams);
			FastBufferWriter val2 = (FastBufferWriter)methodInfo.Invoke(instance, new object[3]
			{
				2961867446u,
				val,
				(object)(RpcDelivery)0
			});
			BytePacker.WriteValueBitPacked(val2, playerId);
			BytePacker.WriteValueBitPacked(val2, frequency);
			methodInfo2.Invoke(instance, new object[4]
			{
				val2,
				2961867446u,
				val,
				(object)(RpcDelivery)0
			});
		}
		if (num != 2 || (!networkManager.IsClient && !networkManager.IsHost))
		{
			return;
		}
		for (int i = 0; i < WalkieTalkie.allWalkieTalkies.Count; i++)
		{
			if ((int)((GrabbableObject)WalkieTalkie.allWalkieTalkies[i]).playerHeldBy.playerClientId == playerId)
			{
				walkieTalkieFrequencies[((Object)WalkieTalkie.allWalkieTalkies[i]).GetInstanceID()] = frequency;
				((MonoBehaviour)instance).StartCoroutine(OnFrequencyChanged(WalkieTalkie.allWalkieTalkies[i], increased: false));
				break;
			}
		}
		if (walkieTalkieFrequencies[((Object)instance).GetInstanceID()] == frequency || frequency == 0)
		{
			StartOfRound.Instance.allPlayerScripts[playerId].speakingToWalkieTalkie = true;
			instance.clientIsHoldingAndSpeakingIntoThis = true;
			methodInfo3.Invoke(instance, new object[1] { playerId });
			StartOfRound.Instance.UpdatePlayerVoiceEffects();
		}
	}
}
public static class Patches
{
	public static void ApplyPatches(Harmony harmony)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Expected O, but got Unknown
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Expected O, but got Unknown
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Expected O, but got Unknown
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Expected O, but got Unknown
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Expected O, but got Unknown
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Expected O, but got Unknown
		MethodInfo methodInfo = AccessTools.Method(typeof(WalkieTalkie), "SetLocalClientSpeaking", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(Patches), "WalkieTalkie_SetLocalClientSpeaking", (Type[])null, (Type[])null);
		harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo3 = AccessTools.Method(typeof(WalkieTalkie), "__rpc_handler_64994802", (Type[])null, (Type[])null);
		MethodInfo methodInfo4 = AccessTools.Method(typeof(Patches), "WalkieTalkie_HandlePlayerSpeakingServerRPC", (Type[])null, (Type[])null);
		harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo5 = AccessTools.Method(typeof(WalkieTalkie), "__rpc_handler_2961867446", (Type[])null, (Type[])null);
		MethodInfo methodInfo6 = AccessTools.Method(typeof(Patches), "WalkieTalkie_HandlePlayerSpeakingClientRPC", (Type[])null, (Type[])null);
		harmony.Patch((MethodBase)methodInfo5, new HarmonyMethod(methodInfo6), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo7 = AccessTools.Method(typeof(WalkieTalkie), "Update", (Type[])null, (Type[])null);
		MethodInfo methodInfo8 = AccessTools.Method(typeof(Patches), "WalkieTalkie_Update", (Type[])null, (Type[])null);
		harmony.Patch((MethodBase)methodInfo7, (HarmonyMethod)null, new HarmonyMethod(methodInfo8), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo9 = AccessTools.Method(typeof(WalkieTalkie), "Start", (Type[])null, (Type[])null);
		MethodInfo methodInfo10 = AccessTools.Method(typeof(Patches), "WalkieTalkie_Start", (Type[])null, (Type[])null);
		harmony.Patch((MethodBase)methodInfo9, (HarmonyMethod)null, new HarmonyMethod(methodInfo10), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo11 = AccessTools.Method(typeof(WalkieTalkie), "SwitchWalkieTalkieOn", (Type[])null, (Type[])null);
		MethodInfo methodInfo12 = AccessTools.Method(typeof(Patches), "WalkieTalkie_SwitchWalkieTalkieOn", (Type[])null, (Type[])null);
		harmony.Patch((MethodBase)methodInfo11, (HarmonyMethod)null, new HarmonyMethod(methodInfo12), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo13 = AccessTools.Method(typeof(WalkieTalkie), "EquipItem", (Type[])null, (Type[])null);
		MethodInfo methodInfo14 = AccessTools.Method(typeof(Patches), "WalkieTalkie_EquipItem", (Type[])null, (Type[])null);
		harmony.Patch((MethodBase)methodInfo13, (HarmonyMethod)null, new HarmonyMethod(methodInfo14), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo15 = AccessTools.Method(typeof(WalkieTalkie), "PocketItem", (Type[])null, (Type[])null);
		MethodInfo methodInfo16 = AccessTools.Method(typeof(Patches), "WalkieTalkie_PocketItem", (Type[])null, (Type[])null);
		harmony.Patch((MethodBase)methodInfo15, (HarmonyMethod)null, new HarmonyMethod(methodInfo16), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private static void WalkieTalkie_EquipItem(WalkieTalkie __instance)
	{
		if (((GrabbableObject)__instance).isBeingUsed)
		{
			((Behaviour)((Component)__instance).gameObject.GetComponent<Canvas>()).enabled = true;
		}
	}

	private static void WalkieTalkie_PocketItem(WalkieTalkie __instance)
	{
		((Behaviour)((Component)__instance).gameObject.GetComponent<Canvas>()).enabled = false;
	}

	private static void WalkieTalkie_Start(WalkieTalkie __instance)
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		//IL_00b3: 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)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Expected O, but got Unknown
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Expected O, but got Unknown
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Expected O, but got Unknown
		//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Expected O, but got Unknown
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_0386: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e7: Expected O, but got Unknown
		//IL_0410: Unknown result type (might be due to invalid IL or missing references)
		//IL_0431: Unknown result type (might be due to invalid IL or missing references)
		//IL_0452: Unknown result type (might be due to invalid IL or missing references)
		//IL_0497: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0529: Unknown result type (might be due to invalid IL or missing references)
		FrequencyWalkie.walkieTalkieFrequencies.Add(((Object)__instance).GetInstanceID(), 0);
		((GrabbableObject)__instance).itemProperties.toolTips = CollectionExtensions.AddToArray<string>(((GrabbableObject)__instance).itemProperties.toolTips, FrequencyWalkie.tooltip);
		RenderTexture val = new RenderTexture(__instance.onMaterial.mainTexture.width, __instance.onMaterial.mainTexture.width, 32);
		Graphics.Blit(__instance.onMaterial.mainTexture, val);
		RenderTexture.active = val;
		Texture2D val2 = new Texture2D(__instance.onMaterial.mainTexture.width, __instance.onMaterial.mainTexture.height);
		val2.ReadPixels(new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), 0, 0);
		Color[] array = (Color[])(object)new Color[((Texture)val2).width * ((Texture)val2).height];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = new Color(122f, 150f, 121f);
		}
		val2.SetPixels(420, 64, 135, 76, array);
		val2.Apply();
		RenderTexture.active = null;
		__instance.onMaterial.mainTexture = (Texture)(object)val2;
		Canvas val3 = ((Component)__instance).gameObject.AddComponent<Canvas>();
		val3.renderMode = (RenderMode)2;
		val3.worldCamera = Camera.main;
		RectTransform component = ((Component)val3).GetComponent<RectTransform>();
		component.sizeDelta = new Vector2(40f, 40f);
		GameObject val4 = new GameObject("Text");
		val4.transform.parent = ((Component)val3).transform;
		val4.transform.localPosition = new Vector3(2.7f, -0.9f, -0.23f);
		val4.transform.localRotation = Quaternion.Euler(-90f, -90f, 0f);
		GameObject val5 = new GameObject("Circle");
		val5.transform.parent = ((Component)val3).transform;
		val5.transform.localPosition = new Vector3(3.25f, -0.9f, -0.45f);
		val5.transform.localRotation = Quaternion.Euler(-90f, -90f, 0f);
		val5.transform.localScale = new Vector3(0.003f, 0.003f, 0.003f);
		Image val6 = val5.AddComponent<Image>();
		val6.sprite = Assets.GetResource<Sprite>("scanCircle2");
		((Graphic)val6).color = Color.black;
		GameObject val7 = new GameObject("Speaking");
		val7.transform.parent = ((Component)val3).transform;
		val7.transform.localPosition = new Vector3(3.25f, -0.9f, 0.2f);
		val7.transform.localRotation = Quaternion.Euler(-90f, -90f, 0f);
		Image val8 = val7.AddComponent<Image>();
		val8.sprite = Assets.GetResource<Sprite>("SpeakingSymbol");
		((Graphic)val8).color = Color.black;
		val7.transform.localScale = new Vector3(0.003f, 0.003f, 0.003f);
		GameObject val9 = new GameObject("ArrowUp");
		val9.transform.parent = ((Component)val3).transform;
		val9.transform.localPosition = new Vector3(3.25f, -0.9f, -0.2f);
		val9.transform.localRotation = Quaternion.Euler(-90f, -90f, 0f);
		val9.transform.localScale = new Vector3(0.003f, 0.003f, 0.003f);
		Image val10 = val9.AddComponent<Image>();
		val10.sprite = Assets.GetResource<Sprite>("arrow2");
		((Graphic)val10).color = Color.black;
		GameObject val11 = new GameObject("ArrowDown");
		val11.transform.parent = ((Component)val3).transform;
		val11.transform.localPosition = new Vector3(3.25f, -0.9f, -0.1f);
		val11.transform.localRotation = Quaternion.Euler(-90f, -90f, 0f);
		val11.transform.localScale = new Vector3(0.003f, 0.003f, 0.003f);
		Image val12 = val11.AddComponent<Image>();
		val12.sprite = Assets.GetResource<Sprite>("arrow2");
		((Component)val10).transform.Rotate(0f, 0f, 180f);
		((Graphic)val12).color = Color.black;
		Text val13 = val4.AddComponent<Text>();
		val13.text = "<b><size=40>" + FrequencyWalkie.frequencies[FrequencyWalkie.walkieTalkieFrequencies[((Object)__instance).GetInstanceID()]] + "</size><i><size=30>BEn</size></i></b>";
		val13.font = Assets.GetResource<Font>("3270-Regular");
		((Graphic)val13).color = Color.black;
		val13.fontSize = 40;
		val13.lineSpacing = 0.5f;
		val4.transform.localScale = new Vector3(0.015f, 0.01f, 0.01f);
		((Behaviour)val3).enabled = false;
		Light walkieTalkieLight = __instance.walkieTalkieLight;
		walkieTalkieLight.intensity /= 3f;
	}

	private static void WalkieTalkie_SwitchWalkieTalkieOn(WalkieTalkie __instance)
	{
		((Behaviour)((Component)__instance).gameObject.GetComponent<Canvas>()).enabled = ((GrabbableObject)__instance).isBeingUsed;
		if ((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController && ((GrabbableObject)__instance).isBeingUsed)
		{
			HUDManager.Instance.DisplayTip("FrequencyWalkie", "Press [N] or [M] to cycle between frequencies. Al.l will broadcast to all walkie talkies.", false, true, "FW_UseTip");
		}
	}

	private static void WalkieTalkie_Update(WalkieTalkie __instance)
	{
		PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
		bool flag = (Object)(object)localPlayerController.ItemSlots[localPlayerController.currentItemSlot] == (Object)(object)__instance;
		if (localPlayerController.isGrabbingObjectAnimation || localPlayerController.isTypingChat || localPlayerController.inTerminalMenu || localPlayerController.inSpecialInteractAnimation || !((GrabbableObject)__instance).isBeingUsed || !flag)
		{
			return;
		}
		if (UnityInput.Current.GetKeyUp((KeyCode)109))
		{
			FrequencyWalkie.walkieTalkieFrequencies[((Object)__instance).GetInstanceID()]--;
			if (FrequencyWalkie.walkieTalkieFrequencies[((Object)__instance).GetInstanceID()] < 0)
			{
				FrequencyWalkie.walkieTalkieFrequencies[((Object)__instance).GetInstanceID()] = FrequencyWalkie.frequencies.Count - 1;
			}
			((MonoBehaviour)__instance).StartCoroutine(FrequencyWalkie.OnFrequencyChanged(__instance, increased: false));
		}
		else if (UnityInput.Current.GetKeyUp((KeyCode)110))
		{
			FrequencyWalkie.walkieTalkieFrequencies[((Object)__instance).GetInstanceID()] = (FrequencyWalkie.walkieTalkieFrequencies[((Object)__instance).GetInstanceID()] + 1) % FrequencyWalkie.frequencies.Count;
			((MonoBehaviour)__instance).StartCoroutine(FrequencyWalkie.OnFrequencyChanged(__instance, increased: true));
		}
	}

	private static bool WalkieTalkie_SetLocalClientSpeaking(WalkieTalkie __instance, PlayerControllerB ___previousPlayerHeldBy, bool speaking)
	{
		if (___previousPlayerHeldBy.speakingToWalkieTalkie != speaking)
		{
			___previousPlayerHeldBy.speakingToWalkieTalkie = speaking;
			if (speaking)
			{
				FrequencyWalkie.SetPlayerSpeakingOnWalkieTalkieServerRpc(__instance, (int)___previousPlayerHeldBy.playerClientId, FrequencyWalkie.walkieTalkieFrequencies[((Object)__instance).GetInstanceID()]);
				return false;
			}
			__instance.UnsetPlayerSpeakingOnWalkieTalkieServerRpc((int)___previousPlayerHeldBy.playerClientId);
		}
		return false;
	}

	private static bool WalkieTalkie_HandlePlayerSpeakingServerRPC(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0028: 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_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: 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_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Expected O, but got Unknown
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Invalid comparison between Unknown and I4
		NetworkManager networkManager = target.NetworkManager;
		if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening)
		{
			return false;
		}
		if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
		{
			if ((int)networkManager.LogLevel > 1)
			{
				return false;
			}
			Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
		}
		else
		{
			int playerId = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
			int frequency = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref frequency);
			AccessTools.Field(typeof(WalkieTalkie), "__rpc_exec_stage").SetValue(target, 1);
			FrequencyWalkie.SetPlayerSpeakingOnWalkieTalkieServerRpc((WalkieTalkie)target, playerId, frequency);
			AccessTools.Field(typeof(WalkieTalkie), "__rpc_exec_stage").SetValue(target, 0);
		}
		return false;
	}

	private static bool WalkieTalkie_HandlePlayerSpeakingClientRPC(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		NetworkManager networkManager = target.NetworkManager;
		if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening)
		{
			return false;
		}
		int playerId = default(int);
		ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
		int frequency = default(int);
		ByteUnpacker.ReadValueBitPacked(reader, ref frequency);
		AccessTools.Field(typeof(WalkieTalkie), "__rpc_exec_stage").SetValue(target, 2);
		FrequencyWalkie.SetPlayerSpeakingOnWalkieTalkieClientRpc((WalkieTalkie)target, playerId, frequency);
		AccessTools.Field(typeof(WalkieTalkie), "__rpc_exec_stage").SetValue(target, 0);
		return false;
	}
}