Decompiled source of FermenterTimer v1.0.1

FermenterTimer.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FermenterTimer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FermenterTimer")]
[assembly: AssemblyTitle("FermenterTimer")]
[assembly: AssemblyVersion("1.0.0.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("com.Azura.fermentertimer", "FermenterTimer", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.Azura.fermentertimer";

		public const string PluginName = "FermenterTimer";

		public const string PluginVersion = "1.0.1";

		internal static ConfigEntry<bool> Pourcentage;

		internal static ConfigEntry<string> Couleur;

		private void Awake()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			Pourcentage = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowPercent", false, "Also show how far the fermentation has gone, in percent.\nAffiche aussi l'avancement de la fermentation, en pourcentage.");
			Couleur = ((BaseUnityPlugin)this).Config.Bind<string>("General", "TextColor", "#E8C77A", "Colour of the time left line (HTML colour such as #E8C77A or white; empty = the hover text's colour).\nCouleur de la ligne du temps restant (couleur HTML comme #E8C77A ou white ; vide = celle du texte de survol).");
			new Harmony("com.Azura.fermentertimer").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)Traductions.Format("journal_charge", null, new object[2] { "FermenterTimer", "1.0.1" }));
		}
	}
	[HarmonyPatch(typeof(Fermenter), "GetHoverText")]
	public static class Fermenter_GetHoverText_Patch
	{
		private static readonly FieldRef<Fermenter, ZNetView> Vue = AccessTools.FieldRefAccess<Fermenter, ZNetView>("m_nview");

		private static readonly FieldRef<Fermenter, bool> Toit = AccessTools.FieldRefAccess<Fermenter, bool>("m_hasRoof");

		private static readonly FieldRef<Fermenter, bool> Expose = AccessTools.FieldRefAccess<Fermenter, bool>("m_exposed");

		public static void Postfix(Fermenter __instance, ref string __result)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!string.IsNullOrEmpty(__result) && Restant(__instance, out var restant, out var avancement) && PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, false, false))
				{
					string text = Traductions.Format("restant", null, new object[1] { Duree(restant) });
					if (Plugin.Pourcentage.Value)
					{
						text = text + " (" + Traductions.Format("pourcent", null, new object[1] { (int)Math.Floor(avancement * 100.0) }) + ")";
					}
					string text2 = Plugin.Couleur.Value?.Trim();
					Color val = default(Color);
					if (!string.IsNullOrEmpty(text2) && ColorUtility.TryParseHtmlString(text2, ref val))
					{
						text = "<color=" + text2 + ">" + text + "</color>";
					}
					__result = __result + "\n" + text;
				}
			}
			catch (Exception)
			{
			}
		}

		internal static bool Restant(Fermenter f, out double restant, out double avancement)
		{
			restant = (avancement = 0.0);
			ZNetView val = Vue.Invoke(f);
			ZDO val2 = (((Object)(object)val != (Object)null && val.IsValid()) ? val.GetZDO() : null);
			if (val2 == null || (Object)(object)ZNet.instance == (Object)null || val2.GetInt(ZDOVars.s_content, 0) == 0)
			{
				return false;
			}
			long num = val2.GetLong(ZDOVars.s_startTime, 0L);
			double num2 = f.m_fermentationDuration;
			if (num == 0L || num2 <= 0.0 || !Toit.Invoke(f) || Expose.Invoke(f))
			{
				return false;
			}
			double num3 = Math.Max(0.0, (ZNet.instance.GetTime() - new DateTime(num)).TotalSeconds);
			if (num3 > num2)
			{
				return false;
			}
			restant = num2 - num3;
			avancement = num3 / num2;
			return true;
		}

		internal static string Duree(double secondes)
		{
			int num = (int)Math.Ceiling(secondes);
			int num2 = num / 3600;
			int num3 = num % 3600 / 60;
			int num4 = num % 60;
			if (num2 <= 0)
			{
				return $"{num3}:{num4:00}";
			}
			return $"{num2}:{num3:00}:{num4:00}";
		}
	}
	internal static class Traductions
	{
		internal static readonly string[] Langues = new string[36]
		{
			"English", "Swedish", "French", "Italian", "German", "Spanish", "Russian", "Romanian", "Bulgarian", "Macedonian",
			"Finnish", "Danish", "Norwegian", "Icelandic", "Turkish", "Lithuanian", "Czech", "Hungarian", "Slovak", "Polish",
			"Dutch", "Portuguese_European", "Portuguese_Brazilian", "Chinese", "Chinese_Trad", "Japanese", "Korean", "Hindi", "Thai", "Abenaki",
			"Croatian", "Georgian", "Greek", "Serbian", "Ukrainian", "Latvian"
		};

		private static readonly string[] Cultures = new string[36]
		{
			"en-US", "sv-SE", "fr-FR", "it-IT", "de-DE", "es-ES", "ru-RU", "ro-RO", "bg-BG", "mk-MK",
			"fi-FI", "da-DK", "nb-NO", "is-IS", "tr-TR", "lt-LT", "cs-CZ", "hu-HU", "sk-SK", "pl-PL",
			"nl-NL", "pt-PT", "pt-BR", "zh-CN", "zh-TW", "ja-JP", "ko-KR", "hi-IN", "th-TH", "en-US",
			"hr-HR", "ka-GE", "el-GR", "sr-Latn-RS", "uk-UA", "lv-LV"
		};

		internal static readonly Dictionary<string, string[]> Textes;

		private static readonly FieldInfo TraductionDuJeu;

		private static bool jeuPret;

		internal static string LangueDuJeu
		{
			get
			{
				try
				{
					if (!jeuPret)
					{
						if (TraductionDuJeu != null && TraductionDuJeu.GetValue(null) == null)
						{
							return PlayerPrefs.GetString("language", "English");
						}
						jeuPret = true;
					}
					return Localization.instance.GetSelectedLanguage();
				}
				catch (Exception)
				{
					return "English";
				}
			}
		}

		internal static string Texte(string cle, string langue = null)
		{
			if (!Textes.TryGetValue(cle, out var value))
			{
				return cle;
			}
			int num = Array.IndexOf(Langues, langue ?? LangueDuJeu);
			if (num <= 0 || num >= value.Length || string.IsNullOrEmpty(value[num]))
			{
				return value[0];
			}
			return value[num];
		}

		internal static string Format(string cle, string langue, object[] valeurs)
		{
			string text = Texte(cle, langue);
			if (valeurs != null && valeurs.Length != 0)
			{
				return string.Format(Culture(langue), text, valeurs);
			}
			return text;
		}

		internal static CultureInfo Culture(string langue = null)
		{
			int num = Array.IndexOf(Langues, langue ?? LangueDuJeu);
			try
			{
				return CultureInfo.GetCultureInfo((num >= 0) ? Cultures[num] : "en-US");
			}
			catch
			{
				return CultureInfo.InvariantCulture;
			}
		}

		static Traductions()
		{
			Dictionary<string, string[]> dictionary = new Dictionary<string, string[]>
			{
				["restant"] = new string[36]
				{
					"Time left: {0}", "Tid kvar: {0}", "Temps restant : {0}", "Tempo rimanente: {0}", "Restzeit: {0}", "Tiempo restante: {0}", "Осталось: {0}", "Timp rămas: {0}", "Оставащо време: {0}", "Преостанато време: {0}",
					"Aikaa jäljellä: {0}", "Tid tilbage: {0}", "Tid igjen: {0}", "Tími eftir: {0}", "Kalan süre: {0}", "Liko laiko: {0}", "Zbývající čas: {0}", "Hátralévő idő: {0}", "Zostávajúci čas: {0}", "Pozostały czas: {0}",
					"Resterende tijd: {0}", "Tempo restante: {0}", "Tempo restante: {0}", "剩余时间:{0}", "剩餘時間:{0}", "残り時間:{0}", "남은 시간: {0}", "श\u0947ष समय: {0}", "เวลาท\u0e35\u0e48เหล\u0e37อ: {0}", null,
					"Preostalo vrijeme: {0}", "დარჩენილი დრო: {0}", "Υπόλοιπος χρόνος: {0}", "Preostalo vreme: {0}", "Залишилося: {0}", "Atlikušais laiks: {0}"
				},
				["pourcent"] = new string[36]
				{
					"{0}%", "{0} %", "{0} %", "{0}%", "{0} %", "{0} %", "{0} %", "{0} %", "{0} %", "{0} %",
					"{0} %", "{0} %", "{0} %", "{0}%", "%{0}", "{0} %", "{0} %", "{0}%", "{0} %", "{0}%",
					"{0}%", "{0}%", "{0}%", "{0}%", "{0}%", "{0}%", "{0}%", "{0}%", "{0}%", null,
					"{0} %", "{0}%", "{0}%", "{0}%", "{0}%", "{0}%"
				}
			};
			string[] array = new string[36];
			array[0] = "{0} v{1} loaded.";
			array[2] = "{0} v{1} chargé.";
			dictionary["journal_charge"] = array;
			Textes = dictionary;
			TraductionDuJeu = typeof(Localization).GetField("m_instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		}
	}
}