Decompiled source of BetterScanVision v0.0.6

BetterScanVision.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Extensions;
using CSync.Lib;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("LethalConfig")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("BetterScanVision")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Light your way through the darkness with every scan. Highly configurable.")]
[assembly: AssemblyFileVersion("0.0.6.0")]
[assembly: AssemblyInformationalVersion("0.0.6")]
[assembly: AssemblyProduct("BetterScanVision")]
[assembly: AssemblyTitle("BetterScanVision")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.6.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 BetterScanVision
{
	[BepInPlugin("DBJ.BetterScanVision", "BetterScanVision", "0.0.6")]
	[BepInDependency("com.sigurd.csync", "5.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BetterScanVisionBase : BaseUnityPlugin
	{
		internal const string modGUID = "DBJ.BetterScanVision";

		internal const string modName = "BetterScanVision";

		internal const string internalmodVersion = "0.0.6";

		internal static readonly Harmony harmony = new Harmony("DBJ.BetterScanVision");

		internal static readonly ManualLogSource mls = Logger.CreateLogSource("DBJ.BetterScanVision");

		internal static ConfigFile configFile;

		internal static SyncedConfigValues configValues;

		internal static readonly AnimationCurve scanTimeCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[4]
		{
			new Keyframe(0f, 0f),
			new Keyframe(0.43f, 1f),
			new Keyframe(0.72f, 1f),
			new Keyframe(1f, 0f)
		});

		private void LocalConfigUpdate_visionColor(object sender = null, EventArgs e = null)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<string> entry = configValues.visionColor.Entry;
			entry.SettingChanged -= LocalConfigUpdate_visionColor;
			Color val = default(Color);
			if (!ColorUtility.TryParseHtmlString("#" + entry.Value, ref val))
			{
				ColorUtility.TryParseHtmlString("#0E154C", ref val);
				mls.LogWarning((object)("[Local] Night Vision Color \"" + entry.Value + "\" could not be parsed; it will be replaced with the default value \"0E154C\"!"));
			}
			val.a = 1f;
			entry.Value = ColorUtility.ToHtmlStringRGB(val);
			entry.SettingChanged += LocalConfigUpdate_visionColor;
		}

		private void Awake()
		{
			mls.LogInfo((object)"[Awake Log 1 / 3] Initializing BetterScanVision...");
			configFile = ((BaseUnityPlugin)this).Config;
			configValues = new SyncedConfigValues(configFile);
			LocalConfigUpdate_visionColor();
			if (LethalConfigCompat.IsAvailable)
			{
				LethalConfigCompat.AddConfigItem(configValues.visionRangeMaxScalar.Entry);
				LethalConfigCompat.AddConfigItem(configValues.visionIntensityMaxScalar.Entry);
				LethalConfigCompat.AddConfigItem(configValues.visionDuration.Entry);
				LethalConfigCompat.AddConfigItem(configValues.visionColor.Entry);
				LethalConfigCompat.AddConfigItem(configValues.outdoorsVisionRangeScalar.Entry);
				LethalConfigCompat.AddConfigItem(configValues.outdoorsVisionIntensityScalar.Entry);
			}
			mls.LogInfo((object)"[Awake Log 2 / 3] Config initialized...");
			harmony.PatchAll();
			mls.LogInfo((object)"[Awake Log 3 / 3] Patched PlayerControllerB methods!");
		}
	}
	internal class SyncedConfigValues : SyncedConfig2<SyncedConfigValues>
	{
		[SyncedEntryField]
		internal SyncedEntry<float> visionRangeMaxScalar = null;

		[SyncedEntryField]
		internal SyncedEntry<float> visionIntensityMaxScalar = null;

		[SyncedEntryField]
		internal SyncedEntry<float> visionDuration = null;

		[SyncedEntryField]
		internal SyncedEntry<string> visionColor = null;

		[SyncedEntryField]
		internal SyncedEntry<float> outdoorsVisionRangeScalar = null;

		[SyncedEntryField]
		internal SyncedEntry<float> outdoorsVisionIntensityScalar = null;

		internal const float scanDuration = 1.3f;

		internal const float visionDurationDefault = 0.49f;

		internal const string visionColorDefault = "0E154C";

		internal Color visionColorParsed;

		private void ConfigUpdate_visionColor(object sender = null, EventArgs e = null)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			visionColor.Changed -= ConfigUpdate_visionColor;
			if (!ColorUtility.TryParseHtmlString("#" + visionColor.Value, ref visionColorParsed))
			{
				ColorUtility.TryParseHtmlString("#0E154C", ref visionColorParsed);
				BetterScanVisionBase.mls.LogWarning((object)("[Synced] Night Vision Color \"" + visionColor.Value + "\" could not be parsed; it will be replaced with the default value \"0E154C\"!"));
			}
			visionColorParsed.a = 1f;
			if ((Object)(object)PlayerControllerBPatches.nightVision != (Object)null)
			{
				PlayerControllerBPatches.nightVision.color = visionColorParsed;
			}
			visionColor.Changed += ConfigUpdate_visionColor;
		}

		internal SyncedConfigValues(ConfigFile configFile)
			: base("DBJ.BetterScanVision")
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Expected O, but got Unknown
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			visionRangeMaxScalar = SyncedBindingExtensions.BindSyncedEntry<float>(configFile, "Night Vision Parameters", "Night Vision Range Maximum Scalar", 2.8f, new ConfigDescription("Scales the night vision's maximum range in relation to the vanilla night vision's range. A higher number means an extended night vision range at the scan's peak | a lower number means a decreased night vision range.\n\n1 = unchanged | 0 = disabled", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>()));
			visionIntensityMaxScalar = SyncedBindingExtensions.BindSyncedEntry<float>(configFile, "Night Vision Parameters", "Night Vision Intensity Maximum Scalar", 10f, new ConfigDescription("Scales the night vision's maximum intensity in relation to the vanilla night vision's intensity. A higher number means an extended night vision intensity at the scan's peak | a lower number means a decreased night vision range.\n\n1 = unchanged | 0 = disabled", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>()));
			visionDuration = SyncedBindingExtensions.BindSyncedEntry<float>(configFile, "Night Vision Parameters", "Night Vision Duration", 0.49f, new ConfigDescription("Sets the night vision's duration in seconds. A higher number means an extended night vision duration | a lower number means a decreased night vision duration.", (AcceptableValueBase)new AcceptableValueRange<float>(0.001f, 1.3f), Array.Empty<object>()));
			visionColor = SyncedBindingExtensions.BindSyncedEntry<string>(configFile, "Night Vision Parameters", "Night Vision Color", "0E154C", "Sets the night vision's color in the form of a hex color code (\"RRGGBB\"). Alpha values will be discarded.");
			outdoorsVisionRangeScalar = SyncedBindingExtensions.BindSyncedEntry<float>(configFile, "Outdoors Night Vision Parameters", "Outdoors Night Vision Range Scalar", 150f, new ConfigDescription("Scales the night vision's range while outdoors. A higher number means an extended night vision range while outdoors | a lower number means a decreased night vision range.\n\n1 = unchanged | 0 = disabled", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>()));
			outdoorsVisionIntensityScalar = SyncedBindingExtensions.BindSyncedEntry<float>(configFile, "Outdoors Night Vision Parameters", "Outdoors Night Vision Intensity Scalar", 12f, new ConfigDescription("Scales the night vision's intensity while outdoors. A higher number means an extended night vision intensity while outdoors | a lower number means a decreased night vision intensity.\n\n1 = unchanged | 0 = disabled", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>()));
			ConfigUpdate_visionColor();
			ConfigManager.Register<SyncedConfigValues>((SyncedConfig2<SyncedConfigValues>)this);
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatches
	{
		internal const float base_intensity = 366.9317f;

		internal const float base_range = 12f;

		internal static Light nightVision;

		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		public static void LateUpdatePostfix(PlayerControllerB __instance)
		{
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)(object)StartOfRound.Instance?.localPlayerController)
			{
				return;
			}
			if ((Object)(object)nightVision == (Object)null || !((Behaviour)nightVision).isActiveAndEnabled || (Object)(object)((Component)nightVision).transform.parent != (Object)(object)((Component)__instance).transform)
			{
				Light component = __instance.nightVision;
				if ((Object)(object)component == (Object)null)
				{
					BetterScanVisionBase.mls.LogError((object)"[PlayerControllerB.LateUpdate() Postfix] Could not find PlayerControllerB.nightVision (another mod has tampered with it). Attempting to find any equivalent in the scene (another error will be thrown if this attempt fails; even if it succeeds, the results may not look correct)");
					GameObject val = GameObject.Find("NightVision");
					if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponent<Light>() == (Object)null)
					{
						BetterScanVisionBase.mls.LogError((object)"[PlayerControllerB.LateUpdate() Postfix] Could not find a PlayerControllerB.nightVision equivalent! Unpatching and aborting!");
						Harmony.UnpatchAll();
						return;
					}
					component = val.GetComponent<Light>();
				}
				nightVision = Object.Instantiate<Light>(component, ((Component)__instance).transform);
				nightVision.type = (LightType)2;
				nightVision.shape = (LightShape)0;
				nightVision.spotAngle = 30f;
				nightVision.innerSpotAngle = 21.80208f;
				nightVision.colorTemperature = 11762f;
				nightVision.useColorTemperature = true;
				nightVision.bounceIntensity = 0f;
				nightVision.useBoundingSphereOverride = false;
				nightVision.useViewFrustumForShadowCasterCull = true;
				nightVision.shadowCustomResolution = -1;
				nightVision.shadowBias = 0.05f;
				nightVision.shadowNormalBias = 0.4f;
				nightVision.shadowNearPlane = 0.2f;
				nightVision.useShadowMatrixOverride = false;
				nightVision.cullingMask = -1;
				nightVision.renderingLayerMask = 1;
				nightVision.lightShadowCasterMode = (LightShadowCasterMode)2;
				nightVision.shadows = (LightShadows)0;
				nightVision.renderMode = (LightRenderMode)0;
				nightVision.color = BetterScanVisionBase.configValues.visionColorParsed;
			}
			float num = 0.3f - (HUDManager.Instance?.playerPingingScan ?? (-1f));
			float num2 = Mathf.Clamp(num / BetterScanVisionBase.configValues.visionDuration.Value, 0f, 1f);
			float num3 = BetterScanVisionBase.scanTimeCurve.Evaluate(num2);
			float num4 = BetterScanVisionBase.configValues.visionIntensityMaxScalar.Value;
			float num5 = BetterScanVisionBase.configValues.visionRangeMaxScalar.Value;
			if (!__instance.isInsideFactory && !__instance.isInHangarShipRoom)
			{
				num4 *= BetterScanVisionBase.configValues.outdoorsVisionIntensityScalar.Value;
				num5 *= BetterScanVisionBase.configValues.outdoorsVisionRangeScalar.Value;
			}
			nightVision.intensity = Mathf.Lerp(0f, 366.9317f * num4, num3);
			nightVision.range = Mathf.Lerp(0f, 12f * num5, num3);
			((Behaviour)nightVision).enabled = true;
		}
	}
	internal static class LethalConfigCompat
	{
		private const string GUID = "ainavt.lc.lethalconfig";

		internal static bool IsAvailable => Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void AddConfigItem(ConfigEntry<int> entry, bool isSlider = true, bool restartRequired = false)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			if (IsAvailable)
			{
				if (isSlider)
				{
					LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(entry, restartRequired));
				}
				else
				{
					LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(entry, restartRequired));
				}
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void AddConfigItem(ConfigEntry<float> entry, bool isSlider = true, bool restartRequired = false)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			if (IsAvailable)
			{
				if (isSlider)
				{
					LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(entry, restartRequired));
				}
				else
				{
					LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(entry, restartRequired));
				}
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void AddConfigItem(ConfigEntry<bool> entry, bool restartRequired = false)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			if (IsAvailable)
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(entry, restartRequired));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void AddConfigItem(ConfigEntry<string> entry, bool isDropdown = false, bool restartRequired = false)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			if (IsAvailable)
			{
				if (isDropdown)
				{
					LethalConfigManager.AddConfigItem((BaseConfigItem)new TextDropDownConfigItem(entry, restartRequired));
				}
				else
				{
					LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(entry, restartRequired));
				}
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void AddConfigItem(ConfigEntry<Enum> entry, bool restartRequired = false)
		{
			if (IsAvailable)
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<Enum>(entry, restartRequired));
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BetterScanVision";

		public const string PLUGIN_NAME = "BetterScanVision";

		public const string PLUGIN_VERSION = "0.0.6";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}