Add blacksmith master project

This commit is contained in:
2025-05-17 10:50:17 +02:00
parent 22b048a629
commit fff44bfc93
32 changed files with 2361 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
using System;
using BepInEx.Configuration;
using HarmonyLib;
namespace BlacksmithMaster {
[HarmonyPatch]
public class ModuleEnergyStoreManager {
private static readonly MultipliedObjectManager<ModuleEnergyStore> Manager =
new MultipliedObjectManager<ModuleEnergyStore>(ConfigureModuleEnergyStore);
private static ConfigEntry<bool> playerOnly;
private static ConfigEntry<float> 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<float>(min, max)));
capacityMultiplier.SettingChanged += (sender, args) => DoPatch();
}
private static void ConfigureModuleEnergyStore(MultipliedObject<ModuleEnergyStore> obj) {
obj.AddField(new FieldConfiguration<float, float>("m_Capacity", capacityMultiplier, ShouldApply));
}
private static readonly Func<object, bool> 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<Module, bool> Register = obj => {
if (Main.debug.Value)
Console.WriteLine("Registering ModuleEnergyStore: {0}", obj);
PostfixCreate(obj as ModuleEnergyStore);
return true;
};
}
}