Decompiled source of RandomChallenges v1.0.2

plugins/GeckVolantMarin-RandomChallenge.dll

Decompiled 2 days 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 HarmonyLib;
using InscryptionAPI.Ascension;
using InscryptionAPI.Helpers;
using Microsoft.CodeAnalysis;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GeckVolantMarin-RandomChallenge")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GeckVolantMarin-RandomChallenge")]
[assembly: AssemblyTitle("GeckVolantMarin-RandomChallenge")]
[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;
		}
	}
}
namespace GeckVolantMarin.RandomChallenge
{
	[BepInPlugin("GeckVolantMarin-RandomChallenge", "GeckVolantMarin-RandomChallenge", "1.0.0")]
	[BepInProcess("Inscryption.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static string directory;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			directory = ((BaseUnityPlugin)this).Info.Location;
			AscensionChallengeScreenPatch.register();
			Logger.LogInfo((object)"Reussi?");
			Logger.LogInfo((object)"Plugin GeckVolantMarin-RandomChallenge is loaded!");
		}
	}
	public class AscensionChallengeRandomButton : MonoBehaviour
	{
		public bool initialized;

		public AscensionChallengeScreen screen;

		public AscensionMenuInteractable randomButton;

		public void Initialize(AscensionChallengeScreen screen)
		{
			this.screen = screen;
			AscensionChallengeScreenPatch.iconStatus.Clear();
			foreach (List<GameObject> challengeObjectsForPage in ((Component)screen).GetComponent<AscensionChallengePaginator>().challengeObjectsForPages)
			{
				foreach (GameObject item in challengeObjectsForPage.Where((GameObject o) => (Object)(object)o.gameObject.GetComponent<AscensionIconInteractable>().challengeInfo != (Object)null && (Object)(object)o.gameObject.GetComponent<AscensionIconInteractable>().challengeInfo != (Object)(object)AscensionChallengePaginator.missingChallengeInfo))
				{
					AscensionChallengeScreenPatch.iconStatus[item.gameObject.GetComponent<AscensionIconInteractable>()] = AscensionChallengeScreenPatch.AscensionIconInteractableStatus.Unactive;
					if (!AscensionChallengeScreenPatch.iconBackup.ContainsKey(ChallengeManager.GetFullChallenge(item.gameObject.GetComponent<AscensionIconInteractable>().challengeInfo)))
					{
						AscensionChallengeScreenPatch.iconBackup[ChallengeManager.GetFullChallenge(item.gameObject.GetComponent<AscensionIconInteractable>().challengeInfo)] = item.gameObject.GetComponent<AscensionIconInteractable>().iconRenderer.sprite;
					}
					item.gameObject.GetComponent<AscensionIconInteractable>().iconRenderer.sprite = AscensionChallengeScreenPatch.iconBackup[ChallengeManager.GetFullChallenge(item.gameObject.GetComponent<AscensionIconInteractable>().challengeInfo)];
				}
			}
		}

		public void OnEnable()
		{
			Initialize(((Component)this).GetComponent<AscensionChallengeScreen>());
			if (Object.op_Implicit((Object)(object)randomButton))
			{
				Object.Destroy((Object)(object)((Component)randomButton).gameObject);
			}
			InstantiateRandomButton();
		}

