Decompiled source of Dinghies v1.0.9

Dinghies.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using DinghiesScripts;
using HarmonyLib;
using ShipyardExpansion;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Dinghies")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Dinghies")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4861a431-f590-441d-b316-7e369b90c25b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public class HingeJointFix : MonoBehaviour
{
	private Quaternion initialLocalRotation;

	private Vector3 initialLocalPosition;

	private Quaternion localRotationOnDisable;

	private Vector3 localPositionOnDisable;

	private bool hasDisabled;

	private void Awake()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		initialLocalRotation = ((Component)this).transform.localRotation;
		initialLocalPosition = ((Component)this).transform.localPosition;
	}

	private void OnDisable()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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_003c: Unknown result type (might be due to invalid IL or missing references)
		localRotationOnDisable = ((Component)this).transform.localRotation;
		((Component)this).transform.localRotation = initialLocalRotation;
		localPositionOnDisable = ((Component)this).transform.localPosition;
		((Component)this).transform.localPosition = initialLocalPosition;
		hasDisabled = true;
	}

	private void Update()
	{
		//IL_001a: 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)
		if (hasDisabled)
		{
			hasDisabled = false;
			((Component)this).transform.localRotation = localRotationOnDisable;
			((Component)this).transform.localPosition = localPositionOnDisable;
		}
	}
}
namespace Dinghies;

public class Hook : PickupableItem
{
	public RopeControllerDavits rope;

	private Transform block;

	public Rigidbody rigidbody;

	public StowingBrackets bracket;

	private Quaternion initialRot;

	private Vector3 initialPos;

	public override void Start()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		((GoPointerButton)this).Start();
		rigidbody = ((Component)this).GetComponent<Rigidbody>();
		rigidbody.centerOfMass = new Vector3(0f, 0f, -1f);
	}

	public void Init(Transform b)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		block = b;
		initialRot = ((Component)this).transform.localRotation;
		initialPos = ((Component)this).transform.localPosition;
	}

	public override void OnPickup()
	{
		bracket?.DisconnectHook();
		((RopeController)rope).currentLength = rope.maxLength;
	}

	public override void OnDrop()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		((RopeController)rope).currentLength = GetDistance() / rope.maxLength;
		((Component)this).transform.localRotation = initialRot;
	}

	public void OnDisable()
	{
		ResetHook();
	}

	public override void ExtraLateUpdate()
	{
		if (!Object.op_Implicit((Object)(object)base.held))
		{
			((GoPointerButton)this).enableRedOutline = false;
			return;
		}
		float distance = GetDistance();
		if (distance > rope.maxLength * 0.8f)
		{
			((GoPointerButton)this).enableRedOutline = true;
			if (distance >= rope.maxLength)
			{
				((PickupableItem)this).OnDrop();
				base.held.DropItem();
			}
		}
		else
		{
			((GoPointerButton)this).enableRedOutline = false;
		}
	}

	private float GetDistance()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		return Vector3.Distance(((Component)this).transform.position, block.position);
	}

	private void ResetHook()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		((Component)this).transform.localPosition = initialPos;
		((RopeController)rope).currentLength = 0f;
	}
}
[RequireComponent(typeof(RopeEffect))]
public class RopeControllerDavits : RopeController
{
	private RopeEffect hookRope;

	private RopeEffect rope;

	public ConfigurableJoint joint;

	public float maxLength = 20f;

	private void Start()
	{
		rope = ((Component)this).GetComponent<RopeEffect>();
		ConfigurableJoint[] componentsInChildren = ((Component)((Component)this).transform.parent).GetComponentsInChildren<ConfigurableJoint>();
		if (((Object)this).name.Contains("0"))
		{
			joint = componentsInChildren[0];
		}
		else
		{
			joint = componentsInChildren[1];
		}
	}

	public void Init(RopeEffect hr)
	{
		hookRope = hr;
	}

	private void Update()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		SoftJointLimit linearLimit = joint.linearLimit;
		((SoftJointLimit)(ref linearLimit)).limit = Mathf.Lerp(0f, maxLength, base.currentLength);
		joint.linearLimit = linearLimit;
		float num = Vector3.Distance(((Component)this).transform.position, rope.attachment.position);
		if (Object.op_Implicit((Object)(object)hookRope))
		{
			num = Vector3.Distance(((Component)hookRope).transform.position, ((Component)joint).transform.position);
		}
		SoftJointLimit linearLimit2 = joint.linearLimit;
		float num2 = ((SoftJointLimit)(ref linearLimit2)).limit - num;
		rope.currentRopeLength = Mathf.InverseLerp(0f, maxLength, num2);
		if (Object.op_Implicit((Object)(object)hookRope))
		{
			hookRope.currentRopeLength = rope.currentRopeLength;
		}
	}
}
public class Tarp : GoPointerButton
{
	private GameObject stowedBoat;

	private ConfigurableJoint[] joints;

	public void Awake()
	{
		stowedBoat = ((Component)((Component)this).transform.parent).gameObject;
		joints = ((Component)((Component)this).transform.parent).GetComponents<ConfigurableJoint>();
	}

	public override void OnActivate()
	{
		if (!((Object)(object)((Joint)joints[0]).connectedBody != (Object)null) && !((Object)(object)((Joint)joints[1]).connectedBody != (Object)null))
		{
			GoPointerMovement isClickedBy = base.isClickedBy;
			object obj;
			if (isClickedBy == null)
			{
				obj = null;
			}
			else
			{
				GoPointer pointer = isClickedBy.pointer;
				obj = ((pointer != null) ? pointer.GetHeldItem() : null);
			}
			if (!((Object)obj != (Object)null))
			{
				Launch();
			}
		}
	}

	private void Launch()
	{
		Davits.list.Find((Davits d) => (Object)(object)d.stowedBoat == (Object)(object)stowedBoat).Launch();
	}
}
public class TarpPack : PickupableItem
{
	[CompilerGenerated]
	private sealed class <ReturnToPosition>d__10 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public TarpPack <>4__this;

		private Vector3 <startPos>5__1;

		private Quaternion <startRot>5__2;

		private Vector3 <targetPos>5__3;

		private Quaternion <targetRot>5__4;

		private float <t>5__5;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ReturnToPosition>d__10(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0087: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<startPos>5__1 = <>4__this.trans.localPosition;
				<startRot>5__2 = <>4__this.trans.localRotation;
				<targetPos>5__3 = <>4__this.holder.TransformPoint(<>4__this.storedPosition);
				<targetRot>5__4 = <>4__this.holder.rotation * <>4__this.storedRotation;
				<t>5__5 = 0f;
				break;
			case 1:
				<>1__state = -1;
				<t>5__5 += Time.deltaTime;
				break;
			}
			if (<t>5__5 < 1f)
			{
				<>4__this.trans.localPosition = Vector3.Lerp(<startPos>5__1, <>4__this.storedPosition, <t>5__5);
				<>4__this.trans.localRotation = Quaternion.Lerp(<startRot>5__2, <>4__this.storedRotation, <t>5__5);
				<>2__current = (object)new WaitForEndOfFrame();
				<>1__state = 1;
				return true;
			}
			<>4__this.trans.localPosition = <>4__this.storedPosition;
			<>4__this.trans.localRotation = <>4__this.storedRotation;
			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 Vector3 storedPosition;

	private Quaternion storedRotation;

	private Transform holder;

	private Transform trans;

	private Davits davits;

	public float maxDist = 50f;

	public void Init(Transform h)
	{
		//IL_0037: 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_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		holder = h;
		davits = ((Component)holder).GetComponent<Davits>();
		trans = ((Component)this).transform;
		((GoPointerButton)this).description = "tarp cover";
		storedPosition = trans.localPosition;
		storedRotation = trans.localRotation;
	}

	public override void OnDrop()
	{
		((MonoBehaviour)this).StartCoroutine(ReturnToPosition());
	}

	public void OnTriggerEnter(Collider other)
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)((Component)other).gameObject.GetComponent<Dinghy>()))
		{
			Transform currentBoat = GameState.currentBoat;
			if ((Object)(object)((currentBoat != null) ? currentBoat.parent : null) != (Object)(object)((Component)other).transform)
			{
				davits.Stow(((Component)other).gameObject, false);
				trans.localPosition = storedPosition;
				trans.localRotation = storedRotation;
				((PickupableItem)this).OnDrop();
				base.held.DropItem();
				((Component)this).gameObject.SetActive(false);
			}
		}
	}

	public override void ExtraLateUpdate()
	{
		if (!Object.op_Implicit((Object)(object)base.held))
		{
			((GoPointerButton)this).enableRedOutline = false;
			return;
		}
		float distance = GetDistance();
		if (distance > maxDist * 0.8f)
		{
			((GoPointerButton)this).enableRedOutline = true;
			if (distance >= maxDist)
			{
				((PickupableItem)this).OnDrop();
				base.held.DropItem();
			}
		}
		else
		{
			((GoPointerButton)this).enableRedOutline = false;
		}
	}

	[IteratorStateMachine(typeof(<ReturnToPosition>d__10))]
	private IEnumerator ReturnToPosition()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ReturnToPosition>d__10(0)
		{
			<>4__this = this
		};
	}

	private float GetDistance()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		return Vector3.Distance(storedPosition, trans.localPosition);
	}
}
public class NotificationButton : GoPointerButton
{
	public enum ButtonType
	{
		link,
		ok
	}

	private ButtonType type;

	private GameObject window;

	private string url = "https://github.com/alesparise/Dinghies-Sailwind-Mod/releases/latest";

	public void Init(int t, string u)
	{
		window = ((Component)((Component)this).transform.parent).gameObject;
		type = (ButtonType)t;
		url = u;
	}

	public override void OnActivate()
	{
		if (type == ButtonType.link)
		{
			Application.OpenURL(url);
		}
		if (type == ButtonType.ok)
		{
			window.SetActive(false);
		}
	}
}
public class DinghiesPatches
{
	public static string modFolder;

	public const string bridge = "DinghiesBridge.dll";

	public const string scripts = "DinghiesScripts.dll";

	private const float cartDudeRangeMult = 1.5f;

	public static AssetBundle bundle;

	public static GameObject cutter;

	public static GameObject cutterEmbark;

	public static GameObject notificationUI;

	public static GameObject stowedCutter;

	public static GameObject brigAssets;

	public static GameObject sanbuqAssets;

	public static GameObject junkAssets;

	public static GameObject jongAssets;

	public static GameObject[] letters = (GameObject[])(object)new GameObject[26];

