Decompiled source of Lethal Company Ordnance Disposal v1.0.3

LandmineScrapPlugin.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 LandmineScrapPlugin.NetcodePatcher;
using LandmineScrapPlugin.components;
using LethalLib.Modules;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;

[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 = "")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("LandmineScrapPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Disarm and sell landmines")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LandmineScrapPlugin")]
[assembly: AssemblyTitle("LandmineScrapPlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace LandmineScrapPlugin
{
	[BepInPlugin("LandmineScrapPlugin", "LandmineScrapPlugin", "1.0.0")]
	public class LandmineScrapBase : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("LandmineScrapPlugin");

		public static LandmineScrapBase Instance;

		internal Item landmineScrapItem;

		internal GameObject landmineNetworkHandler;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			NetcodePatcher();
			mls = Logger.CreateLogSource("LandmineScrapPlugin");
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "landminemod");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val == (Object)null)
			{
				mls.LogError((object)"Failed to load asset bundle");
				return;
			}
			mls.LogInfo((object)("Asset Bundle Assets: " + GeneralExtensions.Join<string>((IEnumerable<string>)val.GetAllAssetNames(), (Func<string, string>)null, ", ")));
			landmineScrapItem = val.LoadAsset<Item>("Assets/LandmineResources/LandmineItem.asset");
			landmineNetworkHandler = val.LoadAsset<GameObject>("Assets/LandmineResources/LandmineNetworkHandler.prefab");
			if ((Object)(object)landmineScrapItem == (Object)null || (Object)(object)landmineNetworkHandler == (Object)null)
			{
				mls.LogError((object)"Failed to load custom assets");
				return;
			}
			NetworkPrefabs.RegisterNetworkPrefab(landmineScrapItem.spawnPrefab);
			Utilities.FixMixerGroups(landmineScrapItem.spawnPrefab);
			Items.RegisterScrap(landmineScrapItem, 0, (LevelTypes)1, (string[])null);
			mls.LogInfo((object)"LandmineScrap has awoken!");
			harmony.PatchAll();
		}

		private static void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LandmineScrapPlugin";

		public const string PLUGIN_NAME = "LandmineScrapPlugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LandmineScrapPlugin.Patches
{
	[HarmonyPatch(typeof(Landmine))]
	internal class LandminePatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Landmine), "Start")]
		public static void addInteraction(Landmine __instance)
		{
			CustomLandmines.addInteractionTrigger(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Landmine), "Detonate")]
		public static void remove(Landmine __instance)
		{
			CustomNetworkHandler.Instance.RemoveLandmineServerRPC(((Component)((Component)__instance).transform.parent).GetComponent<NetworkObject>().NetworkObjectId);
		}
	}
	[HarmonyPatch]
	public class NetworkObjectManager
	{
		private static GameObject networkPrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void Init()
		{
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				networkPrefab = LandmineScrapBase.Instance.landmineNetworkHandler;
				networkPrefab.AddComponent<CustomNetworkHandler>();
				NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void SpawnNetworkHandler()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(networkPrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}
}
namespace LandmineScrapPlugin.components
{
	internal class CustomLandmines
	{
		public static void addInteractionTrigger(Landmine mine)
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			GameObject mineObject = ((Component)mine).gameObject;
			mineObject.GetComponent<MeshRenderer>();
			mineObject.tag = "InteractTrigger";
			mineObject.layer = LayerMask.NameToLayer("InteractableObject");
			InteractTrigger val = mineObject.AddComponent<InteractTrigger>();
			GameObject obj = GameObject.Find("StartGameLever");
			val.hoverIcon = ((obj == null) ? null : obj.GetComponent<InteractTrigger>()?.hoverIcon);
			val.hoverTip = "Disarm : [LMB]";
			val.interactable = true;
			val.oneHandedItemAllowed = false;
			val.twoHandedItemAllowed = false;
			val.holdInteraction = true;
			val.timeToHold = 5f;
			val.timeToHoldSpeedMultiplier = 1f;
			val.holdingInteractEvent = new InteractEventFloat();
			val.onInteract = new InteractEvent();
			val.onInteractEarly = new InteractEvent();
			val.onStopInteract = new InteractEvent();
			val.onCancelAnimation = new InteractEvent();
			((UnityEvent<PlayerControllerB>)(object)val.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate(PlayerControllerB player)
			{
				RollDisarm(mineObject, player);
			});
			val.triggerOnce = true;
		}

		private static void RollDisarm(GameObject mineObject, PlayerControllerB player)
		{
			int num = 34;
			int num2 = Random.Range(0, 100);
			LandmineScrapBase.Instance.mls.LogInfo((object)("Rolled chance: " + num2));
			if (num2 <= num)
			{
				mineObject.GetComponent<Landmine>().ExplodeMineServerRpc();
			}
			else
			{
				CustomNetworkHandler.Instance.DeactivateMineServerRPC(((Component)mineObject.transform.parent).GetComponent<NetworkObject>().NetworkObjectId);
			}
		}
	}
	public class CustomNetworkHandler : NetworkBehaviour
	{
		public static CustomNetworkHandler Instance { get; private set; }

		public override void OnNetworkSpawn()
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				CustomNetworkHandler instance = Instance;
				if (instance != null)
				{
					((Component)instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
				}
			}
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		[ServerRpc(RequireOwnership = false)]
		public void DeactivateMineServerRPC(ulong landmineNetworkID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1429377038u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, landmineNetworkID);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1429377038u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				GameObject gameObject = ((Component)((NetworkBehaviour)this).GetNetworkObject(landmineNetworkID)).gameObject;
				Vector3 position = gameObject.transform.position;
				ManualLogSource mls = LandmineScrapBase.Instance.mls;
				Vector3 val3 = position;
				mls.LogInfo((object)("Disarming landmine at " + ((object)(Vector3)(ref val3)).ToString()));
				GameObject val4 = Object.Instantiate<GameObject>(LandmineScrapBase.Instance.landmineScrapItem.spawnPrefab, position, Quaternion.identity);
				if ((Object)(object)val4 == (Object)null)
				{
					LandmineScrapBase.Instance.mls.LogError((object)"Failed to instantiate the mine scrap!");
				}
				val4.GetComponent<NetworkObject>().Spawn(false);
				if (!((GrabbableObject)val4.GetComponent<PhysicsProp>()).isInShipRoom && !((GrabbableObject)val4.GetComponent<PhysicsProp>()).isInFactory)
				{
					Transform transform = val4.transform;
					transform.position += new Vector3(0f, 2f, 0f);
				}
				LandmineScrapBase.Instance.mls.LogInfo((object)"Attempting to destroy landmine!");
				Object.Destroy((Object)(object)gameObject);
				PhysicsProp component = val4.GetComponent<PhysicsProp>();
				int minValue = ((GrabbableObject)component).itemProperties.minValue;
				int maxValue = ((GrabbableObject)component).itemProperties.maxValue;
				int scrapValue = Random.Range(minValue, maxValue);
				SetLandmineScrapValueClientRPC(val4.GetComponent<NetworkObject>().NetworkObjectId, scrapValue);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void RemoveLandmineServerRPC(ulong landmineNetworkID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1910831513u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, landmineNetworkID);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1910831513u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					Object.Destroy((Object)(object)((Component)((NetworkBehaviour)this).GetNetworkObject(landmineNetworkID)).gameObject, 5f);
				}
			}
		}

		[ClientRpc]
		public void SetLandmineScrapValueClientRPC(ulong scrapNetworkID, int scrapValue)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2412340304u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, scrapNetworkID);
					BytePacker.WriteValueBitPacked(val2, scrapValue);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2412340304u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					GameObject gameObject = ((Component)((NetworkBehaviour)this).GetNetworkObject(scrapNetworkID)).gameObject;
					ScanNodeProperties componentInChildren = gameObject.GetComponentInChildren<ScanNodeProperties>();
					componentInChildren.scrapValue = scrapValue;
					componentInChildren.subText = "Value: $" + scrapValue;
					PhysicsProp component = gameObject.GetComponent<PhysicsProp>();
					((GrabbableObject)component).scrapValue = scrapValue;
				}
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_CustomNetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1429377038u, new RpcReceiveHandler(__rpc_handler_1429377038));
			NetworkManager.__rpc_func_table.Add(1910831513u, new RpcReceiveHandler(__rpc_handler_1910831513));
			NetworkManager.__rpc_func_table.Add(2412340304u, new RpcReceiveHandler(__rpc_handler_2412340304));
		}

		private static void __rpc_handler_1429377038(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong landmineNetworkID = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref landmineNetworkID);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((CustomNetworkHandler)(object)target).DeactivateMineServerRPC(landmineNetworkID);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1910831513(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong landmineNetworkID = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref landmineNetworkID);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((CustomNetworkHandler)(object)target).RemoveLandmineServerRPC(landmineNetworkID);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2412340304(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong scrapNetworkID = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref scrapNetworkID);
				int scrapValue = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref scrapValue);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((CustomNetworkHandler)(object)target).SetLandmineScrapValueClientRPC(scrapNetworkID, scrapValue);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "CustomNetworkHandler";
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace LandmineScrapPlugin.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}