Decompiled source of ExplosivePresents v1.1.4

ExplosivePresents.dll

Decompiled 5 months ago
using System;
using System.Collections;
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.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Hypick.ExplosivePresents.NetcodePatcher;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[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 = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Hypick.ExplosivePresents")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.4.0")]
[assembly: AssemblyInformationalVersion("1.1.4+960ff319f7e6a60ad0ebbd89cc21f833f8d7da1c")]
[assembly: AssemblyProduct("ExplosivePresents")]
[assembly: AssemblyTitle("Hypick.ExplosivePresents")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
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 P_0)
		{
			Version = P_0;
		}
	}
}
namespace Hypick
{
	public class NetworkHandler : NetworkBehaviour
	{
		public static NetworkHandler Instance { get; private set; }

		[ServerRpc(RequireOwnership = false)]
		public void CustomExplodeMineServerRpc(Vector3 explosionPosition)
		{
			//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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Invalid comparison between Unknown and I4
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Invalid comparison between Unknown and I4
			//IL_0131: 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(3507213930u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref explosionPosition);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3507213930u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
			{
				return;
			}
			NetworkManager networkManager2 = ((NetworkBehaviour)this).NetworkManager;
			if (!((Object)(object)networkManager2 == (Object)null) && networkManager2.IsListening)
			{
				if ((int)base.__rpc_exec_stage == 1 || networkManager2.IsClient || networkManager2.IsHost)
				{
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager2.IsServer || networkManager2.IsHost))
				{
					CustomExplodeMineClientRpc(explosionPosition);
				}
			}
		}

		[ClientRpc]
		public void CustomExplodeMineClientRpc(Vector3 explosionPosition)
		{
			//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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Invalid comparison between Unknown and I4
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Invalid comparison between Unknown and I4
			//IL_0131: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(4091570818u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref explosionPosition);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 4091570818u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			NetworkManager networkManager2 = ((NetworkBehaviour)this).NetworkManager;
			if (!((Object)(object)networkManager2 == (Object)null) && networkManager2.IsListening)
			{
				if ((int)base.__rpc_exec_stage == 2 || networkManager2.IsServer || networkManager2.IsHost)
				{
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager2.IsClient || networkManager2.IsHost))
				{
					((MonoBehaviour)this).StartCoroutine(DelayedExplosion(explosionPosition, spawnExplosionEffect: true, Plugin.Config.KillRange, Plugin.Config.DamageRange, Plugin.Config.Delay));
				}
			}
		}

		private static IEnumerator DelayedExplosion(Vector3 explosionPosition, bool spawnExplosionEffect = false, float killRange = 1f, float damageRange = 1f, float Delay = 1f)
		{
			//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)
			Landmine landmine = Resources.FindObjectsOfTypeAll<Landmine>()[0];
			GameObject mineAudio = GameObject.Find("SpeakerAudio");
			mineAudio.GetComponent<AudioSource>().PlayOneShot(landmine.mineTrigger, 1f);
			yield return (object)new WaitForSeconds(Delay);
			mineAudio.GetComponent<AudioSource>().PlayOneShot(landmine.mineDetonate, 1f);
			Landmine.SpawnExplosion(explosionPosition + Vector3.up, spawnExplosionEffect, killRange, damageRange);
		}

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

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_NetworkHandler()
		{
			//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
			NetworkManager.__rpc_func_table.Add(3507213930u, new RpcReceiveHandler(__rpc_handler_3507213930));
			NetworkManager.__rpc_func_table.Add(4091570818u, new RpcReceiveHandler(__rpc_handler_4091570818));
		}

		private static void __rpc_handler_3507213930(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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)
			{
				Vector3 explosionPosition = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref explosionPosition);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).CustomExplodeMineServerRpc(explosionPosition);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_4091570818(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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)
			{
				Vector3 explosionPosition = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref explosionPosition);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).CustomExplodeMineClientRpc(explosionPosition);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "NetworkHandler";
		}
	}
	[BepInPlugin("Hypick.ExplosivePresents", "ExplosivePresents", "1.1.3")]
	[BepInIncompatibility("LethalPresents")]
	[BepInIncompatibility("GiftBoxRevert")]
	[BepInIncompatibility("BuffedPresents")]
	[BepInIncompatibility("ExplodingPresents")]
	public class Plugin : BaseUnityPlugin
	{
		public static PluginConfig Config;

		private readonly Harmony _harmony = new Harmony("Hypick.ExplosivePresents");

		public static Plugin Instance { get; set; }

		public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		public Plugin()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			Instance = this;
		}

		private void Awake()
		{
			Config = new PluginConfig(((BaseUnityPlugin)this).Config);
			NetcodePatcher();
			Log.LogInfo((object)"Applying patches...");
			_harmony.PatchAll();
			Log.LogInfo((object)"Patches applied");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Hypick.ExplosivePresents is fully loaded!");
		}

		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 Categories
	{
		public const string Present = "Present";
	}
	public class PluginConfig
	{
		public bool ImmediateExplosion;

		public float SpawnChance;

		public float KillRange;

		public float DamageRange;

		public float Delay;

		public PluginConfig(ConfigFile cfg)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			ImmediateExplosion = cfg.Bind<bool>("Present", "ImmediateExplosion", false, "").Value;
			SpawnChance = cfg.Bind<float>("Present", "SpawnChance", 10f, new ConfigDescription("Chance of the present exploding", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())).Value;
			KillRange = cfg.Bind<float>("Present", "KillRange", 5.7f, "Explosion kill range").Value;
			DamageRange = cfg.Bind<float>("Present", "DamageRange", 6.4f, "Explosion damage range").Value;
			Delay = cfg.Bind<float>("Present", "Delay", 0.5f, "Delay before explosion. In seconds").Value;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Hypick.ExplosivePresents";

		public const string PLUGIN_NAME = "ExplosivePresents";

		public const string PLUGIN_VERSION = "1.1.3";
	}
}
namespace Hypick.Patches
{
	[HarmonyPatch(typeof(GiftBoxItem))]
	internal class GiftBoxItemPatch
	{
		private enum RpcExecStage
		{
			None,
			Server,
			Client
		}

