| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using HarmonyLib;
- using GadgetCore.API;
- using UnityEngine;
- using System.Collections;
- using System.Reflection;
- using System.Collections.Generic;
- namespace RecipeMenuCore.Patches
- {
- [HarmonyPatch(typeof(GameScript))]
- [HarmonyPatch("RefreshRecipeUnlock")]
- [HarmonyGadget("RecipeMenuCore")]
- public static class Patch_GameScript_RefreshRecipeUnlock
- {
- private static Material recipeLockSmall = new Material(Shader.Find("Unlit/Transparent"))
- {
- mainTexture = GadgetCoreAPI.LoadTexture2D("recipeLockSmall.png")
- };
- private static Material recipeLock = new Material(Shader.Find("Unlit/Transparent"))
- {
- mainTexture = GadgetCoreAPI.LoadTexture2D("recipeLock.png")
- };
- [HarmonyPrefix]
- public static bool Prefix(GameScript __instance, int ___craftType, int ___curRecipePage, GameObject ___ultLocksObj, GameObject ___recipeButtons,
- GameObject[] ___recipeLock, GameObject[] ___ultLocks, int[,] ___ultLocksUnlocked)
- {
- if (___craftType == 0 || ___craftType == 1 || ___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
- {
- for (int i = 0; i < 12; i++)
- {
- ___recipeButtons.transform.GetChild(i).gameObject.SetActive(true);
- ___recipeLock[i].GetComponent<Renderer>().material = recipeLock;
- }
- }
- var hoverElements = ___ultLocksObj.transform.parent.Find("hoverElements").gameObject;
- hoverElements.SetActive(false);
- if (___craftType == 2 && ___curRecipePage < 6 && Core.pageUltimateForgeInfoListVanilla[___curRecipePage] == null)
- {
- hoverElements.SetActive(true);
- for (int i = 0; i < 36; i++)
- {
- if (___ultLocksUnlocked[___curRecipePage, i] == 0)
- {
- hoverElements.transform.GetChild(i).gameObject.SetActive(false);
- }
- else
- {
- hoverElements.transform.GetChild(i).gameObject.SetActive(true);
- }
- }
- }
- if (___craftType == 0 && (___curRecipePage >= 6 || Core.pageGearForgeInfoListVanilla[___curRecipePage] != null))
- {
- ___ultLocksObj.SetActive(false);
- ___recipeButtons.SetActive(true);
- var page = ___curRecipePage >= 6 ? Core.pageGearForgeInfoList[___curRecipePage - 6] : Core.pageGearForgeInfoListVanilla[___curRecipePage];
- for (int i = 0; i < 12; i++)
- {
- if (page.GetRecipePageEntries().Length > i)
- {
- int itemID = page.GetRecipePageEntries()[i].ItemIdBase;
- if (__instance.RecipeCraftedAlready(itemID, page.GetRecipePageEntries()[i].MinAmount))
- ___recipeLock[i].SetActive(false);
- else
- {
- if (page.GetRecipePageEntries()[i].AllwaysShowInput)
- ___recipeLock[i].GetComponent<Renderer>().material = recipeLockSmall;
- ___recipeLock[i].SetActive(true);
- }
- }
- else
- {
- ___recipeLock[i].SetActive(false);
- ___recipeButtons.transform.GetChild(i).gameObject.SetActive(false);
- }
- }
- return false;
- }
- else if (___craftType == 1 && (___curRecipePage >=2 || Core.pageAlchemyStationInfoListVanilla[___curRecipePage] != null))
- {
- ___ultLocksObj.SetActive(false);
- ___recipeButtons.SetActive(true);
- var page = ___curRecipePage >= 6 ? Core.pageAlchemyStationInfoList[___curRecipePage - 2] : Core.pageAlchemyStationInfoListVanilla[___curRecipePage];
- for (int i = 0; i < 12; i++)
- {
- if (page.GetRecipePageEntries().Length > i)
- {
- int itemID = page.GetRecipePageEntries()[i].ItemIdBase;
- if (__instance.RecipeCraftedAlready(itemID, page.GetRecipePageEntries()[i].MinAmount))
- ___recipeLock[i].SetActive(false);
- else
- {
- if (page.GetRecipePageEntries()[i].AllwaysShowInput)
- ___recipeLock[i].GetComponent<Renderer>().material = recipeLockSmall;
- ___recipeLock[i].SetActive(true);
- }
- }
- else
- {
- ___recipeLock[i].SetActive(false);
- ___recipeButtons.transform.GetChild(i).gameObject.SetActive(false);
- }
- }
- return false;
- }
- else if (___craftType == 2 && (___curRecipePage >= 6 || Core.pageUltimateForgeInfoListVanilla[___curRecipePage] != null))
- {
- hoverElements.SetActive(true);
- ___ultLocksObj.SetActive(true);
- ___recipeButtons.SetActive(false);
- var page = ___curRecipePage >= 6 ? Core.pageUltimateForgeInfoList[___curRecipePage - 6] : Core.pageUltimateForgeInfoListVanilla[___curRecipePage];
- for (int i = 0; i < 36; i++)
- {
- if (i < 12)
- {
- ___recipeLock[i].SetActive(false);
- }
- if (page.GetRecipePageEntries().Length > i / 3)
- {
- int itemID = page.GetRecipePageEntries()[i / 3].ItemIdExtension[i % 3];
- if (__instance.RecipeCraftedAlready(itemID, 1))
- {
- ___ultLocks[i].SetActive(false);
- hoverElements.transform.GetChild(i).gameObject.SetActive(true);
- }
- else
- {
- ___ultLocks[i].SetActive(true);
- hoverElements.transform.GetChild(i).gameObject.SetActive(false);
- }
- }
- else
- {
- ___ultLocks[i].SetActive(false);
- hoverElements.transform.GetChild(i).gameObject.SetActive(false);
- }
- }
- return false;
- }
- else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
- {
- ___ultLocksObj.SetActive(false);
- ___recipeButtons.SetActive(true);
- var page = Core.pageUniversalCrafterInfoList[___curRecipePage];
- for (int i = 0; i < 12; i++)
- {
- if (page.GetRecipePageEntries().Length > i)
- {
- int itemID = page.GetRecipePageEntries()[i].ItemIdBase;
- if (((CraftMenuInfo)MenuRegistry.Singleton["Gadget Core:Crafter Menu"]).IsRecipeUnlocked(itemID))
- ___recipeLock[i].SetActive(false);
- else
- {
- if (page.GetRecipePageEntries()[i].AllwaysShowInput)
- ___recipeLock[i].GetComponent<Renderer>().material = recipeLockSmall;
- ___recipeLock[i].SetActive(true);
- }
- }
- else
- {
- ___recipeLock[i].SetActive(false);
- ___recipeButtons.transform.GetChild(i).gameObject.SetActive(false);
- }
- }
- return false;
- }
- return true;
- }
- }
- }
|