diff --git a/ConfigOptions.cs b/ConfigOptions.cs index 44ab258..8e7819d 100644 --- a/ConfigOptions.cs +++ b/ConfigOptions.cs @@ -6,43 +6,12 @@ namespace CureBlade { - public class SetupConfigOptions - { - // Declare config options - public static ConfigFile config = new ConfigFile(Path.Combine(Paths.ConfigPath, "CureBlade.cfg"), true); - - public static ConfigEntry cureKnifeRange; - public static ConfigEntry cureKnifeDamage; - - public static void SetupBepinexConfigs() - { - cureKnifeRange = config.Bind("Cure Blade Options", - "Cure Knife Range", - 1.0f, - new ConfigDescription( - "Changes the hit range of the cure knife.", - new AcceptableValueRange(0.1f, 2.0f) - ) - ); - cureKnifeDamage = config.Bind("Cure Blade Options", - "Cure Knife Damage", - 1.0f, - new ConfigDescription( - "Changes the damage of the cure knife.", - new AcceptableValueRange(0.1f, 5.0f) - ) - ); - - OptionsPanelHandler.RegisterModOptions(new CureBladeOptions()); - } - } - public class CureBladeOptions : ModOptions { public CureBladeOptions() : base("Cure Blade Options") { - AddItem(SetupConfigOptions.cureKnifeRange.ToModSliderOption(minValue: 0.1f, maxValue: 2.0f, step: 0.01f, floatFormat: "{0:F2}x")); - AddItem(SetupConfigOptions.cureKnifeDamage.ToModSliderOption(minValue: 0.1f, maxValue: 5.0f, step: 0.1f, floatFormat: "{0:F1}x")); + AddItem(Plugin.cureKnifeRange.ToModSliderOption(minValue: 0.1f, maxValue: 2.0f, step: 0.01f, floatFormat: "{0:F2}x")); + AddItem(Plugin.cureKnifeDamage.ToModSliderOption(minValue: 0.1f, maxValue: 5.0f, step: 0.1f, floatFormat: "{0:F1}x")); } } } \ No newline at end of file diff --git a/Items/Equipment/CureBladeItem.cs b/Items/Equipment/CureBladeItem.cs index 14a0a5e..324cbf2 100644 --- a/Items/Equipment/CureBladeItem.cs +++ b/Items/Equipment/CureBladeItem.cs @@ -70,12 +70,12 @@ public override void OnToolUseAnim(GUIHand hand) { var heatBladeDamage = 40; - this.damage = heatBladeDamage * SetupConfigOptions.cureKnifeDamage.Value; + this.damage = heatBladeDamage * Plugin.cureKnifeDamage.Value; base.OnToolUseAnim(hand); GameObject hitObj = null; Vector3 hitPosition = default; - UWE.Utils.TraceFPSTargetPosition(Player.main.gameObject, attackDist * SetupConfigOptions.cureKnifeRange.Value, ref hitObj, ref hitPosition); + UWE.Utils.TraceFPSTargetPosition(Player.main.gameObject, attackDist * Plugin.cureKnifeRange.Value, ref hitObj, ref hitPosition); } } \ No newline at end of file diff --git a/Patches/CreatureDeathPatch.cs b/Patches/CreatureDeathPatch.cs index c2425ce..61935c8 100644 --- a/Patches/CreatureDeathPatch.cs +++ b/Patches/CreatureDeathPatch.cs @@ -23,6 +23,14 @@ internal static void OnKillAsyncPrefix(CreatureDeath __instance) UWE.CoroutineHost.StartCoroutine(SpawnCuredFish(gameObject, curedData)); } } + + [HarmonyPatch(nameof(CreatureDeath.OnTakeDamage))] + [HarmonyPrefix] + internal static void OnTakeDamagePrefix( CreatureDeath __instance, DamageInfo damageInfo) + { + __instance.gameObject.GetComponent().lastDamageType = damageInfo.type; + } + public static IEnumerator SpawnCuredFish( GameObject origFish, TechType curedFish) { TaskResult result = new TaskResult(); diff --git a/Patches/LiveMixinPatch.cs b/Patches/LiveMixinPatch.cs index 818698b..26f7a1d 100644 --- a/Patches/LiveMixinPatch.cs +++ b/Patches/LiveMixinPatch.cs @@ -8,29 +8,17 @@ internal class LiveMixinPatch [HarmonyPatch(nameof(LiveMixin.Awake))] [HarmonyPrefix] - internal static bool Awake_Prefix( LiveMixin __instance ) + internal static bool Awake_Prefix(LiveMixin __instance) { LiveMixin liveMixin = __instance; var go = liveMixin.gameObject; var crd = go.GetComponent(); - if (liveMixin && go.GetComponent() != null && crd != null) + if (liveMixin && go.GetComponent() != null && crd != null) { var customCreatureData = liveMixin.gameObject.EnsureComponent(); }; return true; } - - [HarmonyPatch(nameof(LiveMixin.TakeDamage))] - [HarmonyPrefix] - internal static bool TakeDamage_Prefix(LiveMixin __instance, DamageType type) - { - var customCreatureData = __instance.gameObject.GetComponent(); - if (customCreatureData != null) - { - customCreatureData.lastDamageType = type; - } - return true; - } } } diff --git a/Plugin.cs b/Plugin.cs index 422b210..8ea72a6 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -3,6 +3,8 @@ using HarmonyLib; using BepInEx; using CureBlade.Items.Equipment; +using BepInEx.Configuration; +using System.IO; namespace CureBlade; @@ -10,10 +12,14 @@ namespace CureBlade; [BepInDependency("com.snmodding.nautilus")] public class Plugin : BaseUnityPlugin { + // Config Stuff + public static ConfigEntry cureKnifeRange; + public static ConfigEntry cureKnifeDamage; + // Plugin Setup private const string myGUID = "com.chadlymasterson.cureknife"; private const string pluginName = "Cure Blade"; - private const string versionString = "1.0.0"; + private const string versionString = "1.0.1"; public static readonly Harmony harmony = new Harmony(myGUID); public static ManualLogSource logger; @@ -26,7 +32,7 @@ private void Awake() harmony.PatchAll(); // Run additional functions prior to registering items - SetupConfigOptions.SetupBepinexConfigs(); + SetupBepinexConfigs(); // Initialise custom prefabs InitializePrefabs(); @@ -37,6 +43,28 @@ private void Awake() logger.LogInfo($"Plugin {myGUID} is loaded!"); } + private void SetupBepinexConfigs() + { + cureKnifeRange = Config.Bind("Cure Blade Options", + "Cure Knife Range", + 1.0f, + new ConfigDescription( + "Changes the hit range of the cure knife.", + new AcceptableValueRange(0.1f, 2.0f) + ) + ); + cureKnifeDamage = Config.Bind("Cure Blade Options", + "Cure Knife Damage", + 1.0f, + new ConfigDescription( + "Changes the damage of the cure knife.", + new AcceptableValueRange(0.1f, 5.0f) + ) + ); + + OptionsPanelHandler.RegisterModOptions(new CureBladeOptions()); + } + private void InitializePrefabs() { CureBladeItem.Patch();