Decompiled source of detonation device v0.1.0

BepInEx/plugins/LCDetonationDevice.dll

Decompiled 2 years ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using LCModBase.Behaviours;
using LCModBase.Patches;
using LCModBase.Singeltons;
using LethalAPI.LibTerminal;
using LethalAPI.LibTerminal.Attributes;
using LethalAPI.LibTerminal.Models;
using LethalLib.Modules;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LCDetonationDevice")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCDetonationDevice")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9EA2A0C7-15FE-4200-9D9A-42E3C85D2112")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCModBase
{
	[BepInPlugin("TechMachine.LCDetonationDevice", "LCDetonationDevice", "1.0.0")]
	public class LCDetonationDevice : BaseUnityPlugin
	{
		private const string modGUID = "TechMachine.LCDetonationDevice";

		private const string modName = "LCDetonationDevice";

		private const string modVersion = "1.0.0";

		private readonly Harmony _harmony = new Harmony("TechMachine.LCDetonationDevice");

		public static LCDetonationDevice _instance;

		internal ManualLogSource mls;

		public TMP_FontAsset arabicFont;

		private TerminalModRegistry Commands;

		private void Awake()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = this;
			}
			mls = Logger.CreateLogSource("TechMachine.LCDetonationDevice");
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "detonationdevice");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			Item val2 = val.LoadAsset<Item>("Assets/Prefabs/DetonationDeviceItem.asset");
			DetonationDeviceBehaviour detonationDeviceBehaviour = val2.spawnPrefab.AddComponent<DetonationDeviceBehaviour>();
			((GrabbableObject)detonationDeviceBehaviour).grabbable = true;
			((GrabbableObject)detonationDeviceBehaviour).grabbableToEnemies = true;
			((GrabbableObject)detonationDeviceBehaviour).itemProperties = val2;
			GameObject val3 = new GameObject();
			val3.AddComponent<Numbers>();
			arabicFont = val.LoadAsset<TMP_FontAsset>("Assets/Prefabs/DetonationDeviceItem.asset");
			Utilities.FixMixerGroups(val2.spawnPrefab);
			TerminalNode val4 = ScriptableObject.CreateInstance<TerminalNode>();
			val4.clearPreviousText = true;
			val4.displayText = "A holy detonation device \n\n";
			Items.RegisterShopItem(val2, (TerminalNode)null, (TerminalNode)null, val4, 200);
			Commands = TerminalRegistry.CreateTerminalRegistry();
			Commands.RegisterFrom<TerminalCommands>();
			_harmony.PatchAll(typeof(LCDetonationDevice));
			mls.LogInfo((object)"Initiated tech malware strike");
		}
	}
}
namespace LCModBase.Singeltons
{
	public class Numbers : MonoBehaviour
	{
		private int _currentDetonationDeviceId = 0;

		private static Numbers _instance;

		private void Awake()
		{
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = this;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		public static int GetNextDetonationDeviceId()
		{
			return _instance._currentDetonationDeviceId++;
		}
	}
}
namespace LCModBase.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	public class ScanNodePropertiesPatch
	{
		[HarmonyPatch("UpdateScanNodes")]
		[HarmonyPostfix]
		private static void UpdateScanNodesPatch(ref HUDManager instance)
		{
			for (int i = 0; i < instance.scanElements.Length; i++)
			{
				TextMeshProUGUI[] componentsInChildren = ((Component)instance.scanElements[i]).gameObject.GetComponentsInChildren<TextMeshProUGUI>();
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					if (((TMP_Text)componentsInChildren[j]).text != null && ((TMP_Text)componentsInChildren[j]).text.StartsWith("__malice__"))
					{
						((TMP_Text)componentsInChildren[j]).font = LCDetonationDevice._instance.arabicFont;
					}
				}
			}
		}
	}
	public class TerminalCommands
	{
		[TerminalCommand("Activate", false)]
		[CommandInfo("alhamdulillah", "[Detonation Device ID]")]
		public string ActivateDetonationDevice(int detonationDeviceId)
		{
			GameObject[] array = GameObject.FindGameObjectsWithTag("PhysicsProp");
			GameObject[] array2 = array;
			foreach (GameObject val in array2)
			{
				DetonationDeviceBehaviour component = val.GetComponent<DetonationDeviceBehaviour>();
				if ((Object)(object)component != (Object)null && component.detonationDeviceId == detonationDeviceId)
				{
					if (component.Detonate())
					{
						return "allahu akbar, detonation device activated successfully.";
					}
					return "mashallah, you already prayed 5 times today.";
				}
			}
			return "istah fur al'lah, no detonation device found with that ID.";
		}
	}
}
namespace LCModBase.Behaviours
{
	public class DetonationDeviceBehaviour : PhysicsProp
	{
		public int detonationDeviceId;

		public bool isUsed = false;

		private string _headerText;

		[CanBeNull]
		private ScanNodeProperties _scanNodeProperties;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			detonationDeviceId = Numbers.GetNextDetonationDeviceId();
			Transform val = ((Component)this).transform.Find("ScanNode");
			if ((Object)(object)val != (Object)null)
			{
				_scanNodeProperties = ((Component)val).GetComponent<ScanNodeProperties>();
				if ((Object)(object)_scanNodeProperties != (Object)null)
				{
					_headerText = _scanNodeProperties.headerText;
					_scanNodeProperties.headerText = $"{_headerText} [{detonationDeviceId}]";
				}
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && (Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && !isUsed)
			{
				isUsed = true;
				if ((Object)(object)_scanNodeProperties != (Object)null)
				{
					_scanNodeProperties.headerText = _headerText + " [used]";
				}
			}
		}

		public bool Detonate()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (isUsed)
			{
				return false;
			}
			Landmine.SpawnExplosion(((Component)this).gameObject.transform.position + Vector3.up, true, 5.7f, 6.4f);
			Object.Destroy((Object)(object)((Component)this).gameObject, 0.05f);
			return true;
		}
	}
}