Decompiled source of GamblingMachineAtTheCompanyForkV2 v1.4.3

GamblersMod.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GamblersMod.NetcodePatcher;
using GamblersMod.Patches;
using GamblersMod.Player;
using GamblersMod.RoundManagerCustomSpace;
using GamblersMod.config;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("GamblersMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GamblersMod")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4389dd08-eb54-4b6f-955c-5f772ecc6fc7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: NetcodePatchedAssembly]
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace GamblersMod
{
	public class GamblingMachineManager : MonoBehaviour
	{
		public List<GameObject> GamblingMachines;

		public static GamblingMachineManager Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			Plugin.mls.LogMessage((object)"Gambling machine manager has awoken!");
			GamblingMachines = new List<GameObject>();
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		}

		public void Spawn(Vector3 spawnPoint, Quaternion quaternion)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			Plugin.mls.LogMessage((object)$"Spawning gambling machine... #{GamblingMachines.Count}");
			GameObject val = Object.Instantiate<GameObject>(Plugin.GamblingMachine, spawnPoint, quaternion);
			val.tag = "Untagged";
			val.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
			val.layer = LayerMask.NameToLayer("InteractableObject");
			val.GetComponent<NetworkObject>().Spawn(false);
			GamblingMachines.Add(val);
		}

		public void DespawnAll()
		{
			Plugin.mls.LogMessage((object)"Despwawning gambling machine...");
			foreach (GameObject gamblingMachine in GamblingMachines)
			{
				gamblingMachine.GetComponent<NetworkObject>().Despawn(true);
			}
			Reset();
		}

		public void Reset()
		{
			Plugin.mls.LogInfo((object)"Resetting gambling machine manager state...");
			GamblingMachines.Clear();
		}
	}
	[BepInPlugin("Junypai.GamblersMod", "Gamblers Mod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string modGUID = "Junypai.GamblersMod";

		public const string modName = "Gamblers Mod";

		public const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Junypai.GamblersMod");

		public static Plugin Instance;

		public static GameObject GamblingMachine;

		public static AudioClip GamblingJackpotScrapAudio;

		public static AudioClip GamblingHalveScrapAudio;

		public static AudioClip GamblingRemoveScrapAudio;

		public static AudioClip GamblingDoubleScrapAudio;

		public static AudioClip GamblingTripleScrapAudio;

		public static AudioClip GamblingDrumrollScrapAudio;

		public static AudioClip GamblingEmotionalDamageAudio;

		public static AudioClip GamblingMineExplodeAudio;

		public static GameObject GamblingATMMachine;

		public static AudioClip GamblingMachineMusicAudio;

		public static GameObject GamblingMachineResultCanvas;

		public static Font GamblingFont;

		public static GameObject GamblingHandIcon;

		public static GambleConfigSettingsSerializable UserConfigSnapshot;

		public static GambleConfigSettingsSerializable RecentHostConfig;

		public static GambleConfigSettingsSerializable CurrentUserConfig;

		public static ManualLogSource mls;

		private void Awake()
		{
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			NetcodeWeaver();
			mls = Logger.CreateLogSource("Junypai.GamblersMod");
			CurrentUserConfig = new GambleConfigSettingsSerializable(((BaseUnityPlugin)this).Config);
			RecentHostConfig = new GambleConfigSettingsSerializable(((BaseUnityPlugin)this).Config);
			UserConfigSnapshot = new GambleConfigSettingsSerializable(((BaseUnityPlugin)this).Config);
			string? directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			mls.LogInfo((object)"Loading gambler bundle assets");
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(directoryName, "gamblingmachinebundle"));
			if (!Object.op_Implicit((Object)(object)val))
			{
				mls.LogError((object)"Unable to load gambler bundle assets");
			}
			else
			{
				mls.LogInfo((object)"Gamblers bundle assets successfully loaded");
			}
			GamblingDrumrollScrapAudio = LoadAssetFromAssetBundleAndLogInfo<AudioClip>(val, "drumroll");
			GamblingJackpotScrapAudio = LoadAssetFromAssetBundleAndLogInfo<AudioClip>(val, "holyshit");
			GamblingHalveScrapAudio = LoadAssetFromAssetBundleAndLogInfo<AudioClip>(val, "cricket");
			GamblingRemoveScrapAudio = LoadAssetFromAssetBundleAndLogInfo<AudioClip>(val, "womp");
			GamblingMachineMusicAudio = LoadAssetFromAssetBundleAndLogInfo<AudioClip>(val, "machineMusic");
			GamblingDoubleScrapAudio = LoadAssetFromAssetBundleAndLogInfo<AudioClip>(val, "doublekill");
			GamblingTripleScrapAudio = LoadAssetFromAssetBundleAndLogInfo<AudioClip>(val, "triplekill");
			GamblingEmotionalDamageAudio = LoadAssetFromAssetBundleAndLogInfo<AudioClip>(val, "emotional-damage");
			GamblingMineExplodeAudio = LoadAssetFromAssetBundleAndLogInfo<AudioClip>(val, "mineexplosion");
			GamblingFont = LoadAssetFromAssetBundleAndLogInfo<Font>(val, "3270-Regular");
			GamblingMachine = LoadAssetFromAssetBundleAndLogInfo<GameObject>(val, "GamblingMachine");
			GamblingHandIcon = LoadAssetFromAssetBundleAndLogInfo<GameObject>(val, "HandIconGO");
			GamblingMachine.AddComponent<GamblingMachine>();
			new GameObject().AddComponent<GamblingMachineManager>();
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(GameNetworkManagerPatch));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(RoundManagerPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
		}

		private T LoadAssetFromAssetBundleAndLogInfo<T>(AssetBundle bundle, string assetName) where T : Object
		{
			T val = bundle.LoadAsset<T>(assetName);
			if (!Object.op_Implicit((Object)(object)val))
			{
				mls.LogError((object)(assetName + " asset failed to load"));
				return val;
			}
			mls.LogInfo((object)(assetName + " asset successfully loaded"));
			return val;
		}

		private static void NetcodeWeaver()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			for (int i = 0; i < types.Length; i++)
			{
				MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public class StartOfRoundCustom : NetworkBehaviour
	{
		private void Awake()
		{
		}

		[ServerRpc(RequireOwnership = false)]
		public void DespawnGamblingMachineServerRpc()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				GamblingMachineManager.Instance.DespawnAll();
			}
		}
	}
}
namespace GamblersMod.RoundManagerCustomSpace
{
	internal class RoundManagerCustom : NetworkBehaviour
	{
		public RoundManager RoundManager;

		private List<Vector3> spawnPoints;

		private float machineRotation;

		private void Awake()
		{
			RoundManager = ((Component)this).GetComponent<RoundManager>();
			BuildSpawnPointsFromConfig();
		}

