Skip to content

Commit

Permalink
finally update code to also include metal tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
sp00ktober committed Jul 3, 2022
1 parent 9204902 commit 61cae92
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 152 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ For support or to discuss any other modding related topic you can join our [Star

## Changelog

0.0.2:

- also include metal tools

0.0.1:

- Initial release
5 changes: 5 additions & 0 deletions ShowDurability.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShowDurability", "ShowDurability\ShowDurability.csproj", "{4058B9D2-05FA-48BE-A71A-AB5DE9E158F8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{16932195-FFE9-4272-90F6-6AE44E3C057B}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
24 changes: 22 additions & 2 deletions ShowDurability/Patches/Dynamic/Slot_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace ShowDurability.Patches.Dynamic
[HarmonyPatch(typeof(Slot))]
class Slot_Patch
{
static float MAX_HEALTH = 300f;
static float MAX_HEALTH_WOOD = 300f;
static float MAX_HEALTH_IRON_PICKAXE = 600f;
static float MAX_HEALTH_IRON_AXE = 540f;

[HarmonyPostfix]
[HarmonyPatch(typeof(Slot), "Refresh")]
Expand All @@ -18,7 +20,25 @@ public static void Refresh_Postfix(Slot __instance)
DurabilityBar bar = (DurabilityBar)AccessTools.Field(typeof(Slot), "m_DurabilityBar").GetValue(__instance);
bar.SetActive(true);

bar.SetFillAmount(__instance.CurrentItem.GetPropertyValue("Durability").Float.Current / MAX_HEALTH);
bar.SetFillAmount(__instance.CurrentItem.GetPropertyValue("Durability").Float.Current / MAX_HEALTH_WOOD);

__instance.Refreshed.Send(__instance);
}
else if (__instance?.CurrentItem?.Name == "METAL PICKAXE")
{
DurabilityBar bar = (DurabilityBar)AccessTools.Field(typeof(Slot), "m_DurabilityBar").GetValue(__instance);
bar.SetActive(true);

bar.SetFillAmount(__instance.CurrentItem.GetPropertyValue("Durability").Float.Current / MAX_HEALTH_IRON_PICKAXE);

__instance.Refreshed.Send(__instance);
}
else if(__instance?.CurrentItem?.Name == "METAL AX")
{
DurabilityBar bar = (DurabilityBar)AccessTools.Field(typeof(Slot), "m_DurabilityBar").GetValue(__instance);
bar.SetActive(true);

bar.SetFillAmount(__instance.CurrentItem.GetPropertyValue("Durability").Float.Current / MAX_HEALTH_IRON_AXE);

__instance.Refreshed.Send(__instance);
}
Expand Down
19 changes: 2 additions & 17 deletions ShowDurability/ShowDurability.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using BepInEx;
using HarmonyLib;
using System;
using System.IO;
using System.Reflection;
using UnityEngine;

namespace ShowDurability
{
[BepInPlugin("com.sp00ktober.ShowDurability", "ShowDurability", "0.0.1")]
[BepInPlugin("com.sp00ktober.ShowDurability", "ShowDurability", "0.0.2")]
public class ShowDurability : BaseUnityPlugin
{
private void Awake()
Expand All @@ -21,23 +20,9 @@ private static void InitPatches()

try
{
Debug.Log("Applying patches from ShowDurability 0.0.1");
#if DEBUG
if (Directory.Exists("./mmdump"))
{
foreach (FileInfo file in new DirectoryInfo("./mmdump").GetFiles())
{
file.Delete();
}
Debug.Log("Applying patches from ShowDurability 0.0.2");

Environment.SetEnvironmentVariable("MONOMOD_DMD_TYPE", "cecil");
Environment.SetEnvironmentVariable("MONOMOD_DMD_DUMP", "./mmdump");
}
#endif
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.sp00ktober.de");
#if DEBUG
Environment.SetEnvironmentVariable("MONOMOD_DMD_DUMP", "");
#endif

Debug.Log("Patching completed successfully");
}
Expand Down
Loading

0 comments on commit 61cae92

Please sign in to comment.