Decompiled source of AdvancedBoating v0.5.1

AdvancedBoating.dll

Decompiled 3 months 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.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AdvancedBoating")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AdvancedBoating")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4a77fe36-4cdf-47f9-8ffc-4d7e9a7ac1cf")]
[assembly: AssemblyFileVersion("0.5.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.5.1.0")]
[module: UnverifiableCode]
namespace AdvancedBoating;

public class RecipeStub
{
	public class RequirementStub
	{
		public string Component;

		public int Amount;

		public int AmountPerLevel;

		public bool Recoverable = true;

		private RequirementStub()
		{
		}

		public static RequirementStub Parse(string def)
		{
			string[] array = def.Split(new char[1] { ':' });
			if (array.Length < 2)
			{
				return null;
			}
			RequirementStub requirementStub = new RequirementStub();
			requirementStub.Component = array[0];
			int.TryParse(array[1], out requirementStub.Amount);
			if (array.Length > 2)
			{
				int.TryParse(array[2], out requirementStub.AmountPerLevel);
			}
			return requirementStub;
		}
	}

	public ItemDrop Item;

	public string CraftingStation;

	public string RepairStation;

	public int MinStationLevel = 1;

	public List<RequirementStub> Requirements = new List<RequirementStub>();

	public string Name => "Recipe" + ((Object)Item).name;
}
[HarmonyPatch]
public static class AssetHelper
{
	public static readonly List<GameObject> Prefabs = new List<GameObject>();

	private static readonly List<RecipeStub> RecipeStubs = new List<RecipeStub>();

	private static readonly List<KeyValuePair<string, StatusEffect>> StatusEffects = new List<KeyValuePair<string, StatusEffect>>();

	public static AssetBundle LoadAssetBundle(string name)
	{
		Assembly callingAssembly = Assembly.GetCallingAssembly();
		return AssetBundle.LoadFromStream(callingAssembly.GetManifestResourceStream(callingAssembly.GetName().Name + "." + name));
	}

	public static void RegisterPrefab(GameObject prefab)
	{
		Prefabs.Add(prefab);
		Object.DontDestroyOnLoad((Object)(object)prefab);
	}

	public static void RegisterRecipe(RecipeStub rs)
	{
		RecipeStubs.Add(rs);
	}

	public static void RegisterStatusEffect<T>(string name) where T : StatusEffect
	{
		StatusEffects.Add(new KeyValuePair<string, StatusEffect>(name, (StatusEffect)(object)ScriptableObject.CreateInstance<T>()));
	}

	public static RecipeStub GetRecipeStub(string itemName)
	{
		return RecipeStubs.Find((RecipeStub r) => ((Object)r.Item).name == itemName);
	}