		private void BuildSpawnPointsFromConfig()
		{
			//IL_00c8: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			spawnPoints = new List<Vector3>();
			GambleConfigSettingsSerializable currentUserConfig = Plugin.CurrentUserConfig;
			int num = Mathf.Max(1, currentUserConfig.configNumberOfRows);
			int num2 = Mathf.Max(1, currentUserConfig.configMachinesPerRow);
			float num3 = (Mathf.Approximately(currentUserConfig.configRowSpacing, 0f) ? 5f : currentUserConfig.configRowSpacing);
			float num4 = (Mathf.Approximately(currentUserConfig.configColumnSpacing, 0f) ? 5f : currentUserConfig.configColumnSpacing);
			machineRotation = ((currentUserConfig.configMachineRotation < 0f || currentUserConfig.configMachineRotation > 359f) ? 90f : currentUserConfig.configMachineRotation);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(-27.808f, -2.6256f, -14.7409f);
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(currentUserConfig.configLayoutOffsetX, currentUserConfig.configLayoutOffsetY, currentUserConfig.configLayoutOffsetZ);
			val += val2;
			Vector3 val3 = default(Vector3);
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num2; j++)
				{
					((Vector3)(ref val3))..ctor((float)i * num3, 0f, (float)j * num4);
					spawnPoints.Add(val + val3);
				}
			}
		}

		private int CalculateSpawnCount()
		{
			GambleConfigSettingsSerializable currentUserConfig = Plugin.CurrentUserConfig;
			int count = spawnPoints.Count;
			string text = (currentUserConfig.configMachineSpawnMode ?? string.Empty).ToUpperInvariant();
			if (text == "MAX")
			{
				return count;
			}
			if (text == "AUTO")
			{
				int num = 1;
				if ((Object)(object)NetworkManager.Singleton != (Object)null)
				{
					num = Mathf.Max(1, NetworkManager.Singleton.ConnectedClients.Count);
				}
				return Mathf.Min(count, num);
			}
			return count;
		}

		[ServerRpc(RequireOwnership = false)]
		public void DespawnGamblingMachineServerRpc()
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				GamblingMachineManager.Instance.DespawnAll();
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void SpawnGamblingMachineServerRpc()
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			if (((NetworkBehaviour)this).IsServer)
			{
				Plugin.mls.LogInfo((object)("Attempting to spawn gambling machine at " + ((Object)RoundManager.currentLevel).name));
				BuildSpawnPointsFromConfig();
				int num = CalculateSpawnCount();
				Plugin.mls.LogInfo((object)$"Spawning up to {num} gambling machines (capacity {spawnPoints.Count})");
				for (int i = 0; i < num && i < spawnPoints.Count; i++)
				{
					GamblingMachineManager.Instance.Spawn(spawnPoints[i], Quaternion.Euler(0f, machineRotation, 0f));
					Plugin.mls.LogInfo((object)$"Spawned machine number: {i}");
				}
			}
		}
	}
}
namespace GamblersMod.Player
{
	internal class PlayerControllerCustom : NetworkBehaviour
	{
		private PlayerGamblingUIManager PlayerGamblingUIManager;

		private PlayerControllerB PlayerControllerOriginal;

		public bool isUsingGamblingMachine;

		public PlayerControllerB OriginalController => PlayerControllerOriginal;

		private void Awake()
		{
			PlayerGamblingUIManager = ((Component)this).gameObject.AddComponent<PlayerGamblingUIManager>();
			PlayerControllerOriginal = ((Component)this).gameObject.GetComponent<PlayerControllerB>();
		}

		private void Update()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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)
			if (!((NetworkBehaviour)this).IsOwner)
			{
				return;
			}
			Camera gameplayCamera = PlayerControllerOriginal.gameplayCamera;
			Vector3 position = ((Component)gameplayCamera).transform.position;
			Vector3 forward = ((Component)gameplayCamera).transform.forward;
			Ray val = new Ray(position, forward);
			float num = 5f;
			int num2 = 512;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, ref val2, num, num2) && Object.op_Implicit((Object)(object)((RaycastHit)(ref val2)).collider))
			{
				GameObject gameObject = ((Component)((RaycastHit)(ref val2)).transform).gameObject;
				if (((Object)gameObject).name.Contains("GamblingMachine"))
				{
					PlayerGamblingUIManager.ShowInteractionText();
					GrabbableObject val3 = PlayerControllerOriginal.ItemSlots[PlayerControllerOriginal.currentItemSlot];
					GamblingMachine component = gameObject.GetComponent<GamblingMachine>();
					if (component.isInCooldownPhase())
					{
						PlayerGamblingUIManager.SetInteractionText($"Cooling down... {component.gamblingMachineCurrentCooldown}");
					}
					else if (component.numberOfUses <= 0)
					{
						PlayerGamblingUIManager.SetInteractionText("This machine is all used up");
					}
					else
					{
						string bindingDisplayString = InputActionRebindingExtensions.GetBindingDisplayString(IngamePlayerSettings.Instance.playerInput.actions.FindAction("Interact", false), 0, (DisplayStringOptions)0);
						PlayerGamblingUIManager.SetInteractionText(isUsingGamblingMachine ? "You're already using a machine" : ("Gamble: [" + bindingDisplayString + "]"));
					}
					if (Object.op_Implicit((Object)(object)val3))
					{
						PlayerGamblingUIManager.SetInteractionSubText($"Scrap value on hand: ■{val3.scrapValue}");
					}
					else
					{
						PlayerGamblingUIManager.SetInteractionSubText("Please hold a scrap on your hand");
					}
				}
				if (((Object)gameObject).name.Contains("GamblingMachine") && IngamePlayerSettings.Instance.playerInput.actions.FindAction("Interact", false).triggered)
				{
					GamblingMachine component2 = gameObject.GetComponent<GamblingMachine>();
					HandleGamblingMachineInput(component2);
				}
			}
			else
			{
				PlayerGamblingUIManager.HideInteractionText();
			}
		}

		public void ReleaseGamblingMachineLock()
		{
			Plugin.mls.LogInfo((object)$"Releasing gambling machine lock for: {((NetworkBehaviour)this).OwnerClientId}");
			isUsingGamblingMachine = false;
		}

		public void LockGamblingMachine()
		{
			Plugin.mls.LogInfo((object)$"Locking gambling machine for: {((NetworkBehaviour)this).OwnerClientId}");
			isUsingGamblingMachine = true;
		}

		private void HandleGamblingMachineInput(GamblingMachine gamblingMachine)
		{
			//IL_0087: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			GrabbableObject val = PlayerControllerOriginal.ItemSlots[PlayerControllerOriginal.currentItemSlot];
			if (Object.op_Implicit((Object)(object)val) && !gamblingMachine.isInCooldownPhase() && gamblingMachine.numberOfUses > 0 && !isUsingGamblingMachine)
			{
				Plugin.mls.LogInfo((object)("Gambling machine was interacted with by: " + PlayerControllerOriginal.playerUsername));
				gamblingMachine.SetCurrentGamblingCooldownToMaxCooldown();
				Plugin.mls.LogMessage((object)$"Scrap value of {((Object)val).name} on hand: ▊{val.scrapValue}");
				gamblingMachine.ActivateGamblingMachineServerRPC(NetworkBehaviourReference.op_Implicit((NetworkBehaviour)(object)val), NetworkBehaviourReference.op_Implicit((NetworkBehaviour)(object)this));
				PlayerGamblingUIManager.SetInteractionText($"Cooling down... {gamblingMachine.gamblingMachineCurrentCooldown}");
			}
		}

		public void KillWithExplosion()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerOriginal.KillPlayer(Vector3.zero, true, (CauseOfDeath)3, 0, default(Vector3));
		}
	}
}
namespace GamblersMod.Patches
{
	internal class GamblingMachine : NetworkBehaviour
	{
		[CompilerGenerated]
		private sealed class <CountdownCooldownCoroutine>d__34 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public GamblingMachine <>4__this;

			public Action onCountdownFinish;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <CountdownCooldownCoroutine>d__34(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Expected O, but got Unknown
				int num = <>1__state;
				GamblingMachine gamblingMachine = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					Plugin.mls.LogInfo((object)"Start gambling machine cooldown");
					break;
				case 1:
					<>1__state = -1;
					gamblingMachine.gamblingMachineCurrentCooldown--;
					Plugin.mls.LogMessage((object)$"Gambling machine cooldown: {gamblingMachine.gamblingMachineCurrentCooldown}");
					break;
				}
				if (gamblingMachine.gamblingMachineCurrentCooldown > 0)
				{
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				}
				onCountdownFinish();
				Plugin.mls.LogMessage((object)"End gambling machine cooldown");
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <DelayedExplosion>d__29 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public float delay;

			public GamblingMachine <>4__this;

