Decompiled source of Limit Perk Pool v1.0.0

plugins/LimitPerkPool.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LimitPerkPool")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LimitPerkPool")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fcd0a3b8-5916-4304-b2af-f66fbc68ff14")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LPP;

[BepInPlugin("nachariah.whiteknuckle.limitperkpool", "LimitPerkPool", "1.0.0")]
public class LimitPerkPool : BaseUnityPlugin
{
	public const string pluginGuid = "nachariah.whiteknuckle.limitperkpool";

	public const string pluginName = "LimitPerkPool";

	public const string pluginVersion = "1.0.0";

	public static LimitPerkPool Instance;

	public Dictionary<string, bool> AllowedPerks = new Dictionary<string, bool>();

	private void Awake()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		Instance = this;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[LimitPerkPool] Loaded");
		Harmony val = new Harmony("nachariah.whiteknuckle.limitperkpool");
		MethodInfo methodInfo = AccessTools.Method(typeof(App_PerkPage), "GenerateCards", (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(LimitPerkPatches), "GenerateCards_Limit", (Type[])null, (Type[])null);
		val.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		string configFilePath = ((BaseUnityPlugin)Instance).Config.ConfigFilePath;
		if (!File.Exists(configFilePath))
		{
			Debug.Log((object)"[LimitPerkPool] Open an upgrade station to generate a config file");
		}
	}
}
public class LimitPerkPatches
{
	public static bool GenerateCards_Limit(App_PerkPage __instance)
	{
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Expected O, but got Unknown
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Invalid comparison between Unknown and I4
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Invalid comparison between Unknown and I4
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Invalid comparison between Unknown and I4
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Invalid comparison between Unknown and I4
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Invalid comparison between Unknown and I4
		Debug.Log((object)"[LimitPerkPool] Generating Perks...");
		List<Perk> list = CL_AssetManager.instance?.assetDatabase?.perkAssets;
		if (list == null || list.Count == 0)
		{
			Debug.LogError((object)"[LimitPerkPool] Could not initialize perk config — perkAssets not ready - fallback to base method.");
			return true;
		}
		foreach (Perk item in list)
		{
			string name = ((Object)item).name;
			ConfigEntry<bool> val = ((BaseUnityPlugin)LimitPerkPool.Instance).Config.Bind<bool>("PerkToggles", name, true, "Enable or disable '" + name + "'");
			LimitPerkPool.Instance.AllowedPerks[name] = val.Value;
		}
		FieldInfo field = typeof(App_PerkPage).GetField("os", BindingFlags.Instance | BindingFlags.NonPublic);
		FieldInfo field2 = typeof(App_PerkPage).GetField("cards", BindingFlags.Instance | BindingFlags.NonPublic);
		OS_Manager val2 = (OS_Manager)field.GetValue(__instance);
		List<App_PerkPage_Card> list2 = (List<App_PerkPage_Card>)field2.GetValue(__instance);
		OS_Computer_Interface worldInterface = val2.worldInterface;
		SessionFlag gameFlag = CL_GameManager.GetGameFlag("recieved-" + worldInterface.computerID + "-perk");
		if (gameFlag != null && gameFlag.state)
		{
			return false;
		}
		if (worldInterface.GetSeed() != -1)
		{
			Random.InitState(worldInterface.GetSeed());
		}
		int num = Random.Range(__instance.minCards, __instance.maxCards + 1);
		List<Perk> list3 = new List<Perk>(CL_AssetManager.instance.assetDatabase.perkAssets);
		for (int num2 = list3.Count - 1; num2 >= 0; num2--)
		{
			if ((int)__instance.perkPageType == 0)
			{
				if ((int)list3[num2].spawnPool > 0)
				{
					list3.RemoveAt(num2);
				}
			}
			else if ((int)__instance.perkPageType == 1 && (int)list3[num2].spawnPool != 1)
			{
				list3.RemoveAt(num2);
			}
		}
		Dictionary<string, bool> allowed = LimitPerkPool.Instance.AllowedPerks;
		list3.RemoveAll((Perk p) => !allowed.TryGetValue(((Object)p).name, out var value) || !value);
		Debug.Log((object)$"[LimitPerkPool] {list3.Count} perk(s) in perk pool.");
		for (int i = 0; i < num; i++)
		{
			App_PerkPage_Card component = ((Component)Object.Instantiate<App_PerkPage_Card>(__instance.cardAsset, __instance.cardParent.position, Quaternion.identity, __instance.cardParent)).GetComponent<App_PerkPage_Card>();
			bool flag = false;
			Perk val3 = null;
			int num3 = 0;
			while (!flag && num3 < 100)
			{
				num3++;
				val3 = list3[Random.Range(0, list3.Count)];
				if (!val3.CanSpawn())
				{
					Debug.Log((object)("Found perk which can't spawn: " + ((Object)val3).name));
				}
				else if ((int)__instance.perkPageType == 1)
				{
					flag = true;
				}
				else if ((i < num - 1 && val3.cost == 0) || (i == num - 1 && val3.cost > 0))
				{
					flag = true;
				}
			}
			list3.Remove(val3);
			val3 = Object.Instantiate<Perk>(val3);
			int num4 = 0;
			if (CL_GameManager.gMan.GetPlayerAscent() > 2000f)
			{
				num4 = Mathf.RoundToInt((CL_GameManager.gMan.GetPlayerAscent() - 2000f) / 200f);
			}
			Perk obj = val3;
			obj.cost += num4;
			val3.cost = Mathf.Min(val3.cost, 99);
			component.Initialize(__instance, val3);
			list2.Add(component);
		}
		__instance.SubmitCard(list2[0]);
		return false;
	}
}