	public static Recipe BuildRecipe(RecipeStub rs, ObjectDB odb)
	{
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Expected O, but got Unknown
		Recipe val = ScriptableObject.CreateInstance<Recipe>();
		val.m_item = rs.Item;
		GameObject itemPrefab = odb.GetItemPrefab(rs.CraftingStation);
		val.m_craftingStation = ((itemPrefab != null) ? itemPrefab.GetComponentInChildren<CraftingStation>(true) : null);
		if ((Object)(object)val.m_craftingStation == (Object)null)
		{
			ZNetScene instance = ZNetScene.instance;
			object craftingStation;
			if (instance == null)
			{
				craftingStation = null;
			}
			else
			{
				GameObject prefab = instance.GetPrefab(rs.CraftingStation);
				craftingStation = ((prefab != null) ? prefab.GetComponentInChildren<CraftingStation>(true) : null);
			}
			val.m_craftingStation = (CraftingStation)craftingStation;
			if ((Object)(object)val.m_craftingStation == (Object)null)
			{
				Plugin.Log.LogInfo((object)("BuildRecipe couldn't find crafting station " + rs.CraftingStation + " for " + rs.Name));
				return null;
			}
		}
		if (!string.IsNullOrWhiteSpace(rs.RepairStation))
		{
			GameObject itemPrefab2 = odb.GetItemPrefab(rs.RepairStation);
			val.m_repairStation = ((itemPrefab2 != null) ? itemPrefab2.GetComponentInChildren<CraftingStation>(true) : null);
			if ((Object)(object)val.m_repairStation == (Object)null)
			{
				ZNetScene instance2 = ZNetScene.instance;
				object repairStation;
				if (instance2 == null)
				{
					repairStation = null;
				}
				else
				{
					GameObject prefab2 = instance2.GetPrefab(rs.RepairStation);
					repairStation = ((prefab2 != null) ? prefab2.GetComponentInChildren<CraftingStation>(true) : null);
				}
				val.m_repairStation = (CraftingStation)repairStation;
				if ((Object)(object)val.m_repairStation == (Object)null)
				{
					Plugin.Log.LogInfo((object)("BuildRecipe couldn't find declared repair station " + rs.RepairStation + " for " + rs.Name));
					return null;
				}
			}
			if ((Object)(object)val.m_repairStation == (Object)null)
			{
				return null;
			}
		}
		val.m_minStationLevel = Mathf.Max(1, rs.MinStationLevel);
		List<Requirement> list = new List<Requirement>();
		foreach (RecipeStub.RequirementStub requirement in rs.Requirements)
		{
			GameObject itemPrefab3 = odb.GetItemPrefab(requirement.Component);
			ItemDrop val2 = ((itemPrefab3 != null) ? itemPrefab3.GetComponentInChildren<ItemDrop>(true) : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				Plugin.Log.LogInfo((object)("BuildRecipe couldn't get requirement component " + requirement.Component + " for " + rs.Name));
				return null;
			}
			Requirement val3 = new Requirement();
			val3.m_resItem = val2;
			val3.m_amount = requirement.Amount;
			val3.m_amountPerLevel = requirement.AmountPerLevel;
			val3.m_recover = requirement.Recoverable;
			list.Add(val3);
		}
		val.m_resources = list.ToArray();
		return val;
	}

	private static void PopulateObjectDB(ObjectDB odb)
	{
		if (Prefabs.Count > 0 && !Object.op_Implicit((Object)(object)odb.m_items.Find((GameObject p) => ((Object)p).name == ((Object)Prefabs[0]).name)))
		{
			foreach (GameObject prefab in Prefabs)
			{
				if (Object.op_Implicit((Object)(object)prefab.GetComponentInChildren<ItemDrop>(true)))
				{
					odb.m_items.Add(prefab);
				}
			}
			odb.UpdateRegisters();
		}
		if (RecipeStubs.Count > 0 && !Object.op_Implicit((Object)(object)odb.GetRecipe(RecipeStubs[0].Item.m_itemData)))
		{
			foreach (RecipeStub recipeStub in RecipeStubs)
			{
				Recipe val = BuildRecipe(recipeStub, odb);
				if (Object.op_Implicit((Object)(object)val))
				{
					odb.m_recipes.Add(val);
					Plugin.Log.LogInfo((object)("Added recipe " + ((Object)val).name));
				}
			}
		}
		if (StatusEffects.Count <= 0 || Object.op_Implicit((Object)(object)odb.GetStatusEffect(StringExtensionMethods.GetStableHashCode(StatusEffects[0].Key))))
		{
			return;
		}
		foreach (KeyValuePair<string, StatusEffect> statusEffect in StatusEffects)
		{
			odb.m_StatusEffects.Add(statusEffect.Value);
		}
	}