	public static void StartPatch(FloatingOriginManager __instance)
	{
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		SetupThings();
		IndexManager.AssignAvailableIndex(cutter);
		Transform transform = ((Component)__instance).transform;
		SetMooring(transform);
		GameObject val = Object.Instantiate<GameObject>(cutter, transform);
		cutterEmbark = ((Component)val.transform.Find("WALK cutter")).gameObject;
		cutterEmbark.transform.parent = GameObject.Find("walk cols").transform;
		GameObject gameObject = ((Component)val.transform.Find("stowedCutter")).gameObject;
		gameObject.transform.parent = transform;
		gameObject.SetActive(false);
		GameObject boat = GameObject.Find("BOAT medi medium (50)");
		GameObject boat2 = GameObject.Find("BOAT dhow medium (20)");
		GameObject boat3 = GameObject.Find("BOAT junk medium (80)");
		GameObject boat4 = GameObject.Find("BOAT junk large (70)");
		AddDavitsOptions(boat, brigAssets, "brig");
		AddDavitsOptions(boat2, sanbuqAssets, "sanbuq");
		AddDavitsOptions(boat3, junkAssets, "junk");
		AddDavitsOptions(boat4, jongAssets, "jong");
		Vector3 position = default(Vector3);
		((Vector3)(ref position))..ctor(5691.12f, 0.3087376f, 38987.02f);
		SetRotationAndPosition(val, -89.8f, position);
	}

	public static void SailSetupPatch(Mast __instance)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		if (!(((Object)((Component)__instance).transform.parent.parent).name == "cutterModel"))
		{
			return;
		}
		GameObject[] sails = PrefabsDirectory.instance.sails;
		GameObject val = new GameObject();
		GameObject val2 = new GameObject();
		if (Chainloader.PluginInfos.ContainsKey("com.nandbrew.shipyardexpansion"))
		{
			val = sails[158];
			val2 = sails[156];
			if (((Object)__instance).name == "mizzen_mast")
			{
				__instance.startSailPrefab = val2;
			}
			if (((Object)__instance).name == "main_mast")
			{
				__instance.startSailPrefab = val;
			}
		}
		else
		{
			val = sails[45];
			val2 = sails[3];
			if (((Object)__instance).name == "mizzen_mast")
			{
				__instance.startSailPrefab = val2;
			}
			if (((Object)__instance).name == "main_mast")
			{
				__instance.startSailPrefab = val;
			}
		}
	}

	public static void SailSetupPatch2(Mast __instance)
	{
		if (((Object)((Component)__instance).transform.parent.parent).name == "cutterModel" && Chainloader.PluginInfos.ContainsKey("com.nandbrew.shipyardexpansion"))
		{
			if (((Object)__instance).name == "mizzen_mast")
			{
				((Component)__instance).GetComponentInChildren<SailScaler>().SetScaleRel(0.525f);
				Sail componentInChildren = ((Component)__instance).GetComponentInChildren<Sail>();
				componentInChildren.ChangeInstallHeight(-1f);
				componentInChildren.UpdateInstallPosition();
			}
			if (((Object)__instance).name == "main_mast")
			{
				((Component)__instance).GetComponentInChildren<SailScaler>().SetScaleRel(0.7447f);
				Sail componentInChildren2 = ((Component)__instance).GetComponentInChildren<Sail>();
				componentInChildren2.ChangeInstallHeight(0.3f);
				componentInChildren2.UpdateInstallPosition();
			}
		}
	}

	public static bool ImpactPatch(Collision collision)
	{
		object obj;
		if (collision == null)
		{
			obj = null;
		}
		else
		{
			Collider collider = collision.collider;
			obj = ((collider != null) ? ((Object)collider).name : null);
		}
		if (!((string?)obj == "stowedCutter"))
		{
			object obj2;
			if (collision == null)
			{
				obj2 = null;
			}
			else
			{
				Collider collider2 = collision.collider;
				if (collider2 == null)
				{
					obj2 = null;
				}
				else
				{
					Transform parent = ((Component)collider2).transform.parent;
					obj2 = ((parent != null) ? ((Object)parent).name : null);
				}
			}
			if (!((string?)obj2 == "stowedCutter"))
			{
				return true;
			}
		}
		return false;
	}

	public static bool CartDudePatch(CargoStorageUI __instance, Transform ___currentDude)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)___currentDude) && Vector3.Distance(((Component)Refs.observerMirror).transform.position, ___currentDude.position) > 270f)
		{
			Debug.Log((object)"Transport dude out of range, disabling cargo carry mode.");
			__instance.UnregisterCarrier();
			if (PlayerNeedsUI.instance.IsActive())
			{
				__instance.ToggleUI(false);
			}
		}
		return false;
	}

	public static void SetupThings()
	{
		modFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string text = Path.Combine(modFolder, "DinghiesBridge.dll");
		string text2 = Path.Combine(modFolder, "DinghiesScripts.dll");
		if (File.Exists(text) && File.Exists(text2))
		{
			Assembly.LoadFrom(text);
			Assembly.LoadFrom(text2);
		}
		else
		{
			Debug.LogError((object)"Dinghies: Couldn't load DinghiesBridge.dll and/or DinghiesScripts.dll!");
		}
		string text3 = Path.Combine(modFolder, "dinghies");
		bundle = AssetBundle.LoadFromFile(text3);
		if ((Object)(object)bundle == (Object)null)
		{
			Debug.LogError((object)"Dinghies: Could not load the bundle!");
			return;
		}
		string text4 = "Assets/Dinghies/DNG Cutter.prefab";
		cutter = bundle.LoadAsset<GameObject>(text4);
		string text5 = "Assets/Dinghies/nameplate/letter";
		for (int i = 0; i < 26; i++)
		{
			letters[i] = bundle.LoadAsset<GameObject>(text5 + i + ".prefab");
		}
		if (DinghiesMain.notificationsConfig.Value)
		{
			string text6 = "Assets/Dinghies/notificationWindow.prefab";
			notificationUI = bundle.LoadAsset<GameObject>(text6);
			GameObject val = Object.Instantiate<GameObject>(notificationUI);
		}
		string text7 = "Assets/Dinghies/brig_stowing.prefab";
		brigAssets = bundle.LoadAsset<GameObject>(text7);
		string text8 = "Assets/Dinghies/sanbuq_stowing.prefab";
		sanbuqAssets = bundle.LoadAsset<GameObject>(text8);
		string text9 = "Assets/Dinghies/junk_stowing.prefab";
		junkAssets = bundle.LoadAsset<GameObject>(text9);
		string text10 = "Assets/Dinghies/jong_stowing.prefab";
		jongAssets = bundle.LoadAsset<GameObject>(text10);
		Transform transform = cutter.transform;
		Transform val2 = cutter.transform.Find("cutterModel");
		cutter.GetComponent<PurchasableBoat>().region = GameObject.Find("Region Medi").GetComponent<Region>();
		Transform val3 = val2.Find("oars_locks");
		((Component)val3.GetChild(0).GetChild(0)).gameObject.AddComponent<Oar>();
		((Component)val3.GetChild(1).GetChild(0)).gameObject.AddComponent<Oar>();
		((Component)val3).gameObject.AddComponent<OarLocks>();
		stowedCutter = ((Component)transform.Find("stowedCutter")).gameObject;
		Transform transform2 = stowedCutter.transform;
		Transform val4 = val2.Find("nameplates");
		((Component)val4.Find("nameplate_left")).gameObject.AddComponent<Nameplate>();
		((Component)val4.Find("nameplate_right")).gameObject.AddComponent<Nameplate>();
		MatLib.RegisterMaterials();
		((Renderer)((Component)transform.Find("WaterFoam")).GetComponent<MeshRenderer>()).sharedMaterial = MatLib.foam;
		((Renderer)((Component)transform.Find("WaterObjectInteractionSphereBack")).GetComponent<MeshRenderer>()).sharedMaterial = MatLib.objectInteraction;
		((Renderer)((Component)transform.Find("WaterObjectInteractionSphereFront")).GetComponent<MeshRenderer>()).sharedMaterial = MatLib.objectInteraction;
		((Component)transform.Find("overflow particles")).GetComponent<Renderer>().sharedMaterial = MatLib.overflow;
		((Component)transform.Find("overflow particles (1)")).GetComponent<Renderer>().sharedMaterial = MatLib.overflow;
		((Renderer)((Component)val2.Find("mask")).GetComponent<MeshRenderer>()).sharedMaterial = MatLib.convexHull;
		((Renderer)((Component)val2.Find("damage_water")).GetComponent<MeshRenderer>()).sharedMaterial = MatLib.water4;
		((Renderer)((Component)val2.Find("mask_splash")).GetComponent<MeshRenderer>()).sharedMaterial = MatLib.mask;
		((Component)val2.Find("easter_egg")).gameObject.SetActive(false);
		if (DinghiesMain.nothingConfig.Value)
		{
			EasterEgg(val2);
		}
	}

	public static void SetRotationAndPosition(GameObject boat, float yRot, Vector3 position)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = boat.transform;
		transform.eulerAngles = new Vector3(0f, yRot, 0f);
		transform.position = position;
	}

	public static void SetMooring(Transform shiftingWorld)
	{
		Transform val = shiftingWorld.Find("island 15 M (Fort)");
		BoatMooringRopes component = cutter.GetComponent<BoatMooringRopes>();
		component.mooringFront = ((Component)val.Find("dock_mooring M")).transform;
		component.mooringBack = ((Component)val.Find("dock_mooring M (8)")).transform;
	}

	public static void EasterEgg(Transform cutterModel)
	{
		DateTime now = DateTime.Now;
		int month = now.Month;
		int day = now.Day;
		if ((month == 12 && day >= 8) || (month == 1 && day <= 6))
		{
			GameObject gameObject = ((Component)cutterModel.Find("easter_egg")).gameObject;
			gameObject.SetActive(true);
		}
	}

	public static void AddDavitsOptions(GameObject boat, GameObject prefab, string boatName)
	{
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: 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_019a: Expected O, but got Unknown
		BoatCustomParts component = boat.GetComponent<BoatCustomParts>();
		Rigidbody component2 = boat.GetComponent<Rigidbody>();
		BoatRefs component3 = boat.GetComponent<BoatRefs>();
		Transform walkCol = component3.walkCol;
		Transform boatModel = component3.boatModel;
		GameObject val = Object.Instantiate<GameObject>(prefab);
		Transform transform = val.transform;
		Transform val2 = transform.Find("davits_0_" + boatName);
		Transform val3 = transform.Find("no_davits");
		Transform val4 = transform.Find("davits_0_walk");
		Transform val5 = transform.Find("no_davits_walk");
		val2.SetParent(boatModel, false);
		val3.SetParent(boatModel, false);
		val4.SetParent(walkCol, false);
		val5.SetParent(walkCol, false);
		Transform val6 = val2.Find("block0/davits_0_hook_0_" + boatName);
		Transform val7 = val2.Find("block1/davits_0_hook_1_" + boatName);
		((Joint)((Component)val6).GetComponent<ConfigurableJoint>()).connectedBody = component2;
		((Joint)((Component)val7).GetComponent<ConfigurableJoint>()).connectedBody = component2;
		RopeControllerDavits component4 = ((Component)val2.Find("controller0")).gameObject.GetComponent<RopeControllerDavits>();
		RopeControllerDavits component5 = ((Component)val2.Find("controller1")).gameObject.GetComponent<RopeControllerDavits>();
		((Component)val6).GetComponent<Hook>().rope = component4;
		((Component)val7).GetComponent<Hook>().rope = component5;
		((Component)val2.Find("winch0")).GetComponent<GPButtonRopeWinch>().rope = (RopeController)(object)component4;
		((Component)val2.Find("winch1")).GetComponent<GPButtonRopeWinch>().rope = (RopeController)(object)component5;
		BoatPart item = new BoatPart
		{
			category = 1,
			partOptions = new List<BoatPartOption>
			{
				((Component)val2).GetComponent<BoatPartOption>(),
				((Component)val3).GetComponent<BoatPartOption>()
			},
			activeOption = 1
		};
		component.availableParts.Add(item);
	}

	public static void LogStartupTime(float timeInMs)
	{
		string path = Path.Combine(modFolder, "StartupTimes.txt");
		try
		{
			List<float> list = new List<float>();
			if (File.Exists(path))
			{
				string[] source = File.ReadAllLines(path);
				foreach (string item in source.Skip(1))
				{
					if (item.Contains("Startup #"))
					{
						string[] array = item.Split(new string[1] { ":" }, StringSplitOptions.None);
						if (array.Length > 1 && float.TryParse(array[1].Replace("ms", "").Trim(), out var result))
						{
							list.Add(result);
						}
					}
				}
			}
			list.Add(timeInMs);
			float num = list.Average();
			List<string> list2 = new List<string> { $"Average Startup Time: {num:F2} ms" };
			int num2 = 0;
			foreach (float item2 in list)
			{
				list2.Add($"Startup #{num2}: {item2} ms");
				num2++;
			}
			File.WriteAllLines(path, list2);
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("Failed to write log: " + ex.Message));
		}
	}

	public static void ShowWalkCols()
	{
		Camera main = Camera.main;
		main.cullingMask |= 1 << LayerMask.NameToLayer("WalkCols");
	}
}
internal class IndexManager
{
	private static bool updateSave;

