Decompiled source of MusicalInstruments v0.0.11

MusicalInstruments.dll

Decompiled 10 months ago
using System;
using System.Collections;
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 LethalLib.Modules;
using LethalThings;
using LethalThings.MonoBehaviours;
using MusicalInstruments.Instruments;
using MusicalInstruments.Patches;
using Unity.Netcode.Components;
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("MusicalInstruments")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MusicalInstruments")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("be81ca85-48bf-4d3e-9a64-25fdc0e33cc3")]
[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 MusicalInstruments
{
	[BepInPlugin("01Ryan.MusicalInstruments", "Musical Instruments", "1.0.0")]
	public class MusicalInstrumentsBase : BaseUnityPlugin
	{
		private const string modGUID = "01Ryan.MusicalInstruments";

		private const string modName = "Musical Instruments";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("01Ryan.MusicalInstruments");

		private static MusicalInstrumentsBase Instance;

		public static ManualLogSource mls;

		public static ConfigFile config;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("01Ryan.MusicalInstruments");
			mls.LogInfo((object)"Musical Instruments Mod is ready to go!");
			config = ((BaseUnityPlugin)this).Config;
			Utilities.Init();
			Config.Load();
			MyContent.Load();
			harmony.PatchAll(typeof(MusicalInstrumentsBase));
		}
	}
}
namespace MusicalInstruments.Patches
{
	public class Config
	{
		public static ConfigEntry<int> buglePrice;

		public static ConfigEntry<int> banjoPrice;

		public static ConfigEntry<int> tambourinePrice;

		public static void Load()
		{
			buglePrice = MusicalInstrumentsBase.config.Bind<int>("Items", "BuglePrice", 15, "How much does Bugle cost?");
			banjoPrice = MusicalInstrumentsBase.config.Bind<int>("Items", "BanjoPrice", 15, "How much does Banjo cost?");
			tambourinePrice = MusicalInstrumentsBase.config.Bind<int>("Items", "TambourinePrice", 15, "How much does Tambourine cost?");
		}
	}
	public class MyContent
	{
		public static AssetBundle MainAssets;

		public static List<CustomItem> customItems;

		public static void TryLoadAssets()
		{
			if (MainAssets == null)
			{
				MainAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "instruments"));
				MusicalInstrumentsBase.mls.LogInfo((object)"Loaded asset bundle");
			}
		}

		public static void Load()
		{
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			TryLoadAssets();
			customItems = new List<CustomItem>
			{
				(CustomItem)(object)CustomShopItem.Add("Bugle", "Assets/Custom/MusicalInstruments/Bugle/Bugle.asset", "Assets/Custom/MusicalInstruments/Bugle/BugleInfo.asset", Config.buglePrice.Value, (Action<Item>)null, true),
				(CustomItem)(object)CustomShopItem.Add("Banjo", "Assets/Custom/MusicalInstruments/Banjo/Banjo.asset", "Assets/Custom/MusicalInstruments/Banjo/BanjoInfo.asset", Config.banjoPrice.Value, (Action<Item>)null, true),
				(CustomItem)(object)CustomShopItem.Add("Tambourine", "Assets/Custom/MusicalInstruments/Tambourine/Tambourine.asset", "Assets/Custom/MusicalInstruments/Tambourine/TambourineInfo.asset", Config.tambourinePrice.Value, (Action<Item>)null, true)
			};
			foreach (CustomItem customItem in customItems)
			{
				if (customItem.enabled)
				{
					Item val = MainAssets.LoadAsset<Item>(customItem.itemPath);
					if (val.spawnPrefab.GetComponent<NetworkTransform>() == null && val.spawnPrefab.GetComponent<CustomNetworkTransform>() == null)
					{
						NetworkTransform val2 = val.spawnPrefab.AddComponent<NetworkTransform>();
						val2.SlerpPosition = false;
						val2.Interpolate = false;
						val2.SyncPositionX = false;
						val2.SyncPositionY = false;
						val2.SyncPositionZ = false;
						val2.SyncScaleX = false;
						val2.SyncScaleY = false;
						val2.SyncScaleZ = false;
						val2.UseHalfFloatPrecision = true;
					}
					if (val.itemName.Equals("Bugle"))
					{
						InstrumentBase instrumentBase = val.spawnPrefab.AddComponent<InstrumentBase>();
						((GrabbableObject)instrumentBase).itemProperties = val;
						((GrabbableObject)instrumentBase).grabbable = true;
						((GrabbableObject)instrumentBase).grabbableToEnemies = true;
						instrumentBase.instrumentName = "Bugle";
						instrumentBase.canPlayDifferentNotes = true;
						instrumentBase.canHoldNotes = true;
					}
					else if (val.itemName.Equals("Banjo"))
					{
						Banjo banjo = val.spawnPrefab.AddComponent<Banjo>();
						((GrabbableObject)banjo).itemProperties = val;
						((GrabbableObject)banjo).grabbable = true;
						((GrabbableObject)banjo).grabbableToEnemies = true;
					}
					else if (val.itemName.Equals("Tambourine"))
					{
						InstrumentBase instrumentBase2 = val.spawnPrefab.AddComponent<InstrumentBase>();
						((GrabbableObject)instrumentBase2).itemProperties = val;
						((GrabbableObject)instrumentBase2).grabbable = true;
						((GrabbableObject)instrumentBase2).grabbableToEnemies = true;
						instrumentBase2.instrumentName = "Tambourine";
						instrumentBase2.canPlayDifferentNotes = false;
						instrumentBase2.canHoldNotes = false;
					}
					Content.Prefabs.Add(customItem.name, val.spawnPrefab);
					NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
					customItem.itemAction(val);
					if (customItem is CustomShopItem)
					{
						TerminalNode val3 = MainAssets.LoadAsset<TerminalNode>(customItem.infoPath);
						MusicalInstrumentsBase.mls.LogInfo((object)$"Registering shop item {customItem.name} with price {((CustomShopItem)customItem).itemPrice}");
						Items.RegisterShopItem(val, (TerminalNode)null, (TerminalNode)null, val3, ((CustomShopItem)customItem).itemPrice);
					}
				}
			}
			MusicalInstrumentsBase.mls.LogInfo((object)"Musical Instruments loaded!");
		}
	}
}
namespace MusicalInstruments.Instruments
{
	internal class Banjo : Shovel
	{
		private InstrumentBase instrument;

