Decompiled source of PushMod v0.5.0

plugins/com.github.boxofbiscuits97.PushMod.dll

Decompiled 4 days ago
using System;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.boxofbiscuits97.PushMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.5.0.0")]
[assembly: AssemblyInformationalVersion("0.5.0")]
[assembly: AssemblyProduct("com.github.boxofbiscuits97.PushMod")]
[assembly: AssemblyTitle("PushMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.5.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace PushMod
{
	[BepInPlugin("com.github.boxofbiscuits97.PushMod", "PushMod", "0.5.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Id = "com.github.boxofbiscuits97.PushMod";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "PushMod";

		public static string Version => "0.5.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			Harmony.CreateAndPatchAll(typeof(PushPatch), (string)null);
		}
	}
	public static class PushPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Character), "Awake")]
		public static void AwakePatch(Character __instance)
		{
			((Component)__instance).gameObject.AddComponent<PushManager>();
			Plugin.Log.LogInfo((object)("Added Component to character: " + __instance.characterName));
		}
	}
	public class PushManager : MonoBehaviour
	{
		private Character localCharacter;

		private float coolDownLeft;

		private float animationCoolDown;

		private float animationTime = 0.25f;

		private float forceMultiplier = 1f;

		private bool bingBong;

		private void Awake()
		{
			Character component = ((Component)this).GetComponent<Character>();
			if (component.IsLocal)
			{
				localCharacter = component;
			}
		}

		private void Update()
		{
			//IL_0108: 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_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			coolDownLeft -= Time.deltaTime;
			animationCoolDown -= Time.deltaTime;
			if (animationCoolDown > 0f)
			{
				Character component = ((Component)this).gameObject.GetComponent<Character>();
				PlayPushAnimation(component);
			}
			if (coolDownLeft > 0f || (Object)(object)localCharacter == (Object)null || !localCharacter.view.IsMine || !localCharacter.data.fullyConscious || localCharacter.data.isCarried || localCharacter.data.isClimbing)
			{
				return;
			}
			Item currentItem = localCharacter.data.currentItem;
			if ((Object)(object)currentItem != (Object)null)
			{
				bingBong = currentItem.GetItemName((ItemInstanceData)null).Contains("Bing Bong");
				if (!bingBong)
				{
					return;
				}
			}
			else
			{
				bingBong = false;
			}
			if (!Input.GetKeyDown((KeyCode)102))
			{
				return;
			}
			Transform transform = ((Component)Camera.main).transform;
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(transform.position, transform.forward, ref val, 2.5f))
			{
				return;
			}
			Character character = GetCharacter(((Component)((RaycastHit)(ref val)).transform).gameObject);
			if (!((Object)(object)character == (Object)null))
			{
				if (bingBong)
				{
					forceMultiplier = 10f;
				}
				else
				{
					forceMultiplier = 1f;
				}
				Vector3 val2 = ((Component)Camera.main).transform.forward * 500f * forceMultiplier;
				Transform val3 = ((Component)character).gameObject.transform.Find("Scout").Find("SFX").Find("Movement")
					.Find("SFX Jump");
				if ((Object)(object)val3 == (Object)null)
				{
					Plugin.Log.LogError((object)"Could not find sound effect for pushed character.");
				}
				else
				{
					((Component)val3).gameObject.SetActive(true);
				}
				coolDownLeft = 1f;
				float num = 0.1f * forceMultiplier;
				localCharacter.UseStamina(num, true);
				Plugin.Log.LogInfo((object)"Sending Push RPC Event");
				localCharacter.view.RPC("PushPlayer_Rpc", (RpcTarget)0, new object[3]
				{
					character.view.ViewID,
					val2,
					localCharacter.view.ViewID
				});
			}
		}

		private Character GetCharacter(GameObject obj)
		{
			Character result = default(Character);
			if (!obj.TryGetComponent<Character>(ref result))
			{
				if ((Object)(object)obj.transform.parent == (Object)null)
				{
					return result;
				}
				return GetCharacter(((Component)obj.transform.parent).gameObject);
			}
			return result;
		}

		private void PlayPushAnimation(Character character)
		{
			CharacterAnimations component = ((Component)character).gameObject.GetComponent<CharacterAnimations>();
			Animator animator = component.character.refs.animator;
			animator.Play("A_Scout_Reach_Straight");
		}

		[PunRPC]
		private void PushPlayer_Rpc(int viewID, Vector3 force, int senderID)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log.LogInfo((object)$"Recieved Event for ID: {viewID} with Force: {force} from ID: {senderID}");
			foreach (Character allCharacter in Character.AllCharacters)
			{
				if (allCharacter.IsLocal)
				{
					localCharacter = allCharacter;
				}
			}
			if ((Object)(object)localCharacter == (Object)null)
			{
				Plugin.Log.LogError((object)"Local Character is null!");
				return;
			}
			Character val = null;
			Character.GetCharacterWithPhotonID(senderID, ref val);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)$"Could not find character with photon ID: {senderID}");
			}
			else
			{
				PushManager component = ((Component)val).GetComponent<PushManager>();
				component.animationCoolDown = animationTime;
			}
			int viewID2 = localCharacter.view.ViewID;
			if (viewID != viewID2)
			{
				Plugin.Log.LogInfo((object)$"Local Player ID: {viewID2} is not pushed ID: {viewID}");
				return;
			}
			Transform val2 = ((Component)localCharacter).gameObject.transform.Find("Scout").Find("SFX").Find("Movement")
				.Find("SFX Jump");
			if ((Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogError((object)"Could not find sound effect for local character.");
			}
			else
			{
				((Component)val2).gameObject.SetActive(true);
			}
			localCharacter.AddForce(force, 1f, 1f);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}