commit 5189d79feabc7948f78fa463625c1fc82c69fdaf Author: 18107 <18107@users.noreply.github.com> Date: Fri Jul 26 08:57:36 2024 +0930 Add files via upload diff --git a/AutomaticShipSystems/BepInPlugin.cs b/AutomaticShipSystems/BepInPlugin.cs new file mode 100644 index 0000000..5c43212 --- /dev/null +++ b/AutomaticShipSystems/BepInPlugin.cs @@ -0,0 +1,29 @@ +using BepInEx; +using BepInEx.Logging; +using HarmonyLib; +using System.Reflection; + +namespace AutomaticShipSystems +{ + internal static class MyPluginInfo + { + internal const string PLUGIN_GUID = "id107.automaticshipsystems"; + internal const string PLUGIN_NAME = "AutomaticShipSystems"; + internal const string PLUGIN_VERSION = "0.0.0"; + } + + [BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] + [BepInProcess("Void Crew.exe")] + [BepInDependency("VoidManager")] + public class BepinPlugin : BaseUnityPlugin + { + internal static ManualLogSource Log; + private void Awake() + { + Log = Logger; + Configs.Load(this); + Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), MyPluginInfo.PLUGIN_GUID); + Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!"); + } + } +} \ No newline at end of file diff --git a/AutomaticShipSystems/Configs.cs b/AutomaticShipSystems/Configs.cs new file mode 100644 index 0000000..3933e44 --- /dev/null +++ b/AutomaticShipSystems/Configs.cs @@ -0,0 +1,22 @@ +using BepInEx.Configuration; + +namespace AutomaticShipSystems +{ + internal class Configs + { + internal const double CircuitBreakerDelay = 30 * 1000; + internal const double ThrusterBoosterDelay = 60 * 1000; + internal const double TrimDelay = 5 * 60 * 1000; + + internal static ConfigEntry CircuitBreakerConfig; + internal static ConfigEntry ThrusterBoosterConfig; + internal static ConfigEntry TrimConfig; + + internal static void Load(BepinPlugin plugin) + { + CircuitBreakerConfig = plugin.Config.Bind("AutomaticShipSystems", "CircuitBreakers", true); + ThrusterBoosterConfig = plugin.Config.Bind("AutomaticShipSystems", "ThrusterBooster", true); + TrimConfig = plugin.Config.Bind("AutomaticShipSystems", "Trim", true); + } + } +} diff --git a/AutomaticShipSystems/EnhancementPatch.cs b/AutomaticShipSystems/EnhancementPatch.cs new file mode 100644 index 0000000..3a1d41c --- /dev/null +++ b/AutomaticShipSystems/EnhancementPatch.cs @@ -0,0 +1,75 @@ +using CG.Game; +using CG.Ship.Modules; +using Gameplay.Enhancements; +using Gameplay.Ship; +using HarmonyLib; +using Photon.Pun; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VoidManager.Utilities; + +namespace AutomaticShipSystems +{ + [HarmonyPatch(typeof(Enhancement))] + internal class EnhancementPatch + { + [HarmonyPrepare] + static void HookEvents() + { + Configs.TrimConfig.SettingChanged += ToggleAutomaticTrims; + } + + [HarmonyPostfix] + [HarmonyPatch("SetState")] + static void SetState(Enhancement __instance, EnhancementState newState) + { + if (!PhotonNetwork.IsMasterClient) return; + + if (Configs.TrimConfig.Value && + ClientGame.Current?.PlayerShip?.GetModule()?.Engine?.GetComponentsInChildren()?.Contains(__instance) == true && + newState == EnhancementState.Inactive) + { + Tools.DelayDoUnique(__instance, () => ResetTrim(__instance), Configs.TrimDelay); + } + } + + private static void ResetTrim(Enhancement trim) + { + if (!PhotonNetwork.IsMasterClient || !Tools.PlayerShipExists) return; + + if (trim.CurrentState.Value == EnhancementState.Inactive) + { + trim.RequestStateChange(EnhancementState.Active, 1); + } + } + + internal static void ToggleAutomaticTrims(object sender, EventArgs e) + { + if (!PhotonNetwork.IsMasterClient) return; + + Enhancement[] trims = ClientGame.Current?.PlayerShip?.GetModule()?.Engine?.GetComponentsInChildren(); + if (trims == null || trims.Length == 0) return; + + if (Configs.TrimConfig.Value) + { + foreach (Enhancement trim in trims) + { + if (trim.CurrentState.Value == EnhancementState.Inactive) + { + Tools.DelayDoUnique(trim, () => ResetTrim(trim), Configs.TrimDelay); + } + } + } + else + { + foreach (Enhancement trim in trims) + { + Tools.CancelDelayDoUnique(trim); + } + } + } + } +} diff --git a/AutomaticShipSystems/GUI.cs b/AutomaticShipSystems/GUI.cs new file mode 100644 index 0000000..4bf8ff3 --- /dev/null +++ b/AutomaticShipSystems/GUI.cs @@ -0,0 +1,17 @@ +using VoidManager.CustomGUI; +using VoidManager.Utilities; + +namespace AutomaticShipSystems +{ + internal class GUI : ModSettingsMenu + { + public override string Name() => "Automatic Ship Systems"; + + public override void Draw() + { + GUITools.DrawCheckbox("Circuit Breakers", ref Configs.CircuitBreakerConfig); + GUITools.DrawCheckbox("Thruster Boosters", ref Configs.ThrusterBoosterConfig); + GUITools.DrawCheckbox("Trims", ref Configs.TrimConfig); + } + } +} diff --git a/AutomaticShipSystems/PowerBreakerPatch.cs b/AutomaticShipSystems/PowerBreakerPatch.cs new file mode 100644 index 0000000..58cb712 --- /dev/null +++ b/AutomaticShipSystems/PowerBreakerPatch.cs @@ -0,0 +1,65 @@ +using CG.Game; +using Gameplay.PowerSystem; +using HarmonyLib; +using Photon.Pun; +using System; +using System.Collections.Generic; +using VoidManager.Utilities; + +namespace AutomaticShipSystems +{ + [HarmonyPatch(typeof(PowerBreaker))] + internal class PowerBreakerPatch + { + [HarmonyPrepare] + static void HookEvents() + { + Configs.CircuitBreakerConfig.SettingChanged += ToggleAutomaticBreakers; + } + + [HarmonyPostfix] + [HarmonyPatch("OnPowerStateChange")] + static void OnPowerStateChange(PowerBreaker __instance, bool isOn) + { + if (!PhotonNetwork.IsMasterClient) return; + + if (!isOn && Configs.CircuitBreakerConfig.Value) + { + Tools.DelayDoUnique(__instance, () => ResetCircuitBreakers(__instance), Configs.CircuitBreakerDelay); + } + } + + private static void ResetCircuitBreakers(PowerBreaker breaker) + { + if (!PhotonNetwork.IsMasterClient || !Tools.PlayerShipExists) return; + + breaker.IsOn.RequestChange(true); + } + + internal static void ToggleAutomaticBreakers(object sender, EventArgs e) + { + if (!PhotonNetwork.IsMasterClient) return; + + List breakers = ClientGame.Current?.PlayerShip?.GetComponentInChildren()?.Breakers; + if (breakers == null) return; + + if (Configs.CircuitBreakerConfig.Value) + { + foreach (PowerBreaker powerBreaker in breakers) + { + if (!powerBreaker.IsOn.Value) + { + Tools.DelayDoUnique(powerBreaker, () => powerBreaker.IsOn.RequestChange(true), Configs.CircuitBreakerDelay); + } + } + } + else + { + foreach (PowerBreaker powerBreaker in breakers) + { + Tools.CancelDelayDoUnique(powerBreaker); + } + } + } + } +} diff --git a/AutomaticShipSystems/ThrusterBoosterPatch.cs b/AutomaticShipSystems/ThrusterBoosterPatch.cs new file mode 100644 index 0000000..feed4fb --- /dev/null +++ b/AutomaticShipSystems/ThrusterBoosterPatch.cs @@ -0,0 +1,72 @@ +using CG.Client.Ship.Interactions; +using CG.Game; +using CG.Ship.Modules; +using HarmonyLib; +using Photon.Pun; +using System; +using System.Collections.Generic; +using System.Reflection; +using VoidManager.Utilities; + +namespace AutomaticShipSystems +{ + [HarmonyPatch(typeof(ThrusterBooster))] + internal class ThrusterBoosterPatch + { + private static readonly MethodInfo SetLeverPositionMethod = AccessTools.Method(typeof(Lever), "set_LeverPosition"); + + [HarmonyPrepare] + static void HookEvents() + { + Configs.ThrusterBoosterConfig.SettingChanged += ToggleAutomaticThrusterBoosters; + } + + [HarmonyPostfix] + [HarmonyPatch("ChangeState")] + static void ChangeState(ThrusterBooster __instance, ThrusterBoosterState state) + { + if (!PhotonNetwork.IsMasterClient) return; + + if (state == ThrusterBoosterState.Off && Configs.ThrusterBoosterConfig.Value) + { + Tools.DelayDoUnique(__instance, () => ChargeThrusterBooster(__instance), Configs.ThrusterBoosterDelay); + } + } + + private static void ChargeThrusterBooster(ThrusterBooster booster) + { + if (!PhotonNetwork.IsMasterClient || !Tools.PlayerShipExists) return; + + if (booster.state == ThrusterBoosterState.Off) + { + SetLeverPositionMethod.Invoke(booster.ChargeLever, new object[] { 1f }); + } + } + + internal static void ToggleAutomaticThrusterBoosters(object sender, EventArgs e) + { + if (!PhotonNetwork.IsMasterClient) return; + + List boosters = ClientGame.Current.PlayerShip?.Transform?.GetComponent()?.ThrusterBoosters; + if (boosters == null) return; + + if (Configs.ThrusterBoosterConfig.Value) + { + foreach (ThrusterBooster booster in boosters) + { + if (booster.state == ThrusterBoosterState.Off) + { + Tools.DelayDoUnique(booster, () => ChargeThrusterBooster(booster), Configs.ThrusterBoosterDelay); + } + } + } + else + { + foreach (ThrusterBooster booster in boosters) + { + Tools.CancelDelayDoUnique(booster); + } + } + } + } +} diff --git a/AutomaticShipSystems/VoidManagerPlugin.cs b/AutomaticShipSystems/VoidManagerPlugin.cs new file mode 100644 index 0000000..231ac69 --- /dev/null +++ b/AutomaticShipSystems/VoidManagerPlugin.cs @@ -0,0 +1,25 @@ +using Photon.Pun; +using VoidManager.MPModChecks; + +namespace AutomaticShipSystems +{ + public class VoidManagerPlugin : VoidManager.VoidPlugin + { + public VoidManagerPlugin() + { + VoidManager.Events.Instance.MasterClientSwitched += (_, _) => { + if (PhotonNetwork.IsMasterClient) + { + PowerBreakerPatch.ToggleAutomaticBreakers(null, null); + ThrusterBoosterPatch.ToggleAutomaticThrusterBoosters(null, null); + EnhancementPatch.ToggleAutomaticTrims(null, null); + } }; + } + + public override MultiplayerType MPType => MultiplayerType.Host; + + public override string Author => "18107"; + + public override string Description => "Makes circuit breakers, thruster boosters, and trims self reset"; + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f1df92 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +[![](https://img.shields.io/badge/-Void_Crew_Modding_Team-111111?style=just-the-label&logo=github&labelColor=24292f)](https://github.com/Void-Crew-Modding-Team) +![](https://img.shields.io/badge/Game%20Version-0.26.3-111111?style=flat&labelColor=24292f&color=111111) +[![](https://img.shields.io/discord/1180651062550593536.svg?&logo=discord&logoColor=ffffff&style=flat&label=Discord&labelColor=24292f&color=111111)](https://discord.gg/g2u5wpbMGu "Void Crew Modding Discord") + +# AutomaticShipSystems + +Version 0.0.0 +For Game Version 0.26.3 +Developed by 18107 +Requires VoidManager 1.1.7 + + +--------------------- + +### 💡 Function - **Makes circuit breakers, thruster boosters, and trims self reset** + +- Intended for solo play + +### 🎮 Client Usage + +- Install +- Configure at F5 > Mod Settings > Automatic Ship Systems + +### 👥 Multiplayer Functionality + +- ✅ Host + - This affects all players if the host has the mod + +--------------------- + +## 🔧 Install Instructions - **Install following the normal BepInEx procedure.** + +Ensure that you have [BepInEx 5](https://thunderstore.io/c/void-crew/p/BepInEx/BepInExPack/) (stable version 5 **MONO**) and [VoidManager](https://thunderstore.io/c/void-crew/p/VoidCrewModdingTeam/VoidManager/) installed. + +#### ✔️ Mod installation - **Unzip the contents into the BepInEx plugin directory** + +Drag and drop `AutomaticShipSystems.dll` into `Void Crew\BepInEx\plugins`