Decompiled source of Flashlight v1.1.2

Flashlight.dll

Decompiled 3 months 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Flashlight")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Allows flashlight customisation. Client Side.")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+e593228772f1d6c846ef9a5ff0bf3d1e1b9ed6d0")]
[assembly: AssemblyProduct("Flashlight")]
[assembly: AssemblyTitle("Allows flashlight customisation. Client Side.")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.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 Flashlight
{
	[BepInPlugin("Mest.Flashlight", "Flashlight", "1.1.2")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal static BepinPlugin instance;

		internal static ManualLogSource Log;

		internal static string profilesDirectiory;

		private void Awake()
		{
			instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			profilesDirectiory = Path.Combine(Paths.ConfigPath, "FlashlightProfiles");
			Directory.CreateDirectory(profilesDirectiory);
			Configs.Load();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Mest.Flashlight is loaded!");
		}
	}
	internal class ProfileData
	{
		public string Name;

		public ConfigFile ConfigFile;

		public Color Colour;

		public ConfigEntry<float> Angle;

		public ConfigEntry<float> Range;

		public ConfigEntry<float> Intensity;

		public ConfigEntry<bool> AOE;

		public ConfigEntry<bool> Rainbow;
	}
	public class Configs : ModSettingsMenu
	{
		private static Color DefaultColor = Color.white;

		private static float DefaultAngle = 45.1f;

		private static float DefaultRange = 25f;

		private static float DefaultIntensity = 416.34f;

		internal static ConfigEntry<string> PlayerFlashlightProfile;

		internal static ProfileData playerFlashlight;

		internal static ConfigEntry<string> OthersFlashlightProfile;

		internal static ProfileData othersFlashlight;

		private static Dictionary<string, ProfileData> Profiles = new Dictionary<string, ProfileData>();

		private static ProfileData SelectedProfile = null;

		private static bool HomePage = true;

		private static string searchValue = "";

		internal static string[] profileFiles;

		internal static ConfigEntry<bool> SeperateFlashlights;

		internal static ConfigEntry<bool> PrecisionMode;

		internal static ConfigEntry<float> RainbowSpeed;

		public override string Name()
		{
			if (HomePage)
			{
				return "Flashlight Config - Home Page";
			}
			if (SelectedProfile == null)
			{
				return "Flashlight Config - Profile List";
			}
			return "Flashlight Config - Editing Profile: " + SelectedProfile.Name;
		}

		internal static void Load()
		{
			SeperateFlashlights = ((BaseUnityPlugin)BepinPlugin.instance).Config.Bind<bool>("SeperateFlashlights", "Enabled", true, (ConfigDescription)null);
			PrecisionMode = ((BaseUnityPlugin)BepinPlugin.instance).Config.Bind<bool>("PrecisionMode", "Enabled", true, (ConfigDescription)null);
			RainbowSpeed = ((BaseUnityPlugin)BepinPlugin.instance).Config.Bind<float>("RainbowFlashlight", "Speed", 0.125f, (ConfigDescription)null);
			PlayerFlashlightProfile = ((BaseUnityPlugin)BepinPlugin.instance).Config.Bind<string>("Profile", "Player", "default", (ConfigDescription)null);
			playerFlashlight = LoadProfile(PlayerFlashlightProfile.Value);
			OthersFlashlightProfile = ((BaseUnityPlugin)BepinPlugin.instance).Config.Bind<string>("Profile", "Others", "default", (ConfigDescription)null);
			othersFlashlight = LoadProfile(OthersFlashlightProfile.Value);
		}

		internal static ProfileData LoadProfile(string profileName)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(BepinPlugin.profilesDirectiory, profileName + ".cfg");
			ConfigFile val = new ConfigFile(text, true);
			ProfileData profileData = new ProfileData();
			profileData.Name = profileName;
			profileData.ConfigFile = val;
			profileData.Colour = LoadColor("Colour", val);
			profileData.Angle = val.Bind<float>("Settings", "Angle", DefaultAngle, (ConfigDescription)null);
			profileData.Range = val.Bind<float>("Settings", "Range", DefaultRange, (ConfigDescription)null);
			profileData.Intensity = val.Bind<float>("Settings", "Intensity", DefaultIntensity, (ConfigDescription)null);
			profileData.AOE = val.Bind<bool>("Settings", "AOE", false, (ConfigDescription)null);
			profileData.Rainbow = val.Bind<bool>("Settings", "Rainbow", false, (ConfigDescription)null);
			BepinPlugin.Log.LogInfo((object)("Loaded profile: " + profileName));
			return profileData;
		}

		private static Color LoadColor(string colorPrefix, ConfigFile currentConfigFile = null)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (currentConfigFile == null)
			{
				currentConfigFile = ((BaseUnityPlugin)BepinPlugin.instance).Config;
			}
			ConfigEntry<float> val = currentConfigFile.Bind<float>(colorPrefix, "R", 1f, (ConfigDescription)null);
			ConfigEntry<float> val2 = currentConfigFile.Bind<float>(colorPrefix, "G", 1f, (ConfigDescription)null);
			ConfigEntry<float> val3 = currentConfigFile.Bind<float>(colorPrefix, "B", 1f, (ConfigDescription)null);
			return new Color(val.Value, val2.Value, val3.Value);
		}

		internal static void UpdateColor(string colorPrefix, ref Color color, ConfigFile currentConfigFile = null)
		{
			if (currentConfigFile == null)
			{
				currentConfigFile = ((BaseUnityPlugin)BepinPlugin.instance).Config;
			}
			currentConfigFile.Bind<float>(colorPrefix, "R", 1f, (ConfigDescription)null).Value = color.r;
			currentConfigFile.Bind<float>(colorPrefix, "G", 1f, (ConfigDescription)null).Value = color.g;
			currentConfigFile.Bind<float>(colorPrefix, "B", 1f, (ConfigDescription)null).Value = color.b;
		}

		internal static void DrawProfile((float, float) loc, ProfileData profile)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (profile != null)
			{
				GUILayout.BeginArea(new Rect(loc.Item1, loc.Item2, 466f, 345f), "", GUIStyle.op_Implicit("Box"));
				GUILayout.Label(profile.Name, Array.Empty<GUILayoutOption>());
				if (GUITools.DrawColorPicker(new Rect(4f, 30f, 458f, 160f), "Colour", ref profile.Colour, DefaultColor, false, 0f, 1f))
				{
					UpdateColor("Colour", ref profile.Colour, profile.ConfigFile);
				}
				GUILayout.Space(160f);
				GUILayout.BeginVertical(GUIStyle.op_Implicit("Box"), Array.Empty<GUILayoutOption>());
				DrawLabeledSlider("Angle", ref profile.Angle, 15f, 160f, DefaultAngle);
				DrawLabeledSlider("Range", ref profile.Range, 0f, PrecisionMode.Value ? 25 : 100, DefaultRange);
				DrawLabeledSlider("Intensity", ref profile.Intensity, 0f, PrecisionMode.Value ? 1000 : 10000, DefaultIntensity);
				GUITools.DrawCheckbox("Precision for Range & Intensity", ref PrecisionMode);
				GUITools.DrawCheckbox("Area Of Effect Flashlight", ref profile.AOE);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUITools.DrawCheckbox("Rainbow", ref profile.Rainbow);
				DrawLabeledSlider("Speed", ref RainbowSpeed, 0.001f, 0.4f, 0.125f);
				GUILayout.EndHorizontal();
				GUILayout.EndVertical();
				GUILayout.EndArea();
			}
		}

		public static bool DrawTextField(string label, ref string value, string defaultValue = null, float minWidth = 80f)
		{
			bool result = false;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label + ": ", Array.Empty<GUILayoutOption>());
			value = GUILayout.TextField(value, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(minWidth) });
			GUILayout.FlexibleSpace();
			if (defaultValue != null && GUILayout.Button("Reset", Array.Empty<GUILayoutOption>()))
			{
				value = defaultValue;
			}
			if (GUILayout.Button("Create", Array.Empty<GUILayoutOption>()))
			{
				result = true;
			}
			GUILayout.EndHorizontal();
			return result;
		}

		public static void DrawLabeledSlider(string label, ref ConfigEntry<float> value, float minValue, float maxValue, float defaultValue)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"{label} {value.Value:F3}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(230f) });
			if (GUILayout.Button("Reset", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }))
			{
				value.Value = defaultValue;
			}
			GUITools.DrawSlider(ref value, minValue, maxValue);
			GUILayout.EndHorizontal();
		}

		public override void Draw()
		{
			if (HomePage)
			{
				DrawHomePage();
			}
			else if (SelectedProfile == null)
			{
				DrawProfileList();
			}
			else
			{
				DrawProfile();
			}
		}

		private static void DrawHomePage()
		{
			if (GUILayout.Button("Browse Flashlight Profiles", Array.Empty<GUILayoutOption>()))
			{
				SelectedProfile = null;
				HomePage = false;
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Player Flashlight: " + PlayerFlashlightProfile.Value, Array.Empty<GUILayoutOption>()))
			{
				SelectedProfile = playerFlashlight;
				HomePage = false;
			}
			if (GUILayout.Button("Others Flashlight: " + OthersFlashlightProfile.Value, Array.Empty<GUILayoutOption>()))
			{
				SelectedProfile = othersFlashlight;
				HomePage = false;
			}
			GUILayout.EndHorizontal();
			DrawProfile((4f, 130f), playerFlashlight);
			DrawProfile((476f, 130f), othersFlashlight);
		}

		private static void DrawProfile()
		{
			if (GUILayout.Button("Back to Flashlight Profile list", Array.Empty<GUILayoutOption>()))
			{
				SelectedProfile = null;
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Player Flashlight: " + PlayerFlashlightProfile.Value, Array.Empty<GUILayoutOption>()))
			{
				SelectedProfile = playerFlashlight;
			}
			HomePage = false;
			if (GUILayout.Button("Others Flashlight: " + OthersFlashlightProfile.Value, Array.Empty<GUILayoutOption>()))
			{
				SelectedProfile = othersFlashlight;
			}
			HomePage = false;
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Assign", Array.Empty<GUILayoutOption>()))
			{
				PlayerFlashlightProfile.Value = SelectedProfile.Name;
				playerFlashlight = SelectedProfile;
			}
			if (GUILayout.Button("Assign", Array.Empty<GUILayoutOption>()))
			{
				OthersFlashlightProfile.Value = SelectedProfile.Name;
				othersFlashlight = SelectedProfile;
			}
			GUILayout.EndHorizontal();
			DrawProfile((4f, 130f), SelectedProfile);
		}

		private static void DrawProfileList()
		{
			if (GUILayout.Button("Home", Array.Empty<GUILayoutOption>()))
			{
				SelectedProfile = null;
				HomePage = true;
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Player Flashlight: " + PlayerFlashlightProfile.Value, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Others Flashlight: " + OthersFlashlightProfile.Value, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			profileFiles = Directory.GetFiles(BepinPlugin.profilesDirectiory, "*.cfg");
			if (DrawTextField("Search", ref searchValue, "", 200f))
			{
				string text = searchValue;
				int num = 1;
				do
				{
					text = ((num == 1) ? searchValue : $"{searchValue} ({num})");
					num++;
				}
				while (Profiles.ContainsKey(text));
				Profiles.Add(text, LoadProfile(text));
			}
			for (int i = 0; i < profileFiles.Count(); i++)
			{
				string path = profileFiles[i];
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
				if (!Profiles.ContainsKey(fileNameWithoutExtension))
				{
					Profiles.Add(fileNameWithoutExtension, LoadProfile(fileNameWithoutExtension));
				}
				if (!(searchValue != "") || fileNameWithoutExtension.ToLower().Contains(searchValue.ToLower()))
				{
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					if (GUILayout.Button(fileNameWithoutExtension, Array.Empty<GUILayoutOption>()))
					{
						SelectedProfile = Profiles[fileNameWithoutExtension];
					}
					if (GUILayout.Button("X", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(20f) }))
					{
						DeleteProfileFile(fileNameWithoutExtension);
					}
					GUILayout.EndHorizontal();
				}
			}
		}

		public static void DeleteProfileFile(string profileName)
		{
			string path = Path.Combine(BepinPlugin.profilesDirectiory, profileName + ".cfg");
			if (Profiles.ContainsKey(profileName))
			{
				Profiles[profileName].ConfigFile.Clear();
				Profiles.Remove(profileName);
			}
			if (File.Exists(path))
			{
				File.Delete(path);
			}
			if (PlayerFlashlightProfile.Value == profileName)
			{
				PlayerFlashlightProfile.Value = "default";
				playerFlashlight = LoadProfile("default");
			}
			if (OthersFlashlightProfile.Value == profileName)
			{
				OthersFlashlightProfile.Value = "default";
				othersFlashlight = LoadProfile("default");
			}
			if (profileName == "default")
			{
				LoadProfile("default");
			}
			else
			{
				BepinPlugin.Log.LogInfo((object)("[Flashlights] Deleted Profile " + profileName));
			}
		}
	}
	public class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Mest.Flashlight";

		public const string PLUGIN_NAME = "Flashlight";

		public const string USERS_PLUGIN_NAME = "Flashlight";

		public const string PLUGIN_VERSION = "1.1.2";

		public const string PLUGIN_DESCRIPTION = "Allows flashlight customisation. Client Side.";

		public const string PLUGIN_ORIGINAL_AUTHOR = "Mest";

		public const string PLUGIN_AUTHORS = "Mest";

		public const string PLUGIN_THUNDERSTORE_ID = "";
	}
	[HarmonyPatch(typeof(CustomPunCharacterTransformMonitor), "Update")]
	internal class Patch
	{
		internal static Dictionary<GameObject, Light> playerFlashlights = new Dictionary<GameObject, Light>();

		private static void Postfix(CustomPunCharacterTransformMonitor __instance)
		{
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)__instance).gameObject;
			if ((Object)(object)gameObject == (Object)null)
			{
				return;
			}
			if (playerFlashlights.TryGetValue(gameObject, out var value))
			{
				if (PunExtensions.GetPhotonView(gameObject).IsMine && Configs.SeperateFlashlights.Value)
				{
					value.color = Configs.playerFlashlight.Colour;
					if (Configs.playerFlashlight.Rainbow.Value)
					{
						value.color = GetRainbowColor();
					}
					value.spotAngle = Configs.playerFlashlight.Angle.Value;
					value.range = Configs.playerFlashlight.Range.Value;
					value.intensity = Configs.playerFlashlight.Intensity.Value;
					if (Configs.playerFlashlight.AOE.Value)
					{
						value.type = (LightType)2;
					}
					else
					{
						value.type = (LightType)0;
					}
				}
				else
				{
					value.color = Configs.othersFlashlight.Colour;
					if (Configs.othersFlashlight.Rainbow.Value)
					{
						value.color = GetRainbowColor();
					}
					value.spotAngle = Configs.othersFlashlight.Angle.Value;
					value.range = Configs.othersFlashlight.Range.Value;
					value.intensity = Configs.othersFlashlight.Intensity.Value;
					if (Configs.othersFlashlight.AOE.Value)
					{
						value.type = (LightType)2;
					}
					else
					{
						value.type = (LightType)0;
					}
				}
			}
			else
			{
				Light componentInChildren = gameObject.GetComponentInChildren<Light>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					playerFlashlights.Add(gameObject, componentInChildren);
				}
			}
		}

		private static Color GetRainbowColor()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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)
			float num = Time.time * Configs.RainbowSpeed.Value % 1f;
			return Color.HSVToRGB(num, 1f, 1f);
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)8;

		public override string Author => "Mest";

		public override string Description => "Allows flashlight customisation. Client Side.";

		public override string ThunderstoreID => "";
	}
}