Decompiled source of LethalCasinoTracker Plus v1.2.0

plugins/LethalCasinoTracker.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCasinoTracker.Patches;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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 LethalCasinoTracker
{
	public static class CasinoGameNames
	{
		public static string Display(CasinoGameType t)
		{
			return t switch
			{
				CasinoGameType.Blackjack => "Blackjack", 
				CasinoGameType.Roulette => "Roulette", 
				CasinoGameType.Slots => "Slots", 
				CasinoGameType.Wheel => "The Wheel", 
				CasinoGameType.Mines => "Mines", 
				CasinoGameType.Crash => "Crash", 
				CasinoGameType.HiLo => "Hi-Lo", 
				CasinoGameType.Towers => "Towers", 
				CasinoGameType.Plinko => "Plinko", 
				CasinoGameType.Dice => "Dice", 
				CasinoGameType.CoinFlip => "Coin Flip", 
				CasinoGameType.FortuneWheel => "Fortune Wheel", 
				CasinoGameType.KeyMaster => "Key Master", 
				CasinoGameType.Cyclone => "Cyclone", 
				CasinoGameType.ClawMachine => "Claw Machine", 
				CasinoGameType.CoinPusher => "Coin Pusher", 
				CasinoGameType.Stacker => "Stacker", 
				CasinoGameType.NeonSteps => "Neon Steps", 
				_ => "Casino", 
			};
		}

		public static CasinoGameType FromTypeName(string typeName)
		{
			return typeName switch
			{
				"Blackjack" => CasinoGameType.Blackjack, 
				"Roulette" => CasinoGameType.Roulette, 
				"SlotMachine" => CasinoGameType.Slots, 
				"TheWheel" => CasinoGameType.Wheel, 
				_ => CasinoGameType.Unknown, 
			};
		}

		public static CasinoGameType FromPlusMachine(int machine)
		{
			return machine switch
			{
				0 => CasinoGameType.Mines, 
				1 => CasinoGameType.Crash, 
				2 => CasinoGameType.HiLo, 
				3 => CasinoGameType.Towers, 
				4 => CasinoGameType.Plinko, 
				5 => CasinoGameType.Dice, 
				6 => CasinoGameType.CoinFlip, 
				11 => CasinoGameType.FortuneWheel, 
				12 => CasinoGameType.KeyMaster, 
				13 => CasinoGameType.Cyclone, 
				14 => CasinoGameType.ClawMachine, 
				15 => CasinoGameType.CoinPusher, 
				16 => CasinoGameType.Stacker, 
				17 => CasinoGameType.NeonSteps, 
				_ => CasinoGameType.Unknown, 
			};
		}
	}
	public enum CasinoGameType
	{
		Unknown,
		Blackjack,
		Roulette,
		Slots,
		Wheel,
		Mines,
		Crash,
		HiLo,
		Towers,
		Plinko,
		Dice,
		CoinFlip,
		FortuneWheel,
		KeyMaster,
		Cyclone,
		ClawMachine,
		CoinPusher,
		Stacker,
		NeonSteps
	}
	public static class CasinoHooks
	{
		public struct ScrapCapture
		{
			public bool valid;

			public GrabbableObject grab;

			public int before;
		}

		public struct PlusSettleState
		{
			public bool valid;

			public ulong owner;

			public int originalValue;

			public CasinoGameType game;

			public int machineId;
		}

		public static readonly string[] GameTypeNames = new string[4] { "Blackjack", "Roulette", "SlotMachine", "TheWheel" };

		private static readonly Dictionary<string, FieldInfo> _fieldCache = new Dictionary<string, FieldInfo>();

		private static readonly Dictionary<GrabbableObject, int> _lastValue = new Dictionary<GrabbableObject, int>();

		private static readonly Dictionary<long, int> _ticketMachines = new Dictionary<long, int>();

		private static bool _hasActiveWheelPrizeOwner;

		private static ulong _activeWheelPrizeOwner;

		public static void ResetValueTracking()
		{
			_lastValue.Clear();
			_ticketMachines.Clear();
			_hasActiveWheelPrizeOwner = false;
		}

		public static void ScrapPrefix(NetworkBehaviourReference item, out ScrapCapture __state)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			__state = default(ScrapCapture);
			try
			{
				GrabbableObject val = null;
				if (((NetworkBehaviourReference)(ref item)).TryGet<GrabbableObject>(ref val, (NetworkManager)null) && (Object)val != (Object)null)
				{
					__state.valid = true;
					__state.grab = val;
					__state.before = val.scrapValue;
				}
			}
			catch
			{
			}
		}

		public static void ScrapPostfix(object __instance, int newValue, ScrapCapture __state)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			if (!__state.valid || (Object)__state.grab == (Object)null || !TrackerManager.IsServer())
			{
				return;
			}
			try
			{
				GrabbableObject grab = __state.grab;
				int scrapValue = grab.scrapValue;
				if (!_lastValue.TryGetValue(grab, out var value))
				{
					value = __state.before;
				}
				int num = scrapValue - value;
				_lastValue[grab] = scrapValue;
				string name = __instance.GetType().Name;
				if (Plugin.VerboseLogging)
				{
					Plugin.Log.LogInfo((object)("[bet] " + name + " baseline=" + value + " after=" + scrapValue + " newArg=" + newValue + " orig=" + ReadOriginal(grab) + " delta=" + num));
				}
				if (num == 0)
				{
					return;
				}
				CasinoGameType game = CasinoGameNames.FromTypeName(name);
				PlayerControllerB val = ResolveOwner(__instance, name, grab);
				if ((Object)val == (Object)null)
				{
					if (Plugin.VerboseLogging)
					{
						Plugin.Log.LogWarning((object)("Could not resolve owner for a " + name + " payout of " + num));
					}
					return;
				}
				int gameInstanceId = 0;
				Object val2 = (Object)((__instance is Object) ? __instance : null);
				if (val2 != (Object)null)
				{
					gameInstanceId = val2.GetInstanceID();
				}
				RecordForPlayer(val, num, game, gameInstanceId);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Casino capture error: " + ex.Message));
			}
		}

		private static PlayerControllerB ResolveOwner(object inst, string typeName, GrabbableObject grab)
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected O, but got Unknown
			Type type = inst.GetType();
			switch (typeName)
			{
			case "Blackjack":
			{
				List<GrabbableObject>[] array = GetField(type, "gambledScrap").GetValue(inst) as List<GrabbableObject>[];
				PlayerControllerB[] array2 = GetField(type, "gamblingPlayers").GetValue(inst) as PlayerControllerB[];
				if (array == null || array2 == null)
				{
					return null;
				}
				int num = Math.Min(array.Length, array2.Length);
				for (int i = 0; i < num; i++)
				{
					if (array[i] != null && array[i].Contains(grab))
					{
						return array2[i];
					}
				}
				return null;
			}
			case "Roulette":
			{
				if (GetField(type, "gambledScrapOwners").GetValue(inst) is Dictionary<GrabbableObject, PlayerControllerB> dictionary && dictionary.TryGetValue(grab, out var value2))
				{
					return value2;
				}
				return null;
			}
			case "SlotMachine":
			case "TheWheel":
			{
				FieldInfo field = GetField(type, "gamblingPlayer");
				if (!(field == null))
				{
					object value = field.GetValue(inst);
					return (PlayerControllerB)((value is PlayerControllerB) ? value : null);
				}
				return null;
			}
			default:
				return null;
			}
		}

		private static int ReadOriginal(GrabbableObject grab)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			try
			{
				Type type = AccessTools.TypeByName("LethalCasino.Custom.CustomScrapController");
				if (type == null)
				{
					return -1;
				}
				Component component = ((Component)grab).GetComponent(type);
				if ((Object)component == (Object)null)
				{
					return -1;
				}
				FieldInfo field = GetField(type, "originalScrapValue");
				if (field == null)
				{
					return -1;
				}
				object value = field.GetValue(component);
				return (value is int) ? ((int)value) : (-1);
			}
			catch
			{
				return -1;
			}
		}

		public static void PlusReservePostfix(object request, object __result)
		{
			if (!TrackerManager.IsServer() || request == null || __result == null)
			{
				return;
			}
			try
			{
				long num = Convert.ToInt64(GetField(__result.GetType(), "Ticket")?.GetValue(__result) ?? ((object)0L));
				int num2 = Convert.ToInt32(GetField(request.GetType(), "Machine")?.GetValue(request) ?? ((object)(-1)));
				if (num > 0 && num2 >= 0)
				{
					_ticketMachines[num] = num2;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("CasinoPlus Reserve capture error: " + ex.Message));
			}
		}

		public static void PlusSettlePrefix(object __instance, long ticket, out PlusSettleState __state)
		{
			__state = default(PlusSettleState);
			if (!TrackerManager.IsServer() || __instance == null)
			{
				return;
			}
			try
			{
				object obj = GetField(__instance.GetType(), "ledger")?.GetValue(__instance);
				if (obj == null || !(GetField(obj.GetType(), "tickets")?.GetValue(obj) is IDictionary dictionary) || !dictionary.Contains(ticket))
				{
					return;
				}
				object obj2 = dictionary[ticket];
				if (obj2 != null)
				{
					Type type = obj2.GetType();
					__state.valid = true;
					__state.owner = Convert.ToUInt64(GetField(type, "Owner")?.GetValue(obj2) ?? ((object)0uL));
					__state.originalValue = Convert.ToInt32(GetField(type, "OriginalValue")?.GetValue(obj2) ?? ((object)0));
					if (_ticketMachines.TryGetValue(ticket, out var value))
					{
						__state.machineId = value;
						__state.game = CasinoGameNames.FromPlusMachine(value);
					}
					else
					{
						__state.machineId = 99;
						__state.game = CasinoGameType.Unknown;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("CasinoPlus Settle prefix error: " + ex.Message));
			}
			finally
			{
				_ticketMachines.Remove(ticket);
			}
		}

		public static void PlusSettlePostfix(object __result, PlusSettleState __state)
		{
			if (!__state.valid || __result == null || !TrackerManager.IsServer())
			{
				return;
			}
			try
			{
				object obj = GetField(__result.GetType(), "Wager")?.GetValue(__result);
				if (obj != null)
				{
					int num = Convert.ToInt32(GetField(obj.GetType(), "SettledValue")?.GetValue(obj) ?? ((object)0));
					int num2 = num - __state.originalValue;
					if (Plugin.VerboseLogging)
					{
						Plugin.Log.LogInfo((object)("[CasinoPlus] Settle " + CasinoGameNames.Display(__state.game) + " owner=" + __state.owner + " orig=" + __state.originalValue + " settled=" + num + " delta=" + num2));
					}
					if (num2 != 0)
					{
						RecordForActualClientId(__state.owner, num2, __state.game, 90000 + __state.machineId);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("CasinoPlus Settle postfix error: " + ex.Message));
			}
		}

		public static void PlusArcadeOutcomePostfix(object outcome, bool __result)
		{
			if (!__result || outcome == null || !TrackerManager.IsServer())
			{
				return;
			}
			try
			{
				Type type = outcome.GetType();
				bool flag = Convert.ToBoolean(GetField(type, "Won")?.GetValue(outcome) ?? ((object)false));
				bool flag2 = Convert.ToBoolean(GetField(type, "Refunded")?.GetValue(outcome) ?? ((object)false));
				int num = Convert.ToInt32(GetField(type, "PrizeValue")?.GetValue(outcome) ?? ((object)0));
				if (!(!flag || flag2) && num > 0)
				{
					int num2 = Convert.ToInt32(GetField(type, "Machine")?.GetValue(outcome) ?? ((object)(-1)));
					ulong actualClientId = Convert.ToUInt64(GetField(type, "Owner")?.GetValue(outcome) ?? ((object)0uL));
					CasinoGameType casinoGameType = CasinoGameNames.FromPlusMachine(num2);
					if (Plugin.VerboseLogging)
					{
						Plugin.Log.LogInfo((object)("[CasinoPlus] Arcade prize " + CasinoGameNames.Display(casinoGameType) + " owner=" + actualClientId + " prizeValue=" + num));
					}
					RecordForActualClientId(actualClientId, num, casinoGameType, 90000 + num2);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("CasinoPlus Arcade prize error: " + ex.Message));
			}
		}

		public static void PlusWheelTryPrizePrefix(object __instance)
		{
			if (!TrackerManager.IsServer() || __instance == null)
			{
				return;
			}
			try
			{
				object obj = GetField(__instance.GetType(), "state")?.GetValue(__instance);
				if (obj != null)
				{
					_activeWheelPrizeOwner = Convert.ToUInt64(GetField(obj.GetType(), "Owner")?.GetValue(obj) ?? ((object)0uL));
					_hasActiveWheelPrizeOwner = true;
				}
			}
			catch
			{
				_hasActiveWheelPrizeOwner = false;
			}
		}

		public static void PlusWheelTryPrizePostfix()
		{
			_hasActiveWheelPrizeOwner = false;
		}

		public static void PlusRewardSpawnPostfix(int value, bool __result)
		{
			if (__result && _hasActiveWheelPrizeOwner && value > 0 && TrackerManager.IsServer())
			{
				if (Plugin.VerboseLogging)
				{
					Plugin.Log.LogInfo((object)("[CasinoPlus] Fortune Wheel spawned prize value=" + value + " owner=" + _activeWheelPrizeOwner));
				}
				RecordForActualClientId(_activeWheelPrizeOwner, value, CasinoGameType.FortuneWheel, 90011);
			}
		}

		public static void PlusCreditPusherPostfix(ulong owner, int amount, bool __result)
		{
			if (__result && amount > 0 && TrackerManager.IsServer())
			{
				if (Plugin.VerboseLogging)
				{
					Plugin.Log.LogInfo((object)("[CasinoPlus] Coin Pusher payout amount=" + amount + " owner=" + owner));
				}
				RecordForActualClientId(owner, amount, CasinoGameType.CoinPusher, 90015);
			}
		}

		public static void PlusCoinPlayPrefix(ulong sender, out int __state)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			__state = -1;
			if (!TrackerManager.IsServer())
			{
				return;
			}
			try
			{
				PlayerControllerB val = FindPlayerByActualClientId(sender);
				if ((Object)val != (Object)null && (Object)val.currentlyHeldObjectServer != (Object)null)
				{
					__state = val.currentlyHeldObjectServer.scrapValue;
				}
			}
			catch
			{
			}
		}

		public static void PlusCoinPlayPostfix(ulong sender, int __state)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			if (__state < 0 || !TrackerManager.IsServer())
			{
				return;
			}
			try
			{
				PlayerControllerB val = FindPlayerByActualClientId(sender);
				if ((Object)val != (Object)null && (Object)val.currentlyHeldObjectServer != (Object)null)
				{
					int num = val.currentlyHeldObjectServer.scrapValue - __state;
					if (num < 0)
					{
						RecordForPlayer(val, num, CasinoGameType.CoinPusher, 90015);
					}
				}
			}
			catch
			{
			}
		}

		private static PlayerControllerB FindPlayerByActualClientId(ulong actualClientId)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			if ((Object)StartOfRound.Instance == (Object)null || StartOfRound.Instance.allPlayerScripts == null)
			{
				return null;
			}
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if ((Object)val != (Object)null && val.actualClientId == actualClientId)
				{
					return val;
				}
			}
			return null;
		}

		private static void RecordForActualClientId(ulong actualClientId, int delta, CasinoGameType game, int gameInstanceId)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			if (delta != 0)
			{
				PlayerControllerB val = FindPlayerByActualClientId(actualClientId);
				if ((Object)val != (Object)null)
				{
					RecordForPlayer(val, delta, game, gameInstanceId);
				}
				else if ((Object)TrackerManager.Instance != (Object)null)
				{
					string username = "Player " + actualClientId;
					TrackerManager.Instance.RecordResolution(actualClientId, username, delta, game, gameInstanceId);
					NetworkSync.BroadcastDelta(actualClientId, username, delta, game, gameInstanceId);
				}
			}
		}

		private static void RecordForPlayer(PlayerControllerB player, int delta, CasinoGameType game, int gameInstanceId)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			if (delta != 0 && !((Object)player == (Object)null))
			{
				ulong playerClientId = player.playerClientId;
				string playerUsername = player.playerUsername;
				if ((Object)TrackerManager.Instance != (Object)null)
				{
					TrackerManager.Instance.RecordResolution(playerClientId, playerUsername, delta, game, gameInstanceId);
				}
				NetworkSync.BroadcastDelta(playerClientId, playerUsername, delta, game, gameInstanceId);
			}
		}

		private static FieldInfo GetField(Type t, string name)
		{
			string key = t.FullName + "." + name;
			if (!_fieldCache.TryGetValue(key, out var value))
			{
				value = AccessTools.Field(t, name);
				_fieldCache[key] = value;
			}
			return value;
		}

		public static void ApplyPatches(Harmony h)
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00bc: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(CasinoHooks), "ScrapPrefix", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(CasinoHooks), "ScrapPostfix", (Type[])null, (Type[])null);
			for (int i = 0; i < GameTypeNames.Length; i++)
			{
				string text = "LethalCasino.Custom." + GameTypeNames[i];
				Type type = AccessTools.TypeByName(text);
				if (type == null)
				{
					Plugin.Log.LogWarning((object)("Casino type not found: " + text));
					continue;
				}
				MethodInfo methodInfo3 = AccessTools.Method(type, "UpdateScrapValueClientRpc", (Type[])null, (Type[])null);
				if (methodInfo3 == null)
				{
					Plugin.Log.LogWarning((object)("UpdateScrapValueClientRpc not found on " + text));
					continue;
				}
				try
				{
					h.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo), new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					Plugin.Log.LogInfo((object)("Patched " + GameTypeNames[i] + ".UpdateScrapValueClientRpc"));
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)("Failed to patch " + text + ": " + ex.Message));
				}
			}
			ApplyCasinoPlusPatches(h);
		}

		private static void ApplyCasinoPlusPatches(Harmony h)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00ba: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_01c8: Expected O, but got Unknown
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Expected O, but got Unknown
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Expected O, but got Unknown
			//IL_0298: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("LethalCasinoPlus.ScrapController");
			if (type == null)
			{
				Plugin.Log.LogInfo((object)"LethalCasinoPlus not detected; skipping CasinoPlus hooks.");
				return;
			}
			try
			{
				MethodInfo methodInfo = AccessTools.Method(type, "ReserveCore", (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(CasinoHooks), "PlusReservePostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				MethodInfo methodInfo2 = AccessTools.Method(type, "Settle", (Type[])null, (Type[])null);
				if (methodInfo2 != null)
				{
					h.Patch((MethodBase)methodInfo2, new HarmonyMethod(AccessTools.Method(typeof(CasinoHooks), "PlusSettlePrefix", (Type[])null, (Type[])null)), new HarmonyMethod(AccessTools.Method(typeof(CasinoHooks), "PlusSettlePostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				MethodInfo methodInfo3 = AccessTools.Method(type, "CreditPusher", (Type[])null, (Type[])null);
				if (methodInfo3 != null)
				{
					h.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(CasinoHooks), "PlusCreditPusherPostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				Type type2 = AccessTools.TypeByName("LethalCasinoPlus.ArcadeRules");
				MethodInfo methodInfo4 = ((type2 == null) ? null : AccessTools.Method(type2, "TryConsume", (Type[])null, (Type[])null));
				if (methodInfo4 != null)
				{
					h.Patch((MethodBase)methodInfo4, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(CasinoHooks), "PlusArcadeOutcomePostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				Type type3 = AccessTools.TypeByName("LethalCasinoPlus.FortuneWheelController");
				MethodInfo methodInfo5 = ((type3 == null) ? null : AccessTools.Method(type3, "TryPrize", (Type[])null, (Type[])null));
				if (methodInfo5 != null)
				{
					h.Patch((MethodBase)methodInfo5, new HarmonyMethod(AccessTools.Method(typeof(CasinoHooks), "PlusWheelTryPrizePrefix", (Type[])null, (Type[])null)), new HarmonyMethod(AccessTools.Method(typeof(CasinoHooks), "PlusWheelTryPrizePostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				Type type4 = AccessTools.TypeByName("LethalCasinoPlus.CasinoRewards");
				MethodInfo methodInfo6 = ((type4 == null) ? null : AccessTools.Method(type4, "Spawn", (Type[])null, (Type[])null));
				if (methodInfo6 != null)
				{
					h.Patch((MethodBase)methodInfo6, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(CasinoHooks), "PlusRewardSpawnPostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				Type type5 = AccessTools.TypeByName("LethalCasinoPlus.CoinPusherController");
				MethodInfo methodInfo7 = ((type5 == null) ? null : AccessTools.Method(type5, "Play", (Type[])null, (Type[])null));
				if (methodInfo7 != null)
				{
					h.Patch((MethodBase)methodInfo7, new HarmonyMethod(AccessTools.Method(typeof(CasinoHooks), "PlusCoinPlayPrefix", (Type[])null, (Type[])null)), new HarmonyMethod(AccessTools.Method(typeof(CasinoHooks), "PlusCoinPlayPostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				Plugin.Log.LogInfo((object)"Patched LethalCasinoPlus ScrapController, ArcadeRules, FortuneWheelController, and CoinPusherController.");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Failed to patch LethalCasinoPlus: " + ex.Message));
			}
		}
	}
	public class ChalkboardController : MonoBehaviour
	{
		private Type _buildingType;

		private Component _building;

		private float _nextSearch;

		private GameObject _board;

		private TextMeshProUGUI _text;

		private bool _dirty = true;

		private void Start()
		{
			_buildingType = AccessTools.TypeByName("LethalCasino.Custom.CasinoBuilding");
			if (_buildingType == null)
			{
				Plugin.Log.LogWarning((object)"CasinoBuilding type not found; chalkboard disabled.");
			}
		}

		private void Update()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_012e: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			if (!Plugin.ChalkboardEnabled() || _buildingType == null)
			{
				return;
			}
			if ((Object)_building == (Object)null && Time.realtimeSinceStartup >= _nextSearch)
			{
				_nextSearch = Time.realtimeSinceStartup + 1.5f;
				Object val = Object.FindObjectOfType(_buildingType);
				_building = (Component)((val is Component) ? val : null);
				if ((Object)_building != (Object)null && (Object)_board == (Object)null)
				{
					BuildBoard();
				}
			}
			if ((Object)_building == (Object)null)
			{
				if ((Object)_board != (Object)null)
				{
					Object.Destroy((Object)_board);
					_board = null;
				}
			}
			else if (!((Object)_board == (Object)null))
			{
				Transform transform = _building.transform;
				_board.transform.position = transform.position + transform.right * Plugin.ChalkOffsetX() + Vector3.up * Plugin.ChalkOffsetY() + transform.forward * Plugin.ChalkOffsetZ();
				Vector3 forward = transform.forward;
				forward.y = 0f;
				if (((Vector3)(ref forward)).sqrMagnitude < 0.0001f)
				{
					forward = Vector3.forward;
				}
				_board.transform.rotation = Quaternion.AngleAxis(Plugin.ChalkYaw(), Vector3.up) * Quaternion.LookRotation(((Vector3)(ref forward)).normalized, Vector3.up);
				TrackerManager instance = TrackerManager.Instance;
				if ((Object)instance != (Object)null && (instance.RecordsDirty || _dirty))
				{
					RefreshText(instance);
					instance.RecordsDirty = false;
					_dirty = false;
				}
			}
		}

		private void OnDestroy()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if ((Object)_board != (Object)null)
			{
				Object.Destroy((Object)_board);
			}
		}

		private void BuildBoard()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			_board = new GameObject("LCCasinoChalkboard");
			_board.transform.localScale = Vector3.one * Plugin.ChalkScale();
			Canvas obj = _board.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)2;
			((Component)obj).GetComponent<RectTransform>().sizeDelta = new Vector2(520f, 360f);
			Image obj2 = LCStyle.Panel(_board.transform, new Color(0.05f, 0.08f, 0.06f, 0.96f));
			LCStyle.Stretch(((Graphic)obj2).rectTransform, 0f, 0f);
			RectTransform rectTransform = ((Graphic)LCStyle.Panel(((Component)obj2).transform, new Color(0.4f, 0.52f, 0.36f, 0.5f))).rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 1f);
			rectTransform.anchorMax = new Vector2(1f, 1f);
			rectTransform.pivot = new Vector2(0.5f, 1f);
			rectTransform.sizeDelta = new Vector2(0f, 3f);
			rectTransform.anchoredPosition = Vector2.zero;
			_text = LCStyle.Text(_board.transform, "Text", 22f, (TextAlignmentOptions)257, nativeGlow: false);
			((Graphic)_text).color = new Color(0.88f, 0.93f, 0.83f);
			LCStyle.Stretch(((TMP_Text)_text).rectTransform, 26f, 22f);
			_dirty = true;
			ManualLogSource log = Plugin.Log;
			Vector3 position = _building.transform.position;
			log.LogInfo((object)("Chalkboard spawned at casino " + ((Vector3)(ref position)).ToString("F1")));
		}

		private void RefreshText(TrackerManager tm)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0021: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)_text == (Object)null))
			{
				List<PlayerRunRecord> recordsSorted = tm.GetRecordsSorted();
				string value = LCStyle.Tag("------------------------------", LCStyle.Rule);
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append(LCStyle.Tag("ALL-TIME CASINO RECORDS", LCStyle.Header)).Append('\n');
				stringBuilder.Append(value).Append('\n');
				Color c = default(Color);
				((Color)(ref c))..ctor(0.88f, 0.93f, 0.83f);
				FindExtremes(recordsSorted, out var biggestWin, out var biggestLoss);
				stringBuilder.Append(LCStyle.Tag("BIGGEST WIN", LCStyle.Dim)).Append("<pos=38%>");
				if (biggestWin != null && biggestWin.biggestSingleWin > 0)
				{
					stringBuilder.Append(LCStyle.Tag(Trunc(biggestWin.username, 11), c)).Append("<pos=70%>").Append(LCStyle.Tag("+" + biggestWin.biggestSingleWin.ToString("N0"), LCStyle.Up));
				}
				else
				{
					stringBuilder.Append(LCStyle.Tag("-", LCStyle.Dim));
				}
				stringBuilder.Append('\n');
				stringBuilder.Append(LCStyle.Tag("BIGGEST LOSS", LCStyle.Dim)).Append("<pos=38%>");
				if (biggestLoss != null && biggestLoss.biggestSingleLoss > 0)
				{
					stringBuilder.Append(LCStyle.Tag(Trunc(biggestLoss.username, 11), c)).Append("<pos=70%>").Append(LCStyle.Tag("-" + biggestLoss.biggestSingleLoss.ToString("N0"), LCStyle.Down));
				}
				else
				{
					stringBuilder.Append(LCStyle.Tag("-", LCStyle.Dim));
				}
				stringBuilder.Append('\n');
				stringBuilder.Append(value).Append('\n');
				stringBuilder.Append(LCStyle.Tag("TOTAL GAMES", LCStyle.Dim)).Append("<pos=38%>").Append(tm.TotalGames());
				((TMP_Text)_text).text = stringBuilder.ToString();
			}
		}

		private static void FindExtremes(List<PlayerRunRecord> recs, out PlayerRunRecord biggestWin, out PlayerRunRecord biggestLoss)
		{
			biggestWin = null;
			biggestLoss = null;
			for (int i = 0; i < recs.Count; i++)
			{
				PlayerRunRecord playerRunRecord = recs[i];
				if (biggestWin == null || playerRunRecord.biggestSingleWin > biggestWin.biggestSingleWin)
				{
					biggestWin = playerRunRecord;
				}
				if (biggestLoss == null || playerRunRecord.biggestSingleLoss > biggestLoss.biggestSingleLoss)
				{
					biggestLoss = playerRunRecord;
				}
			}
		}

		private static string Trunc(string s, int max)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			if (s.Length > max)
			{
				return s.Substring(0, max);
			}
			return s;
		}
	}
	[Serializable]
	public class DeltaMsg
	{
		public long id;

		public int delta;

		public int game;

		public int inst;

		public string name = "";
	}
	public class HUDController : MonoBehaviour
	{
		private GameObject _root;

		private RectTransform _panel;

		private RawImage _scan;

		private TextMeshProUGUI _text;

		private bool _built;

		private void Build()
		{
			//IL_0045: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			if (LCStyle.Ready)
			{
				Canvas val = LCStyle.OverlayCanvas("LCCT_HUD", 800);
				_root = ((Component)val).gameObject;
				Image val2 = LCStyle.SoftPanel(_root.transform, new Color(0.02f, 0.04f, 0.03f, 0.5f));
				_panel = ((Graphic)val2).rectTransform;
				_panel.anchorMin = new Vector2(1f, 1f);
				_panel.anchorMax = new Vector2(1f, 1f);
				_panel.pivot = new Vector2(1f, 1f);
				_scan = LCStyle.Scanlines(((Component)val2).transform, new Color(0f, 0f, 0f, 0.18f));
				LCStyle.Stretch(((Graphic)_scan).rectTransform, 3f, 3f);
				_text = LCStyle.Text(((Component)val2).transform, "Text", Plugin.HudFontSize(), (TextAlignmentOptions)257, nativeGlow: true);
				LCStyle.Stretch(((TMP_Text)_text).rectTransform, 16f, 12f);
				_built = true;
			}
		}

		private void Update()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00f0: Expected O, but got Unknown
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			if (!_built)
			{
				Build();
				if (!_built)
				{
					return;
				}
			}
			TrackerManager instance = TrackerManager.Instance;
			StartOfRound instance2 = StartOfRound.Instance;
			bool flag = Plugin.HudEnabled() && (Object)instance != (Object)null && (Object)instance2 != (Object)null && instance2.shipHasLanded && !instance2.shipIsLeaving && IsGordion(instance2);
			if (_root.activeSelf != flag)
			{
				_root.SetActive(flag);
			}
			if (flag)
			{
				List<PlayerControllerB> crew = GetCrew(instance2);
				float num = (float)Plugin.HudFontSize() * 1.34f;
				float num2 = (float)(crew.Count + 4) * num + 22f;
				_panel.sizeDelta = new Vector2((float)Plugin.HudWidth(), num2);
				_panel.anchoredPosition = new Vector2((float)(-Plugin.HudMarginX()), (float)(-Plugin.HudMarginY()));
				if ((Object)_scan != (Object)null)
				{
					_scan.uvRect = new Rect(0f, 0f, 1f, num2 / 3f);
				}
				((TMP_Text)_text).text = BuildText(instance, crew);
			}
		}

		private static string BuildText(TrackerManager tm, List<PlayerControllerB> crew)
		{
			//IL_0005: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			string value = LCStyle.Tag("------------------------", LCStyle.Rule);
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(LCStyle.Tag("SESSION", LCStyle.Header)).Append('\n');
			stringBuilder.Append(value).Append('\n');
			for (int i = 0; i < crew.Count; i++)
			{
				PlayerControllerB val = crew[i];
				string s = (string.IsNullOrEmpty(val.playerUsername) ? ("Player " + val.playerClientId) : val.playerUsername);
				stringBuilder.Append(LCStyle.Tag(Trunc(s, 12), LCStyle.Ink));
				if (tm.TryGetSessionDelta(val.playerClientId, out var delta) && delta != 0)
				{
					Color c = ((delta > 0) ? LCStyle.Up : LCStyle.Down);
					stringBuilder.Append("<pos=60%>").Append(LCStyle.Tag(LCStyle.Signed(delta), c));
				}
				stringBuilder.Append('\n');
			}
			stringBuilder.Append(value).Append('\n');
			int num = tm.CrewNet();
			Color c2 = ((num <= 0) ? ((num < 0) ? LCStyle.Down : LCStyle.Ink) : LCStyle.Up);
			stringBuilder.Append(LCStyle.Tag("CREW", LCStyle.Dim)).Append("<pos=60%>").Append(LCStyle.Tag((num == 0) ? "0" : LCStyle.Signed(num), c2));
			return stringBuilder.ToString();
		}

		private static bool IsGordion(StartOfRound sor)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			SelectableLevel currentLevel = sor.currentLevel;
			if ((Object)currentLevel == (Object)null || string.IsNullOrEmpty(currentLevel.PlanetName))
			{
				return false;
			}
			return currentLevel.PlanetName.IndexOf("Gordion", StringComparison.OrdinalIgnoreCase) >= 0;
		}

		private static List<PlayerControllerB> GetCrew(StartOfRound sor)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			List<PlayerControllerB> list = new List<PlayerControllerB>();
			PlayerControllerB[] allPlayerScripts = sor.allPlayerScripts;
			if (allPlayerScripts == null)
			{
				return list;
			}
			PlayerControllerB[] array = allPlayerScripts;
			foreach (PlayerControllerB val in array)
			{
				if (!((Object)val == (Object)null) && (val.isPlayerControlled || val.isPlayerDead))
				{
					list.Add(val);
				}
			}
			return list;
		}

		private static string Trunc(string s, int max)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			if (s.Length > max)
			{
				return s.Substring(0, max);
			}
			return s;
		}

		private void OnDestroy()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if ((Object)_root != (Object)null)
			{
				Object.Destroy((Object)_root);
			}
		}
	}
	public static class LCStyle
	{
		public static readonly Color Ink;

		public static readonly Color Dim;

		public static readonly Color Up;

		public static readonly Color Down;

		public static readonly Color Header;

		public static readonly Color Rule;

		private static TMP_FontAsset _font;

		private static Material _mat;

		private static Sprite _softPanel;

		private static Texture2D _scan;

		private static Sprite _outline;

		public static bool Ready
		{
			get
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Expected O, but got Unknown
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Expected O, but got Unknown
				EnsureRef();
				if ((Object)_font != (Object)null)
				{
					return (Object)_mat != (Object)null;
				}
				return false;
			}
		}

		public static string Hex(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return ColorUtility.ToHtmlStringRGB(c);
		}

		public static string Tag(string s, Color c)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			return "<color=#" + Hex(c) + ">" + s + "</color>";
		}

		public static string Signed(int v)
		{
			return ((v > 0) ? "+" : "") + v.ToString("N0");
		}

		private static void EnsureRef()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)_font != (Object)null && (Object)_mat != (Object)null)
			{
				return;
			}
			try
			{
				HUDManager instance = HUDManager.Instance;
				if ((Object)instance == (Object)null)
				{
					return;
				}
				TextMeshProUGUI val = null;
				if ((Object)instance.weightCounter != (Object)null)
				{
					val = instance.weightCounter;
				}
				else if (instance.controlTipLines != null && instance.controlTipLines.Length != 0)
				{
					val = instance.controlTipLines[0];
				}
				else if ((Object)instance.clockNumber != (Object)null)
				{
					val = instance.clockNumber;
				}
				if ((Object)val == (Object)null)
				{
					return;
				}
				if ((Object)((TMP_Text)val).font != (Object)null)
				{
					_font = ((TMP_Text)val).font;
				}
				if (!((Object)((TMP_Text)val).fontSharedMaterial != (Object)null))
				{
					return;
				}
				_mat = new Material(((TMP_Text)val).fontSharedMaterial);
				try
				{
					_mat.SetColor("_FaceColor", Color.white);
					_mat.EnableKeyword("GLOW_ON");
					_mat.SetColor("_GlowColor", new Color(0.4f, 1f, 0.55f, 1f));
					_mat.SetFloat("_GlowPower", 0.35f);
					_mat.SetFloat("_GlowOuter", 0.45f);
					_mat.SetFloat("_GlowInner", 0.05f);
					_mat.EnableKeyword("OUTLINE_ON");
					_mat.SetColor("_OutlineColor", new Color(0f, 0.08f, 0.03f, 1f));
					_mat.SetFloat("_OutlineWidth", 0.18f);
				}
				catch
				{
				}
			}
			catch
			{
			}
		}

		public static TMP_FontAsset Font()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			EnsureRef();
			if ((Object)_font == (Object)null)
			{
				try
				{
					_font = TMP_Settings.defaultFontAsset;
				}
				catch
				{
				}
			}
			return _font;
		}

		public static Canvas OverlayCanvas(string name, int sortingOrder)
		{
			//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_0008: Expected O, but got Unknown
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0011: 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)
			GameObject val = new GameObject(name);
			Object.DontDestroyOnLoad((Object)val);
			Canvas val2 = val.AddComponent<Canvas>();
			val2.renderMode = (RenderMode)0;
			val2.sortingOrder = sortingOrder;
			CanvasScaler obj = val.AddComponent<CanvasScaler>();
			obj.uiScaleMode = (ScaleMode)1;
			obj.referenceResolution = new Vector2(1920f, 1080f);
			obj.screenMatchMode = (ScreenMatchMode)0;
			obj.matchWidthOrHeight = 0.5f;
			return val2;
		}

		public static Image Panel(Transform parent, Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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)
			GameObject val = new GameObject("Panel");
			val.transform.SetParent(parent, false);
			Image obj = val.AddComponent<Image>();
			((Graphic)obj).color = color;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		public static Image SoftPanel(Transform parent, Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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)
			GameObject val = new GameObject("Panel");
			val.transform.SetParent(parent, false);
			Image obj = val.AddComponent<Image>();
			obj.sprite = SoftSprite();
			obj.type = (Type)1;
			((Graphic)obj).color = color;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		public static Image Box(Transform parent, Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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)
			GameObject val = new GameObject("Box");
			val.transform.SetParent(parent, false);
			Image obj = val.AddComponent<Image>();
			obj.sprite = OutlineSprite();
			obj.type = (Type)1;
			((Graphic)obj).color = color;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private static Sprite OutlineSprite()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)_outline != (Object)null)
			{
				return _outline;
			}
			int num = 16;
			int num2 = 4;
			int num3 = 2;
			Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					bool flag = j < num3 || j >= num - num3 || i < num3 || i >= num - num3;
					val.SetPixel(j, i, new Color(1f, 1f, 1f, flag ? 1f : 0f));
				}
			}
			val.Apply();
			((Object)val).hideFlags = (HideFlags)61;
			_outline = Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4((float)num2, (float)num2, (float)num2, (float)num2));
			return _outline;
		}

		public static RawImage Scanlines(Transform parent, Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_002c: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Scanlines");
			val.transform.SetParent(parent, false);
			RawImage obj = val.AddComponent<RawImage>();
			obj.texture = (Texture)ScanTex();
			((Graphic)obj).color = color;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		public static TextMeshProUGUI Text(Transform parent, string name, float size, TextAlignmentOptions align, bool nativeGlow)
		{
			//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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val2).font = Font();
			if (nativeGlow && (Object)_mat != (Object)null)
			{
				((TMP_Text)val2).fontSharedMaterial = _mat;
			}
			((TMP_Text)val2).fontSize = size;
			((Graphic)val2).color = Ink;
			((TMP_Text)val2).alignment = align;
			((TMP_Text)val2).richText = true;
			((TMP_Text)val2).enableWordWrapping = false;
			((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
			((Graphic)val2).raycastTarget = false;
			return val2;
		}

		public static void Stretch(RectTransform rt, float padX, float padY)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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)
			rt.anchorMin = Vector2.zero;
			rt.anchorMax = Vector2.one;
			rt.offsetMin = new Vector2(padX, padY);
			rt.offsetMax = new Vector2(0f - padX, 0f - padY);
		}

		private static Sprite SoftSprite()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)_softPanel != (Object)null)
			{
				return _softPanel;
			}
			int num = 32;
			int num2 = 12;
			Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					float num3 = Mathf.Clamp01((float)Mathf.Min(Mathf.Min(j, num - 1 - j), Mathf.Min(i, num - 1 - i)) / (float)num2);
					num3 = num3 * num3 * (3f - 2f * num3);
					val.SetPixel(j, i, new Color(1f, 1f, 1f, num3));
				}
			}
			val.Apply();
			((Object)val).hideFlags = (HideFlags)61;
			_softPanel = Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4((float)num2, (float)num2, (float)num2, (float)num2));
			return _softPanel;
		}

		private static Texture2D ScanTex()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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)
			if ((Object)_scan != (Object)null)
			{
				return _scan;
			}
			_scan = new Texture2D(1, 3, (TextureFormat)4, false);
			((Texture)_scan).wrapMode = (TextureWrapMode)0;
			((Texture)_scan).filterMode = (FilterMode)0;
			_scan.SetPixel(0, 0, new Color(0f, 0f, 0f, 0f));
			_scan.SetPixel(0, 1, new Color(0f, 0f, 0f, 0f));
			_scan.SetPixel(0, 2, new Color(0f, 0f, 0f, 1f));
			_scan.Apply();
			((Object)_scan).hideFlags = (HideFlags)61;
			return _scan;
		}

		static LCStyle()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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)
			Ink = new Color(0.74f, 0.85f, 0.7f);
			Dim = new Color(0.46f, 0.55f, 0.44f);
			Up = new Color(0.56f, 0.96f, 0.52f);
			Down = new Color(0.95f, 0.46f, 0.36f);
			Header = new Color(0.72f, 0.88f, 0.6f);
			Rule = new Color(0.55f, 0.66f, 0.45f, 0.5f);
		}
	}
	public static class NetworkSync
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnDelta;

			public static HandleNamedMessageDelegate <1>__OnRequest;

			public static HandleNamedMessageDelegate <2>__OnState;
		}

		private const string MsgDelta = "LCCT_Delta";

		private const string MsgRequest = "LCCT_Req";

		private const string MsgState = "LCCT_State";

		private static bool _registered;

		private static NetworkManager _registeredOn;

		private static bool _requested;

		public static void Tick()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_004c: Expected O, but got Unknown
			try
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)singleton == (Object)null || !singleton.IsListening)
				{
					_registered = false;
					_registeredOn = null;
					_requested = false;
					return;
				}
				if (!_registered || (Object)_registeredOn != (Object)singleton)
				{
					Register(singleton);
				}
				if (!singleton.IsServer && singleton.IsConnectedClient && !_requested)
				{
					Send("LCCT_Req", 0uL, "1");
					_requested = true;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("NetworkSync.Tick: " + ex.Message));
			}
		}

		public static void RequestResync()
		{
			_requested = false;
		}

		private static void Register(NetworkManager nm)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			CustomMessagingManager customMessagingManager = nm.CustomMessagingManager;
			if (customMessagingManager != null)
			{
				object obj = <>O.<0>__OnDelta;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = OnDelta;
					<>O.<0>__OnDelta = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("LCCT_Delta", (HandleNamedMessageDelegate)obj);
				object obj2 = <>O.<1>__OnRequest;
				if (obj2 == null)
				{
					HandleNamedMessageDelegate val2 = OnRequest;
					<>O.<1>__OnRequest = val2;
					obj2 = (object)val2;
				}
				customMessagingManager.RegisterNamedMessageHandler("LCCT_Req", (HandleNamedMessageDelegate)obj2);
				object obj3 = <>O.<2>__OnState;
				if (obj3 == null)
				{
					HandleNamedMessageDelegate val3 = OnState;
					<>O.<2>__OnState = val3;
					obj3 = (object)val3;
				}
				customMessagingManager.RegisterNamedMessageHandler("LCCT_State", (HandleNamedMessageDelegate)obj3);
				_registered = true;
				_registeredOn = nm;
				Plugin.Log.LogInfo((object)("NetworkSync handlers registered (server=" + nm.IsServer + ")."));
			}
		}

		public static void BroadcastDelta(ulong id, string username, int delta, CasinoGameType game, int instId)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			try
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)singleton == (Object)null || !singleton.IsServer || singleton.CustomMessagingManager == null)
				{
					return;
				}
				string payload = JsonUtility.ToJson((object)new DeltaMsg
				{
					id = (long)id,
					delta = delta,
					game = (int)game,
					inst = instId,
					name = ((username == null) ? "" : username)
				});
				foreach (ulong connectedClientsId in singleton.ConnectedClientsIds)
				{
					if (connectedClientsId != 0L)
					{
						Send("LCCT_Delta", connectedClientsId, payload);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("BroadcastDelta: " + ex.Message));
			}
		}

		private static void Send(string msg, ulong clientId, string payload)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(Encoding.UTF8.GetByteCount(payload) + 64, (Allocator)2, 524288);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe(payload, false);
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage(msg, clientId, val, (NetworkDelivery)2);
			}
			finally
			{
				((FastBufferWriter)(ref val)).Dispose();
			}
		}

		private static void OnDelta(ulong sender, FastBufferReader reader)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			try
			{
				if (!TrackerManager.IsServer())
				{
					string text = null;
					((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false);
					DeltaMsg deltaMsg = JsonUtility.FromJson<DeltaMsg>(text);
					if (deltaMsg != null && (Object)TrackerManager.Instance != (Object)null)
					{
						TrackerManager.Instance.RecordResolution((ulong)deltaMsg.id, deltaMsg.name, deltaMsg.delta, (CasinoGameType)deltaMsg.game, deltaMsg.inst);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("OnDelta: " + ex.Message));
			}
		}

		private static void OnRequest(ulong sender, FastBufferReader reader)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			try
			{
				if (TrackerManager.IsServer() && !((Object)TrackerManager.Instance == (Object)null))
				{
					SyncBlob syncBlob = TrackerManager.Instance.BuildSyncBlob();
					Send("LCCT_State", sender, JsonUtility.ToJson((object)syncBlob));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("OnRequest: " + ex.Message));
			}
		}

		private static void OnState(ulong sender, FastBufferReader reader)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			try
			{
				if (!TrackerManager.IsServer())
				{
					string text = null;
					((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false);
					SyncBlob b = JsonUtility.FromJson<SyncBlob>(text);
					if ((Object)TrackerManager.Instance != (Object)null)
					{
						TrackerManager.Instance.ApplySyncBlob(b);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("OnState: " + ex.Message));
			}
		}
	}
	[Serializable]
	public class PlayerRunRecord
	{
		public long clientId;

		public string username = "";

		public int totalWon;

		public int totalLost;

		public int biggestSingleWin;

		public int biggestSingleLoss;

		public string biggestWinGame = "";

		public string biggestLossGame = "";

		public int gamesPlayed;

		public int Net => totalWon - totalLost;
	}
	[BepInPlugin("jaredfreedman.LethalCasinoTracker", "LethalCasinoTracker", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "jaredfreedman.LethalCasinoTracker";

		public static ManualLogSource Log;

		public static bool VerboseLogging;

		private static bool _initialized;

		private static ConfigEntry<bool> _verbose;

		private static ConfigEntry<bool> _hudEnabled;

		private static ConfigEntry<int> _hudMarginX;

		private static ConfigEntry<int> _hudMarginY;

		private static ConfigEntry<int> _hudWidth;

		private static ConfigEntry<int> _hudFont;

		private static ConfigEntry<bool> _summaryEnabled;

		private static ConfigEntry<float> _summaryDuration;

		private static ConfigEntry<bool> _sfxEnabled;

		private static ConfigEntry<float> _sfxVolume;

		private static ConfigEntry<bool> _chalkEnabled;

		private static ConfigEntry<float> _chalkX;

		private static ConfigEntry<float> _chalkY;

		private static ConfigEntry<float> _chalkZ;

		private static ConfigEntry<float> _chalkScale;

		private static ConfigEntry<float> _chalkYaw;

		private void Awake()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0033: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			BindConfig();
			if (!_initialized)
			{
				_initialized = true;
				try
				{
					Harmony val = new Harmony("jaredfreedman.LethalCasinoTracker");
					GameOverPatch.ApplyPatches(val);
					CasinoHooks.ApplyPatches(val);
				}
				catch (Exception ex)
				{
					Log.LogError((object)("Failed to apply Harmony patches: " + ex.Message));
				}
				((Component)this).gameObject.AddComponent<TrackerManager>();
				((Component)this).gameObject.AddComponent<SummaryScreenController>();
				((Component)this).gameObject.AddComponent<HUDController>();
				((Component)this).gameObject.AddComponent<ChalkboardController>();
				Log.LogInfo((object)"LethalCasinoTracker 1.1.0 loaded.");
			}
		}

		private void BindConfig()
		{
			_verbose = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "VerboseLogging", false, "Log every tracked bet result (debugging).");
			_hudEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Enabled", true, "Show the top-right session scoreboard while on a moon.");
			_hudMarginX = ((BaseUnityPlugin)this).Config.Bind<int>("HUD", "MarginX", 12, "Distance from the right edge of the screen, in pixels.");
			_hudMarginY = ((BaseUnityPlugin)this).Config.Bind<int>("HUD", "MarginY", 70, "Distance from the top edge of the screen, in pixels.");
			_hudWidth = ((BaseUnityPlugin)this).Config.Bind<int>("HUD", "Width", 270, "Panel width (reference px at 1080p).");
			_hudFont = ((BaseUnityPlugin)this).Config.Bind<int>("HUD", "FontSize", 19, "Font size for HUD rows.");
			_summaryEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Summary", "Enabled", true, "Show the centered session recap on takeoff.");
			_summaryDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Summary", "HoldSeconds", 7f, "How long the recap stays fully visible (matches the vanilla performance report).");
			_sfxEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Summary", "Sound", true, "Play a win/loss jingle with the recap.");
			_sfxVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Summary", "Volume", 0.5f, "Recap jingle volume (0-1).");
			_chalkEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Chalkboard", "Enabled", true, "Spawn the physical casino records board near the casino.");
			_chalkX = ((BaseUnityPlugin)this).Config.Bind<float>("Chalkboard", "OffsetRight", 0f, "Board placement offset along the casino's right axis (m).");
			_chalkY = ((BaseUnityPlugin)this).Config.Bind<float>("Chalkboard", "OffsetUp", 2.6f, "Board placement offset upward from the casino (m).");
			_chalkZ = ((BaseUnityPlugin)this).Config.Bind<float>("Chalkboard", "OffsetForward", 4.5f, "Board placement offset in front of the casino (m).");
			_chalkScale = ((BaseUnityPlugin)this).Config.Bind<float>("Chalkboard", "Scale", 0.0075f, "World scale of the board.");
			_chalkYaw = ((BaseUnityPlugin)this).Config.Bind<float>("Chalkboard", "Yaw", 180f, "Rotate the board to face the right way (degrees: try 0/90/180/270).");
			VerboseLogging = _verbose.Value;
		}

		public static bool HudEnabled()
		{
			if (_hudEnabled != null)
			{
				return _hudEnabled.Value;
			}
			return true;
		}

		public static int HudMarginX()
		{
			if (_hudMarginX == null)
			{
				return 12;
			}
			return _hudMarginX.Value;
		}

		public static int HudMarginY()
		{
			if (_hudMarginY == null)
			{
				return 70;
			}
			return _hudMarginY.Value;
		}

		public static int HudWidth()
		{
			if (_hudWidth == null)
			{
				return 270;
			}
			return _hudWidth.Value;
		}

		public static int HudFontSize()
		{
			if (_hudFont == null)
			{
				return 19;
			}
			return _hudFont.Value;
		}

		public static bool SummaryEnabled()
		{
			if (_summaryEnabled != null)
			{
				return _summaryEnabled.Value;
			}
			return true;
		}

		public static float SummaryDuration()
		{
			if (_summaryDuration == null)
			{
				return 7f;
			}
			return _summaryDuration.Value;
		}

		public static bool SfxEnabled()
		{
			if (_sfxEnabled != null)
			{
				return _sfxEnabled.Value;
			}
			return true;
		}

		public static float SfxVolume()
		{
			if (_sfxVolume == null)
			{
				return 0.5f;
			}
			return _sfxVolume.Value;
		}

		public static bool ChalkboardEnabled()
		{
			if (_chalkEnabled != null)
			{
				return _chalkEnabled.Value;
			}
			return true;
		}

		public static float ChalkOffsetX()
		{
			if (_chalkX == null)
			{
				return 0f;
			}
			return _chalkX.Value;
		}

		public static float ChalkOffsetY()
		{
			if (_chalkY == null)
			{
				return 2.6f;
			}
			return _chalkY.Value;
		}

		public static float ChalkOffsetZ()
		{
			if (_chalkZ == null)
			{
				return 4.5f;
			}
			return _chalkZ.Value;
		}

		public static float ChalkScale()
		{
			if (_chalkScale == null)
			{
				return 0.0075f;
			}
			return _chalkScale.Value;
		}

		public static float ChalkYaw()
		{
			if (_chalkYaw == null)
			{
				return 180f;
			}
			return _chalkYaw.Value;
		}
	}
	[Serializable]
	public class RunSaveBlob
	{
		public List<PlayerRunRecord> records = new List<PlayerRunRecord>();
	}
	[Serializable]
	public class SessionEntry
	{
		public long clientId;

		public string username = "";

		public int delta;
	}
	public class SummaryScreenController : MonoBehaviour
	{
		private class Row
		{
			public string name;

			public bool has;

			public int delta;
		}

		private const float W = 700f;

		private const float Pad = 26f;

		private const float RowH = 40f;

		private static readonly Color RInk;

		private static readonly Color RHead;

		private static readonly Color RDim;

		private static readonly Color RBg;

		private static readonly Color RBorder;

		private static readonly Color Up;

		private static readonly Color Down;

		private GameObject _root;

		private CanvasGroup _group;

		private RectTransform _panel;

		private RectTransform _inner;

		private TextMeshProUGUI _title;

		private TextMeshProUGUI _notes;

		private TextMeshProUGUI _collected;

		private TextMeshProUGUI _grade;

		private readonly List<GameObject> _rowBoxes = new List<GameObject>();

		private bool _built;

		private Coroutine _co;

		private AudioSource _audio;

		private AudioClip _winClip;

		private AudioClip _loseClip;

		private AudioClip _neutralClip;

		public static SummaryScreenController Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			_audio = ((Component)this).gameObject.AddComponent<AudioSource>();
			_audio.playOnAwake = false;
			_audio.spatialBlend = 0f;
			_audio.ignoreListenerPause = true;
			try
			{
				_winClip = MakeJingle("win", new float[4] { 523.25f, 659.25f, 783.99f, 1046.5f }, 0.13f, 0f);
				_loseClip = MakeJingle("lose", new float[4] { 440f, 392f, 349.23f, 293.66f }, 0.2f, -28f);
				_neutralClip = MakeJingle("neutral", new float[1] { 660f }, 0.09f, 0f);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not build recap audio: " + ex.Message));
			}
		}

		private void OnDestroy()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0015: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			if ((Object)Instance == (Object)this)
			{
				Instance = null;
			}
			if ((Object)_root != (Object)null)
			{
				Object.Destroy((Object)_root);
			}
		}

		private static string Tag(string s, Color c)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			return "<color=#" + ColorUtility.ToHtmlStringRGB(c) + ">" + s + "</color>";
		}

		private static string Signed(int v)
		{
			return ((v > 0) ? "+" : "") + v.ToString("N0");
		}

		private TextMeshProUGUI Label(string name, float x, float y, float w, float h, float size, TextAlignmentOptions align, Color col)
		{
			//IL_000e: 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_003c: 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_0064: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = LCStyle.Text(((Component)_inner).transform, name, size, align, nativeGlow: false);
			RectTransform rectTransform = ((TMP_Text)obj).rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 1f);
			rectTransform.anchorMax = new Vector2(0f, 1f);
			rectTransform.pivot = new Vector2(0f, 1f);
			rectTransform.anchoredPosition = new Vector2(x, 0f - y);
			rectTransform.sizeDelta = new Vector2(w, h);
			((Graphic)obj).color = col;
			return obj;
		}

		private void BuildUI()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			Canvas val = LCStyle.OverlayCanvas("LCCT_Recap", 950);
			_root = ((Component)val).gameObject;
			_group = _root.AddComponent<CanvasGroup>();
			_group.alpha = 0f;
			LCStyle.Stretch(((Graphic)LCStyle.Panel(_root.transform, new Color(0f, 0f, 0f, 0.6f))).rectTransform, 0f, 0f);
			Image val2 = LCStyle.Panel(_root.transform, RBorder);
			_panel = ((Graphic)val2).rectTransform;
			RectTransform panel = _panel;
			RectTransform panel2 = _panel;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			panel2.anchorMax = val3;
			Vector2 anchorMin = val3;
			panel.anchorMin = anchorMin;
			_panel.pivot = new Vector2(0.5f, 0.5f);
			Image val4 = LCStyle.Panel(((Component)val2).transform, RBg);
			_inner = ((Graphic)val4).rectTransform;
			LCStyle.Stretch(_inner, 4f, 4f);
			LCStyle.Stretch(((Graphic)LCStyle.Scanlines(((Component)_inner).transform, new Color(0.3f, 0f, 0f, 0.22f))).rectTransform, 0f, 0f);
			_title = Label("Title", 26f, 14f, 648f, 40f, 30f, (TextAlignmentOptions)258, RHead);
			((TMP_Text)_title).fontStyle = (FontStyles)1;
			((TMP_Text)_title).text = "CASINO PERFORMANCE REPORT";
			RectTransform rectTransform = ((Graphic)LCStyle.Panel(((Component)_inner).transform, RBorder)).rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 1f);
			rectTransform.anchorMax = new Vector2(0f, 1f);
			rectTransform.pivot = new Vector2(0f, 1f);
			rectTransform.anchoredPosition = new Vector2(26f, -58f);
			rectTransform.sizeDelta = new Vector2(648f, 3f);
			float num = 406f;
			((TMP_Text)Label("EmpHead", 26f, 70f, num - 26f, 24f, 18f, (TextAlignmentOptions)257, RDim)).text = "EMPLOYEE";
			((TMP_Text)Label("NotesHead", num + 6f, 70f, 674f - num - 6f, 24f, 18f, (TextAlignmentOptions)257, RDim)).text = "NOTES";
			float num2 = num + 6f;
			float num3 = 674f - num2;
			RectTransform rectTransform2 = ((Graphic)LCStyle.Box(((Component)_inner).transform, RBorder)).rectTransform;
			rectTransform2.anchorMin = new Vector2(0f, 1f);
			rectTransform2.anchorMax = new Vector2(0f, 1f);
			rectTransform2.pivot = new Vector2(0f, 1f);
			rectTransform2.anchoredPosition = new Vector2(num2, -98f);
			rectTransform2.sizeDelta = new Vector2(num3, 160f);
			_notes = LCStyle.Text(((Component)_inner).transform, "Notes", 17f, (TextAlignmentOptions)257, nativeGlow: false);
			RectTransform rectTransform3 = ((TMP_Text)_notes).rectTransform;
			rectTransform3.anchorMin = new Vector2(0f, 1f);
			rectTransform3.anchorMax = new Vector2(0f, 1f);
			rectTransform3.pivot = new Vector2(0f, 1f);
			rectTransform3.anchoredPosition = new Vector2(num2 + 12f, -110f);
			rectTransform3.sizeDelta = new Vector2(num3 - 24f, 160f);
			((Graphic)_notes).color = RInk;
			RectTransform rectTransform4 = ((Graphic)LCStyle.Box(((Component)_inner).transform, RBorder)).rectTransform;
			rectTransform4.anchorMin = new Vector2(0f, 0f);
			rectTransform4.anchorMax = new Vector2(0f, 0f);
			rectTransform4.pivot = new Vector2(0f, 0f);
			rectTransform4.anchoredPosition = new Vector2(26f, 16f);
			rectTransform4.sizeDelta = new Vector2(num - 26f, 44f);
			_collected = LCStyle.Text(((Component)_inner).transform, "Collected", 20f, (TextAlignmentOptions)513, nativeGlow: false);
			RectTransform rectTransform5 = ((TMP_Text)_collected).rectTransform;
			rectTransform5.anchorMin = new Vector2(0f, 0f);
			rectTransform5.anchorMax = new Vector2(0f, 0f);
			rectTransform5.pivot = new Vector2(0f, 0f);
			rectTransform5.anchoredPosition = new Vector2(40f, 16f);
			rectTransform5.sizeDelta = new Vector2(num - 26f - 20f, 44f);
			_grade = LCStyle.Text(((Component)_inner).transform, "Grade", 30f, (TextAlignmentOptions)516, nativeGlow: false);
			RectTransform rectTransform6 = ((TMP_Text)_grade).rectTransform;
			rectTransform6.anchorMin = new Vector2(1f, 0f);
			rectTransform6.anchorMax = new Vector2(1f, 0f);
			rectTransform6.pivot = new Vector2(1f, 0f);
			rectTransform6.anchoredPosition = new Vector2(-26f, 16f);
			rectTransform6.sizeDelta = new Vector2(294f, 44f);
			((TMP_Text)_grade).fontStyle = (FontStyles)1;
			_built = true;
		}

		public void Show(Dictionary<ulong, int> sessionSnapshot, int crewNet)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.SummaryEnabled())
			{
				if ((Object)TrackerManager.Instance != (Object)null)
				{
					TrackerManager.Instance.EndSessionWipe();
				}
				return;
			}
			if (!_built)
			{
				BuildUI();
			}
			List<Row> list = BuildRows(sessionSnapshot);
			for (int i = 0; i < _rowBoxes.Count; i++)
			{
				if ((Object)_rowBoxes[i] != (Object)null)
				{
					Object.Destroy((Object)_rowBoxes[i]);
				}
			}
			_rowBoxes.Clear();
			float num = 406f - 26f;
			int num2 = Mathf.Min(list.Count, 6);
			for (int j = 0; j < num2; j++)
			{
				Row row = list[j];
				Image val = LCStyle.Box(((Component)_inner).transform, RBorder);
				RectTransform rectTransform = ((Graphic)val).rectTransform;
				rectTransform.anchorMin = new Vector2(0f, 1f);
				rectTransform.anchorMax = new Vector2(0f, 1f);
				rectTransform.pivot = new Vector2(0f, 1f);
				rectTransform.anchoredPosition = new Vector2(26f, 0f - (98f + (float)j * 40f));
				rectTransform.sizeDelta = new Vector2(num, 34f);
				TextMeshProUGUI obj = LCStyle.Text(((Component)val).transform, "Row", 19f, (TextAlignmentOptions)513, nativeGlow: false);
				LCStyle.Stretch(((TMP_Text)obj).rectTransform, 12f, 0f);
				((TMP_Text)obj).text = string.Concat(str2: row.has ? Tag(Signed(row.delta), (row.delta > 0) ? Up : Down) : Tag("--", RDim), str0: Tag(Trunc(row.name, 12), RInk), str1: "<pos=72%>");
				_rowBoxes.Add(((Component)val).gameObject);
			}
			((TMP_Text)_notes).text = BuildNotes();
			Color c = ((crewNet <= 0) ? ((crewNet < 0) ? Down : RInk) : Up);
			((TMP_Text)_collected).text = Tag("COLLECTED: ", RDim) + Tag((crewNet == 0) ? "0" : Signed(crewNet), c);
			((TMP_Text)_grade).text = Tag("GRADE ", RDim) + Tag(Grade(crewNet), RHead);
			float num3 = 98f + (float)Mathf.Max(num2, 3) * 40f + 76f;
			_panel.sizeDelta = new Vector2(700f, num3);
			PlayResultSound(crewNet);
			_root.SetActive(true);
			if (_co != null)
			{
				((MonoBehaviour)this).StopCoroutine(_co);
			}
			_co = ((MonoBehaviour)this).StartCoroutine(Run());
		}

		private static string BuildNotes()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_00e7: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			TrackerManager instance = TrackerManager.Instance;
			if ((Object)instance == (Object)null)
			{
				return "";
			}
			List<PlayerRunRecord> recordsSorted = instance.GetRecordsSorted();
			PlayerRunRecord playerRunRecord = null;
			PlayerRunRecord playerRunRecord2 = null;
			for (int i = 0; i < recordsSorted.Count; i++)
			{
				if (playerRunRecord == null || recordsSorted[i].biggestSingleWin > playerRunRecord.biggestSingleWin)
				{
					playerRunRecord = recordsSorted[i];
				}
				if (playerRunRecord2 == null || recordsSorted[i].biggestSingleLoss > playerRunRecord2.biggestSingleLoss)
				{
					playerRunRecord2 = recordsSorted[i];
				}
			}
			StringBuilder stringBuilder = new StringBuilder();
			if (playerRunRecord != null && playerRunRecord.biggestSingleWin > 0)
			{
				stringBuilder.Append(Tag("Top win: ", RDim)).Append(Tag(Trunc(playerRunRecord.username, 9) + " " + Signed(playerRunRecord.biggestSingleWin), Up)).Append('\n');
			}
			else
			{
				stringBuilder.Append(Tag("Top win: --", RDim)).Append('\n');
			}
			if (playerRunRecord2 != null && playerRunRecord2.biggestSingleLoss > 0)
			{
				stringBuilder.Append(Tag("Top loss: ", RDim)).Append(Tag(Trunc(playerRunRecord2.username, 9) + " -" + playerRunRecord2.biggestSingleLoss.ToString("N0"), Down)).Append('\n');
			}
			else
			{
				stringBuilder.Append(Tag("Top loss: --", RDim)).Append('\n');
			}
			stringBuilder.Append(Tag("Games: " + instance.TotalGames(), RDim));
			return stringBuilder.ToString();
		}

		private static string Grade(int crewNet)
		{
			if (crewNet >= 1500)
			{
				return "S";
			}
			if (crewNet >= 400)
			{
				return "A";
			}
			if (crewNet > 0)
			{
				return "B";
			}
			if (crewNet == 0)
			{
				return "C";
			}
			if (crewNet > -400)
			{
				return "D";
			}
			return "F";
		}

		private static List<Row> BuildRows(Dictionary<ulong, int> snap)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			List<Row> list = new List<Row>();
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)instance != (Object)null && instance.allPlayerScripts != null)
			{
				PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
				foreach (PlayerControllerB val in allPlayerScripts)
				{
					if (!((Object)val == (Object)null) && (val.isPlayerControlled || val.isPlayerDead))
					{
						Row row = new Row();
						row.name = (string.IsNullOrEmpty(val.playerUsername) ? ("Player " + val.playerClientId) : val.playerUsername);
						row.has = snap != null && snap.TryGetValue(val.playerClientId, out var value) && value != 0;
						row.delta = (row.has ? snap[val.playerClientId] : 0);
						list.Add(row);
					}
				}
			}
			return list;
		}

		private IEnumerator Run()
		{
			float fadeIn = 0.45f;
			float hold = Plugin.SummaryDuration();
			float fadeOut = 0.8f;
			float t = 0f;
			while (t < fadeIn)
			{
				t += Time.unscaledDeltaTime;
				_group.alpha = Mathf.Clamp01(t / fadeIn);
				yield return null;
			}
			_group.alpha = 1f;
			yield return (object)new WaitForSecondsRealtime(hold);
			t = 0f;
			while (t < fadeOut)
			{
				t += Time.unscaledDeltaTime;
				_group.alpha = 1f - Mathf.Clamp01(t / fadeOut);
				yield return null;
			}
			_group.alpha = 0f;
			_root.SetActive(false);
			_co = null;
			if ((Object)TrackerManager.Instance != (Object)null)
			{
				TrackerManager.Instance.EndSessionWipe();
			}
		}

		private void PlayResultSound(int crewNet)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			if (Plugin.SfxEnabled() && !((Object)_audio == (Object)null))
			{
				AudioClip val = ((crewNet <= 0) ? ((crewNet < 0) ? _loseClip : _neutralClip) : _winClip);
				if ((Object)val != (Object)null)
				{
					_audio.PlayOneShot(val, Plugin.SfxVolume());
				}
			}
		}

		private static string Trunc(string s, int max)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			if (s.Length > max)
			{
				return s.Substring(0, max);
			}
			return s;
		}

		private static AudioClip MakeJingle(string name, float[] freqs, float noteDur, float noteGlideHz)
		{
			int num = 44100;
			int num2 = Mathf.Max(1, (int)(noteDur * (float)num));
			int num3 = num2 * freqs.Length;
			float[] array = new float[num3];
			for (int i = 0; i < freqs.Length; i++)
			{
				float num4 = freqs[i];
				for (int j = 0; j < num2; j++)
				{
					float num5 = (float)j / (float)num;
					float num6 = (float)j / (float)num2;
					float num7 = num4 + noteGlideHz * num6;
					float num8 = Mathf.Exp(-4f * num6);
					float num9 = Mathf.Clamp01(num6 * 40f);
					array[i * num2 + j] = Mathf.Sin(MathF.PI * 2f * num7 * num5) * num8 * num9 * 0.28f;
				}
			}
			AudioClip obj = AudioClip.Create("LCCT_" + name, num3, 1, num, false);
			obj.SetData(array, 0);
			return obj;
		}

		static SummaryScreenController()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			RInk = new Color(0.95f, 0.5f, 0.36f);
			RHead = new Color(1f, 0.36f, 0.24f);
			RDim = new Color(0.74f, 0.34f, 0.27f);
			RBg = new Color(0.11f, 0.015f, 0.015f, 0.94f);
			RBorder = new Color(0.92f, 0.26f, 0.17f, 0.95f);
			Up = new Color(0.55f, 0.95f, 0.5f);
			Down = new Color(1f, 0.42f, 0.35f);
		}
	}
	[Serializable]
	public class SyncBlob
	{
		public List<PlayerRunRecord> records = new List<PlayerRunRecord>();

		public List<SessionEntry> session = new List<SessionEntry>();
	}
	public class TrackerManager : MonoBehaviour
	{
		private class Pending
		{
			public ulong id;

			public string name;

			public int delta;

			public CasinoGameType game;

			public float lastTouch;
		}

		public const string Es3File = "LethalCasinoTracker.es3";

		private const string Es3KeyPrefix = "CasinoTracker_RunRecords_";

		private const float FlushDelay = 0.85f;

		private readonly Dictionary<ulong, int> _sessionDeltas = new Dictionary<ulong, int>();

		private readonly Dictionary<ulong, PlayerRunRecord> _runRecords = new Dictionary<ulong, PlayerRunRecord>();

		private readonly Dictionary<string, Pending> _pending = new Dictionary<string, Pending>();

		private bool _recordsLoaded;

		private bool _wasLanded;

		private bool _wasListening;

		public static TrackerManager Instance { get; private set; }

		public bool SessionActive { get; private set; }

		public bool RecordsDirty { get; set; }

		private void Awake()
		{
			Instance = this;
		}

		private void OnDestroy()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0015: Expected O, but got Unknown
			if ((Object)Instance == (Object)this)
			{
				Instance = null;
			}
		}

		public void RecordResolution(ulong id, string username, int delta, CasinoGameType game, int gameInstanceId)
		{
			if (delta != 0)
			{
				string text = (string.IsNullOrEmpty(username) ? ("Player " + id) : username);
				_sessionDeltas.TryGetValue(id, out var value);
				_sessionDeltas[id] = value + delta;
				string key = gameInstanceId + ":" + id;
				if (!_pending.TryGetValue(key, out var value2))
				{
					value2 = new Pending();
					value2.id = id;
					value2.name = text;
					value2.game = game;
					_pending[key] = value2;
				}
				value2.delta += delta;
				value2.game = game;
				value2.name = text;
				value2.lastTouch = Time.realtimeSinceStartup;
				if (Plugin.VerboseLogging)
				{
					Plugin.Log.LogInfo((object)("Delta " + delta + " -> " + text + " (" + CasinoGameNames.Display(game) + "), session net now " + _sessionDeltas[id]));
				}
			}
		}

		private void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			bool flag = (Object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.IsListening;
			if (_wasListening && !flag)
			{
				SoftResetForMenu();
			}
			_wasListening = flag;
			StartOfRound instance = StartOfRound.Instance;
			bool flag2 = (Object)instance != (Object)null && instance.shipHasLanded && !instance.shipIsLeaving;
			if (flag2 && !_wasLanded)
			{
				OnShipLanded();
			}
			else if (!flag2 && _wasLanded)
			{
				OnShipLeaving();
			}
			_wasLanded = flag2;
			if (_pending.Count > 0)
			{
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				List<string> list = null;
				foreach (KeyValuePair<string, Pending> item in _pending)
				{
					if (realtimeSinceStartup - item.Value.lastTouch >= 0.85f)
					{
						if (list == null)
						{
							list = new List<string>();
						}
						list.Add(item.Key);
					}
				}
				if (list != null)
				{
					for (int i = 0; i < list.Count; i++)
					{
						Pending p = _pending[list[i]];
						_pending.Remove(list[i]);
						FinalizeRound(p);
					}
				}
			}
			NetworkSync.Tick();
		}

		private void FinalizeRound(Pending p)
		{
			PlayerRunRecord orCreateRecord = GetOrCreateRecord(p.id, p.name);
			orCreateRecord.gamesPlayed++;
			if (p.delta > 0)
			{
				orCreateRecord.totalWon += p.delta;
				if (p.delta > orCreateRecord.biggestSingleWin)
				{
					orCreateRecord.biggestSingleWin = p.delta;
					orCreateRecord.biggestWinGame = CasinoGameNames.Display(p.game);
				}
			}
			else if (p.delta < 0)
			{
				int num = -p.delta;
				orCreateRecord.totalLost += num;
				if (num > orCreateRecord.biggestSingleLoss)
				{
					orCreateRecord.biggestSingleLoss = num;
					orCreateRecord.biggestLossGame = CasinoGameNames.Display(p.game);
				}
			}
			RecordsDirty = true;
		}

		private void FlushAllPendingNow()
		{
			if (_pending.Count != 0)
			{
				List<Pending> list = new List<Pending>(_pending.Values);
				_pending.Clear();
				for (int i = 0; i < list.Count; i++)
				{
					FinalizeRound(list[i]);
				}
			}
		}

		private PlayerRunRecord GetOrCreateRecord(ulong id, string name)
		{
			if (!_runRecords.TryGetValue(id, out var value))
			{
				value = new PlayerRunRecord();
				value.clientId = (long)id;
				value.username = name;
				_runRecords[id] = value;
			}
			else if (!string.IsNullOrEmpty(name))
			{
				value.username = name;
			}
			return value;
		}

		public void OnShipLanded()
		{
			SessionActive = true;
			if (IsServer())
			{
				if (!_recordsLoaded)
				{
					LoadRecords();
				}
				_recordsLoaded = true;
			}
			else
			{
				NetworkSync.RequestResync();
			}
			RecordsDirty = true;
		}

		public void OnShipLeaving()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			FlushAllPendingNow();
			if (IsServer())
			{
				SaveRecords();
			}
			bool num = IsGordion();
			Dictionary<ulong, int> sessionSnapshot = new Dictionary<ulong, int>(_sessionDeltas);
			SessionActive = false;
			SummaryScreenController instance = SummaryScreenController.Instance;
			if (num && (Object)instance != (Object)null)
			{
				instance.Show(sessionSnapshot, CrewNet());
			}
			else
			{
				EndSessionWipe();
			}
		}

		pub