Decompiled source of PiCHUPatches v0.2.2

PiCHUPatches.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Peak.Afflictions;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.Core.Serizalization;

[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("PiCHUPatches")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PiCHUPatches")]
[assembly: AssemblyTitle("PiCHUPatches")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
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 PiCHUPatches
{
	[HarmonyPatch(typeof(UIPlayerNames), "UpdateName")]
	internal static class AscentNameColorPatch
	{
		private static void Postfix(UIPlayerNames __instance, int index, bool visible)
		{
			if (!visible || __instance.playerNameText == null || index < 0 || index >= __instance.playerNameText.Length)
			{
				return;
			}
			PlayerName val = __instance.playerNameText[index];
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.text == (Object)null) && !((Object)(object)val.characterInteractable == (Object)null))
			{
				Character character = val.characterInteractable.character;
				if (!((Object)(object)character == (Object)null))
				{
					AscentNameColor.Apply((TMP_Text)(object)val.text, character);
				}
			}
		}
	}
	[HarmonyPatch(typeof(AudioLevelSlider), "Update")]
	internal static class AscentAudioSliderColorPatch
	{
		private static void Postfix(AudioLevelSlider __instance)
		{
			if (__instance.player != null && !((Object)(object)__instance.playerName == (Object)null))
			{
				Character playerCharacter = PlayerHandler.GetPlayerCharacter(__instance.player);
				if (!((Object)(object)playerCharacter == (Object)null))
				{
					AscentNameColor.Apply((TMP_Text)(object)__instance.playerName, playerCharacter);
				}
			}
		}
	}
	[HarmonyPatch(typeof(EndScreenScoutWindow), "Init", new Type[] { typeof(Character) })]
	internal static class AscentEndScreenNamePatch
	{
		private static void Postfix(EndScreenScoutWindow __instance, Character character)
		{
			if (!((Object)(object)character == (Object)null) && !((Object)(object)__instance.scoutName == (Object)null))
			{
				AscentNameColor.Apply(__instance.scoutName, character);
			}
		}
	}
	internal static class AscentNameColor
	{
		internal const int TotalAscents = 8;

		private static readonly Color32 SilverColor = new Color32((byte)198, (byte)202, (byte)209, byte.MaxValue);

		private static readonly Color32 GoldColor = new Color32(byte.MaxValue, (byte)208, (byte)92, byte.MaxValue);

		private static readonly Color32 PlatinumColor = new Color32((byte)213, (byte)238, byte.MaxValue, byte.MaxValue);

		internal static int GetClearedCount(Character character)
		{
			if ((Object)(object)character == (Object)null)
			{
				return 0;
			}
			AscentSync component = ((Component)character).GetComponent<AscentSync>();
			return Mathf.Clamp(((Object)(object)component != (Object)null) ? component.MaxAscent : 0, 0, 8);
		}

		internal static void Apply(TMP_Text text, Character character)
		{
			//IL_0012: 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_0042: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			int clearedCount = GetClearedCount(character);
			if (clearedCount > 0)
			{
				int num = 8;
				Color32 baseColor;
				float intensity;
				float speed;
				if (clearedCount >= num)
				{
					baseColor = PlatinumColor;
					intensity = 0.55f;
					speed = 3.5f;
				}
				else if (clearedCount >= num / 2)
				{
					baseColor = GoldColor;
					intensity = 0.35f;
					speed = 2.5f;
				}
				else
				{
					baseColor = SilverColor;
					intensity = 0.2f;
					speed = 2f;
				}
				ApplyShimmerColor(text, baseColor, intensity, speed);
			}
		}

		private static void ApplyShimmerColor(TMP_Text text, Color32 baseColor, float intensity, float speed)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0039: 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_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_0076: 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)
			//IL_0083: 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_009e: 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_00aa: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)text).color = Color.white;
			text.ForceMeshUpdate(false, false);
			TMP_TextInfo textInfo = text.textInfo;
			int characterCount = textInfo.characterCount;
			if (characterCount == 0)
			{
				return;
			}
			for (int i = 0; i < characterCount; i++)
			{
				TMP_CharacterInfo val = textInfo.characterInfo[i];
				if (val.isVisible)
				{
					float num = 0.5f + 0.5f * Mathf.Sin(Time.time * speed + (float)i * 0.4f);
					Color32 val2 = Color32.Lerp(baseColor, Color32.op_Implicit(Color.white), num * intensity);
					Color32[] colors = textInfo.meshInfo[val.materialReferenceIndex].colors32;
					int vertexIndex = val.vertexIndex;
					colors[vertexIndex] = val2;
					colors[vertexIndex + 1] = val2;
					colors[vertexIndex + 2] = val2;
					colors[vertexIndex + 3] = val2;
				}
			}
			for (int j = 0; j < textInfo.meshInfo.Length; j++)
			{
				textInfo.meshInfo[j].mesh.colors32 = textInfo.meshInfo[j].colors32;
				text.UpdateGeometry(textInfo.meshInfo[j].mesh, j);
			}
		}
	}
	[HarmonyPatch(typeof(PauseMenuHandler), "OnEnable")]
	internal static class AscentOverviewPatch
	{
		private static void Postfix(PauseMenuHandler __instance)
		{
			AscentOverviewPanel.EnsureCreated(((Component)__instance).transform);
		}
	}
	internal static class AscentOverviewPanel
	{
		private const string GreenHex = "#4CD964";

		private const string GrayHex = "#585858";

		private static GameObject _root;

		private static TextMeshProUGUI _text;

		internal static void EnsureCreated(Transform parent)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0058: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			if ((Object)(object)_root == (Object)null)
			{
				_root = new GameObject("PiCHU_AscentOverview", new Type[1] { typeof(RectTransform) });
				_root.transform.SetParent(parent, false);
				RectTransform component = _root.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0f, 0f);
				component.anchorMax = new Vector2(0f, 0f);
				component.pivot = new Vector2(0f, 0f);
				component.anchoredPosition = new Vector2(32f, 32f);
				component.sizeDelta = new Vector2(320f, 160f);
				_text = _root.AddComponent<TextMeshProUGUI>();
				((TMP_Text)_text).fontSize = 34f;
				((TMP_Text)_text).lineSpacing = 8f;
				((TMP_Text)_text).alignment = (TextAlignmentOptions)1025;
				((TMP_Text)_text).textWrappingMode = (TextWrappingModes)0;
				((Graphic)_text).raycastTarget = false;
				ApplyPeakFont(_text, parent);
			}
			((TMP_Text)_text).text = BuildText();
		}

		private static void ApplyPeakFont(TextMeshProUGUI text, Transform searchRoot)
		{
			TMP_Text val = ((Component)searchRoot).GetComponentInChildren<TMP_Text>(true);
			if ((Object)(object)val == (Object)null)
			{
				val = Object.FindFirstObjectByType<TMP_Text>();
			}
			if ((Object)(object)val != (Object)null && (Object)(object)val.font != (Object)null)
			{
				((TMP_Text)text).font = val.font;
				((TMP_Text)text).fontSharedMaterial = val.fontSharedMaterial;
			}
		}

		private static string BuildText()
		{
			int num = (((Object)(object)Singleton<AchievementManager>.Instance != (Object)null) ? Singleton<AchievementManager>.Instance.GetMaxAscent() : 0);
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("ASCENT\n");
			for (int i = 1; i <= 8; i++)
			{
				string value = ((i <= num) ? "#4CD964" : "#585858");
				stringBuilder.Append("<color=").Append(value).Append('>')
					.Append(i)
					.Append("</color>");
				if (i == 4)
				{
					stringBuilder.Append('\n');
				}
				else if (i < 8)
				{
					stringBuilder.Append(' ');
				}
			}
			return stringBuilder.ToString();
		}
	}
	[HarmonyPatch(typeof(Character), "Awake")]
	internal static class AscentSyncAttachPatch
	{
		private static void Postfix(Character __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<AscentSync>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<AscentSync>();
			}
		}
	}
	public class AscentSync : MonoBehaviour
	{
		private Character _character;

		internal int MaxAscent { get; private set; }

		private void Awake()
		{
			_character = ((Component)this).GetComponent<Character>();
		}

		private void Start()
		{
			if ((Object)(object)_character != (Object)null && _character.IsLocal)
			{
				((MonoBehaviour)this).StartCoroutine(BroadcastRoutine());
			}
		}

		private IEnumerator BroadcastRoutine()
		{
			float timeout = 5f;
			while (timeout > 0f && ((Object)(object)((MonoBehaviourPun)_character).photonView == (Object)null || !((MonoBehaviourPun)_character).photonView.IsMine))
			{
				timeout -= Time.deltaTime;
				yield return null;
			}
			if (!((Object)(object)((MonoBehaviourPun)_character).photonView == (Object)null))
			{
				int num = (MaxAscent = (((Object)(object)Singleton<AchievementManager>.Instance != (Object)null) ? Singleton<AchievementManager>.Instance.GetMaxAscent() : 0));
				((MonoBehaviourPun)_character).photonView.RPC("RPC_ReceiveMaxAscent", (RpcTarget)0, new object[1] { num });
			}
		}

		[PunRPC]
		private void RPC_ReceiveMaxAscent(int maxAscent)
		{
			MaxAscent = maxAscent;
		}
	}
	[HarmonyPatch(typeof(CharacterAfflictions), "AddAffliction", new Type[]
	{
		typeof(Affliction),
		typeof(bool)
	})]
	internal static class EnergyDrinkComboPatch
	{
		internal static bool SuppressCombo;

		private static bool Prefix(CharacterAfflictions __instance, Affliction affliction, bool fromRPC)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			if (SuppressCombo || fromRPC || affliction == null)
			{
				return true;
			}
			if ((int)affliction.GetAfflictionType() != 2)
			{
				return true;
			}
			if ((Object)(object)__instance.character == (Object)null || !__instance.character.IsLocal)
			{
				return true;
			}
			Affliction val = default(Affliction);
			if (!__instance.HasAfflictionType((AfflictionType)2, ref val))
			{
				return true;
			}
			EnergyDrinkComboEffect.Trigger(__instance, affliction);
			return false;
		}
	}
	internal class EnergyDrinkComboEffect : MonoBehaviour
	{
		private static EnergyDrinkComboEffect _instance;

		private void Awake()
		{
			_instance = this;
		}

		public static void Trigger(CharacterAfflictions afflictions, Affliction incomingEnergyDrink)
		{
			if ((Object)(object)_instance == (Object)null)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)"EnergyDrinkComboEffect nicht bereit, Combo übersprungen.");
				}
			}
			else
			{
				((MonoBehaviour)_instance).StartCoroutine(_instance.ComboRoutine(afflictions, incomingEnergyDrink));
			}
		}

		private IEnumerator ComboRoutine(CharacterAfflictions afflictions, Affliction incomingEnergyDrink)
		{
			Affliction_FasterBoi val = (Affliction_FasterBoi)incomingEnergyDrink.Copy();
			((Affliction)val).totalTime = 10f;
			EnergyDrinkComboPatch.SuppressCombo = true;
			try
			{
				afflictions.AddAffliction((Affliction)(object)val, false);
				afflictions.AddAffliction((Affliction)new Affliction_InfiniteStamina(10f), false);
			}
			finally
			{
				EnergyDrinkComboPatch.SuppressCombo = false;
			}
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)"Energy-Combo: 10s Energy + Rainbow Stamina aktiviert.");
			}
			yield return (object)new WaitForSeconds(10f);
			for (int i = 0; i < 10; i++)
			{
				if ((Object)(object)afflictions == (Object)null || (Object)(object)afflictions.character == (Object)null)
				{
					yield break;
				}
				afflictions.AddStatus((STATUSTYPE)6, 0.1f, false, true, true, false);
				yield return (object)new WaitForSeconds(1f);
			}
			ManualLogSource log2 = Plugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)"Energy-Combo: Sleep-Aufbau abgeschlossen (100).");
			}
		}
	}
	[HarmonyPatch(typeof(ItemCooking), "RPC_CookingExplode")]
	internal static class HolyWaterCureAllPatch
	{
		private const string DonorItemNameFragment = "Cure-All";

		private const float SplashRadius = 8f;

		private const float CurseInstant = 1f;

		private const float CurseDecayPerTick = 0.05f;

		private const float RecoveryDelay = 5f;

		private static void Prefix(ItemCooking __instance)
		{
			//IL_0055: 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_005c: 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)
			if ((Object)(object)__instance == (Object)null || (Object)(object)((ItemComponent)__instance).item == (Object)null || ((Object)((ItemComponent)__instance).item).name.IndexOf("Cure-All", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return;
			}
			Character localCharacter = Character.localCharacter;
			if (!((Object)(object)localCharacter == (Object)null) && localCharacter.data.fullyConscious)
			{
				Vector3 position = ((Component)__instance).transform.position;
				if (!(Vector3.Distance(localCharacter.Center, position) > 8f))
				{
					((MonoBehaviour)localCharacter).StartCoroutine(SplashRoutine(localCharacter));
				}
			}
		}

		private static IEnumerator SplashRoutine(Character local)
		{
			CharacterAfflictions afflictions = local.refs.afflictions;
			afflictions.AddStatus((STATUSTYPE)5, 1f, false, true, true, false);
			yield return (object)new WaitForSeconds(5f);
			if (local.data.petrifyAmount > 0)
			{
				local.data.SetPetrify(0);
			}
			for (int i = 0; i < 40; i++)
			{
				if (!(afflictions.GetCurrentStatus((STATUSTYPE)5) > 0f))
				{
					break;
				}
				afflictions.SubtractStatus((STATUSTYPE)5, 0.05f, false, false);
				yield return (object)new WaitForSeconds(1f);
			}
		}
	}
	public class KickHotkey : MonoBehaviour
	{
		private const Key TriggerKey = (Key)20;

		private const float MinStaminaToKick = 0.005f;

		private const float KickAnimationDuration = 1f;

		private readonly Dictionary<Character, float> _kickResetTimers = new Dictionary<Character, float>();

		private ManualLogSource _log;

		private void Awake()
		{
			_log = Plugin.Log;
		}

		private void Update()
		{
			ResetStuckKickFlags();
			if (Keyboard.current != null && ((ButtonControl)Keyboard.current[(Key)20]).wasPressedThisFrame)
			{
				TryKick();
			}
		}

		private void ResetStuckKickFlags()
		{
			List<Character> allPlayerCharacters = PlayerHandler.GetAllPlayerCharacters();
			for (int i = 0; i < allPlayerCharacters.Count; i++)
			{
				Character val = allPlayerCharacters[i];
				if ((Object)(object)val == (Object)null || (Object)(object)val.data == (Object)null)
				{
					continue;
				}
				if (!val.data.isKicking)
				{
					_kickResetTimers.Remove(val);
					continue;
				}
				float value;
				float num = (_kickResetTimers.TryGetValue(val, out value) ? value : 0f) + Time.deltaTime;
				if (num > 1f)
				{
					val.data.isKicking = false;
					_kickResetTimers.Remove(val);
				}
				else
				{
					_kickResetTimers[val] = num;
				}
			}
		}

		private void TryKick()
		{
			if (!Character.localCharacterExists)
			{
				return;
			}
			Character localCharacter = Character.localCharacter;
			CharacterData data = localCharacter.data;
			if (data.fullyConscious && !data.isKicking && !data.isClimbingAnything && data.isGrounded && !(data.currentStamina < 0.005f))
			{
				localCharacter.refs.view.RPC("RPCA_Kick", (RpcTarget)0, Array.Empty<object>());
				ManualLogSource log = _log;
				if (log != null)
				{
					log.LogInfo((object)"Tritt ausgelöst.");
				}
			}
		}
	}
	internal static class PiggybackShared
	{
		internal const float HoldToCarrySeconds = 2f;

		internal static bool IsDoingIllegalCarryActions(Character character)
		{
			if (!character.data.isSprinting && !character.data.isJumping && !character.data.isClimbingAnything && !character.data.isCrouching && !character.data.isReaching && !character.data.isKicking)
			{
				return (Object)(object)character.data.carriedPlayer != (Object)null;
			}
			return true;
		}

		internal static bool CanCarryConsciousPlayer(Character target)
		{
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null || (Object)(object)target == (Object)(object)localCharacter || target.isBot || target.data.dead)
			{
				return false;
			}
			if ((Object)(object)target.data.carrier != (Object)null)
			{
				return false;
			}
			if (!((ItemSlot)Player.localPlayer.backpackSlot).IsEmpty() && !((ItemSlot)target.player.backpackSlot).IsEmpty())
			{
				return false;
			}
			if ((Object)(object)target.data.currentItem != (Object)null)
			{
				return false;
			}
			if (target.refs.movement.rocketLit || target.refs.movement.rocketActive || localCharacter.refs.movement.rocketLit || localCharacter.refs.movement.rocketActive)
			{
				return false;
			}
			if (localCharacter.data.isClimbingAnything)
			{
				return false;
			}
			return !IsDoingIllegalCarryActions(target);
		}
	}
	[HarmonyPatch(typeof(CharacterInteractible), "CanBeCarried")]
	internal static class PiggybackCanBeCarriedPatch
	{
		private static void Postfix(ref bool __result, Character ___character)
		{
			if (!__result && PiggybackShared.CanCarryConsciousPlayer(___character))
			{
				__result = true;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterInteractible), "Interact")]
	internal static class PiggybackHoldToCarryInteractPatch
	{
		internal static bool IsAttemptingToCarry;

		private static bool Prefix(CharacterInteractible __instance)
		{
			IsAttemptingToCarry = false;
			Character character = __instance.character;
			if (((Object)(object)character.data.carrier != (Object)null && (Object)(object)character.data.carrier == (Object)(object)Character.localCharacter) || character.refs.customization.isCannibalizable || character.data.fullyPassedOut)
			{
				return true;
			}
			if (!PiggybackShared.CanCarryConsciousPlayer(character))
			{
				return true;
			}
			IsAttemptingToCarry = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(CharacterInteractible), "IsConstantlyInteractable")]
	internal static class PiggybackHoldToCarryConstantPatch
	{
		private static void Postfix(ref bool __result, CharacterInteractible __instance)
		{
			if (!__result && !__instance.character.data.fullyPassedOut)
			{
				__result = PiggybackShared.CanCarryConsciousPlayer(__instance.character);
			}
		}
	}
	[HarmonyPatch(typeof(CharacterInteractible), "GetInteractTime")]
	internal static class PiggybackHoldToCarryTimePatch
	{
		private static void Postfix(ref float __result, CharacterInteractible __instance)
		{
			if (!__instance.character.refs.customization.isCannibalizable && !__instance.character.data.fullyPassedOut && PiggybackShared.CanCarryConsciousPlayer(__instance.character))
			{
				__result = 2f;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterInteractible), "Interact_CastFinished")]
	internal static class PiggybackHoldToCarryCastFinishedPatch
	{
		private static bool Prefix(CharacterInteractible __instance, Character interactor)
		{
			if (!interactor.IsLocal)
			{
				return false;
			}
			if (!PiggybackHoldToCarryInteractPatch.IsAttemptingToCarry)
			{
				return true;
			}
			PiggybackHoldToCarryInteractPatch.IsAttemptingToCarry = false;
			if (PiggybackShared.CanCarryConsciousPlayer(__instance.character))
			{
				StartCarry(interactor, __instance.character);
			}
			return false;
		}

		private static void StartCarry(Character interactor, Character target)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			interactor.refs.items.EquipSlot(Optionable<byte>.None);
			((MonoBehaviourPun)interactor).photonView.RPC("RPCA_StartCarry", (RpcTarget)0, new object[1] { ((MonoBehaviourPun)target).photonView });
		}
	}
	[HarmonyPatch(typeof(CharacterInteractible), "CancelCast")]
	internal static class PiggybackHoldToCarryCancelPatch
	{
		private static void Postfix(Character interactor)
		{
			if ((Object)(object)interactor != (Object)null && interactor.IsLocal)
			{
				PiggybackHoldToCarryInteractPatch.IsAttemptingToCarry = false;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterCarrying), "Update")]
	internal static class PiggybackCarryingUpdatePatch
	{
		private static bool Prefix(Character ___character)
		{
			if (!___character.refs.view.IsMine)
			{
				return true;
			}
			Character carriedPlayer = ___character.data.carriedPlayer;
			if ((Object)(object)carriedPlayer == (Object)null)
			{
				return true;
			}
			if ((Object)(object)carriedPlayer.data.currentItem != (Object)null)
			{
				return true;
			}
			if (carriedPlayer.refs.movement.rocketLit || carriedPlayer.refs.movement.rocketActive)
			{
				return true;
			}
			if (PiggybackShared.IsDoingIllegalCarryActions(carriedPlayer))
			{
				return true;
			}
			if (carriedPlayer.data.dead || ___character.data.fullyPassedOut || ___character.data.dead)
			{
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(CharacterCarrying), "CarrierGone")]
	internal static class PiggybackCarrierGonePatch
	{
		private static void Postfix(Character ___character)
		{
			___character.data.isCarried = false;
		}
	}
	[HarmonyPatch(typeof(CharacterInput), "Sample")]
	internal static class PiggybackInputSuppressPatch
	{
		private static void Postfix(CharacterInput __instance)
		{
			//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)
			Character localCharacter = Character.localCharacter;
			if (!((Object)(object)localCharacter == (Object)null) && !localCharacter.data.fullyPassedOut && localCharacter.data.isCarried)
			{
				if (__instance.jumpWasPressed)
				{
					JumpOffCarrier(localCharacter);
				}
				__instance.movementInput = Vector2.zero;
				__instance.interactWasPressed = false;
				__instance.interactIsPressed = false;
				__instance.emoteIsPressed = false;
				__instance.sprintWasPressed = false;
				__instance.sprintIsPressed = false;
				__instance.sprintToggleIsPressed = false;
				__instance.sprintToggleWasPressed = false;
				__instance.jumpWasPressed = false;
				__instance.jumpIsPressed = false;
				__instance.dropWasPressed = false;
				__instance.dropIsPressed = false;
				__instance.usePrimaryWasPressed = false;
				__instance.usePrimaryIsPressed = false;
				__instance.useSecondaryWasPressed = false;
				__instance.useSecondaryIsPressed = false;
				__instance.spectateLeftWasPressed = false;
				__instance.spectateRightWasPressed = false;
				__instance.selectBackpackWasPressed = false;
				__instance.scrollBackwardWasPressed = false;
				__instance.scrollForwardWasPressed = false;
				__instance.scrollBackwardIsPressed = false;
				__instance.scrollForwardIsPressed = false;
				__instance.selectSlotForwardWasPressed = false;
				__instance.selectSlotBackwardWasPressed = false;
				__instance.unselectSlotWasPressed = false;
			}
		}

		private static void JumpOffCarrier(Character local)
		{
			Character carrier = local.data.carrier;
			if (!((Object)(object)carrier == (Object)null))
			{
				((MonoBehaviourPun)carrier).photonView.RPC("RPCA_Drop", (RpcTarget)0, new object[1] { ((MonoBehaviourPun)local).photonView });
			}
		}
	}
	[HarmonyPatch(typeof(MainCameraMovement), "LateUpdate")]
	internal static class PiggybackSpectateViewPatch
	{
		private static readonly Action<MainCameraMovement, bool> SpectateMethod = (Action<MainCameraMovement, bool>)Delegate.CreateDelegate(typeof(Action<MainCameraMovement, bool>), null, AccessTools.Method(typeof(MainCameraMovement), "Spectate", new Type[1] { typeof(bool) }, (Type[])null));

		private static readonly FieldRef<MainCamera, CameraOverride> CamOverrideRef = AccessTools.FieldRefAccess<MainCamera, CameraOverride>("camOverride");

		private static void Postfix(MainCameraMovement __instance, MainCamera ___cam, bool ___isGodCam, ref bool ___isSpectating, bool ___isRocketing)
		{
			if (!((___isGodCam | ___isSpectating) || ___isRocketing))
			{
				Character localCharacter = Character.localCharacter;
				if (!((Object)(object)localCharacter == (Object)null) && !localCharacter.data.fullyPassedOut && localCharacter.data.isCarried && !((Object)(object)CamOverrideRef.Invoke(___cam) != (Object)null))
				{
					SpectateMethod(__instance, arg2: false);
					___isSpectating = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(CharacterCarrying), "StartCarry")]
	internal static class PiggybackBackpackSwapStartPatch
	{
		private static readonly Dictionary<Character, Guid> SwappedBackpackGuids = new Dictionary<Character, Guid>();

		internal static bool TryGetSwappedGuid(Character carrier, out Guid guid)
		{
			return SwappedBackpackGuids.TryGetValue(carrier, out guid);
		}

		internal static void Clear(Character carrier)
		{
			SwappedBackpackGuids.Remove(carrier);
		}

		private static void Prefix(Character ___character, Character target)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			Clear(___character);
			BackpackSlot backpackSlot = ___character.player.backpackSlot;
			if (!((ItemSlot)backpackSlot).IsEmpty() && ((ItemSlot)target.player.backpackSlot).IsEmpty())
			{
				Guid guid = ((ItemSlot)backpackSlot).data.guid;
				target.player.backpackSlot = backpackSlot;
				___character.player.backpackSlot = new BackpackSlot((byte)3);
				PiggybackBackpackSwapShared.SyncInventory(___character.player);
				PiggybackBackpackSwapShared.SyncInventory(target.player);
				SwappedBackpackGuids[___character] = guid;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterCarrying), "RPCA_Drop")]
	internal static class PiggybackBackpackSwapDropPatch
	{
		private static void Prefix(Character ___character, PhotonView targetView)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			if ((Object)(object)Character.localCharacter != (Object)(object)___character || !PiggybackBackpackSwapStartPatch.TryGetSwappedGuid(___character, out var guid))
			{
				return;
			}
			PiggybackBackpackSwapStartPatch.Clear(___character);
			if (!((ItemSlot)___character.player.backpackSlot).IsEmpty())
			{
				return;
			}
			Character val = (((Object)(object)targetView != (Object)null) ? ((Component)targetView).GetComponent<Character>() : null);
			if (!((Object)(object)val == (Object)null))
			{
				BackpackSlot backpackSlot = val.player.backpackSlot;
				if (!((ItemSlot)backpackSlot).IsEmpty() && ((ItemSlot)backpackSlot).data != null && !(((ItemSlot)backpackSlot).data.guid != guid))
				{
					___character.player.backpackSlot = backpackSlot;
					val.player.backpackSlot = new BackpackSlot((byte)3);
					PiggybackBackpackSwapShared.SyncInventory(___character.player);
					PiggybackBackpackSwapShared.SyncInventory(val.player);
				}
			}
		}
	}
	internal static class PiggybackBackpackSwapShared
	{
		internal static void SyncInventory(Player player)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			byte[] array = IBinarySerializable.ToManagedArray<InventorySyncData>(new InventorySyncData(player.itemSlots, player.backpackSlot, player.tempFullSlot));
			((MonoBehaviourPun)player).photonView.RPC("SyncInventoryRPC", (RpcTarget)1, new object[2] { array, false });
		}
	}
	[BepInPlugin("com.CptPICHU.peak.pichupatches", "PiCHUPatches", "0.2.2")]
	public class Plugin : BaseUnityPlugin
	{
		private const string ModGuid = "com.CptPICHU.peak.pichupatches";

		private const string ModName = "PiCHUPatches";

		private const string ModVersion = "0.2.2";

		private Harmony _harmony;

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[PiCHUPatches] geladen (v0.2.2).");
			_harmony = new Harmony("com.CptPICHU.peak.pichupatches");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			((Component)this).gameObject.AddComponent<KickHotkey>();
			((Component)this).gameObject.AddComponent<EnergyDrinkComboEffect>();
		}
	}
}