Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BoatMotor v1.0.0
BoatMotor.dll
Decompiled 14 hours agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("BoatMotor")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("BoatMotor")] [assembly: AssemblyTitle("BoatMotor")] [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 BoatMotor { internal sealed class Gearbox { private const int MinGear = 1; private const int MaxGear = 5; private const float BrakeCutoffSpeed = 0.2f; private int _gear = 1; private Ship _patched; private float _originalSailForce; private float _originalRowForce; private bool _wasAccelerating; private bool _wasBraking; public void Tick(bool typing) { Ship localShip = Ship.GetLocalShip(); if (!Plugin.ModEnabled.Value || (Object)(object)localShip == (Object)null) { Restore(); return; } if (!typing) { HandleGearKeys(); } if (Plugin.TakeOverBoat.Value) { ZNetView component = ((Component)localShip).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid() && !component.IsOwner()) { component.ClaimOwnership(); } } ApplyGear(localShip); } public void FixedTick(bool typing) { //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.ModEnabled.Value || typing) { ReportThrottle(accelerating: false, braking: false); return; } Ship localShip = Ship.GetLocalShip(); if ((Object)(object)localShip == (Object)null || !IsOwner(localShip)) { ReportThrottle(accelerating: false, braking: false); return; } Rigidbody component = ((Component)localShip).GetComponent<Rigidbody>(); if ((Object)(object)component == (Object)null || component.isKinematic) { return; } int num; int num2; if ((Object)(object)Player.m_localPlayer != (Object)null) { num = (((Character)Player.m_localPlayer).IsAttachedToShip() ? 1 : 0); if (num != 0) { num2 = (Held(Plugin.AccelerateKey.Value) ? 1 : 0); goto IL_0082; } } else { num = 0; } num2 = 0; goto IL_0082; IL_0082: bool flag = (byte)num2 != 0; bool flag2 = num != 0 && Held(Plugin.BrakeKey.Value); ReportThrottle(flag, flag2); float num3 = Time.fixedDeltaTime * component.mass; if (flag) { Vector3 forward = ((Component)localShip).transform.forward; forward.y = 0f; component.AddForce(((Vector3)(ref forward)).normalized * (Plugin.Thrust.Value * MultiplierFor(_gear) * num3), (ForceMode)1); } if (flag2) { Vector3 linearVelocity = component.linearVelocity; linearVelocity.y = 0f; if (((Vector3)(ref linearVelocity)).magnitude > 0.2f) { component.AddForce(-((Vector3)(ref linearVelocity)).normalized * (Plugin.BrakeForce.Value * num3), (ForceMode)1); } } } private void ReportThrottle(bool accelerating, bool braking) { if (accelerating != _wasAccelerating) { _wasAccelerating = accelerating; Plugin.Log.LogInfo((object)(accelerating ? "Throttle: accelerating" : "Throttle: released")); } if (braking != _wasBraking) { _wasBraking = braking; Plugin.Log.LogInfo((object)(braking ? "Throttle: braking" : "Throttle: brake released")); } } private static bool Held(KeyboardShortcut shortcut) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0) { return ((KeyboardShortcut)(ref shortcut)).IsPressed(); } return false; } private static bool IsOwner(Ship ship) { ZNetView component = ((Component)ship).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.IsValid()) { return component.IsOwner(); } return false; } private void HandleGearKeys() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = Plugin.GearUpKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { Shift(_gear + 1); return; } value = Plugin.GearDownKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { Shift(_gear - 1); } } private void Shift(int gear) { gear = Mathf.Clamp(gear, 1, 5); if (gear != _gear) { _gear = gear; float num = MultiplierFor(_gear); Plugin.Message((_gear == 1) ? "Gear 1 (normal)" : $"Gear {_gear} ({num:0.##}x)"); Plugin.Log.LogInfo((object)$"Gear {_gear} ({num:0.##}x)"); } } private static float MultiplierFor(int gear) { return gear switch { 2 => Plugin.Gear2.Value, 3 => Plugin.Gear3.Value, 4 => Plugin.Gear4.Value, 5 => Plugin.Gear5.Value, _ => 1f, }; } private void ApplyGear(Ship ship) { if ((Object)(object)_patched != (Object)(object)ship) { Restore(); _patched = ship; _originalSailForce = ship.m_sailForceFactor; _originalRowForce = ship.m_backwardForce; } float num = MultiplierFor(_gear); ship.m_sailForceFactor = _originalSailForce * num; ship.m_backwardForce = _originalRowForce * num; } public void Restore() { if ((Object)(object)_patched == (Object)null) { _patched = null; return; } _patched.m_sailForceFactor = _originalSailForce; _patched.m_backwardForce = _originalRowForce; _patched = null; } } [BepInPlugin("matheba.boatmotor", "BoatMotor", "1.0.0")] [BepInProcess("valheim.exe")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; internal static ConfigEntry<bool> ModEnabled; internal static ConfigEntry<KeyboardShortcut> ToggleKey; internal static ConfigEntry<bool> ShowMessages; internal static ConfigEntry<KeyboardShortcut> GearUpKey; internal static ConfigEntry<KeyboardShortcut> GearDownKey; internal static ConfigEntry<float> Gear2; internal static ConfigEntry<float> Gear3; internal static ConfigEntry<float> Gear4; internal static ConfigEntry<float> Gear5; internal static ConfigEntry<KeyboardShortcut> AccelerateKey; internal static ConfigEntry<KeyboardShortcut> BrakeKey; internal static ConfigEntry<float> Thrust; internal static ConfigEntry<float> BrakeForce; internal static ConfigEntry<bool> TakeOverBoat; private Gearbox _gearbox; private void Awake() { //IL_0041: 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) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected O, but got Unknown //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Expected O, but got Unknown //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Expected O, but got Unknown //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Expected O, but got Unknown //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Expected O, but got Unknown //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Expected O, but got Unknown //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Boat motor", false, "Turns the gearbox on and off. Applies only to your own client, on the boat you are standing in."); ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("1 - General", "Toggle hotkey", new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), "Optional key to turn the motor on and off in game. Unbound by default, since gear 1 is already the unmodified game."); ShowMessages = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Show on-screen messages", true, "Shows the current gear centre-screen when you shift."); GearUpKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("2 - Gears", "Gear up", new KeyboardShortcut((KeyCode)280, Array.Empty<KeyCode>()), "Shifts up one gear. Only does anything while you are standing in a boat."); GearDownKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("2 - Gears", "Gear down", new KeyboardShortcut((KeyCode)281, Array.Empty<KeyCode>()), "Shifts down one gear. Only does anything while you are standing in a boat."); Gear2 = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Gears", "Gear 2 speed", 1.5f, new ConfigDescription("Speed multiplier for gear 2. Gear 1 is always the unmodified game.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>())); Gear3 = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Gears", "Gear 3 speed", 2f, new ConfigDescription("Speed multiplier for gear 3.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>())); Gear4 = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Gears", "Gear 4 speed", 3f, new ConfigDescription("Speed multiplier for gear 4.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>())); Gear5 = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Gears", "Gear 5 speed", 4f, new ConfigDescription("Speed multiplier for gear 5.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>())); AccelerateKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("3 - Throttle", "Accelerate at the helm (hold)", new KeyboardShortcut((KeyCode)324, Array.Empty<KeyCode>()), "Hold to push the boat forward. Only works while you are actually steering, which is what keeps the right mouse button free to block anywhere else on the boat."); BrakeKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("3 - Throttle", "Brake at the helm (hold)", new KeyboardShortcut((KeyCode)306, Array.Empty<KeyCode>()), "Hold to slow the boat down. Only works while you are actually steering, so left control still crouches everywhere else. The boat comes to a stop and does not back up."); Thrust = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Throttle", "Thrust", 50f, new ConfigDescription("How hard the motor pushes while you hold accelerate. The gear multiplier applies to this too.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 500f), Array.Empty<object>())); BrakeForce = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Throttle", "Brake force", 40f, new ConfigDescription("How hard the brake pushes back against the boat's motion.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 500f), Array.Empty<object>())); TakeOverBoat = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Advanced", "Take over the boat while aboard", false, "Valheim runs a boat's physics only on whoever owns it, and that is not always the person steering. With this on, you take ownership of the boat you are standing in, so the gears always work even with friends aboard. Leave it off if you would rather not move the simulation onto your machine."); _gearbox = new Gearbox(); Log.LogInfo((object)string.Format("{0} {1} loaded. Enabled: {2}, gears: {3}/{4}", "BoatMotor", "1.0.0", ModEnabled.Value, GearUpKey.Value, GearDownKey.Value)); } private void OnDestroy() { _gearbox?.Restore(); } private void Update() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = ToggleKey.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey != 0) { value = ToggleKey.Value; if (((KeyboardShortcut)(ref value)).IsDown() && !IsTyping()) { ModEnabled.Value = !ModEnabled.Value; Log.LogInfo((object)("Boat motor: " + (ModEnabled.Value ? "on" : "off"))); Message(ModEnabled.Value ? "Boat motor: ON" : "Boat motor: OFF"); } } _gearbox.Tick(IsTyping()); } private void FixedUpdate() { _gearbox.FixedTick(IsTyping()); } internal static void Message(string text) { if (ShowMessages.Value && (Object)(object)Player.m_localPlayer != (Object)null) { ((Character)Player.m_localPlayer).Message((MessageType)2, text, 0, (Sprite)null); } } private static bool IsTyping() { if (Console.IsVisible() || TextInput.IsVisible()) { return true; } if ((Object)(object)Chat.instance != (Object)null) { return Chat.instance.HasFocus(); } return false; } } internal static class PluginInfo { internal const string Guid = "matheba.boatmotor"; internal const string Name = "BoatMotor"; internal const string Version = "1.0.0"; } }