Skip to content

Commit

Permalink
Made changes to patches and moved the config options around
Browse files Browse the repository at this point in the history
  • Loading branch information
chudders1231 committed Jun 26, 2023
1 parent 2d8bec2 commit d0626ca
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 51 deletions.
35 changes: 2 additions & 33 deletions ConfigOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> cureKnifeRange;
public static ConfigEntry<float> 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<float>(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<float>(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"));
}
}
}
4 changes: 2 additions & 2 deletions Items/Equipment/CureBladeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
8 changes: 8 additions & 0 deletions Patches/CreatureDeathPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CustomCreatureData>().lastDamageType = damageInfo.type;
}

public static IEnumerator SpawnCuredFish( GameObject origFish, TechType curedFish)
{
TaskResult<GameObject> result = new TaskResult<GameObject>();
Expand Down
16 changes: 2 additions & 14 deletions Patches/LiveMixinPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CreatureDeath>();

if (liveMixin && go.GetComponent<EntityTag>() != null && crd != null)
if (liveMixin && go.GetComponent<EntityTag>() != null && crd != null)
{
var customCreatureData = liveMixin.gameObject.EnsureComponent<CustomCreatureData>();
};
return true;
}

[HarmonyPatch(nameof(LiveMixin.TakeDamage))]
[HarmonyPrefix]
internal static bool TakeDamage_Prefix(LiveMixin __instance, DamageType type)
{
var customCreatureData = __instance.gameObject.GetComponent<CustomCreatureData>();
if (customCreatureData != null)
{
customCreatureData.lastDamageType = type;
}
return true;
}
}
}
32 changes: 30 additions & 2 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
using HarmonyLib;
using BepInEx;
using CureBlade.Items.Equipment;
using BepInEx.Configuration;
using System.IO;

namespace CureBlade;

[BepInPlugin(myGUID, pluginName, versionString)]
[BepInDependency("com.snmodding.nautilus")]
public class Plugin : BaseUnityPlugin
{
// Config Stuff
public static ConfigEntry<float> cureKnifeRange;
public static ConfigEntry<float> 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;

Expand All @@ -26,7 +32,7 @@ private void Awake()
harmony.PatchAll();

// Run additional functions prior to registering items
SetupConfigOptions.SetupBepinexConfigs();
SetupBepinexConfigs();

// Initialise custom prefabs
InitializePrefabs();
Expand All @@ -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<float>(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<float>(0.1f, 5.0f)
)
);

OptionsPanelHandler.RegisterModOptions(new CureBladeOptions());
}

private void InitializePrefabs()
{
CureBladeItem.Patch();
Expand Down

0 comments on commit d0626ca

Please sign in to comment.