Decompiled source of OnOff WispToggle v1.1.0

WispToggle.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("WispToggle")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WispToggle")]
[assembly: AssemblyTitle("WispToggle")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 WispToggle
{
	[BepInPlugin("com.Azura.wisptoggle", "On/Off WispToggle", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.Azura.wisptoggle";

		public const string PluginName = "On/Off WispToggle";

		public const string PluginVersion = "1.1.0";

		internal static ConfigEntry<KeyboardShortcut> ToggleKey;

		internal static ConfigEntry<bool> StartHidden;

		internal static ConfigEntry<bool> OtherPlayersWisps;

		internal static ConfigEntry<bool> AlsoStopMistClearing;

		internal static bool Hidden;

		private void Awake()
		{
			//IL_0017: 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)
			ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleKey", new KeyboardShortcut((KeyCode)106, Array.Empty<KeyCode>()), "Switches the wisp's glow off and on.");
			StartHidden = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "StartHidden", false, "Start the game with the wisp's glow switched off.");
			OtherPlayersWisps = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "OtherPlayersWisps", true, "Also switch off the glow of the other players' wisps on your screen (they still see them).");
			AlsoStopMistClearing = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AlsoStopMistClearing", false, "Also stop your wisp from clearing the mist while its glow is off.");
			Hidden = StartHidden.Value;
			new Harmony("com.Azura.wisptoggle").PatchAll();
		}

		private void Update()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (Boules.Toutes.Count > 0)
			{
				Boules.Appliquer();
			}
			KeyboardShortcut value = ToggleKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown() && !((Object)(object)Player.m_localPlayer == (Object)null) && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible())
			{
				Hidden = !Hidden;
				Boules.Appliquer(force: true);
				MessageHud instance = MessageHud.instance;
				if (instance != null)
				{
					instance.ShowMessage((MessageType)1, Traductions.Texte(Hidden ? "eteint" : "allume"), 0, (Sprite)null, false, true);
				}
			}
		}
	}
	internal static class Boules
	{
		internal static readonly HashSet<Demister> Toutes = new HashSet<Demister>();

		private static readonly Dictionary<Demister, bool> EtatApplique = new Dictionary<Demister, bool>();

		private static readonly Dictionary<Light, float> Intensites = new Dictionary<Light, float>();

		internal static void Appliquer(bool force = false)
		{
			Toutes.RemoveWhere((Demister b) => (Object)(object)b == (Object)null);
			foreach (Demister toute in Toutes)
			{
				bool flag = Plugin.Hidden && (Plugin.OtherPlayersWisps.Value || EstLaMienne(toute));
				if (!force && EtatApplique.TryGetValue(toute, out var value) && value == flag)
				{
					continue;
				}
				EtatApplique[toute] = flag;
				ZNetView componentInParent = ((Component)toute).GetComponentInParent<ZNetView>();
				Transform val = ((componentInParent != null) ? ((Component)componentInParent).transform : null) ?? ((Component)toute).transform;
				Light[] componentsInChildren = ((Component)val).GetComponentsInChildren<Light>(true);
				foreach (Light val2 in componentsInChildren)
				{
					LightFlicker[] components = ((Component)val2).GetComponents<LightFlicker>();
					for (int num2 = 0; num2 < components.Length; num2++)
					{
						((Behaviour)components[num2]).enabled = !flag;
					}
					float value2;
					if (flag)
					{
						if (!Intensites.ContainsKey(val2))
						{
							Intensites[val2] = val2.intensity;
						}
						val2.intensity = 0f;
					}
					else if (Intensites.TryGetValue(val2, out value2))
					{
						val2.intensity = value2;
						Intensites.Remove(val2);
					}
				}
				Renderer[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Renderer>(true);
				for (int num = 0; num < componentsInChildren2.Length; num++)
				{
					componentsInChildren2[num].enabled = !flag;
				}
				if ((Object)(object)toute.m_forceField != (Object)null && EstLaMienne(toute))
				{
					((Behaviour)toute.m_forceField).enabled = !flag || !Plugin.AlsoStopMistClearing.Value;
				}
			}
		}

		private static bool EstLaMienne(Demister boule)
		{
			ZNetView componentInParent = ((Component)boule).GetComponentInParent<ZNetView>();
			if (!((Object)(object)componentInParent == (Object)null) && componentInParent.IsValid())
			{
				return componentInParent.IsOwner();
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Demister), "OnEnable")]
	internal static class Demister_OnEnable_Patch
	{
		private static void Postfix(Demister __instance)
		{
			ZNetView componentInParent = ((Component)__instance).GetComponentInParent<ZNetView>();
			if (componentInParent != null && ((Object)componentInParent).name.ToLowerInvariant().Contains("demister_ball"))
			{
				Boules.Toutes.Add(__instance);
			}
		}
	}
	internal static class Traductions
	{
		internal static readonly string[] Langues = new string[36]
		{
			"English", "Swedish", "French", "Italian", "German", "Spanish", "Russian", "Romanian", "Bulgarian", "Macedonian",
			"Finnish", "Danish", "Norwegian", "Icelandic", "Turkish", "Lithuanian", "Czech", "Hungarian", "Slovak", "Polish",
			"Dutch", "Portuguese_European", "Portuguese_Brazilian", "Chinese", "Chinese_Trad", "Japanese", "Korean", "Hindi", "Thai", "Abenaki",
			"Croatian", "Georgian", "Greek", "Serbian", "Ukrainian", "Latvian"
		};

		private static readonly string[] Cultures = new string[36]
		{
			"en-US", "sv-SE", "fr-FR", "it-IT", "de-DE", "es-ES", "ru-RU", "ro-RO", "bg-BG", "mk-MK",
			"fi-FI", "da-DK", "nb-NO", "is-IS", "tr-TR", "lt-LT", "cs-CZ", "hu-HU", "sk-SK", "pl-PL",
			"nl-NL", "pt-PT", "pt-BR", "zh-CN", "zh-TW", "ja-JP", "ko-KR", "hi-IN", "th-TH", "en-US",
			"hr-HR", "ka-GE", "el-GR", "sr-Latn-RS", "uk-UA", "lv-LV"
		};

		internal static readonly Dictionary<string, string[]> Textes = new Dictionary<string, string[]>
		{
			["eteint"] = new string[36]
			{
				"Wisplight: glow off", "Lysande irrbloss: skenet släckt", "Feu follet : lumière éteinte", "Fuoco fatuo: luce spenta", "Irrlicht: Leuchten aus", "Luz de Wisp: brillo apagado", "Свет светлячка: свечение выключено", "Lumină de Wisp: strălucire oprită", "Светлик: светлината е изключена", "Светулка: светлото е исклучено",
				"Virvatuli: hehku pois", "Lygtemandslys: skæret slukket", "Lyktemann: lyset slukket", "Ljómalukt: slökkt á ljómanum", "Peri Işığı: parıltı kapalı", "Sielos šviesa: švytėjimas išjungtas", "Bludné světélko: záře vypnuta", "Tündérfény: ragyogás kikapcsolva", "Bludička: žiara vypnutá", "Światełko ognika: blask wyłączony",
				"Dwaallicht: gloed uit", "Luz de fogo-fátuo: brilho desligado", "Luz de Wisp: brilho desligado", "冥火之光:光芒已关闭", "幽光:光芒已關閉", "ウィスプライト:光を消しました", "위습등: 빛 꺼짐", "व\u093fस\u094dपल\u093eइट: र\u094bशन\u0940 ब\u0902द", "ภ\u0e39ต\u0e34แสงนำทาง: ป\u0e34ดแสง", null,
				"Svjetlo lutalice: sjaj isključen", "მოხეტიალე შუქი: ნათება გამორთულია", "Φως αερικού: λάμψη σβηστή", "Svetlo lutalice: sjaj isključen", "Світлячок: сяйво вимкнено", "Maldugunsgaisma: spīdums izslēgts"
			},
			["allume"] = new string[36]
			{
				"Wisplight: glow on", "Lysande irrbloss: skenet tänt", "Feu follet : lumière allumée", "Fuoco fatuo: luce accesa", "Irrlicht: Leuchten an", "Luz de Wisp: brillo encendido", "Свет светлячка: свечение включено", "Lumină de Wisp: strălucire pornită", "Светлик: светлината е включена", "Светулка: светлото е вклучено",
				"Virvatuli: hehku päällä", "Lygtemandslys: skæret tændt", "Lyktemann: lyset tent", "Ljómalukt: kveikt á ljómanum", "Peri Işığı: parıltı açık", "Sielos šviesa: švytėjimas įjungtas", "Bludné světélko: záře zapnuta", "Tündérfény: ragyogás bekapcsolva", "Bludička: žiara zapnutá", "Światełko ognika: blask włączony",
				"Dwaallicht: gloed aan", "Luz de fogo-fátuo: brilho ligado", "Luz de Wisp: brilho ligado", "冥火之光:光芒已开启", "幽光:光芒已開啟", "ウィスプライト:光をつけました", "위습등: 빛 켜짐", "व\u093fस\u094dपल\u093eइट: र\u094bशन\u0940 च\u093eल\u0942", "ภ\u0e39ต\u0e34แสงนำทาง: เป\u0e34ดแสง", null,
				"Svjetlo lutalice: sjaj uključen", "მოხეტიალე შუქი: ნათება ჩართულია", "Φως αερικού: λάμψη αναμμένη", "Svetlo lutalice: sjaj uključen", "Світлячок: сяйво увімкнено", "Maldugunsgaisma: spīdums ieslēgts"
			}
		};

		internal static string LangueDuJeu
		{
			get
			{
				if (Localization.instance == null)
				{
					return "English";
				}
				return Localization.instance.GetSelectedLanguage();
			}
		}

		internal static string Texte(string cle, string langue = null)
		{
			if (!Textes.TryGetValue(cle, out var value))
			{
				return cle;
			}
			int num = Array.IndexOf(Langues, langue ?? LangueDuJeu);
			if (num <= 0 || num >= value.Length || string.IsNullOrEmpty(value[num]))
			{
				return value[0];
			}
			return value[num];
		}

		internal static string Format(string cle, string langue, object[] valeurs)
		{
			string text = Texte(cle, langue);
			if (valeurs != null && valeurs.Length != 0)
			{
				return string.Format(Culture(langue), text, valeurs);
			}
			return text;
		}

		internal static CultureInfo Culture(string langue = null)
		{
			int num = Array.IndexOf(Langues, langue ?? LangueDuJeu);
			try
			{
				return CultureInfo.GetCultureInfo((num >= 0) ? Cultures[num] : "en-US");
			}
			catch
			{
				return CultureInfo.InvariantCulture;
			}
		}
	}
}