Decompiled source of SeisComidas v1.0.1

SeisComidas.dll

Decompiled 18 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.SeisComidas", "Seis Comidas", "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. E de cliente. 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.SeisComidas").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Seis Comidas 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 void Prefix(Hud __instance)
	{
		if (!Plugin.Ligado.Value)
		{
			return;
		}
		int instanceID = ((Object)__instance).GetInstanceID();
		if (instanceID != hudId)
		{
			hudId = instanceID;
			parou = false;
		}
		if (!parou)
		{
			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 < num && foodIcons.Length >= 2 && foodBars.Length >= 2 && foodTime.Length >= 2 && foodIcons.Length == foodBars.Length && foodIcons.Length == foodTime.Length)
			{
				Crescer(__instance, num, foodIcons, foodBars, foodTime);
			}
		}
	}

	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>();
	}
}