Decompiled source of MoreItems v0.0.1

plugins/MoreItems/MoreItems.dll

Decompiled 20 hours 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 BepInEx;
using GameNetcodeStuff;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using MoreItems.Behaviours;
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: AssemblyCompany("MoreItems")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MoreItems")]
[assembly: AssemblyTitle("MoreItems")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace MoreItems
{
	[BepInPlugin("LeoLR.MoreItems", "MoreItems", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private const string guid = "LeoLR.MoreItems";

		private const string name = "MoreItems";

		private const string version = "0.0.1";

		public static Plugin instance;

		private void Awake()
		{
			instance = this;
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "moreitems");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			Item val2 = val.LoadAsset<Item>("Assets/DynamiteItem.asset");
			DynamiteBehaviour dynamiteBehaviour = val2.spawnPrefab.AddComponent<DynamiteBehaviour>();
			((GrabbableObject)dynamiteBehaviour).itemProperties = val2;
			((GrabbableObject)dynamiteBehaviour).grabbable = true;
			((GrabbableObject)dynamiteBehaviour).grabbableToEnemies = true;
			Utilities.FixMixerGroups(val2.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
			TerminalNode val3 = ScriptableObject.CreateInstance<TerminalNode>();
			val3.clearPreviousText = true;
			val3.displayText = "Boom boom";
			Items.RegisterShopItem(val2, (TerminalNode)null, (TerminalNode)null, val3, 50);
		}
	}
}
namespace MoreItems.Behaviours
{
	internal class DynamiteBehaviour : PhysicsProp
	{
		public Ray grenadeThrowRay;

		public RaycastHit grenadeHit;

		private float explodeTimer = 0f;

		private float timeToExplode = 999f;

		private readonly float minExplosionTime = 2f;

		private readonly float manExplosionTime = 10f;

		private readonly float radius = 10f;

		private AudioSource MeshBurnSFX;

		private AudioSource ExplosionSFX;

		private AudioSource EarRingSFX;

		private ParticleSystem MeshSmoke;

		private ParticleSystem LingeringFire;

		private ParticleSystem MainBlast;

		private ParticleSystem Smoke;

		private bool active = false;

		private AudioSource getSource(string gameObjectName)
		{
			GameObject gameObject = ((Component)((Component)this).gameObject.transform.Find("DynamiteSFX")).gameObject;
			GameObject gameObject2 = ((Component)gameObject.transform.Find(gameObjectName)).gameObject;
			return gameObject2.GetComponent<AudioSource>();
		}

		private ParticleSystem getSystem(string gameObjectName)
		{
			GameObject gameObject = ((Component)((Component)this).gameObject.transform.Find("DynamiteParticles")).gameObject;
			GameObject gameObject2 = ((Component)gameObject.transform.Find(gameObjectName)).gameObject;
			return gameObject2.GetComponent<ParticleSystem>();
		}

		private void destroyMesh()
		{
			try
			{
				Object.Destroy((Object)(object)((Component)((Component)this).gameObject.transform.Find("Mesh")).gameObject);
			}
			catch
			{
				MonoBehaviour.print((object)"Cannot destroy mesh !");
			}
		}

		private void destroyBase()
		{
			try
			{
				Object.Destroy((Object)(object)((Component)((Component)this).gameObject.transform.Find("Base")).gameObject);
			}
			catch
			{
				MonoBehaviour.print((object)"Cannot destroy base !");
			}
		}

		private void Awake()
		{
			MeshBurnSFX = getSource("MeshBurnSFX");
			ExplosionSFX = getSource("ExplosionSFX");
			EarRingSFX = getSource("EarRingSFX");
			MeshSmoke = getSystem("MeshSmoke");
			LingeringFire = getSystem("LingeringFire");
			MainBlast = getSystem("MainBlast");
			Smoke = getSystem("Smoke");
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null)
			{
				if (!active)
				{
					timeToExplode = Random.Range(manExplosionTime, minExplosionTime);
					MeshBurnSFX.Play();
					MeshSmoke.Play();
					destroyMesh();
					active = true;
				}
				else
				{
					((GrabbableObject)this).playerHeldBy.DiscardHeldObject(true, (NetworkObject)null, GetGrenadeThrowDestination(), true);
				}
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (active)
			{
				if (explodeTimer > timeToExplode)
				{
					Explode();
				}
				explodeTimer += Time.deltaTime;
			}
		}

		public void Explode()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			destroyBase();
			MeshBurnSFX.Stop();
			MeshSmoke.Stop();
			ExplosionSFX.Play();
			MainBlast.Play();
			LingeringFire.Play();
			Smoke.Play();
			active = false;
			explodeTimer = 0f;
			int mask = LayerMask.GetMask(new string[2] { "Player", "Enemies" });
			List<int> list = new List<int>();
			Collider[] array = Physics.OverlapSphere(((Component)this).gameObject.transform.position, radius, mask);
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				PlayerControllerB component = ((Component)val).GetComponent<PlayerControllerB>();
				GameObject playerColliderGameObject = ((Component)val).gameObject;
				Transform enemyColliderRoot = ((Component)val).transform.root;
				if ((Object)(object)component != (Object)null && !list.Exists((int i) => i == ((Object)playerColliderGameObject).GetInstanceID()))
				{
					list.Add(((Object)playerColliderGameObject).GetInstanceID());
					component.DamagePlayer(100, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
					component.statusEffectAudio.PlayOneShot(EarRingSFX.clip);
				}
				EnemyAI component2 = ((Component)enemyColliderRoot).GetComponent<EnemyAI>();
				if ((Object)(object)component2 != (Object)null && !list.Exists((int i) => i == ((Object)((Component)enemyColliderRoot).gameObject).GetInstanceID()) && !component2.isEnemyDead)
				{
					list.Add(((Object)((Component)enemyColliderRoot).gameObject).GetInstanceID());
					if ((Object)(object)component2.creatureVoice != (Object)null && (Object)(object)component2.dieSFX != (Object)null)
					{
						component2.creatureVoice.PlayOneShot(component2.dieSFX);
					}
					component2.KillEnemy(true);
				}
			}
			list.Clear();
			((GrabbableObject)this).DiscardItem();
			Object.Destroy((Object)(object)((Component)this).gameObject, EarRingSFX.clip.length);
		}

		public Vector3 GetGrenadeThrowDestination()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			Debug.DrawRay(((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.position, ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.forward, Color.yellow, 15f);
			grenadeThrowRay = new Ray(((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.position, ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.forward);
			Vector3 val = ((!Physics.Raycast(grenadeThrowRay, ref grenadeHit, 12f, StartOfRound.Instance.collidersAndRoomMaskAndDefault)) ? ((Ray)(ref grenadeThrowRay)).GetPoint(10f) : ((Ray)(ref grenadeThrowRay)).GetPoint(((RaycastHit)(ref grenadeHit)).distance - 0.05f));
			Debug.DrawRay(val, Vector3.down, Color.blue, 15f);
			grenadeThrowRay = new Ray(val, Vector3.down);
			return (!Physics.Raycast(grenadeThrowRay, ref grenadeHit, 30f, StartOfRound.Instance.collidersAndRoomMaskAndDefault)) ? ((Ray)(ref grenadeThrowRay)).GetPoint(30f) : (((RaycastHit)(ref grenadeHit)).point + Vector3.up * 0.05f);
		}
	}
}