Decompiled source of CookedInfo v1.1.0

CookedInfo.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
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.4")]
public class CookedInfoMain : BaseUnityPlugin
{
	public const string pluginGuid = "pr0skynesis.cookedinfo";

	public const string pluginName = "Cooked Info";

	public const string pluginVersion = "1.0.4";

	public static ConfigEntry<bool> configColoredText;

	public static ConfigEntry<bool> configCookingPercent;

	public static ConfigEntry<bool> configCookingBar;

	public static ConfigEntry<bool> configNameAllFood;

	public void Awake()
	{
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		configColoredText = ((BaseUnityPlugin)this).Config.Bind<bool>("Colored Text", "showColoredText", true, "Enables the colored text for raw, cooked and burnt food, change to false to disable it.");
		configCookingPercent = ((BaseUnityPlugin)this).Config.Bind<bool>("Cooking Percentage", "showCookingPercent", true, "Enables the cooking percentage when cooking food, change to false to disable it.");
		configCookingBar = ((BaseUnityPlugin)this).Config.Bind<bool>("Loading Bar", "showCookingBar", true, "Enables the cooking loading bar when cooking food, change to false to disable it.");
		configNameAllFood = ((BaseUnityPlugin)this).Config.Bind<bool>("Name All Food", "nameAllFood", true, "Display names for all foods items, like bread, and applies the cookedinfo to them as well.");
		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
{
	private static readonly string red = "#4D0000";

	private static readonly string green = "#003300";

	private static readonly string yellow = "#CC7F00";

	private static readonly string[] noNameFoods = new string[14]
	{
		"sausage", "dates", "bread", "banana", "bun", "crab cake", "cheese", "goat cheese", "lamb", "rice cake",
		"forest mushroom", "field mushroom", "cave mushroom", "orange"
	};

	[HarmonyPostfix]
	public static void UpdateMaterial_Patch(ShipItem ___item)
	{
		if (noNameFoods.Contains(___item.name) && ___item.amount == 0f && CookedInfoMain.configNameAllFood.Value)
		{
			((GoPointerButton)___item).description = ___item.name;
		}
		if (CookedInfoMain.configColoredText.Value && ((GoPointerButton)___item).description != "")
		{
			if (___item.amount == 0f && !noNameFoods.Contains(___item.name))
			{
				((GoPointerButton)___item).description = "\n<color=" + yellow + ">" + BuildDescription(___item) + "</color>";
			}
			if (___item.amount > 0f && ___item.amount < 1f)
			{
				((GoPointerButton)___item).description = "\n<color=" + yellow + ">" + BuildDescription(___item) + "</color>";
			}
			if (___item.amount >= 1f && ___item.amount < 1.5f)
			{
				((GoPointerButton)___item).description = "\n<color=" + green + ">" + BuildDescription(___item) + "</color>";
			}
			if (___item.amount > 1.5f)
			{
				((GoPointerButton)___item).description = "\n<color=" + red + ">" + BuildDescription(___item) + "</color>";
			}
		}
		else if (!CookedInfoMain.configColoredText.Value && ((GoPointerButton)___item).description != "")
		{
			((GoPointerButton)___item).description = "\n" + BuildDescription(___item);
		}
	}

	public static bool DebugDescription(ShipItem item)
	{
		if (((GoPointerButton)item).description != null && ((GoPointerButton)item).description != "")
		{
			return true;
		}
		return false;
	}

	private static string BuildDescription(ShipItem food)
	{
		return CookedStatus(food) + CookedPercent(food.amount) + CookingBar(food.amount);
	}

	private static string CookedStatus(ShipItem food)
	{
		if (food.amount <= 0f)
		{
			return "Raw " + food.name;
		}
		if (food.amount > 0f && food.amount < 1f)
		{
			return "Undercooked " + food.name;
		}
		if (food.amount >= 1f && food.amount < 1.5f)
		{
			return "Cooked " + food.name;
		}
		if (food.amount >= 1.5f && food.amount < 1.75f)
		{
			return "Overcooked " + food.name;
		}
		return "Burnt " + food.name;
	}

	private static string CookedPercent(float amount)
	{
		if (!CookedInfoMain.configCookingPercent.Value)
		{
			return "";
		}
		int num = Mathf.RoundToInt(amount * 100f);
		return $"\n<b>{num}%</b>";
	}

	private static string CookingBar(float amount)
	{
		if (!CookedInfoMain.configCookingBar.Value)
		{
			return "";
		}
		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>";
	}
}