using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CookedInfo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CookedInfo")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dd8fbe8a-de2b-4d9a-917e-e86b43c6cf06")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.2.0.0")]
namespace CookedInfo;
[BepInPlugin("pr0skynesis.cookedinfo", "Cooked Info", "1.2.0")]
public class Plugin : BaseUnityPlugin
{
public const string PLUGIN_GUID = "pr0skynesis.cookedinfo";
public const string PLUGIN_NAME = "Cooked Info";
public const string PLUGIN_VERSION = "1.2.0";
internal static Plugin instance;
internal static ManualLogSource logger;
internal static ConfigEntry<bool> configColoredText;
internal static ConfigEntry<bool> configCookingPercent;
internal static ConfigEntry<bool> configCookingBar;
internal static ConfigEntry<bool> configFreshnessBar;
private void Awake()
{
instance = this;
logger = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "pr0skynesis.cookedinfo");
configColoredText = ((BaseUnityPlugin)this).Config.Bind<bool>("Colored Text", "showColoredText", true, "Enables the colored text for raw, cooked, and overcooked food, change to false to disable it.");
configCookingPercent = ((BaseUnityPlugin)this).Config.Bind<bool>("Cooking Percentage", "showCookingPercent", true, "Enables the cooking percentage when cooking or drying food, change to false to disable it.");
configCookingBar = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading Bar", "showCookingBar", true, "Enables the cooking loading bar when cooking or drying food, change to false to disable it.");
configFreshnessBar = ((BaseUnityPlugin)this).Config.Bind<bool>("Freshness Bar", "showFreshnessBar", true, "Enables the freshness loading bar, change to false to disable it.");
}
}
internal class Patches
{
[HarmonyPatch(typeof(FoodState))]
public class FoodStatePatches
{
private static readonly string red = "#4D0000";
private static readonly string green = "#003300";
private static readonly string yellow = "#CC7F00";
private static readonly string light_blue = "#2861fc";
private static readonly string med_blue = "#1C3270";
private static readonly string dark_blue = "#071336";
[HarmonyPostfix]
[HarmonyPatch("UpdateLookText")]
public static void UpdateLookText_Patch(ShipItemFood ___food, CookableFood ___cookable, float ___dried, DryingRackCol ___dryingCol, float ___spoiled)
{
if (Object.op_Implicit((Object)(object)___cookable.GetCurrentCookTrigger()))
{
if (((ShipItem)___food).amount > 0f && ((ShipItem)___food).amount < 1f)
{
((GoPointerButton)___food).description = BuildDescription(yellow, ((GoPointerButton)___food).description, ((ShipItem)___food).amount) ?? "";
}
if (((ShipItem)___food).amount >= 1f && ((ShipItem)___food).amount < 1.25f)
{
((GoPointerButton)___food).description = BuildDescription(green, ((GoPointerButton)___food).description, ((ShipItem)___food).amount) ?? "";
}
if (((ShipItem)___food).amount >= 1.25f)
{
((GoPointerButton)___food).description = BuildDescription(red, "overcooked " + ((GoPointerButton)___food).description.Replace("cooked ", ""), ((ShipItem)___food).amount) ?? "";
}
}
if (Object.op_Implicit((Object)(object)___dryingCol))
{
if (___dried > 0f && ___dried < 0.99f)
{
((GoPointerButton)___food).description = BuildDescription(yellow, ((GoPointerButton)___food).description, ___dried) ?? "";
}
if (___dried >= 0.99f)
{
((GoPointerButton)___food).description = BuildDescription(green, ((GoPointerButton)___food).description, ___dried) ?? "";
}
}
if (Plugin.configFreshnessBar.Value)
{
if (___spoiled < 0.3f)
{
((GoPointerButton)___food).description = FreshnessBar(light_blue, ___food, ___spoiled) ?? "";
}
if (___spoiled >= 0.3f && ___spoiled < 0.6f)
{
((GoPointerButton)___food).description = FreshnessBar(med_blue, ___food, ___spoiled) ?? "";
}
if (___spoiled >= 0.6f && ___spoiled < 0.9f)
{
((GoPointerButton)___food).description = FreshnessBar(dark_blue, ___food, ___spoiled) ?? "";
}
}
}
private static string BuildDescription(string color, string desc, float amount)
{
if (!Plugin.configColoredText.Value)
{
return desc + CookedPercent(amount) + CookingBar(amount);
}
return desc + "<color=" + color + ">" + CookedPercent(amount) + CookingBar(amount) + "</color>";
}
private static string CookedPercent(float amount)
{
if (!Plugin.configCookingPercent.Value)
{
return "";
}
return $"\n<b>{Mathf.RoundToInt(amount * 100f)}%</b>";
}
private static string CookingBar(float amount)
{
if (!Plugin.configCookingBar.Value)
{
return "";
}
return ProgressBar(amount) ?? "";
}
private static string FreshnessBar(string color, ShipItemFood food, float amount)
{
if (!Plugin.configColoredText.Value)
{
return ((GoPointerButton)food).description + ProgressBar(0.9f - amount);
}
return ((GoPointerButton)food).description + "<color=" + color + ">" + ProgressBar(0.9f - amount) + "</color>";
}
private static string ProgressBar(float amount)
{
int num = 300;
int num2 = (int)(amount * (float)num);
if (num2 <= 0 || num2 >= num)
{
return "";
}
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < num; i++)
{
if (i < num2)
{
stringBuilder.Append("█");
}
else
{
stringBuilder.Append("░");
}
}
return $"\n<size=3%>{stringBuilder}</size>";
}
}
}