Decompiled source of AnimatedName v1.0.0

Mods/AnimatedName.dll

Decompiled 20 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AnimatedName;
using AnimatedName.Utilities;
using BoneLib;
using BoneLib.BoneMenu;
using LabFusion.Player;
using LabFusion.Preferences.Client;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Animated Name", "1.0.0", "Camobiwon", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonAdditionalDependencies(new string[] { "LabFusion" })]
[assembly: MelonColor(255, 0, 255, 255)]
[assembly: MelonAuthorColor(255, 0, 100, 255)]
[assembly: RequiresPreviewFeatures]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AnimatedName")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AnimatedName")]
[assembly: AssemblyTitle("AnimatedName")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 AnimatedName
{
	public static class BuildInfo
	{
		public const string Name = "Animated Name";

		public const string Author = "Camobiwon";

		public const string Version = "1.0.0";

		public const string Company = "Camobiwon";

		public const string DownloadLink = null;
	}
	public class Core : MelonMod
	{
		internal static Core Instance;

		internal static MelonPreferences_Category PrefsCategory { get; private set; }

		public static Page RootPage { get; private set; }

		public static event Action Update;

		private Core()
		{
			Instance = this;
		}

		public override void OnInitializeMelon()
		{
			PrefsCategory = MelonPreferences.CreateCategory("Animated Name");
			Mod.Initialize();
			SavePrefences();
		}

		public override void OnUpdate()
		{
			Extensions.InvokeActionSafe(Core.Update);
		}

		internal static void SavePrefences()
		{
			PrefsCategory.SaveToFile(false);
		}

		public static void Log(object message)
		{
			((MelonBase)Instance).LoggerInstance.Msg(message?.ToString() ?? "null");
		}

		public static void Log(object message, ConsoleColor color)
		{
			((MelonBase)Instance).LoggerInstance.Msg(color, message?.ToString() ?? "null");
		}

		public static void Warn(object message)
		{
			((MelonBase)Instance).LoggerInstance.Warning(message?.ToString() ?? "null");
		}

		public static void Error(object message)
		{
			((MelonBase)Instance).LoggerInstance.Error(message?.ToString() ?? "null");
		}

		[Conditional("DEBUG")]
		internal static void DebugLog(object message)
		{
			Log(message);
		}

		[Conditional("DEBUG")]
		internal static void DebugWarn(object message)
		{
			Warn(message);
		}

		[Conditional("DEBUG")]
		internal static void DebugError(object message)
		{
			Error(message);
		}
	}
	public class Mod
	{
		public static MelonPreferences_Entry<bool> animationEnabled;

		public static MelonPreferences_Entry<float> animationTimer;

		public static MelonPreferences_Entry<string[]> animationElements;

		private static int animationIndex;

		private static float timer;

		private static Element previewElement;

		private static Element[] menuNameElements;

		public static Page Page { get; set; }

		public static void Initialize()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			Core.Update += Update;
			Page = Page.Root.CreatePage("Animated Name", Color.cyan, 0, true);
			animationElements = Core.PrefsCategory.CreateEntry<string[]>("Animated Name Elements", new string[3] { "Your", "Name", "Here" }, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			SetElements(animationElements.Value.Length);
		}

		private static void BuildMenu()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			previewElement = (Element)(object)Page.CreateFunction("Preview\n" + ClientSettings.Nickname.Value, Color.white, (Action)null);
			Page.CreateBoolPref("Animate", Color.white, ref animationEnabled, delegate(bool x)
			{
				if (x)
				{
					timer = 0f;
					animationIndex = 0;
					SetNametag(animationElements.Value[animationIndex]);
				}
				else
				{
					SetNametag(ClientSettings.Nickname.Value);
				}
			}, "Animated Name Enabled");
			Page.CreateFloatPref("Timer (s)", Color.white, ref animationTimer, 0.025f, 0.1f, 5f, null, "Animated Name Timer", 0.2f);
			Page.CreateFunction("Paste (CB)", Color.white, (Action)delegate
			{
				Menu.DisplayDialog("Paste Elements", "This will overwrite all existing elements and paste from the clipboard separated by new lines. Continue?", (Texture2D)null, (Action)delegate
				{
					if (Clipboard.ContainsText())
					{
						string[] array = Clipboard.GetText().Split(new string[3] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
						SetElements(array.Length);
						for (int j = 0; j < array.Length; j++)
						{
							SetElement(j, array[j]);
						}
						Core.SavePrefences();
					}
				}, (Action)null);
			});
			Page.CreateInt("Elements (CB)", Color.white, animationElements.Value.Length, 1, 1, 1000, (Action<int>)SetElements);
			for (int i = 0; i < animationElements.Value.Length; i++)
			{
				int value = i;
				menuNameElements[value] = (Element)(object)Page.CreateFunction($"{value}: {animationElements.Value[value]}", Color.white, (Action)delegate
				{
					if (Clipboard.ContainsText())
					{
						SetElement(value, Clipboard.GetText());
						Core.SavePrefences();
					}
				});
			}
		}

		internal static void Update()
		{
			if (animationEnabled.Value)
			{
				timer += Time.unscaledDeltaTime;
				if (timer > animationTimer.Value)
				{
					animationIndex = (animationIndex + 1) % animationElements.Value.Length;
					SetNametag(animationElements.Value[animationIndex]);
					timer = 0f;
				}
			}
		}

		private static void SetNametag(string name)
		{
			PlayerId localId = PlayerIdManager.LocalId;
			if (localId != null)
			{
				localId.Metadata.TrySetMetadata("Nickname", name);
			}
			previewElement.ElementName = "Preview\n" + name;
		}

		private static void SetElement(int index, string text)
		{
			animationElements.Value[index] = text;
			menuNameElements[index].ElementName = $"{index}: {animationElements.Value[index]}";
		}

		private static void SetElements(int elements)
		{
			string[] array = new string[elements];
			for (int i = 0; i < array.Length; i++)
			{
				if (i < animationElements.Value.Length)
				{
					array[i] = animationElements.Value[i];
				}
				if (array[i] == null)
				{
					array[i] = "Name";
				}
			}
			animationElements.Value = array;
			Page.RemoveAll();
			Element[] array2 = (Element[])(object)new FunctionElement[elements];
			menuNameElements = array2;
			BuildMenu();
			Menu.OpenPage(Page);
		}
	}
}
namespace AnimatedName.Utilities
{
	public class Clipboard
	{
		internal static void SetText(string text)
		{
			GUIUtility.systemCopyBuffer = text;
		}

		internal static bool ContainsText()
		{
			return !string.IsNullOrEmpty(GUIUtility.systemCopyBuffer);
		}

		internal static string GetText()
		{
			return GUIUtility.systemCopyBuffer;
		}
	}
	public static class MenuHelper
	{
		internal static IntElement CreateIntPref(this Page page, string name, Color color, ref MelonPreferences_Entry<int> value, int increment, int minValue, int maxValue, Action<int> callback = null, string prefName = null, int prefDefaultValue = 0)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return page.CreateIntPref(name, color, ref value, Core.PrefsCategory, increment, minValue, maxValue, callback, prefName, prefDefaultValue);
		}

		internal static FloatElement CreateFloatPref(this Page page, string name, Color color, ref MelonPreferences_Entry<float> value, float increment, float minValue, float maxValue, Action<float> callback = null, string prefName = null, float prefDefaultValue = 0f)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return page.CreateFloatPref(name, color, ref value, Core.PrefsCategory, increment, minValue, maxValue, callback, prefName, prefDefaultValue);
		}

		internal static BoolElement CreateBoolPref(this Page page, string name, Color color, ref MelonPreferences_Entry<bool> value, Action<bool> callback = null, string prefName = null, bool prefDefaultValue = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return page.CreateBoolPref(name, color, ref value, Core.PrefsCategory, callback, prefName, prefDefaultValue);
		}

		internal static EnumElement CreateEnumPref<T>(this Page page, string name, Color color, ref MelonPreferences_Entry<T> value, Action<Enum> callback = null, string prefName = null, Enum prefDefaultValue = null) where T : Enum
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return page.CreateEnumPref(name, color, ref value, Core.PrefsCategory, callback, prefName, prefDefaultValue);
		}

		internal static StringElement CreateStringPref(this Page page, string name, Color color, ref MelonPreferences_Entry<string> value, Action<string> callback = null, string prefName = null, string prefDefaultValue = null)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return page.CreateStringPref(name, color, ref value, Core.PrefsCategory, callback, prefName, prefDefaultValue);
		}

		public static IntElement CreateIntPref(this Page page, string name, Color color, ref MelonPreferences_Entry<int> value, MelonPreferences_Category prefCategory, int increment, int minValue, int maxValue, Action<int> callback = null, string prefName = null, int prefDefaultValue = 0)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!prefCategory.HasEntry(prefName))
			{
				value = prefCategory.CreateEntry<int>(prefName, prefDefaultValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<int> val = value;
			return page.CreateInt(name, color, val.Value, increment, minValue, maxValue, (Action<int>)delegate(int x)
			{
				val.Value = x;
				prefCategory.SaveToFile(false);
				Action<int> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<int>(action, x);
				}
			});
		}

		public static FloatElement CreateFloatPref(this Page page, string name, Color color, ref MelonPreferences_Entry<float> value, MelonPreferences_Category prefCategory, float increment, float minValue, float maxValue, Action<float> callback = null, string prefName = null, float prefDefaultValue = 0f)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!prefCategory.HasEntry(prefName))
			{
				value = prefCategory.CreateEntry<float>(prefName, prefDefaultValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<float> val = value;
			return page.CreateFloat(name, color, val.Value, increment, minValue, maxValue, (Action<float>)delegate(float x)
			{
				val.Value = x;
				prefCategory.SaveToFile(false);
				Action<float> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<float>(action, x);
				}
			});
		}

		public static BoolElement CreateBoolPref(this Page page, string name, Color color, ref MelonPreferences_Entry<bool> value, MelonPreferences_Category prefCategory, Action<bool> callback = null, string prefName = null, bool prefDefaultValue = false)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!prefCategory.HasEntry(prefName))
			{
				value = prefCategory.CreateEntry<bool>(prefName, prefDefaultValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<bool> val = value;
			return page.CreateBool(name, color, val.Value, (Action<bool>)delegate(bool x)
			{
				val.Value = x;
				prefCategory.SaveToFile(false);
				Action<bool> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<bool>(action, x);
				}
			});
		}

		public static EnumElement CreateEnumPref<T>(this Page page, string name, Color color, ref MelonPreferences_Entry<T> value, MelonPreferences_Category prefCategory, Action<Enum> callback = null, string prefName = null, Enum prefDefaultValue = null) where T : Enum
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!prefCategory.HasEntry(prefName))
			{
				value = prefCategory.CreateEntry<T>(prefName, (T)prefDefaultValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<T> val = value;
			return page.CreateEnum(name, color, (Enum)val.Value, (Action<Enum>)delegate(Enum x)
			{
				val.Value = (T)x;
				prefCategory.SaveToFile(false);
				Action<Enum> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<Enum>(action, x);
				}
			});
		}

		public static StringElement CreateStringPref(this Page page, string name, Color color, ref MelonPreferences_Entry<string> value, MelonPreferences_Category prefCategory, Action<string> callback = null, string prefName = null, string prefDefaultValue = null)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (prefName == null)
			{
				prefName = name;
			}
			if (!prefCategory.HasEntry(prefName))
			{
				value = prefCategory.CreateEntry<string>(prefName, prefDefaultValue, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			MelonPreferences_Entry<string> val = value;
			StringElement obj = page.CreateString(name, color, val.Value, (Action<string>)delegate(string x)
			{
				val.Value = x;
				prefCategory.SaveToFile(false);
				Action<string> action = callback;
				if (action != null)
				{
					Extensions.InvokeActionSafe<string>(action, x);
				}
			});
			obj.Value = value.Value;
			return obj;
		}
	}
}