Decompiled source of RyumisFairGamblingMod v1.3.6

GamblersMod.dll

Decompiled 7 months 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.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.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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
internal class <Module>
{
	static <Module>()
	{
	}
}
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_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_0054: 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);
			if (GamblingMachines.Count >= 1)
			{
				val.GetComponent<AudioSource>().Pause();
			}
			GamblingMachines.Add(val);
		}

		public void DespawnAll()
		{
			Plugin.mls.LogMessage((object)"Despwawning gambling machine...");
			foreach (GameObject gamblingMachine in GamblingMachines)
			{
				gamblingMachine.GetComponent<NetworkObject>().Despawn(true);
			}
			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 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_0177: 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");
			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"));
			}
			else
			{
				mls.LogInfo((object)(assetName + " asset successfully loaded"));
			}
			return val;
		}

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

		[ServerRpc]
		public void DespawnGamblingMachineServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Invalid comparison between Unknown and I4
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Invalid comparison between Unknown and I4
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
				{
					if ((int)networkManager.LogLevel <= 1)
					{
						Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
					}
					return;
				}
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1680317104u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1680317104u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				GamblingMachineManager.Instance.DespawnAll();
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_StartOfRoundCustom()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1680317104u, new RpcReceiveHandler(__rpc_handler_1680317104));
		}

		private static void __rpc_handler_1680317104(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
			}
			else
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((StartOfRoundCustom)(object)target).DespawnGamblingMachineServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "StartOfRoundCustom";
		}
	}
}
namespace GamblersMod.RoundManagerCustomSpace
{
	internal class RoundManagerCustom : NetworkBehaviour
	{
		public RoundManager RoundManager;

		public GameObject GamblingMachine;

		private List<Vector3> spawnPoints;

		private void Awake()
		{
			//IL_002d: 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_006d: 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)
			RoundManager = ((Component)this).GetComponent<RoundManager>();
			spawnPoints = new List<Vector3>();
			spawnPoints.Add(new Vector3(-27.808f, -2.6256f, -9.7409f));
			spawnPoints.Add(new Vector3(-27.808f, -2.6256f, -4.7409f));
			spawnPoints.Add(new Vector3(-27.808f, -2.6256f, 0.7409f));
			spawnPoints.Add(new Vector3(-27.808f, -2.6256f, 6.7409f));
		}

		[ServerRpc]
		public void DespawnGamblingMachineServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Invalid comparison between Unknown and I4
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Invalid comparison between Unknown and I4
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
				{
					if ((int)networkManager.LogLevel <= 1)
					{
						Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
					}
					return;
				}
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3258984052u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3258984052u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				GamblingMachineManager.Instance.DespawnAll();
			}
		}

		[ServerRpc]
		public void SpawnGamblingMachineServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Invalid comparison between Unknown and I4
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Invalid comparison between Unknown and I4
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
				{
					if ((int)networkManager.LogLevel <= 1)
					{
						Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
					}
					return;
				}
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2764001088u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2764001088u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				Plugin.mls.LogInfo((object)("Attempting to spawn gambling machine at " + ((Object)RoundManager.currentLevel).name));
				for (int i = 0; i < Plugin.CurrentUserConfig.configNumberOfMachines && i < spawnPoints.Count; i++)
				{
					Plugin.mls.LogInfo((object)$"AA: {spawnPoints}");
					Plugin.mls.LogInfo((object)$"AAWW: {spawnPoints[i]}");
					GamblingMachineManager.Instance.Spawn(spawnPoints[i], Quaternion.Euler(0f, 90f, 0f));
					Plugin.mls.LogInfo((object)$"Spawned machine number: {i}");
				}
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_RoundManagerCustom()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3258984052u, new RpcReceiveHandler(__rpc_handler_3258984052));
			NetworkManager.__rpc_func_table.Add(2764001088u, new RpcReceiveHandler(__rpc_handler_2764001088));
		}

		private static void __rpc_handler_3258984052(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
			}
			else
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RoundManagerCustom)(object)target).DespawnGamblingMachineServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2764001088(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
			}
			else
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((RoundManagerCustom)(object)target).SpawnGamblingMachineServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "RoundManagerCustom";
		}
	}
}
namespace GamblersMod.Player
{
	internal class PlayerControllerCustom : NetworkBehaviour
	{
		private PlayerGamblingUIManager PlayerGamblingUIManager;

