Files
AVA2/tests/python_test.cpp
T
shenleiandClaude Opus 5.5 11bd94d1ce Mobile HUD layout: disc widgets, quickslot wheel and belt (mobile step 4)
Native CDisc window for procedural round frames; ui_mobile_widgets
(RoundButton, QuickSlotDisc); HUD laid out as the phone plan: player
panel, top-right entry row with minimap, left button column, attack disc
with two quickslot rings, potion belt on quickslot page 4, exp bar. The
PC taskbar and its tooltips are hidden in mobile mode. Adds global
quickslot use/add/move for the belt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 21:14:29 +09:00

1403 lines
114 KiB
C++

#include "item_proto.h"
#include <cmath>
#include <algorithm>
#include <filesystem>
#include "skill_description.h"
#include "python_runtime.h"
#include "nonplayer_data.h"
#include "python_wiki.h"
#include "python_app.h"
#include "pet_skill_state.h"
#include "python_gameplay_modules.h"
#include "python_native_modules.h"
#include "python_net.h"
#include "python_chat.h"
#include "eter_net/PythonNetworkStream.h"
#include "eter_net/NetworkActorManager.h"
#include "eter_net/PythonSafeBox.h"
#include "eter_render/ActorInstance.h"
#include "eter_resource/ResourceManager.h"
#include "eter_render/RaceData.h"
#include <iostream>
#include <cassert>
#include <cctype>
#include <cstring>
#include "test_rundir.h"
int main(int argc,char** argv) {
if(argc!=3) return 2;
if(!ava2_test::EnterTestRunDir()) return ava2_test::kSkip;
try {
ava2::SkillDescriptions fixture;
if(!fixture.load("900\tWARRIOR\tBase\t\t\tDescription\tFirst\t\tThird\tIgnored fourth\tTOGGLE|STANDING_SKILL|USE_HP\t\ticon\r\n")) throw std::runtime_error("fixture load failed");
auto* desc=fixture.find(900);
if(!desc || desc->type!=1 || desc->gradeNames[2]!="Base" || desc->conditions.size()!=2 || desc->attributes!=((1u<<1)|(1u<<4)|(1u<<6))) throw std::runtime_error("skill field mismatch");
if(!fixture.load("900\tsupport\tUpdated\tMaster\t\tNew description\t\t\t\t\tPASSIVE|toggle\t\ticon\n")) throw std::runtime_error("duplicate load failed");
desc=fixture.find(900);
if(desc->type!=2 || desc->name!="Updated" || !desc->conditions.empty() || desc->attributes!=((1u<<1)|(1u<<4)|(1u<<6)|(1u<<17))) throw std::runtime_error("duplicate semantics mismatch");
if(!fixture.load("901\twolfman\tExcluded\t\t\t\t\t\t\t\tTOGGLE\t\ticon\n")) throw std::runtime_error("disabled type load failed");
if(!fixture.find(901) || !fixture.find(901)->name.empty() || fixture.find(901)->attributes) throw std::runtime_error("disabled wolfman type accepted");
std::vector<std::string> columns(28);
columns[0]="902";columns[1]="WARRIOR";columns[2]="Motion";columns[11]="SWORD|TWO_HANDED|ARROW|EMPTY_HAND";
columns[13]="65530";columns[14]="4";columns[15]="k+1";columns[16]="2";
columns[17]="Damage";columns[18]="minatk";columns[19]="maxatk";columns[26]="300";
std::string row;for(size_t i=0;i<columns.size();++i){if(i)row+='\t';row+=columns[i];}row+='\t';
if(!fixture.load(row))throw std::runtime_error("motion fixture failed");
auto* motion=fixture.find(902);
if(motion->needWeapon!=(1u|8u|(1u<<11)) || motion->gradeMotions[1]!=19 || motion->gradeMotions[3]!=69 || motion->levelLimit!=44 || motion->maxLevel!=44 || motion->affects.size()!=1 || motion->affects[0].maxFormula!="maxatk")throw std::runtime_error("motion/limits/weapons mismatch");
if(!fixture.load(row) || fixture.find(902)->affects.size()!=2)throw std::runtime_error("original affect append semantics lost");
std::vector<std::string> table(27);table[0]="902";table[4]="300";table[5]="0";table[7]="atk+mwep+number(1,2)";table[8]="40+100*k";table[9]="60";table[10]="2";table[11]="12";table[25]="-1";table[26]="0";
std::string tableRow;for(size_t i=0;i<table.size();++i){if(i)tableRow+='\t';tableRow+=table[i];}
if(!fixture.loadTable(tableRow))throw std::runtime_error("skill table rejected");
auto* merged=fixture.find(902);
if(merged->maxLevel!=44 || merged->levelLimit!=0 || merged->needSPFormula!="40+100*k" || merged->cooldownFormula!="12" || merged->targetRange!=uint32_t(-1) || merged->affects[0].minFormula!="minatk+minmwep+min(1,2)" || merged->affects[0].maxFormula!="maxatk+maxmwep+max(1,2)")throw std::runtime_error("skill table merge mismatch");
fixture.records[34]=*merged;
tableRow.replace(0,3,"34");
auto oldFormula=fixture.find(34)->affects[0].minFormula;
if(!fixture.loadTable(tableRow) || fixture.find(34)->affects[0].minFormula!=oldFormula)throw std::runtime_error("excluded formula overwritten");
fixture.records[1]=*merged;
table[0]="1";tableRow.clear();for(size_t i=0;i<table.size();++i){if(i)tableRow+='\t';tableRow+=table[i];}
if(!fixture.loadTable(tableRow) || fixture.find(1)->affects[0].minFormula!="minatk+minmwep+min(1,2)* 3")throw std::runtime_error("three-way multiplier lost");
auto before=fixture.find(1)->affects[0].minFormula;
table[7]="k+1";table[8].clear();table[9].clear();table[5]="99";
tableRow.clear();for(size_t i=0;i<table.size();++i){if(i)tableRow+='\t';tableRow+=table[i];}
if(!fixture.loadTable(tableRow,true) || fixture.find(1)->affects[0].minFormula!=before || fixture.find(1)->needSPFormula!="40+100*k" || !fixture.find(1)->durationFormula.empty() || fixture.find(1)->levelLimit!=0)throw std::runtime_error("locale/empty field semantics mismatch");
if(!fixture.loadTable(tableRow) || fixture.find(1)->affects[0].minFormula!="k+1" || !fixture.find(1)->affects[0].maxFormula.empty())throw std::runtime_error("scalar formula overwrite mismatch");
ava2::PythonRuntime python(argv[1],argv[2]);
ava2::ItemProto items;
ava2::ItemProto rangeFixture;
rangeFixture.records[2000].vnum=2000;rangeFixture.records[2000].range=10;
rangeFixture.records[1998].vnum=1998;rangeFixture.records[1998].range=20;
rangeFixture.ranges={2000,1998};
if(rangeFixture.find(2001)->vnum!=2000 || rangeFixture.find(1998)->vnum!=1998 || rangeFixture.find(2010)->vnum!=1998 || rangeFixture.find(2018))throw std::runtime_error("item range ordering/bounds mismatch");
if(!items.load(ava2::ReadPackedText("locale/en/item_proto")))throw std::runtime_error("original item proto rejected");
auto sword=items.records.find(10);
if(sword==items.records.end()||sword->second.name!="Sword+0"||sword->second.type!=1||sword->second.size!=2)throw std::runtime_error("original item proto fields mismatch");
python.execute("import item, app\n");
// app.LoadLocaleData: original order item_list -> item_proto -> ... -> mob_scale -> item_scale.
python.execute("import net\nassert app.LoadLocaleData('locale/en')==1\nassert net.IsInsultIn('you SHIT')==1 and net.IsInsultIn('hello')==0\nassert net.IsChatInsultIn('shit')==1\nnet.EnableChatInsultFilter(1)\nassert net.IsChatInsultIn('shit')==0\nnet.EnableChatInsultFilter(0)\n");
{
auto& pets=ava2::GetPetSkillState().records;
if(pets.size()!=18||pets.at(17).delay!=600||pets.at(17).icon!="d:/ymir work/ui/skill/pet/invincibility.sub"||pets.at(1).type!=ava2::SKILLPET_TYPE_PASSIVE)throw std::runtime_error("LoadLocaleData pet_skill mismatch");
auto* scale=ava2::NonPlayerData::Instance().getMobScale(8061);
if(!scale||std::fabs(scale->x-1.3f)>1e-6f)throw std::runtime_error("LoadLocaleData mob_scale mismatch");
ava2::ItemScaleInfo sash; // 85001 JOB_ASSASSIN M 69 68 88 0 0 0.52 -> tInfo[2] for vnum 85001..85005
if(!ava2::GetItemScale(85005,2,&sash)||std::fabs(sash.scaleX-0.69f)>1e-6f||std::fabs(sash.positionZ-52.0f)>1e-4f)throw std::runtime_error("LoadLocaleData item_scale mismatch");
char chat[]="Bob : you shit head";auto& stream=ava2::PythonNetworkStream::Instance();
stream.FilterInsult(chat+6,std::strlen(chat+6));
if(std::string(chat)!="Bob : you **** head")throw std::runtime_error(std::string("insult filter mismatch: ")+chat);
if(ava2::LoadLocaleData("locale/missing")||!ava2::GetPetSkillState().records.empty())throw std::runtime_error("missing locale must fail after Destroy()");
if(!ava2::LoadLocaleData("locale/en"))throw std::runtime_error("locale reload failed");
}
{
// CPythonWiki::ReadData (ENABLE_WIKI): locale/common text tables fed from memory, item_proto/mob_proto from locale/en.
using ava2::WikiTextFile;
if(!ava2::WikiLoadText(WikiTextFile::RefineTable,"refine_table.txt","#id\tv0\n7\t27001\t2\t0\t0\t27002\t1\t0\t0\t0\t0\t1500\t0\t0\t90\r\n8\t1\t2\n")||
!ava2::WikiLoadText(WikiTextFile::SpecialItemGroup,"special_item_group.txt","Group\tA\n{\n\tVnum\t77900\n\t1\t55101\t1\t30\n\t2\t55108\t1\t30\n}\nGroup\tB\n{\n\tVnum\t77900\n\t1\t1\t1\t1\n}\n")||
!ava2::WikiLoadText(WikiTextFile::MobDropItem,"mob_drop_item.txt","Group\tBOSS\n{\n\tMob\t191\n\tType\tdrop\n\t1\t30037\t1\t100\n\t2\t76023\t10\t100\n}\n"))
throw std::runtime_error("wiki text tables failed to load");
python.execute("import wiki\n"
"assert wiki.GetRefineItems(7)==(7,27001,2,0,0,27002,1,0,0,0,0,1500,90,3)\nassert wiki.GetRefineItems(8)==0\n"
"assert wiki.GetSpecialInfoSize(77900)==2 and wiki.GetSpecialInfoData(77900,1)==(55108,1)\n"
"assert wiki.GetMobInfoSize(191)==2 and wiki.GetMobInfoData(191,1)==(76023,10) and wiki.GetMobInfoData(192,0)==(0,0)\n"
"assert wiki.GetItemDropFromMonster(30037,False)==[191] and wiki.GetItemDropFromMonster(30046,True)==[191] and wiki.GetItemDropFromMonster(30047,True)==[]\n"
"assert wiki.GetItemDropFromChest(55108,0)==[77900]\n"
"assert wiki.IsBlackList(529,0,0)==1 and wiki.IsBlackList(10,0,529)==0\n"
"assert wiki.GetBossSize(3)==2 and wiki.GetBossData(3,1)==2493\n"
"assert wiki.GetCostumeSize(0)==53 and wiki.GetCostumeData(4,0)==65000 and wiki.GetCostumeSize(9)==0\n"
"assert wiki.GetRefineMaxLevel(10)==9\n"
"assert wiki.GetCategorySize(0,0)>0 and wiki.GetCategorySize(4,0)==0\n"
"item.SelectItem(wiki.GetCategoryData(0,0,0))\nassert item.GetItemType()==1 and '+9' in item.GetItemName()\n"
"assert wiki.GetStoneSize(0)>0 and 8001<=wiki.GetStoneData(0,0)<=8056\n");
}
python.execute("import shop\nassert shop.IsOpen()==0\nassert shop.GetTabCount()==1\nshop.Open()\nassert shop.IsOpen()==1\nshop.Close()\nassert shop.IsOpen()==0\nshop.Open()\nshop.Clear()\nassert shop.IsOpen()==0\nassert shop.GetTabCount()==1\n");
if(!ava2::SetShopTabCount(3)||ava2::SetShopTabCount(4))throw std::runtime_error("shop tab capacity validation failed");
ava2::SetShopTab(0,"Weapons",0);ava2::SetShopTab(2,"Special",257);
python.execute("assert shop.GetTabCount()==3\nassert shop.GetTabName(2)=='Special'\nassert shop.GetTabCoinType(258)==1\nassert shop.GetTabName(3) is None\nassert shop.GetTabCoinType(-1)==255\nshop.Clear()\nassert shop.GetTabCount()==1\nassert shop.GetTabName(0)=='Weapons'\nassert shop.GetTabName(2) is None\n");
ava2::ResetShopState();
ava2::ShopItemRecord shopItem{};shopItem.vnum=0x80000001;shopItem.count=0xffffffff;shopItem.price=-1234567890123LL;shopItem.buyVnum=10;shopItem.buyCount=3;
ava2::SetShopItem(119,shopItem);
shopItem.sockets[7]=-123;shopItem.attributes[14]={255,-32768};shopItem.gloveAttributes[6]={254,-2};ava2::SetShopItem(119,shopItem);
python.execute("assert shop.GetItemMetinSocket(119,7)==-123\nassert shop.GetItemAttribute(119,14)==(255,-32768)\nassert shop.GetItemRandomAttribute(119,6)==(254,-2)\nassert shop.GetItemAttribute(119,15)==(0,0)\nassert shop.GetItemRandomAttribute(120,0)==(0,0)\nassert shop.GetItemMetinSocket(119,8)==0\n");
python.execute("assert shop.GetItemID(119)==-2147483647\nassert shop.GetItemCount(119)==-1\nassert shop.GetItemPrice(119)==-1234567890123\nassert shop.GetVnumBuy(119)==10\nassert shop.GetCountBuy(119)==3\nassert shop.GetItemID(120)==0\nshop.Clear()\nassert shop.GetItemID(119)==0\n");
std::map<std::pair<unsigned,unsigned>,uint32_t> classifications;
for(const auto& [id,record]:items.records)classifications[{record.type,record.subtype}]=id;
for(const auto& [kind,id]:classifications) {
const auto type=kind.first,subtype=kind.second;
const auto arg=std::to_string(id);
const std::map<unsigned,std::string> useNames={{2,"USE_TUNING"},{14,"USE_DETACHMENT"},{17,"USE_CLEAN_SOCKET"},{18,"USE_CHANGE_ATTRIBUTE"},{19,"USE_ADD_ATTRIBUTE"},{20,"USE_ADD_ACCESSORY_SOCKET"},{21,"USE_PUT_INTO_ACCESSORY_SOCKET"},{22,"USE_ADD_ATTRIBUTE2"},{24,"USE_CHANGE_ATTRIBUTE2"},{29,"USE_PUT_INTO_BELT_SOCKET"},{30,"USE_PUT_INTO_RING_SOCKET"},{31,"USE_CHANGE_COSTUME_ATTR"},{32,"USE_RESET_COSTUME_ATTR"}};
const auto use=type!=3?"NOT_USE_TYPE":useNames.contains(subtype)?useNames.at(subtype):"USE_UNKNOWN_TYPE";
python.execute("assert item.GetUseType("+arg+")== '"+use+"'\n");
python.execute("assert item.IsEquipmentVID("+arg+")=="+std::to_string(type==1||type==2)+"\n"
"assert item.GetRefinedVnum()=="+std::to_string(items.records.at(id).refined)+"\n");
python.execute("assert item.IsRefineScroll("+arg+")=="+std::to_string(type==3&&subtype==2)+"\n"
"assert item.IsDetachScroll("+arg+")=="+std::to_string(type==3&&subtype==14)+"\n"
"assert item.IsKey("+arg+")=="+std::to_string(type==21)+"\n"
"assert item.IsMetin("+arg+")=="+std::to_string(type==10)+"\n"
"assert item.CanAddToQuickSlotItem("+arg+")=="+std::to_string(type==3||type==18)+"\n"
"assert item.GetRefinedVnum()=="+std::to_string(items.records.at(id).refined)+"\n");
}
python.execute("assert item.GetUseType(10)=='NOT_USE_TYPE'\nassert item.GetUseType(27001)=='USE_UNKNOWN_TYPE'\nassert item.GetUseType(25040)=='USE_TUNING'\nassert item.IsRefineScroll(25040)==1\nassert item.GetItemName()==item.GetNames()\nitem.SelectItem(10)\n");
python.execute("import player\n");
ava2::TItemData metadata{};metadata.vnum=10;metadata.flags=0x800000aa;metadata.anti_flags=0x800000bb;
ava2::SetPlayerItemData(1,12,metadata);
python.execute("assert player.IsSameItemVnum(10,12)==1\nassert player.IsSameItemVnum(19,12)==0\nassert player.IsSameItemVnum(10,257,65548)==1\nassert player.IsSameItemVnum(0,3,12)==1\n");
ava2::TItemData renamed{};renamed.vnum=10;std::strcpy(renamed.name,"Custom Sword");
ava2::SetPlayerItemData(6,14,renamed);
python.execute("assert player.GetItemNewName(6,14)=='Custom Sword'\nassert player.GetItemNewName(262)=='^'\nassert player.GetItemNewName()=='^'\nassert player.GetItemNewName(262,65550)=='Custom Sword'\n");
python.execute("import player\n");
ava2::TItemData counted{};counted.vnum=0x80001234u;counted.count=0xffffffffu;
ava2::SetPlayerItemData(1,250,counted);
counted.count=3;ava2::SetPlayerItemData(1,251,counted);
counted.count=99;ava2::SetPlayerItemData(1,262,counted);
counted.count=7;ava2::SetPlayerItemData(6,170,counted);
counted.count=99;ava2::SetPlayerItemData(6,180,counted);
counted.count=42;ava2::SetPlayerItemData(7,170,counted);
python.execute("assert player.GetItemCountByVnum(-2147478988)==2\nassert player.GetItemCountByTT(-2147478988)==7\n");
python.execute("for cell in range(-1,300):\n assert player.IsEquipmentSlot(cell)==int(180<=cell<=228)\n assert player.IsCostumeSlot(cell)==int(199<=cell<=203)\n assert player.IsBeltInventorySlot(cell)==int(246<=cell<262)\n assert player.IsDSEquipmentSlot(1,cell)==int(216<=cell<=228)\n assert player.IsDSEquipmentSlot(2,cell)==0\nassert player.IsDSEquipmentSlot(257,228)==1\nassert player.IsBeltInventorySlot(65782)==1\nassert player.IsEquipmentSlot(65716)==0\n");
for(const auto& [id,record]:items.records) {
if((record.flags&8u) && !record.sellPrice)continue;
ava2::TItemData priced{};priced.vnum=id;priced.count=0xffffffffu;
ava2::SetPlayerItemData(6,15,priced);
const uint32_t expected=(record.flags&8u)?priced.count/record.sellPrice:priced.count*record.sellPrice;
python.execute("assert player.GetISellItemPrice(6,15)=="+std::to_string(std::bit_cast<int32_t>(expected))+"\n");
}
python.execute("assert player.GetISellItemPrice(3,12)==0\nassert player.GetISellItemPrice(262)==0\n");
uint32_t cheap=0,expensive=0;
for(const auto& [id,record]:items.records) {
if(record.sellPrice<=5000)cheap=id;
if(record.sellPrice>5000)expensive=id;
}
if(!cheap||!expensive)throw std::runtime_error("valuable item price fixtures missing");
ava2::TItemData valued{};valued.vnum=cheap;valued.count=0xffffffffu;
ava2::SetPlayerItemData(6,16,valued);
python.execute("assert player.IsValuableItem(6,16)==0\nassert item.GetRefinedVnum()=="+std::to_string(items.records.at(cheap).refined)+"\n");
for(size_t socket=0;socket<8;++socket) {
std::fill(std::begin(valued.alSockets),std::end(valued.alSockets),0);valued.alSockets[socket]=-1;
ava2::SetPlayerItemData(6,16,valued);
python.execute("assert player.IsValuableItem(6,16)=="+std::to_string(socket<6)+"\n");
}
std::fill(std::begin(valued.alSockets),std::end(valued.alSockets),0);valued.vnum=expensive;valued.count=1;
ava2::SetPlayerItemData(1,16,valued);
python.execute("assert player.IsValuableItem(16)==1\nassert player.IsValuableItem(1,16)==1\nitem.SelectItem(10)\n");
ava2::SetPlayerItemData(3,12,metadata);
ava2::SetPlayerItemData(1,262,metadata);
python.execute("import player\nassert player.GetItemFlags(12)==-2147483478\nassert player.GetItemFlags(1,12)==-2147483478\nassert player.GetItemFlags(6,12)==0\nassert player.IsAntiFlagBySlot(12,0x20)==1\nassert player.IsAntiFlagBySlot(1,12,0x40)==0\nassert player.IsAntiFlagBySlot(12,-1)==1\nassert player.GetItemTypeBySlot(12)==1\nassert player.GetItemSubTypeBySlot(1,12)==0\nassert player.GetItemTypeBySlot(6,12)==0\nassert player.GetItemFlags(257,65548)==-2147483478\n");
python.execute("assert player.GetItemFlags(3,12)==0\nassert player.GetItemFlags(262)==0\nassert player.GetItemTypeBySlot(262)==0\n");
const std::map<unsigned,unsigned> capacities={{1,262},{2,228},{5,1152},{6,180},{7,180},{8,180},{9,180},{10,180},{11,6},{12,102}};
for(const auto& [window,capacity]:capacities) {
ava2::TItemData edge{};edge.vnum=0x80000001u;edge.count=0xffffffffu;
edge.alSockets[7]=-123;edge.aAttr[14].bType=255;edge.aAttr[14].sValue=-32768;
ava2::SetPlayerItemData(window,capacity-1,edge);
ava2::SetPlayerItemData(window,capacity,edge);
const auto w=std::to_string(window),last=std::to_string(capacity-1),end=std::to_string(capacity);
python.execute("assert player.GetItemIndex("+w+","+last+")==-2147483647\n"
"assert player.GetItemCount("+w+","+last+")==-1\n"
"assert player.GetItemIndex("+w+","+end+")==0\n"
"assert player.GetItemCount("+w+","+end+")==0\n"
"assert player.GetItemMetinSocket("+w+","+last+",7)==-123\n"
"assert player.GetItemAttribute("+w+","+last+",14)==(255,-32768)\n"
"assert player.GetItemMetinSocket("+w+","+end+",7)==0\n"
"assert player.GetItemAttribute("+w+","+end+",14)==(0,0)\n"
"assert player.GetItemMetinSocket("+w+","+last+",8)==0\n"
"assert player.GetItemAttribute("+w+","+last+",15)==(0,0)\n");
}
python.execute("assert player.GetItemIndex(3,12)==0\nassert player.GetItemCount(3,12)==0\nassert player.GetItemIndex(257,65548)==10\n");
python.execute("assert player.GetItemMetinSocket(257,65797,7)==-123\nassert player.GetItemAttribute(257,65797,14)==(255,-32768)\nassert player.GetItemMetinSocket(261,-1)==0\nassert player.GetItemAttribute(261,-1)==(0,0)\nassert player.GetItemMetinSocket(261,7)==-123\nassert player.GetItemAttribute(261,14)==(255,-32768)\n");
uint32_t tuning=0,rod=0;
for(const auto& [id,record]:items.records) {
if(record.type==3&&record.subtype==2)tuning=id;
if(record.type==13)rod=id;
}
if(!tuning||!rod)throw std::runtime_error("refine fixture prototypes missing");
python.execute("item.SelectItem(10)\nfor args in [(),(12,),(1,12),(1,12,0),('bad',),(None,12)]:\n assert player.IsRefineGradeScroll(*args) is None\n assert item.GetItemName()=='Sword+0'\n");
uint32_t unlockKey=0,unlockBox=0;
for(const auto& [id,record]:items.records) {
if(record.type==21)unlockKey=id;
if(record.type==20)unlockBox=id;
}
if(!unlockKey||!unlockBox)throw std::runtime_error("unlock fixture prototypes missing");
ava2::TItemData locked{};locked.vnum=unlockBox;ava2::SetPlayerItemData(6,19,locked);
python.execute("assert player.CanUnlock(10,6,19)==0\nassert player.CanUnlock("+std::to_string(unlockKey)+",6,19)==1\n"
"assert item.GetRefinedVnum()=="+std::to_string(items.records.at(unlockBox).refined)+"\n"
"assert player.CanUnlock("+std::to_string(unlockKey)+",12)==0\n");
uint32_t detach=0;
uint32_t sashCleaner=0,sashItem=0;
for(const auto& [id,record]:items.records) {
if(record.type==3&&record.subtype==14&&record.values[0]==7)sashCleaner=id;
if(record.type==28&&record.subtype==3)sashItem=id;
}
if(!sashCleaner||!sashItem)throw std::runtime_error("sash cleaning fixture prototypes missing");
ava2::TItemData sashTarget{};sashTarget.vnum=sashItem;
for(const int32_t absorbed:{-1,0,1,2147483647}) {
sashTarget.alSockets[1]=absorbed;
ava2::SetPlayerItemData(6,20,sashTarget);
python.execute("assert player.CanDetach("+std::to_string(sashCleaner)+",6,20)=="+std::to_string(absorbed>0)+"\n"
"assert item.GetRefinedVnum()=="+std::to_string(items.records.at(sashItem).refined)+"\n");
}
sashTarget.vnum=10;ava2::SetPlayerItemData(6,20,sashTarget);
python.execute("assert player.CanDetach("+std::to_string(sashCleaner)+",6,20)==0\n");
for(const auto& [id,record]:items.records)if(record.type==3&&record.subtype==14&&record.values[0]!=7)detach=id;
if(!detach||(sword->second.flags&1u)==0)throw std::runtime_error("detach fixture prototypes missing");
ava2::TItemData detachable{};detachable.vnum=10;
ava2::SetPlayerItemData(1,18,detachable);
python.execute("assert player.CanDetach(10,18)==0\nassert player.CanDetach("+std::to_string(detach)+",18)==0\n");
for(size_t socket=0;socket<8;++socket) {
std::fill(std::begin(detachable.alSockets),std::end(detachable.alSockets),0);detachable.alSockets[socket]=-1;
ava2::SetPlayerItemData(1,18,detachable);
python.execute("assert player.CanDetach("+std::to_string(detach)+",18)=="+std::to_string(socket<6)+"\n");
}
uint32_t normalStone=0,goldStone=0;
for(const auto& [id,record]:items.records) {
if(record.type!=10||!(record.wearFlags&sword->second.wearFlags))continue;
if(record.subtype==0)normalStone=id;
if(record.subtype==1)goldStone=id;
}
if(!normalStone&&!goldStone)throw std::runtime_error("metin fixture prototypes missing");
// The distributed table may contain only gold stones. Do not invent
// a normal stone by interpreting an unrelated prototype as METIN.
const auto testStone=normalStone?normalStone:goldStone;
ava2::TItemData socketTarget{};socketTarget.vnum=10;
ava2::SetPlayerItemData(6,17,socketTarget);
python.execute("assert player.CanAttachMetin("+std::to_string(testStone)+",6,17)==3\nassert player.CanAttachMetin(0,180)==5\n");
socketTarget.alSockets[7]=1;ava2::SetPlayerItemData(6,17,socketTarget);
python.execute("assert player.CanAttachMetin("+std::to_string(testStone)+",6,17)=="+std::to_string(normalStone?1:4)+"\n");
socketTarget.alSockets[7]=2;ava2::SetPlayerItemData(6,17,socketTarget);
python.execute("assert player.CanAttachMetin("+std::to_string(testStone)+",6,17)==1\n");
metadata.vnum=19;ava2::SetPlayerItemData(6,12,metadata);
metadata.vnum=rod;ava2::SetPlayerItemData(6,13,metadata);
python.execute("assert player.GetItemGrade(6,12)==9\nassert item.GetItemName().endswith('+9')\n"
"assert player.GetItemGrade(12)==0\nassert item.GetItemName()=='Sword+0'\n"
"assert player.CanRefine(10,12)==0\n"
"assert player.CanRefine("+std::to_string(tuning)+",12)==1\n"
"assert player.CanRefine("+std::to_string(tuning)+",6,12)==5\n"
"assert player.CanRefine("+std::to_string(tuning)+",6,13)==7\n"
"assert player.CanRefine(10,180)==6\nitem.SelectItem(10)\n");
python.execute("assert item.SelectItemWiki(10) == 1\n"
"assert item.GetRefinedVnum() == "+std::to_string(sword->second.refined)+"\n"
"assert item.GetRefineSet() == "+std::to_string(sword->second.refineSet)+"\n"
"assert item.SelectItemWiki(-1) == 0\n"
"assert item.GetItemName() == 'Sword+0'\n");
python.execute("assert item.GetIBuyItemPrice() == "+std::to_string(sword->second.buyPrice)+"\n"
"assert item.GetISellItemPrice() == "+std::to_string(sword->second.sellPrice)+"\n"
"assert item.IsAntiFlag(-1) == "+std::to_string(sword->second.antiFlags!=0)+"\n"
"assert item.IsFlag(-1) == "+std::to_string(sword->second.flags!=0)+"\n"
"assert item.IsWearableFlag(-1) == "+std::to_string(sword->second.wearFlags!=0)+"\n"
"assert item.Is1GoldItem() == "+std::to_string((sword->second.flags&8)!=0)+"\n"
"assert item.IsFlag(0) == 0\n");
for(int i=0;i<8;++i)python.execute("assert item.GetSocket("+std::to_string(i)+") == "+std::to_string(sword->second.sockets[i])+"\n");
python.execute("assert item.GetSocket(8) == -1\nassert item.GetSocket(-1) == -1\nassert item.GetSocket(256) == item.GetSocket(0)\n");
for(int bit=0;bit<31;++bit) {
uint32_t mask=1u<<bit;
python.execute("assert item.IsAntiFlag("+std::to_string(mask)+") == "+std::to_string((sword->second.antiFlags&mask)!=0)+"\n"
"assert item.IsFlag("+std::to_string(mask)+") == "+std::to_string((sword->second.flags&mask)!=0)+"\n"
"assert item.IsWearableFlag("+std::to_string(mask)+") == "+std::to_string((sword->second.wearFlags&mask)!=0)+"\n");
}
auto finalSword=items.records.find(19);
if(finalSword==items.records.end())throw std::runtime_error("missing final sword fixture");
python.execute("item.SelectItem(19)\nassert item.GetRefinedVnum() == "+std::to_string(finalSword->second.refined)+"\n");
for(int i=0;i<2;++i) {auto pair=sword->second.limits[i];python.execute("item.SelectItem(10)\nassert item.GetLimit("+std::to_string(i)+") == ("+std::to_string(pair.first)+","+std::to_string(pair.second)+")\n");}
for(int i=0;i<3;++i) {auto pair=sword->second.applies[i];python.execute("assert item.GetAffect("+std::to_string(i)+") == ("+std::to_string(pair.first)+","+std::to_string(pair.second)+")\n");}
python.execute("assert item.GetLimit(256) == item.GetLimit(0)\n"
"for getter, index in ((item.GetLimit,2),(item.GetAffect,3),(item.GetAffect,-1)):\n"
" try:\n getter(index)\n raise AssertionError('invalid table index accepted')\n"
" except RuntimeError:\n pass\n");
auto countBefore=items.records.size();
bool checkedTwoHanded=false;
for(const auto& [id,record]:items.records) {
if(record.type!=1 || record.subtype!=3)continue;
for(int i=0;i<3;++i) {
if(record.applies[i].first!=7)continue;
python.execute("item.SelectItem("+std::to_string(id)+")\n"
"app.SetTwoHandedWeaponAttSpeedDecreaseValue(9)\n"
"assert item.GetAffect("+std::to_string(i)+") == (7,"+std::to_string(record.applies[i].second-9)+")\n"
"app.SetTwoHandedWeaponAttSpeedDecreaseValue(0)\n");
checkedTwoHanded=true;break;
}
if(checkedTwoHanded)break;
}
if(!checkedTwoHanded)throw std::runtime_error("no two-handed attack-speed fixture");
python.execute("item.SelectItem(60001)\nfallbackName=item.GetItemName()\n"
"item.SelectItem(0)\nassert item.GetItemName() == fallbackName\n");
if(items.load("MIPX")||items.records.size()!=countBefore)throw std::runtime_error("truncated item proto damaged records");
auto originalWorkingDir=std::filesystem::current_path();
std::filesystem::current_path(std::filesystem::temp_directory_path());
// This fixture mount has proto/text but no icon assets. Windows returns Noname rather than a declared path.
python.execute("import item\nitem.SelectItem(10)\nassert item.GetItemName() == 'Sword+0'\nassert item.GetIconImageFileName() == 'Noname', item.GetIconImageFileName()\nitem.LoadItemTable('locale/en/item_proto')\nassert item.GetItemName() == 'Sword+0'\nassert item.GetItemType() == 1\n");
std::filesystem::current_path(originalWorkingDir);
// SkillDesc/SkillTable were registered by app.LoadLocaleData above; registering again would
// append duplicate affect rows exactly like CPythonSkill::RegisterSkillDesc without Destroy().
ava2::SetPlayerStatusPoint(12,20);ava2::SetPlayerStatusPoint(204,80);
if(std::fabs(ava2::EvaluateSkillFormula("str+ar*100+k",0.5f)-100.5f)>0.0001f || ava2::EvaluateSkillFormula("JeungJiFoo+k",0.5f)!=0.5f || ava2::EvaluateSkillFormula("UnknownState+k",0.5f)!=0)throw std::runtime_error("formula status binding mismatch " + std::to_string(ava2::EvaluateSkillFormula("str+ar*100+k",0.5f))+" / "+std::to_string(ava2::EvaluateSkillFormula("JeungJiFoo+k",0.5f))+" / "+std::to_string(ava2::EvaluateSkillFormula("1+",0.5f)));
ava2::SetPlayerStatusPoint(12,0);ava2::SetPlayerStatusPoint(204,0);
python.execute("import sys, struct, pack, colorInfo, musicInfo\n"
"assert sys.version_info[:2] == (2, 7)\n"
"assert colorInfo.CHAT_RGB_TALK == (255,255,255)\n"
"assert musicInfo.loginMusic == 'login_window.mp3'\n"
"assert pack.Exist('COLORINFO.PY') == 1\n"
"assert pack.Exist('../README.md') == 0\n"
"assert pack.Get('colorInfo.py').startswith('SUCCESS')\n"
"try:\n pack.Get('../README.md')\n raise AssertionError('traversal accepted')\n"
"except IOError:\n pass\n"
"exec 'print 21 / 2'\n"
"assert 21 / 2 == 10\n"
"import item, player, chrmgr, chr, chat, snd, background, effect, fly, nonplayer\n"
"import skill\n"
"assert skill.GetSkillName(1) == 'Three-Way Cut'\n"
"assert skill.GetSkillName(1,1) == 'Triple Cut'\n"
"assert skill.GetSkillName(1,2) == 'Triple Slash'\n"
"assert skill.GetSkillName(121,2) == 'Leadership'\n"
"assert skill.GetSkillName(1,3) == 'Three-Way Cut'\n"
"assert skill.GetSkillType(121) == skill.SKILL_TYPE_SUPPORT\n"
"assert skill.GetSkillDescription(1) == 'Cut the enemy with lightning speed.'\n"
"assert skill.GetSkillConditionDescriptionCount(1) == 2\n"
"assert skill.GetSkillConditionDescription(1,0) == 'Frontal Slash Attack 3 times'\n"
"assert skill.GetSkillConditionDescription(1,2) is None\n"
"assert skill.GetSkillConditionDescription(1,-1) is None\n"
"assert skill.IsToggleSkill(122) == 1\n"
"assert skill.IsToggleSkill(1) == 0\n"
"assert skill.GetSkillMaxLevel(1) == 20\n"
"assert skill.GetSkillCoolTime(1,0.5) == 12\n"
"assert skill.GetSkillNeedSP(1,0.5) == 90\n"
"assert skill.GetSkillNeedSP(1,0.125) == 52\n"
"assert skill.GetSkillContinuationSP(1,0.5) == 0\n"
"assert skill.GetDuration(1,0.5) == 0\n"
"assert skill.GetSkillLevelUpPoint(1) == 1\n"
"assert skill.GetSkillLevelLimit(1) == 0\n"
"assert skill.GetSkillAffectDescriptionCount(1) == 1\n"
"assert skill.GetNewAffectDataCount(1) == 0\n"
"for sid, index in ((1,0),(1,-1),(999999,0)):\n"
" try:\n skill.GetNewAffectData(sid,index,0.5)\n raise AssertionError('invalid affect accepted')\n"
" except RuntimeError:\n pass\n"
"for invalid_point in (-1,255,99999):\n"
" player.SetStatus(invalid_point,123)\n"
" assert player.GetStatus(invalid_point) == 0\n"
"player.SetStatus(29,100)\n"
"player.SetStatus(30,200)\n"
"player.SetStatus(12,20)\n"
"assert skill.GetSkillAffectDescription(1,0,0.5) == 'Total Attack Power 450-855'\n"
"assert skill.GetSkillAffectDescription(1,-1,0.5) is None\n"
"assert skill.GetSkillAffectDescription(1,1,0.5) is None\n"
"player.SetStatus(29,0)\n"
"player.SetStatus(30,0)\n"
"player.SetStatus(12,0)\n"
"assert skill.IsToggleSkill(19) == 0\n"
"assert skill.IsStandingSkill(19) == 1\n"
"assert skill.IsUseHPSkill(19) == 0\n"
"assert skill.GetSkillName(999999) == 'NoneSkill'\n"
"try:\n skill.IsToggleSkill(999999)\n raise AssertionError('missing skill accepted')\n"
"except RuntimeError:\n pass\n"
"assert skill.SKILL_TYPE_NONE == 0\n"
"assert skill.SKILL_TYPE_ACTIVE == 1\n"
"assert skill.SKILL_TYPE_SUPPORT == 2\n"
"assert skill.SKILL_TYPE_GUILD == 3\n"
"assert skill.SKILL_TYPE_HORSE == 4\n"
"assert skill.SKILL_TYPE_MAX_NUM == 5\n"
"assert skill.SKILL_GRADE_COUNT == 3\n"
"assert skill.SKILL_GRADE_STEP_COUNT == 20\n"
"assert skill.SKILL_GRADEGAP == 25\n"
"assert skill.SKILL_EFFECT_COUNT == 4\n"
"assert nonplayer.GetMonsterName(101) == ''\n"
"nonplayer.LoadNonPlayerData('locale/en/mob_proto')\n"
"assert nonplayer.GetMonsterName(101) == 'Wild Dog'\n"
"assert nonplayer.GetMonsterMaxHP(101) == 126\n"
"assert nonplayer.GetMonsterDamage(101) == (20,24)\n"
"assert nonplayer.GetMonsterLevel(101) == 1\n"
"matches = nonplayer.GetMobsByName('wild dog')\n"
"assert 101 in matches and matches == sorted(matches)\n"
"assert all(nonplayer.GetMonsterName(v).lower().startswith('wild dog') for v in matches)\n"
"assert nonplayer.GetMobsByName('Wild Dog') == []\n"
"assert nonplayer.GetMonsterPrice(101) == (0,0), repr(nonplayer.GetMonsterPrice(101))\n"
"assert nonplayer.GetGradeByVID(999999) == -1\n"
"assert nonplayer.GetLevelByVID(999999) == -1\n"
"assert nonplayer.ON_CLICK_EVENT_TALK == 3\n"
"assert nonplayer.MOB_RESIST_POISON == 10\n"
"assert background.GlobalPositionToLocalPosition(123,456) == (123,456)\n"
"assert background.GlobalPositionToMapInfo(409600,896000) == ('metin2_map_a1',409600,896000)\n"
"assert background.GlobalPositionToMapInfo(-1,-1) == ('',0,0)\n"
"assert effect.INDEX_FLY_TYPE_NORMAL == 0\n"
"assert effect.INDEX_FLY_TYPE_FIRE_CRACKER == 1\n"
"assert effect.FLY_HP_BIG == 3\n"
"effect.RegisterEffect('ymir work/pc/warrior/effect/palbang_2_spin.mse')\n"
"eid = effect.CreateEffect('ymir work/pc/warrior/effect/palbang_2_spin.mse', 0.0, 100.0, 0.0)\n"
"assert eid > 0\n"
"effect.SetPosition(eid, 10.0, 20.0, 30.0)\n"
"effect.Update()\n"
"effect.Render()\n"
"effect.DeleteEffect(eid)\n"
"fly.Update()\n"
"fly.Render()\n"
"assert item.ITEM_TYPE_NONE == 0\n"
"assert item.ITEM_TYPE_WEAPON == 1\n"
"assert item.ITEM_TYPE_ARMOR == 2\n"
"assert item.APPLY_BLEEDING_PCT == 93\n"
"assert item.APPLY_ATTBONUS_WOLFMAN == 94\n"
"assert item.ANTIFLAG_WOLFMAN == (1 << 18)\n"
"assert player.LEVEL == 1\n"
"assert player.CONQUEROR_LEVEL == 205\n"
"assert player.ATT_ELEMENTS == 180\n"
"assert player.GetName() == ''\n"
"assert player.GetStatus(player.HP) == 0\n"
"player.SetStatus(player.LEVEL, 99)\n"
"assert player.GetStatus(player.LEVEL) == 99\n"
"assert player.GetMainCharacterPosition() == (0.0, 0.0, 0.0)\n"
"assert chr.AFFECT_BLEEDING == 42\n"
"assert chr.MOTION_MODE_BOW_SPECIAL == 17 and not hasattr(chr, 'MOTION_MODE_CLAW')\n"
"assert chrmgr.NAMECOLOR_TOURNAMENT_TEAM_A == 32\n"
"assert chrmgr.EFFECT_ELEMENTS_WEAPON == 280\n"
"import privateShopSearch\n"
"assert privateShopSearch.GetItemCount() == 0\n"
"privateShopSearch.ClearSearchItems()\n"
"import combat_zone\n"
"assert combat_zone.COMBAT_ZONE_MAX_ROWS_RANKING == 11\n"
"assert combat_zone.IsRunning() == False\n"
"import exchange\n"
"assert exchange.EXCHANGE_ITEM_MAX_NUM == 12\n"
"assert exchange.GetItemElementGradeFromTarget(0) == 0\n"
"import safebox\n"
"assert safebox.GetItemBind(0) == 0\n"
"assert safebox.GetElements(0) == (0, 0, 0, 0)\n"
"import shop\n"
"assert shop.SHOP_SLOT_COUNT == 40\n"
"assert shop.OFFLINE_SHOP_SLOT_COUNT == 80\n"
"assert shop.GetItemElements(0) == (0, 0, 0, 0)\n"
"import constInfo, localeInfo\n"
"assert constInfo.IN_GAME_SHOP_ENABLE == 1\n"
"import networkModule\n"
"import uiInventory, ui, wndMgr\n"
"print 'Testing LoadDialog steps...'\n"
"boardsizex = 330 - 130\n"
"board = ui.Board()\n"
"board.SetPosition(wndMgr.GetScreenWidth()-boardsizex, wndMgr.GetScreenHeight()-100+30)\n"
"board.SetSize(boardsizex, 50)\n"
"print 'board width:', board.GetWidth()\n"
"slot0 = ui.ImageBox()\n"
"slot0.SetParent(board)\n"
"slot0.LoadImage('d:/ymir work/ui/public/Parameter_Slot_02.sub')\n"
"print 'slot0 width:', slot0.GetWidth()\n"
"diff = board.GetWidth() - slot0.GetWidth()\n"
"print 'diff:', diff\n"
"import prototype\n"
"import game\n"
"chr.CreateInstance(101)\n"
"assert chr.HasInstance(101) == 1\n"
"chr.SelectInstance(101)\n"
"chr.SetRace(0)\n"
"chr.SetArmor(0)\n"
"assert chr.GetRace() == 0\n"
"chr.SetWeapon(11299)\n"
"chr.SetHair(1)\n"
"chr.SetRotation(45.0)\n"
"chr.SetPixelPosition(100, 200, 30)\n"
"chr.Update()\n"
"chr.Deform()\n"
"print 'Testing CreateCharacterWindow lifecycle...'\n"
"stream = networkModule.MainStream()\n"
"stream.Create()\n"
"stream.SetCharacterSlot(1)\n"
"stream.SetCreateCharacterPhase()\n"
"assert stream.curPhaseWindow.__class__.__name__ == 'CreateCharacterWindow'\n"
"stream.curPhaseWindow._CreateCharacterWindow__SelectSlot(1)\n"
"stream.curPhaseWindow._CreateCharacterWindow__SelectShape(1)\n"
"stream.curPhaseWindow.editCharacterName.SetText('TestHero')\n"
"assert stream.curPhaseWindow.editCharacterName.GetText() == 'TestHero'\n"
"stream.curPhaseWindow.OnCreateSuccess()\n"
"assert stream.curPhaseWindow.__class__.__name__ == 'SelectCharacterWindow'\n"
"print 'Testing monster/NPC instantiation and network movement...'\n"
"chr.CreateInstance(201)\n"
"chr.SelectInstance(201)\n"
"chr.SetRace(101)\n"
"chr.SetPixelPosition(500, 600, 20)\n"
"chr.CreateInstance(301)\n"
"chr.SelectInstance(301)\n"
"chr.SetRace(8001)\n"
"chr.SetPixelPosition(800, 900, 10)\n"
"import net\n"
"assert net.COMBAT_ZONE_ACTION_LEAVE == 4\n"
"net.SendCombatZoneRequestActionPacket(net.COMBAT_ZONE_ACTION_LEAVE, net.COMBAT_ZONE_EMPTY_DATA)\n"
"net.SendCharacterMovePacket(1, 0, 90.0, 12345, 67890)\n"
"net.SendCharacterPositionPacket(2)\n"
"sw = ui.SlotWindow()\n"
"sw.AppendSlot(0, 0, 0, 32, 32)\n"
"wndMgr.ActivateSlot(sw.hWnd, 0)\n"
"wndMgr.LockSlot(sw.hWnd, 0)\n"
"wndMgr.SetSlotCountNew(sw.hWnd, 0, 1, 10)\n"
"import textTail\n"
"textTail.Clear()\n"
"textTail.RegisterCharacterTextTail(1, 201)\n"
"textTail.AttachTitle(201, 'Noble', 1.0, 0.8, 0.0)\n"
"textTail.AttachLevel(201, '[Lv. 75]', 0.6, 1.0, 0.2)\n"
"textTail.RegisterChatTail(201, 'Hello World!')\n"
"assert textTail.IsChat(201) == 1\n"
"chr.SelectInstance(201)\n"
"chr.SetNameString('DogMaster')\n"
"assert chr.GetName() == 'DogMaster'\n"
"assert chr.GetNameByVID(201) == 'DogMaster'\n"
"pos = chr.GetPixelPosition(201)\n"
"assert pos[0] == 500.0 and pos[1] == 600.0\n"
"textTail.RegisterItemTextTail(555, 'Full Moon Sword +9', 120, 'TestHero')\n"
"textTail.ShowAllTextTail()\n"
"textTail.ArrangeTextTail()\n"
"textTail.SelectItemName(555)\n"
"textTail.Render()\n"
"textTail.HideAllTextTail()\n"
"textTail.Clear()\n"
"assert background.ATTR_BLOCK == 1\n"
"assert background.ATTR_WATER == 2\n"
"assert background.ATTR_BANPK == 4\n"
"background.Initialize()\n"
"background.LoadMap('ava2_nonexistent_map_fixture',0.0,0.0,0.0)\n"
"assert background.GetCurrentMapName() == ''\n"
"background.LoadMap('metin2_map_a1',25600.0,76800.0,0.0)\n"
"assert background.GetCurrentMapName() == ''\n"
"bg_h = background.GetHeight(0.0, 0.0)\n"
"bg_block = background.isAttrOn(0.0, 0.0, background.ATTR_BLOCK)\n"
"print 'Python background verified: h =', bg_h, ', blocked =', bg_block\n"
"snd.SetMusicVolume(0.8)\n"
"snd.SetMusicVolumef(0.8)\n"
"snd.SetSoundVolume(4)\n"
"snd.SetSoundVolumef(0.7)\n"
"snd.SetSoundScale(250.0)\n"
"snd.SetAmbienceSoundScale(1200.0)\n"
"snd.PlaySound('sound/ui/click.wav')\n"
"snd.PlaySound3D(100.0, 50.0, 200.0, 'sound/common/swing/w_1h_c_1.wav')\n"
"snd.FadeInMusic('bgm/login_window.mp3', 0.05)\n"
"snd.FadeLimitOutMusic('bgm/login_window.mp3', 0.2, 0.05)\n"
"snd.FadeOutMusic('bgm/login_window.mp3', 0.05)\n"
"snd.FadeOutAllMusic()\n"
"snd.StopAllSound()\n"
"print 'Python snd module verified successfully'\n"
"print 'Testing Python net PhaseGame integration...'\n"
"class StartFixture:\n def __init__(self):\n self.calls=0\n def SetGamePhase(self):\n self.calls+=1\nstart_fixture=StartFixture()\nnet.SetHandler(start_fixture)\nnet.StartGame()\n"
"net.SendEnterGamePacket()\n"
"net.SendChatPacket('Hello Metin2 World!')\n"
"net.SendWhisperPacket('TesterGM', 'Whisper test')\n"
"net.SendItemPickUpPacket(777)\n"
"net.SendItemDropPacketNew(1, 0, 5)\n"
"net.SendOnClickPacket(201)\n"
"net.Warp()\n"
"print 'Testing Equipment Refine System (uirefine)...'\n"
"item.SelectItem(10)\nassert item.GetRefinedVnum() == 11\n"
"item.SelectItem(19)\nassert item.GetRefinedVnum() == 0\n"
"assert player.GetItemGrade(0) >= 0\n"
"assert player.IsRefineGradeScroll(0) is None\n"
"assert player.GetItemCountByTT(10) == 0\n"
"assert not hasattr(player,'GetItemRefineInformation')\n"
"import uirefine\n"
"refineDlg = uirefine.RefineDialog()\n"
"pct = refineDlg.GetRefineSuccessPercentage(0, 0)\n"
"assert pct >= 0\n"
"refineDlg.Open(0, 0)\n"
"refineDlg.Accept()\n"
"net.SendRefinePacket(0, 0)\n"
"net.SendGiveItemPacket(1001, 0, 1)\n"
"print 'Testing Quest Dialog System (uiquest & event)...'\n"
"import event\n"
"assert event.BUTTON_TYPE_NEXT == 0\n"
"assert event.BUTTON_TYPE_DONE == 1\n"
"assert event.BUTTON_TYPE_CANCEL == 2\n"
"evt = event.RegisterEventSetFromString('[ENTER]')\n"
"event.InsertText(evt, 'Welcome Adventurer!')\n"
"event.InsertTextInline(evt, ' Accept quest:', 40)\n"
"assert event.GetLineCount(evt) == 2\n"
"assert event.GetEventSetLocalYPosition(evt) >= 10\n"
"event.SelectAnswer(evt, 254)\n"
"event.ClearEventSet(evt)\n"
"import uiquest\n"
"evt = event.RegisterEventSetFromString('[ENTER]')\n"
"event.InsertText(evt, 'Quest: Clear Wild Boars')\n"
"questDlg = uiquest.QuestDialog(1, evt)\n"
"questDlg.MakeNextButton(event.BUTTON_TYPE_NEXT)\n"
"questDlg.MakeQuestion(3)\n"
"questDlg.OnUpdate()\n"
"questDlg.CloseSelf()\n"
"net.SendScriptAnswerPacket(1)\n"
"net.SendScriptButtonPacket(2)\n"
"print 'Equipment Refine & Quest System verified successfully'\n"
"print 'Python net module PhaseGame commands verified successfully'\n");
auto draws = ava2::GetAllActiveChrDraws();
std::cout << "Python-driven 3D Character draws count: " << draws.size() << std::endl;
if (draws.empty()) {
throw std::runtime_error("GetAllActiveChrDraws returned empty despite Python chr instance creation!");
}
const auto& last_move = ava2::get_last_character_move();
if (!last_move.valid || last_move.x != 12345 || last_move.y != 67890 || last_move.rot != 18 || last_move.arg != 2) {
throw std::runtime_error("Network character move state mismatch!");
}
std::cout << "Character move packet verified: x=" << last_move.x << ", y=" << last_move.y << ", rot=" << int(last_move.rot) << "\n";
// Verify PhaseGame network stream state and outgoing packets
auto& netStream = ava2::PythonNetworkStream::Instance();
if(netStream.IsGamePhase()) throw std::runtime_error("StartGame incorrectly changed wire phase");
netStream.ProcessRecvData();
python.execute("assert start_fixture.calls==1\n");
const auto& sendQueue = netStream.GetSendQueue();
if (sendQueue.empty()) {
throw std::runtime_error("PythonNetworkStream send queue is unexpectedly empty after net sends!");
}
std::cout << "PythonNetworkStream send queue byte count: " << sendQueue.size() << std::endl;
std::string mobName;
if(!ava2::GetNonPlayerName(101,mobName) || mobName!="Wild Dog")
throw std::runtime_error("native actor name did not use decrypted mob proto");
if(ava2::UseNonPlayerName(30000) || ava2::UseNonPlayerName(34041) || !ava2::UseNonPlayerName(20001))
throw std::runtime_error("Windows NPC name policy mismatch");
if(ava2::NonPlayerData::Instance().load("MMPT"))
throw std::runtime_error("truncated mob proto accepted");
// Test C++ receiving packet dispatching (TPacketGCMainCharacter2Empire, TPacketGCChat)
ava2::TPacketGCMainCharacter2Empire mainCharPkt{};
mainCharPkt.header = ava2::HEADER_GC_MAIN_CHARACTER2_EMPIRE;
mainCharPkt.dwVID = 54321;
mainCharPkt.wRaceNum = 0;
std::strncpy(mainCharPkt.szName, "HeroPlayer", ava2::CHARACTER_NAME_MAX_LEN);
mainCharPkt.byEmpire = 2;
mainCharPkt.bySkillGroup = 1;
mainCharPkt.lX = 435200;
mainCharPkt.lY = 972800;
mainCharPkt.lZ = 50;
netStream.PushRecvData(reinterpret_cast<const uint8_t*>(&mainCharPkt), sizeof(mainCharPkt));
netStream.ProcessRecvData();
if (netStream.GetMainActorVID() != 54321) {
throw std::runtime_error("MainActorVID mismatch after receiving TPacketGCMainCharacter2Empire!");
}
if (netStream.GetMainActorRace() != 0 || netStream.GetMainActorEmpire() != 2 || netStream.GetMainActorSkillGroup() != 1) {
throw std::runtime_error("MainActor attributes mismatch after TPacketGCMainCharacter2Empire!");
}
netStream.ClearSendQueue();
python.execute("player.RequestAddLocalQuickSlot(0,2,6)\nassert player.GetLocalQuickSlot(0)==(0,0)\n");
if(!netStream.PopSendBytes().empty()) throw std::runtime_error("quick request without main actor sent");
ava2::SNetworkActorData quickActor{};quickActor.m_dwVID=54321;quickActor.m_dwRace=0;quickActor.m_stName="HeroPlayer";
ava2::NetworkActorManager::Instance().AppendActor(quickActor);
python.execute("class QuickCallbacks:\n def __init__(self):\n self.refreshes=0\n self.emotions=[]\n def RefreshInventory(self):\n self.refreshes+=1\n def BINARY_ActEmotion(self,pos):\n self.emotions.append(pos)\nquick_callbacks=QuickCallbacks()\nplayer.SetGameWindow(quick_callbacks)\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,quick_callbacks)\nplayer.SetQuickPage(1)\nassert player.LocalQuickSlotIndexToGlobalQuickSlotIndex(2)==10\nplayer.RequestAddLocalQuickSlot(2,2,6)\nassert player.GetLocalQuickSlot(2)==(0,0)\n");
if(netStream.PopSendBytes()!=std::vector<uint8_t>{16,10,2,6}) throw std::runtime_error("quick add wire/page mismatch");
const uint8_t quickStart[]={28,10,2};netStream.PushRecvData(quickStart,sizeof(quickStart));netStream.ProcessRecvData();
python.execute("assert player.GetLocalQuickSlot(2)==(0,0)\n");
const uint8_t quickEnd[]={6,28,11,1,7,30,10,11,29,11};netStream.PushRecvData(quickEnd,sizeof(quickEnd));netStream.ProcessRecvData();
python.execute("assert quick_callbacks.refreshes==2\nassert player.GetLocalQuickSlot(2)==(1,7)\nassert player.GetGlobalQuickSlot(11)==(0,0)\nplayer.RequestDeleteGlobalQuickSlot(10)\nassert player.GetLocalQuickSlot(2)==(1,7)\nplayer.RequestMoveGlobalQuickSlotToLocalQuickSlot(10,4)\nplayer.RequestAddToEmptyLocalQuickSlot(3,9)\n");
if(netStream.PopSendBytes()!=std::vector<uint8_t>{17,10,18,10,12,16,8,3,9}) throw std::runtime_error("quick delete/move/empty request mismatch");
const uint8_t extraQuick[]={28,35,1,7};netStream.PushRecvData(extraQuick,sizeof(extraQuick));netStream.ProcessRecvData();
python.execute("player.RemoveQuickSlotByValue(1,7)\nassert player.GetGlobalQuickSlot(35)==(1,7)\n");
if(netStream.PopSendBytes()!=std::vector<uint8_t>{17,10,17,35}) throw std::runtime_error("remove by value missed hidden server quickslot");
python.execute("player.RequestUseLocalQuickSlot(2)\n");
if(netStream.PopSendBytes()!=std::vector<uint8_t>{11,1,7,0}) throw std::runtime_error("inventory quickslot use mismatch");
// Mobile HUD potion belt addresses global slots directly (any page, < 32), same packets.
python.execute("player.RequestUseGlobalQuickSlot(10)\nplayer.RequestAddGlobalQuickSlot(25,2,6)\nplayer.RequestMoveGlobalQuickSlotToGlobalQuickSlot(10,26)\n"
"player.RequestUseGlobalQuickSlot(35)\nplayer.RequestAddGlobalQuickSlot(32,2,6)\nplayer.RequestMoveGlobalQuickSlotToGlobalQuickSlot(10,32)\n");
if(netStream.PopSendBytes()!=std::vector<uint8_t>{11,1,7,0,16,25,2,6,18,10,26}) throw std::runtime_error("global quickslot request mismatch");
python.execute("net.SendItemDropPacket(7)\nnet.SendItemDropPacketNew(1,7,70000)\n");
if(netStream.PopSendBytes()!=std::vector<uint8_t>{224,1,7,0,0,0,0,0,20,1,7,0,0,0,0,0,0x70,0x11,1,0})
throw std::runtime_error("AVA2 old/new drop wire or DWORD count mismatch");
python.execute("net.SendElkDropPacket(123456)\nnet.SendGoldDropPacketNew(123456)\n");
if(netStream.PopSendBytes()!=std::vector<uint8_t>{224,0,0,0,0x40,0xe2,1,0,20,0,0,0,0x40,0xe2,1,0,0,0,0,0})
throw std::runtime_error("gold drop reserved window or count mismatch");
ava2::TPacketGCCharacterUpdate stunUpdate{};stunUpdate.header=19;stunUpdate.dwVID=54321;stunUpdate.dwAffectFlag[0]=1u<<5;
netStream.PushRecvData(reinterpret_cast<const uint8_t*>(&stunUpdate),sizeof(stunUpdate));netStream.ProcessRecvData();
python.execute("player.RequestDeleteGlobalQuickSlot(10)\n");
if(!netStream.PopSendBytes().empty()) throw std::runtime_error("affect stun allowed quickslot request");
netStream.SendAttackPacket(0,123);netStream.SendItemUsePacket(1,7);netStream.SendItemMovePacket(1,7,1,8,1);
netStream.SendItemPickUpPacket(123);netStream.SendItemDropPacket(1,7,0);netStream.SendItemDropPacketNew(1,7,0,1);
netStream.SendItemUseToItemPacket(7,8);
if(!netStream.PopSendBytes().empty()) throw std::runtime_error("controlled actor sent inventory/attack action");
python.execute("net.SendShopEndPacket()\nnet.SendShopBuyPacket(7)\nnet.SendShopSellPacket(7)\nnet.SendShopSellPacketNew(6,7,1)\n");
if(!netStream.PopSendBytes().empty())throw std::runtime_error("controlled actor sent shop transaction");
python.execute("net.SendOfflineShopEndPacket()\nnet.SendOfflineShopBuyPacket(-1,511)\n");
if(!netStream.PopSendBytes().empty())throw std::runtime_error("controlled actor sent offline transaction");
for(const auto operation:{5,6,11}) {
python.execute(operation==5?"net.SendRemoveOfflineShopItem(511)\n":operation==6?"net.SendDestroyOfflineShop()\n":"net.SendOfflineShopRemoveLogs()\n");
std::vector<uint8_t> expected(58,0);expected[0]=57;expected[1]=operation;
if(operation==5)expected.push_back(255);
if(netStream.PopSendBytes()!=expected)throw std::runtime_error("offline management layout/action gate mismatch");
}
for(const auto operation:{13,14,15}) {
python.execute(operation==13?"net.SendOpenShopSlot(-1)\n":operation==14?"net.SendGetBackItems()\n":"net.SendAddTime()\n");
std::vector<uint8_t> expected(58,0);expected[0]=57;expected[1]=operation;
if(operation==13)expected.push_back(255);
if(netStream.PopSendBytes()!=expected)throw std::runtime_error("offline slot/return/time layout mismatch");
}
python.execute("net.SendOpenWithVID(-1)\n");
std::vector<uint8_t> openVidExpected(58,0);openVidExpected[0]=57;openVidExpected[1]=16;openVidExpected.insert(openVidExpected.end(),{255,255,255,255});
if(netStream.PopSendBytes()!=openVidExpected)throw std::runtime_error("offline open VID layout mismatch");
stunUpdate.dwAffectFlag[0]=0;
netStream.PushRecvData(reinterpret_cast<const uint8_t*>(&stunUpdate),sizeof(stunUpdate));netStream.ProcessRecvData();
python.execute("player.RequestDeleteGlobalQuickSlot(10)\n");
if(netStream.PopSendBytes()!=std::vector<uint8_t>{17,10}) throw std::runtime_error("cleared affect did not restore action");
auto quickActorInstance=ava2::NetworkActorManager::Instance().GetActorInstance(54321);
netStream.PopSendBytes();
for(uint8_t operation=0;operation<4;++operation) {
netStream.SendShopPacket(operation,6,255,0x12345678);
std::vector<uint8_t> expected(58,0);expected[0]=50;expected[1]=operation;
if(operation==1) { expected.push_back(1);expected.push_back(255); }
if(operation==2)expected.push_back(255);
if(operation==3)expected.insert(expected.end(),{6,255,0x78,0x56,0x34,0x12});
if(netStream.PopSendBytes()!=expected)throw std::runtime_error("AVA2 shop send layout mismatch");
}
const std::array<std::string,4> shopCalls={"net.SendShopEndPacket()","net.SendShopBuyPacket(511)","net.SendShopSellPacket(-1)","net.SendShopSellPacketNew(262,511,-1)"};
python.execute("net.SendOfflineShopEndPacket()\n");
std::vector<uint8_t> offlineExpected(58,0);offlineExpected[0]=57;
if(netStream.PopSendBytes()!=offlineExpected)throw std::runtime_error("offline end layout mismatch");
python.execute("net.SendOfflineShopBuyPacket(-1,511)\n");
offlineExpected[1]=1;for(unsigned i=53;i<58;++i)offlineExpected[i]=255;
if(netStream.PopSendBytes()!=offlineExpected)throw std::runtime_error("offline purchase layout mismatch");
python.execute("class ShopCallbacks:\n def __init__(self):\n self.errors=[]\n self.ends=0\n self.price=0\n def OnShopError(self,error):\n self.errors.append(error)\n def EndShop(self):\n self.ends+=1\n def SetShopSellingPrice(self,price):\n self.price=price\nshop_callbacks=ShopCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,shop_callbacks)\n");
const uint8_t fragmented[]={38,4,0,5};
std::vector<uint8_t> shopUpdate(128,0);shopUpdate[0]=38;shopUpdate[1]=128;shopUpdate[3]=2;shopUpdate[4]=39;
shopUpdate[5]=10;shopUpdate[9]=0x78;shopUpdate[10]=0x56;shopUpdate[11]=0x34;shopUpdate[12]=0x12;shopUpdate[17]=3;shopUpdate[22]=20;shopUpdate[26]=5;
shopUpdate[58]=0xff;shopUpdate[59]=0xff;shopUpdate[60]=0xff;shopUpdate[61]=0xff;
shopUpdate[104]=7;shopUpdate[105]=0xfe;shopUpdate[106]=0xff;
shopUpdate[125]=8;shopUpdate[126]=0xfd;shopUpdate[127]=0xff;
python.execute("ShopCallbacks.RefreshShop=lambda self: None\n");
netStream.PushRecvData(shopUpdate);netStream.ProcessRecvData();
python.execute("assert shop.GetItemID(39)==10\nassert shop.GetItemPrice(39)==0x12345678\nassert shop.GetItemCount(39)==3\nassert shop.GetVnumBuy(39)==20\nassert shop.GetCountBuy(39)==5\n");
python.execute("assert shop.GetItemMetinSocket(39,7)==-1\nassert shop.GetItemAttribute(39,14)==(7,-2)\nassert shop.GetItemRandomAttribute(39,6)==(8,-3)\n");
python.execute("ShopCallbacks.StartShop=lambda self,owner: setattr(self,'owner',owner)\n");
std::vector<uint8_t> shopStart(4928,0);shopStart[0]=38;shopStart[1]=64;shopStart[2]=19;shopStart[4]=123;
std::copy(shopUpdate.begin()+5,shopUpdate.end(),shopStart.begin()+8+39*123);
netStream.PushRecvData(shopStart.data(),shopStart.size()-1);
if(netStream.ProcessRecvData())throw std::runtime_error("partial shop start consumed");
netStream.PushRecvData(shopStart.data()+shopStart.size()-1,1);netStream.ProcessRecvData();
python.execute("assert shop_callbacks.owner==123\nassert shop.GetTabCount()==1\nassert shop.GetItemID(39)==10\nassert shop.GetItemID(79)==0\n");
std::vector<uint8_t> shopTabs(9915,0);shopTabs[0]=38;shopTabs[1]=187;shopTabs[2]=38;shopTabs[3]=10;shopTabs[4]=124;shopTabs[8]=2;
std::memcpy(shopTabs.data()+9,"Gold",4);std::memcpy(shopTabs.data()+4962,"Tokens",6);shopTabs[4994]=1;
std::copy(shopUpdate.begin()+5,shopUpdate.end(),shopTabs.begin()+4995+39*123);
netStream.PushRecvData(shopTabs);netStream.ProcessRecvData();
python.execute("assert shop_callbacks.owner==124\nassert shop.GetTabCount()==2\nassert shop.GetTabName(0)=='Gold'\nassert shop.GetTabName(1)=='Tokens'\nassert shop.GetTabCoinType(1)==1\nassert shop.GetItemID(79)==10\nassert shop.GetItemID(39)==0\n");
const std::vector<std::vector<uint8_t>> badShopFrames={
{38,3,0,1},{38,4,0,0},{38,4,0,2},{38,4,0,3},
{38,9,0,10,0,0,0,0,4},{38,9,0,10,0,0,0,0,2}};
for(const auto& frame:badShopFrames) {
ava2::PythonNetworkStream malformed;
malformed.PushRecvData(frame);
bool rejected=false;
try { malformed.ProcessRecvData(); }catch(const std::runtime_error&) { rejected=true; }
if(!rejected)throw std::runtime_error("malformed shop frame accepted");
python.execute("assert shop.GetTabCount()==2\nassert shop.GetTabName(1)=='Tokens'\nassert shop.GetItemID(79)==10\n");
}
netStream.PushRecvData(fragmented,3);
if(netStream.ProcessRecvData())throw std::runtime_error("partial shop frame consumed");
netStream.PushRecvData(fragmented+3,1);netStream.ProcessRecvData();
const uint8_t shopEvents[]={38,4,0,1,38,12,0,3,255,255,255,255,255,255,255,255};
netStream.PushRecvData(shopEvents,sizeof(shopEvents));netStream.ProcessRecvData();
python.execute("assert shop_callbacks.errors==['NOT_ENOUGH_MONEY']\nassert shop_callbacks.ends==1\nassert shop_callbacks.price==-1\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,quick_callbacks)\n");
for(uint8_t operation=0;operation<4;++operation) {
python.execute(shopCalls[operation]+"\n");
std::vector<uint8_t> expected(58,0);expected[0]=50;expected[1]=operation;
if(operation==1)expected.insert(expected.end(),{1,255});
if(operation==2)expected.push_back(255);
if(operation==3)expected.insert(expected.end(),{6,255,255,255,255,255});
if(netStream.PopSendBytes()!=expected)throw std::runtime_error("Python shop argument conversion mismatch");
}
netStream.SetMainActorVID(999);
const uint8_t remoteStun[]={13,0x31,0xd4,0,0};
netStream.PushRecvData(remoteStun,sizeof(remoteStun));netStream.ProcessRecvData();
if(!quickActorInstance->IsStun() || quickActorInstance->IsDead()) throw std::runtime_error("remote stun incorrectly entered death");
netStream.SetMainActorVID(54321);
const uint8_t mainStun[]={13,0x31,0xd4,0,0}; // VID54321, main actor enters death as Windows does.
netStream.PushRecvData(mainStun,sizeof(mainStun));netStream.ProcessRecvData();
if(!quickActorInstance->IsDead()) throw std::runtime_error("Windows main-actor stun did not enter death");
python.execute("player.RequestDeleteGlobalQuickSlot(10)\nplayer.RequestAddLocalQuickSlot(0,2,6)\n");
if(!netStream.PopSendBytes().empty()) throw std::runtime_error("dead actor sent quickslot request");
ava2::AddPlayerQuickSlot(8,3,9);
python.execute("player.RequestUseLocalQuickSlot(0)\nassert quick_callbacks.emotions==[9]\nplayer.SetQuickPage(-1)\nassert player.GetQuickPage()==3\nplayer.SetQuickPage(4)\nassert player.GetQuickPage()==0\nplayer.SetGameWindow(None)\nnet.ClearPhaseWindow(net.PHASE_WINDOW_GAME,quick_callbacks)\n");
ava2::NetworkActorManager::Instance().RemoveActor(54321);
ava2::NetworkActorManager::Instance().AppendActor(quickActor);
python.execute("assert player.GetMainCharacterPosition() == (25600.0,76800.0,50.0)\n"
"assert background.GlobalPositionToLocalPosition(410600,898000) == (1000,2000)\n");
netStream.ClearSendQueue();
netStream.SendCharacterMovePacket(1,0,0,1000,2000,123);
auto globalMove=netStream.PopSendBytes();
auto wire32=[&](size_t offset) { return uint32_t(globalMove[offset]) | (uint32_t(globalMove[offset+1])<<8) | (uint32_t(globalMove[offset+2])<<16) | (uint32_t(globalMove[offset+3])<<24); };
if(globalMove.size()!=16 || wire32(4)!=410600 || wire32(8)!=898000)
throw std::runtime_error("local movement not converted to Windows global coordinates");
netStream.ClearSendQueue();
netStream.SendGiveItemPacket(0x12345678,1,0x1234,70000);
if(netStream.PopSendBytes()!=std::vector<uint8_t>{83,0x78,0x56,0x34,0x12,1,0x34,0x12,0x70,0x11,1,0})
throw std::runtime_error("AVA2 DWORD give-item count/layout mismatch");
netStream.SendRefinePacket(7,2,3,-1);
if(netStream.PopSendBytes()!=std::vector<uint8_t>{96,7,2,3,255})
throw std::runtime_error("AVA2 BYTE refine index mismatch");
netStream.SendItemUseToItemPacket(0x1234,0x5678);
if(netStream.PopSendBytes()!=std::vector<uint8_t>{60,1,0x34,0x12,1,0x78,0x56})
throw std::runtime_error("AVA2 default INVENTORY position mismatch");
netStream.SendScriptButtonPacket(0x12345678);
if(netStream.PopSendBytes()!=std::vector<uint8_t>{66,0x78,0x56,0x34,0x12})
throw std::runtime_error("AVA2 script button layout mismatch");
python.execute("import app\nassert app.IsEnableTestServerFlag()==0\napp.EnableTestServerFlag()\nassert app.IsEnableTestServerFlag()==1\n");
python.execute("import eventMgr\neventMgr.Update(1.5,2.5,-3.5)\n");
if(ava2::GetGameEventCenter()!=std::array<float,3>{1.5f,-2.5f,-3.5f}) throw std::runtime_error("AVA2 event center Y sign mismatch");
// Independent AVA2 non-GAIDEN wire fixture, including the last of 8 sockets/15 attrs/7 glove attrs.
auto itemPacket=[](uint8_t header,uint8_t window) {
std::vector<uint8_t> bytes(header==20?135:144,0);
bytes[0]=header;bytes[1]=window;bytes[2]=7;
bytes[4]=0x34;bytes[5]=0x12;bytes[8]=3;
const size_t sockets=header==20?12:21;
bytes[sockets+28]=0x78;bytes[sockets+29]=0x56;bytes[sockets+30]=0x34;bytes[sockets+31]=0x12;
bytes[sockets+32+42]=9;bytes[sockets+32+43]=0xfe;bytes[sockets+32+44]=0xff;
bytes[sockets+32+45+18]=10;bytes[sockets+32+45+19]=42;
if(header==21) { bytes[12]=0xaa;bytes[16]=0xbb;bytes[20]=1; }
return bytes;
};
python.execute("class ItemCallbacks:\n def __init__(self):\n self.refreshes=0\n self.highlights=[]\n def RefreshInventory(self):\n self.refreshes+=1\n def BINARY_Highlight_Item(self,window,cell):\n self.highlights.append((window,cell))\nitem_callbacks=ItemCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,item_callbacks)\n");
auto basic=itemPacket(20,1);
netStream.PushRecvData(basic.data(),basic.size()-1);
if(netStream.ProcessRecvData()) throw std::runtime_error("incomplete AVA2 item packet consumed");
netStream.PushRecvData(basic.data()+basic.size()-1,1);netStream.ProcessRecvData();
auto extended=itemPacket(21,6);netStream.PushRecvData(extended);netStream.ProcessRecvData();
python.execute("assert player.GetItemIndex(1,7)==0x1234\nassert player.GetItemCount(6,7)==3\nassert player.GetItemMetinSocket(6,7,7)==0x12345678\nassert player.GetItemAttribute(6,7,14)==(9,-2)\nassert item_callbacks.refreshes==2\nassert item_callbacks.highlights==[(6,7)]\n");
auto data=ava2::GetPlayerItemData(6,7);
python.execute("assert player.GetItemFlags(6,7)==0xaa\nassert player.IsAntiFlagBySlot(6,7,0x20)==1\nassert player.IsAntiFlagBySlot(6,7,0x40)==0\n");
if(data.flags!=0xaa || data.anti_flags!=0xbb || data.randomAttr[6].bType!=10 || data.randomAttr[6].sValue!=42)
throw std::runtime_error("AVA2 extended item data lost");
std::vector<uint8_t> update(131,0);update[0]=25;update[1]=6;update[2]=7;update[4]=2;
netStream.PushRecvData(update);netStream.ProcessRecvData();
python.execute("assert player.GetItemCount(6,7)==2\nassert player.GetItemIndex(6,7)==0x1234\nnet.ClearPhaseWindow(net.PHASE_WINDOW_GAME,item_callbacks)\n");
auto stored=itemPacket(85,1); // Storage/mall use extended packet format, despite different header.
stored=extended;stored[0]=85;stored[1]=3;
ava2::CPythonSafeBox::Instance().OpenSafeBox(45);
netStream.PushRecvData(stored);netStream.ProcessRecvData();
const ava2::TItemData* storedData=nullptr;
if(!ava2::CPythonSafeBox::Instance().GetItemDataPtr(7,&storedData) || storedData->alSockets[7]!=0x12345678 || storedData->aAttr[14].sValue!=-2)
throw std::runtime_error("AVA2 storage extended packet mismatch");
const uint8_t phase[]={253,5};netStream.PushRecvData(phase,2);netStream.ProcessRecvData();
if(!netStream.IsGamePhase()) throw std::runtime_error("AVA2 wire phase 5 is not Game");
netStream.ClearSendQueue();netStream.SetPhase(ava2::PHASE_SELECT);
if(netStream.SendChatPacket("outside game",0) || !netStream.GetSendQueue().empty()) throw std::runtime_error("AVA2 chat phase guard missing");
if(netStream.SendSafeBoxMoneyPacket(0,100) || !netStream.GetSendQueue().empty()) throw std::runtime_error("disabled AVA2 storage money emitted party packet");
netStream.SetPhase(ava2::PHASE_GAME);
// AVA2 Windows golden layouts for the net.Send* wrappers that used to be placeholders.
{
using bytes_t=std::vector<uint8_t>;
auto le32=[](bytes_t b,uint32_t v){ for(int i=0;i<32;i+=8) b.push_back(uint8_t(v>>i)); return b; };
auto text=[](bytes_t b,const std::string& value,size_t field){ size_t start=b.size();b.resize(start+field,0);std::copy(value.begin(),value.end(),b.begin()+start);return b; };
auto expect=[&](const char* call,const bytes_t& expected,const char* what){
netStream.ClearSendQueue();python.execute(std::string(call)+"\n");
if(netStream.PopSendBytes()!=expected) throw std::runtime_error(std::string("AVA2 Windows layout mismatch: ")+what);
};
// Exchange: TPacketCGExchange {header, sub, long long arg1, BYTE arg2, TItemPos(ctor {INVENTORY,WORD_MAX})}
expect("net.SendExchangeStartPacket(0x01020304)",{27,0,4,3,2,1,0,0,0,0,0,1,255,255},"exchange start");
expect("net.SendExchangeElkAddPacket(0x123456789)",{27,3,0x89,0x67,0x45,0x23,1,0,0,0,0,1,255,255},"exchange elk (long long)");
expect("net.SendExchangeItemAddPacket(1,0x1234,300)",{27,1,0,0,0,0,0,0,0,0,44,1,0x34,0x12},"exchange item add");
expect("net.SendExchangeItemDelPacket(3)",{},"exchange item del must be a Windows no-op");
expect("net.SendExchangeAcceptPacket()",{27,4,0,0,0,0,0,0,0,0,0,1,255,255},"exchange accept");
expect("net.SendExchangeExitPacket()",{27,5,0,0,0,0,0,0,0,0,0,1,255,255},"exchange cancel");
// Safebox / mall
expect("net.SendSafeboxCheckinPacket(7,3)",{70,3,1,7,0},"safebox checkin (2 args)");
expect("net.SendSafeboxCheckinPacket(6,0x0102,3)",{70,3,6,2,1},"safebox checkin (3 args)");
expect("net.SendSafeboxCheckoutPacket(4,9)",{71,4,1,9,0},"safebox checkout (2 args)");
expect("net.SendSafeboxItemMovePacket(5,6,70000)",{77,1,5,0,1,6,0,0x70,0x11,1,0},"safebox move = TPacketCGItemMove");
expect("net.SendMallCheckoutPacket(2,1,8)",{69,2,1,8,0},"mall checkout");
expect("net.SendMallCheckoutPacket(2)",{},"mall checkout bad arity");
expect("net.SendSafeboxSaveMoneyPacket(100)\nnet.SendSafeboxWithdrawMoneyPacket(100)",{},"disabled safebox money");
// Messenger
expect("net.SendMessengerAddByVIDPacket(0x0a0b0c0d)",le32({67,0},0x0a0b0c0d),"messenger add by vid");
expect("net.SendMessengerAddByNamePacket('A'*30)",text({67,1},std::string(23,'A'),24),"messenger add by name");
python.execute("class BoardCallbacks:\n def __init__(self):\n self.names=[]\n def RefreshTargetBoardByName(self,name):\n self.names.append(name)\nboard_callbacks=BoardCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,board_callbacks)\n");
expect("net.SendMessengerRemovePacket('Key','Friend')",text({67,2},"Key",24),"messenger remove");
python.execute("assert board_callbacks.names==['Friend']\nnet.ClearPhaseWindow(net.PHASE_WINDOW_GAME,board_callbacks)\n");
// Party
expect("net.SendPartyInvitePacket(77)",le32({72},77),"party invite");
auto answer=le32({73},88);answer.push_back(1);
expect("net.SendPartyInviteAnswerPacket(88,1)",answer,"party invite answer");
expect("net.SendPartyRemovePacket(99)",le32({74},99),"party remove (PID alias)");
expect("net.SendPartyRemovePacketVID(54321)\nnet.SendPartyExitPacket()",{},"party VID lookups without party state");
auto state=le32({75},5);state.push_back(2);state.push_back(1);
expect("net.SendPartySetStatePacket(5,2,1)",state,"party set state");
expect("net.SendPartyUseSkillPacket(3,6)",le32({76,3},6),"party use skill");
expect("net.SendPartyParameterPacket(1)",{78,1},"party parameter");
netStream.SetPhase(ava2::PHASE_SELECT);
expect("net.SendPartyRemovePacketPID(99)",{},"party remove outside Game");
netStream.SetPhase(ava2::PHASE_GAME);
// Guild
expect("net.SendGuildAddMemberPacket(11)",le32({80,0},11),"guild add member");
expect("net.SendGuildRemoveMemberPacket('Nobody')",{},"guild remove without member list");
expect("net.SendGuildChangeGradeNamePacket(2,'Captain12345')",text({80,2,2},"Captain1",9),"guild grade name");
expect("net.SendGuildChangeGradeAuthorityPacket(2,7)",{80,3,2,7},"guild grade authority");
expect("net.SendGuildOfferPacket(1000)",le32({80,4},1000),"guild offer");
expect("net.SendGuildPostCommentPacket('hi')",{80,5,3,'h','i',0},"guild post comment");
expect("net.SendGuildDeleteCommentPacket(4)",le32({80,6},4),"guild delete comment");
netStream.ResetGuildCommentRefreshThrottle();
expect("net.SendGuildRefreshCommentsPacket(0)\nnet.SendGuildRefreshCommentsPacket(0)",{80,7},"guild refresh 1000 ms throttle");
auto grade=le32({80,8},12);grade.push_back(3);
expect("net.SendGuildChangeMemberGradePacket(12,3)",grade,"guild member grade");
expect("net.SendGuildUseSkillPacket(151,54321)",le32(le32({80,9},151),54321),"guild use skill");
auto general=le32({80,10},12);general.push_back(1);
expect("net.SendGuildChangeMemberGeneralPacket(12,1)",general,"guild member general");
auto invite=le32({80,11},5);invite.push_back(1);
expect("net.SendGuildInviteAnswerPacket(5,1)",invite,"guild invite answer");
expect("net.SendGuildChargeGSPPacket(10)",le32({80,12},10),"guild charge gsp");
expect("net.SendGuildDepositMoneyPacket(20)",le32({80,13},20),"guild deposit");
expect("net.SendGuildWithdrawMoneyPacket(30)",le32({80,14},30),"guild withdraw");
// Quest / script
expect("net.SendAnswerMakeGuildPacket('GuildNameIsTooLong')",text({81},"GuildNameIsT",13),"answer make guild");
expect("net.SendQuestInputStringPacket('abc')",text({30},"abc",65),"quest input string");
expect("net.SendQuestInputLongStringPacket('abc')",text({214},"abc",512),"quest input long string");
expect("net.SendQuestConfirmPacket(1,0x01020304)",{31,1,4,3,2,1},"quest confirm");
expect("net.SendSelectItemPacket(9)",le32({114},9),"script select item");
expect("net.SendTargetInfoLoad(54321)",le32({59},54321),"target info load");
expect("net.SendRequestRefineInfoPacket(1)",{},"refine info is a Windows no-op");
expect("net.SendExchangeStartPacket('x')",{},"ScriptLib argument failure returns None");
// __CanActMainInstance gate on exchange
netStream.SetMainActorVID(999);
expect("net.SendExchangeStartPacket(1)\nnet.SendExchangeAcceptPacket()",{},"exchange without an acting main actor");
netStream.SetMainActorVID(54321);
}
// Chat / whisper / ServerCommand follow Windows RecvChatPacket, RecvWhisperPacket and
// PythonNetworkStreamCommand.cpp (ENABLE_MULTILANGUAGE_SYSTEM branch).
netStream.ResetConnection();netStream.SetPhase(ava2::PHASE_GAME);
// RecvChatPacket appends into CPythonChat; set 0 (CHAT_SET_CHAT_WINDOW) holds every line.
ava2::CPythonChat::Instance().Destroy();
auto appendedLines=[]() {
std::vector<std::string> out;
if(const auto* lines=ava2::CPythonChat::Instance().GetChatLineDeque(0))
for(const auto* line:*lines) out.push_back(std::to_string(line->iType)+":"+line->text);
return out;
};
python.execute(
"class ChatWnd:\n"
" def __init__(self):\n self.calls=[]\n self.run=False\n"
" def GetLocaleString(self,t,s):\n self.calls.append(('locale',t,s))\n"
" def BINARY_ServerCommand_Run(self,s):\n self.calls.append(('run',s))\n return self.run\n"
" def BINARY_Cube_Open(self,v):\n self.calls.append(('cube',v))\n"
" def BINARY_Cube_UpdateInfo(self,g,v,c):\n self.calls.append(('cubeinfo',g,v,c))\n"
" def OnMessengerAddFriendQuestion(self,n):\n self.calls.append(('friend',n))\n"
" def OnRecvWhisper(self,t,n,l,lang,emp):\n self.calls.append(('whisper',t,n,l,lang,emp))\n"
" def OnRecvWhisperSystemMessage(self,t,n,b):\n self.calls.append(('wsys',t,n,b))\n"
" def OnRecvWhisperError(self,t,n,b):\n self.calls.append(('werr',t,n,b))\n"
"chat_wnd=ChatWnd()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,chat_wnd)\n");
auto chatWire=[](uint8_t type,uint32_t vid,const std::string& msg) {
std::vector<uint8_t> out(sizeof(ava2::TPacketGCChat)+msg.size()+1,0);
auto* pkt=reinterpret_cast<ava2::TPacketGCChat*>(out.data());
pkt->header=ava2::HEADER_GC_CHAT;pkt->size=uint16_t(out.size());pkt->type=type;pkt->dwVID=vid;pkt->bEmpire=1;
std::memcpy(out.data()+sizeof(ava2::TPacketGCChat),msg.data(),msg.size());
return out;
};
auto feed=[&](const std::vector<uint8_t>& bytes) { netStream.PushRecvData(bytes.data(),bytes.size());netStream.ProcessRecvData(); };
auto check=[&](bool ok,const char* what) { if(!ok) throw std::runtime_error(std::string("AVA2 chat parity: ")+what); };
feed(chatWire(ava2::CHAT_TYPE_NOTICE,0,"Server: Welcome to AVA2!"));
python.execute("assert chat_wnd.calls==[('locale',2,'Server: Welcome to AVA2!')], chat_wnd.calls\nchat_wnd.calls=[]\n");
check(appendedLines().empty(),"VID 0 non-shout goes to GetLocaleString, not AppendChat");
feed(chatWire(ava2::CHAT_TYPE_SHOUT,0,"Bob : hello"));
check(appendedLines()==std::vector<std::string>{"6:Bob : hello"},"VID 0 shout goes to AppendChat");
feed(chatWire(15,0,"ignored"));feed(chatWire(ava2::CHAT_TYPE_TALKING,4242,"Nobody : x"));
check(appendedLines().size()==1,"type >= CHAT_TYPE_MAX_NUM and unknown chatter are dropped");
python.execute("assert chat_wnd.calls==[], chat_wnd.calls\n");
// CHAT_TYPE_COMMAND -> ServerCommand: BINARY_ServerCommand_Run first, then the C++ fallback.
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"cube open 20383"));
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"cube info 100 \"27001\" 2"));
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"messenger_auth Alice"));
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"ConsoleEnable"));
python.execute(
"assert chat_wnd.calls==[('run','cube open 20383'),('cube',20383),('run','cube info 100 \"27001\" 2'),('cubeinfo',100,27001,2),"
"('run','messenger_auth Alice'),('friend','Alice')], chat_wnd.calls\n"
"chat_wnd.calls=[]\nchat_wnd.run=True\n");
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"cube open 1"));
python.execute("assert chat_wnd.calls==[('run','cube open 1')], chat_wnd.calls\nchat_wnd.calls=[]\n");
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"ObserverMode 1"));feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"sms"));
python.execute("assert player.IsObserverMode()==0 and player.HasMobilePhoneNumber()==0\nchat_wnd.run=False\nchat_wnd.calls=[]\n");
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"ObserverMode 1"));feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"sms"));
python.execute("assert player.IsObserverMode()==1 and player.HasMobilePhoneNumber()==1\nchat_wnd.calls=[]\n");
// Whisper: 31-byte header with bLanguage/bEmpire.
auto whisperWire=[](uint8_t type,const char* from,uint8_t language,uint8_t empire,const std::string& msg) {
std::vector<uint8_t> out(31+msg.size()+1,0);
out[0]=ava2::HEADER_GC_WHISPER;out[1]=uint8_t(out.size());out[2]=uint8_t(out.size()>>8);out[3]=type;
std::memcpy(out.data()+4,from,std::strlen(from));out[29]=language;out[30]=empire;
std::memcpy(out.data()+31,msg.data(),msg.size());
return out;
};
feed(whisperWire(ava2::WHISPER_TYPE_CHAT,"Alice",2,3,"hi"));
feed(whisperWire(ava2::WHISPER_TYPE_SYSTEM,"Alice",0,0,"sys"));
feed(whisperWire(ava2::WHISPER_TYPE_NOT_EXIST,"Ghost",0,0,""));
python.execute("assert chat_wnd.calls==[('whisper',0,'Alice','Alice : hi',2,3),('wsys',255,'Alice','sys'),('werr',1,'Ghost','')], chat_wnd.calls\n");
// PyCallClassMemberFunc: a missing method or a raising callback never aborts the pump.
python.execute("chat_wnd.GetLocaleString=None\ndel ChatWnd.OnRecvWhisper\ndef boom(*a):\n raise ValueError('callback error is printed, not thrown')\nchat_wnd.OnRecvWhisperSystemMessage=boom\n");
feed(chatWire(ava2::CHAT_TYPE_NOTICE,0,"x"));
feed(whisperWire(ava2::WHISPER_TYPE_CHAT,"Alice",0,0,"hi"));feed(whisperWire(ava2::WHISPER_TYPE_SYSTEM,"Alice",0,0,"sys"));
// '/' repeats the last slash command (SendChatPacket m_strLastCommand).
netStream.ClearSendQueue();netStream.SendChatPacket("/stat ht");netStream.SendChatPacket("/");
auto sent=netStream.PopSendPackets();
check(sent.size()==2 && sent[0]==sent[1],"'/' repeats the previous command");
// CheckPacket framing: a fixed GamePhase packet is consumed, the next one still dispatches;
// a partial dynamic packet waits; an unknown header clears the buffer and requests quit.
ava2::CPythonChat::Instance().Destroy();
std::vector<uint8_t> stream={114,0,0,0,0,0}; // HEADER_GC_SEPCIAL_EFFECT (type 0, unknown VID): fixed packet
auto shout=chatWire(ava2::CHAT_TYPE_SHOUT,0,"A : b");
stream.insert(stream.end(),shout.begin(),shout.end());
netStream.PushRecvData(stream.data(),stream.size()-2);netStream.ProcessRecvData();
check(netStream.GetUnportedPackets().empty() && appendedLines().empty(),"partial packet waits after a fixed packet");
netStream.PushRecvData(stream.data()+stream.size()-2,2);netStream.ProcessRecvData();
check(appendedLines().size()==1,"packet after a fixed one is dispatched");
std::vector<uint8_t> unknown={250,1,2,3};unknown.insert(unknown.end(),shout.begin(),shout.end());
feed(unknown);
check(appendedLines().size()==1 && netStream.IsQuitRequested(),"unknown header clears the buffer and posts quit");
netStream.ResetConnection();netStream.SetPhase(ava2::PHASE_GAME);
check(!netStream.IsQuitRequested(),"ResetConnection clears the quit request");
std::vector<uint8_t> bgm={ava2::HEADER_GC_MAIN_CHARACTER4_BGM_VOL};bgm.resize(75,0);
bgm.insert(bgm.end(),shout.begin(),shout.end());feed(bgm);
check(appendedLines().size()==1,"MAIN_CHARACTER4_BGM_VOL in Game phase is RecvDefaultPacket (buffer cleared)");
ava2::CPythonChat::Instance().Destroy();
python.execute("net.SetPhaseWindow(net.PHASE_WINDOW_GAME,0)\n");
std::cout << "PhaseGame wire packet receive & dispatch verified successfully!\n";
{
// Pass 17: player-settings effects, GC114, emoticon gate, name colours, NPC wear, sash.
auto& actors=ava2::NetworkActorManager::Instance();
using NAM=ava2::NetworkActorManager;
check(NAM::GetEffectCRC(17)!=0 && NAM::GetEffectCRC(NAM::EFFECT_EMOTICON)!=0,"introLoading/player settings registered effects");
check(NAM::GetIndexedNameColor(NAM::NAMECOLOR_SHOP)!=0 && NAM::GetIndexedNameColor(NAM::NAMECOLOR_PK)!=0,"chrmgr.RegisterNameColor tables filled");
ava2::SNetworkActorData pc;pc.m_dwVID=7001;pc.m_bType=6;pc.m_dwRace=1;pc.m_stName="Killer";pc.m_dwEmpireID=1;
pc.m_dwStateFlags=NAM::ADD_CHARACTER_STATE_KILLER;actors.AppendActor(pc);
check(actors.GetNameColorIndex(7001)==NAM::NAMECOLOR_PK,"KILLER state uses NAMECOLOR_PK");
ava2::SNetworkActorData shop;shop.m_dwVID=7002;shop.m_bType=1;shop.m_dwRace=30001;shop.m_dwWeapon=5;actors.AppendActor(shop);
check(actors.GetNameColorIndex(7002)==NAM::NAMECOLOR_SHOP,"race 30000-30020 NPC uses NAMECOLOR_SHOP");
check(actors.GetActorData(7002)->m_dwWeapon==0,"non-PC without npc_wear takes no weapon");
// GC114: 6 bytes, SE_CRITICAL attaches EFFECT_CRITICAL (17) to the actor.
const size_t before=actors.GetActorData(7001)->m_attachedEffects.size();
const uint8_t se[]={114,uint8_t(ava2::SE_CRITICAL),0x59,0x1b,0,0};
netStream.PushRecvData(se,sizeof(se));netStream.ProcessRecvData();
check(netStream.GetUnportedPackets().empty() && actors.GetActorData(7001)->m_attachedEffects.size()==before+1,"GC114 attaches the special effect");
// SetEmoticon: one emoticon per 1000 ms (m_dwEmoticonTime).
static uint32_t fakeNow=5000;actors.SetTimeSourceForTest([]{return fakeNow;});
check(actors.IsPossibleEmoticon(7002),"fresh actor may show an emoticon");
actors.SetEmoticon(7002,0);fakeNow=5500;
check(!actors.IsPossibleEmoticon(7002),"emoticon blocked inside 1000 ms");
actors.SetTimeSourceForTest(nullptr);
// npc_wear.txt row (ENABLE_NPC_WEAR_ITEM): race/weapon/armor/hair/acce/mount/7 shining.
auto& npd=ava2::NonPlayerData::Instance();
npd.loadNPCWear("20016\tall\t2\t11\t12\t13\t86010\t0\t1\t2\t3\t4\t5\t6\t7\n");
ava2::SNetworkActorData wear;wear.m_dwVID=7003;wear.m_bType=1;wear.m_dwRace=20016;actors.AppendActor(wear);
const auto* w=actors.GetActorData(7003);
check(w->m_dwRace==2 && w->m_dwWeapon==11 && w->m_dwArmor==12 && w->m_dwHair==13 && w->m_dwSash==1010
&& w->m_shining[0]==1 && w->m_shining[ava2::CHR_SHINING_NUM-1]==ava2::CHR_SHINING_NUM,"npc_wear replaces race and parts");
check(w->m_dwSashEffect!=0,"acce > 86000 attaches EFFECT_REFINED+EFFECT_SASH");
actors.ChangeSash(7003,0);
check(actors.GetActorData(7003)->m_dwSash==0 && actors.GetActorData(7003)->m_dwSashEffect==0,"ChangeSash clears the sash effect");
npd.clearNPCWear();
for(uint32_t vid:{7001u,7002u,7003u}) actors.RemoveActor(vid);
}
{
// Pass 20: 64-bit Granny (Map_Sands shadow_dragon) loads and its curve2-compressed
// animation (D4nK*/D3K* tracks) drives the bones instead of leaving them at bind.
auto resolve=[](const char* p){
std::error_code ec;
for(const auto& c:CResourceManager::GetCandidatePaths(CResourceManager::NormalizePath(p)))
if(std::filesystem::is_regular_file(c,ec)) return c;
return std::string();
};
const std::string model=resolve("d:/ymir work/monster/shadow_dragon/shadow_dragon.gr2");
const std::string run=resolve("d:/ymir work/monster/shadow_dragon/run.gr2");
if(model.empty()||run.empty()) {
std::cout<<"pass20 shadow_dragon assets missing: 64-bit gr2 checks skipped\n";
} else {
auto dragon=ava2::Gr2ModelInstance::Load(model);
check(dragon && dragon->GetFile().magic()==gr2::Magic::Bit64_LE && !dragon->GetInfo().meshes.empty(),"64-bit shadow_dragon.gr2 loads with meshes");
check(dragon && dragon->LoadExternalAnimation(run),"64-bit run.gr2 loads");
if(dragon) {
size_t compressed=0,decoded=0;
gr2::LoadError err;auto anim=gr2::File::load_path(run,&err);
if(anim) for(auto& t:anim->file_info().animations[0].tracks)
if(t.rot_type.rfind("D4n",0)==0){++compressed;decoded+=!t.orientation.empty();}
check(compressed>0 && decoded==compressed,"D4n compressed quaternion tracks decode");
const float dur=dragon->GetAnimationDuration();
float a[16]={},b[16]={},bind[16]={};
const bool ok=dragon->GetBoneWorldTransform("Spine01_jnt",a,0.0f)
&& dragon->GetBoneWorldTransform("Spine01_jnt",b,dur*0.5f)
&& dragon->GetBoneWorldTransform("Spine01_jnt",bind,-1.0f);
float moved=0.0f,fromBind=0.0f;bool finite=ok;
for(int i=0;i<16;++i){finite&=std::isfinite(a[i])&&std::isfinite(b[i]);moved=std::max(moved,std::fabs(a[i]-b[i]));fromBind=std::max(fromBind,std::fabs(a[i]-bind[i]));}
check(finite && dur>0.0f && moved>1e-3f && fromBind>1e-3f,"curve2 animation moves Spine01_jnt away from bind");
}
}
}
{
// Pass 18: CRaceManager .msm race/shape/hair, AttachWeapon bones and AttachSash on network actors.
auto& actors=ava2::NetworkActorManager::Instance();
using NAM=ava2::NetworkActorManager;using RD=ava2::RaceData;
auto& races=ava2::RaceManager::Instance();
races.LoadGameNPC("npclist.txt");races.LoadPlayerRaces();
if(!races.GetRaceDataPointer(0)) {
std::cout<<"pass18 race assets (warrior_m.msm) missing: mount checks skipped\n";
} else {
NAM::SetHairColorEnable(true);
ava2::SNetworkActorData hero;hero.m_dwVID=7101;hero.m_bType=6;hero.m_dwRace=0;hero.m_dwArmor=1;
hero.m_dwHair=1;hero.m_dwWeapon=10;hero.m_dwSash=1;hero.m_stName="Mounted";
actors.AppendActor(hero);
auto inst=actors.GetActorInstance(7101);
check(inst && inst->GetRace()==0 && inst->GetShape()==1,"SetRace(0) + SetArmor(1) -> shape 1");
check(inst->GetShapeModelFile().find("warrior_novice")!=std::string::npos,"ShapeData01 model requested");
check(inst->GetPartModelPath(RD::PART_HAIR).find("hair_1_1")!=std::string::npos && inst->GetPartBone(RD::PART_HAIR).empty(),"HairData01 skinned on PART_HAIR");
check(inst->GetPartItemID(RD::PART_WEAPON)==10 && inst->GetPartBone(RD::PART_WEAPON)=="equip_right_hand"
&& inst->GetPartModelPath(RD::PART_WEAPON).find("00010")!=std::string::npos,"warrior weapon on equip_right_hand");
check(inst->GetPartBone(RD::PART_SASH)=="Bip01 Spine2" && inst->GetPartModelPath(RD::PART_SASH).find("85_001")!=std::string::npos,"sash 85001 on Bip01 Spine2");
check(actors.GetActorData(7101)->m_awPart[RD::PART_SASH]==1 && actors.GetActorData(7101)->m_awPart[RD::PART_HAIR]==1,"m_awPart tracks hair/sash");
// The AVA2 pc/item gr2 are BitKnit2-compressed (Granny format 4): the meshes must decode and draw.
check(inst->GetModel() && !inst->GetModel()->GetInfo().meshes.empty(),"BitKnit2 warrior_novice.gr2 loads");
{
auto draws=inst->BuildDrawCommands();
size_t shapeMeshes=inst->GetModel()->GetInfo().meshes.size();
bool textured=true,bodySkin=false,hairSkin=false,weapon=false,sash=false;
for(auto& dc:draws){
std::string t=dc.texture0;for(auto& c:t) c=char(std::tolower((unsigned char)c));
if(t.empty()) textured=false;
bodySkin|=t.find("warrior_novice_blue")!=std::string::npos; // .msm ShapeData SourceSkin->TargetSkin
hairSkin|=t.find("warrior_hair_01_white")!=std::string::npos; // .msm HairData skin
weapon|=t.find("weapon_chogeup_01")!=std::string::npos;
sash|=t.find("acce_85_001")!=std::string::npos;
}
check(draws.size()>shapeMeshes && textured,"shape + hair/weapon/sash parts draw with textures");
check(bodySkin && hairSkin && weapon && sash,"msm skins and part textures reach the draws");
}
// ChangeWeapon(0) detaches; ChangeArmor rebuilds the race and re-applies hair/sash/weapon.
ava2::SNetworkUpdateActorData up;up.m_dwVID=7101;up.m_dwArmor=1;up.m_dwWeapon=0;up.m_dwHair=1;up.m_dwSash=1;
actors.UpdateActor(up);
check(inst->GetPartItemID(RD::PART_WEAPON)==0 && inst->GetPartModelPath(RD::PART_WEAPON).empty(),"ChangeWeapon(0) removes the weapon");
up.m_dwArmor=0;up.m_dwWeapon=10;actors.UpdateActor(up);
check(inst->GetShape()==0 && inst->GetPartModelPath(RD::PART_HAIR).find("hair_1_1")!=std::string::npos
&& inst->GetPartItemID(RD::PART_WEAPON)==10 && inst->GetPartBone(RD::PART_SASH)=="Bip01 Spine2","ChangeArmor re-applies parts");
// Missing sash item keeps the previous sash (GetItemDataPointer failure returns early).
actors.ChangeSash(7101,999);
check(inst->GetPartModelPath(RD::PART_SASH).find("85_001")!=std::string::npos,"unknown sash keeps the old model");
// npc_wear: the NPC is drawn as race 0 with the listed parts (hair allowed, race <= 8).
auto& npd=ava2::NonPlayerData::Instance();
npd.loadNPCWear("20016\tall\t0\t10\t1\t1\t85001\t0\t0\t0\t0\t0\t0\t0\t0\n");
ava2::SNetworkActorData wear;wear.m_dwVID=7102;wear.m_bType=1;wear.m_dwRace=20016;actors.AppendActor(wear);
auto w=actors.GetActorInstance(7102);
check(w->GetRace()==0 && w->GetShape()==1 && w->GetPartItemID(RD::PART_WEAPON)==10
&& !w->GetPartModelPath(RD::PART_HAIR).empty() && w->GetPartBone(RD::PART_SASH)=="Bip01 Spine2","npc_wear mounts race/armor/weapon/hair/sash");
npd.clearNPCWear();
// Monster race from npclist: no hair / sash / weapon for non-PC races.
ava2::SNetworkActorData dog;dog.m_dwVID=7103;dog.m_bType=0;dog.m_dwRace=101;dog.m_dwWeapon=10;actors.AppendActor(dog);
auto d=actors.GetActorInstance(7103);
check(d->GetRace()==101 && d->GetShapeModelFile().find("stray_dog")!=std::string::npos && d->GetPartItemID(RD::PART_WEAPON)==0,"npclist stray_dog race loads without parts");
for(uint32_t vid:{7101u,7102u,7103u}) actors.RemoveActor(vid);
}
}
{
// Remaining GamePhase() handlers (PythonNetworkStreamPhaseGameRecv.cpp): golden wire bytes -> callbacks.
netStream.ResetConnection();netStream.SetPhase(ava2::PHASE_GAME);
python.execute("class GameRec(object):\n def __init__(self):\n self.calls=[]\n def __getattr__(self,name):\n if name.startswith('__'):\n raise AttributeError(name)\n return lambda *a: self.calls.append((name,)+a)\ngame_rec=GameRec()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,game_rec)\n");
struct W { std::vector<uint8_t> b;
W& u8(uint32_t v){b.push_back(uint8_t(v));return *this;}
W& u16(uint32_t v){u8(v);u8(v>>8);return *this;}
W& u32(uint32_t v){u16(v);u16(v>>16);return *this;}
W& i64(int64_t v){u32(uint32_t(v));u32(uint32_t(uint64_t(v)>>32));return *this;}
W& str(const std::string& t,size_t n){for(size_t i=0;i<n;++i) u8(i<t.size()?uint8_t(t[i]):0);return *this;}
W& zero(size_t n){b.insert(b.end(),n,0);return *this;}
W& size16(){b[1]=uint8_t(b.size());b[2]=uint8_t(b.size()>>8);return *this;}
W& size32(){for(int i=0;i<4;++i) b[1+i]=uint8_t(b.size()>>(8*i));return *this;} };
auto feedG=[&](const std::vector<uint8_t>& bytes) { netStream.PushRecvData(bytes.data(),bytes.size());netStream.ProcessRecvData(); };
auto expect=[&](const std::string& calls,const char* what) {
python.execute("calls,game_rec.calls=game_rec.calls,[]\nassert calls=="+calls+",('"+what+"',calls)\n");
};
auto channel=W{}.u8(121).u8(3).u8(1).b;
// 255 Handshake: TIME_SYNC reply (sequenced) and GamePhase() returns before the next packet.
auto hs=W{}.u8(255).u32(0x11223344).u32(1000).u32(50).b;hs.insert(hs.end(),channel.begin(),channel.end());
netStream.ClearSendQueue();feedG(hs);
auto sent=netStream.PopSendPacketsWithSequence();
check(sent.size()==1 && sent[0].first==W{}.u8(0xfc).u32(0x11223344).u32(1100).u32(0).b && sent[0].second,"Handshake -> TIME_SYNC dwTime+2*lDelta");
expect("[]","Handshake stops the GamePhase frame");
netStream.ProcessRecvData();
expect("[('SetChannelIndex',3),('SetAntiExp',1)]","packet after Handshake runs next frame");
feedG(W{}.u8(252).b);
check(ava2::GetServerMSec()-1050<1000,"HandshakeOK sets server msec to time+delta+elapsed");
// 205 XTrap: ACK 204 + 128 bytes without SendSequence.
feedG(W{}.u8(205).zero(128).b);
sent=netStream.PopSendPacketsWithSequence();
check(sent.size()==1 && sent[0].first==W{}.u8(204).zero(128).b && !sent[0].second,"XTrap ACK is unsequenced");
// 204 HS / 213 Unk213 fail -> RecvErrorPacket clears the buffer.
auto hsReq=W{}.u8(204).zero(402).b;hsReq.insert(hsReq.end(),channel.begin(),channel.end());feedG(hsReq);
auto unk=W{}.u8(213).u8(0).b;unk.insert(unk.end(),channel.begin(),channel.end());feedG(unk);
expect("[]","HS and Unk213 fail and clear the buffer");
// 152 HybridCrypt keys: stream dropped, frame stops.
auto keys=W{}.u8(152).u16(0).u32(3).u8(1).u8(2).u8(3).size16().b;keys.insert(keys.end(),channel.begin(),channel.end());
feedG(keys);expect("[]","HybridCrypt stops the frame");
netStream.ProcessRecvData();expect("[('SetChannelIndex',3),('SetAntiExp',1)]","HybridCrypt key stream consumed");
// 95/119 refine (ENABLE_MULTI_REFINE_WORLDARD).
auto refine=[&](bool isNew,uint8_t sub) {
W w;w.u8(isNew?119:95);if(isNew) w.u8(4);w.u8(7);
w.u32(11).u32(12).u8(1).u32(500).u32(90).u8(1).u32(2).u8(sub).u32(30).u32(2).zero(32);return w.b; };
feedG(refine(false,1));feedG(refine(true,1));feedG(refine(true,5));feedG(refine(false,0));
expect("[('OpenRefineDialog',2,7,12,500,90,1),('AppendMaterialToRefineDialog',2,30,2),"
"('BINARY_MULTI_REFINE_ADD_INFO',2,7,12,500,90,1,4),('BINARY_MULTI_REFINE_ADD_MATERIAL',2,30,2),"
"('BINARY_MULTI_REFINE_DATES_CLEAR',),('BINARY_MULTI_REFINE_CLEAR_INFO',)]","refine information");
// 112 ChangeSkillGroup + 72 SkillLevel: refresh block order Character, Skill, Status.
std::vector<uint8_t> grp=W{}.u8(112).u8(2).b;std::vector<uint8_t> lv(256,0);lv[0]=72;grp.insert(grp.end(),lv.begin(),lv.end());
feedG(grp);
check(netStream.GetMainActorSkillGroup()==2,"skill group stored");
expect("[('RefreshCharacter',),('RefreshSkill',),('RefreshStatus',)]","refresh order");
// 41 PVP, 215 Sash, 218 KingdomsWar, 231 Sungma, 131/132 Love, 242 67Attr, 82 guild.
feedG(W{}.u8(41).u32(5).u32(6).u8(ava2::PVP_MODE_FIGHT).b);
check(ava2::NetworkActorManager::Instance().FindPVPKey(6,5),"PVP fight key");
feedG(W{}.u8(215).u8(ava2::SASH_SUBHEADER_GC_ADDED).u8(1).u32(0).u8(1).u8(0).u16(0).u32(0).u32(0).u32(0).b);
feedG(W{}.u8(218).u8(1).u32(1).u32(2).u32(3).u32(10).u32(4).u32(5).u32(60).b);
feedG(W{}.u8(231).u8(1).u8(2).u8(3).u8(4).b);
feedG(W{}.u8(131).str("Bob",25).u8(80).b);feedG(W{}.u8(132).u8(90).b);
feedG(W{}.u8(242).b);feedG(W{}.u8(82).b);
expect("[('RefreshTargetBoardByVID',5),('RefreshTargetBoardByVID',6),('AlertSash',1),('ActSash',3,1),"
"('ActKingdomsWar',3,1,2,3,10,4,5,60),('BINARY_SungMaAttr',1,2,3,4),('BINARY_LoverInfo','Bob',80),"
"('BINARY_UpdateLovePoint',90),('OpenAttr67AddDlg',),('AskGuildName',)]","small callbacks");
// 235 ExchangeLog (LOAD + LOAD_ITEM), 241 CatchKing, 214/216 Calendar, 209 DS refine.
W log;log.u8(235).u32(0).u8(0).str("CODE",19).u8(1).u16(1).u32(9)
.str("Al",25).u32(1).i64(5000000000LL).str("1.2.3.4",16).str("Bo",25).u32(2).i64(7).str("5.6.7.8",16).str("2026-10-06",25).u8(0);
feedG(log.size32().b);
W item;item.u8(235).u32(0).u8(1).u16(1).u32(9).u8(2).u32(19).u16(1).u32(4);item.zero(28).u8(1).u16(15).zero(42).u8(1);
feedG(item.size32().b);
feedG(W{}.u8(241).u16(5).u8(ava2::SUBHEADER_GC_CATCH_KING_START).u32(123).b);
feedG(W{}.u8(241).u16(4).u8(ava2::SUBHEADER_GC_CATCH_KING_REWARD).b);
feedG(W{}.u8(214).u8(ava2::CALENDAR_RECEIVE_OPEN).u8(0).zero(400).u32(0).u32(777).b);
feedG(W{}.u8(216).u8(ava2::CALENDAR_RECEIVE_LOAD_EVENTS_ADM).u32(3).str("ev",100).str("desc",100).b);
feedG(W{}.u8(209).u8(ava2::DS_SUB_HEADER_REFINE_SUCCEED).u8(1).u16(12).b);
expect("[('ExchangeLogClear','CODE'),('ExchangeLogAppend',9,'Al',5000000000,'1.2.3.4','Bo',7,'5.6.7.8','2026-10-06'),('ExchangeLogRefresh',0),"
"('ExchangeLogItemAppend',9,2,19,1,[4,0,0,0,0,0,0,0],[1]+[0]*14,[15]+[0]*14,1),('ExchangeLogRefresh',9),"
"('MiniGameCatchKingEventStart',123),('BINARY_CALENDAR_OPEN',777),('BINARY_CALENDAR_LOAD_EVENTS_ADM',3,'ev','desc'),"
"('BINARY_DragonSoulRefineWindow_RefineSucceed',1,12)]","exchange log / catch king / calendar / DS");
// 130 Land, 115 NPC list, 110 Dungeon destination, 249 blacklist: consumed exactly.
feedG(W{}.u8(130).u16(0).zero(48).size16().b);
feedG(W{}.u8(115).u16(0).u16(1).zero(17).size16().b);
feedG(W{}.u8(110).u16(12).u8(ava2::DUNGEON_SUBHEADER_GC_DESTINATION_POSITION).u32(100).u32(200).b);
feedG(W{}.u8(249).zero(1024).b);
feedG(channel);
check(netStream.GetDungeonDestination()==std::make_pair(100,200),"dungeon destination stored");
expect("[('SetChannelIndex',3),('SetAntiExp',1)]","land/npc/dungeon/blacklist consumed exactly");
check(netStream.GetUnportedPackets().empty(),"no newly ported header is skipped");
python.execute("net.SetPhaseWindow(net.PHASE_WINDOW_GAME,0)\n");
std::cout << "PhaseGame remaining handlers verified successfully!\n";
}
netStream.ResetConnection();
python.execute("class SkillCallbacks:\n def __init__(self):\n self.skills=0\n self.status=0\n def RefreshSkill(self):\n self.skills+=1\n def RefreshStatus(self):\n self.status+=1\nskill_callbacks=SkillCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,skill_callbacks)\nplayer.SetSkill(1,1)\nplayer.SetSkill(2,2)\nplayer.SetSkill(3,3)\nplayer.SetSkill(4,4)\nassert player.GetSkillLevel(1)==0\nassert player.GetSkillSlotIndex(3)==3\n");
std::vector<uint8_t> skillsWire(1531,0);skillsWire[0]=76;
auto setSkill=[&](int index,uint8_t grade,uint8_t level) { skillsWire[1+index*6]=grade;skillsWire[2+index*6]=level; };
setSkill(1,0,19);setSkill(2,1,20);setSkill(3,2,30);setSkill(4,3,40);
setSkill(114,0,10);setSkill(221,1,20);setSkill(228,2,31);setSkill(229,1,20);setSkill(243,3,40);
netStream.PushRecvData(skillsWire.data(),1530);netStream.ProcessRecvData();
python.execute("assert skill_callbacks.skills==0\n");
netStream.PushRecvData(skillsWire.data()+1530,1);netStream.ProcessRecvData();
python.execute("assert skill_callbacks.skills==1 and skill_callbacks.status==1\n"
"assert player.GetSkillLevel(1)==19 and player.GetSkillGrade(1)==0\n"
"assert player.GetSkillLevel(2)==1 and player.GetSkillGrade(2)==1\n"
"assert player.GetSkillLevel(3)==1 and player.GetSkillGrade(3)==2\n"
"assert player.GetSkillLevel(4)==1 and player.GetSkillGrade(4)==3\n"
"assert abs(player.GetSkillCurrentEfficientPercentage(3)-0.82)<0.00001\n"
"assert abs(player.GetSkillNextEfficientPercentage(3)-0.85)<0.00001\n"
"assert player.GetSkillCurrentEfficientPercentage(4)==1.25\n"
"assert player.GetSkillIndex(7)==228 and player.GetSkillLevel(7)==2\n"
"assert player.GetSkillIndex(8)==243\n");
std::vector<uint8_t> oldSkills(256,0);oldSkills[0]=72;oldSkills[3]=17;
netStream.PushRecvData(oldSkills);netStream.ProcessRecvData();
python.execute("assert player.GetSkillLevel(2)==17 and player.GetSkillGrade(2)==-1\n"
"assert skill_callbacks.skills==2 and skill_callbacks.status==2\n"
"net.ClearPhaseWindow(net.PHASE_WINDOW_GAME,skill_callbacks)\n");
python.execute("player.SetSkill(6,101)\nassert player.GetSkillLevel(6)==0\n");
ava2::SetSkillCoolTime(101,10);
python.execute("assert player.IsSkillCoolTime(6)==1\n"
"assert player.GetSkillCoolTime(6)[0]==10.0\n"
"assert player.GetSkillCoolTime(101)[0]==0.0\n"
"assert player.ToggleCoolTime()==0\nassert player.IsSkillCoolTime(6)==0\n"
"assert player.ToggleCoolTime()==1\nassert player.IsSkillCoolTime(6)==1\n");
ava2::SetSkillCoolTimeAt(101,10,float(SDL_GetTicks())/1000.0f-12);
python.execute("assert player.IsSkillCoolTime(6)==0\n"
"total,elapsed=player.GetSkillCoolTime(6)\nassert total==10.0 and elapsed>=12.0\n"
"assert player.GetSkillCoolTime(255)==(0.0,0.0)\n");
netStream.ResetConnection();
python.execute("assert player.GetSkillCoolTime(6)[0]==0.0\nassert player.IsSkillCoolTime(6)==0\n");
python.execute("class AffectCallbacks:\n def __init__(self):\n self.adds=[]\n self.removes=[]\n self.refreshes=0\n def BINARY_NEW_AddAffect(self,*args):\n self.adds.append(args)\n def BINARY_NEW_RemoveAffect(self,*args):\n self.removes.append(args)\n def RefreshStatus(self):\n self.refreshes+=1\naffect_callbacks=AffectCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,affect_callbacks)\nassert player.AffectIndexToSkillIndex(14)==3\nassert player.AffectIndexToSkillIndex(33)==19\nassert player.AffectIndexToSkillIndex(46)==182\nassert player.AffectIndexToSkillIndex(19)==63\nassert player.AffectIndexToSkillIndex(25)==79\nassert player.AffectIndexToSkillIndex(26)==78\nassert player.AffectIndexToSkillIndex(999)==0\n");
ava2::SetServerTime(1700000000);
const uint8_t affectWire[]={126,0xf4,1,0,0,128,0xfb,0xff,0xff,0xff,0,0,0,0,60,0,0,0,0,0,0,0};
netStream.PushRecvData(affectWire,21);netStream.ProcessRecvData();
python.execute("assert affect_callbacks.adds==[]\n");
netStream.PushRecvData(affectWire+21,1);netStream.ProcessRecvData();
const uint8_t removeWire[]={127,0xf4,1,0,0,128};netStream.PushRecvData(removeWire,sizeof(removeWire));netStream.ProcessRecvData();
python.execute("assert affect_callbacks.adds==[(500,128,-5,60)]\n"
"assert affect_callbacks.removes==[(500,128)]\n"
"assert affect_callbacks.refreshes==1\n"
"assert 1700000060<=player.GetStatus(129)<=1700000062\n"
"net.ClearPhaseWindow(net.PHASE_WINDOW_GAME,affect_callbacks)\n");
// Literal Windows wire lengths, independent of the port's sizeof values.
// An unmatched additional-info packet is ignored, not used to spawn an actor.
netStream.ResetConnection();
std::vector<uint8_t> actorInfo(75,0);
actorInfo[0]=ava2::HEADER_GC_CHAR_ADDITIONAL_INFO;
actorInfo[1]=0x7f;
netStream.PushRecvData(actorInfo.data(),74);
netStream.ProcessRecvData();
if(ava2::NetworkActorManager::Instance().GetActorData(127))
throw std::runtime_error("fragmented actor info spawned an actor");
std::vector<uint8_t> actorTail(1+56+1,0);
actorTail[1]=ava2::HEADER_GC_CHARACTER_UPDATE;
actorTail[2]=0x7f;
actorTail.back()=44;
netStream.PushRecvData(actorTail);
netStream.ProcessRecvData();
if(ava2::NetworkActorManager::Instance().GetActorData(127))
throw std::runtime_error("unmatched actor info spawned an actor");
if(netStream.PopSendBytes()!=std::vector<uint8_t>{ava2::HEADER_CG_PONG})
throw std::runtime_error("Windows actor packet length corrupted next packet");
netStream.ResetConnection();
std::vector<uint8_t> petAdd(36,0);
petAdd[0]=1; petAdd[1]=126; petAdd[21]=10;
netStream.PushRecvData(petAdd); netStream.ProcessRecvData();
if(ava2::NetworkActorManager::Instance().GetActorData(126))
throw std::runtime_error("pet created before Windows additional-info packet");
netStream.ResetConnection();
// Add2 is 85 bytes; invisible race 20025 must never instantiate a model.
std::vector<uint8_t> actor2(85,0);
actor2[0]=120; actor2[1]=0x7f; actor2[47]=0x39; actor2[48]=0x4e;
netStream.PushRecvData(actor2.data(),84); netStream.ProcessRecvData();
std::vector<uint8_t> actor2Tail(1+52+1,0);
actor2Tail[1]=117; actor2Tail[2]=0x7f; actor2Tail.back()=44;
netStream.PushRecvData(actor2Tail); netStream.ProcessRecvData();
if(ava2::NetworkActorManager::Instance().GetActorData(127))
throw std::runtime_error("Windows invisible race instantiated");
if(netStream.PopSendBytes()!=std::vector<uint8_t>{ava2::HEADER_CG_PONG})
throw std::runtime_error("Windows add2/update2 packet framing mismatch");
const uint8_t deadFirst[]={14,0x7f,0,0,0,5,10};
netStream.PushRecvData(deadFirst,sizeof(deadFirst));
netStream.ProcessRecvData();
const uint8_t deadTail[]={30,44};
netStream.PushRecvData(deadTail,sizeof(deadTail));
netStream.ProcessRecvData();
if(netStream.PopSendBytes()!=std::vector<uint8_t>{ava2::HEADER_CG_PONG})
throw std::runtime_error("renewal death packet corrupted following packet");
ava2::ActorInstance actionActor;
if(!actionActor.CanAct()) throw std::runtime_error("fresh actor cannot act");
actionActor.SetParalysis(true);if(actionActor.CanAct()) throw std::runtime_error("paralysis allowed action");
actionActor.SetParalysis(false);actionActor.SetFaint(true);if(actionActor.CanAct()) throw std::runtime_error("faint allowed action");
actionActor.SetFaint(false);actionActor.SetSleep(true);if(actionActor.CanAct()) throw std::runtime_error("sleep allowed action");
actionActor.SetSleep(false);if(!actionActor.CanAct()) throw std::runtime_error("cleared flags did not restore action");
actionActor.Stun();if(actionActor.CanAct()) throw std::runtime_error("stun allowed action");
ava2::ActorInstance deathActor;
deathActor.SetMaxHP(200000);
deathActor.Die();
if(!deathActor.IsDead()) throw std::runtime_error("server death depended on fabricated damage amount");
netStream.ResetConnection();
ava2::TPacketGCChat malformed{};malformed.header=ava2::HEADER_GC_CHAT;malformed.size=1;
netStream.PushRecvData(reinterpret_cast<const uint8_t*>(&malformed),sizeof(malformed));
bool invalidRejected=false;
try { netStream.ProcessRecvData(); } catch(const std::runtime_error&) { invalidRejected=true; }
if(!invalidRejected) throw std::runtime_error("undersized dynamic AVA2 packet accepted");
netStream.ResetConnection();
bool overflowRejected=false;
try { netStream.PushRecvData(std::vector<uint8_t>(128*1024+1)); } catch(const std::runtime_error&) { overflowRejected=true; }
if(!overflowRejected) throw std::runtime_error("unbounded AVA2 game receive queue");
ava2::ResetSkillDescriptions();
python.execute("assert skill.GetSkillName(1) == 'NoneSkill'\n"
"try:\n skill.GetSkillType(1)\n raise AssertionError('skill state survived reset')\n"
"except RuntimeError:\n pass\n");
std::cout<<"Embedded Python 2 original AVA2 modules, gameplay constants, networkModule, ui, prototype & chr 3D passed\n";
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
}