Decompiled source of Simple Sailing v1.1.0

SimpleSailing/SimpleSailing.dll

Decompiled 3 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
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("SimpleSailing")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SimpleSailing")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("08801a33-6395-44e1-a854-28476390a72d")]
[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 SimpleSailing;

[BepInPlugin("nb.wackjob.SimpleSailing", "Simple Sailing", "1.1.0")]
public class SimpleSailing : BaseUnityPlugin
{
	[HarmonyPatch(typeof(EnvMan), "GetWindDir")]
	public static class EnvManGetWindDirPatch
	{
		private static void Postfix(ref Vector3 __result)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)Player.m_localPlayer.GetControlledShip() != (Object)null)
			{
				__result = ((Component)Player.m_localPlayer).transform.forward;
			}
		}
	}

	[HarmonyPatch(typeof(Ship), "CustomFixedUpdate")]
	public static class ShipFixedUpdatePatch
	{
		private static FieldInfo sailForceField = typeof(Ship).GetField("m_sailForce", BindingFlags.Instance | BindingFlags.NonPublic);

		private static FieldInfo bodyField = typeof(Ship).GetField("m_body", BindingFlags.Instance | BindingFlags.NonPublic);

		private static void Prefix(Ship __instance)
		{
			//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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			Vector3 forward = ((Component)__instance).transform.forward;
			float num = 1f;
			if (sailForceField != null && bodyField != null)
			{
				Vector3 val = (Vector3)sailForceField.GetValue(__instance);
				Vector3 val2 = val * num;
				Rigidbody val3 = (Rigidbody)bodyField.GetValue(__instance);
				if ((Object)(object)val3 != (Object)null)
				{
					val3.AddForce(val2, (ForceMode)2);
				}
			}
		}
	}

	public static Harmony harmony = new Harmony("nb.wackjob.SimpleSailing");

	private void Awake()
	{
		harmony.PatchAll();
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}
}