using System;
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("FermenterUtilities")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2025 KompjoeFriek")]
[assembly: AssemblyDescription("Fermenter Utilities")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+35f8745d74e46728a22fbc780c28d9192f279505")]
[assembly: AssemblyProduct("FermenterUtilities")]
[assembly: AssemblyTitle("FermenterUtilities")]
[assembly: AssemblyVersion("1.1.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 FermenterUtilities
{
[BepInPlugin("kompjoefriek.FermenterUtilities", "Fermenter Utilities", "1.1.0")]
[HarmonyPatch]
public class FermenterUtilitiesPlugin : BaseUnityPlugin
{
internal const string _modVersion = "1.1.0";
internal const string _modDescription = "Fermenter Utilities";
internal const string _modUid = "kompjoefriek.FermenterUtilities";
internal static ManualLogSource Logger;
private static ConfigEntry<bool> _configEnableMod;
private static ConfigEntry<bool> _configShowPercentage;
private static ConfigEntry<bool> _configShowColorPercentage;
private static ConfigEntry<bool> _configShowTime;
private static ConfigEntry<bool> _configCustomFermentTime;
private static ConfigEntry<bool> _configNoCover;
private static ConfigEntry<int> _configAmountOfDecimals;
private static ConfigEntry<int> _configNewFermentTime;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
_configEnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Global", "Enable Mod", true, "Enable or disable this mod");
if (_configEnableMod.Value)
{
_configShowPercentage = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Progress", "Show Percentage", true, "Shows the fermentation progress as a percentage when you hover over the fermenter");
_configShowColorPercentage = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Progress", "Show Color Percentage", true, "Makes it so the percentage changes color depending on the progress");
_configAmountOfDecimals = ((BaseUnityPlugin)this).Config.Bind<int>("2 - Progress", "Amount of Decimal Places", 2, "The amount of decimal places to show");
_configShowTime = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Progress", "Show Time", false, "Show the time when done");
_configCustomFermentTime = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Time", "Custom Time", false, "Enables the custom time for fermentation");
_configNewFermentTime = ((BaseUnityPlugin)this).Config.Bind<int>("3 - Time", "Fermentation Time", 5, "The amount of minutes fermentation takes (Default 40)");
_configNoCover = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Cover", "Work Without Cover", false, "Allow the Fermenter to work without any cover");
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
}
}
private static string GetColorStringFromPercentage(double percentage)
{
if (!_configShowColorPercentage.Value)
{
return "white";
}
if (percentage >= 75.0)
{
return "green";
}
if (percentage >= 50.0)
{
return "yellow";
}
if (percentage >= 25.0)
{
return "orange";
}
return "red";
}
private static string GetValueAsColoredString(string color, double value)
{
return $"<color={color}>{value}%</color>";
}
private static string FormatMinutesAsString(double minutes)
{
int num = (int)(minutes / 60.0);
int num2 = (int)(minutes % 60.0);
int num3 = (int)((minutes - Math.Floor(minutes)) * 60.0);
if (num > 1)
{
return $"{num:D2}:{num2:D2}:{num3:D2}";
}
return $"{num2:D2}:{num3:D2}";
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Fermenter), "Awake")]
public static void FermenterAwake_Patch(Fermenter __instance)
{
if (!((Object)(object)__instance == (Object)null))
{
if (_configCustomFermentTime.Value)
{
__instance.m_fermentationDuration = _configNewFermentTime.Value * 60;
}
if (_configNoCover.Value)
{
Traverse.Create((object)__instance).Field("m_updateCoverTimer").SetValue((object)(-100f));
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Fermenter), "GetHoverText")]
public static string FermenterGetHoverText_Patch(string __result, Fermenter __instance)
{
if ((Object)(object)__instance == (Object)null)
{
return __result;
}
object value = ((object)__instance).GetType().GetNestedType("Status", BindingFlags.NonPublic).GetField("Fermenting")
.GetValue(__instance);
object value2 = Traverse.Create((object)__instance).Method("GetStatus", Array.Empty<object>()).GetValue<object>();
if (_configShowPercentage.Value && value2.Equals(value))
{
double value3 = Traverse.Create((object)__instance).Method("GetFermentationTime", Array.Empty<object>()).GetValue<double>();
double num = value3 / (double)__instance.m_fermentationDuration * 100.0;
string text = GetValueAsColoredString(GetColorStringFromPercentage(num), Math.Round(num, _configAmountOfDecimals.Value, MidpointRounding.AwayFromZero));
if (_configShowTime.Value)
{
double minutes = ((double)__instance.m_fermentationDuration - value3) / 60.0;
text = text + ", " + FormatMinutesAsString(minutes);
}
string oldValue = Localization.instance.Localize("$piece_fermenter_fermenting");
return __result.Replace(oldValue, text);
}
return __result;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "FermenterUtilities";
public const string PLUGIN_NAME = "FermenterUtilities";
public const string PLUGIN_VERSION = "1.1.0";
}
}