AVA2 cross-platform client parity baseline

This commit is contained in:
shen
2026-10-06 00:53:42 -07:00
commit 9f748eb05a
3271 changed files with 1275528 additions and 0 deletions
+214
View File
@@ -0,0 +1,214 @@
#pragma once
#include "Packet.h"
#include "NetworkActorManager.h"
#include <Python.h>
#include <cstdint>
#include <string>
#include <vector>
#include <deque>
#include <memory>
#include <functional>
namespace ava2 {
/**
* PythonNetworkStream:
* Partial AVA2 game-phase packet model and dispatch bridge.
* Encrypted socket integration covers supported packets; full Windows parity remains pending:
* - Phase transitions (PHASE_LOGIN, PHASE_SELECT, PHASE_LOADING, PHASE_GAME)
* - Wire packet parser with fixed & dynamic length packet dispatching
* - Full GamePhase() processor for entity updates, combat, inventory, chat, and skills
* - Integration with Python callbacks, TextTailManager, SoundManager, EffectManager, FlyingManager
*/
class PythonNetworkStream {
public:
static PythonNetworkStream& Instance();
PythonNetworkStream();
~PythonNetworkStream();
// ── Phase Management ──
void SetPhaseWindow(int phase, PyObject* poWindow);
void ClearPhaseWindow(int phase, PyObject* poWindow);
void SetHandler(PyObject* poHandler);
void SetPhase(EPhase phase);
EPhase GetPhase() const { return m_phase; }
bool IsGamePhase() const { return m_phase == PHASE_GAME; }
void StartGame();
void ResetConnection();
void SetClientFilename(std::string name) { m_clientFilename=std::move(name); }
// ── Main Actor Attributes ──
void SetMainActorVID(uint32_t vid);
uint32_t GetMainActorVID() const { return m_dwMainActorVID; }
uint16_t GetMainActorRace() const { return m_wMainActorRace; }
uint8_t GetMainActorEmpire() const { return m_byMainActorEmpire; }
uint8_t GetMainActorSkillGroup() const { return m_byMainActorSkillGroup; }
const std::string& GetMainActorName() const { return m_strMainActorName; }
const std::string& GetFieldMusicFileName() const { return m_strFieldMusicFileName; }
float GetFieldMusicVolume() const { return m_fFieldMusicVolume; }
// ── Wire Ingestion & Dispatch ──
void PushRecvData(const uint8_t* data, size_t len);
void PushRecvData(const std::vector<uint8_t>& bytes);
bool ProcessRecvData();
// ── Client-to-Server Sending API ──
bool SendEnterGamePacket();
bool SendShopPacket(uint8_t operation,uint8_t window=0,uint8_t slot=0,uint32_t count=0);
bool SendOfflineShopPacket(bool buy,uint32_t owner=0,uint8_t position=0);
bool SendOfflineShopManagement(uint8_t operation,uint8_t position=0,uint32_t owner=0);
bool SendQuickSlotAddPacket(uint8_t index,uint8_t type,uint8_t pos);
bool SendQuickSlotDelPacket(uint8_t index);
bool SendQuickSlotMovePacket(uint8_t source,uint8_t target);
bool SendCharacterMovePacket(uint8_t func, uint8_t arg, uint8_t rot, int32_t x, int32_t y, uint32_t time);
bool SendAttackPacket(uint8_t type, uint32_t victimVID);
bool SendChatPacket(const std::string& text, uint8_t type = CHAT_TYPE_TALKING);
bool SendWhisperPacket(const std::string& name, const std::string& text);
bool SendItemUsePacket(uint8_t window, uint16_t cell);
bool SendItemMovePacket(uint8_t srcWindow, uint16_t srcCell, uint8_t dstWindow, uint16_t dstCell, uint32_t count);
bool SendItemPickUpPacket(uint32_t vid);
bool SendItemDropPacket(uint8_t window, uint16_t cell, uint32_t gold);
bool SendItemDropPacketNew(uint8_t window,uint16_t cell,uint32_t gold,uint32_t count);
bool SendOnClickPacket(uint32_t vid);
bool SendFlyTargetingPacket(uint32_t targetVID, int32_t x, int32_t y);
bool SendWarpPacket();
// ── Exchange Protocol ──
bool SendExchangeStartPacket(uint32_t vid);
bool SendExchangeItemAddPacket(uint8_t window, uint16_t cell, uint8_t exchangePos);
bool SendExchangeItemDelPacket(uint8_t exchangePos);
bool SendExchangeElkAddPacket(int64_t elk);
bool SendExchangeAcceptPacket();
bool SendExchangeExitPacket();
// ── SafeBox & Mall Protocol ──
bool SendSafeBoxCheckinPacket(uint8_t window, uint16_t cell, uint8_t safeboxPos);
bool SendSafeBoxCheckoutPacket(uint8_t safeboxPos, uint8_t window, uint16_t cell);
bool SendSafeBoxItemMovePacket(uint8_t srcPos, uint8_t dstPos, uint8_t count);
bool SendSafeBoxMoneyPacket(uint8_t state, uint32_t money);
bool SendMallCheckoutPacket(uint8_t safeboxPos, uint8_t window, uint16_t cell);
// ── Refine & Quest Protocol ──
bool SendRefinePacket(uint8_t targetItemPos, uint8_t type, uint8_t specialStorage = 0, int32_t indexSelect = -1);
bool SendItemUseToItemPacket(uint16_t srcCell, uint16_t dstCell);
bool SendGiveItemPacket(uint32_t targetVID, uint8_t window, uint16_t cell, uint32_t count);
bool SendScriptAnswerPacket(int answer);
bool SendScriptButtonPacket(int button);
// Raw outgoing bytes for network transport / unit test inspection
const std::vector<uint8_t>& GetSendQueue() const { return m_sendBuffer; }
std::vector<uint8_t> PopSendBytes();
void ClearSendQueue() { m_sendBuffer.clear();m_sendPackets.clear(); }
std::vector<std::vector<uint8_t>> PopSendPackets();
// Callback when damage occurs
using DamageCallback = std::function<void(uint32_t vid, int damage, uint8_t flag)>;
void SetDamageCallback(DamageCallback cb) { m_damageCallback = cb; }
// Callback when chat is received
using ChatCallback = std::function<void(uint8_t type, const std::string& text, uint32_t vid)>;
void SetChatCallback(ChatCallback cb) { m_chatCallback = cb; }
// Callback when whisper is received
using WhisperCallback = std::function<void(uint8_t type, const std::string& from, const std::string& text)>;
void SetWhisperCallback(WhisperCallback cb) { m_whisperCallback = cb; }
// Callback when ground item is added/deleted
using GroundItemCallback = std::function<void(uint32_t vid, uint32_t vnum, int32_t x, int32_t y, int32_t z, bool isAdd)>;
void SetGroundItemCallback(GroundItemCallback cb) { m_groundItemCallback = cb; }
// Callback when fly projectile is created
using FlyCallback = std::function<void(uint8_t flyType, uint32_t startVID, uint32_t endVID)>;
void SetFlyCallback(FlyCallback cb) { m_flyCallback = cb; }
private:
bool DispatchGamePhasePacket(uint8_t header);
// Handlers matching CPythonNetworkStreamPhaseGame
bool RecvPhasePacket();
bool RecvMainCharacter();
bool RecvMainCharacter2Empire();
bool RecvMainCharacter3BGM();
bool RecvMainCharacter4BGMVolume();
bool RecvTimePacket();
bool RecvPlayerPoints();
bool RecvAffectAddPacket();
bool RecvAffectRemovePacket();
bool RecvSkillLevel();
bool RecvSkillLevelNew();
void MainCharacterLoaded(int32_t x,int32_t y,int32_t z);
bool RecvCharacterAppendPacket();
bool RecvCharacterAdditionalInfo();
bool RecvCharacterAppendPacketNew();
bool RecvCharacterUpdatePacketNew();
bool RecvCharacterUpdatePacket();
bool RecvCharacterDeletePacket();
bool RecvCharacterMovePacket();
bool RecvSyncPositionPacket();
bool RecvChatPacket();
bool RecvWhisperPacket();
bool RecvDamageInfoPacket();
bool RecvStunPacket();
bool RecvDeadPacket();
bool RecvPointChange();
bool m_refreshSkill=false;
bool m_startGameRequested=false;
std::string m_clientFilename="ava2_client";
std::vector<std::vector<uint8_t>> m_sendPackets;
bool m_refreshInventory=false,m_refreshStatus=false;
bool RecvItemSetPacket();
bool RecvItemSetPacket2();
bool RecvItemUpdatePacket();
bool RecvItemUsePacket();
bool RecvItemGroundAddPacket();
bool RecvItemGroundDelPacket();
bool RecvItemOwnership();
bool RecvQuickSlotAddPacket();
bool RecvQuickSlotDelPacket();
bool RecvQuickSlotMovePacket();
bool RecvCreateFlyPacket();
bool RecvWarpPacket();
bool RecvExchangePacket();
bool RecvShopPacket();
bool RecvSafeBoxSetPacket();
bool RecvSafeBoxDelPacket();
bool RecvSafeBoxWrongPasswordPacket();
bool RecvSafeBoxSizePacket();
bool RecvSafeBoxMoneyChangePacket();
bool RecvMallOpenPacket();
bool RecvMallSetPacket();
bool RecvMallDelPacket();
bool Peek(size_t size, void* outBuf);
bool Read(size_t size, void* outBuf);
void Send(const void* data, size_t size);
private:
EPhase m_phase = PHASE_OFFLINE;
PyObject* m_poHandler = nullptr;
PyObject* m_phaseWindows[7] = {nullptr};
uint32_t m_dwMainActorVID = 0;
uint16_t m_wMainActorRace = 0;
uint8_t m_byMainActorEmpire = 0;
uint8_t m_byMainActorSkillGroup = 0;
std::string m_strMainActorName;
std::string m_strFieldMusicFileName;
float m_fFieldMusicVolume = 0.02f;
std::vector<uint8_t> m_recvBuffer;
std::vector<uint8_t> m_sendBuffer;
// Temporary pending actor data when CharacterAdd arrives before CharacterAdditionalInfo
SNetworkActorData m_pendingActorData;
DamageCallback m_damageCallback;
ChatCallback m_chatCallback;
WhisperCallback m_whisperCallback;
GroundItemCallback m_groundItemCallback;
FlyCallback m_flyCallback;
};
} // namespace ava2