Decompiled source of AtomicropsOnline v0.8.0

AtomicropsOnline.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Atomicrops.Assets.Bosses.WinterBoss;
using Atomicrops.Bt.ArtTasks;
using Atomicrops.Core;
using Atomicrops.Core.Agent2;
using Atomicrops.Core.Art;
using Atomicrops.Core.Art.AnimClipInterfaces;
using Atomicrops.Core.CameraSystem;
using Atomicrops.Core.DamageSystem;
using Atomicrops.Core.GunSystem;
using Atomicrops.Core.InGameSelectable;
using Atomicrops.Core.InGameWidget;
using Atomicrops.Core.Loot;
using Atomicrops.Core.ModelViewAgent2;
using Atomicrops.Core.Models;
using Atomicrops.Core.SoDb2;
using Atomicrops.Core.Upgrades;
using Atomicrops.Core.ViewUtils;
using Atomicrops.Crops;
using Atomicrops.Game.Agents;
using Atomicrops.Game.Crops;
using Atomicrops.Game.Data;
using Atomicrops.Game.EnemySystem;
using Atomicrops.Game.FertilizerSystem;
using Atomicrops.Game.GameState;
using Atomicrops.Game.Loot;
using Atomicrops.Game.Models;
using Atomicrops.Game.Mvw4;
using Atomicrops.Game.NightWaves2;
using Atomicrops.Game.ParamsSystem;
using Atomicrops.Game.Player;
using Atomicrops.Game.Player.PlayerGun;
using Atomicrops.Game.Scenes.Farm;
using Atomicrops.Game.Scenes.Farm.Devices;
using Atomicrops.Game.SellableSystem;
using Atomicrops.Game.ShopSystem;
using Atomicrops.Game.Upgrades;
using Atomicrops.Global;
using Atomicrops.Rendering;
using Atomicrops.Scripts.Art.Player;
using Atomicrops.Scripts.Core.Ufmod;
using AtomicropsOnline.Coop;
using AtomicropsOnline.Net;
using AtomicropsOnline.Sync;
using AtomicropsOnline.Ui;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FurySmarterLocalization;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MonsterLove.StateMachine;
using SharedLib;
using Steamworks;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("AtomicropsOnline")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AtomicropsOnline")]
[assembly: AssemblyTitle("AtomicropsOnline")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AtomicropsOnline
{
	[BepInPlugin("romas.atomicrops.online", "Atomicrops Online", "0.8.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "romas.atomicrops.online";

		public const string PluginName = "Atomicrops Online";

		public const string PluginVersion = "0.8.0";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static NetSession Session;

		internal static PlayerSync Players;

		internal static RunSync Run;

		internal static TimeSync Clock;

		internal static AgentSync Agents;

		internal static FarmSync Farm;

		internal static ResourceSync Shared;

		internal static CombatSync Combat;

		internal static WorldFxSync WorldFx;

		internal static LootSync Loot;

		internal static EnemyAnimSync EnemyAnims;

		internal static FxSync Effects;

		internal static MapSync Map;

		internal static WorldCheck Check;

		internal static FriendSync Friends;

		internal static BossSync Bosses;

		internal static TallySync Tally;

		internal static WorldUpgradeSync Upgrades;

		internal ConfigEntry<KeyboardShortcut> ToggleOverlayKey;

		internal ConfigEntry<KeyboardShortcut> DumpKey;

		internal ConfigEntry<int> DirectPort;

		internal ConfigEntry<string> JoinAddress;

		private string _joinAddressField;

		private Harmony _harmony;

		private bool _showOverlay = true;

		private ulong _pendingLobbyFromCmdLine;

		private int _patchFailures;

		private static string _toast = "";

		private static float _toastUntil;

		private static readonly HashSet<string> _loggedOnce = new HashSet<string>();

		private static readonly FieldRef<PlayerGunInputs, Vector2> AimDirRef = AccessTools.FieldRefAccess<PlayerGunInputs, Vector2>("_aimDir");

		private static readonly FieldRef<PlayerComp, bool> IsBlinkingRef = AccessTools.FieldRefAccess<PlayerComp, bool>("_isBlinking");

		private static readonly FieldRef<PlayerGridWorkController, IPlayerGridWorkItem> CurrentWorkItemRef = AccessTools.FieldRefAccess<PlayerGridWorkController, IPlayerGridWorkItem>("_currentWorkItem");

		private static readonly FieldRef<AutoWaterer, WaterStreamEndAttachment> WaterTargetRef = AccessTools.FieldRefAccess<AutoWaterer, WaterStreamEndAttachment>("_currentWaterTarget");

		private bool _autoHostDirect;

		private bool _autoHostLoopback;

		private string _autoJoinDirect;

		private bool _autoStartRun;

		private float _autoStartAt = -1f;

		private bool _godMode;

		private bool _autoNextDay;

		private float _townSince = -1f;

		private bool _testLoot;

		private bool _testMap;

		private float _testMapAt = -1f;

		private bool _testShop;

		private bool _testInteract;

		private float _testInteractAt = -1f;

		private bool _testFar;

		private bool _testForage;

		private bool _testBuy;

		private bool _testShoot;

		private string _testGun;

		private string _testChar;

		private bool _testEffects;

		private bool _testMinimap;

		private bool _testHarvest;

		private float _testHarvestAt = -1f;

		private bool _testPowerSow;

		private float _testPowerSowAt = -1f;

		private readonly List<Int2> _testPowerSowCoords = new List<Int2>();

		private bool _testBoss;

		private string _testBossName;

		private float _testBossAt = -1f;

		private int _testBossStep;

		private float _testMinimapAt = -1f;

		private float _testEffectsAt = -1f;

		private int _testEffectsStep;

		private static readonly FieldRef<PlayerGridWorkController, float> EnergizedRef = AccessTools.FieldRefAccess<PlayerGridWorkController, float>("_energizedDuration");

		private float _testCharAt = -1f;

		private bool _testAbility;

		private float _testAbilityAt = -1f;

		private int _testAbilityStep;

		private RunToTill _testRunToTill;

		private readonly List<Int2> _testAbilityCoords = new List<Int2>();

		private bool _listChars;

		private float _testShootAt = -1f;

		private int _testShots;

		private float _testBuyAt = -1f;

		private float _testForageAt = -1f;

		private float _testFarAt = -1f;

		private float _testShopAt = -1f;

		private float _nextTestLoot;

		private bool? _originalRunInBackground;

		internal static Harmony HarmonyInstance
		{
			get
			{
				if (!((Object)(object)Instance != (Object)null))
				{
					return null;
				}
				return Instance._harmony;
			}
		}

		private void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			ToggleOverlayKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleOverlay", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Tecla para mostrar/esconder o painel do mod.");
			DumpKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Debug", "DumpPlayer", new KeyboardShortcut((KeyCode)290, Array.Empty<KeyCode>()), "Escreve a hierarquia do jogador no log (depuração).");
			DirectPort = ((BaseUnityPlugin)this).Config.Bind<int>("Direct", "Port", 27777, "Porta TCP para jogar por IP direto (LAN, ZeroTier/Hamachi ou duas janelas no mesmo PC).");
			JoinAddress = ((BaseUnityPlugin)this).Config.Bind<string>("Direct", "LastAddress", "127.0.0.1", "Último endereço usado em 'Entrar por IP' (aceita ip ou ip:porta).");
			_joinAddressField = JoinAddress.Value;
			Balance.Bind(((BaseUnityPlugin)this).Config);
			ApplyPatches();
			string[] commandLineArgs = Environment.GetCommandLineArgs();
			for (int i = 0; i < commandLineArgs.Length - 1; i++)
			{
				if (commandLineArgs[i] == "+connect_lobby" && ulong.TryParse(commandLineArgs[i + 1], out var result))
				{
					_pendingLobbyFromCmdLine = result;
				}
			}
			ReadTestArgs(commandLineArgs);
			Log.LogInfo((object)"Atomicrops Online v0.8.0 carregado. Pressione F8 para o painel.");
		}

		private void ApplyPatches()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_harmony = new Harmony("romas.atomicrops.online");
			int num = 0;
			Type[] types = typeof(Plugin).Assembly.GetTypes();
			foreach (Type type in types)
			{
				if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0)
				{
					try
					{
						_harmony.CreateClassProcessor(type).Patch();
						num++;
					}
					catch (Exception ex)
					{
						_patchFailures++;
						Log.LogError((object)("[Harmony] Patch " + type.Name + " falhou: " + ex.GetBaseException().Message));
					}
				}
			}
			Log.LogInfo((object)$"[Harmony] {num} patches aplicados, {_patchFailures} falharam.");
		}

		private void ReadTestArgs(string[] args)
		{
			for (int i = 0; i < args.Length; i++)
			{
				string text = args[i];
				string text2 = ((i + 1 < args.Length) ? args[i + 1] : null);
				if (text == "--coop-user" && int.TryParse(text2, out var result))
				{
					SingletonScriptableObject<ConfigGame>.I.UserIdx = result;
					Log.LogInfo((object)$"[Teste] Usando perfil/save do usuário {result}.");
					continue;
				}
				if (text == "--coop-host-ip")
				{
					_autoHostDirect = true;
					_autoHostLoopback = text2 == "local";
					continue;
				}
				if (text == "--coop-join-ip" && text2 != null)
				{
					_autoJoinDirect = text2;
					continue;
				}
				switch (text)
				{
				case "--coop-autostart":
					_autoStartRun = true;
					continue;
				case "--coop-godmode":
					_godMode = true;
					continue;
				case "--coop-autonext":
					_autoNextDay = true;
					continue;
				case "--coop-testloot":
					_testLoot = true;
					continue;
				case "--coop-testmap":
					_testMap = (_testShop = (_testInteract = (_testFar = (_testForage = true))));
					continue;
				case "--coop-testbuy":
					_testBuy = true;
					continue;
				case "--coop-testshoot":
					_testShoot = true;
					continue;
				case "--coop-testgun":
					if (text2 != null)
					{
						_testGun = text2;
						continue;
					}
					break;
				}
				if (text == "--coop-testchar" && text2 != null)
				{
					_testChar = text2;
					continue;
				}
				switch (text)
				{
				case "--coop-testeffects":
					_testEffects = true;
					break;
				case "--coop-testminimap":
					_testMinimap = true;
					break;
				case "--coop-testharvest":
					_testHarvest = true;
					break;
				case "--coop-testpowersow":
					_testPowerSow = true;
					break;
				case "--coop-testboss":
					_testBoss = true;
					if (text2 != null && !text2.StartsWith("--"))
					{
						_testBossName = text2;
					}
					break;
				case "--coop-testability":
					_testAbility = true;
					break;
				case "--coop-listchars":
					_listChars = true;
					break;
				case "--coop-spawndiag":
					SpawnDiagPatch.Enabled = true;
					break;
				}
			}
		}

		private static string Names<T>(List<T> list) where T : Object
		{
			if (list != null && list.Count != 0)
			{
				return string.Join(", ", (from x in list
					where (Object)(object)x != (Object)null
					select ((Object)x).name).ToArray());
			}
			return "-";
		}

		private static void RunMapTest()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			PlayerComp i = SingletonSceneScope<PlayerComp>.I;
			Dictionary<MvgTypes, MvgWrapperModel> dictionary = CoopState.Data?.Mvgs;
			if ((Object)(object)i == (Object)null || dictionary == null || !dictionary.TryGetValue((MvgTypes)0, out var value) || value == null)
			{
				return;
			}
			MvgModel val = null;
			float num = float.MaxValue;
			foreach (MvgModel allModel in value.GetCollection().GetAllModels())
			{
				Vector2 val2 = GridCollectionUtils.GridCoordToWorldCoord(allModel.Coord, (Pivot)0) - Vector2.op_Implicit(((Component)i).transform.position);
				float sqrMagnitude = ((Vector2)(ref val2)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
					val = allModel;
				}
			}
			if (val != null)
			{
				((Component)i).transform.position = Vector2.op_Implicit(GridCollectionUtils.GridCoordToWorldCoord(val.Coord, (Pivot)0) + new Vector2(1.5f, 0f));
				MapSync.MarkPlayerAction();
				if (CoopState.IsHost)
				{
					val.Bool4 = !val.Bool4;
				}
				else
				{
					val.Bool3 = !val.Bool3;
				}
				ManualLogSource log = Log;
				object[] array = new object[5];
				MvgDef def = val.Def;
				array[0] = ((def != null) ? ((Object)def).name : null);
				array[1] = val.Coord.x;
				array[2] = val.Coord.y;
				array[3] = val.Bool3;
				array[4] = val.Bool4;
				log.LogInfo((object)string.Format("[Teste] {0} em {1},{2}: Bool3 = {3}, Bool4 = {4}.", array));
			}
		}

		private static void RunFarTest()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			PlayerComp i = SingletonSceneScope<PlayerComp>.I;
			Dictionary<MvgTypes, MvgWrapperModel> dictionary = CoopState.Data?.Mvgs;
			if ((Object)(object)i == (Object)null || dictionary == null || !dictionary.TryGetValue((MvgTypes)0, out var value) || value == null)
			{
				return;
			}
			Vector2 val = ((Session != null && Session.HasRemoteState) ? Vector2.op_Implicit(Session.RemoteState.Position) : Vector2.op_Implicit(((Component)i).transform.position));
			MvgModel val2 = null;
			float num = float.MaxValue;
			foreach (MvgModel allModel in value.GetCollection().GetAllModels())
			{
				Vector2 val3 = GridCollectionUtils.GridCoordToWorldCoord(allModel.Coord, (Pivot)0) - val;
				float magnitude = ((Vector2)(ref val3)).magnitude;
				if (!(magnitude < 40f) && magnitude < num)
				{
					num = magnitude;
					val2 = allModel;
				}
			}
			if (val2 == null)
			{
				Log.LogInfo((object)"[Teste] Nenhum objeto do mapa longe do host.");
				return;
			}
			((Component)i).transform.position = Vector2.op_Implicit(GridCollectionUtils.GridCoordToWorldCoord(val2.Coord, (Pivot)0) + new Vector2(2f, 0f));
			ManualLogSource log = Log;
			object[] array = new object[5];
			MvgDef def = val2.Def;
			array[0] = ((def != null) ? ((Object)def).name : null);
			array[1] = val2.Coord.x;
			array[2] = val2.Coord.y;
			array[3] = num;
			array[4] = val2.GetQueuedStateChange();
			log.LogInfo((object)string.Format("[Teste] Indo até {0} em {1},{2} ({3:0} de distância do host, pendente: {4}).", array));
		}

		private static void RunInteractTest()
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			PlayerComp i = SingletonSceneScope<PlayerComp>.I;
			if ((Object)(object)i == (Object)null)
			{
				return;
			}
			InGameSelectable val = null;
			float num = float.MaxValue;
			InGameSelectable[] array = Object.FindObjectsOfType<InGameSelectable>();
			foreach (InGameSelectable val2 in array)
			{
				if (!((Object)(object)val2 == (Object)null) && ((Behaviour)val2).isActiveAndEnabled && !((Object)(object)((Component)val2).GetComponentInParent<MvgViewItem>() == (Object)null))
				{
					Vector2 val3 = Vector2.op_Implicit(((Component)val2).transform.position);
					float sqrMagnitude = ((Vector2)(ref val3)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = val2;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Log.LogInfo((object)"[Teste] Nenhum objeto do mapa com interação na tela.");
				return;
			}
			((Component)i).transform.position = ((Component)val).transform.position + new Vector3(1f, 0f, 0f);
			MapSync.MarkPlayerAction();
			ManualLogSource log = Log;
			MvgModel model = ((Component)val).GetComponentInParent<MvgViewItem>().GetModel();
			object arg;
			if (model == null)
			{
				arg = null;
			}
			else
			{
				MvgDef def = model.Def;
				arg = ((def != null) ? ((Object)def).name : null);
			}
			log.LogInfo((object)$"[Teste] Interagindo com {arg} em {((Component)val).transform.position}.");
			val._Interacted();
		}

		private static void LogShopState(string when)
		{
			GameData data = CoopState.Data;
			if (!((Object)(object)data == (Object)null))
			{
				List<PlayerGunModel> collection = data.Guns.GetCollection();
				PlayerGunModel gunModel = data.Guns.GetGunModel(data.CurrentGunIdx.Get());
				ShopModel weaponShop = data.WeaponShop;
				string text = ((weaponShop?.LootForSale == null) ? "sem loja" : string.Join(", ", weaponShop.LootForSale.Select((LootModel l) => (l != null) ? ((((Object)(object)l.Weapon?.Def != (Object)null) ? ((Object)l.Weapon.Def).name : ((object)l.LootDef)?.ToString()) + " $" + l.Cost) : "-").ToArray()));
				_ = Players?.RemotePlayer;
				ManualLogSource log = Log;
				object[] obj = new object[5]
				{
					when,
					data.Money.Get(),
					string.Join(", ", collection.Select((PlayerGunModel g) => (!((Object)(object)g?.Def != (Object)null)) ? "-" : ((Object)g.Def).name).ToArray()),
					null,
					null
				};
				object obj2;
				if (gunModel == null)
				{
					obj2 = null;
				}
				else
				{
					PlayerGunDef def = gunModel.Def;
					obj2 = ((def != null) ? ((Object)def).name : null);
				}
				obj[3] = obj2;
				obj[4] = text;
				log.LogInfo((object)string.Format("[Teste] {0}: dinheiro {1}, armas [{2}], arma atual {3}, loja de armas [{4}].", obj));
			}
		}

		private static void RunBuyTest()
		{
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			LogShopState("convidado antes da compra");
			GameData data = CoopState.Data;
			ShopView val = null;
			ShopView[] array = Object.FindObjectsOfType<ShopView>();
			foreach (ShopView val2 in array)
			{
				if ((Object)(object)val2 != (Object)null && val2.GetModel() == data.WeaponShop)
				{
					val = val2;
					break;
				}
			}
			if ((Object)(object)val == (Object)null || data.WeaponShop?.LootForSale == null)
			{
				Log.LogInfo((object)"[Teste] Loja de armas não encontrada na cidade.");
				return;
			}
			int num = Array.FindIndex(data.WeaponShop.LootForSale, (LootModel l) => l != null && l.Weapon != null);
			if (num < 0)
			{
				Log.LogInfo((object)"[Teste] Loja de armas sem arma à venda.");
				return;
			}
			LootModel val3 = data.WeaponShop.LootForSale[num];
			if ((int)val3.CostType == 0 && data.Money.Get() < val3.Cost)
			{
				Log.LogInfo((object)$"[Teste] Dinheiro insuficiente ({data.Money.Get()}); somando {val3.Cost - data.Money.Get()} para a compra.");
				data.Money.Add(val3.Cost - data.Money.Get());
			}
			ManualLogSource log = Log;
			object[] array2 = new object[4];
			PlayerGunDef def = val3.Weapon.Def;
			array2[0] = ((def != null) ? ((Object)def).name : null);
			array2[1] = num;
			array2[2] = val3.Cost;
			array2[3] = val3.CostType;
			log.LogInfo((object)string.Format("[Teste] Comprando {0} na vaga {1} por {2} ({3}).", array2));
			val.ManualInteract(num);
			LogShopState("convidado depois da compra");
		}

		private static bool RunShopTest()
		{
			FieldInfo[] fields = typeof(GameData).GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				if (!(fieldInfo.FieldType != typeof(ShopModel)))
				{
					object? value = fieldInfo.GetValue(CoopState.Data);
					ShopModel val = (ShopModel)((value is ShopModel) ? value : null);
					LootModel val2 = ((val?.LootForSale != null) ? Array.Find(val.LootForSale, (LootModel x) => x != null) : null);
					if (val2 != null)
					{
						val.RemoveLoot(val2);
						Log.LogInfo((object)("[Teste] Primeiro item da loja " + fieldInfo.Name + " comprado."));
						return true;
					}
				}
			}
			return false;
		}

		private unsafe void RunTestAutomation()
		{
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_07fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0803: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0910: Unknown result type (might be due to invalid IL or missing references)
			//IL_0915: Unknown result type (might be due to invalid IL or missing references)
			//IL_0742: Unknown result type (might be due to invalid IL or missing references)
			//IL_0748: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d99: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d9e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0daa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0daf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0db4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0db9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b1c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b36: Unknown result type (might be due to invalid IL or missing references)
			//IL_1b3f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1b44: Unknown result type (might be due to invalid IL or missing references)
			//IL_127e: Unknown result type (might be due to invalid IL or missing references)
			//IL_1283: Unknown result type (might be due to invalid IL or missing references)
			//IL_128b: Unknown result type (might be due to invalid IL or missing references)
			//IL_1297: Unknown result type (might be due to invalid IL or missing references)
			//IL_12a2: Expected O, but got Unknown
			//IL_0eff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f04: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a1f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a24: Unknown result type (might be due to invalid IL or missing references)
			//IL_1d31: Unknown result type (might be due to invalid IL or missing references)
			//IL_1d36: Unknown result type (might be due to invalid IL or missing references)
			//IL_1d38: Unknown result type (might be due to invalid IL or missing references)
			//IL_1b9c: Unknown result type (might be due to invalid IL or missing references)
			//IL_1ba2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f17: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f1c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f0d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f12: Unknown result type (might be due to invalid IL or missing references)
			//IL_1d3c: Unknown result type (might be due to invalid IL or missing references)
			//IL_1d3f: Invalid comparison between Unknown and I4
			//IL_1b78: Unknown result type (might be due to invalid IL or missing references)
			//IL_1b7d: Unknown result type (might be due to invalid IL or missing references)
			//IL_176f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1774: Unknown result type (might be due to invalid IL or missing references)
			//IL_155e: Unknown result type (might be due to invalid IL or missing references)
			//IL_1563: Unknown result type (might be due to invalid IL or missing references)
			//IL_156d: Unknown result type (might be due to invalid IL or missing references)
			//IL_1572: Unknown result type (might be due to invalid IL or missing references)
			//IL_1574: Unknown result type (might be due to invalid IL or missing references)
			//IL_1580: Unknown result type (might be due to invalid IL or missing references)
			//IL_1585: Unknown result type (might be due to invalid IL or missing references)
			//IL_158a: Unknown result type (might be due to invalid IL or missing references)
			//IL_158f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1594: Unknown result type (might be due to invalid IL or missing references)
			//IL_15b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_15c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_15c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_15cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_1d41: Unknown result type (might be due to invalid IL or missing references)
			//IL_1d44: Invalid comparison between Unknown and I4
			//IL_1c6e: Unknown result type (might be due to invalid IL or missing references)
			//IL_1c73: Unknown result type (might be due to invalid IL or missing references)
			//IL_13ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_13f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cbb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc0: Unknown result type (might be due to invalid IL or missing references)
			//IL_1beb: Unknown result type (might be due to invalid IL or missing references)
			//IL_1bf0: Unknown result type (might be due to invalid IL or missing references)
			//IL_1bfc: Unknown result type (might be due to invalid IL or missing references)
			//IL_1c01: Unknown result type (might be due to invalid IL or missing references)
			//IL_1c06: Unknown result type (might be due to invalid IL or missing references)
			//IL_1c0b: Unknown result type (might be due to invalid IL or missing references)
			//IL_1c81: Unknown result type (might be due to invalid IL or missing references)
			//IL_17aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_17af: Unknown result type (might be due to invalid IL or missing references)
			//IL_17bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_17c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_17c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_17ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_140e: Unknown result type (might be due to invalid IL or missing references)
			//IL_1413: Unknown result type (might be due to invalid IL or missing references)
			//IL_1404: Unknown result type (might be due to invalid IL or missing references)
			//IL_1409: Unknown result type (might be due to invalid IL or missing references)
			//IL_17e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_17e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f39: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f43: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f59: Unknown result type (might be due to invalid IL or missing references)
			//IL_183f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1844: Unknown result type (might be due to invalid IL or missing references)
			//IL_1850: Unknown result type (might be due to invalid IL or missing references)
			//IL_1855: Unknown result type (might be due to invalid IL or missing references)
			//IL_185a: Unknown result type (might be due to invalid IL or missing references)
			//IL_185f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1516: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f6c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d11: Unknown result type (might be due to invalid IL or missing references)
			//IL_1871: Unknown result type (might be due to invalid IL or missing references)
			//IL_1876: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f7f: Unknown result type (might be due to invalid IL or missing references)
			//IL_190a: Unknown result type (might be due to invalid IL or missing references)
			//IL_190f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1914: Unknown result type (might be due to invalid IL or missing references)
			//IL_191b: Unknown result type (might be due to invalid IL or missing references)
			//IL_1920: Unknown result type (might be due to invalid IL or missing references)
			//IL_1925: Unknown result type (might be due to invalid IL or missing references)
			//IL_1436: Unknown result type (might be due to invalid IL or missing references)
			//IL_1440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f8f: Unknown result type (might be due to invalid IL or missing references)
			//IL_195a: Unknown result type (might be due to invalid IL or missing references)
			//IL_195c: Unknown result type (might be due to invalid IL or missing references)
			//IL_1961: Unknown result type (might be due to invalid IL or missing references)
			//IL_1967: Unknown result type (might be due to invalid IL or missing references)
			//IL_145b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f9f: Unknown result type (might be due to invalid IL or missing references)
			//IL_18b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_18bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_18c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_18cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_18d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_18d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_1942: Unknown result type (might be due to invalid IL or missing references)
			//IL_1944: Unknown result type (might be due to invalid IL or missing references)
			//IL_1949: Unknown result type (might be due to invalid IL or missing references)
			//IL_194f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1471: Unknown result type (might be due to invalid IL or missing references)
			//IL_0faf: Unknown result type (might be due to invalid IL or missing references)
			//IL_18ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_18f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fe7: Unknown result type (might be due to invalid IL or missing references)
			//IL_1492: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ff6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fc6: Unknown result type (might be due to invalid IL or missing references)
			//IL_149d: Unknown result type (might be due to invalid IL or missing references)
			//IL_14ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_14bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_14cc: Unknown result type (might be due to invalid IL or missing references)
			if (Session == null)
			{
				return;
			}
			if (_godMode)
			{
				PlayerComp i = SingletonSceneScope<PlayerComp>.I;
				if ((Object)(object)i != (Object)null && !i.IfIsInNonDamageInvincible())
				{
					i.StartTrackableInvincible((object)this);
				}
			}
			if (_autoNextDay && CoopState.IsHost && RunSyncState.PartnerInSameScene && RunSync.CurrentSceneKind() == SceneKind.Town)
			{
				if (_townSince < 0f)
				{
					_townSince = Time.unscaledTime;
				}
				else if (Time.unscaledTime - _townSince > 15f && (Object)(object)SingletonSceneScope<TownManager>.I != (Object)null)
				{
					_townSince = -1f;
					Log.LogInfo((object)"[Teste] Voltando para a fazenda automaticamente.");
					SingletonSceneScope<TownManager>.I.ReturnToFarm();
				}
			}
			else
			{
				_townSince = -1f;
			}
			if (_testMap && ((CoopState.IsClient && RunSync.ClientSceneReady) || CoopState.HostReplicating) && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				if (_testMapAt < 0f)
				{
					_testMapAt = Time.unscaledTime + (CoopState.IsHost ? 30f : 15f);
				}
				else if (Time.unscaledTime >= _testMapAt)
				{
					_testMap = false;
					RunMapTest();
				}
			}
			Vector2 val4;
			if (_testForage && CoopState.IsClient && RunSync.ClientSceneReady && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				if (_testForageAt < 0f)
				{
					_testForageAt = Time.unscaledTime + 25f;
				}
				else if (Time.unscaledTime >= _testForageAt)
				{
					_testForage = false;
					PlayerComp me = SingletonSceneScope<PlayerComp>.I;
					GameData data = CoopState.Data;
					object obj;
					if (data == null)
					{
						obj = null;
					}
					else
					{
						WeedCollection weeds = data.Weeds;
						obj = ((weeds == null) ? null : weeds.GetAll()?.Where((WeedModel w) => (int)w.GetWeedType() == 1).OrderBy(delegate(WeedModel w)
						{
							//IL_0001: Unknown result type (might be due to invalid IL or missing references)
							//IL_0007: Unknown result type (might be due to invalid IL or missing references)
							//IL_0017: Unknown result type (might be due to invalid IL or missing references)
							//IL_001c: 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)
							Vector2 val30 = GridCollectionUtils.GridCoordToWorldCoord(w.Coord, (Pivot)0) - Vector2.op_Implicit(((Component)me).transform.position);
							return ((Vector2)(ref val30)).sqrMagnitude;
						}).FirstOrDefault());
					}
					WeedModel val = (WeedModel)obj;
					if (val != null && (Object)(object)me != (Object)null)
					{
						Log.LogInfo((object)$"[Teste] Pisando no broto de erva em {val.Coord.x},{val.Coord.y}.");
						((Component)me).transform.position = Vector2.op_Implicit(GridCollectionUtils.GridCoordToWorldCoord(val.Coord, (Pivot)0));
						return;
					}
					Forageable val2 = null;
					float num = float.MaxValue;
					Forageable[] array = Object.FindObjectsOfType<Forageable>();
					foreach (Forageable val3 in array)
					{
						if (!((Object)(object)me == (Object)null) && !((Object)(object)val3 == (Object)null))
						{
							val4 = Vector2.op_Implicit(((Component)val3).transform.position) - Vector2.op_Implicit(((Component)me).transform.position);
							float sqrMagnitude = ((Vector2)(ref val4)).sqrMagnitude;
							if (sqrMagnitude < num)
							{
								num = sqrMagnitude;
								val2 = val3;
							}
						}
					}
					if ((Object)(object)val2 != (Object)null)
					{
						Log.LogInfo((object)$"[Teste] Pisando no broto em {((Component)val2).transform.position}.");
						((Component)me).transform.position = ((Component)val2).transform.position;
					}
					else
					{
						Log.LogInfo((object)"[Teste] Nenhum broto na tela.");
					}
				}
			}
			if (_testFar && CoopState.IsClient && RunSync.ClientSceneReady && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				if (_testFarAt < 0f)
				{
					_testFarAt = Time.unscaledTime + 55f;
				}
				else if (Time.unscaledTime >= _testFarAt)
				{
					_testFar = false;
					RunFarTest();
				}
			}
			if (_testInteract && ((CoopState.IsClient && RunSync.ClientSceneReady) || CoopState.HostReplicating) && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				if (_testInteractAt < 0f)
				{
					_testInteractAt = Time.unscaledTime + 40f;
				}
				else if (Time.unscaledTime >= _testInteractAt)
				{
					_testInteract = false;
					RunInteractTest();
				}
			}
			if (_listChars && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				_listChars = false;
				foreach (PlayerDef item in from p in Resources.FindObjectsOfTypeAll<PlayerDef>()
					where (Object)(object)p != (Object)null
					group p by ((Object)p).name into g
					select g.First())
				{
					string text = ((item.CharacterSpecificObjects == null) ? "-" : string.Join("; ", (from o in item.CharacterSpecificObjects
						where (Object)(object)o != (Object)null
						select ((Object)o).name + "[" + string.Join(",", (from c in o.GetComponentsInChildren<MonoBehaviour>(true)
							where (Object)(object)c != (Object)null
							select ((object)c).GetType().Name).Distinct().ToArray()) + "]").ToArray()));
					Log.LogInfo((object)("[Personagem] " + ((Object)item).name + ": objetos " + text + " | upgrades " + Names<UpgradeDef>(item.DefaultUpgrades) + " | amigos " + Names<FriendDef>(item.DefaultFriends) + " | itens " + Names<ActionItemDef>(item.DefaultActionItem) + " | torretas " + Names<TurretDef>(item.DefaultTurret)));
				}
			}
			if (_testGun != null && CoopState.IsClient && RunSync.ClientSceneReady && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				List<PlayerGunDef> source = (from g in Resources.FindObjectsOfTypeAll<PlayerGunDef>()
					where (Object)(object)g != (Object)null && (Object)(object)g.GunPrefab != (Object)null
					select g).ToList();
				Log.LogInfo((object)("[Teste] Armas do jogo: " + string.Join(", ", source.Select((PlayerGunDef g) => ((Object)g).name).Distinct().ToArray())));
				PlayerGunDef val5 = ((_testGun == "*Beam") ? ((IEnumerable<PlayerGunDef>)source).FirstOrDefault((Func<PlayerGunDef, bool>)((PlayerGunDef g) => (Object)(object)g.GunPrefab.GetComponentInChildren<BeamGun>(true) != (Object)null)) : ((_testGun == "*Flame") ? ((IEnumerable<PlayerGunDef>)source).FirstOrDefault((Func<PlayerGunDef, bool>)((PlayerGunDef g) => (Object)(object)g.GunPrefab.GetComponentInChildren<FlameThrower>(true) != (Object)null)) : ((IEnumerable<PlayerGunDef>)source).FirstOrDefault((Func<PlayerGunDef, bool>)((PlayerGunDef g) => ((Object)g).name == _testGun))));
				Log.LogInfo((object)(((Object)(object)val5 != (Object)null) ? ("[Teste] Recebendo a arma " + _testGun + ".") : ("[Teste] Arma " + _testGun + " não encontrada.")));
				_testGun = null;
				if ((Object)(object)val5 != (Object)null)
				{
					LootModel obj2 = LootModelGenerator.GenerateLootModel((ILootDef)(object)val5, 1, true, false, (LootCollectionIdsEnum)0);
					val4 = default(Vector2);
					LootApply.Apply(obj2, false, val4);
				}
			}
			if (_testChar != null && Session.IsConnected && RunSync.CurrentSceneKind() == SceneKind.Farm && (CoopState.HostReplicating || (CoopState.IsClient && RunSync.ClientSceneReady)))
			{
				if (_testCharAt < 0f)
				{
					_testCharAt = Time.unscaledTime + 10f;
				}
				else if (Time.unscaledTime >= _testCharAt)
				{
					PlayerComp i2 = SingletonSceneScope<PlayerComp>.I;
					bool flag = PlayerSync.TestSwapCharacter(i2, _testChar);
					if ((Object)(object)i2 != (Object)null)
					{
						Transform transform = ((Component)i2).transform;
						transform.position += new Vector3(3f, 0f, 0f);
					}
					Log.LogInfo((object)("[Teste] Trocando o personagem para " + _testChar + ": " + (flag ? "ok" : "não encontrado") + "."));
					_testChar = null;
				}
			}
			if (_testEffects && CoopState.IsClient && RunSync.ClientSceneReady && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				PlayerComp i3 = SingletonSceneScope<PlayerComp>.I;
				if (_testEffectsAt < 0f)
				{
					_testEffectsAt = Time.unscaledTime + 10f;
				}
				else if ((Object)(object)i3 != (Object)null && Time.unscaledTime >= _testEffectsAt)
				{
					float num3 = Time.unscaledTime - _testEffectsAt;
					PlayerGridWorkController gridWorkController = i3.GetGridWorkController();
					if (_testEffectsStep == 0)
					{
						_testEffectsStep = 1;
						Transform transform2 = ((Component)i3).transform;
						transform2.position += new Vector3(5f, 0f, 0f);
						if ((Object)(object)gridWorkController != (Object)null)
						{
							EnergizedRef.Invoke(gridWorkController) = 8f;
						}
						i3.StartTimedInvicibility(3f);
						Log.LogInfo((object)"[Teste] Efeitos: energizado e piscando.");
					}
					else if (_testEffectsStep == 1 && num3 >= 4f)
					{
						_testEffectsStep = 2;
						i3.StartTrackableInvincibilityWithGraphic((object)this);
						Log.LogInfo((object)"[Teste] Efeitos: invencível com gráfico.");
					}
					else if (_testEffectsStep == 2 && num3 >= 8f)
					{
						_testEffectsStep = 3;
						i3.StopTrackableInvincibilityWithGraphic((object)this);
						LiveParams.Player.DoHorseAlwaysOn = true;
						Log.LogInfo((object)"[Teste] Efeitos: montando no cavalo.");
					}
					else if (_testEffectsStep == 3 && num3 >= 13f)
					{
						_testEffectsStep = 4;
						LiveParams.Player.DoHorseAlwaysOn = false;
						PlayerHorseController componentInChildren = ((Component)i3).GetComponentInChildren<PlayerHorseController>();
						if (componentInChildren != null)
						{
							componentInChildren.Dismount();
						}
						Transform transform3 = ((Component)i3).transform;
						transform3.position += new Vector3(22f, 6f, 0f);
						_testEffects = false;
						Log.LogInfo((object)"[Teste] Efeitos: desmontou e foi para longe.");
					}
				}
			}
			if (_testBoss && CoopState.HostReplicating && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				if (_testBossAt < 0f)
				{
					_testBossAt = Time.unscaledTime + 15f;
				}
				else if (Time.unscaledTime >= _testBossAt)
				{
					float num4 = Time.unscaledTime - _testBossAt;
					FarmSceneManager i4 = SingletonSceneScope<FarmSceneManager>.I;
					BossesManager i5 = SingletonSceneScope<BossesManager>.I;
					if (_testBossStep == 0 && (Object)(object)i4 != (Object)null)
					{
						_testBossStep = 1;
						BossDef val6 = ((_testBossName == null) ? null : ((IEnumerable<BossDef>)Resources.FindObjectsOfTypeAll<BossDef>()).FirstOrDefault((Func<BossDef, bool>)((BossDef d) => (Object)(object)d != (Object)null && ((Object)d).name.IndexOf(_testBossName, StringComparison.OrdinalIgnoreCase) >= 0)));
						if ((Object)(object)val6 != (Object)null && (Object)(object)i5 != (Object)null)
						{
							Log.LogInfo((object)$"[Teste] Chefão: chamando {((Object)val6).name} ({val6.Season}).");
							i5.StartBoss(val6, val6.Season);
						}
						else
						{
							Log.LogInfo((object)("[Teste] Chefão: chamando o chefão da estação. Disponíveis: " + string.Join(", ", (from d in Resources.FindObjectsOfTypeAll<BossDef>()
								where (Object)(object)d != (Object)null
								select ((Object)d).name).Distinct().ToArray())));
							AccessTools.Method(((object)i4).GetType(), "_warpToBoss", (Type[])null, (Type[])null).Invoke(i4, null);
						}
					}
					else if (_testBossStep >= 1 && _testBossStep < 9 && num4 >= (float)_testBossStep * 5f)
					{
						_testBossStep++;
						GameObject val7 = (((Object)(object)i5 != (Object)null) ? i5.GetMainBossObj() : null);
						Enemy val8 = (((Object)(object)val7 != (Object)null) ? val7.GetComponent<Enemy>() : null);
						Log.LogInfo((object)("[Teste] Chefão: " + (((Object)(object)val7 != (Object)null) ? ((Object)val7).name : "nenhum") + " vida " + (((Object)(object)val8 != (Object)null) ? val8.Health.ToString() : "-") + " em " + (((Object)(object)val7 != (Object)null) ? ((object)val7.transform.position/*cast due to .constrained prefix*/).ToString() : "-") + "."));
						if (_testBossStep == 9 && (Object)(object)val8 != (Object)null)
						{
							Log.LogInfo((object)"[Teste] Chefão: matando o chefão.");
							val8.DoDamage(99999, 1f, Vector2.right);
							_testBoss = false;
						}
					}
				}
			}
			if (_testMinimap && CoopState.HostReplicating && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				PlayerComp i6 = SingletonSceneScope<PlayerComp>.I;
				RemotePlayer remotePlayer = Players?.RemotePlayer;
				UiInfoScreen val9 = Object.FindObjectOfType<UiInfoScreen>();
				if (_testMinimapAt < 0f && (Object)(object)i6 != (Object)null && (Object)(object)remotePlayer != (Object)null && remotePlayer.HasPosition && (Object)(object)val9 != (Object)null)
				{
					val4 = Vector2.op_Implicit(remotePlayer.Position) - Vector2.op_Implicit(((Component)i6).transform.position);
					if (((Vector2)(ref val4)).magnitude > 12f)
					{
						_testMinimapAt = Time.unscaledTime;
						val9.Show();
						Log.LogInfo((object)"[Teste] Mapa: tela de informações aberta.");
						goto IL_0e35;
					}
				}
				if (_testMinimapAt > 0f && Time.unscaledTime - _testMinimapAt > 15f && (Object)(object)val9 != (Object)null)
				{
					val9.Hide();
					_testMinimap = false;
					Log.LogInfo((object)"[Teste] Mapa: tela fechada.");
				}
			}
			goto IL_0e35;
			IL_0e35:
			if (_testPowerSow && ((CoopState.IsClient && RunSync.ClientSceneReady) || CoopState.HostReplicating) && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				CropsController crops = SingletonSceneScope<CropsController>.I;
				if (_testPowerSowAt < 0f)
				{
					_testPowerSowAt = Time.unscaledTime + 12f;
				}
				else if ((Object)(object)crops != (Object)null && _testPowerSowCoords.Count == 0 && Time.unscaledTime >= _testPowerSowAt)
				{
					RemotePlayer remotePlayer2 = Players?.RemotePlayer;
					PlayerComp i7 = SingletonSceneScope<PlayerComp>.I;
					Int2 val10 = Grid.Coord(((Object)(object)remotePlayer2 != (Object)null && remotePlayer2.HasPosition) ? Vector2.op_Implicit(remotePlayer2.Position) : Vector2.op_Implicit(((Component)i7).transform.position));
					GameData data2 = CoopState.Data;
					Int2 val11 = default(Int2);
					for (int num5 = -20; num5 <= 20; num5++)
					{
						if (_testPowerSowCoords.Count >= 6)
						{
							break;
						}
						for (int num6 = -20; num6 <= 20; num6++)
						{
							if (_testPowerSowCoords.Count >= 6)
							{
								break;
							}
							((Int2)(ref val11))..ctor(val10.x + num6, val10.y + num5);
							if (crops.GetCrop(val11) != null || !crops.IsInFarmingArea(val11) || data2.SoilCrustCollection.Get(val11) != null || data2.Weeds.Get(val11) != null || data2.Turrets.Get(val11) != null)
							{
								continue;
							}
							if (crops.GetSoil(val11) == null)
							{
								using (CoopState.LocalAction())
								{
									crops.AddSoil(val11, 1, (FriendModel)null, false);
								}
							}
							if (crops.GetSoil(val11) != null)
							{
								_testPowerSowCoords.Add(val11);
							}
						}
					}
					if (_testPowerSowCoords.Count == 0)
					{
						Log.LogInfo((object)"[Teste] Fileira: nenhum canteiro livre; teste cancelado.");
						_testPowerSow = false;
						return;
					}
					CropDef val12 = ((IEnumerable<CropDef>)Resources.FindObjectsOfTypeAll<CropDef>()).FirstOrDefault((Func<CropDef, bool>)((CropDef d) => (Object)(object)d != (Object)null && PowerSowUtils.IsPowerSowEnabledForCrop(d))) ?? ((IEnumerable<CropDef>)Resources.FindObjectsOfTypeAll<CropDef>()).FirstOrDefault((Func<CropDef, bool>)((CropDef d) => (Object)(object)d != (Object)null));
					Log.LogInfo((object)string.Format("[Teste] Fileira: plantando {0} em {1} canteiros: {2}", (val12 != null) ? ((Object)val12).name : null, _testPowerSowCoords.Count, string.Join(" ", _testPowerSowCoords.Select((Int2 c) => ((object)(*(Int2*)(&c))/*cast due to .constrained prefix*/).ToString()).ToArray())));
					if ((Object)(object)val12 != (Object)null && _testPowerSowCoords.Count > 0)
					{
						SingletonSceneScopeAutoLoad<PowerSowController>.I.PowerSow(new List<Int2>(_testPowerSowCoords), val12);
					}
					_testPowerSowAt = Time.unscaledTime + 6f;
				}
				else if ((Object)(object)crops != (Object)null && _testPowerSowCoords.Count > 0 && Time.unscaledTime >= _testPowerSowAt)
				{
					int num7 = _testPowerSowCoords.Count((Int2 c) => crops.GetCrop(c) != null);
					Log.LogInfo((object)$"[Teste] Fileira: {num7} de {_testPowerSowCoords.Count} canteiros com planta no convidado.");
					_testPowerSow = false;
				}
			}
			if (_testHarvest && CoopState.IsClient && RunSync.ClientSceneReady && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				if (_testHarvestAt < 0f)
				{
					_testHarvestAt = Time.unscaledTime + 10f;
				}
				else if (Time.unscaledTime >= _testHarvestAt)
				{
					_testHarvest = false;
					SellableDef val13 = ((IEnumerable<SellableDef>)Resources.FindObjectsOfTypeAll<SellableDef>()).FirstOrDefault((Func<SellableDef, bool>)((SellableDef x) => (Object)(object)x != (Object)null));
					if ((Object)(object)val13 != (Object)null)
					{
						for (int num8 = 0; num8 < 3; num8++)
						{
							CoopState.Data.Sellables.Add(new SellableModel
							{
								Def = val13,
								ValuePer = 1f
							}, false, Vector2.zero, (CropModel)null);
						}
					}
					Log.LogInfo((object)("[Teste] Colheita: 3x " + ((val13 != null) ? ((Object)val13).name : null) + " na colheita do dia do convidado."));
				}
			}
			if (_testAbility && CoopState.IsClient && RunSync.ClientSceneReady && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				PlayerComp i8 = SingletonSceneScope<PlayerComp>.I;
				PlayerParams player = LiveParams.Player;
				if (_testAbilityAt < 0f)
				{
					_testAbilityAt = Time.unscaledTime + 8f;
				}
				else if ((Object)(object)i8 != (Object)null && Time.unscaledTime >= _testAbilityAt)
				{
					float num9 = Time.unscaledTime - _testAbilityAt;
					if (num9 < 4f)
					{
						player.IsFlying = true;
						player.RunToTill = true;
						if (num9 >= (float)_testAbilityStep * 0.5f)
						{
							CropsController i9 = SingletonSceneScope<CropsController>.I;
							if (_testAbilityStep == 0)
							{
								if ((Object)(object)((Component)i8).GetComponentInChildren<RunToTill>() == (Object)null)
								{
									_testRunToTill = ((Component)i8).gameObject.AddComponent<RunToTill>();
								}
								Int2 val14 = Grid.Coord(((Object)(object)Players?.RemotePlayer != (Object)null && Players.RemotePlayer.HasPosition) ? Vector2.op_Implicit(Players.RemotePlayer.Position) : Vector2.op_Implicit(i8.Anchors.Feet));
								GameData data3 = CoopState.Data;
								int num10 = 0;
								int num11 = 0;
								Int2 val15 = default(Int2);
								for (int num12 = -20; num12 <= 20; num12++)
								{
									for (int num13 = -20; num13 <= 20; num13++)
									{
										((Int2)(ref val15))..ctor(val14.x + num13, val14.y + num12);
										if (!((Object)(object)i9 == (Object)null) && i9.IsInFarmingArea(val15))
										{
											num10++;
											if (data3.SoilCrustCollection.Get(val15) != null)
											{
												num11++;
											}
											else if (_testAbilityCoords.Count < 8 && i9.GetCrop(val15) == null && i9.GetSoil(val15) == null && data3.Weeds.Get(val15) == null && data3.Turrets.Get(val15) == null)
											{
												_testAbilityCoords.Add(val15);
											}
										}
									}
								}
								Log.LogInfo((object)$"[Teste] Habilidade: {_testAbilityCoords.Count} quadrados livres perto de {val14} ({num10} na área de plantio, {num11} com crosta).");
							}
							if (_testAbilityStep < _testAbilityCoords.Count)
							{
								Int2 val16 = _testAbilityCoords[_testAbilityStep];
								Transform transform4 = ((Component)i8).transform;
								transform4.position += Vector2.op_Implicit(Grid.WorldPos(val16) - Vector2.op_Implicit(i8.Anchors.Feet));
								Log.LogInfo((object)$"[Teste] Habilidade: passo {_testAbilityStep + 1} voando e arando em {val16} (pé em {Grid.Coord(Vector2.op_Implicit(i8.Anchors.Feet))})");
							}
							_testAbilityStep++;
						}
					}
					else
					{
						player.IsFlying = false;
						player.RunToTill = false;
						if ((Object)(object)_testRunToTill != (Object)null)
						{
							Object.Destroy((Object)(object)_testRunToTill);
						}
						_testAbility = false;
						CropsController cc = SingletonSceneScope<CropsController>.I;
						Log.LogInfo((object)("[Teste] Habilidade: terra arada agora em " + _testAbilityCoords.Count((Int2 c) => (Object)(object)cc != (Object)null && cc.GetSoil(c) != null) + " de " + _testAbilityCoords.Count + " passos."));
						Log.LogInfo((object)"[Teste] Habilidade: perdendo 10 s (Botanist) e ganhando 5 s (ampulheta).");
						DayNightUtils.FastForward(10f);
						DayNightUtils.AddTime(5f);
					}
				}
			}
			if (_testShoot && !_testBuy && ((CoopState.IsClient && RunSync.ClientSceneReady) || CoopState.HostReplicating) && RunSync.CurrentSceneKind() == SceneKind.Farm)
			{
				if (_testShootAt < 0f)
				{
					_testShootAt = Time.unscaledTime + 10f;
				}
				else if (Time.unscaledTime >= _testShootAt)
				{
					_testShootAt = Time.unscaledTime + 0.5f;
					PlayerComp i10 = SingletonSceneScope<PlayerComp>.I;
					object obj3;
					if (!((Object)(object)i10 != (Object)null))
					{
						obj3 = null;
					}
					else
					{
						PlayerGunController componentInChildren2 = ((Component)i10).GetComponentInChildren<PlayerGunController>();
						obj3 = ((componentInChildren2 != null) ? componentInChildren2.GetCurrentGun() : null);
					}
					IPlayerGun val17 = (IPlayerGun)obj3;
					if (val17 != null)
					{
						Vector2 val18 = Vector2.right;
						float num14 = 144f;
						Enemy[] array2 = Object.FindObjectsOfType<Enemy>();
						foreach (Enemy val19 in array2)
						{
							if (!((Object)(object)val19 == (Object)null) && !val19.GetIsDead())
							{
								Vector2 val20 = Vector2.op_Implicit(((Component)val19).transform.position) - Vector2.op_Implicit(((Component)i10).transform.position);
								if (((Vector2)(ref val20)).sqrMagnitude < num14)
								{
									num14 = ((Vector2)(ref val20)).sqrMagnitude;
									val18 = ((Vector2)(ref val20)).normalized;
								}
							}
						}
						BossesManager i11 = SingletonSceneScope<BossesManager>.I;
						GameObject val21 = ((i11 != null) ? i11.GetMainBossObj() : null);
						if ((Object)(object)val21 == (Object)null && CoopState.IsClient)
						{
							BossPuppet bossPuppet = Object.FindObjectOfType<BossPuppet>();
							val21 = ((bossPuppet != null) ? ((Component)bossPuppet).gameObject : null);
						}
						if ((Object)(object)val21 != (Object)null)
						{
							Vector2 val22 = Vector2.op_Implicit(val21.transform.position) - Vector2.op_Implicit(((Component)i10).transform.position);
							if (((Vector2)(ref val22)).sqrMagnitude < 324f)
							{
								val18 = ((Vector2)(ref val22)).normalized;
								num14 = -1f;
							}
						}
						DamageReceiver[] array3 = Object.FindObjectsOfType<DamageReceiver>();
						foreach (DamageReceiver val23 in array3)
						{
							if (!((Object)(object)val23 == (Object)null) && !(((Object)val23).name != "MirrorHitbox"))
							{
								Vector2 val24 = Vector2.op_Implicit(((Component)val23).transform.position) - Vector2.op_Implicit(((Component)i10).transform.position);
								if (((Vector2)(ref val24)).sqrMagnitude < num14)
								{
									num14 = ((Vector2)(ref val24)).sqrMagnitude;
									val18 = ((Vector2)(ref val24)).normalized;
								}
							}
						}
						Vector2 val25 = Vector2.op_Implicit(((Component)i10).transform.position) + val18 * 6f;
						if (val17 is GunEveryFrameFire)
						{
							if (val17.IsTriggerDown())
							{
								val17.TriggerUp();
							}
							Vector2 val26 = val18;
							val4 = default(Vector2);
							val17.TriggerDown(val26, val25, (DamageLayer)0, val4);
						}
						else
						{
							Vector2 val27 = val18;
							val4 = default(Vector2);
							val17.ForceFire(val27, val25, (DamageLayer)0, val4);
						}
						if (_testShots == 0)
						{
							ManualLogSource log = Log;
							PlayerGunModel gunModel = CoopState.Data.Guns.GetGunModel(CoopState.Data.CurrentGunIdx.Get());
							object obj4;
							if (gunModel == null)
							{
								obj4 = null;
							}
							else
							{
								PlayerGunDef def = gunModel.Def;
								obj4 = ((def != null) ? ((Object)def).name : null);
							}
							log.LogInfo((object)("[Teste] Atirando com " + (string?)obj4 + "."));
						}
					}
					if (++_testShots >= 800)
					{
						_testShoot = false;
					}
				}
			}
			if (_testBuy && ((CoopState.IsClient && RunSync.ClientSceneReady) || CoopState.HostReplicating) && RunSync.CurrentSceneKind() == SceneKind.Town)
			{
				if (_testBuyAt < 0f)
				{
					_testBuyAt = Time.unscaledTime + (CoopState.IsHost ? 12f : 5f);
				}
				else if (Time.unscaledTime >= _testBuyAt)
				{
					_testBuy = false;
					if (CoopState.IsClient)
					{
						RunBuyTest();
					}
					else
					{
						LogShopState("host depois da compra do convidado");
					}
				}
			}
			if (_testShop && ((CoopState.IsClient && RunSync.ClientSceneReady) || CoopState.HostReplicating) && RunSync.CurrentSceneKind() == SceneKind.Town)
			{
				if (_testShopAt < 0f)
				{
					_testShopAt = Time.unscaledTime + (CoopState.IsHost ? 10f : 5f);
				}
				else if (Time.unscaledTime >= _testShopAt)
				{
					_testShop = false;
					if (!RunShopTest())
					{
						Log.LogInfo((object)"[Teste] Nenhuma loja com estoque.");
					}
				}
			}
			if (_testLoot && CoopState.HostReplicating && RunSync.CurrentSceneKind() == SceneKind.Farm && Time.unscaledTime >= _nextTestLoot)
			{
				PlayerComp i12 = SingletonSceneScope<PlayerComp>.I;
				if ((Object)(object)i12 != (Object)null)
				{
					_nextTestLoot = Time.unscaledTime + 8f;
					LootItemFuncs.DropFert(Vector2.op_Implicit(((Component)i12).transform.position), 1f);
					List<CropDef> crops2 = CropDefLoader.GetCrops();
					if (crops2 != null && crops2.Count > 0)
					{
						LootItemFuncs.DropAutoPickup((ILootDef)(object)crops2[0], 1, Vector2.op_Implicit(((Component)i12).transform.position), 1f, true);
					}
					PlayerUtils.AddHealth(0);
					val4 = default(Vector2);
					InGameText.FloatUpFromPlayer("Teste", false, val4);
					Enemy val28 = null;
					float num15 = 196f;
					Enemy[] array2 = Object.FindObjectsOfType<Enemy>();
					foreach (Enemy val29 in array2)
					{
						if (!((Object)(object)val29 == (Object)null) && !val29.GetIsDead() && AgentSync.TryGetWorldModel((Component)(object)val29, out var _))
						{
							val4 = Vector2.op_Implicit(((Component)val29).transform.position) - Vector2.op_Implicit(((Component)i12).transform.position);
							float sqrMagnitude2 = ((Vector2)(ref val4)).sqrMagnitude;
							if (sqrMagnitude2 < num15)
							{
								num15 = sqrMagnitude2;
								val28 = val29;
							}
						}
					}
					if ((Object)(object)val28 != (Object)null)
					{
						Log.LogInfo((object)("[Teste] Matando " + ((Object)val28).name + "."));
						GroundSplats i13 = SingletonSceneScopeAutoLoad<GroundSplats>.I;
						if (i13 != null)
						{
							i13.EmiteSplatDrop(Vector2.op_Implicit(((Component)val28).transform.position), 6, (GroundSplatsType)0);
						}
						val28.Kill(Vector2.right, 2f, (DamageInfo)null);
					}
					Log.LogInfo((object)"[Teste] Adubo solto aos pés do host, coração e texto tocados.");
				}
			}
			if (_autoHostDirect && Session.Status == NetStatus.Offline)
			{
				_autoHostDirect = false;
				Session.HostDirect(DirectPort.Value, _autoHostLoopback);
			}
			if (_autoJoinDirect != null && Session.Status == NetStatus.Offline && Time.unscaledTime > 8f)
			{
				string autoJoinDirect = _autoJoinDirect;
				_autoJoinDirect = null;
				JoinDirect(autoJoinDirect);
			}
			if (!_autoStartRun || !CoopState.IsHost)
			{
				return;
			}
			GameStateManager i14 = SinglePrefab<GameStateManager>.I;
			if ((Object)(object)i14 == (Object)null)
			{
				return;
			}
			States state = GameStateManager.GetState();
			if ((int)state == 0 || (int)state == 5 || (int)state == 6)
			{
				if (_autoStartAt < 0f)
				{
					_autoStartAt = Time.unscaledTime + 3f;
				}
				if (!(Time.unscaledTime < _autoStartAt))
				{
					_autoStartRun = false;
					Log.LogInfo((object)"[Teste] Iniciando partida nova automaticamente.");
					i14.StartGame(true, true, false, "custom");
				}
			}
		}

		private void OnDestroy()
		{
			Session?.Dispose();
			Session = null;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void OnApplicationQuit()
		{
			Session?.Leave();
		}

		private void Update()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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)
			KeyboardShortcut value = ToggleOverlayKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				_showOverlay = !_showOverlay;
			}
			value = DumpKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				DumpPlayerHierarchy();
			}
			if (Input.GetKeyDown((KeyCode)292) || ((Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)) && Input.GetKeyDown((KeyCode)13)))
			{
				VideoManager.ToggleFullscreen();
			}
			if (Session == null && IsSteamReady())
			{
				CreateSession();
			}
			if (Session != null)
			{
				UpdateRunInBackground();
				Safe("test", RunTestAutomation);
				Safe("net", delegate
				{
					Session.Tick();
				});
				Safe("run", delegate
				{
					Run.Tick();
				});
				PlayerComp local = SingletonSceneScope<PlayerComp>.I;
				Safe("players", delegate
				{
					Players.Tick(local);
				});
				Safe("clock", delegate
				{
					Clock.Tick();
				});
				Safe("agents", delegate
				{
					Agents.Tick();
				});
				Safe("bosses", delegate
				{
					Bosses.Tick();
				});
				Safe("farm", delegate
				{
					Farm.Tick();
				});
				Safe("shared", delegate
				{
					Shared.Tick();
				});
				Safe("map", delegate
				{
					Map.Tick();
				});
				Safe("check", delegate
				{
					Check.Tick();
				});
				Safe("friends", delegate
				{
					Friends.Tick();
				});
				Safe("upgrades", delegate
				{
					Upgrades.Tick();
				});
				bool flag = Session.IsConnected && Session.HasRemoteState && Session.RemoteState.Scene == CurrentScene();
				Players.SetRemoteVisible(flag && (Object)(object)local != (Object)null);
				AiTargeting.Refresh();
			}
		}

		private void LateUpdate()
		{
			if (Session != null)
			{
				Safe("agents-late", delegate
				{
					Agents.LateTick();
				});
				Safe("farm-late", delegate
				{
					Farm.LateTick();
				});
				Safe("loot-late", delegate
				{
					Loot.LateTick();
				});
				Safe("anim-late", delegate
				{
					EnemyAnims.LateTick();
				});
				Safe("fx-late", delegate
				{
					Effects.LateTick();
				});
				Safe("map-late", delegate
				{
					Map.LateTick();
				});
			}
		}

		private void UpdateRunInBackground()
		{
			if (Session.Status != NetStatus.Offline)
			{
				if (!_originalRunInBackground.HasValue)
				{
					_originalRunInBackground = Application.runInBackground;
				}
				if (!Application.runInBackground)
				{
					Application.runInBackground = true;
				}
			}
			else if (_originalRunInBackground.HasValue)
			{
				Application.runInBackground = _originalRunInBackground.Value;
				_originalRunInBackground = null;
			}
		}

		private void CreateSession()
		{
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			Session = new NetSession
			{
				LocalStateProvider = GetLocalState
			};
			Run = new RunSync(Session);
			Players = new PlayerSync(Session);
			Clock = new TimeSync(Session);
			Agents = new AgentSync(Session);
			Bosses = new BossSync(Session);
			Tally = new TallySync(Session);
			Farm = new FarmSync(Session);
			Shared = new ResourceSync(Session);
			Combat = new CombatSync(Session);
			WorldFx = new WorldFxSync(Session);
			Loot = new LootSync(Session);
			EnemyAnims = new EnemyAnimSync(Session);
			Effects = new FxSync(Session);
			Map = new MapSync(Session);
			Check = new WorldCheck(Session);
			Friends = new FriendSync(Session);
			Upgrades = new WorldUpgradeSync(Session);
			Log.LogInfo((object)"Sessão de rede inicializada.");
			if (_pendingLobbyFromCmdLine != 0L)
			{
				Session.JoinLobby(new CSteamID(_pendingLobbyFromCmdLine));
				_pendingLobbyFromCmdLine = 0uL;
			}
		}

		private static void Safe(string key, Action a)
		{
			try
			{
				a();
			}
			catch (Exception arg)
			{
				LogOnce("tick-" + key, $"[{key}] Erro no loop: {arg}");
			}
		}

		internal static void LogOnce(string key, string message)
		{
			if (_loggedOnce.Add(key))
			{
				Log.LogWarning((object)message);
			}
		}

		internal static void ShowToast(string message)
		{
			_toast = message;
			_toastUntil = Time.unscaledTime + 6f;
			Log.LogInfo((object)("[Aviso] " + message));
		}

		private static short CurrentScene()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			return (short)((Scene)(ref activeScene)).buildIndex;
		}

		private static PlayerStateData? GetLocalState()
		{
			//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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			PlayerComp i = SingletonSceneScope<PlayerComp>.I;
			if ((Object)(object)i == (Object)null)
			{
				return null;
			}
			PlayerStateData value = new PlayerStateData
			{
				Position = ((Component)i).transform.position,
				Scene = CurrentScene()
			};
			PlayerInfo i2 = SingletonSceneScope<PlayerInfo>.I;
			if ((Object)(object)i2 != (Object)null)
			{
				value.Aim = i2.GetAimDirPotentiallyAutoAimed();
			}
			else if ((Object)(object)i.GunInputs != (Object)null)
			{
				value.Aim = AimDirRef.Invoke(i.GunInputs);
			}
			AutoWaterer[] componentsInChildren = ((Component)i).GetComponentsInChildren<AutoWaterer>();
			foreach (AutoWaterer val in componentsInChildren)
			{
				WaterStreamEndAttachment val2 = WaterTargetRef.Invoke(val);
				CropViewItem val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<CropViewItem>() : null);
				CropModel val4 = (((Object)(object)val3 != (Object)null) ? val3.GetModel() : null);
				if (val4 != null)
				{
					value.Watering = true;
					value.WaterCoord = val4.Coord;
					break;
				}
			}
			PlayerMoveInputs moveInputs = i.GetMoveInputs();
			if ((Object)(object)moveInputs != (Object)null)
			{
				value.IsMoving = moveInputs.IsMoving();
				value.Velocity = moveInputs.GetCurrentVelocity();
			}
			PlayerGridWorkController gridWorkController = i.GetGridWorkController();
			if ((Object)(object)gridWorkController != (Object)null && gridWorkController.IsDoingWork())
			{
				value.Work = (byte)gridWorkController.GetWorkType();
				IPlayerGridWorkItem val5 = CurrentWorkItemRef.Invoke(gridWorkController);
				if (val5 != null)
				{
					value.WorkCoord = val5.GetCoord();
				}
			}
			if (RunSyncState.LocalDowned || i.IsDead())
			{
				value.Flags |= 1;
			}
			PlayerGunController componentInChildren = ((Component)i).GetComponentInChildren<PlayerGunController>();
			IPlayerGun val6 = ((componentInChildren != null) ? componentInChildren.GetCurrentGun() : null);
			if (val6 != null && val6.IsTriggerDown())
			{
				value.Flags |= 4;
			}
			if (LiveParams.Player.IsFlying)
			{
				value.Flags |= 8;
			}
			if ((Object)(object)gridWorkController != (Object)null && gridWorkController.IsEnergized())
			{
				value.Flags |= 16;
			}
			if (IsBlinkingRef.Invoke(i))
			{
				value.Flags |= 32;
			}
			if ((Object)(object)i.InvincibilityGraphic != (Object)null && i.InvincibilityGraphic.activeSelf)
			{
				value.Flags |= 64;
			}
			if (RunSync.CurrentSceneKind() != SceneKind.None)
			{
				value.Flags |= 2;
			}
			PlayerHorseController componentInChildren2 = ((Component)i).GetComponentInChildren<PlayerHorseController>();
			if ((Object)(object)componentInChildren2 != (Object)null && componentInChildren2.IsMounted())
			{
				value.Mount = 1;
			}
			GameData data = CoopState.Data;
			if ((Object)(object)data != (Object)null && data.PlayerHealth != null && data.PlayerMaxHealth != null)
			{
				value.Health = (byte)Mathf.Clamp(data.PlayerHealth.Get(), 0, 255);
				value.MaxHealth = (byte)Mathf.Clamp(data.PlayerMaxHealth.Get(), 0, 255);
			}
			return value;
		}

		private void OnGUI()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			DrawPartnerNameTag();
			DrawCenterMessages();
			if (_showOverlay)
			{
				AtomiStyle.Ensure();
				bool loaded = AtomiStyle.Loaded;
				int num = ((!loaded) ? 1 : AtomiStyle.Scale);
				Matrix4x4 matrix = GUI.matrix;
				GUI.matrix = Matrix4x4.Scale(new Vector3((float)num, (float)num, 1f));
				float num2 = (loaded ? 236f : 300f);
				GUILayout.BeginArea(new Rect(6f, 6f, num2, (float)Screen.height / (float)num - 12f), GUIStyle.none);
				GUILayout.BeginVertical(loaded ? AtomiStyle.Panel : GUI.skin.box, Array.Empty<GUILayoutOption>());
				Title("ATOMICROPS ONLINE");
				Small(Loc.F("v{0}   ·   F8 esconde", "0.8.0"));
				if (_patchFailures > 0)
				{
					Small("<color=#FF6B5B>" + Loc.F("{0} patch(es) falharam — veja o LogOutput.log", _patchFailures) + "</color>");
				}
				Section();
				DrawNetPanel();
				GUILayout.EndVertical();
				GUILayout.EndArea();
				GUI.matrix = matrix;
			}
		}

		private static void Title(string text)
		{
			GUILayout.Label(text, AtomiStyle.Loaded ? AtomiStyle.Title : GUI.skin.label, Array.Empty<GUILayoutOption>());
		}

		private static void Text(string text)
		{
			GUILayout.Label(Loc.T(text), AtomiStyle.Loaded ? AtomiStyle.Label : GUI.skin.label, Array.Empty<GUILayoutOption>());
		}

		private static void Small(string text)
		{
			GUILayout.Label(Loc.T(text), AtomiStyle.Loaded ? AtomiStyle.Small : GUI.skin.label, Array.Empty<GUILayoutOption>());
		}

		private static void Section()
		{
			GUILayout.Space((float)(AtomiStyle.Loaded ? 4 : 6));
		}

		private static string Lime(string s)
		{
			return "<color=#CAEE00>" + s + "</color>";
		}

		private static string StatusText(NetStatus st)
		{
			return st switch
			{
				NetStatus.Offline => "desconectado", 
				NetStatus.WaitingForPlayer => "esperando o parceiro", 
				NetStatus.Connected => "conectado", 
				_ => st.ToString(), 
			};
		}

		private void DrawNetPanel()
		{
			NetSession session = Session;
			if (session == null)
			{
				Text("Aguardando a Steam...");
				return;
			}
			switch (session.Status)
			{
			case NetStatus.Offline:
				if (AtomiStyle.Btn("Hospedar partida (Steam)"))
				{
					session.Host();
				}
				Small("Para entrar: aceite o convite do seu amigo na Steam.");
				Section();
				if (AtomiStyle.Btn(Loc.F("Hospedar por IP (porta {0})", DirectPort.Value)))
				{
					session.HostDirect(DirectPort.Value);
				}
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				_joinAddressField = (AtomiStyle.Loaded ? GUILayout.TextField(_joinAddressField ?? "", AtomiStyle.Field, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }) : GUILayout.TextField(_joinAddressField ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(200f) }));
				if (AtomiStyle.Btn("Entrar", GUILayout.Width((float)(AtomiStyle.Loaded ? 60 : 90))))
				{
					JoinDirect(_joinAddressField);
				}
				GUILayout.EndHorizontal();
				break;
			case NetStatus.WaitingForPlayer:
				if (!string.IsNullOrEmpty(session.LastMessage))
				{
					Text(session.LastMessage);
				}
				if (!session.IsDirect && AtomiStyle.Btn("Convidar amigo (Steam)"))
				{
					session.InviteFriend();
				}
				if (AtomiStyle.Btn(session.IsDirect ? "Parar de hospedar" : "Fechar lobby"))
				{
					session.Leave();
				}
				break;
			case NetStatus.Connected:
				Text(string.Format("{0}  {1}   {2} {3:F0} ms", Lime(Loc.T("Parceiro")), session.PeerName, Lime("Ping"), session.PingMs));
				Small(DescribeRole());
				if (CoopState.IsClient && RunSync.CurrentSceneKind() == SceneKind.Farm && Check != null && !string.IsNullOrEmpty(Check.Status))
				{
					Small("<color=#FF6B5B>" + Loc.F("Diferente do host: {0}", Check.Status) + "</color>");
				}
				if (AtomiStyle.Btn("Desconectar"))
				{
					session.Leave();
				}
				break;
			default:
				if (!string.IsNullOrEmpty(session.LastMessage))
				{
					Text(session.LastMessage);
				}
				if (AtomiStyle.Btn("Cancelar"))
				{
					session.Leave();
				}
				break;
			}
		}

		private void JoinDirect(string text)
		{
			text = (text ?? "").Trim();
			if (text.Length != 0)
			{
				string address = text;
				int port = DirectPort.Value;
				int num = text.LastIndexOf(':');
				if (num > 0 && int.TryParse(text.Substring(num + 1), out var result))
				{
					address = text.Substring(0, num);
					port = result;
				}
				JoinAddress.Value = text;
				Session.JoinDirect(address, port);
			}
		}

		private static string DescribeRole()
		{
			if (CoopState.IsHost)
			{
				if (RunSyncState.PartnerInSameScene)
				{
					return "Você é o host. Parceiro no mesmo mundo.";
				}
				if (!GameStateManagerInRun())
				{
					return "Você é o host. Inicie ou continue uma partida.";
				}
				return "Você é o host. Aguardando o parceiro carregar.";
			}
			if (CoopState.ClientInRun)
			{
				if (!RunSync.ClientSceneReady)
				{
					return "Carregando o mundo do host...";
				}
				return "Convidado no mundo do host.";
			}
			return "Convidado: aguardando o host entrar numa partida.";
		}

		private static bool GameStateManagerInRun()
		{
			try
			{
				return RunSync.CurrentSceneKind() != SceneKind.None;
			}
			catch (Exception)
			{
				return false;
			}
		}

		private static void DrawCenterMessages()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			string text = ((Run != null) ? Loc.T(Run.StatusText) : "");
			string text2 = ((Time.unscaledTime < _toastUntil) ? Loc.T(_toast) : "");
			if (!string.IsNullOrEmpty(text) || !string.IsNullOrEmpty(text2))
			{
				GUIStyle style = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4,
					fontStyle = (FontStyle)1,
					fontSize = 18,
					wordWrap = true
				};
				float num = (float)Screen.height * 0.18f;
				if (!string.IsNullOrEmpty(text))
				{
					DrawShadowed(new Rect(0f, num, (float)Screen.width, 30f), text, style);
				}
				if (!string.IsNullOrEmpty(text2))
				{
					DrawShadowed(new Rect(0f, num + 32f, (float)Screen.width, 30f), text2, style);
				}
			}
		}

		private static void DrawShadowed(Rect rect, string text, GUIStyle style)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			GUI.color = Color.black;
			GUI.Label(new Rect(((Rect)(ref rect)).x + 2f, ((Rect)(ref rect)).y + 2f, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height), text, style);
			GUI.color = new Color(1f, 0.92f, 0.4f);
			GUI.Label(rect, text, style);
			GUI.color = Color.white;
		}

		private static void DrawPartnerNameTag()
		{
			RemotePlayer remotePlayer = Players?.RemotePlayer;
			if (!((Object)(object)remotePlayer == (Object)null))
			{
				string text = (string.IsNullOrEmpty(Session?.PeerName) ? "Parceiro" : Session.PeerName);
				if (Session != null && Session.HasRemoteState && Session.RemoteState.IsDowned)
				{
					text += " (caído)";
				}
				remotePlayer.SetNameTag(text);
			}
		}

		internal static void LogPlayerFxState(string when)
		{
			try
			{
				PlayerComp i = SingletonSceneScope<PlayerComp>.I;
				if ((Object)(object)i == (Object)null)
				{
					return;
				}
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append($"[Diag] {when}: voando={LiveParams.Player.IsFlying}, " + $"invencível={i.IfIsInNonDamageInvincible()}, efeitos ligados:");
				Renderer[] componentsInChildren = ((Component)i).GetComponentsInChildren<Renderer>(false);
				foreach (Renderer val in componentsInChildren)
				{
					string name = ((Object)((Component)val).gameObject).name;
					if (name.IndexOf("Wing", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Shield", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Aura", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Invincib", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Boost", StringComparison.OrdinalIgnoreCase) >= 0 || val is ParticleSystemRenderer)
					{
						stringBuilder.Append(' ').Append(name).Append(val.enabled ? "" : "(off)");
					}
				}
				GameData data = CoopState.Data;
				object obj;
				if (data == null)
				{
					obj = null;
				}
				else
				{
					UpgradesCollection upgrades = data.Upgrades;
					obj = ((upgrades != null) ? upgrades.GetCollection() : null);
				}
				List<UpgradeDef> list = (List<UpgradeDef>)obj;
				if (list != null)
				{
					stringBuilder.Append(" | upgrades:");
					foreach (UpgradeDef item in list)
					{
						if ((Object)(object)item != (Object)null)
						{
							stringBuilder.Append(' ').Append(((Object)item).name);
						}
					}
				}
				Log.LogInfo((object)stringBuilder.ToString());
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[Diag] " + ex.Message));
			}
		}

		private static void DumpPlayerHierarchy()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			PlayerComp i = SingletonSceneScope<PlayerComp>.I;
			if ((Object)(object)i == (Object)null)
			{
				Log.LogInfo((object)"[Dump] Nenhum jogador ativo.");
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			string name = ((Object)i).name;
			Scene activeScene = SceneManager.GetActiveScene();
			stringBuilder.AppendLine($"[Dump] Jogador '{name}' na cena {((Scene)(ref activeScene)).name} ({CurrentScene()})");
			DumpTransform(((Component)i).transform, 0, stringBuilder);
			Log.LogInfo((object)stringBuilder.ToString());
		}

		private static void DumpTransform(Transform t, int depth, StringBuilder sb)
		{
			sb.Append(' ', depth * 2).Append(((Component)t).gameObject.activeSelf ? "+ " : "- ").Append(((Object)t).name)
				.Append("  [");
			Component[] components = ((Component)t).GetComponents<Component>();
			foreach (Component val in components)
			{
				if (!((Object)(object)val == (Object)null) && !(val is Transform))
				{
					sb.Append(((object)val).GetType().Name).Append(", ");
				}
			}
			sb.AppendLine("]");
			for (int j = 0; j < t.childCount; j++)
			{
				DumpTransform(t.GetChild(j), depth + 1, sb);
			}
		}

		private static bool IsSteamReady()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CSteamID steamID = SteamUser.GetSteamID();
				return ((CSteamID)(ref steamID)).IsValid();
			}
			catch (Exception)
			{
				return false;
			}
		}

		private static string SteamStatus()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return $"{SteamFriends.GetPersonaName()} ({SteamUser.GetSteamID().m_SteamID})";
			}
			catch (Exception)
			{
				return "não inicializada";
			}
		}
	}
}
namespace AtomicropsOnline.Ui
{
	internal static class AtomiStyle
	{
		internal static readonly Color Lime = Color32.op_Implicit(new Color32((byte)202, (byte)238, (byte)0, byte.MaxValue));

