Decompiled source of Put It Back v1.1.3

plugins/PutItBack.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("PutItBack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.3.0")]
[assembly: AssemblyInformationalVersion("1.1.3+0432fa6d500bfa4f931c11a014a841a17e638294")]
[assembly: AssemblyProduct("Put It Back")]
[assembly: AssemblyTitle("PutItBack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.3.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;
		}
	}
}
public 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 PutItBack
{
	public class HeldCardData
	{
		public int BinderPageIndex { get; set; }

		public int BinderCardSlotIndex { get; set; }

		public Transform Transform { get; set; }

		public int GradedCardIndex { get; set; }

		public bool SortingSelectionChanged { get; set; }
	}
	public class ModConfigManager
	{
		private static ModConfigManager instance;

		private ConfigFile config;

		private readonly Dictionary<string, ConfigEntryBase> entries = new Dictionary<string, ConfigEntryBase>();

		public static ModConfigManager Instance => instance ?? (instance = new ModConfigManager());

		private ModConfigManager()
		{
		}

		public void Initialize(ConfigFile config)
		{
			this.config = config;
		}

		public ConfigEntry<T> BindSetting<T>(string category, string key, T value, string description = "", AcceptableValueBase acceptableValueBase = null, ConfigurationManagerAttributes configurationManagerAttributes = null)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription(description, acceptableValueBase, new object[1] { configurationManagerAttributes });
			ConfigEntry<T> val2 = config.Bind<T>(category, key, value, val);
			string key2 = category + "." + key;
			entries[key2] = (ConfigEntryBase)(object)val2;
			return val2;
		}

		public T GetValue<T>(string category, string key)
		{
			string key2 = category + "." + key;
			if (!entries.TryGetValue(key2, out var value) || !(value is ConfigEntry<T> val))
			{
				return default(T);
			}
			return val.Value;
		}

		public void SetValue<T>(string category, string key, T value)
		{
			string key2 = category + "." + key;
			if (entries.TryGetValue(key2, out var value2) && value2 is ConfigEntry<T> val)
			{
				val.Value = value;
			}
		}

		public ConfigEntry<T> GetEntry<T>(string category, string key)
		{
			string key2 = category + "." + key;
			if (!entries.TryGetValue(key2, out var value) || !(value is ConfigEntry<T> result))
			{
				return null;
			}
			return result;
		}

		public void OnSettingChanged<T>(string category, string key, Action<T> callback)
		{
			ConfigEntry<T> entry = GetEntry<T>(category, key);
			if (entry != null)
			{
				entry.SettingChanged += delegate
				{
					callback(entry.Value);
				};
			}
		}
	}
	[BepInPlugin("PutItBack", "Put It Back", "1.1.3")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private readonly Harmony m_Harmony = new Harmony("PutItBack");

		public static PutItBack PutItBack { get; private set; } = new PutItBack();


		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			ModConfigManager.Instance.Initialize(((BaseUnityPlugin)this).Config);
			PutItBack.RegisterConfigs();
			m_Harmony.PatchAll();
			Logger.LogInfo((object)"Plugin PutItBack v:1.1.3 by GhostNarwhal is loaded!");
		}

		private void Update()
		{
			PutItBack.Update();
		}

		private void OnDestroy()
		{
			m_Harmony.UnpatchSelf();
			Logger.LogInfo((object)"Plugin Put It Back is unloaded!");
		}
	}
	public class PutItBack
	{
		private bool isEnabled;

		private bool isEnabledWthBinderClosed;

		private bool isReturningCard;

		private bool sortingSelectionChanged;

		private readonly List<HeldCardData> heldCards = new List<HeldCardData>();

		private InteractionPlayerController interactionPlayerController;

		private CollectionBinderFlipAnimCtrl collectionBinderFlipAnimCtrl;

		public void RegisterConfigs()
		{
			ModConfigManager.Instance.BindSetting("PutItBack", "Enabled", value: true);
			ModConfigManager.Instance.BindSetting("PutItBack", "Enabled With Binder Closed", value: true);
			ModConfigManager.Instance.OnSettingChanged("PutItBack", "Enabled", delegate(bool value)
			{
				isEnabled = value;
			});
			ModConfigManager.Instance.OnSettingChanged("PutItBack", "Enabled With Binder Closed", delegate(bool value)
			{
				isEnabledWthBinderClosed = value;
			});
			isEnabled = ModConfigManager.Instance.GetValue<bool>("PutItBack", "Enabled");
			isEnabledWthBinderClosed = ModConfigManager.Instance.GetValue<bool>("PutItBack", "Enabled With Binder Closed");
		}

		public void CollectionBinderAwake(CollectionBinderFlipAnimCtrl instance)
		{
			collectionBinderFlipAnimCtrl = instance;
		}

		public void InteractionPlayerControllerAwake(InteractionPlayerController instance)
		{
			interactionPlayerController = instance;
		}

		public void OnSortingSelectionChange()
		{
			foreach (HeldCardData heldCard in heldCards)
			{
				heldCard.SortingSelectionChanged = true;
			}
			sortingSelectionChanged = true;
		}

		public void Update()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (!isEnabled || interactionPlayerController == null)
			{
				return;
			}
			if (isEnabledWthBinderClosed && !interactionPlayerController.m_IsViewCardAlbumMode && interactionPlayerController.m_CurrentCardCompartment == null && UnityInput.Current.GetMouseButtonUp(0) && interactionPlayerController.m_CurrentHoldingCard3dList.Count > 0)
			{
				ReturnLastCardToBinder((Action)interactionPlayerController.ExitHoldCardMode);
			}
			if (collectionBinderFlipAnimCtrl != null && collectionBinderFlipAnimCtrl.m_IsBookOpen && interactionPlayerController.m_IsViewCardAlbumMode)
			{
				if (UnityInput.Current.mouseScrollDelta.y > 0f && interactionPlayerController.m_CurrentHoldingCard3dList.Count > 0)
				{
					collectionBinderFlipAnimCtrl.OnMouseButtonUp();
				}
				if (UnityInput.Current.mouseScrollDelta.y < 0f)
				{
					collectionBinderFlipAnimCtrl.OnRightMouseButtonUp();
				}
			}
		}

		public bool CollectionBinderRightMouseButtonUpPrefix()
		{
			if (!isEnabled)
			{
				return true;
			}
			if (isReturningCard || collectionBinderFlipAnimCtrl?.m_CurrentRaycastedInteractableCard3d == null)
			{
				return false;
			}
			if (!interactionPlayerController.IsSelectingCardForGradingScreen())
			{
				CardData cardData = collectionBinderFlipAnimCtrl.m_CurrentRaycastedInteractableCard3d.m_Card3dUI.m_CardUI.GetCardData();
				if (InteractionPlayerController.HasEnoughSlotToHoldCard())
				{
					heldCards.Add(new HeldCardData
					{
						BinderCardSlotIndex = collectionBinderFlipAnimCtrl.m_CurrentRaycastedCardIndex,
						BinderPageIndex = collectionBinderFlipAnimCtrl.m_Index,
						Transform = ((Component)collectionBinderFlipAnimCtrl.m_CurrentRaycastedInteractableCard3d).transform,
						GradedCardIndex = cardData.gradedCardIndex
					});
				}
			}
			return true;
		}

		public bool CollectionBinderLeftMouseButtonUpPrefix()
		{
			if (!isEnabled || heldCards.Count == 0)
			{
				return true;
			}
			if (!isReturningCard)
			{
				if (sortingSelectionChanged)
				{
					sortingSelectionChanged = false;
					return false;
				}
				if (interactionPlayerController != null && interactionPlayerController.m_CurrentHoldingCard3dList.Count > 0)
				{
					int num = heldCards.Last().BinderCardSlotIndex;
					int num2 = heldCards.Last().BinderPageIndex - collectionBinderFlipAnimCtrl.m_Index;
					int index = 0;
					if (num2 <= -1)
					{
						index = 2;
						int num3 = num;
						int num4;
						switch (num)
						{
						case 8:
						case 11:
							num4 = 8;
							break;
						case 7:
						case 10:
							num4 = 6;
							break;
						case 6:
						case 9:
							num4 = 4;
							break;
						default:
							num4 = 0;
							break;
						}
						num = num3 - num4;
					}
					else if (num2 >= 1)
					{
						index = 1;
						int num4 = num;
						int num3;
						switch (num)
						{
						case 0:
						case 3:
							num3 = 8;
							break;
						case 1:
						case 4:
							num3 = 6;
							break;
						case 2:
						case 5:
							num3 = 4;
							break;
						default:
							num3 = 0;
							break;
						}
						num = num4 + num3;
					}
					Transform transform = ((Component)collectionBinderFlipAnimCtrl.m_BinderPageGrpList[index].m_CardList[num]).transform;
					isReturningCard = true;
					((InteractableObject)interactionPlayerController.m_CurrentHoldingCard3dList.Last()).StopLerpToTransform();
					((InteractableObject)interactionPlayerController.m_CurrentHoldingCard3dList.Last()).LerpToTransform(transform, transform.parent, 3f);
				}
			}
			return false;
		}

		public void OnCardFinishLerp()
		{
			if (isEnabled && isReturningCard && interactionPlayerController.m_CurrentHoldingCard3dList.Count > 0)
			{
				ReturnLastCardToBinder((Action)interactionPlayerController.EnterViewCardAlbumMode);
				isReturningCard = false;
			}
		}

		private void ReturnLastCardToBinder(Action emptyHandAction)
		{
			//IL_005d: 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_006e: 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_007c: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			if (interactionPlayerController.m_CurrentHoldingCard3dList.Count <= 0)
			{
				return;
			}
			CardData cardData = interactionPlayerController.m_CurrentHoldingCard3dList.Last().m_Card3dUI.m_CardUI.GetCardData();
			if (cardData.cardGrade > 0 && interactionPlayerController.m_IsViewCardAlbumMode)
			{
				int gradedCardIndex = heldCards.Last().GradedCardIndex;
				CompactCardDataAmount item = new CompactCardDataAmount
				{
					cardSaveIndex = CPlayerData.GetCardSaveIndex(cardData),
					amount = cardData.cardGrade,
					expansionType = cardData.expansionType,
					isDestiny = cardData.isDestiny,
					gradedCardIndex = gradedCardIndex
				};
				CPlayerData.m_GradedCardInventoryList.Add(item);
			}
			else
			{
				CPlayerData.AddCard(cardData, 1);
			}
			if (interactionPlayerController.m_IsViewCardAlbumMode && collectionBinderFlipAnimCtrl.m_IsBookOpen && !heldCards.Last().SortingSelectionChanged)
			{
				int num = heldCards.Last().BinderPageIndex - collectionBinderFlipAnimCtrl.m_Index;
				if (num >= -1 && num <= 1)
				{
					int index = ((num == -1) ? 2 : num);
					int binderCardSlotIndex = heldCards.Last().BinderCardSlotIndex;
					int cardAmount = CPlayerData.GetCardAmount(cardData);
					collectionBinderFlipAnimCtrl.m_BinderPageGrpList[index].SetSingleCard(binderCardSlotIndex, cardData, cardAmount, collectionBinderFlipAnimCtrl.m_SortingType);
					((Component)collectionBinderFlipAnimCtrl.m_BinderPageGrpList[index].m_CardList[binderCardSlotIndex]).gameObject.SetActive(true);
					((Component)heldCards.Last().Transform).gameObject.SetActive(true);
				}
			}
			((InteractableObject)interactionPlayerController.m_CurrentHoldingCard3dList.Last()).OnDestroyed();
			interactionPlayerController.m_CurrentHoldingCard3dList.RemoveAt(interactionPlayerController.m_CurrentHoldingCard3dList.Count - 1);
			CPlayerData.m_HoldCardDataList.RemoveAt(CPlayerData.m_HoldCardDataList.Count - 1);
			while (heldCards.Count > CPlayerData.m_HoldCardDataList.Count)
			{
				heldCards.RemoveAt(heldCards.Count - 1);
			}
			if (heldCards.Count == 0)
			{
				interactionPlayerController.m_HoldCardGrpTargetRotation = Quaternion.Euler(0f, 0f, 0f);
				emptyHandAction?.Invoke();
			}
			else
			{
				interactionPlayerController.m_HoldCardGrpTargetRotation = Quaternion.Euler(0f, 0f, Mathf.Lerp(0f, 15f, (float)heldCards.Count / 7f));
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "PutItBack";

		public const string PLUGIN_NAME = "Put It Back";

		public const string PLUGIN_VERSION = "1.1.3";
	}
}
namespace PutItBack.Patches
{
	[HarmonyPatch(typeof(CollectionBinderFlipAnimCtrl))]
	public class CollectionBinderFlipAnimCtrlPatches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePostfix(CollectionBinderFlipAnimCtrl __instance)
		{
			Plugin.PutItBack.CollectionBinderAwake(__instance);
		}

