Decompiled source of Enhanced Playtables v1.0.2

plugins/EnhancedPlayTables.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("EnhancedPlayTables")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Enhanced Play Tables")]
[assembly: AssemblyTitle("EnhancedPlayTables")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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;
		}
	}
}
internal sealed class ConfigurationManagerAttributes
{
	public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput);

	public bool? ShowRangeAsPercent;

	public Action<ConfigEntryBase> CustomDrawer;

	public CustomHotkeyDrawerFunc CustomHotkeyDrawer;

	public bool? Browsable;

	public string Category;

	public object DefaultValue;

	public bool? HideDefaultButton;

	public bool? HideSettingName;

	public string Description;

	public string DispName;

	public int? Order;

	public bool? ReadOnly;

	public bool? IsAdvanced;

	public Func<object, string> ObjToStr;

	public Func<string, object> StrToObj;
}
namespace EnhancedPlayTables
{
	public class EnhancedPlayTable : CSingleton<EnhancedPlayTable>
	{
		private List<Mesh> m_MeshList = new List<Mesh>();

		private List<Material> m_PlayCardMaterial = new List<Material>();

		private EGameEventFormat m_PreviousGameEvent = CPlayerData.m_GameEventFormat;

		private void Awake()
		{
			Settings.Instance.isEnabled.SettingChanged += delegate
			{
				((Behaviour)this).enabled = Settings.Instance.isEnabled.Value;
			};
		}

		private void OnEnable()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			m_PreviousGameEvent = CPlayerData.m_GameEventFormat;
		}

		private void Update()
		{
			if (((Behaviour)this).enabled && Settings.Instance.autoResetEvents.Value)
			{
				CheckPlayTableCount();
			}
		}

