Decompiled source of Dinghies v1.0.3

Dinghies.dll

Decompiled 2 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 BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Dinghies;

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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		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.3";
	}

	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 OarLocks : GoPointerButton
{
	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()
	{
		leftOar = ((Component)((Component)this).transform.GetChild(0).GetChild(0)).GetComponent<Oar>();
		rightOar = ((Component)((Component)this).transform.GetChild(1).GetChild(0)).GetComponent<Oar>();
		leftOar.locks = this;
		rightOar.locks = this;
	}

	public override void OnActivate()
	{
		//IL_0075: 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)
		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
{
	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>();
		tiller = ((Component)((Component)rudder).transform.GetChild(0)).GetComponent<TillerRudder>();
	}

	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_0105: 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_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: 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)
				{
					Debug.LogWarning((object)"Dinghies: tiller is null");
				}
				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();
			}
		}
	}

	public IEnumerator Row(float dir)
	{
		rowing = true;
		JointSpring spring1 = joint.spring;
		JointSpring spring2 = parentJoint.spring;
		for (float t = 0f; t <= 1f; t += Time.deltaTime * 0.5f)
		{
			float heel = GetBoatHeeling() * (float)isLeft;
			float angle = t * 2f * (float)Math.PI;
			spring1.targetPosition = Mathf.Lerp(-10f + heel, 25f + heel, 0.5f + 0.5f * Mathf.Sin(angle));
			joint.spring = spring1;
			spring2.targetPosition = Mathf.Lerp(35f * dir, -35f * dir, 0.5f + 0.5f * Mathf.Cos(angle));
			parentJoint.spring = spring2;
			yield return (object)new WaitForEndOfFrame();
		}
		AddOarForce(dir);
		rowing = false;
	}

	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 == "BOAT Cutter (130)")
				{
					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);
				}
			}
		}
		using (FileStream serializationStream2 = File.Open(path, FileMode.Create))
		{
			binaryFormatter.Serialize(serializationStream2, val);
		}
		Debug.LogWarning((object)"Dinghies: save cleaned...");
	}
}
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 float volumeMult = 0.05f;

	private float mult = 0.025f;

	private void Awake()
	{
		//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)
		rudder = ((Component)((Component)this).transform.parent).GetComponent<Rudder>();
		hingeJoint = ((Component)rudder).GetComponent<HingeJoint>();
		input = 0f;
		lastInput = 0f;
		JointLimits limits = hingeJoint.limits;
		rotationAngleLimit = ((JointLimits)(ref limits)).max;
		audio = ((Component)this).GetComponentInChildren<AudioSource>();
	}

	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_00b5: 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 * mult * (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 * volumeMult, 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 RotateRudderAlt()
	{
		//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_0020: Unknown result type (might be due to invalid IL or missing references)
		JointSpring spring = hingeJoint.spring;
		spring.targetPosition = input;
		hingeJoint.spring = spring;
	}

	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.3")]
public class DinghiesMain : BaseUnityPlugin
{
	public const string pluginGuid = "pr0skynesis.dinghies";

	public const string pluginName = "Dinghies";

	public const string pluginVersion = "1.0.3";

	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 void Awake()
	{
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Expected O, but got Unknown
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Expected O, but got Unknown
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: 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_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Expected O, but got Unknown
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Expected O, but got Unknown
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: 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;");
		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;");
		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;");
		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;");
		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.");
		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);
		if (!saveCleanerConfig.Value)
		{
			MethodInfo methodInfo7 = AccessTools.Method(typeof(FloatingOriginManager), "Start", (Type[])null, (Type[])null);
			MethodInfo methodInfo8 = AccessTools.Method(typeof(DinghiesPatches), "StartPatch", (Type[])null, (Type[])null);
			val.Patch((MethodBase)methodInfo7, new HarmonyMethod(methodInfo8), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo9 = AccessTools.Method(typeof(Mast), "Start", (Type[])null, (Type[])null);
			MethodInfo methodInfo10 = AccessTools.Method(typeof(DinghiesPatches), "SailSetupPatch", (Type[])null, (Type[])null);
			val.Patch((MethodBase)methodInfo9, new HarmonyMethod(methodInfo10), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		else
		{
			MethodInfo methodInfo11 = AccessTools.Method(typeof(SaveLoadManager), "LoadGame", (Type[])null, (Type[])null);
			MethodInfo methodInfo12 = AccessTools.Method(typeof(SaveCleaner), "CleanSave", (Type[])null, (Type[])null);
			val.Patch((MethodBase)methodInfo11, new HarmonyMethod(methodInfo12), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}
}
public class DinghiesPatches
{
	public static AssetBundle bundle;

	public static string bundlePath;

	public static GameObject cutter;

	public static GameObject cutterEmbark;

	[HarmonyPrefix]
	public static void StartPatch(FloatingOriginManager __instance)
	{
		SetupThings();
		IndexManager.AssignAvailableIndex(cutter);
		Transform transform = ((Component)__instance).transform;
		SetMooring(cutter, transform);
		cutter = Object.Instantiate<GameObject>(cutter, transform);
		cutterEmbark = ((Component)cutter.transform.Find("WALK cutter")).gameObject;
		cutterEmbark.transform.parent = GameObject.Find("walk cols").transform;
		SetRotation(cutter, -89.8f);
	}

	[HarmonyPrefix]
	public static void SailSetupPatch(Mast __instance)
	{
		if (((Object)((Component)__instance).transform.parent.parent).name == "cutterModel")
		{
			GameObject[] sails = PrefabsDirectory.instance.sails;
			GameObject startSailPrefab = sails[45];
			GameObject startSailPrefab2 = sails[3];
			if (((Object)__instance).name == "mizzen_mast")
			{
				__instance.startSailPrefab = startSailPrefab2;
			}
			if (((Object)__instance).name == "main_mast")
			{
				__instance.startSailPrefab = startSailPrefab;
			}
		}
	}

	public static void SetupThings()
	{
		bundlePath = Paths.PluginPath + "\\Dinghies\\dinghies";
		bundle = AssetBundle.LoadFromFile(bundlePath);
		if ((Object)(object)bundle == (Object)null)
		{
			bundlePath = Paths.PluginPath + "\\Pr0SkyNesis-Dinghies-1.0.3\\dinghies";
			bundle = AssetBundle.LoadFromFile(bundlePath);
			if ((Object)(object)bundle == (Object)null)
			{
				bundlePath = Paths.PluginPath + "\\Pr0SkyNesis-Dinghies\\dinghies";
				bundle = AssetBundle.LoadFromFile(bundlePath);
				if ((Object)(object)bundle == (Object)null)
				{
					Debug.LogError((object)"Dinghies: Bundle not loaded! Did you place it in the correct folder?");
				}
			}
		}
		string text = "Assets/Dinghies/BOAT Cutter (130).prefab";
		cutter = bundle.LoadAsset<GameObject>(text);
		Transform transform = cutter.transform;
		cutter.GetComponent<PurchasableBoat>().region = GameObject.Find("Region Medi").GetComponent<Region>();
		((Component)transform.Find("cutterModel").Find("rudder").Find("rudder_tiller_cutter")).gameObject.AddComponent<TillerRudder>();
		Transform val = transform.Find("cutterModel").Find("oars_locks");
		((Component)val.GetChild(0).GetChild(0)).gameObject.AddComponent<Oar>();
		((Component)val.GetChild(1).GetChild(0)).gameObject.AddComponent<Oar>();
		((Component)val).gameObject.AddComponent<OarLocks>();
		MatLib.RegisterMaterials();
		((Renderer)((Component)transform.Find("WaterFoam")).GetComponent<MeshRenderer>()).material = MatLib.foam;
		((Renderer)((Component)transform.Find("WaterObjectInteractionSphereBack")).GetComponent<MeshRenderer>()).material = MatLib.objectInteraction;
		((Renderer)((Component)transform.Find("WaterObjectInteractionSphereFront")).GetComponent<MeshRenderer>()).material = MatLib.objectInteraction;
		Transform val2 = cutter.transform.Find("cutterModel");
		((Renderer)((Component)val2.Find("mask")).GetComponent<MeshRenderer>()).material = MatLib.convexHull;
		((Renderer)((Component)val2.Find("damage_water")).GetComponent<MeshRenderer>()).material = MatLib.water4;
		((Renderer)((Component)val2.Find("mask_splash")).GetComponent<MeshRenderer>()).material = MatLib.mask;
		((Component)transform.Find("overflow particles")).GetComponent<Renderer>().material = MatLib.overflow;
		((Component)transform.Find("overflow particles (1)")).GetComponent<Renderer>().material = MatLib.overflow;
		((Component)val2.Find("easter_egg")).gameObject.SetActive(false);
		if (DinghiesMain.nothingConfig.Value)
		{
			EasterEgg(((Component)cutter.transform.Find("cutterModel").Find("easter_egg")).gameObject);
		}
	}

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

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

	public static void EasterEgg(GameObject easterEgg)
	{
		DateTime now = DateTime.Now;
		int month = now.Month;
		int day = now.Day;
		if ((month == 12 && day >= 8) || (month == 1 && day <= 6))
		{
			easterEgg.SetActive(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;
	}
}