Decompiled source of AnchorImprovements v1.1.5

AnchorImprovements.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AnchorRework")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AnchorRework")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1b4ae26a-cac3-415c-8208-6a87974cddf7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AnchorRework;

internal class LookTextPatch
{
	[HarmonyPatch(typeof(LookUI), "ShowLookText")]
	private static class ControlHintPatch
	{
		public static void Postfix(LookUI __instance, GoPointer ___pointer, GoPointerButton button, TextMesh ___controlsText, TextMesh ___textLicon, TextMesh ___textRIcon, bool ___altIconsOn, bool ___showingIcon)
		{
			if (button is PickupableBoatAnchor)
			{
				___controlsText.text = "pick up\n";
				AccessTools.Method(((object)__instance).GetType(), "ShowLicon", (Type[])null, (Type[])null).Invoke(__instance, new object[0]);
			}
		}
	}
}
[BepInPlugin("com.nandbrew.anchorimprovements", "Anchor Improvements", "1.1.5")]
internal class Main : BaseUnityPlugin
{
	public const string GUID = "com.nandbrew.anchorimprovements";

	public const string NAME = "Anchor Improvements";

	public const string VERSION = "1.1.5";

	internal static ManualLogSource logSource;

	internal static ConfigEntry<string> simplePhysics;

	internal static ConfigEntry<bool> saveAnchorPosition;

	internal static ConfigEntry<bool> winchInfo;

	internal static List<PickupableBoatAnchor> boatAnchors = new List<PickupableBoatAnchor>();

