Decompiled source of PEAKEmoteLib v1.0.0

plugins/com.github.WaporVave.PEAKEmoteLib.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 PEAKLib.UI;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("WaporVave")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("An API for custom emotes in the game PEAK")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+355c66bb54138e4090ad8c6e61e89c395a0b290f")]
[assembly: AssemblyProduct("com.github.WaporVave.PEAKEmoteLib")]
[assembly: AssemblyTitle("PEAKEmoteLib")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/WaporVave/PEAKEmoteLib")]
[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.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;
		}
	}
}
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 PEAKEmoteLib
{
	internal static class CharacterAnimationsExtensions
	{
		private class Holder
		{
			public AnimatorOverrideController AnimatorOverrideController = new AnimatorOverrideController();

			public bool Emoting;

			public Emote? CurrentEmote;
		}

		private static readonly ConditionalWeakTable<CharacterAnimations, Holder> data = new ConditionalWeakTable<CharacterAnimations, Holder>();

		public static AnimatorOverrideController GetAnimatorOverrideController(this CharacterAnimations characterAnimations)
		{
			return data.GetOrCreateValue(characterAnimations).AnimatorOverrideController;
		}

		public static void SetAnimatorOverrideController(this CharacterAnimations characterAnimations, AnimatorOverrideController overrideController)
		{
			data.GetOrCreateValue(characterAnimations).AnimatorOverrideController = overrideController;
		}

		public static bool GetEmoting(this CharacterAnimations characterAnimations)
		{
			return data.GetOrCreateValue(characterAnimations).Emoting;
		}

		public static void SetEmoting(this CharacterAnimations characterAnimations, bool emoting)
		{
			data.GetOrCreateValue(characterAnimations).Emoting = emoting;
		}

		public static Emote? GetCurrentEmote(this CharacterAnimations characterAnimations)
		{
			return data.GetOrCreateValue(characterAnimations).CurrentEmote;
		}

		public static void SetCurrentEmote(this CharacterAnimations characterAnimations, Emote? emote)
		{
			data.GetOrCreateValue(characterAnimations).CurrentEmote = emote;
		}
	}
	public class Emote
	{
		public enum EmoteType
		{
			Vanilla,
			OneShot
		}

		public const string CustomEmotePrefix = "PEAKEmoteLib_";

		public static Sprite PlaceholderSprite;

		private TranslationKey translationKey;

		public AnimationClip AnimationClip { get; private set; }

		public EmoteType Type { get; private set; }

		public bool DisableIK { get; private set; }

		public string Name { get; private set; }

		public Sprite Icon { get; private set; }

		static Emote()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, new Color(0f, 0f, 0f, 0f));
			val.Apply();
			Sprite placeholderSprite = Sprite.Create(val, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f));
			PlaceholderSprite = placeholderSprite;
		}

		public Emote(string name, AnimationClip animationClip, Sprite? icon = null, EmoteType type = EmoteType.Vanilla, bool disableIK = false)
		{
			Name = "PEAKEmoteLib_" + name;
			AnimationClip = animationClip;
			Type = type;
			DisableIK = disableIK;
			Icon = (Sprite)(((Object)(object)icon == (Object)null) ? ((object)PlaceholderSprite) : ((object)icon));
			translationKey = MenuAPI.CreateLocalization(Name);
		}

		public Emote(string name, AnimationClip animationClip, Texture2D iconTexture, EmoteType type = EmoteType.Vanilla, bool disableIK = false)
			: this(name, animationClip, Sprite.Create(iconTexture, new Rect(0f, 0f, (float)((Texture)iconTexture).width, (float)((Texture)iconTexture).height), new Vector2(0.5f, 0.5f)), type, disableIK)
		{
		}//IL_001c: 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)


		public void AddLocalization(string text, Language language)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			translationKey.AddLocalization(text, language);
		}
	}
	internal static class EmoteRegistry
	{
		private static Dictionary<string, Emote> _emotes = new Dictionary<string, Emote>();

		public static Emote RegisterEmote(string name, AnimationClip clip, Sprite? icon = null, Emote.EmoteType type = Emote.EmoteType.Vanilla, bool disableIK = false)
		{
			return RegisterEmote(new Emote(name, clip, icon, type, disableIK));
		}

		public static Emote RegisterEmote(string name, AnimationClip clip, Texture2D iconTexture, Emote.EmoteType type = Emote.EmoteType.Vanilla, bool disableIK = false)
		{
			return RegisterEmote(new Emote(name, clip, iconTexture, type, disableIK));
		}

		public static Emote RegisterEmote(Emote emote)
		{
			if (_emotes.ContainsKey(emote.Name))
			{
				Plugin.Log.LogWarning((object)("Ignoring duplicate emote '" + emote.Name + "'. Custom emote names must be globally unique."));
				return emote;
			}
			_emotes.Add(emote.Name, emote);
			Plugin.Log.LogInfo((object)("Registered new emote: '" + emote.Name + "'"));
			return emote;
		}

		public static IEnumerable<Emote> RegisterEmotes(IEnumerable<Emote> emotes)
		{
			foreach (Emote emote in emotes)
			{
				RegisterEmote(emote);
			}
			return emotes;
		}

		public static IReadOnlyDictionary<string, Emote> GetEmotes()
		{
			return _emotes;
		}
	}
	[HarmonyPatch(typeof(CharacterAnimations), "RPCA_PlayRemove")]
	public static class CharacterAnimationsRPCA_PlayRemovePatch
	{
		public const string OverrideState = "A_Scout_Emote_Dance2";

		private static AnimationClip? OriginalOverridenClip;

		[HarmonyPrefix]
		public static void Prefix(CharacterAnimations __instance, ref string emoteName)
		{
			AnimatorOverrideController animatorOverrideController = __instance.GetAnimatorOverrideController();
			if ((Object)(object)OriginalOverridenClip == (Object)null)
			{
				OriginalOverridenClip = animatorOverrideController["A_Scout_Emote_Dance2"];
			}
			if (emoteName.StartsWith("PEAKEmoteLib_"))
			{
				Plugin.Log.LogDebug((object)("Attempting to play custom emote " + emoteName));
				Emote emote = EmoteRegistry.GetEmotes()[emoteName];
				__instance.SetCurrentEmote(emote);
				if (emote.DisableIK)
				{
					__instance.character.data.overrideIKForSeconds = emote.AnimationClip.length;
				}
				animatorOverrideController["A_Scout_Emote_Dance2"] = emote.AnimationClip;
				emoteName = "A_Scout_Emote_Dance2";
			}
			else if (emoteName == "A_Scout_Emote_Dance2" && (Object)(object)OriginalOverridenClip != (Object)null)
			{
				animatorOverrideController["A_Scout_Emote_Dance2"] = OriginalOverridenClip;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterAnimations), "UpdateHeadBob")]
	public static class CharacterAnimationsUpdateHeadBobPatch
	{
		[HarmonyPostfix]
		public static void Postfix(CharacterAnimations __instance)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			Plugin.Log.LogDebug((object)"Applying AnimatorOverrideController to character Animator");
			AnimatorOverrideController val = new AnimatorOverrideController(__instance.character.refs.animator.runtimeAnimatorController);
			__instance.SetAnimatorOverrideController(val);
			__instance.character.refs.animator.runtimeAnimatorController = (RuntimeAnimatorController)(object)val;
		}
	}
	[HarmonyPatch(typeof(CharacterAnimations), "Update")]
	public static class CharacterAnimationsUpdatePatch
	{
		public const float MaxEmoteTime = 10f;

		[HarmonyPrefix]
		public static void Prefix(CharacterAnimations __instance)
		{
			__instance.SetEmoting(__instance.emoting);
		}

		[HarmonyPostfix]
		public static void Postfix(CharacterAnimations __instance)
		{
			Emote currentEmote = __instance.GetCurrentEmote();
			if (currentEmote != null && currentEmote.Type == Emote.EmoteType.OneShot)
			{
				if (__instance.GetEmoting() && (__instance.sinceEmoteStart > currentEmote.AnimationClip.length || (__instance.sinceEmoteStart > 0.7f && (((Vector2)(ref __instance.character.input.movementInput)).magnitude > 0.1f || __instance.character.input.jumpWasPressed || __instance.character.data.sinceGrounded > 0.2f))))
				{
					Plugin.Log.LogDebug((object)"Stopping emote");
					__instance.character.refs.animator.SetBool("Emote", false);
					__instance.emoting = false;
					__instance.SetCurrentEmote(null);
					__instance.character.data.overrideIKForSeconds = 0f;
				}
				else if (__instance.GetEmoting())
				{
					__instance.character.refs.animator.SetBool("Emote", true);
					__instance.emoting = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(EmoteWheel), "Start")]
	public static class EmoteWheelStartPatch
	{
		public const int SlicesPerPage = 8;

		[HarmonyPostfix]
		public static void Postfix(EmoteWheel __instance)
		{
			int pages = __instance.pages;
			Emote[] array = EmoteRegistry.GetEmotes().Values.ToArray();
			int num = (array.Length + 8 - 1) / 8;
			Plugin.Log.LogDebug((object)$"Discovered {pages} vanilla emote pages, {num} custom emote pages");
			__instance.pages = pages + num;
			Plugin.Log.LogDebug((object)$"Emote wheel page count overridden to {__instance.pages}");
			Array.Resize(ref __instance.data, __instance.pages * 8);
			Plugin.Log.LogDebug((object)$"Resized emote wheel data array to size {__instance.pages * 8}");
			for (int i = pages * 8; i < __instance.data.Length; i++)
			{
				if (i >= array.Length + pages * 8)
				{
					__instance.data[i] = null;
					continue;
				}
				Emote emote = array[i - pages * 8];
				EmoteWheelData val = ScriptableObject.CreateInstance<EmoteWheelData>();
				val.emoteName = emote.Name;
				val.anim = emote.Name;
				val.emoteSprite = emote.Icon;
				__instance.data[i] = val;
			}
		}
	}
	[HarmonyPatch(typeof(GUIManager), "UpdateEmoteWheel")]
	public static class GUIManagerUpdateEmoteWheelPatch
	{
		[HarmonyPostfix]
		public static void Postfix(GUIManager __instance)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.emoteWheel.activeSelf)
			{
				return;
			}
			Vector2 mouseScrollDelta = Input.mouseScrollDelta;
			if (((Vector2)(ref mouseScrollDelta))[1] < 0f)
			{
				EmoteWheel component = __instance.emoteWheel.GetComponent<EmoteWheel>();
				component.TabNext();
				return;
			}
			mouseScrollDelta = Input.mouseScrollDelta;
			if (((Vector2)(ref mouseScrollDelta))[1] > 0f)
			{
				EmoteWheel component2 = __instance.emoteWheel.GetComponent<EmoteWheel>();
				component2.TabPrev();
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.github.WaporVave.PEAKEmoteLib", "PEAKEmoteLib", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony = new Harmony("PEAKEmoteLib");

		public const string Id = "com.github.WaporVave.PEAKEmoteLib";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "PEAKEmoteLib";

		public static string Version => "1.0.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony.PatchAll();
			if (LocalizedText.mainTable != null)
			{
				Log.LogInfo((object)"Touching LocalizedText.mainTable to ensure it's initialized");
			}
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
			Log.LogInfo((object)("Plugin " + Name + " unloaded."));
		}
	}
	public static class BaseUnityPluginExtensions
	{
		public static Emote RegisterEmote(this BaseUnityPlugin plugin, Emote emote)
		{
			return EmoteRegistry.RegisterEmote(emote);
		}

		public static Emote RegisterEmote(this BaseUnityPlugin plugin, string name, AnimationClip clip)
		{
			return EmoteRegistry.RegisterEmote(name, clip);
		}

		public static Emote RegisterEmote(this BaseUnityPlugin plugin, string name, AnimationClip clip, Sprite? icon = null, Emote.EmoteType type = Emote.EmoteType.Vanilla, bool disableIK = false)
		{
			return EmoteRegistry.RegisterEmote(name, clip, icon, type, disableIK);
		}

		public static Emote RegisterEmote(this BaseUnityPlugin plugin, string name, AnimationClip clip, Texture2D iconTexture, Emote.EmoteType type = Emote.EmoteType.Vanilla, bool disableIK = false)
		{
			return EmoteRegistry.RegisterEmote(name, clip, iconTexture, type, disableIK);
		}

		public static IEnumerable<Emote> RegisterEmotes(this BaseUnityPlugin plugin, IEnumerable<Emote> emotes)
		{
			return EmoteRegistry.RegisterEmotes(emotes);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}