Decompiled source of Silence v1.1.1

SilenceMod.dll

Decompiled 5 days 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.Versioning;
using BepInEx;
using BepInEx.Logging;
using BlackMagicAPI.Enums;
using BlackMagicAPI.Helpers;
using BlackMagicAPI.Managers;
using BlackMagicAPI.Modules.Spells;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Audio;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("SilenceMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SilenceMod")]
[assembly: AssemblyTitle("SilenceMod")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace Fail.Silence
{
	[BepInPlugin("Fail.Silence", "Silence", "1.1.0")]
	public class SilencePlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static SilencePlugin Instance;

		public static string modsync = "all";

		private void Awake()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			SpellManager.RegisterSpell((BaseUnityPlugin)this, typeof(SilenceSpellData), typeof(SilenceSpellLogic));
			Logger.LogInfo((object)"Silence has loaded successfully.");
		}
	}
	public class SilenceSpellData : SpellData
	{
		public override SpellType SpellType => (SpellType)0;

		public override string Name => "Silence";

		public override float Cooldown => 20f;

		public override Color GlowColor => Color.magenta;

		public override bool CanSpawnInTeamChest => false;

		public override bool CanSpawnInColoseum => true;

		public override bool DebugForceSpawn => false;

		public bool CanSpawnInMageTower => true;

		public bool CanBeTradedWithGnomes => true;

		public bool CanSpawnInPots()
		{
			return true;
		}

		public override Texture2D? GetMainTexture()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string text = Path.Combine(directoryName, "SilenceMain.png");
			Texture2D val = Utils.LoadTextureFromDisk(text);
			if ((Object)(object)val == (Object)null)
			{
				SilencePlugin.Logger.LogWarning((object)"[Silence] Main texture not found on disk - trying embedded.");
				val = Utils.LoadTextureFromResources(Assembly.GetExecutingAssembly(), "Silence.Resources.SilenceMain.png");
			}
			if ((Object)(object)val == (Object)null)
			{
				SilencePlugin.Logger.LogWarning((object)"[Silence] No texture found - using fallback.");
				return new Texture2D(1, 1);
			}
			return val;
		}

		public override Texture2D? GetEmissionTexture()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string text = Path.Combine(directoryName, "SilenceMainEmissive.png");
			Texture2D val = Utils.LoadTextureFromDisk(text);
			if ((Object)(object)val == (Object)null)
			{
				SilencePlugin.Logger.LogWarning((object)"[Silence] Emission texture not found on disk - trying embedded.");
				val = Utils.LoadTextureFromResources(Assembly.GetExecutingAssembly(), "Silence.Resources.SilenceMainEmissive.png");
			}
			if ((Object)(object)val == (Object)null)
			{
				SilencePlugin.Logger.LogWarning((object)"[Silence] No emission texture found - using fallback.");
				return new Texture2D(1, 1);
			}
			return val;
		}
	}
	public class SilenceSpellLogic : SpellLogic
	{
		[CompilerGenerated]
		private sealed class <TrySilence>d__9 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public AudioSource au;

			public float dura;

			public SilenceSpellLogic <>4__this;

			private SilenceController <silenceController>5__1;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <TrySilence>d__9(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<silenceController>5__1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				if (<>1__state != 0)
				{
					return false;
				}
				<>1__state = -1;
				<>4__this.silenceTime = dura;
				if ((Object)(object)au == (Object)null)
				{
					return false;
				}
				<silenceController>5__1 = ((Component)((Component)au).transform.parent).GetComponent<SilenceController>();
				if ((Object)(object)<silenceController>5__1 == (Object)null)
				{
					<silenceController>5__1 = ((Component)((Component)au).transform.parent).gameObject.AddComponent<SilenceController>();
				}
				<silenceController>5__1.ApplySilence(<>4__this.silenceTime, au, <>4__this.muffledGroup, <>4__this.defaultGroup);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public float duration = 3f;

		public float silenceTime = 0f;

		public Transform tf;

		public LayerMask playerLayer;

		private AudioMixer? voiceMixer;

		private AudioMixerGroup? muffledGroup;

		private AudioMixerGroup? defaultGroup;

		private void Awake()
		{
			voiceMixer = Resources.Load<AudioMixer>("VoiceMixer");
			if ((Object)(object)voiceMixer != (Object)null)
			{
				muffledGroup = voiceMixer.FindMatchingGroups("Muffled")[0];
				defaultGroup = voiceMixer.FindMatchingGroups("Default")[0];
			}
		}

		public override void CastSpell(GameObject casterObj, Vector3 spawnPos, Vector3 viewDir, int level)
		{
			//IL_0012: 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)
			//IL_002b: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			((Component)tf).transform.position = casterObj.transform.position + new Vector3(0f, 40f, 0f);
			Collider[] array = Physics.OverlapSphere(((Component)this).transform.position, 40f, LayerMask.op_Implicit(playerLayer));
			AudioSource au = default(AudioSource);
			for (int i = 0; i < array.Length; i++)
			{
				if (((Component)array[i]).TryGetComponent<AudioSource>(ref au))
				{
					((MonoBehaviour)this).StartCoroutine(TrySilence(au, duration));
				}
			}
		}

		[IteratorStateMachine(typeof(<TrySilence>d__9))]
		private IEnumerator TrySilence(AudioSource au, float dura)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <TrySilence>d__9(0)
			{
				<>4__this = this,
				au = au,
				dura = dura
			};
		}
	}
	public class SilenceController : MonoBehaviour
	{
		private float silenceTimer = 0f;

		private bool isSilenced = false;

		private AudioSource? audioSource;

		private AudioMixerGroup? defaultGroup;

		private void Update()
		{
			if (isSilenced)
			{
				silenceTimer -= Time.deltaTime;
				if (silenceTimer <= 0f)
				{
					isSilenced = false;
					ReenableVoice();
				}
			}
		}

		public void ApplySilence(float duration, AudioSource source, AudioMixerGroup? muffled, AudioMixerGroup? defaultGrp)
		{
			silenceTimer = duration;
			audioSource = source;
			defaultGroup = defaultGrp;
			if ((Object)(object)audioSource != (Object)null && (Object)(object)muffled != (Object)null)
			{
				audioSource.outputAudioMixerGroup = muffled;
			}
			isSilenced = true;
			Debug.Log((object)"Silence applied: voice muffled and spellcasting disabled.");
		}

		private void ReenableVoice()
		{
			if ((Object)(object)audioSource != (Object)null && (Object)(object)defaultGroup != (Object)null)
			{
				audioSource.outputAudioMixerGroup = defaultGroup;
			}
			Debug.Log((object)"Silence expired: voice restored and spellcasting enabled.");
		}
	}
}