	public static void UpdateRecipes()
	{
		foreach (RecipeStub recipeStub in RecipeStubs)
		{
			Recipe r = BuildRecipe(recipeStub, ObjectDB.instance);
			if (Object.op_Implicit((Object)(object)r))
			{
				Recipe val = ObjectDB.instance.m_recipes.Find((Recipe rt) => ((Object)rt).name == ((Object)r).name);
				if (Object.op_Implicit((Object)(object)val))
				{
					ObjectDB.instance.m_recipes.Remove(val);
				}
				ObjectDB.instance.m_recipes.Add(r);
				Plugin.Log.LogInfo((object)("Updated recipe " + ((Object)r).name));
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	public static void AwakePostfix(ObjectDB __instance)
	{
		PopulateObjectDB(__instance);
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
	public static void CopyOtherDBPostfix(ObjectDB __instance, ObjectDB other)
	{
		PopulateObjectDB(__instance);
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	public static void AwakePostfix(ZNetScene __instance)
	{
		if (Prefabs.Count == 0)
		{
			return;
		}
		foreach (GameObject prefab in Prefabs)
		{
			__instance.m_namedPrefabs[StringExtensionMethods.GetStableHashCode(((Object)prefab).name)] = prefab;
		}
	}
}
[HarmonyPatch(typeof(Ship))]
public static class ShipPatches
{
	private static int AttachSitshipHash = ZSyncAnimation.GetHash("attach_sitship");

	private static int AttachMastHash = ZSyncAnimation.GetHash("attach_mast");

	private static int AttachDragonHash = ZSyncAnimation.GetHash("attach_dragon");

	[HarmonyPrefix]
	[HarmonyPatch("CustomFixedUpdate")]
	public static bool CustomFixedUpdatePrefix(Ship __instance, float fixedDeltaTime)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: 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)
		//IL_00bf: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: 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: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: 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_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: 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_0071: Invalid comparison between Unknown and I4
		//IL_007e: 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_007a: Invalid comparison between Unknown and I4
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Unknown result type (might be due to invalid IL or missing references)
		//IL_040b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0413: Unknown result type (might be due to invalid IL or missing references)
		//IL_043c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0447: Unknown result type (might be due to invalid IL or missing references)
		//IL_044e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0453: Unknown result type (might be due to invalid IL or missing references)
		//IL_045b: Unknown result type (might be due to invalid IL or missing references)
		//IL_045f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0464: Unknown result type (might be due to invalid IL or missing references)
		//IL_0471: Unknown result type (might be due to invalid IL or missing references)
		//IL_047c: Unknown result type (might be due to invalid IL or missing references)
		//IL_048e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0499: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0528: Unknown result type (might be due to invalid IL or missing references)
		//IL_0530: Unknown result type (might be due to invalid IL or missing references)
		//IL_0546: Unknown result type (might be due to invalid IL or missing references)
		//IL_054b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0550: Unknown result type (might be due to invalid IL or missing references)
		//IL_0552: Unknown result type (might be due to invalid IL or missing references)
		//IL_055a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0570: Unknown result type (might be due to invalid IL or missing references)
		//IL_0575: Unknown result type (might be due to invalid IL or missing references)
		//IL_057a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0589: Unknown result type (might be due to invalid IL or missing references)
		//IL_058e: Unknown result type (might be due to invalid IL or missing references)
		//IL_059b: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0607: Unknown result type (might be due to invalid IL or missing references)
		//IL_0612: Unknown result type (might be due to invalid IL or missing references)
		//IL_0619: Unknown result type (might be due to invalid IL or missing references)
		//IL_061e: Unknown result type (might be due to invalid IL or missing references)
		//IL_063b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0656: Unknown result type (might be due to invalid IL or missing references)
		//IL_065d: Unknown result type (might be due to invalid IL or missing references)
		//IL_067d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0699: Unknown result type (might be due to invalid IL or missing references)
		//IL_06a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0705: Unknown result type (might be due to invalid IL or missing references)
		//IL_070c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0711: Unknown result type (might be due to invalid IL or missing references)
		//IL_071e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0725: Unknown result type (might be due to invalid IL or missing references)
		//IL_072c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0731: Unknown result type (might be due to invalid IL or missing references)
		//IL_073e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0745: Unknown result type (might be due to invalid IL or missing references)
		//IL_074c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0751: Unknown result type (might be due to invalid IL or missing references)
		//IL_075f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0766: Unknown result type (might be due to invalid IL or missing references)
		//IL_076d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0772: Unknown result type (might be due to invalid IL or missing references)
		//IL_0782: Unknown result type (might be due to invalid IL or missing references)
		//IL_0788: Invalid comparison between Unknown and I4
		//IL_0794: Unknown result type (might be due to invalid IL or missing references)
		//IL_079a: Invalid comparison between Unknown and I4
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_07fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0802: Unknown result type (might be due to invalid IL or missing references)
		//IL_081b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0822: Unknown result type (might be due to invalid IL or missing references)
		//IL_0833: Unknown result type (might be due to invalid IL or missing references)
		//IL_0839: Unknown result type (might be due to invalid IL or missing references)
		//IL_083e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0846: Unknown result type (might be due to invalid IL or missing references)
		//IL_084b: Unknown result type (might be due to invalid IL or missing references)
		//IL_084e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0854: Invalid comparison between Unknown and I4
		//IL_0863: Unknown result type (might be due to invalid IL or missing references)
		//IL_0869: Invalid comparison between Unknown and I4
		//IL_0857: Unknown result type (might be due to invalid IL or missing references)
		//IL_085d: Invalid comparison between Unknown and I4
		//IL_08ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_087f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0886: Unknown result type (might be due to invalid IL or missing references)
		//IL_088b: Unknown result type (might be due to invalid IL or missing references)
		//IL_088d: Unknown result type (might be due to invalid IL or missing references)
		//IL_08aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_08af: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_08d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_08dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_08e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_08e6: Unknown result type (might be due to invalid IL or missing references)
		bool flag = __instance.HaveControllingPlayer();
		__instance.UpdateControlls(fixedDeltaTime);
		__instance.UpdateSail(fixedDeltaTime);
		__instance.UpdateRudder(fixedDeltaTime, flag);
		if ((Object)(object)__instance.m_nview != (Object)null && !__instance.m_nview.IsOwner())
		{
			return false;
		}
		__instance.UpdateUpsideDmg(fixedDeltaTime);
		__instance.TakeAshlandsDamage(fixedDeltaTime);
		if (__instance.m_players.Count == 0)
		{
			__instance.m_speed = (Speed)0;
			__instance.m_rudderValue = 0f;
		}
		if (!flag && ((int)__instance.m_speed == 2 || (int)__instance.m_speed == 1))
		{
			__instance.m_speed = (Speed)0;
		}
		Vector3 worldCenterOfMass = __instance.m_body.worldCenterOfMass;
		Vector3 val = ((Component)__instance.m_floatCollider).transform.position + ((Component)__instance.m_floatCollider).transform.forward * __instance.m_floatCollider.size.z / 2f;
		Vector3 val2 = ((Component)__instance.m_floatCollider).transform.position - ((Component)__instance.m_floatCollider).transform.forward * __instance.m_floatCollider.size.z / 2f;
		Vector3 val3 = ((Component)__instance.m_floatCollider).transform.position - ((Component)__instance.m_floatCollider).transform.right * __instance.m_floatCollider.size.x / 2f;
		Vector3 val4 = ((Component)__instance.m_floatCollider).transform.position + ((Component)__instance.m_floatCollider).transform.right * __instance.m_floatCollider.size.x / 2f;
		float waterLevel = Floating.GetWaterLevel(worldCenterOfMass, ref __instance.m_previousCenter);
		float waterLevel2 = Floating.GetWaterLevel(val3, ref __instance.m_previousLeft);
		float waterLevel3 = Floating.GetWaterLevel(val4, ref __instance.m_previousRight);
		float waterLevel4 = Floating.GetWaterLevel(val, ref __instance.m_previousForward);
		float waterLevel5 = Floating.GetWaterLevel(val2, ref __instance.m_previousBack);
		float num = (waterLevel + waterLevel2 + waterLevel3 + waterLevel4 + waterLevel5) / 5f;
		float num2 = worldCenterOfMass.y - num - __instance.m_waterLevelOffset;
		if (num2 <= __instance.m_disableLevel)
		{
			float num3 = 1f;
			float num4 = 1f;
			if (((Object)((Component)__instance).gameObject).name.StartsWith("Raft"))
			{
				num3 = Plugin.RaftBaseRowingPower.Value;
			}
			else if (((Object)((Component)__instance).gameObject).name.StartsWith("Karve"))
			{
				num3 = Plugin.KarveBaseRowingPower.Value;
				num4 = Plugin.KarveRowingStrengthPerRower.Value;
			}
			else if (((Object)((Component)__instance).gameObject).name.StartsWith("VikingShip"))
			{
				num3 = Plugin.LongshipBaseRowingPower.Value;
				num4 = Plugin.LongshipRowingStrengthPerRower.Value;
			}
			if (flag)
			{
				long user = __instance.m_shipControlls.GetUser();
				foreach (Player player in __instance.m_players)
				{
					ZDOID zDOID = ((Character)player).GetZDOID();
					if (((ZDOID)(ref zDOID)).UserID != user)
					{
						if (!Plugin.RequireAttachedRowers.Value)
						{
							num3 += num4;
						}
						else if (Plugin.RequireSeatedRowers.Value && ((Character)player).m_zanim.m_animator.GetBool(AttachSitshipHash))
						{
							num3 += num4;
						}
						else if (!Plugin.RequireSeatedRowers.Value && (((Character)player).m_zanim.m_animator.GetBool(AttachSitshipHash) || ((Character)player).m_zanim.m_animator.GetBool(AttachMastHash) || ((Character)player).m_zanim.m_animator.GetBool(AttachDragonHash)))
						{
							num3 += num4;
						}
					}
				}
			}
			__instance.m_body.WakeUp();
			__instance.UpdateWaterForce(num2, Time.time);
			Vector3 val5 = new Vector3(val3.x, waterLevel2, val3.z);
			Vector3 val6 = default(Vector3);
			((Vector3)(ref val6))..ctor(val4.x, waterLevel3, val4.z);
			Vector3 val7 = new Vector3(val.x, waterLevel4, val.z);
			Vector3 val8 = default(Vector3);
			((Vector3)(ref val8))..ctor(val2.x, waterLevel5, val2.z);
			float num5 = fixedDeltaTime * 50f;
			float num6 = Utils.Clamp01(Utils.Abs(num2) / __instance.m_forceDistance);
			Vector3 val9 = Vector3.up * __instance.m_force * num6;
			__instance.m_body.AddForceAtPosition(val9 * num5, worldCenterOfMass, (ForceMode)2);
			float num7 = Vector3.Dot(__instance.m_body.velocity, ((Component)__instance).transform.forward);
			float num8 = Vector3.Dot(__instance.m_body.velocity, ((Component)__instance).transform.right);
			Vector3 val10 = __instance.m_body.velocity;
			float num9 = val10.y * val10.y * Utils.Sign(val10.y) * __instance.m_damping * num6;
			float num10 = num7 * num7 * Utils.Sign(num7) * __instance.m_dampingForward * num6;
			float num11 = num8 * num8 * Utils.Sign(num8) * __instance.m_dampingSideway * num6;
			val10.y -= Utils.Clamp(num9, -1f, 1f);
			val10 -= ((Component)__instance).transform.forward * Utils.Clamp(num10, -1f, 1f);
			val10 -= ((Component)__instance).transform.right * Utils.Clamp(num11, -1f, 1f);
			float magnitude = ((Vector3)(ref val10)).magnitude;
			Vector3 velocity = __instance.m_body.velocity;
			if (magnitude > ((Vector3)(ref velocity)).magnitude)
			{
				Vector3 normalized = ((Vector3)(ref val10)).normalized;
				velocity = __instance.m_body.velocity;
				val10 = normalized * ((Vector3)(ref velocity)).magnitude;
			}
			if (__instance.m_players.Count == 0)
			{
				val10.x *= 0.1f;
				val10.z *= 0.1f;
			}
			__instance.m_body.velocity = val10;
			Rigidbody body = __instance.m_body;
			body.angularVelocity -= __instance.m_body.angularVelocity * __instance.m_angularDamping * num6;
			float num12 = 0.15f;
			float num13 = 0.5f;
			float num14 = Utils.Clamp((val7.y - val.y) * num12, 0f - num13, num13);
			float num15 = Utils.Clamp((val8.y - val2.y) * num12, 0f - num13, num13);
			float num16 = Utils.Clamp((val5.y - val3.y) * num12, 0f - num13, num13);
			float num17 = Utils.Clamp((val6.y - val4.y) * num12, 0f - num13, num13);
			num14 = Utils.Sign(num14) * num14 * num14;
			num15 = Utils.Sign(num15) * num15 * num15;
			num16 = Utils.Sign(num16) * num16 * num16;
			num17 = Utils.Sign(num17) * num16 * num16;
			__instance.m_body.AddForceAtPosition(Vector3.up * num14 * num5, val, (ForceMode)2);
			__instance.m_body.AddForceAtPosition(Vector3.up * num15 * num5, val2, (ForceMode)2);
			__instance.m_body.AddForceAtPosition(Vector3.up * num16 * num5, val3, (ForceMode)2);
			__instance.m_body.AddForceAtPosition(Vector3.up * num17 * num5, val4, (ForceMode)2);
			float num18 = 0f;
			if ((int)__instance.m_speed == 4)
			{
				num18 = 1f;
			}
			else if ((int)__instance.m_speed == 3)
			{
				num18 = 0.5f;
			}
			Vector3 sailForce = __instance.GetSailForce(num18, fixedDeltaTime);
			Vector3 val11 = worldCenterOfMass + ((Component)__instance).transform.up * __instance.m_sailForceOffset;
			__instance.m_body.AddForceAtPosition(sailForce, val11, (ForceMode)2);
			Vector3 val12 = ((Component)__instance).transform.position + ((Component)__instance).transform.forward * __instance.m_stearForceOffset;
			float num19 = num7 * __instance.m_stearVelForceFactor;
			__instance.m_body.AddForceAtPosition(((Component)__instance).transform.right * num19 * (0f - __instance.m_rudderValue) * fixedDeltaTime, val12, (ForceMode)2);
			Vector3 val13 = Vector3.zero;
			if ((int)__instance.m_speed == 1 || (int)__instance.m_speed == 2)
			{
				float num20 = (((int)__instance.m_speed != 1) ? 1f : (-1f));
				val13 = ((Component)__instance).transform.forward * num20;
				val13 *= __instance.m_backwardForce * num3 * (1f - Utils.Abs(__instance.m_rudderValue));
				val13 += ((Component)__instance).transform.right * __instance.m_stearForce * (0f - __instance.m_rudderValue) * num20;
			}
			__instance.m_body.AddForceAtPosition(val13 * fixedDeltaTime, val12, (ForceMode)2);
			__instance.ApplyEdgeForce(Time.fixedDeltaTime);
		}
		return false;
	}
}
[BepInPlugin("pfhoenix.advancedboating", "Advanced Boating", "0.5.1")]
public class Plugin : BaseUnityPlugin
{
	public const string Version = "0.5.1";

	public const string ModName = "Advanced Boating";

	private Harmony _Harmony;

	public static ManualLogSource Log;

	private object AutomatedConfigDiscovery;

	public static ConfigEntry<bool> RequireSeatedRowers;

	public static ConfigEntry<bool> RequireAttachedRowers;

	public static ConfigEntry<float> RaftBaseRowingPower;

	public static ConfigEntry<float> KarveBaseRowingPower;

	public static ConfigEntry<float> LongshipBaseRowingPower;

	public static ConfigEntry<float> KarveRowingStrengthPerRower;

	public static ConfigEntry<float> LongshipRowingStrengthPerRower;

	private void Awake()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		Log = new ManualLogSource((string)null);
		AutomatedConfigDiscovery = this;
		RequireSeatedRowers = ((BaseUnityPlugin)this).Config.Bind<bool>("Rowing", "RequireSeatedRowers", true, "Rowers must be seated on a ship to contribute to rowing speeds");
		RequireAttachedRowers = ((BaseUnityPlugin)this).Config.Bind<bool>("Rowing", "RequireAttachedRowers", true, "Rowers must be attached to a ship to contribute to rowing speeds");
		RaftBaseRowingPower = ((BaseUnityPlugin)this).Config.Bind<float>("Rowing", "RaftBaseRowingPower", 1f, "The base strength of the rowing for the raft driver");
		KarveBaseRowingPower = ((BaseUnityPlugin)this).Config.Bind<float>("Rowing", "KarveBaseRowingPower", 1f, "The base strength of the rowing for the karve driver");
		LongshipBaseRowingPower = ((BaseUnityPlugin)this).Config.Bind<float>("Rowing", "LongshipBaseRowingPower", 2f, "The base strength of the rowing for the longship driver");
		KarveRowingStrengthPerRower = ((BaseUnityPlugin)this).Config.Bind<float>("Rowing", "KarveRowingStrengthPerRower", 2f, "The rowing amount each rower contributes for the karve. Value is a multiplier of the base rowing speed.");
		LongshipRowingStrengthPerRower = ((BaseUnityPlugin)this).Config.Bind<float>("Rowing", "LongshipRowingStrengthPerRower", 3f, "The rowing amount each rower contributes for the longship. Value is a multiplier of the base rowing speed.");
		_Harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
	}

	private void OnDestroy()
	{
		if (_Harmony != null)
		{
			_Harmony.UnpatchSelf();
		}
	}
}