		[HarmonyPatch("OnMouseButtonUp")]
		[HarmonyPrefix]
		private static bool OnMouseButtonUpPrefix()
		{
			return Plugin.PutItBack.CollectionBinderLeftMouseButtonUpPrefix();
		}

		[HarmonyPatch("OnRightMouseButtonUp")]
		[HarmonyPrefix]
		private static bool OnRightMouseButtonUpPrefix()
		{
			return Plugin.PutItBack.CollectionBinderRightMouseButtonUpPrefix();
		}

		[HarmonyPatch("OnPressSwitchSortingMethod")]
		[HarmonyPrefix]
		private static void OnPressSwitchSortingMethodPrefix(int sortingMethodIndex)
		{
			Plugin.PutItBack.OnSortingSelectionChange();
		}

		[HarmonyPatch("OnPressSwitchExpansion")]
		[HarmonyPrefix]
		private static void OnPressSwitchExpansionPrefix(int expansionIndex)
		{
			Plugin.PutItBack.OnSortingSelectionChange();
		}

		[HarmonyPatch("OnPressSwitchToGradedAlbum")]
		[HarmonyPrefix]
		private static void OnPressSwitchToGradedAlbumPrefix()
		{
			Plugin.PutItBack.OnSortingSelectionChange();
		}
	}
	[HarmonyPatch(typeof(CPlayerData))]
	public class CPlayerDataPatches
	{
		[HarmonyPatch("RemoveGradedCard")]
		[HarmonyPrefix]
		private static void RemoveGradeCardPrefix(CardData cardData, bool ignoreGradedCardIndex)
		{
			//IL_0047: 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)
			int cardSaveIndex = CPlayerData.GetCardSaveIndex(cardData);
			for (int i = 0; i < CPlayerData.m_GradedCardInventoryList.Count; i++)
			{
				if (CPlayerData.m_GradedCardInventoryList[i].cardSaveIndex == cardSaveIndex && CPlayerData.m_GradedCardInventoryList[i].amount == cardData.cardGrade && CPlayerData.m_GradedCardInventoryList[i].expansionType == cardData.expansionType && CPlayerData.m_GradedCardInventoryList[i].isDestiny == cardData.isDestiny)
				{
					if (ignoreGradedCardIndex)
					{
						Plugin.Logger.LogError((object)"REMOVE CARD");
						break;
					}
					if (CPlayerData.m_GradedCardInventoryList[i].gradedCardIndex == cardData.gradedCardIndex)
					{
						Plugin.Logger.LogError((object)"REMOVE CARD");
						break;
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(InteractionPlayerController))]
	public class InteractionPlayerControllerPatches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePostfix(InteractionPlayerController __instance)
		{
			Plugin.PutItBack.InteractionPlayerControllerAwake(__instance);
		}
	}
}
namespace PutItBack.Extensions
{
	public static class CardDataExt
	{
		public static bool IsOwned(this CardData cardData)
		{
			return CPlayerData.GetCardAmount(cardData) > 0;
		}
	}
	[HarmonyPatch(typeof(InteractableCard3d))]
	internal class InteractableCard3dPatches
	{
		[HarmonyPatch("OnFinishLerp")]
		[HarmonyPostfix]
		private static void OnFinishLerpPostfix()
		{
			Plugin.PutItBack.OnCardFinishLerp();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}