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 NightVision.Patches;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NightVision")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NightVision")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("30558705-be06-4ac4-ba83-bce5f1f25495")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NightVision
{
[BepInPlugin("Ken.NightVision", "Toggleable Night Vision", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private const string PLUGIN_GUID = "Ken.NightVision";
private const string PLUGIN_NAME = "Toggleable Night Vision";
private const string PLUGIN_VERSION = "1.0.0";
public static Harmony _harmony = new Harmony("NightVision");
internal static ManualLogSource mls;
private static ConfigEntry<string> cfgKeyBind;
public static ConfigEntry<float> intensity;
private void Awake()
{
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Expected O, but got Unknown
_harmony.PatchAll(typeof(NightVisionPatch));
mls = Logger.CreateLogSource("Ken.NightVision");
mls.LogInfo((object)"NightVision loaded");
cfgKeyBind = ((BaseUnityPlugin)this).Config.Bind<string>("Toggle Button", "Key", "C", "Button to toggle night vision mode in the bunker.");
intensity = ((BaseUnityPlugin)this).Config.Bind<float>("Numeric Values", "Intensity", 7500f, "Intensity of the night vision when toggled. [Originally was 100000]");
InputAction val = new InputAction((string)null, (InputActionType)0, "<Keyboard>/" + cfgKeyBind.Value, (string)null, (string)null, (string)null);
val.performed += OnInsertKeyPressed;
val.Enable();
}
private void OnInsertKeyPressed(CallbackContext obj)
{
NightVisionPatch.toggled = !NightVisionPatch.toggled;
mls.LogDebug((object)("Night mode " + (NightVisionPatch.toggled ? "enabled" : "disabled")));
}
}
}
namespace NightVision.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class NightVisionPatch
{
internal static bool toggled;
private static MethodInfo TargetMethod()
{
return typeof(PlayerControllerB).GetMethod("SetNightVisionEnabled", BindingFlags.Instance | BindingFlags.NonPublic);
}
[HarmonyPrefix]
private static void Prefix(PlayerControllerB __instance)
{
if (toggled)
{
__instance.nightVision.intensity = Plugin.intensity.Value;
__instance.nightVision.range = 100000f;
__instance.nightVision.shadowStrength = 0f;
__instance.nightVision.shadows = (LightShadows)0;
__instance.nightVision.shape = (LightShape)2;
}
else
{
__instance.nightVision.intensity = 366.9317f;
__instance.nightVision.range = 12f;
__instance.nightVision.shadowStrength = 1f;
__instance.nightVision.shadows = (LightShadows)0;
__instance.nightVision.shape = (LightShape)0;
}
}
}
}