	private static bool updateLegacySave;

	private static bool xebec;

	public static Dictionary<string, int> loadedIndexMap = new Dictionary<string, int>();

	public static Dictionary<string, int> indexMap = new Dictionary<string, int>();

	public static string loadedVersion;

	[HarmonyPriority(400)]
	[HarmonyPrefix]
	private static void Manager(int backupIndex)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		Debug.LogWarning((object)"Dinghies: Manager running");
		string path = ((backupIndex != 0) ? SaveSlots.GetBackupPath(SaveSlots.currentSlot, backupIndex) : SaveSlots.GetCurrentSavePath());
		BinaryFormatter binaryFormatter = new BinaryFormatter();
		SaveContainer val;
		using (FileStream serializationStream = File.Open(path, FileMode.Open))
		{
			val = (SaveContainer)binaryFormatter.Deserialize(serializationStream);
		}
		LoadSavedIndexes(val);
		DetectXebec(val);
		ValidateIndexes();
		if (updateSave || updateLegacySave)
		{
			if (updateLegacySave)
			{
				val = UpdateFromLegacy(val);
			}
			if (updateSave)
			{
				val = UpdateSave(val);
			}
		}
		using FileStream serializationStream2 = File.Open(path, FileMode.Create);
		binaryFormatter.Serialize(serializationStream2, val);
	}

	[HarmonyPostfix]
	public static void SaveIndex()
	{
		if (GameState.currentlyLoading)
		{
			GameState.modData["pr0skynesis.dinghies"] = "";
			SaveModData();
		}
	}

	[HarmonyPostfix]
	public static void StartNewGamePatch()
	{
		SaveModData();
	}

	public static void AssignAvailableIndex(GameObject boat)
	{
		SaveableObject[] currentObjects = SaveLoadManager.instance.GetCurrentObjects();
		int holeSize = GetHoleSize(boat);
		int num = FindHole(currentObjects, holeSize);
		boat.GetComponent<SaveableObject>().sceneIndex = num;
		indexMap[((Object)boat).name] = num;
	}

	public static void LoadSavedIndexes(SaveContainer saveContainer)
	{
		if (saveContainer.modData.ContainsKey("pr0skynesis.dinghies"))
		{
			string text = saveContainer.modData["pr0skynesis.dinghies"];
			string[] array = text.Split(new char[1] { ';' });
			for (int i = 0; i < array.Length - 1; i++)
			{
				string key = array[i].Split(new char[1] { ':' })[0];
				int value = int.Parse(array[i].Split(new char[1] { ':' })[1]);
				loadedIndexMap[key] = value;
			}
		}
		if (saveContainer.modData.ContainsKey("pr0.dinghies.version"))
		{
			loadedVersion = saveContainer.modData["pr0.dinghies.version"];
		}
		else
		{
			updateLegacySave = true;
		}
	}

	private static void DetectXebec(SaveContainer saveContainer)
	{
		if (saveContainer.savedObjects.Any((SaveObjectData x) => x.sceneIndex == 133) && updateLegacySave)
		{
			xebec = true;
		}
	}

	private static SaveContainer UpdateSave(SaveContainer saveContainer)
	{
		Debug.LogWarning((object)("Dinghies: updating save " + SaveSlots.currentSlot));
		foreach (string boat in loadedIndexMap.Keys)
		{
			foreach (SavePrefabData item in saveContainer.savedPrefabs.Where((SavePrefabData x) => x != null && x.itemParentObject == loadedIndexMap[boat]))
			{
				item.itemParentObject = indexMap[boat];
			}
			foreach (SaveObjectData item2 in saveContainer.savedObjects.Where((SaveObjectData x) => x != null && x.sceneIndex == loadedIndexMap[boat]))
			{
				item2.sceneIndex = indexMap[boat];
			}
			if (saveContainer.modData.ContainsKey($"SEboatSails.{loadedIndexMap[boat]}"))
			{
				string value = saveContainer.modData[$"SEboatSails.{loadedIndexMap[boat]}"];
				saveContainer.modData.Remove($"SEboatSails.{loadedIndexMap[boat]}");
				saveContainer.modData[$"SEboatSails.{indexMap[boat]}"] = value;
			}
		}
		Debug.LogWarning((object)"Dinghies: save updated...");
		return saveContainer;
	}

	public static SaveContainer UpdateFromLegacy(SaveContainer saveContainer)
	{
		Debug.LogWarning((object)("Dinghies: updating save " + SaveSlots.currentSlot + " from legacy version"));
		foreach (string key in indexMap.Keys)
		{
			if (!xebec)
			{
				foreach (SavePrefabData item in saveContainer.savedPrefabs.Where((SavePrefabData x) => x.itemParentObject == 130 || x.itemParentObject == 131 || x.itemParentObject == 132))
				{
					item.itemParentObject = indexMap[key];
				}
				continue;
			}
			foreach (SavePrefabData item2 in saveContainer.savedPrefabs.Where((SavePrefabData x) => x.itemParentObject == 130))
			{
				item2.itemParentObject = indexMap[key];
			}
		}
		foreach (string key2 in indexMap.Keys)
		{
			if (!xebec)
			{
				foreach (SaveObjectData item3 in saveContainer.savedObjects.Where((SaveObjectData x) => x.sceneIndex == 130 || x.sceneIndex == 131 || x.sceneIndex == 132))
				{
					if (item3.sceneIndex == 130)
					{
						item3.sceneIndex = indexMap[key2];
					}
					else if (item3.sceneIndex == 131)
					{
						item3.sceneIndex = indexMap[key2] + 1;
					}
					else if (item3.sceneIndex == 132)
					{
						item3.sceneIndex = indexMap[key2] + 2;
					}
				}
				continue;
			}
			foreach (SaveObjectData item4 in saveContainer.savedObjects.Where((SaveObjectData x) => x.sceneIndex == 130))
			{
				if (item4.sceneIndex == 130)
				{
					item4.sceneIndex = indexMap[key2];
				}
			}
		}
		if (saveContainer.modData.ContainsKey("SEboatSails.130"))
		{
			string value = saveContainer.modData["SEboatSails.130"];
			saveContainer.modData.Remove("SEboatSails.130");
			saveContainer.modData[$"SEboatSails.{indexMap[indexMap.Keys.First()]}"] = value;
		}
		Debug.LogWarning((object)"Dinghies: save updated from legacy version...");
		return saveContainer;
	}

	private static void SaveModData()
	{
		GameState.modData["pr0skynesis.dinghies"] = "";
		foreach (string key in indexMap.Keys)
		{
			string text = key.ToString() + ":" + indexMap[key] + ";";
			if (GameState.modData.ContainsKey("pr0skynesis.dinghies"))
			{
				GameState.modData["pr0skynesis.dinghies"] += text;
			}
			else
			{
				GameState.modData["pr0skynesis.dinghies"] = text;
			}
		}
		GameState.modData["pr0.dinghies.version"] = "1.0.9";
	}

	private static int GetHoleSize(GameObject boat)
	{
		return boat.GetComponent<BoatMooringRopes>().ropes.Length + 1;
	}

	public static int FindHole(SaveableObject[] array, int holeSize)
	{
		for (int i = 1; i < array.Length - holeSize; i++)
		{
			if (!((Object)(object)array[i] == (Object)null))
			{
				continue;
			}
			for (int j = 0; j < holeSize && !((Object)(object)array[i + j] != (Object)null); j++)
			{
				if (j == holeSize - 1)
				{
					return i;
				}
			}
		}
		return -1;
	}

	private static void ValidateIndexes()
	{
		foreach (string key in indexMap.Keys)
		{
			if (loadedIndexMap.ContainsKey(key) && loadedIndexMap[key] != indexMap[key])
			{
				updateSave = true;
			}
		}
	}
}
public class MatLib
{
	public static Material convexHull;

	public static Material foam;

	public static Material objectInteraction;

	public static Material water4;

	public static Material mask;

	public static Material overflow;

