using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ScrollThrottle")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("ScrollThrottle")]
[assembly: AssemblyTitle("ScrollThrottle")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 ScrollThrottle
{
[BepInPlugin("sodmods.scrollthrottle", "Scroll Throttle", "1.1.0")]
public class Plugin : BasePlugin
{
internal static ManualLogSource Logger;
internal static ConfigEntry<float> Throttle;
internal static ConfigEntry<float> MinThrottle;
internal static ConfigEntry<float> MaxThrottle;
internal static ConfigEntry<float> Step;
internal static ConfigEntry<bool> ApplyToRun;
internal static ConfigEntry<bool> RememberThrottle;
internal static ConfigEntry<KeyCode> Modifier;
internal static ConfigEntry<KeyCode> ResetKey;
internal static ConfigEntry<bool> InvertScroll;
internal static ConfigEntry<bool> ShowMessages;
internal static ConfigEntry<bool> Detent;
internal static ConfigEntry<float> DetentTime;
public override void Load()
{
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Invalid comparison between Unknown and I4
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
//IL_025e: Expected O, but got Unknown
Logger = ((BasePlugin)this).Log;
Throttle = ((BasePlugin)this).Config.Bind<float>("Throttle", "Current", 1f, "Current throttle (1 = normal speed). Saved between sessions if RememberThrottle is true.");
MinThrottle = ((BasePlugin)this).Config.Bind<float>("Throttle", "Minimum", 0.2f, "Lowest throttle the wheel can set.");
MaxThrottle = ((BasePlugin)this).Config.Bind<float>("Throttle", "Maximum", 1.5f, "Highest throttle the wheel can set.");
Step = ((BasePlugin)this).Config.Bind<float>("Throttle", "Step", 0.1f, "Throttle change per wheel notch.");
ApplyToRun = ((BasePlugin)this).Config.Bind<bool>("Throttle", "ApplyToRun", true, "Scale running speed too. If false, only walking is affected.");
RememberThrottle = ((BasePlugin)this).Config.Bind<bool>("Throttle", "RememberThrottle", true, "Keep the throttle between game sessions. If false it starts at 100% each launch.");
Modifier = ((BasePlugin)this).Config.Bind<KeyCode>("Controls", "ModifierKey", (KeyCode)0, "Key that must be held while scrolling. None = the wheel alone controls the throttle.");
ResetKey = ((BasePlugin)this).Config.Bind<KeyCode>("Controls", "ResetKey", (KeyCode)0, "Key that resets the throttle to 100%. None to disable. Note: middle mouse (Mouse2) is the game's flashlight by default.");
InvertScroll = ((BasePlugin)this).Config.Bind<bool>("Controls", "InvertScroll", false, "Scroll down to speed up instead.");
Detent = ((BasePlugin)this).Config.Bind<bool>("Controls", "DetentAt100", true, "Pause at 100% when scrolling through it, so a quick flick always stops at normal speed.");
DetentTime = ((BasePlugin)this).Config.Bind<float>("Controls", "DetentSeconds", 0.35f, "How long the throttle holds at 100% before further scrolling in the same direction continues.");
ShowMessages = ((BasePlugin)this).Config.Bind<bool>("Display", "ShowMessages", true, "Show an on-screen speed notification.");
ConfigEntry<int> val = ((BasePlugin)this).Config.Bind<int>("Internal", "ConfigVersion", 1, "Used to migrate old settings. Don't edit.");
if (val.Value < 2)
{
if ((int)ResetKey.Value == 325)
{
ResetKey.Value = (KeyCode)0;
}
val.Value = 2;
}
if (!RememberThrottle.Value)
{
Throttle.Value = 1f;
}
Throttle.Value = Mathf.Clamp(Throttle.Value, MinThrottle.Value, MaxThrottle.Value);
new Harmony("sodmods.scrollthrottle").PatchAll(typeof(Plugin).Assembly);
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(34, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Scroll Throttle loaded (throttle ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(Throttle.Value, "P0");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(")");
}
log.LogInfo(val2);
}
}
[HarmonyPatch(typeof(Player), "SetMaxSpeed")]
internal static class SetMaxSpeedPatch
{
internal static float BaseWalk = -1f;
internal static float BaseRun = -1f;
private static void Prefix(Player __instance, ref float newWalkSpeed, ref float newRunSpeed)
{
BaseWalk = newWalkSpeed;
BaseRun = newRunSpeed;
if (!__instance.transitionActive)
{
float value = Plugin.Throttle.Value;
newWalkSpeed *= value;
if (Plugin.ApplyToRun.Value)
{
newRunSpeed *= value;
}
}
}
internal static void Reapply()
{
Player instance = Player.Instance;
if (!((Object)(object)instance == (Object)null) && !(BaseWalk < 0f) && !instance.transitionActive)
{
instance.SetMaxSpeed(BaseWalk, BaseRun);
}
}
}
[HarmonyPatch(typeof(Player), "Update")]
internal static class PlayerUpdatePatch
{
private static float pendingMessageAt = -1f;
private static float detentUntil = -1f;
private static void Postfix()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!InFreeMovement())
{
return;
}
KeyCode value = Plugin.Modifier.Value;
if ((int)value != 0 && !Input.GetKey(value))
{
return;
}
KeyCode value2 = Plugin.ResetKey.Value;
if ((int)value2 != 0 && Input.GetKeyDown(value2))
{
SetThrottle(1f);
return;
}
float y = Input.mouseScrollDelta.y;
if (Mathf.Abs(y) > 0.01f)
{
Scroll(Mathf.Sign(y) * (Plugin.InvertScroll.Value ? (-1f) : 1f));
}
if (pendingMessageAt > 0f && Time.unscaledTime >= pendingMessageAt)
{
pendingMessageAt = -1f;
ShowMessage();
}
}
catch (Exception ex)
{
Plugin.Logger.LogError((object)ex);
}
}
private static void Scroll(float direction)
{
float unscaledTime = Time.unscaledTime;
float value = Plugin.Throttle.Value;
float num = value + direction * Plugin.Step.Value;
if (Plugin.Detent.Value)
{
bool flag = Mathf.Abs(value - 1f) < 0.001f;
if (flag && unscaledTime < detentUntil)
{
detentUntil = unscaledTime + Plugin.DetentTime.Value;
return;
}
if ((value < 1f && num > 1f) || (value > 1f && num < 1f))
{
num = 1f;
}
if (!flag && Mathf.Abs(num - 1f) < 0.001f)
{
detentUntil = unscaledTime + Plugin.DetentTime.Value;
}
}
SetThrottle(num);
}
private static void SetThrottle(float value)
{
float num = Mathf.Clamp(Mathf.Round(value * 100f) / 100f, Plugin.MinThrottle.Value, Plugin.MaxThrottle.Value);
if (!Mathf.Approximately(num, Plugin.Throttle.Value))
{
Plugin.Throttle.Value = num;
SetMaxSpeedPatch.Reapply();
pendingMessageAt = Time.unscaledTime + 0.35f;
}
}
private static void ShowMessage()
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.ShowMessages.Value && !((Object)(object)InterfaceController.Instance == (Object)null))
{
InterfaceController.Instance.NewGameMessage((GameMessageType)0, 0, $"Speed {Plugin.Throttle.Value:P0}", (Icon)16, (AudioEvent)null, false, default(Color), -1, 0f, (RectTransform)null, (PingOnComplete)0, (Evidence)null, (List<DataKey>)null, (Sprite)null);
}
}
private static bool InFreeMovement()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Invalid comparison between Unknown and I4
if ((Object)(object)SessionData.Instance == (Object)null || !SessionData.Instance.play)
{
return false;
}
if ((int)Cursor.lockState != 1)
{
return false;
}
if ((Object)(object)InterfaceController.Instance != (Object)null && InterfaceController.Instance.desktopMode)
{
return false;
}
if ((Object)(object)InteractionController.Instance != (Object)null && InteractionController.Instance.dialogMode)
{
return false;
}
return true;
}
}
}