Decompiled source of LethalSprayCans v1.0.0

LethalSprayCans.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
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.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalSprayCans.Patches;
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 = "")]
[assembly: AssemblyCompany("LethalSprayCans")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalSprayCans")]
[assembly: AssemblyTitle("LethalSprayCans")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace LethalSprayCans
{
	[BepInPlugin("Ryokune.ExplosiveSprayCans", "Lethal Spray Cans", "1.0.0")]
	public class LethalSprayCanBase : BaseUnityPlugin
	{
		private const string modGUID = "Ryokune.ExplosiveSprayCans";

		private const string modName = "Lethal Spray Cans";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Ryokune.ExplosiveSprayCans");

		internal static ConfigEntry<int> ProbabilityMin;

		internal static ConfigEntry<int> ProbabilityMax;

		public static ManualLogSource mls;

		private static LethalSprayCanBase instance;

		private void Awake()
		{
			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);
					}
				}
			}
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			ProbabilityMin = ((BaseUnityPlugin)this).Config.Bind<int>("Probability", "Min", 0, "Min Multiplier");
			ProbabilityMax = ((BaseUnityPlugin)this).Config.Bind<int>("Probability", "Max", 20, "Max Multiplier");
			mls = Logger.CreateLogSource("Ryokune.ExplosiveSprayCans");
			mls.LogInfo((object)"Plugin Lethal Spray Cans is loaded!");
			harmony.PatchAll(typeof(LethalSprayCanBase));
			harmony.PatchAll(typeof(SprayCanPatch));
		}
	}
	public class SprayNetworkBehaviour : NetworkBehaviour
	{
		public static event Action<string> LevelEvent;

		public override void OnNetworkSpawn()
		{
			SprayNetworkBehaviour.LevelEvent = null;
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		[ClientRpc]
		public void EventClientRpc(string eventName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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(3324330754u, val, (RpcDelivery)0);
				bool flag = eventName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(eventName, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3324330754u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				SprayNetworkBehaviour.LevelEvent?.Invoke(eventName);
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_SprayNetworkBehaviour()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3324330754u, new RpcReceiveHandler(__rpc_handler_3324330754));
		}

		private static void __rpc_handler_3324330754(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string eventName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref eventName, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((SprayNetworkBehaviour)(object)target).EventClientRpc(eventName);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "SprayNetworkBehaviour";
		}
	}
}
namespace LethalSprayCans.Patches
{
	[HarmonyPatch(typeof(SprayPaintItem))]
	internal class SprayCanPatch : NetworkBehaviour
	{
		public static Dictionary<SprayPaintItem, int> currentProbability = new Dictionary<SprayPaintItem, int>();

		private static bool TrySpraying(SprayPaintItem spray)
		{
			//IL_003d: 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)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)spray == (Object)null)
			{
				LethalSprayCanBase.mls.LogWarning((object)"Spray item is null uh oh!");
				return false;
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			localPlayerController.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
			localPlayerController.DamagePlayer(Random.Range(1, localPlayerController.health + 1), true, true, (CauseOfDeath)0, 0, false, default(Vector3));
			Landmine.SpawnExplosion(((Component)localPlayerController.gameplayCamera).transform.position, true, 0f, 0f);
			return false;
		}

		[HarmonyPatch("ItemInteractLeftRight")]
		[HarmonyPostfix]
		private static void Interact(SprayPaintItem __instance, ref float ___sprayCanShakeMeter, ref bool ___isSpraying, ref float ___sprayCanTank, bool right)
		{
			if (!currentProbability.ContainsKey(__instance))
			{
				currentProbability.Add(__instance, 0);
			}
			if (!right && !((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null) && !___isSpraying && !(___sprayCanTank <= 0f) && !(___sprayCanShakeMeter <= 0f) && ___sprayCanShakeMeter + 0.15f > 1f && ((NetworkBehaviour)__instance).IsOwner)
			{
				currentProbability[__instance] += Random.Range(LethalSprayCanBase.ProbabilityMin.Value, LethalSprayCanBase.ProbabilityMax.Value);
				float num = Random.Range(1, 100);
				if (num <= (float)currentProbability[__instance])
				{
					currentProbability[__instance] = 0;
					TrySpraying(__instance);
				}
			}
		}

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

		protected internal override string __getTypeName()
		{
			return "SprayCanPatch";
		}
	}
}