- 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
5.3 KiB
C++
76 lines
5.3 KiB
C++
#include "battlepass_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(uint8_t sub) {
|
|
Bytes b{230,sub};u32(b,uint32_t(-100));u32(b,0x80000001);u32(b,0xffffffff);u32(b,uint32_t(-10));u32(b,50);u32(b,0xffffffff);
|
|
for(unsigned i=0;i<4;++i) {u32(b,100+i);u32(b,i==3?0x80000001:i+1);}
|
|
return b;
|
|
}
|
|
Bytes control(uint8_t sub) {Bytes b(58);b[0]=230;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 battlepass as bp,net,weakref,gc
|
|
assert bp.CountDates()==0 and bp.GetTime()==0
|
|
assert bp.GetDates(-1)==(0,0) and bp.GetDatesCount(0)==(0,0,0)
|
|
assert bp.GetDatesItems(0,0)==0
|
|
assert bp.GetDates() is None and bp.GetDatesItems(0) is None
|
|
assert bp.Reward('x') is None and bp.SetBattlePassHandler() is None
|
|
class Game:
|
|
def __init__(self): self.events=[]
|
|
def BINARY_BATTLEPASS_OPEN(self): self.events.append('open')
|
|
def BINARY_BATTLEPASS_MP(self): self.events.append('mp')
|
|
class Loader:
|
|
def __init__(self): self.events=[]
|
|
def BINARY_BATTLEPASS_LOADING(self,sub):
|
|
self.events.append((sub,bp.CountDates(),bp.GetDatesCount(0),bp.GetTime()))
|
|
game=Game()
|
|
loader=Loader()
|
|
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)
|
|
bp.SetBattlePassHandler(loader)
|
|
)PY");
|
|
auto data=record(2);require(data.size()==58,"battlepass literal wire size");data.push_back(44);
|
|
stream.PushRecvData(data.data(),57);stream.ProcessRecvData();python.execute("assert bp.CountDates()==0\n");
|
|
stream.PushRecvData(data.data()+57,2);stream.ProcessRecvData();require(stream.PopSendBytes()==Bytes{254},"battlepass consumed following ping");
|
|
send(record(2));send(record(7));send(record(7));send(record(3));send(control(4));send(control(8));send(control(0));send(control(9));
|
|
python.execute(R"PY(assert bp.CountDates()==2
|
|
assert bp.GetDates(0)==(-2147483647,-1) and bp.GetDates(1)==bp.GetDates(0)
|
|
assert bp.GetDates(2)==(0,0)
|
|
assert bp.GetDatesCount(0)==(-10,50,-1) and bp.GetDatesCount(1)==bp.GetDatesCount(0)
|
|
assert bp.GetDatesCount(2)==(0,0,0)
|
|
assert bp.GetDatesItems(0,0)==(100,1) and bp.GetDatesItems(0,3)==(103,-2147483647)
|
|
assert bp.GetDatesItems(0,4)==(0,0) and bp.GetDatesItems(0,-1)==(0,0)
|
|
assert bp.GetDatesItems(-1,4)==0
|
|
assert bp.GetTime()==-100
|
|
assert loader.events==[(4,2,(-10,50,-1),-100),(8,2,(-10,50,-1),-100)]
|
|
assert game.events==['open','mp']
|
|
)PY");
|
|
send(control(6));python.execute("assert bp.CountDates()==2 and bp.GetTime()==-100\nassert bp.GetDatesCount(0)==(0,0,0)\n");
|
|
send(record(7));send(control(1));send(control(255));send(control(5));send(control(8));
|
|
python.execute("assert bp.CountDates()==0 and bp.GetTime()==0\nassert bp.GetDatesCount(0)==(-10,50,-1)\nassert loader.events[-1]==(8,0,(-10,50,-1),0)\nbp.Open()\nbp.Reward(1)\n");require(stream.PopSendBytes().empty(),"battlepass sent without actionable main actor");
|
|
SNetworkActorData actor{};actor.m_dwVID=1001;actor.m_stName="BattlePassFixture";NetworkActorManager::Instance().AppendActor(actor);stream.SetMainActorVID(1001);
|
|
auto instance=NetworkActorManager::Instance().GetActorInstance(1001);require(bool(instance),"missing native actor");
|
|
python.execute("bp.Open()\nbp.Reward(-1)\nbp.Reward(2147483649)\n");
|
|
auto packets=stream.PopSendPacketsWithSequence();require(packets.size()==3,"battlepass request count");
|
|
require(packets[0].first==Bytes{230,0,0,0,0,0} && packets[1].first==Bytes{230,5,255,255,255,255} && packets[2].first==Bytes{230,5,1,0,0,128},"battlepass request Win32 byte conversion");
|
|
require(packets[0].second && packets[1].second && packets[2].second,"battlepass missing SendSequence");
|
|
instance->SetSleep(true);python.execute("bp.Open()\nbp.Reward(0)\n");require(stream.PopSendBytes().empty(),"sleeping actor sent battlepass request");instance->SetSleep(false);
|
|
python.execute("temporary=Loader()\nref=weakref.ref(temporary)\nbp.SetBattlePassHandler(temporary)\ndel temporary\ngc.collect()\nassert ref() is not None\n");
|
|
send(control(1));send(control(6));python.execute("assert ref() is not None\nbp.SetBattlePassHandler(None)\ngc.collect()\nassert ref() is None\nclass Broken:\n def BINARY_BATTLEPASS_LOADING(self,*args): raise ValueError('expected failure')\nbp.SetBattlePassHandler(Broken())\n");
|
|
send(record(2));send(control(4));python.execute("assert bp.CountDates()==1\n");
|
|
require(stream.GetUnportedPackets().empty(),"battlepass still routed through skip handler");stream.ResetConnection();
|
|
}
|
|
{PythonRuntime python(argv[1],argv[2]);python.execute("import battlepass as bp\nassert bp.CountDates()==0 and bp.GetTime()==0 and bp.GetDatesCount(0)==(0,0,0)\n");}
|
|
std::cout<<"AVA2 battlepass state, wire and Python parity passed\n";
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
|
}
|