Decompiled source of Fartura v1.0.1

Fartura.dll

Decompiled 16 hours ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

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

[BepInPlugin("yuri.Fartura", "Fartura", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	public static ConfigEntry<bool> Ligado;

	public static ConfigEntry<int> Comidas;

	private void Awake()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		Ligado = ((BaseUnityPlugin)this).Config.Bind<bool>("Geral", "Ligado", true, "Ate seis comidas diferentes ao mesmo tempo. A mesma comida continua uma vez. So no seu jogo.");
		Comidas = ((BaseUnityPlugin)this).Config.Bind<int>("Geral", "Comidas", 6, new ConfigDescription("Quantas comidas diferentes ao mesmo tempo.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(3, 8), new object[0]));
		new Harmony("yuri.Fartura").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Fartura 1.0.1");
	}

	public static int Limite()
	{
		if (Ligado == null || !Ligado.Value)
		{
			return 3;
		}
		int value = Comidas.Value;
		if (value < 3)
		{
			return 3;
		}
		if (value > 8)
		{
			return 8;
		}
		return value;
	}
}
public static class TrocaTres
{
	public static IEnumerable<CodeInstruction> Troca(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo metodo = AccessTools.Method(typeof(Plugin), "Limite", (Type[])null, (Type[])null);
		foreach (CodeInstruction ins in instructions)
		{
			if (ins.opcode != OpCodes.Ldc_I4_3)
			{
				yield return ins;
				continue;
			}
			CodeInstruction novo = new CodeInstruction(OpCodes.Call, (object)metodo);
			novo.labels.AddRange(ins.labels);
			novo.blocks.AddRange(ins.blocks);
			yield return novo;
		}
	}
}
[HarmonyPatch(typeof(Player), "CanEat")]
public static class PodeComer
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		return TrocaTres.Troca(instructions);
	}
}
[HarmonyPatch(typeof(Player), "EatFood")]
public static class Come
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		return TrocaTres.Troca(instructions);
	}
}
[HarmonyPatch(typeof(Hud), "UpdateFood")]
public static class Mostra
{
	private static int hudId;

	private static bool parou;

	private static bool guardou;

	private static bool temRaiz;

	private static Vector2[] baseIcone;

	private static Vector2[] baseBarra;

	private static Vector2[] baseTempo;

	private static Vector2[] baseRaiz;

	private static Vector2 passoI;

	private static Vector2 passoB;

	private static Vector2 passoT;

	private static Vector2 passoRaiz;

	private static void Prefix(Hud __instance)
	{
		if (!Plugin.Ligado.Value)
		{
			return;
		}
		int instanceID = ((Object)__instance).GetInstanceID();
		if (instanceID != hudId)
		{
			hudId = instanceID;
			parou = false;
			guardou = false;
		}
		int num = Plugin.Limite();
		Image[] foodIcons = __instance.m_foodIcons;
		Image[] foodBars = __instance.m_foodBars;
		TMP_Text[] foodTime = __instance.m_foodTime;
		if (foodIcons != null && foodBars != null && foodTime != null && foodIcons.Length >= 2 && foodBars.Length >= 2 && foodTime.Length >= 2 && foodIcons.Length == foodBars.Length && foodIcons.Length == foodTime.Length)
		{
			Guardar(foodIcons, foodBars, foodTime);
			if (!parou && foodIcons.Length < num)
			{
				Crescer(__instance, num, foodIcons, foodBars, foodTime);
			}
			Posicionar(__instance.m_foodIcons, __instance.m_foodBars, __instance.m_foodTime);
		}
	}

