- 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>
132 lines
11 KiB
C++
132 lines
11 KiB
C++
#include "guild_state.h"
|
|
#include "python_runtime.h"
|
|
#include "python_net.h"
|
|
#include "python_gameplay_modules.h"
|
|
#include "eter_net/PythonNetworkStream.h"
|
|
#include <iostream>
|
|
#include <cstddef>
|
|
#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 v) {for(int i=0;i<4;++i)b.push_back(uint8_t(v>>(8*i)));}
|
|
void u16(Bytes& b,uint16_t v) {b.push_back(uint8_t(v));b.push_back(uint8_t(v>>8));}
|
|
void str(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 pid(uint32_t id) {Bytes b;u32(b,id);return b;}
|
|
Bytes frame(uint8_t sub,const Bytes& b) {Bytes out{75};u16(out,uint16_t(b.size()+4));out.push_back(sub);out.insert(out.end(),b.begin(),b.end());return out;}
|
|
void send(uint8_t sub,const Bytes& b) {auto& net=PythonNetworkStream::Instance();net.PushRecvData(frame(sub,b));net.ProcessRecvData();}
|
|
void member(Bytes& b,uint32_t id,uint8_t grade,uint8_t job,uint8_t level,uint32_t offer,uint8_t general,const char* name) {
|
|
u32(b,id);b.insert(b.end(),{grade,general,job,level});u32(b,offer);b.push_back(name?1:0);if(name)str(b,name,25);
|
|
}
|
|
int main(int argc,char** argv) {
|
|
if(argc!=3)return 2;
|
|
try {
|
|
{
|
|
PythonRuntime python(argv[1],argv[2]);auto& net=PythonNetworkStream::Instance();net.ResetConnection();net.SetPhase(PHASE_GAME);SetMainCharacterName("Hero");
|
|
Character hero;hero.name="Hero";hero.guild_id=7;hero.guild_name="Seven";set_mock_character(0,hero);
|
|
python.execute(R"PY(import guild,net,messenger
|
|
assert (guild.AUTH_ADD_MEMBER,guild.AUTH_REMOVE_MEMBER,guild.AUTH_NOTICE,guild.AUTH_SKILL,guild.ENEMY_GUILD_SLOT_MAX_COUNT)==(1,2,4,8,6)
|
|
assert guild.IsGuildEnable()==0 and guild.HasGuildLand()==0
|
|
assert guild.GetGuildID()==0 and guild.GetGuildName()==''
|
|
assert guild.GetGuildName(99)=='Noname' and guild.GetGuildMasterName()=='Noname'
|
|
assert guild.GetGuildExperience()==(0,0) and guild.GetGuildMemberCount()==(0,0)
|
|
assert guild.GetGuildBoardCommentData(-1)==(0,'Noname','Noname')
|
|
assert guild.GetMemberData(-1)==(-1,'',0,0,0,0,0) and guild.MemberIndexToPID(0)==-1
|
|
assert guild.GetGradeData(1)==('?',0) and guild.GetGradeName(1)=='?'
|
|
assert guild.GuildIDToMarkID(987654321)==-1
|
|
assert guild.GetMemberData() is None and guild.SetSkillIndex() is None
|
|
class Handler:
|
|
def __init__(self): self.events=[]
|
|
def __getattr__(self,name):
|
|
def event(*args): self.events.append((name,)+args)
|
|
return event
|
|
def BINARY_GuildWar_OnStart(self,a,b):
|
|
assert guild.GetEnemyGuildName(0)==''
|
|
self.events.append(('start',a,b))
|
|
def BINARY_GuildWar_OnEnd(self,a,b):
|
|
assert guild.GetEnemyGuildName(0)=='Enemy'
|
|
self.events.append(('end',a,b))
|
|
h=Handler()
|
|
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,h)
|
|
messenger.SetMessengerHandler(h)
|
|
)PY");
|
|
Bytes info;u16(info,2);u16(info,32);u32(info,7);u32(info,11);u32(info,1000);info.push_back(2);str(info,"Seven",13);u32(info,123456);info.push_back(1);send(8,info);
|
|
python.execute("assert guild.IsGuildEnable()==1 and guild.HasGuildLand()==1\nassert guild.GetGuildID()==7 and guild.GetGuildName()=='Seven'\nassert guild.GetGuildLevel()==2 and guild.GetGuildExperience()==(1000,17000)\nassert guild.GetGuildMemberCount()==(2,32) and guild.GetGuildMoney()==123456\nassert h.events==[('RefreshGuildInfoPage',)]\nh.events=[]\n");
|
|
Bytes list;member(list,22,3,2,40,200,0,"Bob");member(list,11,1,0,60,500,1,"Hero");auto packet=frame(2,list);packet.push_back(44);
|
|
net.PushRecvData(packet.data(),packet.size()-2);net.ProcessRecvData();python.execute("assert guild.GetMemberCount()==0 and h.events==[]\n");
|
|
net.PushRecvData(packet.data()+packet.size()-2,2);net.ProcessRecvData();require(net.PopSendBytes()==Bytes{254},"guild list consumed coalesced ping");
|
|
python.execute(R"PY(assert guild.GetGuildMasterName()=='Hero'
|
|
assert guild.GetMemberData(0)==(11,'Hero',1,0,60,500,1)
|
|
assert guild.GetMemberData(1)==(22,'Bob',3,2,40,200,0)
|
|
assert guild.IsMember(0)==1 and guild.IsMember(11)==0
|
|
assert guild.IsMemberByName('Bob')==1 and guild.IsMemberByName('bob')==0
|
|
assert guild.MemberIndexToPID(1)==22
|
|
assert (guild.GetGuildMemberLevelSummary(),guild.GetGuildMemberLevelAverage(),guild.GetGuildExperienceSummary())==(100,50,700)
|
|
assert h.events==[('OnLogout',1,'Bob'),('RefreshTargetBoardByName','Bob'),('RefreshTargetBoardByName','Hero'),('RefreshCharacter',),('RefreshMessenger',),('RefreshGuildInfoPage',),('RefreshGuildMemberPage',)]
|
|
h.events=[]
|
|
net.SendGuildRemoveMemberPacket('Bob')
|
|
)PY");
|
|
require(net.PopSendBytes()==Bytes{80,1,22,0,0,0},"guild removal must resolve name to PID");
|
|
send(0,pid(22));send(1,pid(22));send(0,pid(11));send(0,pid(99));
|
|
python.execute("assert h.events==[('OnLogin',1,'Bob'),('OnLogout',1,'Bob')]\nh.events=[]\n");
|
|
Bytes update;member(update,22,2,4,45,300,1,nullptr);send(2,update);
|
|
python.execute("assert guild.GetMemberData(1)==(22,'Bob',2,2,45,300,1)\nassert guild.GetGuildMemberLevelAverage()==52 and guild.GetGuildExperienceSummary()==800\nh.events=[]\n");
|
|
Bytes grade{2,1};str(grade,"Master",9);grade.push_back(15);grade.push_back(2);str(grade,"Officer",9);grade.push_back(3);send(3,grade);
|
|
python.execute("assert guild.GetGradeData(1)==('Master',15)\nassert guild.MainPlayerHasAuthority(3)==1 and guild.MainPlayerHasAuthority(16)==0\nassert h.events==[('RefreshGuildMemberPageGradeComboBox',),('RefreshGuildGradePage',)]\nh.events=[]\n");
|
|
Bytes rename{1};str(rename,"Leader",9);send(6,rename);send(7,{1,5});
|
|
python.execute("assert guild.GetGradeData(1)==('Leader',5) and guild.MainPlayerHasAuthority(3)==0\nassert h.events==[('RefreshGuildGrade',),('RefreshGuildMemberPageGradeComboBox',),('RefreshGuildGradePage',),('RefreshGuildGrade',),('RefreshGuildGradePage',)]\nh.events=[]\n");
|
|
send(7,{9,255});python.execute("assert guild.GetGradeData(9)==('?',0)\nh.events=[]\n");
|
|
auto change=pid(11);change.push_back(5);send(11,change);change=pid(22);change.push_back(0);send(13,change);
|
|
python.execute("assert guild.MemberIndexToPID(0)==11 and guild.GetMemberData(0)[2]==5\nassert guild.GetMemberData(1)[6]==0\nh.events=[]\n");
|
|
Bytes skills{8,1,2,3,4,5,6,7,8,9,10,11,12};u16(skills,300);u16(skills,600);send(12,skills);
|
|
python.execute(R"PY(assert guild.GetGuildSkillPoint()==8 and guild.GetDragonPowerPoint()==(300,600)
|
|
assert guild.GetGuildSkillLevel(11)==12 and guild.GetGuildSkillLevel(-1)==0
|
|
assert guild.GetSkillLevel(3)==0 and guild.GetSkillIndex(3)==0
|
|
guild.SetSkillIndex(3,7)
|
|
guild.SetSkillIndex(3,2)
|
|
assert guild.GetSkillIndex(3)==7 and guild.GetSkillLevel(3)==8 and guild.GetSkillMaxLevelNew(3)==8
|
|
guild.SetSkillIndex(9,99)
|
|
assert guild.GetSkillLevel(9)==0
|
|
h.events=[]
|
|
)PY");
|
|
Bytes comments{2};u32(comments,101);str(comments,"Hero",25);str(comments,"Notice",51);u32(comments,102);str(comments,"Bob",25);str(comments,"",51);send(9,comments);
|
|
python.execute("assert guild.GetGuildBoardCommentCount()==1 and guild.GetGuildBoardCommentData(0)==(101,'Hero','Notice')\nassert h.events==[('RefreshGuildBoardPage',)]\nh.events=[]\n");
|
|
Bytes exp{19};u32(exp,4000001);send(10,exp);python.execute("assert guild.GetGuildExperience()==(4000001,-1)\n");exp={20};u32(exp,100);send(10,exp);python.execute("assert guild.GetGuildExperience()==(0,0)\n");send(20,pid(0xffffffff));python.execute("assert guild.GetGuildMoney()==-1\nh.events=[]\n");
|
|
Bytes names;u32(names,9);str(names,"Enemy",12);u32(names,9);str(names,"Replacement",12);u32(names,7);str(names,"Seven",12);send(16,names);python.execute("assert guild.GetGuildName(9)=='Enemy'\n");
|
|
Bytes invite=pid(7);str(invite,"ABCDEFGHIJKL",12);send(14,invite);
|
|
Bytes war=pid(7);u32(war,9);war.push_back(2);war.push_back(1);send(15,war);war.back()=3;send(15,war);war.back()=6;send(15,war);python.execute("assert guild.GetEnemyGuildName(0)=='Enemy'\n");war.back()=7;send(15,war);
|
|
Bytes point=pid(7);u32(point,9);u32(point,uint32_t(-3));send(19,point);
|
|
python.execute("assert guild.GetEnemyGuildName(0)==''\nassert h.events==[('RecvGuildInviteQuestion',7,'ABCDEFGHIJKL'),('BINARY_GuildWar_OnSendDeclare',9),('BINARY_GuildWar_OnRecvDeclare',9,2),('start',7,9),('end',7,9),('BINARY_GuildWar_OnRecvPoint',7,9,-3)]\nh.events=[]\n");
|
|
Bytes pair=pid(7);u32(pair,9);send(17,pair);require(NetworkActorManager::Instance().FindGVGKey(9,7),"missing symmetric guild war key");send(18,pair);require(!NetworkActorManager::Instance().FindGVGKey(7,9),"guild war end key not removed");
|
|
send(5,pid(22));python.execute("assert guild.GetMemberCount()==1 and guild.GetGuildExperienceSummary()==800\nassert h.events==[('OnRemoveList',1,'Bob'),('RefreshTargetBoardByName','Bob'),('RefreshGuildMemberPage',)]\nh.events=[]\n");
|
|
// Main actor updates synchronize net.GetGuildID and the account roster.
|
|
net.SetMainActorVID(123);
|
|
Bytes actorUpdate(sizeof(TPacketGCCharacterUpdate),0);actorUpdate[0]=HEADER_GC_CHARACTER_UPDATE;
|
|
const auto put=[&](size_t offset,uint32_t value) {for(unsigned i=0;i<4;++i)actorUpdate[offset+i]=uint8_t(value>>(8*i));};
|
|
put(offsetof(TPacketGCCharacterUpdate,dwVID),123);put(offsetof(TPacketGCCharacterUpdate,dwGuildID),7);
|
|
net.PushRecvData(actorUpdate);net.ProcessRecvData();
|
|
python.execute("assert net.GetGuildID()==7\nassert net.GetAccountCharacterSlotDataInteger(0,12)==7\nassert net.GetAccountCharacterSlotDataString(0,13)=='Seven'\n");
|
|
send(5,pid(11));
|
|
python.execute(R"PY(assert guild.IsGuildEnable()==0 and guild.GetGuildID()==0 and net.GetGuildID()==0
|
|
assert net.GetAccountCharacterSlotDataInteger(0,12)==0 and net.GetAccountCharacterSlotDataString(0,13)==''
|
|
assert guild.GetGuildBoardCommentCount()==1 and guild.GetGuildExperienceSummary()==800
|
|
assert guild.GetSkillIndex(3)==7
|
|
assert h.events==[('DeleteGuild',),('OnRemoveAllList',1),('RefreshTargetBoard',),('RefreshCharacter',),('RefreshMessenger',)]
|
|
guild.Destroy()
|
|
assert guild.GetSkillIndex(3)==0
|
|
assert guild.GetGuildBoardCommentCount()==1 and guild.GetGuildExperienceSummary()==800
|
|
h.events=[]
|
|
)PY");
|
|
// Original ADD/unknown subheaders do not consume their payload.
|
|
send(4,{44});require(net.PopSendBytes()==Bytes{254},"unknown guild subheader handling changed");
|
|
// Reject a truncated member record without reading into the next frame.
|
|
auto bad=frame(2,{1});bad.push_back(44);net.PushRecvData(bad);net.ProcessRecvData();require(net.PopSendBytes().empty(),"bad guild list consumed next frame");
|
|
python.execute("assert guild.GetMemberCount()==0 and h.events==[]\n");
|
|
auto& g=GetGuildState();for(uint32_t i=1;i<=7;++i)g.StartWar(i);require(g.enemies[5]==6,"six enemy slot cap changed");g.EndWar(2);g.StartWar(8);require(g.enemies[1]==8 && g.enemies[2]==3,"enemy slot reuse compacted list");
|
|
net.ResetConnection();
|
|
}
|
|
{PythonRuntime python(argv[1],argv[2]);python.execute("import guild\nassert guild.GetGuildBoardCommentCount()==0 and guild.GetGuildExperienceSummary()==0\nassert guild.GetMemberCount()==0\n");}
|
|
std::cout<<"AVA2 guild state, wire and Python parity passed\n";
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
|
}
|