using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LethalCasino;
using LethalCasino.Custom;
using LethalCasinoTweaks.Components;
using LethalCasinoTweaks.Patches;
using LobbyCompatibility.Attributes;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using confusingus.LethalCasinoTweaks.NetcodePatcher;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("mrgrm7.LethalCasino")]
[assembly: AssemblyCompany("confusingus.LethalCasinoTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1+bd054c7a1a9dd12a8cd3babe26eee1b72a3bc551")]
[assembly: AssemblyProduct("LethalCasinoTweaks")]
[assembly: AssemblyTitle("confusingus.LethalCasinoTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
static <Module>()
{
}
}
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace LethalCasinoTweaks
{
[BepInPlugin("confusingus.LethalCasinoTweaks", "LethalCasinoTweaks", "1.2.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[LobbyCompatibility(/*Could not decode attribute arguments.*/)]
public class LethalCasinoTweaks : BaseUnityPlugin
{
public static LethalCasinoTweaks Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony? Harmony { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
Patch();
AttachNetworkBridgeToPrefab();
Logger.LogInfo((object)"confusingus.LethalCasinoTweaks v1.2.1 has loaded!");
}
internal static void Patch()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("confusingus.LethalCasinoTweaks");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
Logger.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
internal static void AttachNetworkBridgeToPrefab()
{
GameObject val = Plugin.Prefabs["Blackjack"];
val.AddComponent<BlackjackGameStateRpcBridge>();
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "confusingus.LethalCasinoTweaks";
public const string PLUGIN_NAME = "LethalCasinoTweaks";
public const string PLUGIN_VERSION = "1.2.1";
}
}
namespace LethalCasinoTweaks.Patches
{
[HarmonyPatch(typeof(Blackjack))]
public class BlackjackPatch
{
public static readonly int FullDeckSize = 52;
public static readonly float FDeckCardYOffset = 0.001f;
public static float FInitialDeckLocalYPos = 0.9462f;
public static float FEmptyDeckLocalYPos = FInitialDeckLocalYPos - FDeckCardYOffset * (float)FullDeckSize;
public static List<Card>? InstanceCardsInPlay = null;
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPostfix(Blackjack __instance)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
Transform cardDeckTransform = GetCardDeckTransform(__instance);
if ((Object)(object)cardDeckTransform != (Object)null)
{
FInitialDeckLocalYPos = ((Component)cardDeckTransform).transform.localPosition.y;
FEmptyDeckLocalYPos = FInitialDeckLocalYPos - FDeckCardYOffset * (float)FullDeckSize;
}
else
{
LethalCasinoTweaks.Logger.LogDebug((object)"Failed to find card deck on start, using default position");
}
}
[HarmonyPatch("ShuffleDeck")]
[HarmonyPrefix]
public static void ShuffleDeckPrefix(List<Card> ts)
{
if (InstanceCardsInPlay == null)
{
LethalCasinoTweaks.Logger.LogDebug((object)"Skipping shuffle deck behavior, InstanceCardsInPlay is null");
return;
}
LethalCasinoTweaks.Logger.LogDebug((object)$"Dropping {InstanceCardsInPlay.Count} in-play cards from new deck");
List<Card> list = new List<Card>();
foreach (Card card in ts)
{
int num = InstanceCardsInPlay.FindIndex((Card x) => x.suit == card.suit && x.face == card.face);
if (num != -1)
{
InstanceCardsInPlay.RemoveAt(num);
}
else
{
list.Add(card);
}
}
ts.Clear();
ts.AddRange(list);
}
[HarmonyPatch("CreateDeck")]
[HarmonyPrefix]
private static bool CreateDeckPrefix(Blackjack __instance, out bool __state)
{
if (!ShouldCreateDeck(__instance))
{
LethalCasinoTweaks.Logger.LogDebug((object)"Skipping create deck while non-empty");
__state = false;
return false;
}
LethalCasinoTweaks.Logger.LogDebug((object)"Storing cards in play before creating/shuffling deck");
__state = true;
InstanceCardsInPlay = __instance.playerCards.SelectMany((List<Card> c) => c).ToList();
return true;
}
[HarmonyPatch("CreateDeck")]
[HarmonyPostfix]
private static void CreateDeckPostfix(Blackjack __instance, bool __state)
{
BlackjackGameStateRpcBridge componentInParent = ((Component)__instance).GetComponentInParent<BlackjackGameStateRpcBridge>();
if ((Object)(object)componentInParent == (Object)null)
{
LethalCasinoTweaks.Logger.LogDebug((object)"Failed to find RPC bridge");
return;
}
if (__state)
{
LethalCasinoTweaks.Logger.LogDebug((object)"Playing shuffle sound for all clients");
componentInParent.OnShuffleClientRpc();
}
else
{
LethalCasinoTweaks.Logger.LogDebug((object)"Didn't create a deck, skipping shuffle sound");
}
InstanceCardsInPlay = null;
}
[HarmonyPatch("DealCard")]
[HarmonyPrefix]
private static void DealCardPrefix(Blackjack __instance)
{
if (ShouldCreateDeck(__instance))
{
LethalCasinoTweaks.Logger.LogDebug((object)"Reshuffling empty deck before dealing");
__instance.CreateDeck();
}
}
[HarmonyPatch("DealCard")]
[HarmonyPostfix]
private static void DealCardPostfix(Blackjack __instance)
{
BlackjackGameStateRpcBridge componentInParent = ((Component)__instance).GetComponentInParent<BlackjackGameStateRpcBridge>();
if ((Object)(object)componentInParent == (Object)null)
{
LethalCasinoTweaks.Logger.LogDebug((object)"Failed to find RPC bridge");
}
else
{
componentInParent.UpdateDeckCountClientRpc(__instance.deck.Count);
}
}
private static bool ShouldCreateDeck(Blackjack instance)
{
if (instance.deck != null)
{
return instance.deck.Count == 0;
}
return true;
}
private static Transform? GetCardDeckTransform(Blackjack instance)
{
return ((Component)instance).transform.Find("CardDeck");
}
}
[HarmonyPatch(typeof(Blackjack), "StartGameClientRpc")]
public static class BlackjackStartGameClientRpcPatch
{
private static readonly MethodInfo MPlayOneShot = AccessTools.Method(typeof(AudioSource), "PlayOneShot", new Type[2]
{
typeof(AudioClip),
typeof(float)
}, (Type[])null);
private static readonly FieldInfo FAudioSource = AccessTools.Field(typeof(Blackjack), "audioSource");
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
LethalCasinoTweaks.Logger.LogDebug((object)"Generating reverse patch code");
List<CodeInstruction> list = instructions.ToList();
int num = -1;
int num2 = -1;
for (int i = 0; i < list.Count; i++)
{
if (num == -1)
{
int num3 = i + 1;
if (list[i].opcode == OpCodes.Ldarg_0 && num3 < list.Count && list[num3].opcode == OpCodes.Ldfld && (FieldInfo)list[num3].operand == FAudioSource)
{
num = i;
}
}
else if (list[i].opcode == OpCodes.Callvirt && (MethodInfo)list[i].operand == MPlayOneShot)
{
num2 = i;
}
}
if (num > -1 && num2 > -1)
{
LethalCasinoTweaks.Logger.LogDebug((object)$"Found instructions to patch, removing: [{num}, {num2}]");
list.RemoveRange(num, num2 - num + 1);
}
else
{
LethalCasinoTweaks.Logger.LogWarning((object)$"Failed to find audioSource call to patch: [{num}, {num2}]");
}
return list.AsEnumerable();
}
}
}
namespace LethalCasinoTweaks.Components
{
public class BlackjackGameStateRpcBridge : NetworkBehaviour
{
private void Awake()
{
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);
}
}
}
}
[ClientRpc]
public void UpdateDeckCountClientRpc(int count)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: 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_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: 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(396620961u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, count);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 396620961u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
{
return;
}
Blackjack componentInParent = ((Component)this).GetComponentInParent<Blackjack>();
if ((Object)(object)componentInParent == (Object)null)
{
LethalCasinoTweaks.Logger.LogWarning((object)"Failed to find blackjack sibling component");
return;
}
float yPos;
if (count == 0)
{
LethalCasinoTweaks.Logger.LogDebug((object)"Adjusting CardDeck transform: deck is empty, resetting position");
yPos = BlackjackPatch.FInitialDeckLocalYPos;
}
else
{
LethalCasinoTweaks.Logger.LogDebug((object)$"Adjusting CardDeck transform: {count}");
yPos = BlackjackPatch.FEmptyDeckLocalYPos + (float)count * BlackjackPatch.FDeckCardYOffset;
}
LethalCasinoTweaks.Logger.LogDebug((object)"Adjusting CardDeck transform for shuffle");
componentInParent.SetCardDeckLocalYPosition(yPos);
}
[ClientRpc]
public void OnShuffleClientRpc()
{
//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)
{
return;
}
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3155747470u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3155747470u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
Blackjack componentInParent = ((Component)this).GetComponentInParent<Blackjack>();
if ((Object)(object)componentInParent == (Object)null)
{
LethalCasinoTweaks.Logger.LogWarning((object)"Failed to find blackjack sibling component");
return;
}
LethalCasinoTweaks.Logger.LogDebug((object)"Adjusting CardDeck transform for shuffle");
componentInParent.SetCardDeckLocalYPosition(BlackjackPatch.FInitialDeckLocalYPos);
componentInParent.audioSource.PlayOneShot(Plugin.Sounds["ShuffleDeck"], 1f);
}
}
protected override void __initializeVariables()
{
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_BlackjackGameStateRpcBridge()
{
//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(396620961u, new RpcReceiveHandler(__rpc_handler_396620961));
NetworkManager.__rpc_func_table.Add(3155747470u, new RpcReceiveHandler(__rpc_handler_3155747470));
}
private static void __rpc_handler_396620961(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
int count = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref count);
target.__rpc_exec_stage = (__RpcExecStage)2;
((BlackjackGameStateRpcBridge)(object)target).UpdateDeckCountClientRpc(count);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_3155747470(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;
((BlackjackGameStateRpcBridge)(object)target).OnShuffleClientRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
protected internal override string __getTypeName()
{
return "BlackjackGameStateRpcBridge";
}
}
public static class BlackjackExtensions
{
public static void SetCardDeckLocalYPosition(this Blackjack instance, float yPos)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
Transform val = ((Component)instance).transform.Find("CardDeck");
if ((Object)(object)val != (Object)null)
{
Vector3 localPosition = val.localPosition;
val.localPosition = new Vector3(localPosition.x, yPos, localPosition.z);
}
else
{
LethalCasinoTweaks.Logger.LogWarning((object)"Failed to find CardDeck transform");
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace confusingus.LethalCasinoTweaks.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}