using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using RopeAnchorFix.Patches; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("RopeAnchorFix")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+547eac5980954cd1eaea844e07ee33fbadaa77c2")] [assembly: AssemblyProduct("RopeAnchorFix")] [assembly: AssemblyTitle("RopeAnchorFix")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.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 RopeAnchorFix { [BepInPlugin("jill920.ropeanchorfix", "Rope Anchor Range Fix", "1.0.0")] public class RopeAnchorFixPlugin : BaseUnityPlugin { public const string MOD_GUID = "jill920.ropeanchorfix"; public const string MOD_NAME = "Rope Anchor Range Fix"; public const string MOD_VERSION = "1.0.0"; public static RopeAnchorFixPlugin Instance { get; private set; } public static ManualLogSource Logger { get; private set; } public static bool DebugMode { get; private set; } private void Awake() { Instance = this; Logger = ((BaseUnityPlugin)this).Logger; DebugMode = ((BaseUnityPlugin)this).Config.Bind("Debug", "EnableLogs", false, "Enable debug logging to console").Value; try { Harmony val = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "jill920.ropeanchorfix"); Logger.LogInfo((object)"[Rope Anchor Range Fix 1.0.0] Loaded successfully!"); Logger.LogInfo((object)$" Blue preview range: {RopeTier_FullFix_Patch.BluePreviewRange}m"); Logger.LogInfo((object)$" Red preview range: {RopeTier_FullFix_Patch.RedPreviewRange}m"); Logger.LogInfo((object)$" Use ground position: {RopeTier_FullFix_Patch.UseGroundPosition}"); if (DebugMode) { Logger.LogInfo((object)" Debug logging: ENABLED"); } } catch (Exception ex) { Logger.LogError((object)("Failed to load: " + ex.Message)); Logger.LogError((object)ex.StackTrace); } } } } namespace RopeAnchorFix.Patches { [HarmonyPatch(typeof(RopeTier))] internal static class RopeTier_FullFix_Patch { [CompilerGenerated] private sealed class d__40 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public Vector3 originalPos; object? IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object? IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__40(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = null; <>1__state = 1; return true; case 1: <>1__state = -1; if ((Object)(object)MainCamera.instance != (Object)null) { ((Component)MainCamera.instance).transform.position = originalPos; } return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static FieldInfo? _maxAnchorGhostDistanceField; private static FieldInfo? _maxAnchorDistanceField; private static FieldInfo? _releaseCheckField; private static FieldInfo? _goodAnchorPlaceField; private static FieldInfo? _ropeAnchorField; private static FieldInfo? _timeWithGoodAnchorField; private static FieldInfo? _itemField; private static FieldInfo? _itemOverrideProgressField; private static FieldInfo? _itemOverrideForceProgressField; private static MethodInfo? _getBodypartMethod; private static FieldInfo? _mainCameraInstanceField; private static Vector3 _lockedAnchorPosition; private static bool _isCasting; public static float BluePreviewRange { get; set; } public static float RedPreviewRange { get; set; } public static bool UseGroundPosition { get; set; } public static float VerticalOffset { get; set; } public static bool UseConsistentRaycastHeight { get; set; } public static float FixedRaycastHeight { get; set; } static RopeTier_FullFix_Patch() { BluePreviewRange = 2f; RedPreviewRange = 2.5f; UseGroundPosition = true; VerticalOffset = 0.07f; UseConsistentRaycastHeight = true; FixedRaycastHeight = 1.2f; Type typeFromHandle = typeof(RopeTier); _maxAnchorGhostDistanceField = AccessTools.Field(typeFromHandle, "maxAnchorGhostDistance"); _maxAnchorDistanceField = AccessTools.Field(typeFromHandle, "maxAnchorDistance"); _releaseCheckField = AccessTools.Field(typeFromHandle, "releaseCheck"); _goodAnchorPlaceField = AccessTools.Field(typeFromHandle, "goodAnchorPlace"); _ropeAnchorField = AccessTools.Field(typeFromHandle, "ropeAnchor"); _timeWithGoodAnchorField = AccessTools.Field(typeFromHandle, "timeWithGoodAnchor"); _itemField = AccessTools.Field(typeFromHandle, "item"); Type typeFromHandle2 = typeof(Item); _itemOverrideProgressField = AccessTools.Field(typeFromHandle2, "overrideProgress"); _itemOverrideForceProgressField = AccessTools.Field(typeFromHandle2, "overrideForceProgress"); _getBodypartMethod = AccessTools.Method(typeof(Character), "GetBodypart", new Type[1] { typeof(BodypartType) }, (Type[])null); Type typeFromHandle3 = typeof(MainCamera); _mainCameraInstanceField = AccessTools.Field(typeFromHandle3, "instance"); } [HarmonyPatch("Update")] [HarmonyTranspiler] private static IEnumerable Transpiler_Update(IEnumerable instructions) { List list = new List(instructions); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldfld && list[i].operand is FieldInfo fieldInfo && fieldInfo == _maxAnchorGhostDistanceField) { list[i].operand = _maxAnchorDistanceField; if (RopeAnchorFixPlugin.DebugMode) { RopeAnchorFixPlugin.Logger.LogInfo((object)"Patched: maxAnchorGhostDistance -> maxAnchorDistance"); } } if (list[i].opcode == OpCodes.Callvirt && list[i].operand is MethodInfo methodInfo && methodInfo.Name == "get_Center" && methodInfo.DeclaringType == typeof(Character)) { list[i].opcode = OpCodes.Call; list[i].operand = AccessTools.Method(typeof(RopeTier_FullFix_Patch), "GetDistancePoint", (Type[])null, (Type[])null); if (RopeAnchorFixPlugin.DebugMode) { RopeAnchorFixPlugin.Logger.LogInfo((object)"Patched: Character.Center -> GetDistancePoint"); } } if (i >= 1 && list[i].opcode == OpCodes.Callvirt && list[i].operand is MethodInfo methodInfo2 && methodInfo2.Name == "get_position" && methodInfo2.DeclaringType == typeof(Transform) && i > 0 && list[i - 1].opcode == OpCodes.Ldsfld && list[i - 1].operand is FieldInfo fieldInfo2 && fieldInfo2 == _mainCameraInstanceField && RopeAnchorFixPlugin.DebugMode) { RopeAnchorFixPlugin.Logger.LogInfo((object)("Found camera position access at index " + i)); } } return list; } [HarmonyPatch("Update")] [HarmonyPrefix] private static void Prefix_Update(RopeTier __instance) { //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Invalid comparison between Unknown and I4 //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Unknown result type (might be due to invalid IL or missing references) //IL_02de: Unknown result type (might be due to invalid IL or missing references) //IL_03c3: Unknown result type (might be due to invalid IL or missing references) if (!((MonoBehaviourPun)__instance).photonView.IsMine) { return; } if (_maxAnchorDistanceField != null) { _maxAnchorDistanceField.SetValue(__instance, BluePreviewRange); } if (_maxAnchorGhostDistanceField != null) { _maxAnchorGhostDistanceField.SetValue(__instance, RedPreviewRange); } if (UseConsistentRaycastHeight && (Object)(object)MainCamera.instance != (Object)null) { Vector3 position = ((Component)MainCamera.instance).transform.position; object? obj = _itemField?.GetValue(__instance); Item val = (Item)((obj is Item) ? obj : null); if ((Object)(object)val != (Object)null && (Object)(object)val.holderCharacter != (Object)null) { Character holderCharacter = val.holderCharacter; Vector3 characterPosition = GetCharacterPosition(holderCharacter); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(position.x, characterPosition.y + FixedRaycastHeight, position.z); ((Component)MainCamera.instance).transform.position = val2; if (RopeAnchorFixPlugin.DebugMode) { RopeAnchorFixPlugin.Logger.LogInfo((object)$"Camera height adjusted: {position.y:F2} -> {val2.y:F2} (fixed height: {FixedRaycastHeight}m above ground)"); } ((MonoBehaviour)__instance).StartCoroutine(RestoreCameraPosition(position)); } } object? obj2 = _itemField?.GetValue(__instance); Item val3 = (Item)((obj2 is Item) ? obj2 : null); if ((Object)(object)val3 == (Object)null || (int)val3.itemState != 1) { _isCasting = false; return; } bool flag = _releaseCheckField != null && (bool)_releaseCheckField.GetValue(__instance); RaycastHit? val4 = _goodAnchorPlaceField?.GetValue(__instance) as RaycastHit?; object obj3 = _ropeAnchorField?.GetValue(__instance); if (!_isCasting && obj3 != null && val4.HasValue && !flag) { _isCasting = true; RaycastHit value = val4.Value; _lockedAnchorPosition = ((RaycastHit)(ref value)).point; if (RopeAnchorFixPlugin.DebugMode) { RopeAnchorFixPlugin.Logger.LogInfo((object)$"=== CASTING STARTED === Anchor locked at: {_lockedAnchorPosition}"); } } if (_isCasting && obj3 != null && val4.HasValue) { RaycastHit value2 = val4.Value; ((RaycastHit)(ref value2)).point = _lockedAnchorPosition; _goodAnchorPlaceField?.SetValue(__instance, value2); Character holderCharacter2 = val3.holderCharacter; if ((Object)(object)holderCharacter2 != (Object)null) { Vector3 characterPosition2 = GetCharacterPosition(holderCharacter2); float num = Vector3.Distance(_lockedAnchorPosition, characterPosition2); if (RopeAnchorFixPlugin.DebugMode && Time.frameCount % 30 == 0) { RopeAnchorFixPlugin.Logger.LogInfo((object)$"Cast distance: {num:F2}m / {BluePreviewRange:F2}m"); } if (num > BluePreviewRange) { if (RopeAnchorFixPlugin.DebugMode) { RopeAnchorFixPlugin.Logger.LogInfo((object)$"=== CAST CANCELLED === Distance {num:F2}m > {BluePreviewRange:F2}m"); } if (_itemOverrideProgressField != null) { _itemOverrideProgressField.SetValue(val3, 0f); } if (_itemOverrideForceProgressField != null) { _itemOverrideForceProgressField.SetValue(val3, false); } if (obj3 != null) { Object.DestroyImmediate((Object)(object)((Component)(RopeAnchor)obj3).gameObject); } if (_ropeAnchorField != null) { _ropeAnchorField.SetValue(__instance, null); } if (_goodAnchorPlaceField != null) { _goodAnchorPlaceField.SetValue(__instance, null); } if (_timeWithGoodAnchorField != null) { _timeWithGoodAnchorField.SetValue(__instance, 0f); } if (_releaseCheckField != null) { _releaseCheckField.SetValue(__instance, false); } _isCasting = false; } } } if (_isCasting && flag && obj3 == null) { _isCasting = false; if (RopeAnchorFixPlugin.DebugMode) { RopeAnchorFixPlugin.Logger.LogInfo((object)"=== CASTING COMPLETED ==="); } } } [IteratorStateMachine(typeof(d__40))] private static IEnumerator RestoreCameraPosition(Vector3 originalPos) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__40(0) { originalPos = originalPos }; } public static Vector3 GetDistancePoint(Character character) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) return GetCharacterPosition(character); } private static Vector3 GetCharacterPosition(Character character) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)character == (Object)null) { return Vector3.zero; } Vector3 val = ((!UseGroundPosition) ? GetBodypartPosition(character) : GetGroundPosition(character)); return val + Vector3.up * VerticalOffset; } private static Vector3 GetBodypartPosition(Character character) { //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_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) if (_getBodypartMethod == null) { return character.Center; } try { object? obj = _getBodypartMethod.Invoke(character, new object[1] { (object)(BodypartType)0 }); Bodypart val = (Bodypart)((obj is Bodypart) ? obj : null); if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).transform != (Object)null) { return ((Component)val).transform.position; } } catch (Exception ex) { if (RopeAnchorFixPlugin.DebugMode) { RopeAnchorFixPlugin.Logger.LogError((object)("Failed to get bodypart: " + ex.Message)); } } return character.Center; } private static Vector3 GetGroundPosition(Character character) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: 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) Vector3 center = character.Center; float num = 3f; RaycastHit val = HelperFunctions.LineCheck(center, center + Vector3.down * num, (LayerType)1, 0f, (QueryTriggerInteraction)1); if ((Object)(object)((RaycastHit)(ref val)).collider != (Object)null) { return ((RaycastHit)(ref val)).point + Vector3.up * 0.1f; } RaycastHit val2 = default(RaycastHit); if (Physics.Raycast(center, Vector3.down, ref val2, num)) { return ((RaycastHit)(ref val2)).point + Vector3.up * 0.1f; } return character.Center - Vector3.up * 0.8f; } } }