using System;
using System.Diagnostics;
using System.IO;
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 LC_QOLTweaks.Config;
using LC_QOLTweaks.Patches;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LC_QOLTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LC_QOLTweaks")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3be32523-19c4-4efc-b55a-3fb759a87320")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LC_QOLTweaks
{
public abstract class Plugin
{
public const string Guid = "com.snazzy.LC_QOLTweaks";
public const string Name = "LC_QOLTweaks";
public const string Version = "0.0.1";
}
[BepInPlugin("com.snazzy.LC_QOLTweaks", "LC_QOLTweaks", "0.0.1")]
public class PluginBase : BaseUnityPlugin
{
private static PluginBase _instance;
private readonly Harmony _harmonyHook = new Harmony("com.snazzy.LC_QOLTweaks");
private static ManualLogSource ManualLogSource { get; set; }
private void Awake()
{
InitSingleton();
InitStartup();
InitHarmonyHooks();
}
private void InitSingleton()
{
InitLogSource();
if ((Object)(object)_instance == (Object)null)
{
_instance = this;
ManualLogSource.LogMessage((object)"Instance set.");
}
else
{
ManualLogSource.LogWarning((object)"Duplicate instance of PluginBase detected!");
}
}
private void InitHarmonyHooks()
{
try
{
_harmonyHook.PatchAll(typeof(PluginBase));
_harmonyHook.PatchAll(typeof(RoundManagerPatch));
_harmonyHook.PatchAll(typeof(TimeOfDayPatch));
_harmonyHook.PatchAll(typeof(PlayerControllerBPatch));
ManualLogSource.LogMessage((object)"Patching with Harmony complete.");
}
catch (Exception arg)
{
ManualLogSource.LogFatal((object)$"Failed to apply patches with Harmony: {arg}");
}
}
private static void InitLogSource()
{
ManualLogSource = Logger.CreateLogSource("com.snazzy.LC_QOLTweaks");
}
private static void InitStartup()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: 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)
ManualLogSource.LogMessage((object)"Loaded LC_QOLTweaks.");
try
{
ManualLogSource.LogMessage((object)$"ToggleSpectateCamera keybinding set to: {Binds.ToggleSpectateCamera.Value}");
ManualLogSource.LogMessage((object)$"ToggleClockVisibility keybinding set to: {Binds.ToggleClockVisibility.Value}");
ManualLogSource.LogMessage((object)$"ToggleInfSprint keybinding set to: {Binds.ToggleInfSprint.Value}");
}
catch (Exception arg)
{
ManualLogSource.LogError((object)$"Keybindings not created: {arg}");
}
}
public static ManualLogSource GetManualLogSource()
{
return ManualLogSource;
}
}
}
namespace LC_QOLTweaks.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
private const float Offset = 1.5f;
private static bool _firstPerson = true;
private static bool _spectatingDebounce;
private static bool _infSprintState = true;
private static bool _infSprintDebounce;
[HarmonyPatch("LateUpdate")]
[HarmonyPostfix]
private static void ToggleSpectatorCamera(PlayerControllerB __instance)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: 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_00b2: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
if (((ButtonControl)Keyboard.current[Binds.ToggleSpectateCamera.Value]).wasPressedThisFrame && !_spectatingDebounce)
{
_firstPerson = !_firstPerson;
_spectatingDebounce = true;
}
if (((ButtonControl)Keyboard.current[Binds.ToggleSpectateCamera.Value]).wasReleasedThisFrame)
{
_spectatingDebounce = false;
}
if (!((Object)(object)__instance.spectatedPlayerScript == (Object)null) && _firstPerson)
{
Transform transform = ((Component)__instance.spectateCameraPivot).transform;
Transform transform2 = ((Component)__instance.spectatedPlayerScript.visorCamera).transform;
Vector3 position = transform2.position;
Vector3 forward = transform2.forward;
transform.position = position + ((Vector3)(ref forward)).normalized * 1.5f;
transform.rotation = transform2.rotation;
PluginBase.GetManualLogSource().LogMessage((object)("Changed spectate camera view to " + (_firstPerson ? "First Person." : "Default.")));
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void ToggleInfSprint(ref float ___sprintMeter)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
StartOfRound instance = StartOfRound.Instance;
if (((ButtonControl)Keyboard.current[Binds.ToggleInfSprint.Value]).wasPressedThisFrame && !_infSprintDebounce && !instance.localPlayerController.inTerminalMenu)
{
_infSprintState = !_infSprintState;
_infSprintDebounce = true;
HUDManager.Instance.DisplayTip("Infinite Sprint", "Toggle set to: " + (_infSprintState ? "ON" : "OFF"), false, false, "LC_Tip1");
}
if (((ButtonControl)Keyboard.current[Binds.ToggleInfSprint.Value]).wasReleasedThisFrame)
{
_infSprintDebounce = false;
}
if (_infSprintState)
{
___sprintMeter = 1f;
}
}
}
[HarmonyPatch(typeof(TimeOfDay))]
internal class TimeOfDayPatch
{
private static bool _visible = true;
[HarmonyPatch("SetInsideLightingDimness")]
[HarmonyPostfix]
private static void SetClockVisible()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
if (((ButtonControl)Keyboard.current[Binds.ToggleClockVisibility.Value]).wasPressedThisFrame)
{
_visible = !_visible;
}
if (TimeOfDay.Instance.insideLighting)
{
if (_visible)
{
HUDManager.Instance.SetClockVisible(true);
}
else if (!_visible)
{
HUDManager.Instance.SetClockVisible(false);
}
}
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
[HarmonyPatch("SpawnScrapInLevel")]
[HarmonyPostfix]
private static void GetScrapValuesInLevel()
{
HUDManager instance = HUDManager.Instance;
SelectableLevel currentLevel = RoundManager.Instance.currentLevel;
try
{
instance.DisplayTip("Current scrap in level", $"Minimum of {currentLevel.minScrap} scrap items with a value of {currentLevel.minTotalScrapValue}. " + $"Maximum of {currentLevel.maxScrap} scrap items with a value of {currentLevel.maxTotalScrapValue}.", false, false, "LC_Tip1");
}
catch (Exception ex)
{
PluginBase.GetManualLogSource().LogFatal((object)ex);
}
}
}
}
namespace LC_QOLTweaks.Config
{
internal static class Binds
{
public static ConfigFile ConfigFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "QOLTweaks.cfg"), true);
public static ConfigEntry<Key> ToggleSpectateCamera = ConfigFile.Bind<Key>(new ConfigDefinition("Keybindings", "ToggleSpectateCamera"), (Key)36, new ConfigDescription("Toggle from the default camera view to first person camera view", (AcceptableValueBase)null, Array.Empty<object>()));
public static ConfigEntry<Key> ToggleClockVisibility = ConfigFile.Bind<Key>(new ConfigDefinition("Keybindings", "ToggleClockVisibility"), (Key)38, new ConfigDescription("Toggle the clock visibility", (AcceptableValueBase)null, Array.Empty<object>()));
public static ConfigEntry<Key> ToggleInfSprint = ConfigFile.Bind<Key>(new ConfigDefinition("Keybindings", "ToggleInfSprint"), (Key)28, new ConfigDescription("Toggle infinite sprint", (AcceptableValueBase)null, Array.Empty<object>()));
}
}