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 SpeedBoat v0.1.1
SpeedBoat.dll
Decompiled 10 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] namespace SpeedBoat; public enum Setting { Stop, Back, Slow, Half, Full } public static class SpeedSteps { public const int MaxForward = 2; public const int FastReverse = -1; public static bool Forward(Setting setting, ref int extra) { if (setting == Setting.Full && extra < 2) { extra++; return true; } if (setting == Setting.Back && extra < 0) { extra = 0; return true; } return setting == Setting.Full; } public static bool Backward(Setting setting, ref int extra) { if (setting == Setting.Full && extra > 0) { extra--; return true; } if (setting == Setting.Back) { extra = -1; return true; } return false; } public static int Settle(Setting setting, int extra) { if (extra > 0 && setting != Setting.Full) { return 0; } if (extra >= 0 || setting == Setting.Back) { return extra; } return 0; } public static string Label(int extra) { if (extra > 0) { return "+" + extra; } if (extra >= 0) { return ""; } return "fast"; } } [BepInPlugin("com.parallel53.speedboat", "SpeedBoat", "0.1.1")] public class SpeedBoatPlugin : BaseUnityPlugin { private struct Forces { public float Sail; public float Backward; } private const float LabelFontSize = 18f; private static readonly Vector2 LabelOffset = new Vector2(4f, 0f); private static readonly Color LabelColor = new Color(1f, 0.85f, 0.4f); private static readonly Dictionary<Ship, int> Extras = new Dictionary<Ship, int>(); private static ConfigEntry<float> fullPlusOne; private static ConfigEntry<float> fullPlusTwo; private static ConfigEntry<float> fastReverse; private static ConfigEntry<float> rowForward; private static ConfigEntry<float> rowBackward; private static TMP_Text sailLabel; private static TMP_Text reverseLabel; private static readonly Vector3[] Corners = (Vector3[])(object)new Vector3[4]; private void Awake() { //IL_0087: Unknown result type (might be due to invalid IL or missing references) fullPlusOne = Multiplier("FullPlusOne", 2f, "Sail force at the first speed above Full, as a multiple of Full."); fullPlusTwo = Multiplier("FullPlusTwo", 3f, "Sail force at the second speed above Full, as a multiple of Full."); fastReverse = Multiplier("FastReverse", 2f, "Rowing force in fast reverse, as a multiple of reverse."); rowForward = Multiplier("RowForward", 1f, "Rowing force going forward, as a multiple of the game's."); rowBackward = Multiplier("RowBackward", 1f, "Rowing force in reverse, as a multiple of the game's."); new Harmony("com.parallel53.speedboat").PatchAll(typeof(SpeedBoatPlugin)); } private ConfigEntry<float> Multiplier(string key, float value, string description) { //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<float>("Speed", key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>())); } private static Setting SettingOf(Ship ship) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected I4, but got Unknown return (Setting)ship.GetSpeedSetting(); } private static int ExtraOf(Ship ship) { Extras.TryGetValue(ship, out var value); return SpeedSteps.Settle(SettingOf(ship), value); } [HarmonyPrefix] [HarmonyPatch(typeof(Ship), "RPC_Forward")] private static bool BeforeForward(Ship __instance) { int extra = ExtraOf(__instance); bool num = SpeedSteps.Forward(SettingOf(__instance), ref extra); Extras[__instance] = extra; return !num; } [HarmonyPrefix] [HarmonyPatch(typeof(Ship), "RPC_Backward")] private static bool BeforeBackward(Ship __instance) { int extra = ExtraOf(__instance); bool num = SpeedSteps.Backward(SettingOf(__instance), ref extra); Extras[__instance] = extra; return !num; } [HarmonyPrefix] [HarmonyPatch(typeof(Ship), "CustomFixedUpdate")] private static void BeforeMove(Ship __instance, out Forces __state) { __state = new Forces { Sail = __instance.m_sailForceFactor, Backward = __instance.m_backwardForce }; int num = ExtraOf(__instance); Extras[__instance] = num; switch (num) { case 1: __instance.m_sailForceFactor *= fullPlusOne.Value; break; case 2: __instance.m_sailForceFactor *= fullPlusTwo.Value; break; } switch (SettingOf(__instance)) { case Setting.Slow: __instance.m_backwardForce *= rowForward.Value; break; case Setting.Back: __instance.m_backwardForce *= rowBackward.Value * ((num < 0) ? fastReverse.Value : 1f); break; } } [HarmonyPostfix] [HarmonyPatch(typeof(Ship), "CustomFixedUpdate")] private static void AfterMove(Ship __instance, Forces __state) { __instance.m_sailForceFactor = __state.Sail; __instance.m_backwardForce = __state.Backward; } [HarmonyPostfix] [HarmonyPatch(typeof(Ship), "OnDisable")] private static void Forget(Ship __instance) { Extras.Remove(__instance); } [HarmonyPostfix] [HarmonyPatch(typeof(Hud), "UpdateShipHud")] private static void ShowLevel(Hud __instance, Player player) { Ship controlledShip = player.GetControlledShip(); int num = (((Object)(object)controlledShip != (Object)null) ? ExtraOf(controlledShip) : 0); if ((Object)(object)sailLabel == (Object)null) { sailLabel = CreateLabel(__instance); reverseLabel = CreateLabel(__instance); } SetLabel(sailLabel, __instance.m_rudderFastForward, (num > 0) ? SpeedSteps.Label(num) : ""); SetLabel(reverseLabel, __instance.m_rudderBackward, (num < 0) ? SpeedSteps.Label(num) : ""); } private static void SetLabel(TMP_Text label, GameObject icon, string text) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)label == (Object)null || (Object)(object)icon == (Object)null) { return; } bool flag = text.Length > 0 && icon.activeInHierarchy; if (((Component)label).gameObject.activeSelf != flag) { ((Component)label).gameObject.SetActive(flag); } if (flag) { if (label.text != text) { label.text = text; } ((RectTransform)icon.transform).GetWorldCorners(Corners); float num = Mathf.Max(Mathf.Max(Corners[0].x, Corners[1].x), Mathf.Max(Corners[2].x, Corners[3].x)); float num2 = (Corners[0].y + Corners[1].y + Corners[2].y + Corners[3].y) / 4f; RectTransform rectTransform = label.rectTransform; ((Transform)rectTransform).position = new Vector3(num, num2, ((Transform)rectTransform).position.z); rectTransform.anchoredPosition += LabelOffset; } } private static TMP_Text CreateLabel(Hud hud) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_00ca: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("SpeedBoatLabel", new Type[1] { typeof(RectTransform) }); val.SetActive(false); RectTransform val2 = (RectTransform)val.transform; ((Transform)val2).SetParent(hud.m_shipHudRoot.transform, false); Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(0.5f, 0.5f); val2.anchorMax = val3; val2.anchorMin = val3; val2.pivot = new Vector2(0f, 0.5f); ((Transform)val2).rotation = Quaternion.identity; val2.sizeDelta = new Vector2(60f, 30f); TextMeshProUGUI val4 = val.AddComponent<TextMeshProUGUI>(); TMP_Text componentInChildren = ((Component)hud).GetComponentInChildren<TMP_Text>(true); if ((Object)(object)componentInChildren != (Object)null) { ((TMP_Text)val4).font = componentInChildren.font; } ((TMP_Text)val4).fontSize = 18f; ((TMP_Text)val4).fontStyle = (FontStyles)1; ((Graphic)val4).color = LabelColor; ((TMP_Text)val4).alignment = (TextAlignmentOptions)513; ((Graphic)val4).raycastTarget = false; ((TMP_Text)val4).text = ""; return (TMP_Text)(object)val4; } }