Decompiled source of GiantCardAPI v0.0.1

plugins/GiantCardManager.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Logging;
using DiskCardGame;
using GiantCardManager.JSON;
using HarmonyLib;
using InscryptionAPI.Card;
using InscryptionAPI.Helpers;
using Microsoft.CodeAnalysis;
using TinyJson;
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.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("GiantCardManager")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GiantCardManager")]
[assembly: AssemblyTitle("GiantCardManager")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
public static class Tools
{
	public static Assembly _assembly;

	public static GameObject Particle;

	public static Assembly CurrentAssembly => _assembly ?? (_assembly = Assembly.GetExecutingAssembly());

	public static Texture2D LoadTexture(string name)
	{
		if (name == null)
		{
			return null;
		}
		return TextureHelper.GetImageAsTexture(name + (name.EndsWith(".png") ? "" : ".png"), CurrentAssembly, (FilterMode)0);
	}

	public static int GetActAsInt()
	{
		if (SaveManager.SaveFile.IsPart1)
		{
			return 1;
		}
		if (SaveManager.SaveFile.IsPart2)
		{
			return 2;
		}
		if (SaveManager.SaveFile.IsPart3)
		{
			return 3;
		}
		if (SaveManager.SaveFile.IsGrimora)
		{
			return 4;
		}
		if (SaveManager.SaveFile.IsMagnificus)
		{
			return 5;
		}
		return 0;
	}
}
namespace GiantCardManager
{
	[BepInPlugin("Cevin_2006.Inscryption.GiantCardManager", "GiantCardManager", "0.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "Cevin_2006.Inscryption.GiantCardManager";

		public const string PluginName = "GiantCardManager";

		public const string PluginVersion = "0.0.1";

		public static string staticpath;

		public static string Directory;

		public static List<Sprite> art_sprites;

		internal static ManualLogSource Log;

		public static AssetBundle GiantCardBundle;

		private void Awake()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GiantCardManager.Resources.giantcardbundle"))
			{
				GiantCardBundle = AssetBundle.LoadFromStream(stream);
			}
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("Cevin_2006.Inscryption.GiantCardManager");
			val.PatchAll();
			GiantCardJSON.LoadAllGiantCards();
		}

		private static Sprite ConvertToSprite(Texture2D texture)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			return Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), Vector2.zero);
		}

		public static GameObject CreateGiantCard(Texture2D texture)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Sprite sprite = ConvertToSprite(texture);
			GameObject val = GiantCardBundle.LoadAsset<GameObject>("GiantCardPortrait");
			val.transform.localScale = new Vector3(0.4f, 0.25f, 0f);
			val.transform.Find("Anim").localPosition = new Vector3(0f, 0.16f, 0f);
			val.GetComponentsInChildren<Transform>(true).ToList().ForEach(delegate(Transform x)
			{
				((Component)x).gameObject.layer = LayerMask.NameToLayer("CardOffscreen");
			});
			((Component)val.transform.Find("Anim").Find("Body")).GetComponent<SpriteRenderer>().sprite = sprite;
			return val;
		}

		public void AddTest()
		{
			CardInfo obj = CardExtensions.SetCost(CardManager.New("TestTest", "TestiesBigBallius", "IDunnoBigBalls", 1, 200, "Test Purposes only."), (int?)0, (int?)0, (int?)0, (List<GemType>)null);
			Ability[] array = new Ability[4];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			CardInfo val = CardExtensions.AddAppearances(CardExtensions.AddSpecialAbilities(CardExtensions.AddTraits(CardExtensions.AddAbilities(obj, (Ability[])(object)array), (Trait[])(object)new Trait[1] { (Trait)16 }), (SpecialTriggeredAbility[])(object)new SpecialTriggeredAbility[1] { (SpecialTriggeredAbility)15 }), (Appearance[])(object)new Appearance[1] { (Appearance)11 });
			CardManager.Add("Terra", val);
			val.animatedPortrait = CreateGiantCard(Tools.LoadTexture("Moonlord_Body"));
		}
	}
}
namespace GiantCardManager.JSON
{
	[HarmonyPatch]
	public static class GiantCardJSON
	{
		[Serializable]
		public class GiantCardList
		{
			public class GiantCardInfo
			{
				public string? name;

				public string? texture;
			}

			public GiantCardInfo[]? giantCards;
		}

		public static Dictionary<string, GameObject> PrefabCache = new Dictionary<string, GameObject>();

		public static void LoadAllGiantCards()
		{
			IEnumerable<string> enumerable = Directory.EnumerateFiles(Paths.PluginPath, "*_giant.json", SearchOption.AllDirectories);
			foreach (string item in enumerable)
			{
				string fileName = Path.GetFileName(item);
				Plugin.Log.LogDebug((object)("Loading JSON (giant card) " + fileName));
				GiantCardList giantCardList = JSONParser.FromJson<GiantCardList>(File.ReadAllText(item));
				if (giantCardList?.giantCards == null)
				{
					Plugin.Log.LogError((object)("Couldn't load JSON data from file " + fileName + "!"));
					continue;
				}
				GiantCardList.GiantCardInfo[] giantCards = giantCardList.giantCards;
				foreach (GiantCardList.GiantCardInfo giantCardInfo in giantCards)
				{
					if (giantCardInfo.name != null && giantCardInfo.texture != null)
					{
						CardInfo cardByName = CardLoader.GetCardByName(giantCardInfo.name);
						GiveGiantProperties(cardByName);
						GameObject val = Plugin.CreateGiantCard(TextureHelper.GetImageAsTexture(giantCardInfo.texture, (FilterMode)0));
						Object.DontDestroyOnLoad((Object)(object)val);
						PrefabCache.Add(((Object)cardByName).name, val);
						Plugin.Log.LogInfo((object)("Loaded JSON giant card '" + ((Object)cardByName).name + "'!"));
					}
				}
			}
		}

		private static void GiveGiantProperties(CardInfo card)
		{
			if (!card.HasTrait((Trait)16))
			{
				CardExtensions.AddTraits(card, (Trait[])(object)new Trait[1] { (Trait)16 });
			}
			if (!CardExtensions.HasSpecialAbility(card, (SpecialTriggeredAbility)15))
			{
				CardExtensions.AddSpecialAbilities(card, (SpecialTriggeredAbility[])(object)new SpecialTriggeredAbility[1] { (SpecialTriggeredAbility)15 });
			}
			if (!card.appearanceBehaviour.Contains((Appearance)11))
			{
				CardExtensions.AddAppearances(card, (Appearance[])(object)new Appearance[1] { (Appearance)11 });
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void AnimatedIconPatch(CardInfo __instance, ref GameObject __result)
		{
			if (PrefabCache.ContainsKey(((Object)__instance).name))
			{
				__instance.animatedPortrait = PrefabCache[((Object)__instance).name];
				__result = PrefabCache[((Object)__instance).name];
			}
		}
	}
}