		internal static readonly Color Green = Color32.op_Implicit(new Color32((byte)7, (byte)155, (byte)0, byte.MaxValue));

		internal static readonly Color Cream = Color32.op_Implicit(new Color32((byte)248, byte.MaxValue, (byte)191, byte.MaxValue));

		internal static readonly Color Pink = Color32.op_Implicit(new Color32((byte)238, (byte)81, (byte)210, byte.MaxValue));

		internal static readonly Color Night = Color32.op_Implicit(new Color32((byte)19, (byte)25, (byte)40, byte.MaxValue));

		internal static readonly Color Red = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)107, (byte)91, byte.MaxValue));

		internal static GUIStyle Panel;

		internal static GUIStyle Title;

		internal static GUIStyle Label;

		internal static GUIStyle Small;

		internal static GUIStyle Button;

		internal static GUIStyle Field;

		internal static GUIStyle Box;

		private static bool _tried;

		private static float _nextRetry;

		private static bool _pixelFontWhenLoaded;

		private static readonly Dictionary<Sprite, Texture2D> Cache = new Dictionary<Sprite, Texture2D>();

		private static SoundItem _select;

		internal static bool Loaded { get; private set; }

		internal static int Scale => Mathf.Max(1, Mathf.FloorToInt((float)Screen.height / 480f));

		internal static void Ensure()
		{
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			//IL_0180: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: 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_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Expected O, but got Unknown
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Expected O, but got Unknown
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Expected O, but got Unknown
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Expected O, but got Unknown
			//IL_02f0: Expected O, but got Unknown
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Expected O, but got Unknown
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Expected O, but got Unknown
			//IL_038c: Expected O, but got Unknown
			if (Loaded && _pixelFontWhenLoaded != Loc.PixelFontLanguage)
			{
				Loaded = false;
			}
			if (Loaded || (_tried && Time.unscaledTime < _nextRetry))
			{
				return;
			}
			_tried = true;
			_nextRetry = Time.unscaledTime + 3f;
			try
			{
				Font[] fonts = Resources.FindObjectsOfTypeAll<Font>();
				Sprite[] sprites = Resources.FindObjectsOfTypeAll<Sprite>();
				bool flag = (_pixelFontWhenLoaded = Loc.PixelFontLanguage);
				Font val = (flag ? Fnt(new string[2] { "Helvegica_White", "Helvegica" }) : null);
				Font val2 = (flag ? Fnt(new string[3] { "Atomitype_Gold", "Atomitype_White", "atomitype" }) : null);
				Font val3 = val;
				Sprite val4 = Spr("BackgroundPopupDialog");
				Sprite val5 = Spr("MenuItemBg");
				Spr("selectBg");
				Sprite val6 = Spr("DialogThinBordersGreenA") ?? Spr("InfoRegionBackground");
				if ((!flag || !((Object)(object)val == (Object)null)) && !((Object)(object)val4 == (Object)null) && !((Object)(object)val5 == (Object)null))
				{
					GUIStyle val7 = new GUIStyle(GUI.skin.box);
					val7.normal.background = TexOf(val4);
					val7.normal.textColor = Cream;
					val7.border = BorderOf(val4);
					val7.padding = new RectOffset(14, 14, 12, 14);
					Panel = val7;
					Title = Text(val2 ?? val, Lime);
					Label = Text(val, Cream);
					Label.wordWrap = true;
					Small = Text(val3 ?? val, Cream);
					Small.wordWrap = true;
					Button = new GUIStyle(GUI.skin.button)
					{
						font = val,
						alignment = (TextAnchor)4,
						border = BorderOf(val5),
						padding = new RectOffset(6, 6, 4, 5),
						margin = new RectOffset(2, 2, 2, 2),
						richText = true
					};
					Texture2D val8 = TexOf(val5);
					Texture2D background = val8;
					Button.normal.background = val8;
					Button.normal.textColor = Cream;
					Button.hover.background = background;
					Button.hover.textColor = Night;
					Button.active.background = background;
					Button.active.textColor = Night;
					Button.focused.background = val8;
					Button.focused.textColor = Cream;
					Field = new GUIStyle(GUI.skin.textField)
					{
						font = val,
						padding = new RectOffset(5, 5, 3, 4)
					};
					if ((Object)(object)val6 != (Object)null)
					{
						Field.normal.background = TexOf(val6);
						Field.focused.background = TexOf(val6);
						Field.border = BorderOf(val6);
					}
					Field.normal.textColor = Cream;
					Field.focused.textColor = Lime;
					Box = new GUIStyle(GUIStyle.none)
					{
						padding = new RectOffset(6, 6, 5, 6),
						margin = new RectOffset(0, 0, 3, 3)
					};
					if ((Object)(object)val6 != (Object)null)
					{
						Box.normal.background = TexOf(val6);
						Box.border = BorderOf(val6);
					}
					Loaded = true;
					Plugin.Log.LogInfo((object)("[UI] Visual do jogo carregado (fonte " + ((Object)val).name + ", títulos " + (((Object)(object)val2 != (Object)null) ? ((Object)val2).name : "-") + ")."));
				}
				Font Fnt(params string[] names)
				{
					return names.Select((string n) => ((IEnumerable<Font>)fonts).FirstOrDefault((Func<Font, bool>)((Font f) => (Object)(object)f != (Object)null && ((Object)f).name == n))).FirstOrDefault<Font>((Func<Font, bool>)((Font f) => (Object)(object)f != (Object)null));
				}
				Sprite Spr(string name)
				{
					return ((IEnumerable<Sprite>)sprites).FirstOrDefault((Func<Sprite, bool>)((Sprite s) => (Object)(object)s != (Object)null && ((Object)s).name == name));
				}
			}
			catch (Exception ex)
			{
				Plugin.LogOnce("ui-style", "[UI] Não deu para usar o visual do jogo: " + ex.Message);
			}
		}

		private static GUIStyle Text(Font f, Color c)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0048: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				font = f,
				richText = true
			};
			val.normal.textColor = c;
			val.padding = new RectOffset(0, 0, 1, 1);
			val.margin = new RectOffset(0, 0, 2, 2);
			return val;
		}

		private static RectOffset BorderOf(Sprite s)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			Vector4 border = s.border;
			return new RectOffset((int)border.x, (int)border.z, (int)border.w, (int)border.y);
		}

		private static Texture2D TexOf(Sprite s)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			if (Cache.TryGetValue(s, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Texture2D texture = s.texture;
			Rect textureRect = s.textureRect;
			if (Mathf.Approximately(((Rect)(ref textureRect)).width, (float)((Texture)texture).width) && Mathf.Approximately(((Rect)(ref textureRect)).height, (float)((Texture)texture).height))
			{
				((Texture)texture).filterMode = (FilterMode)0;
				return Cache[s] = texture;
			}
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			Graphics.Blit((Texture)(object)texture, temporary);
			RenderTexture.active = temporary;
			value = new Texture2D((int)((Rect)(ref textureRect)).width, (int)((Rect)(ref textureRect)).height, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0
			};
			value.ReadPixels(new Rect(((Rect)(ref textureRect)).x, ((Rect)(ref textureRect)).y, ((Rect)(ref textureRect)).width, ((Rect)(ref textureRect)).height), 0, 0);
			value.Apply();
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return Cache[s] = value;
		}

		private static Texture2D Tinted(Sprite s, Color tint)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			Texture2D texture = s.texture;
			Rect textureRect = s.textureRect;
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			Graphics.Blit((Texture)(object)texture, temporary);
			RenderTexture.active = temporary;
			Texture2D val = new Texture2D((int)((Rect)(ref textureRect)).width, (int)((Rect)(ref textureRect)).height, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0
			};
			val.ReadPixels(new Rect(((Rect)(ref textureRect)).x, (float)((Texture)texture).height - ((Rect)(ref textureRect)).y - ((Rect)(ref textureRect)).height, ((Rect)(ref textureRect)).width, ((Rect)(ref textureRect)).height), 0, 0);
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			Color[] pixels = val.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				pixels[i] = new Color(pixels[i].r * tint.r, pixels[i].g * tint.g, pixels[i].b * tint.b, pixels[i].a);
			}
			val.SetPixels(pixels);
			val.Apply();
			return val;
		}

		internal static void Click()
		{
			try
			{
				if (_select == null)
				{
					UfEvent obj = ScriptableObject.CreateInstance<UfEvent>();
					obj.Path = "event:/Menu/Select";
					_select = SoundItem.Create(obj);
				}
				Camera main = Camera.main;
				if ((Object)(object)main != (Object)null)
				{
					_select.PlayOneShot(((Component)main).transform);
				}
			}
			catch (Exception)
			{
			}
		}

		internal static bool Btn(string text, params GUILayoutOption[] opts)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0043: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			text = Loc.T(text);
			bool flag;
			if (Loaded)
			{
				GUIContent val = new GUIContent(text);
				Rect rect = GUILayoutUtility.GetRect(val, Button, opts);
				bool num = ((Rect)(ref rect)).Contains(Event.current.mousePosition);
				Color backgroundColor = GUI.backgroundColor;
				GUI.backgroundColor = (num ? Lime : Green);
				flag = GUI.Button(rect, val, Button);
				GUI.backgroundColor = backgroundColor;
			}
			else
			{
				flag = GUILayout.Button(text, opts);
			}
			if (flag)
			{
				Click();
			}
			return flag;
		}
	}
	internal static class Loc
	{
		private enum L
		{
			Pt,
			En,
			Es,
			Fr,
			De
		}

		private static readonly string[][] Table = new string[69][]
		{
			new string[5] { "Aguardando a Steam...", "Waiting for Steam...", "Esperando a Steam...", "En attente de Steam...", "Warte auf Steam..." },
			new string[5] { "Rede", "Network", "Red", "Réseau", "Netzwerk" },
			new string[5] { "Parceiro", "Partner",