- 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>
58 lines
3.8 KiB
C++
58 lines
3.8 KiB
C++
#include "legacy_cipher.h"
|
|
#include "login_session.h"
|
|
#include "login_oracle.h"
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <iostream>
|
|
#include <random>
|
|
#include <cstring>
|
|
int main() {
|
|
using namespace ava2_oracle;
|
|
static_assert(sizeof(client::TSimplePlayerInformation)==70);
|
|
static_assert(sizeof(server::TSimplePlayer)==70);
|
|
static_assert(sizeof(client::TPacketGCLoginSuccess4)==444);
|
|
static_assert(sizeof(server::TPacketGCLoginSuccess)==444);
|
|
static_assert(offsetof(client::TSimplePlayerInformation,x)==50);
|
|
static_assert(offsetof(client::TSimplePlayerInformation,byConquerorLevel)==65);
|
|
std::mt19937 random(914);
|
|
for(int n=0;n<512;++n) {
|
|
ava2::wire::Key key{};for(auto& word:key) word=random();
|
|
std::array<std::uint32_t,2> input{random(),random()}, expected{};
|
|
original_cipher::tea_code(input[1],input[0],key.data(),expected.data());
|
|
ava2::wire::Bytes bytes;for(auto word:input) ava2::wire::append32(bytes,word);
|
|
auto cipher=ava2::wire::encrypt(bytes,key);
|
|
if(ava2::wire::read32(cipher,0)!=expected[0] || ava2::wire::read32(cipher,4)!=expected[1]) return 1;
|
|
if(ava2::wire::decrypt(cipher,key)!=bytes) return 2;
|
|
}
|
|
try { ava2::wire::decrypt({std::array<std::uint8_t,1>{0}},ava2::wire::locale_key());return 3; } catch(const std::invalid_argument&) {}
|
|
// Bound malformed peers without allocating unbounded buffers.
|
|
ava2::LoginSession session("fixture","fixture-password",{1,2,3,4});
|
|
ava2::wire::Bytes oversized(128*1024+1,0);session.feed(oversized);
|
|
if(session.state()!=ava2::LoginSession::State::Failed) return 4;
|
|
ava2::wire::Key client_key{1,2,3,4};
|
|
ava2::LoginSession valid("fixture","fixture-password",client_key);
|
|
std::array<std::uint8_t,2> auth_phase{253,10};valid.feed(auth_phase);valid.take_output();
|
|
ava2::wire::Bytes accepted{150};ava2::wire::append32(accepted,123);accepted.push_back(1);
|
|
valid.feed(ava2::wire::encrypt(accepted,ava2::wire::locale_key()));valid.begin_game();
|
|
std::array<std::uint8_t,2> login_phase{253,2};valid.feed(login_phase);valid.take_output();
|
|
client::TPacketGCLoginSuccess4 roster{};roster.header=32;
|
|
roster.akSimplePlayerInformation[0].dwID=11;roster.akSimplePlayerInformation[0].x=12345;
|
|
roster.akSimplePlayerInformation[0].y=-54321;roster.akSimplePlayerInformation[0].wPort=13000;
|
|
roster.akSimplePlayerInformation[0].byConquerorLevel=2;
|
|
ava2::wire::Bytes payload{253,3};auto* raw=reinterpret_cast<const std::uint8_t*>(&roster);
|
|
payload.insert(payload.end(),raw,raw+sizeof(roster));
|
|
valid.feed(ava2::wire::encrypt(payload,ava2::wire::derive_receive_key(client_key)));
|
|
if(valid.state()!=ava2::LoginSession::State::Selecting || valid.characters()[0].x!=12345 || valid.characters()[0].y!=-54321 || valid.characters()[0].port!=13000 || valid.characters()[0].conqueror_level!=2) return 5;
|
|
try { valid.select(1);return 7; } catch(const std::invalid_argument&) {}
|
|
valid.select(0);auto sent=valid.take_output();
|
|
if(sent.size()!=1 || ava2::wire::decrypt(sent[0],client_key)!=ava2::wire::Bytes{6,0,0xca,0,0,0,0,0}) return 6;
|
|
// 128 KB game receive buffer (networkmodule.py SetTCPRecvBufferSize): partial takes keep the rest queued.
|
|
auto rx=ava2::wire::derive_receive_key(client_key);
|
|
ava2::wire::Bytes loading{253,4};for(int i=0;i<14;++i) loading.push_back(std::uint8_t(i));
|
|
valid.feed(ava2::wire::encrypt(loading,rx));
|
|
if(valid.state()!=ava2::LoginSession::State::Loading || valid.receive_space()!=ava2::LoginSession::kRecvBufferSize-14) return 8;
|
|
if(valid.take_game_input(0).size()!=0 || valid.take_game_input(5)!=ava2::wire::Bytes{0,1,2,3,4}) return 9;
|
|
if(valid.take_game_input()!=ava2::wire::Bytes{5,6,7,8,9,10,11,12,13} || valid.receive_space()!=ava2::LoginSession::kRecvBufferSize) return 10;
|
|
std::cout<<"Original AVA2 client/server layout, cipher and character selection oracle passed\n";
|
|
}
|