Decompiled source of ThrowableBrick v1.2.1

Assets/SeanathonHooper.ThrowableBrick.dll

Decompiled a week 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 LethalLib.Modules;
using Microsoft.CodeAnalysis;
using ThrowableBrick.Patches;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SeanathonHooper.ThrowableBrick")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1+13a7b406e89448fa0e575185827ee00e06b409d7")]
[assembly: AssemblyProduct("ThrowableBrick")]
[assembly: AssemblyTitle("SeanathonHooper.ThrowableBrick")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
	[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 ThrowableBrick
{
	[BepInPlugin("SeanathonHooper.ThrowableBrick", "ThrowableBrick", "1.2.1")]
	public class ThrowableBrick : BaseUnityPlugin
	{
		public static AssetBundle BrickAsset;

		public static ThrowableBrick Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Logger.LogInfo((object)"SeanathonHooper.ThrowableBrick v1.2.1 has loaded!");
			InitializeItem();
		}

		internal static void InitializeItem()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			BrickCustomization brickCustomization = JsonUtility.FromJson<BrickCustomization>(File.ReadAllText(Path.Combine(directoryName, "settings.json")));
			BrickAsset = AssetBundle.LoadFromFile(Path.Combine(directoryName, "brickassetbundle"));
			if ((Object)(object)BrickAsset == (Object)null)
			{
				Logger.LogInfo((object)"Failed to load custom assets");
				return;
			}
			Item val = BrickAsset.LoadAsset<Item>("Assets/BRICK/BrickItem.asset");
			BrickBehavior brickBehavior = val.spawnPrefab.AddComponent<BrickBehavior>();
			((GrabbableObject)brickBehavior).grabbable = true;
			((GrabbableObject)brickBehavior).itemProperties = val;
			int itemRarity = brickCustomization.itemRarity;
			val.minValue = (int)((double)brickCustomization.minValue / 0.4);
			val.maxValue = (int)((double)brickCustomization.maxValue / 0.4);
			val.weight = (float)brickCustomization.weight / 105f + 1f;
			brickBehavior.isExplosive = brickCustomization.funnyMode;
			((GrabbableObject)brickBehavior).grabbableToEnemies = brickCustomization.grabbableToEnemies;
			brickBehavior.health = brickCustomization.brickHealth;
			brickBehavior.explosiveDamange = brickCustomization.funnyModeExplosionDamage;
			brickBehavior.entityDamage = brickCustomization.entityDamage;
			brickBehavior.playerDamage = brickCustomization.playerDamage;
			brickBehavior.damagePlayers = brickCustomization.damagePlayers;
			Debug.Log((object)val.minValue);
			Debug.Log((object)val.weight);
			Debug.Log((object)((GrabbableObject)brickBehavior).grabbableToEnemies);
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, itemRarity, (LevelTypes)(-1));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SeanathonHooper.ThrowableBrick";

		public const string PLUGIN_NAME = "ThrowableBrick";

		public const string PLUGIN_VERSION = "1.2.1";
	}
}
namespace ThrowableBrick.Patches
{
	internal class BrickBehavior : PhysicsProp
	{
		private Ray brickThrowRay;

		private int brickMask = 268437761;

		private RaycastHit brickHit;

		private PlayerControllerB playerThrower;

		public bool isExplosive = true;

		public int health = 5;

		public int entityDamage = 3;

		public int playerDamage = 20;

		public int explosiveDamange = 37;

		public bool damagePlayers = true;

		private bool isThrown;

		private HashSet<Collider> hits = new HashSet<Collider>();

		private void DamageBrick()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			health--;
			if (health <= 0)
			{
				if (isExplosive)
				{
					Landmine.SpawnExplosion(((Component)this).transform.position + Vector3.up, true, 5.7f, 6f, explosiveDamange, 10f, (GameObject)null, false);
				}
				((GrabbableObject)this).DestroyObjectInHand(((GrabbableObject)this).playerHeldBy);
			}
			((GrabbableObject)this).SetScrapValue((int)((double)((GrabbableObject)this).scrapValue * 0.72));
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			Debug.Log((object)"ACTIVATED!");
			isThrown = true;
			playerThrower = ((GrabbableObject)this).playerHeldBy;
			((GrabbableObject)this).playerHeldBy.DiscardHeldObject(true, (NetworkObject)null, GetThrowDestination(), true);
		}

		public override void Update()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Update();
			if (!isThrown)
			{
				return;
			}
			Collider[] array = Physics.OverlapSphere(((Component)this).transform.position, 1f, 2621448, (QueryTriggerInteraction)2);
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				if (hits.Contains(val))
				{
					continue;
				}
				if (((Component)val).gameObject.layer == 3)
				{
					if (damagePlayers)
					{
						PlayerControllerB component = ((Component)val).gameObject.GetComponent<PlayerControllerB>();
						if ((Object)(object)component != (Object)(object)playerThrower)
						{
							Debug.Log((object)("Hit " + ((Object)((Component)component).gameObject).name));
							component.DamagePlayer(playerDamage, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
							hits.Add(val);
						}
					}
				}
				else if (((Component)val).gameObject.layer == 19)
				{
					EnemyAICollisionDetect componentInChildren = ((Component)val).gameObject.GetComponentInChildren<EnemyAICollisionDetect>();
					componentInChildren.mainScript.HitEnemy(entityDamage, ((GrabbableObject)this).playerHeldBy, true, -1);
					Debug.Log((object)("Hit " + ((Object)((Component)componentInChildren).gameObject).name));
					hits.Add(val);
				}
			}
		}

		public override void EquipItem()
		{
			((PhysicsProp)this).EquipItem();
			string[] array = new string[1] { "Throw: [LMB]" };
			if (((NetworkBehaviour)this).IsOwner)
			{
				HUDManager.Instance.ChangeControlTipMultiple(array, true, ((GrabbableObject)this).itemProperties);
			}
		}

		public override void OnHitGround()
		{
			((GrabbableObject)this).OnHitGround();
			hits.Clear();
			if (isThrown && ((Component)((Component)this).transform.Find("Brick")).gameObject.activeSelf)
			{
				((Component)((Component)this).transform.Find("Brick")).gameObject.SetActive(false);
				((Component)((Component)this).transform.Find("BrickDamaged")).gameObject.SetActive(true);
			}
			isThrown = false;
			DamageBrick();
		}

		private Vector3 GetThrowDestination()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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)
			//IL_00c2: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: 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_00e9: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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);
			brickThrowRay = new Ray(((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.position, ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.forward);
			position = ((!Physics.Raycast(brickThrowRay, ref brickHit, 12f, brickMask, (QueryTriggerInteraction)1)) ? ((Ray)(ref brickThrowRay)).GetPoint(10f) : ((Ray)(ref brickThrowRay)).GetPoint(((RaycastHit)(ref brickHit)).distance - 0.05f));
			Debug.DrawRay(position, Vector3.down, Color.blue, 15f);
			brickThrowRay = new Ray(position, Vector3.down);
			if (Physics.Raycast(brickThrowRay, ref brickHit, 30f, brickMask, (QueryTriggerInteraction)1))
			{
				return ((RaycastHit)(ref brickHit)).point + Vector3.up * 0.05f;
			}
			return ((Ray)(ref brickThrowRay)).GetPoint(30f);
		}
	}
	internal struct BrickCustomization
	{
		public int minValue;

		public int maxValue;

		public int weight;

		public int entityDamage;

		public int playerDamage;

		public int brickHealth;

		public bool grabbableToEnemies;

		public bool damagePlayers;

		public int itemRarity;

		public bool funnyMode;

		public int funnyModeExplosionDamage;
	}
}