		[HarmonyPatch("OpenGiftBoxServerRpc")]
		[HarmonyPrefix]
		private static bool OpenGiftBox(GiftBoxItem __instance)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (Mathf.Clamp(Plugin.Config.SpawnChance, 0f, 100f) / 100f > Random.Range(0f, 0.99f))
			{
				NetworkHandler.Instance.CustomExplodeMineServerRpc(((Component)__instance).transform.position);
				return OpenGiftBoxCustom(__instance, explosive: true);
			}
			return OpenGiftBoxCustom(__instance);
		}

		private static bool OpenGiftBoxCustom(GiftBoxItem __instance, bool explosive = false)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Expected O, but got Unknown
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Expected O, but got Unknown
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
			if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening)
			{
				return false;
			}
			if ((RpcExecStage)((object)__instance).GetType().GetField("__rpc_exec_stage", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) != RpcExecStage.Server && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = (FastBufferWriter)((object)__instance).GetType().GetMethod("__beginSendServerRpc", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[3]
				{
					2878544999u,
					val,
					(object)(RpcDelivery)0
				});
				((object)__instance).GetType().GetMethod("__endSendServerRpc", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[4]
				{
					val2,
					2878544999u,
					val,
					(object)(RpcDelivery)0
				});
			}
			if ((RpcExecStage)((object)__instance).GetType().GetField("__rpc_exec_stage", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) != RpcExecStage.Server || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return false;
			}
			if (explosive)
			{
				Plugin.Log.LogInfo((object)"OPEN GIFTBOX WTTH BOMB AHAHAAHAAH");
				__instance.OpenGiftBoxNoPresentClientRpc();
				return false;
			}
			Plugin.Log.LogInfo((object)"OPEN GIFTBOX without bomb :(");
			GameObject val3 = null;
			int num = 0;
			Vector3 val4 = Vector3.zero;
			GameObject val5 = (GameObject)((object)__instance).GetType().GetField("objectInPresent", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
			if ((Object)(object)val5 == (Object)null)
			{
				Debug.LogError((object)"Error: There is no object in gift box!");
			}
			else
			{
				Transform val6 = ((((!((Object)(object)((GrabbableObject)__instance).playerHeldBy != (Object)null) || !((GrabbableObject)__instance).playerHeldBy.isInElevator) && !StartOfRound.Instance.inShipPhase) || !((Object)(object)RoundManager.Instance.spawnedScrapContainer != (Object)null)) ? StartOfRound.Instance.elevatorTransform : RoundManager.Instance.spawnedScrapContainer);
				val4 = ((Component)__instance).transform.position + Vector3.up * 0.25f;
				val3 = Object.Instantiate<GameObject>(val5, val4, Quaternion.identity, val6);
				GrabbableObject component = val3.GetComponent<GrabbableObject>();
				PlayerControllerB val7 = (PlayerControllerB)((object)__instance).GetType().GetField("previousPlayerHeldBy", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
				component.startFallingPosition = val4;
				((MonoBehaviour)__instance).StartCoroutine(__instance.SetObjectToHitGroundSFX(component));
				component.targetFloorPosition = component.GetItemFloorPosition(((Component)__instance).transform.position);
				if ((Object)(object)val7 != (Object)null && val7.isInHangarShipRoom)
				{
					val7.SetItemInElevator(true, true, component);
				}
				num = (int)((object)__instance).GetType().GetField("objectInPresentValue", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
				component.SetScrapValue(num);
				((NetworkBehaviour)component).NetworkObject.Spawn(false);
			}
			if ((Object)(object)val3 != (Object)null)
			{
				__instance.OpenGiftBoxClientRpc(NetworkObjectReference.op_Implicit(val3.GetComponent<NetworkObject>()), num, val4);
			}
			__instance.OpenGiftBoxNoPresentClientRpc();
			return false;
		}
	}
	[HarmonyPatch]
	public class NetworkObjectManager
	{
		private static GameObject networkPrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void Init()
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Assets/netcodemod");
				AssetBundle val = ((!File.Exists(text)) ? AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "netcodemod")) : AssetBundle.LoadFromFile(text));
				Plugin.Log.LogInfo((object)$"Loading NetworkManager Prefab: {val}");
				networkPrefab = (GameObject)val.LoadAsset("Assets/Necode/NetwordManager.prefab");
				networkPrefab.AddComponent<NetworkHandler>();
				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 System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace Hypick.ExplosivePresents.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}