Files
BepInEx/Projects/TerraTech/TerraTech/ModuleWingManager.cs

66 lines
2.8 KiB
C#

using System;
using BepInEx.Configuration;
using HarmonyLib;
namespace TerraTech {
[HarmonyPatch]
public class ModuleWingManager {
private static readonly MultipliedObjectManager<ModuleWing.Aerofoil> manager =
new MultipliedObjectManager<ModuleWing.Aerofoil>(ConfigureAerofoil);
public static ConfigEntry<float> angleRangeMultiplier;
public static ConfigEntry<float> turnSpeedMultiplier;
public static ConfigEntry<float> liftStrengthMultiplier;
public static void Setup(ConfigFile config) {
float min = 0.01f;
float max = 32f;
angleRangeMultiplier =
config.Bind("Aerofoil", "Angle Range Multiplier", 1f,
new ConfigDescription("Angle Range Multiplier", new AcceptableValueRange<float>(min, max)));
angleRangeMultiplier.SettingChanged += (sender, args) => DoPatch();
turnSpeedMultiplier =
config.Bind("Aerofoil", "Turn Speed Multiplier", 1f,
new ConfigDescription("Turn Speed Multiplier", new AcceptableValueRange<float>(min, max)));
turnSpeedMultiplier.SettingChanged += (sender, args) => DoPatch();
liftStrengthMultiplier = config.Bind(
"Aerofoil", "Lift Strength Multiplier", 1f,
new ConfigDescription("Lift Strength Multiplier", new AcceptableValueRange<float>(min, max)));
liftStrengthMultiplier.SettingChanged += (sender, args) => DoPatch();
}
private static void ConfigureAerofoil(MultipliedObject<ModuleWing.Aerofoil> obj) {
obj.AddField(new FieldConfiguration<float, float>("flipAngleRangeActual", angleRangeMultiplier));
obj.AddField(new FieldConfiguration<float, float>("flipAngleRangeVisual", angleRangeMultiplier));
obj.AddField(new FieldConfiguration<float, float>("flipAngleTurnSpeed", turnSpeedMultiplier));
obj.AddField(new FieldConfiguration<float, float>("liftStrength", liftStrengthMultiplier));
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ModuleWing), "OnAttached")]
static void PostfixCreate(ModuleWing __instance) {
for (int i = 0; i < __instance.m_Aerofoils.Length; i++) {
var aerofoil = __instance.m_Aerofoils[i];
manager.OnObjectAttached(aerofoil);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ModuleWing), "OnDetaching")]
static void PostfixDestroy(ModuleWing __instance) {
for (int i = 0; i < __instance.m_Aerofoils.Length; i++) {
var aerofoil = __instance.m_Aerofoils[i];
manager.OnObjectDetached(aerofoil);
}
}
public static void DoPatch() {
manager.ApplyAll();
}
}
}