Decompiled source of CaixaDoF1 v1.0.0

CaixaDoF1.dll

Decompiled 16 hours ago
using System;
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 CaixaDoF1;

[BepInPlugin("yuri.CaixaDoF1", "Caixa do F1", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static ConfigEntry<int> Largura;

	public static ConfigEntry<int> Altura;

	private void Awake()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Expected O, but got Unknown
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Expected O, but got Unknown
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Expected O, but got Unknown
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Expected O, but got Unknown
		Largura = ((BaseUnityPlugin)this).Config.Bind<int>("Geral", "Largura", 900, new ConfigDescription("Largura da janela do F1, no eixo X.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(480, 1600), new object[0]));
		Altura = ((BaseUnityPlugin)this).Config.Bind<int>("Geral", "Altura", 900, new ConfigDescription("Altura da janela do F1, no eixo Y.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(360, 1400), new object[0]));
		Type type = AccessTools.TypeByName("ConfigurationManager.ConfigurationManager");
		if (!(type == null))
		{
			Harmony val = new Harmony("yuri.CaixaDoF1");
			val.Patch((MethodBase)AccessTools.Method(type, "CalculateWindowRect", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Ajuste), "DepoisDoCalculo", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.Method(type, "OnGUI", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Ajuste), "DepoisDoDesenho", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.Method(type, "SettingsWindow", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Ajuste), "AntesDaJanela", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}
}
public static class Ajuste
{
	public static void DepoisDoCalculo(object __instance)
	{
		Aplicar(__instance, recentrar: true);
	}

	public static void DepoisDoDesenho(object __instance)
	{
		if (Aberto(__instance))
		{
			Aplicar(__instance, recentrar: false);
		}
	}

	public static void AntesDaJanela()
	{
		if (Plugin.Largura != null && Plugin.Altura != null)
		{
			GUILayout.Label("Tamanho desta janela", (GUILayoutOption[])(object)new GUILayoutOption[0]);
			int num = Barra("Largura", Plugin.Largura.Value, 480, 1600);
			int num2 = Barra("Altura", Plugin.Altura.Value, 360, 1400);
			if (num != Plugin.Largura.Value)
			{
				Plugin.Largura.Value = num;
			}
			if (num2 != Plugin.Altura.Value)
			{
				Plugin.Altura.Value = num2;
			}
		}
	}

	private static int Barra(string nome, int atual, int minimo, int maximo)
	{
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(nome, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
		int result = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)atual, (float)minimo, (float)maximo, (GUILayoutOption[])(object)new GUILayoutOption[0]));
		GUILayout.Label(result.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(48f) });
		GUILayout.EndHorizontal();
		return result;
	}

	private static bool Aberto(object alvo)
	{
		PropertyInfo property = alvo.GetType().GetProperty("DisplayingWindow");
		if (property == null)
		{
			return false;
		}
		return (bool)property.GetValue(alvo, null);
	}

	private static void Aplicar(object alvo, bool recentrar)
	{
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.Largura == null || Plugin.Altura == null)
		{
			return;
		}
		PropertyInfo property = alvo.GetType().GetProperty("SettingWindowRect");
		if (property == null)
		{
			return;
		}
		float num = Plugin.Largura.Value;
		float num2 = Plugin.Altura.Value;
		float num3 = (float)Screen.width - 40f;
		float num4 = (float)Screen.height - 40f;
		if (num3 < 480f)
		{
			num3 = 480f;
		}
		if (num4 < 360f)
		{
			num4 = 360f;
		}
		if (num < 480f)
		{
			num = 480f;
		}
		if (num2 < 360f)
		{
			num2 = 360f;
		}
		if (num > num3)
		{
			num = num3;
		}
		if (num2 > num4)
		{
			num2 = num4;
		}
		Rect val = (Rect)property.GetValue(alvo, null);
		if (recentrar || !(Mathf.Abs(((Rect)(ref val)).width - num) < 0.5f) || !(Mathf.Abs(((Rect)(ref val)).height - num2) < 0.5f))
		{
			if (recentrar)
			{
				((Rect)(ref val)).x = ((float)Screen.width - num) / 2f;
				((Rect)(ref val)).y = ((float)Screen.height - num2) / 2f;
			}
			((Rect)(ref val)).width = num;
			((Rect)(ref val)).height = num2;
			if (((Rect)(ref val)).x < 0f)
			{
				((Rect)(ref val)).x = 0f;
			}
			if (((Rect)(ref val)).y < 0f)
			{
				((Rect)(ref val)).y = 0f;
			}
			if (((Rect)(ref val)).xMax > (float)Screen.width)
			{
				((Rect)(ref val)).x = (float)Screen.width - ((Rect)(ref val)).width;
			}
			if (((Rect)(ref val)).yMax > (float)Screen.height)
			{
				((Rect)(ref val)).y = (float)Screen.height - ((Rect)(ref val)).height;
			}
			property.SetValue(alvo, val, null);
			int num5 = Mathf.RoundToInt(num / 2.5f);
			int num6 = Mathf.RoundToInt(num) - num5 - 115;
			if (num6 < 80)
			{
				num6 = 80;
			}
			Definir(alvo, "LeftColumnWidth", num5);
			Definir(alvo, "RightColumnWidth", num6);
		}
	}

	private static void Definir(object alvo, string nome, int valor)
	{
		PropertyInfo property = alvo.GetType().GetProperty(nome);
		if (property != null)
		{
			property.SetValue(alvo, valor, null);
		}
	}
}