		public void OnRandomizeSetup(TableGameItemSet tableGameItemSet)
		{
			//IL_0098: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Behaviour)this).enabled)
			{
				return;
			}
			MeshFilter[] componentsInChildren = ((Component)tableGameItemSet).gameObject.GetComponentsInChildren<MeshFilter>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (((Object)componentsInChildren[i]).name.StartsWith("CardSingle"))
				{
					Mesh mesh = m_MeshList[Random.Range(0, m_MeshList.Count)];
					Texture mainTexture = m_PlayCardMaterial[Random.Range(0, m_PlayCardMaterial.Count)].mainTexture;
					((Renderer)((Component)componentsInChildren[i]).GetComponent<MeshRenderer>()).material.mainTexture = mainTexture;
					componentsInChildren[i].mesh = mesh;
					((Component)componentsInChildren[i]).transform.localRotation = Quaternion.identity;
					NormalizeCardRotation(componentsInChildren[i], mesh);
					if (Settings.Instance.allowFacedownCards.Value && Random.Range(0, 10) == 0)
					{
						((Component)componentsInChildren[i]).transform.Rotate(new Vector3(0f, 180f, 0f), (Space)1);
					}
					if (Settings.Instance.allowTappedCards.Value && Random.Range(0, 10) == 0)
					{
						((Component)componentsInChildren[i]).transform.Rotate(new Vector3(0f, 0f, -75f), (Space)1);
					}
				}
			}
		}

		public void OnPlayTableGameStarted(Customer customer)
		{
			if (!((Behaviour)this).enabled)
			{
				return;
			}
			CardFanRandomizer componentInChildren = ((Component)customer).gameObject.GetComponentInChildren<CardFanRandomizer>();
			componentInChildren.RandomizePlayCard();
			m_PlayCardMaterial = componentInChildren.m_PlayCardMatList;
			if (m_MeshList.Count != 0)
			{
				return;
			}
			foreach (GameObject cardFanGrp in componentInChildren.m_CardFanGrpList)
			{
				m_MeshList.Add(cardFanGrp.gameObject.GetComponent<MeshFilter>().mesh);
				MeshFilter[] componentsInChildren = cardFanGrp.gameObject.GetComponentsInChildren<MeshFilter>(true);
				foreach (MeshFilter val in componentsInChildren)
				{
					m_MeshList.Add(val.mesh);
				}
			}
		}

		public void OnPressConfirmBtn(EGameEventFormat eventFormat)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (((Behaviour)this).enabled)
			{
				m_PreviousGameEvent = eventFormat;
			}
		}

		private void CheckPlayTableCount()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (CSingleton<ShelfManager>.Instance.m_PlayTableList.Count > 0)
			{
				foreach (InteractablePlayTable playTable in CSingleton<ShelfManager>.Instance.m_PlayTableList)
				{
					if (!((InteractableObject)playTable).GetIsBoxedUp())
					{
						CPlayerData.m_PendingGameEventFormat = m_PreviousGameEvent;
						return;
					}
				}
			}
			CPlayerData.m_PendingGameEventFormat = (EGameEventFormat)(-1);
		}

		private void NormalizeCardRotation(MeshFilter meshFilter, Mesh mesh)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (Vector3)(((Object)mesh).name.Substring(0, 5) switch
			{
				"Card5" => new Vector3(90f, 0f, 22f), 
				"Card4" => new Vector3(90f, 0f, 10f), 
				"Card3" => new Vector3(90f, 0f, -22f), 
				"Card2" => new Vector3(90f, 0f, -10f), 
				_ => new Vector3(90f, 0f, 0f), 
			});
			((Component)meshFilter).transform.Rotate(val, (Space)1);
		}
	}
	[BepInPlugin("EnhancedPlayTables", "Enhanced Play Tables", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony m_Harmony = new Harmony("EnhancedPlayTables");

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Settings.Instance.Load(this);
			m_Harmony.PatchAll();
			Logger.LogInfo((object)"Plugin Enhanced Play Tables v:1.0.0 by GhostNarwhal is loaded!");
		}

		private void OnDestroy()
		{
			m_Harmony.UnpatchSelf();
			Logger.LogInfo((object)"Plugin Enhanced Play Tables is unloaded!");
		}
	}
	public class Settings
	{
		public ConfigEntry<bool> isEnabled;

		public ConfigEntry<bool> allowFacedownCards;

		public ConfigEntry<bool> autoResetEvents;

		public ConfigEntry<bool> allowTappedCards;

		private static Settings m_instance;

		public static Settings Instance
		{
			get
			{
				if (m_instance == null)
				{
					m_instance = new Settings();
				}
				return m_instance;
			}
		}

		public void Load(Plugin plugin)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			isEnabled = ((BaseUnityPlugin)plugin).Config.Bind<bool>("Enhanced Playtable", "Enabled", true, new ConfigDescription("Enables or disables enhanced play table", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 25
				}
			}));
			allowFacedownCards = ((BaseUnityPlugin)plugin).Config.Bind<bool>("Enhanced Playtable", "Allow Facedown Cards", true, new ConfigDescription("Allows some of the cards to be facedown still. 1 in 10 cards should be face down.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 24
				}
			}));
			allowTappedCards = ((BaseUnityPlugin)plugin).Config.Bind<bool>("Enhanced Playtable", "Allow Tapped Cards", true, new ConfigDescription("Allows some of the cards to be \"tapped\". 1 in 10 cards should be \"tapped\"", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 23
				}
			}));
			autoResetEvents = ((BaseUnityPlugin)plugin).Config.Bind<bool>("Enhanced Playtable", "Auto Reset Events", true, new ConfigDescription("Disables event when last table is boxed or reenables it when a new table is placed.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 22
				}
			}));
		}

		private Settings()
		{
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "EnhancedPlayTables";

		public const string PLUGIN_NAME = "Enhanced Play Tables";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace EnhancedPlayTables.Patches
{
	[HarmonyPatch(typeof(Customer))]
	public class CustomerPatch
	{
		[HarmonyPatch("PlayTableGameStarted")]
		[HarmonyPostfix]
		private static void PlayTableGameStartedPostfix(Customer __instance)
		{
			CSingleton<EnhancedPlayTable>.Instance.OnPlayTableGameStarted(__instance);
		}
	}
	[HarmonyPatch(typeof(SetGameEventFormatScreen))]
	public class SetGameEventFormatScreenPatch
	{
		[HarmonyPatch("OnPressConfirmBtn")]
		[HarmonyPostfix]
		private static void OnPressConfirmBtnPostfix(int ___m_CurrentFormatIndex)
		{
			CSingleton<EnhancedPlayTable>.Instance.OnPressConfirmBtn((EGameEventFormat)___m_CurrentFormatIndex);
		}
	}
	[HarmonyPatch(typeof(TableGameItemSet))]
	public class TableGameItemSetPatch
	{
		[HarmonyPatch("RandomizeSetup")]
		[HarmonyPostfix]
		private static void RandomizeSetupPostfix(TableGameItemSet __instance)
		{
			CSingleton<EnhancedPlayTable>.Instance.OnRandomizeSetup(__instance);
		}
	}
}