Decompiled source of SlipEmote v0.1.0

BepInEx/plugins/MoSadie-SlipEmote/com.mosadie.slipemote.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 Cysharp.Threading.Tasks;
using Microsoft.CodeAnalysis;
using MoCore;
using Subpixel;
using Subpixel.Events;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.mosadie.slipemote")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Add keybinds for your favorite emotes!")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+6fd36c0f0e0a8f79f96e2c22cb0f5fc298f1c375")]
[assembly: AssemblyProduct("SlipEmote")]
[assembly: AssemblyTitle("com.mosadie.slipemote")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 SlipEmote
{
	[BepInPlugin("com.mosadie.slipemote", "SlipEmote", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("Slipstream_Win.exe")]
	public class SlipEmote : BaseUnityPlugin, IMoPlugin
	{
		private static ConfigEntry<bool> debugLogs;

		internal static ManualLogSource Log;

		private static ConfigEntry<KeyboardShortcut> AssignEmoteKeybind;

		private static List<ConfigEntry<KeyboardShortcut>> EmoteKeybindList = new List<ConfigEntry<KeyboardShortcut>>();

		private static List<ConfigEntry<string>> EmoteKeybindAssignedEmoteList = new List<ConfigEntry<string>>();

		private static List<KeyCode> defaultKeys = new List<KeyCode>(10)
		{
			(KeyCode)49,
			(KeyCode)50,
			(KeyCode)51,
			(KeyCode)52,
			(KeyCode)53,
			(KeyCode)54,
			(KeyCode)55,
			(KeyCode)56,
			(KeyCode)57,
			(KeyCode)48
		};

		private bool isSetup;

		private EmoteCatalogEntry emoteToSave;

		public static readonly string COMPATIBLE_GAME_VERSION = "4.1595";

		public static readonly string GAME_VERSION_URL = "https://raw.githubusercontent.com/MoSadie/SlipEmote/refs/heads/main/versions.json";

		private void Awake()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Log = ((BaseUnityPlugin)this).Logger;
				if (!MoCore.RegisterPlugin((IMoPlugin)(object)this))
				{
					Log.LogError((object)"Failed to register plugin with MoCore. Please check the logs for more information.");
					return;
				}
				debugLogs = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugLogs", false, "Enable additional logging for debugging");
				AssignEmoteKeybind = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", "AssignEmoteKeybind", new KeyboardShortcut((KeyCode)282, Array.Empty<KeyCode>()), "Keybind to start/cancel the process of setting an emote to an emote key.");
				for (int i = 0; i < defaultKeys.Count; i++)
				{
					ConfigEntry<KeyboardShortcut> item = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keybinds", $"EmoteKeybind{i + 1}", new KeyboardShortcut(defaultKeys[i], Array.Empty<KeyCode>()), $"Keybind to trigger emote key {i + 1}");
					EmoteKeybindList.Add(item);
					ConfigEntry<string> item2 = ((BaseUnityPlugin)this).Config.Bind<string>("Emotes", $"Emote{i + 1}", "", $"The emote assigned to emote key {i + 1}. Leave empty for no emote.");
					EmoteKeybindAssignedEmoteList.Add(item2);
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.mosadie.slipemote is loaded!");
				isSetup = true;
			}
			catch (Exception ex)
			{
				Log.LogError((object)"An error occurred while starting the plugin.");
				Log.LogError((object)ex.Message);
			}
		}

		private void Update()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			if (!isSetup)
			{
				return;
			}
			try
			{
				KeyboardShortcut value = AssignEmoteKeybind.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					if (emoteToSave == null)
					{
						LocalCrewmate selectedLocalCrewmate = Mainstay<LocalCrewSelectionManager>.Main.GetSelectedLocalCrewmate();
						if ((Object)(object)selectedLocalCrewmate == (Object)null)
						{
							DebugLogWarn("Attempted to start emote assignment, but no local crewmate is found!");
							return;
						}
						if ((Object)(object)selectedLocalCrewmate.Crewmate == (Object)null || (Object)(object)selectedLocalCrewmate.Crewmate.EmoteController == (Object)null)
						{
							DebugLogWarn("Attempted to start emote assignment, but no crewmate or emote controller is found!");
							return;
						}
						CrewmateEmoteController emoteController = selectedLocalCrewmate.Crewmate.EmoteController;
						if (emoteController.LastEmoteUsed == null)
						{
							DebugLogWarn("Attempted to start emote assignment, but no last emote used is found! Please use an emote first, then press this key again!");
							RecieveOrder("Please use an emote first, then press this key again to start assigning it to an emote key!");
							return;
						}
						emoteToSave = emoteController.LastEmoteUsed;
						DebugLogInfo("Starting emote assignment process for emote: " + emoteToSave.Doc.Id);
						RecieveOrder("Ready to assign emote: " + emoteToSave.Doc.Data.Name + ". Press the desired emote key to assign it to, or press this key again to cancel.");
					}
					else
					{
						DebugLogInfo("Emote key assignment cancelled.");
						RecieveOrder("Emote key assignment cancelled.");
						emoteToSave = null;
					}
				}
				for (int i = 0; i < EmoteKeybindList.Count; i++)
				{
					value = EmoteKeybindList[i].Value;
					if (!((KeyboardShortcut)(ref value)).IsDown())
					{
						continue;
					}
					if (emoteToSave != null)
					{
						EmoteKeybindAssignedEmoteList[i].Value = emoteToSave.Doc.Id;
						((BaseUnityPlugin)this).Config.Save();
						DebugLogInfo($"Assigned emote {emoteToSave.Doc.Id} to emote key {i + 1}");
						RecieveOrder($"Assigned emote {emoteToSave.Doc.Data.Name} to emote key {i + 1}");
						emoteToSave = null;
					}
					string value2 = EmoteKeybindAssignedEmoteList[i].Value;
					if (!string.IsNullOrEmpty(value2))
					{
						DebugLogInfo($"Emote Keybind {i + 1} Pressed, triggering emote: {value2}");
						UserEmotesInventory val = Svc.Get<UserEmotesInventory>();
						if (val == null)
						{
							Log.LogError((object)"UserEmotesInventory service is null, cannot check owned emotes.");
							break;
						}
						if (!val.IsEmoteUnlocked(value2))
						{
							Log.LogError((object)("Attempted to trigger emote " + value2 + ", but the user does not own this emote."));
							RecieveOrder("Something went wrong triggering that emote. Please try assigning it again.");
							break;
						}
						LocalCrewmate selectedLocalCrewmate2 = Mainstay<LocalCrewSelectionManager>.Main.GetSelectedLocalCrewmate();
						if ((Object)(object)selectedLocalCrewmate2 == (Object)null)
						{
							Log.LogWarning((object)"Attempted to trigger emote, but no local crewmate is found!");
							break;
						}
						if ((Object)(object)selectedLocalCrewmate2.Crewmate == (Object)null || (Object)(object)selectedLocalCrewmate2.Crewmate.EmoteController == (Object)null)
						{
							Log.LogWarning((object)"Attempted to trigger emote, but no crewmate or emote controller is found!");
							break;
						}
						CrewmateEmoteController emoteController2 = selectedLocalCrewmate2.Crewmate.EmoteController;
						StaticData val2 = Svc.Get<StaticData>();
						if (val2 == null)
						{
							Log.LogError((object)"StaticData service is null, cannot retrieve emote data.");
							break;
						}
						EmotesCatalog emotes = val2.Emotes;
						if (emotes == null)
						{
							Log.LogError((object)"Emote catalog is null, cannot retrieve emote data.");
							break;
						}
						EmoteCatalogEntry entryByEmoteId = emotes.GetEntryByEmoteId(value2);
						UniTaskExtensions.Forget<bool>(emoteController2.Local_Emote(entryByEmoteId));
					}
					else
					{
						DebugLogInfo($"Emote Keybind {i + 1} Pressed, but no emote is assigned.");
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("An error occurred during the Update process. " + ex.Message));
				Log.LogError((object)ex.StackTrace);
			}
		}

		internal static void RecieveOrder(string msg)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			try
			{
				if ((Object)(object)Mainstay<LocalCrewSelectionManager>.Main.GetSelectedLocalCrewmate() == (Object)null)
				{
					DebugLogWarn("Attempted to send local order, but no local crewmate is found!");
					return;
				}
				OrderVo val = OrderHelpers.CreateLocal((OrderIssuer)2, (OrderType)0, msg);
				Svc.Get<Events>().Dispatch<OrderGivenEvent>(new OrderGivenEvent(val, (CustomizableArgs?)null));
			}
			catch (Exception ex)
			{
				Log.LogError((object)"An error occurred while trying to receive a local order.");
				Log.LogError((object)ex);
			}
		}

		internal static void DebugLogInfo(string message)
		{
			if (debugLogs.Value)
			{
				Log.LogInfo((object)message);
			}
		}

		internal static void DebugLogWarn(string message)
		{
			if (debugLogs.Value)
			{
				Log.LogWarning((object)message);
			}
		}

		internal static void DebugLogError(string message)
		{
			if (debugLogs.Value)
			{
				Log.LogError((object)message);
			}
		}

		internal static void DebugLogDebug(string message)
		{
			if (debugLogs.Value)
			{
				Log.LogDebug((object)message);
			}
		}

		public string GetCompatibleGameVersion()
		{
			return COMPATIBLE_GAME_VERSION;
		}

		public string GetVersionCheckUrl()
		{
			return GAME_VERSION_URL;
		}

		public BaseUnityPlugin GetPluginObject()
		{
			return (BaseUnityPlugin)(object)this;
		}

		public IMoHttpHandler GetHttpHandler()
		{
			return null;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.mosadie.slipemote";

		public const string PLUGIN_NAME = "SlipEmote";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}