Files
WoW-Hybrid-gateway/tests/native_guild_bank_packet_test.cpp

153 lines
12 KiB
C++

#include "world_translation.hpp"
#include "gateway/chat.hpp"
#include "gateway/turtle_entity_profile.hpp"
#include <cstdlib>
using namespace gateway;
namespace {
Bytes addon(uint64_t sender,const std::string& text){
auto wire="TW_GUILDBANK\t"+text;
Bytes b{3};le(b,0xffffffffu,4);le(b,sender,8);le(b,wire.size()+1,4);cstring(b,wire);le(b,0,1);return b;
}
}
int main(){
// Value-initialize through the default constructor: GCC 16 misdiagnoses aggregate cleanup at -O2.
auto world = NativeWorldTranslation();world.selected.guid=4520;world.selected.name="Fixture";
world.realm=70;world.guild_id=22;world.guild_rank=0;world.self_created=true;
uint64_t npc=(uint64_t(0xf130)<<48)|(uint64_t(80918)<<24)|17;
auto modern=forever_creature_guid(npc,80918,70,1);
NativeEntityTranslation::Actor a;a.entry=80918;a.kind=3;a.sent=true;a.generation=1;a.modern=modern;
world.entities.actors.emplace(npc,a);
Bytes gossip;le(gossip,npc,8);le(gossip,1,4);le(gossip,0,4);le(gossip,0,4);
// Live 2026-11-22: the client sent REMAINING_WITHDRAW_MONEY_QUERY (empty) with no banker open; it ended the session.
if(!world.bank_idle_query(0x2f001a,{}) || world.bank_idle_query(0x2f001a,Bytes{1}) || world.bank_idle_query(0x3f0059,{}))return 40;
if(world.translate({0x17d,gossip},0x46010046,0,nullptr)!=Bytes(4) || !world.bank_current() || world.requests.size()!=3)return 1;
if(world.bank_idle_query(0x2f001a,{}))return 41; // With the bank open it is a genuine query.
if(world.requests[0].opcode!=0x13d || world.requests[1].opcode!=0x89 || world.requests[2].opcode!=0x95)return 2;
// Pinned GuildBank::HandleAddonMessages matches "GetBankInfo:" including
// the final colon. A bare command is silently ignored on an unlocked bank.
{Reader q(world.requests[2].body);
if(q.le(4)!=3 || q.le(4)!=0xffffffffu || q.cstring(256)!="TW_GUILDBANK\tGetBankInfo:")return 27;
q.end();}
Bytes roster;le(roster,1,4);cstring(roster,"");cstring(roster,"");le(roster,1,4);le(roster,0x000ff1ff,4);
le(roster,4520,8);le(roster,1,1);cstring(roster,"Fixture");le(roster,0,4);le(roster,60,1);le(roster,1,1);le(roster,33,4);cstring(roster,"");cstring(roster,"");
if(turtle_guild_rank_rights(roster)!=std::vector<uint32_t>{0x000ff1ff})return 3;
for(size_t n=0;n<roster.size();++n){try{turtle_guild_rank_rights(std::span(roster).first(n));return 4;}catch(const Error&){}}
world.translate({0x8a,roster},0x46010046,0,nullptr);
world.translate({0x96,addon(4520,"BankInfo:money:123456")},0x46010046,0,nullptr);
world.translate({0x96,addon(4520,"BankInfo:Tabs:1:One:Two:Three:Four:Five:i1:i2:i3:i4:i5:0:0:0:0:0:0:0:0:0:0")},0x46010046,0,nullptr);
if(world.requests.size()!=5 || world.requests[3].opcode!=0x87 || !world.requests[3].body.empty() ||
world.requests[4].opcode!=0x95 || !world.guild_bank.tab_pending(1))return 5;
world.translate({0x96,addon(4520,"TabWithdrawalsLeft:1:Unlimited")},0x46010046,0,nullptr);
world.translate({0x96,addon(4520,"TabItems:1:1:1:200:11684:1:0:0:1900")},0x46010046,0,nullptr);
if(world.bank_window->opened || world.guild_bank.tabs[0].loaded)return 6;
auto opened=world.translate({0x96,addon(4520,"TabItems:1:end")},0x46010046,0,nullptr);
Reader r(opened);auto count=r.le(4);bool interaction=false,contents=false,permissions=false;
for(unsigned i=0;i<count;++i){auto op=r.le(4);auto body=r.take(r.le(4));
if(op==0x47031b){Reader p(body);auto guid=unpack_guid(p,16);if(guid!=Bytes(modern.begin(),modern.end()) || p.le(4)!=10 || p.le(1)!=0x80)return 7;p.end();interaction=true;}
if(op==0x530028){if(!interaction)return 28;Reader p(body);if(p.le(4)!=0)return 29;p.take(16);if(p.le(4)!=3 || p.le(4)!=0xffffffffu)return 30;p.end();permissions=true;}
if(op==0x530025){if(!permissions)return 31;Reader p(body);if(p.le(8)!=123456 || p.le(4)!=0 || p.le(4)!=0xffffffffu || p.le(4)!=1 || p.le(4)!=1)return 8;
if(p.le(4)!=0 || p.le(1)!=6 || p.le(1)!=2)return 9; // name3/icon2 => big-endian7/9 lengths.
p.take(5);if(p.le(4)!=0 || p.le(4)!=11684 || p.le(1)!=0 || p.le(1)!=0 || p.le(4)!=1 || p.le(4)!=1900)return 10;
for(unsigned j=0;j<3;++j)if(p.le(4))return 11;
if(p.le(1)!=0 || p.le(1)!=0x80)return 12;
p.end();contents=true;
}
}
r.end();if(!interaction || !permissions || !contents || !world.bank_window->opened)return 13;
auto request=pack_guid(modern);le(request,0,1);le(request,0x80,1);
if(world.bank_duplicate_query(0x3f0059,request))return 14;
auto outbound=world.gameplay(0x3f0059,request);Reader q(outbound.body);
if(outbound.opcode!=0x95 || q.le(4)!=3 || q.le(4)!=0xffffffffu || q.cstring(256)!="TW_GUILDBANK\tGetTabItems:1")return 15;
q.end();
world.gameplay_sent(0x3f0059,request);if(!world.bank_duplicate_query(0x3f0059,request))return 16;
auto money=pack_guid(modern);le(money,100,8);auto deposit=world.gameplay(0x3f005c,money);Reader d(deposit.body);
if(d.le(4)!=3 || d.le(4)!=0xffffffffu || d.cstring(256)!="TW_GUILDBANK\tDepositMoney:100")return 17;
d.end();
auto malformed=money;malformed.push_back(0);try{world.gameplay(0x3f005c,malformed);return 18;}catch(const Error&){}
{
namespace F=turtle_entity_fields;
constexpr uint64_t source_item=0x4000000000000064ULL,container=0x4000000000000065ULL,child=0x4000000000000066ULL;
world.inventory.player_fields[F::PLAYER_FIELD_PACK_SLOT_1]=uint32_t(source_item);
world.inventory.player_fields[F::PLAYER_FIELD_PACK_SLOT_1+1]=uint32_t(source_item>>32);
LegacyObjectUpdate record;record.guid=source_item;record.type=1;record.fields[F::ITEM_FIELD_STACK_COUNT]=20;
world.inventory.items[source_item]=record;
auto transfer=[&](uint8_t bank_slot,uint8_t player_slot,std::optional<uint8_t> bag){
auto b=pack_guid(modern);le(b,0,1);le(b,bank_slot,1);le(b,player_slot,1);le(b,bag?0x80:0,1);if(bag)le(b,*bag,1);return b;
};
auto check=[&](uint32_t op,const Bytes& b,const std::string& expected){
auto result=world.gameplay(op,b);Reader p(result.body);
if(result.opcode!=0x95 || p.le(4)!=3 || p.le(4)!=0xffffffffu || p.cstring(256)!="TW_GUILDBANK\t"+expected)return false;
p.end();return true;
};
if(!check(0x3f004d,transfer(255,35,{}),"DepositItem:0:1:1:0:20"))return 21;
if(!check(0x3f004e,transfer(0,255,{}),"WithdrawItem:1:1:0:0:1"))return 22;
if(!check(0x3f004e,transfer(0,35,{}),"WithdrawItem:1:1:0:1:1"))return 23;
world.inventory.player_fields[F::PLAYER_FIELD_INV_SLOT_HEAD+2*19]=uint32_t(container);
world.inventory.player_fields[F::PLAYER_FIELD_INV_SLOT_HEAD+2*19+1]=uint32_t(container>>32);
LegacyObjectUpdate bag;bag.guid=container;bag.type=2;bag.fields[F::CONTAINER_FIELD_NUM_SLOTS]=36;
world.inventory.items[container]=bag;
LegacyObjectUpdate inside;inside.guid=child;inside.type=1;inside.fields[F::ITEM_FIELD_STACK_COUNT]=5;
inside.fields[F::ITEM_FIELD_CONTAINED]=uint32_t(container);inside.fields[F::ITEM_FIELD_CONTAINED+1]=uint32_t(container>>32);
world.inventory.items[child]=inside;
for(uint8_t i=0;i<36;++i){
auto& fields=world.inventory.items.at(container).fields;
if(i){fields.erase(F::CONTAINER_FIELD_SLOT_1+2*(i-1));fields.erase(F::CONTAINER_FIELD_SLOT_1+2*(i-1)+1);}
fields[F::CONTAINER_FIELD_SLOT_1+2*i]=uint32_t(child);fields[F::CONTAINER_FIELD_SLOT_1+2*i+1]=uint32_t(child>>32);
if(!check(0x3f004d,transfer(255,i,30),"DepositItem:1:"+std::to_string(i+1)+":1:0:5"))return 24;
}
world.inventory.items.at(source_item).fields[F::ITEM_FIELD_STACK_COUNT]=256;
try{world.gameplay(0x3f004d,transfer(255,35,{}));return 25;}catch(const Error&){}
try{world.gameplay(0x3f004d,transfer(255,36,30));return 26;}catch(const Error&){}
// #90: right-click withdraw and moves/splits inside one tab.
for(uint32_t n=0;n<98;++n)if(native_guild_bank_slot(turtle_guild_bank_slot(n))!=n)return 49;
// Turtle row 0 col 1 (slot 2) is native Button8 (index 7); Turtle slot 15 (row 1 col 0) is native index 1.
if(native_guild_bank_slot(2)!=7 || native_guild_bank_slot(15)!=1 || native_guild_bank_slot(98)!=97)return 50;
auto two=[&](uint8_t t,uint8_t s,uint8_t t1,uint8_t s1,std::optional<uint32_t> n){
auto b=pack_guid(modern);le(b,t,1);le(b,s,1);le(b,t1,1);le(b,s1,1);if(n)le(b,*n,4);return b;
};
{auto b=pack_guid(modern);le(b,0,1);le(b,0,1);if(!check(0x3f0056,b,"WithdrawItem:1:1:0:0:1"))return 40;}
{auto b=pack_guid(modern);le(b,0,1);le(b,7,1);try{world.gameplay(0x3f0056,b);return 41;}catch(const Error&){}} // empty slot
if(!check(0x3f0051,two(0,0,0,5,{}),"MoveItem:1:1:71"))return 42;
if(!check(0x3f0050,two(0,0,0,5,{}),"MoveItem:1:1:71"))return 43;
if(!check(0x3f0058,two(0,0,0,5,1),"SplitItem:1:1:71:1"))return 44;
if(!check(0x3f0057,two(0,0,0,5,1),"SplitItem:1:1:71:1"))return 45;
try{world.gameplay(0x3f0051,two(0,0,1,5,{}));return 46;}catch(const Error&){} // cross-tab: no Turtle form
try{world.gameplay(0x3f0058,two(0,0,0,0,1));return 47;}catch(const Error&){} // same slot
try{world.gameplay(0x3f0058,two(0,0,0,5,0));return 48;}catch(const Error&){} // zero count
// #91: buy the next tab (one unlocked -> native index 1 = Turtle tab 2), rename a tab.
{auto b=pack_guid(modern);le(b,1,1);if(!check(0x3f005a,b,"UnlockTab:2:1"))return 51;}
{auto b=pack_guid(modern);le(b,3,1);try{world.gameplay(0x3f005a,b);return 52;}catch(const Error&){}} // skips a tab
auto upd=[&](uint8_t t,std::string n,std::string i){auto b=pack_guid(modern);le(b,t,1);auto bits=uint32_t(n.size())<<9|uint32_t(i.size());
le(b,bits>>8,1);le(b,bits&0xff,1);b.insert(b.end(),n.begin(),n.end());b.insert(b.end(),i.begin(),i.end());return b;};
if(!check(0x3f005b,upd(0,"Mats","133784"),"UpdateTab:1:Mats:133784:0:0"))return 53;
try{world.gameplay(0x3f005b,upd(0,"a:b","1"));return 54;}catch(const Error&){} // separator
try{world.gameplay(0x3f005b,upd(1,"Two","1"));return 55;}catch(const Error&){} // locked tab
}
// Client CMSG_CLOSE_INTERACTION 0x3F002A (WPP) ends the native vault state.
(void)world.close_interaction(pack_guid(modern));if(world.bank_window || world.guild_bank.metadata_ready)return 19;
try{world.gameplay(0x3f005c,money);return 20;}catch(const Error&){}
// #91: a guild without a bank (BankInfo:NoGuildBank) opens the native window with zero tabs, and buying native
// tab 0 is Turtle UnlockGuildBank:Ok; the server's following BankInfo then loads tab 1 into the open window.
{
if(world.translate({0x17d,gossip},0x46010046,0,nullptr)!=Bytes(4) || !world.bank_current())return 60;
world.translate({0x8a,roster},0x46010046,0,nullptr);
auto empty=world.translate({0x96,addon(4520,"BankInfo:NoGuildBank")},0x46010046,0,nullptr);
Reader e(empty);auto n=e.le(4);bool open=false,perm=false,list=false;
for(unsigned i=0;i<n;++i){auto op=e.le(4);auto body=e.take(e.le(4));
if(op==0x47031b)open=true;
if(op==0x530028){Reader p(body);p.take(12);if(p.le(4)!=0 || p.le(4)!=0)return 61;p.end();perm=open;}
if(op==0x530025){Reader p(body);if(p.le(8)!=0 || p.le(4)!=0 || p.le(4)!=0 || p.le(4)!=0 || p.le(4)!=0 || p.le(1)!=0x80)return 62;p.end();list=perm;}
}
e.end();if(!open || !perm || !list || !world.bank_window->opened)return 63;
auto buy=pack_guid(modern);le(buy,0,1);auto unlock=world.gameplay(0x3f005a,buy);Reader u(unlock.body);
if(unlock.opcode!=0x95 || u.le(4)!=3 || u.le(4)!=0xffffffffu || u.cstring(256)!="TW_GUILDBANK\tUnlockGuildBank:Ok")return 64;
{auto b=pack_guid(modern);le(b,1,1);try{world.gameplay(0x3f005a,b);return 65;}catch(const Error&){}} // no bank: only tab 0
auto before=world.requests.size();
world.translate({0x96,addon(4520,"BankInfo:money:0")},0x46010046,0,nullptr);
world.translate({0x96,addon(4520,"BankInfo:Tabs:1:One:Two:Three:Four:Five:i1:i2:i3:i4:i5:0:0:0:0:0:0:0:0:0:0")},0x46010046,0,nullptr);
if(world.requests.size()!=before+1 || !world.guild_bank.tab_pending(1))return 66;
}
return EXIT_SUCCESS;
}