Decompiled source of Hungarian BingBong v1.0.3

com.github.IceWloxy.HungarianBingBong.dll

Decompiled 2 weeks 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.IceWloxy.HungarianBingBong")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("com.github.IceWloxy.HungarianBingBong")]
[assembly: AssemblyTitle("Hungarian BingBong")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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.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;
		}
	}
	[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;
		}
	}
}
[BepInPlugin("com.ice.peak.bingbong", "Bing Bong Mod", "1.0.3")]
public class Plugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <LoadAllAudio>d__2 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public Plugin <>4__this;

		private string <modFolder>5__1;

		private string[] <allFiles>5__2;

		private string[] <>s__3;

		private int <>s__4;

		private string <fullPath>5__5;

		private string <fileName>5__6;

		private string <extension>5__7;

		private string <uri>5__8;

		private UnityWebRequest <www>5__9;

		private AudioClip <clip>5__10;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || num == 1)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<modFolder>5__1 = null;
			<allFiles>5__2 = null;
			<>s__3 = null;
			<fullPath>5__5 = null;
			<fileName>5__6 = null;
			<extension>5__7 = null;
			<uri>5__8 = null;
			<www>5__9 = null;
			<clip>5__10 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Invalid comparison between Unknown and I4
			try
			{
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -3;
					if ((int)<www>5__9.result == 1)
					{
						<clip>5__10 = DownloadHandlerAudioClip.GetContent(<www>5__9);
						((Object)<clip>5__10).name = <fileName>5__6;
						CustomClips.Add(<clip>5__10);
						((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)("Sikeresen betöltve: " + <fileName>5__6));
						<clip>5__10 = null;
					}
					else
					{
						((BaseUnityPlugin)<>4__this).Logger.LogError((object)("Hiba a " + <fileName>5__6 + " betöltésekor: " + <www>5__9.error));
					}
					<>m__Finally1();
					<www>5__9 = null;
					<fileName>5__6 = null;
					<extension>5__7 = null;
					<uri>5__8 = null;
					<fullPath>5__5 = null;
					goto IL_0212;
				}
				<>1__state = -1;
				<modFolder>5__1 = Path.GetDirectoryName(((BaseUnityPlugin)<>4__this).Info.Location);
				<allFiles>5__2 = Directory.GetFiles(<modFolder>5__1);
				<>s__3 = <allFiles>5__2;
				<>s__4 = 0;
				goto IL_0220;
				IL_0220:
				if (<>s__4 < <>s__3.Length)
				{
					<fullPath>5__5 = <>s__3[<>s__4];
					<fileName>5__6 = Path.GetFileName(<fullPath>5__5);
					<extension>5__7 = Path.GetExtension(<fullPath>5__5).ToLower();
					if (<extension>5__7 != ".wav")
					{
						((BaseUnityPlugin)<>4__this).Logger.LogWarning((object)("Nem támogatott formátum kihagyva: " + <fileName>5__6 + " (Csak .wav használható)"));
						goto IL_0212;
					}
					<uri>5__8 = "file://" + <fullPath>5__5;
					<www>5__9 = UnityWebRequestMultimedia.GetAudioClip(<uri>5__8, (AudioType)20);
					<>1__state = -3;
					<>2__current = <www>5__9.SendWebRequest();
					<>1__state = 1;
					return true;
				}
				<>s__3 = null;
				((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)$"Betöltés kész! Összesen {CustomClips.Count} hang lett hozzáadva.");
				return false;
				IL_0212:
				<>s__4++;
				goto IL_0220;
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

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

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<www>5__9 != null)
			{
				((IDisposable)<www>5__9).Dispose();
			}
		}

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

	public static List<AudioClip> CustomClips = new List<AudioClip>();

	private void Awake()
	{
		//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.yourname.peak.bingbong");
		val.PatchAll();
		((MonoBehaviour)this).StartCoroutine(LoadAllAudio());
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Bing Bong Dinamikus Audio Mod betöltve!");
	}

	[IteratorStateMachine(typeof(<LoadAllAudio>d__2))]
	private IEnumerator LoadAllAudio()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <LoadAllAudio>d__2(0)
		{
			<>4__this = this
		};
	}
}
[HarmonyPatch(typeof(AudioSource), "PlayOneShot", new Type[]
{
	typeof(AudioClip),
	typeof(float)
})]
internal class AudioPatch
{
	private static readonly RollingMemory<int> rollingMemory = new RollingMemory<int>(5);

	private static AudioClip getRandomClip()
	{
		int num = Random.Range(0, Plugin.CustomClips.Count);
		while (rollingMemory.Contains(num))
		{
			num = Random.Range(0, Plugin.CustomClips.Count);
		}
		rollingMemory.Push(num);
		return Plugin.CustomClips[num];
	}

	private static void Prefix(ref AudioClip clip, AudioSource __instance)
	{
		string name = ((Object)((Component)__instance).gameObject).name;
		if ((name.Contains("BingBong") || name.Contains("Prop")) && Plugin.CustomClips.Count > 0)
		{
			clip = getRandomClip();
			Debug.Log((object)("--- MOD: BingBong hang lecserélve erre: " + ((Object)clip).name + " ---"));
		}
	}
}
public class RollingMemory<T>
{
	private readonly T[] _buffer;

	private readonly int _maxSize;

	private int _currentIndex = 0;

	private int _currentCount = 0;

	public RollingMemory(int itemCount)
	{
		if (itemCount <= 0)
		{
			throw new ArgumentException("A méretnek nagyobbnak kell lennie nullánál.");
		}
		_maxSize = itemCount;
		_buffer = new T[itemCount];
	}

	public void Push(T item)
	{
		_buffer[_currentIndex] = item;
		_currentIndex = (_currentIndex + 1) % _maxSize;
		if (_currentCount < _maxSize)
		{
			_currentCount++;
		}
	}

	public bool Contains(T item)
	{
		if (item == null)
		{
			return false;
		}
		for (int i = 0; i < _currentCount; i++)
		{
			if (EqualityComparer<T>.Default.Equals(_buffer[i], item))
			{
				return true;
			}
		}
		return false;
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}