- 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>
76 lines
6.5 KiB
C++
76 lines
6.5 KiB
C++
#include "dungeon_info_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)));}
|
|
void text(Bytes& b,const std::string& value,size_t width) {for(size_t i=0;i<width;++i)b.push_back(i<value.size()?value[i]:0);}
|
|
Bytes record(uint8_t sub) {
|
|
Bytes b{217,sub};u32(b,uint32_t(-5));text(b,"Dungeon",100);text(b,"image.tga",100);
|
|
for(int32_t v:{20,120,8,-1,int32_t(0x80000001),-10,40})u32(b,uint32_t(v));
|
|
for(const auto* value:{"Portal","Ice","Fire"})text(b,value,100);
|
|
for(int32_t v:{101,2,3,400,5,-6,700,800})u32(b,uint32_t(v));
|
|
u32(b,800);u32(b,2);text(b,"RankHero",24);u32(b,uint32_t(-100));
|
|
for(int32_t v:{900,-2,3,1})u32(b,uint32_t(v));return b;
|
|
}
|
|
Bytes control(uint8_t sub) {Bytes b(618);b[0]=217;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 dungeon_info as dungeon,net
|
|
empty=(0,'None','None',0,0,0,0,0,0,0,'None','None','None',0,0,0,0,0,0,0,0)
|
|
assert dungeon.CountDate()==0 and dungeon.CountDateRanking()==0
|
|
assert dungeon.GetPageView()==13 and dungeon.GetPageCount()==1
|
|
assert dungeon.InfoDate(-1)==empty and dungeon.InfoDate(0)==empty
|
|
assert dungeon.InfoDateMision(-1)==(0,0,0,0) and dungeon.InfoDateRanking(0)==(0,0,'None',0)
|
|
assert dungeon.InfoDate() is None and dungeon.InfoDateRanking() is None and dungeon.InfoDateMision() is None
|
|
assert dungeon.Teleport('x') is None and dungeon.SetPageCount() is None
|
|
class Game:
|
|
def __init__(self): self.events=[]
|
|
def BINARY_TABLE_DUNGEON_INFO_OPEN(self): self.events.append(('open',dungeon.CountDate()))
|
|
def BINARY_TABLE_DUNGEON_RANKING_LOAD(self): self.events.append(('ranking',dungeon.CountDateRanking()))
|
|
def BINARY_TABLE_DUNGEON_MISION_LOAD(self): self.events.append(('mission',dungeon.InfoDateMision(0)))
|
|
game=Game()
|
|
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)
|
|
dungeon.SetPageCount(-2)
|
|
assert dungeon.GetPageCount()==-2
|
|
)PY");
|
|
auto data=record(4);require(data.size()==618,"dungeon literal wire size");data.push_back(44);
|
|
stream.PushRecvData(data.data(),617);stream.ProcessRecvData();python.execute("assert dungeon.CountDate()==0\n");
|
|
stream.PushRecvData(data.data()+617,2);stream.ProcessRecvData();require(stream.PopSendBytes()==Bytes{254},"dungeon consumed following ping");
|
|
send(record(4));send(record(7));send(record(7));send(control(3));send(control(8));send(control(255));
|
|
python.execute(R"PY(expected=(-5,'Dungeon','image.tga',20,120,8,-1,-2147483647,-10,40,'Portal','Ice','Fire',101,2,3,400,5,-6,700,800)
|
|
assert dungeon.CountDate()==2 and dungeon.InfoDate(0)==expected and dungeon.InfoDate(1)==expected
|
|
assert dungeon.InfoDate(0,'ignored')==expected and dungeon.InfoDate(2)==empty
|
|
assert dungeon.CountDateRanking()==2 and dungeon.InfoDateRanking(0)==(800,2,'RankHero',-100)
|
|
assert dungeon.GetPageCount()==-2
|
|
assert game.events==[('open',2),('ranking',2)]
|
|
)PY");
|
|
// Mission-send falls through to ranking-clear in the original switch.
|
|
send(record(11));send(record(11));send(control(12));python.execute("assert dungeon.InfoDateMision(0)==(900,-2,3,1) and dungeon.InfoDateMision(1)==(900,-2,3,1)\nassert dungeon.InfoDateMision(2)==(0,0,0,0) and dungeon.CountDateRanking()==0\nassert game.events[-1]==('mission',(900,-2,3,1))\n");
|
|
send(record(7));send(control(10));python.execute("assert dungeon.InfoDateMision(0)==(0,0,0,0) and dungeon.CountDateRanking()==1\nassert dungeon.CountDate()==2 and dungeon.GetPageCount()==-2\n");
|
|
send(record(11));send(record(7));send(control(5));python.execute("assert dungeon.CountDate()==0 and dungeon.InfoDateMision(0)==(0,0,0,0) and dungeon.GetPageCount()==1\nassert dungeon.CountDateRanking()==1\n");send(control(6));python.execute("assert dungeon.CountDateRanking()==0\n");
|
|
// Fixed strings are bounded even when the server supplies no terminator.
|
|
data=record(4);std::fill(data.begin()+6,data.begin()+106,'x');send(data);
|
|
data=record(7);std::fill(data.begin()+574,data.begin()+598,'y');send(data);
|
|
python.execute("assert dungeon.InfoDate(0)[1]=='x'*100\nassert dungeon.InfoDateRanking(0)[2]=='y'*24\ndungeon.SetPageCount(2147483649)\nassert dungeon.GetPageCount()==-2147483647\ndungeon.Open()\ndungeon.Teleport(1)\ndungeon.Mision(2)\ndungeon.Ranking(3)\n");require(stream.PopSendBytes().empty(),"dungeon request sent without main actor");
|
|
SNetworkActorData actor{};actor.m_dwVID=1001;actor.m_stName="DungeonFixture";NetworkActorManager::Instance().AppendActor(actor);stream.SetMainActorVID(1001);
|
|
auto instance=NetworkActorManager::Instance().GetActorInstance(1001);require(bool(instance),"missing native actor");
|
|
python.execute("dungeon.Open()\ndungeon.Teleport(-1)\ndungeon.Mision(2147483649)\ndungeon.Ranking(3)\n");auto packets=stream.PopSendPacketsWithSequence();require(packets.size()==4,"dungeon request count");
|
|
const std::vector<Bytes> expected{{213,0,0,0,0,0},{213,1,255,255,255,255},{213,2,1,0,0,128},{213,9,3,0,0,0}};
|
|
for(size_t i=0;i<4;++i)require(packets[i].first==expected[i] && packets[i].second,"dungeon Win32 bytes or sequence mismatch");
|
|
instance->SetSleep(true);python.execute("dungeon.Open()\ndungeon.Teleport(1)\ndungeon.Mision(2)\ndungeon.Ranking(3)\n");require(stream.PopSendBytes().empty(),"sleeping actor sent dungeon request");instance->SetSleep(false);
|
|
python.execute("def broken(): raise ValueError('expected callback failure')\ngame.BINARY_TABLE_DUNGEON_INFO_OPEN=broken\n");send(control(3));send(record(4));python.execute("assert dungeon.CountDate()==2\n");
|
|
require(stream.GetUnportedPackets().empty(),"dungeon still routed through skip handler");stream.ResetConnection();
|
|
}
|
|
{PythonRuntime python(argv[1],argv[2]);python.execute("import dungeon_info as dungeon\nassert dungeon.CountDate()==0 and dungeon.CountDateRanking()==0 and dungeon.GetPageCount()==1\nassert dungeon.InfoDateMision(0)==(0,0,0,0)\n");}
|
|
std::cout<<"AVA2 dungeon info state, wire and Python parity passed\n";
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
|
}
|