	public static void RegisterMaterials()
	{
		GameObject val = GameObject.Find("BOAT medi small (40)");
		Transform val2 = val.transform.Find("medi small");
		convexHull = ((Renderer)((Component)val2.Find("mask")).GetComponent<MeshRenderer>()).sharedMaterial;
		foam = ((Renderer)((Component)val.transform.Find("WaterFoam")).GetComponent<MeshRenderer>()).sharedMaterial;
		objectInteraction = ((Renderer)((Component)val.transform.Find("WaterObjectInteractionSphereBack")).GetComponent<MeshRenderer>()).sharedMaterial;
		water4 = ((Renderer)((Component)val2.Find("damage_water")).GetComponent<MeshRenderer>()).sharedMaterial;
		mask = ((Renderer)((Component)val2.Find("mask_splash")).GetComponent<MeshRenderer>()).sharedMaterial;
		overflow = ((Component)val.transform.Find("overflow particles")).GetComponent<Renderer>().sharedMaterial;
	}
}
public class Nameplate : GoPointerButton
{
	internal class NameSaver
	{
		public string boatName;

		public string plateName;

		public static string Serialize(List<NameSaver> nameSavers)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (NameSaver nameSaver in nameSavers)
			{
				stringBuilder.Append(nameSaver.boatName);
				stringBuilder.Append(":");
				stringBuilder.Append(nameSaver.plateName);
				stringBuilder.Append(";");
			}
			return stringBuilder.ToString();
		}

		public static List<NameSaver> Unserialize(string s)
		{
			List<NameSaver> list = new List<NameSaver>();
			string[] array = s.Split(new char[1] { ';' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (!(text == ""))
				{
					string[] array3 = text.Split(new char[1] { ':' });
					NameSaver item = new NameSaver
					{
						boatName = array3[0],
						plateName = array3[1]
					};
					list.Add(item);
				}
			}
			return list;
		}
	}

	private string plateName = "CUTTER";

	private const string key = "pr0.dinghies.plateName";

	private int letterCount;

	private float unpausedTimescale;

	private float textAnchorX;

	private float textAnchorY;

	private float textAnchorZ;

	private float currentOffset;

	private readonly float[] spacing = new float[27]
	{
		0.045f, 0.065f, 0.06f, 0.07f, 0.06f, 0.06f, 0.06f, 0.07f, 0.035f, 0.045f,
		0.065f, 0.055f, 0.095f, 0.075f, 0.065f, 0.055f, 0.065f, 0.06f, 0.05f, 0.06f,
		0.07f, 0.065f, 0.09f, 0.06f, 0.06f, 0.05f, 0.06f
	};

	private bool typing;

	private bool initialised;

	private Nameplate otherPlate;

	private Transform boat;

	private Transform textAnchor;

	private Vector3 direction = new Vector3(-1f, 0f, 0f);

	private NameSaver nameSaver;

	private static List<NameSaver> list;

	private void Awake()
	{
		//IL_0078: 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)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		Transform parent = ((Component)this).transform.parent;
		boat = parent.parent;
		if (((Object)this).name == "nameplate_left")
		{
			otherPlate = ((Component)parent.Find("nameplate_right")).GetComponent<Nameplate>();
		}
		else
		{
			otherPlate = ((Component)parent.Find("nameplate_left")).GetComponent<Nameplate>();
		}
		textAnchor = ((Component)this).transform.GetChild(0);
		textAnchorX = textAnchor.localPosition.x;
		textAnchorY = textAnchor.localPosition.y;
		textAnchorZ = textAnchor.localPosition.z;
		WriteLoadedName(plateName);
		if (list == null)
		{
			list = new List<NameSaver>();
		}
	}

	public override void OnActivate()
	{
		if (!typing)
		{
			unpausedTimescale = Time.timeScale;
			Time.timeScale = 0f;
			typing = true;
			MouseLook.ToggleMouseLook(false);
			Refs.SetPlayerControl(false);
		}
	}

	public override void ExtraLateUpdate()
	{
		if (!initialised && GameState.playing)
		{
			LoadName();
			initialised = true;
		}
		if (typing)
		{
			if (Input.GetKeyDown((KeyCode)97))
			{
				AddLetter('A', 0);
				otherPlate.AddLetter('A', 0);
			}
			else if (Input.GetKeyDown((KeyCode)98))
			{
				AddLetter('B', 1);
				otherPlate.AddLetter('B', 1);
			}
			else if (Input.GetKeyDown((KeyCode)99))
			{
				AddLetter('C', 2);
				otherPlate.AddLetter('C', 2);
			}
			else if (Input.GetKeyDown((KeyCode)100))
			{
				AddLetter('D', 3);
				otherPlate.AddLetter('D', 3);
			}
			else if (Input.GetKeyDown((KeyCode)101))
			{
				AddLetter('E', 4);
				otherPlate.AddLetter('E', 4);
			}
			else if (Input.GetKeyDown((KeyCode)102))
			{
				AddLetter('F', 5);
				otherPlate.AddLetter('F', 5);
			}
			else if (Input.GetKeyDown((KeyCode)103))
			{
				AddLetter('G', 6);
				otherPlate.AddLetter('G', 6);
			}
			else if (Input.GetKeyDown((KeyCode)104))
			{
				AddLetter('H', 7);
				otherPlate.AddLetter('H', 7);
			}
			else if (Input.GetKeyDown((KeyCode)105))
			{
				AddLetter('I', 8);
				otherPlate.AddLetter('I', 8);
			}
			else if (Input.GetKeyDown((KeyCode)106))
			{
				AddLetter('J', 9);
				otherPlate.AddLetter('J', 9);
			}
			else if (Input.GetKeyDown((KeyCode)107))
			{
				AddLetter('K', 10);
				otherPlate.AddLetter('K', 10);
			}
			else if (Input.GetKeyDown((KeyCode)108))
			{
				AddLetter('L', 11);
				otherPlate.AddLetter('L', 11);
			}
			else if (Input.GetKeyDown((KeyCode)109))
			{
				AddLetter('M', 12);
				otherPlate.AddLetter('M', 12);
			}
			else if (Input.GetKeyDown((KeyCode)110))
			{
				AddLetter('N', 13);
				otherPlate.AddLetter('N', 13);
			}
			else if (Input.GetKeyDown((KeyCode)111))
			{
				AddLetter('O', 14);
				otherPlate.AddLetter('O', 14);
			}
			else if (Input.GetKeyDown((KeyCode)112))
			{
				AddLetter('P', 15);
				otherPlate.AddLetter('P', 15);
			}
			else if (Input.GetKeyDown((KeyCode)113))
			{
				AddLetter('Q', 16);
				otherPlate.AddLetter('Q', 16);
			}
			else if (Input.GetKeyDown((KeyCode)114))
			{
				AddLetter('R', 17);
				otherPlate.AddLetter('R', 17);
			}
			else if (Input.GetKeyDown((KeyCode)115))
			{
				AddLetter('S', 18);
				otherPlate.AddLetter('S', 18);
			}
			else if (Input.GetKeyDown((KeyCode)116))
			{
				AddLetter('T', 19);
				otherPlate.AddLetter('T', 19);
			}
			else if (Input.GetKeyDown((KeyCode)117))
			{
				AddLetter('U', 20);
				otherPlate.AddLetter('U', 20);
			}
			else if (Input.GetKeyDown((KeyCode)118))
			{
				AddLetter('V', 21);
				otherPlate.AddLetter('V', 21);
			}
			else if (Input.GetKeyDown((KeyCode)119))
			{
				AddLetter('W', 22);
				otherPlate.AddLetter('W', 22);
			}
			else if (Input.GetKeyDown((KeyCode)120))
			{
				AddLetter('X', 23);
				otherPlate.AddLetter('X', 23);
			}
			else if (Input.GetKeyDown((KeyCode)121))
			{
				AddLetter('Y', 24);
				otherPlate.AddLetter('Y', 24);
			}
			else if (Input.GetKeyDown((KeyCode)122))
			{
				AddLetter('Z', 25);
				otherPlate.AddLetter('Z', 25);
			}
			else if (Input.GetKeyDown((KeyCode)32))
			{
				AddLetter(' ', 26);
				otherPlate.AddLetter(' ', 26);
			}
			else if (Input.GetKeyDown((KeyCode)8))
			{
				RemoveLetter();
				otherPlate.RemoveLetter();
			}
			else if (Input.GetKeyDown((KeyCode)13))
			{
				Time.timeScale = unpausedTimescale;
				SaveName();
				otherPlate.SaveName();
				typing = false;
				Refs.SetPlayerControl(true);
				MouseLook.ToggleMouseLook(true);
			}
		}
	}

	private void AddLetter(char letter, int index)
	{
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		//IL_006a: 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)
		if (!(currentOffset > 1.25f))
		{
			plateName += letter;
			if (index < 26)
			{
				GameObject val = Object.Instantiate<GameObject>(DinghiesPatches.letters[index], textAnchor);
				Transform transform = val.transform;
				currentOffset += spacing[index];
				transform.localPosition += direction * currentOffset;
			}
			else
			{
				Object.Instantiate<GameObject>(new GameObject(), textAnchor);
				currentOffset += spacing[index];
			}
			if (currentOffset > 0.95f)
			{
				ScaleAnchor(0.4f);
			}
			else if (currentOffset > 0.72f)
			{
				ScaleAnchor(0.6f);
			}
			else if (currentOffset > 0.55f)
			{
				ScaleAnchor(0.8f);
			}
			letterCount++;
		}
	}

	private void RemoveLetter()
	{
		if (letterCount != 0)
		{
			letterCount--;
			char l = plateName[letterCount];
			plateName = plateName.Remove(letterCount);
			currentOffset -= spacing[IndexFromLetter(l)];
			Object.Destroy((Object)(object)((Component)textAnchor.GetChild(letterCount)).gameObject);
			if (currentOffset < 0.55f)
			{
				ScaleAnchor(1f);
			}
			else if (currentOffset < 0.72f)
			{
				ScaleAnchor(0.8f);
			}
			else if (currentOffset < 0.95f)
			{
				ScaleAnchor(0.6f);
			}
		}
	}

	private void ScaleAnchor(float scale)
	{
		//IL_000b: 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)
		textAnchor.localScale = new Vector3(0f - scale, scale, scale);
		textAnchor.localPosition = new Vector3(textAnchorX, textAnchorY * scale, textAnchorZ);
	}

	private int IndexFromLetter(char l)
	{
		return l switch
		{
			'A' => 0, 
			'B' => 1, 
			'C' => 2, 
			'D' => 3, 
			'E' => 4, 
			'F' => 5, 
			'G' => 6, 
			'H' => 7, 
			'I' => 8, 
			'J' => 9, 
			'K' => 10, 
			'L' => 11, 
			'M' => 12, 
			'N' => 13, 
			'O' => 14, 
			'P' => 15, 
			'Q' => 16, 
			'R' => 17, 
			'S' => 18, 
			'T' => 19, 
			'U' => 20, 
			'V' => 21, 
			'W' => 22, 
			'X' => 23, 
			'Y' => 24, 
			'Z' => 25, 
			_ => 26, 
		};
	}

