Decompiled source of Alones TooManyEmotes v1.0.0

plugins/Alones_TooManyEmotes/TooManyEmotesAdditionalEmotes.dll

Decompiled 4 hours 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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TooManyEmotes;
using UnityEngine;

[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("TooManyEmotesAdditionalEmotes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+04890f608120b2fb861ac2c4bc8454479c9448da")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("TooManyEmotesAdditionalEmotes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 TooManyEmotesAdditionalEmotes
{
	public class EmoteLoader
	{
		public static void LoadAssets()
		{
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.instance).Info.Location), "aloneemotes");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			LoadAnimationAssets(val);
			EmotesManager.BuildEmotesList();
			AnimationClip[] array = val.LoadAllAssets<AnimationClip>();
			AnimationClip[] array2 = array;
			foreach (AnimationClip val2 in array2)
			{
				AdditionalEmoteData.SetEmoteDoesNotUseBoombox(((Object)val2).name);
			}
			Plugin.Logger.LogInfo((object)"Loaded emotes!");
			Plugin.instance.StartAudioRetry(val);
		}

		private static void LoadAnimationAssets(AssetBundle assetBundle)
		{
			try
			{
				AnimationClip[] array = assetBundle.LoadAllAssets<AnimationClip>();
				Plugin.complementaryAnimationClips.AddRange(array);
				Plugin.customAnimationClipsHash.UnionWith(array);
				Plugin.customAnimationClips.AddRange(array);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Unable to load animations: {arg}");
			}
		}

		public static bool TryLoadAudio(AssetBundle assetBundle)
		{
			try
			{
				AudioClip[] array = assetBundle.LoadAllAssets<AudioClip>();
				Dictionary<string, AudioClip> dictionary = (Dictionary<string, AudioClip>)Traverse.CreateWithType("TooManyEmotes.Audio.AudioManager").Field("audioClipsDictDmca").GetValue();
				HashSet<AudioClip> hashSet = (HashSet<AudioClip>)Traverse.CreateWithType("TooManyEmotes.Audio.AudioManager").Field("loadedAudioClips").GetValue();
				HashSet<AudioClip> hashSet2 = (HashSet<AudioClip>)Traverse.CreateWithType("TooManyEmotes.Audio.AudioManager").Field("loadedAudioClipsDmca").GetValue();
				if (dictionary == null || hashSet == null || hashSet2 == null)
				{
					return false;
				}
				AudioClip[] array2 = array;
				foreach (AudioClip val in array2)
				{
					if (!dictionary.ContainsKey(((Object)val).name))
					{
						dictionary[((Object)val).name] = val;
					}
					if (!hashSet.Contains(val))
					{
						hashSet.Add(val);
					}
					if (!hashSet2.Contains(val))
					{
						hashSet2.Add(val);
					}
				}
				return true;
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogError((object)$"Audio retry failed: {arg}");
				return false;
			}
		}
	}
	[BepInPlugin("luvsya.aloneemotes", "alones emotes", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static Plugin instance;

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			instance = this;
			Harmony val = new Harmony("luvsya.aloneemotes");
			val.PatchAll();
			EmoteLoader.LoadAssets();
			Logger.LogInfo((object)"Plugin luvsya.aloneemotes is loaded!");
		}

		public void StartAudioRetry(AssetBundle bundle)
		{
			((MonoBehaviour)this).StartCoroutine(RetryAudioLoad(bundle));
		}

		private IEnumerator RetryAudioLoad(AssetBundle bundle)
		{
			int attempts = 0;
			while (attempts < 30)
			{
				yield return (object)new WaitForSeconds(1f);
				attempts++;
				if (EmoteLoader.TryLoadAudio(bundle))
				{
					Logger.LogInfo((object)"Audio loaded successfully!");
					yield break;
				}
			}
			Logger.LogError((object)"Failed to load audio after 30 attempts.");
		}
	}
	internal class PluginInfo
	{
		public const string PLUGIN_GUID = "luvsya.aloneemotes";

		public const string PLUGIN_NAME = "alones emotes";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "TooManyEmotesAdditionalEmotes";

		public const string PLUGIN_NAME = "My first plugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}