Decompiled source of ShipSpeed v1.0.0

ShipSpeed.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ShipSpeed")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShipSpeed")]
[assembly: AssemblyTitle("ShipSpeed")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ShipSpeed
{
	internal static class Patches
	{
		[HarmonyPatch(typeof(Ship), "GetSailForce")]
		private static class SailPatch
		{
			private static void Postfix(ref Vector3 __result)
			{
				//IL_0002: 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_0011: Unknown result type (might be due to invalid IL or missing references)
				__result *= ShipSpeedPlugin.SailForceFactor;
			}
		}

		[HarmonyPatch(typeof(Ship), "CustomFixedUpdate")]
		private static class OarPatch
		{
			private static readonly FieldInfo BackwardForce = AccessTools.Field(typeof(Ship), "m_backwardForce");

			private static readonly MethodInfo Scale = AccessTools.Method(typeof(OarPatch), "OarForce", (Type[])null, (Type[])null);

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Expected O, but got Unknown
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				int num = 0;
				for (int num2 = list.Count - 1; num2 >= 0; num2--)
				{
					if (CodeInstructionExtensions.LoadsField(list[num2], BackwardForce, false))
					{
						list.Insert(num2 + 1, new CodeInstruction(OpCodes.Call, (object)Scale));
						num++;
					}
				}
				if (num == 0)
				{
					ShipSpeedPlugin.Log.LogWarning((object)"Ship.CustomFixedUpdate has changed: oar speed is the game's own");
				}
				return list;
			}

			private static float OarForce(float force)
			{
				return force * ShipSpeedPlugin.OarForceFactor;
			}
		}
	}
	[BepInPlugin("qua8ion.valheim.shipspeed", "ShipSpeed", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class ShipSpeedPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "qua8ion.valheim.shipspeed";

		public const string PluginName = "ShipSpeed";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> SailSpeed;

		internal static ConfigEntry<float> OarSpeed;

		internal static float SailForceFactor => Square(SailSpeed.Value);

		internal static float OarForceFactor => Square(OarSpeed.Value);

		private void Awake()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			AcceptableValueRange<float> range = new AcceptableValueRange<float>(0.5f, 3f);
			SailSpeed = Rule("Speed", "SailSpeed", 1.5f, "How many times faster ships go under sail, half or full, in any wind. 1 is the game's own speed.", (AcceptableValueBase)(object)range);
			OarSpeed = Rule("Speed", "OarSpeed", 1.5f, "How many times faster ships go on oars, forward and back. 1 is the game's own speed.", (AcceptableValueBase)(object)range);
			new Harmony("qua8ion.valheim.shipspeed").PatchAll(Assembly.GetExecutingAssembly());
			Log.LogInfo((object)$"Ships go {SailSpeed.Value:0.##}x faster under sail and {OarSpeed.Value:0.##}x on oars");
		}

		private static float Square(float k)
		{
			return k * k;
		}

		private ConfigEntry<T> Rule<T>(string section, string key, T value, string description, AcceptableValueBase range)
		{
			//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_0022: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(description, range, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
		}
	}
}