Decompiled source of MotorBoatin v1.0.3

MotorBoatin.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.IO;
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 Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MotorBoatin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Norger")]
[assembly: AssemblyProduct("MotorBoatin")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace MotorBoatin
{
	[BepInPlugin("Norger.MotorBoatin", "MotorBoatin", "1.0.3")]
	public class MotorBoatinPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Boat))]
		[HarmonyPatch("FixedUpdate")]
		public static class Boat_Patch
		{
			private static void Postfix(ref Boat __instance)
			{
				__instance.BoosterValue = BoosterValue.Value;
				__instance.ConsumeFuelAmount = ConsumeFuelAmount.Value;
			}
		}

		[HarmonyPatch(typeof(Boat))]
		[HarmonyPatch("AddTorque")]
		public static class Boat_Patch1
		{
			private static void Postfix(ref Boat __instance)
			{
				__instance.steeringForce = steeringForce.Value;
			}
		}

		[HarmonyPatch(typeof(Boat))]
		[HarmonyPatch("AddForce")]
		public static class Boat_Patch2
		{
			private static void Postfix(ref Boat __instance)
			{
				__instance.enginePower = EnginePower.Value;
			}
		}

		internal const string ModName = "MotorBoatin";

		internal const string ModVersion = "1.0.3";

		internal const string Author = "Norger";

		private const string ModGUID = "Norger.MotorBoatin";

		private static string ConfigFileName = "Norger.MotorBoatin.cfg";

		private static string ConfigFileFullPath;

		private readonly Harmony _harmony = new Harmony("Norger.MotorBoatin");

		public static readonly ManualLogSource MotorBoatinLogger;

		public static ConfigEntry<bool> ModEnabled;

		public static ConfigEntry<float> BoosterValue;

		public static ConfigEntry<float> EnginePower;

		public static ConfigEntry<float> ConsumeFuelAmount;

		public static ConfigEntry<float> steeringForce;

		public void Awake()
		{
			ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "ModEnabled", true, "Enable or disable the mod.");
			BoosterValue = ((BaseUnityPlugin)this).Config.Bind<float>("2 - General", "BoosterValue", 1.5f, "Adjust the booster value (SHIFT).");
			EnginePower = ((BaseUnityPlugin)this).Config.Bind<float>("3 - General", "EnginePower", 2800f, "Adjust the engine power ( Default Speed).");
			ConsumeFuelAmount = ((BaseUnityPlugin)this).Config.Bind<float>("4 - General", "ConsumeFuelAmount", 0.0001f, "Adjust the fuel consumption rate per second.");
			steeringForce = ((BaseUnityPlugin)this).Config.Bind<float>("5 - General", "steeringForce", 35f, "Adjust the turning power. (Jetstream default is 45)");
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			SetupWatcher();
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				MotorBoatinLogger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				MotorBoatinLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
				MotorBoatinLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		static MotorBoatinPlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			MotorBoatinLogger = Logger.CreateLogSource("MotorBoatin");
		}
	}
}