Decompiled source of TebBoatTweaks v0.1.0

TebBoatTweaks.dll

Decompiled 6 months ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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("TebBoatTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TebBoatTweaks")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5a012cd2-ba7d-45b8-ba9e-7b543a92a5eb")]
[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 Tebbeh.TebBoatTweaks;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.tebbeh.mod.TebBoatTweaks", "TebBoatTweaks", "0.1.0")]
public class TebBoatTweaks : BaseUnityPlugin
{
	private const string ModName = "TebBoatTweaks";

	private const string ModVersion = "0.1.0";

	private const string Author = "com.tebbeh.mod";

	private const string ModGUID = "com.tebbeh.mod.TebBoatTweaks";

	private static string ConfigFileName = "com.tebbeh.mod.TebBoatTweaks.cfg";

	private static string ConfigFileFullPath;

	private readonly Harmony HarmonyInstance = new Harmony("com.tebbeh.mod.TebBoatTweaks");

	public static readonly ManualLogSource TebLogger;

	internal static ConfigEntry<bool> AdminBypass;

	internal static ConfigEntry<int> SailSpeed;

	internal static ConfigEntry<int> RowingSpeed;

	private readonly ConfigurationManagerAttributes AdminConfig = new ConfigurationManagerAttributes
	{
		IsAdminOnly = true
	};

	private readonly ConfigurationManagerAttributes ClientConfig = new ConfigurationManagerAttributes
	{
		IsAdminOnly = false
	};

	public static bool GetAdminBypass()
	{
		return AdminBypass.Value;
	}

	public static int GetSailSpeed()
	{
		return SailSpeed.Value;
	}

	public static int GetRowingSpeed()
	{
		return RowingSpeed.Value;
	}

	private void AddConfig<T>(string key, string section, string description, bool synced, T value, ref ConfigEntry<T> configEntry)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		string extendedDescription = GetExtendedDescription(description, synced);
		configEntry = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(extendedDescription, (AcceptableValueBase)null, new object[1] { synced ? AdminConfig : ClientConfig }));
	}

	public string GetExtendedDescription(string description, bool synchronizedSetting)
	{
		return description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]");
	}

	private void Awake()
	{
		AddConfig("AdminBypass", "General", "True to allow admins to bypass some setting restrictions (boolean).", synced: true, value: true, ref AdminBypass);
		AddConfig("SailSpeed", "Misc", "Multiply vanilla sail base speed (int).", synced: true, 2, ref SailSpeed);
		AddConfig("RowingSpeed", "Misc", "Multiply vanilla rowing base speed (int).", synced: true, 3, ref RowingSpeed);
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		HarmonyInstance.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
		{
			TebLogger.LogDebug((object)"Attempting to reload configuration...");
			((BaseUnityPlugin)this).Config.Reload();
		}
		catch
		{
			TebLogger.LogError((object)("There was an issue loading " + ConfigFileName));
		}
	}

	static TebBoatTweaks()
	{
		string configPath = Paths.ConfigPath;
		char directorySeparatorChar = Path.DirectorySeparatorChar;
		ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
		TebLogger = Logger.CreateLogSource("TebBoatTweaks");
		AdminBypass = null;
		SailSpeed = null;
		RowingSpeed = null;
	}
}
internal static class SailSpeed
{
	[HarmonyPatch(typeof(Ship), "GetSailForce")]
	private class ChangeShipBaseSpeed
	{
		private static void Postfix(ref Vector3 __result)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			__result *= (float)TebBoatTweaks.GetSailSpeed();
		}
	}
}
[HarmonyPatch(typeof(Ship), "Start")]
internal static class RudderSpeed
{
	private static void Prefix(Ship __instance)
	{
		int rowingSpeed = TebBoatTweaks.GetRowingSpeed();
		__instance.m_backwardForce *= (float)rowingSpeed;
	}
}