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
+463
-41
@@ -1,20 +1,31 @@
|
||||
#include "item_proto.h"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include "skill_description.h"
|
||||
#include "python_runtime.h"
|
||||
#include "nonplayer_data.h"
|
||||
#include "python_wiki.h"
|
||||
#include "python_app.h"
|
||||
#include "pet_skill_state.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "python_native_modules.h"
|
||||
#include "python_net.h"
|
||||
#include "python_chat.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include "eter_net/NetworkActorManager.h"
|
||||
#include "eter_net/PythonSafeBox.h"
|
||||
#include "eter_render/ActorInstance.h"
|
||||
#include "eter_resource/ResourceManager.h"
|
||||
#include "eter_render/RaceData.h"
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include "test_rundir.h"
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3) return 2;
|
||||
if(!ava2_test::EnterTestRunDir()) return ava2_test::kSkip;
|
||||
try {
|
||||
ava2::SkillDescriptions fixture;
|
||||
if(!fixture.load("900\tWARRIOR\tBase\t\t\tDescription\tFirst\t\tThird\tIgnored fourth\tTOGGLE|STANDING_SKILL|USE_HP\t\ticon\r\n")) throw std::runtime_error("fixture load failed");
|
||||
@@ -61,7 +72,43 @@ int main(int argc,char** argv) {
|
||||
if(!items.load(ava2::ReadPackedText("locale/en/item_proto")))throw std::runtime_error("original item proto rejected");
|
||||
auto sword=items.records.find(10);
|
||||
if(sword==items.records.end()||sword->second.name!="Sword+0"||sword->second.type!=1||sword->second.size!=2)throw std::runtime_error("original item proto fields mismatch");
|
||||
python.execute("import item, app\nitem.LoadItemTable('locale/en/item_proto')\n");
|
||||
python.execute("import item, app\n");
|
||||
// app.LoadLocaleData: original order item_list -> item_proto -> ... -> mob_scale -> item_scale.
|
||||
python.execute("import net\nassert app.LoadLocaleData('locale/en')==1\nassert net.IsInsultIn('you SHIT')==1 and net.IsInsultIn('hello')==0\nassert net.IsChatInsultIn('shit')==1\nnet.EnableChatInsultFilter(1)\nassert net.IsChatInsultIn('shit')==0\nnet.EnableChatInsultFilter(0)\n");
|
||||
{
|
||||
auto& pets=ava2::GetPetSkillState().records;
|
||||
if(pets.size()!=18||pets.at(17).delay!=600||pets.at(17).icon!="d:/ymir work/ui/skill/pet/invincibility.sub"||pets.at(1).type!=ava2::SKILLPET_TYPE_PASSIVE)throw std::runtime_error("LoadLocaleData pet_skill mismatch");
|
||||
auto* scale=ava2::NonPlayerData::Instance().getMobScale(8061);
|
||||
if(!scale||std::fabs(scale->x-1.3f)>1e-6f)throw std::runtime_error("LoadLocaleData mob_scale mismatch");
|
||||
ava2::ItemScaleInfo sash; // 85001 JOB_ASSASSIN M 69 68 88 0 0 0.52 -> tInfo[2] for vnum 85001..85005
|
||||
if(!ava2::GetItemScale(85005,2,&sash)||std::fabs(sash.scaleX-0.69f)>1e-6f||std::fabs(sash.positionZ-52.0f)>1e-4f)throw std::runtime_error("LoadLocaleData item_scale mismatch");
|
||||
char chat[]="Bob : you shit head";auto& stream=ava2::PythonNetworkStream::Instance();
|
||||
stream.FilterInsult(chat+6,std::strlen(chat+6));
|
||||
if(std::string(chat)!="Bob : you **** head")throw std::runtime_error(std::string("insult filter mismatch: ")+chat);
|
||||
if(ava2::LoadLocaleData("locale/missing")||!ava2::GetPetSkillState().records.empty())throw std::runtime_error("missing locale must fail after Destroy()");
|
||||
if(!ava2::LoadLocaleData("locale/en"))throw std::runtime_error("locale reload failed");
|
||||
}
|
||||
{
|
||||
// CPythonWiki::ReadData (ENABLE_WIKI): locale/common text tables fed from memory, item_proto/mob_proto from locale/en.
|
||||
using ava2::WikiTextFile;
|
||||
if(!ava2::WikiLoadText(WikiTextFile::RefineTable,"refine_table.txt","#id\tv0\n7\t27001\t2\t0\t0\t27002\t1\t0\t0\t0\t0\t1500\t0\t0\t90\r\n8\t1\t2\n")||
|
||||
!ava2::WikiLoadText(WikiTextFile::SpecialItemGroup,"special_item_group.txt","Group\tA\n{\n\tVnum\t77900\n\t1\t55101\t1\t30\n\t2\t55108\t1\t30\n}\nGroup\tB\n{\n\tVnum\t77900\n\t1\t1\t1\t1\n}\n")||
|
||||
!ava2::WikiLoadText(WikiTextFile::MobDropItem,"mob_drop_item.txt","Group\tBOSS\n{\n\tMob\t191\n\tType\tdrop\n\t1\t30037\t1\t100\n\t2\t76023\t10\t100\n}\n"))
|
||||
throw std::runtime_error("wiki text tables failed to load");
|
||||
python.execute("import wiki\n"
|
||||
"assert wiki.GetRefineItems(7)==(7,27001,2,0,0,27002,1,0,0,0,0,1500,90,3)\nassert wiki.GetRefineItems(8)==0\n"
|
||||
"assert wiki.GetSpecialInfoSize(77900)==2 and wiki.GetSpecialInfoData(77900,1)==(55108,1)\n"
|
||||
"assert wiki.GetMobInfoSize(191)==2 and wiki.GetMobInfoData(191,1)==(76023,10) and wiki.GetMobInfoData(192,0)==(0,0)\n"
|
||||
"assert wiki.GetItemDropFromMonster(30037,False)==[191] and wiki.GetItemDropFromMonster(30046,True)==[191] and wiki.GetItemDropFromMonster(30047,True)==[]\n"
|
||||
"assert wiki.GetItemDropFromChest(55108,0)==[77900]\n"
|
||||
"assert wiki.IsBlackList(529,0,0)==1 and wiki.IsBlackList(10,0,529)==0\n"
|
||||
"assert wiki.GetBossSize(3)==2 and wiki.GetBossData(3,1)==2493\n"
|
||||
"assert wiki.GetCostumeSize(0)==53 and wiki.GetCostumeData(4,0)==65000 and wiki.GetCostumeSize(9)==0\n"
|
||||
"assert wiki.GetRefineMaxLevel(10)==9\n"
|
||||
"assert wiki.GetCategorySize(0,0)>0 and wiki.GetCategorySize(4,0)==0\n"
|
||||
"item.SelectItem(wiki.GetCategoryData(0,0,0))\nassert item.GetItemType()==1 and '+9' in item.GetItemName()\n"
|
||||
"assert wiki.GetStoneSize(0)>0 and 8001<=wiki.GetStoneData(0,0)<=8056\n");
|
||||
}
|
||||
python.execute("import shop\nassert shop.IsOpen()==0\nassert shop.GetTabCount()==1\nshop.Open()\nassert shop.IsOpen()==1\nshop.Close()\nassert shop.IsOpen()==0\nshop.Open()\nshop.Clear()\nassert shop.IsOpen()==0\nassert shop.GetTabCount()==1\n");
|
||||
if(!ava2::SetShopTabCount(3)||ava2::SetShopTabCount(4))throw std::runtime_error("shop tab capacity validation failed");
|
||||
ava2::SetShopTab(0,"Weapons",0);ava2::SetShopTab(2,"Special",257);
|
||||
@@ -274,10 +321,11 @@ int main(int argc,char** argv) {
|
||||
if(items.load("MIPX")||items.records.size()!=countBefore)throw std::runtime_error("truncated item proto damaged records");
|
||||
auto originalWorkingDir=std::filesystem::current_path();
|
||||
std::filesystem::current_path(std::filesystem::temp_directory_path());
|
||||
python.execute("import item\nitem.SelectItem(10)\nassert item.GetItemName() == 'Sword+0'\nassert item.GetIconImageFileName() == 'icon/item/00010.tga'\nitem.LoadItemTable('locale/en/item_proto')\nassert item.GetItemName() == 'Sword+0'\nassert item.GetItemType() == 1\n");
|
||||
// This fixture mount has proto/text but no icon assets. Windows returns Noname rather than a declared path.
|
||||
python.execute("import item\nitem.SelectItem(10)\nassert item.GetItemName() == 'Sword+0'\nassert item.GetIconImageFileName() == 'Noname', item.GetIconImageFileName()\nitem.LoadItemTable('locale/en/item_proto')\nassert item.GetItemName() == 'Sword+0'\nassert item.GetItemType() == 1\n");
|
||||
std::filesystem::current_path(originalWorkingDir);
|
||||
if(!ava2::LoadSkillDescriptions("locale/en/SkillDesc.txt")) throw std::runtime_error("skill description load failed");
|
||||
if(!ava2::LoadSkillTable("locale/en/SkillTable.txt")) throw std::runtime_error("skill table file load failed");
|
||||
// SkillDesc/SkillTable were registered by app.LoadLocaleData above; registering again would
|
||||
// append duplicate affect rows exactly like CPythonSkill::RegisterSkillDesc without Destroy().
|
||||
ava2::SetPlayerStatusPoint(12,20);ava2::SetPlayerStatusPoint(204,80);
|
||||
if(std::fabs(ava2::EvaluateSkillFormula("str+ar*100+k",0.5f)-100.5f)>0.0001f || ava2::EvaluateSkillFormula("JeungJiFoo+k",0.5f)!=0.5f || ava2::EvaluateSkillFormula("UnknownState+k",0.5f)!=0)throw std::runtime_error("formula status binding mismatch " + std::to_string(ava2::EvaluateSkillFormula("str+ar*100+k",0.5f))+" / "+std::to_string(ava2::EvaluateSkillFormula("JeungJiFoo+k",0.5f))+" / "+std::to_string(ava2::EvaluateSkillFormula("1+",0.5f)));
|
||||
ava2::SetPlayerStatusPoint(12,0);ava2::SetPlayerStatusPoint(204,0);
|
||||
@@ -437,6 +485,7 @@ int main(int argc,char** argv) {
|
||||
"assert chr.HasInstance(101) == 1\n"
|
||||
"chr.SelectInstance(101)\n"
|
||||
"chr.SetRace(0)\n"
|
||||
"chr.SetArmor(0)\n"
|
||||
"assert chr.GetRace() == 0\n"
|
||||
"chr.SetWeapon(11299)\n"
|
||||
"chr.SetHair(1)\n"
|
||||
@@ -486,7 +535,7 @@ int main(int argc,char** argv) {
|
||||
"chr.SetNameString('DogMaster')\n"
|
||||
"assert chr.GetName() == 'DogMaster'\n"
|
||||
"assert chr.GetNameByVID(201) == 'DogMaster'\n"
|
||||
"pos = chr.GetPixelPosition()\n"
|
||||
"pos = chr.GetPixelPosition(201)\n"
|
||||
"assert pos[0] == 500.0 and pos[1] == 600.0\n"
|
||||
"textTail.RegisterItemTextTail(555, 'Full Moon Sword +9', 120, 'TestHero')\n"
|
||||
"textTail.ShowAllTextTail()\n"
|
||||
@@ -546,21 +595,20 @@ int main(int argc,char** argv) {
|
||||
"net.SendGiveItemPacket(1001, 0, 1)\n"
|
||||
"print 'Testing Quest Dialog System (uiquest & event)...'\n"
|
||||
"import event\n"
|
||||
"assert event.BUTTON_TYPE_CANCEL == 0\n"
|
||||
"assert event.BUTTON_TYPE_NEXT == 0\n"
|
||||
"assert event.BUTTON_TYPE_DONE == 1\n"
|
||||
"assert event.BUTTON_TYPE_NEXT == 2\n"
|
||||
"event.RegisterEventSet(1)\n"
|
||||
"event.InsertText(1, 'Welcome Adventurer!')\n"
|
||||
"event.InsertTextInline(1, ' Accept quest:')\n"
|
||||
"assert event.GetLineCount(1) >= 1\n"
|
||||
"assert event.GetLineHeight(1) >= 10\n"
|
||||
"assert event.GetEventSetLocalYPosition(1) >= 10\n"
|
||||
"event.SelectAnswer(1, 254)\n"
|
||||
"event.ClearEventSet(1)\n"
|
||||
"assert event.BUTTON_TYPE_CANCEL == 2\n"
|
||||
"evt = event.RegisterEventSetFromString('[ENTER]')\n"
|
||||
"event.InsertText(evt, 'Welcome Adventurer!')\n"
|
||||
"event.InsertTextInline(evt, ' Accept quest:', 40)\n"
|
||||
"assert event.GetLineCount(evt) == 2\n"
|
||||
"assert event.GetEventSetLocalYPosition(evt) >= 10\n"
|
||||
"event.SelectAnswer(evt, 254)\n"
|
||||
"event.ClearEventSet(evt)\n"
|
||||
"import uiquest\n"
|
||||
"event.RegisterEventSet(2)\n"
|
||||
"event.InsertText(2, 'Quest: Clear Wild Boars')\n"
|
||||
"questDlg = uiquest.QuestDialog(1, 2)\n"
|
||||
"evt = event.RegisterEventSetFromString('[ENTER]')\n"
|
||||
"event.InsertText(evt, 'Quest: Clear Wild Boars')\n"
|
||||
"questDlg = uiquest.QuestDialog(1, evt)\n"
|
||||
"questDlg.MakeNextButton(event.BUTTON_TYPE_NEXT)\n"
|
||||
"questDlg.MakeQuestion(3)\n"
|
||||
"questDlg.OnUpdate()\n"
|
||||
@@ -819,31 +867,405 @@ int main(int argc,char** argv) {
|
||||
if(netStream.SendSafeBoxMoneyPacket(0,100) || !netStream.GetSendQueue().empty()) throw std::runtime_error("disabled AVA2 storage money emitted party packet");
|
||||
netStream.SetPhase(ava2::PHASE_GAME);
|
||||
|
||||
// Test Chat packet reception
|
||||
bool chatCallbackFired = false;
|
||||
netStream.SetChatCallback([&](uint8_t type, const std::string& text, uint32_t vid) {
|
||||
(void)type;
|
||||
(void)vid;
|
||||
chatCallbackFired = true;
|
||||
if (text != "Server: Welcome to AVA2!") {
|
||||
throw std::runtime_error("Chat text content mismatch: " + text);
|
||||
}
|
||||
});
|
||||
std::string chatMsg = "Server: Welcome to AVA2!";
|
||||
std::vector<uint8_t> chatBuf(sizeof(ava2::TPacketGCChat) + chatMsg.size());
|
||||
auto* chatPkt = reinterpret_cast<ava2::TPacketGCChat*>(chatBuf.data());
|
||||
chatPkt->header = ava2::HEADER_GC_CHAT;
|
||||
chatPkt->size = static_cast<uint16_t>(chatBuf.size());
|
||||
chatPkt->type = ava2::CHAT_TYPE_NOTICE;
|
||||
chatPkt->dwVID = 0;
|
||||
chatPkt->bEmpire = 1;
|
||||
std::memcpy(chatBuf.data() + sizeof(ava2::TPacketGCChat), chatMsg.data(), chatMsg.size());
|
||||
netStream.PushRecvData(chatBuf.data(), chatBuf.size());
|
||||
netStream.ProcessRecvData();
|
||||
if (!chatCallbackFired) {
|
||||
throw std::runtime_error("Chat callback did not fire upon receiving TPacketGCChat!");
|
||||
// AVA2 Windows golden layouts for the net.Send* wrappers that used to be placeholders.
|
||||
{
|
||||
using bytes_t=std::vector<uint8_t>;
|
||||
auto le32=[](bytes_t b,uint32_t v){ for(int i=0;i<32;i+=8) b.push_back(uint8_t(v>>i)); return b; };
|
||||
auto text=[](bytes_t b,const std::string& value,size_t field){ size_t start=b.size();b.resize(start+field,0);std::copy(value.begin(),value.end(),b.begin()+start);return b; };
|
||||
auto expect=[&](const char* call,const bytes_t& expected,const char* what){
|
||||
netStream.ClearSendQueue();python.execute(std::string(call)+"\n");
|
||||
if(netStream.PopSendBytes()!=expected) throw std::runtime_error(std::string("AVA2 Windows layout mismatch: ")+what);
|
||||
};
|
||||
// Exchange: TPacketCGExchange {header, sub, long long arg1, BYTE arg2, TItemPos(ctor {INVENTORY,WORD_MAX})}
|
||||
expect("net.SendExchangeStartPacket(0x01020304)",{27,0,4,3,2,1,0,0,0,0,0,1,255,255},"exchange start");
|
||||
expect("net.SendExchangeElkAddPacket(0x123456789)",{27,3,0x89,0x67,0x45,0x23,1,0,0,0,0,1,255,255},"exchange elk (long long)");
|
||||
expect("net.SendExchangeItemAddPacket(1,0x1234,300)",{27,1,0,0,0,0,0,0,0,0,44,1,0x34,0x12},"exchange item add");
|
||||
expect("net.SendExchangeItemDelPacket(3)",{},"exchange item del must be a Windows no-op");
|
||||
expect("net.SendExchangeAcceptPacket()",{27,4,0,0,0,0,0,0,0,0,0,1,255,255},"exchange accept");
|
||||
expect("net.SendExchangeExitPacket()",{27,5,0,0,0,0,0,0,0,0,0,1,255,255},"exchange cancel");
|
||||
// Safebox / mall
|
||||
expect("net.SendSafeboxCheckinPacket(7,3)",{70,3,1,7,0},"safebox checkin (2 args)");
|
||||
expect("net.SendSafeboxCheckinPacket(6,0x0102,3)",{70,3,6,2,1},"safebox checkin (3 args)");
|
||||
expect("net.SendSafeboxCheckoutPacket(4,9)",{71,4,1,9,0},"safebox checkout (2 args)");
|
||||
expect("net.SendSafeboxItemMovePacket(5,6,70000)",{77,1,5,0,1,6,0,0x70,0x11,1,0},"safebox move = TPacketCGItemMove");
|
||||
expect("net.SendMallCheckoutPacket(2,1,8)",{69,2,1,8,0},"mall checkout");
|
||||
expect("net.SendMallCheckoutPacket(2)",{},"mall checkout bad arity");
|
||||
expect("net.SendSafeboxSaveMoneyPacket(100)\nnet.SendSafeboxWithdrawMoneyPacket(100)",{},"disabled safebox money");
|
||||
// Messenger
|
||||
expect("net.SendMessengerAddByVIDPacket(0x0a0b0c0d)",le32({67,0},0x0a0b0c0d),"messenger add by vid");
|
||||
expect("net.SendMessengerAddByNamePacket('A'*30)",text({67,1},std::string(23,'A'),24),"messenger add by name");
|
||||
python.execute("class BoardCallbacks:\n def __init__(self):\n self.names=[]\n def RefreshTargetBoardByName(self,name):\n self.names.append(name)\nboard_callbacks=BoardCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,board_callbacks)\n");
|
||||
expect("net.SendMessengerRemovePacket('Key','Friend')",text({67,2},"Key",24),"messenger remove");
|
||||
python.execute("assert board_callbacks.names==['Friend']\nnet.ClearPhaseWindow(net.PHASE_WINDOW_GAME,board_callbacks)\n");
|
||||
// Party
|
||||
expect("net.SendPartyInvitePacket(77)",le32({72},77),"party invite");
|
||||
auto answer=le32({73},88);answer.push_back(1);
|
||||
expect("net.SendPartyInviteAnswerPacket(88,1)",answer,"party invite answer");
|
||||
expect("net.SendPartyRemovePacket(99)",le32({74},99),"party remove (PID alias)");
|
||||
expect("net.SendPartyRemovePacketVID(54321)\nnet.SendPartyExitPacket()",{},"party VID lookups without party state");
|
||||
auto state=le32({75},5);state.push_back(2);state.push_back(1);
|
||||
expect("net.SendPartySetStatePacket(5,2,1)",state,"party set state");
|
||||
expect("net.SendPartyUseSkillPacket(3,6)",le32({76,3},6),"party use skill");
|
||||
expect("net.SendPartyParameterPacket(1)",{78,1},"party parameter");
|
||||
netStream.SetPhase(ava2::PHASE_SELECT);
|
||||
expect("net.SendPartyRemovePacketPID(99)",{},"party remove outside Game");
|
||||
netStream.SetPhase(ava2::PHASE_GAME);
|
||||
// Guild
|
||||
expect("net.SendGuildAddMemberPacket(11)",le32({80,0},11),"guild add member");
|
||||
expect("net.SendGuildRemoveMemberPacket('Nobody')",{},"guild remove without member list");
|
||||
expect("net.SendGuildChangeGradeNamePacket(2,'Captain12345')",text({80,2,2},"Captain1",9),"guild grade name");
|
||||
expect("net.SendGuildChangeGradeAuthorityPacket(2,7)",{80,3,2,7},"guild grade authority");
|
||||
expect("net.SendGuildOfferPacket(1000)",le32({80,4},1000),"guild offer");
|
||||
expect("net.SendGuildPostCommentPacket('hi')",{80,5,3,'h','i',0},"guild post comment");
|
||||
expect("net.SendGuildDeleteCommentPacket(4)",le32({80,6},4),"guild delete comment");
|
||||
netStream.ResetGuildCommentRefreshThrottle();
|
||||
expect("net.SendGuildRefreshCommentsPacket(0)\nnet.SendGuildRefreshCommentsPacket(0)",{80,7},"guild refresh 1000 ms throttle");
|
||||
auto grade=le32({80,8},12);grade.push_back(3);
|
||||
expect("net.SendGuildChangeMemberGradePacket(12,3)",grade,"guild member grade");
|
||||
expect("net.SendGuildUseSkillPacket(151,54321)",le32(le32({80,9},151),54321),"guild use skill");
|
||||
auto general=le32({80,10},12);general.push_back(1);
|
||||
expect("net.SendGuildChangeMemberGeneralPacket(12,1)",general,"guild member general");
|
||||
auto invite=le32({80,11},5);invite.push_back(1);
|
||||
expect("net.SendGuildInviteAnswerPacket(5,1)",invite,"guild invite answer");
|
||||
expect("net.SendGuildChargeGSPPacket(10)",le32({80,12},10),"guild charge gsp");
|
||||
expect("net.SendGuildDepositMoneyPacket(20)",le32({80,13},20),"guild deposit");
|
||||
expect("net.SendGuildWithdrawMoneyPacket(30)",le32({80,14},30),"guild withdraw");
|
||||
// Quest / script
|
||||
expect("net.SendAnswerMakeGuildPacket('GuildNameIsTooLong')",text({81},"GuildNameIsT",13),"answer make guild");
|
||||
expect("net.SendQuestInputStringPacket('abc')",text({30},"abc",65),"quest input string");
|
||||
expect("net.SendQuestInputLongStringPacket('abc')",text({214},"abc",512),"quest input long string");
|
||||
expect("net.SendQuestConfirmPacket(1,0x01020304)",{31,1,4,3,2,1},"quest confirm");
|
||||
expect("net.SendSelectItemPacket(9)",le32({114},9),"script select item");
|
||||
expect("net.SendTargetInfoLoad(54321)",le32({59},54321),"target info load");
|
||||
expect("net.SendRequestRefineInfoPacket(1)",{},"refine info is a Windows no-op");
|
||||
expect("net.SendExchangeStartPacket('x')",{},"ScriptLib argument failure returns None");
|
||||
// __CanActMainInstance gate on exchange
|
||||
netStream.SetMainActorVID(999);
|
||||
expect("net.SendExchangeStartPacket(1)\nnet.SendExchangeAcceptPacket()",{},"exchange without an acting main actor");
|
||||
netStream.SetMainActorVID(54321);
|
||||
}
|
||||
|
||||
// Chat / whisper / ServerCommand follow Windows RecvChatPacket, RecvWhisperPacket and
|
||||
// PythonNetworkStreamCommand.cpp (ENABLE_MULTILANGUAGE_SYSTEM branch).
|
||||
netStream.ResetConnection();netStream.SetPhase(ava2::PHASE_GAME);
|
||||
// RecvChatPacket appends into CPythonChat; set 0 (CHAT_SET_CHAT_WINDOW) holds every line.
|
||||
ava2::CPythonChat::Instance().Destroy();
|
||||
auto appendedLines=[]() {
|
||||
std::vector<std::string> out;
|
||||
if(const auto* lines=ava2::CPythonChat::Instance().GetChatLineDeque(0))
|
||||
for(const auto* line:*lines) out.push_back(std::to_string(line->iType)+":"+line->text);
|
||||
return out;
|
||||
};
|
||||
python.execute(
|
||||
"class ChatWnd:\n"
|
||||
" def __init__(self):\n self.calls=[]\n self.run=False\n"
|
||||
" def GetLocaleString(self,t,s):\n self.calls.append(('locale',t,s))\n"
|
||||
" def BINARY_ServerCommand_Run(self,s):\n self.calls.append(('run',s))\n return self.run\n"
|
||||
" def BINARY_Cube_Open(self,v):\n self.calls.append(('cube',v))\n"
|
||||
" def BINARY_Cube_UpdateInfo(self,g,v,c):\n self.calls.append(('cubeinfo',g,v,c))\n"
|
||||
" def OnMessengerAddFriendQuestion(self,n):\n self.calls.append(('friend',n))\n"
|
||||
" def OnRecvWhisper(self,t,n,l,lang,emp):\n self.calls.append(('whisper',t,n,l,lang,emp))\n"
|
||||
" def OnRecvWhisperSystemMessage(self,t,n,b):\n self.calls.append(('wsys',t,n,b))\n"
|
||||
" def OnRecvWhisperError(self,t,n,b):\n self.calls.append(('werr',t,n,b))\n"
|
||||
"chat_wnd=ChatWnd()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,chat_wnd)\n");
|
||||
auto chatWire=[](uint8_t type,uint32_t vid,const std::string& msg) {
|
||||
std::vector<uint8_t> out(sizeof(ava2::TPacketGCChat)+msg.size()+1,0);
|
||||
auto* pkt=reinterpret_cast<ava2::TPacketGCChat*>(out.data());
|
||||
pkt->header=ava2::HEADER_GC_CHAT;pkt->size=uint16_t(out.size());pkt->type=type;pkt->dwVID=vid;pkt->bEmpire=1;
|
||||
std::memcpy(out.data()+sizeof(ava2::TPacketGCChat),msg.data(),msg.size());
|
||||
return out;
|
||||
};
|
||||
auto feed=[&](const std::vector<uint8_t>& bytes) { netStream.PushRecvData(bytes.data(),bytes.size());netStream.ProcessRecvData(); };
|
||||
auto check=[&](bool ok,const char* what) { if(!ok) throw std::runtime_error(std::string("AVA2 chat parity: ")+what); };
|
||||
feed(chatWire(ava2::CHAT_TYPE_NOTICE,0,"Server: Welcome to AVA2!"));
|
||||
python.execute("assert chat_wnd.calls==[('locale',2,'Server: Welcome to AVA2!')], chat_wnd.calls\nchat_wnd.calls=[]\n");
|
||||
check(appendedLines().empty(),"VID 0 non-shout goes to GetLocaleString, not AppendChat");
|
||||
feed(chatWire(ava2::CHAT_TYPE_SHOUT,0,"Bob : hello"));
|
||||
check(appendedLines()==std::vector<std::string>{"6:Bob : hello"},"VID 0 shout goes to AppendChat");
|
||||
feed(chatWire(15,0,"ignored"));feed(chatWire(ava2::CHAT_TYPE_TALKING,4242,"Nobody : x"));
|
||||
check(appendedLines().size()==1,"type >= CHAT_TYPE_MAX_NUM and unknown chatter are dropped");
|
||||
python.execute("assert chat_wnd.calls==[], chat_wnd.calls\n");
|
||||
// CHAT_TYPE_COMMAND -> ServerCommand: BINARY_ServerCommand_Run first, then the C++ fallback.
|
||||
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"cube open 20383"));
|
||||
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"cube info 100 \"27001\" 2"));
|
||||
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"messenger_auth Alice"));
|
||||
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"ConsoleEnable"));
|
||||
python.execute(
|
||||
"assert chat_wnd.calls==[('run','cube open 20383'),('cube',20383),('run','cube info 100 \"27001\" 2'),('cubeinfo',100,27001,2),"
|
||||
"('run','messenger_auth Alice'),('friend','Alice')], chat_wnd.calls\n"
|
||||
"chat_wnd.calls=[]\nchat_wnd.run=True\n");
|
||||
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"cube open 1"));
|
||||
python.execute("assert chat_wnd.calls==[('run','cube open 1')], chat_wnd.calls\nchat_wnd.calls=[]\n");
|
||||
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"ObserverMode 1"));feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"sms"));
|
||||
python.execute("assert player.IsObserverMode()==0 and player.HasMobilePhoneNumber()==0\nchat_wnd.run=False\nchat_wnd.calls=[]\n");
|
||||
feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"ObserverMode 1"));feed(chatWire(ava2::CHAT_TYPE_COMMAND,0,"sms"));
|
||||
python.execute("assert player.IsObserverMode()==1 and player.HasMobilePhoneNumber()==1\nchat_wnd.calls=[]\n");
|
||||
// Whisper: 31-byte header with bLanguage/bEmpire.
|
||||
auto whisperWire=[](uint8_t type,const char* from,uint8_t language,uint8_t empire,const std::string& msg) {
|
||||
std::vector<uint8_t> out(31+msg.size()+1,0);
|
||||
out[0]=ava2::HEADER_GC_WHISPER;out[1]=uint8_t(out.size());out[2]=uint8_t(out.size()>>8);out[3]=type;
|
||||
std::memcpy(out.data()+4,from,std::strlen(from));out[29]=language;out[30]=empire;
|
||||
std::memcpy(out.data()+31,msg.data(),msg.size());
|
||||
return out;
|
||||
};
|
||||
feed(whisperWire(ava2::WHISPER_TYPE_CHAT,"Alice",2,3,"hi"));
|
||||
feed(whisperWire(ava2::WHISPER_TYPE_SYSTEM,"Alice",0,0,"sys"));
|
||||
feed(whisperWire(ava2::WHISPER_TYPE_NOT_EXIST,"Ghost",0,0,""));
|
||||
python.execute("assert chat_wnd.calls==[('whisper',0,'Alice','Alice : hi',2,3),('wsys',255,'Alice','sys'),('werr',1,'Ghost','')], chat_wnd.calls\n");
|
||||
// PyCallClassMemberFunc: a missing method or a raising callback never aborts the pump.
|
||||
python.execute("chat_wnd.GetLocaleString=None\ndel ChatWnd.OnRecvWhisper\ndef boom(*a):\n raise ValueError('callback error is printed, not thrown')\nchat_wnd.OnRecvWhisperSystemMessage=boom\n");
|
||||
feed(chatWire(ava2::CHAT_TYPE_NOTICE,0,"x"));
|
||||
feed(whisperWire(ava2::WHISPER_TYPE_CHAT,"Alice",0,0,"hi"));feed(whisperWire(ava2::WHISPER_TYPE_SYSTEM,"Alice",0,0,"sys"));
|
||||
// '/' repeats the last slash command (SendChatPacket m_strLastCommand).
|
||||
netStream.ClearSendQueue();netStream.SendChatPacket("/stat ht");netStream.SendChatPacket("/");
|
||||
auto sent=netStream.PopSendPackets();
|
||||
check(sent.size()==2 && sent[0]==sent[1],"'/' repeats the previous command");
|
||||
// CheckPacket framing: a fixed GamePhase packet is consumed, the next one still dispatches;
|
||||
// a partial dynamic packet waits; an unknown header clears the buffer and requests quit.
|
||||
ava2::CPythonChat::Instance().Destroy();
|
||||
std::vector<uint8_t> stream={114,0,0,0,0,0}; // HEADER_GC_SEPCIAL_EFFECT (type 0, unknown VID): fixed packet
|
||||
auto shout=chatWire(ava2::CHAT_TYPE_SHOUT,0,"A : b");
|
||||
stream.insert(stream.end(),shout.begin(),shout.end());
|
||||
netStream.PushRecvData(stream.data(),stream.size()-2);netStream.ProcessRecvData();
|
||||
check(netStream.GetUnportedPackets().empty() && appendedLines().empty(),"partial packet waits after a fixed packet");
|
||||
netStream.PushRecvData(stream.data()+stream.size()-2,2);netStream.ProcessRecvData();
|
||||
check(appendedLines().size()==1,"packet after a fixed one is dispatched");
|
||||
std::vector<uint8_t> unknown={250,1,2,3};unknown.insert(unknown.end(),shout.begin(),shout.end());
|
||||
feed(unknown);
|
||||
check(appendedLines().size()==1 && netStream.IsQuitRequested(),"unknown header clears the buffer and posts quit");
|
||||
netStream.ResetConnection();netStream.SetPhase(ava2::PHASE_GAME);
|
||||
check(!netStream.IsQuitRequested(),"ResetConnection clears the quit request");
|
||||
std::vector<uint8_t> bgm={ava2::HEADER_GC_MAIN_CHARACTER4_BGM_VOL};bgm.resize(75,0);
|
||||
bgm.insert(bgm.end(),shout.begin(),shout.end());feed(bgm);
|
||||
check(appendedLines().size()==1,"MAIN_CHARACTER4_BGM_VOL in Game phase is RecvDefaultPacket (buffer cleared)");
|
||||
ava2::CPythonChat::Instance().Destroy();
|
||||
python.execute("net.SetPhaseWindow(net.PHASE_WINDOW_GAME,0)\n");
|
||||
std::cout << "PhaseGame wire packet receive & dispatch verified successfully!\n";
|
||||
{
|
||||
// Pass 17: player-settings effects, GC114, emoticon gate, name colours, NPC wear, sash.
|
||||
auto& actors=ava2::NetworkActorManager::Instance();
|
||||
using NAM=ava2::NetworkActorManager;
|
||||
check(NAM::GetEffectCRC(17)!=0 && NAM::GetEffectCRC(NAM::EFFECT_EMOTICON)!=0,"introLoading/player settings registered effects");
|
||||
check(NAM::GetIndexedNameColor(NAM::NAMECOLOR_SHOP)!=0 && NAM::GetIndexedNameColor(NAM::NAMECOLOR_PK)!=0,"chrmgr.RegisterNameColor tables filled");
|
||||
ava2::SNetworkActorData pc;pc.m_dwVID=7001;pc.m_bType=6;pc.m_dwRace=1;pc.m_stName="Killer";pc.m_dwEmpireID=1;
|
||||
pc.m_dwStateFlags=NAM::ADD_CHARACTER_STATE_KILLER;actors.AppendActor(pc);
|
||||
check(actors.GetNameColorIndex(7001)==NAM::NAMECOLOR_PK,"KILLER state uses NAMECOLOR_PK");
|
||||
ava2::SNetworkActorData shop;shop.m_dwVID=7002;shop.m_bType=1;shop.m_dwRace=30001;shop.m_dwWeapon=5;actors.AppendActor(shop);
|
||||
check(actors.GetNameColorIndex(7002)==NAM::NAMECOLOR_SHOP,"race 30000-30020 NPC uses NAMECOLOR_SHOP");
|
||||
check(actors.GetActorData(7002)->m_dwWeapon==0,"non-PC without npc_wear takes no weapon");
|
||||
// GC114: 6 bytes, SE_CRITICAL attaches EFFECT_CRITICAL (17) to the actor.
|
||||
const size_t before=actors.GetActorData(7001)->m_attachedEffects.size();
|
||||
const uint8_t se[]={114,uint8_t(ava2::SE_CRITICAL),0x59,0x1b,0,0};
|
||||
netStream.PushRecvData(se,sizeof(se));netStream.ProcessRecvData();
|
||||
check(netStream.GetUnportedPackets().empty() && actors.GetActorData(7001)->m_attachedEffects.size()==before+1,"GC114 attaches the special effect");
|
||||
// SetEmoticon: one emoticon per 1000 ms (m_dwEmoticonTime).
|
||||
static uint32_t fakeNow=5000;actors.SetTimeSourceForTest([]{return fakeNow;});
|
||||
check(actors.IsPossibleEmoticon(7002),"fresh actor may show an emoticon");
|
||||
actors.SetEmoticon(7002,0);fakeNow=5500;
|
||||
check(!actors.IsPossibleEmoticon(7002),"emoticon blocked inside 1000 ms");
|
||||
actors.SetTimeSourceForTest(nullptr);
|
||||
// npc_wear.txt row (ENABLE_NPC_WEAR_ITEM): race/weapon/armor/hair/acce/mount/7 shining.
|
||||
auto& npd=ava2::NonPlayerData::Instance();
|
||||
npd.loadNPCWear("20016\tall\t2\t11\t12\t13\t86010\t0\t1\t2\t3\t4\t5\t6\t7\n");
|
||||
ava2::SNetworkActorData wear;wear.m_dwVID=7003;wear.m_bType=1;wear.m_dwRace=20016;actors.AppendActor(wear);
|
||||
const auto* w=actors.GetActorData(7003);
|
||||
check(w->m_dwRace==2 && w->m_dwWeapon==11 && w->m_dwArmor==12 && w->m_dwHair==13 && w->m_dwSash==1010
|
||||
&& w->m_shining[0]==1 && w->m_shining[ava2::CHR_SHINING_NUM-1]==ava2::CHR_SHINING_NUM,"npc_wear replaces race and parts");
|
||||
check(w->m_dwSashEffect!=0,"acce > 86000 attaches EFFECT_REFINED+EFFECT_SASH");
|
||||
actors.ChangeSash(7003,0);
|
||||
check(actors.GetActorData(7003)->m_dwSash==0 && actors.GetActorData(7003)->m_dwSashEffect==0,"ChangeSash clears the sash effect");
|
||||
npd.clearNPCWear();
|
||||
for(uint32_t vid:{7001u,7002u,7003u}) actors.RemoveActor(vid);
|
||||
}
|
||||
{
|
||||
// Pass 20: 64-bit Granny (Map_Sands shadow_dragon) loads and its curve2-compressed
|
||||
// animation (D4nK*/D3K* tracks) drives the bones instead of leaving them at bind.
|
||||
auto resolve=[](const char* p){
|
||||
std::error_code ec;
|
||||
for(const auto& c:CResourceManager::GetCandidatePaths(CResourceManager::NormalizePath(p)))
|
||||
if(std::filesystem::is_regular_file(c,ec)) return c;
|
||||
return std::string();
|
||||
};
|
||||
const std::string model=resolve("d:/ymir work/monster/shadow_dragon/shadow_dragon.gr2");
|
||||
const std::string run=resolve("d:/ymir work/monster/shadow_dragon/run.gr2");
|
||||
if(model.empty()||run.empty()) {
|
||||
std::cout<<"pass20 shadow_dragon assets missing: 64-bit gr2 checks skipped\n";
|
||||
} else {
|
||||
auto dragon=ava2::Gr2ModelInstance::Load(model);
|
||||
check(dragon && dragon->GetFile().magic()==gr2::Magic::Bit64_LE && !dragon->GetInfo().meshes.empty(),"64-bit shadow_dragon.gr2 loads with meshes");
|
||||
check(dragon && dragon->LoadExternalAnimation(run),"64-bit run.gr2 loads");
|
||||
if(dragon) {
|
||||
size_t compressed=0,decoded=0;
|
||||
gr2::LoadError err;auto anim=gr2::File::load_path(run,&err);
|
||||
if(anim) for(auto& t:anim->file_info().animations[0].tracks)
|
||||
if(t.rot_type.rfind("D4n",0)==0){++compressed;decoded+=!t.orientation.empty();}
|
||||
check(compressed>0 && decoded==compressed,"D4n compressed quaternion tracks decode");
|
||||
const float dur=dragon->GetAnimationDuration();
|
||||
float a[16]={},b[16]={},bind[16]={};
|
||||
const bool ok=dragon->GetBoneWorldTransform("Spine01_jnt",a,0.0f)
|
||||
&& dragon->GetBoneWorldTransform("Spine01_jnt",b,dur*0.5f)
|
||||
&& dragon->GetBoneWorldTransform("Spine01_jnt",bind,-1.0f);
|
||||
float moved=0.0f,fromBind=0.0f;bool finite=ok;
|
||||
for(int i=0;i<16;++i){finite&=std::isfinite(a[i])&&std::isfinite(b[i]);moved=std::max(moved,std::fabs(a[i]-b[i]));fromBind=std::max(fromBind,std::fabs(a[i]-bind[i]));}
|
||||
check(finite && dur>0.0f && moved>1e-3f && fromBind>1e-3f,"curve2 animation moves Spine01_jnt away from bind");
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
// Pass 18: CRaceManager .msm race/shape/hair, AttachWeapon bones and AttachSash on network actors.
|
||||
auto& actors=ava2::NetworkActorManager::Instance();
|
||||
using NAM=ava2::NetworkActorManager;using RD=ava2::RaceData;
|
||||
auto& races=ava2::RaceManager::Instance();
|
||||
races.LoadGameNPC("npclist.txt");races.LoadPlayerRaces();
|
||||
if(!races.GetRaceDataPointer(0)) {
|
||||
std::cout<<"pass18 race assets (warrior_m.msm) missing: mount checks skipped\n";
|
||||
} else {
|
||||
NAM::SetHairColorEnable(true);
|
||||
ava2::SNetworkActorData hero;hero.m_dwVID=7101;hero.m_bType=6;hero.m_dwRace=0;hero.m_dwArmor=1;
|
||||
hero.m_dwHair=1;hero.m_dwWeapon=10;hero.m_dwSash=1;hero.m_stName="Mounted";
|
||||
actors.AppendActor(hero);
|
||||
auto inst=actors.GetActorInstance(7101);
|
||||
check(inst && inst->GetRace()==0 && inst->GetShape()==1,"SetRace(0) + SetArmor(1) -> shape 1");
|
||||
check(inst->GetShapeModelFile().find("warrior_novice")!=std::string::npos,"ShapeData01 model requested");
|
||||
check(inst->GetPartModelPath(RD::PART_HAIR).find("hair_1_1")!=std::string::npos && inst->GetPartBone(RD::PART_HAIR).empty(),"HairData01 skinned on PART_HAIR");
|
||||
check(inst->GetPartItemID(RD::PART_WEAPON)==10 && inst->GetPartBone(RD::PART_WEAPON)=="equip_right_hand"
|
||||
&& inst->GetPartModelPath(RD::PART_WEAPON).find("00010")!=std::string::npos,"warrior weapon on equip_right_hand");
|
||||
check(inst->GetPartBone(RD::PART_SASH)=="Bip01 Spine2" && inst->GetPartModelPath(RD::PART_SASH).find("85_001")!=std::string::npos,"sash 85001 on Bip01 Spine2");
|
||||
check(actors.GetActorData(7101)->m_awPart[RD::PART_SASH]==1 && actors.GetActorData(7101)->m_awPart[RD::PART_HAIR]==1,"m_awPart tracks hair/sash");
|
||||
// The AVA2 pc/item gr2 are BitKnit2-compressed (Granny format 4): the meshes must decode and draw.
|
||||
check(inst->GetModel() && !inst->GetModel()->GetInfo().meshes.empty(),"BitKnit2 warrior_novice.gr2 loads");
|
||||
{
|
||||
auto draws=inst->BuildDrawCommands();
|
||||
size_t shapeMeshes=inst->GetModel()->GetInfo().meshes.size();
|
||||
bool textured=true,bodySkin=false,hairSkin=false,weapon=false,sash=false;
|
||||
for(auto& dc:draws){
|
||||
std::string t=dc.texture0;for(auto& c:t) c=char(std::tolower((unsigned char)c));
|
||||
if(t.empty()) textured=false;
|
||||
bodySkin|=t.find("warrior_novice_blue")!=std::string::npos; // .msm ShapeData SourceSkin->TargetSkin
|
||||
hairSkin|=t.find("warrior_hair_01_white")!=std::string::npos; // .msm HairData skin
|
||||
weapon|=t.find("weapon_chogeup_01")!=std::string::npos;
|
||||
sash|=t.find("acce_85_001")!=std::string::npos;
|
||||
}
|
||||
check(draws.size()>shapeMeshes && textured,"shape + hair/weapon/sash parts draw with textures");
|
||||
check(bodySkin && hairSkin && weapon && sash,"msm skins and part textures reach the draws");
|
||||
}
|
||||
// ChangeWeapon(0) detaches; ChangeArmor rebuilds the race and re-applies hair/sash/weapon.
|
||||
ava2::SNetworkUpdateActorData up;up.m_dwVID=7101;up.m_dwArmor=1;up.m_dwWeapon=0;up.m_dwHair=1;up.m_dwSash=1;
|
||||
actors.UpdateActor(up);
|
||||
check(inst->GetPartItemID(RD::PART_WEAPON)==0 && inst->GetPartModelPath(RD::PART_WEAPON).empty(),"ChangeWeapon(0) removes the weapon");
|
||||
up.m_dwArmor=0;up.m_dwWeapon=10;actors.UpdateActor(up);
|
||||
check(inst->GetShape()==0 && inst->GetPartModelPath(RD::PART_HAIR).find("hair_1_1")!=std::string::npos
|
||||
&& inst->GetPartItemID(RD::PART_WEAPON)==10 && inst->GetPartBone(RD::PART_SASH)=="Bip01 Spine2","ChangeArmor re-applies parts");
|
||||
// Missing sash item keeps the previous sash (GetItemDataPointer failure returns early).
|
||||
actors.ChangeSash(7101,999);
|
||||
check(inst->GetPartModelPath(RD::PART_SASH).find("85_001")!=std::string::npos,"unknown sash keeps the old model");
|
||||
// npc_wear: the NPC is drawn as race 0 with the listed parts (hair allowed, race <= 8).
|
||||
auto& npd=ava2::NonPlayerData::Instance();
|
||||
npd.loadNPCWear("20016\tall\t0\t10\t1\t1\t85001\t0\t0\t0\t0\t0\t0\t0\t0\n");
|
||||
ava2::SNetworkActorData wear;wear.m_dwVID=7102;wear.m_bType=1;wear.m_dwRace=20016;actors.AppendActor(wear);
|
||||
auto w=actors.GetActorInstance(7102);
|
||||
check(w->GetRace()==0 && w->GetShape()==1 && w->GetPartItemID(RD::PART_WEAPON)==10
|
||||
&& !w->GetPartModelPath(RD::PART_HAIR).empty() && w->GetPartBone(RD::PART_SASH)=="Bip01 Spine2","npc_wear mounts race/armor/weapon/hair/sash");
|
||||
npd.clearNPCWear();
|
||||
// Monster race from npclist: no hair / sash / weapon for non-PC races.
|
||||
ava2::SNetworkActorData dog;dog.m_dwVID=7103;dog.m_bType=0;dog.m_dwRace=101;dog.m_dwWeapon=10;actors.AppendActor(dog);
|
||||
auto d=actors.GetActorInstance(7103);
|
||||
check(d->GetRace()==101 && d->GetShapeModelFile().find("stray_dog")!=std::string::npos && d->GetPartItemID(RD::PART_WEAPON)==0,"npclist stray_dog race loads without parts");
|
||||
for(uint32_t vid:{7101u,7102u,7103u}) actors.RemoveActor(vid);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Remaining GamePhase() handlers (PythonNetworkStreamPhaseGameRecv.cpp): golden wire bytes -> callbacks.
|
||||
netStream.ResetConnection();netStream.SetPhase(ava2::PHASE_GAME);
|
||||
python.execute("class GameRec(object):\n def __init__(self):\n self.calls=[]\n def __getattr__(self,name):\n if name.startswith('__'):\n raise AttributeError(name)\n return lambda *a: self.calls.append((name,)+a)\ngame_rec=GameRec()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,game_rec)\n");
|
||||
struct W { std::vector<uint8_t> b;
|
||||
W& u8(uint32_t v){b.push_back(uint8_t(v));return *this;}
|
||||
W& u16(uint32_t v){u8(v);u8(v>>8);return *this;}
|
||||
W& u32(uint32_t v){u16(v);u16(v>>16);return *this;}
|
||||
W& i64(int64_t v){u32(uint32_t(v));u32(uint32_t(uint64_t(v)>>32));return *this;}
|
||||
W& str(const std::string& t,size_t n){for(size_t i=0;i<n;++i) u8(i<t.size()?uint8_t(t[i]):0);return *this;}
|
||||
W& zero(size_t n){b.insert(b.end(),n,0);return *this;}
|
||||
W& size16(){b[1]=uint8_t(b.size());b[2]=uint8_t(b.size()>>8);return *this;}
|
||||
W& size32(){for(int i=0;i<4;++i) b[1+i]=uint8_t(b.size()>>(8*i));return *this;} };
|
||||
auto feedG=[&](const std::vector<uint8_t>& bytes) { netStream.PushRecvData(bytes.data(),bytes.size());netStream.ProcessRecvData(); };
|
||||
auto expect=[&](const std::string& calls,const char* what) {
|
||||
python.execute("calls,game_rec.calls=game_rec.calls,[]\nassert calls=="+calls+",('"+what+"',calls)\n");
|
||||
};
|
||||
auto channel=W{}.u8(121).u8(3).u8(1).b;
|
||||
// 255 Handshake: TIME_SYNC reply (sequenced) and GamePhase() returns before the next packet.
|
||||
auto hs=W{}.u8(255).u32(0x11223344).u32(1000).u32(50).b;hs.insert(hs.end(),channel.begin(),channel.end());
|
||||
netStream.ClearSendQueue();feedG(hs);
|
||||
auto sent=netStream.PopSendPacketsWithSequence();
|
||||
check(sent.size()==1 && sent[0].first==W{}.u8(0xfc).u32(0x11223344).u32(1100).u32(0).b && sent[0].second,"Handshake -> TIME_SYNC dwTime+2*lDelta");
|
||||
expect("[]","Handshake stops the GamePhase frame");
|
||||
netStream.ProcessRecvData();
|
||||
expect("[('SetChannelIndex',3),('SetAntiExp',1)]","packet after Handshake runs next frame");
|
||||
feedG(W{}.u8(252).b);
|
||||
check(ava2::GetServerMSec()-1050<1000,"HandshakeOK sets server msec to time+delta+elapsed");
|
||||
// 205 XTrap: ACK 204 + 128 bytes without SendSequence.
|
||||
feedG(W{}.u8(205).zero(128).b);
|
||||
sent=netStream.PopSendPacketsWithSequence();
|
||||
check(sent.size()==1 && sent[0].first==W{}.u8(204).zero(128).b && !sent[0].second,"XTrap ACK is unsequenced");
|
||||
// 204 HS / 213 Unk213 fail -> RecvErrorPacket clears the buffer.
|
||||
auto hsReq=W{}.u8(204).zero(402).b;hsReq.insert(hsReq.end(),channel.begin(),channel.end());feedG(hsReq);
|
||||
auto unk=W{}.u8(213).u8(0).b;unk.insert(unk.end(),channel.begin(),channel.end());feedG(unk);
|
||||
expect("[]","HS and Unk213 fail and clear the buffer");
|
||||
// 152 HybridCrypt keys: stream dropped, frame stops.
|
||||
auto keys=W{}.u8(152).u16(0).u32(3).u8(1).u8(2).u8(3).size16().b;keys.insert(keys.end(),channel.begin(),channel.end());
|
||||
feedG(keys);expect("[]","HybridCrypt stops the frame");
|
||||
netStream.ProcessRecvData();expect("[('SetChannelIndex',3),('SetAntiExp',1)]","HybridCrypt key stream consumed");
|
||||
// 95/119 refine (ENABLE_MULTI_REFINE_WORLDARD).
|
||||
auto refine=[&](bool isNew,uint8_t sub) {
|
||||
W w;w.u8(isNew?119:95);if(isNew) w.u8(4);w.u8(7);
|
||||
w.u32(11).u32(12).u8(1).u32(500).u32(90).u8(1).u32(2).u8(sub).u32(30).u32(2).zero(32);return w.b; };
|
||||
feedG(refine(false,1));feedG(refine(true,1));feedG(refine(true,5));feedG(refine(false,0));
|
||||
expect("[('OpenRefineDialog',2,7,12,500,90,1),('AppendMaterialToRefineDialog',2,30,2),"
|
||||
"('BINARY_MULTI_REFINE_ADD_INFO',2,7,12,500,90,1,4),('BINARY_MULTI_REFINE_ADD_MATERIAL',2,30,2),"
|
||||
"('BINARY_MULTI_REFINE_DATES_CLEAR',),('BINARY_MULTI_REFINE_CLEAR_INFO',)]","refine information");
|
||||
// 112 ChangeSkillGroup + 72 SkillLevel: refresh block order Character, Skill, Status.
|
||||
std::vector<uint8_t> grp=W{}.u8(112).u8(2).b;std::vector<uint8_t> lv(256,0);lv[0]=72;grp.insert(grp.end(),lv.begin(),lv.end());
|
||||
feedG(grp);
|
||||
check(netStream.GetMainActorSkillGroup()==2,"skill group stored");
|
||||
expect("[('RefreshCharacter',),('RefreshSkill',),('RefreshStatus',)]","refresh order");
|
||||
// 41 PVP, 215 Sash, 218 KingdomsWar, 231 Sungma, 131/132 Love, 242 67Attr, 82 guild.
|
||||
feedG(W{}.u8(41).u32(5).u32(6).u8(ava2::PVP_MODE_FIGHT).b);
|
||||
check(ava2::NetworkActorManager::Instance().FindPVPKey(6,5),"PVP fight key");
|
||||
feedG(W{}.u8(215).u8(ava2::SASH_SUBHEADER_GC_ADDED).u8(1).u32(0).u8(1).u8(0).u16(0).u32(0).u32(0).u32(0).b);
|
||||
feedG(W{}.u8(218).u8(1).u32(1).u32(2).u32(3).u32(10).u32(4).u32(5).u32(60).b);
|
||||
feedG(W{}.u8(231).u8(1).u8(2).u8(3).u8(4).b);
|
||||
feedG(W{}.u8(131).str("Bob",25).u8(80).b);feedG(W{}.u8(132).u8(90).b);
|
||||
feedG(W{}.u8(242).b);feedG(W{}.u8(82).b);
|
||||
expect("[('RefreshTargetBoardByVID',5),('RefreshTargetBoardByVID',6),('AlertSash',1),('ActSash',3,1),"
|
||||
"('ActKingdomsWar',3,1,2,3,10,4,5,60),('BINARY_SungMaAttr',1,2,3,4),('BINARY_LoverInfo','Bob',80),"
|
||||
"('BINARY_UpdateLovePoint',90),('OpenAttr67AddDlg',),('AskGuildName',)]","small callbacks");
|
||||
// 235 ExchangeLog (LOAD + LOAD_ITEM), 241 CatchKing, 214/216 Calendar, 209 DS refine.
|
||||
W log;log.u8(235).u32(0).u8(0).str("CODE",19).u8(1).u16(1).u32(9)
|
||||
.str("Al",25).u32(1).i64(5000000000LL).str("1.2.3.4",16).str("Bo",25).u32(2).i64(7).str("5.6.7.8",16).str("2026-10-06",25).u8(0);
|
||||
feedG(log.size32().b);
|
||||
W item;item.u8(235).u32(0).u8(1).u16(1).u32(9).u8(2).u32(19).u16(1).u32(4);item.zero(28).u8(1).u16(15).zero(42).u8(1);
|
||||
feedG(item.size32().b);
|
||||
feedG(W{}.u8(241).u16(5).u8(ava2::SUBHEADER_GC_CATCH_KING_START).u32(123).b);
|
||||
feedG(W{}.u8(241).u16(4).u8(ava2::SUBHEADER_GC_CATCH_KING_REWARD).b);
|
||||
feedG(W{}.u8(214).u8(ava2::CALENDAR_RECEIVE_OPEN).u8(0).zero(400).u32(0).u32(777).b);
|
||||
feedG(W{}.u8(216).u8(ava2::CALENDAR_RECEIVE_LOAD_EVENTS_ADM).u32(3).str("ev",100).str("desc",100).b);
|
||||
feedG(W{}.u8(209).u8(ava2::DS_SUB_HEADER_REFINE_SUCCEED).u8(1).u16(12).b);
|
||||
expect("[('ExchangeLogClear','CODE'),('ExchangeLogAppend',9,'Al',5000000000,'1.2.3.4','Bo',7,'5.6.7.8','2026-10-06'),('ExchangeLogRefresh',0),"
|
||||
"('ExchangeLogItemAppend',9,2,19,1,[4,0,0,0,0,0,0,0],[1]+[0]*14,[15]+[0]*14,1),('ExchangeLogRefresh',9),"
|
||||
"('MiniGameCatchKingEventStart',123),('BINARY_CALENDAR_OPEN',777),('BINARY_CALENDAR_LOAD_EVENTS_ADM',3,'ev','desc'),"
|
||||
"('BINARY_DragonSoulRefineWindow_RefineSucceed',1,12)]","exchange log / catch king / calendar / DS");
|
||||
// 130 Land, 115 NPC list, 110 Dungeon destination, 249 blacklist: consumed exactly.
|
||||
feedG(W{}.u8(130).u16(0).zero(48).size16().b);
|
||||
feedG(W{}.u8(115).u16(0).u16(1).zero(17).size16().b);
|
||||
feedG(W{}.u8(110).u16(12).u8(ava2::DUNGEON_SUBHEADER_GC_DESTINATION_POSITION).u32(100).u32(200).b);
|
||||
feedG(W{}.u8(249).zero(1024).b);
|
||||
feedG(channel);
|
||||
check(netStream.GetDungeonDestination()==std::make_pair(100,200),"dungeon destination stored");
|
||||
expect("[('SetChannelIndex',3),('SetAntiExp',1)]","land/npc/dungeon/blacklist consumed exactly");
|
||||
check(netStream.GetUnportedPackets().empty(),"no newly ported header is skipped");
|
||||
python.execute("net.SetPhaseWindow(net.PHASE_WINDOW_GAME,0)\n");
|
||||
std::cout << "PhaseGame remaining handlers verified successfully!\n";
|
||||
}
|
||||
|
||||
netStream.ResetConnection();
|
||||
python.execute("class SkillCallbacks:\n def __init__(self):\n self.skills=0\n self.status=0\n def RefreshSkill(self):\n self.skills+=1\n def RefreshStatus(self):\n self.status+=1\nskill_callbacks=SkillCallbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,skill_callbacks)\nplayer.SetSkill(1,1)\nplayer.SetSkill(2,2)\nplayer.SetSkill(3,3)\nplayer.SetSkill(4,4)\nassert player.GetSkillLevel(1)==0\nassert player.GetSkillSlotIndex(3)==3\n");
|
||||
|
||||
Reference in New Issue
Block a user