Decompiled source of FreeCooking v1.0.2

FreeCooking.dll

Decompiled 2 days ago
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace CozinhaLivre;

[BepInPlugin("yuri.FreeCooking", "Free Cooking", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static Plugin Inst;

	public static bool pularCusto;

	public static FieldInfo CampoReceita;

	public static FieldInfo CampoUpgrade;

	private ConfigEntry<bool> Ligado;

	private void Awake()
	{
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		Inst = this;
		Ligado = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Known food recipes craft without using ingredients. Only your own game needs this mod.");
		CampoReceita = typeof(InventoryGui).GetField("m_craftRecipe", BindingFlags.Instance | BindingFlags.NonPublic);
		CampoUpgrade = typeof(InventoryGui).GetField("m_craftUpgradeItem", BindingFlags.Instance | BindingFlags.NonPublic);
		Harmony val = new Harmony("yuri.FreeCooking");
		val.PatchAll(typeof(Plugin).Assembly);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Free Cooking 1.0.1");
	}

	public static bool Ativo()
	{
		return (Object)(object)Inst != (Object)null && Inst.Ligado.Value;
	}

	public void Avisar(string nome)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Food without ingredients: " + nome));
	}

	public static bool ComidaConhecida(Player jogador, Recipe receita)
	{
		if ((Object)(object)jogador == (Object)null || (Object)(object)receita == (Object)null || (Object)(object)receita.m_item == (Object)null)
		{
			return false;
		}
		if (receita.m_item.m_itemData == null || receita.m_item.m_itemData.m_shared == null)
		{
			return false;
		}
		SharedData shared = receita.m_item.m_itemData.m_shared;
		if (shared.m_food <= 0f && shared.m_foodStamina <= 0f && shared.m_foodEitr <= 0f)
		{
			return false;
		}
		return jogador.IsRecipeKnown(shared.m_name);
	}
}
[HarmonyPatch(typeof(Player), "HaveRequirementItems")]
public static class ItensDaComida
{
	private static bool Prefix(Player __instance, Recipe piece, bool discover, int qualityLevel, ref bool __result)
	{
		if (!Plugin.Ativo() || discover || qualityLevel > 1)
		{
			return true;
		}
		if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
		{
			return true;
		}
		if (!Plugin.ComidaConhecida(__instance, piece))
		{
			return true;
		}
		__result = true;
		return false;
	}
}
[HarmonyPatch(typeof(InventoryGui), "DoCrafting")]
public static class CraftDaComida
{
	private static void Prefix(InventoryGui __instance, Player player)
	{
		Plugin.pularCusto = false;
		if (Plugin.Ativo() && !((Object)(object)player != (Object)(object)Player.m_localPlayer) && !(Plugin.CampoUpgrade == null) && !(Plugin.CampoReceita == null) && Plugin.CampoUpgrade.GetValue(__instance) == null)
		{
			object? value = Plugin.CampoReceita.GetValue(__instance);
			Recipe val = (Recipe)((value is Recipe) ? value : null);
			if (Plugin.ComidaConhecida(player, val))
			{
				Plugin.pularCusto = true;
				Plugin.Inst.Avisar(val.m_item.m_itemData.m_shared.m_name);
			}
		}
	}

	private static void Postfix()
	{
		Plugin.pularCusto = false;
	}
}
[HarmonyPatch(typeof(Player), "ConsumeResources")]
public static class NaoGastaComida
{
	private static bool Prefix()
	{
		return !Plugin.pularCusto;
	}
}