	public void Awake()
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Expected O, but got Unknown
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Expected O, but got Unknown
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Expected O, but got Unknown
		logSource = ((BaseUnityPlugin)this).Logger;
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.nandbrew.anchorimprovements");
		simplePhysics = ((BaseUnityPlugin)this).Config.Bind<string>("Options", "Anchor mechanics", "Simple", new ConfigDescription("Simple: Normal with minor improvements \nRealistic: Holding power based on scope (angle)", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Simple", "Realistic" }), Array.Empty<object>()));
		saveAnchorPosition = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "Save anchor position", true, new ConfigDescription("", (AcceptableValueBase)null, Array.Empty<object>()));
		winchInfo = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "Winch info", true, new ConfigDescription("Show how many yards of rope are out when looking at windlass", (AcceptableValueBase)null, Array.Empty<object>()));
	}
}
internal class Patches
{
	[HarmonyPatch(typeof(Anchor))]
	private static class AnchorPatches
	{
		private static readonly GameObject anchorStock = new GameObject
		{
			name = "anchor_stock"
		};

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void StartPatch2(Anchor __instance, ref float ___initialMass, AudioSource ___audio, ref float ___anchorDrag, ConfigurableJoint ___joint)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			((Component)__instance).gameObject.layer = 0;
			((Component)__instance).gameObject.AddComponent<PickupableBoatAnchor>();
			GameObject obj = Object.Instantiate<GameObject>(anchorStock, ((Component)__instance).transform);
			obj.transform.localPosition = new Vector3(0f, 0f, -0.28f);
			CapsuleCollider obj2 = obj.AddComponent<CapsuleCollider>();
			obj2.radius = 0.05f;
			obj2.height = 0.6f;
			if (((Object)((Joint)___joint).connectedBody).name.Contains("medi medium"))
			{
				((Component)__instance).transform.localScale = new Vector3(1.25f, 1.25f, 1.25f);
			}
			___anchorDrag += 5f;
			___audio.maxDistance *= 3f;
			if (___initialMass == 1f || ___initialMass == 75f)
			{
				___initialMass = 100f;
			}
		}
	}

	[HarmonyPatch(typeof(Anchor))]
	private static class AnchorPatchesComplex
	{
		private static float powerDivisor = 64f;

		private static float Power(float angle)
		{
			return Mathf.Pow(angle, 2f) / powerDivisor;
		}

		[HarmonyPrefix]
		[HarmonyPatch("FixedUpdate")]
		public static bool FixedUpdatePatch(Anchor __instance, ConfigurableJoint ___joint, ref float ___unsetForce, AudioSource ___audio, ref float ___lastLength, ref bool ___grounded, Rigidbody ___body, float ___anchorDrag, float ___initialMass, ref float ___outCurrentForce)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			if (Main.simplePhysics.Value != "Realistic")
			{
				return true;
			}
			if (!GameState.playing || !((Component)((Joint)___joint).connectedBody).GetComponentInChildren<BoatHorizon>().closeToPlayer)
			{
				return true;
			}
			SoftJointLimit linearLimit = ___joint.linearLimit;
			Vector3 val;
			if (((SoftJointLimit)(ref linearLimit)).limit > 1f)
			{
				___body.mass = ___initialMass;
				Vector3 position = ((Component)___joint).transform.position;
				float num = Vector3.Angle(((Component)((Joint)___joint).connectedBody).transform.TransformPoint(((Joint)___joint).connectedAnchor) - position, ((Component)___joint).transform.root.up);
				float num2 = ((!(num < 90f)) ? Power((0f - num) % 90f) : Power(num));
				___unsetForce = ___initialMass * num2;
				SoftJointLimitSpring linearLimitSpring = ___joint.linearLimitSpring;
				linearLimit = ___joint.linearLimit;
				((SoftJointLimitSpring)(ref linearLimitSpring)).spring = Mathf.Max(5000f - (num2 + ((SoftJointLimit)(ref linearLimit)).limit) * 20f, ___initialMass * 10f);
				((SoftJointLimitSpring)(ref linearLimitSpring)).damper = ((SoftJointLimitSpring)(ref linearLimitSpring)).spring;
				___joint.linearLimitSpring = linearLimitSpring;
				SoftJointLimit linearLimit2 = ___joint.linearLimit;
				((SoftJointLimit)(ref linearLimit2)).contactDistance = (num2 + ((SoftJointLimit)(ref linearLimit2)).limit) / 30f;
				___joint.linearLimit = linearLimit2;
				val = ((Joint)___joint).currentForce;
				if (((Vector3)(ref val)).magnitude > ___unsetForce && !___audio.isPlaying)
				{
					InvokePrivate(__instance, "ReleaseAnchor");
				}
				linearLimit = ___joint.linearLimit;
				if ((double)((SoftJointLimit)(ref linearLimit)).limit + 0.01 < (double)___lastLength && num < 20f)
				{
					InvokePrivate(__instance, "ReleaseAnchor");
				}
				if (___grounded)
				{
					if (___body.drag < ___anchorDrag)
					{
						___body.drag += Time.deltaTime * (num / 45f + 0.1f);
					}
					else
					{
						val = ___body.velocity;
						if (((Vector3)(ref val)).sqrMagnitude < 5f)
						{
							___body.drag = ___anchorDrag;
							if (!___body.isKinematic && !___audio.isPlaying)
							{
								InvokePrivate(__instance, "SetAnchor");
							}
						}
					}
				}
				else if (((Component)__instance).transform.position.y < 0f)
				{
					if (___body.drag > 3f)
					{
						___body.drag -= Time.deltaTime * ___anchorDrag * 0.25f;
					}
					else
					{
						___body.drag = 3f;
					}
				}
			}
			else
			{
				___body.mass = 1f;
			}
			if (Object.op_Implicit((Object)(object)GameState.currentBoat) && (Object)(object)((Component)((Joint)___joint).connectedBody).transform == (Object)(object)GameState.currentBoat.parent)
			{
				___body.interpolation = (RigidbodyInterpolation)1;
			}
			else
			{
				___body.interpolation = (RigidbodyInterpolation)0;
			}
			if (Object.op_Implicit((Object)(object)___audio) && ((Behaviour)___audio).enabled && !___audio.isPlaying)
			{
				((Behaviour)___audio).enabled = false;
			}
			linearLimit = ___joint.linearLimit;
			___lastLength = ((SoftJointLimit)(ref linearLimit)).limit;
			val = ((Joint)___joint).currentForce;
			___outCurrentForce = ((Vector3)(ref val)).magnitude;
			return false;
		}
	}

	[HarmonyPatch(typeof(Anchor))]
	private static class AnchorPatchesSimple
	{
		[HarmonyPatch("FixedUpdate")]
		[HarmonyPostfix]
		public static void FixedUpdatePatchSimple(Anchor __instance, Rigidbody ___body, bool ___grounded, float ___anchorDrag, AudioSource ___audio, ref ConfigurableJoint ___joint)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (Main.simplePhysics.Value != "Simple" || !GameState.playing || !((Component)((Joint)___joint).connectedBody).GetComponentInChildren<BoatHorizon>().closeToPlayer)
			{
				return;
			}
			SoftJointLimitSpring linearLimitSpring = ___joint.linearLimitSpring;
			((SoftJointLimitSpring)(ref linearLimitSpring)).damper = 2000f;
			((SoftJointLimitSpring)(ref linearLimitSpring)).spring = 2000f;
			___joint.linearLimitSpring = linearLimitSpring;
			if (!___grounded || !(___body.drag >= ___anchorDrag))
			{
				return;
			}
			Vector3 velocity = ___body.velocity;
			if (((Vector3)(ref velocity)).sqrMagnitude < 1f)
			{
				bool isColliding = ((Component)__instance).GetComponent<PickupableBoatAnchor>().isColliding;
				___body.drag = ___anchorDrag;
				if (!___body.isKinematic && !___audio.isPlaying && isColliding)
				{
					InvokePrivate(__instance, "SetAnchor");
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("ReleaseAnchor")]
		public static bool Prefix(Anchor __instance, ConfigurableJoint ___joint, float ___unsetForce, AudioSource ___audio, float ___lastLength)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if (Main.simplePhysics.Value != "Simple")
			{
				return true;
			}
			Vector3 position = ((Component)___joint).transform.position;
			if (Vector3.Angle(((Component)((Joint)___joint).connectedBody).transform.TransformPoint(((Joint)___joint).connectedAnchor) - position, ((Component)___joint).transform.root.up) < 45f)
			{
				SoftJointLimit linearLimit = ___joint.linearLimit;
				if (((SoftJointLimit)(ref linearLimit)).limit + 0.01f < ___lastLength)
				{
					return true;
				}
			}
			Vector3 currentForce = ((Joint)___joint).currentForce;
			if (((Vector3)(ref currentForce)).magnitude >= ___unsetForce)
			{
				return true;
			}
			if (Object.op_Implicit((Object)(object)((PickupableItem)((Component)__instance).GetComponent<PickupableBoatAnchor>()).held))
			{
				return true;
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(RopeControllerAnchor))]
	private static class RopeControllerAnchorPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		public static void UpdatePatch(RopeControllerAnchor __instance, ConfigurableJoint ___joint, ref float ___currentResistance, ref float ___maxLength)
		{
			//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)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			if (Main.simplePhysics.Value == "Simple")
			{
				___maxLength = 50f;
			}
			if (Main.simplePhysics.Value == "Realistic")
			{
				___maxLength = 150f;
			}
			Vector3 currentForce;
			if (((Component)___joint).GetComponent<PickupableBoatAnchor>().isColliding || ((Component)___joint).GetComponent<Anchor>().IsSet())
			{
				float num = Vector3.Distance(((Component)((Joint)___joint).connectedBody).transform.TransformPoint(((Joint)___joint).connectedAnchor), ((Component)___joint).transform.position);
				SoftJointLimit linearLimit = ___joint.linearLimit;
				if (num >= ((SoftJointLimit)(ref linearLimit)).limit)
				{
					currentForce = ((Joint)___joint).currentForce;
					___currentResistance = Mathf.Max(((Vector3)(ref currentForce)).magnitude, 5f);
				}
				else
				{
					___currentResistance = 5f;
				}
			}
			else
			{
				currentForce = ((Joint)___joint).currentForce;
				___currentResistance = Mathf.Min(((Vector3)(ref currentForce)).magnitude / 10f, 10f);
			}
		}
	}

	public static object InvokePrivate(object obj, string name)
	{
		return AccessTools.Method(obj.GetType(), name, (Type[])null, (Type[])null).Invoke(obj, null);
	}
}
internal class PickupableBoatAnchor : PickupableItem
{
	public bool isColliding;

