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:
co-authored by
Claude Opus 5.5
parent
9f748eb05a
commit
9077aa389a
@@ -1,8 +1,14 @@
|
||||
#include "item_sound.h"
|
||||
#include "PythonNetworkStream.h"
|
||||
#include "python_net.h"
|
||||
#include "guild_state.h"
|
||||
#include "switchbot_state.h"
|
||||
#include "protocol.h"
|
||||
#include "shared/common/PythonUtils.h"
|
||||
#include "nonplayer_data.h"
|
||||
#include "python_app.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "python_chat.h"
|
||||
#include "python_native_modules.h"
|
||||
#include "PythonExchange.h"
|
||||
#include "PythonSafeBox.h"
|
||||
@@ -11,6 +17,7 @@
|
||||
#include "eter_sound/SoundManager.h"
|
||||
#include "eter_effect/EffectManager.h"
|
||||
#include "eter_effect/FlyingManager.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <bit>
|
||||
#include <stdexcept>
|
||||
@@ -79,14 +86,30 @@ void PythonNetworkStream::StartGame() {
|
||||
}
|
||||
|
||||
void PythonNetworkStream::ResetConnection() {
|
||||
m_recvBuffer.clear();ClearSendQueue();m_startGameRequested=m_refreshInventory=m_refreshStatus=m_refreshSkill=false;
|
||||
m_recvBuffer.clear();m_unportedPackets.clear();m_unknownPacketQuit=false;m_isObserverMode=m_bMobileFlag=false;std::memset(m_lastPacket,0,sizeof(m_lastPacket));ClearSendQueue();m_startGameRequested=m_refreshInventory=m_refreshStatus=m_refreshSkill=m_refreshCharacter=m_refreshShopSearch=m_stopGamePhase=false;
|
||||
m_refreshGuildInfo=m_refreshGuildBoard=m_refreshGuildMember=m_refreshGuildCombo=m_refreshGuildSkill=m_refreshGuildGrade=m_refreshMessenger=false;
|
||||
m_guildID=0;
|
||||
m_changeServerTime=m_changeClientTime=0;m_dungeonDestination={};
|
||||
ResetPlayerState();NetworkActorManager::Instance().Clear();
|
||||
m_pendingActorData={};m_strFieldMusicFileName.clear();m_fFieldMusicVolume=0.02f;
|
||||
m_phase=PHASE_OFFLINE;m_dwMainActorVID=0;m_wMainActorRace=0;
|
||||
m_byMainActorEmpire=m_byMainActorSkillGroup=0;m_strMainActorName.clear();
|
||||
}
|
||||
std::vector<std::vector<uint8_t>> PythonNetworkStream::PopSendPackets() {
|
||||
auto packets=std::move(m_sendPackets);m_sendPackets.clear();m_sendBuffer.clear();return packets;
|
||||
auto packets=std::move(m_sendPackets);m_sendPackets.clear();m_sendSequence.clear();m_sendBuffer.clear();return packets;
|
||||
}
|
||||
std::vector<std::pair<std::vector<uint8_t>,bool>> PythonNetworkStream::PopSendPacketsWithSequence() {
|
||||
std::vector<std::pair<std::vector<uint8_t>,bool>> packets;
|
||||
for(size_t i=0;i<m_sendPackets.size();++i) packets.emplace_back(std::move(m_sendPackets[i]),m_sendSequence[i]);
|
||||
m_sendPackets.clear();m_sendSequence.clear();m_sendBuffer.clear();
|
||||
return packets;
|
||||
}
|
||||
|
||||
void PythonNetworkStream::SetGuildID(uint32_t id) {
|
||||
if(m_guildID==id)return;
|
||||
m_guildID=id;
|
||||
auto it=GetGuildState().names.find(id);
|
||||
update_player_guild(id,it==GetGuildState().names.end()?"":it->second);
|
||||
}
|
||||
|
||||
void PythonNetworkStream::SetMainActorVID(uint32_t vid) {
|
||||
@@ -127,43 +150,123 @@ void PythonNetworkStream::Send(const void* data, size_t size) {
|
||||
const uint8_t* bytes = static_cast<const uint8_t*>(data);
|
||||
m_sendBuffer.insert(m_sendBuffer.end(), bytes, bytes + size);
|
||||
m_sendPackets.emplace_back(bytes,bytes+size);
|
||||
m_sendSequence.push_back(true);
|
||||
}
|
||||
}
|
||||
|
||||
void PythonNetworkStream::SendUnsequenced(const void* data, size_t size) {
|
||||
const size_t count=m_sendPackets.size();
|
||||
Send(data,size);
|
||||
if(m_sendPackets.size()>count) m_sendSequence.back()=false;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> PythonNetworkStream::PopSendBytes() {
|
||||
std::vector<uint8_t> result = std::move(m_sendBuffer);
|
||||
m_sendBuffer.clear();m_sendPackets.clear();
|
||||
m_sendBuffer.clear();m_sendPackets.clear();m_sendSequence.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace { void inventory_callback(PyObject*,const char*,PyObject*); }
|
||||
namespace {
|
||||
void inventory_callback(PyObject*,const char*,PyObject*);
|
||||
|
||||
// CMainPacketHeaderMap + GamePhase() case labels, generated from the Windows reference.
|
||||
struct GcPacketType { uint8_t header; uint32_t size; bool dynamic, mapped, gameHandled; };
|
||||
constexpr GcPacketType kGcPacketTable[] = {
|
||||
#include "Ava2GcPacketTable.inc"
|
||||
};
|
||||
const GcPacketType* gc_packet_type(uint8_t header) {
|
||||
for(const auto& type:kGcPacketTable) if(type.header==header) return &type;
|
||||
return nullptr;
|
||||
}
|
||||
void trace_error(const std::string& text) { std::cerr<<"[AVA2 TraceError] "<<text<<std::endl; }
|
||||
}
|
||||
|
||||
// CPythonNetworkStream::CheckPacket: skip padding, reject unmapped headers and wait
|
||||
// until the whole static/dynamic packet is buffered.
|
||||
bool PythonNetworkStream::CheckPacket(uint8_t* retHeader) {
|
||||
*retHeader=0;
|
||||
while(!m_recvBuffer.empty() && m_recvBuffer.front()==0) m_recvBuffer.erase(m_recvBuffer.begin());
|
||||
if(m_recvBuffer.empty()) return false;
|
||||
const uint8_t header=m_recvBuffer.front();
|
||||
const auto* type=gc_packet_type(header);
|
||||
if(!type || !type->mapped) {
|
||||
trace_error("Unknown packet header: "+std::to_string(header)+", last: "+std::to_string(m_lastPacket[0])+" "+std::to_string(m_lastPacket[1]));
|
||||
m_recvBuffer.clear();
|
||||
m_unknownPacketQuit=true; // Windows: PostQuitMessage(0)
|
||||
return false;
|
||||
}
|
||||
size_t need=type->size;
|
||||
if(type->dynamic) {
|
||||
if(m_recvBuffer.size()<3) return false;
|
||||
need=size_t(m_recvBuffer[1])|size_t(m_recvBuffer[2])<<8;
|
||||
}
|
||||
if(m_recvBuffer.size()<need) return false;
|
||||
*retHeader=header;
|
||||
m_lastPacket[0]=m_lastPacket[1];m_lastPacket[1]=header;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::ProcessRecvData() {
|
||||
if(m_startGameRequested) { m_startGameRequested=false;inventory_callback(m_poHandler,"SetGamePhase",nullptr); }
|
||||
bool progress = false;
|
||||
while (!m_recvBuffer.empty()) {
|
||||
uint8_t header = 0;
|
||||
if (!Peek(sizeof(header), &header)) break;
|
||||
|
||||
bool handled = DispatchGamePhasePacket(header);
|
||||
if (!handled) {
|
||||
// Unhandled or incomplete packet: wait for more data or stop
|
||||
break;
|
||||
uint8_t header = 0;
|
||||
while (CheckPacket(&header)) {
|
||||
const auto* type=gc_packet_type(header);
|
||||
bool ret;
|
||||
// LoadingPhase() handles MAIN_CHARACTER* itself and falls back to GamePhase();
|
||||
// GamePhase() has no case for them, so in Game they hit RecvDefaultPacket.
|
||||
const bool loadingOnly=header==HEADER_GC_MAIN_CHARACTER || header==HEADER_GC_MAIN_CHARACTER2_EMPIRE ||
|
||||
header==HEADER_GC_MAIN_CHARACTER3_BGM || header==HEADER_GC_MAIN_CHARACTER4_BGM_VOL;
|
||||
if(loadingOnly && m_phase==PHASE_GAME) {
|
||||
trace_error("Unprocessed packet header "+std::to_string(header)+", state Game");
|
||||
m_recvBuffer.clear();
|
||||
} else if(DispatchGamePhasePacket(header,ret)) {
|
||||
// RecvErrorPacket
|
||||
if(!ret) { trace_error("Phase Game does not handle this header (header: "+std::to_string(header)+")");m_recvBuffer.clear(); }
|
||||
} else if(type->gameHandled) {
|
||||
// Windows has a GamePhase handler that is not ported yet: consume exactly
|
||||
// this packet instead of stalling the stream.
|
||||
size_t size=type->dynamic?(size_t(m_recvBuffer[1])|size_t(m_recvBuffer[2])<<8):type->size;
|
||||
if(size==0) size=1;
|
||||
m_unportedPackets.push_back(header);
|
||||
m_recvBuffer.erase(m_recvBuffer.begin(),m_recvBuffer.begin()+std::min(size,m_recvBuffer.size()));
|
||||
} else {
|
||||
// RecvDefaultPacket
|
||||
trace_error("Unprocessed packet header "+std::to_string(header)+", state Game");
|
||||
m_recvBuffer.clear();
|
||||
}
|
||||
progress = true;
|
||||
if(m_stopGamePhase) { m_stopGamePhase=false;return progress; }
|
||||
}
|
||||
if(m_refreshSkill) {m_refreshSkill=false;inventory_callback(m_phaseWindows[5],"RefreshSkill",nullptr);}
|
||||
// GamePhase() refresh block order: Character, (Equipment), Inventory, (Exchange), Skill, ..., Status.
|
||||
if(m_refreshCharacter) { m_refreshCharacter=false;inventory_callback(m_phaseWindows[5],"RefreshCharacter",nullptr); }
|
||||
if(m_refreshInventory) { m_refreshInventory=false;inventory_callback(m_phaseWindows[5],"RefreshInventory",nullptr); }
|
||||
if(m_refreshSkill) {m_refreshSkill=false;inventory_callback(m_phaseWindows[5],"RefreshSkill",nullptr);}
|
||||
if(m_refreshStatus) { m_refreshStatus=false;inventory_callback(m_phaseWindows[5],"RefreshStatus",nullptr); }
|
||||
if(m_refreshMessenger) { m_refreshMessenger=false;inventory_callback(m_phaseWindows[5],"RefreshMessenger",nullptr); }
|
||||
if(m_refreshGuildInfo) { m_refreshGuildInfo=false;inventory_callback(m_phaseWindows[5],"RefreshGuildInfoPage",nullptr); }
|
||||
if(m_refreshGuildBoard) { m_refreshGuildBoard=false;inventory_callback(m_phaseWindows[5],"RefreshGuildBoardPage",nullptr); }
|
||||
if(m_refreshGuildMember) { m_refreshGuildMember=false;inventory_callback(m_phaseWindows[5],"RefreshGuildMemberPage",nullptr); }
|
||||
if(m_refreshGuildCombo) { m_refreshGuildCombo=false;inventory_callback(m_phaseWindows[5],"RefreshGuildMemberPageGradeComboBox",nullptr); }
|
||||
if(m_refreshGuildSkill) { m_refreshGuildSkill=false;inventory_callback(m_phaseWindows[5],"RefreshGuildSkillPage",nullptr); }
|
||||
if(m_refreshGuildGrade) { m_refreshGuildGrade=false;inventory_callback(m_phaseWindows[5],"RefreshGuildGradePage",nullptr); }
|
||||
if(m_refreshShopSearch) { m_refreshShopSearch=false;inventory_callback(m_phaseWindows[5],"RefreshShopSearch",nullptr); }
|
||||
return progress;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::DispatchGamePhasePacket(uint8_t header) {
|
||||
bool PythonNetworkStream::DispatchGamePhasePacket(uint8_t header,bool& ret) {
|
||||
m_dispatchUnported=false;
|
||||
ret=DispatchPortedGamePhasePacket(header);
|
||||
return !m_dispatchUnported;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::DispatchPortedGamePhasePacket(uint8_t header) {
|
||||
switch (header) {
|
||||
case 0: { uint8_t padding;return Read(1,&padding); }
|
||||
case 44: { uint8_t ping;if(!Read(1,&ping)) return false;const uint8_t pong=254;Send(&pong,1);return true; }
|
||||
case HEADER_GC_PHASE:
|
||||
return RecvPhasePacket();
|
||||
case HEADER_GC_SHOP: return RecvShopPacket();
|
||||
case HEADER_GC_OFFLINE_SHOP: return RecvOfflineShopPacket();
|
||||
case HEADER_GC_MAIN_CHARACTER:
|
||||
return RecvMainCharacter();
|
||||
case HEADER_GC_MAIN_CHARACTER2_EMPIRE:
|
||||
@@ -250,8 +353,81 @@ bool PythonNetworkStream::DispatchGamePhasePacket(uint8_t header) {
|
||||
return RecvMallSetPacket();
|
||||
case HEADER_GC_MALL_DEL:
|
||||
return RecvMallDelPacket();
|
||||
case HEADER_GC_CHANGE_SPEED: return RecvChangeSpeedPacket();
|
||||
case HEADER_GC_MOTION: return RecvMotionPacket();
|
||||
case HEADER_GC_ITEMSHOP: return RecvItemShop();
|
||||
case HEADER_GC_EVENT_MANAGER: return RecvEventManager();
|
||||
case HEADER_GC_DUEL_START: return RecvDuelStartPacket();
|
||||
case HEADER_GC_PVP: return RecvPVPPacket();
|
||||
case HEADER_GC_CHARACTER_POSITION: return RecvCharacterPositionPacket();
|
||||
case HEADER_GC_SCRIPT: return RecvScriptPacket();
|
||||
case HEADER_GC_SHOPSEARCH_SET: return RecvShopSearchSet();
|
||||
case HEADER_GC_CUBE_RENEWAL: return RecvCubeRenewalPacket();
|
||||
case HEADER_GC_SWITCHBOT: return RecvSwitchbotPacket();
|
||||
case HEADER_GC_DUNGEON_INFO_SYSTEM: return RecvDungeonInfoPacket();
|
||||
case HEADER_GC_DROP_ITEM_SYSTEM: return RecvDropItemPacket();
|
||||
case HEADER_GC_BATTLEPASS: return RecvBattlePassPacket();
|
||||
case HEADER_GC_GUILD: return RecvGuild();
|
||||
case HEADER_GC_MESSENGER: return RecvMessenger();
|
||||
case HEADER_GC_QUEST_INFO: return RecvQuestInfoPacket();
|
||||
case HEADER_GC_QUEST_CONFIRM: return RecvQuestConfirmPacket();
|
||||
case HEADER_GC_OFFLINE_SHOP_SIGN: return RecvOfflineShopSignPacket();
|
||||
case HEADER_GC_TARGET_INFO: return RecvTargetInfoPacket();
|
||||
case HEADER_GC_MOUNT: return RecvMountPacket();
|
||||
case HEADER_GC_OWNERSHIP: return RecvOwnerShipPacket();
|
||||
case HEADER_GC_TARGET: return RecvTargetPacket();
|
||||
case HEADER_GC_CHESTDROP: return RecvChestDrop();
|
||||
case HEADER_GC_KILL_LOG: return RecvKillLOG();
|
||||
case HEADER_GC_ADD_FLY_TARGETING: return RecvFlyTargetingPacket(true);
|
||||
case HEADER_GC_FLY_TARGETING: return RecvFlyTargetingPacket(false);
|
||||
case HEADER_GC_PARTY_INVITE: return RecvPartyInvite();
|
||||
case HEADER_GC_PARTY_ADD: return RecvPartyAdd();
|
||||
case HEADER_GC_PARTY_UPDATE: return RecvPartyUpdate();
|
||||
case HEADER_GC_PARTY_REMOVE: return RecvPartyRemove();
|
||||
case HEADER_GC_REQUEST_MAKE_GUILD: return RecvRequestMakeGuild();
|
||||
case HEADER_GC_PARTY_PARAMETER: return RecvPartyParameter();
|
||||
case HEADER_GC_FISHING: return RecvFishing();
|
||||
case HEADER_GC_PARTY_LINK: return RecvPartyLink();
|
||||
case HEADER_GC_PARTY_UNLINK: return RecvPartyUnlink();
|
||||
case HEADER_GC_REFINE_INFORMATION: return RecvRefineInformationPacket();
|
||||
case HEADER_GC_REFINE_INFORMATION_NEW: return RecvRefineInformationPacketNew();
|
||||
case HEADER_GC_VIEW_EQUIP: return RecvViewEquipPacket();
|
||||
case HEADER_GC_DUNGEON: return RecvDungeon();
|
||||
case HEADER_GC_WALK_MODE: return RecvWalkModePacket();
|
||||
case HEADER_GC_CHANGE_SKILL_GROUP: return RecvChangeSkillGroupPacket();
|
||||
case HEADER_GC_SEPCIAL_EFFECT: return RecvSpecialEffect();
|
||||
case HEADER_GC_NPC_POSITION: return RecvNPCList();
|
||||
case HEADER_GC_CHANNEL: return RecvChannelPacket();
|
||||
case HEADER_GC_TARGET_UPDATE: return RecvTargetUpdatePacket();
|
||||
case HEADER_GC_TARGET_DELETE: return RecvTargetDeletePacket();
|
||||
case HEADER_GC_TARGET_CREATE_NEW: return RecvTargetCreatePacketNew();
|
||||
case HEADER_GC_LAND_LIST: return RecvLandPacket();
|
||||
case HEADER_GC_LOVER_INFO: return RecvLoverInfoPacket();
|
||||
case HEADER_GC_LOVE_POINT_UPDATE: return RecvLovePointUpdatePacket();
|
||||
case HEADER_GC_DIG_MOTION: return RecvDigMotionPacket();
|
||||
case HEADER_GC_BANK: return RecvAccountBankPacket();
|
||||
case HEADER_GC_HS_REQUEST: return RecvHSCheckRequest();
|
||||
case HEADER_GC_XTRAP_CS1_REQUEST: return RecvXTrapVerifyRequest();
|
||||
case HEADER_GC_SPECIFIC_EFFECT: return RecvSpecificEffect();
|
||||
case HEADER_GC_DRAGON_SOUL_REFINE: return RecvDragonSoulRefine();
|
||||
case HEADER_GC_UNK_213: return RecvUnk213();
|
||||
case HEADER_GC_CALENDAR_SYSTEM: return RecvCalendarSystem();
|
||||
case HEADER_GC_SASH: return RecvSashPacket();
|
||||
case HEADER_GC_CALENDAR_SYSTEM_ADM: return RecvCalendarSystemADM();
|
||||
case HEADER_GC_KINGDOMSWAR: return RecvKingdomsWarPacket();
|
||||
case HEADER_GC_SUNGMA_ATTR_UPDATE: return RecvSungmaAttrUpdatePacket();
|
||||
case HEADER_GC_EXCHANGE_LOG: return RecvExchangeLog();
|
||||
case HEADER_GC_MINI_GAME_CATCH_KING: return RecvMiniGameCatchKingPacket();
|
||||
case HEADER_GC_OPEN_67_ATTR: return Recv67AttrOpenPacket();
|
||||
case HEADER_GC_CHEAT_BLACKLIST: return RecvCheatBlacklist();
|
||||
// GamePhase() `return`s after these four: the rest of the buffer and the refresh
|
||||
// block wait for the next frame, and the handler result is ignored.
|
||||
case HEADER_GC_HANDSHAKE: RecvHandshakePacket();m_stopGamePhase=true;return true;
|
||||
case HEADER_GC_HANDSHAKE_OK: RecvHandshakeOKPacket();m_stopGamePhase=true;return true;
|
||||
case HEADER_GC_HYBRIDCRYPT_KEYS:
|
||||
case HEADER_GC_HYBRIDCRYPT_SDB: RecvHybridCryptPacket();m_stopGamePhase=true;return true;
|
||||
default:
|
||||
// Unknown packet header
|
||||
m_dispatchUnported=true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -407,6 +583,7 @@ bool PythonNetworkStream::RecvCharacterAppendPacketNew() {
|
||||
data.m_dwEmpireID=p.bEmpire; data.m_dwGuildID=p.dwGuild;
|
||||
data.m_sAlignment=p.sAlignment; data.m_byPKMode=p.bPKMode; data.m_dwMountVnum=p.dwMountVnum;
|
||||
NetworkActorManager::Instance().AppendActor(data);
|
||||
if(data.m_dwVID==m_dwMainActorVID)SetGuildID(data.m_dwGuildID);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -437,6 +614,7 @@ bool PythonNetworkStream::RecvCharacterAdditionalInfo() {
|
||||
actorData.m_dwMountVnum = p.dwMountVnum;
|
||||
|
||||
NetworkActorManager::Instance().AppendActor(actorData);
|
||||
if(actorData.m_dwVID==m_dwMainActorVID)SetGuildID(actorData.m_dwGuildID);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -463,6 +641,7 @@ bool PythonNetworkStream::RecvCharacterUpdatePacket() {
|
||||
upd.m_dwAtkSpd = p.bAttackSpeed;
|
||||
|
||||
NetworkActorManager::Instance().UpdateActor(upd);
|
||||
if(upd.m_dwVID==m_dwMainActorVID)SetGuildID(upd.m_dwGuildID);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -492,6 +671,7 @@ bool PythonNetworkStream::RecvCharacterUpdatePacketNew() {
|
||||
upd.m_dwAtkSpd = p.bAttackSpeed;
|
||||
|
||||
NetworkActorManager::Instance().UpdateActor(upd);
|
||||
if(upd.m_dwVID==m_dwMainActorVID)SetGuildID(upd.m_dwGuildID);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -540,48 +720,104 @@ bool PythonNetworkStream::RecvSyncPositionPacket() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// CPythonNetworkStream::RecvChatPacket (ENABLE_MULTILANGUAGE_SYSTEM branch).
|
||||
bool PythonNetworkStream::RecvChatPacket() {
|
||||
TPacketGCChat p;
|
||||
if (!Peek(sizeof(p), &p)) return false;
|
||||
if(p.size<sizeof(p)) throw std::runtime_error("invalid AVA2 chat packet length");
|
||||
if (m_recvBuffer.size() < p.size) return false;
|
||||
TPacketGCChat kChat;
|
||||
if (!Peek(sizeof(kChat), &kChat)) return false;
|
||||
if (kChat.size < sizeof(kChat)) throw std::runtime_error("invalid AVA2 chat packet length");
|
||||
if (m_recvBuffer.size() < kChat.size) return false;
|
||||
|
||||
Read(sizeof(p), &p);
|
||||
size_t textLen = p.size - sizeof(p);
|
||||
std::string text(textLen, '\0');
|
||||
if (textLen > 0) {
|
||||
Read(textLen, text.data());
|
||||
Read(sizeof(kChat), &kChat);
|
||||
std::string text(kChat.size - sizeof(kChat), '\0');
|
||||
if (!text.empty()) Read(text.size(), text.data());
|
||||
text.resize(strnlen(text.c_str(), text.size())); // buf[uChatSize]='\0' + C-string use
|
||||
|
||||
if (kChat.type >= CHAT_TYPE_MAX_NUM)
|
||||
return true;
|
||||
|
||||
if (CHAT_TYPE_COMMAND == kChat.type) {
|
||||
ServerCommand(text);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Strip trailing null characters
|
||||
while (!text.empty() && text.back() == '\0') text.pop_back();
|
||||
if (kChat.dwVID != 0) {
|
||||
auto& actors = NetworkActorManager::Instance();
|
||||
const SNetworkActorData* chatter = actors.GetActorData(kChat.dwVID);
|
||||
if (!chatter)
|
||||
return true;
|
||||
|
||||
if (m_chatCallback) {
|
||||
m_chatCallback(p.type, text, p.dwVID);
|
||||
}
|
||||
std::string line;
|
||||
switch (kChat.type) {
|
||||
case CHAT_TYPE_TALKING:
|
||||
case CHAT_TYPE_PARTY:
|
||||
case CHAT_TYPE_GUILD:
|
||||
case CHAT_TYPE_SHOUT:
|
||||
case CHAT_TYPE_WHISPER: {
|
||||
const size_t colon = text.find(':');
|
||||
// p = strchr(buf, ':') + 2
|
||||
const size_t start = colon == std::string::npos ? 0 : std::min(colon + 2, text.size());
|
||||
uint32_t dwEmoticon;
|
||||
if (ParseEmoticon(text.c_str() + start, &dwEmoticon)) {
|
||||
actors.SetEmoticon(kChat.dwVID, dwEmoticon);
|
||||
return true;
|
||||
}
|
||||
// __ConvertEmpireText needs lang%d.cvt, which Windows only loads for the YMIR
|
||||
// locale; AVA2 runs EUROPE, so the conversion is a no-op here.
|
||||
// p points into buf, so the filtered text also reaches AppendChat(buf).
|
||||
if (m_isEnableChatInsultFilter && chatter->m_bType != 1 && chatter->m_bType != 0) // !IsNPC && !IsEnemy
|
||||
FilterInsult(text.data() + start, strlen(text.c_str() + start));
|
||||
line = text.substr(start);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
line = text;
|
||||
break;
|
||||
}
|
||||
|
||||
if (p.dwVID != 0) {
|
||||
TextTailManager::Instance().RegisterChatTail(p.dwVID, text);
|
||||
if (CHAT_TYPE_SHOUT != kChat.type)
|
||||
TextTailManager::Instance().RegisterChatTail(kChat.dwVID, line);
|
||||
|
||||
if (chatter->m_bType == 6) // IsPC: CActorInstance::TYPE_PC
|
||||
CPythonChat::Instance().AppendChat(kChat.type, text.c_str());
|
||||
} else {
|
||||
if (CHAT_TYPE_SHOUT == kChat.type) {
|
||||
const size_t colon = text.find(':');
|
||||
if (colon != std::string::npos && m_isEnableChatInsultFilter)
|
||||
FilterInsult(text.data() + colon, strlen(text.c_str() + colon));
|
||||
CPythonChat::Instance().AppendChat(kChat.type, text.c_str());
|
||||
} else
|
||||
PyCallClassMemberFunc(m_phaseWindows[5], "GetLocaleString", Py_BuildValue("(is)", int(kChat.type), text.c_str()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// CPythonNetworkStream::RecvWhisperPacket (ENABLE_MULTILANGUAGE_SYSTEM).
|
||||
bool PythonNetworkStream::RecvWhisperPacket() {
|
||||
TPacketGCWhisper p;
|
||||
if (!Peek(sizeof(p), &p)) return false;
|
||||
if(p.wSize<sizeof(p)) throw std::runtime_error("invalid AVA2 dynamic packet length");
|
||||
if (m_recvBuffer.size() < p.wSize) return false;
|
||||
TPacketGCWhisper whisperPacket;
|
||||
if (!Peek(sizeof(whisperPacket), &whisperPacket)) return false;
|
||||
if (whisperPacket.wSize < sizeof(whisperPacket)) throw std::runtime_error("invalid AVA2 dynamic packet length");
|
||||
if (m_recvBuffer.size() < whisperPacket.wSize) return false;
|
||||
|
||||
Read(sizeof(p), &p);
|
||||
size_t textLen = p.wSize - sizeof(p);
|
||||
std::string text(textLen, '\0');
|
||||
if (textLen > 0) {
|
||||
Read(textLen, text.data());
|
||||
}
|
||||
while (!text.empty() && text.back() == '\0') text.pop_back();
|
||||
Read(sizeof(whisperPacket), &whisperPacket);
|
||||
std::string buf(whisperPacket.wSize - sizeof(whisperPacket), '\0');
|
||||
if (!buf.empty()) Read(buf.size(), buf.data());
|
||||
buf.resize(strnlen(buf.c_str(), buf.size()));
|
||||
char name[sizeof(whisperPacket.szNameFrom) + 1] {};
|
||||
std::memcpy(name, whisperPacket.szNameFrom, sizeof(whisperPacket.szNameFrom));
|
||||
|
||||
if (m_whisperCallback) {
|
||||
m_whisperCallback(p.bType, p.szNameFrom, text);
|
||||
if (m_whisperCallback)
|
||||
m_whisperCallback(whisperPacket.bType, name, buf);
|
||||
|
||||
PyObject* gameWnd = m_phaseWindows[5];
|
||||
if (WHISPER_TYPE_CHAT == whisperPacket.bType || WHISPER_TYPE_GM == whisperPacket.bType) {
|
||||
char line[256];
|
||||
std::snprintf(line, sizeof(line), "%s : %s", name, buf.c_str());
|
||||
PyCallClassMemberFunc(gameWnd, "OnRecvWhisper", Py_BuildValue("(issii)", int(whisperPacket.bType), name, line,
|
||||
int(whisperPacket.bLanguage), int(whisperPacket.bEmpire)));
|
||||
} else if (WHISPER_TYPE_SYSTEM == whisperPacket.bType || WHISPER_TYPE_ERROR == whisperPacket.bType) {
|
||||
PyCallClassMemberFunc(gameWnd, "OnRecvWhisperSystemMessage", Py_BuildValue("(iss)", int(whisperPacket.bType), name, buf.c_str()));
|
||||
} else {
|
||||
PyCallClassMemberFunc(gameWnd, "OnRecvWhisperError", Py_BuildValue("(iss)", int(whisperPacket.bType), name, buf.c_str()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -662,12 +898,7 @@ template<class Packet> TItemData item_data(const Packet& p) {
|
||||
return data;
|
||||
}
|
||||
void inventory_callback(PyObject* target,const char* name,PyObject* args) {
|
||||
if(!target) { Py_XDECREF(args);return; }
|
||||
Py_INCREF(target);
|
||||
PyObject* method=PyObject_GetAttrString(target,name);
|
||||
PyObject* result=method?PyObject_CallObject(method,args):nullptr;
|
||||
Py_XDECREF(result);Py_XDECREF(method);Py_XDECREF(args);Py_DECREF(target);
|
||||
if(!result) throw std::runtime_error(std::string("AVA2 Python callback failed: ")+name);
|
||||
PyCallClassMemberFunc(target,name,args); // ScriptLib semantics: skip missing, PyErr_Print on error
|
||||
}
|
||||
}
|
||||
bool PythonNetworkStream::RecvItemSetPacket() {
|
||||
@@ -811,6 +1042,66 @@ bool main_actor_can_act(uint32_t vid) {
|
||||
return actor && actor->CanAct();
|
||||
}
|
||||
}
|
||||
bool PythonNetworkStream::SendPrivateShopSearchInfo(const TPacketCGShopSearch& p) {
|
||||
if(!main_actor_can_act(m_dwMainActorVID))return true;
|
||||
std::vector<uint8_t> bytes{HEADER_CG_SHOP_SEARCH};
|
||||
auto put=[&](uint64_t value,unsigned width) { for(unsigned i=0;i<width;++i)bytes.push_back(uint8_t(value>>(8*i))); };
|
||||
put(uint32_t(p.ItemCat),4);put(uint32_t(p.SubCat),4);
|
||||
bytes.insert(bytes.end(),p.searchInput,p.searchInput+50);
|
||||
for(const auto* pair:{p.avg,p.skill,p.abs,p.level,p.refine})bytes.insert(bytes.end(),pair,pair+2);
|
||||
bytes.insert(bytes.end(),{p.sex,p.enchant,p.alchemy,p.character});
|
||||
put(uint64_t(p.price[0]),8);put(uint64_t(p.price[1]),8);
|
||||
// Unlike normal gameplay transactions, Windows does not call SendSequence here.
|
||||
SendUnsequenced(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendSwitchbotPacket(bool start,uint8_t slot) {
|
||||
// Original has no main-actor action gate. Preserve slot6's declared37/actual7 quirk.
|
||||
std::vector<uint8_t> bytes{HEADER_CG_SWITCHBOT,uint8_t(start?37:7),0,0,0,uint8_t(start?SUBHEADER_CG_SWITCHBOT_START:SUBHEADER_CG_SWITCHBOT_STOP),slot};
|
||||
if(start && slot<6) {
|
||||
const auto& alternatives=GetSwitchbotState().table.alternatives[slot];
|
||||
for(const auto& alt:alternatives)for(const auto& a:alt.attributes) {
|
||||
const uint16_t value=uint16_t(a.sValue);bytes.push_back(a.bType);bytes.push_back(uint8_t(value));bytes.push_back(uint8_t(value>>8));
|
||||
}
|
||||
}
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendDungeonInfoPacket(uint8_t subheader,int32_t index) {
|
||||
if(!main_actor_can_act(m_dwMainActorVID))return true;
|
||||
// OPEN leaves index undefined in Windows; deterministic zero padding here.
|
||||
const uint32_t value=subheader==DUNGEON_INFO_SUB_HEADER_OPEN?0:uint32_t(index);
|
||||
const uint8_t bytes[]={HEADER_CG_DUNGEON_INFO_SYSTEM,subheader,uint8_t(value),uint8_t(value>>8),uint8_t(value>>16),uint8_t(value>>24)};
|
||||
Send(bytes,sizeof(bytes));return true; // All four original senders use SendSequence.
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendDropItemPacket(bool search,int32_t vnum) {
|
||||
if(!main_actor_can_act(m_dwMainActorVID))return true;
|
||||
// Original OPEN leaves vnum undefined. Zero its padding deterministically.
|
||||
const uint32_t value=search?uint32_t(vnum):0;
|
||||
const uint8_t bytes[]={HEADER_CG_DROP_ITEM_SYSTEM,uint8_t(search?DROP_ITEM_SUB_HEADER_SEARCH:DROP_ITEM_SUB_HEADER_OPEN),
|
||||
uint8_t(value),uint8_t(value>>8),uint8_t(value>>16),uint8_t(value>>24)};
|
||||
Send(bytes,sizeof(bytes));return true; // Both original senders use SendSequence.
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendBattlePassPacket(bool reward,int32_t index) {
|
||||
if(!main_actor_can_act(m_dwMainActorVID))return true;
|
||||
// Windows OPEN leaves index undefined; deterministic zero padding on the port.
|
||||
const uint32_t value=reward?uint32_t(index):0;
|
||||
const uint8_t bytes[]={HEADER_CG_BATTLEPASS,uint8_t(reward?BATTLEPASS_SUB_HEADER_REWARD:BATTLEPASS_SUB_HEADER_OPEN),
|
||||
uint8_t(value),uint8_t(value>>8),uint8_t(value>>16),uint8_t(value>>24)};
|
||||
Send(bytes,sizeof(bytes));return true; // Original SendSequence() applies to both.
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendCubeRenewalPacket(bool close,uint32_t index,uint32_t count) {
|
||||
if(!main_actor_can_act(m_dwMainActorVID))return true;
|
||||
// Close leaves index/count undefined on Windows; deterministically zero them.
|
||||
std::array<uint8_t,10> bytes{};bytes[0]=HEADER_CG_CUBE_RENEWAL;
|
||||
bytes[1]=close?CUBE_RENEWAL_SUB_HEADER_CLOSE:CUBE_RENEWAL_SUB_HEADER_MAKE_ITEM;
|
||||
if(!close)for(unsigned i=0;i<4;++i) { bytes[2+i]=uint8_t(index>>(i*8));bytes[6+i]=uint8_t(count>>(i*8)); }
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendQuickSlotAddPacket(uint8_t index,uint8_t type,uint8_t pos) {
|
||||
if(!main_actor_can_act(m_dwMainActorVID)) return true;
|
||||
const uint8_t bytes[]={HEADER_CG_QUICKSLOT_ADD,index,type,pos};Send(bytes,sizeof(bytes));return true;
|
||||
@@ -933,8 +1224,15 @@ bool PythonNetworkStream::SendAttackPacket(uint8_t type, uint32_t victimVID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendChatPacket(const std::string& text,uint8_t type) {
|
||||
bool PythonNetworkStream::SendChatPacket(const std::string& input,uint8_t type) {
|
||||
if(m_phase!=PHASE_GAME) return false;
|
||||
if(input.empty() || input.size()>=512) return true;
|
||||
std::string text=input;
|
||||
if(text[0]=='/') {
|
||||
if(text.size()==1) { if(!m_strLastCommand.empty()) text=m_strLastCommand; }
|
||||
else m_strLastCommand=text;
|
||||
}
|
||||
// ClientCommand() always returns false in AVA2.
|
||||
auto bytes=wire::chat(text,type);Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendWhisperPacket(const std::string& name,const std::string& text) {
|
||||
@@ -943,6 +1241,12 @@ bool PythonNetworkStream::SendWhisperPacket(const std::string& name,const std::s
|
||||
|
||||
bool PythonNetworkStream::SendItemUsePacket(uint8_t window, uint16_t cell) {
|
||||
if(!main_actor_can_act(m_dwMainActorVID)) return true;
|
||||
if(IsPlayerEquipmentItem(window,cell)) {
|
||||
const char* error=CPythonExchange::Instance().isTrading()?"CANNOT_EQUIP_EXCHANGE":IsShopOpen()?"CANNOT_EQUIP_SHOP":nullptr;
|
||||
if(error) {PyCallClassMemberFunc(m_phaseWindows[5],"BINARY_AppendNotifyMessage",Py_BuildValue("(s)",error));return true;}
|
||||
if(auto actor=NetworkActorManager::Instance().GetActorInstance(m_dwMainActorVID);actor&&actor->IsAttacking())return true;
|
||||
}
|
||||
PlayItemUseSound(GetPlayerItemData(window,cell).vnum);
|
||||
TPacketCGItemUse p;
|
||||
p.header = HEADER_CG_ITEM_USE;
|
||||
p.Cell.window_type = window;
|
||||
@@ -953,6 +1257,14 @@ bool PythonNetworkStream::SendItemUsePacket(uint8_t window, uint16_t cell) {
|
||||
|
||||
bool PythonNetworkStream::SendItemMovePacket(uint8_t srcWindow, uint16_t srcCell, uint8_t dstWindow, uint16_t dstCell, uint32_t count) {
|
||||
if(!main_actor_can_act(m_dwMainActorVID)) return true;
|
||||
if(IsPlayerEquipmentItem(srcWindow,srcCell)) {
|
||||
const bool equipDestination=(dstWindow==1||dstWindow==2)&&dstCell>=180&&dstCell<216;
|
||||
const bool equipSource=(srcWindow==1||srcWindow==2)&&srcCell>=180&&srcCell<216;
|
||||
const char* error=CPythonExchange::Instance().isTrading()?"CANNOT_EQUIP_EXCHANGE":IsShopOpen()?"CANNOT_EQUIP_SHOP":nullptr;
|
||||
if(error&&(equipSource||equipDestination)) {PyCallClassMemberFunc(m_phaseWindows[5],"BINARY_AppendNotifyMessage",Py_BuildValue("(s)",error));return true;}
|
||||
if(auto actor=NetworkActorManager::Instance().GetActorInstance(m_dwMainActorVID);actor&&actor->IsAttacking())return true;
|
||||
}
|
||||
PlayItemDropSound(GetPlayerItemData(srcWindow,srcCell).vnum);
|
||||
TPacketCGItemMove p;
|
||||
p.header = HEADER_CG_ITEM_MOVE;
|
||||
p.Cell.window_type = srcWindow;
|
||||
@@ -1092,19 +1404,31 @@ bool PythonNetworkStream::RecvExchangePacket() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendExchangeStartPacket(uint32_t vid) {
|
||||
// AVA2 PythonNetworkStreamPhaseGame.cpp: every exchange sender is gated by __CanActMainInstance().
|
||||
// Fields a sender leaves alone keep TItemPos's ctor value {INVENTORY, WORD_MAX}; the rest is emitted as zero.
|
||||
namespace {
|
||||
TPacketCGExchange exchange_packet(uint8_t subheader) {
|
||||
TPacketCGExchange p{};
|
||||
p.header = HEADER_CG_EXCHANGE;
|
||||
p.subheader = EXCHANGE_SUBHEADER_CG_START;
|
||||
p.subheader = subheader;
|
||||
p.Pos.window_type = 1; // INVENTORY
|
||||
p.Pos.cell = 0xffff; // WORD_MAX
|
||||
return p;
|
||||
}
|
||||
bool main_actor_can_act(uint32_t vid);
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendExchangeStartPacket(uint32_t vid) {
|
||||
if (!main_actor_can_act(m_dwMainActorVID)) return true;
|
||||
auto p = exchange_packet(EXCHANGE_SUBHEADER_CG_START);
|
||||
p.arg1 = vid;
|
||||
Send(&p, sizeof(p));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendExchangeItemAddPacket(uint8_t window, uint16_t cell, uint8_t exchangePos) {
|
||||
TPacketCGExchange p{};
|
||||
p.header = HEADER_CG_EXCHANGE;
|
||||
p.subheader = EXCHANGE_SUBHEADER_CG_ITEM_ADD;
|
||||
if (!main_actor_can_act(m_dwMainActorVID)) return true;
|
||||
auto p = exchange_packet(EXCHANGE_SUBHEADER_CG_ITEM_ADD);
|
||||
p.Pos.window_type = window;
|
||||
p.Pos.cell = cell;
|
||||
p.arg2 = exchangePos;
|
||||
@@ -1112,36 +1436,29 @@ bool PythonNetworkStream::SendExchangeItemAddPacket(uint8_t window, uint16_t cel
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendExchangeItemDelPacket(uint8_t exchangePos) {
|
||||
TPacketCGExchange p{};
|
||||
p.header = HEADER_CG_EXCHANGE;
|
||||
p.subheader = EXCHANGE_SUBHEADER_CG_ITEM_DEL;
|
||||
p.arg2 = exchangePos;
|
||||
Send(&p, sizeof(p));
|
||||
bool PythonNetworkStream::SendExchangeItemDelPacket(uint8_t) {
|
||||
// Windows: assert(!"Can't be called function"); return true; -- nothing is sent.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendExchangeElkAddPacket(int64_t elk) {
|
||||
TPacketCGExchange p{};
|
||||
p.header = HEADER_CG_EXCHANGE;
|
||||
p.subheader = EXCHANGE_SUBHEADER_CG_ELK_ADD;
|
||||
if (!main_actor_can_act(m_dwMainActorVID)) return true;
|
||||
auto p = exchange_packet(EXCHANGE_SUBHEADER_CG_ELK_ADD);
|
||||
p.arg1 = elk;
|
||||
Send(&p, sizeof(p));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendExchangeAcceptPacket() {
|
||||
TPacketCGExchange p{};
|
||||
p.header = HEADER_CG_EXCHANGE;
|
||||
p.subheader = EXCHANGE_SUBHEADER_CG_ACCEPT;
|
||||
if (!main_actor_can_act(m_dwMainActorVID)) return true;
|
||||
auto p = exchange_packet(EXCHANGE_SUBHEADER_CG_ACCEPT);
|
||||
Send(&p, sizeof(p));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendExchangeExitPacket() {
|
||||
TPacketCGExchange p{};
|
||||
p.header = HEADER_CG_EXCHANGE;
|
||||
p.subheader = EXCHANGE_SUBHEADER_CG_CANCEL;
|
||||
if (!main_actor_can_act(m_dwMainActorVID)) return true;
|
||||
auto p = exchange_packet(EXCHANGE_SUBHEADER_CG_CANCEL);
|
||||
Send(&p, sizeof(p));
|
||||
return true;
|
||||
}
|
||||
@@ -1206,6 +1523,7 @@ bool PythonNetworkStream::RecvMallDelPacket() {
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendSafeBoxCheckinPacket(uint8_t window, uint16_t cell, uint8_t safeboxPos) {
|
||||
PlayItemDropSound(GetPlayerItemData(window,cell).vnum);
|
||||
TPacketCGSafeboxCheckin p{};
|
||||
p.header = HEADER_CG_SAFEBOX_CHECKIN;
|
||||
p.bSafeBoxPos = safeboxPos;
|
||||
@@ -1216,6 +1534,7 @@ bool PythonNetworkStream::SendSafeBoxCheckinPacket(uint8_t window, uint16_t cell
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendSafeBoxCheckoutPacket(uint8_t safeboxPos, uint8_t window, uint16_t cell) {
|
||||
uint32_t vnum;if(CPythonSafeBox::Instance().GetSlotItemID(safeboxPos,&vnum))PlayItemDropSound(vnum);
|
||||
TPacketCGSafeboxCheckout p{};
|
||||
p.header = HEADER_CG_SAFEBOX_CHECKOUT;
|
||||
p.bSafeBoxPos = safeboxPos;
|
||||
@@ -1225,13 +1544,12 @@ bool PythonNetworkStream::SendSafeBoxCheckoutPacket(uint8_t safeboxPos, uint8_t
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendSafeBoxItemMovePacket(uint8_t srcPos, uint8_t dstPos, uint8_t count) {
|
||||
TPacketCGSafeboxItemMove p{};
|
||||
p.header = HEADER_CG_SAFEBOX_ITEM_MOVE;
|
||||
p.bSourcePos = srcPos;
|
||||
p.bTargetPos = dstPos;
|
||||
p.bCount = count;
|
||||
Send(&p, sizeof(p));
|
||||
bool PythonNetworkStream::SendSafeBoxItemMovePacket(uint8_t srcPos, uint8_t dstPos, uint32_t count) {
|
||||
uint32_t vnum;if(CPythonSafeBox::Instance().GetSlotItemID(srcPos,&vnum))PlayItemDropSound(vnum);
|
||||
// Windows sends TPacketCGItemMove {header, pos, change_pos, DWORD num} under HEADER_CG_SAFEBOX_ITEM_MOVE.
|
||||
std::vector<uint8_t> bytes{HEADER_CG_SAFEBOX_ITEM_MOVE,1,srcPos,0,1,dstPos,0};
|
||||
for(int shift=0;shift<32;shift+=8) bytes.push_back(static_cast<uint8_t>(count>>shift));
|
||||
Send(bytes.data(), bytes.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1241,6 +1559,7 @@ bool PythonNetworkStream::SendSafeBoxMoneyPacket(uint8_t, uint32_t) {
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendMallCheckoutPacket(uint8_t safeboxPos, uint8_t window, uint16_t cell) {
|
||||
uint32_t vnum;if(CPythonSafeBox::Instance().GetSlotMallItemID(safeboxPos,&vnum))PlayItemDropSound(vnum);
|
||||
TPacketCGSafeboxCheckout p{};
|
||||
p.header = HEADER_CG_MALL_CHECKOUT;
|
||||
p.bSafeBoxPos = safeboxPos;
|
||||
@@ -1254,6 +1573,156 @@ namespace {
|
||||
void append16(std::vector<uint8_t>& bytes,uint16_t value) { bytes.push_back(value);bytes.push_back(value>>8); }
|
||||
void append32(std::vector<uint8_t>& bytes,uint32_t value) { for(int shift=0;shift<32;shift+=8) bytes.push_back(value>>shift); }
|
||||
}
|
||||
namespace {
|
||||
// strncpy(dst,src,n) into a zeroed fixed char field; bytes Windows leaves uninitialized are emitted as zero.
|
||||
void append_text(std::vector<uint8_t>& bytes,const char* text,size_t field,size_t copy) {
|
||||
const size_t start=bytes.size();bytes.resize(start+field,0);
|
||||
for(size_t i=0;i<copy && text[i];++i) bytes[start+i]=static_cast<uint8_t>(text[i]);
|
||||
}
|
||||
std::vector<uint8_t> guild_packet(uint8_t subheader) { return {HEADER_CG_GUILD,subheader}; }
|
||||
}
|
||||
|
||||
// ── Script / quest (AVA2 PythonNetworkStreamPhaseGame.cpp) ──
|
||||
bool PythonNetworkStream::SendAnswerMakeGuildPacket(const char* name) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_ANSWER_MAKE_GUILD};append_text(bytes,name,GUILD_NAME_MAX_LEN+1,GUILD_NAME_MAX_LEN);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendQuestInputStringPacket(const char* text) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_QUEST_INPUT_STRING};append_text(bytes,text,QUEST_INPUT_STRING_MAX_NUM+1,QUEST_INPUT_STRING_MAX_NUM);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendQuestInputStringLongPacket(const char* text) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_QUEST_INPUT_LONG_STRING};append_text(bytes,text,QUEST_INPUT_STRING_LONG_MAX_NUM,QUEST_INPUT_STRING_LONG_MAX_NUM);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendQuestConfirmPacket(uint8_t answer,uint32_t pid) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_QUEST_CONFIRM,answer};append32(bytes,pid);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendSelectItemPacket(uint32_t itemPos) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_SCRIPT_SELECT_ITEM};append32(bytes,itemPos);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendTargetInfoLoadPacket(uint32_t vid) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_TARGET_INFO_LOAD};append32(bytes,vid);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
|
||||
// ── Messenger ──
|
||||
bool PythonNetworkStream::SendMessengerAddByVIDPacket(uint32_t vid) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_MESSENGER,MESSENGER_SUBHEADER_CG_ADD_BY_VID};append32(bytes,vid);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendMessengerAddByNamePacket(const char* name) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_MESSENGER,MESSENGER_SUBHEADER_CG_ADD_BY_NAME};append_text(bytes,name,CHARACTER_NAME_MAX_LEN,CHARACTER_NAME_MAX_LEN-1);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendMessengerRemovePacket(const char* key,const char* name) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_MESSENGER,MESSENGER_SUBHEADER_CG_REMOVE};append_text(bytes,key,CHARACTER_NAME_MAX_LEN,CHARACTER_NAME_MAX_LEN-1);
|
||||
Send(bytes.data(),bytes.size());
|
||||
// __RefreshTargetBoardByName: PyCallClassMemberFunc skips a phase window without the method.
|
||||
if(auto* game=m_phaseWindows[5]; game && PyObject_HasAttrString(game,"RefreshTargetBoardByName"))
|
||||
inventory_callback(game,"RefreshTargetBoardByName",Py_BuildValue("(s)",name));
|
||||
return true;
|
||||
}
|
||||
|
||||
// ── Party ──
|
||||
bool PythonNetworkStream::SendPartyInvitePacket(uint32_t vid) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_PARTY_INVITE};append32(bytes,vid);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendPartyInviteAnswerPacket(uint32_t leaderPID,uint8_t answer) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_PARTY_INVITE_ANSWER};append32(bytes,leaderPID);bytes.push_back(answer);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendPartyRemovePacket(uint32_t pid) {
|
||||
if(m_phase!=PHASE_GAME) return false;
|
||||
std::vector<uint8_t> bytes{HEADER_CG_PARTY_REMOVE};append32(bytes,pid);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendPartySetStatePacket(uint32_t vid,uint8_t state,uint8_t flag) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_PARTY_SET_STATE};append32(bytes,vid);bytes.push_back(state);bytes.push_back(flag);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendPartyUseSkillPacket(uint8_t skillIndex,uint32_t vid) {
|
||||
std::vector<uint8_t> bytes{HEADER_CG_PARTY_USE_SKILL,skillIndex};append32(bytes,vid);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendPartyParameterPacket(uint8_t distributeMode) {
|
||||
const uint8_t bytes[]={HEADER_CG_PARTY_PARAMETER,distributeMode};
|
||||
Send(bytes,sizeof(bytes));return true;
|
||||
}
|
||||
|
||||
// ── Guild: TPacketCGGuild {header, subheader} followed by the raw payload ──
|
||||
bool PythonNetworkStream::SendGuildAddMemberPacket(uint32_t vid) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_ADD_MEMBER);append32(bytes,vid);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildRemoveMemberPacket(uint32_t pid) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_REMOVE_MEMBER);append32(bytes,pid);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildChangeGradeNamePacket(uint8_t grade,const char* name) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_CHANGE_GRADE_NAME);bytes.push_back(grade);
|
||||
append_text(bytes,name,GUILD_GRADE_NAME_MAX_LEN+1,GUILD_GRADE_NAME_MAX_LEN);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildChangeGradeAuthorityPacket(uint8_t grade,uint8_t authority) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_CHANGE_GRADE_AUTHORITY);bytes.push_back(grade);bytes.push_back(authority);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildOfferPacket(uint32_t experience) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_OFFER);append32(bytes,experience);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildPostCommentPacket(const char* message) {
|
||||
// BYTE(strlen)+1 wraps like Windows; that many bytes of the message (terminator included) follow.
|
||||
const uint8_t size=static_cast<uint8_t>(static_cast<uint8_t>(std::strlen(message))+1);
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_POST_COMMENT);bytes.push_back(size);
|
||||
bytes.insert(bytes.end(),message,message+size);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildDeleteCommentPacket(uint32_t index) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_DELETE_COMMENT);append32(bytes,index);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildRefreshCommentsPacket(uint32_t) {
|
||||
// Windows throttles with a static timeGetTime() stamp: one request per 1000 ms, extra calls return true.
|
||||
const auto now=std::chrono::steady_clock::now();
|
||||
if(m_lastGuildCommentRefresh && now-*m_lastGuildCommentRefresh<std::chrono::milliseconds(1000)) return true;
|
||||
m_lastGuildCommentRefresh=now;
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_REFRESH_COMMENT);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildChangeMemberGradePacket(uint32_t pid,uint8_t grade) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_CHANGE_MEMBER_GRADE);append32(bytes,pid);bytes.push_back(grade);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildUseSkillPacket(uint32_t skillID,uint32_t targetVID) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_USE_SKILL);append32(bytes,skillID);append32(bytes,targetVID);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildChangeMemberGeneralPacket(uint32_t pid,uint8_t flag) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_CHANGE_MEMBER_GENERAL);append32(bytes,pid);bytes.push_back(flag);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildInviteAnswerPacket(uint32_t guildID,uint8_t answer) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_GUILD_INVITE_ANSWER);append32(bytes,guildID);bytes.push_back(answer);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildChargeGSPPacket(uint32_t money) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_CHARGE_GSP);append32(bytes,money);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildDepositMoneyPacket(uint32_t money) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_DEPOSIT_MONEY);append32(bytes,money);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendGuildWithdrawMoneyPacket(uint32_t money) {
|
||||
auto bytes=guild_packet(GUILD_SUBHEADER_CG_WITHDRAW_MONEY);append32(bytes,money);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendRefinePacket(uint8_t pos,uint8_t type,uint8_t storage,int32_t index) {
|
||||
const uint8_t bytes[]={HEADER_CG_REFINE,pos,type,storage,static_cast<uint8_t>(index)};
|
||||
Send(bytes,sizeof(bytes));return true;
|
||||
@@ -1279,3 +1748,23 @@ bool PythonNetworkStream::SendScriptButtonPacket(int button) {
|
||||
}
|
||||
|
||||
} // namespace ava2
|
||||
|
||||
namespace ava2 {
|
||||
bool PythonNetworkStream::SendBuildOfflineShopPacket(const std::string& name,const std::vector<TOfflineShopItemTable>& items,uint32_t vnum,uint8_t title) {
|
||||
// Serialize the original Win32 packed layout. Original unused fields are zeroed.
|
||||
std::vector<uint8_t> bytes(53,0);bytes[0]=HEADER_CG_MY_OFFLINE_SHOP;
|
||||
std::copy_n(name.begin(),std::min(size_t(45),name.size()),bytes.begin()+1);
|
||||
bytes[47]=static_cast<uint8_t>(items.size());
|
||||
for(unsigned i=0;i<4;++i)bytes[48+i]=uint8_t(vnum>>(8*i));bytes[52]=title;
|
||||
auto put=[&](uint64_t value,unsigned width) {for(unsigned i=0;i<width;++i)bytes.push_back(uint8_t(value>>(8*i)));};
|
||||
for(const auto& item:items) {put(item.vnum,4);put(uint32_t(item.count),4);put(item.pos.window_type,1);put(item.pos.cell,2);put(uint64_t(item.price),8);put(item.display_pos,1);}
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
bool PythonNetworkStream::SendOfflineShopChangeDecoration(const std::string& sign,uint32_t vnum,uint32_t type) {
|
||||
std::vector<uint8_t> bytes(110,0);bytes[0]=57;bytes[1]=12;
|
||||
std::copy_n(sign.begin(),std::min(size_t(45),sign.size()),bytes.begin()+58);
|
||||
// Original owner_id is never assigned; deterministic zero avoids leaking memory.
|
||||
bytes[108]=uint8_t(vnum);bytes[109]=uint8_t(type);
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user