		private bool isMordhauGripEnabled = false;

		private Item myItemProperties;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			myItemProperties = Object.Instantiate<Item>(((GrabbableObject)this).itemProperties);
			instrument = ((Component)this).gameObject.AddComponent<InstrumentBase>();
			((GrabbableObject)instrument).itemProperties = myItemProperties;
			((GrabbableObject)instrument).grabbable = true;
			((GrabbableObject)instrument).grabbableToEnemies = true;
			instrument.instrumentName = "Banjo";
			instrument.canPlayDifferentNotes = true;
			instrument.canHoldNotes = false;
			instrument.instrumentAudio = ((Component)this).GetComponent<AudioSource>();
			instrument.instrumentSound = instrument.instrumentAudio.clip;
			((GrabbableObject)instrument).Start();
			((GrabbableObject)this).itemProperties = myItemProperties;
			base.shovelHitForce = 1;
			base.reelUp = MyContent.MainAssets.LoadAsset<AudioClip>("Assets/Custom/MusicalInstruments/Banjo/Banjo-ReelUp-trimmed.wav");
			base.hitSFX = (AudioClip[])(object)new AudioClip[1] { MyContent.MainAssets.LoadAsset<AudioClip>("Assets/Custom/MusicalInstruments/Banjo/Banjo Notes.mp3") };
			base.shovelAudio = ((Component)this).GetComponent<AudioSource>();
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (base.reelingUp)
			{
				((GrabbableObject)this).ItemActivate(true, false);
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			if (base.reelingUp)
			{
				buttonDown = false;
				base.isHoldingButton = false;
				((GrabbableObject)this).isHeld = true;
			}
			if (isMordhauGripEnabled)
			{
				base.shovelHitForce = 1;
				base.reelUp = MyContent.MainAssets.LoadAsset<AudioClip>("Assets/Custom/MusicalInstruments/Banjo/Banjo-ReelUp-trimmed.wav");
				base.hitSFX = (AudioClip[])(object)new AudioClip[1] { MyContent.MainAssets.LoadAsset<AudioClip>("Assets/Custom/MusicalInstruments/Banjo/Banjo Notes.mp3") };
				base.shovelAudio = ((Component)this).GetComponent<AudioSource>();
				((Shovel)this).ItemActivate(used, buttonDown);
			}
			else
			{
				((GrabbableObject)instrument).playerHeldBy = ((GrabbableObject)this).playerHeldBy;
				((GrabbableObject)instrument).ItemActivate(used, buttonDown);
			}
		}

		public override void ItemInteractLeftRight(bool right)
		{
			((GrabbableObject)this).ItemInteractLeftRight(right);
			if (!right)
			{
				MusicalInstrumentsBase.mls.LogInfo((object)"Toggle grip");
				ToggleMordhauGrip();
			}
		}