	private void WriteLoadedName(string str)
	{
		foreach (char c in str)
		{
			AddLetter(c, IndexFromLetter(c));
		}
	}

	private void SaveName()
	{
		nameSaver = new NameSaver
		{
			boatName = ((Object)boat).name,
			plateName = plateName
		};
		if (!list.Contains(nameSaver))
		{
			list.Add(nameSaver);
		}
		GameState.modData["pr0.dinghies.plateName"] = NameSaver.Serialize(list);
	}

	private void LoadName()
	{
		if (!GameState.modData.ContainsKey("pr0.dinghies.plateName"))
		{
			return;
		}
		List<NameSaver> list = NameSaver.Unserialize(GameState.modData["pr0.dinghies.plateName"]);
		foreach (NameSaver item in list)
		{
			if (item.boatName == ((Object)boat).name)
			{
				CleanName();
				WriteLoadedName(item.plateName);
				break;
			}
		}
	}

	private void CleanName()
	{
		int length = plateName.Length;
		for (int i = 0; i < length; i++)
		{
			RemoveLetter();
		}
	}
}
public class OarLocks : GoPointerButton
{
	private SaveableObject saveable;

	public bool oarUp;

	private Oar leftOar;

	private Oar rightOar;

	private float min1 = -3f;

	private float max1 = -2.9f;

	private float min2 = 94.5f;

	private float max2 = 95f;

	private void Awake()
	{
		Transform transform = ((Component)this).transform;
		saveable = ((Component)transform.parent.parent).GetComponent<SaveableObject>();
		leftOar = ((Component)transform.GetChild(0).GetChild(0)).GetComponent<Oar>();
		rightOar = ((Component)transform.GetChild(1).GetChild(0)).GetComponent<Oar>();
		leftOar.locks = this;
		rightOar.locks = this;
	}

	public override void OnActivate()
	{
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		if (saveable.extraSetting)
		{
			if (!oarUp)
			{
				oarUp = true;
				SetPosition(oarUp);
				Juicebox.juice.PlaySoundAt("lock unlock", ((Component)this).transform.position, 0f, 0.66f, 0.88f);
			}
			else
			{
				oarUp = false;
				SetPosition(oarUp);
				Juicebox.juice.PlaySoundAt("lock unlock", ((Component)this).transform.position, 0f, 0.66f, 0.88f);
			}
		}
	}

	public void SetPosition(bool up)
	{
		//IL_0015: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		if (up)
		{
			JointLimits limits = leftOar.joint.limits;
			JointLimits limits2 = leftOar.parentJoint.limits;
			((JointLimits)(ref limits)).min = min1;
			((JointLimits)(ref limits)).max = max1;
			((JointLimits)(ref limits2)).min = min2;
			((JointLimits)(ref limits2)).max = max2;
			leftOar.joint.limits = limits;
			rightOar.joint.limits = limits;
			leftOar.parentJoint.limits = limits2;
			rightOar.parentJoint.limits = limits2;
			leftOar.joint.useLimits = true;
			rightOar.joint.useLimits = true;
			leftOar.parentJoint.useLimits = true;
			rightOar.parentJoint.useLimits = true;
			leftOar.joint.useSpring = false;
			rightOar.joint.useSpring = false;
			leftOar.parentJoint.useSpring = false;
			rightOar.parentJoint.useSpring = false;
		}
		else
		{
			leftOar.joint.useLimits = false;
			rightOar.joint.useLimits = false;
			leftOar.parentJoint.useLimits = false;
			rightOar.parentJoint.useLimits = false;
			leftOar.joint.useSpring = true;
			rightOar.joint.useSpring = true;
			leftOar.parentJoint.useSpring = true;
			rightOar.parentJoint.useSpring = true;
		}
	}
}
public class Oar : GoPointerButton
{
	[CompilerGenerated]
	private sealed class <Row>d__18 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public float dir;

		public Oar <>4__this;

		private JointSpring <spring1>5__1;

		private JointSpring <spring2>5__2;

		private float <t>5__3;

		private float <heel>5__4;

		private float <angle>5__5;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <Row>d__18(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>4__this.rowing = true;
				<spring1>5__1 = <>4__this.joint.spring;
				<spring2>5__2 = <>4__this.parentJoint.spring;
				<t>5__3 = 0f;
				break;
			case 1:
				<>1__state = -1;
				<t>5__3 += Time.deltaTime * 0.5f;
				break;
			}
			if (<t>5__3 <= 1f)
			{
				<heel>5__4 = GetBoatHeeling() * (float)<>4__this.isLeft;
				<angle>5__5 = <t>5__3 * 2f * (float)Math.PI;
				<spring1>5__1.targetPosition = Mathf.Lerp(-10f + <heel>5__4, 25f + <heel>5__4, 0.5f + 0.5f * Mathf.Sin(<angle>5__5));
				<>4__this.joint.spring = <spring1>5__1;
				<spring2>5__2.targetPosition = Mathf.Lerp(35f * dir, -35f * dir, 0.5f + 0.5f * Mathf.Cos(<angle>5__5));
				<>4__this.parentJoint.spring = <spring2>5__2;
				<>2__current = (object)new WaitForEndOfFrame();
				<>1__state = 1;
				return true;
			}
			<>4__this.AddOarForce(dir);
			<>4__this.rowing = false;
			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 Oar leftOar;

	private Oar rightOar;

	public HingeJoint joint;

	public HingeJoint parentJoint;

	public static bool grabbed;

	public static bool used;

	public static bool firstTime;

	public bool rowing;

	private int isLeft;

	private Rigidbody rb;

	private Transform forcePoint;

	public Rudder rudder;

	public TillerRudder tiller;

	public OarLocks locks;

	private void Awake()
	{
		joint = ((Component)this).GetComponent<HingeJoint>();
		parentJoint = ((Component)((Component)this).transform.parent).GetComponent<HingeJoint>();
		if (((Object)this).name == "oar_left")
		{
			leftOar = this;
			isLeft = 1;
			rightOar = ((Component)((Component)this).transform.parent.parent.GetChild(1)).GetComponentInChildren<Oar>();
			forcePoint = ((Component)this).transform.parent.parent.GetChild(2);
		}
		else
		{
			rightOar = this;
			isLeft = -1;
			leftOar = ((Component)((Component)this).transform.parent.parent.GetChild(0)).GetComponentInChildren<Oar>();
			forcePoint = ((Component)this).transform.parent.parent.GetChild(3);
		}
		rb = ((Component)((Component)this).transform.parent.parent.parent.parent).GetComponent<Rigidbody>();
		rudder = ((Component)((Component)rb).transform.Find("cutterModel").Find("rudder")).GetComponent<Rudder>();
	}

	public override void OnActivate(GoPointer activatingPointer)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		if (Settings.steeringWithMouse && (int)activatingPointer.type == 2)
		{
			MouseLook.ToggleMouseLook(false);
		}
		if (!Settings.steeringWithMouse && (int)activatingPointer.type == 2)
		{
			((GoPointerButton)this).StickyClick(activatingPointer);
		}
	}

	public override void OnUnactivate(GoPointer activatingPointer)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		if (Settings.steeringWithMouse && (int)activatingPointer.type == 2)
		{
			MouseLook.ToggleMouseLook(true);
		}
	}

	public override void ExtraLateUpdate()
	{
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		if (!firstTime)
		{
			locks.oarUp = true;
			locks.SetPosition(locks.oarUp);
			firstTime = true;
		}
		else
		{
			if (locks.oarUp)
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)base.stickyClickedBy) || base.isClicked)
			{
				leftOar.joint.useLimits = false;
				leftOar.joint.useSpring = true;
				rightOar.joint.useLimits = false;
				rightOar.joint.useSpring = true;
				used = true;
				if ((Object)(object)tiller == (Object)null)
				{
					tiller = ((Component)((Component)rudder).transform.GetChild(0)).GetComponent<TillerRudder>();
				}
				if (!tiller.locked)
				{
					rudder.rudderPower = 0f;
				}
				if (Input.GetKey(DinghiesMain.leftFConfig.Value) && !leftOar.rowing)
				{
					((MonoBehaviour)this).StartCoroutine(leftOar.Row(1f));
				}
				if (Input.GetKey(DinghiesMain.rightFConfig.Value) && !rightOar.rowing)
				{
					((MonoBehaviour)this).StartCoroutine(rightOar.Row(1f));
				}
				if (Input.GetKey(DinghiesMain.leftBConfig.Value) && !leftOar.rowing)
				{
					((MonoBehaviour)this).StartCoroutine(leftOar.Row(-1f));
				}
				if (Input.GetKey(DinghiesMain.rightBConfig.Value) && !rightOar.rowing)
				{
					((MonoBehaviour)this).StartCoroutine(rightOar.Row(-1f));
				}
			}
			else if (used && !Object.op_Implicit((Object)(object)((GoPointerButton)leftOar).stickyClickedBy) && !Object.op_Implicit((Object)(object)((GoPointerButton)rightOar).stickyClickedBy) && !((GoPointerButton)leftOar).isClicked && !((GoPointerButton)rightOar).isClicked)
			{
				rudder.rudderPower = 10f;
				leftOar.ResetPos();
				rightOar.ResetPos();
			}
		}
	}

	[IteratorStateMachine(typeof(<Row>d__18))]
	public IEnumerator Row(float dir)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <Row>d__18(0)
		{
			<>4__this = this,
			dir = dir
		};
	}

	public void ResetPos()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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_009d: 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)
		JointSpring spring = joint.spring;
		JointSpring spring2 = parentJoint.spring;
		JointLimits limits = joint.limits;
		spring.targetPosition = 0f;
		spring2.targetPosition = 0f;
		((JointLimits)(ref limits)).max = 45f;
		rightOar.joint.spring = spring;
		leftOar.joint.spring = spring;
		rightOar.parentJoint.spring = spring2;
		leftOar.parentJoint.spring = spring2;
		rightOar.joint.limits = limits;
		leftOar.joint.limits = limits;
		joint.useLimits = true;
		joint.useSpring = false;
		used = false;
	}

	private void AddOarForce(float dir)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: 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_0071: 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_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		Juicebox.juice.PlaySoundAt("ug tank splash", ((Component)this).transform.position, 2f, 1f);
		float z = ((Component)rb).transform.InverseTransformDirection(rb.velocity).z;
		Vector3 val = ((dir > 0f) ? ((Component)rb).transform.forward : (-((Component)rb).transform.forward));
		Vector3 velocity = rb.velocity;
		float magnitude = ((Vector3)(ref velocity)).magnitude;
		float num = Mathf.Lerp(250f, 0f, Mathf.Clamp(magnitude, 0f, 2f) / 2f);
		if (z * dir < 0f)
		{
			num = 200f;
		}
		rb.AddForceAtPosition(val * num, forcePoint.position, (ForceMode)1);
	}

	private static float GetBoatHeeling()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		Transform currentBoat = GameState.currentBoat;
		Vector3 up = ((Component)currentBoat).transform.up;
		return Vector3.SignedAngle(up, Vector3.up, -Vector3.forward);
	}
}
internal class SaveCleaner
{
	[HarmonyPriority(300)]
	[HarmonyPrefix]
	private static void CleanSave(int backupIndex)
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		Debug.LogWarning((object)"Dinghies: CleanSave running");
		Debug.LogWarning((object)("Dinghies: cleaning save " + SaveSlots.currentSlot));
		string path = ((backupIndex != 0) ? SaveSlots.GetBackupPath(SaveSlots.currentSlot, backupIndex) : SaveSlots.GetCurrentSavePath());
		BinaryFormatter binaryFormatter = new BinaryFormatter();
		SaveContainer val;
		using (FileStream serializationStream = File.Open(path, FileMode.Open))
		{
			val = (SaveContainer)binaryFormatter.Deserialize(serializationStream);
		}
		if (IndexManager.loadedIndexMap.Count == 0)
		{
			val.savedPrefabs.RemoveAll((SavePrefabData x) => x.itemParentObject == 130 || x.itemParentObject == 131 || x.itemParentObject == 132);
			val.savedObjects.RemoveAll((SaveObjectData x) => x.sceneIndex == 130 || x.sceneIndex == 131 || x.sceneIndex == 132);
		}
		else
		{
			foreach (string boat in IndexManager.loadedIndexMap.Keys)
			{
				if (boat == "DNG Cutter")
				{
					val.savedPrefabs.RemoveAll((SavePrefabData x) => x.itemParentObject == IndexManager.loadedIndexMap[boat] || x.itemParentObject == IndexManager.loadedIndexMap[boat] + 1 || x.itemParentObject == IndexManager.loadedIndexMap[boat] + 2);
					val.savedObjects.RemoveAll((SaveObjectData x) => x.sceneIndex == IndexManager.loadedIndexMap[boat] || x.sceneIndex == IndexManager.loadedIndexMap[boat] + 1 || x.sceneIndex == IndexManager.loadedIndexMap[boat] + 2);
				}
			}
			foreach (SaveObjectData savedObject in val.savedObjects)
			{
				if (savedObject.customization != null && savedObject.sceneIndex != 20 && savedObject.sceneIndex != 50 && savedObject.sceneIndex != 70 && savedObject.sceneIndex != 80)
				{
					savedObject.customization = CleanDavits(savedObject.customization, savedObject.sceneIndex);
				}
			}
		}
		using (FileStream serializationStream2 = File.Open(path, FileMode.Create))
		{
			binaryFormatter.Serialize(serializationStream2, val);
		}
		Debug.LogWarning((object)"Dinghies: save cleaned...");
	}

	private static SaveBoatCustomizationData CleanDavits(SaveBoatCustomizationData custom, int index)
	{
		BoatCustomParts component = ((Component)SaveLoadManager.instance.GetCurrentObjects()[index]).GetComponent<BoatCustomParts>();
		if (custom.partActiveOptions.Count > component.availableParts.Count)
		{
			custom.partActiveOptions.RemoveRange(component.availableParts.Count, custom.partActiveOptions.Count - component.availableParts.Count);
		}
		for (int i = 0; i < custom.partActiveOptions.Count; i++)
		{
			if (custom.partActiveOptions[i] >= component.availableParts[i].partOptions.Count)
			{
				custom.partActiveOptions[i] = component.availableParts[i].activeOption;
			}
		}
		return custom;
	}
}
public class StowingBrackets : GoPointerButton
{
	internal class BracketSaver
	{
		public string bracket;