		private PlayerControllerB PlayerControllerOriginal;

		public bool isUsingGamblingMachine;

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

		private void Update()
		{
			//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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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 = default(Ray);
			((Ray)(ref val))..ctor(position, forward);
			float num = 5f;
			int num2 = 512;
			RaycastHit val2 = default(RaycastHit);
			bool flag = Physics.Raycast(val, ref val2, num, num2);
			if (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);
						if (isUsingGamblingMachine)
						{
							PlayerGamblingUIManager.SetInteractionText("You're already using a machine");
						}
						else
						{
							PlayerGamblingUIManager.SetInteractionText("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 GamblingMachineHit)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			GrabbableObject val = PlayerControllerOriginal.ItemSlots[PlayerControllerOriginal.currentItemSlot];
			if (Object.op_Implicit((Object)(object)val) && !GamblingMachineHit.isInCooldownPhase() && GamblingMachineHit.numberOfUses > 0 && !isUsingGamblingMachine)
			{
				Plugin.mls.LogInfo((object)("Gambling machine was interacted with by: " + PlayerControllerOriginal.playerUsername));
				GamblingMachineHit.SetCurrentGamblingCooldownToMaxCooldown();
				Plugin.mls.LogMessage((object)$"Scrap value of {((Object)val).name} on hand: ▊{val.scrapValue}");
				GamblingMachineHit.ActivateGamblingMachineServerRPC(NetworkBehaviourReference.op_Implicit((NetworkBehaviour)(object)val), NetworkBehaviourReference.op_Implicit((NetworkBehaviour)(object)this));
				PlayerGamblingUIManager.SetInteractionText($"Cooling down... {GamblingMachineHit.gamblingMachineCurrentCooldown}");
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "PlayerControllerCustom";
		}
	}
}
namespace GamblersMod.Patches
{
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPatch(GameNetworkManager __instance)
		{
			Plugin.mls.LogInfo((object)"Adding Gambling machine to network prefab");
			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;
		}
	}
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class GrabbableObjectPatch
	{
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePatch(StartOfRound __instance)
		{
			Plugin.mls.LogInfo((object)"StartOfRoundPatch has awoken");
		}
	}
	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;

		private void Awake()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00e2: 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_0106: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: 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_01c5: Expected O, but got Unknown
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: 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);
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "PlayerGamblingUIManager";
		}
	}
	internal class GamblingMachine : NetworkBehaviour
	{
		private int gamblingMachineMaxCooldown;

		public int gamblingMachineCurrentCooldown = 0;

		private float jackpotMultiplier;

		private float tripleMultiplier;

		private float doubleMultiplier;

		private float halvedMultiplier;

		private float zeroMultiplier;

		private int jackpotPercentage;

		private int triplePercentage;

		private int doublePercentage;

		private int halvedPercentage;

		private int removedPercentage;

		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 = false;

		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;
			jackpotPercentage = Plugin.CurrentUserConfig.configJackpotChance;
			triplePercentage = Plugin.CurrentUserConfig.configTripleChance;
			doublePercentage = Plugin.CurrentUserConfig.configDoubleChance;
			halvedPercentage = Plugin.CurrentUserConfig.configHalveChance;
			removedPercentage = Plugin.CurrentUserConfig.configZeroChance;
			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: 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: gamblingMusicEnabled loaded from config: {isMusicEnabled}");
			Plugin.mls.LogInfo((object)$"GamblingMachine: gamblingMusicVolume loaded from config: {musicVolume}");
			InitAudioSource();
			rollMinValue = 1;
			rollMaxValue = jackpotPercentage + triplePercentage + doublePercentage + halvedPercentage + removedPercentage;
		}

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

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

		public void PlayGambleResultAudio(string outcome)
		{
			//IL_001c: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_000c: 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;
		}

		private IEnumerator CountdownCooldownCoroutine(Action onCountdownFinish)
		{
			Plugin.mls.LogInfo((object)"Start gambling machine cooldown");
			while (gamblingMachineCurrentCooldown > 0)
			{
				yield return (object)new WaitForSeconds(1f);
				gamblingMachineCurrentCooldown--;
				Plugin.mls.LogMessage((object)$"Gambling machine cooldown: {gamblingMachineCurrentCooldown}");
			}
			onCountdownFinish();
			Plugin.mls.LogMessage((object)"End gambling machine cooldown");
		}

		public void SetCurrentGamblingCooldownToMaxCooldown()
		{
			gamblingMachineCurrentCooldown = gamblingMachineMaxCooldown;
		}

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

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

		public int GetScrapValueBasedOnGambledOutcome(GrabbableObject scrap)
		{
			return (int)Mathf.Floor((float)scrap.scrapValue * currentGamblingOutcomeMultiplier);
		}

		[ServerRpc(RequireOwnership = false)]
		public void ActivateGamblingMachineServerRPC(NetworkBehaviourReference scrapBeingGambledRef, NetworkBehaviourReference playerWhoGambledRef, ServerRpcParams serverRpcParams = default(ServerRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(3977934568u, serverRpcParams, (RpcDelivery)0);
				((FastBufferWriter)(ref val)).WriteValueSafe<NetworkBehaviourReference>(ref scrapBeingGambledRef, default(ForNetworkSerializable));
				((FastBufferWriter)(ref val)).WriteValueSafe<NetworkBehaviourReference>(ref playerWhoGambledRef, default(ForNetworkSerializable));
				((NetworkBehaviour)this).__endSendServerRpc(ref val, 3977934568u, serverRpcParams, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost) || !((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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(875756295u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkBehaviourReference>(ref scrapBeingGambledRef, default(ForNetworkSerializable));
				((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkBehaviourReference>(ref playerWhoGambledRef, default(ForNetworkSerializable));
				BytePacker.WriteValueBitPacked(val2, invokerId);
				BytePacker.WriteValueBitPacked(val2, updatedScrapValue);
				bool flag = outcome != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(outcome, false);
				}
				BytePacker.WriteValueBitPacked(val2, numberOfUsesServer);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 875756295u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			NetworkBehaviourReference scrapBeingGambledRef2 = scrapBeingGambledRef;
			int updatedScrapValue2 = updatedScrapValue;
			string outcome2 = outcome;
			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
			{
				GrabbableObject val3 = default(GrabbableObject);
				if (!((NetworkBehaviourReference)(ref scrapBeingGambledRef2)).TryGet<GrabbableObject>(ref val3, (NetworkManager)null))
				{
					Plugin.mls.LogError((object)"ActivateGamblingMachineClientRPC: Failed to get scrap value on client side.");
				}
				else
				{
					Plugin.mls.LogInfo((object)$"Setting scrap value to: {updatedScrapValue2}");
					val3.SetScrapValue(updatedScrapValue2);
					PlayGambleResultAudio(outcome2);
					playerWhoGambled.ReleaseGamblingMachineLock();
					if (((NetworkBehaviour)this).IsServer)
					{
						Plugin.mls.LogMessage((object)"Unlocking gambling machine");
						lockGamblingMachineServer = false;
					}
				}
			});
		}

		[ClientRpc]
		private void BeginGamblingMachineCooldownClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1546410253u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1546410253u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					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;
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_GamblingMachine()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3977934568u, new RpcReceiveHandler(__rpc_handler_3977934568));
			NetworkManager.__rpc_func_table.Add(875756295u, new RpcReceiveHandler(__rpc_handler_875756295));
			NetworkManager.__rpc_func_table.Add(1546410253u, new RpcReceiveHandler(__rpc_handler_1546410253));
		}

		private static void __rpc_handler_3977934568(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//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)
			//IL_004a: 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_0059: 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_0069: 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_0078: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				NetworkBehaviourReference scrapBeingGambledRef = default(NetworkBehaviourReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkBehaviourReference>(ref scrapBeingGambledRef, default(ForNetworkSerializable));
				NetworkBehaviourReference playerWhoGambledRef = default(NetworkBehaviourReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkBehaviourReference>(ref playerWhoGambledRef, default(ForNetworkSerializable));
				ServerRpcParams server = rpcParams.Server;
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((GamblingMachine)(object)target).ActivateGamblingMachineServerRPC(scrapBeingGambledRef, playerWhoGambledRef, server);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_875756295(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//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)
			//IL_004a: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_00ab: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				NetworkBehaviourReference scrapBeingGambledRef = default(NetworkBehaviourReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkBehaviourReference>(ref scrapBeingGambledRef, default(ForNetworkSerializable));
				NetworkBehaviourReference playerWhoGambledRef = default(NetworkBehaviourReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkBehaviourReference>(ref playerWhoGambledRef, default(ForNetworkSerializable));
				ulong invokerId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref invokerId);
				int updatedScrapValue = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref updatedScrapValue);
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string outcome = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref outcome, false);
				}
				int numberOfUsesServer = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref numberOfUsesServer);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((GamblingMachine)(object)target).ActivateGamblingMachineClientRPC(scrapBeingGambledRef, playerWhoGambledRef, invokerId, updatedScrapValue, outcome, numberOfUsesServer);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1546410253(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((GamblingMachine)(object)target).BeginGamblingMachineCooldownClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "GamblingMachine";
		}
	}
	[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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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();
			}
		}
	}
	[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 && Object.op_Implicit((Object)(object)RoundManagerCustom.GamblingMachine))
			{
				Plugin.mls.LogInfo((object)"Despawning gambling machine...");
				RoundManagerCustom.DespawnGamblingMachineServerRpc();
			}
			if (__instance.currentLevel.levelID == 3 && !Object.op_Implicit((Object)(object)RoundManagerCustom.GamblingMachine))
			{
				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();
		}
	}
}
namespace GamblersMod.GrabbableObjectCustom
{
	internal class GrabbableObjectCustom
	{
	}
}
namespace GamblersMod.config
{
	public class GambleConfigNetworkHelper
	{
		public static void OnHostRecievesClientConfigRequest(ulong clientId, FastBufferReader _)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_00cd: 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);
			FastBufferWriter val2 = val;
			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 val2)).Dispose();
			}
		}

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

		public static void OnClientRecievesHostConfigRequest(ulong _, FastBufferReader reader)
		{
			//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)
			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.");
			}
			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}");
			mls.LogInfo((object)$"Number of machines from config: {Plugin.CurrentUserConfig.configNumberOfMachines}");
			Plugin.mls.LogInfo((object)"Successfully synced a client with host configuration");
		}
	}
	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 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 CONFIG_MAXCOOLDOWN = "gamblingMachineMaxCooldown";

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

		public static readonly string CONFIG_NUMBER_OF_MACHINES = "Number Of Machines";

		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_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_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";
	}
	[Serializable]
	public class GambleConfigSettingsSerializable
	{
		public int configMaxCooldown;

		public int configNumberOfUses;

		public int configNumberOfMachines;

		public int configJackpotChance;

		public int configTripleChance;

		public int configDoubleChance;

		public int configHalveChance;

		public int configZeroChance;

		public float configJackpotMultiplier;

		public float configTripleMultiplier;

		public float configDoubleMultiplier;

		public float configHalveMultiplier;

		public float configZeroMultiplier;

		public bool configGamblingMusicEnabled;

		public float configGamblingMusicVolume;

		public GambleConfigSettingsSerializable(ConfigFile configFile)
		{
			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_NUMBER_OF_MACHINES, 3, "How many gambling machines will be spawned (max 4)");
			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, 50, "Chance to roll a halve. Ex. If set to 47, you have a 47% 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<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<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);
			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);
			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);
			configNumberOfMachines = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_GENERAL_SECTION_KEY, GambleConstants.CONFIG_NUMBER_OF_MACHINES);
			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)$"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)$"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)$"Number of machines from config: {configNumberOfMachines}");
		}

		private T GetConfigFileKeyValue<T>(ConfigFile configFile, string section, string key)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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;
		}
	}
	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);
		}
	}
}