	public ConfigurableJoint joint;

	public Anchor anchor;

	public float yankSpeed = 15f;

	private Transform topAttach;

	private RopeControllerAnchor anchorController;

	public string dataName;

	private float currentThrowPower;

	private BoatHorizon boatHorizon;

	private bool closeToPlayer;

	private void Awake()
	{
		base.holdDistance = 1.5f;
		base.heldRotationOffset = 200f;
		base.big = false;
		if (!Main.boatAnchors.Contains(this))
		{
			Main.boatAnchors.Add(this);
		}
	}

	public override void Start()
	{
		((GoPointerButton)this).Start();
		joint = ((Component)this).GetComponentInParent<ConfigurableJoint>();
		dataName = "Anchor Improvements." + ((Object)((Joint)joint).connectedBody).name;
		anchor = ((Component)joint).GetComponentInParent<Anchor>();
		GetAnchorController();
		boatHorizon = ((Component)((Joint)joint).connectedBody).gameObject.GetComponentInChildren<BoatHorizon>();
		((MonoBehaviour)this).StartCoroutine(LoadAnchorData());
	}

	private void Update()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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_0070: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)base.held) && GetCurrentDistance() >= GetAnchorController().maxLength)
		{
			((PickupableItem)this).OnDrop();
			base.held.DropItem();
			Vector3 val = topAttach.position - ((Component)this).transform.position;
			((Component)this).GetComponentInParent<Rigidbody>().AddForceAtPosition(((Vector3)(ref val)).normalized * yankSpeed, ((Component)joint).transform.position, (ForceMode)2);
		}
		if (closeToPlayer && !boatHorizon.closeToPlayer)
		{
			SaveAnchorData();
		}
		closeToPlayer = boatHorizon.closeToPlayer;
	}

	public void SaveAnchorData()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		if (!closeToPlayer)
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)GetAnchorController()) && Main.saveAnchorPosition.Value)
		{
			SoftJointLimit linearLimit = joint.linearLimit;
			if (((SoftJointLimit)(ref linearLimit)).limit > 1f)
			{
				Vector3 val = ((Component)((Joint)joint).connectedBody).transform.TransformPoint(((Joint)joint).connectedAnchor);
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(((Component)this).transform.position.x - val.x, ((Component)this).transform.position.y - val.y, ((Component)this).transform.position.z - val.z);
				string[] obj = new string[17]
				{
					val2.x.ToString(CultureInfo.InvariantCulture),
					",",
					val2.y.ToString(CultureInfo.InvariantCulture),
					",",
					val2.z.ToString(CultureInfo.InvariantCulture),
					",",
					((RopeController)GetAnchorController()).currentLength.ToString(CultureInfo.InvariantCulture),
					",",
					anchor.IsSet().ToString(),
					",",
					null,
					null,
					null,
					null,
					null,
					null,
					null
				};
				linearLimit = joint.linearLimit;
				obj[10] = ((SoftJointLimit)(ref linearLimit)).limit.ToString(CultureInfo.InvariantCulture);
				obj[11] = ",";
				obj[12] = ((Component)this).transform.eulerAngles.x.ToString(CultureInfo.InvariantCulture);
				obj[13] = ",";
				obj[14] = ((Component)this).transform.eulerAngles.y.ToString(CultureInfo.InvariantCulture);
				obj[15] = ",";
				obj[16] = ((Component)this).transform.eulerAngles.z.ToString(CultureInfo.InvariantCulture);
				string value = string.Concat(obj);
				if (GameState.modData.ContainsKey(dataName))
				{
					GameState.modData[dataName] = value;
				}
				else
				{
					GameState.modData.Add(dataName, value);
				}
				return;
			}
		}
		if (GameState.modData.Remove(dataName))
		{
			Main.logSource.LogDebug((object)("Removed " + dataName + " from modData"));
		}
	}

	private IEnumerator LoadAnchorData()
	{
		yield return (object)new WaitUntil((Func<bool>)(() => GameState.playing && !GameState.justStarted && closeToPlayer));
		if (Main.saveAnchorPosition.Value && GameState.modData.TryGetValue(dataName, out var value))
		{
			string[] strings = value.Split(new char[1] { ',' });
			Vector3 pos = new Vector3(float.Parse(strings[0], CultureInfo.InvariantCulture), float.Parse(strings[1], CultureInfo.InvariantCulture), float.Parse(strings[2], CultureInfo.InvariantCulture));
			float num = float.Parse(strings[5], CultureInfo.InvariantCulture);
			float num2 = Vector3.Magnitude(pos);
			if (num2 > num && num2 < GetAnchorController().maxLength)
			{
				num = num2;
			}
			SoftJointLimit linearLimit = joint.linearLimit;
			((SoftJointLimit)(ref linearLimit)).limit = num;
			((RopeController)GetAnchorController()).currentLength = num / GetAnchorController().maxLength;
			joint.linearLimit = linearLimit;
			yield return (object)new WaitForEndOfFrame();
			((Component)this).transform.position = pos + ((Component)((Joint)joint).connectedBody).transform.TransformPoint(((Joint)joint).connectedAnchor);
			Vector3 eulerAngles = default(Vector3);
			((Vector3)(ref eulerAngles))..ctor(float.Parse(strings[6], CultureInfo.InvariantCulture), float.Parse(strings[7], CultureInfo.InvariantCulture), float.Parse(strings[8], CultureInfo.InvariantCulture));
			((Component)this).transform.eulerAngles = eulerAngles;
			if (strings[4] == "True")
			{
				InvokePrivate(anchor, "SetAnchor");
			}
		}
	}

	public RopeControllerAnchor GetAnchorController()
	{
		if ((Object)(object)anchorController == (Object)null)
		{
			anchorController = ((Component)((Joint)joint).connectedBody).gameObject.GetComponent<BoatMooringRopes>().GetAnchorController();
		}
		return anchorController;
	}

	private float GetCurrentDistance()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		return Vector3.Distance(((Component)this).transform.position, ((Component)((Joint)joint).connectedBody).transform.TransformPoint(((Joint)joint).connectedAnchor));
	}

	public override void ExtraLateUpdate()
	{
		if (Object.op_Implicit((Object)(object)base.held) && GetCurrentDistance() > anchorController.maxLength * 0.9f)
		{
			((GoPointerButton)this).enableRedOutline = true;
		}
		else
		{
			((GoPointerButton)this).enableRedOutline = false;
		}
		if (Object.op_Implicit((Object)(object)base.held))
		{
			GoPointer held = base.held;
			if (GameInput.GetKey((InputName)10))
			{
				currentThrowPower += Time.deltaTime;
			}
			else if (GameInput.GetKeyUp((InputName)10))
			{
				Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
				((PickupableItem)this).OnDrop();
				held.DropItem();
				((MonoBehaviour)held).StartCoroutine(ThrowItemAfterDelay(component, currentThrowPower, held));
				currentThrowPower = 0f;
			}
		}
	}

	private IEnumerator ThrowItemAfterDelay(Rigidbody heldRigidbody, float force, GoPointer holdingPointer)
	{
		yield return (object)new WaitForFixedUpdate();
		heldRigidbody.AddForce(((Component)holdingPointer).transform.forward * 20f * Mathf.Min(force, 1f), (ForceMode)2);
	}

	public override void OnPickup()
	{
		InvokePrivate(anchor, "ReleaseAnchor");
		Main.logSource.LogDebug((object)"Picked up anchor");
		((RopeController)GetAnchorController()).currentLength = anchorController.maxLength;
	}

	public object InvokePrivate(object obj, string name)
	{
		return AccessTools.Method(obj.GetType(), name, (Type[])null, (Type[])null).Invoke(obj, null);
	}

	public override void OnDrop()
	{
		if (isColliding)
		{
			InvokePrivate(anchor, "SetAnchor");
			((RopeController)GetAnchorController()).currentLength = GetCurrentDistance() / anchorController.maxLength;
		}
		else
		{
			((RopeController)GetAnchorController()).currentLength = (GetCurrentDistance() + currentThrowPower * 10f) / anchorController.maxLength;
		}
		((PickupableItem)this).OnDrop();
	}

	private IEnumerator WaitForDoneProcess(float timeout)
	{
		while ((double)GetCurrentDistance() < (double)GetAnchorController().maxLength * 0.8 && !isColliding)
		{
			yield return null;
			timeout -= Time.deltaTime;
			if (timeout <= 0f)
			{
				break;
			}
		}
	}

	private IEnumerator SetRopeLength(float timeout)
	{
		yield return WaitForDone(timeout);
		((RopeController)GetAnchorController()).currentLength = GetCurrentDistance() / anchorController.maxLength;
	}

	private YieldInstruction WaitForDone(float timeout)
	{
		return (YieldInstruction)(object)((MonoBehaviour)this).StartCoroutine(WaitForDoneProcess(timeout));
	}

	private void OnCollisionExit(Collision collision)
	{
		if (((Component)collision.collider).CompareTag("Terrain"))
		{
			isColliding = false;
			if (Object.op_Implicit((Object)(object)base.held))
			{
				InvokePrivate(anchor, "ReleaseAnchor");
			}
		}
	}

	private void OnCollisionEnter(Collision collision)
	{
		if (((Component)collision.collider).CompareTag("Terrain"))
		{
			isColliding = true;
		}
	}

	public override void OnScroll(float input)
	{
		base.heldRotationOffset = 200f;
	}
}
[HarmonyPatch(typeof(SaveLoadManager))]
internal class SaveLoadPatches
{
	[HarmonyPrefix]
	[HarmonyPatch("SaveModData")]
	public static void SavePatch()
	{
		foreach (PickupableBoatAnchor boatAnchor in Main.boatAnchors)
		{
			boatAnchor.SaveAnchorData();
		}
	}
}
[HarmonyPatch(typeof(IslandHorizon), "Start")]
internal static class TerrainFixer
{
	[HarmonyPostfix]
	public static void Postfix(IslandHorizon __instance)
	{
		Transform[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Transform>();
		foreach (Transform val in componentsInChildren)
		{
			if (((Component)val).CompareTag("Untagged") && ((Object)val).name.ToLower().Contains("terrain"))
			{
				((Component)val).tag = "Terrain";
			}
		}
	}
}
[HarmonyPatch(typeof(GPButtonRopeWinch))]
internal static class WinchPatches
{
	[HarmonyPostfix]
	[HarmonyPatch("FindBoat")]
	public static void FindBoatPatch(GPButtonRopeWinch __instance, PurchasableBoat ___boat, ref float ___gearRatio, ref float ___rotationSpeed, RopeController ___rope)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		if (___rope is RopeControllerAnchor)
		{
			if (((Object)((Component)___boat).transform).name.Contains("medi medium"))
			{
				((Component)__instance).transform.localScale = new Vector3(2f, 2f, 1.5f);
			}
			___gearRatio = 25f;
			___rotationSpeed = 8f;
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch("Update")]
	public static void WinchUpdatePatch(GPButtonRopeWinch __instance, GoPointer ___stickyClickedBy, bool ___isLookedAt, ref string ___description, RopeController ___rope, ref string ___lookText)
	{
		//IL_0022: 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)
		if (!___isLookedAt && !Object.op_Implicit((Object)(object)___stickyClickedBy))
		{
			return;
		}
		RopeControllerAnchor val = (RopeControllerAnchor)(object)((___rope is RopeControllerAnchor) ? ___rope : null);
		if (val != null)
		{
			string text = "";
			SoftJointLimit linearLimit = val.joint.linearLimit;
			float num = Mathf.Round(((SoftJointLimit)(ref linearLimit)).limit);
			if (Main.winchInfo.Value)
			{
				text = num + " yd";
			}
			___description = text;
		}
	}
}