using System;
using System.Collections;
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")]
namespace GamblersMod
{
[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 GambleConfigSettingsSerializable UserConfigSnapshot;
public static GambleConfigSettingsSerializable RecentHostConfig;
public static GambleConfigSettingsSerializable CurrentUserConfig;
public static ManualLogSource mls;
private void Awake()
{
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");
GamblingMachineResultCanvas = LoadAssetFromAssetBundleAndLogInfo<GameObject>(val, "GamblingMachineResultCanvas");
GamblingMachine = LoadAssetFromAssetBundleAndLogInfo<GameObject>(val, "GamblingMachine");
GamblingMachine.AddComponent<GamblingMachine>();
harmony.PatchAll(typeof(Plugin));
harmony.PatchAll(typeof(GameNetworkManagerPatch));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(RoundManagerPatch));
}
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);
}
}
}
}
}
}
namespace GamblersMod.RoundManagerCustomSpace
{
internal class RoundManagerCustom : NetworkBehaviour
{
public RoundManager RoundManager;
public GameObject GamblingMachine;
private void Awake()
{
RoundManager = ((Component)this).GetComponent<RoundManager>();
}
[ServerRpc]
public void DespawnGamblingMachineServerRpc()
{
GamblingMachine.GetComponent<NetworkObject>().Despawn(true);
}
[ServerRpc]
public void SpawnGamblingMachineServerRpc()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
Plugin.mls.LogInfo((object)("Attempting to spawn gambling machine at " + ((Object)RoundManager.currentLevel).name));
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(-27.808f, -2.6256f, -9.7409f);
GamblingMachine = Object.Instantiate<GameObject>(Plugin.GamblingMachine, val, Quaternion.Euler(0f, 90f, 0f));
GamblingMachine.tag = "Untagged";
GamblingMachine.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
GamblingMachine.layer = LayerMask.NameToLayer("InteractableObject");
GamblingMachine.GetComponent<NetworkObject>().Spawn(false);
}
}
}
namespace GamblersMod.Player
{
internal class PlayerControllerCustom : NetworkBehaviour
{
private PlayerGamblingUIManager PlayerGamblingUIManager;
private PlayerControllerB PlayerControllerOriginal;
private bool lockGamblingMachineServer = false;
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
{
string bindingDisplayString = InputActionRebindingExtensions.GetBindingDisplayString(IngamePlayerSettings.Instance.playerInput.actions.FindAction("Interact", false), 0, (DisplayStringOptions)0);
PlayerGamblingUIManager.SetInteractionText("Press " + bindingDisplayString + " to gamble");
}
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();
}
}
[ServerRpc(RequireOwnership = false)]
private void ActivateGamblingMachineServerRPC(NetworkBehaviourReference GambleMachineHitRef, NetworkBehaviourReference scrapBeingGambledRef, ServerRpcParams serverRpcParams = default(ServerRpcParams))
{
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: 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 (!((NetworkBehaviour)this).IsServer)
{
return;
}
if (lockGamblingMachineServer)
{
Plugin.mls.LogWarning((object)"Gambling machine is already processing one client's request. Throwing away a request...");
return;
}
lockGamblingMachineServer = true;
GamblingMachine gamblingMachine = default(GamblingMachine);
if (!((NetworkBehaviourReference)(ref GambleMachineHitRef)).TryGet<GamblingMachine>(ref gamblingMachine, (NetworkManager)null))
{
Plugin.mls.LogError((object)"ActivateGamblingMachineServerRPC: Failed to get gambling machine on server side.");
return;
}
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(GambleMachineHitRef);
Plugin.mls.LogMessage((object)("ActivateGamblingMachineServerRPC: Starting gambling machine cooldown phase in the server invoked by: " + serverRpcParams.Receive.SenderClientId));
int roll = gamblingMachine.RollDice();
gamblingMachine.SetRoll(roll);
gamblingMachine.GenerateGamblingOutcomeFromCurrentRoll();
int scrapValueBasedOnGambledOutcome = gamblingMachine.GetScrapValueBasedOnGambledOutcome(scrap);
ActivateGamblingMachineClientRPC(GambleMachineHitRef, scrapBeingGambledRef, scrapValueBasedOnGambledOutcome, gamblingMachine.currentGamblingOutcome);
Plugin.mls.LogMessage((object)"Unlocking gambling machine");
lockGamblingMachineServer = false;
}
[ClientRpc]
private void ActivateGamblingMachineClientRPC(NetworkBehaviourReference GambleMachineHitRef, NetworkBehaviourReference scrapBeingGambledRef, int updatedScrapValue, string outcome)
{
//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...");
GamblingMachine GambleMachineHit = default(GamblingMachine);
if (!((NetworkBehaviourReference)(ref GambleMachineHitRef)).TryGet<GamblingMachine>(ref GambleMachineHit, (NetworkManager)null))
{
Plugin.mls.LogError((object)"ActivateGamblingMachineClientRPC: Failed to get gambling machine on client side.");
return;
}
GambleMachineHit.PlayDrumRoll();
GambleMachineHit.BeginGamblingMachineCooldown(delegate
{
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
{
val.SetScrapValue(updatedScrapValue);
GambleMachineHit.PlayGambleResultAudio(outcome);
}
});
}
[ClientRpc]
private void BeginGamblingMachineCooldownClientRpc(NetworkBehaviourReference GambleMachineHitRef)
{
GamblingMachine gamblingMachine = default(GamblingMachine);
if (!((NetworkBehaviourReference)(ref GambleMachineHitRef)).TryGet<GamblingMachine>(ref gamblingMachine, (NetworkManager)null))
{
Plugin.mls.LogError((object)"BeginGamblingMachineCooldownClientRpc: Failed to get gambling machine on client side.");
}
else
{
gamblingMachine.SetCurrentGamblingCooldownToMaxCooldown();
}
}
private void handleGamblingMachineInput(GamblingMachine GamblingMachineHit)
{
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_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)
GrabbableObject val = PlayerControllerOriginal.ItemSlots[PlayerControllerOriginal.currentItemSlot];
if (Object.op_Implicit((Object)(object)val) && !GamblingMachineHit.isInCooldownPhase())
{
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}");
ActivateGamblingMachineServerRPC(NetworkBehaviourReference.op_Implicit((NetworkBehaviour)(object)GamblingMachineHit), NetworkBehaviourReference.op_Implicit((NetworkBehaviour)(object)val));
PlayerGamblingUIManager.SetInteractionText($"Cooling down... {GamblingMachineHit.gamblingMachineCurrentCooldown}");
}
}
}
}
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;
}
}
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_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Expected O, but got Unknown
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: 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_023c: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
//IL_02da: Unknown result type (might be due to invalid IL or missing references)
gamblingMachineInteractionTextCanvasObject = new GameObject();
gamblingMachineInteractionTextCanvasObject.transform.parent = ((Component)this).transform;
interactionName = "gamblingMachine";
interactionText = "Press E to gamble";
((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 = Resources.GetBuiltinResource<Font>("Arial.ttf");
((Graphic)gamblingMachineInteractionText).rectTransform.sizeDelta = new Vector2(300f, 200f);
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 = Resources.GetBuiltinResource<Font>("Arial.ttf");
((Graphic)gamblingMachineInteractionScrapInfoText).rectTransform.sizeDelta = new Vector2(300f, 200f);
gamblingMachineInteractionScrapInfoText.fontSize = 15;
((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);
}
}
internal class GamblingMachine : NetworkBehaviour
{
private int gamblingMachineMaxCooldown;
public int gamblingMachineCurrentCooldown = 0;
private int jackpotMultiplier;
private int tripleMultiplier;
private int doubleMultiplier;
private float halvedMultiplier;
private int jackpotPercentage;
private int triplePercentage;
private int doublePercentage;
private int halvedPercentage;
private int removedPercentage;
private int zeroMultiplier;
private bool isMusicEnabled = true;
private float musicVolume = 0.35f;
private int rollMinValue;
private int rollMaxValue;
private int currentRoll = 1;
public float currentGamblingOutcomeMultiplier = 1f;
public string currentGamblingOutcome = GambleConstants.GamblingOutcome.DEFAULT;
private Coroutine CountdownCooldownCoroutineBeingRan;
private void Awake()
{
Plugin.mls.LogInfo((object)"GamblingMachine has Awoken");
gamblingMachineMaxCooldown = Plugin.CurrentUserConfig.configMaxCooldown;
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);
}
private void InitAudioSource()
{
if (!isMusicEnabled)
{
((Component)this).GetComponent<AudioSource>().Pause();
}
((Component)this).GetComponent<AudioSource>().volume = musicVolume;
}
}
[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();
}
}
}
}
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}");
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_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 configJackpotChance;
public int configTripleChance;
public int configDoubleChance;
public int configHalveChance;
public int configZeroChance;
public int configJackpotMultiplier;
public int configTripleMultiplier;
public int configDoubleMultiplier;
public float configHalveMultiplier;
public int 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.");
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<int>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_JACKPOT_MULTIPLIER, 10, "Jackpot multiplier");
configFile.Bind<int>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_TRIPLE_MULTIPLIER, 3, "Triple multiplier");
configFile.Bind<int>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_DOUBLE_MULTIPLIER, 2, "Double multiplier");
configFile.Bind<float>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_HALVE_MULTIPLIER, 0.5f, "Halve multiplier");
configFile.Bind<int>(GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_ZERO_MULTIPLIER, 0, "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<int>(configFile, GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_JACKPOT_MULTIPLIER);
configTripleMultiplier = GetConfigFileKeyValue<int>(configFile, GambleConstants.GAMBLING_MULTIPLIERS_SECTION_KEY, GambleConstants.CONFIG_TRIPLE_MULTIPLIER);
configDoubleMultiplier = GetConfigFileKeyValue<int>(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<int>(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);
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)$"gambling music enabled from config: {configGamblingMusicEnabled}");
mls.LogInfo((object)$"gambling music volume from config: {configGamblingMusicVolume}");
}
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);
}
}
}