Decompiled source of BetterCommand v0.0.6

BetterCommand.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using BetterCommand.Source.DataStructures;
using BetterCommand.Source.NetworkMessages;
using BetterCommand.Source.Utils;
using Microsoft.CodeAnalysis;
using On.RoR2;
using R2API.Networking;
using R2API.Networking.Interfaces;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[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("BetterCommand")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Made you immune and untargetable when you open artifact of command menu")]
[assembly: AssemblyFileVersion("0.0.6.0")]
[assembly: AssemblyInformationalVersion("0.0.6+69f0dad9d14a35e7d4336b54dd3568db7a938e13")]
[assembly: AssemblyProduct("BetterCommand")]
[assembly: AssemblyTitle("BetterCommand")]
[assembly: AssemblyVersion("0.0.6.0")]
[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 BetterCommand.Source
{
	[BepInPlugin("AnnasVirtual.BetterCommand", "BetterCommand", "0.0.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BetterCommand : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_OnDisplayBegin <>9__5_0;

			public static hook_OnDisplayEnd <>9__5_1;

			internal void <Awake>b__5_0(orig_OnDisplayBegin orig, PickupPickerController self, NetworkUIPromptController networkUIPromptController, LocalUser localUser, CameraRigController cameraRigController)
			{
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				if (NetworkServer.active)
				{
					CharacterMaster currentParticipantMaster = networkUIPromptController.currentParticipantMaster;
					currentlyInItemPickerPlayers.Add(new PlayerHealthData(((Component)currentParticipantMaster).gameObject, currentParticipantMaster.GetBody().healthComponent.health));
					currentParticipantMaster.GetBody().AddBuff(Buffs.Untargetable);
					currentParticipantMaster.GetBody().AddBuff(Buffs.Immune);
					orig.Invoke(self, networkUIPromptController, localUser, cameraRigController);
				}
				else
				{
					NetMessageExtensions.Send((INetMessage)(object)new PickupPickerMessage(((NetworkBehaviour)networkUIPromptController.currentParticipantMaster).netId, PickupPickerMessageType.Add), (NetworkDestination)2);
					orig.Invoke(self, networkUIPromptController, localUser, cameraRigController);
				}
			}

			internal void <Awake>b__5_1(orig_OnDisplayEnd orig, PickupPickerController self, NetworkUIPromptController networkUIPromptController, LocalUser localUser, CameraRigController cameraRigController)
			{
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				if (NetworkServer.active)
				{
					<>c__DisplayClass5_0 CS$<>8__locals0 = new <>c__DisplayClass5_0
					{
						currentParticipantMasterServer = networkUIPromptController.currentParticipantMaster
					};
					currentlyInItemPickerPlayers.RemoveAll((PlayerHealthData currentlyInItemPickerPlayer) => (Object)(object)currentlyInItemPickerPlayer.Player == (Object)(object)((Component)CS$<>8__locals0.currentParticipantMasterServer).gameObject);
					CS$<>8__locals0.currentParticipantMasterServer.GetBody().RemoveBuff(Buffs.Untargetable);
					CS$<>8__locals0.currentParticipantMasterServer.GetBody().RemoveBuff(Buffs.Immune);
					orig.Invoke(self, networkUIPromptController, localUser, cameraRigController);
				}
				else
				{
					NetMessageExtensions.Send((INetMessage)(object)new PickupPickerMessage(((NetworkBehaviour)networkUIPromptController.currentParticipantMaster).netId, PickupPickerMessageType.Remove), (NetworkDestination)2);
					orig.Invoke(self, networkUIPromptController, localUser, cameraRigController);
				}
			}
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass5_0
		{
			public CharacterMaster currentParticipantMasterServer;

			internal bool <Awake>b__2(PlayerHealthData currentlyInItemPickerPlayer)
			{
				return (Object)(object)currentlyInItemPickerPlayer.Player == (Object)(object)((Component)currentParticipantMasterServer).gameObject;
			}
		}

		public const string PluginGUID = "AnnasVirtual.BetterCommand";

		public const string PluginAuthor = "AnnasVirtual";

		public const string PluginName = "BetterCommand";

		public const string PluginVersion = "0.0.6";

		public static List<PlayerHealthData> currentlyInItemPickerPlayers = new List<PlayerHealthData>();

		public void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			NetworkingAPI.RegisterMessageType<PickupPickerMessage>();
			object obj = <>c.<>9__5_0;
			if (obj == null)
			{
				hook_OnDisplayBegin val = delegate(orig_OnDisplayBegin orig, PickupPickerController self, NetworkUIPromptController networkUIPromptController, LocalUser localUser, CameraRigController cameraRigController)
				{
					//IL_0066: Unknown result type (might be due to invalid IL or missing references)
					if (NetworkServer.active)
					{
						CharacterMaster currentParticipantMaster = networkUIPromptController.currentParticipantMaster;
						currentlyInItemPickerPlayers.Add(new PlayerHealthData(((Component)currentParticipantMaster).gameObject, currentParticipantMaster.GetBody().healthComponent.health));
						currentParticipantMaster.GetBody().AddBuff(Buffs.Untargetable);
						currentParticipantMaster.GetBody().AddBuff(Buffs.Immune);
						orig.Invoke(self, networkUIPromptController, localUser, cameraRigController);
					}
					else
					{
						NetMessageExtensions.Send((INetMessage)(object)new PickupPickerMessage(((NetworkBehaviour)networkUIPromptController.currentParticipantMaster).netId, PickupPickerMessageType.Add), (NetworkDestination)2);
						orig.Invoke(self, networkUIPromptController, localUser, cameraRigController);
					}
				};
				<>c.<>9__5_0 = val;
				obj = (object)val;
			}
			PickupPickerController.OnDisplayBegin += (hook_OnDisplayBegin)obj;
			object obj2 = <>c.<>9__5_1;
			if (obj2 == null)
			{
				hook_OnDisplayEnd val2 = delegate(orig_OnDisplayEnd orig, PickupPickerController self, NetworkUIPromptController networkUIPromptController, LocalUser localUser, CameraRigController cameraRigController)
				{
					//IL_006d: Unknown result type (might be due to invalid IL or missing references)
					if (NetworkServer.active)
					{
						CharacterMaster currentParticipantMasterServer = networkUIPromptController.currentParticipantMaster;
						currentlyInItemPickerPlayers.RemoveAll((PlayerHealthData currentlyInItemPickerPlayer) => (Object)(object)currentlyInItemPickerPlayer.Player == (Object)(object)((Component)currentParticipantMasterServer).gameObject);
						currentParticipantMasterServer.GetBody().RemoveBuff(Buffs.Untargetable);
						currentParticipantMasterServer.GetBody().RemoveBuff(Buffs.Immune);
						orig.Invoke(self, networkUIPromptController, localUser, cameraRigController);
					}
					else
					{
						NetMessageExtensions.Send((INetMessage)(object)new PickupPickerMessage(((NetworkBehaviour)networkUIPromptController.currentParticipantMaster).netId, PickupPickerMessageType.Remove), (NetworkDestination)2);
						orig.Invoke(self, networkUIPromptController, localUser, cameraRigController);
					}
				};
				<>c.<>9__5_1 = val2;
				obj2 = (object)val2;
			}
			PickupPickerController.OnDisplayEnd += (hook_OnDisplayEnd)obj2;
			Log.Info("Better Command is loaded");
		}

		public void Update()
		{
			if (!NetworkServer.active)
			{
				return;
			}
			CharacterMaster val = default(CharacterMaster);
			foreach (PlayerHealthData currentlyInItemPickerPlayer in currentlyInItemPickerPlayers)
			{
				if (currentlyInItemPickerPlayer.Player.TryGetComponent<CharacterMaster>(ref val))
				{
					CharacterBody body = val.GetBody();
					body.healthComponent.health = currentlyInItemPickerPlayer.CurrentHealth;
				}
			}
		}
	}
}
namespace BetterCommand.Source.Utils
{
	internal static class Log
	{
		private static ManualLogSource? _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			ManualLogSource? logSource = _logSource;
			if (logSource != null)
			{
				logSource.LogDebug(data);
			}
		}

		internal static void Error(object data)
		{
			ManualLogSource? logSource = _logSource;
			if (logSource != null)
			{
				logSource.LogError(data);
			}
		}

		internal static void Fatal(object data)
		{
			ManualLogSource? logSource = _logSource;
			if (logSource != null)
			{
				logSource.LogFatal(data);
			}
		}

		internal static void Info(object data)
		{
			ManualLogSource? logSource = _logSource;
			if (logSource != null)
			{
				logSource.LogInfo(data);
			}
		}

		internal static void Message(object data)
		{
			ManualLogSource? logSource = _logSource;
			if (logSource != null)
			{
				logSource.LogMessage(data);
			}
		}

		internal static void Warning(object data)
		{
			ManualLogSource? logSource = _logSource;
			if (logSource != null)
			{
				logSource.LogWarning(data);
			}
		}
	}
}
namespace BetterCommand.Source.NetworkMessages
{
	public enum PickupPickerMessageType
	{
		Add,
		Remove
	}
	public class PickupPickerMessage : INetMessage, ISerializableObject
	{
		private NetworkInstanceId characterMasterNetId;

		private PickupPickerMessageType pickupPickerMessageType;

		public PickupPickerMessage()
		{
		}

		public PickupPickerMessage(NetworkInstanceId characterMasterNetId, PickupPickerMessageType pickupPickerMessageType)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			this.characterMasterNetId = characterMasterNetId;
			this.pickupPickerMessageType = pickupPickerMessageType;
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			characterMasterNetId = reader.ReadNetworkId();
			pickupPickerMessageType = (PickupPickerMessageType)reader.ReadInt32();
		}

		public void OnReceived()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				return;
			}
			GameObject gameObject = Util.FindNetworkObject(characterMasterNetId);
			CharacterMaster val = default(CharacterMaster);
			if (!Object.op_Implicit((Object)(object)gameObject) || !gameObject.TryGetComponent<CharacterMaster>(ref val))
			{
				return;
			}
			CharacterBody body = val.GetBody();
			switch (pickupPickerMessageType)
			{
			case PickupPickerMessageType.Add:
				BetterCommand.currentlyInItemPickerPlayers.Add(new PlayerHealthData(gameObject, body.healthComponent.health));
				body.AddBuff(Buffs.Untargetable);
				body.AddBuff(Buffs.Immune);
				break;
			case PickupPickerMessageType.Remove:
				BetterCommand.currentlyInItemPickerPlayers.RemoveAll((PlayerHealthData currentlyInItemPickerPlayer) => (Object)(object)currentlyInItemPickerPlayer.Player == (Object)(object)gameObject);
				body.RemoveBuff(Buffs.Untargetable);
				body.RemoveBuff(Buffs.Immune);
				break;
			}
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(characterMasterNetId);
			writer.Write((int)pickupPickerMessageType);
		}
	}
}
namespace BetterCommand.Source.DataStructures
{
	public class PlayerHealthData
	{
		public GameObject Player { get; private set; }

		public float CurrentHealth { get; private set; }

		public PlayerHealthData(GameObject player, float currentHealth)
		{
			Player = player;
			CurrentHealth = currentHealth;
			base..ctor();
		}
	}
}