Decompiled source of FlashlightTweaks v0.0.1

Plugins/FlashlightTweaks.dll

Decompiled 6 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using NeatWolf.NeatFlashlight.Patches;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NeatFlashlight")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NeatFlashlight")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("371D94BB-434D-4D2C-BCE9-55D06E9D32FC")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NeatWolf.NeatFlashlight
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "NeatWolf.NeatFlashlight";

		public const string PLUGIN_NAME = "NeatFlashlight";

		public const string PLUGIN_VERSION = "0.0.1";
	}
	public class Config
	{
		public static ConfigEntry<bool> ChangeColourWithCharge;

		public static ConfigEntry<Color> BatteryFullChargeColour;

		public static ConfigEntry<Color> BatteryNoChargeColour;

		public static ConfigEntry<bool> FadeOutIntensityWithCharge;

		public static ConfigEntry<float> IntensityWhenDepletedMultiplier;

		public static ConfigEntry<bool> FadeOutRangeWithCharge;

		public static ConfigEntry<float> RangeWhenDepletedMultiplier;

		public static ConfigEntry<float> LightIntensity;

		public static ConfigEntry<float> LightRange;

		public static ConfigEntry<float> LightConeAngle;

		public static ConfigEntry<float> LightVolumetricIntensity;

		public static ConfigEntry<float> BulbGlowIntensity;

		public static ConfigEntry<float> BulbGlowRange;

		public static ConfigEntry<float> BulbGlowConeAngle;

		public static ConfigEntry<float> BulbGlowVolumetricIntensity;

		public static ConfigEntry<float> NightVisionIntensity;

		public static ConfigEntry<float> NightVisionRange;

		public static ConfigEntry<float> NightVisionConeAngle;

		public static ConfigEntry<float> NightVisionVolumetricIntensity;

		public Config(ConfigFile config)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			ChangeColourWithCharge = config.Bind<bool>("Battery Fading", "ChangeColourWithCharge", false, (ConfigDescription)null);
			BatteryFullChargeColour = config.Bind<Color>("Battery Fading", "BatteryFullChargeColour", new Color(0.8f, 0.8f, 1f, 1f), (ConfigDescription)null);
			BatteryNoChargeColour = config.Bind<Color>("Battery Fading", "BatteryNoChargeColour", new Color(1f, 0.8f, 0.8f, 255f), (ConfigDescription)null);
			FadeOutIntensityWithCharge = config.Bind<bool>("Battery Fading", "FadeOutIntensityWithCharge", false, (ConfigDescription)null);
			IntensityWhenDepletedMultiplier = config.Bind<float>("Battery Fading", "IntensityWhenDepletedMultiplier", 0.1f, (ConfigDescription)null);
			FadeOutRangeWithCharge = config.Bind<bool>("Battery Fading", "FadeOutRangeWithCharge", false, (ConfigDescription)null);
			RangeWhenDepletedMultiplier = config.Bind<float>("Battery Fading", "RangeWhenDepletedMultiplier", 0.25f, (ConfigDescription)null);
			LightIntensity = config.Bind<float>("Flashlight", "LightIntensity", 500f, (ConfigDescription)null);
			LightRange = config.Bind<float>("Flashlight", "LightRange", 55f, (ConfigDescription)null);
			LightConeAngle = config.Bind<float>("Flashlight", "LightConeAngle", 73f, (ConfigDescription)null);
			LightVolumetricIntensity = config.Bind<float>("Flashlight", "LightVolumetricIntensity", 0.6f, (ConfigDescription)null);
			BulbGlowIntensity = config.Bind<float>("Bulb Glow", "BulbGlowIntensity", 2f, (ConfigDescription)null);
			BulbGlowRange = config.Bind<float>("Bulb Glow", "BulbGlowRange", 8f, (ConfigDescription)null);
			BulbGlowConeAngle = config.Bind<float>("Bulb Glow", "BulbGlowConeAngle", 73f, (ConfigDescription)null);
			BulbGlowVolumetricIntensity = config.Bind<float>("Bulb Glow", "BulbGlowVolumetricIntensity", 0.9f, (ConfigDescription)null);
			NightVisionIntensity = config.Bind<float>("NightVision", "NightVisionIntensity", 400f, (ConfigDescription)null);
			NightVisionRange = config.Bind<float>("NightVision", "NightVisionRange", 12f, (ConfigDescription)null);
			NightVisionConeAngle = config.Bind<float>("NightVision", "NightVisionConeAngle", 73f, (ConfigDescription)null);
			NightVisionVolumetricIntensity = config.Bind<float>("NightVision", "NightVisionVolumetricIntensity", 0.9f, (ConfigDescription)null);
		}
	}
	[BepInPlugin("NeatWolf.NeatFlashlight", "NeatFlashlight", "0.0.1")]
	public class ModBase : BaseUnityPlugin
	{
		private static ModBase Instance;

		private static ManualLogSource mls;

		private readonly Harmony harmony = new Harmony("NeatWolf.NeatFlashlight");

		public static Config MyConfig { get; internal set; }

		public static Color LerpHSV(Color32 a, Color32 b, float t)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(Color32.op_Implicit(a), ref num, ref num2, ref num3);
			float num4 = default(float);
			float num5 = default(float);
			float num6 = default(float);
			Color.RGBToHSV(Color32.op_Implicit(b), ref num4, ref num5, ref num6);
			float num7 = Mathf.Lerp(num, num4, t);
			float num8 = Mathf.Lerp(num2, num5, t);
			float num9 = Mathf.Lerp(num3, num6, t);
			return Color.HSVToRGB(num7, num8, num9);
		}

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			MyConfig = new Config(((BaseUnityPlugin)this).Config);
			LogInfo("Starting...");
			harmony.PatchAll(typeof(ModBase));
			harmony.PatchAll(typeof(FlashlightPatch));
			harmony.PatchAll(typeof(HelmetLightPatch));
			LogInfo("All patches applied");
		}

		internal static void LogInfo(string info)
		{
			if (mls == null)
			{
				mls = CreateLogger();
			}
			mls.LogInfo((object)("NeatFlashlight: " + info));
		}

		private static ManualLogSource CreateLogger()
		{
			mls = Logger.CreateLogSource("NeatFlashlight");
			return mls;
		}
	}
}
namespace NeatWolf.NeatFlashlight.Patches
{
	[HarmonyPatch(typeof(FlashlightItem))]
	internal class FlashlightPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void SwitchFlashlight(ref float ___initialIntensity, ref FlashlightItem __instance)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			try
			{
			}
			finally
			{
				float num = 1f;
				if (Config.FadeOutIntensityWithCharge.Value)
				{
					num = Mathf.Lerp(Config.IntensityWhenDepletedMultiplier.Value, 1f, ((GrabbableObject)__instance).insertedBattery.charge);
				}
				float num2 = 1f;
				if (Config.FadeOutRangeWithCharge.Value)
				{
					num2 = Mathf.Lerp(Config.RangeWhenDepletedMultiplier.Value, 1f, ((GrabbableObject)__instance).insertedBattery.charge);
				}
				if (Config.ChangeColourWithCharge.Value)
				{
					Color color = ModBase.LerpHSV(Color32.op_Implicit(Config.BatteryNoChargeColour.Value), Color32.op_Implicit(Config.BatteryFullChargeColour.Value), ((GrabbableObject)__instance).insertedBattery.charge);
					__instance.flashlightBulb.color = color;
					__instance.flashlightBulbGlow.color = color;
				}
				__instance.flashlightBulbGlow.intensity = Config.BulbGlowIntensity.Value * num;
				__instance.flashlightBulbGlow.range = Config.BulbGlowRange.Value * num2;
				__instance.flashlightBulbGlow.spotAngle = Config.BulbGlowConeAngle.Value;
				((Component)__instance.flashlightBulbGlow).GetComponent<HDAdditionalLightData>().affectsVolumetric = Config.BulbGlowVolumetricIntensity.Value > 0f;
				((Component)__instance.flashlightBulbGlow).GetComponent<HDAdditionalLightData>().volumetricDimmer = Config.BulbGlowVolumetricIntensity.Value;
				___initialIntensity = Config.LightIntensity.Value;
				__instance.flashlightBulb.intensity = Config.LightIntensity.Value * num;
				__instance.flashlightBulb.range = Config.LightRange.Value * num2;
				__instance.flashlightBulb.spotAngle = Config.LightConeAngle.Value;
				((Component)__instance.flashlightBulb).GetComponent<HDAdditionalLightData>().affectsVolumetric = Config.LightVolumetricIntensity.Value > 0f;
				((Component)__instance.flashlightBulb).GetComponent<HDAdditionalLightData>().volumetricDimmer = Config.LightVolumetricIntensity.Value;
				((Component)__instance.flashlightBulb).GetComponent<HDAdditionalLightData>().enableSpotReflector = true;
				__instance.flashlightBulb.innerSpotAngle = num * __instance.flashlightBulb.spotAngle;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class HelmetLightPatch
	{
		[HarmonyPatch("ChangeHelmetLight")]
		[HarmonyPostfix]
		public static void ChangeHelmetLight(ref Light ___nightVision, ref PlayerControllerB __instance)
		{
			try
			{
			}
			finally
			{
				__instance.helmetLight.intensity = Config.LightIntensity.Value;
				__instance.helmetLight.range = Config.LightRange.Value;
				__instance.helmetLight.spotAngle = Config.LightConeAngle.Value;
				((Component)__instance.helmetLight).GetComponent<HDAdditionalLightData>().affectsVolumetric = Config.LightVolumetricIntensity.Value > 0f;
				((Component)__instance.helmetLight).GetComponent<HDAdditionalLightData>().volumetricDimmer = Config.LightVolumetricIntensity.Value;
				___nightVision.intensity = Config.NightVisionIntensity.Value;
				___nightVision.range = Config.NightVisionRange.Value;
				___nightVision.spotAngle = Config.NightVisionConeAngle.Value;
				((Component)___nightVision).GetComponent<HDAdditionalLightData>().affectsVolumetric = Config.NightVisionVolumetricIntensity.Value > 0f;
				((Component)___nightVision).GetComponent<HDAdditionalLightData>().volumetricDimmer = Config.NightVisionVolumetricIntensity.Value;
			}
		}
	}
}