Decompiled source of Miku Emotes v1.1.0

CustomEmotesAPITemplateMod.dll

Decompiled 16 hours ago
using System;
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 System.Security;
using System.Security.Permissions;
using BepInEx;
using CustomEmotesAPI_Template_Mod;
using EmotesAPI;
using LethalEmotesAPI.ImportV2;
using Lethal_Company_CustomEmotesAPI_Template_Mod;
using Microsoft.CodeAnalysis;
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("Lethal Company CustomEmotesAPI Template Mod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Lethal Company CustomEmotesAPI Template Mod")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("199912ba-43b6-4276-b420-7bfaa3eedbe5")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[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 Lethal_Company_CustomEmotesAPI_Template_Mod
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.Cayden.mods.MikuEmotes", "MikuEmotes", "1.0.0")]
	public class MikuEmoteMod : BaseUnityPlugin
	{
		public const string PluginGUID = "com.Cayden.mods.MikuEmotes";

		public const string PluginName = "MikuEmotes";

		public const string PluginVersion = "1.0.0";

		public static MikuEmoteMod instance;

		public static PluginInfo PInfo { get; private set; }

		public void Awake()
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			instance = this;
			PInfo = ((BaseUnityPlugin)this).Info;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			Assets.LoadAssetBundlesFromFolder(directoryName);
			ImportAnimation((AnimationClip[])(object)new AnimationClip[1] { Assets.Load<AnimationClip>("Miku Live/LiveStart.anim") }, (AnimationClip[])(object)new AnimationClip[1] { Assets.Load<AnimationClip>("Miku Live/LiveLoop.anim") }, looping: true, (AudioClip[])(object)new AudioClip[1] { Assets.Load<AudioClip>("Miku Live/LiveMusic.wav") }, sync: true, "Miku Live", dmca: true, cantMove: false, thirdPerson: true);
			ImportAnimation((AnimationClip[])(object)new AnimationClip[1] { Assets.Load<AnimationClip>("Miku Miku Beam/BeamStart.anim") }, (AnimationClip[])(object)new AnimationClip[1] { Assets.Load<AnimationClip>("Miku Miku Beam/BeamLoop.anim") }, looping: true, (AudioClip[])(object)new AudioClip[1] { Assets.Load<AudioClip>("Miku Miku Beam/BeamMusic.wav") }, sync: true, "Miku Beam", dmca: true, cantMove: false, thirdPerson: true);
			AnimationClip val = Assets.Load<AnimationClip>("Miku Live/LiveStart.anim");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"Failed to load LiveStart.anim");
			}
			CustomEmotesAPI.animChanged += new AnimationChanged(CustomEmotesAPI_animChanged);
		}

		private void CustomEmotesAPI_animChanged(string newAnimation, BoneMapper mapper)
		{
			if (newAnimation.StartsWith("com.Cayden.mods.MikuEmotes"))
			{
				newAnimation = newAnimation.Split("__")[1];
			}
		}

		public void ImportAnimation(AnimationClip[] primaryClips, AnimationClip[] secondaryClips, bool looping, AudioClip[] primaryAudioClips, bool sync, string customName, bool dmca, bool cantMove, bool thirdPerson)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			CustomEmoteParams val = new CustomEmoteParams();
			val.primaryAnimationClips = primaryClips;
			val.secondaryAnimationClips = secondaryClips;
			val.audioLoops = looping;
			val.primaryAudioClips = primaryAudioClips;
			val.secondaryAudioClips = null;
			val.primaryDMCAFreeAudioClips = null;
			val.secondaryDMCAFreeAudioClips = null;
			val.visible = true;
			val.syncAnim = sync;
			val.syncAudio = sync;
			val.startPref = -1;
			val.joinPref = -1;
			val.joinSpots = null;
			val.internalName = "";
			val.lockType = (LockType)1;
			val.willGetClaimedByDMCA = dmca;
			val.audioLevel = 0.3f;
			val.rootBonesToIgnore = null;
			val.soloBonesToIgnore = null;
			val.stopWhenMove = cantMove;
			val.thirdPerson = thirdPerson;
			val.displayName = customName;
			EmoteImporter.ImportEmote(val);
		}
	}
}
namespace CustomEmotesAPI_Template_Mod
{
	internal static class Assets
	{
		internal static readonly List<AssetBundle> AssetBundles = new List<AssetBundle>();

		private static readonly Dictionary<string, int> AssetIndices = new Dictionary<string, int>();

		internal static void LoadAssetBundlesFromFolder(string folderName)
		{
			if (MikuEmoteMod.PInfo == null)
			{
				DebugClass.Log((object)"Error: PInfo is null. Ensure MikuEmoteMod is initialized properly.");
				return;
			}
			string directoryName = Path.GetDirectoryName(MikuEmoteMod.PInfo.Location);
			if (string.IsNullOrEmpty(directoryName))
			{
				DebugClass.Log((object)"Error: Could not determine mod directory.");
				return;
			}
			folderName = Path.Combine(directoryName, folderName);
			if (!Directory.Exists(folderName))
			{
				DebugClass.Log((object)("Error: Folder '" + folderName + "' does not exist."));
				return;
			}
			string[] files = Directory.GetFiles(folderName);
			foreach (string text in files)
			{
				AssetBundle val = AssetBundle.LoadFromFile(text);
				if ((Object)(object)val == (Object)null)
				{
					DebugClass.Log((object)("Warning: Failed to load asset bundle from " + text));
					continue;
				}
				int count = AssetBundles.Count;
				AssetBundles.Add(val);
				string[] allAssetNames = val.GetAllAssetNames();
				foreach (string text2 in allAssetNames)
				{
					string text3 = text2.ToLowerInvariant();
					if (text3.StartsWith("assets/"))
					{
						text3 = text3.Substring("assets/".Length);
					}
					AssetIndices[text3] = count;
				}
				DebugClass.Log((object)("Loaded AssetBundle: " + Path.GetFileName(text)));
			}
		}

		internal static T Load<T>(string assetName) where T : Object
		{
			try
			{
				if (string.IsNullOrEmpty(assetName))
				{
					DebugClass.Log((object)"Error: Asset name is null or empty.");
					return default(T);
				}
				assetName = assetName.ToLowerInvariant();
				if (assetName.Contains(":"))
				{
					string[] array = assetName.Split(':');
					if (array.Length < 2)
					{
						DebugClass.Log((object)("Error: Invalid asset format " + assetName));
						return default(T);
					}
					assetName = array[1].ToLowerInvariant();
				}
				if (assetName.StartsWith("assets/"))
				{
					assetName = assetName.Substring("assets/".Length);
				}
				if (!AssetIndices.ContainsKey(assetName))
				{
					DebugClass.Log((object)("Error: Asset '" + assetName + "' not found in loaded bundles."));
					return default(T);
				}
				int num = AssetIndices[assetName];
				if (num < 0 || num >= AssetBundles.Count)
				{
					DebugClass.Log((object)$"Error: Invalid asset index {num} for '{assetName}'.");
					return default(T);
				}
				return AssetBundles[num].LoadAsset<T>("assets/" + assetName);
			}
			catch (Exception arg)
			{
				DebugClass.Log((object)$"Couldn't load asset [{assetName}] reason: {arg}");
				return default(T);
			}
		}
	}
}