Decompiled source of Lilys Custom Costs v1.1.0

Lilys_Custom_Costs.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Card;
using InscryptionAPI.Helpers;
using InscryptionCommunityPatch.Card;
using Pixelplacement;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Lilys_Custom_Costs")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Custom costs made by Lily.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Lilys_Custom_Costs")]
[assembly: AssemblyTitle("Lilys_Custom_Costs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Lilys_Custom_Costs;

public static class Soul_Cost
{
	public static int Souls = 0;

	public static List<BoneTokenInteractable> soulTokens = new List<BoneTokenInteractable>();

	public static void AddSoulCost()
	{
		Part1CardCostRender.UpdateCardCost += delegate(CardInfo card, List<Texture2D> costs)
		{
			if (card.SoulCost() > 0)
			{
				Texture2D val = Plugin.GetTexture($"soul_cost/soul{card.SoulCost()}");
				if (card.SoulCost() > 3)
				{
					val = val.ChangeSize(64, 28);
				}
				costs.Add(val);
			}
		};
	}

	public static int SoulCost(this CardInfo card)
	{
		return CardExtensions.GetExtendedPropertyAsInt(card, "SoulCost").GetValueOrDefault();
	}

	public static void AddSouls(int amount, CardSlot slot = null)
	{
		Souls += amount;
		((MonoBehaviour)Singleton<Part1ResourcesManager>.Instance).StartCoroutine(ShowAddSouls(amount, slot));
	}

	public static void SpendSouls(int amount)
	{
		Souls -= amount;
		((MonoBehaviour)Singleton<Part1ResourcesManager>.Instance).StartCoroutine(RemoveSouls(amount));
	}

	public static IEnumerator ShowAddSouls(int amount, CardSlot slot)
	{
		for (int i = 0; i < amount; i++)
		{
			GameObject SoulToken = Object.Instantiate<GameObject>(Singleton<Part1ResourcesManager>.Instance.boneTokenPrefab);
			Object.Destroy((Object)(object)((Component)SoulToken.transform.GetChild(0)).gameObject);
			GameObject SoulTokenMesh = Object.Instantiate<GameObject>(Plugin.SoulTokenPrefab);
			SoulTokenMesh.transform.SetParent(SoulToken.transform);
			SoulToken.transform.localPosition = new Vector3(0f, 0f, 0f);
			BoneTokenInteractable component = SoulToken.GetComponent<BoneTokenInteractable>();
			Rigidbody tokenRB = SoulToken.GetComponent<Rigidbody>();
			if ((Object)(object)slot != (Object)null)
			{
				tokenRB.Sleep();
				SoulToken.transform.position = ((Component)slot).transform.position + Vector3.up;
				Singleton<Part1ResourcesManager>.Instance.PushTokenDown(tokenRB);
				Vector3 endValue = Singleton<Part1ResourcesManager>.Instance.GetRandomLandingPosition() + Vector3.up;
				Tween.Position(((Component)component).transform, endValue, 0.25f, 0.5f, Tween.EaseInOut, (LoopType)0, (Action)null, (Action)delegate
				{
					tokenRB.WakeUp();
					Singleton<Part1ResourcesManager>.Instance.PushTokenDown(tokenRB);
				}, true);
			}
			else
			{
				SoulToken.transform.position = Singleton<Part1ResourcesManager>.Instance.GetRandomLandingPosition() + Vector3.up * 5f;
				Singleton<Part1ResourcesManager>.Instance.PushTokenDown(tokenRB);
			}
			soulTokens.Add(component);
			Singleton<Part1ResourcesManager>.Instance.isOrganized = false;
			yield return (object)new WaitForSeconds(0.05f);
		}
	}

	public static IEnumerator RemoveSouls(int amount)
	{
		for (int i = 0; i < amount; i++)
		{
			if (soulTokens.Count > 0)
			{
				BoneTokenInteractable component = ((Component)soulTokens[soulTokens.Count - 1]).GetComponent<BoneTokenInteractable>();
				component.FlyOffBoard();
				soulTokens.Remove(component);
				yield return (object)new WaitForSeconds(0.075f);
			}
		}
		yield return (object)new WaitForSeconds(0.05f);
	}
}
[HarmonyPatch]
public class CanPlay_Patch
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayableCard), "CanPlay")]
	public static void CanPlay(ref bool __result, ref PlayableCard __instance)
	{
		if (Soul_Cost.Souls < ((Card)__instance).Info.SoulCost())
		{
			__result = false;
		}
	}
}
[HarmonyPatch]
public class CardCanBePlayedByTurn2_Patch
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(Deck), "CardCanBePlayedByTurn2WithHand")]
	public static void CardCanBePlayedByTurn2WithHand(ref CardInfo card, ref bool __result)
	{
		if (card.SoulCost() > 0)
		{
			__result = false;
		}
	}
}
[HarmonyPatch]
public class HintsHandler_Patch
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(HintsHandler), "OnNonplayableCardClicked")]
	public static bool OnNonplayableCardClicked(ref PlayableCard card)
	{
		if (Soul_Cost.Souls < ((Card)card).Info.SoulCost())
		{
			Utils.ShowLeshyMessage("You don't have enough [c:bB]souls [c:]to play that creature.");
			return false;
		}
		return true;
	}
}
[HarmonyPatch]
public class OnDie_Patch
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayableCard), "Die")]
	public static void CanPlay(ref PlayableCard __instance)
	{
		if (__instance.OpponentCard)
		{
			Soul_Cost.AddSouls(1);
		}
	}
}
[HarmonyPatch]
public class OnPlay_Patch
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerHand), "PlayCardOnSlot")]
	public static void PlayCardOnSlot(PlayerHand __instance, PlayableCard card, CardSlot slot)
	{
		if (((Card)card).Info.SoulCost() > 0)
		{
			Soul_Cost.SpendSouls(((Card)card).Info.SoulCost());
		}
	}
}
[HarmonyPatch]
public class OnResourceCleanup_Patch
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(Part1ResourcesManager), "CleanUp")]
	public static void CleanUp()
	{
		((MonoBehaviour)Singleton<Part1ResourcesManager>.Instance).StartCoroutine(Soul_Cost.RemoveSouls(Soul_Cost.Souls));
		Soul_Cost.Souls = 0;
	}
}
[HarmonyPatch]
public class TryOrganizeTokens_Patch
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(Part1ResourcesManager), "TryOrganizeBoneTokens")]
	public static bool TryOrganizeBoneTokens(ref bool __result, ref Part1ResourcesManager __instance)
	{
		//IL_0093: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: 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)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.AllTokens == Singleton<Part1ResourcesManager>.Instance.boneTokens)
		{
			return true;
		}
		int i = 5;
		if (!__instance.isOrganized && Plugin.AllTokens.Count > i)
		{
			for (; i * __instance.pileMarkers.Length < Plugin.AllTokens.Count; i += 5)
			{
			}
			for (int j = 0; j < Plugin.AllTokens.Count; j++)
			{
				int num = Mathf.FloorToInt((float)j / (float)i);
				int num2 = j % i;
				Vector3 val = __instance.pileMarkers[num].position + Vector3.up * (float)num2 * 0.1f;
				BoneTokenInteractable token = Plugin.AllTokens[j];
				((Component)token).GetComponent<Collider>().enabled = false;
				if (num2 < i - 1 && j < Plugin.AllTokens.Count - 1)
				{
					((Component)token).GetComponent<Rigidbody>().isKinematic = true;
				}
				Tween.Rotation(((Component)token).transform, new Vector3(-90f, 0f, 0f), 0.1f, 0f, Tween.EaseInOut, (LoopType)0, (Action)null, (Action)null, true);
				Tween.Position(((Component)token).transform, val, 0.15f, 0f, Tween.EaseInOut, (LoopType)0, (Action)null, (Action)delegate
				{
					((Component)token).GetComponent<Collider>().enabled = true;
				}, true);
			}
			__instance.isOrganized = true;
			__result = true;
		}
		__result = false;
		return false;
	}
}
[BepInPlugin("Lily.LCC", "Lily's Custom Costs", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string PluginGuid = "Lily.LCC";

	private const string PluginName = "Lily's Custom Costs";

	private const string PluginVersion = "1.0.0";

	public static string Directory;

	internal static ManualLogSource Log;

	public static GameObject SoulTokenPrefab;

	public static List<BoneTokenInteractable> AllTokens
	{
		get
		{
			List<BoneTokenInteractable> list = new List<BoneTokenInteractable>();
			list.AddRange(Singleton<Part1ResourcesManager>.Instance.boneTokens);
			list.AddRange(Soul_Cost.soulTokens);
			return list;
		}
	}

	public void Awake()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Lily's Custom Costs!");
		Log = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("Lily.LCC");
		val.PatchAll();
		Directory = ((BaseUnityPlugin)this).Info.Location;
		GameObject soulTokenPrefab = default(GameObject);
		if (AssetBundleHelper.TryGet<GameObject>(Path.Combine(Path.GetDirectoryName(Directory), "custom_costs"), "soul_coin", ref soulTokenPrefab))
		{
			SoulTokenPrefab = soulTokenPrefab;
		}
		Soul_Cost.AddSoulCost();
	}

	public void AddDevStuff()
	{
		CardInfo val = CardExtensions.CardByName((IEnumerable<CardInfo>)CardManager.BaseGameCards, "Squirrel");
		CardExtensions.SetExtendedProperty(val, "SoulCost", (object)3);
		val.baseHealth = 99;
		val.baseAttack = 1;
		CardInfo val2 = CardExtensions.CardByName((IEnumerable<CardInfo>)CardManager.BaseGameCards, "Geck");
		CardExtensions.AddAbilities(val2, (Ability[])(object)new Ability[1] { (Ability)4 });
		val2.baseHealth = 99;
		val2.baseAttack = 1;
	}

	public static Texture2D GetTexture(string path)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		byte[] array = File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(Directory), "Artwork/", path + ".png"));
		Texture2D val = new Texture2D(2, 2);
		ImageConversion.LoadImage(val, array);
		((Texture)val).filterMode = (FilterMode)0;
		return val;
	}
}
public static class Utils
{
	public static void ShowLeshyMessage(string message)
	{
		((MonoBehaviour)Singleton<TextDisplayer>.Instance).StartCoroutine(Singleton<TextDisplayer>.Instance.ShowThenClear(message, 1.5f, 0f, (Emotion)0, (LetterAnimation)0, (Speaker)1, (string[])null));
	}

	public static Texture2D ChangeSize(this Texture2D texture2D, int targetX, int targetY)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		RenderTexture val2 = (RenderTexture.active = new RenderTexture(targetX, targetY, 24));
		Graphics.Blit((Texture)(object)texture2D, val2);
		Texture2D val3 = new Texture2D(targetX, targetY);
		val3.ReadPixels(new Rect(0f, 0f, (float)targetX, (float)targetY), 0, 0);
		val3.Apply();
		return val3;
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "Lilys_Custom_Costs";

	public const string PLUGIN_NAME = "Lilys_Custom_Costs";

	public const string PLUGIN_VERSION = "1.0.0";
}