Decompiled source of ScrapAttack v1.0.1

Wes.ScrapAttack.dll

Decompiled 3 weeks 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.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using LobbyCompatibility.Attributes;
using Microsoft.CodeAnalysis;
using ScrapAttack.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("Wes.ScrapAttack")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScrapAttack")]
[assembly: AssemblyTitle("Wes.ScrapAttack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 ScrapAttack
{
	[BepInPlugin("Wes.ScrapAttack", "ScrapAttack", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[LobbyCompatibility(/*Could not decode attribute arguments.*/)]
	public class ScrapAttack : BaseUnityPlugin
	{
		public static AssetBundle MyAssetBundle;

		public static ScrapAttack Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			MyAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "scrapattack"));
			if ((Object)(object)MyAssetBundle == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			RegisterItem("OldBattery", typeof(OldBatteryItem), 60, isScrap: true, new Battery(false, 0.5f));
			RegisterItem("TanglersRope", typeof(TanglersRopeItem), 60, isScrap: true);
			Patch();
			Logger.LogInfo((object)"Wes.ScrapAttack v1.0.0 has loaded!");
		}

		private void RegisterItem(string name, Type itemComponent, int rarity, bool isScrap, Battery battery)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			if (!itemComponent.IsSubclassOf(typeof(GrabbableObject)))
			{
				Logger.LogError((object)("Error registering " + name + ": Given type is not of GrabbableObject"));
				return;
			}
			Item val = MyAssetBundle.LoadAsset<Item>(name + ".asset");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)("Error registering " + name + ": Cant find assetbundle with inputted name. Maybe it's misspelled?"));
				return;
			}
			GrabbableObject val2 = (GrabbableObject)val.spawnPrefab.AddComponent(itemComponent);
			if (isScrap)
			{
				val2.grabbable = true;
				val2.grabbableToEnemies = true;
				val2.isInFactory = true;
				val2.itemProperties = val;
			}
			if (battery != null)
			{
				val2.insertedBattery = battery;
			}
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, rarity, (LevelTypes)(-1));
		}

		private void RegisterItem(string name, Type itemComponent, int rarity, bool isScrap)
		{
			RegisterItem(name, itemComponent, rarity, isScrap, null);
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Wes.ScrapAttack");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Wes.ScrapAttack";

		public const string PLUGIN_NAME = "ScrapAttack";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ScrapAttack.Patches
{
	[HarmonyPatch(typeof(TVScript))]
	public class ExampleTVPatch
	{
		[HarmonyPatch("SwitchTVLocalClient")]
		[HarmonyPrefix]
		private static void SwitchTVPrefix(TVScript __instance)
		{
			StartOfRound.Instance.shipRoomLights.SetShipLightsBoolean(__instance.tvOn);
		}
	}
}
namespace ScrapAttack.Behaviours
{
	internal class OldBatteryItem : GrabbableObject
	{
		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if ((Object)(object)base.playerHeldBy == (Object)null || !((NetworkBehaviour)this).IsOwner || !Physics.Raycast(new Ray(((Component)base.playerHeldBy.gameplayCamera).transform.position, ((Component)base.playerHeldBy.gameplayCamera).transform.forward), ref val, 3f, 1073742656))
			{
				return;
			}
			GrabbableObject component = ((Component)((RaycastHit)(ref val)).transform).GetComponent<GrabbableObject>();
			if ((Object)(object)component == (Object)null || base.insertedBattery.charge == 0f)
			{
				return;
			}
			if (component.itemProperties.requiresBattery && component.insertedBattery.charge != 1f)
			{
				float num = component.insertedBattery.charge * component.itemProperties.batteryUsage + base.insertedBattery.charge * base.itemProperties.batteryUsage;
				float num2 = num / component.itemProperties.batteryUsage - 1f;
				ScrapAttack.Logger.LogInfo((object)num2);
				component.insertedBattery.charge = Math.Clamp(num, 0f, component.itemProperties.batteryUsage) / component.itemProperties.batteryUsage;
				if (num2 > 0f)
				{
					base.insertedBattery.charge = num2;
				}
				else
				{
					base.insertedBattery.charge = 0f;
				}
			}
			else if (component.itemProperties.isConductiveMetal)
			{
				((MonoBehaviour)this).StartCoroutine(SpawnDelayedExplosion(base.insertedBattery.charge * 2f, ((Component)component).transform.position + Vector3.up, spawnExplosionEffect: true, base.insertedBattery.charge * 6f, base.insertedBattery.charge * 6f + 1f, 50, 1f));
				base.insertedBattery.charge = 0f;
			}
		}

		private void SpawnExplosion(Vector3 explosionPosition, bool spawnExplosionEffect = false, float killRange = 1f, float damageRange = 1f, int nonLethalDamage = 50, float physicsForce = 0f, GameObject overridePrefab = null, bool goThroughCar = false)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: 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_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			if (spawnExplosionEffect)
			{
				GameObject val = ((!((Object)(object)overridePrefab != (Object)null)) ? Object.Instantiate<GameObject>(StartOfRound.Instance.explosionPrefab, explosionPosition, Quaternion.Euler(-90f, 0f, 0f), RoundManager.Instance.mapPropsContainer.transform) : Object.Instantiate<GameObject>(overridePrefab, explosionPosition, Quaternion.identity, RoundManager.Instance.mapPropsContainer.transform));
				val.SetActive(true);
			}
			float num = Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, explosionPosition);
			if (num < 14f)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			}
			else if (num < 25f)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
			}
			bool flag = false;
			Collider[] array = Physics.OverlapSphere(explosionPosition, damageRange, 2621448, (QueryTriggerInteraction)2);
			PlayerControllerB val2 = null;
			RaycastHit val3 = default(RaycastHit);
			Vector3 val5;
			for (int i = 0; i < array.Length; i++)
			{
				float num2 = Vector3.Distance(explosionPosition, ((Component)array[i]).transform.position);
				if (Physics.Linecast(explosionPosition, ((Component)array[i]).transform.position + Vector3.up * 0.3f, ref val3, 1073742080, (QueryTriggerInteraction)1) && ((!goThroughCar && ((Component)((RaycastHit)(ref val3)).collider).gameObject.layer == 30) || num2 > 4f))
				{
					continue;
				}
				if (((Component)array[i]).gameObject.layer == 3 && !flag)
				{
					val2 = ((Component)array[i]).gameObject.GetComponent<PlayerControllerB>();
					if ((Object)(object)val2 != (Object)null && ((NetworkBehaviour)val2).IsOwner)
					{
						flag = true;
						if (num2 < killRange)
						{
							Vector3 val4 = Vector3.Normalize(((Component)val2.gameplayCamera).transform.position - explosionPosition) * 80f / Vector3.Distance(((Component)val2.gameplayCamera).transform.position, explosionPosition);
							PlayerControllerB obj = val2;
							val5 = default(Vector3);
							obj.KillPlayer(val4, true, (CauseOfDeath)3, 0, val5);
						}
						else if (num2 < damageRange)
						{
							Vector3 val6 = Vector3.Normalize(((Component)val2.gameplayCamera).transform.position - explosionPosition) * 80f / Vector3.Distance(((Component)val2.gameplayCamera).transform.position, explosionPosition);
							val2.DamagePlayer(nonLethalDamage, true, true, (CauseOfDeath)3, 0, false, val6);
						}
					}
				}
				else if (((Component)array[i]).gameObject.layer == 21)
				{
					Landmine componentInChildren = ((Component)array[i]).gameObject.GetComponentInChildren<Landmine>();
					if ((Object)(object)componentInChildren != (Object)null && !componentInChildren.hasExploded && num2 < 6f)
					{
						((MonoBehaviour)componentInChildren).StartCoroutine(componentInChildren.TriggerOtherMineDelayed(componentInChildren));
					}
				}
				else if (((Component)array[i]).gameObject.layer == 19)
				{
					EnemyAICollisionDetect componentInChildren2 = ((Component)array[i]).gameObject.GetComponentInChildren<EnemyAICollisionDetect>();
					if ((Object)(object)componentInChildren2 != (Object)null && ((NetworkBehaviour)componentInChildren2.mainScript).IsOwner && num2 < 4.5f)
					{
						EnemyAI mainScript = componentInChildren2.mainScript;
						val5 = default(Vector3);
						mainScript.HitEnemyOnLocalClient(6, val5, (PlayerControllerB)null, false, -1);
						componentInChildren2.mainScript.HitFromExplosion(num2);
					}
				}
			}
			val2 = GameNetworkManager.Instance.localPlayerController;
			if (physicsForce > 0f && Vector3.Distance(((Component)val2).transform.position, explosionPosition) < 35f && !Physics.Linecast(explosionPosition, ((Component)val2).transform.position + Vector3.up * 0.3f, ref val3, 256, (QueryTriggerInteraction)1))
			{
				float num3 = Vector3.Distance(((Component)val2).transform.position, explosionPosition);
				Vector3 val7 = Vector3.Normalize(((Component)val2).transform.position + Vector3.up * num3 - explosionPosition) / (num3 * 0.35f) * physicsForce;
				if (((Vector3)(ref val7)).magnitude > 2f)
				{
					if (((Vector3)(ref val7)).magnitude > 10f)
					{
						val2.CancelSpecialTriggerAnimations();
					}
					if (val2.inVehicleAnimation)
					{
						val5 = val2.externalForceAutoFade + val7;
						if (!(((Vector3)(ref val5)).magnitude > 50f))
						{
							goto IL_04a8;
						}
					}
					PlayerControllerB obj2 = val2;
					obj2.externalForceAutoFade += val7;
				}
			}
			goto IL_04a8;
			IL_04a8:
			VehicleController val8 = Object.FindObjectOfType<VehicleController>();
			if ((Object)(object)val8 != (Object)null && !val8.magnetedToShip && physicsForce > 0f && Vector3.Distance(((Component)val8).transform.position, explosionPosition) < 35f)
			{
				val8.mainRigidbody.AddExplosionForce(physicsForce * 50f, explosionPosition, 12f, 3f, (ForceMode)1);
			}
			int num4 = ~LayerMask.GetMask(new string[1] { "Room" });
			num4 = ~LayerMask.GetMask(new string[1] { "Colliders" });
			array = Physics.OverlapSphere(explosionPosition, 10f, num4);
			for (int j = 0; j < array.Length; j++)
			{
				Rigidbody component = ((Component)array[j]).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.AddExplosionForce(70f, explosionPosition, 10f);
				}
			}
		}

		private IEnumerator SpawnDelayedExplosion(float delay, Vector3 explosionPosition, bool spawnExplosionEffect = false, float killRange = 1f, float damageRange = 1f, int nonLethalDamage = 50, float physicsForce = 0f, GameObject overridePrefab = null, bool goThroughCar = false)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSeconds(delay);
			SpawnExplosion(explosionPosition, spawnExplosionEffect, killRange, damageRange, nonLethalDamage, physicsForce, overridePrefab, goThroughCar);
		}
	}
	internal class TanglersRopeItem : GrabbableObject
	{
		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			RaycastHit val = default(RaycastHit);
			if (!((Object)(object)base.playerHeldBy == (Object)null) && ((NetworkBehaviour)this).IsOwner && Physics.Raycast(new Ray(((Component)base.playerHeldBy.gameplayCamera).transform.position, ((Component)base.playerHeldBy.gameplayCamera).transform.forward), ref val, 3f, 2816))
			{
				DoorLock component = ((Component)((RaycastHit)(ref val)).transform).GetComponent<DoorLock>();
				if ((Object)(object)component != (Object)null)
				{
					component.defaultTimeToHold *= 5f;
					base.playerHeldBy.DespawnHeldObject();
				}
			}
		}
	}
}