Patch_GameScript_Update.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using GadgetCore.API;
  2. using HarmonyLib;
  3. using UnityEngine;
  4. namespace StorageExpansion.Patches
  5. {
  6. [HarmonyPatch(typeof(GameScript))]
  7. [HarmonyPatch("Update")]
  8. [HarmonyGadget("StorageExpansion")]
  9. public static class Patch_GameScript_Update
  10. {
  11. [HarmonyPrefix]
  12. public static void Prefix(GameScript __instance, ref int ___storageLevel)
  13. {
  14. if (MenuScript.player)
  15. {
  16. if (!GameScript.pausing)
  17. {
  18. if (Input.GetMouseButtonDown(0) && GameScript.inventoryOpen)
  19. {
  20. var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  21. RaycastHit hit;
  22. if (Physics.Raycast(ray, out hit, 7f))
  23. {
  24. if (hit.transform.gameObject.layer != 16 && hit.transform.gameObject.layer != 17)
  25. {
  26. string name = hit.transform.gameObject.name;
  27. if (name.StartsWith("page"))
  28. {
  29. var slot = int.Parse(hit.transform.gameObject.name.Substring("page".Length));
  30. __instance.SelectPage(slot);
  31. }
  32. }
  33. }
  34. }
  35. }
  36. }
  37. }
  38. }
  39. }