Decompiled source of DoAFlip v1.0.2

FlipMod.dll

Decompiled a month 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 GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using LethalNetworkAPI;
using LethalNetworkAPI.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FlipMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Flip whenever you want")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FlipMod")]
[assembly: AssemblyTitle("FlipMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 FlipMod
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FlipMod";

		public const string PLUGIN_NAME = "FlipMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace DoAFlip
{
	[BepInPlugin("ironbean.DoAFlip", "Do A Flip", "1.0.2")]
	public class DoAFlipBase : BaseUnityPlugin
	{
		internal class BackflipInputClass : LcInputActions
		{
			[InputAction(/*Could not decode attribute arguments.*/)]
			public InputAction FlipButton { get; set; }
		}

		[HarmonyPatch(typeof(PlayerControllerB))]
		internal class PlayerSpin
		{
			[HarmonyPatch("Update")]
			[HarmonyPostfix]
			private static void CreatePatch()
			{
				PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				if (!val.thisController.isGrounded)
				{
					if (!(val.currentlyHeldObjectServer?.itemProperties.itemName == "Jetpack") && !val.inVehicleAnimation && !val.isClimbingLadder && InputActionsInstance.FlipButton.ReadValue<float>() != 0f && !val.jetpackControls)
					{
						StartFlip(val);
						FlipMessage.SendServer("StartFlip");
					}
				}
				else if (val.jetpackControls)
				{
					GrabbableObject currentlyHeldObjectServer = val.currentlyHeldObjectServer;
					if (!(currentlyHeldObjectServer?.itemProperties.itemName == "Jetpack") || !currentlyHeldObjectServer.isBeingUsed)
					{
						StopFlip(val);
						FlipMessage.SendServer("StopFlip");
					}
				}
			}
		}

		private const string modGUID = "ironbean.DoAFlip";

		private const string modName = "Do A Flip";

		private const string modVersion = "1.0.2";

		private readonly Harmony harmony = new Harmony("ironbean.DoAFlip");

		private static DoAFlipBase Instance;

		internal static BackflipInputClass InputActionsInstance;

		internal static ManualLogSource mls;

		internal static LNetworkMessage<string>? FlipMessage;

		internal static LNetworkMessage<ulong>? ClientStartFlipMessage;

		internal static LNetworkMessage<ulong>? ClientStopFlipMessage;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("ironbean.DoAFlip");
			FlipMessage = LNetworkMessage<string>.Connect("ServerGetFlip", (Action<string, ulong>)ServerHandleFlip, (Action<string>)null, (Action<string, ulong>)null);
			ClientStartFlipMessage = LNetworkMessage<ulong>.Connect("ClientStartFlip", (Action<ulong, ulong>)null, (Action<ulong>)null, (Action<ulong, ulong>)ClientStartFlip);
			ClientStopFlipMessage = LNetworkMessage<ulong>.Connect("ClientStopFlip", (Action<ulong, ulong>)null, (Action<ulong>)null, (Action<ulong, ulong>)ClientStopFlip);
			InputActionsInstance = new BackflipInputClass();
			mls.LogInfo((object)"DO A FLIP!");
			harmony.PatchAll(typeof(DoAFlipBase));
			harmony.PatchAll(typeof(PlayerSpin));
		}

		public static PlayerControllerB? GetPlayer(ulong clientID)
		{
			if (!StartOfRound.Instance.ClientPlayerList.TryGetValue(clientID, out var value))
			{
				mls.LogError((object)$"Invalid client ID: {clientID}");
				return null;
			}
			PlayerControllerB result = default(PlayerControllerB);
			if (!StartOfRound.Instance.allPlayerObjects[value].TryGetComponent<PlayerControllerB>(ref result))
			{
				mls.LogError((object)$"Client ID did not have player controller: {clientID}");
				return null;
			}
			return result;
		}

		private static void ServerHandleFlip(string FlipStatus, ulong clientId)
		{
			if (LNetworkUtils.IsHostOrServer)
			{
				if (FlipStatus == "StartFlip")
				{
					ClientStartFlipMessage.SendOtherClients(clientId);
					ClientStartFlip(clientId, clientId);
				}
				else if (FlipStatus == "StopFlip")
				{
					ClientStopFlipMessage.SendOtherClients(clientId);
					ClientStopFlip(clientId, clientId);
				}
			}
		}

		private static void ClientStartFlip(ulong clientId, ulong receivedFrom)
		{
			PlayerControllerB player = GetPlayer(clientId);
			if (!((Object)(object)player == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)(object)player))
			{
				StartFlip(player);
			}
		}

		private static void ClientStopFlip(ulong clientId, ulong receivedFrom)
		{
			PlayerControllerB player = GetPlayer(clientId);
			if (!((Object)(object)player == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)(object)player))
			{
				StopFlip(player);
			}
		}

		private static void StartFlip(PlayerControllerB player)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			player.disablingJetpackControls = false;
			player.jetpackControls = true;
			player.syncFullRotation = ((Component)player).transform.eulerAngles;
		}

		private static void StopFlip(PlayerControllerB player)
		{
			player.DisableJetpackControlsLocally();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}