Net: port the select-phase packets

Character create/delete/rename and empire selection now reach the
server, and LOGIN_SUCCESS3, PLAYER_CREATE_SUCCESS/FAILURE,
PLAYER_DELETE_SUCCESS/WRONG_SOCIAL_ID, POINT_CHANGE and CHANGE_NAME are
parsed and forwarded to the select/create windows like Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-13 13:27:52 +09:00
co-authored by Claude Opus 5.5
parent 40cac5cf52
commit 31c74cec28
10 changed files with 205 additions and 15 deletions
+2
View File
@@ -1727,6 +1727,8 @@ P0, the real-server flow stops:
On the real server, `net.SendCreateCharacterPacket`/`SendDestroyCharacterPacket` raise NotImplementedError, and `SendSelectEmpirePacket`/`SendChangeNamePacket` send nothing.
- **Fixed:** `LoginSession` parses GC 6/8/9/10/11/17/107 in LoggingIn/Selecting/Entering (17 is dropped like Windows) and queues `SelectResult`s; `pump_python_net` turns them into OnCreateSuccess (create window), OnCreateFailure (create + select), OnDeleteSuccess/OnDeleteFailure/OnChangeName (select). The four senders build the original struct images (`wire::create_character`/`destroy_character`/`select_empire`/`change_name`, checked against Packet.h in `login_oracle_test`); a failed Send only logs, and the empire is stored after a successful Send.
P1, visible gameplay:
4. `ParseRaceMotionData` ignores `motioneventdata` in .msa files (effect, effect-to-target, fly, screen waving/flashing, special attack, character show/hide). Per-motion .mss sound scripts are not loaded either. On the real server, skills and attacks show no effects and play no swing, footstep, hit or death sounds.
5. `RecvDamageInfoPacket` and fly-target hits always spawn `warrior/effect/gihyeol_spark.mse` and play `sound/ui/punch.wav`. These are invented. Windows uses the race-registered hit effects (chrmgr EFFECT_HIT…) and the damage-number effects.
+5
View File
@@ -131,6 +131,7 @@ bool LoginClient::advance() {
}
if(on_game_ && session_->handshake_phase_entered() && !handshake_notified_) { handshake_notified_=true;if(!direct_enter_) notify(EventType::Handshake); }
if(on_game_ && session_->game_login_sent() && !login_notified_) { login_notified_=true;if(!direct_enter_) notify(EventType::LoginStart); }
for(auto& result:session_->take_select_results()) { notify(EventType::SelectResult);events_.back().result=std::move(result); }
// __RecvLoginSuccessPacket4 in SelectPhase: PHASE_WINDOW_SELECT.Refresh.
if(session_->state()==LoginSession::State::Selecting && selection_notified_ && !direct_enter_ && session_->roster_version()!=roster_version_)
notify(EventType::SelectRefresh);
@@ -186,6 +187,10 @@ void LoginClient::reconnect(std::uint32_t wire_address,std::uint16_t port,std::u
deadline_=std::chrono::steady_clock::now()+std::chrono::seconds(15);
start_endpoint({host,port});
}
void LoginClient::send_select_packet(wire::Bytes packet) {
if(!session_ || status_!=Status::Selecting) throw std::logic_error("not in the select phase");
session_->send_select_packet(std::move(packet));enqueue();flush();
}
void LoginClient::select(std::uint8_t slot) {
if(!session_) throw std::logic_error("not connected");session_->select(slot);selected_slot_=slot;status_=Status::Entering;deadline_=std::chrono::steady_clock::now()+std::chrono::seconds(15);enqueue();
}
+5 -2
View File
@@ -9,8 +9,8 @@ class LoginClient {
public:
struct Endpoint { std::string host; int port=0; };
enum class Status { Idle, Resolving, Connecting, Authenticating, Selecting, Entering, Loading, Failed };
enum class EventType { Handshake, RemoteDisconnect, LoginStart, SelectReady, SelectRefresh, DirectEnterReady, Loading, Failure };
struct Event { EventType type; std::string reason; bool connection_failure=false; std::uint64_t generation=0; };
enum class EventType { Handshake, RemoteDisconnect, LoginStart, SelectReady, SelectRefresh, SelectResult, DirectEnterReady, Loading, Failure };
struct Event { EventType type; std::string reason; bool connection_failure=false; std::uint64_t generation=0; ava2::SelectResult result{}; };
LoginClient()=default;
~LoginClient();
LoginClient(const LoginClient&)=delete;
@@ -20,6 +20,9 @@ public:
void pump(); // no blocking socket operation or DNS lookup on the caller thread
void update_player_guild(const std::string& player,uint32_t id,const std::string& name) {if(session_)session_->update_player_guild(player,id,name);}
void select(std::uint8_t slot);
// SendCreateCharacterPacket/SendDestroyCharacterPacket/SendSelectEmpirePacket/SendChangeNamePacket.
void send_select_packet(wire::Bytes packet);
void set_empire(std::uint8_t empire) { if(session_) session_->set_empire(empire); }
void direct_enter(std::uint8_t slot);
// CPythonNetworkStream::RecvWarpPacket: __DirectEnterMode_Set(m_dwSelectedCharacterIndex, true) + Connect(lAddr, wPort).
void warp(std::uint32_t address,std::uint16_t port);
+58 -9
View File
@@ -13,6 +13,18 @@ void text(Bytes& out,const std::string& value,std::size_t max) {
std::string string_at(std::span<const std::uint8_t> b,std::size_t offset,std::size_t width) {
auto end=std::find(b.begin()+offset,b.begin()+offset+width,0); return {b.begin()+offset,end};
}
// TSimplePlayerInformation (70 bytes, sash + conqueror fields enabled).
Character read_player(std::span<const std::uint8_t> packet,std::size_t o) {
Character c;
c.id=read32(packet,o);c.name=string_at(packet,o+4,25);c.job=packet[o+29];c.level=packet[o+30];
c.play_minutes=read32(packet,o+31);c.strength=packet[o+35];c.health=packet[o+36];c.dexterity=packet[o+37];c.intelligence=packet[o+38];
c.main_part=packet[o+39]|(std::uint16_t(packet[o+40])<<8);c.change_name=packet[o+41];
c.hair_part=packet[o+42]|(std::uint16_t(packet[o+43])<<8);c.sash_part=packet[o+44]|(std::uint16_t(packet[o+45])<<8);
for(std::size_t j=0;j<4;++j) c.sungma[j]=packet[o+66+j];
c.x=static_cast<std::int32_t>(read32(packet,o+50));c.y=static_cast<std::int32_t>(read32(packet,o+54));
c.address=read32(packet,o+58);c.port=packet[o+62]|(std::uint16_t(packet[o+63])<<8);c.skill_group=packet[o+64];c.conqueror_level=packet[o+65];
return c;
}
}
LoginSession::LoginSession(std::string account,std::string password,Key client)
:account_(std::move(account)),password_(std::move(password)),client_key_(client),receive_key_(derive_receive_key(client)),tx_(locale_key()),rx_(locale_key()) {
@@ -74,6 +86,13 @@ bool LoginSession::process_packet() {
break;
case 150:size=6;break; case 7:size=10;break; case 90:size=2;break;
case 32:size=444;break; // 5 * (70-byte player + 4-byte guild id + 13-byte guild name) + 9
// SelectPhase (PythonNetworkStreamPhaseSelect.cpp)
case 6:size=270;break; // LOGIN_SUCCESS3: 3 * (70 + 4 + 13) + 9
case 8:size=72;break; // PLAYER_CREATE_SUCCESS: slot + TSimplePlayerInformation
case 9: case 10:size=2;break; // PLAYER_CREATE_FAILURE(bType) / PLAYER_DELETE_SUCCESS(account_index)
case 11:size=1;break; // PLAYER_DELETE_WRONG_SOCIAL_ID (TPacketGCBlank)
case 17:size=25;break; // PLAYER_POINT_CHANGE (int header): received and dropped
case 107:size=30;break; // CHANGE_NAME: pid + name[25]
default:
if(state_==State::Entering) {
state_=State::Loading;
@@ -121,17 +140,43 @@ bool LoginSession::process_packet() {
++roster_version_;
characters_.clear();
for(std::size_t i=0;i<5;++i) {
std::size_t o=1+i*70; Character c;
c.id=read32(packet,o);c.name=string_at(packet,o+4,25);c.job=packet[o+29];c.level=packet[o+30];
c.play_minutes=read32(packet,o+31);c.strength=packet[o+35];c.health=packet[o+36];c.dexterity=packet[o+37];c.intelligence=packet[o+38];
c.main_part=packet[o+39]|(std::uint16_t(packet[o+40])<<8);c.change_name=packet[o+41];
c.hair_part=packet[o+42]|(std::uint16_t(packet[o+43])<<8);c.sash_part=packet[o+44]|(std::uint16_t(packet[o+45])<<8);
c.guild_id=read32(packet,351+i*4);c.guild_name=string_at(packet,371+i*13,13);
for(std::size_t j=0;j<4;++j) c.sungma[j]=packet[o+66+j];
c.x=static_cast<std::int32_t>(read32(packet,o+50));c.y=static_cast<std::int32_t>(read32(packet,o+54));
c.address=read32(packet,o+58);c.port=packet[o+62]|(std::uint16_t(packet[o+63])<<8);c.skill_group=packet[o+64];c.conqueror_level=packet[o+65];characters_.push_back(std::move(c));
auto c=read_player(packet,1+i*70);
c.guild_id=read32(packet,351+i*4);c.guild_name=string_at(packet,371+i*13,13);characters_.push_back(std::move(c));
}
roster_received_=true; if(select_phase_received_) state_=State::Selecting;
} else if(header==6) {
// __RecvLoginSuccessPacket3: only the first PLAYER_PER_ACCOUNT3 slots are overwritten.
if(!game_ || (state_!=State::LoggingIn && state_!=State::Selecting)) { fail("character roster in wrong state"); return false; }
++roster_version_;characters_.resize(5);
for(std::size_t i=0;i<3;++i) {
auto c=read_player(packet,1+i*70);
c.guild_id=read32(packet,211+i*4);c.guild_name=string_at(packet,223+i*13,13);characters_[i]=std::move(c);
}
roster_received_=true; if(select_phase_received_) state_=State::Selecting;
} else if(header==8 || header==9 || header==10 || header==11 || header==17 || header==107) {
if(!game_ || (state_!=State::LoggingIn && state_!=State::Selecting && state_!=State::Entering)) { fail("select packet in wrong state"); return false; }
if(header==8) {
// __RecvPlayerCreateSuccessPacket: m_akSimplePlayerInfo only; guild id/name stay.
auto slot=packet[1];
if(slot<characters_.size()) {
auto c=read_player(packet,2);c.guild_id=characters_[slot].guild_id;c.guild_name=characters_[slot].guild_name;
characters_[slot]=std::move(c);
select_results_.push_back({SelectResult::Kind::CreateSuccess});
}
} else if(header==9) select_results_.push_back({SelectResult::Kind::CreateFailure,packet[1]});
else if(header==10) {
auto slot=packet[1];
if(slot<characters_.size()) characters_[slot]=Character{};
select_results_.push_back({SelectResult::Kind::DeleteSuccess,slot});
} else if(header==11) select_results_.push_back({SelectResult::Kind::DeleteFailure});
else if(header==107) {
auto pid=read32(packet,1);auto name=string_at(packet,5,25);
auto it=std::find_if(characters_.begin(),characters_.end(),[&](const Character& c) { return c.id==pid; });
if(it!=characters_.end()) {
it->change_name=0;it->name=name;
select_results_.push_back({SelectResult::Kind::ChangeName,int(it-characters_.begin()),name});
} else select_results_.push_back({SelectResult::Kind::CreateFailure,100});
}
} else if(header==90) {
if(!game_ || (state_!=State::LoggingIn && state_!=State::Selecting)) fail("empire packet in wrong state");
else empire_=packet[1];
@@ -148,6 +193,10 @@ void LoginSession::send_game_packet(wire::Bytes packet,bool sequence) {
if(packet.empty() || packet.size()>65535) throw std::invalid_argument("invalid game packet size");
emit(std::move(packet),sequence);
}
void LoginSession::send_select_packet(wire::Bytes packet) {
if(state_!=State::Selecting) throw std::logic_error("select packet outside the select phase");
emit(std::move(packet),true);
}
void LoginSession::select(std::uint8_t slot) {
if(state_!=State::Selecting) throw std::logic_error("selection requires character roster and select phase");
if(slot>=characters_.size() || characters_[slot].id==0) throw std::invalid_argument("cannot select an empty character slot");
+11
View File
@@ -12,6 +12,12 @@ struct Character {
std::array<std::uint8_t,4> sungma{};
std::int32_t x=0,y=0; std::uint32_t address=0; std::uint16_t port=0;
};
// SelectPhase results for the Python phase windows (OnCreateSuccess/OnCreateFailure/OnDeleteSuccess/
// OnDeleteFailure/OnChangeName).
struct SelectResult {
enum class Kind { CreateSuccess, CreateFailure, DeleteSuccess, DeleteFailure, ChangeName } kind;
int value=0; std::string name;
};
class LoginSession {
public:
enum class State { Handshake, Authenticating, Authenticated, LoggingIn, Selecting, Entering, Loading, Failed };
@@ -27,6 +33,10 @@ public:
for(auto& c:characters_)if(c.name==player) {c.guild_id=id;c.guild_name=name;}
}
void select(std::uint8_t slot);
// SelectPhase senders: Send(...) + SendSequence() on the select connection.
void send_select_packet(wire::Bytes packet);
void set_empire(std::uint8_t empire) { empire_=empire; } // SendSelectEmpirePacket: SetEmpireID
std::vector<SelectResult> take_select_results() { auto r=std::move(select_results_);select_results_.clear();return r; }
// Windows networkmodule.py: net.SetTCPRecvBufferSize(128*1024). A full buffer pauses recv() (restSize<=0).
static constexpr std::size_t kRecvBufferSize=128*1024;
std::size_t receive_space() const { return kRecvBufferSize-(raw_.size()+plain_.size()); }
@@ -68,6 +78,7 @@ private:
wire::Bytes raw_,plain_;
std::vector<wire::Bytes> output_;
std::vector<Character> characters_;
std::vector<SelectResult> select_results_;
std::vector<wire::Bytes> pack_metadata_;
};
}
+33
View File
@@ -1,5 +1,6 @@
#include "protocol.h"
#include "eter_net/Packet.h"
#include <algorithm>
#include <stdexcept>
#include <cstring>
@@ -19,6 +20,38 @@ Bytes select_character(std::uint8_t slot) {
return {HEADER_CG_CHARACTER_SELECT, slot};
}
namespace {
// strncpy into a zeroed char[width]: at most width-1 bytes keep the terminator (CHARACTER_NAME_MAX_LEN+1 field).
void fixed(Bytes& out, const std::string& value, std::size_t width, std::size_t copy) {
auto start=out.size(); out.resize(start+width,0);
std::copy_n(value.begin(), std::min({value.size(), copy, width}), out.begin()+start);
}
}
Bytes create_character(std::uint8_t slot, const std::string& name, std::uint16_t job, std::uint8_t shape,
std::uint8_t con, std::uint8_t intelligence, std::uint8_t str, std::uint8_t dex) {
Bytes out{HEADER_CG_PLAYER_CREATE, slot};
// strncpy(name, name, CHARACTER_NAME_MAX_LEN): the 25th byte stays 0.
fixed(out, name, CHARACTER_NAME_MAX_LEN+1, CHARACTER_NAME_MAX_LEN);
u16(out, job);
out.insert(out.end(), {shape, con, intelligence, str, dex});
return out;
}
Bytes destroy_character(std::uint8_t slot, const std::string& private_code) {
Bytes out{HEADER_CG_PLAYER_DESTROY, slot};
fixed(out, private_code, 8, 8-1); // strncpy(szPrivateCode, code, PRIVATE_CODE_LENGTH-1)
return out;
}
Bytes select_empire(std::uint8_t empire) { return {HEADER_CG_EMPIRE, empire}; }
Bytes change_name(std::uint8_t slot, const std::string& name) {
Bytes out{HEADER_CG_CHANGE_NAME, slot};
fixed(out, name, CHARACTER_NAME_MAX_LEN+1, CHARACTER_NAME_MAX_LEN);
return out;
}
Bytes attack(std::uint8_t type, std::uint32_t victim, std::uint8_t process_crc, std::uint8_t file_crc) {
Bytes out{HEADER_CG_ATTACK, type};
u32(out, victim);
+6
View File
@@ -8,6 +8,12 @@ using Bytes = std::vector<std::uint8_t>;
// AVA2 Packet.h, packed Win32 wire format. Independent from host ABI.
Bytes select_character(std::uint8_t slot);
// CPythonNetworkStream SelectPhase senders (TPacketCGCreateCharacter/DestroyCharacter/Empire/ChangeName).
Bytes create_character(std::uint8_t slot, const std::string& name, std::uint16_t job, std::uint8_t shape,
std::uint8_t con, std::uint8_t intelligence, std::uint8_t str, std::uint8_t dex);
Bytes destroy_character(std::uint8_t slot, const std::string& private_code);
Bytes select_empire(std::uint8_t empire);
Bytes change_name(std::uint8_t slot, const std::string& name);
Bytes attack(std::uint8_t type, std::uint32_t victim, std::uint8_t process_crc = 0, std::uint8_t file_crc = 0);
Bytes pickup(std::uint32_t vid);
Bytes character_move(std::uint8_t func, std::uint8_t arg, std::uint8_t rot, std::int32_t x, std::int32_t y, std::uint32_t time);
+34 -2
View File
@@ -580,12 +580,23 @@ PyObject* net_warp(PyObject*, PyObject*) {
Py_RETURN_NONE;
}
// CPythonNetworkStream::Send* on the select connection; Windows only traces a failed Send.
void send_select_packet(const char* what,wire::Bytes packet) {
try { client.send_select_packet(std::move(packet)); }
catch(const std::exception& e) { SDL_Log("%s - Error: %s",what,e.what()); }
}
PyObject* send_create_character(PyObject*, PyObject* args) {
if(!has_mock_characters) { PyErr_SetString(PyExc_NotImplementedError,"AVA2 character creation server exchange has not been ported");return nullptr; }
int slot = 0, race = 0, shape = 0, con = 0, i_stat = 0, str = 0, dex = 0;
char* name = nullptr;
if (!PyArg_ParseTuple(args, "isiiiiii", &slot, &name, &race, &shape, &con, &i_stat, &str, &dex))
return nullptr;
if(!has_mock_characters) {
// netSendCreateCharacterPacket: (BYTE) index/job/shape and the four stats.
send_select_packet("Failed to SendCreateCharacterPacket",wire::create_character(std::uint8_t(slot),name,std::uint8_t(race),std::uint8_t(shape),
std::uint8_t(con),std::uint8_t(i_stat),std::uint8_t(str),std::uint8_t(dex)));
Py_RETURN_NONE;
}
if (slot >= 0 && slot < 5) {
Character chr;
@@ -613,11 +624,14 @@ PyObject* send_create_character(PyObject*, PyObject* args) {
}
PyObject* send_destroy_character(PyObject*, PyObject* args) {
if(!has_mock_characters) { PyErr_SetString(PyExc_NotImplementedError,"AVA2 character deletion server exchange has not been ported");return nullptr; }
int slot = 0;
char* privateCode = nullptr;
if (!PyArg_ParseTuple(args, "is", &slot, &privateCode))
return nullptr;
if(!has_mock_characters) {
send_select_packet("SendDestroyCharacterPacket",wire::destroy_character(std::uint8_t(slot),privateCode));
Py_RETURN_NONE;
}
if (slot >= 0 && slot < 5) {
mock_characters[slot] = Character{};
@@ -975,6 +989,10 @@ static PyObject* net_SendSelectEmpirePacket(PyObject*, PyObject* poArgs) {
int iEmpireIndex = 0;
if (!PyTuple_GetInteger(poArgs, 0, &iEmpireIndex))
return Py_BuildException();
if(has_mock_characters) { set_mock_empire(std::uint8_t(iEmpireIndex));return Py_BuildNone(); }
// SendSelectEmpirePacket: the empire id is kept locally only after a successful Send.
try { client.send_select_packet(wire::select_empire(std::uint8_t(iEmpireIndex)));client.set_empire(std::uint8_t(iEmpireIndex)); }
catch(const std::exception& e) { SDL_Log("SendSelectEmpirePacket - Error: %s",e.what()); }
return Py_BuildNone();
}
@@ -983,6 +1001,7 @@ static PyObject* net_SendChangeNamePacket(PyObject*, PyObject* poArgs) {
char* szName = nullptr;
if (!PyTuple_GetInteger(poArgs, 0, &iIndex) || !PyTuple_GetString(poArgs, 1, &szName))
return Py_BuildException();
if(!has_mock_characters) send_select_packet("Failed to SendChangeNamePacket",wire::change_name(std::uint8_t(iIndex),szName));
return Py_BuildNone();
}
@@ -1410,6 +1429,19 @@ void pump_python_net() {
callback(handler, client.session()->empire() ? "SetSelectCharacterPhase" : "SetSelectEmpirePhase");
if(event.generation == client.generation()) callback(phases[2], "Refresh");
} else if(event.type == LoginClient::EventType::SelectRefresh) callback(phases[2], "Refresh");
else if(event.type == LoginClient::EventType::SelectResult) {
// PHASE_WINDOW_SELECT=2, PHASE_WINDOW_CREATE=3 (PythonNetworkStreamPhaseSelect.cpp).
const auto& r=event.result;
switch(r.kind) {
case SelectResult::Kind::CreateSuccess: callback(phases[3],"OnCreateSuccess");break;
case SelectResult::Kind::CreateFailure:
PyCallClassMemberFunc(phases[3],"OnCreateFailure",Py_BuildValue("(i)",r.value));
PyCallClassMemberFunc(phases[2],"OnCreateFailure",Py_BuildValue("(i)",r.value));break;
case SelectResult::Kind::DeleteSuccess: PyCallClassMemberFunc(phases[2],"OnDeleteSuccess",Py_BuildValue("(i)",r.value));break;
case SelectResult::Kind::DeleteFailure: callback(phases[2],"OnDeleteFailure");break;
case SelectResult::Kind::ChangeName: PyCallClassMemberFunc(phases[2],"OnChangeName",Py_BuildValue("(is)",r.value,r.name.c_str()));break;
}
}
else if(event.type == LoginClient::EventType::DirectEnterReady) callback(handler, "SetLoadingPhase");
else if(event.type == LoginClient::EventType::Loading) {
PythonNetworkStream::Instance().SetPhase(PHASE_LOADING);
+39
View File
@@ -1,6 +1,7 @@
#include "legacy_cipher.h"
#include "login_session.h"
#include "login_oracle.h"
#include "protocol.h"
#include <array>
#include <cstddef>
#include <iostream>
@@ -14,6 +15,9 @@ int main() {
static_assert(sizeof(server::TPacketGCLoginSuccess)==444);
static_assert(offsetof(client::TSimplePlayerInformation,x)==50);
static_assert(offsetof(client::TSimplePlayerInformation,byConquerorLevel)==65);
static_assert(sizeof(client::TPacketGCLoginSuccess3)==270 && offsetof(client::TPacketGCLoginSuccess3,guild_id)==211 && offsetof(client::TPacketGCLoginSuccess3,guild_name)==223);
static_assert(sizeof(client::TPacketGCPlayerCreateSuccess)==72 && sizeof(client::TPacketGCPointChange)==25 && sizeof(client::TPacketGCChangeName)==30);
static_assert(sizeof(client::TPacketCGCreateCharacter)==34 && sizeof(client::TPacketCGDestroyCharacter)==10 && sizeof(client::TPacketCGChangeName)==27);
std::mt19937 random(914);
for(int n=0;n<512;++n) {
ava2::wire::Key key{};for(auto& word:key) word=random();
@@ -77,6 +81,41 @@ int main() {
if(valid.state()!=ava2::LoginSession::State::Selecting || valid.characters()[0].id!=11) return 17;
valid.feed(ava2::wire::encrypt(ava2::wire::Bytes(payload.begin()+2,payload.end()),rx));
if(valid.state()!=ava2::LoginSession::State::Selecting || valid.roster_version()!=version+1) return 18;
// SelectPhase senders: original struct images plus the sequence byte.
{
client::TPacketCGCreateCharacter create{};create.header=4;create.index=2;std::strncpy(create.name,"Fixture Ninja",24);
create.job=1;create.shape=1;create.CON=3;create.INT=4;create.STR=5;create.DEX=6;
auto bytes=ava2::wire::create_character(2,"Fixture Ninja",1,1,3,4,5,6);
if(bytes.size()!=sizeof(create) || std::memcmp(bytes.data(),&create,sizeof(create))) return 20;
client::TPacketCGDestroyCharacter destroy{};destroy.header=5;destroy.index=1;std::strncpy(destroy.szPrivateCode,"12345678",7);
bytes=ava2::wire::destroy_character(1,"12345678");
if(bytes.size()!=sizeof(destroy) || std::memcmp(bytes.data(),&destroy,sizeof(destroy))) return 21;
client::TPacketCGChangeName rename{};rename.header=106;rename.index=0;std::strncpy(rename.name,"Renamed",24);
bytes=ava2::wire::change_name(0,"Renamed");
if(bytes.size()!=sizeof(rename) || std::memcmp(bytes.data(),&rename,sizeof(rename))) return 22;
valid.send_select_packet(ava2::wire::select_empire(2));sent=valid.take_output();
auto plain=ava2::wire::decrypt(sent.at(0),client_key);
if(plain[0]!=90 || plain[1]!=2) return 23;
}
// SelectPhase receivers: create success/failure, delete success/failure, point change, change name.
{
client::TPacketGCPlayerCreateSuccess created{};created.header=8;created.bAccountCharacterSlot=2;
created.kSimplePlayerInfomation.dwID=33;std::strncpy(created.kSimplePlayerInfomation.szName,"Fixture Ninja",24);created.kSimplePlayerInfomation.byJob=1;
client::TPacketGCPointChange point{};point.header=17;
client::TPacketGCChangeName renamed{};renamed.header=107;renamed.pid=11;std::strncpy(renamed.name,"Renamed",24);
client::TPacketGCChangeName unknown=renamed;unknown.pid=999;
ava2::wire::Bytes in;
auto add=[&](const auto& v) { auto* b=reinterpret_cast<const std::uint8_t*>(&v);in.insert(in.end(),b,b+sizeof(v)); };
add(created);in.insert(in.end(),{9,3, 10,2, 11});add(point);add(renamed);add(unknown);
valid.feed(ava2::wire::encrypt(in,rx));
using K=ava2::SelectResult::Kind;
auto results=valid.take_select_results();
if(valid.state()!=ava2::LoginSession::State::Selecting || results.size()!=6) return 24;
if(results[0].kind!=K::CreateSuccess || results[1].kind!=K::CreateFailure || results[1].value!=3) return 25;
if(results[2].kind!=K::DeleteSuccess || results[2].value!=2 || valid.characters()[2].id!=0) return 26;
if(results[3].kind!=K::DeleteFailure || results[4].kind!=K::ChangeName || results[4].value!=0 || results[4].name!="Renamed") return 27;
if(valid.characters()[0].name!="Renamed" || results[5].kind!=K::CreateFailure || results[5].value!=100) return 28;
}
valid.select(0);
if(valid.state()!=ava2::LoginSession::State::Entering) return 19;
std::cout<<"Original AVA2 client/server layout, cipher and character selection oracle passed\n";
+12 -2
View File
@@ -11,8 +11,13 @@ tea=(root/'upstream/ava2-client/EterBase/tea.cpp').read_text(errors='replace')
def declaration(source, start, end):
text=source[source.index(start):]
text=text[:text.index(end)+len(end)]
text=re.sub(r'\blong\s+long\b','std::int64_t',text)
return re.sub(r'\blong\b','std::int32_t',text)
def struct(source, tag, name):
match=re.search(r'typedef struct '+tag+r'\s*\{',source)
return declaration(source[match.start():],'typedef struct','} '+name+';')
# Both baseline macro headers enable sash, conqueror and five-character accounts.
for path,names in [
('upstream/ava2-client/UserInterface/Locale_inc.h',['ENABLE_SASH_SYSTEM','ENABLE_CONQUEROR_LEVEL','ENABLE_PLAYER_PER_ACCOUNT5']),
@@ -25,13 +30,18 @@ header='''#pragma once
#include <cstdint>
namespace ava2_oracle {
using BYTE=std::uint8_t; using WORD=std::uint16_t; using DWORD=std::uint32_t; using LONG=std::int32_t;
constexpr int CHARACTER_NAME_MAX_LEN=24, GUILD_NAME_MAX_LEN=12, PLAYER_PER_ACCOUNT4=5, PLAYER_PER_ACCOUNT=5;
constexpr int CHARACTER_NAME_MAX_LEN=24, GUILD_NAME_MAX_LEN=12, PLAYER_PER_ACCOUNT3=3, PLAYER_PER_ACCOUNT4=5, PLAYER_PER_ACCOUNT=5, PRIVATE_CODE_LENGTH=8;
#define ENABLE_SASH_SYSTEM
#define __SASH_SYSTEM__
#define ENABLE_CONQUEROR_LEVEL
#pragma pack(push,1)
namespace client {
'''+declaration(client,'typedef struct SSimplePlayerInformation','} TSimplePlayerInformation;')+'\n'+declaration(client,'typedef struct packet_login_success4','} TPacketGCLoginSuccess4;')+'\n}\nnamespace server {\n'+declaration(server,'typedef struct SSimplePlayer','} TSimplePlayer;')+'\n'+declaration(packet,'typedef struct packet_login_success','} TPacketGCLoginSuccess;')+'''\n}
'''+declaration(client,'typedef struct SSimplePlayerInformation','} TSimplePlayerInformation;')+'\n'+declaration(client,'typedef struct packet_login_success4','} TPacketGCLoginSuccess4;')+'\n'+'\n'.join(struct(client,tag,name) for tag,name in [
# SelectPhase packets (PythonNetworkStreamPhaseSelect.cpp)
('packet_login_success3','TPacketGCLoginSuccess3'),('command_player_create_success','TPacketGCPlayerCreateSuccess'),
('packet_point_change','TPacketGCPointChange'),('SPacketGCChangeName','TPacketGCChangeName'),
('command_player_create','TPacketCGCreateCharacter'),('command_player_delete','TPacketCGDestroyCharacter'),
('SPacketCGChangeName','TPacketCGChangeName')])+'\n}\nnamespace server {\n'+declaration(server,'typedef struct SSimplePlayer','} TSimplePlayer;')+'\n'+declaration(packet,'typedef struct packet_login_success','} TPacketGCLoginSuccess;')+'''\n}
#pragma pack(pop)
namespace original_cipher {
'''