Decompiled source of DrogenJedenTag v1.4.0

RoR2Drogen.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using EntityStates;
using EntityStates.TitanMonster;
using Microsoft.CodeAnalysis;
using On.EntityStates.TitanMonster;
using On.RoR2;
using R2API;
using R2API.Utils;
using RoR2;
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("RoR2Drogen")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d1989ce58e53511767cc60dec6b85709356f9fe4")]
[assembly: AssemblyProduct("RoR2Drogen")]
[assembly: AssemblyTitle("RoR2Drogen")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RoR2Drogen
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.respeak.drogen", "DrogenJedenTag", "1.3.0")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class DrogenMain : BaseUnityPlugin
	{
		private const string BankName = "drogen_soundbank.bnk";

		public const uint DrogenStart = 1821358973u;

		public const uint DrogenStop = 3106969855u;

		public const uint DrogenPause = 83071095u;

		public const uint DrogenResume = 3040584550u;

		public const uint DrogenRehabilitation = 452547817u;

		public const uint GnomeGnomedPlay = 3563009708u;

		public const uint GnomeHuhPlay = 247409129u;

		public const uint SteamworksStart = 2660522436u;

		public const uint SteamworksStop = 1138002366u;

		public const uint LazerStart = 2729798857u;

		public const uint LazerCharge = 758272295u;

		public const uint LazerFire = 2040934607u;

		public const uint LazerFireEnd = 2649077457u;

		public const uint LazerStop = 182908003u;

		public static ConfigEntry<bool> UseLazer { get; set; }

		public static ConfigEntry<bool> UseGnome { get; set; }

		public static ConfigEntry<bool> UseSteamworks { get; set; }

		public static ConfigEntry<bool> UseDrogen { get; set; }

		public void Awake()
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Expected O, but got Unknown
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Expected O, but got Unknown
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Expected O, but got Unknown
			AddSoundBank();
			UseLazer = ((BaseUnityPlugin)this).Config.Bind<bool>("Toggle", "Lazer", true, "Enables laser sounds for Aurelionite");
			UseGnome = ((BaseUnityPlugin)this).Config.Bind<bool>("Toggle", "Gnome", true, "Enables gnome sounds for Ghor's Tome");
			UseSteamworks = ((BaseUnityPlugin)this).Config.Bind<bool>("Toggle", "Gambling", true, "Enable MHW steamworks music on gambling shrines");
			UseDrogen = ((BaseUnityPlugin)this).Config.Bind<bool>("Toggle", "Drogen", true, "drogen jeden tag");
			((BaseUnityPlugin)this).Config.ConfigReloaded += Config_ConfigReloaded;
			CharacterBody.OnBuffFirstStackGained += new hook_OnBuffFirstStackGained(CharacterBody_OnBuffFirstStackGained);
			CharacterBody.OnBuffFinalStackLost += new hook_OnBuffFinalStackLost(CharacterBody_OnBuffFinalStackLost);
			CharacterBody.OnDeathStart += new hook_OnDeathStart(CharacterBody_OnDeathStart);
			CharacterBody.OnDestroy += new hook_OnDestroy(CharacterBody_OnDestroy);
			ShrineChanceBehavior.AddShrineStack += new hook_AddShrineStack(ShrineChanceBehavior_AddShrineStack);
			PurchaseInteraction.OnEnable += new hook_OnEnable(PurchaseInteraction_OnEnable);
			PurchaseInteraction.OnDisable += new hook_OnDisable(PurchaseInteraction_OnDisable);
			PurchaseInteraction.SetAvailable += new hook_SetAvailable(PurchaseInteraction_SetAvailable);
			Inventory.RpcItemAdded += new hook_RpcItemAdded(Inventory_RpcItemAdded);
			MoneyPickup.Start += new hook_Start(MoneyPickup_Start);
			FireMegaLaser.OnEnter += new hook_OnEnter(FireMegaLaser_OnEnter);
			ChargeMegaLaser.OnEnter += new hook_OnEnter(ChargeMegaLaser_OnEnter);
			FireMegaLaser.OnExit += new hook_OnExit(FireMegaLaser_OnExit);
			SceneDirector.Start += new hook_Start(SceneDirector_Start);
		}

		private void SceneDirector_Start(orig_Start orig, SceneDirector self)
		{
			Debug.LogError((object)"Reloading config...");
			((BaseUnityPlugin)this).Config.Reload();
			orig.Invoke(self);
		}

		private void Config_ConfigReloaded(object sender, EventArgs e)
		{
			Debug.LogError((object)"Drogen config reloaded.");
		}

		private void ChargeMegaLaser_OnEnter(orig_OnEnter orig, ChargeMegaLaser self)
		{
			if (!UseLazer.Value)
			{
				orig.Invoke(self);
				return;
			}
			GameObject gameObject = ((Component)((EntityState)self).outer).gameObject;
			if ((Object)(object)gameObject.GetComponent<Lazermaster>() == (Object)null)
			{
				gameObject.AddComponent<Lazermaster>();
				AkSoundEngine.PostEvent(2729798857u, gameObject);
			}
			AkSoundEngine.PostEvent(758272295u, gameObject);
			orig.Invoke(self);
		}

		private void FireMegaLaser_OnEnter(orig_OnEnter orig, FireMegaLaser self)
		{
			Lazermaster component = ((Component)((EntityState)self).outer).gameObject.GetComponent<Lazermaster>();
			if (component != null && component.Alive)
			{
				AkSoundEngine.PostEvent(2040934607u, ((Component)((EntityState)self).outer).gameObject);
			}
			orig.Invoke(self);
		}

		private void FireMegaLaser_OnExit(orig_OnExit orig, FireMegaLaser self)
		{
			Lazermaster component = ((Component)((EntityState)self).outer).gameObject.GetComponent<Lazermaster>();
			if (component != null && component.Alive)
			{
				AkSoundEngine.PostEvent(2649077457u, ((Component)((EntityState)self).outer).gameObject);
			}
			orig.Invoke(self);
		}

		public static void LazermasterDed(CharacterBody self)
		{
			if ((Object)(object)self == (Object)null || (Object)(object)((Component)self).gameObject == (Object)null)
			{
				Debug.LogWarning((object)"Why are you null?");
				return;
			}
			Lazermaster component = ((Component)self).gameObject.GetComponent<Lazermaster>();
			if ((Object)(object)component != (Object)null)
			{
				component.LazermasterDed();
			}
		}

		private void Inventory_RpcItemAdded(orig_RpcItemAdded orig, Inventory self, ItemIndex itemIndex)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Debug.LogWarning((object)$"Inventory_RpcItemAdded {self} {itemIndex}");
				CheckGnooomed(self, itemIndex);
			}
			catch
			{
				Debug.LogWarning((object)"ERRRRR: Inventory_RpcItemAdded");
			}
			orig.Invoke(self, itemIndex);
		}

		public static void CheckGnooomed(Inventory self, ItemIndex itemIndex)
		{
			//IL_0000: 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)
			if (itemIndex != Items.BonusGoldPackOnKill.itemIndex || !UseGnome.Value)
			{
				return;
			}
			CharacterMaster component = ((Component)self).GetComponent<CharacterMaster>();
			if ((Object)(object)component == (Object)null)
			{
				Debug.Log((object)"No character master, skipping");
				return;
			}
			GameObject bodyObject = component.GetBodyObject();
			if ((Object)(object)bodyObject == (Object)null)
			{
				Debug.Log((object)"No character body, skipping");
				return;
			}
			Debug.LogError((object)"You got gnomed");
			AkSoundEngine.PostEvent(3563009708u, bodyObject);
		}

		private void MoneyPickup_Start(orig_Start orig, MoneyPickup self)
		{
			if (UseGnome.Value)
			{
				((Component)self).gameObject.AddComponent<GoldDestroyer>();
			}
			orig.Invoke(self);
		}

		private void PurchaseInteraction_OnDisable(orig_OnDisable orig, PurchaseInteraction self)
		{
			AkSoundEngine.PostEvent(1138002366u, ((Component)self).gameObject);
			orig.Invoke(self);
		}

		private void PurchaseInteraction_SetAvailable(orig_SetAvailable orig, PurchaseInteraction self, bool newAvailable)
		{
			if ((Object)(object)((Component)self).gameObject.GetComponent<ShrineChanceBehavior>() != (Object)null)
			{
				if (newAvailable)
				{
					StartSteamworks(((Component)self).gameObject);
				}
				else
				{
					AkSoundEngine.PostEvent(1138002366u, ((Component)self).gameObject);
				}
			}
			orig.Invoke(self, newAvailable);
		}

		private void PurchaseInteraction_OnEnable(orig_OnEnable orig, PurchaseInteraction self)
		{
			if ((Object)(object)((Component)self).gameObject.GetComponent<ShrineChanceBehavior>() != (Object)null)
			{
				StartSteamworks(((Component)self).gameObject);
			}
			orig.Invoke(self);
		}

		private void ShrineChanceBehavior_AddShrineStack(orig_AddShrineStack orig, ShrineChanceBehavior self, Interactor activator)
		{
			orig.Invoke(self, activator);
		}

		private void StartSteamworks(GameObject go)
		{
			if (UseSteamworks.Value)
			{
				AkSoundEngine.PostEvent(2660522436u, go);
			}
		}

		private void CharacterBody_OnDestroy(orig_OnDestroy orig, CharacterBody self)
		{
			Drogenentzug(self);
			LazermasterDed(self);
			orig.Invoke(self);
		}

		private void CharacterBody_OnDeathStart(orig_OnDeathStart orig, CharacterBody self)
		{
			Drogenentzug(self);
			LazermasterDed(self);
			orig.Invoke(self);
		}

		private void CharacterBody_OnBuffFinalStackLost(orig_OnBuffFinalStackLost orig, CharacterBody self, BuffDef buffDef)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (self.isPlayerControlled && buffDef.buffIndex == Buffs.TonicBuff.buffIndex)
			{
				Drogenentzug(self);
			}
			orig.Invoke(self, buffDef);
		}

		private void CharacterBody_OnBuffFirstStackGained(orig_OnBuffFirstStackGained orig, CharacterBody self, BuffDef buffDef)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (self.isPlayerControlled && buffDef.buffIndex == Buffs.TonicBuff.buffIndex)
			{
				Drogenrausch(self);
			}
			orig.Invoke(self, buffDef);
		}

		public static void Drogenrausch(CharacterBody self)
		{
			if (UseDrogen.Value)
			{
				AkSoundEngine.PostEvent(1821358973u, ((Component)self).gameObject);
			}
		}

		public static void Drogenentzug(CharacterBody self)
		{
			if (!((Object)(object)self == (Object)null) && !((Object)(object)((Component)self).gameObject == (Object)null) && self.isPlayerControlled)
			{
				AkSoundEngine.PostEvent(3106969855u, ((Component)self).gameObject);
			}
		}

		public static void AddSoundBank()
		{
			byte[] array = LoadEmbeddedResource("drogen_soundbank.bnk");
			if (array != null)
			{
				uint num = SoundBanks.Add(array);
				Debug.LogWarning((object)$"Load BankId {num}");
			}
			else
			{
				Debug.LogError((object)"SoundBank Fetching Failed");
			}
		}

		private static byte[] LoadEmbeddedResource(string resourceName)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			resourceName = executingAssembly.GetManifestResourceNames().First((string str) => str.EndsWith(resourceName));
			using Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			return array;
		}

		private static void PrintGameObjectTree(GameObject start)
		{
			Debug.LogWarning((object)"---");
			GameObject val = start;
			List<GameObject> list = new List<GameObject>();
			while ((Object)(object)val.transform.parent != (Object)null)
			{
				val = ((Component)val.transform.parent).gameObject;
				list.Add(val);
			}
			list.Reverse();
			int num = 0;
			foreach (GameObject item in list)
			{
				PrintGameObject(item, num, isStart: false);
				num++;
			}
			PrintGameObjectChildren(start, num, isStart: true);
			Debug.LogWarning((object)"---");
		}

		private static void PrintGameObject(GameObject gameObject, int indentCount, bool isStart)
		{
			string text = (isStart ? "<-" : "");
			string indent = "";
			for (int i = 0; i < indentCount; i++)
			{
				indent += "  ";
			}
			Debug.LogWarning((object)(indent + ((Object)gameObject).name + " " + text));
			gameObject.GetComponents<MonoBehaviour>().ToList().ForEach(delegate(MonoBehaviour mb)
			{
				Debug.LogWarning((object)(indent + "⊢" + ((object)mb).GetType().Name));
			});
		}

		private static void PrintGameObjectChildren(GameObject gameObject, int indentCount, bool isStart)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			PrintGameObject(gameObject, indentCount, isStart);
			foreach (Transform item in gameObject.transform)
			{
				PrintGameObjectChildren(((Component)item).gameObject, indentCount + 1, isStart: false);
			}
		}
	}
	internal class GoldDestroyer : MonoBehaviour
	{
		public void OnDestroy()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			GameObject go = new GameObject("temp gnome");
			go.transform.position = ((Component)this).gameObject.transform.position;
			AkSoundEngine.PostEvent(247409129u, go, 1u, (EventCallback)delegate(object cookie, AkCallbackType type, AkCallbackInfo info)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Invalid comparison between Unknown and I4
				if ((int)type == 1)
				{
					Object.Destroy((Object)(object)go);
				}
			}, (object)null);
		}
	}
	internal class Lazermaster : MonoBehaviour
	{
		public bool Alive { get; set; } = true;


		public void OnDisable()
		{
			LazermasterDed();
		}

		public void LazermasterDed()
		{
			Alive = false;
			AkSoundEngine.PostEvent(182908003u, ((Component)this).gameObject);
		}
	}
}