		public string hook;

		public static string Serialize(List<BracketSaver> bracketSavers)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (BracketSaver bracketSaver in bracketSavers)
			{
				stringBuilder.Append(bracketSaver.bracket);
				stringBuilder.Append(':');
				stringBuilder.Append(bracketSaver.hook);
				stringBuilder.Append(';');
			}
			return stringBuilder.ToString();
		}

		public static List<BracketSaver> Unserialize(string s)
		{
			List<BracketSaver> list = new List<BracketSaver>();
			string[] array = s.Split(new char[1] { ';' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (!(text == ""))
				{
					string[] array3 = text.Split(new char[1] { ':' });
					BracketSaver item = new BracketSaver
					{
						bracket = array3[0],
						hook = array3[1]
					};
					list.Add(item);
				}
			}
			return list;
		}
	}

	private const string key = "pr0.dinghies.stowingBrackets";

	private bool connected;

	private bool initialized;

	private static int toLoad;

	private ConfigurableJoint joint;

	private Hook hook;

	private static List<BracketSaver> bracketSavers;

	private BracketSaver saver;

	public void Init(ConfigurableJoint j)
	{
		joint = j;
		if (bracketSavers == null)
		{
			bracketSavers = new List<BracketSaver>();
		}
		saver = new BracketSaver();
	}

	public void FixedUpdate()
	{
		if (!initialized)
		{
			LoadBracket();
			initialized = true;
		}
		GoPointer pointedAtBy = base.pointedAtBy;
		if ((Object)(object)((pointedAtBy != null) ? pointedAtBy.GetHeldItem() : null) == (Object)null)
		{
			((GoPointerButton)this).ForceUnlook();
		}
	}

	public override void OnActivate()
	{
		GoPointerMovement isClickedBy = base.isClickedBy;
		object obj;
		if (isClickedBy == null)
		{
			obj = null;
		}
		else
		{
			GoPointer pointer = isClickedBy.pointer;
			if (pointer == null)
			{
				obj = null;
			}
			else
			{
				PickupableItem heldItem = pointer.GetHeldItem();
				obj = ((heldItem != null) ? ((Component)heldItem).GetComponent<Hook>() : null);
			}
		}
		Hook hook = (Hook)obj;
		if ((Object)(object)hook != (Object)null)
		{
			ConnectHook(hook);
		}
		else if (connected)
		{
			connected = false;
			DisconnectHook();
		}
		((GoPointerButton)this).ForceUnlook();
	}

	private void ConnectHook(Hook h)
	{
		hook = h;
		((Joint)joint).connectedBody = hook.rigidbody;
		joint.xMotion = (ConfigurableJointMotion)0;
		joint.yMotion = (ConfigurableJointMotion)0;
		joint.zMotion = (ConfigurableJointMotion)0;
		hook.bracket = this;
		((PickupableItem)hook).OnDrop();
		GoPointer held = ((PickupableItem)hook).held;
		if (held != null)
		{
			held.DropItem();
		}
		connected = true;
		if (toLoad == 0)
		{
			SaveBracket();
		}
		else
		{
			toLoad--;
		}
	}

	public void DisconnectHook()
	{
		joint.xMotion = (ConfigurableJointMotion)2;
		joint.yMotion = (ConfigurableJointMotion)2;
		joint.zMotion = (ConfigurableJointMotion)2;
		((Joint)joint).connectedBody = null;
		hook.bracket = null;
		hook = null;
		connected = false;
		UnsaveBracket();
	}

	private void LoadBracket()
	{
		if (!GameState.modData.ContainsKey("pr0.dinghies.stowingBrackets"))
		{
			return;
		}
		List<BracketSaver> list = BracketSaver.Unserialize(GameState.modData["pr0.dinghies.stowingBrackets"]);
		if (toLoad == 0)
		{
			toLoad = list.Count;
		}
		foreach (BracketSaver item in list)
		{
			if (item.bracket == ((Object)this).name)
			{
				hook = GameObject.Find(item.hook).GetComponent<Hook>();
				ConnectHook(hook);
				break;
			}
		}
	}

	private void SaveBracket()
	{
		saver.bracket = ((Object)this).name;
		saver.hook = ((Object)hook).name;
		if (!bracketSavers.Contains(saver))
		{
			bracketSavers.Add(saver);
		}
		GameState.modData["pr0.dinghies.stowingBrackets"] = BracketSaver.Serialize(bracketSavers);
	}

	private void UnsaveBracket()
	{
		if (bracketSavers.Contains(saver))
		{
			bracketSavers.Remove(saver);
		}
		if (bracketSavers.Count == 0)
		{
			GameState.modData["pr0.dinghies.stowingBrackets"] = "";
		}
		else
		{
			GameState.modData["pr0.dinghies.stowingBrackets"] = BracketSaver.Serialize(bracketSavers);
		}
	}
}
public class TillerRudder : GoPointerButton
{
	private Rudder rudder;

	private HingeJoint hingeJoint;

	private AudioSource audio;

	public bool locked;

	private bool held;

	public float input;

	private float lastInput;

	private float rotationAngleLimit;

	private const float volumeMult = 0.05f;

	private const float mult = 0.025f;

