using GadgetCore.API;
using HarmonyLib;
using System.Linq;
using System.Reflection;

namespace Subworlds.Patches
{

  [HarmonyPatch]
  [HarmonyGadget("SubworldCore_")]
  public static class Patch_PlanetRegistry_get_PlanetSelectorPages
  {

    [HarmonyTargetMethod]
    static MethodBase TargetMethod()
    {
      return AccessTools.Method(typeof(GadgetCoreAPI).Assembly.GetType("GadgetCore.API.PlanetRegistry"), "get_PlanetSelectorPages");
    }

    [HarmonyPrefix]
    public static bool Prefix(ref int __result)
    {
      __result = ((PlanetRegistry.Singleton.AsEnumerable().Count(x => x.SelectorButtonMat != null) + 13) / 14) + 1;
      return false;
    }
  }
}