Decompiled source of WhiteKnuckleEmotes v1.0.1

WhiteKnuckleEmotes.dll

Decompiled 5 months 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Networking;
using WKLib.API.Input;

[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("WhiteKnuckleEmotes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+a8290d6e708dd712902a7396d330f7dff2236325")]
[assembly: AssemblyProduct("WhiteKnuckleEmotes")]
[assembly: AssemblyTitle("WhiteKnuckleEmotes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 WhiteKnuckleEmotes
{
	public static class Patches
	{
		private class HandState
		{
			public int CurrentEmote = -1;

			public Vector3 EmoteOffset;
		}

		[Serializable]
		public class EmoteData
		{
			[Serializable]
			public class HandEmote
			{
				public string id;

				public string sound;
			}

			public string id;

			public List<HandEmote> emotes;
		}

		[HarmonyPatch(typeof(ENT_Player), "Awake")]
		private class Patch_ENT_Player_Awake
		{
			private static void Postfix(ENT_Player __instance)
			{
				_handStates = new HandState[__instance.hands.Length];
				for (int i = 0; i < _handStates.Length; i++)
				{
					_handStates[i] = new HandState();
				}
			}
		}

		[HarmonyPatch(typeof(CL_CosmeticManager), "CreateHandCosmetics")]
		private class Patch_CL_CosmeticManager_CreateHandCosmetics
		{
			[CompilerGenerated]
			private sealed class <LoadAudioClip>d__1 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public string path;

				public string cosmeticId;

				public string emoteId;

				private UnityWebRequest <uwr>5__1;

				private AudioClip <content>5__2;

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

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

				[DebuggerHidden]
				public <LoadAudioClip>d__1(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();
						}
					}
					<uwr>5__1 = null;
					<content>5__2 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0078: Unknown result type (might be due to invalid IL or missing references)
					//IL_007e: Invalid comparison between Unknown and I4
					bool result;
					try
					{
						switch (<>1__state)
						{
						default:
							result = false;
							break;
						case 0:
							<>1__state = -1;
							<uwr>5__1 = UnityWebRequestMultimedia.GetAudioClip("file://" + path, (AudioType)20);
							<>1__state = -3;
							<>2__current = <uwr>5__1.SendWebRequest();
							<>1__state = 1;
							result = true;
							break;
						case 1:
							<>1__state = -3;
							if ((int)<uwr>5__1.result != 1)
							{
								Plugin.Log.LogError((object)<uwr>5__1.error);
								result = false;
								<>m__Finally1();
								break;
							}
							<content>5__2 = DownloadHandlerAudioClip.GetContent(<uwr>5__1);
							((Object)<content>5__2).name = Path.GetFileNameWithoutExtension(path);
							Plugin.Log.LogInfo((object)("Loaded Clip: " + ((Object)<content>5__2).name));
							if (!_emoteSounds.ContainsKey(cosmeticId))
							{
								_emoteSounds.Add(cosmeticId, new Dictionary<string, AudioClip>());
							}
							if (!_emoteSounds[cosmeticId].ContainsKey(emoteId))
							{
								_emoteSounds[cosmeticId].Add(emoteId, <content>5__2);
							}
							<content>5__2 = null;
							<>m__Finally1();
							<uwr>5__1 = null;
							result = false;
							break;
						}
					}
					catch
					{
						//try-fault
						((IDisposable)this).Dispose();
						throw;
					}
					return result;
				}

				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 (<uwr>5__1 != null)
					{
						((IDisposable)<uwr>5__1).Dispose();
					}
				}

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

			private static void Postfix(CL_CosmeticManager __instance, string subdir, List<string> jsonList, Dictionary<string, Cosmetic_HandItem> ___cosmeticHandDict)
			{
				foreach (string json in jsonList)
				{
					string text = File.ReadAllText(json);
					EmoteData emoteData = JsonConvert.DeserializeObject<EmoteData>(text);
					if (!___cosmeticHandDict.TryGetValue(emoteData.id, out var value) || value.cosmeticData.emotes == null || value.cosmeticData.emotes.Count == 0)
					{
						continue;
					}
					List<ColorPalette> palettes = value.cosmeticData.palettes;
					bool flag = palettes != null && palettes.Count > 0;
					for (int i = 0; i < value.cosmeticData.emotes.Count; i++)
					{
						HandEmote val = value.cosmeticData.emotes[i];
						EmoteData.HandEmote handEmote = emoteData.emotes[i];
						if (!string.IsNullOrEmpty(val.spriteName))
						{
							Sprite val2 = RuntimeSpriteImporter.LoadSpriteFromFile(Path.Combine(subdir, "Sprites", val.spriteName + ".png"), 100f, (FilterMode)0, false, flag);
							((Object)val2).name = val.spriteName;
							val.sprite = val2;
							if (!string.IsNullOrEmpty(handEmote.sound))
							{
								((MonoBehaviour)Plugin.Instance).StartCoroutine(LoadAudioClip(Path.Combine(subdir, "Sounds", handEmote.sound + ".wav"), emoteData.id, handEmote.id));
							}
						}
					}
				}
			}

			[IteratorStateMachine(typeof(<LoadAudioClip>d__1))]
			private static IEnumerator LoadAudioClip(string path, string cosmeticId, string emoteId)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <LoadAudioClip>d__1(0)
				{
					path = path,
					cosmeticId = cosmeticId,
					emoteId = emoteId
				};
			}
		}

		[HarmonyPatch(typeof(ENT_Player), "HandAnimation")]
		private class Patch_ENT_Player_HandAnimation
		{
			private static void Postfix(ENT_Player __instance, Hand curhand, bool interacting, bool canInteract)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_0122: Unknown result type (might be due to invalid IL or missing references)
				//IL_0128: Invalid comparison between Unknown and I4
				//IL_013d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0181: Unknown result type (might be due to invalid IL or missing references)
				//IL_0191: Unknown result type (might be due to invalid IL or missing references)
				//IL_0196: Unknown result type (might be due to invalid IL or missing references)
				//IL_019b: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0309: Unknown result type (might be due to invalid IL or missing references)
				//IL_030e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0278: Unknown result type (might be due to invalid IL or missing references)
				//IL_027d: Unknown result type (might be due to invalid IL or missing references)
				if (interacting || !canInteract || !curhand.IsFree())
				{
					if (_handStates[curhand.id].CurrentEmote != -1)
					{
						if (_handStates[curhand.id].EmoteOffset == curhand.GetViewSway().targetOffset)
						{
							curhand.GetViewSway().targetOffset = Vector3.zero;
						}
						_handStates[curhand.id].CurrentEmote = -1;
					}
				}
				else
				{
					if (curhand.currentCosmetics == null || curhand.currentCosmetics.Count == 0)
					{
						return;
					}
					List<ConfigEntry<KeyCode>> list = ((curhand.id == 0) ? Plugin.EmoteKeysLeft : Plugin.EmoteKeysRight);
					foreach (Cosmetic_HandItem currentCosmetic in curhand.currentCosmetics)
					{
						if (currentCosmetic.cosmeticData.emotes == null || currentCosmetic.cosmeticData.emotes.Count == 0)
						{
							continue;
						}
						bool flag = false;
						for (int i = 0; i < Mathf.Min(currentCosmetic.cosmeticData.emotes.Count, 10); i++)
						{
							if ((int)list[i].Value == 0 || !InputUtility.GetKeyDown(list[i].Value))
							{
								continue;
							}
							HandEmote val = currentCosmetic.cosmeticData.emotes[i];
							curhand.SetSprite(val.sprite, (Sprite)null);
							curhand.GetViewSway().targetOffset = Vector3.Scale(val.position, ((Component)curhand.handSprite).transform.localScale);
							if (_handStates[curhand.id].CurrentEmote == -1 && _emoteSounds.ContainsKey(currentCosmetic.cosmeticData.id) && _emoteSounds[currentCosmetic.cosmeticData.id].ContainsKey(val.id))
							{
								AudioClip val2 = _emoteSounds[currentCosmetic.cosmeticData.id][val.id];
								if (Object.op_Implicit((Object)(object)val2))
								{
									AudioManager.PlaySound(val2, curhand.handModel, 1f, 1f, 1f, false, 1f, (AudioMixerGroup)null, "");
								}
							}
							_handStates[curhand.id].CurrentEmote = i;
							_handStates[curhand.id].EmoteOffset = curhand.GetViewSway().targetOffset;
							flag = true;
							break;
						}
						if (!flag && _handStates[curhand.id].CurrentEmote != -1)
						{
							if (_handStates[curhand.id].EmoteOffset == curhand.GetViewSway().targetOffset)
							{
								curhand.GetViewSway().targetOffset = Vector3.zero;
							}
							_handStates[curhand.id].CurrentEmote = -1;
						}
					}
				}
			}
		}

		private static HandState[] _handStates;

		private static Dictionary<string, Dictionary<string, AudioClip>> _emoteSounds = new Dictionary<string, Dictionary<string, AudioClip>>();
	}
	[BepInPlugin("WhiteKnuckleEmotes", "WhiteKnuckleEmotes", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static readonly List<ConfigEntry<KeyCode>> EmoteKeysLeft = new List<ConfigEntry<KeyCode>>();

		public static readonly List<ConfigEntry<KeyCode>> EmoteKeysRight = new List<ConfigEntry<KeyCode>>();

		public const int MaxEmotes = 10;

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			for (int i = 0; i < 10; i++)
			{
				EmoteKeysLeft.Add(((BaseUnityPlugin)this).Config.Bind<KeyCode>("General.KeyBinds", "EmoteKeyLeft" + i, (KeyCode)0, (ConfigDescription)null));
				EmoteKeysRight.Add(((BaseUnityPlugin)this).Config.Bind<KeyCode>("General.KeyBinds", "EmoteKeyRight" + i, (KeyCode)0, (ConfigDescription)null));
			}
			Harmony val = new Harmony("WhiteKnuckleEmotes.patch");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin WhiteKnuckleEmotes is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "WhiteKnuckleEmotes";

		public const string PLUGIN_NAME = "WhiteKnuckleEmotes";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}