Decompiled source of FermenterTimer v1.1.1

plugins/FermenterTimer.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("FermenterTimer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+5d9e50044f12784b51d2c67a996f2fb5ec34f195")]
[assembly: AssemblyProduct("FermenterTimer")]
[assembly: AssemblyTitle("FermenterTimer")]
[assembly: AssemblyVersion("1.1.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 FermenterTimer
{
	[BepInPlugin("Tie.FermenterTimer", "FermenterTimer", "1.1.1")]
	public sealed class FermenterTimerPlugin : BaseUnityPlugin
	{
		public const string Guid = "Tie.FermenterTimer";

		private const string OldGuid = "local.fermentertimer";

		public const string Version = "1.1.1";

		private static ConfigEntry<bool> _showSeconds;

		private static readonly FieldRef<Fermenter, ZNetView> NView = AccessTools.FieldRefAccess<Fermenter, ZNetView>("m_nview");

		private static readonly Func<Fermenter, double> FermentationTime = AccessTools.MethodDelegate<Func<Fermenter, double>>(AccessTools.Method(typeof(Fermenter), "GetFermentationTime", (Type[])null, (Type[])null), (object)null, true);

		private void Awake()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Paths.ConfigPath, "local.fermentertimer.cfg");
			if (File.Exists(text) && !File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath))
			{
				try
				{
					File.Move(text, ((BaseUnityPlugin)this).Config.ConfigFilePath);
					((BaseUnityPlugin)this).Config.Reload();
				}
				catch (IOException)
				{
				}
			}
			_showSeconds = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowSeconds", true, "Show seconds in the remaining time.");
			new Harmony("Tie.FermenterTimer").PatchAll(typeof(FermenterTimerPlugin));
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Fermenter), "GetHoverText")]
		private static void GetHoverText(Fermenter __instance, ref string __result)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			ZNetView val = NView.Invoke(__instance);
			if (!((Object)(object)val == (Object)null) && val.IsValid() && val.GetZDO().GetInt(ZDOVars.s_content, 0) != 0 && PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, false, false))
			{
				double num = FermentationTime(__instance);
				if (!(num < 0.0) && !(num > (double)__instance.m_fermentationDuration))
				{
					TimeSpan t = TimeSpan.FromSeconds(Math.Ceiling((double)__instance.m_fermentationDuration - num));
					__result = __result + "\n<color=orange>Ready in " + Format(t) + "</color>";
				}
			}
		}

		private static string Format(TimeSpan t)
		{
			if (t.TotalHours >= 1.0)
			{
				return $"{(int)t.TotalHours}h {t.Minutes:00}m";
			}
			if (!_showSeconds.Value)
			{
				return $"{Math.Max(1, (int)Math.Ceiling(t.TotalMinutes))}m";
			}
			return $"{t.Minutes}m {t.Seconds:00}s";
		}
	}
}