Decompiled source of DisablePvpInShip Standalone v1.0.1

DisablePvpInShip_Standalone.dll

Decompiled 12 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
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 Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("DisablePvpInShip_Standalone")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("HostFixes DisablePvpInShip Standalone")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DisablePvpInShip_Standalone")]
[assembly: AssemblyTitle("DisablePvpInShip_Standalone")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int A_1)
		{
			Version = A_1;
		}
	}
}
namespace DisablePvpInShip_Standalone
{
	[BepInPlugin("HostFixes.DisablePvpInShip_Standalone", "DisablePvpInShip_Standalone", "1.0.0")]
	public class DisablePvpInShip_StandalonePlugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "HostFixes.DisablePvpInShip_Standalone";

		public const string PLUGIN_NAME = "DisablePvpInShip_Standalone";

		public const string PLUGIN_VERSION = "1.0.0";

		public const string PLUGIN_VERSION_FULL = "1.0.0.0";

		private Harmony harmony = new Harmony("HostFixes.DisablePvpInShip_Standalone");

		public static DisablePvpInShip_StandalonePlugin Instance;

		public static ManualLogSource logger;

		private void Awake()
		{
			Instance = this;
			logger = ((BaseUnityPlugin)this).Logger;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			DisablePvpInShip_StandaloneServerReceiveRpcs.Instance = new DisablePvpInShip_StandaloneServerReceiveRpcs();
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"DisablePvpInShip Standalone is loaded!");
		}
	}
	internal class DisablePvpInShip_StandaloneServerReceiveRpcs
	{
		public static DisablePvpInShip_StandaloneServerReceiveRpcs Instance;

		public void DamagePlayerFromOtherClientServerRpc(int damageAmount, Vector3 hitDirection, int playerWhoHit, PlayerControllerB instance, __RpcParams RpcParams)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			ulong senderClientId = RpcParams.Server.Receive.SenderClientId;
			if (!StartOfRound.Instance.ClientPlayerList.TryGetValue(senderClientId, out var value))
			{
				DisablePvpInShip_StandalonePlugin.logger.LogError((object)$"[DamagePlayerFromOtherClientServerRpc] Failed to get the playerId from senderClientId: {senderClientId}");
				return;
			}
			string playerUsername = StartOfRound.Instance.allPlayerScripts[value].playerUsername;
			if ((Object)(object)StartOfRound.Instance.shipInnerRoomBounds != (Object)null)
			{
				Bounds bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds;
				if (((Bounds)(ref bounds)).Contains(((Component)instance).transform.position))
				{
					DisablePvpInShip_StandalonePlugin.logger.LogInfo((object)$"Player #{value} ({playerUsername}) tried to damage ({instance.playerUsername}) inside the ship.");
					return;
				}
			}
			instance.DamagePlayerFromOtherClientServerRpc(damageAmount, hitDirection, playerWhoHit);
		}
	}
	[HarmonyPatch]
	internal static class Patches
	{
		[HarmonyPatch(typeof(PlayerControllerB), "__rpc_handler_638895557")]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> RedirectDamageRpc(IEnumerable<CodeInstruction> instructions)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			bool flag = false;
			int num = -1;
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Callvirt && list[i].operand is MethodInfo methodInfo && methodInfo.Name == "DamagePlayerFromOtherClientServerRpc")
				{
					num = i;
					flag = true;
					break;
				}
			}
			if (flag)
			{
				list.Insert(num, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
				list.Insert(num + 1, new CodeInstruction(OpCodes.Ldarg_2, (object)null));
				list[num + 2].operand = AccessTools.Method(typeof(DisablePvpInShip_StandaloneServerReceiveRpcs), "DamagePlayerFromOtherClientServerRpc", (Type[])null, (Type[])null);
			}
			else
			{
				DisablePvpInShip_StandalonePlugin.logger.LogError((object)"Could not patch DamagePlayerFromOtherClientServerRpc");
			}
			return list.AsEnumerable();
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}