Decompiled source of ItemDraft v1.0.1

ItemDraft.dll

Decompiled 2 weeks ago
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 BepInEx;
using DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Ascension;
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("ItemDraft")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ItemDraft")]
[assembly: AssemblyTitle("ItemDraft")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ItemDraft;

internal class ItemDraftPatch
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(AscensionSaveData), "NewRun")]
	public static void OnNewRun(ref AscensionSaveData __instance)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (!AscensionSaveData.Data.ChallengeIsActive(PluginManager.ItemDraftID))
		{
			return;
		}
		List<string> list = new List<string>();
		foreach (string consumable in __instance.currentRun.consumables)
		{
			if (consumable != "FishHook")
			{
				list.Add(consumable);
			}
		}
		foreach (string item in list)
		{
			__instance.currentRun.consumables.Remove(item);
		}
	}

	private static bool First(int rowIndex)
	{
		return SaveFile.IsAscension && rowIndex == 1 && RunState.Run.regionTier == 0 && AscensionSaveData.Data.numRunsSinceReachedFirstBoss < 2;
	}

	[HarmonyPatch(typeof(MapGenerator), "GenerateNodes")]
	[HarmonyPostfix]
	private static void AddItemNodeChallenge(ref List<NodeData> __result)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		int frontStart = ((!First(1)) ? 1 : 2);
		List<NodeData> frontNodes = new List<NodeData>();
		NodeData val = (NodeData)new GainConsumablesNodeData();
		frontNodes.Add(val);
		val.gridY++;
		if (!AscensionSaveData.Data.ChallengeIsActive(PluginManager.ItemDraftID) || RunState.Run.regionTier != 0)
		{
			return;
		}
		Singleton<ChallengeActivationUI>.Instance.ShowActivation(PluginManager.ItemDraftID);
		foreach (NodeData item in __result.Where((NodeData n) => n.gridY >= frontStart).ToList())
		{
			item.gridY += frontNodes.Count;
		}
		NodeData lastNodeBeforeCustomFront = GetLastNodeBeforeCustomFront(__result);
		lastNodeBeforeCustomFront.connectedNodes.Clear();
		lastNodeBeforeCustomFront.connectedNodes.Add(frontNodes[0]);
		foreach (NodeData item2 in __result.Where((NodeData n) => n.gridY == frontStart + frontNodes.Count))
		{
			frontNodes[frontNodes.Count - 1].connectedNodes.Add(item2);
		}
		__result = __result.Where((NodeData n) => n.gridY < frontStart).Concat(frontNodes).Concat(__result.Where((NodeData n) => n.gridY >= frontStart))
			.ToList();
	}

	private static NodeData GetLastNodeBeforeCustomFront(List<NodeData> nodes)
	{
		if (First(1))
		{
			return nodes.First((NodeData n) => n.gridY == 1);
		}
		return nodes.First((NodeData n) => n.gridY == 0);
	}

	public static void Register(Harmony harmony)
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		AscensionChallengeInfo val = ScriptableObject.CreateInstance<AscensionChallengeInfo>();
		val.title = "Item Draft";
		val.iconSprite = Tools.ConvertTexToSprite(Tools.LoadTex("ItemDraft/Resources/ItemDraftInactive.png"));
		val.description = "No items except Fish Hook, but guarenteed item node at the start.";
		val.activatedSprite = Tools.ConvertTexToSprite(Tools.LoadTex("ItemDraft/Resources/ItemDraftActive.png"));
		val.pointValue = -10;
		PluginManager.ItemDraftID = ChallengeManager.Add("roundqueen.inscryption.itemdraft", val, 0, false).Challenge.challengeType;
		harmony.PatchAll(typeof(ItemDraftPatch));
	}
}
[BepInPlugin("roundqueen.inscryption.itemdraft", "ItemDraft", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class PluginManager : BaseUnityPlugin
{
	public static AscensionChallenge ItemDraftID;

	public const string PluginGuid = "roundqueen.inscryption.itemdraft";

	public const string PluginName = "ItemDraft";

	public const string PluginVersion = "1.0.0";

	public const string PluginPrefix = "ItemDraft";

	public void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("ItemDraft.harmonypatcher");
		val.PatchAll(Assembly.GetExecutingAssembly());
		ItemDraftPatch.Register(val);
	}
}
internal static class Tools
{
	public static Texture2D LoadTex(string path)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		byte[] array = ExtractEmbeddedResource(path);
		Texture2D val = new Texture2D(2, 2);
		ImageConversion.LoadImage(val, array);
		((Texture)val).filterMode = (FilterMode)0;
		return val;
	}

	public static byte[] ExtractEmbeddedResource(string filePath)
	{
		filePath = filePath.Replace("/", ".");
		filePath = filePath.Replace("\\", ".");
		Assembly callingAssembly = Assembly.GetCallingAssembly();
		using Stream stream = callingAssembly.GetManifestResourceStream(filePath);
		if (stream == null)
		{
			return null;
		}
		byte[] array = new byte[stream.Length];
		stream.Read(array, 0, array.Length);
		return array;
	}

	public static Sprite ConvertTexToSprite(Texture2D tex, Vector2? pivot = null)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: 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_002e: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(0.5f, 0.5f);
		if (pivot.HasValue)
		{
			((Vector2)(ref val))..ctor(pivot.Value.x, pivot.Value.y);
		}
		((Texture)tex).filterMode = (FilterMode)0;
		return Sprite.Create(tex, new Rect(0f, 0f, (float)((Texture)tex).width, (float)((Texture)tex).height), val, 100f);
	}

	public static T2 GetPrivateType<T, T2>(T obj, string field)
	{
		FieldInfo field2 = typeof(T).GetField(field, BindingFlags.Instance | BindingFlags.NonPublic);
		return (T2)field2.GetValue(obj);
	}

	public static void ShowLeshyMessage(string message, Emotion emotion, float duration)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		((MonoBehaviour)Singleton<TextDisplayer>.Instance).StartCoroutine(Singleton<TextDisplayer>.Instance.ShowThenClear(message, duration, 0f, emotion, (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;
	}
}