			public Vector3 position;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayedExplosion>d__29(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Expected O, but got Unknown
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				GamblingMachine gamblingMachine = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(delay);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					gamblingMachine.SpawnExplosion(position);
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private int gamblingMachineMaxCooldown;

		public int gamblingMachineCurrentCooldown;

		private float jackpotMultiplier;

		private float tripleMultiplier;

		private float doubleMultiplier;

		private float halvedMultiplier;

		private float zeroMultiplier;

		private float explodeMultiplier;

		private int jackpotPercentage;

		private int triplePercentage;

		private int doublePercentage;

		private int halvedPercentage;

		private int removedPercentage;

		private int explodePercentage;

		private int maxValueLimit;

		private bool isMusicEnabled = true;

		private float musicVolume = 0.35f;

		private int rollMinValue;

		private int rollMaxValue;

		private int currentRoll = 100;

		public float currentGamblingOutcomeMultiplier = 1f;

		public string currentGamblingOutcome = GambleConstants.GamblingOutcome.DEFAULT;

		private Coroutine CountdownCooldownCoroutineBeingRan;

		private bool lockGamblingMachineServer;

		public int numberOfUses;

		private void Awake()
		{
			Plugin.mls.LogInfo((object)"GamblingMachine has Awoken");
			gamblingMachineMaxCooldown = Plugin.CurrentUserConfig.configMaxCooldown;
			numberOfUses = Plugin.CurrentUserConfig.configNumberOfUses;
			jackpotMultiplier = Plugin.CurrentUserConfig.configJackpotMultiplier;
			tripleMultiplier = Plugin.CurrentUserConfig.configTripleMultiplier;
			doubleMultiplier = Plugin.CurrentUserConfig.configDoubleMultiplier;
			halvedMultiplier = Plugin.CurrentUserConfig.configHalveMultiplier;
			zeroMultiplier = Plugin.CurrentUserConfig.configZeroMultiplier;
			explodeMultiplier = Plugin.CurrentUserConfig.configExplodeMultiplier;
			jackpotPercentage = Plugin.CurrentUserConfig.configJackpotChance;
			triplePercentage = Plugin.CurrentUserConfig.configTripleChance;
			doublePercentage = Plugin.CurrentUserConfig.configDoubleChance;
			halvedPercentage = Plugin.CurrentUserConfig.configHalveChance;
			removedPercentage = Plugin.CurrentUserConfig.configZeroChance;
			explodePercentage = Plugin.CurrentUserConfig.configExplodeChance;
			maxValueLimit = Plugin.CurrentUserConfig.configMaxValueLimit;
			isMusicEnabled = Plugin.CurrentUserConfig.configGamblingMusicEnabled;
			musicVolume = Plugin.CurrentUserConfig.configGamblingMusicVolume;
			Plugin.mls.LogInfo((object)$"GamblingMachine: gamblingMachineMaxCooldown loaded from config: {gamblingMachineMaxCooldown}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: jackpotMultiplier loaded from config: {jackpotMultiplier}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: tripleMultiplier loaded from config: {tripleMultiplier}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: doubleMultiplier loaded from config: {doubleMultiplier}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: halvedMultiplier loaded from config: {halvedMultiplier}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: zeroMultiplier loaded from config: {zeroMultiplier}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: explodeMultiplier loaded from config: {explodeMultiplier}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: jackpotPercentage loaded from config: {jackpotPercentage}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: triplePercentage loaded from config: {triplePercentage}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: doublePercentage loaded from config: {doublePercentage}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: halvedPercentage loaded from config: {halvedPercentage}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: removedPercentage loaded from config: {removedPercentage}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: explodePercentage loaded from config: {explodePercentage}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: maxValueLimit loaded from config: {maxValueLimit}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: gamblingMusicEnabled loaded from config: {isMusicEnabled}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: gamblingMusicVolume loaded from config: {musicVolume}");
			InitAudioSource();
			rollMinValue = 1;
			rollMaxValue = jackpotPercentage + triplePercentage + doublePercentage + halvedPercentage + removedPercentage + explodePercentage;
		}

		private void Start()
		{
			Plugin.mls.LogInfo((object)"GamblingMachine has Started");
		}

		public void GenerateGamblingOutcomeFromCurrentRoll()
		{
			bool num = currentRoll >= rollMinValue && currentRoll <= jackpotPercentage;
			int num2 = jackpotPercentage;
			int num3 = jackpotPercentage + triplePercentage;
			bool flag = currentRoll > num2 && currentRoll <= num3;
			int num4 = num3;
			int num5 = num3 + doublePercentage;
			bool flag2 = currentRoll > num4 && currentRoll <= num5;
			int num6 = num5;
			int num7 = num5 + halvedPercentage;
			bool flag3 = currentRoll > num6 && currentRoll <= num7;
			int num8 = num7;
			int num9 = num7 + explodePercentage;
			bool flag4 = currentRoll > num8 && currentRoll <= num9;
			if (num)
			{
				Plugin.mls.LogMessage((object)"Rolled Jackpot");
				currentGamblingOutcomeMultiplier = jackpotMultiplier;
				currentGamblingOutcome = GambleConstants.GamblingOutcome.JACKPOT;
			}
			else if (flag)
			{
				Plugin.mls.LogMessage((object)"Rolled Triple");
				currentGamblingOutcomeMultiplier = tripleMultiplier;
				currentGamblingOutcome = GambleConstants.GamblingOutcome.TRIPLE;
			}
			else if (flag2)
			{
				Plugin.mls.LogMessage((object)"Rolled Double");
				currentGamblingOutcomeMultiplier = doubleMultiplier;
				currentGamblingOutcome = GambleConstants.GamblingOutcome.DOUBLE;
			}
			else if (flag3)
			{
				Plugin.mls.LogMessage((object)"Rolled Halved");
				currentGamblingOutcomeMultiplier = halvedMultiplier;
				currentGamblingOutcome = GambleConstants.GamblingOutcome.HALVE;
			}
			else if (flag4)
			{
				Plugin.mls.LogMessage((object)"Rolled Explode");
				currentGamblingOutcomeMultiplier = explodeMultiplier;
				currentGamblingOutcome = GambleConstants.GamblingOutcome.EXPLODE;
			}
			else
			{
				Plugin.mls.LogMessage((object)"Rolled Remove");
				currentGamblingOutcomeMultiplier = zeroMultiplier;
				currentGamblingOutcome = GambleConstants.GamblingOutcome.REMOVE;
			}
		}

		private void SpawnExplosion(Vector3 position)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Landmine.SpawnExplosion(position, true, 1f, 1f, 50, 0f, (GameObject)null, false);
		}

		[IteratorStateMachine(typeof(<DelayedExplosion>d__29))]
		private IEnumerator DelayedExplosion(Vector3 position, float delay)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedExplosion>d__29(0)
			{
				<>4__this = this,
				position = position,
				delay = delay
			};
		}

