AVA2 client Windows parity passes (gr2 BitKnit2/64-bit, GamePhase handlers, python modules)

- 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>
This commit is contained in:
shenlei
2026-10-08 10:43:01 +09:00
co-authored by Claude Opus 5.5
parent 9f748eb05a
commit 9077aa389a
145 changed files with 22692 additions and 6584 deletions
+181 -6
View File
@@ -3,12 +3,15 @@
#include "Packet.h"
#include "NetworkActorManager.h"
#include <Python.h>
#include <chrono>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
#include <deque>
#include <memory>
#include <functional>
#include <utility>
namespace ava2 {
@@ -37,6 +40,8 @@ public:
bool IsGamePhase() const { return m_phase == PHASE_GAME; }
void StartGame();
void ResetConnection();
void SetGuildID(uint32_t id);
uint32_t GetGuildID() const {return m_guildID;}
void SetClientFilename(std::string name) { m_clientFilename=std::move(name); }
// ── Main Actor Attributes ──
@@ -53,11 +58,21 @@ public:
void PushRecvData(const uint8_t* data, size_t len);
void PushRecvData(const std::vector<uint8_t>& bytes);
bool ProcessRecvData();
// Free bytes in the 128 KB game receive buffer (networkmodule.py SetTCPRecvBufferSize(128*1024)).
size_t RecvBufferSpace() const { return m_recvBuffer.size()>=128*1024?0:128*1024-m_recvBuffer.size(); }
// ── Client-to-Server Sending API ──
bool SendEnterGamePacket();
bool SendPrivateShopSearchInfo(const TPacketCGShopSearch& data);
bool SendSwitchbotPacket(bool start,uint8_t slot);
bool SendDungeonInfoPacket(uint8_t subheader,int32_t index=0);
bool SendDropItemPacket(bool search,int32_t vnum=0);
bool SendBattlePassPacket(bool reward,int32_t index=0);
bool SendCubeRenewalPacket(bool close,uint32_t index=0,uint32_t count=0);
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 SendBuildOfflineShopPacket(const std::string& name,const std::vector<TOfflineShopItemTable>& items,uint32_t vnum,uint8_t title);
bool SendOfflineShopChangeDecoration(const std::string& sign,uint32_t vnum,uint32_t type);
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);
@@ -86,7 +101,7 @@ public:
// ── 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 SendSafeBoxItemMovePacket(uint8_t srcPos, uint8_t dstPos, uint32_t count);
bool SendSafeBoxMoneyPacket(uint8_t state, uint32_t money);
bool SendMallCheckoutPacket(uint8_t safeboxPos, uint8_t window, uint16_t cell);
@@ -96,20 +111,77 @@ public:
bool SendGiveItemPacket(uint32_t targetVID, uint8_t window, uint16_t cell, uint32_t count);
bool SendScriptAnswerPacket(int answer);
bool SendScriptButtonPacket(int button);
// CPythonNetworkStream::OnScriptEventStart: phase window OpenQuestWindow(skin, index).
void OnScriptEventStart(int iSkin, int iIndex);
bool SendAnswerMakeGuildPacket(const char* name);
bool SendQuestInputStringPacket(const char* text);
bool SendQuestInputStringLongPacket(const char* text);
bool SendQuestConfirmPacket(uint8_t answer, uint32_t pid);
bool SendSelectItemPacket(uint32_t itemPos);
bool SendTargetInfoLoadPacket(uint32_t vid);
// ── Messenger / Party / Guild Protocol (AVA2 PythonNetworkStreamPhaseGame.cpp) ──
bool SendMessengerAddByVIDPacket(uint32_t vid);
bool SendMessengerAddByNamePacket(const char* name);
bool SendMessengerRemovePacket(const char* key, const char* name);
bool SendPartyInvitePacket(uint32_t vid);
bool SendPartyInviteAnswerPacket(uint32_t leaderPID, uint8_t answer);
bool SendPartyRemovePacket(uint32_t pid);
bool SendPartySetStatePacket(uint32_t vid, uint8_t state, uint8_t flag);
bool SendPartyUseSkillPacket(uint8_t skillIndex, uint32_t vid);
bool SendPartyParameterPacket(uint8_t distributeMode);
bool SendGuildAddMemberPacket(uint32_t vid);
bool SendGuildRemoveMemberPacket(uint32_t pid);
bool SendGuildChangeGradeNamePacket(uint8_t grade, const char* name);
bool SendGuildChangeGradeAuthorityPacket(uint8_t grade, uint8_t authority);
bool SendGuildOfferPacket(uint32_t experience);
bool SendGuildPostCommentPacket(const char* message);
bool SendGuildDeleteCommentPacket(uint32_t index);
bool SendGuildRefreshCommentsPacket(uint32_t highestIndex);
bool SendGuildChangeMemberGradePacket(uint32_t pid, uint8_t grade);
bool SendGuildUseSkillPacket(uint32_t skillID, uint32_t targetVID);
bool SendGuildChangeMemberGeneralPacket(uint32_t pid, uint8_t flag);
bool SendGuildInviteAnswerPacket(uint32_t guildID, uint8_t answer);
bool SendGuildChargeGSPPacket(uint32_t money);
bool SendGuildDepositMoneyPacket(uint32_t money);
bool SendGuildWithdrawMoneyPacket(uint32_t money);
void ResetGuildCommentRefreshThrottle() { m_lastGuildCommentRefresh.reset(); }
// 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();
// Packets with whether the transport appends the sequence byte (SendSequence()).
std::vector<std::pair<std::vector<uint8_t>,bool>> PopSendPacketsWithSequence();
std::pair<int32_t,int32_t> GetDungeonDestination() const { return m_dungeonDestination; }
// 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; }
// ── Chat / ServerCommand (AVA2 PythonNetworkStreamPhaseGame.cpp, PythonNetworkStreamCommand.cpp) ──
void ServerCommand(const std::string& command);
void SetServerCommandParserWindow(PyObject* window) { m_poSerCommandParserWnd = window; }
void RegisterEmoticonString(const std::string& emoticon);
bool ParseEmoticon(const char* chatMsg, uint32_t* emoticon) const;
void SendEmoticon(unsigned emoticon);
void EnableChatInsultFilter(bool enable) { m_isEnableChatInsultFilter = enable; }
// CInsultChecker (AVA2 UserInterface/InsultChecker.cpp); text = already-read insult.txt.
bool LoadInsultList(const std::string& text);
bool IsChatInsultIn(const char* msg) const;
bool IsInsultIn(const char* msg) const;
void FilterInsult(char* line, size_t lineLen) const;
void SetEmpireLanguageMode(bool enable) { m_bEmpireLanguageEnable = enable; }
bool IsObserverMode() const { return m_isObserverMode; }
bool HasMobilePhoneNumber() const { return m_bMobileFlag; }
bool GetComboSkillFlag() const { return m_bComboSkillFlag; }
// Windows calls PostQuitMessage(0); the host loop polls this instead.
bool IsQuitRequested() const { return m_unknownPacketQuit; }
// GamePhase() headers Windows handles but this port skips (consumed, not dispatched).
const std::vector<uint8_t>& GetUnportedPackets() const { return m_unportedPackets; }
// Callback when whisper is received
using WhisperCallback = std::function<void(uint8_t type, const std::string& from, const std::string& text)>;
@@ -124,7 +196,9 @@ public:
void SetFlyCallback(FlyCallback cb) { m_flyCallback = cb; }
private:
bool DispatchGamePhasePacket(uint8_t header);
bool CheckPacket(uint8_t* retHeader);
bool DispatchGamePhasePacket(uint8_t header,bool& ret);
bool DispatchPortedGamePhasePacket(uint8_t header);
// Handlers matching CPythonNetworkStreamPhaseGame
bool RecvPhasePacket();
@@ -157,7 +231,15 @@ private:
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 m_refreshGuildInfo=false,m_refreshGuildBoard=false,m_refreshGuildMember=false;
bool m_refreshGuildCombo=false,m_refreshGuildSkill=false,m_refreshGuildGrade=false,m_refreshMessenger=false;
bool m_refreshShopSearch=false;
bool m_refreshInventory=false,m_refreshStatus=false,m_refreshCharacter=false;
std::vector<bool> m_sendSequence;
// Handshake/HandshakeOK/HybridCrypt return from GamePhase() before the refresh block.
bool m_stopGamePhase=false;
uint32_t m_changeServerTime=0,m_changeClientTime=0; // CPythonNetworkStream::m_kServerTimeSync
std::pair<int32_t,int32_t> m_dungeonDestination{};
bool RecvItemSetPacket();
bool RecvItemSetPacket2();
bool RecvItemUpdatePacket();
@@ -172,6 +254,7 @@ private:
bool RecvWarpPacket();
bool RecvExchangePacket();
bool RecvShopPacket();
bool RecvOfflineShopPacket();
bool RecvSafeBoxSetPacket();
bool RecvSafeBoxDelPacket();
bool RecvSafeBoxWrongPasswordPacket();
@@ -181,31 +264,123 @@ private:
bool RecvMallSetPacket();
bool RecvMallDelPacket();
// Remaining GamePhase() handlers (PythonNetworkStreamPhaseGameRecv.cpp)
SNetworkActorData* MainInstance();
void RefreshTargetBoardByVID(uint32_t vid);
bool RecvChangeSpeedPacket();
bool RecvMotionPacket();
bool RecvEventManager();
bool RecvItemShop();
bool RecvDuelStartPacket();
bool RecvPVPPacket();
bool RecvCharacterPositionPacket();
bool RecvScriptPacket();
bool RecvShopSearchSet();
bool RecvCubeRenewalPacket();
bool RecvMessenger();
bool RecvGuild();
bool RecvBattlePassPacket();
bool RecvDropItemPacket();
bool RecvDungeonInfoPacket();
bool RecvSwitchbotPacket();
bool RecvQuestInfoPacket();
bool RecvQuestConfirmPacket();
bool RecvOfflineShopSignPacket();
bool RecvTargetInfoPacket();
bool RecvMountPacket();
bool RecvOwnerShipPacket();
bool RecvTargetPacket();
bool RecvChestDrop();
bool RecvKillLOG();
bool RecvFlyTargetingPacket(bool add);
bool RecvPartyInvite();
bool RecvPartyAdd();
bool RecvPartyUpdate();
bool RecvPartyRemove();
bool RecvRequestMakeGuild();
bool RecvPartyParameter();
bool RecvFishing();
bool RecvPartyLink();
bool RecvPartyUnlink();
template<class Packet> void RefineInformation(const Packet& p,bool isNew);
static uint8_t RefineType(const TPacketGCRefineInformation&);
static uint8_t RefineType(const TPacketGCRefineInformationNew& p);
bool RecvRefineInformationPacket();
bool RecvRefineInformationPacketNew();
bool RecvViewEquipPacket();
bool RecvDungeon();
bool RecvWalkModePacket();
bool RecvChangeSkillGroupPacket();
bool RecvNPCList();
bool RecvChannelPacket();
bool RecvTargetUpdatePacket();
bool RecvTargetDeletePacket();
bool RecvTargetCreatePacketNew();
bool RecvLandPacket();
bool RecvLoverInfoPacket();
bool RecvLovePointUpdatePacket();
bool RecvDigMotionPacket();
bool RecvAccountBankPacket();
bool RecvHybridCryptPacket();
bool RecvHSCheckRequest();
bool RecvXTrapVerifyRequest();
bool RecvSpecificEffect();
bool RecvSpecialEffect();
bool RecvDragonSoulRefine();
bool RecvUnk213();
bool RecvCalendarSystem();
bool RecvCalendarSystemADM();
bool RecvSashPacket();
bool RecvKingdomsWarPacket();
bool RecvSungmaAttrUpdatePacket();
bool RecvExchangeLog();
bool RecvMiniGameCatchKingPacket();
bool Recv67AttrOpenPacket();
bool RecvCheatBlacklist();
bool RecvHandshakePacket();
bool RecvHandshakeOKPacket();
bool Peek(size_t size, void* outBuf);
bool Read(size_t size, void* outBuf);
void Send(const void* data, size_t size);
// Windows Send() without SendSequence() (XTrap ACK).
void SendUnsequenced(const void* data, size_t size);
private:
EPhase m_phase = PHASE_OFFLINE;
PyObject* m_poHandler = nullptr;
PyObject* m_phaseWindows[7] = {nullptr};
uint32_t m_guildID=0;
uint32_t m_dwMainActorVID = 0;
uint16_t m_wMainActorRace = 0;
uint8_t m_byMainActorEmpire = 0;
std::optional<std::chrono::steady_clock::time_point> m_lastGuildCommentRefresh;
uint8_t m_byMainActorSkillGroup = 0;
std::string m_strMainActorName;
std::string m_strFieldMusicFileName;
float m_fFieldMusicVolume = 0.02f;
std::vector<uint8_t> m_recvBuffer;
uint8_t m_lastPacket[2] {};
bool m_dispatchUnported = false;
bool m_unknownPacketQuit = false;
std::vector<uint8_t> m_unportedPackets;
PyObject* m_poSerCommandParserWnd = nullptr;
std::vector<std::string> m_emoticonStrings;
std::string m_strLastCommand;
bool m_isEnableChatInsultFilter = false;
std::vector<std::string> m_insults; // CInsultChecker::m_kList_stInsult
bool m_bEmpireLanguageEnable = true; // gs_bEmpireLanuageEnable
bool m_isObserverMode = false;
bool m_bMobileFlag = false;
bool m_bComboSkillFlag = false;
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;