Decompiled source of HexRowFaster v1.2.0

Plugins/HexRowFaster.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("HexRowFaster")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HexRowFaster")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a7a3b18f-1ccb-45d1-8f8c-344070327601")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HexRowFaster
{
	[BepInPlugin("com.hex.rowfaster", "HexRowFaster", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string PluginGuid = "com.hex.rowfaster";

		private const string PluginName = "HexRowFaster";

		private const string PluginVersion = "1.2.0";

		private ConfigEntry<bool> _isModEnabled;

		private ConfigEntry<ForceMultiplier> _forceMultiplier;

		private ConfigEntry<KeyboardShortcut> _brakeKey;

		internal static ManualLogSource Log;

		internal static Plugin Instance;

		internal static Harmony HarmonyInstance;

		internal static bool IsModEnabled => Instance?._isModEnabled.Value ?? false;

		internal static ForceMultiplier ForceMultiplier => Instance?._forceMultiplier.Value ?? ForceMultiplier.Cruising;

		internal static KeyboardShortcut BrakeKey => (KeyboardShortcut)(((??)Instance?._brakeKey.Value) ?? new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()));

		private void Awake()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			_isModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable", true, "Enables or disables HexRowFaster for newly spawned ships.");
			_forceMultiplier = ((BaseUnityPlugin)this).Config.Bind<ForceMultiplier>("General", "Force Multiplier", ForceMultiplier.Cruising, "How fast do you want to go?");
			_brakeKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Brake", "Brake Key", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), "Hold this key while piloting a ship to apply the brakes.");
			HarmonyInstance = new Harmony("com.hex.rowfaster");
			HarmonyInstance.PatchAll();
			Log.LogInfo((object)"HexRowFaster v1.2.0 loaded.");
		}

		private void OnDestroy()
		{
			Log.LogInfo((object)"HexRowFaster v1.2.0 unloaded.");
			Harmony harmonyInstance = HarmonyInstance;
			if (harmonyInstance != null)
			{
				harmonyInstance.UnpatchSelf();
			}
			HarmonyInstance = null;
			Instance = null;
			Log = null;
		}
	}
	public enum ForceMultiplier
	{
		Vanilla = 1,
		LittleFaster = 5,
		Cruising = 10,
		Speeding = 20,
		Insane = 40
	}
}
namespace HexRowFaster.Patches
{
	[HarmonyPatch(typeof(Ship), "CustomFixedUpdate")]
	internal static class PatchShip
	{
		private const float BrakeForce = 2.5f;

		[HarmonyPrefix]
		private static void Prefix(Ship __instance, out ShipState __state)
		{
			__state = new ShipState();
			if (Plugin.IsModEnabled)
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)localPlayer.GetControlledShip() != (Object)(object)__instance))
				{
					__state.OriginalBackwardForce = __instance.m_backwardForce;
					__state.BackwardForceChanged = true;
					__instance.m_backwardForce *= (float)Plugin.ForceMultiplier;
				}
			}
		}

		[HarmonyPostfix]
		private static void Postfix(Ship __instance, Rigidbody ___m_body, ShipState __state)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (__state != null && __state.BackwardForceChanged)
			{
				__instance.m_backwardForce = __state.OriginalBackwardForce;
			}
			if (!Plugin.IsModEnabled)
			{
				return;
			}
			KeyboardShortcut brakeKey = Plugin.BrakeKey;
			if (!((KeyboardShortcut)(ref brakeKey)).IsPressed())
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)localPlayer.GetControlledShip() != (Object)(object)__instance) && !((Object)(object)___m_body == (Object)null))
			{
				Vector3 linearVelocity = ___m_body.linearVelocity;
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(linearVelocity.x, 0f, linearVelocity.z);
				if (!(((Vector3)(ref val)).sqrMagnitude < 0.01f))
				{
					___m_body.AddForce(-val * 2.5f, (ForceMode)5);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Ship), "GetSailForce")]
	internal static class PatchShipGetSailForce
	{
		[HarmonyPostfix]
		private static void Postfix(Ship __instance, ref Vector3 __result)
		{
			//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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.IsModEnabled)
			{
				return;
			}
			KeyboardShortcut brakeKey = Plugin.BrakeKey;
			if (((KeyboardShortcut)(ref brakeKey)).IsPressed())
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)localPlayer.GetControlledShip() != (Object)(object)__instance))
				{
					__result = Vector3.zero;
				}
			}
		}
	}
	internal sealed class ShipState
	{
		internal float OriginalBackwardForce;

		internal bool BackwardForceChanged;
	}
}