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 UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BetterRopePlacement")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+81edd1fdcdd9e38faecf25c4eb9c31830c042fc4")]
[assembly: AssemblyProduct("BetterRopePlacement")]
[assembly: AssemblyTitle("BetterRopePlacement")]
[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 ABUF.BetterRopePlacement
{
[BepInPlugin("abuf.betterropeplacement", "Better Rope Placement", "1.1.0")]
public sealed class Plugin : BaseUnityPlugin
{
public const string Guid = "abuf.betterropeplacement";
public const string PluginName = "Better Rope Placement";
public const string PluginVersion = "1.1.0";
public static ManualLogSource Log;
public static ConfigEntry<float> MaxDistance;
public static ConfigEntry<float> CastTime;
public static ConfigEntry<float> Damping;
private void Awake()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Expected O, but got Unknown
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
MaxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("绳索", "最大放置距离", 4f, new ConfigDescription("绳结可以放置的最大距离(米,从身体中心算)。原版是 2.2 米,调到 4 米就能少做几次后空翻。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2.2f, 4f), Array.Empty<object>()));
CastTime = ((BaseUnityPlugin)this).Config.Bind<float>("绳索", "读条时间", 0.5f, new ConfigDescription("打绳结需要按住的时间(秒)。越小越快;原版约 1 秒。范围 0.2 ~ 1 秒。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 1f), Array.Empty<object>()));
Damping = ((BaseUnityPlugin)this).Config.Bind<float>("绳索", "晃动阻尼", 8f, new ConfigDescription("绳索放置后抑制来回飘荡的强度;0 = 原版物理,数值越大越稳。范围 0 ~ 20。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), Array.Empty<object>()));
new Harmony("abuf.betterropeplacement").PatchAll();
Log.LogInfo((object)("Better Rope Placement 1.1.0 loaded. distance=" + MaxDistance.Value + " cast=" + CastTime.Value + " damping=" + Damping.Value));
}
}
[HarmonyPatch(typeof(RopeTier), "Update")]
internal static class RopePlacementPatch
{
private static readonly ConditionalWeakTable<RopeTier, float[]> Originals = new ConditionalWeakTable<RopeTier, float[]>();
[HarmonyPrefix]
private static void Prefix(RopeTier __instance)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Invalid comparison between Unknown and I4
if (!((Object)(object)__instance == (Object)null) && !((Object)(object)((ItemComponent)__instance).item == (Object)null) && (int)((ItemComponent)__instance).item.itemState == 1)
{
if (!Originals.TryGetValue(__instance, out var value))
{
value = new float[3] { __instance.maxAnchorDistance, __instance.maxAnchorGhostDistance, __instance.castTime };
Originals.Add(__instance, value);
}
float num = (__instance.maxAnchorDistance = Mathf.Clamp(Plugin.MaxDistance.Value, 2.2f, 4f));
if (__instance.maxAnchorGhostDistance < num)
{
__instance.maxAnchorGhostDistance = num;
}
float castTime = Mathf.Clamp(Plugin.CastTime.Value, 0.2f, value[2]);
__instance.castTime = castTime;
}
}
}
[HarmonyPatch(typeof(RopeSegment), "Awake")]
internal static class RopeDampingPatch
{
[HarmonyPostfix]
private static void Postfix(RopeSegment __instance)
{
if ((Object)(object)__instance == (Object)null)
{
return;
}
float num = Mathf.Clamp(Plugin.Damping.Value, 0f, 20f);
if (!(num <= 0f))
{
Rigidbody component = ((Component)__instance).GetComponent<Rigidbody>();
if (!((Object)(object)component == (Object)null))
{
component.linearDamping = Mathf.Max(component.linearDamping, num * 0.15f);
component.angularDamping = Mathf.Max(component.angularDamping, num);
}
}
}
}
}