Decompiled source of CustomizableName v1.2.0

CustomizableName.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Configuration;
using BepInEx.Logging;
using CustomizableName.Components;
using CustomizableName.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.UI;
using Peak.Network;
using Photon.Pun;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.Settings;
using Zorro.Settings.UI;

[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("Adeithe")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyInformationalVersion("1.2.0+d3e7d4d16fc96a445bc4f651ad6286e4320baec1")]
[assembly: AssemblyProduct("CustomizableName")]
[assembly: AssemblyTitle("CustomizableName")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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 CustomizableName
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Adeithe.Peak.CustomizableName", "CustomizableName", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static BuilderDelegate <0>__Initialize;
		}

		internal static ConfigManager Config = new ConfigManager();

		internal static readonly ManualLogSource Logger = Logger.CreateLogSource(Name);

		internal static readonly BepInPlugin Metadata = MetadataHelper.GetMetadata(typeof(Plugin));

		private Harmony harmony = new Harmony("Adeithe.Peak.CustomizableName");

		private FileSystemWatcher watcher = new FileSystemWatcher
		{
			Path = Paths.ConfigPath,
			Filter = "Adeithe-CustomizableName.cfg",
			NotifyFilter = (NotifyFilters.Size | NotifyFilters.LastWrite)
		};

		public const string Id = "Adeithe.Peak.CustomizableName";

		public static string Name => "CustomizableName";

		public static string Version => "1.2.0";

		private void Awake()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			List<Type> list = types.Where((Type t) => t.Namespace == ((object)this).GetType().Namespace + ".Patches" && t.Name.EndsWith("Patch")).ToList();
			list.ForEach((Action<Type>)harmony.PatchAll);
			watcher.Changed += delegate
			{
				Config.Reload();
			};
			Logger.LogInfo((object)$"Loaded {((BaseUnityPlugin)this).Info.Metadata.Name} v{((BaseUnityPlugin)this).Info.Metadata.Version}");
		}

		private void Start()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			object obj = <>O.<0>__Initialize;
			if (obj == null)
			{
				BuilderDelegate val = PreferredNameSetting.Initialize;
				<>O.<0>__Initialize = val;
				obj = (object)val;
			}
			MenuAPI.AddToSettingsMenu((BuilderDelegate)obj);
		}

		private void OnDestroy()
		{
			watcher.Dispose();
			harmony.UnpatchSelf();
		}
	}
}
namespace CustomizableName.Patches
{
	[HarmonyPatch(typeof(NetworkConnector))]
	internal class NetworkConnectorPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Start_Postfix(NetworkConnector __instance)
		{
			PhotonNetwork.NickName = NetworkingUtilities.GetUsername();
		}

		[HarmonyPatch(typeof(NetworkingUtilities), "GetUsername")]
		[HarmonyPrefix]
		public static bool GetUsername_Prefix(ref string __result)
		{
			__result = Plugin.Config.DisplayName;
			return false;
		}
	}
	[HarmonyPatch(typeof(PassportManager))]
	internal class PassportManagerPatch
	{
		[HarmonyPatch("ToggleOpen")]
		[HarmonyPrefix]
		public static bool ToggleOpen_Prefix(PassportManager __instance)
		{
			string characterName = Character.localCharacter.characterName;
			string text = PassportManager.GeneratePassportNumber(characterName);
			((TMP_Text)__instance.nameText).text = characterName;
			((TMP_Text)__instance.passportNumberText).text = text;
			return true;
		}
	}
}
namespace CustomizableName.Configuration
{
	public sealed class ConfigManager
	{
		private static readonly string ConfigPath = Path.Combine(Paths.ConfigPath, "Adeithe-CustomizableName.cfg");

		private ConfigFile Config = new ConfigFile(ConfigPath, true, Plugin.Metadata);

		public ConfigEntry<string?> PreferredName;

		public string DisplayName
		{
			get
			{
				return PreferredName.Value ?? SteamFriends.GetPersonaName();
			}
			set
			{
				string personaName = SteamFriends.GetPersonaName();
				string text = (string.IsNullOrWhiteSpace(value) ? personaName : value);
				if (personaName.Equals(value, StringComparison.OrdinalIgnoreCase))
				{
					text = null;
				}
				if (PhotonNetwork.IsConnected)
				{
					PhotonNetwork.NickName = text ?? personaName;
				}
				PreferredName.Value = text;
				if (text != null)
				{
					Plugin.Logger.LogInfo((object)("Set preferred name to '" + text + "'"));
				}
			}
		}

