Decompiled source of Airhorn v1.0.5

plugins/Airhorn/AirHorn.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using REPOLib.Modules;
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("ZortModBepInex")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ZortModBepInex")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9df868d5-31a0-4d0d-8de2-7370fe2e4989")]
[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 Airhorn;

[BepInPlugin("erne.repo.airhorn", "Airhorn", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Airhorn : BaseUnityPlugin
{
	public const string pluginGuid = "erne.repo.airhorn";

	public const string pluginName = "Airhorn";

	public const string pluginVersion = "1.0.2";

	public const int DRONE = 3;

	public static Item item;

	public static ManualLogSource logger;

	public static Airhorn instance;

	public static AudioClip audio;

	public ConfigEntry<float> cooldown;

	public void Awake()
	{
		instance = this;
		logger = ((BaseUnityPlugin)this).Logger;
		SetConfigs();
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string text = Path.Combine(directoryName, "airhornbundle");
		AssetBundle val = AssetBundle.LoadFromFile(text);
		GameObject val2 = val.LoadAsset<GameObject>("Item Airhorn");
		item = val2.GetComponent<ItemAttributes>().item;
		audio = val.LoadAsset<AudioClip>("AirhornSound");
		if (Object.op_Implicit((Object)(object)item))
		{
			item.prefab = val2;
			Items.RegisterItem(item);
			item.prefab.AddComponent<ItemAirhorn>();
			((BaseUnityPlugin)this).Logger.LogInfo((object)(item.itemName + " is loaded succesfully"));
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)item).name + " is not loaded"));
		}
	}

	private void SetConfigs()
	{
		cooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Airhorn", "Cooldown", 1f, "Cooldown");
	}

	private void Patch()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//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_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		if (RunManager.instance.levelsCompleted != 0)
		{
			return;
		}
		Vector3 position = Vector3.zero;
		Quaternion identity = Quaternion.identity;
		List<LevelPoint> list = new List<LevelPoint>();
		foreach (LevelPoint levelPathPoint in LevelGenerator.Instance.LevelPathPoints)
		{
			if (levelPathPoint.Room.Truck)
			{
				position = ((Component)levelPathPoint).transform.position;
				break;
			}
		}
		Spawn(position, identity, item);
	}

	public void Spawn(Item item)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Spawn(Vector3.zero, Quaternion.identity, item);
	}

	public void Spawn(Vector3 position, Quaternion rotation, Item item)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		if (SemiFunc.IsMultiplayer() && SemiFunc.IsMasterClientOrSingleplayer())
		{
			PhotonNetwork.InstantiateRoomObject("Items/" + ((Object)item).name, position, rotation, (byte)0, (object[])null);
		}
		else
		{
			Object.Instantiate<GameObject>(item.prefab, position, rotation);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)item).name + " is spawned"));
	}
}
public class ItemAirhorn : MonoBehaviour
{
	private ItemEquippable itemEquippable;

	private ItemBattery itemBattery;

	private ItemToggle itemToggle;

	public Sound sound;

	public float maxCooldown;

	private float cooldown;

	private bool itemActive;

	public void Awake()
	{
		itemEquippable = ((Component)this).GetComponent<ItemEquippable>();
		itemBattery = ((Component)this).GetComponent<ItemBattery>();
		itemToggle = ((Component)this).GetComponent<ItemToggle>();
		sound.Sounds = (AudioClip[])(object)new AudioClip[1];
		sound.Sounds[0] = Airhorn.audio;
		itemEquippable.ItemIcon = ((Component)this).GetComponent<ItemAttributes>().icon;
		itemActive = itemToggle.toggleState;
		maxCooldown = Airhorn.instance.cooldown.Value;
	}

	private void Update()
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		if (cooldown > 0f)
		{
			cooldown -= Time.deltaTime;
		}
		else if (itemActive != itemToggle.toggleState)
		{
			itemActive = itemToggle.toggleState;
			sound.Play(((Component)this).transform.position, 1f, 1f, 1f, 1f);
			cooldown = maxCooldown;
		}
	}
}
public static class PatchUtils
{
	private static Dictionary<string, Action> actions = new Dictionary<string, Action>();

	private static object callback;

	public static void RegisterCallback(Type classType, string callback, Action action, bool oneTime = false)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		PatchUtils.callback = callback;
		if (!actions.ContainsKey(callback))
		{
			actions.Add(callback, action);
		}
		else
		{
			actions[callback] = action;
		}
		Harmony val = new Harmony("com.example.patch");
		MethodInfo methodInfo = AccessTools.Method(classType, callback, (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(PatchUtils), oneTime ? "DynamicPostfixOnce" : "DynamicPostfix", (Type[])null, (Type[])null);
		val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	public static void UnRegisterCallback(Type classType, string callback)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("com.example.patch");
		MethodInfo methodInfo = AccessTools.Method(classType, callback, (Type[])null, (Type[])null);
		val.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "com.example.patch");
		actions.Remove(callback);
	}

	public static void DynamicPostfix(MethodBase __originalMethod)
	{
		string name = __originalMethod.Name;
		actions[name]?.Invoke();
	}

	public static void DynamicPostfixOnce(MethodBase __originalMethod)
	{
		string name = __originalMethod.Name;
		actions[name]?.Invoke();
		UnRegisterCallback(__originalMethod.DeclaringType, name);
	}
}