144 lines
3.1 KiB
C#
144 lines
3.1 KiB
C#
using Dalamud.Plugin.Services;
|
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
|
using LLib.GameUI;
|
|
|
|
namespace LLib.Shop;
|
|
|
|
public static class VendorPurchaseActions
|
|
{
|
|
private const string ShopAddon = "Shop";
|
|
|
|
private const string SelectStringAddon = "SelectString";
|
|
|
|
private const string SelectIconStringAddon = "SelectIconString";
|
|
|
|
private const string SelectYesnoAddon = "SelectYesno";
|
|
|
|
public unsafe static bool IsDialogReady(IGameGui gameGui)
|
|
{
|
|
if (gameGui.TryGetAddonByName<AtkUnitBase>("SelectIconString", out var addonPtr) && LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return true;
|
|
}
|
|
if (gameGui.TryGetAddonByName<AtkUnitBase>("SelectString", out var addonPtr2) && LAddon.IsAddonReady(addonPtr2))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public unsafe static bool TrySelectDialogOption(IGameGui gameGui, int index)
|
|
{
|
|
if (gameGui.TryGetAddonByName<AtkUnitBase>("SelectIconString", out var addonPtr) && LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
AddonCallback.Fire(addonPtr, index);
|
|
return true;
|
|
}
|
|
if (gameGui.TryGetAddonByName<AtkUnitBase>("SelectString", out var addonPtr2) && LAddon.IsAddonReady(addonPtr2))
|
|
{
|
|
AddonCallback.Fire(addonPtr2, index);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public unsafe static bool IsShopReady(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("Shop", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
return LAddon.IsAddonReady(addonPtr);
|
|
}
|
|
|
|
public unsafe static int FindItemDisplayIndex(IGameGui gameGui, uint itemId)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("Shop", out var addonPtr))
|
|
{
|
|
return -1;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return -1;
|
|
}
|
|
if (addonPtr->AtkValues == null || addonPtr->AtkValuesCount <= 2)
|
|
{
|
|
return -1;
|
|
}
|
|
uint uInt = addonPtr->AtkValues[2].UInt;
|
|
for (int i = 0; i < uInt; i++)
|
|
{
|
|
int num = 441 + i;
|
|
if (num >= addonPtr->AtkValuesCount)
|
|
{
|
|
return -1;
|
|
}
|
|
if (addonPtr->AtkValues[num].UInt == itemId)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public unsafe static bool TryBuyItem(IGameGui gameGui, int itemIndex, int quantity)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("Shop", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
AtkValue* values = stackalloc AtkValue[4]
|
|
{
|
|
new AtkValue
|
|
{
|
|
Type = AtkValueType.Int,
|
|
Int = 0
|
|
},
|
|
new AtkValue
|
|
{
|
|
Type = AtkValueType.Int,
|
|
Int = itemIndex
|
|
},
|
|
new AtkValue
|
|
{
|
|
Type = AtkValueType.Int,
|
|
Int = quantity
|
|
},
|
|
new AtkValue
|
|
{
|
|
Type = AtkValueType.Undefined,
|
|
Int = 0
|
|
}
|
|
};
|
|
addonPtr->FireCallback(4u, values);
|
|
return true;
|
|
}
|
|
|
|
public unsafe static bool TryConfirmPurchase(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("SelectYesno", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
AddonCallback.ClickYes(addonPtr);
|
|
return true;
|
|
}
|
|
|
|
public unsafe static bool TryCloseShop(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("Shop", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
addonPtr->Close(fireCallback: true);
|
|
return true;
|
|
}
|
|
}
|