diff --git a/Projects/BlacksmithMaster/.clang-format b/Projects/BlacksmithMaster/.clang-format new file mode 100644 index 0000000..d53bf86 --- /dev/null +++ b/Projects/BlacksmithMaster/.clang-format @@ -0,0 +1,3 @@ +BasedOnStyle: Google +IndentWidth: 4 +ColumnLimit: 120 \ No newline at end of file diff --git a/Projects/BlacksmithMaster/.vs/BlacksmithMaster/v16/.suo b/Projects/BlacksmithMaster/.vs/BlacksmithMaster/v16/.suo new file mode 100644 index 0000000..a50e4b3 Binary files /dev/null and b/Projects/BlacksmithMaster/.vs/BlacksmithMaster/v16/.suo differ diff --git a/Projects/BlacksmithMaster/.vs/Ereshor/v16/.suo b/Projects/BlacksmithMaster/.vs/Ereshor/v16/.suo new file mode 100644 index 0000000..112ae7c Binary files /dev/null and b/Projects/BlacksmithMaster/.vs/Ereshor/v16/.suo differ diff --git a/Projects/BlacksmithMaster/BlacksmithMaster.sln b/Projects/BlacksmithMaster/BlacksmithMaster.sln new file mode 100644 index 0000000..6fc0b7c --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithMaster", "BlacksmithMaster\BlacksmithMaster.csproj", "{EE5EFB7F-A4DC-44F0-967B-F71ECA2D46AE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EE5EFB7F-A4DC-44F0-967B-F71ECA2D46AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE5EFB7F-A4DC-44F0-967B-F71ECA2D46AE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE5EFB7F-A4DC-44F0-967B-F71ECA2D46AE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE5EFB7F-A4DC-44F0-967B-F71ECA2D46AE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/BlacksmithMaster.csproj b/Projects/BlacksmithMaster/BlacksmithMaster/BlacksmithMaster.csproj new file mode 100644 index 0000000..b971ef2 --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/BlacksmithMaster.csproj @@ -0,0 +1,94 @@ + + + + + Debug + C:\Games\Blacksmith.Master.Early.Access + $(GAME_DIR)/Blacksmith Master_Data/Managed + $(GAME_DIR)/BepInEx + AnyCPU + {EE5EFB7F-A4DC-44F0-967B-F71ECA2D46AE} + Library + Properties + BlacksmithMaster + BlacksmithMaster + v4.8 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + $(GAME_BEPINEX)/core/0Harmony.dll + + + $(GAME_BEPINEX)/core/BepInEx.dll + + + $(GAME_MANAGED)/UnityEngine.dll + + + $(GAME_MANAGED)/UnityEngine.CoreModule.dll + + + $(GAME_MANAGED)/Assembly-CSharp.dll + + + $(GAME_BEPINEX)/plugins/ConfigurationManager/ConfigurationManager.dll + + + + + \ No newline at end of file diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/Class1.cs b/Projects/BlacksmithMaster/BlacksmithMaster/Class1.cs new file mode 100644 index 0000000..9d219d9 --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/Class1.cs @@ -0,0 +1,48 @@ +using System; +using System.Linq; +using BepInEx; +using BepInEx.Configuration; +using HarmonyLib; +using HarmonyLib.Tools; + +namespace BlacksmithMaster { + [BepInPlugin(PluginGuid, PluginName, PluginVersion)] + public class Main : BaseUnityPlugin { + private const string PluginGuid = "Cykasmith"; + private const string PluginName = "Cykasmith"; + private const string PluginVersion = "1.0.0"; + + public static ConfigEntry debug; + + public static ConfigEntry xpMultiplier; + + public void Awake() { + debug = Config.Bind("General", "Debug", false); + + xpMultiplier = + Config.Bind("General", "XP Multiplier", 1f, + new ConfigDescription("XP Multiplier", new AcceptableValueRange(0.01f, 1024f))); + + Logger.LogInfo("Cykasmith loaded"); + HarmonyFileLog.Enabled = true; + Harmony harmony = new Harmony(PluginGuid); + harmony.PatchAll(); + var originalMethods = harmony.GetPatchedMethods(); + Logger.LogInfo("Patched " + originalMethods.Count() + " methods"); + } + + public static void LogDebug(string message) { + if (Main.debug.Value) + Console.WriteLine(message); + } + } + + [HarmonyPatch(typeof(StaffBase), "AddXp")] + public class TavernData_AddXp { + public static void Prefix(ref int amount) { + Main.LogDebug("Original XP amount: " + amount); + amount = (int)((float)amount * Main.xpMultiplier.Value); + Main.LogDebug("Modified XP amount: " + amount); + } + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/CykUtil.cs b/Projects/BlacksmithMaster/BlacksmithMaster/CykUtil.cs new file mode 100644 index 0000000..2a6cc7d --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/CykUtil.cs @@ -0,0 +1,28 @@ +using System; + +namespace BlacksmithMaster { + public class CykUtil { + public static bool IsPlayerTank(Module module) { + if (module == null) + return false; + TankBlock block = module.block; + if (block == null) + return false; + Tank tank = block.tank; + if (tank == null) + return false; + return tank.ControllableByLocalPlayer; + } + + public static Func isObjectPlayerTank = obj => { + if (obj == null) + return false; + try { + return IsPlayerTank(obj as Module); + } catch (Exception e) { + Console.WriteLine("Failed to check if object is a player tank: " + e.Message); + return false; + } + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleBoosterManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleBoosterManager.cs new file mode 100644 index 0000000..0de44fe --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleBoosterManager.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleBoosterManager { + private static readonly MultipliedObjectManager FanManager = + new MultipliedObjectManager(ConfigureFanThruster); + private static readonly MultipliedObjectManager JetManager = + new MultipliedObjectManager(ConfigureJetThruster); + + private static ConfigEntry playerOnly; + private static ConfigEntry fanThrustMultiplier; + private static ConfigEntry jetThrustMultiplier; + + public static void Setup(ConfigFile config) { + float min = 0.01f; + float max = 32f; + + playerOnly = config.Bind("Booster", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + fanThrustMultiplier = + config.Bind("Booster", "Fan Thrust Multiplier", 1f, + new ConfigDescription("Fan Thrust Multiplier", new AcceptableValueRange(min, max))); + fanThrustMultiplier.SettingChanged += (sender, args) => DoPatch(); + + jetThrustMultiplier = + config.Bind("Booster", "Jet Thrust Multiplier", 1f, + new ConfigDescription("Jet Thrust Multiplier", new AcceptableValueRange(min, max))); + jetThrustMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureFanThruster(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_Force", fanThrustMultiplier, ShouldApply)); + } + + private static void ConfigureJetThruster(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_Force", jetThrustMultiplier, ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.isObjectPlayerTank(obj); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleBooster), "OnAttached")] + public static void PostfixCreate(ModuleBooster __instance) { + var trav = Traverse.Create(__instance); + var fans = trav.Field("fans").GetValue>(); + var jets = trav.Field("jets").GetValue>(); + + foreach (var fan in fans) FanManager.OnObjectAttached(fan); + foreach (var jet in jets) JetManager.OnObjectAttached(jet); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleBooster), "OnDetaching")] + public static void PostfixDestroy(ModuleBooster __instance) { + var trav = Traverse.Create(__instance); + var fans = trav.Field("fans").GetValue>(); + var jets = trav.Field("jets").GetValue>(); + + foreach (var fan in fans) FanManager.OnObjectDetached(fan); + foreach (var jet in jets) JetManager.OnObjectDetached(jet); + } + + private static void DoPatch() { + FanManager.ApplyAll(); + JetManager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleBooster: {0}", obj); + PostfixCreate(obj as ModuleBooster); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleEnergyManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleEnergyManager.cs new file mode 100644 index 0000000..6cba354 --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleEnergyManager.cs @@ -0,0 +1,67 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleEnergyManager { + private static readonly MultipliedObjectManager Manager = + new MultipliedObjectManager(ConfigureModuleEnergy); + + private static ConfigEntry playerOnly; + private static ConfigEntry outputMultiplier; + private static ConfigEntry powerUpDelayMultiplier; + + public static void Setup(ConfigFile config) { + float min = 0.01f; + float max = 32f; + + playerOnly = config.Bind("Energy", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + outputMultiplier = + config.Bind("Energy", "Output Multiplier", 1f, + new ConfigDescription("Output Multiplier", new AcceptableValueRange(min, max))); + outputMultiplier.SettingChanged += (sender, args) => DoPatch(); + + powerUpDelayMultiplier = config.Bind( + "Energy", "Power Up Delay Multiplier", 1f, + new ConfigDescription("Power Up Delay Multiplier", new AcceptableValueRange(min, max))); + powerUpDelayMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureModuleEnergy(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_OutputPerSecond", outputMultiplier, ShouldApply)); + obj.AddField(new FieldConfiguration("m_PowerUpDelay", powerUpDelayMultiplier, ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.IsPlayerTank(obj as Module); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergy), "OnAnchorStatusChanged")] + public static void PostfixCreate(ModuleEnergy __instance) { + Manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergy), "OnDetaching")] + public static void PostfixDestroy(ModuleEnergy __instance) { + Manager.OnObjectDetached(__instance); + } + + private static void DoPatch() { + Manager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleEnergy: {0}", obj); + PostfixCreate(obj as ModuleEnergy); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleEnergyStoreManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleEnergyStoreManager.cs new file mode 100644 index 0000000..e47862f --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleEnergyStoreManager.cs @@ -0,0 +1,60 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleEnergyStoreManager { + private static readonly MultipliedObjectManager Manager = + new MultipliedObjectManager(ConfigureModuleEnergyStore); + + private static ConfigEntry playerOnly; + private static ConfigEntry capacityMultiplier; + + public static void Setup(ConfigFile config) { + float min = 0.01f; + float max = 32f; + + playerOnly = config.Bind("Energy", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + capacityMultiplier = + config.Bind("Energy", "Capacity Multiplier", 1f, + new ConfigDescription("Capacity Multiplier", new AcceptableValueRange(min, max))); + capacityMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureModuleEnergyStore(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_Capacity", capacityMultiplier, ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.IsPlayerTank(obj as Module); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergyStore), "OnAttached")] + public static void PostfixCreate(ModuleEnergyStore __instance) { + Manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleEnergyStore), "OnDetaching")] + public static void PostfixDestroy(ModuleEnergyStore __instance) { + Manager.OnObjectDetached(__instance); + } + + private static void DoPatch() { + Manager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleEnergyStore: {0}", obj); + PostfixCreate(obj as ModuleEnergyStore); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleFuelTankManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleFuelTankManager.cs new file mode 100644 index 0000000..64dbaef --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleFuelTankManager.cs @@ -0,0 +1,67 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleFuelTankManager { + private static readonly MultipliedObjectManager Manager = + new MultipliedObjectManager(ConfigureFuelTank); + + private static ConfigEntry playerOnly; + private static ConfigEntry fuelCapacityMultiplier; + private static ConfigEntry fuelRefillMultiplier; + + public static void Setup(ConfigFile config) { + float min = 0.01f; + float max = 32f; + + playerOnly = config.Bind("FuelTank", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + fuelCapacityMultiplier = config.Bind( + "FuelTank", "Fuel Capacity Multiplier", 1f, + new ConfigDescription("Fuel Capacity Multiplier", new AcceptableValueRange(min, max))); + fuelCapacityMultiplier.SettingChanged += (sender, args) => DoPatch(); + + fuelRefillMultiplier = + config.Bind("FuelTank", "Fuel Refill Multiplier", 1f, + new ConfigDescription("Fuel Refill Multiplier", new AcceptableValueRange(min, max))); + fuelRefillMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureFuelTank(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_Capacity", fuelCapacityMultiplier, ShouldApply)); + obj.AddField(new FieldConfiguration("m_RefillRate", fuelRefillMultiplier, ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.isObjectPlayerTank(obj); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleFuelTank), "OnAttached")] + public static void PostfixCreate(ModuleFuelTank __instance) { + Manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleFuelTank), "OnDetaching")] + public static void PostfixDestroy(ModuleFuelTank __instance) { + Manager.OnObjectDetached(__instance); + } + + private static void DoPatch() { + Manager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleFuelTank: {0}", obj); + PostfixCreate(obj as ModuleFuelTank); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleGyroManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleGyroManager.cs new file mode 100644 index 0000000..4622c7c --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleGyroManager.cs @@ -0,0 +1,60 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleGyroManager { + private static readonly MultipliedObjectManager Manager = + new MultipliedObjectManager(ConfigureModuleGyro); + + private static ConfigEntry playerOnly; + private static ConfigEntry activeSpeedMultiplier; + + public static void Setup(ConfigFile config) { + float min = 0.01f; + float max = 32f; + + playerOnly = config.Bind("Gyro", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + activeSpeedMultiplier = config.Bind( + "Gyro", "Active Speed Multiplier", 1f, + new ConfigDescription("Active Speed Multiplier", new AcceptableValueRange(min, max))); + activeSpeedMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureModuleGyro(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_ActiveSpeed", activeSpeedMultiplier, ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.IsPlayerTank(obj as Module); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleGyro), "OnAttached")] + public static void PostfixCreate(ModuleGyro __instance) { + Manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleGyro), "OnDetaching")] + public static void PostfixDestroy(ModuleGyro __instance) { + Manager.OnObjectDetached(__instance); + } + + private static void DoPatch() { + Manager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleGyro: {0}", obj); + PostfixCreate(obj as ModuleGyro); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleHeartManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleHeartManager.cs new file mode 100644 index 0000000..28ad2d1 --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleHeartManager.cs @@ -0,0 +1,76 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleHeartManager { + private static readonly MultipliedObjectManager Manager = + new MultipliedObjectManager(ConfigureHeart); + + private static ConfigEntry playerOnly; + private static ConfigEntry eventHorizonRadiusMultiplier; + private static ConfigEntry setupTimeMultiplier; + private static ConfigEntry startShrinkingRadiusMultiplier; + + public static void Setup(ConfigFile config) { + float min = 0.01f; + float max = 32f; + + playerOnly = config.Bind("Heart", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + eventHorizonRadiusMultiplier = config.Bind( + "Heart", "Event Horizon Radius Multiplier", 1f, + new ConfigDescription("Event Horizon Radius Multiplier", new AcceptableValueRange(min, max))); + eventHorizonRadiusMultiplier.SettingChanged += (sender, args) => DoPatch(); + + setupTimeMultiplier = + config.Bind("Heart", "Setup Time Multiplier", 1f, + new ConfigDescription("Setup Time Multiplier", new AcceptableValueRange(min, max))); + setupTimeMultiplier.SettingChanged += (sender, args) => DoPatch(); + + startShrinkingRadiusMultiplier = config.Bind( + "Heart", "Start Shrinking Radius Multiplier", 1f, + new ConfigDescription("Start Shrinking Radius Multiplier", new AcceptableValueRange(min, max))); + startShrinkingRadiusMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureHeart(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_EventHorizonRadius", eventHorizonRadiusMultiplier, + ShouldApply)); + obj.AddField(new FieldConfiguration("m_SetupTime", setupTimeMultiplier, ShouldApply)); + obj.AddField(new FieldConfiguration("m_StartShrinkingRadius", startShrinkingRadiusMultiplier, + ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.isObjectPlayerTank(obj); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleHeart), "OnAttached")] + public static void PostfixCreate(ModuleHeart __instance) { + Manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleHeart), "OnDetaching")] + public static void PostfixDestroy(ModuleHeart __instance) { + Manager.OnObjectDetached(__instance); + } + + private static void DoPatch() { + Manager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleHeart: {0}", obj); + PostfixCreate(obj as ModuleHeart); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleItemHolderManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleItemHolderManager.cs new file mode 100644 index 0000000..d9fbc51 --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleItemHolderManager.cs @@ -0,0 +1,164 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleItemHolderManager { + private static readonly MultipliedObjectManager BeamManager = + new MultipliedObjectManager(ConfigureBeam); + private static readonly MultipliedObjectManager BeamHolderManager = + new MultipliedObjectManager(ConfigureBeamHolder); + private static readonly MultipliedObjectManager BeamPickupManager = + new MultipliedObjectManager(ConfigureBeamPickup); + + private static readonly MultipliedObjectManager MagnetHolderManager = + new MultipliedObjectManager(ConfigureMagnetHolder); + private static readonly MultipliedObjectManager MagnetPickupManager = + new MultipliedObjectManager(ConfigureMagnetPickup); + + private static ConfigEntry playerOnly; + private static ConfigEntry capacityPerStackMultiplier; + private static ConfigEntry beamStrengthMultiplier; + private static ConfigEntry beamHeightIncrementScaleMultiplier; + private static ConfigEntry beamPickupRangeMultiplier; + private static ConfigEntry magnetStrengthMultiplier; + private static ConfigEntry magnetPickupRangeMultiplier; + + public static void Setup(ConfigFile config) { + float min = 0.01f; + float max = 32f; + + playerOnly = config.Bind("Item Holder", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + capacityPerStackMultiplier = config.Bind( + "Item Holder", "Capacity Per Stack Multiplier", 1f, + new ConfigDescription("Capacity Per Stack Multiplier", new AcceptableValueRange(min, max))); + capacityPerStackMultiplier.SettingChanged += (sender, args) => DoPatch(); + + beamStrengthMultiplier = config.Bind( + "Item Holder", "Beam Strength Multiplier", 1f, + new ConfigDescription("Beam Strength Multiplier", new AcceptableValueRange(min, max))); + beamStrengthMultiplier.SettingChanged += (sender, args) => DoPatch(); + + beamHeightIncrementScaleMultiplier = + config.Bind("Item Holder", "Beam Height Increment Scale Multiplier", 1f, + new ConfigDescription("Beam Height Increment Scale Multiplier", + new AcceptableValueRange(min, max))); + beamHeightIncrementScaleMultiplier.SettingChanged += (sender, args) => DoPatch(); + + beamPickupRangeMultiplier = config.Bind( + "Item Holder", "Beam Pickup Range Multiplier", 1f, + new ConfigDescription("Beam Pickup Range Multiplier", new AcceptableValueRange(min, max))); + beamPickupRangeMultiplier.SettingChanged += (sender, args) => DoPatch(); + + magnetStrengthMultiplier = config.Bind( + "Item Holder", "Magnet Strength Multiplier", 1f, + new ConfigDescription("Magnet Strength Multiplier", new AcceptableValueRange(min, max))); + magnetStrengthMultiplier.SettingChanged += (sender, args) => DoPatch(); + + magnetPickupRangeMultiplier = config.Bind( + "Item Holder", "Magnet Pickup Range Multiplier", 1f, + new ConfigDescription("Magnet Pickup Range Multiplier", new AcceptableValueRange(min, max))); + magnetPickupRangeMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureBeam(MultipliedObject obj) { + obj.AddField( + new FieldConfiguration("m_CapacityPerStack", capacityPerStackMultiplier, ShouldApply)); + } + + private static void ConfigureBeamHolder(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_BeamStrength", beamStrengthMultiplier, ShouldApply)); + obj.AddField(new FieldConfiguration("m_HeightIncrementScale", + beamHeightIncrementScaleMultiplier, ShouldApply)); + } + + private static void ConfigureBeamPickup(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_PickupRange", beamPickupRangeMultiplier, ShouldApply)); + } + + private static void ConfigureMagnetHolder(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_Strength", magnetStrengthMultiplier, ShouldApply)); + } + + private static void ConfigureMagnetPickup(MultipliedObject obj) { + obj.AddField( + new FieldConfiguration("m_PickupRange", magnetPickupRangeMultiplier, ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.IsPlayerTank(obj as Module); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleItemHolder), "OnAttached")] + public static void PostfixCreate(ModuleItemHolder __instance) { + BeamManager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleItemHolder), "OnDetaching")] + public static void PostfixDestroy(ModuleItemHolder __instance) { + BeamManager.OnObjectDetached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleItemHolderBeam), "OnAttached")] + public static void PostfixCreate(ModuleItemHolderBeam __instance) { + var trav = Traverse.Create(__instance); + var pickup = trav.Field("m_Pickup").GetValue(); + + BeamHolderManager.OnObjectAttached(__instance); + BeamPickupManager.OnObjectAttached(pickup); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleItemHolderBeam), "OnDetaching")] + public static void PostfixDestroy(ModuleItemHolderBeam __instance) { + var trav = Traverse.Create(__instance); + var pickup = trav.Field("m_Pickup").GetValue(); + + BeamHolderManager.OnObjectDetached(__instance); + BeamPickupManager.OnObjectDetached(pickup); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleItemHolderMagnet), "OnAttached")] + public static void PostfixCreate(ModuleItemHolderMagnet __instance) { + var trav = Traverse.Create(__instance); + var pickup = trav.Field("m_Pickup").GetValue(); + + MagnetHolderManager.OnObjectAttached(__instance); + MagnetPickupManager.OnObjectAttached(pickup); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleItemHolderMagnet), "OnDetaching")] + public static void PostfixDestroy(ModuleItemHolderMagnet __instance) { + var trav = Traverse.Create(__instance); + var pickup = trav.Field("m_Pickup").GetValue(); + + MagnetHolderManager.OnObjectDetached(__instance); + MagnetPickupManager.OnObjectDetached(pickup); + } + + private static void DoPatch() { + BeamManager.ApplyAll(); + BeamHolderManager.ApplyAll(); + BeamPickupManager.ApplyAll(); + MagnetHolderManager.ApplyAll(); + MagnetPickupManager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleItemHolder: {0}", obj); + PostfixCreate(obj as ModuleItemHolder); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleItemProducerManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleItemProducerManager.cs new file mode 100644 index 0000000..b6322a8 --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleItemProducerManager.cs @@ -0,0 +1,77 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleItemProducerManager { + private static readonly MultipliedObjectManager Manager = + new MultipliedObjectManager(ConfigureModuleItemProducer); + + private static ConfigEntry playerOnly; + private static ConfigEntry resourceGroundRadiusMultiplier; + private static ConfigEntry minDispenseIntervalMultiplier; + private static ConfigEntry secPerItemProducedMultiplier; + + public static void Setup(ConfigFile config) { + float min = 0.01f; + float max = 32f; + + playerOnly = config.Bind("Item Producer", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + resourceGroundRadiusMultiplier = config.Bind( + "Item Producer", "Resource Ground Radius Multiplier", 1f, + new ConfigDescription("Resource Ground Radius Multiplier", new AcceptableValueRange(min, max))); + resourceGroundRadiusMultiplier.SettingChanged += (sender, args) => DoPatch(); + + minDispenseIntervalMultiplier = config.Bind( + "Item Producer", "Min Dispense Interval Multiplier", 1f, + new ConfigDescription("Min Dispense Interval Multiplier", new AcceptableValueRange(min, max))); + minDispenseIntervalMultiplier.SettingChanged += (sender, args) => DoPatch(); + + secPerItemProducedMultiplier = config.Bind( + "Item Producer", "Sec Per Item Produced Multiplier", 1f, + new ConfigDescription("Sec Per Item Produced Multiplier", new AcceptableValueRange(min, max))); + secPerItemProducedMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureModuleItemProducer(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_ResourceGroundRadius", resourceGroundRadiusMultiplier, + ShouldApply)); + obj.AddField(new FieldConfiguration("m_MinDispenseInterval", minDispenseIntervalMultiplier, + ShouldApply)); + obj.AddField(new FieldConfiguration("m_SecPerItemProduced", secPerItemProducedMultiplier, + ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.IsPlayerTank(obj as Module); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleItemProducer), "GetClosestResourceReservoirInRange")] + public static void PostfixCreate(ModuleItemProducer __instance) { + Manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleItemProducer), "OnDetaching")] + public static void PostfixDestroy(ModuleItemProducer __instance) { + Manager.OnObjectDetached(__instance); + } + + private static void DoPatch() { + Manager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleItemProducer: {0}", obj); + PostfixCreate(obj as ModuleItemProducer); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleRemoteChargerManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleRemoteChargerManager.cs new file mode 100644 index 0000000..e4725cd --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleRemoteChargerManager.cs @@ -0,0 +1,77 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleRemoteChargerManager { + private static readonly MultipliedObjectManager Manager = + new MultipliedObjectManager(ConfigureModuleRemoteCharger); + + private static ConfigEntry playerOnly; + private static ConfigEntry arcFiringIntervalMultiplier; + private static ConfigEntry chargingRadiusMultiplier; + private static ConfigEntry powerTransferPerArcMultiplier; + + public static void Setup(ConfigFile config) { + const float min = 0.01f; + const float max = 32f; + + playerOnly = config.Bind("Remote Charger", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + arcFiringIntervalMultiplier = config.Bind( + "Remote Charger", "Arc Firing Interval Multiplier", 1f, + new ConfigDescription("Arc Firing Interval Multiplier", new AcceptableValueRange(min, max))); + arcFiringIntervalMultiplier.SettingChanged += (sender, args) => DoPatch(); + + chargingRadiusMultiplier = config.Bind( + "Remote Charger", "Charging Radius Multiplier", 1f, + new ConfigDescription("Charging Radius Multiplier", new AcceptableValueRange(min, max))); + chargingRadiusMultiplier.SettingChanged += (sender, args) => DoPatch(); + + powerTransferPerArcMultiplier = config.Bind( + "Remote Charger", "Power Transfer Per Arc Multiplier", 1f, + new ConfigDescription("Power Transfer Per Arc Multiplier", new AcceptableValueRange(min, max))); + powerTransferPerArcMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureModuleRemoteCharger(MultipliedObject obj) { + obj.AddField( + new FieldConfiguration("m_ArcFiringInterval", arcFiringIntervalMultiplier, ShouldApply)); + obj.AddField( + new FieldConfiguration("m_ChargingRadius", chargingRadiusMultiplier, ShouldApply)); + obj.AddField(new FieldConfiguration("m_PowerTransferPerArc", powerTransferPerArcMultiplier, + ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.IsPlayerTank(obj as Module); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleRemoteCharger), "OnAttached")] + public static void PostfixCreate(ModuleRemoteCharger __instance) { + Manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleRemoteCharger), "OnDetaching")] + public static void PostfixDestroy(ModuleRemoteCharger __instance) { + Manager.OnObjectDetached(__instance); + } + + private static void DoPatch() { + Manager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleRemoteCharger: {0}", obj); + PostfixCreate(obj as ModuleRemoteCharger); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleShieldGeneratorManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleShieldGeneratorManager.cs new file mode 100644 index 0000000..8924a87 --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleShieldGeneratorManager.cs @@ -0,0 +1,88 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleShieldGeneratorManager { + private static readonly MultipliedObjectManager Manager = + new MultipliedObjectManager(ConfigureShieldGenerator); + + private static ConfigEntry playerOnly; + private static ConfigEntry radiusMultiplier; + private static ConfigEntry radiusMultiplierHealing; + private static ConfigEntry heartbeatIntervalMultiplier; + private static ConfigEntry powerUpDelayMultiplier; + + public static void Setup(ConfigFile config) { + const float min = 0.01f; + const float max = 32f; + + playerOnly = config.Bind("Shield", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + radiusMultiplier = + config.Bind("Shield", "Radius Multiplier", 1f, + new ConfigDescription("Radius Multiplier", new AcceptableValueRange(min, max))); + radiusMultiplier.SettingChanged += (sender, args) => DoPatch(); + + heartbeatIntervalMultiplier = config.Bind( + "Shield", "Heartbeat Interval Multiplier", 1f, + new ConfigDescription("Heartbeat Interval Multiplier", new AcceptableValueRange(min, max))); + heartbeatIntervalMultiplier.SettingChanged += (sender, args) => DoPatch(); + + powerUpDelayMultiplier = config.Bind( + "Shield", "Power Up Delay Multiplier", 1f, + new ConfigDescription("Power Up Delay Multiplier", new AcceptableValueRange(min, max))); + powerUpDelayMultiplier.SettingChanged += (sender, args) => DoPatch(); + + radiusMultiplierHealing = config.Bind( + "Shield", "Radius Multiplier Healing", 1f, + new ConfigDescription("Radius Multiplier Healing", new AcceptableValueRange(min, max))); + radiusMultiplierHealing.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureShieldGenerator(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_HealingHeartbeatInterval", heartbeatIntervalMultiplier, + ShouldApply)); + + obj.AddField(new FieldConfiguration("m_Radius", radiusMultiplier, __instance => { + if (!ShouldApply(__instance)) + return radiusMultiplier; + var shield = (ModuleShieldGenerator)__instance; + return shield.m_Healing ? radiusMultiplierHealing : radiusMultiplier; + })); + + obj.AddField(new FieldConfiguration("m_PowerUpDelay", powerUpDelayMultiplier, ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.IsPlayerTank(obj as Module); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleShieldGenerator), "OnAttached")] + public static void PostfixCreate(ModuleShieldGenerator __instance) { + Manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleShieldGenerator), "OnDetaching")] + public static void PostfixDestroy(ModuleShieldGenerator __instance) { + Manager.OnObjectDetached(__instance); + } + + private static void DoPatch() { + Manager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleShieldGenerator: {0}", obj); + PostfixCreate(obj as ModuleShieldGenerator); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWeaponGunManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWeaponGunManager.cs new file mode 100644 index 0000000..65cea2c --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWeaponGunManager.cs @@ -0,0 +1,121 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleWeaponGunManager { + private static readonly MultipliedObjectManager Manager = + new MultipliedObjectManager(ConfigureManager); + private static readonly MultipliedObjectManager FireDataManager = + new MultipliedObjectManager(ConfigureFireData); + + private static ConfigEntry playerOnly; + private static ConfigEntry kickbackStrengthMultiplier; + private static ConfigEntry muzzleVelocityMultiplier; + private static ConfigEntry burstCooldownMultiplier; + private static ConfigEntry burstShotCountMultiplier; + private static ConfigEntry shotCooldownMultiplier; + private static ConfigEntry seekingRoundsAll; + private static ConfigEntry resetBurstOnInterruptAll; + + public static void Setup(ConfigFile config) { + const float min = 0.01f; + const float max = 32f; + + playerOnly = config.Bind("WeaponGun", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + kickbackStrengthMultiplier = config.Bind( + "FireData", "Kickback Strength Multiplier", 1f, + new ConfigDescription("Kickback Strength Multiplier", new AcceptableValueRange(min, max))); + kickbackStrengthMultiplier.SettingChanged += (sender, args) => DoPatch(); + + muzzleVelocityMultiplier = config.Bind( + "FireData", "Muzzle Velocity Multiplier", 1f, + new ConfigDescription("Muzzle Velocity Multiplier", new AcceptableValueRange(min, max))); + muzzleVelocityMultiplier.SettingChanged += (sender, args) => DoPatch(); + + burstCooldownMultiplier = config.Bind( + "FireData", "Burst Cooldown Multiplier", 1f, + new ConfigDescription("Burst Cooldown Multiplier", new AcceptableValueRange(min, max))); + burstCooldownMultiplier.SettingChanged += (sender, args) => DoPatch(); + + burstShotCountMultiplier = config.Bind( + "FireData", "Burst Shot Count Multiplier", 1f, + new ConfigDescription("Burst Shot Count Multiplier", new AcceptableValueRange(min, max))); + burstShotCountMultiplier.SettingChanged += (sender, args) => DoPatch(); + + shotCooldownMultiplier = config.Bind( + "FireData", "Shot Cooldown Multiplier", 1f, + new ConfigDescription("Shot Cooldown Multiplier", new AcceptableValueRange(min, max))); + shotCooldownMultiplier.SettingChanged += (sender, args) => DoPatch(); + + seekingRoundsAll = + config.Bind("FireData", "Seeking Rounds All", false, + new ConfigDescription("Seeking Rounds All", new AcceptableValueRange(false, true))); + seekingRoundsAll.SettingChanged += (sender, args) => DoPatch(); + + resetBurstOnInterruptAll = config.Bind( + "FireData", "Reset Burst On Interrupt All", false, + new ConfigDescription("Reset Burst On Interrupt All", new AcceptableValueRange(false, true))); + resetBurstOnInterruptAll.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureManager(MultipliedObject obj) { + obj.AddBooleanField(new BooleanFieldConfiguration("m_SeekingRounds", seekingRoundsAll, ShouldApply)); + obj.AddBooleanField( + new BooleanFieldConfiguration("m_ResetBurstOnInterrupt", resetBurstOnInterruptAll, ShouldApply)); + obj.AddField(new FieldConfiguration("m_BurstCooldown", burstCooldownMultiplier, ShouldApply)); + obj.AddField(new FieldConfiguration("m_BurstShotCount", burstShotCountMultiplier, ShouldApply)); + obj.AddField(new FieldConfiguration("m_ShotCooldown", shotCooldownMultiplier, ShouldApply)); + } + + private static void ConfigureFireData(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_MuzzleVelocity", muzzleVelocityMultiplier)); + obj.AddField(new FieldConfiguration("m_KickbackStrength", kickbackStrengthMultiplier)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.IsPlayerTank(obj as Module); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleWeaponGun), "OnAttached")] + public static void PostfixCreate(ModuleWeaponGun __instance) { + Manager.OnObjectAttached(__instance); + if (playerOnly.Value && !CykUtil.IsPlayerTank(__instance)) + return; + + var trav = Traverse.Create(__instance); + var firingData = trav.Field("m_FiringData"); + FireDataManager.OnObjectAttached(firingData.GetValue()); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleWeaponGun), "OnDetaching")] + public static void PostfixDestroy(ModuleWeaponGun __instance) { + Manager.OnObjectAttached(__instance); + var trav = Traverse.Create(__instance); + if (playerOnly.Value && !CykUtil.IsPlayerTank(__instance)) + return; + + var firingData = trav.Field("m_FiringData"); + FireDataManager.OnObjectDetached(firingData.GetValue()); + } + + private static void DoPatch() { + FireDataManager.ApplyAll(); + Manager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleWeaponGun: {0}", obj); + PostfixCreate(obj as ModuleWeaponGun); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWeaponManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWeaponManager.cs new file mode 100644 index 0000000..6a1a7c8 --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWeaponManager.cs @@ -0,0 +1,60 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleWeaponManager { + private static readonly MultipliedObjectManager Manager = + new MultipliedObjectManager(ConfigureManager); + + private static ConfigEntry playerOnly; + private static ConfigEntry rotateSpeedMultiplier; + + public static void Setup(ConfigFile config) { + const float min = 0.01f; + const float max = 32f; + + playerOnly = config.Bind("ModuleWeapon", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + rotateSpeedMultiplier = config.Bind( + "ModuleWeapon", "Rotate Speed Multiplier", 1f, + new ConfigDescription("Rotate Speed Multiplier", new AcceptableValueRange(min, max))); + rotateSpeedMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureManager(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("m_RotateSpeed", rotateSpeedMultiplier, ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.IsPlayerTank(obj as Module); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleWeapon), "OnAttached")] + public static void PostfixCreate(ModuleWeapon __instance) { + Manager.OnObjectAttached(__instance); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleWeapon), "OnDetaching")] + public static void PostfixDestroy(ModuleWeapon __instance) { + Manager.OnObjectDetached(__instance); + } + + private static void DoPatch() { + Manager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleWeapon: {0}", obj); + PostfixCreate(obj as ModuleWeapon); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWheelsManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWheelsManager.cs new file mode 100644 index 0000000..a32b42b --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWheelsManager.cs @@ -0,0 +1,71 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class ModuleWheelsManager { + private static readonly MultipliedObjectManager TorqueParamsManager = + new MultipliedObjectManager(ConfigureTorqueParams); + + private static ConfigEntry playerOnly; + private static ConfigEntry torqueRpmMultiplier; + private static ConfigEntry torqueMultiplier; + + public static void Setup(ConfigFile config) { + const float min = 0.01f; + const float max = 32f; + + playerOnly = config.Bind("TorqueParams", "Player Only", false, new ConfigDescription("Player Only")); + playerOnly.SettingChanged += (sender, args) => DoPatch(); + + torqueRpmMultiplier = + config.Bind("TorqueParams", "Torque RPM Multiplier", 1f, + new ConfigDescription("Torque RPM Multiplier", new AcceptableValueRange(min, max))); + torqueRpmMultiplier.SettingChanged += (sender, args) => DoPatch(); + + torqueMultiplier = + config.Bind("TorqueParams", "Torque Multiplier", 1f, + new ConfigDescription("Torque Multiplier", new AcceptableValueRange(min, max))); + torqueMultiplier.SettingChanged += (sender, args) => DoPatch(); + } + + private static void ConfigureTorqueParams(MultipliedObject obj) { + obj.AddField(new FieldConfiguration("torqueCurveMaxRpm", torqueRpmMultiplier, ShouldApply)); + obj.AddField(new FieldConfiguration("torqueCurveMaxTorque", torqueMultiplier, ShouldApply)); + } + + private static readonly Func ShouldApply = obj => { + if (!playerOnly.Value) + return true; + return CykUtil.IsPlayerTank(obj as Module); + }; + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleWheels), "OnAttached")] + public static void PostfixCreate(ModuleWheels __instance) { + var trav = Traverse.Create(__instance); + var torqueParams = trav.Field("torqueParams"); + TorqueParamsManager.OnObjectAttached(torqueParams.GetValue()); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ModuleWheels), "OnDetaching")] + public static void PostfixDestroy(ModuleWheels __instance) { + var trav = Traverse.Create(__instance); + var torqueParams = trav.Field("torqueParams"); + TorqueParamsManager.OnObjectDetached(torqueParams.GetValue()); + } + + private static void DoPatch() { + TorqueParamsManager.ApplyAll(); + } + + public static readonly Func Register = obj => { + if (Main.debug.Value) + Console.WriteLine("Registering ModuleWheels: {0}", obj); + PostfixCreate(obj as ModuleWheels); + return true; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWingManager.cs b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWingManager.cs new file mode 100644 index 0000000..d35c4dd --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/ModuleWingManager.cs @@ -0,0 +1,83 @@ +using System; +using BepInEx.Configuration; +using HarmonyLib; + +namespace BlacksmithMaster { + [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; + }; + } +} diff --git a/Projects/BlacksmithMaster/BlacksmithMaster/MultiBuy.cs b/Projects/BlacksmithMaster/BlacksmithMaster/MultiBuy.cs new file mode 100644 index 0000000..b275fbb --- /dev/null +++ b/Projects/BlacksmithMaster/BlacksmithMaster/MultiBuy.cs @@ -0,0 +1,71 @@ +using System; +using System.Reflection; +using HarmonyLib; +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace BlacksmithMaster { + [HarmonyPatch] + public class MultiBuy { + public static UIShopBlockSelect panel; + public static Traverse panelTraverse; + + [HarmonyPostfix] + [HarmonyPatch(typeof(UIShopBlockSelect), "OnSpawn")] + public static void PostfixCreate(UIShopBlockSelect __instance) { + panel = __instance; + if (Main.debugBuyAll.Value) + Console.WriteLine("UISnapshotPanel.OnPool: {0}", __instance); + panelTraverse = Traverse.Create(__instance); + var placeButton = panelTraverse.Field("m_PurchaseBlockButton").GetValue