	private static void Guardar(Image[] icones, Image[] barras, TMP_Text[] tempos)
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_024a: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		if (guardou)
		{
			return;
		}
		int num = icones.Length;
		baseIcone = (Vector2[])(object)new Vector2[num];
		baseBarra = (Vector2[])(object)new Vector2[num];
		baseTempo = (Vector2[])(object)new Vector2[num];
		baseRaiz = (Vector2[])(object)new Vector2[num];
		temRaiz = true;
		for (int i = 0; i < num; i++)
		{
			ref Vector2 reference = ref baseIcone[i];
			reference = ((Graphic)icones[i]).rectTransform.anchoredPosition;
			ref Vector2 reference2 = ref baseBarra[i];
			reference2 = ((Graphic)barras[i]).rectTransform.anchoredPosition;
			ref Vector2 reference3 = ref baseTempo[i];
			reference3 = tempos[i].rectTransform.anchoredPosition;
			Transform transform = ((Component)icones[(i == 0) ? 1u : 0u]).transform;
			Transform val = Raiz(((Component)icones[i]).transform, ((Component)barras[i]).transform, tempos[i].transform, transform);
			RectTransform val2 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<RectTransform>());
			if ((Object)(object)val2 == (Object)null)
			{
				temRaiz = false;
				continue;
			}
			ref Vector2 reference4 = ref baseRaiz[i];
			reference4 = val2.anchoredPosition;
		}
		Rect rect = ((Graphic)icones[0]).rectTransform.rect;
		float height = ((Rect)(ref rect)).height;
		rect = ((Graphic)barras[0]).rectTransform.rect;
		float height2 = ((Rect)(ref rect)).height;
		rect = tempos[0].rectTransform.rect;
		float height3 = ((Rect)(ref rect)).height;
		passoI = Passo(baseIcone[0], baseIcone[1], height);
		passoB = Passo(baseBarra[0], baseBarra[1], height2);
		passoT = Passo(baseTempo[0], baseTempo[1], height3);
		if (temRaiz)
		{
			float num2 = height;
			if (num2 < 16f)
			{
				num2 = 64f;
			}
			passoRaiz = Passo(baseRaiz[0], baseRaiz[1], num2);
		}
		guardou = true;
	}

	private static Vector2 Passo(Vector2 a, Vector2 b, float alto)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		Vector2 result = b - a;
		if (alto < 16f)
		{
			alto = 64f;
		}
		float num = alto + 8f;
		if (((Vector2)(ref result)).magnitude >= num * 0.85f)
		{
			return result;
		}
		if (result.y > 0.5f)
		{
			return new Vector2(0f, num);
		}
		if (result.y < -0.5f)
		{
			return new Vector2(0f, 0f - num);
		}
		if (result.x > 0.5f)
		{
			return new Vector2(num, 0f);
		}
		if (result.x < -0.5f)
		{
			return new Vector2(0f - num, 0f);
		}
		return new Vector2(0f, 0f - num);
	}

	private static Vector2 Onde(int i, Vector2[] bases, Vector2 passo)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		if (i < bases.Length)
		{
			return bases[i];
		}
		int num = bases.Length - 1;
		return bases[num] + passo * (float)(i - num);
	}

	private static void Soltar(Transform t)
	{
		if (!((Object)(object)t == (Object)null))
		{
			LayoutGroup component = ((Component)t).GetComponent<LayoutGroup>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			ContentSizeFitter component2 = ((Component)t).GetComponent<ContentSizeFitter>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Behaviour)component2).enabled = false;
			}
		}
	}

	private static void Posicionar(Image[] icones, Image[] barras, TMP_Text[] tempos)
	{
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		if (!guardou || icones == null || barras == null || tempos == null || icones.Length == 0 || icones.Length != barras.Length || icones.Length != tempos.Length)
		{
			return;
		}
		Soltar(((Component)icones[0]).transform.parent);
		Soltar(((Component)barras[0]).transform.parent);
		Soltar(tempos[0].transform.parent);
		for (int i = 0; i < icones.Length; i++)
		{
			Transform transform = ((Component)icones[(i == 0) ? Mathf.Min(1, icones.Length - 1) : 0]).transform;
			Transform val = Raiz(((Component)icones[i]).transform, ((Component)barras[i]).transform, tempos[i].transform, transform);
			RectTransform val2 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<RectTransform>());
			if (temRaiz && (Object)(object)val2 != (Object)null)
			{
				val2.anchoredPosition = Onde(i, baseRaiz, passoRaiz);
				continue;
			}
			((Graphic)icones[i]).rectTransform.anchoredPosition = Onde(i, baseIcone, passoI);
			((Graphic)barras[i]).rectTransform.anchoredPosition = Onde(i, baseBarra, passoB);
			tempos[i].rectTransform.anchoredPosition = Onde(i, baseTempo, passoT);
		}
	}

	private static void Crescer(Hud hud, int quer, Image[] icones, Image[] barras, TMP_Text[] tempos)
	{
		List<Image> list = new List<Image>(icones);
		List<Image> list2 = new List<Image>(barras);
		List<TMP_Text> list3 = new List<TMP_Text>(tempos);
		int num = icones.Length;
		Transform val = Raiz(((Component)icones[num - 2]).transform, ((Component)barras[num - 2]).transform, tempos[num - 2].transform, ((Component)icones[num - 1]).transform);
		Transform val2 = Raiz(((Component)icones[num - 1]).transform, ((Component)barras[num - 1]).transform, tempos[num - 1].transform, ((Component)icones[num - 2]).transform);
		if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null && (Object)(object)val != (Object)(object)val2)
		{
			CrescerJunto(quer, list, list2, list3, icones[num - 1], barras[num - 1], tempos[num - 1], val, val2);
		}
		else
		{
			CrescerSolto(quer, list, list2, list3, icones, barras, tempos);
		}
		hud.m_foodIcons = list.ToArray();
		hud.m_foodBars = list2.ToArray();
		hud.m_foodTime = list3.ToArray();
	}

	private static void CrescerJunto(int quer, List<Image> novosIcones, List<Image> novasBarras, List<TMP_Text> novosTempos, Image iconeBase, Image barraBase, TMP_Text tempoBase, Transform raizA, Transform raizB)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		string caminho = Caminho(raizB, ((Component)iconeBase).transform);
		string caminho2 = Caminho(raizB, ((Component)barraBase).transform);
		string caminho3 = Caminho(raizB, tempoBase.transform);
		Vector3 val = raizB.localPosition - raizA.localPosition;
		if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
		{
			((Vector3)(ref val))..ctor(0f, -36f, 0f);
		}
		int count = novosIcones.Count;
		for (int i = count; i < quer; i++)
		{
			GameObject val2 = Object.Instantiate<GameObject>(((Component)raizB).gameObject, raizB.parent);
			((Object)val2).name = "seiscomida_" + i;
			val2.transform.localPosition = raizB.localPosition + val * (float)(i - (count - 1));
			val2.transform.localRotation = raizB.localRotation;
			val2.transform.localScale = raizB.localScale;
			Image val3 = Imagem(val2.transform, caminho);
			Image val4 = Imagem(val2.transform, caminho2);
			TMP_Text val5 = Texto(val2.transform, caminho3);
			if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null)
			{
				Object.Destroy((Object)(object)val2);
				parou = true;
				break;
			}
			novosIcones.Add(val3);
			novasBarras.Add(val4);
			novosTempos.Add(val5);
		}
	}

	private static void CrescerSolto(int quer, List<Image> novosIcones, List<Image> novasBarras, List<TMP_Text> novosTempos, Image[] icones, Image[] barras, TMP_Text[] tempos)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		int num = icones.Length - 1;
		Vector3 val = ((Transform)((Graphic)icones[num]).rectTransform).localPosition - ((Transform)((Graphic)icones[num - 1]).rectTransform).localPosition;
		Vector3 val2 = ((Transform)((Graphic)barras[num]).rectTransform).localPosition - ((Transform)((Graphic)barras[num - 1]).rectTransform).localPosition;
		Vector3 val3 = ((Transform)tempos[num].rectTransform).localPosition - ((Transform)tempos[num - 1].rectTransform).localPosition;
		if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
		{
			((Vector3)(ref val))..ctor(0f, -36f, 0f);
		}
		if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
		{
			val2 = val;
		}
		if (((Vector3)(ref val3)).sqrMagnitude < 0.01f)
		{
			val3 = val;
		}
		int count = novosIcones.Count;
		for (int i = count; i < quer; i++)
		{
			int num2 = i - num;
			Image val4 = Object.Instantiate<Image>(icones[num], ((Component)icones[num]).transform.parent);
			Image val5 = Object.Instantiate<Image>(barras[num], ((Component)barras[num]).transform.parent);
			TMP_Text val6 = Object.Instantiate<TMP_Text>(tempos[num], tempos[num].transform.parent);
			((Object)val4).name = "seisicone_" + i;
			((Object)val5).name = "seisbarra_" + i;
			((Object)val6).name = "seistempo_" + i;
			((Transform)((Graphic)val4).rectTransform).localPosition = ((Transform)((Graphic)icones[num]).rectTransform).localPosition + val * (float)num2;
			((Transform)((Graphic)val5).rectTransform).localPosition = ((Transform)((Graphic)barras[num]).rectTransform).localPosition + val2 * (float)num2;
			((Transform)val6.rectTransform).localPosition = ((Transform)tempos[num].rectTransform).localPosition + val3 * (float)num2;
			novosIcones.Add(val4);
			novasBarras.Add(val5);
			novosTempos.Add(val6);
		}
	}

	private static Transform Raiz(Transform icone, Transform barra, Transform tempo, Transform outro)
	{
		Transform val = icone;
		while ((Object)(object)val != (Object)null)
		{
			if (Debaixo(barra, val) && Debaixo(tempo, val) && !Debaixo(outro, val))
			{
				return val;
			}
			val = val.parent;
		}
		return null;
	}

	private static bool Debaixo(Transform filho, Transform pai)
	{
		while ((Object)(object)filho != (Object)null)
		{
			if ((Object)(object)filho == (Object)(object)pai)
			{
				return true;
			}
			filho = filho.parent;
		}
		return false;
	}

	private static string Caminho(Transform raiz, Transform alvo)
	{
		if ((Object)(object)alvo == (Object)(object)raiz)
		{
			return "";
		}
		string text = ((Object)alvo).name;
		Transform parent = alvo.parent;
		while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)raiz)
		{
			text = ((Object)parent).name + "/" + text;
			parent = parent.parent;
		}
		return text;
	}

	private static Transform Achar(Transform raiz, string caminho)
	{
		if (caminho == null || caminho.Length == 0)
		{
			return raiz;
		}
		return raiz.Find(caminho);
	}

	private static Image Imagem(Transform raiz, string caminho)
	{
		Transform val = Achar(raiz, caminho);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		return ((Component)val).GetComponent<Image>();
	}

	private static TMP_Text Texto(Transform raiz, string caminho)
	{
		Transform val = Achar(raiz, caminho);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		return ((Component)val).GetComponent<TMP_Text>();
	}
}