	public void Init(Rudder r, HingeJoint j, AudioSource a)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		rudder = r;
		hingeJoint = j;
		audio = a;
		input = 0f;
		lastInput = 0f;
		JointLimits limits = hingeJoint.limits;
		rotationAngleLimit = ((JointLimits)(ref limits)).max;
	}

	public override void OnActivate(GoPointer activatingPointer)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		if (Settings.steeringWithMouse && (int)activatingPointer.type == 2)
		{
			MouseLook.ToggleMouseLook(false);
		}
		if (!Settings.steeringWithMouse && (int)activatingPointer.type == 2)
		{
			((GoPointerButton)this).StickyClick(activatingPointer);
		}
		if (locked)
		{
			Unlock();
		}
	}

	public override void OnUnactivate(GoPointer activatingPointer)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		if (Settings.steeringWithMouse && (int)activatingPointer.type == 2)
		{
			MouseLook.ToggleMouseLook(true);
		}
	}

	private void ToggleLock()
	{
		if (!locked)
		{
			Lock();
		}
		else
		{
			Unlock();
		}
	}

	private void Lock()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)base.stickyClickedBy))
		{
			((GoPointerButton)this).UnStickyClick();
		}
		locked = true;
		Juicebox.juice.PlaySoundAt("lock unlock", ((Component)this).transform.position, 0f, 0.66f, 0.88f);
	}

	private void Unlock()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		locked = false;
		Juicebox.juice.PlaySoundAt("lock unlock", ((Component)this).transform.position, 0f, 0.66f, 1f);
	}

	public override void ExtraLateUpdate()
	{
		//IL_0090: 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 (Object.op_Implicit((Object)(object)base.stickyClickedBy) || base.isClicked)
		{
			if (base.stickyClickedBy.AltButtonDown())
			{
				ToggleLock();
			}
			if (!locked)
			{
				if (!held)
				{
					held = true;
					ChangeDamper(held);
				}
				int num = ((!DinghiesMain.invertedTillerConfig.Value) ? 1 : (-1));
				input += base.stickyClickedBy.movement.GetKeyboardDelta().x * 0.025f * (float)num;
				if (base.stickyClickedBy.movement.GetKeyboardDelta().y != 0f)
				{
					input = 0f;
				}
			}
			ApplyRotationLimit();
			RotateRudder();
		}
		else if (locked)
		{
			ApplyRotationLimit();
			RotateRudder();
		}
		else
		{
			if (held)
			{
				held = false;
				ChangeDamper(held);
			}
			input = rudder.currentAngle;
		}
		if (Object.op_Implicit((Object)(object)audio))
		{
			float num2 = Mathf.Abs(input - lastInput) / Time.deltaTime;
			audio.volume = Mathf.Lerp(audio.volume, num2 * 0.05f, Time.deltaTime * 3f);
		}
		lastInput = input;
	}

	private void RotateRudder()
	{
		//IL_0015: 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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		float num = input / rotationAngleLimit;
		JointSpring spring = hingeJoint.spring;
		JointLimits limits = hingeJoint.limits;
		spring.targetPosition = ((JointLimits)(ref limits)).max * num;
		hingeJoint.spring = spring;
	}

	private void ApplyRotationLimit()
	{
		if (input > rotationAngleLimit)
		{
			input = rotationAngleLimit;
		}
		if (input < 0f - rotationAngleLimit)
		{
			input = 0f - rotationAngleLimit;
		}
	}

	private void ChangeDamper(bool held)
	{
		//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_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: 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)
		if (held)
		{
			JointSpring spring = hingeJoint.spring;
			spring.spring = 250f;
			spring.damper = 50f;
			hingeJoint.spring = spring;
		}
		else
		{
			JointSpring spring2 = hingeJoint.spring;
			spring2.spring = 50f;
			spring2.damper = 10f;
			hingeJoint.spring = spring2;
		}
	}
}
[BepInPlugin("pr0skynesis.dinghies", "Dinghies", "1.0.9")]
public class DinghiesMain : BaseUnityPlugin
{
	public const string pluginGuid = "pr0skynesis.dinghies";

	public const string pluginName = "Dinghies";

	public const string pluginVersion = "1.0.9";

	public const string shortName = "pr0.dinghies";

	public static ConfigEntry<bool> nothingConfig;

	public static ConfigEntry<bool> invertedTillerConfig;

	public static ConfigEntry<KeyCode> leftFConfig;

	public static ConfigEntry<KeyCode> rightFConfig;

	public static ConfigEntry<KeyCode> leftBConfig;

	public static ConfigEntry<KeyCode> rightBConfig;

	public static ConfigEntry<bool> saveCleanerConfig;

	public static ConfigEntry<bool> notificationsConfig;

	public static ConfigEntry<string> lastNoteVer;

