Decompiled source of ShowPlantProgress v1.5.0

ShowPlantProgress.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("ShowPlantProgress")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2024  KompjoeFriek")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyInformationalVersion("1.5.0+72f060948c7a2c496b3e6ee8537c1ef6bf15cbc9")]
[assembly: AssemblyProduct("Show Plant Progress")]
[assembly: AssemblyTitle("ShowPlantProgress")]
[assembly: AssemblyVersion("1.5.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ShowPlantProgress
{
	[BepInPlugin("kompjoefriek.showplantprogress", "Show Plant Progress", "1.5.0")]
	[HarmonyPatch]
	public class ShowPlantProgressPlugin : BaseUnityPlugin
	{
		internal const string _modVersion = "1.5.0";

		internal const string _modDescription = "Show Plant Progress";

		internal const string _modUid = "kompjoefriek.showplantprogress";

		internal static ManualLogSource Logger;

		private static ConfigEntry<bool> enableMod;

		private static ConfigEntry<int> amountofDecimals;

		private static readonly List<string> bushList = new List<string> { "RaspberryBush(Clone)", "BlueberryBush(Clone)", "CloudberryBush(Clone)" };

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			enableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Global", "Enable Mod", true, "Enable or disable this mod");
			amountofDecimals = ((BaseUnityPlugin)this).Config.Bind<int>("2 - General", "Amount of Decimal Places", 2, "The amount of decimal places to show");
			if (enableMod.Value)
			{
				Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			}
		}

		private static string GetColor(double percentage)
		{
			if (percentage >= 75.0)
			{
				return "green";
			}
			if (percentage >= 50.0)
			{
				return "yellow";
			}
			if (percentage >= 25.0)
			{
				return "orange";
			}
			return "red";
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Plant), "GetHoverText")]
		public static string PlantGetHoverText_Patch(string __result, Plant __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return __result;
			}
			double num = Math.Floor(Traverse.Create((object)__instance).Method("TimeSincePlanted", Array.Empty<object>()).GetValue<double>() / (double)Traverse.Create((object)__instance).Method("GetGrowTime", Array.Empty<object>()).GetValue<float>() * 100.0);
			string color = GetColor(num);
			string text = $"<color={color}>{Math.Round(num, amountofDecimals.Value, MidpointRounding.AwayFromZero)}%</color>";
			return __result.Replace(" )", ", " + text + " )");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Pickable), "GetHoverText")]
		public static string BerryBushPickable_Patch(string __result, Pickable __instance, ZNetView ___m_nview)
		{
			if (!bushList.Contains(((Object)__instance).name))
			{
				return __result;
			}
			DateTime dateTime = new DateTime(___m_nview.GetZDO().GetLong(ZDOVars.s_pickedTime, 0L));
			double num = (ZNet.instance.GetTime() - dateTime).TotalMinutes / (double)__instance.m_respawnTimeMinutes * 100.0;
			if (num > 99.98999786376953)
			{
				return __result;
			}
			string color = GetColor(num);
			string text = $"<color={color}>{Math.Round(num, amountofDecimals.Value, MidpointRounding.AwayFromZero)}%</color>";
			return __result + Localization.instance.Localize(__instance.GetHoverName()) + " ( " + text + " )";
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ShowPlantProgress";

		public const string PLUGIN_NAME = "Show Plant Progress";

		public const string PLUGIN_VERSION = "1.5.0";
	}
}