| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using GadgetCore;
- using GadgetCore.API;
- using HarmonyLib;
- using System;
- using UnityEngine;
- namespace VanitySlots.Patches
- {
- [HarmonyPatch(typeof(GameScript))]
- [HarmonyPatch("Update")]
- [HarmonyGadget("VanitySlots")]
- public static class Patch_GameScript_Update
- {
- [HarmonyPrefix]
- public static void Prefix(GameScript __instance, ref Item ___holdingItem, ref int ___curhoveringstat, ref bool ___holdingCombatChip, bool ___exitingcombatmode)
- {
- try
- {
- if (MenuScript.player)
- {
- if (!GameScript.pausing && Input.GetMouseButtonDown(0) && GameScript.inventoryOpen)
- {
- var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, 7f))
- {
- if (hit.transform.gameObject.name.StartsWith("vanity_slot_"))
- {
- var slot = 2;
- if (hit.transform.gameObject.name.StartsWith("vanity_slot_"))
- slot = int.Parse(hit.transform.gameObject.name.Substring("vanity_slot_".Length));
- if (slot >= 0 && slot < Core.itemStore.Items.Length)
- {
- if (___holdingItem.id != 0)
- {
- if (Core.itemStore.CanUse(___holdingItem, slot))
- {
- if (Core.itemStore.Items[slot].id == 0)
- {
- Place(__instance, slot, ref ___holdingItem);
- }
- else
- {
- Swap(__instance, slot, ref ___holdingItem);
- }
- }
- }
- else if (Core.itemStore.Items[slot].id != 0)
- {
- Select(__instance, slot, ref ___holdingItem);
- }
- }
- }
- }
- }
- }
- }
- catch (Exception e) { Core.logger.LogConsole(e.Message); }
- }
- [HarmonyPostfix]
- public static void Postfix()
- {
- if (MenuScript.player)
- {
- if (GameScript.inventoryOpen)
- {
- var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, 7f))
- {
- if (hit.transform.gameObject.name.StartsWith("vanity_slot_"))
- {
- var slot = 2;
- if (hit.transform.gameObject.name.StartsWith("vanity_slot_"))
- slot = int.Parse(hit.transform.gameObject.name.Substring("vanity_slot_".Length));
- if ((Core.itemStore.Items[slot]?.id ?? 0) != 0)
- PatchMethods.HoverItem(Core.itemStore.Items[slot]);
- }
- }
- }
- }
- }
- private static void Swap(GameScript __instance, int slot, ref Item ___holdingItem)
- {
- __instance.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/CLICK1"), Menuu.soundLevel / 10f);
- Item item = ___holdingItem;
- ___holdingItem = Core.itemStore.Items[slot];
- Core.itemStore.Items[slot] = item;
- Core.itemStore.UpdateUI();
- __instance.RefreshHoldingSlot();
- }
- private static void Select(GameScript __instance, int slot, ref Item ___holdingItem)
- {
- __instance.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/CLICK1"), Menuu.soundLevel / 10f);
- ___holdingItem = Core.itemStore.Items[slot];
- Core.itemStore.Items[slot] = __instance.EmptyItem();
- Core.itemStore.UpdateUI();
- __instance.RefreshHoldingSlot();
- }
- private static void Place(GameScript __instance, int slot, ref Item ___holdingItem)
- {
- __instance.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/CLICK1"), Menuu.soundLevel / 10f);
- Core.itemStore.Items[slot] = ___holdingItem;
- ___holdingItem = __instance.EmptyItem();
- Core.itemStore.UpdateUI();
- __instance.RefreshHoldingSlot();
- }
- }
- }
|