		public void ToggleMordhauGrip()
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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)
			if (isMordhauGripEnabled)
			{
				((Behaviour)instrument).enabled = true;
				myItemProperties.toolTips[0] = "Play note : [LMB]";
				((GrabbableObject)this).SetControlTipsForItem();
				myItemProperties.positionOffset = new Vector3(0f, 0.3f, 0.3f);
				myItemProperties.rotationOffset = new Vector3(0f, -90f, 120f);
				MusicalInstrumentsBase.mls.LogInfo((object)"Mordhau grip : off");
				isMordhauGripEnabled = false;
			}
			else
			{
				((Behaviour)instrument).enabled = false;
				myItemProperties.toolTips[0] = "Swing : [LMB]";
				((GrabbableObject)this).SetControlTipsForItem();
				myItemProperties.positionOffset = new Vector3(-0.1f, 0f, -0.7f);
				myItemProperties.rotationOffset = new Vector3(0f, -90f, -100f);
				MusicalInstrumentsBase.mls.LogInfo((object)"Mordhau grip : activated");
				isMordhauGripEnabled = true;
			}
		}

		public override void EquipItem()
		{
			((GrabbableObject)this).EquipItem();
			((GrabbableObject)this).playerHeldBy.equippedUsableItemQE = true;
		}

		public override void DiscardItem()
		{
			((Shovel)this).DiscardItem();
			if (isMordhauGripEnabled)
			{
				ToggleMordhauGrip();
			}
			((GrabbableObject)this).isHeld = false;
		}

		public override void GrabItem()
		{
			//IL_0051: 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_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)
			((GrabbableObject)this).GrabItem();
			((GrabbableObject)this).isHeld = true;
			isMordhauGripEnabled = false;
			((Behaviour)instrument).enabled = true;
			myItemProperties.toolTips[0] = "Play note : [LMB]";
			((GrabbableObject)this).SetControlTipsForItem();
			myItemProperties.positionOffset = new Vector3(0f, 0.3f, 0.3f);
			myItemProperties.rotationOffset = new Vector3(0f, -90f, 120f);
		}

		protected override void __initializeVariables()
		{
			((Shovel)this).__initializeVariables();
		}
	}
	internal class InstrumentBase : GrabbableObject
	{
		public string instrumentName;

		public AudioSource instrumentAudio;

		public AudioClip instrumentSound;

		public float pitch;

		public bool canPlayDifferentNotes;

		public bool canHoldNotes;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (!buttonDown)
			{
				if (canHoldNotes)
				{
					((MonoBehaviour)this).StartCoroutine("StopAudio");
				}
			}
			else if (!((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null))
			{
				if (canPlayDifferentNotes)
				{
					Transform transform = ((Component)base.playerHeldBy.gameplayCamera).transform;
					Vector3 forward = transform.forward;
					forward.y = 0f;
					((Vector3)(ref forward)).Normalize();
					Vector3 val = forward;
					Vector3 forward2 = transform.forward;
					float num = Vector3.SignedAngle(val, ((Vector3)(ref forward2)).normalized, transform.right);
					pitch = 1f / (num / 90f + 1f);
					instrumentAudio.pitch = Mathf.Clamp(pitch, 0.2f, 1.5f);
				}
				if (canHoldNotes)
				{
					instrumentAudio.Play();
					WalkieTalkie.TransmitOneShotAudio(instrumentAudio, instrumentSound, 1f);
					RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 10f, 0.5f, 0, false, 0);
				}
				else
				{
					instrumentAudio.PlayOneShot(instrumentSound);
					WalkieTalkie.TransmitOneShotAudio(instrumentAudio, instrumentSound, 1f);
					RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 10f, 0.5f, 0, false, 0);
				}
			}
		}

		public IEnumerator StopAudio()
		{
			float startVolume = instrumentAudio.volume;
			while (instrumentAudio.volume > 0f)
			{
				AudioSource obj = instrumentAudio;
				obj.volume -= startVolume * Time.deltaTime / 0.1f;
				yield return null;
			}
			instrumentAudio.Stop();
			instrumentAudio.volume = startVolume;
		}

		public override void Update()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)((Component)this).gameObject.GetComponent<Shovel>()))
			{
				((GrabbableObject)this).Update();
				if (instrumentAudio.isPlaying && canPlayDifferentNotes && canHoldNotes && base.isHeld)
				{
					Transform transform = ((Component)base.playerHeldBy.gameplayCamera).transform;
					Vector3 forward = transform.forward;
					forward.y = 0f;
					((Vector3)(ref forward)).Normalize();
					Vector3 val = forward;
					Vector3 forward2 = transform.forward;
					float num = Vector3.SignedAngle(val, ((Vector3)(ref forward2)).normalized, transform.right);
					pitch = 1f / (num / 90f + 1f);
					instrumentAudio.pitch = Mathf.Clamp(pitch, 0.2f, 1.5f);
				}
			}
		}

		public override void Start()
		{
			((GrabbableObject)this).Start();
			instrumentAudio = ((Component)this).GetComponent<AudioSource>();
			instrumentSound = instrumentAudio.clip;
		}

		public override void DiscardItem()
		{
			((GrabbableObject)this).DiscardItem();
			base.isHeld = false;
			base.playerHeldBy = null;
		}
	}
}