Decompiled source of Bonk Players v1.0.0

Stacked.dll

Decompiled 3 days ago
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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Stacked")]
[assembly: AssemblyTitle("Stacked")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 Empress.PlayerStacking
{
	[BepInPlugin("Empress.PlayerStacking", "PlayerStacking", "2.0.0")]
	public class PlayerStackingPlugin : BaseUnityPlugin
	{
		internal class StackState
		{
			public PlayerAvatar Avatar = null;

			public Rigidbody? AvatarRb;

			public Collider? AvatarCollider;

			public bool IsLocalAvatar;

			public float NextBonkAllowedTime;

			public float StopTumbleAt;
		}

		private static readonly Dictionary<PlayerAvatar, StackState> States = new Dictionary<PlayerAvatar, StackState>();

		private const float ProbeRadius = 0.2f;

		private const float ProbeDistance = 2f;

		private const float BonkCooldown = 1f;

		private const float TumbleSeconds = 3f;

		private const float KickForce = 10f;

		private const float KickUp = 2f;

		private const float SpinTorque = 10f;

		internal static PlayerStackingPlugin Instance { get; private set; } = null;


		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; private set; }

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			Instance = this;
			((Component)this).transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			Harmony.PatchAll();
		}

		private void OnDestroy()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
			float time = Time.time;
			foreach (KeyValuePair<PlayerAvatar, StackState> state in States)
			{
				StackState value = state.Value;
				if (value.StopTumbleAt > 0f && time >= value.StopTumbleAt)
				{
					value.StopTumbleAt = 0f;
					if (Object.op_Implicit((Object)(object)value.Avatar) && Object.op_Implicit((Object)(object)value.Avatar.tumble))
					{
						value.Avatar.tumble.TumbleRequest(false, false);
					}
				}
			}
		}

		internal static void RegisterAvatar(PlayerAvatar avatar)
		{
			if (Object.op_Implicit((Object)(object)avatar) && !States.ContainsKey(avatar))
			{
				Rigidbody component = ((Component)avatar).GetComponent<Rigidbody>();
				Collider val = null;
				PlayerAvatarCollision componentInChildren = ((Component)avatar).GetComponentInChildren<PlayerAvatarCollision>();
				if (Object.op_Implicit((Object)(object)componentInChildren) && Object.op_Implicit((Object)(object)componentInChildren.Collider))
				{
					val = (Collider)(object)componentInChildren.Collider;
				}
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = ((Component)avatar).GetComponentInChildren<Collider>();
				}
				StackState stackState = new StackState
				{
					Avatar = avatar,
					AvatarRb = component,
					AvatarCollider = val
				};
				UpdateIsLocal(stackState);
				States[avatar] = stackState;
			}
		}

		internal static void UnregisterAvatar(PlayerAvatar avatar)
		{
			if (Object.op_Implicit((Object)(object)avatar) && States.ContainsKey(avatar))
			{
				States.Remove(avatar);
			}
		}

		internal static void OnPlayerFixedUpdate(PlayerAvatar avatar)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00ba: 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)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)avatar) || !States.TryGetValue(avatar, out StackState value))
			{
				return;
			}
			UpdateIsLocal(value);
			if (!value.IsLocalAvatar || !Object.op_Implicit((Object)(object)value.AvatarRb) || !Object.op_Implicit((Object)(object)value.AvatarCollider) || (Object.op_Implicit((Object)(object)avatar.tumble) && avatar.tumble.isTumbling))
			{
				return;
			}
			Vector3 val = value.AvatarRb.position + Vector3.up * 0.15f;
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.SphereCast(val, 0.2f, Vector3.down, ref val2, 2f, -5, (QueryTriggerInteraction)1) || (Object.op_Implicit((Object)(object)((RaycastHit)(ref val2)).collider) && ((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(((Component)avatar).transform)))
			{
				return;
			}
			PlayerAvatar componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<PlayerAvatar>();
			if (!Object.op_Implicit((Object)(object)componentInParent) || (Object)(object)componentInParent == (Object)(object)avatar || !States.TryGetValue(componentInParent, out StackState value2) || (Object)(object)value2.AvatarCollider == (Object)null)
			{
				return;
			}
			Vector3 position = ((Component)value2.Avatar).transform.position;
			if (value.AvatarRb.position.y <= position.y)
			{
				return;
			}
			Vector3 val3 = Vector3.ProjectOnPlane(value.AvatarRb.position - position, Vector3.up);
			Bounds bounds = value2.AvatarCollider.bounds;
			float x = ((Bounds)(ref bounds)).extents.x;
			bounds = value2.AvatarCollider.bounds;
			float num = Mathf.Max(x, ((Bounds)(ref bounds)).extents.z);
			bounds = value.AvatarCollider.bounds;
			float x2 = ((Bounds)(ref bounds)).extents.x;
			bounds = value.AvatarCollider.bounds;
			float num2 = Mathf.Max(x2, ((Bounds)(ref bounds)).extents.z);
			float num3 = num + num2 + 0.45f;
			if (!(((Vector3)(ref val3)).sqrMagnitude > num3 * num3))
			{
				float time = Time.time;
				if (!(value2.NextBonkAllowedTime > time))
				{
					BonkVictim(value, value2);
				}
			}
		}

		private static void BonkVictim(StackState rider, StackState victim)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_0094: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar avatar = victim.Avatar;
			if (!Object.op_Implicit((Object)(object)avatar) || (Object)(object)avatar.tumble == (Object)null)
			{
				return;
			}
			try
			{
				Sound tumbleStartSound = avatar.tumbleStartSound;
				if (tumbleStartSound != null)
				{
					tumbleStartSound.Play(((Component)avatar).transform.position, 0.2f, 1f, 1f, 1f);
				}
			}
			catch
			{
			}
			avatar.tumble.TumbleRequest(true, false);
			avatar.tumble.TumbleOverrideTime(3f);
			Vector3 forward = ((Component)avatar).transform.forward;
			Vector3 val = forward * 10f + Vector3.up * 2f;
			avatar.tumble.TumbleForce(val);
			PlayerTumble tumble = avatar.tumble;
			Vector3 insideUnitSphere = Random.insideUnitSphere;
			tumble.TumbleTorque(((Vector3)(ref insideUnitSphere)).normalized * 10f);
			victim.StopTumbleAt = Time.time + 3f;
			victim.NextBonkAllowedTime = Time.time + 1f;
		}

		private static void UpdateIsLocal(StackState state)
		{
			if (!Object.op_Implicit((Object)(object)state.Avatar))
			{
				state.IsLocalAvatar = false;
				return;
			}
			if (!GameManager.Multiplayer())
			{
				state.IsLocalAvatar = true;
				return;
			}
			PhotonView photonView = state.Avatar.photonView;
			state.IsLocalAvatar = Object.op_Implicit((Object)(object)photonView) && photonView.IsMine;
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar))]
	internal static class PlayerAvatar_Awake_Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void Postfix(PlayerAvatar __instance)
		{
			PlayerStackingPlugin.RegisterAvatar(__instance);
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar))]
	internal static class PlayerAvatar_OnDestroy_Patch
	{
		[HarmonyPrefix]
		[HarmonyPatch("OnDestroy")]
		private static void Prefix(PlayerAvatar __instance)
		{
			PlayerStackingPlugin.UnregisterAvatar(__instance);
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar))]
	internal static class PlayerAvatar_FixedUpdate_Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch("FixedUpdate")]
		private static void Postfix(PlayerAvatar __instance)
		{
			PlayerStackingPlugin.OnPlayerFixedUpdate(__instance);
		}
	}
}