using System; using BepInEx.Configuration; using HarmonyLib; namespace BanquetForCyka { [HarmonyPatch] public class ModuleWingManager { private static readonly MultipliedObjectManager Manager = new MultipliedObjectManager(ConfigureAerofoil); private static ConfigEntry playerOnly; private static ConfigEntry angleRangeMultiplier; private static ConfigEntry turnSpeedMultiplier; private static ConfigEntry liftStrengthMultiplier; public static void Setup(ConfigFile config) { const float min = 0.01f; const float max = 32f; playerOnly = config.Bind("Aerofoil", "Player Only", false, new ConfigDescription("Player Only")); playerOnly.SettingChanged += (sender, args) => DoPatch(); angleRangeMultiplier = config.Bind("Aerofoil", "Angle Range Multiplier", 1f, new ConfigDescription("Angle Range Multiplier", new AcceptableValueRange(min, max))); angleRangeMultiplier.SettingChanged += (sender, args) => DoPatch(); turnSpeedMultiplier = config.Bind("Aerofoil", "Turn Speed Multiplier", 1f, new ConfigDescription("Turn Speed Multiplier", new AcceptableValueRange(min, max))); turnSpeedMultiplier.SettingChanged += (sender, args) => DoPatch(); liftStrengthMultiplier = config.Bind( "Aerofoil", "Lift Strength Multiplier", 1f, new ConfigDescription("Lift Strength Multiplier", new AcceptableValueRange(min, max))); liftStrengthMultiplier.SettingChanged += (sender, args) => DoPatch(); } private static void ConfigureAerofoil(MultipliedObject obj) { obj.AddField(new FieldConfiguration("flapAngleRangeActual", angleRangeMultiplier)); obj.AddField(new FieldConfiguration("flapAngleRangeVisual", angleRangeMultiplier)); obj.AddField(new FieldConfiguration("flapTurnSpeed", turnSpeedMultiplier)); obj.AddField(new FieldConfiguration("liftStrength", liftStrengthMultiplier)); } private static readonly Func ShouldApply = obj => { if (!playerOnly.Value) return true; return CykUtil.IsPlayerTank(obj as Module); }; [HarmonyPrefix] [HarmonyPatch(typeof(ModuleWing), "OnAttached")] public static void PostfixCreate(ModuleWing __instance) { if (playerOnly.Value && !CykUtil.IsPlayerTank(__instance)) return; for (int i = 0; i < __instance.m_Aerofoils.Length; i++) { var aerofoil = __instance.m_Aerofoils[i]; Manager.OnObjectAttached(aerofoil); } } [HarmonyPrefix] [HarmonyPatch(typeof(ModuleWing), "OnDetaching")] public static void PostfixDestroy(ModuleWing __instance) { if (playerOnly.Value && !CykUtil.IsPlayerTank(__instance)) return; foreach (var aerofoil in __instance.m_Aerofoils) Manager.OnObjectDetached(aerofoil); } private static void DoPatch() { Manager.ApplyAll(); } public static readonly Func Register = obj => { if (Main.debug.Value) Console.WriteLine("Registering ModuleWing: {0}", obj); PostfixCreate(obj as ModuleWing); return true; }; } }