mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
feat(model): DressUpModel IsSlotAllowed and IsSlotVisible
IsSlotAllowed answers from the gates of 1.12.1's DressUpModel::TryOnItem worker (0x00504540): a hand takes any held item, and an armor slot needs the pane's character component (+0x3F8) with its ready byte (+0x40C) set. A shapeshifted unit has neither, so its armor slots are not allowed. The neck, rings, trinkets and ranged slot have no arm in the worker. A pane without a model allows nothing. No 1.12 model hides an item in a slot it takes, so IsSlotVisible gives the same answer. The slot rule moves into Outfit::SlotAllowed, which the ModelScene actor now shares, and TryOnResult reads the armor gate through the same ArmorReady helper.
This commit is contained in:
@@ -115,7 +115,7 @@ In the Frame rows, a name that starts with `:` is a method of the widget that th
|
||||
| [Map](docs/API.md#map) | `C_Map.CanSetUserWaypointOnMap`, `C_Map.ClearUserWaypoint`, `C_Map.GetAreaInfo`, `C_Map.GetAreas`, `C_Map.GetAreaTriggerInfo`, `C_Map.GetAreaTriggers`, `C_Map.GetBestMapForUnit`, `C_Map.GetFallbackWorldMapID`, `C_Map.GetMapAreaIDs`, `C_Map.GetMapArtLayers`, `C_Map.GetMapArtLayerTextures`, `C_Map.GetMapChildrenInfo`, `C_Map.GetMapInfo`, `C_Map.GetMapInfoAtPosition`, `C_Map.GetMapOverlays`, `C_Map.GetMapPosFromWorldPos`, `C_Map.GetMapRectOnMap`, `C_Map.GetMapWorldSize`, `C_Map.GetPlayerMapPosition`, `C_Map.GetUserWaypoint`, `C_Map.GetUserWaypointFromHyperlink`, `C_Map.GetUserWaypointHyperlink`, `C_Map.GetUserWaypointPositionForMap`, `C_Map.GetWorldPosFromMapPos`, `C_Map.HasUserWaypoint`, `C_Map.MapHasArt`, `C_Map.SetUserWaypoint` |
|
||||
| [MapExplorationInfo](docs/API.md#mapexplorationinfo) | `C_MapExplorationInfo.GetExploredAreaIDsAtPosition`, `C_MapExplorationInfo.GetExploredMapTextures`, `C_MapExplorationInfo.GetUnexploredMapTextures` |
|
||||
| [MerchantFrame](docs/API.md#merchantframe) | `C_MerchantFrame.GetBuybackItemID`, `C_MerchantFrame.GetItemInfo`, `C_MerchantFrame.GetNumJunkItems`, `C_MerchantFrame.IsMerchantItemRefundable`, `C_MerchantFrame.IsSellAllJunkEnabled`, `C_MerchantFrame.SellAllJunkItems`, `GetBuybackItemLink` |
|
||||
| [Model](docs/API.md#model) | `DressUpModel:TryOn` (links, recipes, names, hand, enchant glow, result), `DressUpModel:UndressSlot`, `DressUpModel:IsGeoReady`, `DressUpModel:SetSheathed` / `GetSheathed`, `DressUpModel:SetAutoDress` / `GetAutoDress`, `DressUpModel:GetItemTransmogInfo` / `GetItemTransmogInfoList` / `SetItemTransmogInfo`, `Model:SetGlow`, `PlayerModel:RefreshCamera`, `PlayerModel:SetCamDistanceScale`, `PlayerModel:SetCreature` (`displayID`), `PlayerModel:SetDisplayInfo`, `PlayerModel:SetItem`, `PlayerModel:SetPortraitZoom`, `PlayerModel:SetRotation` (`animate`), `PlayerModel:SetUnit` (result), `PlayerModel:CanSetUnit`, `PlayerModel:GetDisplayInfo`, `PlayerModel:SetAnimation`, `PlayerModel:FreezeAnimation`, `PlayerModel:HasAnimation`, `PlayerModel:SetDoBlend` / `GetDoBlend`, `PlayerModel:SetKeepModelOnHide` / `GetKeepModelOnHide`, `PlayerModel:ApplySpellVisualKit` |
|
||||
| [Model](docs/API.md#model) | `DressUpModel:TryOn` (links, recipes, names, hand, enchant glow, result), `DressUpModel:UndressSlot`, `DressUpModel:IsGeoReady`, `DressUpModel:SetSheathed` / `GetSheathed`, `DressUpModel:SetAutoDress` / `GetAutoDress`, `DressUpModel:GetItemTransmogInfo` / `GetItemTransmogInfoList` / `SetItemTransmogInfo`, `DressUpModel:IsSlotAllowed` / `IsSlotVisible`, `Model:SetGlow`, `PlayerModel:RefreshCamera`, `PlayerModel:SetCamDistanceScale`, `PlayerModel:SetCreature` (`displayID`), `PlayerModel:SetDisplayInfo`, `PlayerModel:SetItem`, `PlayerModel:SetPortraitZoom`, `PlayerModel:SetRotation` (`animate`), `PlayerModel:SetUnit` (result), `PlayerModel:CanSetUnit`, `PlayerModel:GetDisplayInfo`, `PlayerModel:SetAnimation`, `PlayerModel:FreezeAnimation`, `PlayerModel:HasAnimation`, `PlayerModel:SetDoBlend` / `GetDoBlend`, `PlayerModel:SetKeepModelOnHide` / `GetKeepModelOnHide`, `PlayerModel:ApplySpellVisualKit` |
|
||||
| [ModelInfo](docs/API.md#c_modelinfogetmodelsceneinfobyidmodelsceneid) | `C_ModelInfo.GetModelSceneInfoByID`, `C_ModelInfo.GetModelSceneCameraInfoByID`, `C_ModelInfo.GetModelSceneActorInfoByID`, `C_ModelInfo.GetModelSceneActorDisplayInfoByID` |
|
||||
| [Mount](docs/API.md#mount) | `C_MountJournal.GetMountFromItem`, `C_MountJournal.GetMountFromSpell`, `C_MountJournal.GetMountInfoExtraByID` |
|
||||
| [NamePlate](docs/API.md#nameplate) | `C_NamePlate.GetNamePlateForGUID`, `C_NamePlate.GetNamePlateForUnit`, `C_NamePlate.GetNamePlateGUIDs`, `C_NamePlate.GetNamePlates` |
|
||||
|
||||
+16
@@ -814,6 +814,7 @@ build instructions.
|
||||
- [`DressUpModel:GetAutoDress()`](#dressupmodelgetautodress)
|
||||
- [`DressUpModel:GetItemTransmogInfo(slot)` / `DressUpModel:GetItemTransmogInfoList()`](#dressupmodelgetitemtransmoginfoslot--dressupmodelgetitemtransmoginfolist)
|
||||
- [`DressUpModel:SetItemTransmogInfo(info [, slot, ignoreChildItems])`](#dressupmodelsetitemtransmoginfoinfo--slot-ignorechilditems)
|
||||
- [`DressUpModel:IsSlotAllowed(slot)` / `DressUpModel:IsSlotVisible(slot)`](#dressupmodelisslotallowedslot--dressupmodelisslotvisibleslot)
|
||||
- [`Model:SetGlow(value)`](#modelsetglowvalue)
|
||||
|
||||
- [ModelScene](#modelscene)
|
||||
@@ -19077,6 +19078,21 @@ for slot, info in ipairs(DressUpModel:GetItemTransmogInfoList()) do
|
||||
end
|
||||
```
|
||||
|
||||
### `DressUpModel:IsSlotAllowed(slot)` / `DressUpModel:IsSlotVisible(slot)`
|
||||
|
||||
`IsSlotAllowed` returns `true` when the frame can wear an item in the
|
||||
inventory slot:
|
||||
|
||||
- The hands (`16` and `17`) are allowed on all models.
|
||||
- The armor slots are allowed when `TryOn` can put armor on the frame. A
|
||||
shapeshifted player, or a creature without a character model, has no armor
|
||||
slots.
|
||||
- The neck, the rings, the trinkets, and the ranged slot are not allowed. A
|
||||
ranged weapon that `TryOn` puts on goes into a hand.
|
||||
|
||||
It returns `false` for a frame that shows no model. `IsSlotVisible` returns
|
||||
the same value, because an item in an allowed slot always shows.
|
||||
|
||||
### `Model:SetGlow(value)`
|
||||
|
||||
This method exists on every `Model` frame, for code from later clients. It
|
||||
|
||||
+51
-6
@@ -13,7 +13,8 @@
|
||||
|
||||
// `DressUpModel:UndressSlot(slot)`, the 4.3.4 `DressUpModel:TryOn(item)`
|
||||
// (DressUpModelFrame_Scripts.cpp), and retail's TryOn result, IsGeoReady,
|
||||
// SetSheathed / GetSheathed and SetAutoDress / GetAutoDress.
|
||||
// SetSheathed / GetSheathed, SetAutoDress / GetAutoDress, IsSlotAllowed /
|
||||
// IsSlotVisible and the ItemTransmogInfo methods.
|
||||
//
|
||||
// UndressSlot is one step of vanilla's own Undress (DressUpModel::ClearModel
|
||||
// 0x00504490), which 4.3.4 split per slot: a component slot is cleared with
|
||||
@@ -222,6 +223,12 @@ int __fastcall Script_UndressSlot(void *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The worker's armor gate: the component and the ready byte.
|
||||
bool ArmorReady(void *pane) {
|
||||
return Game::Read<void *>(pane, Offsets::OFF_DRESSUPMODEL_COMPONENT) != nullptr &&
|
||||
Game::Read<uint8_t>(pane, Offsets::OFF_DRESSUPMODEL_READY) != 0;
|
||||
}
|
||||
|
||||
// What the worker did with `itemID`, from the gates it passes (0x00504540).
|
||||
int TryOnResult(void *pane, uint32_t itemID) {
|
||||
const uint8_t *record = Item::PeekRecord(itemID);
|
||||
@@ -231,11 +238,8 @@ int TryOnResult(void *pane, uint32_t itemID) {
|
||||
Pane::Model(pane) == nullptr)
|
||||
return TryOn::kNotEquippable;
|
||||
switch (Outfit::ArmOf(Game::Read<uint32_t>(record, Offsets::OFF_ITEMSTATS_INVENTORY_TYPE))) {
|
||||
case Outfit::Arm::Armor: // the component and the ready byte
|
||||
return Game::Read<void *>(pane, Offsets::OFF_DRESSUPMODEL_COMPONENT) != nullptr &&
|
||||
Game::Read<uint8_t>(pane, Offsets::OFF_DRESSUPMODEL_READY) != 0
|
||||
? TryOn::kSuccess
|
||||
: TryOn::kNotEquippable;
|
||||
case Outfit::Arm::Armor:
|
||||
return ArmorReady(pane) ? TryOn::kSuccess : TryOn::kNotEquippable;
|
||||
case Outfit::Arm::Held:
|
||||
return TryOn::kSuccess;
|
||||
default:
|
||||
@@ -400,6 +404,30 @@ int __fastcall Script_SetItemTransmogInfo(void *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// The slots the worker's arms put an item in. No 1.12 model hides a slot it
|
||||
// takes, so IsSlotVisible gives the same.
|
||||
int SlotQuery(void *L, const char *usage) {
|
||||
void *pane = Game::Lua::ResolveDressUpModel(L);
|
||||
if (pane == nullptr)
|
||||
return 0;
|
||||
if (!Game::Lua::IsNumber(L, 2)) {
|
||||
Game::Lua::Error(L, usage, Game::Lua::ObjectDisplayName(pane));
|
||||
return 0;
|
||||
}
|
||||
Game::Lua::PushBool(L, Pane::Model(pane) != nullptr &&
|
||||
Outfit::SlotAllowed(static_cast<int>(Game::Lua::ToNumber(L, 2)),
|
||||
ArmorReady(pane)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int __fastcall Script_IsSlotAllowed(void *L) {
|
||||
return SlotQuery(L, "Usage: %s:IsSlotAllowed(slot)");
|
||||
}
|
||||
|
||||
int __fastcall Script_IsSlotVisible(void *L) {
|
||||
return SlotQuery(L, "Usage: %s:IsSlotVisible(slot)");
|
||||
}
|
||||
|
||||
const Game::Lua::FrameMethodEntry g_methods[] = {
|
||||
{"UndressSlot", &Script_UndressSlot},
|
||||
{"TryOn", &Script_TryOn},
|
||||
@@ -412,6 +440,8 @@ const Game::Lua::FrameMethodEntry g_methods[] = {
|
||||
{"GetItemTransmogInfo", &Script_GetItemTransmogInfo},
|
||||
{"GetItemTransmogInfoList", &Script_GetItemTransmogInfoList},
|
||||
{"SetItemTransmogInfo", &Script_SetItemTransmogInfo},
|
||||
{"IsSlotAllowed", &Script_IsSlotAllowed},
|
||||
{"IsSlotVisible", &Script_IsSlotVisible},
|
||||
};
|
||||
|
||||
const Game::Doc::Field kUndressArgs[] = {
|
||||
@@ -482,6 +512,19 @@ const Game::Doc::Function kSetItemTransmogInfo{
|
||||
"Puts an item on the model, as TryOn does. Shows no error. An appearanceID of 0 changes "
|
||||
"nothing.",
|
||||
kSetTransmogInfoArgs, kTryOnRets};
|
||||
const Game::Doc::Field kSlotAllowedRets[] = {
|
||||
Game::Doc::Req("allowed", "bool"),
|
||||
};
|
||||
const Game::Doc::Function kIsSlotAllowed{
|
||||
"Returns whether TryOn can put an item in an inventory slot of the model. The hands are "
|
||||
"always allowed. An armor slot is allowed when TryOn can put armor on the model.",
|
||||
kUndressArgs, kSlotAllowedRets};
|
||||
const Game::Doc::Field kSlotVisibleRets[] = {
|
||||
Game::Doc::Req("visible", "bool"),
|
||||
};
|
||||
const Game::Doc::Function kIsSlotVisible{
|
||||
"Returns whether an item in an inventory slot shows on the model. Same as IsSlotAllowed.",
|
||||
kUndressArgs, kSlotVisibleRets};
|
||||
const Game::Doc::Method g_methodDocs[] = {
|
||||
{"UndressSlot", &kUndressSlot}, {"TryOn", &kTryOn},
|
||||
{"Dress", &kDress}, {"IsGeoReady", &kIsGeoReady},
|
||||
@@ -490,6 +533,8 @@ const Game::Doc::Method g_methodDocs[] = {
|
||||
{"GetItemTransmogInfo", &kGetItemTransmogInfo},
|
||||
{"GetItemTransmogInfoList", &kGetItemTransmogInfoList},
|
||||
{"SetItemTransmogInfo", &kSetItemTransmogInfo},
|
||||
{"IsSlotAllowed", &kIsSlotAllowed},
|
||||
{"IsSlotVisible", &kIsSlotVisible},
|
||||
};
|
||||
|
||||
const Game::Lua::EnumIntegerEntry kItemTryOnReason[] = {
|
||||
|
||||
@@ -150,6 +150,12 @@ int InvSlotOfComponent(uint32_t componentSlot) {
|
||||
return componentSlot < std::size(kInvSlotOfComponent) ? kInvSlotOfComponent[componentSlot] : 0;
|
||||
}
|
||||
|
||||
bool SlotAllowed(int invSlot, bool armorReady) {
|
||||
if (invSlot == Offsets::INVSLOT_MAINHAND || invSlot == Offsets::INVSLOT_OFFHAND)
|
||||
return true;
|
||||
return ComponentSlotOf(invSlot) >= 0 && armorReady;
|
||||
}
|
||||
|
||||
void ReadLanes(void *unit, Lanes &lanes) {
|
||||
const auto get = VirtualOf<GetHeldItemLane_t>(unit, Offsets::VTBL_UNIT_GET_HELD_ITEM_LANE);
|
||||
for (uint32_t hand = 0; hand < 2; ++hand) {
|
||||
|
||||
@@ -120,6 +120,11 @@ int ComponentSlotOf(int invSlot);
|
||||
// The inventory slot (1-based) of a component slot ArmOf gives, or 0.
|
||||
int InvSlotOfComponent(uint32_t componentSlot);
|
||||
|
||||
// Whether TryOnItem's arms put anything in an inventory slot (1-based): a
|
||||
// hand takes any held item, an armor slot needs `armorReady` (a component the
|
||||
// model's ready gate allows).
|
||||
bool SlotAllowed(int invSlot, bool armorReady);
|
||||
|
||||
// What `unit` wears in one inventory slot (1-based), back on the model: an
|
||||
// armor slot takes the unit's component record (empty when the unit hides
|
||||
// its helm or cloak), a held lane the unit's lane, row and glow. Armor needs
|
||||
|
||||
@@ -741,12 +741,9 @@ int __fastcall Script_SetItemTransmogInfo(void *L) {
|
||||
// The slots TryOnReason's arms accept: a hand on any model, armor on one
|
||||
// that takes it.
|
||||
bool SlotAllowed(const Actor &actor, int invSlot) {
|
||||
if (actor.model == nullptr)
|
||||
return false;
|
||||
if (invSlot == Offsets::INVSLOT_MAINHAND || invSlot == Offsets::INVSLOT_OFFHAND)
|
||||
return true;
|
||||
return Outfit::ComponentSlotOf(invSlot) >= 0 &&
|
||||
(actor.dresser != nullptr || actor.dressRecord != nullptr) && actor.armorReady;
|
||||
return actor.model != nullptr &&
|
||||
Outfit::SlotAllowed(invSlot, (actor.dresser != nullptr || actor.dressRecord != nullptr) &&
|
||||
actor.armorReady);
|
||||
}
|
||||
|
||||
int __fastcall Script_IsSlotAllowed(void *L) {
|
||||
|
||||
Reference in New Issue
Block a user