		public void InstantiateRandomButton()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)screen.continueButton).transform.position + Vector3.left * 400f;
			AscensionChallengeScreen obj = screen;
			randomButton = Object.Instantiate<GameObject>(((Component)(((obj != null) ? ((Component)obj).gameObject : null) ?? ((Component)((Component)this).transform).gameObject).GetComponentInParent<AscensionMenuScreens>().starterDeckSelectScreen.GetComponent<AscensionChooseStarterDeckScreen>().randomButton).gameObject).GetComponent<AscensionMenuInteractable>();
			Transform transform = ((Component)randomButton).transform;
			AscensionChallengeScreen obj2 = screen;
			transform.SetParent(((obj2 != null) ? ((Component)obj2).transform : null) ?? ((Component)((Component)this).transform).transform, false);
			((Component)randomButton).GetComponent<ViewportRelativePosition>().offset = new Vector2(-0.45f, -0.22f);
			((InteractableBase)randomButton).ClearDelegates();
			AscensionMenuInteractable obj3 = randomButton;
			((MainInputInteractable)obj3).CursorSelectStarted = (Action<MainInputInteractable>)Delegate.Combine(((MainInputInteractable)obj3).CursorSelectStarted, (Action<MainInputInteractable>)delegate
			{
				OnRandomSelected();
			});
			((InteractableBase)randomButton).SetEnabled(true);
			((Component)randomButton).gameObject.SetActive(true);
			((ManagedBehaviour)randomButton).OnEnable();
		}

		private void OnRandomSelected()
		{
			int num = 0;
			foreach (AscensionIconInteractable item in from icon in AscensionChallengeScreenPatch.iconStatus.Keys.ToList()
				where (Object)(object)icon != (Object)null && ChallengeManager.GetFullChallenge(icon.challengeInfo).UnlockLevel <= AscensionSaveData.Data.challengeLevel && icon.challengeInfo.pointValue >= 0 && AscensionChallengeScreenPatch.iconStatus[icon] == AscensionChallengeScreenPatch.AscensionIconInteractableStatus.Unactive
				select icon)
			{
				num += item.challengeInfo.pointValue;
			}
			int num2 = (int)((Math.Floor(RNG.getRandomNumber_InRange(0.0, (double)(num + 1), 1.5)) + Math.Floor(RNG.getRandomNumber_InRange(0.0, (double)(num + 1), -3.0)) * 2.0) / 3.0);
			int num3 = 0;
			while (num3 <= num2 && (from icon in AscensionChallengeScreenPatch.iconStatus.Keys.ToList()
				where (Object)(object)icon != (Object)null && ChallengeManager.GetFullChallenge(icon.challengeInfo).UnlockLevel <= AscensionSaveData.Data.challengeLevel && icon.challengeInfo.pointValue >= 0 && AscensionChallengeScreenPatch.iconStatus[icon] == AscensionChallengeScreenPatch.AscensionIconInteractableStatus.Unactive
				select icon).Count() > 0)
			{
				List<AscensionIconInteractable> list = new List<AscensionIconInteractable>((from icon in AscensionChallengeScreenPatch.iconStatus.Keys.ToList()
					where (Object)(object)icon != (Object)null && ChallengeManager.GetFullChallenge(icon.challengeInfo).UnlockLevel <= AscensionSaveData.Data.challengeLevel && icon.challengeInfo.pointValue >= 0 && AscensionChallengeScreenPatch.iconStatus[icon] == AscensionChallengeScreenPatch.AscensionIconInteractableStatus.Unactive
					select icon).ToArray());
				double[] array = new double[list.Count()];
				for (int i = 0; i < list.Count(); i++)
				{
					array[i] = 1.0;
				}
				AscensionIconInteractable randomThings_FromArray = RNG.getRandomThings_FromArray<AscensionIconInteractable>(list.ToArray(), array, 0.0);
				AscensionChallengeScreenPatch.iconBackup[ChallengeManager.GetFullChallenge(randomThings_FromArray.challengeInfo)] = randomThings_FromArray.iconRenderer.sprite;
				num3 += randomThings_FromArray.challengeInfo.pointValue;
				AscensionChallengeScreenPatch.iconStatus[randomThings_FromArray] = AscensionChallengeScreenPatch.AscensionIconInteractableStatus.Active;
				randomThings_FromArray.ShowActivated(true);
				Singleton<AscensionChallengeScreen>.Instance.SetChallengeActivated(randomThings_FromArray.challengeInfo, true);
			}
			num = 0;
			foreach (AscensionIconInteractable item2 in from icon in AscensionChallengeScreenPatch.iconStatus.Keys.ToList()
				where (Object)(object)icon != (Object)null && ChallengeManager.GetFullChallenge(icon.challengeInfo).UnlockLevel <= AscensionSaveData.Data.challengeLevel && icon.challengeInfo.pointValue <= 0 && AscensionChallengeScreenPatch.iconStatus[icon] == AscensionChallengeScreenPatch.AscensionIconInteractableStatus.Unactive
				select icon)
			{
				num += item2.challengeInfo.pointValue;
			}
			num2 = (int)((Math.Floor(RNG.getRandomNumber_InRange(0.0, (double)(num + 1), 1.5)) * 2.0 + Math.Floor(RNG.getRandomNumber_InRange(0.0, (double)(num + 1), -3.0)) * 2.0) / 3.0);
			num3 = 0;
			while (num3 >= num2 && (from icon in AscensionChallengeScreenPatch.iconStatus.Keys.ToList()
				where (Object)(object)icon != (Object)null && ChallengeManager.GetFullChallenge(icon.challengeInfo).UnlockLevel <= AscensionSaveData.Data.challengeLevel && icon.challengeInfo.pointValue <= 0 && AscensionChallengeScreenPatch.iconStatus[icon] == AscensionChallengeScreenPatch.AscensionIconInteractableStatus.Unactive
				select icon).Count() > 0)
			{
				List<AscensionIconInteractable> list2 = new List<AscensionIconInteractable>((from icon in AscensionChallengeScreenPatch.iconStatus.Keys.ToList()
					where (Object)(object)icon != (Object)null && ChallengeManager.GetFullChallenge(icon.challengeInfo).UnlockLevel <= AscensionSaveData.Data.challengeLevel && icon.challengeInfo.pointValue <= 0 && AscensionChallengeScreenPatch.iconStatus[icon] == AscensionChallengeScreenPatch.AscensionIconInteractableStatus.Unactive
					select icon).ToArray());
				double[] array2 = new double[list2.Count()];
				for (int j = 0; j < list2.Count(); j++)
				{
					array2[j] = 1.0;
				}
				AscensionIconInteractable randomThings_FromArray2 = RNG.getRandomThings_FromArray<AscensionIconInteractable>(list2.ToArray(), array2, 0.0);
				AscensionChallengeScreenPatch.iconBackup[ChallengeManager.GetFullChallenge(randomThings_FromArray2.challengeInfo)] = randomThings_FromArray2.iconRenderer.sprite;
				num3 += randomThings_FromArray2.challengeInfo.pointValue;
				AscensionChallengeScreenPatch.iconStatus[randomThings_FromArray2] = AscensionChallengeScreenPatch.AscensionIconInteractableStatus.Active;
				randomThings_FromArray2.ShowActivated(true);
				Singleton<AscensionChallengeScreen>.Instance.SetChallengeActivated(randomThings_FromArray2.challengeInfo, true);
			}
		}
	}
	[HarmonyPatch]
	public static class AscensionChallengeScreenPatch
	{
		public enum AscensionIconInteractableStatus
		{
			NONE,
			Unactive,
			Active,
			Crossed,
			NUM_STATUS
		}

		private static readonly Harmony HarmonyInstance = new Harmony("GeckVolantMarin-RandomChallenge");

		public static Dictionary<AscensionIconInteractable, AscensionIconInteractableStatus> iconStatus = new Dictionary<AscensionIconInteractable, AscensionIconInteractableStatus>();

		public static Dictionary<FullChallenge, Sprite> iconBackup = new Dictionary<FullChallenge, Sprite>();

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AscensionChallengeScreen), "Start")]
		private static void AddRandomButtonToChallengeScreen(AscensionChallengeScreen __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<AscensionChallengeRandomButton>() == (Object)null)
			{
				AscensionChallengeRandomButton ascensionChallengeRandomButton = ((Component)__instance).gameObject.AddComponent<AscensionChallengeRandomButton>();
				ascensionChallengeRandomButton.Initialize(__instance);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(AscensionIconInteractable), "OnCursorSelectStart")]
		private static bool OnCursorSelectStart(AscensionIconInteractable __instance)
		{
			if (__instance.clickable && __instance.Unlocked)
			{
				if (iconStatus[__instance] == AscensionIconInteractableStatus.Unactive)
				{
					iconBackup[ChallengeManager.GetFullChallenge(__instance.challengeInfo)] = __instance.iconRenderer.sprite;
					iconStatus[__instance] = AscensionIconInteractableStatus.Active;
					__instance.ShowActivated(true);
					Singleton<AscensionChallengeScreen>.Instance.SetChallengeActivated(__instance.challengeInfo, true);
				}
				else if (iconStatus[__instance] == AscensionIconInteractableStatus.Active)
				{
					iconStatus[__instance] = AscensionIconInteractableStatus.Crossed;
					__instance.iconRenderer.sprite = TextureHelper.GetImageAsSprite(Path.Combine(Path.GetDirectoryName(Plugin.directory), "crossedIcon.png"), (SpriteType)4, (FilterMode)0);
					__instance.ShowActivated(false);
					Singleton<AscensionChallengeScreen>.Instance.SetChallengeActivated(__instance.challengeInfo, false);
				}
				else if (iconStatus[__instance] == AscensionIconInteractableStatus.Crossed)
				{
					iconStatus[__instance] = AscensionIconInteractableStatus.Unactive;
					__instance.iconRenderer.sprite = iconBackup[ChallengeManager.GetFullChallenge(__instance.challengeInfo)];
					__instance.ShowActivated(false);
				}
				return false;
			}
			return true;
		}

		public static void register()
		{
			HarmonyInstance.PatchAll(typeof(Plugin).Assembly);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "GeckVolantMarin-RandomChallenge";

		public const string PLUGIN_NAME = "GeckVolantMarin-RandomChallenge";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}