using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
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.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CookedInfo;
[BepInPlugin("pr0skynesis.cookedinfo", "Cooked Info", "1.0.1")]
public class CookedInfoMain : BaseUnityPlugin
{
public const string pluginGuid = "pr0skynesis.cookedinfo";
public const string pluginName = "Cooked Info";
public const string pluginVersion = "1.0.1";
public static ConfigEntry<bool> configCookedInfo;
public void Awake()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
configCookedInfo = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "showCookingBar", true, "enables the Cooking loading bar when cooking food, change to false to disable it.");
Harmony val = new Harmony("pr0skynesis.cookedinfo");
MethodInfo methodInfo = AccessTools.Method(typeof(CookableFood), "UpdateMaterial", (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(CookedInfoPatches), "UpdateMaterial_Patch", (Type[])null, (Type[])null);
val.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
public class CookedInfoPatches
{
[HarmonyPrefix]
public static bool UpdateMaterial_Patch(ShipItem ___item, Renderer ___renderer, Material ___rawMaterial, Material ___cookedMaterial, Material ___blendedMaterial, Material ___burntMaterial)
{
if (___item.amount < 0.75f && !((GoPointerButton)___item).description.StartsWith("\n<color=#C"))
{
___renderer.sharedMaterial = ___rawMaterial;
if ((___item.amount != 0f || !(((GoPointerButton)___item).description == "")) && (((GoPointerButton)___item).description != "" || (((GoPointerButton)___item).description == "" && ___item.amount > 0f)))
{
((GoPointerButton)___item).description = $"\n<color=#CC7F00>Raw {((GoPointerButton)___item).description} \n<b>{Mathf.Round(___item.amount * 100f)}%</b></color>";
}
}
else if (___item.amount >= 1f && ___item.amount <= 1.5f && !((GoPointerButton)___item).description.StartsWith("\n<color=#1"))
{
___renderer.sharedMaterial = ___cookedMaterial;
((GoPointerButton)___item).description = ((GoPointerButton)___item).description.Replace("\n<color=#CC7F00>Raw ", "\n<color=#113905>Cooked ");
}
else if (___item.amount >= 1.75f)
{
___renderer.sharedMaterial = ___burntMaterial;
}
else if (___item.amount < 1f)
{
float num = Mathf.InverseLerp(0.75f, 1f, ___item.amount);
___blendedMaterial.Lerp(___rawMaterial, ___cookedMaterial, num);
___renderer.sharedMaterial = ___blendedMaterial;
}
else
{
if (___item.amount > 1.5f && !((GoPointerButton)___item).description.StartsWith("\n<color=#7"))
{
((GoPointerButton)___item).description = Regex.Replace(((GoPointerButton)___item).description, "\n<color=#CC7F00>Raw |\n<color=#113905>Cooked ", "\n<color=#7C0000>Burnt ");
}
float num2 = Mathf.InverseLerp(1.5f, 1.75f, ___item.amount);
___blendedMaterial.Lerp(___cookedMaterial, ___burntMaterial, num2);
___renderer.sharedMaterial = ___blendedMaterial;
}
if (((GoPointerButton)___item).description.StartsWith("\n"))
{
((GoPointerButton)___item).description = CookednessUpdate(((GoPointerButton)___item).description, ___item.amount) + " <size=3%>\n" + CookingBar(___item.amount, CookedInfoMain.configCookedInfo.Value) + "</size></color>";
}
return false;
}
public static string CookednessUpdate(string description, float amount)
{
int num = description.LastIndexOf("\n<b>");
if (num != -1)
{
string arg = description.Substring(0, num);
description = $"{arg}\n<b>{Mathf.Round(amount * 100f)}%</b>";
return description;
}
return "";
}
public static string CookingBar(float amount, bool configCheck)
{
int num = 300;
int num2 = (int)(amount * (float)num);
if (configCheck)
{
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 stringBuilder.ToString();
}
return "";
}
}