	public void Awake()
	{
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Expected O, but got Unknown
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Expected O, but got Unknown
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Expected O, but got Unknown
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Expected O, but got Unknown
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Expected O, but got Unknown
		//IL_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Expected O, but got Unknown
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Expected O, but got Unknown
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_0320: Expected O, but got Unknown
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: Expected O, but got Unknown
		nothingConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("A) General Settings", "nothing", true, "This setting does nothing. Default is true, set to false to disable.");
		invertedTillerConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("B) Rudder Settings", "Inverted Tiller", false, "Inverts the tiller control, e.g. press left to move right. Default is false, set to true to enable.");
		leftFConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("C) Rowing Settings", "Forward Left Button", (KeyCode)97, "Controls the rowing forward of the left oar. Default is A. Use the Bepniex Configuration Manager for this!;");
		rightFConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("C) Rowing Settings", "Forward Right Button", (KeyCode)100, "Controls the rowing forward of the right oar. Default is D. Use the Bepniex Configuration Manager for this!;");
		leftBConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("C) Rowing Settings", "Bakcward Left Button", (KeyCode)113, "Controls the rowing backward of the left oar. Default is Q. Use the Bepniex Configuration Manager for this!;");
		rightBConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("C) Rowing Settings", "Backward Right Button", (KeyCode)101, "Controls the rowing backward of the right oar. Default is E. Use the Bepniex Configuration Manager for this!;");
		saveCleanerConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("D) Other Settings", "Save Cleaner", false, "Removes the saves dependency on this mod. Only use if you want to remove the mod from an ongoing save! Change to true (with the game closed), open the game → load the save → save → close the game → remove the mod → done. A save backup is recommended.");
		notificationsConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("D) Other Settings", "Notifications", true, "Enable this mod notifications on startup. Set to false to disable.");
		lastNoteVer = ((BaseUnityPlugin)this).Config.Bind<string>("D) Other Settings", "Last Note Version", "", "Saves the hash of the last notification. Only change this if you want to see the last notification again.");
		Harmony val = new Harmony("pr0skynesis.dinghies");
		MethodInfo methodInfo = AccessTools.Method(typeof(SaveLoadManager), "LoadGame", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(IndexManager), "Manager", (Type[])null, (Type[])null);
		val.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo3 = AccessTools.Method(typeof(SaveLoadManager), "LoadModData", (Type[])null, (Type[])null);
		MethodInfo methodInfo4 = AccessTools.Method(typeof(IndexManager), "SaveIndex", (Type[])null, (Type[])null);
		val.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo5 = AccessTools.Method(typeof(StartMenu), "StartNewGame", (Type[])null, (Type[])null);
		MethodInfo methodInfo6 = AccessTools.Method(typeof(IndexManager), "StartNewGamePatch", (Type[])null, (Type[])null);
		val.Patch((MethodBase)methodInfo5, new HarmonyMethod(methodInfo6), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo7 = AccessTools.Method(typeof(BoatImpactSounds), "Impact", (Type[])null, (Type[])null);
		MethodInfo methodInfo8 = AccessTools.Method(typeof(DinghiesPatches), "ImpactPatch", (Type[])null, (Type[])null);
		val.Patch((MethodBase)methodInfo7, new HarmonyMethod(methodInfo8), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo methodInfo9 = AccessTools.Method(typeof(CargoStorageUI), "Update", (Type[])null, (Type[])null);
		MethodInfo methodInfo10 = AccessTools.Method(typeof(DinghiesPatches), "CartDudePatch", (Type[])null, (Type[])null);
		val.Patch((MethodBase)methodInfo9, new HarmonyMethod(methodInfo10), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		if (!saveCleanerConfig.Value)
		{
			MethodInfo methodInfo11 = AccessTools.Method(typeof(FloatingOriginManager), "Start", (Type[])null, (Type[])null);
			MethodInfo methodInfo12 = AccessTools.Method(typeof(DinghiesPatches), "StartPatch", (Type[])null, (Type[])null);
			val.Patch((MethodBase)methodInfo11, new HarmonyMethod(methodInfo12), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo13 = AccessTools.Method(typeof(Mast), "Start", (Type[])null, (Type[])null);
			MethodInfo methodInfo14 = AccessTools.Method(typeof(DinghiesPatches), "SailSetupPatch", (Type[])null, (Type[])null);
			val.Patch((MethodBase)methodInfo13, new HarmonyMethod(methodInfo14), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo15 = AccessTools.Method(typeof(Mast), "AttachInitialSail", (Type[])null, (Type[])null);
			MethodInfo methodInfo16 = AccessTools.Method(typeof(DinghiesPatches), "SailSetupPatch2", (Type[])null, (Type[])null);
			val.Patch((MethodBase)methodInfo15, (HarmonyMethod)null, new HarmonyMethod(methodInfo16), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		else
		{
			MethodInfo methodInfo17 = AccessTools.Method(typeof(SaveLoadManager), "LoadGame", (Type[])null, (Type[])null);
			MethodInfo methodInfo18 = AccessTools.Method(typeof(SaveCleaner), "CleanSave", (Type[])null, (Type[])null);
			val.Patch((MethodBase)methodInfo17, new HarmonyMethod(methodInfo18), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}
}

DinghiesBridge.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using Dinghies;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("DinghiesBridge")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DinghiesBridge")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cf3f6bc0-d29d-4def-bc02-4094bead3a25")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DinghiesBridge;

public class HookBridge : MonoBehaviour
{
	public Transform block;

	public void Awake()
	{
		((Component)this).gameObject.AddComponent<Hook>().Init(block);
		Object.Destroy((Object)(object)this);
	}
}
public class NotificationButtonBridge : MonoBehaviour
{
	[Tooltip("Set to 0 for link button, set to 1 for ok button")]
	public int typeIndex;

	public string url;

	public void Awake()
	{
		((Component)this).gameObject.AddComponent<NotificationButton>().Init(typeIndex, url);
	}
}
public class NotificationManager : MonoBehaviour
{
	[Serializable]
	internal class MessageNote
	{
		public string mod;

		public string latestVersion;

		public string header;

		public string message;

		public float charSize;

		public string messageVersion;
	}

	[CompilerGenerated]
	private sealed class <CheckForUpdate>d__5 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public NotificationManager <>4__this;

		private UnityWebRequest <www>5__1;

		private string <jsonResponse>5__2;

		private MessageNote <note>5__3;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <CheckForUpdate>d__5(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || num == 1)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<www>5__1 = null;
			<jsonResponse>5__2 = null;
			<note>5__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			try
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<www>5__1 = UnityWebRequest.Get("https://raw.githubusercontent.com/alesparise/Dinghies-Sailwind-Mod/refs/heads/main/notification.json");
					<>1__state = -3;
					<>2__current = <www>5__1.SendWebRequest();
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -3;
					if (<www>5__1.isNetworkError || <www>5__1.isHttpError)
					{
						((Component)<>4__this).gameObject.SetActive(false);
						Debug.LogError((object)("Dinghies: cannot fetch notifications from GitHub: " + <www>5__1.error));
					}
					else
					{
						<jsonResponse>5__2 = <www>5__1.downloadHandler.text;
						<note>5__3 = JsonUtility.FromJson<MessageNote>(<jsonResponse>5__2);
						if (<note>5__3.messageVersion != DinghiesMain.lastNoteVer.Value || <>4__this.debugMessage)
						{
							<>4__this.header.text = <note>5__3.header;
							<>4__this.message.text = <note>5__3.message;
							<>4__this.message.characterSize = <note>5__3.charSize;
							DinghiesMain.lastNoteVer.Value = <note>5__3.messageVersion;
							if (<>4__this.debugMessage)
							{
								Debug.LogWarning((object)("Message:\n" + <note>5__3.message));
							}
						}
						else
						{
							((Component)<>4__this).gameObject.SetActive(false);
						}
						<jsonResponse>5__2 = null;
						<note>5__3 = null;
					}
					<>m__Finally1();
					<www>5__1 = null;
					return false;
				}
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<www>5__1 != null)
			{
				((IDisposable)<www>5__1).Dispose();
			}
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private const string URL = "https://raw.githubusercontent.com/alesparise/Dinghies-Sailwind-Mod/refs/heads/main/notification.json";

	public TextMesh header;

	public TextMesh message;

	private bool debugMessage = false;

	public void Awake()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = GameObject.FindGameObjectWithTag("Player").transform;
		((Component)this).transform.parent = transform;
		((Component)this).transform.localPosition = new Vector3(0f, 0.75f, 0.5f);
		((Component)this).transform.localRotation = Quaternion.identity;
		((MonoBehaviour)this).StartCoroutine(CheckForUpdate());
	}

	[IteratorStateMachine(typeof(<CheckForUpdate>d__5))]
	private IEnumerator CheckForUpdate()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <CheckForUpdate>d__5(0)
		{
			<>4__this = this
		};
	}
}
public class RopeControllerDavitsBridge : MonoBehaviour
{
	public RopeEffect hookRope;

	public void Awake()
	{
		((Component)this).gameObject.AddComponent<RopeControllerDavits>().Init(hookRope);
	}
}
public class StowingBracketsBridge : MonoBehaviour
{
	internal class StowingSaver
	{
		public string davits;

		public string boat;

		public static string Serialize(List<StowingSaver> stowingSavers)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (StowingSaver stowingSaver in stowingSavers)
			{
				stringBuilder.Append(stowingSaver.davits);
				stringBuilder.Append(':');
				stringBuilder.Append(stowingSaver.boat);
				stringBuilder.Append(';');
			}
			return stringBuilder.ToString();
		}

		public static List<StowingSaver> Unserialize(string s)
		{
			List<StowingSaver> list = new List<StowingSaver>();
			string[] array = s.Split(new char[1] { ';' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (!(text == ""))
				{
					string[] array3 = text.Split(new char[1] { ':' });
					StowingSaver item = new StowingSaver
					{
						davits = array3[0],
						boat = array3[1]
					};
					list.Add(item);
				}
			}
			return list;
		}
	}

	public Transform stowedBoat;

	private void Awake()
	{
		ConfigurableJoint[] components = ((Component)stowedBoat).GetComponents<ConfigurableJoint>();
		ConfigurableJoint val = (((Object)this).name.Contains("0") ? components[0] : components[1]);
		((Component)this).gameObject.AddComponent<StowingBrackets>().Init(val);
		Object.Destroy((Object)(object)this);
	}
}
public class TarpBridge : MonoBehaviour
{
	public void Awake()
	{
		((Component)this).gameObject.AddComponent<Tarp>();
		Object.Destroy((Object)(object)this);
	}
}
public class TarpPackBridge : MonoBehaviour
{
	public Transform davits;

	public void Awake()
	{
		((Component)this).gameObject.AddComponent<TarpPack>().Init(davits);
		Object.Destroy((Object)(object)this);
	}
}
public class TillerBridge : MonoBehaviour
{
	public Rudder rudder;

	public HingeJoint hingeJoint;

	public AudioSource audio;

	public void Awake()
	{
		((Component)this).gameObject.AddComponent<TillerRudder>().Init(rudder, hingeJoint, audio);
		Object.Destroy((Object)(object)this);
	}
}

DinghiesScripts.dll

Decompiled 3 weeks ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("DinghiesScripts")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DinghiesScripts")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0d5504c4-f5a6-4702-9213-368175d39c48")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DinghiesScripts;

public class Davits : MonoBehaviour
{
	internal class StowingSaver
	{
		public string davits;

		public string boat;

		public static string Serialize(List<StowingSaver> stowingSavers)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (StowingSaver stowingSaver in stowingSavers)
			{
				stringBuilder.Append(stowingSaver.davits);
				stringBuilder.Append(':');
				stringBuilder.Append(stowingSaver.boat);
				stringBuilder.Append(';');
			}
			return stringBuilder.ToString();
		}

		public static List<StowingSaver> Unserialize(string s)
		{
			List<StowingSaver> list = new List<StowingSaver>();
			string[] array = s.Split(new char[1] { ';' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (!(text == ""))
				{
					string[] array3 = text.Split(new char[1] { ':' });
					StowingSaver item = new StowingSaver
					{
						davits = array3[0],
						boat = array3[1]
					};
					list.Add(item);
				}
			}
			return list;
		}
	}

	private const string key = "pr0.dinghies.stowing";

	public GameObject tarpPackage;

	public GameObject winch0;

	public GameObject winch1;

	private GameObject boat;

	public GameObject stowedBoat;

	public ConfigurableJoint hook0;

	public ConfigurableJoint hook1;

	private Rigidbody boatAnchor;

	private bool initialized = false;

	private static int toLoad;

	private List<Renderer> toHide;

	public static List<Davits> list;

	private static List<StowingSaver> savers;

	private StowingSaver saver;

	public void Awake()
	{
		if (list == null)
		{
			list = new List<Davits>();
		}
		list.Add(this);
		if (savers == null)
		{
			savers = new List<StowingSaver>();
		}
		saver = new StowingSaver();
	}

	public void FixedUpdate()
	{
		//IL_003e: 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_0093: Unknown result type (might be due to invalid IL or missing references)
		if (!initialized && GameState.playing)
		{
			winch0.SetActive(true);
			winch1.SetActive(true);
			if (winch0.transform.localScale.x > 0.8f)
			{
				winch0.transform.localScale = new Vector3(0.7f, 0.7f, 0.6f);
				winch1.transform.localScale = new Vector3(0.7f, 0.7f, 0.6f);
			}
			LoadStowed();
			initialized = true;
		}
	}

	public void Stow(GameObject boat, bool loading)
	{
		//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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: 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)
		RegisterBoat(boat);
		Transform transform = boat.transform;
		Transform transform2 = stowedBoat.transform;
		if (!loading)
		{
			transform2.position = transform.position;
			transform2.rotation = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y - 90f, transform.eulerAngles.z);
		}
		else
		{
			transform2.position = ((Component)this).transform.position + ((Component)this).transform.forward * 4f;
			transform2.rotation = Quaternion.identity;
		}
		boatAnchor.isKinematic = true;
		((Component)boatAnchor).transform.parent = transform;
		transform.position = new Vector3(transform.position.x, transform.position.y + 400f, transform.position.z);
		boat.GetComponent<Rigidbody>().isKinematic = true;
		HideRenderers(transform);
		stowedBoat.SetActive(true);
		tarpPackage.SetActive(false);
		SaveStowed();
		Debug.LogWarning((object)"Davits: stowed");
	}

	public void Launch()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = boat.transform;
		Transform transform2 = stowedBoat.transform;
		transform.position = transform2.position;
		transform.rotation = Quaternion.Euler(transform2.eulerAngles.x, transform2.eulerAngles.y + 90f, transform2.eulerAngles.z);
		stowedBoat.SetActive(false);
		boat.GetComponent<Rigidbody>().isKinematic = false;
		ShowRenderers(transform);
		boatAnchor.isKinematic = false;
		((Component)boatAnchor).transform.parent = null;
		tarpPackage.SetActive(true);
		UnregisterBoat();
		UnsaveStowed();
		Debug.LogWarning((object)"Davits: launched");
	}

	public void RegisterBoat(GameObject b)
	{
		boat = b;
		stowedBoat = boat.GetComponent<Dinghy>().stowedBoat;
		boatAnchor = ((Component)boat.GetComponent<BoatMooringRopes>().anchor).gameObject.GetComponent<Rigidbody>();
	}

	private void UnregisterBoat()
	{
		boat = null;
		stowedBoat = null;
		boatAnchor = null;
	}

	private void LoadStowed()
	{
		if (!GameState.modData.ContainsKey("pr0.dinghies.stowing"))
		{
			return;
		}
		List<StowingSaver> list = StowingSaver.Unserialize(GameState.modData["pr0.dinghies.stowing"]);
		if (toLoad == 0)
		{
			toLoad = list.Count;
		}
		foreach (StowingSaver item in list)
		{
			if (item.davits == ((Object)this).name)
			{
				Stow(GameObject.Find(item.boat), loading: true);
				break;
			}
		}
	}

	private void SaveStowed()
	{
		saver.boat = ((Object)boat).name;
		saver.davits = ((Object)this).name;
		if (!savers.Contains(saver))
		{
			savers.Add(saver);
		}
		GameState.modData["pr0.dinghies.stowing"] = StowingSaver.Serialize(savers);
		Debug.LogWarning((object)("Saved stowed boat from " + ((Object)this).name));
	}

	private void UnsaveStowed()
	{
		if (savers.Contains(saver))
		{
			savers.Remove(saver);
		}
		if (savers.Count == 0)
		{
			GameState.modData["pr0.dinghies.stowing"] = "";
		}
		else
		{
			GameState.modData["pr0.dinghies.stowing"] = StowingSaver.Serialize(savers);
		}
		Debug.LogWarning((object)("Unsaved stowed boat from " + ((Object)this).name));
	}

	private void HideRenderers(Transform obj)
	{
		toHide = new List<Renderer>();
		Renderer[] componentsInChildren = ((Component)obj).GetComponentsInChildren<Renderer>();
		foreach (Renderer val in componentsInChildren)
		{
			if (val.enabled)
			{
				toHide.Add(val);
				val.enabled = false;
			}
		}
	}

	private void ShowRenderers(Transform obj)
	{
		foreach (Renderer item in toHide)
		{
			item.enabled = true;
		}
	}
}
public class Dinghy : MonoBehaviour
{
	public GameObject stowedBoat;

	public void Init(GameObject sb)
	{
		stowedBoat = sb;
	}
}
public class HingeJointFix : MonoBehaviour
{
	private Quaternion initialLocalRotation;

	private Vector3 initialLocalPosition;

	private Quaternion localRotationOnDisable;

	private Vector3 localPositionOnDisable;

	private bool hasDisabled;

	private void Awake()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		initialLocalRotation = ((Component)this).transform.localRotation;
		initialLocalPosition = ((Component)this).transform.localPosition;
	}

	private void OnDisable()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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_003c: Unknown result type (might be due to invalid IL or missing references)
		localRotationOnDisable = ((Component)this).transform.localRotation;
		((Component)this).transform.localRotation = initialLocalRotation;
		localPositionOnDisable = ((Component)this).transform.localPosition;
		((Component)this).transform.localPosition = initialLocalPosition;
		hasDisabled = true;
	}

	private void Update()
	{
		//IL_001a: 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)
		if (hasDisabled)
		{
			hasDisabled = false;
			((Component)this).transform.localRotation = localRotationOnDisable;
			((Component)this).transform.localPosition = localPositionOnDisable;
		}
	}
}