		public void PlayGambleResultAudio(string outcome)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			if (outcome == GambleConstants.GamblingOutcome.JACKPOT)
			{
				AudioSource.PlayClipAtPoint(Plugin.GamblingJackpotScrapAudio, ((Component)this).transform.position, 0.6f);
			}
			else if (outcome == GambleConstants.GamblingOutcome.TRIPLE)
			{
				AudioSource.PlayClipAtPoint(Plugin.GamblingTripleScrapAudio, ((Component)this).transform.position, 0.6f);
			}
			else if (outcome == GambleConstants.GamblingOutcome.DOUBLE)
			{
				AudioSource.PlayClipAtPoint(Plugin.GamblingDoubleScrapAudio, ((Component)this).transform.position, 0.6f);
			}
			else if (outcome == GambleConstants.GamblingOutcome.HALVE)
			{
				AudioSource.PlayClipAtPoint(Plugin.GamblingHalveScrapAudio, ((Component)this).transform.position, 0.6f);
			}
			else if (outcome == GambleConstants.GamblingOutcome.REMOVE)
			{
				AudioSource.PlayClipAtPoint(Plugin.GamblingRemoveScrapAudio, ((Component)this).transform.position, 0.6f);
			}
		}

		public void PlayDrumRoll()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			AudioSource.PlayClipAtPoint(Plugin.GamblingDrumrollScrapAudio, ((Component)this).transform.position, 0.6f);
		}

		public void BeginGamblingMachineCooldown(Action onCountdownFinish)
		{
			SetCurrentGamblingCooldownToMaxCooldown();
			if (CountdownCooldownCoroutineBeingRan != null)
			{
				((MonoBehaviour)this).StopCoroutine(CountdownCooldownCoroutineBeingRan);
			}
			CountdownCooldownCoroutineBeingRan = ((MonoBehaviour)this).StartCoroutine(CountdownCooldownCoroutine(onCountdownFinish));
		}

		public bool isInCooldownPhase()
		{
			return gamblingMachineCurrentCooldown > 0;
		}

		[IteratorStateMachine(typeof(<CountdownCooldownCoroutine>d__34))]
		private IEnumerator CountdownCooldownCoroutine(Action onCountdownFinish)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CountdownCooldownCoroutine>d__34(0)
			{
				<>4__this = this,
				onCountdownFinish = onCountdownFinish
			};
		}

		public void SetCurrentGamblingCooldownToMaxCooldown()
		{
			gamblingMachineCurrentCooldown = gamblingMachineMaxCooldown;
		}

		public void SetRoll(int newRoll)
		{
			currentRoll = newRoll;
		}

		public int RollDice()
		{
			int num = (currentRoll = Random.Range(rollMinValue, rollMaxValue + 1));
			Plugin.mls.LogMessage((object)$"rollMinValue: {rollMinValue}");
			Plugin.mls.LogMessage((object)$"rollMaxValue: {rollMaxValue}");
			Plugin.mls.LogMessage((object)$"Rolled value: {num}");
			return num;
		}

		public int GetScrapValueBasedOnGambledOutcome(GrabbableObject scrap)
		{
			double val = (double)scrap.scrapValue * (double)currentGamblingOutcomeMultiplier;
			double d = ((maxValueLimit <= 0) ? Math.Min(val, 2147483647.0) : Math.Min(val, maxValueLimit));
			return (int)Math.Floor(d);
		}

		[ServerRpc(RequireOwnership = false)]
		public void ActivateGamblingMachineServerRPC(NetworkBehaviourReference scrapBeingGambledRef, NetworkBehaviourReference playerWhoGambledRef, ServerRpcParams serverRpcParams = default(ServerRpcParams))
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_00e7: 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)
			if (!((NetworkBehaviour)this).IsServer)
			{
				return;
			}
			if (numberOfUses <= 0)
			{
				Plugin.mls.LogWarning((object)"ActivateGamblingMachineServerRPC: Machine usage limit has been reached");
				return;
			}
			if (lockGamblingMachineServer)
			{
				Plugin.mls.LogWarning((object)$"Gambling machine is already processing one client's request. Throwing away a request for... {serverRpcParams.Receive.SenderClientId}");
				return;
			}
			lockGamblingMachineServer = true;
			numberOfUses--;
			Plugin.mls.LogInfo((object)$"ActivateGamblingMachineServerRPC: Number of uses left: {numberOfUses}");
			GrabbableObject scrap = default(GrabbableObject);
			if (!((NetworkBehaviourReference)(ref scrapBeingGambledRef)).TryGet<GrabbableObject>(ref scrap, (NetworkManager)null))
			{
				Plugin.mls.LogError((object)"ActivateGamblingMachineServerRPC: Failed to get scrap value on client side.");
				return;
			}
			BeginGamblingMachineCooldownClientRpc();
			Plugin.mls.LogMessage((object)("ActivateGamblingMachineServerRPC: Starting gambling machine cooldown phase in the server invoked by: " + serverRpcParams.Receive.SenderClientId));
			SetRoll(RollDice());
			GenerateGamblingOutcomeFromCurrentRoll();
			int scrapValueBasedOnGambledOutcome = GetScrapValueBasedOnGambledOutcome(scrap);
			ActivateGamblingMachineClientRPC(scrapBeingGambledRef, playerWhoGambledRef, serverRpcParams.Receive.SenderClientId, scrapValueBasedOnGambledOutcome, currentGamblingOutcome, numberOfUses);
		}

		[ClientRpc]
		private void ActivateGamblingMachineClientRPC(NetworkBehaviourReference scrapBeingGambledRef, NetworkBehaviourReference playerWhoGambledRef, ulong invokerId, int updatedScrapValue, string outcome, int numberOfUsesServer)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			Plugin.mls.LogInfo((object)"ActivateGamblingMachineClientRPC: Activiating gambling machines on client...");
			numberOfUses = numberOfUsesServer;
			Plugin.mls.LogInfo((object)$"ActivateGamblingMachineClientRPC: Number of uses left: {numberOfUses}");
			PlayerControllerCustom playerWhoGambled = default(PlayerControllerCustom);
			if (!((NetworkBehaviourReference)(ref playerWhoGambledRef)).TryGet<PlayerControllerCustom>(ref playerWhoGambled, (NetworkManager)null))
			{
				Plugin.mls.LogError((object)"ActivateGamblingMachineClientRPC: Failed to get player who gambled.");
				return;
			}
			playerWhoGambled.LockGamblingMachine();
			PlayDrumRoll();
			BeginGamblingMachineCooldown(delegate
			{
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				GrabbableObject val = default(GrabbableObject);
				if (!((NetworkBehaviourReference)(ref scrapBeingGambledRef)).TryGet<GrabbableObject>(ref val, (NetworkManager)null))
				{
					Plugin.mls.LogError((object)"ActivateGamblingMachineClientRPC: Failed to get scrap value on client side.");
				}
				else
				{
					Plugin.mls.LogInfo((object)$"Setting scrap value to: {updatedScrapValue}");
					val.SetScrapValue(updatedScrapValue);
					PlayGambleResultAudio(outcome);
					if (outcome == GambleConstants.GamblingOutcome.EXPLODE)
					{
						if (Object.op_Implicit((Object)(object)Plugin.GamblingEmotionalDamageAudio))
						{
							AudioSource.PlayClipAtPoint(Plugin.GamblingEmotionalDamageAudio, ((Component)playerWhoGambled).transform.position, 0.7f);
						}
						if (((NetworkBehaviour)this).IsServer)
						{
							((MonoBehaviour)this).StartCoroutine(DelayedExplosion(((Component)playerWhoGambled).transform.position, 2f));
						}
					}
					playerWhoGambled.ReleaseGamblingMachineLock();
					if (((NetworkBehaviour)this).IsServer)
					{
						Plugin.mls.LogMessage((object)"Unlocking gambling machine");
						lockGamblingMachineServer = false;
					}
				}
			});
		}

		[ClientRpc]
		private void BeginGamblingMachineCooldownClientRpc()
		{
			Plugin.mls.LogInfo((object)"Setting machine cooldown to max");
			SetCurrentGamblingCooldownToMaxCooldown();
		}

		private void InitAudioSource()
		{
			if (!isMusicEnabled)
			{
				((Component)this).GetComponent<AudioSource>().Pause();
			}
			((Component)this).GetComponent<AudioSource>().volume = musicVolume;
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		public static void StartPrefix(GameNetworkManager __instance)
		{
			if ((Object)(object)Plugin.GamblingMachine == (Object)null || (Object)(object)NetworkManager.Singleton == (Object)null)
			{
				Plugin.mls.LogError((object)"Cannot register gambling machine prefab: missing asset or NetworkManager");
			}
			else if (!NetworkManager.Singleton.NetworkConfig.Prefabs.Prefabs.Any((NetworkPrefab p) => (Object)(object)p.Prefab != (Object)null && ((Object)p.Prefab).name == ((Object)Plugin.GamblingMachine).name))
			{
				Plugin.mls.LogInfo((object)"Registering gambling machine network prefab early");
				NetworkManager.Singleton.AddNetworkPrefab(Plugin.GamblingMachine);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
		public static void StartDisconnectPatch()
		{
			Plugin.mls.LogInfo((object)"Player disconnected. Resetting the user's configuration settings.");
			Plugin.CurrentUserConfig = Plugin.UserConfigSnapshot;
			GamblingMachineManager.Instance.Reset();
		}
	}
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class GrabbableObjectPatch
	{
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		public static void Awake(PlayerControllerB __instance)
		{
			((Component)__instance).gameObject.AddComponent<PlayerControllerCustom>();
		}

		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		public static void ConnectClientToPlayerObjectPatch()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			Plugin.mls.LogInfo((object)"ConnectClientToPlayerObjectPatch");
			if (NetworkManager.Singleton.IsHost)
			{
				Plugin.mls.LogInfo((object)("Registering host config message handler: Junypai.GamblersMod_" + GambleConstants.ON_HOST_RECIEVES_CLIENT_CONFIG_REQUEST));
				NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("Junypai.GamblersMod_" + GambleConstants.ON_HOST_RECIEVES_CLIENT_CONFIG_REQUEST, new HandleNamedMessageDelegate(GambleConfigNetworkHelper.OnHostRecievesClientConfigRequest));
			}
			else
			{
				NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("Junypai.GamblersMod_" + GambleConstants.ON_CLIENT_RECIEVES_HOST_CONFIG_REQUEST, new HandleNamedMessageDelegate(GambleConfigNetworkHelper.OnClientRecievesHostConfigRequest));
				GambleConfigNetworkHelper.StartClientRequestConfigFromHost();
			}
		}
	}
	public class PlayerGamblingUIManager : NetworkBehaviour
	{
		private GameObject gamblingMachineInteractionTextCanvasObject;

		private Canvas gamblingMachineInteractionTextCanvas;

		private GameObject gamblingMachineInteractionTextObject;

		private GameObject gamblingMachineInteractionScrapInfoTextObject;

		private Text gamblingMachineInteractionScrapInfoText;

		private Text gamblingMachineInteractionText;

		private string interactionName;

		private string interactionText = string.Empty;

		private void Awake()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Expected O, but got Unknown
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			gamblingMachineInteractionTextCanvasObject = new GameObject();
			gamblingMachineInteractionTextCanvasObject.transform.parent = ((Component)this).transform;
			interactionName = "gamblingMachine";
			((Object)gamblingMachineInteractionTextCanvasObject).name = interactionName + "InteractionTextCanvasObject";
			gamblingMachineInteractionTextCanvasObject.AddComponent<Canvas>();
			gamblingMachineInteractionTextCanvasObject.SetActive(false);
			gamblingMachineInteractionTextCanvas = gamblingMachineInteractionTextCanvasObject.GetComponent<Canvas>();
			gamblingMachineInteractionTextCanvas.renderMode = (RenderMode)0;
			gamblingMachineInteractionTextCanvasObject.AddComponent<CanvasScaler>();
			gamblingMachineInteractionTextCanvasObject.AddComponent<GraphicRaycaster>();
			gamblingMachineInteractionTextObject = new GameObject();
			((Object)gamblingMachineInteractionTextObject).name = interactionName + "InteractionTextObject";
			gamblingMachineInteractionTextObject.AddComponent<Text>();
			Transform transform = gamblingMachineInteractionTextObject.transform;
			Rect rect = ((Component)gamblingMachineInteractionTextCanvas).GetComponent<RectTransform>().rect;
			float num = ((Rect)(ref rect)).width / 2f - 20f;
			rect = ((Component)gamblingMachineInteractionTextCanvas).GetComponent<RectTransform>().rect;
			transform.localPosition = new Vector3(num, ((Rect)(ref rect)).height / 2f - 50f, 0f);
			gamblingMachineInteractionText = gamblingMachineInteractionTextObject.GetComponent<Text>();
			gamblingMachineInteractionText.text = interactionText;
			gamblingMachineInteractionText.alignment = (TextAnchor)4;
			gamblingMachineInteractionText.font = Plugin.GamblingFont;
			((Graphic)gamblingMachineInteractionText).rectTransform.sizeDelta = new Vector2(500f, 400f);
			gamblingMachineInteractionText.fontSize = 26;
			((Component)gamblingMachineInteractionText).transform.parent = gamblingMachineInteractionTextCanvasObject.transform;
			gamblingMachineInteractionScrapInfoTextObject = new GameObject();
			((Object)gamblingMachineInteractionScrapInfoTextObject).name = interactionName + "InteractionScrapInfoTextObject";
			gamblingMachineInteractionScrapInfoTextObject.AddComponent<Text>();
			Transform transform2 = gamblingMachineInteractionScrapInfoTextObject.transform;
			rect = ((Component)gamblingMachineInteractionTextCanvas).GetComponent<RectTransform>().rect;
			float num2 = ((Rect)(ref rect)).width / 2f - 20f;
			rect = ((Component)gamblingMachineInteractionTextCanvas).GetComponent<RectTransform>().rect;
			transform2.localPosition = new Vector3(num2, ((Rect)(ref rect)).height / 2f - 100f, 0f);
			gamblingMachineInteractionScrapInfoText = gamblingMachineInteractionScrapInfoTextObject.GetComponent<Text>();
			gamblingMachineInteractionScrapInfoText.text = interactionText;
			gamblingMachineInteractionScrapInfoText.alignment = (TextAnchor)4;
			gamblingMachineInteractionScrapInfoText.font = Plugin.GamblingFont;
			((Graphic)gamblingMachineInteractionScrapInfoText).rectTransform.sizeDelta = new Vector2(500f, 300f);
			gamblingMachineInteractionScrapInfoText.fontSize = 18;
			((Graphic)gamblingMachineInteractionScrapInfoText).color = Color.green;
			((Component)gamblingMachineInteractionScrapInfoText).transform.parent = gamblingMachineInteractionTextCanvasObject.transform;
		}

		public void SetInteractionText(string text)
		{
			gamblingMachineInteractionText.text = text;
		}

		public void SetInteractionSubText(string text)
		{
			gamblingMachineInteractionScrapInfoText.text = text;
		}

		public void ShowInteractionText()
		{
			gamblingMachineInteractionTextCanvasObject.SetActive(true);
		}

		public void HideInteractionText()
		{
			gamblingMachineInteractionTextCanvasObject.SetActive(false);
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		public static RoundManagerCustom RoundManagerCustom;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void AwakePatch(RoundManager __instance)
		{
			Plugin.mls.LogInfo((object)"RoundManagerPatch has awoken");
			RoundManagerCustom = ((Component)__instance).gameObject.AddComponent<RoundManagerCustom>();
		}

		[HarmonyPatch("LoadNewLevelWait")]
		[HarmonyPrefix]
		public static void LoadNewLevelWaitPatch(RoundManager __instance)
		{
			Plugin.mls.LogInfo((object)"FinishGeneratingNewLevelServerRpcPatch was called");
			if (__instance.currentLevel.levelID != 3)
			{
				Plugin.mls.LogInfo((object)"Despawning gambling machine...");
				RoundManagerCustom.DespawnGamblingMachineServerRpc();
			}
			if (__instance.currentLevel.levelID == 3)
			{
				Plugin.mls.LogInfo((object)"Spawning gambling machine...");
				RoundManagerCustom.SpawnGamblingMachineServerRpc();
			}
		}

		[HarmonyPatch("DespawnPropsAtEndOfRound")]
		[HarmonyPostfix]
		public static void DespawnPropsAtEndOfRoundPatch()
		{
			Plugin.mls.LogInfo((object)"End of round: despawning gambling machines");
			RoundManagerCustom.DespawnGamblingMachineServerRpc();
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePatch(StartOfRound __instance)
		{
			Plugin.mls.LogInfo((object)"StartOfRoundPatch has awoken");
		}
	}
}
namespace GamblersMod.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}
namespace GamblersMod.GrabbableObjectCustom
{
	internal class GrabbableObjectCustom
	{
	}
}
namespace GamblersMod.config
{
	public class GambleConfigNetworkHelper
	{
		public static void OnHostRecievesClientConfigRequest(ulong clientId, FastBufferReader _)
		{
			//IL_006c: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkManager.Singleton.IsHost)
			{
				return;
			}
			Plugin.mls.LogInfo((object)"Host recieved client config request.");
			Plugin.mls.LogInfo((object)"Serializing host config data...");
			byte[] serializedSettings = SerializerHelper.GetSerializedSettings(Plugin.CurrentUserConfig);
			Plugin.mls.LogInfo((object)"Start writing host config data...");
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(serializedSettings.Length + 4, (Allocator)2, -1);
			try
			{
				Plugin.mls.LogInfo((object)"Writing host config data");
				int num = serializedSettings.Length;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteBytesSafe(serializedSettings, -1, 0);
				Plugin.mls.LogInfo((object)$"Sending host config data to client with id of {clientId}...");
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("Junypai.GamblersMod_" + GambleConstants.ON_CLIENT_RECIEVES_HOST_CONFIG_REQUEST, clientId, val, (NetworkDelivery)4);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void StartClientRequestConfigFromHost()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkManager.Singleton.IsClient)
			{
				return;
			}
			Plugin.mls.LogInfo((object)"Client is requesting configuration from host");
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
			try
			{
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("Junypai.GamblersMod_" + GambleConstants.ON_HOST_RECIEVES_CLIENT_CONFIG_REQUEST, 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void OnClientRecievesHostConfigRequest(ulong _, FastBufferReader reader)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Plugin.mls.LogInfo((object)"Client recieved configuration message from host");
			if (!((FastBufferReader)(ref reader)).TryBeginRead(4))
			{
				Plugin.mls.LogError((object)"Could not sync client configuration with host. The stream sent by StartClientRequestConfigFromHost was invalid.");
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			if (!((FastBufferReader)(ref reader)).TryBeginRead(num))
			{
				Plugin.mls.LogError((object)"Could not sync client configuration with host. Host could not serialize the data.");
				return;
			}
			byte[] settingsAsBytes = new byte[num];
			((FastBufferReader)(ref reader)).ReadBytesSafe(ref settingsAsBytes, num, 0);
			Plugin.RecentHostConfig = SerializerHelper.GetDeserializedSettings<GambleConfigSettingsSerializable>(settingsAsBytes);
			Plugin.CurrentUserConfig = Plugin.RecentHostConfig;
			Plugin.CurrentUserConfig.configGamblingMusicEnabled = Plugin.UserConfigSnapshot.configGamblingMusicEnabled;
			Plugin.CurrentUserConfig.configGamblingMusicVolume = Plugin.UserConfigSnapshot.configGamblingMusicVolume;
			ManualLogSource mls = Plugin.mls;
			mls.LogInfo((object)$"Cooldown value from config: {Plugin.CurrentUserConfig.configMaxCooldown}");
			mls.LogInfo((object)$"Jackpot chance value from config: {Plugin.CurrentUserConfig.configJackpotChance}");
			mls.LogInfo((object)$"Triple chance value from config: {Plugin.CurrentUserConfig.configTripleChance}");
			mls.LogInfo((object)$"Double chance value from config: {Plugin.CurrentUserConfig.configDoubleChance}");
			mls.LogInfo((object)$"Halve chance value from config: {Plugin.CurrentUserConfig.configHalveChance}");
			mls.LogInfo((object)$"Zero chance value from config: {Plugin.CurrentUserConfig.configZeroChance}");
			mls.LogInfo((object)$"Jackpot multiplier value from config: {Plugin.CurrentUserConfig.configJackpotMultiplier}");
			mls.LogInfo((object)$"Triple multiplier value from config: {Plugin.CurrentUserConfig.configTripleMultiplier}");
			mls.LogInfo((object)$"Double multiplier value from config: {Plugin.CurrentUserConfig.configDoubleMultiplier}");
			mls.LogInfo((object)$"Halve multiplier value from config: {Plugin.CurrentUserConfig.configHalveMultiplier}");
			mls.LogInfo((object)$"Zero multiplier value from config: {Plugin.CurrentUserConfig.configZeroMultiplier}");
			mls.LogInfo((object)$"Audio enabled from config: {Plugin.CurrentUserConfig.configGamblingMusicEnabled}");
			mls.LogInfo((object)$"Audio volume from config: {Plugin.CurrentUserConfig.configGamblingMusicVolume}");
			mls.LogInfo((object)$"Number of uses from config: {Plugin.CurrentUserConfig.configNumberOfUses}");
			Plugin.mls.LogInfo((object)"Successfully synced a client with host configuration");
		}
	}
	[Serializable]
	public class GambleConfigSettingsSerializable
	{
		public int configMaxCooldown;

		public int configNumberOfUses;

		public int configMaxValueLimit;

		public string configMachineSpawnMode;

		public int configNumberOfRows;

		public int configMachinesPerRow;

		public float configRowSpacing;

		public float configColumnSpacing;

		public float configMachineRotation;

		public float configLayoutOffsetX;

		public float configLayoutOffsetY;

		public float configLayoutOffsetZ;

		public int configJackpotChance;

		public int configTripleChance;

		public int configDoubleChance;

		public int configHalveChance;

		public int configZeroChance;

		public int configExplodeChance;

		public float configJackpotMultiplier;

		public float configTripleMultiplier;

		public float configDoubleMultiplier;

		public float configHalveMultiplier;

		public float configZeroMultiplier;

		public float configExplodeMultiplier;

		public bool configGamblingMusicEnabled;

		public float configGamblingMusicVolume;

		public GambleConfigSettingsSerializable(ConfigFile configFile)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			LoadLegacyLayoutDefaults(configFile, out var spawnMode, out var rows, out var machinesPerRow, out var rowSpacing, out var columnSpacing, out var rotation, out var offsetX, out var offsetY, out var offsetZ);
			configFile.Bind<int>(GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_MAXCOOLDOWN, 4, "Cooldown of the machine. Reducing this will cause the drumroll sound to not sync & may also cause latency issues");
			configFile.Bind<int>(GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_NUMBER_OF_USES, 9999, "Number of times a gambling machine can be used");
			configFile.Bind<int>(GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_MAX_VALUE_LIMIT, int.MaxValue, "Maximum scrap value after gambling. 0 or negative disables the cap");
			string text = CoerceSpawnMode(spawnMode);
			configFile.Bind<string>(GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_MACHINE_SPAWN_MODE, text, new ConfigDescription("Machine spawn mode: AUTO spawns up to the player count, MAX fills the grid capacity", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "AUTO", "MAX" }), Array.Empty<object>()));
			configFile.Bind<int>(GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_NUMBER_OF_ROWS, rows, "How many rows of gambling machines will be spawned (along X). Allows negatives in spacing to flip direction");
			configFile.Bind<int>(GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_MACHINES_PER_ROW, machinesPerRow, "How many gambling machines to place per row (along Z). Allows negatives in spacing to flip direction");
			configFile.Bind<float>(GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_ROW_SPACING, rowSpacing, "Distance between rows of machines along X. Decimals allowed (e.g. 0.3). Zero falls back to 5");
			configFile.Bind<float>(GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_COLUMN_SPACING, columnSpacing, "Distance between machines in a row along Z. Decimals allowed (e.g. 0.3). Zero falls back to 5");
			configFile.Bind<float>(GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_MACHINE_ROTATION, rotation, "Yaw rotation for each machine in degrees (0-359). Invalid values fall back to 90");
			configFile.Bind<float>(GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_LAYOUT_OFFSET_X, offsetX, "Offset the anchor position on the X axis (rows). Decimals allowed. 0 keeps the base point");
			configFile.Bind<float>(GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_LAYOUT_OFFSET_Y, offsetY, "Offset the anchor position on the Y axis (height). Decimals allowed. 0 keeps the base point");
			configFile.Bind<float>(GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_LAYOUT_OFFSET_Z, offsetZ, "Offset the anchor position on the Z axis (columns). Decimals allowed. 0 keeps the base point");
			configFile.Bind<int>(GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_JACKPOT_CHANCE_KEY, 3, "Chance to roll a jackpot. Ex. If set to 3, you have a 3% chance to get a jackpot. Make sure ALL your chance values add up to 100 or else the math won't make sense!");
			configFile.Bind<int>(GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_TRIPLE_CHANCE_KEY, 11, "Chance to roll a triple. Ex. If set to 11, you have a 11% chance to get a triple. Make sure ALL your chance values add up to 100 or else the math won't make sense!");
			configFile.Bind<int>(GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_DOUBLE_CHANCE_KEY, 27, "Chance to roll a double. Ex. If set to 27, you have a 27% chance to get a double. Make sure ALL your chance values add up to 100 or else the math won't make sense!");
			configFile.Bind<int>(GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_HALVE_CHANCE_KEY, 49, "Chance to roll a halve. Ex. If set to 49, you have a 49% chance to get a halve. Make sure ALL your chance values add up to 100 or else the math won't make sense!");
			configFile.Bind<int>(GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_ZERO_CHANCE_KEY, 9, "Chance to roll a zero. Ex. If set to 12, you have a 12% chance to get a zero. Make sure ALL your chance values add up to 100 or else the math won't make sense!");
			configFile.Bind<int>(GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_EXPLODE_CHANCE_KEY, 1, "Chance to explode. Make sure ALL your chance values add up to 100 or else the math won't make sense!");
			configFile.Bind<float>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_JACKPOT_MULTIPLIER, 10f, "Jackpot multiplier");
			configFile.Bind<float>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_TRIPLE_MULTIPLIER, 3f, "Triple multiplier");
			configFile.Bind<float>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_DOUBLE_MULTIPLIER, 2f, "Double multiplier");
			configFile.Bind<float>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_HALVE_MULTIPLIER, 0.5f, "Halve multiplier");
			configFile.Bind<float>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_ZERO_MULTIPLIER, 0f, "Zero multiplier");
			configFile.Bind<float>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_EXPLODE_MULTIPLIER, 0f, "Explode multiplier applied before the explosion");
			configFile.Bind<bool>(GambleConstants.GAMBLING_AUDIO_SECTION_KEY, GambleConstants.CONFIG_GAMBLING_MUSIC_ENABLED, true, "Enable gambling machine music (CLIENT SIDE)");
			configFile.Bind<float>(GambleConstants.GAMBLING_AUDIO_SECTION_KEY, GambleConstants.CONFIG_GAMBLING_MUSIC_VOLUME, 0.35f, "Gambling machine music volume (CLIENT SIDE)");
			configMaxCooldown = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_MAXCOOLDOWN);
			configJackpotChance = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_JACKPOT_CHANCE_KEY);
			configTripleChance = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_TRIPLE_CHANCE_KEY);
			configDoubleChance = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_DOUBLE_CHANCE_KEY);
			configHalveChance = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_HALVE_CHANCE_KEY);
			configZeroChance = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_ZERO_CHANCE_KEY);
			configExplodeChance = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_CHANCE_SECTION_KEY, GambleConstants.CONFIG_EXPLODE_CHANCE_KEY);
			configJackpotMultiplier = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_JACKPOT_MULTIPLIER);
			configTripleMultiplier = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_TRIPLE_MULTIPLIER);
			configDoubleMultiplier = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_DOUBLE_MULTIPLIER);
			configHalveMultiplier = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_HALVE_MULTIPLIER);
			configZeroMultiplier = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_ZERO_MULTIPLIER);
			configExplodeMultiplier = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_EXPLODE_MULTIPLIER);
			configGamblingMusicEnabled = GetConfigFileKeyValue<bool>(configFile, GambleConstants.GAMBLING_AUDIO_SECTION_KEY, GambleConstants.CONFIG_GAMBLING_MUSIC_ENABLED);
			configGamblingMusicVolume = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_AUDIO_SECTION_KEY, GambleConstants.CONFIG_GAMBLING_MUSIC_VOLUME);
			configNumberOfUses = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_NUMBER_OF_USES);
			configMaxValueLimit = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_MAX_VALUE_LIMIT);
			configMachineSpawnMode = GetConfigFileKeyValue<string>(configFile, GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_MACHINE_SPAWN_MODE);
			configNumberOfRows = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_NUMBER_OF_ROWS);
			configMachinesPerRow = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_MACHINES_PER_ROW);
			configRowSpacing = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_ROW_SPACING);
			configColumnSpacing = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_COLUMN_SPACING);
			configMachineRotation = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_MACHINE_ROTATION);
			configLayoutOffsetX = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_LAYOUT_OFFSET_X);
			configLayoutOffsetY = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_LAYOUT_OFFSET_Y);
			configLayoutOffsetZ = GetConfigFileKeyValue<float>(configFile, GambleConstants.GAMBLING_LAYOUT_SECTION_KEY, GambleConstants.CONFIG_LAYOUT_OFFSET_Z);
			LogInitializedConfigsValues();
		}

		private void LogInitializedConfigsValues()
		{
			ManualLogSource mls = Plugin.mls;
			mls.LogInfo((object)$"Cooldown value from config: {configMaxCooldown}");
			mls.LogInfo((object)$"Jackpot chance value from config: {configJackpotChance}");
			mls.LogInfo((object)$"Triple chance value from config: {configTripleChance}");
			mls.LogInfo((object)$"Double chance value from config: {configDoubleChance}");
			mls.LogInfo((object)$"Halve chance value from config: {configHalveChance}");
			mls.LogInfo((object)$"Zero chance value from config: {configZeroChance}");
			mls.LogInfo((object)$"Explode chance value from config: {configExplodeChance}");
			mls.LogInfo((object)$"Jackpot multiplier value from config: {configJackpotMultiplier}");
			mls.LogInfo((object)$"Triple multiplier value from config: {configTripleMultiplier}");
			mls.LogInfo((object)$"Double multiplier value from config: {configDoubleMultiplier}");
			mls.LogInfo((object)$"Halve multiplier value from config: {configHalveMultiplier}");
			mls.LogInfo((object)$"Zero multiplier value from config: {configZeroMultiplier}");
			mls.LogInfo((object)$"Explode multiplier value from config: {configExplodeMultiplier}");
			mls.LogInfo((object)$"Music enabled from config: {configGamblingMusicEnabled}");
			mls.LogInfo((object)$"Music volume from config: {configGamblingMusicVolume}");
			mls.LogInfo((object)$"Number of uses from config: {configNumberOfUses}");
			mls.LogInfo((object)$"Max value limit from config: {configMaxValueLimit}");
			mls.LogInfo((object)("Machine spawn mode from config: " + configMachineSpawnMode));
			mls.LogInfo((object)$"Number of rows from config: {configNumberOfRows}");
			mls.LogInfo((object)$"Machines per row from config: {configMachinesPerRow}");
			mls.LogInfo((object)$"Row spacing from config: {configRowSpacing}");
			mls.LogInfo((object)$"Column spacing from config: {configColumnSpacing}");
			mls.LogInfo((object)$"Machine rotation from config: {configMachineRotation}");
			mls.LogInfo((object)$"Layout offset X from config: {configLayoutOffsetX}");
			mls.LogInfo((object)$"Layout offset Y from config: {configLayoutOffsetY}");
			mls.LogInfo((object)$"Layout offset Z from config: {configLayoutOffsetZ}");
		}

		private T GetConfigFileKeyValue<T>(ConfigFile configFile, string section, string key)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ConfigDefinition val = new ConfigDefinition(section, key);
			Plugin.mls.LogInfo((object)("Getting configuration entry: Section: " + section + " Key: " + key));
			ConfigEntry<T> val2 = default(ConfigEntry<T>);
			if (!configFile.TryGetEntry<T>(val, ref val2))
			{
				Plugin.mls.LogError((object)("Failed to get configuration value. Section: " + section + " Key: " + key));
			}
			return val2.Value;
		}

		private static void LoadLegacyLayoutDefaults(ConfigFile configFile, out string spawnMode, out int rows, out int machinesPerRow, out float rowSpacing, out float columnSpacing, out float rotation, out float offsetX, out float offsetY, out float offsetZ)
		{
			spawnMode = "AUTO";
			rows = 1;
			machinesPerRow = 12;
			rowSpacing = 5f;
			columnSpacing = 5f;
			rotation = 90f;
			offsetX = 0f;
			offsetY = 0f;
			offsetZ = 0f;
			TryReadLegacy(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_MACHINE_SPAWN_MODE, ref spawnMode);
			TryReadLegacy(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_NUMBER_OF_ROWS, ref rows);
			TryReadLegacy(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_MACHINES_PER_ROW, ref machinesPerRow);
			TryReadLegacy(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_ROW_SPACING, ref rowSpacing);
			TryReadLegacy(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_COLUMN_SPACING, ref columnSpacing);
			TryReadLegacy(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_MACHINE_ROTATION, ref rotation);
			TryReadLegacy(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_LAYOUT_OFFSET_X, ref offsetX);
			TryReadLegacy(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_LAYOUT_OFFSET_Y, ref offsetY);
			TryReadLegacy(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_LAYOUT_OFFSET_Z, ref offsetZ);
		}

		private static string CoerceSpawnMode(string mode)
		{
			if (!((mode ?? string.Empty).ToUpperInvariant() == "MAX"))
			{
				return "AUTO";
			}
			return "MAX";
		}

		private static void TryReadLegacy<T>(ConfigFile configFile, string section, string key, ref T target)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ConfigDefinition val = new ConfigDefinition(section, key);
			ConfigEntry<T> val2 = default(ConfigEntry<T>);
			if (configFile.TryGetEntry<T>(val, ref val2))
			{
				target = val2.Value;
				configFile.Remove(val);
			}
		}
	}
	public class GambleConstants
	{
		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public struct GamblingOutcome
		{
			public static string JACKPOT = "JACKPOT";

			public static string TRIPLE = "TRIPLE";

			public static string DOUBLE = "DOUBLE";

			public static string HALVE = "HALVE";

			public static string REMOVE = "REMOVE";

			public static string EXPLODE = "EXPLODE";

			public static string DEFAULT = "DEFAULT";
		}

		public static readonly string GAMBLING_GENERAL_SECTION_KEY = "General Machine Settings";

		public static readonly string GAMBLING_CHANCE_SECTION_KEY = "Gambling Chances";

		public static readonly string GAMBLING_MULTIPLIERS_SECTION_KEY = "Gambling Multipliers";

		public static readonly string GAMBLING_AUDIO_SECTION_KEY = "Audio";

		public static readonly string GAMBLING_LAYOUT_SECTION_KEY = "Machine Layout";

		public static readonly string CONFIG_MAXCOOLDOWN = "gamblingMachineMaxCooldown";

		public static readonly string CONFIG_NUMBER_OF_USES = "Number Of Uses";

		public static readonly string CONFIG_MAX_VALUE_LIMIT = "Max Value Limit";

		public static readonly string CONFIG_MACHINE_SPAWN_MODE = "Machine Spawn Mode";

		public static readonly string CONFIG_NUMBER_OF_ROWS = "Number Of Rows";

		public static readonly string CONFIG_MACHINES_PER_ROW = "Machines Per Row";

		public static readonly string CONFIG_ROW_SPACING = "Row Spacing";

		public static readonly string CONFIG_COLUMN_SPACING = "Machine Spacing";

		public static readonly string CONFIG_MACHINE_ROTATION = "Machine Rotation";

		public static readonly string CONFIG_LAYOUT_OFFSET_X = "Layout Offset X";

		public static readonly string CONFIG_LAYOUT_OFFSET_Y = "Layout Offset Y";

		public static readonly string CONFIG_LAYOUT_OFFSET_Z = "Layout Offset Z";

		public const string MACHINE_SPAWN_MODE_AUTO = "AUTO";

		public const string MACHINE_SPAWN_MODE_MAX = "MAX";

		public static readonly string CONFIG_JACKPOT_CHANCE_KEY = "JackpotChance";

		public static readonly string CONFIG_TRIPLE_CHANCE_KEY = "TripleChance";

		public static readonly string CONFIG_DOUBLE_CHANCE_KEY = "DoubleChance";

		public static readonly string CONFIG_HALVE_CHANCE_KEY = "HalveChance";

		public static readonly string CONFIG_ZERO_CHANCE_KEY = "ZeroChance";

		public static readonly string CONFIG_EXPLODE_CHANCE_KEY = "ExplodeChance";

		public static readonly string CONFIG_JACKPOT_MULTIPLIER = "JackpotMultiplier";

		public static readonly string CONFIG_TRIPLE_MULTIPLIER = "TripleMultiplier";

		public static readonly string CONFIG_DOUBLE_MULTIPLIER = "DoubleMultiplier";

		public static readonly string CONFIG_HALVE_MULTIPLIER = "HalveMultiplier";

		public static readonly string CONFIG_ZERO_MULTIPLIER = "ZeroMultiplier";

		public static readonly string CONFIG_EXPLODE_MULTIPLIER = "ExplodeMultiplier";

		public static readonly string CONFIG_GAMBLING_MUSIC_ENABLED = "GambleMachineMusicEnabled";

		public static readonly string CONFIG_GAMBLING_MUSIC_VOLUME = "GambleMachineMusicVolume";

		public static readonly string ON_HOST_RECIEVES_CLIENT_CONFIG_REQUEST = "OnHostRecievesClientConfigRequest";

		public static readonly string ON_CLIENT_RECIEVES_HOST_CONFIG_REQUEST = "OnClientRecievesHostConfigRequest";
	}
	internal class SerializerHelper
	{
		public static byte[] GetSerializedSettings<T>(T valToSerialize)
		{
			MemoryStream memoryStream = new MemoryStream();
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			try
			{
				binaryFormatter.Serialize(memoryStream, valToSerialize);
			}
			catch (SerializationException ex)
			{
				Plugin.mls.LogError((object)("Config serialization failed: " + ex.Message));
			}
			byte[] result = memoryStream.ToArray();
			memoryStream.Close();
			return result;
		}

		public static T GetDeserializedSettings<T>(byte[] settingsAsBytes)
		{
			MemoryStream memoryStream = new MemoryStream();
			memoryStream.Write(settingsAsBytes, 0, settingsAsBytes.Length);
			memoryStream.Seek(0L, SeekOrigin.Begin);
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			try
			{
				object obj = binaryFormatter.Deserialize(memoryStream);
				memoryStream.Close();
				return (T)obj;
			}
			catch (SerializationException ex)
			{
				Plugin.mls.LogError((object)("Config deserialization failed: " + ex.Message));
			}
			memoryStream.Close();
			return default(T);
		}
	}
}