using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GloveRangeAdjust")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8e9847e3388e9880788b13cd235e8ccfc51ffc87")]
[assembly: AssemblyProduct("GloveRangeAdjust")]
[assembly: AssemblyTitle("GloveRangeAdjust")]
[assembly: AssemblyVersion("1.0.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 GloveRangeAdjust
{
[BepInPlugin("com.ttr.gloverangeadjust", "GloveRangeAdjust", "1.1.2")]
public class GloveRangeAdjustPlugin : BaseUnityPlugin
{
public const string PluginGuid = "com.ttr.gloverangeadjust";
public const string PluginName = "GloveRangeAdjust";
public const string PluginVersion = "1.1.2";
internal static ManualLogSource Log;
internal static ConfigEntry<float> ScrollSensitivity;
internal static ConfigEntry<float> GamepadStep;
internal static ConfigEntry<float> MinRange;
internal static ConfigEntry<float> MaxRangeOverride;
public static bool IsGloveRangeActive;
public static bool IsGlovePressing;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
ScrollSensitivity = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ScrollSensitivity", 0.5f, "How much each scroll wheel notch adjusts the levitation distance.");
GamepadStep = ((BaseUnityPlugin)this).Config.Bind<float>("Gamepad", "Step", 0.5f, "Distance change per LB/RB press on gamepad.");
MinRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MinRange", 1.5f, "Minimum levitation distance (metres). Prevents items from clipping into the player.");
MaxRangeOverride = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxRangeOverride", 0f, "Maximum levitation distance override (metres). 0 = use the glove's built-in maxDistance.");
Harmony.CreateAndPatchAll(typeof(GlovePatches), "com.ttr.gloverangeadjust");
Log.LogInfo((object)"GloveRangeAdjust v1.1.2 loaded.");
}
}
internal static class GlovePatches
{
private static readonly FieldInfo _pressingField = AccessTools.Field(typeof(GnomiumGloves), "pressing");
private static readonly FieldInfo _pushableField = AccessTools.Field(typeof(GnomiumGloves), "pushable");
private static readonly FieldInfo _currentPushDistanceField = AccessTools.Field(typeof(GnomiumGloves), "currentPushDistance");
private static readonly FieldInfo _maxDistanceField = AccessTools.Field(typeof(GnomiumGloves), "maxDistance");
private static float _lbHoldTime = -1f;
private static float _rbHoldTime = -1f;
private const float RepeatDelay = 0.3f;
private const float RepeatRate = 0.08f;
[HarmonyPatch(typeof(GnomiumGloves), "OnFixedUpdate")]
[HarmonyPrefix]
internal static void OnFixedUpdatePrefix(GnomiumGloves __instance)
{
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!((NetworkBehaviour)__instance).IsLocalPlayer)
{
GloveRangeAdjustPlugin.IsGloveRangeActive = false;
GloveRangeAdjustPlugin.IsGlovePressing = false;
return;
}
if (!(bool)_pressingField.GetValue(__instance))
{
GloveRangeAdjustPlugin.IsGloveRangeActive = false;
GloveRangeAdjustPlugin.IsGlovePressing = false;
ResetRepeatTimers();
return;
}
GloveRangeAdjustPlugin.IsGlovePressing = true;
if (_pushableField.GetValue(__instance) == null)
{
GloveRangeAdjustPlugin.IsGloveRangeActive = false;
ResetRepeatTimers();
return;
}
GloveRangeAdjustPlugin.IsGloveRangeActive = true;
float num = (float)_currentPushDistanceField.GetValue(__instance);
float num2 = (float)_maxDistanceField.GetValue(__instance);
float num3 = ((GloveRangeAdjustPlugin.MaxRangeOverride.Value > 0f) ? GloveRangeAdjustPlugin.MaxRangeOverride.Value : num2);
float value = GloveRangeAdjustPlugin.MinRange.Value;
float y = Input.mouseScrollDelta.y;
if (Mathf.Abs(y) > 0.01f)
{
num += y * GloveRangeAdjustPlugin.ScrollSensitivity.Value;
}
Gamepad current = Gamepad.current;
if (current != null)
{
float value2 = GloveRangeAdjustPlugin.GamepadStep.Value;
float unscaledTime = Time.unscaledTime;
bool isPressed = current.leftShoulder.isPressed;
bool isPressed2 = current.rightShoulder.isPressed;
if (isPressed)
{
if (_lbHoldTime < 0f)
{
num -= value2;
_lbHoldTime = unscaledTime;
}
else if (unscaledTime - _lbHoldTime >= 0.3f)
{
float num4 = unscaledTime - _lbHoldTime - 0.3f;
float num5 = _lbHoldTime + 0.3f + (float)(int)(num4 / 0.08f) * 0.08f;
if (unscaledTime - num5 >= 0f)
{
num -= value2 * 0.3f;
_lbHoldTime = unscaledTime - 0.3f - num4 % 0.08f;
}
}
}
else
{
_lbHoldTime = -1f;
}
if (isPressed2)
{
if (_rbHoldTime < 0f)
{
num += value2;
_rbHoldTime = unscaledTime;
}
else if (unscaledTime - _rbHoldTime >= 0.3f)
{
float num6 = unscaledTime - _rbHoldTime - 0.3f;
float num7 = _rbHoldTime + 0.3f + (float)(int)(num6 / 0.08f) * 0.08f;
if (unscaledTime - num7 >= 0f)
{
num += value2 * 0.3f;
_rbHoldTime = unscaledTime - 0.3f - num6 % 0.08f;
}
}
}
else
{
_rbHoldTime = -1f;
}
}
num = Mathf.Clamp(num, value, num3);
_currentPushDistanceField.SetValue(__instance, num);
}
catch (Exception arg)
{
GloveRangeAdjustPlugin.IsGloveRangeActive = false;
GloveRangeAdjustPlugin.IsGlovePressing = false;
GloveRangeAdjustPlugin.Log.LogWarning((object)$"OnFixedUpdate prefix error: {arg}");
}
}
private static void ResetRepeatTimers()
{
_lbHoldTime = -1f;
_rbHoldTime = -1f;
}
}
}