		internal ConfigManager()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Config.SaveOnConfigSet = true;
			PreferredName = Config.Bind<string>("General", "PreferredName", (string)null, "The preferred name to use for your scout. If empty, your Steam name will be used instead.");
		}

		public void Reload()
		{
			Config.Reload();
		}
	}
}
namespace CustomizableName.Components
{
	internal class PreferredNameSetting : StringSetting, IExposedSetting, IConditionalSetting
	{
		private static bool initialized;

		private PreferredNameSetting()
		{
		}

		public override void Load(ISettingsSaveLoad loader)
		{
			((StringSetting)this).Value = Plugin.Config.PreferredName.Value ?? "";
		}

		public override void Save(ISettingsSaveLoad saver)
		{
			Plugin.Config.DisplayName = ((StringSetting)this).Value.Trim();
		}

		public override void ApplyValue()
		{
		}

		protected override string GetDefaultValue()
		{
			return "";
		}

		public string GetDisplayName()
		{
			return "PREFERREDNAMESETTING";
		}

		public string GetCategory()
		{
			return "Accessibility";
		}

		public bool ShouldShow()
		{
			return !PhotonNetwork.InRoom;
		}

		public override GameObject GetSettingUICell()
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("PreferredNameInputCell");
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			GameObject val2 = Object.Instantiate<GameObject>(SingletonAsset<InputCellMapper>.Instance.FloatSettingCell);
			((Object)val2).name = "PreferredNameInputCell";
			FloatSettingUI component = val2.GetComponent<FloatSettingUI>();
			StringSettingUI val3 = val2.AddComponent<StringSettingUI>();
			val3.inputField = component.inputField;
			Object.DestroyImmediate((Object)(object)((Component)component.slider).gameObject);
			Object.DestroyImmediate((Object)(object)component);
			((SettingInputUICell)val3).disable = PhotonNetwork.InRoom;
			val3.inputField.readOnly = ((SettingInputUICell)val3).disable;
			((Selectable)val3.inputField).interactable = !((SettingInputUICell)val3).disable;
			val3.inputField.characterValidation = (CharacterValidation)0;
			val3.inputField.characterLimit = 24;
			val3.inputField.contentType = (ContentType)0;
			RectTransform component2 = ((Component)val3.inputField).GetComponent<RectTransform>();
			component2.pivot = new Vector2(0.5f, 0.5f);
			component2.anchorMin = new Vector2(0f, 0f);
			component2.anchorMax = new Vector2(1f, 1f);
			component2.offsetMin = new Vector2(20f, 15f);
			component2.offsetMax = new Vector2(-20f, -15f);
			component2.sizeDelta = new Vector2(-40f, -30f);
			TextMeshProUGUI[] componentsInChildren = val2.GetComponentsInChildren<TextMeshProUGUI>(true);
			TextMeshProUGUI[] array = componentsInChildren;
			foreach (TextMeshProUGUI val4 in array)
			{
				if (((Object)val4).name == "Placeholder")
				{
					((TMP_Text)val4).text = SteamFriends.GetPersonaName();
				}
				float num2 = (((TMP_Text)val4).fontSizeMax = 24f);
				float fontSize = (((TMP_Text)val4).fontSizeMin = num2);
				((TMP_Text)val4).fontSize = fontSize;
				((TMP_Text)val4).alignment = (TextAlignmentOptions)4097;
			}
			return val2;
		}

		internal static void Initialize(Transform parent)
		{
			if (!initialized)
			{
				TranslationKey val = MenuAPI.CreateLocalization("PREFERREDNAMESETTING").AddLocalization("Preferred Name", (Language)0).AddLocalization("Nom préféré", (Language)1)
					.AddLocalization("Nome preferito", (Language)2)
					.AddLocalization("Bevorzugter Name", (Language)3)
					.AddLocalization("Nombre preferido", (Language)4)
					.AddLocalization("Nombre preferido", (Language)5)
					.AddLocalization("Nome preferido", (Language)6)
					.AddLocalization("Предпочтительное имя", (Language)7)
					.AddLocalization("Бажане ім'я", (Language)8)
					.AddLocalization("首选名称", (Language)9)
					.AddLocalization("首選名稱", (Language)10)
					.AddLocalization("希望する名前", (Language)11)
					.AddLocalization("선호하는 이름", (Language)12)
					.AddLocalization("Preferowana nazwa", (Language)13)
					.AddLocalization("Tercih edilen isim", (Language)14);
				SettingsHandler.Instance.AddSetting((Setting)(object)new PreferredNameSetting());
				initialized = true;
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}