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

namespace Subworlds.Patches
{

  [HarmonyPatch(typeof(GameScript))]
  [HarmonyPatch("RefreshGearMods")]
  [HarmonyGadget("SubworldCore")]
  public static class Patch_GameScript_RefreshGearMods
  {
    [HarmonyPostfix]
    public static void Postfix(GameScript __instance, Item[] ___modSlot)
    {
      int n = 5;
      int id = ___modSlot[0].id;
      if (id > 0)
        for (int i = 0; i < 3; i++)
          if (___modSlot[0].aspect[i] > 0 && ___modSlot[0].aspect[i] == Core.itemOldTexMod.GetID())
            n += ___modSlot[0].aspectLvl[i];
      try
      {
        var text1Transform = GameObject.Find("Main Camera").transform.Find("menuMods").Find("txtName (1)");
        var text2Transform = text1Transform.GetChild(0);
        text1Transform.GetComponent<TextMesh>().text = "Mods can stack up to " + n + " times each";
        text2Transform.GetComponent<TextMesh>().text = "Mods can stack up to " + n + " times each";
      }
      catch { }
    }
  }
}