Files
AVA2/tests/drop_item_test.cpp
shenleiandClaude Opus 5.5 9077aa389a AVA2 client Windows parity passes (gr2 BitKnit2/64-bit, GamePhase handlers, python modules)
- gr2: BitKnit2 decompression, 64-bit LE files, compressed curves
- net: remaining GamePhase handlers, generated GC packet table
- python: event/chat/chr/minimap/guild/quest/messenger/shop-search and
  other native modules ported against the AVA2 Windows client
- render: D3D8 fixed-function lighting in Gr2ModelRenderer, terrain
  without baked shade; cape/NPC equipment attachment
- tests + audits updated; docs/PORT-PLAN.md and WINDOWS-PARITY.md

Batch 4 (render pipeline: background.*, app.RenderGame/UpdateGame,
camera bindings, main.cpp fake-content removal) is still in progress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 10:43:01 +09:00

64 lines
4.9 KiB
C++

#include "drop_item_state.h"
#include "python_runtime.h"
#include "eter_net/PythonNetworkStream.h"
#include <iostream>
#include <stdexcept>
using namespace ava2;
using Bytes=std::vector<uint8_t>;
void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);}
void u32(Bytes& b,uint32_t value) {for(unsigned i=0;i<4;++i)b.push_back(uint8_t(value>>(8*i)));}
Bytes record(const std::string& name="Wolf") {
Bytes b{220,3};for(unsigned i=0;i<100;++i)b.push_back(i<name.size()?name[i]:0);
u32(b,0x80000001);u32(b,0xffffffff);u32(b,uint32_t(-7));return b;
}
Bytes control(uint8_t sub) {Bytes b(114);b[0]=220;b[1]=sub;return b;}
void send(const Bytes& b) {auto& stream=PythonNetworkStream::Instance();stream.PushRecvData(b);stream.ProcessRecvData();}
int main(int argc,char** argv) {
if(argc!=3)return 2;
try {
{
PythonRuntime python(argv[1],argv[2]);auto& stream=PythonNetworkStream::Instance();stream.ResetConnection();stream.SetPhase(PHASE_GAME);
python.execute(R"PY(import drop_item as drop,net,weakref,gc
assert drop.CountDates()==0 and drop.GetPageActual()==1 and drop.GetPageView()==5
assert drop.GetDates(-1)==('None',0,0,0) and drop.GetDates(0)==('None',0,0,0)
assert drop.GetDates() is None and drop.SearchItem('x') is None
assert drop.SetPageSelect() is None and drop.SetDropItemHandler() is None
class Game:
def __init__(self): self.opens=0
def BINARY_DROP_ITEM_OPEN(self): self.opens+=1
class Loader:
def __init__(self): self.events=[]
def BINARY_DROP_ITEM_LOADING(self): self.events.append((drop.CountDates(),drop.GetPageActual()))
game=Game()
loader=Loader()
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)
drop.SetDropItemHandler(loader)
drop.SetPageSelect(-5)
assert drop.GetPageActual()==-5
)PY");
auto data=record();require(data.size()==114,"drop literal wire size");data.push_back(44);
stream.PushRecvData(data.data(),113);stream.ProcessRecvData();python.execute("assert drop.CountDates()==0\n");
stream.PushRecvData(data.data()+113,2);stream.ProcessRecvData();require(stream.PopSendBytes()==Bytes{254},"drop consumed following ping");
send(record());send(control(5));send(control(2));send(control(255));
python.execute("expected=('Wolf',-2147483647,-1,-7)\nassert drop.CountDates()==2 and drop.GetDates(0)==expected and drop.GetDates(1)==expected\nassert drop.GetDates(0,'ignored')==expected\nassert drop.GetDates(2)==('None',0,0,0)\nassert loader.events==[(2,-5)] and game.opens==1\ndrop.SetPageSelect(2147483649)\nassert drop.GetPageActual()==-2147483647\n");
// The Windows name field is 100 bytes; bound unterminated wire strings.
send(record(std::string(100,'x')));python.execute("assert drop.GetDates(2)==('x'*100,-2147483647,-1,-7)\n");
send(control(4));send(control(5));
python.execute("assert drop.CountDates()==0 and drop.GetPageActual()==1\nassert loader.events==[(2,-5),(0,1)]\ndrop.Open()\ndrop.SearchItem(1)\n");require(stream.PopSendBytes().empty(),"drop request sent without main actor");
SNetworkActorData actor{};actor.m_dwVID=1001;actor.m_stName="DropFixture";NetworkActorManager::Instance().AppendActor(actor);stream.SetMainActorVID(1001);
auto instance=NetworkActorManager::Instance().GetActorInstance(1001);require(bool(instance),"missing native actor");
python.execute("drop.Open()\ndrop.SearchItem(-1)\ndrop.SearchItem(2147483649)\n");
auto packets=stream.PopSendPacketsWithSequence();require(packets.size()==3,"drop request count");
require(packets[0].first==Bytes{215,0,0,0,0,0} && packets[1].first==Bytes{215,1,255,255,255,255} && packets[2].first==Bytes{215,1,1,0,0,128},"drop request Win32 layout");
require(packets[0].second && packets[1].second && packets[2].second,"drop request missing SendSequence");
instance->SetSleep(true);python.execute("drop.Open()\ndrop.SearchItem(0)\n");require(stream.PopSendBytes().empty(),"sleeping actor sent drop request");instance->SetSleep(false);
python.execute("temporary=Loader()\nref=weakref.ref(temporary)\ndrop.SetDropItemHandler(temporary)\ndel temporary\ngc.collect()\nassert ref() is not None\n");
send(control(4));send(control(5));python.execute("assert ref() is not None and ref().events==[(0,1)]\ndrop.SetDropItemHandler(None)\ngc.collect()\nassert ref() is None\nclass Broken:\n def BINARY_DROP_ITEM_LOADING(self): raise ValueError('expected failure')\ndrop.SetDropItemHandler(Broken())\n");
send(record());send(control(5));python.execute("assert drop.CountDates()==1\ndrop.SetPageSelect(99)\n");
require(stream.GetUnportedPackets().empty(),"drop receive still uses skip handler");stream.ResetConnection();
}
{PythonRuntime python(argv[1],argv[2]);python.execute("import drop_item as drop\nassert drop.CountDates()==0 and drop.GetPageActual()==1\n");}
std::cout<<"AVA2 drop item state, wire and Python parity passed\n";
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
}