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
@@ -16,8 +16,14 @@
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include "test_rundir.h"
|
||||
|
||||
using ava2_test::kSkip;
|
||||
using ava2_test::PackMaker;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (!ava2_test::EnterTestRunDir()) return kSkip;
|
||||
|
||||
std::string model_path = "ymir work/pc/warrior/warrior_assasin1.gr2";
|
||||
if (argc > 1) {
|
||||
model_path = argv[1];
|
||||
@@ -29,8 +35,20 @@ int main(int argc, char** argv) {
|
||||
} else if (std::filesystem::exists("../" + model_path)) {
|
||||
model_path = "../" + model_path;
|
||||
} else {
|
||||
std::cerr << "Model file not found: " << model_path << std::endl;
|
||||
return 1;
|
||||
std::cerr << "SKIP: model file not found: " << model_path << std::endl;
|
||||
return kSkip;
|
||||
}
|
||||
}
|
||||
|
||||
// The scene below loads cwd-relative client assets (merged `ymir work`, bgm, sound),
|
||||
// like the Windows client root. Without them the asserts would only report the
|
||||
// environment, so skip instead; when they are present every check runs.
|
||||
for (const char* required : {"ymir work/zone/b/obj/b_general_obj_01_2.gr2",
|
||||
"bgm/login_window.mp3",
|
||||
"sound/ui/click.wav"}) {
|
||||
if (!std::filesystem::exists(required)) {
|
||||
std::cerr << "SKIP: client asset missing from working directory: " << required << std::endl;
|
||||
return kSkip;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,13 +277,13 @@ int main(int argc, char** argv) {
|
||||
// ── Test Terrain Heightmap & Outdoor Scene Rendering ────────────────────
|
||||
std::cout << "\n── Testing Terrain Heightmap & Outdoor Scene Rendering ──" << std::endl;
|
||||
ava2::TerrainHeightmap terrain;
|
||||
std::string raw_path = "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Maps/metin2_map_a1/001003/height.raw";
|
||||
std::string raw_path = PackMaker() + "/Maps/metin2_map_a1/001003/height.raw";
|
||||
if (std::filesystem::exists(raw_path)) {
|
||||
bool raw_ok = terrain.LoadRaw(raw_path, 0.5f, 50.0f);
|
||||
std::cout << "Loaded Metin2 height.raw: " << (raw_ok ? "SUCCESS" : "FAILED") << std::endl;
|
||||
assert(raw_ok && "Metin2 height.raw must load successfully");
|
||||
|
||||
std::string tile_path = "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Maps/metin2_map_a1/001003/tile.raw";
|
||||
std::string tile_path = PackMaker() + "/Maps/metin2_map_a1/001003/tile.raw";
|
||||
if (std::filesystem::exists(tile_path)) {
|
||||
bool tile_ok = terrain.LoadTileRaw(tile_path);
|
||||
std::cout << "Loaded Metin2 tile.raw: " << (tile_ok ? "SUCCESS" : "FAILED") << std::endl;
|
||||
@@ -306,11 +324,11 @@ int main(int argc, char** argv) {
|
||||
assert(added_bldg && "Building model must instantiate successfully");
|
||||
|
||||
// Test AreaData & Property scanning
|
||||
std::string prop_dir = "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/property/property";
|
||||
std::string prop_dir = PackMaker() + "/property/property";
|
||||
if (std::filesystem::exists(prop_dir)) {
|
||||
obj_mgr.RegisterProperty(234517142, bldg_path);
|
||||
assert(obj_mgr.GetPropertyCount() >= 1);
|
||||
std::string areadata_path = "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Maps/metin2_map_a1/001003/areadata.txt";
|
||||
std::string areadata_path = PackMaker() + "/Maps/metin2_map_a1/001003/areadata.txt";
|
||||
if (std::filesystem::exists(areadata_path)) {
|
||||
obj_mgr.LoadAreaData(areadata_path, 0.05f);
|
||||
std::cout << "Loaded objects from areadata.txt: " << obj_mgr.GetObjectCount() << std::endl;
|
||||
@@ -369,7 +387,7 @@ int main(int argc, char** argv) {
|
||||
// ── Test WaterManager & Fog Rendering ──────────────────────────────────
|
||||
std::cout << "\n── Testing WaterManager & Depth Fog System ──" << std::endl;
|
||||
ava2::WaterManager water_mgr;
|
||||
std::string water_file = "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Maps/metin2_map_a1/001003/water.wtr";
|
||||
std::string water_file = PackMaker() + "/Maps/metin2_map_a1/001003/water.wtr";
|
||||
if (std::filesystem::exists(water_file)) {
|
||||
bool water_loaded = water_mgr.LoadWater(water_file, 40.0f, 0.5f, 40.0f, -2560.0f, -2560.0f);
|
||||
assert(water_loaded && "Failed to load water.wtr");
|
||||
@@ -521,7 +539,7 @@ int main(int argc, char** argv) {
|
||||
// ── Test MinimapManager (Radar Minimap System) ──────────────────────────
|
||||
std::cout << "\n── Testing MinimapManager (Radar Minimap System) ──" << std::endl;
|
||||
ava2::MinimapManager minimap;
|
||||
std::string minimap_test_path = "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Maps/metin2_map_a1/001003/minimap.dds";
|
||||
std::string minimap_test_path = PackMaker() + "/Maps/metin2_map_a1/001003/minimap.dds";
|
||||
if (std::filesystem::exists(minimap_test_path)) {
|
||||
bool m_ok = minimap.LoadMinimap(minimap_test_path);
|
||||
std::cout << "Loaded Metin2 minimap.dds: " << (m_ok ? "SUCCESS" : "FAILED")
|
||||
@@ -830,19 +848,19 @@ int main(int argc, char** argv) {
|
||||
|
||||
std::string test_raw = "map/metin2_map_a1/001003/height.raw";
|
||||
if (!std::filesystem::exists(test_raw)) {
|
||||
test_raw = "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Maps/metin2_map_a1/001003/height.raw";
|
||||
test_raw = PackMaker() + "/Maps/metin2_map_a1/001003/height.raw";
|
||||
}
|
||||
std::string test_tile = "map/metin2_map_a1/001003/tile.raw";
|
||||
if (!std::filesystem::exists(test_tile)) {
|
||||
test_tile = "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Maps/metin2_map_a1/001003/tile.raw";
|
||||
test_tile = PackMaker() + "/Maps/metin2_map_a1/001003/tile.raw";
|
||||
}
|
||||
std::string test_attr = "map/metin2_map_a1/001003/attr.atr";
|
||||
if (!std::filesystem::exists(test_attr)) {
|
||||
test_attr = "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Maps/metin2_map_a1/001003/attr.atr";
|
||||
test_attr = PackMaker() + "/Maps/metin2_map_a1/001003/attr.atr";
|
||||
}
|
||||
std::string test_tset = "textureset/metin2_map1.txt";
|
||||
if (!std::filesystem::exists(test_tset)) {
|
||||
test_tset = "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Maps/textureset/metin2_map1.txt";
|
||||
test_tset = PackMaker() + "/textureset/textureset/metin2_map1.txt";
|
||||
}
|
||||
|
||||
if (std::filesystem::exists(test_raw)) {
|
||||
@@ -1003,7 +1021,7 @@ int main(int argc, char** argv) {
|
||||
std::vector<ava2::CharacterSoundEvent> mss_events;
|
||||
bool mss_loaded = snd.LoadCharacterSoundScript("sound/pc/warrior/skill/samyeon.mss", mss_events);
|
||||
if (!mss_loaded) {
|
||||
mss_loaded = snd.LoadCharacterSoundScript("/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Sound/sound/pc/warrior/skill/samyeon.mss", mss_events);
|
||||
mss_loaded = snd.LoadCharacterSoundScript(PackMaker() + "/Sound/sound/pc/warrior/skill/samyeon.mss", mss_events);
|
||||
}
|
||||
assert(mss_loaded && "Samyeon .mss script must be loaded");
|
||||
assert(mss_events.size() == 2 && "Samyeon .mss must have exactly 2 sound events");
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#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::PythonRuntime runtime(argv[1], argv[2]);
|
||||
auto* wm = runtime.window_manager();
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "battlepass_state.h"
|
||||
#include "python_runtime.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
using Bytes=std::vector<uint8_t>;
|
||||
void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);}
|
||||
void u32(Bytes& b,uint32_t value) {for(unsigned i=0;i<4;++i)b.push_back(uint8_t(value>>(8*i)));}
|
||||
Bytes record(uint8_t sub) {
|
||||
Bytes b{230,sub};u32(b,uint32_t(-100));u32(b,0x80000001);u32(b,0xffffffff);u32(b,uint32_t(-10));u32(b,50);u32(b,0xffffffff);
|
||||
for(unsigned i=0;i<4;++i) {u32(b,100+i);u32(b,i==3?0x80000001:i+1);}
|
||||
return b;
|
||||
}
|
||||
Bytes control(uint8_t sub) {Bytes b(58);b[0]=230;b[1]=sub;return b;}
|
||||
void send(const Bytes& b) {auto& stream=PythonNetworkStream::Instance();stream.PushRecvData(b);stream.ProcessRecvData();}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
{
|
||||
PythonRuntime python(argv[1],argv[2]);auto& stream=PythonNetworkStream::Instance();stream.ResetConnection();stream.SetPhase(PHASE_GAME);
|
||||
python.execute(R"PY(import battlepass as bp,net,weakref,gc
|
||||
assert bp.CountDates()==0 and bp.GetTime()==0
|
||||
assert bp.GetDates(-1)==(0,0) and bp.GetDatesCount(0)==(0,0,0)
|
||||
assert bp.GetDatesItems(0,0)==0
|
||||
assert bp.GetDates() is None and bp.GetDatesItems(0) is None
|
||||
assert bp.Reward('x') is None and bp.SetBattlePassHandler() is None
|
||||
class Game:
|
||||
def __init__(self): self.events=[]
|
||||
def BINARY_BATTLEPASS_OPEN(self): self.events.append('open')
|
||||
def BINARY_BATTLEPASS_MP(self): self.events.append('mp')
|
||||
class Loader:
|
||||
def __init__(self): self.events=[]
|
||||
def BINARY_BATTLEPASS_LOADING(self,sub):
|
||||
self.events.append((sub,bp.CountDates(),bp.GetDatesCount(0),bp.GetTime()))
|
||||
game=Game()
|
||||
loader=Loader()
|
||||
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)
|
||||
bp.SetBattlePassHandler(loader)
|
||||
)PY");
|
||||
auto data=record(2);require(data.size()==58,"battlepass literal wire size");data.push_back(44);
|
||||
stream.PushRecvData(data.data(),57);stream.ProcessRecvData();python.execute("assert bp.CountDates()==0\n");
|
||||
stream.PushRecvData(data.data()+57,2);stream.ProcessRecvData();require(stream.PopSendBytes()==Bytes{254},"battlepass consumed following ping");
|
||||
send(record(2));send(record(7));send(record(7));send(record(3));send(control(4));send(control(8));send(control(0));send(control(9));
|
||||
python.execute(R"PY(assert bp.CountDates()==2
|
||||
assert bp.GetDates(0)==(-2147483647,-1) and bp.GetDates(1)==bp.GetDates(0)
|
||||
assert bp.GetDates(2)==(0,0)
|
||||
assert bp.GetDatesCount(0)==(-10,50,-1) and bp.GetDatesCount(1)==bp.GetDatesCount(0)
|
||||
assert bp.GetDatesCount(2)==(0,0,0)
|
||||
assert bp.GetDatesItems(0,0)==(100,1) and bp.GetDatesItems(0,3)==(103,-2147483647)
|
||||
assert bp.GetDatesItems(0,4)==(0,0) and bp.GetDatesItems(0,-1)==(0,0)
|
||||
assert bp.GetDatesItems(-1,4)==0
|
||||
assert bp.GetTime()==-100
|
||||
assert loader.events==[(4,2,(-10,50,-1),-100),(8,2,(-10,50,-1),-100)]
|
||||
assert game.events==['open','mp']
|
||||
)PY");
|
||||
send(control(6));python.execute("assert bp.CountDates()==2 and bp.GetTime()==-100\nassert bp.GetDatesCount(0)==(0,0,0)\n");
|
||||
send(record(7));send(control(1));send(control(255));send(control(5));send(control(8));
|
||||
python.execute("assert bp.CountDates()==0 and bp.GetTime()==0\nassert bp.GetDatesCount(0)==(-10,50,-1)\nassert loader.events[-1]==(8,0,(-10,50,-1),0)\nbp.Open()\nbp.Reward(1)\n");require(stream.PopSendBytes().empty(),"battlepass sent without actionable main actor");
|
||||
SNetworkActorData actor{};actor.m_dwVID=1001;actor.m_stName="BattlePassFixture";NetworkActorManager::Instance().AppendActor(actor);stream.SetMainActorVID(1001);
|
||||
auto instance=NetworkActorManager::Instance().GetActorInstance(1001);require(bool(instance),"missing native actor");
|
||||
python.execute("bp.Open()\nbp.Reward(-1)\nbp.Reward(2147483649)\n");
|
||||
auto packets=stream.PopSendPacketsWithSequence();require(packets.size()==3,"battlepass request count");
|
||||
require(packets[0].first==Bytes{230,0,0,0,0,0} && packets[1].first==Bytes{230,5,255,255,255,255} && packets[2].first==Bytes{230,5,1,0,0,128},"battlepass request Win32 byte conversion");
|
||||
require(packets[0].second && packets[1].second && packets[2].second,"battlepass missing SendSequence");
|
||||
instance->SetSleep(true);python.execute("bp.Open()\nbp.Reward(0)\n");require(stream.PopSendBytes().empty(),"sleeping actor sent battlepass request");instance->SetSleep(false);
|
||||
python.execute("temporary=Loader()\nref=weakref.ref(temporary)\nbp.SetBattlePassHandler(temporary)\ndel temporary\ngc.collect()\nassert ref() is not None\n");
|
||||
send(control(1));send(control(6));python.execute("assert ref() is not None\nbp.SetBattlePassHandler(None)\ngc.collect()\nassert ref() is None\nclass Broken:\n def BINARY_BATTLEPASS_LOADING(self,*args): raise ValueError('expected failure')\nbp.SetBattlePassHandler(Broken())\n");
|
||||
send(record(2));send(control(4));python.execute("assert bp.CountDates()==1\n");
|
||||
require(stream.GetUnportedPackets().empty(),"battlepass still routed through skip handler");stream.ResetConnection();
|
||||
}
|
||||
{PythonRuntime python(argv[1],argv[2]);python.execute("import battlepass as bp\nassert bp.CountDates()==0 and bp.GetTime()==0 and bp.GetDatesCount(0)==(0,0,0)\n");}
|
||||
std::cout<<"AVA2 battlepass state, wire and Python parity passed\n";
|
||||
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
// CPythonChat / CWhisper and the "chat" module against AVA2 PythonChat.cpp / PythonChatModule.cpp.
|
||||
#include "python_runtime.h"
|
||||
#include "python_chat.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
using namespace ava2;
|
||||
using Bytes=std::vector<uint8_t>;
|
||||
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
||||
void u32(Bytes& b,uint32_t v) { for(unsigned i=0;i<4;++i)b.push_back(uint8_t(v>>(8*i))); }
|
||||
// One-row MIPX item_proto (literal LZO run), as tests/item_data_test.cpp builds it.
|
||||
void proto(const std::filesystem::path& p,uint32_t id,const std::string& name) {
|
||||
Bytes raw;u32(raw,id);raw.resize(172);std::copy(name.begin(),name.end(),raw.begin()+4);std::copy(name.begin(),name.end(),raw.begin()+29);raw[54]=1;raw[57]=1;
|
||||
Bytes compressed{uint8_t(17+raw.size())};compressed.insert(compressed.end(),raw.begin(),raw.end());compressed.insert(compressed.end(),{17,0,0});
|
||||
Bytes file{'M','I','P','X'};u32(file,1);u32(file,172);u32(file,1);u32(file,20+compressed.size());
|
||||
file.insert(file.end(),{'M','C','O','Z'});u32(file,0);u32(file,compressed.size());u32(file,raw.size());file.insert(file.end(),{'M','C','O','Z'});
|
||||
file.insert(file.end(),compressed.begin(),compressed.end());
|
||||
std::filesystem::create_directories(p.parent_path());std::ofstream out(p,std::ios::binary);out.write(reinterpret_cast<const char*>(file.data()),file.size());
|
||||
}
|
||||
std::vector<std::string> showing(DWORD id) {
|
||||
std::vector<std::string> out;
|
||||
for(const auto* line:CPythonChat::Instance().GetChatSet(id)->m_ShowingChatLineList) out.push_back(line->text);
|
||||
return out;
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
auto root=std::filesystem::temp_directory_path()/("ava2-chat-"+std::to_string(getpid()));
|
||||
std::filesystem::create_directories(root);
|
||||
int rc=0;
|
||||
try {
|
||||
PythonRuntime python(argv[1],root);
|
||||
proto(root/"proto",0x13,"Sword");
|
||||
require(LoadItemTable("proto"),"item proto fixture rejected");
|
||||
auto& chat=CPythonChat::Instance();
|
||||
chat.SetCurrentMillisecond(1000);
|
||||
python.execute(
|
||||
"import chat\n"
|
||||
"assert (chat.CHAT_TYPE_TALKING,chat.CHAT_TYPE_SHOUT,chat.CHAT_TYPE_DICE_INFO,chat.CHAT_TYPE_MISSION)==(0,6,10,14)\n"
|
||||
"assert (chat.WHISPER_TYPE_CHAT,chat.WHISPER_TYPE_GM,chat.WHISPER_TYPE_SYSTEM)==(0,5,255)\n"
|
||||
"assert (chat.BOARD_STATE_VIEW,chat.BOARD_STATE_EDIT,chat.BOARD_STATE_LOG)==(0,1,2)\n"
|
||||
"assert (chat.CHAT_SET_CHAT_WINDOW,chat.CHAT_SET_LOG_WINDOW)==(0,1)\n"
|
||||
"assert chat.GetLineCount(0)==0 and chat.GetLineCount(1)==0 and chat.GetLineCount(7)==0\n"
|
||||
"assert chat.GetLineStep(0)==15 and chat.GetLineStep(7)==0\n");
|
||||
|
||||
// __Initialize colours; SetChatColor packs 0xff RRGGBB.
|
||||
require(chat.GetChatColorValue(0)==0xffffffffu,"talking colour");
|
||||
require(chat.GetChatColorValue(CPythonChat::CHAT_TYPE_WHISPER)==0xff4AE14Au,"whisper colour");
|
||||
require(chat.GetChatColorValue(CPythonChat::CHAT_TYPE_DICE_INFO)==0xffcc00ccu,"dice colour");
|
||||
require(chat.GetChatColorValue(CPythonChat::CHAT_TYPE_INFO)==DWORD(D3DXCOLOR(1.0f,0.785f,0.785f,1.0f)),"info colour");
|
||||
require(chat.GetChatColorValue(99)==DWORD(D3DXCOLOR(0.0f,0.0f,1.0f,1.0f)),"out-of-range colour");
|
||||
python.execute("chat.SetChatColor(chat.CHAT_TYPE_PARTY,1,2,3)\nchat.SetChatColor(15,1,2,3)\n");
|
||||
require(chat.GetChatColorValue(CPythonChat::CHAT_TYPE_PARTY)==0xff010203u,"SetChatColor");
|
||||
|
||||
// Every line store receives the line; "#ebvs" lines are dropped.
|
||||
python.execute(
|
||||
"chat.AppendChat(chat.CHAT_TYPE_TALKING,'a : hello')\n"
|
||||
"chat.AppendChat(chat.CHAT_TYPE_INFO,'x #ebvs y')\n"
|
||||
"assert chat.GetLineCount(0)==1 and chat.GetLineCount(1)==1\n"
|
||||
"assert chat.GetVisibleLineCount(0)==1\n");
|
||||
require(chat.GetChatLineDeque(0)->front()->text=="a : hello","line text");
|
||||
require(chat.GetChatLineDeque(0)->front()->fAppendedTime==1.0f,"appended time is CTimer seconds");
|
||||
|
||||
// Item hyperlinks take this client's item name.
|
||||
python.execute("chat.AppendChat(chat.CHAT_TYPE_INFO,'|cfff1e6c0|Hitem:13:0:0:0:0|h[Old]|h|r and |Hitem:zz:0|h[q]|h')\n");
|
||||
require(chat.GetChatLineDeque(0)->back()->text=="|cfff1e6c0|Hitem:13:0:0:0:0|h[Sword]|h|r and |Hitem:zz:0|h[q]|h","item link rename");
|
||||
|
||||
// SHOUT: "|lang|N|" / "|empire|N|" prefixes are stripped; a bad language becomes 1.
|
||||
python.execute(
|
||||
"chat.AppendChat(chat.CHAT_TYPE_SHOUT,'|lang|3||empire|2|Bob : hi')\n"
|
||||
"chat.AppendChat(chat.CHAT_TYPE_SHOUT,'|lang|99|Al : yo')\n"
|
||||
"chat.AppendChat(chat.CHAT_TYPE_SHOUT,'|lang|5')\n");
|
||||
{
|
||||
const auto& lines=*chat.GetChatLineDeque(0);
|
||||
const auto* bob=lines[lines.size()-3];const auto* al=lines[lines.size()-2];const auto* bare=lines.back();
|
||||
require(bob->text=="Bob : hi" && bob->countryIndex==3 && bob->empireIndex==2,"shout prefixes");
|
||||
require(al->text=="Al : yo" && al->countryIndex==1 && al->empireIndex==0,"shout language clamp");
|
||||
require(bare->text=="5" && bare->countryIndex==5,"shout without closing bar");
|
||||
}
|
||||
python.execute(
|
||||
"assert chat.GetLineCount(0)==5,(chat.GetLineCount(0),chat.GetLineCount(1))\n"
|
||||
"chat.DisableCountryMode(0,3)\nassert chat.GetLineCount(0)==4 and chat.GetLineCount(1)==5,(chat.GetLineCount(0),chat.GetLineCount(1))\n"
|
||||
"chat.EnableCountryMode(0,3)\nchat.DisableCountryMode(0,99)\nassert chat.GetLineCount(0)==5\n"
|
||||
"chat.DisableChatMode(0,chat.CHAT_TYPE_SHOUT)\nassert chat.GetLineCount(0)==2\n"
|
||||
"chat.ToggleChatMode(0,chat.CHAT_TYPE_SHOUT)\nassert chat.GetLineCount(0)==5\n"
|
||||
"chat.ToggleChatMode(0,-1)\nchat.EnableChatMode(0,1000)\n");
|
||||
|
||||
// ArrangeShowingChat: (height+step)/step lines ending at SetEndPos.
|
||||
python.execute("chat.Clear()\nfor i in range(5):\n chat.AppendChat(chat.CHAT_TYPE_TALKING,'l%d'%i)\nchat.SetHeight(0,30)\nchat.ArrangeShowingChat(0)\n");
|
||||
require(showing(0)==std::vector<std::string>{"l2","l3","l4"},"end-position 1 window");
|
||||
require(showing(1)==std::vector<std::string>{"l4"},"zero-height window shows one line");
|
||||
python.execute("chat.SetEndPos(0,0.0)\nassert chat.GetVisibleLineCount(0)==3\n");
|
||||
require(showing(0)==std::vector<std::string>{"l1","l2","l3"},"end-position 0 window");
|
||||
python.execute("chat.SetEndPos(0,5.0)\nchat.SetStep(0,10)\nassert chat.GetLineStep(0)==10\nchat.ArrangeShowingChat(0)\nassert chat.GetVisibleLineCount(0)==3\n");
|
||||
require(showing(0)==std::vector<std::string>{"l2","l3","l4"},"step 10: iHeight starts at 12, so 12/22/32 fit under 40");
|
||||
python.execute("chat.SetStep(0,0)\nchat.ArrangeShowingChat(0)\nassert chat.GetVisibleLineCount(0)==0\nchat.SetStep(0,15)\nchat.ArrangeShowingChat(0)\n");
|
||||
|
||||
// VIEW mode fades lines older than 5 s by a tenth per update; a new append re-arranges.
|
||||
chat.SetCurrentMillisecond(7000);
|
||||
python.execute("chat.SetPosition(0,10,500)\nchat.Update(0)\nchat.Render(0)\n");
|
||||
require(std::abs(chat.GetChatLineDeque(0)->back()->GetColorRef(0).a-0.9f)<1e-4f,"view mode fade");
|
||||
require(chat.GetChatLineDeque(0)->back()->GetColorRef(1).a==1.0f,"fade is per chat set");
|
||||
python.execute("chat.SetBoardState(0,chat.BOARD_STATE_EDIT)\nchat.Update(0)\nchat.SetBoardState(0,chat.BOARD_STATE_LOG)\nchat.Update(0)\nchat.Close()\n");
|
||||
require(chat.GetChatSet(0)->m_ShowingChatLineList.front()->fAppendedTime==0.0f,"Close zeroes appended time");
|
||||
|
||||
// 300-line cap per store.
|
||||
python.execute("for i in range(305):\n chat.AppendChat(chat.CHAT_TYPE_TALKING,'n%d'%i)\nassert chat.GetLineCount(0)==300\n");
|
||||
require(chat.GetChatLineDeque(0)->front()->text=="n5","oldest lines dropped");
|
||||
|
||||
// AppendChatWithDelay waits for CTimer ms past the delay; Update on an existing set flushes
|
||||
// into every set (an unknown id returns before the flush).
|
||||
python.execute("chat.Clear()\nchat.AppendChatWithDelay(chat.CHAT_TYPE_NOTICE,'later',500)\nchat.Update(0)\nassert chat.GetLineCount(0)==0\n");
|
||||
require(chat.GetWaitChatCount()==1,"delayed chat queued");
|
||||
chat.SetCurrentMillisecond(7500);python.execute("chat.Update(0)\nassert chat.GetLineCount(0)==0\n");
|
||||
chat.SetCurrentMillisecond(7501);python.execute("chat.Update(5)\nassert chat.GetLineCount(0)==0\nchat.Update(1)\nassert chat.GetLineCount(0)==1 and chat.GetLineCount(1)==1\n");
|
||||
require(chat.GetWaitChatCount()==0,"delayed chat flushed");
|
||||
|
||||
// CreateChatSet copies set 0; ids are stored by BYTE, colours index by set id.
|
||||
python.execute(
|
||||
"assert chat.CreateChatSet(2)==2 and chat.GetLineCount(2)==1\n"
|
||||
"assert chat.CreateChatSet(256)==256 and chat.GetLineCount(256)==0\n"
|
||||
"chat.AppendChat(chat.CHAT_TYPE_TALKING,'more')\nassert chat.GetLineCount(2)==2\n"
|
||||
"chat.DeleteChatSet(2)\nassert chat.GetLineCount(2)==0 and chat.GetLineStep(2)==0\n");
|
||||
|
||||
// Ignore toggles; chat.IsIgnoreCharacter returns None as on Windows.
|
||||
python.execute("chat.IgnoreCharacter('troll')\nassert chat.IsIgnoreCharacter('troll') is None\n");
|
||||
require(chat.IsIgnoreCharacter("troll"),"ignore set");
|
||||
python.execute("chat.IgnoreCharacter('troll')\n");
|
||||
require(!chat.IsIgnoreCharacter("troll"),"ignore toggled off");
|
||||
|
||||
// Whispers.
|
||||
python.execute(
|
||||
"chat.AppendWhisper(chat.WHISPER_TYPE_CHAT,'bob','hi')\n"
|
||||
"chat.AppendWhisper(chat.WHISPER_TYPE_GM,'bob','gm')\n"
|
||||
"chat.CreateWhisper('al')\nchat.CreateWhisper('al')\n");
|
||||
require(chat.GetNewChatCount()==2 && chat.GetWhisperMap().size()==2,"whisper line count");
|
||||
require(chat.GetWhisperMap().at("bob")->GetLines().size()==2,"whisper lines");
|
||||
python.execute("chat.SetWhisperBoxSize('bob',200.0,90.0)\nchat.SetWhisperPosition('bob',0.5)\nchat.RenderWhisper('bob',1.0,2.0)\nchat.SetWhisperBoxSize('nobody',1.0,1.0)\n");
|
||||
{
|
||||
const auto* bob=chat.GetWhisperMap().at("bob");
|
||||
require(bob->GetWidth()==200.0f && bob->GetHeight()==90.0f && bob->GetCurPosition()==0.5f,"whisper box");
|
||||
require(chat.GetNewChatCount()==0,"GetWhisper marks lines read");
|
||||
}
|
||||
python.execute(
|
||||
"class Iface:\n def __init__(self):\n self.names=[]\n def MakeWhisperButton(self,n):\n self.names.append(n)\n"
|
||||
"f=Iface()\nchat.InitWhisper(f)\nassert f.names==['al','bob'],f.names\n"
|
||||
"chat.ClearWhisper('bob')\nchat.ClearWhisper('bob')\n");
|
||||
require(chat.GetWhisperMap().size()==1,"ClearWhisper");
|
||||
|
||||
// GetLinkFromHyperlink.
|
||||
python.execute(
|
||||
"assert chat.GetLinkFromHyperlink('item:13:1:0:0:0')=='|cfff1e6c0|Hitem:13:1:0:0:0|h[Sword]|h|r'\n"
|
||||
"assert chat.GetLinkFromHyperlink('item:13:0:0:0:0:1:50:2:30')=='|cffffc700|Hitem:13:0:0:0:0:1:50:2:30|h[Sword]|h|r'\n"
|
||||
"assert chat.GetLinkFromHyperlink('item:13:0:0:0:0:1:50:2')=='|cffffc700|Hitem:13:0:0:0:0:1:50:2:0|h[Sword]|h|r'\n"
|
||||
"assert chat.GetLinkFromHyperlink('item:13:0:0:0:0:1')=='|cfff1e6c0|Hitem:13:0:0:0:0|h[Sword]|h|r'\n"
|
||||
"assert chat.GetLinkFromHyperlink('item:13:0:zz:0:0')=='|cfff1e6c0|Hitem:13:0:ffffffff:0:0|h[Sword]|h|r'\n"
|
||||
"assert chat.GetLinkFromHyperlink('item:14:0:0:0:0')==''\n"
|
||||
"assert chat.GetLinkFromHyperlink('item:13')==''\n"
|
||||
"assert chat.GetLinkFromHyperlink('nolink')==''\n"
|
||||
"assert chat.GetLinkFromHyperlink('pm:bob')==''\n");
|
||||
|
||||
// Bad arguments return None (Py_BuildException without a message).
|
||||
python.execute(
|
||||
"assert chat.AppendChat('x') is None and chat.GetLineCount() is None\n"
|
||||
"assert chat.CreateChatSet('a') is None and chat.SetEndPos(0,'z') is None\n");
|
||||
|
||||
python.execute("chat.Clear()\nassert chat.GetLineCount(0)==0 and chat.GetLineStep(1)==15\n");
|
||||
require(chat.GetWhisperMap().empty(),"Clear destroys whispers");
|
||||
chat.SetCurrentMillisecond(0);
|
||||
std::cout<<"AVA2 chat parity passed\n";
|
||||
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';rc=1; }
|
||||
std::error_code ec;std::filesystem::remove_all(root,ec);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Reject original Python scripts that exit(0) before completing a test.
|
||||
Both a successful process exit and the test's final marker are required.
|
||||
"""
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
marker, *command = sys.argv[1:]
|
||||
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
sys.stdout.buffer.write(result.stdout)
|
||||
if result.returncode:
|
||||
sys.exit(result.returncode if result.returncode > 0 else 1)
|
||||
if marker.encode() not in result.stdout:
|
||||
print("Test stopped before its completion marker", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,144 @@
|
||||
// chr / chrmgr against the original AVA2 PythonCharacterModule.cpp + PythonCharacterManagerModule.cpp:
|
||||
// the module surfaces, the no-instance getter answers, Py_BuildException (chr) vs Py_BadArgument
|
||||
// (chrmgr) argument errors, the rotation/direction conversions, CreateInstance's dict path (with the
|
||||
// "y" -> m_lPosX bug), GetVIDInfo, SetPathName's d:/ymir guard, SetRaceHeight and testSetRideMan.
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "python_runtime.h"
|
||||
#include "eter_net/NetworkActorManager.h"
|
||||
#include "eter_render/RaceData.h"
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
namespace fs = std::filesystem;
|
||||
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
const fs::path root=fs::temp_directory_path()/"ava2_chr_test";
|
||||
fs::remove_all(root);fs::create_directories(root);
|
||||
fs::current_path(root);
|
||||
PythonRuntime python(argv[1],root);
|
||||
auto& mgr=NetworkActorManager::Instance();
|
||||
mgr.Destroy();
|
||||
|
||||
python.execute(
|
||||
"import chr, chrmgr\n"
|
||||
"chr_names=('DismountHorse','MountHorse','SetSash','Destroy','Update','Deform','Render','RenderCollision',"
|
||||
"'CreateInstance','DeleteInstance','DeleteInstanceByFade','SelectInstance','HasInstance','IsEnemy','IsNPC',"
|
||||
"'IsGameMaster','IsPartyMember','Select','SetAddRenderMode','SetBlendRenderMode','Unselect','Hide','Show','Pick',"
|
||||
"'PickAll','SetArmor','SetWeapon','ChangeShape','SetRace','SetHair','ChangeHair','SetVirtualID','SetNameString',"
|
||||
"'SetInstanceType','SetPixelPosition','SetDirection','Refresh','Revive','Die','AttachEffectByID','AttachEffectByName',"
|
||||
"'LookAt','SetMotionMode','SetLoopMotion','BlendLoopMotion','PushOnceMotion','PushLoopMotion','GetPixelPosition',"
|
||||
"'SetRotation','SetRotationAll','BlendRotation','GetRotation','GetRace','GetName','GetNameByVID','GetGuildID',"
|
||||
"'GetProjectPosition','GetVirtualNumber','GetInstanceType','GetBoundBoxOnlyXY','RaceToJob','RaceToSex',"
|
||||
"'testGetPKData','FaintTest','SetMoveSpeed','SetAttackSpeed','WeaponTraceSetTexture','WeaponTraceUseAlpha',"
|
||||
"'WeaponTraceUseTexture','MoveToDestPosition','testSetComboType','testSetAddRenderMode','testSetModulateRenderMode',"
|
||||
"'testSetAddRenderModeRGB','testSetModulateRenderModeRGB','testSetSpecularRenderMode','testSetSpecularRenderMode2',"
|
||||
"'testRestoreRenderMode','testSetRideMan','IsStone')\n"
|
||||
"funcs=sorted(n for n in dir(chr) if callable(getattr(chr,n)))\n"
|
||||
"assert funcs==sorted(chr_names), set(funcs)^set(chr_names)\n"
|
||||
"assert not hasattr(chr,'RequestPetName')\n"
|
||||
"mgr_names=('SetRaceHeight','SetEmpireNameMode','GetVIDInfo','GetPickedVID','SetShapeModel','AppendShapeSkin',"
|
||||
"'SetPathName','LoadRaceData','LoadLocalRaceData','CreateRace','SelectRace','RegisterAttachingBoneName',"
|
||||
"'RegisterMotionMode','SetMotionRandomWeight','RegisterNormalAttack','ReserveComboAttack','RegisterComboAttack',"
|
||||
"'ReserveComboAttackNew','RegisterComboAttackNew','RegisterMotionData','RegisterRaceName','RegisterRaceSrcName',"
|
||||
"'RegisterCacheMotionData','SetAffect','SetEmoticon','IsPossibleEmoticon','RegisterEffect','RegisterCacheEffect',"
|
||||
"'RegisterPointEffect','ShowPointEffect','ToggleDirectionLine','SetMovingSpeed','SetDustGap','SetHorseDustGap',"
|
||||
"'RegisterTitleName','RegisterNameColor','RegisterTitleColor')\n"
|
||||
"funcs=sorted(n for n in dir(chrmgr) if callable(getattr(chrmgr,n)))\n"
|
||||
"assert funcs==sorted(mgr_names), set(funcs)^set(mgr_names)\n"
|
||||
"assert not hasattr(chrmgr,'RegisterMotion')\n"
|
||||
// No selected / unknown instance answers.
|
||||
"assert chr.GetRotation()==0.0 and chr.GetRace()==0 and chr.GetName()==0\n"
|
||||
"assert chr.GetNameByVID(5)=='None' and chr.GetGuildID(5)==0\n"
|
||||
"assert chr.GetProjectPosition(5,0)==(-100,-100)\n"
|
||||
"assert chr.GetVirtualNumber(5)==6 and chr.GetInstanceType(5)==6\n"
|
||||
"assert chr.GetBoundBoxOnlyXY()==(0.0,0.0,0.0,0.0)\n"
|
||||
"assert chr.testGetPKData()==(0,4)\n"
|
||||
"assert chr.Pick()==-1 and chr.PickAll()==-1 and chrmgr.GetPickedVID()==-1\n"
|
||||
"assert chr.GetPixelPosition(5) is None\n"
|
||||
"assert chr.IsEnemy(5)==0 and chr.IsNPC(5)==0 and chr.IsStone(5)==0 and chr.IsGameMaster(5)==0\n"
|
||||
"chr.SetDirection(1)\n"
|
||||
// chr argument errors: Py_BuildException() clears and answers None; chrmgr raises.
|
||||
"assert chr.HasInstance() is None and chr.SetRace('x') is None\n"
|
||||
"for f,a in ((chrmgr.CreateRace,()),(chrmgr.SetDustGap,('x',)),(chrmgr.GetVIDInfo,()),(chr.WeaponTraceSetTexture,()),"
|
||||
"(chr.MoveToDestPosition,(1,2)),(chr.testSetRideMan,(1,))):\n"
|
||||
" try:\n"
|
||||
" f(*a)\n"
|
||||
" raise AssertionError('no error: '+f.__name__)\n"
|
||||
" except TypeError:\n"
|
||||
" pass\n"
|
||||
"assert (chr.RaceToJob(5),chr.RaceToSex(5),chr.RaceToSex(1),chr.RaceToSex(7))==(1,1,0,1)\n"
|
||||
// RegisterInstance (no dict) and the selected-instance setters.
|
||||
"chr.CreateInstance(10)\n"
|
||||
"assert chr.HasInstance(10)==1 and chr.GetInstanceType(10)==6\n"
|
||||
"chr.SelectInstance(10)\n"
|
||||
"chr.SetRotation(90.0)\n"
|
||||
"assert abs(chr.GetRotation()-90.0)<1e-3\n"
|
||||
"chr.SetDirection(2)\n"
|
||||
"assert abs(chr.GetRotation()-270.0)<1e-3\n"
|
||||
"chr.SetDirection(9)\n"
|
||||
"assert abs(chr.GetRotation()-360.0)<1e-3\n"
|
||||
"chr.BlendRotation(30.0, 0.1)\n"
|
||||
"assert abs(chr.GetRotation()-30.0)<1e-3\n"
|
||||
"chr.SetRotationAll(1.0, 2.0, 200.0)\n"
|
||||
"assert abs(chr.GetRotation()-160.0)<1e-3\n"
|
||||
"chr.SetPixelPosition(100, 200, 30)\n"
|
||||
"assert chr.GetPixelPosition(10)==(100.0,200.0,30.0)\n"
|
||||
"chr.SetPixelPosition(150, 250)\n"
|
||||
"assert chr.GetPixelPosition(10)==(150.0,250.0,0.0)\n"
|
||||
"chr.SetNameString('Hero')\n"
|
||||
"assert chr.GetName()=='Hero' and chr.GetNameByVID(10)=='Hero'\n"
|
||||
"chr.SetRace(3)\n"
|
||||
"assert chr.GetRace()==3\n"
|
||||
"chr.SetInstanceType(2)\n"
|
||||
"assert chr.IsStone(10)==1 and chr.GetInstanceType(10)==2\n"
|
||||
"chr.SetInstanceType(1)\n"
|
||||
"assert chr.IsNPC(10)==1\n"
|
||||
"chr.SetInstanceType(0)\n"
|
||||
"assert chr.IsEnemy(10)==1\n"
|
||||
"assert chr.testGetPKData()[0]==0\n"
|
||||
"chr.Hide()\n"
|
||||
"assert chrmgr.GetVIDInfo(10)=='VID 10 (isRegistered=1, isAlive=1, isDead=0) pos=(150, 250)'\n"
|
||||
"assert chrmgr.GetVIDInfo(99)=='VID 99 (isRegistered=0, isAlive=0, isDead=0) '\n"
|
||||
// CreateInstance's dict path: "y" lands in m_lPosX like Windows.
|
||||
"chr.CreateInstance(20, {'x':5, 'y':7, 'horse':0})\n"
|
||||
"assert chr.HasInstance(20)==1 and chr.GetInstanceType(20)==6 and chr.GetVirtualNumber(20)==0\n"
|
||||
"assert chr.GetPixelPosition(20)[0]==7.0 and chr.GetPixelPosition(20)[1]==0.0\n"
|
||||
"assert chr.GetNameByVID(20)=='NONAME'\n"
|
||||
"chr.CreateInstance(20, {'x':1})\n"
|
||||
"assert chr.GetPixelPosition(20)[0]==7.0\n"
|
||||
"assert chr.CreateInstance(30, 5) is None and chr.HasInstance(30)==0\n"
|
||||
"chr.testSetRideMan(40, 50)\n"
|
||||
"assert chr.HasInstance(1)==1 and chr.GetPixelPosition(1)[:2]==(40.0,50.0)\n"
|
||||
"chr.testSetRideMan(60, 70)\n"
|
||||
"assert chr.GetPixelPosition(1)[:2]==(40.0,50.0)\n"
|
||||
"chr.DeleteInstance(20)\n"
|
||||
"assert chr.HasInstance(20)==0\n"
|
||||
// chrmgr race manager calls.
|
||||
"chrmgr.SetPathName('c:/other/')\n"
|
||||
"chrmgr.SetRaceHeight(7, 1.5)\n"
|
||||
"chrmgr.ToggleDirectionLine()\n"
|
||||
"assert chrmgr.IsPossibleEmoticon(-1) in (0,1)\n"
|
||||
"chr.Update()\n"
|
||||
"print 'chr script ok'\n");
|
||||
|
||||
const auto* hidden=mgr.GetActorData(10);
|
||||
require(hidden && hidden->m_isHidden,"chr.Hide marks the selected instance hidden");
|
||||
require(RaceManager::Instance().GetFullPathFileName("a.msa")!="c:/other/a.msa","SetPathName ignores paths without d:/ymir");
|
||||
require(RaceManager::Instance().GetRaceHeight(7)==1.5f,"SetRaceHeight stores the race height");
|
||||
python.execute(
|
||||
"chrmgr.SetPathName('d:/ymir work/pc/warrior/')\n"
|
||||
"chr.SelectInstance(10)\n"
|
||||
"chr.Show()\n");
|
||||
require(RaceManager::Instance().GetFullPathFileName("a.msa")=="d:/ymir work/pc/warrior/a.msa","SetPathName keeps d:/ymir paths");
|
||||
require(!mgr.GetActorData(10)->m_isHidden,"chr.Show clears the hidden flag");
|
||||
python.execute("chr.Destroy()\nassert chr.HasInstance(10)==0 and chr.HasInstance(1)==0\n");
|
||||
std::cout<<"AVA2 chr parity passed"<<std::endl;
|
||||
return 0;
|
||||
} catch(const std::exception& e) {
|
||||
std::cerr<<"chr_test: "<<e.what()<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "cube_renewal_state.h"
|
||||
#include "python_runtime.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
||||
void u32(std::vector<uint8_t>& p,uint32_t value) { for(unsigned i=0;i<4;++i)p.push_back(uint8_t(value>>(i*8))); }
|
||||
std::vector<uint8_t> recipe() {
|
||||
std::vector<uint8_t> p{221,2};u32(p,20016);u32(p,99);u32(p,0x80000001);u32(p,uint32_t(-5));p.push_back(1);
|
||||
for(unsigned i=1;i<=5;++i) { u32(p,100+i);u32(p,uint32_t(-int(i))); }
|
||||
u32(p,uint32_t(-70));u32(p,100);p.resize(167,0);const char category[]="Equipment";
|
||||
std::copy_n(category,9,p.begin()+67);return p;
|
||||
}
|
||||
void send(const std::vector<uint8_t>& data) {
|
||||
auto& s=PythonNetworkStream::Instance();s.PushRecvData(data);s.ProcessRecvData();
|
||||
}
|
||||
std::vector<uint8_t> control(uint8_t sub) { std::vector<uint8_t> p(167);p[0]=221;p[1]=sub;return p; }
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
{
|
||||
PythonRuntime python(argv[1],argv[2]);auto& s=PythonNetworkStream::Instance();s.ResetConnection();s.SetPhase(PHASE_GAME);
|
||||
python.execute("import cube_renewal as cube, net, weakref, gc\nassert cube.CountDates()==0\nassert cube.GetDates() is None\nassert cube.GetDates(-1)==(0,)*15+('None',)\nassert cube.CubeRenewalMakeItem('x',1) is None\nassert cube.SetCubeRenewalHandler() is None\nclass Game:\n def __init__(self): self.opens=0\n def BINARY_CUBE_RENEWAL_OPEN(self): self.opens+=1\nclass Loader:\n def __init__(self): self.counts=[]\n def BINARY_CUBE_RENEWAL_LOADING(self): self.counts.append(cube.CountDates())\ngame=Game()\nloader=Loader()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)\ncube.SetCubeRenewalHandler(loader)\n");
|
||||
auto p=recipe();require(p.size()==167,"literal recipe size");p.push_back(44);
|
||||
s.PushRecvData(p.data(),166);s.ProcessRecvData();python.execute("assert cube.CountDates()==0\n");
|
||||
s.PushRecvData(p.data()+166,2);s.ProcessRecvData();require(s.PopSendBytes()==std::vector<uint8_t>{254},"recipe lost following ping");
|
||||
python.execute("expected=(-2147483647,-5,1,101,-1,102,-2,103,-3,104,-4,105,-5,-70,100,'Equipment')\nassert cube.GetDates(0)==expected\nassert cube.GetDates(0,'extra')==expected\nassert cube.GetDates(1)==(0,)*15+('None',)\n");
|
||||
send(recipe());send(control(3));send(control(0));
|
||||
python.execute("assert cube.CountDates()==2\nassert cube.GetDates(1)==expected\nassert loader.counts==[2]\nassert game.opens==1\n");
|
||||
// Unknown subheaders are consumed as a whole fixed packet without changing recipes.
|
||||
send(control(255));send(control(1));send(control(3));
|
||||
python.execute("assert cube.CountDates()==0\nassert loader.counts==[2,0]\ncube.CubeRenewalMakeItem(2,3)\ncube.CubeRenewalClose()\n");
|
||||
require(s.PopSendBytes().empty(),"craft without main actor sent");
|
||||
SNetworkActorData actor{};actor.m_dwVID=1001;actor.m_dwRace=0;actor.m_stName="CubeFixture";
|
||||
NetworkActorManager::Instance().AppendActor(actor);s.SetMainActorVID(1001);
|
||||
auto instance=NetworkActorManager::Instance().GetActorInstance(1001);require(bool(instance),"missing native actor");
|
||||
python.execute("cube.CubeRenewalMakeItem(-1,2147483649)\ncube.CubeRenewalClose()\n");
|
||||
auto bytes=s.PopSendBytes();std::vector<uint8_t> expected{216,4,255,255,255,255,1,0,0,128,216,5,0,0,0,0,0,0,0,0};
|
||||
require(bytes==expected,"cube request Win32 byte conversion");
|
||||
instance->SetSleep(true);python.execute("cube.CubeRenewalMakeItem(1,2)\ncube.CubeRenewalClose()\n");
|
||||
require(s.PopSendBytes().empty(),"controlled actor allowed cube request");instance->SetSleep(false);
|
||||
python.execute("temporary=Loader()\nref=weakref.ref(temporary)\ncube.SetCubeRenewalHandler(temporary)\ndel temporary\ngc.collect()\nassert ref() is not None\n");
|
||||
send(control(1));python.execute("assert ref() is not None\ncube.SetCubeRenewalHandler(None)\ngc.collect()\nassert ref() is None\n");
|
||||
send(recipe());s.ResetConnection();NetworkActorManager::Instance().Clear();
|
||||
}
|
||||
{ PythonRuntime python(argv[1],argv[2]);python.execute("import cube_renewal as cube\nassert cube.CountDates()==0\n"); }
|
||||
std::cout<<"AVA2 cube renewal state, wire and Python parity passed\n";
|
||||
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "drop_item_state.h"
|
||||
#include "python_runtime.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
using Bytes=std::vector<uint8_t>;
|
||||
void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);}
|
||||
void u32(Bytes& b,uint32_t value) {for(unsigned i=0;i<4;++i)b.push_back(uint8_t(value>>(8*i)));}
|
||||
Bytes record(const std::string& name="Wolf") {
|
||||
Bytes b{220,3};for(unsigned i=0;i<100;++i)b.push_back(i<name.size()?name[i]:0);
|
||||
u32(b,0x80000001);u32(b,0xffffffff);u32(b,uint32_t(-7));return b;
|
||||
}
|
||||
Bytes control(uint8_t sub) {Bytes b(114);b[0]=220;b[1]=sub;return b;}
|
||||
void send(const Bytes& b) {auto& stream=PythonNetworkStream::Instance();stream.PushRecvData(b);stream.ProcessRecvData();}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
{
|
||||
PythonRuntime python(argv[1],argv[2]);auto& stream=PythonNetworkStream::Instance();stream.ResetConnection();stream.SetPhase(PHASE_GAME);
|
||||
python.execute(R"PY(import drop_item as drop,net,weakref,gc
|
||||
assert drop.CountDates()==0 and drop.GetPageActual()==1 and drop.GetPageView()==5
|
||||
assert drop.GetDates(-1)==('None',0,0,0) and drop.GetDates(0)==('None',0,0,0)
|
||||
assert drop.GetDates() is None and drop.SearchItem('x') is None
|
||||
assert drop.SetPageSelect() is None and drop.SetDropItemHandler() is None
|
||||
class Game:
|
||||
def __init__(self): self.opens=0
|
||||
def BINARY_DROP_ITEM_OPEN(self): self.opens+=1
|
||||
class Loader:
|
||||
def __init__(self): self.events=[]
|
||||
def BINARY_DROP_ITEM_LOADING(self): self.events.append((drop.CountDates(),drop.GetPageActual()))
|
||||
game=Game()
|
||||
loader=Loader()
|
||||
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)
|
||||
drop.SetDropItemHandler(loader)
|
||||
drop.SetPageSelect(-5)
|
||||
assert drop.GetPageActual()==-5
|
||||
)PY");
|
||||
auto data=record();require(data.size()==114,"drop literal wire size");data.push_back(44);
|
||||
stream.PushRecvData(data.data(),113);stream.ProcessRecvData();python.execute("assert drop.CountDates()==0\n");
|
||||
stream.PushRecvData(data.data()+113,2);stream.ProcessRecvData();require(stream.PopSendBytes()==Bytes{254},"drop consumed following ping");
|
||||
send(record());send(control(5));send(control(2));send(control(255));
|
||||
python.execute("expected=('Wolf',-2147483647,-1,-7)\nassert drop.CountDates()==2 and drop.GetDates(0)==expected and drop.GetDates(1)==expected\nassert drop.GetDates(0,'ignored')==expected\nassert drop.GetDates(2)==('None',0,0,0)\nassert loader.events==[(2,-5)] and game.opens==1\ndrop.SetPageSelect(2147483649)\nassert drop.GetPageActual()==-2147483647\n");
|
||||
// The Windows name field is 100 bytes; bound unterminated wire strings.
|
||||
send(record(std::string(100,'x')));python.execute("assert drop.GetDates(2)==('x'*100,-2147483647,-1,-7)\n");
|
||||
send(control(4));send(control(5));
|
||||
python.execute("assert drop.CountDates()==0 and drop.GetPageActual()==1\nassert loader.events==[(2,-5),(0,1)]\ndrop.Open()\ndrop.SearchItem(1)\n");require(stream.PopSendBytes().empty(),"drop request sent without main actor");
|
||||
SNetworkActorData actor{};actor.m_dwVID=1001;actor.m_stName="DropFixture";NetworkActorManager::Instance().AppendActor(actor);stream.SetMainActorVID(1001);
|
||||
auto instance=NetworkActorManager::Instance().GetActorInstance(1001);require(bool(instance),"missing native actor");
|
||||
python.execute("drop.Open()\ndrop.SearchItem(-1)\ndrop.SearchItem(2147483649)\n");
|
||||
auto packets=stream.PopSendPacketsWithSequence();require(packets.size()==3,"drop request count");
|
||||
require(packets[0].first==Bytes{215,0,0,0,0,0} && packets[1].first==Bytes{215,1,255,255,255,255} && packets[2].first==Bytes{215,1,1,0,0,128},"drop request Win32 layout");
|
||||
require(packets[0].second && packets[1].second && packets[2].second,"drop request missing SendSequence");
|
||||
instance->SetSleep(true);python.execute("drop.Open()\ndrop.SearchItem(0)\n");require(stream.PopSendBytes().empty(),"sleeping actor sent drop request");instance->SetSleep(false);
|
||||
python.execute("temporary=Loader()\nref=weakref.ref(temporary)\ndrop.SetDropItemHandler(temporary)\ndel temporary\ngc.collect()\nassert ref() is not None\n");
|
||||
send(control(4));send(control(5));python.execute("assert ref() is not None and ref().events==[(0,1)]\ndrop.SetDropItemHandler(None)\ngc.collect()\nassert ref() is None\nclass Broken:\n def BINARY_DROP_ITEM_LOADING(self): raise ValueError('expected failure')\ndrop.SetDropItemHandler(Broken())\n");
|
||||
send(record());send(control(5));python.execute("assert drop.CountDates()==1\ndrop.SetPageSelect(99)\n");
|
||||
require(stream.GetUnportedPackets().empty(),"drop receive still uses skip handler");stream.ResetConnection();
|
||||
}
|
||||
{PythonRuntime python(argv[1],argv[2]);python.execute("import drop_item as drop\nassert drop.CountDates()==0 and drop.GetPageActual()==1\n");}
|
||||
std::cout<<"AVA2 drop item state, wire and Python parity passed\n";
|
||||
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "dungeon_info_state.h"
|
||||
#include "python_runtime.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
using Bytes=std::vector<uint8_t>;
|
||||
void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);}
|
||||
void u32(Bytes& b,uint32_t value) {for(unsigned i=0;i<4;++i)b.push_back(uint8_t(value>>(8*i)));}
|
||||
void text(Bytes& b,const std::string& value,size_t width) {for(size_t i=0;i<width;++i)b.push_back(i<value.size()?value[i]:0);}
|
||||
Bytes record(uint8_t sub) {
|
||||
Bytes b{217,sub};u32(b,uint32_t(-5));text(b,"Dungeon",100);text(b,"image.tga",100);
|
||||
for(int32_t v:{20,120,8,-1,int32_t(0x80000001),-10,40})u32(b,uint32_t(v));
|
||||
for(const auto* value:{"Portal","Ice","Fire"})text(b,value,100);
|
||||
for(int32_t v:{101,2,3,400,5,-6,700,800})u32(b,uint32_t(v));
|
||||
u32(b,800);u32(b,2);text(b,"RankHero",24);u32(b,uint32_t(-100));
|
||||
for(int32_t v:{900,-2,3,1})u32(b,uint32_t(v));return b;
|
||||
}
|
||||
Bytes control(uint8_t sub) {Bytes b(618);b[0]=217;b[1]=sub;return b;}
|
||||
void send(const Bytes& b) {auto& stream=PythonNetworkStream::Instance();stream.PushRecvData(b);stream.ProcessRecvData();}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
{
|
||||
PythonRuntime python(argv[1],argv[2]);auto& stream=PythonNetworkStream::Instance();stream.ResetConnection();stream.SetPhase(PHASE_GAME);
|
||||
python.execute(R"PY(import dungeon_info as dungeon,net
|
||||
empty=(0,'None','None',0,0,0,0,0,0,0,'None','None','None',0,0,0,0,0,0,0,0)
|
||||
assert dungeon.CountDate()==0 and dungeon.CountDateRanking()==0
|
||||
assert dungeon.GetPageView()==13 and dungeon.GetPageCount()==1
|
||||
assert dungeon.InfoDate(-1)==empty and dungeon.InfoDate(0)==empty
|
||||
assert dungeon.InfoDateMision(-1)==(0,0,0,0) and dungeon.InfoDateRanking(0)==(0,0,'None',0)
|
||||
assert dungeon.InfoDate() is None and dungeon.InfoDateRanking() is None and dungeon.InfoDateMision() is None
|
||||
assert dungeon.Teleport('x') is None and dungeon.SetPageCount() is None
|
||||
class Game:
|
||||
def __init__(self): self.events=[]
|
||||
def BINARY_TABLE_DUNGEON_INFO_OPEN(self): self.events.append(('open',dungeon.CountDate()))
|
||||
def BINARY_TABLE_DUNGEON_RANKING_LOAD(self): self.events.append(('ranking',dungeon.CountDateRanking()))
|
||||
def BINARY_TABLE_DUNGEON_MISION_LOAD(self): self.events.append(('mission',dungeon.InfoDateMision(0)))
|
||||
game=Game()
|
||||
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)
|
||||
dungeon.SetPageCount(-2)
|
||||
assert dungeon.GetPageCount()==-2
|
||||
)PY");
|
||||
auto data=record(4);require(data.size()==618,"dungeon literal wire size");data.push_back(44);
|
||||
stream.PushRecvData(data.data(),617);stream.ProcessRecvData();python.execute("assert dungeon.CountDate()==0\n");
|
||||
stream.PushRecvData(data.data()+617,2);stream.ProcessRecvData();require(stream.PopSendBytes()==Bytes{254},"dungeon consumed following ping");
|
||||
send(record(4));send(record(7));send(record(7));send(control(3));send(control(8));send(control(255));
|
||||
python.execute(R"PY(expected=(-5,'Dungeon','image.tga',20,120,8,-1,-2147483647,-10,40,'Portal','Ice','Fire',101,2,3,400,5,-6,700,800)
|
||||
assert dungeon.CountDate()==2 and dungeon.InfoDate(0)==expected and dungeon.InfoDate(1)==expected
|
||||
assert dungeon.InfoDate(0,'ignored')==expected and dungeon.InfoDate(2)==empty
|
||||
assert dungeon.CountDateRanking()==2 and dungeon.InfoDateRanking(0)==(800,2,'RankHero',-100)
|
||||
assert dungeon.GetPageCount()==-2
|
||||
assert game.events==[('open',2),('ranking',2)]
|
||||
)PY");
|
||||
// Mission-send falls through to ranking-clear in the original switch.
|
||||
send(record(11));send(record(11));send(control(12));python.execute("assert dungeon.InfoDateMision(0)==(900,-2,3,1) and dungeon.InfoDateMision(1)==(900,-2,3,1)\nassert dungeon.InfoDateMision(2)==(0,0,0,0) and dungeon.CountDateRanking()==0\nassert game.events[-1]==('mission',(900,-2,3,1))\n");
|
||||
send(record(7));send(control(10));python.execute("assert dungeon.InfoDateMision(0)==(0,0,0,0) and dungeon.CountDateRanking()==1\nassert dungeon.CountDate()==2 and dungeon.GetPageCount()==-2\n");
|
||||
send(record(11));send(record(7));send(control(5));python.execute("assert dungeon.CountDate()==0 and dungeon.InfoDateMision(0)==(0,0,0,0) and dungeon.GetPageCount()==1\nassert dungeon.CountDateRanking()==1\n");send(control(6));python.execute("assert dungeon.CountDateRanking()==0\n");
|
||||
// Fixed strings are bounded even when the server supplies no terminator.
|
||||
data=record(4);std::fill(data.begin()+6,data.begin()+106,'x');send(data);
|
||||
data=record(7);std::fill(data.begin()+574,data.begin()+598,'y');send(data);
|
||||
python.execute("assert dungeon.InfoDate(0)[1]=='x'*100\nassert dungeon.InfoDateRanking(0)[2]=='y'*24\ndungeon.SetPageCount(2147483649)\nassert dungeon.GetPageCount()==-2147483647\ndungeon.Open()\ndungeon.Teleport(1)\ndungeon.Mision(2)\ndungeon.Ranking(3)\n");require(stream.PopSendBytes().empty(),"dungeon request sent without main actor");
|
||||
SNetworkActorData actor{};actor.m_dwVID=1001;actor.m_stName="DungeonFixture";NetworkActorManager::Instance().AppendActor(actor);stream.SetMainActorVID(1001);
|
||||
auto instance=NetworkActorManager::Instance().GetActorInstance(1001);require(bool(instance),"missing native actor");
|
||||
python.execute("dungeon.Open()\ndungeon.Teleport(-1)\ndungeon.Mision(2147483649)\ndungeon.Ranking(3)\n");auto packets=stream.PopSendPacketsWithSequence();require(packets.size()==4,"dungeon request count");
|
||||
const std::vector<Bytes> expected{{213,0,0,0,0,0},{213,1,255,255,255,255},{213,2,1,0,0,128},{213,9,3,0,0,0}};
|
||||
for(size_t i=0;i<4;++i)require(packets[i].first==expected[i] && packets[i].second,"dungeon Win32 bytes or sequence mismatch");
|
||||
instance->SetSleep(true);python.execute("dungeon.Open()\ndungeon.Teleport(1)\ndungeon.Mision(2)\ndungeon.Ranking(3)\n");require(stream.PopSendBytes().empty(),"sleeping actor sent dungeon request");instance->SetSleep(false);
|
||||
python.execute("def broken(): raise ValueError('expected callback failure')\ngame.BINARY_TABLE_DUNGEON_INFO_OPEN=broken\n");send(control(3));send(record(4));python.execute("assert dungeon.CountDate()==2\n");
|
||||
require(stream.GetUnportedPackets().empty(),"dungeon still routed through skip handler");stream.ResetConnection();
|
||||
}
|
||||
{PythonRuntime python(argv[1],argv[2]);python.execute("import dungeon_info as dungeon\nassert dungeon.CountDate()==0 and dungeon.CountDateRanking()==0 and dungeon.GetPageCount()==1\nassert dungeon.InfoDateMision(0)==(0,0,0,0)\n");}
|
||||
std::cout<<"AVA2 dungeon info state, wire and Python parity passed\n";
|
||||
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
// CPythonEventManager / script::Group and the pass-23 lookups (item.GetApplyPoint,
|
||||
// player.SlotTypeToInvenType, app.GetRandom, nonplayer.GetResist, player getters) against the
|
||||
// original AVA2 behaviour.
|
||||
#include "windows_item_oracle.h"
|
||||
#include "nonplayer_data.h"
|
||||
#include "python_event_manager.h"
|
||||
#include "python_runtime.h"
|
||||
#include "eter_lib/parser.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
||||
std::vector<uint8_t> literalLzo(const uint8_t* bytes,size_t size) {
|
||||
std::vector<uint8_t> out{uint8_t(17+size)};
|
||||
out.insert(out.end(),bytes,bytes+size);out.insert(out.end(),{17,0,0});return out;
|
||||
}
|
||||
void put32(std::vector<uint8_t>& p,uint32_t n) { for(unsigned i=0;i<4;++i)p.push_back(uint8_t(n>>(i*8))); }
|
||||
void loadMob(uint32_t vnum) {
|
||||
ava2_windows_mob::TMobTable_r235 row{};row.dwVnum=vnum;
|
||||
for(size_t i=0;i<sizeof(row.cResists);++i) row.cResists[i]=static_cast<char>(int(i)-5);
|
||||
auto packed=literalLzo(reinterpret_cast<const uint8_t*>(&row),sizeof(row));
|
||||
std::vector<uint8_t> p{'M','M','P','T'};put32(p,1);put32(p,uint32_t(20+packed.size()));
|
||||
p.insert(p.end(),{'M','C','O','Z'});put32(p,0);put32(p,uint32_t(packed.size()));put32(p,sizeof(row));put32(p,0);
|
||||
p.insert(p.end(),packed.begin(),packed.end());
|
||||
NonPlayerData::Instance().clear();
|
||||
require(NonPlayerData::Instance().load(std::string(p.begin(),p.end())),"mob fixture failed to load");
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
// Parser: one LETTER per character, [CMD a;1|b;2] arguments, '\n' outside commands counted.
|
||||
script::Group group;
|
||||
require(group.Create("ab\n[QUESTION a;Yes|b;No]\n[DELAY value;0]")==2,"line count");
|
||||
script::TCmd cmd;
|
||||
require(group.GetCmd(cmd) && cmd.name=="LETTER" && cmd.argList.front().strValue=="a","letter");
|
||||
require(group.GetCmd(cmd) && group.GetCmd(cmd) && cmd.name=="QUESTION" && cmd.argList.size()==2,"question");
|
||||
require(cmd.argList.front().strName=="a" && cmd.argList.back().strValue=="No","question args");
|
||||
require(group.ReadCmd(cmd) && cmd.name=="DELAY" && group.GetCmd(cmd) && !group.GetCmd(cmd),"peek/pop");
|
||||
require(group.Create("[UNCLOSED")==-1,"syntax error accepted");
|
||||
|
||||
PythonRuntime python(argv[1],argv[2]);
|
||||
auto& stream=PythonNetworkStream::Instance();stream.ResetConnection();stream.SetPhase(PHASE_GAME);
|
||||
auto& events=CPythonEventManager::Instance();
|
||||
python.execute(
|
||||
"import event, net\n"
|
||||
"assert (event.BUTTON_TYPE_NEXT,event.BUTTON_TYPE_DONE,event.BUTTON_TYPE_CANCEL)==(0,1,2)\n"
|
||||
"assert event.BOX_VISIBLE_LINE_COUNT==14\n"
|
||||
"assert not hasattr(event,'GetTotalLineCount')\n"
|
||||
"class Handler:\n"
|
||||
" def __init__(self):\n self.calls=[]\n"
|
||||
" def MakeNextButton(self,t):\n self.calls.append(('next',t))\n"
|
||||
" def DoneEvent(self):\n self.calls.append(('done',))\n"
|
||||
" def MakeQuestion(self,n):\n self.calls.append(('question',n))\n"
|
||||
" def AppendQuestion(self,s,i):\n self.calls.append(('answer',s,i))\n"
|
||||
" def OnTitleImage(self,s):\n self.calls.append(('title',s))\n"
|
||||
"h=Handler()\n"
|
||||
"idx=event.RegisterEventSetFromString('Hi[ENTER]ab[NEXT][QUESTION a;Yes|b;No][TITLE_IMAGE src;t.tga][DONE][WAIT]x\\n')\n"
|
||||
"assert idx==0\n"
|
||||
"event.SetEventHandler(idx,h)\n"
|
||||
"assert event.GetLineCount(idx)==0\n"
|
||||
"event.AllProcessEventSet(idx)\n"
|
||||
"assert h.calls==[('next',0),('question',2),('answer','Yes',0),('answer','No',1),('title','t.tga'),('next',1),('done',)],h.calls\n"
|
||||
"assert event.IsWait(idx)\n"
|
||||
"assert event.GetProcessedLineCount(idx)==1\n"
|
||||
"assert event.GetLineCount(idx)==5\n"
|
||||
"event.Skip(idx)\n"
|
||||
"assert not event.IsWait(idx)\n"
|
||||
"event.AllProcessEventSet(idx)\n"
|
||||
"assert event.IsWait(idx)\n"
|
||||
"event.SetVisibleStartLine(idx,2)\n"
|
||||
"assert event.GetVisibleStartLine(idx)==0\n"
|
||||
"event.SetVisibleStartLine(idx,1)\n"
|
||||
"assert event.GetVisibleStartLine(idx)==1\n"
|
||||
"assert event.RegisterEventSetFromString('[UNCLOSED')==-1\n"
|
||||
"assert event.RegisterEventSetFromString('[RUN_CINEMA value;missing_cinema.txt]')==-1\n");
|
||||
const auto* set=events.GetEventSet(0);
|
||||
require(set && set->strCurrentLine=="abx" && set->iTotalLineCount==1,"current line / total line count");
|
||||
// UpdateEventSet: the frame's elapsed time is taken off the delay twice (Windows quirk), then
|
||||
// spent command by command at the [DELAY] pace.
|
||||
python.execute("j=event.RegisterEventSetFromString('[DELAY value;100]abc')\nassert j==1\n");
|
||||
events.SetElapsedMillisecond(0);
|
||||
python.execute("event.UpdateEventSet(j,0,0)\n");
|
||||
require(events.GetEventSet(1)->strCurrentLine.empty() && events.GetEventSet(1)->lLastDelayTime==0,"zero elapsed processed a command");
|
||||
events.SetElapsedMillisecond(15);
|
||||
python.execute("event.UpdateEventSet(j,0,0)\n");
|
||||
require(events.GetEventSet(1)->lWaitingTime==100 && events.GetEventSet(1)->strCurrentLine.empty(),"DELAY command");
|
||||
python.execute("event.UpdateEventSet(j,0,0)\n");
|
||||
require(events.GetEventSet(1)->strCurrentLine=="a" && events.GetEventSet(1)->lLastDelayTime==85,"first letter");
|
||||
python.execute("event.UpdateEventSet(j,0,0)\n");
|
||||
require(events.GetEventSet(1)->strCurrentLine=="a" && events.GetEventSet(1)->lLastDelayTime==55,"double elapsed subtraction");
|
||||
events.SetElapsedMillisecond(1000);
|
||||
python.execute("event.UpdateEventSet(j,0,0)\nevent.ClearEventSet(j)\n");
|
||||
require(!events.GetEventSet(1),"cleared slot");
|
||||
|
||||
// Answers and quest buttons reach the wire: CG_SCRIPT_ANSWER (29) / CG_SCRIPT_BUTTON (66).
|
||||
stream.PopSendBytes();
|
||||
python.execute("event.SelectAnswer(idx,3)\nevent.SelectAnswer(99,4)\nevent.QuestButtonClick(0x01020304)\n");
|
||||
require(stream.PopSendBytes()==std::vector<uint8_t>{29,3,66,4,3,2,1},"answer/button packets");
|
||||
|
||||
// AddEvent registers, sizes to 30 visible lines and opens the game phase quest window.
|
||||
python.execute(
|
||||
"class Game:\n def __init__(self):\n self.opened=[]\n def OpenQuestWindow(self,skin,index):\n self.opened.append((skin,index))\n"
|
||||
"g=Game()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,g)\n"
|
||||
"event.AddEvent('[ENTER]',7)\n"
|
||||
"assert g.opened==[(7,1)],g.opened\n");
|
||||
require(events.GetEventSet(1)->iVisibleLineCount==30,"AddEvent visible line count");
|
||||
python.execute("event.Destroy()\nassert event.GetLineCount(idx)==0\n");
|
||||
|
||||
// initNonPlayer clears the table, so the fixture goes in after the first import.
|
||||
python.execute("import item, player, app, nonplayer\n");
|
||||
loadMob(2001);
|
||||
python.execute(
|
||||
"assert item.GetApplyPoint(0)==0 and item.GetApplyPoint(1)==6\n"
|
||||
"assert item.GetApplyPoint(177)==0\n"
|
||||
"try:\n item.GetApplyPoint('x')\n raise AssertionError('bad apply type accepted')\nexcept TypeError:\n pass\n"
|
||||
"assert player.SlotTypeToInvenType(1)==1 and player.SlotTypeToInvenType(11)==5\n"
|
||||
"assert player.SlotTypeToInvenType(18)==12 and player.SlotTypeToInvenType(99)==0\n"
|
||||
"for n in range(200):\n r=app.GetRandom(5,1)\n assert 1<=r<=5\n"
|
||||
"assert app.GetRandom(3,3)==3\n"
|
||||
"assert nonplayer.GetResist(2001,0)==-5 and nonplayer.GetResist(2001,10)==5\n"
|
||||
"assert nonplayer.GetResist(2001,11)==0 and nonplayer.GetResist(2001,256)==-5\n"
|
||||
"assert nonplayer.GetResist(9999,0)==0\n"
|
||||
"assert player.GetGuildID()==0 and player.GetGuildName()=='' and player.GetPKMode()==0\n"
|
||||
"assert player.IsGameMaster()==0 and player.GetEXP()==0 and player.GetConquerorEXP()==0\n"
|
||||
"player.SetPlayTime(77)\nassert player.GetPlayTime()==77\n"
|
||||
"assert player.SetPlayTime('x') is None and player.GetPlayTime()==77\n"
|
||||
"assert player.GetJob()==player.GetRace()%4\n");
|
||||
NonPlayerData::Instance().clear();stream.ResetConnection();
|
||||
std::cout<<"AVA2 event manager and simple lookups parity passed\n";
|
||||
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
|
||||
}
|
||||
@@ -26,6 +26,23 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Degree 0 with several knots (AVA2 DaKeyframes32f) holds the last knot <= t.
|
||||
gr2::Curve steps;
|
||||
steps.degree = 0;
|
||||
steps.dim = 1;
|
||||
steps.knots = {0.0f, 0.5f, 1.0f};
|
||||
steps.controls = {10.0f, 20.0f, 30.0f};
|
||||
const float step_t[] = {-1.0f, 0.0f, 0.49f, 0.5f, 0.99f, 1.0f, 2.0f};
|
||||
const float step_v[] = {10.0f, 10.0f, 10.0f, 20.0f, 20.0f, 30.0f, 30.0f};
|
||||
for (size_t i = 0; i < sizeof step_t / sizeof step_t[0]; ++i) {
|
||||
float v = 0.0f;
|
||||
steps.eval(step_t[i], &v);
|
||||
if (v != step_v[i]) {
|
||||
std::fprintf(stderr, "degree-0 step t=%f got %f want %f\n", step_t[i], v, step_v[i]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// BoneTrack::sample fills SRT components and flags; sample_local = compose(sample).
|
||||
gr2::BoneTrack track;
|
||||
track.position.degree = 1;
|
||||
|
||||
@@ -14,9 +14,12 @@ void wr32(std::vector<uint8_t> &bytes, size_t off, uint32_t value) {
|
||||
bytes[off + 3] = uint8_t(value >> 24);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> granny_header(size_t size, uint32_t section_count) {
|
||||
constexpr uint32_t kMagic32LE[] = { 0xCAB067B8, 0x0FB16DF8, 0x7E8C7284, 0x1E00195E };
|
||||
constexpr uint32_t kMagic64LE[] = { 0x5E499BE5, 0x141F636F, 0xA9EB131E, 0xC4EDBE90 };
|
||||
constexpr uint32_t kMagic32BE[] = { 0xB595110E, 0x4BB5A56A, 0x502828EB, 0x04B37825 };
|
||||
|
||||
std::vector<uint8_t> granny_header(size_t size, uint32_t section_count, const uint32_t *magic = kMagic32LE) {
|
||||
std::vector<uint8_t> bytes(size, 0);
|
||||
const uint32_t magic[] = { 0xCAB067B8, 0x0FB16DF8, 0x7E8C7284, 0x1E00195E };
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
wr32(bytes, size_t(i) * 4, magic[i]);
|
||||
}
|
||||
@@ -47,14 +50,53 @@ int main() {
|
||||
bool ok = true;
|
||||
ok &= expect_failure(std::vector<uint8_t>(80, 0), "header");
|
||||
ok &= expect_failure(granny_header(80, 0), "fileinfo");
|
||||
// 64-bit little-endian Granny (AVA2 plechi_* assets) passes the header stage;
|
||||
// big-endian is still rejected there.
|
||||
ok &= expect_failure(granny_header(80, 0, kMagic64LE), "fileinfo");
|
||||
ok &= expect_failure(granny_header(80, 0, kMagic32BE), "header");
|
||||
|
||||
auto unsupported = granny_header(160, 1);
|
||||
constexpr size_t section = 72;
|
||||
wr32(unsupported, section + 0, 4); // unsupported BitKnit
|
||||
wr32(unsupported, section + 0, 3); // BitKnit v1 is not implemented
|
||||
wr32(unsupported, section + 4, uint32_t(unsupported.size()));
|
||||
wr32(unsupported, section + 12, 1); // non-empty expanded section
|
||||
ok &= expect_failure(unsupported, "section");
|
||||
|
||||
// BitKnit2 (Format 4) with an empty stream: no 0x75B1 magic -> clean section failure.
|
||||
auto bitknit_empty = unsupported;
|
||||
wr32(bitknit_empty, section + 0, 4);
|
||||
ok &= expect_failure(bitknit_empty, "section");
|
||||
|
||||
// BitKnit2 stored quantum: magic 0x75B1, u16 0 marker, 8 raw bytes. The section
|
||||
// decodes, so loading proceeds to the (empty) type tree instead of failing in "section".
|
||||
auto bitknit_stored = granny_header(160, 1);
|
||||
const uint8_t stream[] = { 0xB1, 0x75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
for (size_t i = 0; i < sizeof(stream); ++i) bitknit_stored[120 + i] = stream[i];
|
||||
wr32(bitknit_stored, section + 0, 4);
|
||||
wr32(bitknit_stored, section + 4, 120);
|
||||
wr32(bitknit_stored, section + 8, uint32_t(sizeof(stream)));
|
||||
wr32(bitknit_stored, section + 12, 8);
|
||||
{
|
||||
gr2::LoadError err;
|
||||
auto file = gr2::File::load(bitknit_stored.data(), bitknit_stored.size(), &err);
|
||||
if (!file && err.stage == "section") {
|
||||
std::fprintf(stderr, "BitKnit2 stored quantum rejected: %s\n", err.message.c_str());
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Truncated stored quantum (claims 8 bytes, carries 4) must fail cleanly.
|
||||
auto bitknit_short = bitknit_stored;
|
||||
wr32(bitknit_short, section + 8, 8);
|
||||
ok &= expect_failure(bitknit_short, "section");
|
||||
|
||||
// BitKnit2 fixup table: u32 compressed size pointing past EOF -> clean "fixup" failure.
|
||||
auto bitknit_fixup = bitknit_stored;
|
||||
wr32(bitknit_fixup, section + 28, 150); // PointerFixupArrayOffset
|
||||
wr32(bitknit_fixup, section + 32, 1); // PointerFixupArrayCount
|
||||
wr32(bitknit_fixup, 150, 1000);
|
||||
ok &= expect_failure(bitknit_fixup, "fixup");
|
||||
|
||||
auto bad_offset = granny_header(160, 1);
|
||||
wr32(bad_offset, section + 4, UINT32_MAX);
|
||||
ok &= expect_failure(bad_offset, "section");
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
#include "guild_state.h"
|
||||
#include "python_runtime.h"
|
||||
#include "python_net.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <iostream>
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
using Bytes=std::vector<uint8_t>;
|
||||
void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);}
|
||||
void u32(Bytes& b,uint32_t v) {for(int i=0;i<4;++i)b.push_back(uint8_t(v>>(8*i)));}
|
||||
void u16(Bytes& b,uint16_t v) {b.push_back(uint8_t(v));b.push_back(uint8_t(v>>8));}
|
||||
void str(Bytes& b,const std::string& value,size_t width) {for(size_t i=0;i<width;++i)b.push_back(i<value.size()?value[i]:0);}
|
||||
Bytes pid(uint32_t id) {Bytes b;u32(b,id);return b;}
|
||||
Bytes frame(uint8_t sub,const Bytes& b) {Bytes out{75};u16(out,uint16_t(b.size()+4));out.push_back(sub);out.insert(out.end(),b.begin(),b.end());return out;}
|
||||
void send(uint8_t sub,const Bytes& b) {auto& net=PythonNetworkStream::Instance();net.PushRecvData(frame(sub,b));net.ProcessRecvData();}
|
||||
void member(Bytes& b,uint32_t id,uint8_t grade,uint8_t job,uint8_t level,uint32_t offer,uint8_t general,const char* name) {
|
||||
u32(b,id);b.insert(b.end(),{grade,general,job,level});u32(b,offer);b.push_back(name?1:0);if(name)str(b,name,25);
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
{
|
||||
PythonRuntime python(argv[1],argv[2]);auto& net=PythonNetworkStream::Instance();net.ResetConnection();net.SetPhase(PHASE_GAME);SetMainCharacterName("Hero");
|
||||
Character hero;hero.name="Hero";hero.guild_id=7;hero.guild_name="Seven";set_mock_character(0,hero);
|
||||
python.execute(R"PY(import guild,net,messenger
|
||||
assert (guild.AUTH_ADD_MEMBER,guild.AUTH_REMOVE_MEMBER,guild.AUTH_NOTICE,guild.AUTH_SKILL,guild.ENEMY_GUILD_SLOT_MAX_COUNT)==(1,2,4,8,6)
|
||||
assert guild.IsGuildEnable()==0 and guild.HasGuildLand()==0
|
||||
assert guild.GetGuildID()==0 and guild.GetGuildName()==''
|
||||
assert guild.GetGuildName(99)=='Noname' and guild.GetGuildMasterName()=='Noname'
|
||||
assert guild.GetGuildExperience()==(0,0) and guild.GetGuildMemberCount()==(0,0)
|
||||
assert guild.GetGuildBoardCommentData(-1)==(0,'Noname','Noname')
|
||||
assert guild.GetMemberData(-1)==(-1,'',0,0,0,0,0) and guild.MemberIndexToPID(0)==-1
|
||||
assert guild.GetGradeData(1)==('?',0) and guild.GetGradeName(1)=='?'
|
||||
assert guild.GuildIDToMarkID(987654321)==-1
|
||||
assert guild.GetMemberData() is None and guild.SetSkillIndex() is None
|
||||
class Handler:
|
||||
def __init__(self): self.events=[]
|
||||
def __getattr__(self,name):
|
||||
def event(*args): self.events.append((name,)+args)
|
||||
return event
|
||||
def BINARY_GuildWar_OnStart(self,a,b):
|
||||
assert guild.GetEnemyGuildName(0)==''
|
||||
self.events.append(('start',a,b))
|
||||
def BINARY_GuildWar_OnEnd(self,a,b):
|
||||
assert guild.GetEnemyGuildName(0)=='Enemy'
|
||||
self.events.append(('end',a,b))
|
||||
h=Handler()
|
||||
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,h)
|
||||
messenger.SetMessengerHandler(h)
|
||||
)PY");
|
||||
Bytes info;u16(info,2);u16(info,32);u32(info,7);u32(info,11);u32(info,1000);info.push_back(2);str(info,"Seven",13);u32(info,123456);info.push_back(1);send(8,info);
|
||||
python.execute("assert guild.IsGuildEnable()==1 and guild.HasGuildLand()==1\nassert guild.GetGuildID()==7 and guild.GetGuildName()=='Seven'\nassert guild.GetGuildLevel()==2 and guild.GetGuildExperience()==(1000,17000)\nassert guild.GetGuildMemberCount()==(2,32) and guild.GetGuildMoney()==123456\nassert h.events==[('RefreshGuildInfoPage',)]\nh.events=[]\n");
|
||||
Bytes list;member(list,22,3,2,40,200,0,"Bob");member(list,11,1,0,60,500,1,"Hero");auto packet=frame(2,list);packet.push_back(44);
|
||||
net.PushRecvData(packet.data(),packet.size()-2);net.ProcessRecvData();python.execute("assert guild.GetMemberCount()==0 and h.events==[]\n");
|
||||
net.PushRecvData(packet.data()+packet.size()-2,2);net.ProcessRecvData();require(net.PopSendBytes()==Bytes{254},"guild list consumed coalesced ping");
|
||||
python.execute(R"PY(assert guild.GetGuildMasterName()=='Hero'
|
||||
assert guild.GetMemberData(0)==(11,'Hero',1,0,60,500,1)
|
||||
assert guild.GetMemberData(1)==(22,'Bob',3,2,40,200,0)
|
||||
assert guild.IsMember(0)==1 and guild.IsMember(11)==0
|
||||
assert guild.IsMemberByName('Bob')==1 and guild.IsMemberByName('bob')==0
|
||||
assert guild.MemberIndexToPID(1)==22
|
||||
assert (guild.GetGuildMemberLevelSummary(),guild.GetGuildMemberLevelAverage(),guild.GetGuildExperienceSummary())==(100,50,700)
|
||||
assert h.events==[('OnLogout',1,'Bob'),('RefreshTargetBoardByName','Bob'),('RefreshTargetBoardByName','Hero'),('RefreshCharacter',),('RefreshMessenger',),('RefreshGuildInfoPage',),('RefreshGuildMemberPage',)]
|
||||
h.events=[]
|
||||
net.SendGuildRemoveMemberPacket('Bob')
|
||||
)PY");
|
||||
require(net.PopSendBytes()==Bytes{80,1,22,0,0,0},"guild removal must resolve name to PID");
|
||||
send(0,pid(22));send(1,pid(22));send(0,pid(11));send(0,pid(99));
|
||||
python.execute("assert h.events==[('OnLogin',1,'Bob'),('OnLogout',1,'Bob')]\nh.events=[]\n");
|
||||
Bytes update;member(update,22,2,4,45,300,1,nullptr);send(2,update);
|
||||
python.execute("assert guild.GetMemberData(1)==(22,'Bob',2,2,45,300,1)\nassert guild.GetGuildMemberLevelAverage()==52 and guild.GetGuildExperienceSummary()==800\nh.events=[]\n");
|
||||
Bytes grade{2,1};str(grade,"Master",9);grade.push_back(15);grade.push_back(2);str(grade,"Officer",9);grade.push_back(3);send(3,grade);
|
||||
python.execute("assert guild.GetGradeData(1)==('Master',15)\nassert guild.MainPlayerHasAuthority(3)==1 and guild.MainPlayerHasAuthority(16)==0\nassert h.events==[('RefreshGuildMemberPageGradeComboBox',),('RefreshGuildGradePage',)]\nh.events=[]\n");
|
||||
Bytes rename{1};str(rename,"Leader",9);send(6,rename);send(7,{1,5});
|
||||
python.execute("assert guild.GetGradeData(1)==('Leader',5) and guild.MainPlayerHasAuthority(3)==0\nassert h.events==[('RefreshGuildGrade',),('RefreshGuildMemberPageGradeComboBox',),('RefreshGuildGradePage',),('RefreshGuildGrade',),('RefreshGuildGradePage',)]\nh.events=[]\n");
|
||||
send(7,{9,255});python.execute("assert guild.GetGradeData(9)==('?',0)\nh.events=[]\n");
|
||||
auto change=pid(11);change.push_back(5);send(11,change);change=pid(22);change.push_back(0);send(13,change);
|
||||
python.execute("assert guild.MemberIndexToPID(0)==11 and guild.GetMemberData(0)[2]==5\nassert guild.GetMemberData(1)[6]==0\nh.events=[]\n");
|
||||
Bytes skills{8,1,2,3,4,5,6,7,8,9,10,11,12};u16(skills,300);u16(skills,600);send(12,skills);
|
||||
python.execute(R"PY(assert guild.GetGuildSkillPoint()==8 and guild.GetDragonPowerPoint()==(300,600)
|
||||
assert guild.GetGuildSkillLevel(11)==12 and guild.GetGuildSkillLevel(-1)==0
|
||||
assert guild.GetSkillLevel(3)==0 and guild.GetSkillIndex(3)==0
|
||||
guild.SetSkillIndex(3,7)
|
||||
guild.SetSkillIndex(3,2)
|
||||
assert guild.GetSkillIndex(3)==7 and guild.GetSkillLevel(3)==8 and guild.GetSkillMaxLevelNew(3)==8
|
||||
guild.SetSkillIndex(9,99)
|
||||
assert guild.GetSkillLevel(9)==0
|
||||
h.events=[]
|
||||
)PY");
|
||||
Bytes comments{2};u32(comments,101);str(comments,"Hero",25);str(comments,"Notice",51);u32(comments,102);str(comments,"Bob",25);str(comments,"",51);send(9,comments);
|
||||
python.execute("assert guild.GetGuildBoardCommentCount()==1 and guild.GetGuildBoardCommentData(0)==(101,'Hero','Notice')\nassert h.events==[('RefreshGuildBoardPage',)]\nh.events=[]\n");
|
||||
Bytes exp{19};u32(exp,4000001);send(10,exp);python.execute("assert guild.GetGuildExperience()==(4000001,-1)\n");exp={20};u32(exp,100);send(10,exp);python.execute("assert guild.GetGuildExperience()==(0,0)\n");send(20,pid(0xffffffff));python.execute("assert guild.GetGuildMoney()==-1\nh.events=[]\n");
|
||||
Bytes names;u32(names,9);str(names,"Enemy",12);u32(names,9);str(names,"Replacement",12);u32(names,7);str(names,"Seven",12);send(16,names);python.execute("assert guild.GetGuildName(9)=='Enemy'\n");
|
||||
Bytes invite=pid(7);str(invite,"ABCDEFGHIJKL",12);send(14,invite);
|
||||
Bytes war=pid(7);u32(war,9);war.push_back(2);war.push_back(1);send(15,war);war.back()=3;send(15,war);war.back()=6;send(15,war);python.execute("assert guild.GetEnemyGuildName(0)=='Enemy'\n");war.back()=7;send(15,war);
|
||||
Bytes point=pid(7);u32(point,9);u32(point,uint32_t(-3));send(19,point);
|
||||
python.execute("assert guild.GetEnemyGuildName(0)==''\nassert h.events==[('RecvGuildInviteQuestion',7,'ABCDEFGHIJKL'),('BINARY_GuildWar_OnSendDeclare',9),('BINARY_GuildWar_OnRecvDeclare',9,2),('start',7,9),('end',7,9),('BINARY_GuildWar_OnRecvPoint',7,9,-3)]\nh.events=[]\n");
|
||||
Bytes pair=pid(7);u32(pair,9);send(17,pair);require(NetworkActorManager::Instance().FindGVGKey(9,7),"missing symmetric guild war key");send(18,pair);require(!NetworkActorManager::Instance().FindGVGKey(7,9),"guild war end key not removed");
|
||||
send(5,pid(22));python.execute("assert guild.GetMemberCount()==1 and guild.GetGuildExperienceSummary()==800\nassert h.events==[('OnRemoveList',1,'Bob'),('RefreshTargetBoardByName','Bob'),('RefreshGuildMemberPage',)]\nh.events=[]\n");
|
||||
// Main actor updates synchronize net.GetGuildID and the account roster.
|
||||
net.SetMainActorVID(123);
|
||||
Bytes actorUpdate(sizeof(TPacketGCCharacterUpdate),0);actorUpdate[0]=HEADER_GC_CHARACTER_UPDATE;
|
||||
const auto put=[&](size_t offset,uint32_t value) {for(unsigned i=0;i<4;++i)actorUpdate[offset+i]=uint8_t(value>>(8*i));};
|
||||
put(offsetof(TPacketGCCharacterUpdate,dwVID),123);put(offsetof(TPacketGCCharacterUpdate,dwGuildID),7);
|
||||
net.PushRecvData(actorUpdate);net.ProcessRecvData();
|
||||
python.execute("assert net.GetGuildID()==7\nassert net.GetAccountCharacterSlotDataInteger(0,12)==7\nassert net.GetAccountCharacterSlotDataString(0,13)=='Seven'\n");
|
||||
send(5,pid(11));
|
||||
python.execute(R"PY(assert guild.IsGuildEnable()==0 and guild.GetGuildID()==0 and net.GetGuildID()==0
|
||||
assert net.GetAccountCharacterSlotDataInteger(0,12)==0 and net.GetAccountCharacterSlotDataString(0,13)==''
|
||||
assert guild.GetGuildBoardCommentCount()==1 and guild.GetGuildExperienceSummary()==800
|
||||
assert guild.GetSkillIndex(3)==7
|
||||
assert h.events==[('DeleteGuild',),('OnRemoveAllList',1),('RefreshTargetBoard',),('RefreshCharacter',),('RefreshMessenger',)]
|
||||
guild.Destroy()
|
||||
assert guild.GetSkillIndex(3)==0
|
||||
assert guild.GetGuildBoardCommentCount()==1 and guild.GetGuildExperienceSummary()==800
|
||||
h.events=[]
|
||||
)PY");
|
||||
// Original ADD/unknown subheaders do not consume their payload.
|
||||
send(4,{44});require(net.PopSendBytes()==Bytes{254},"unknown guild subheader handling changed");
|
||||
// Reject a truncated member record without reading into the next frame.
|
||||
auto bad=frame(2,{1});bad.push_back(44);net.PushRecvData(bad);net.ProcessRecvData();require(net.PopSendBytes().empty(),"bad guild list consumed next frame");
|
||||
python.execute("assert guild.GetMemberCount()==0 and h.events==[]\n");
|
||||
auto& g=GetGuildState();for(uint32_t i=1;i<=7;++i)g.StartWar(i);require(g.enemies[5]==6,"six enemy slot cap changed");g.EndWar(2);g.StartWar(8);require(g.enemies[1]==8 && g.enemies[2]==3,"enemy slot reuse compacted list");
|
||||
net.ResetConnection();
|
||||
}
|
||||
{PythonRuntime python(argv[1],argv[2]);python.execute("import guild\nassert guild.GetGuildBoardCommentCount()==0 and guild.GetGuildExperienceSummary()==0\nassert guild.GetMemberCount()==0\n");}
|
||||
std::cout<<"AVA2 guild state, wire and Python parity passed\n";
|
||||
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "python_runtime.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
using namespace ava2;
|
||||
using Bytes=std::vector<uint8_t>;
|
||||
void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);}
|
||||
void u32(Bytes& b,uint32_t v) {for(unsigned i=0;i<4;++i)b.push_back(uint8_t(v>>(8*i)));}
|
||||
void write(const std::filesystem::path& p,const Bytes& b) {std::filesystem::create_directories(p.parent_path());std::ofstream out(p,std::ios::binary);out.write(reinterpret_cast<const char*>(b.data()),b.size());}
|
||||
void textfile(const std::filesystem::path& p,const std::string& text) {write(p,Bytes(text.begin(),text.end()));}
|
||||
Bytes row(uint32_t id,const std::string& internal,const std::string& name,uint8_t type=1,uint8_t size=3) {
|
||||
Bytes b;u32(b,id);b.resize(172);std::copy(internal.begin(),internal.end(),b.begin()+4);std::copy(name.begin(),name.end(),b.begin()+29);b[54]=type;b[57]=size;b[131]=123;return b;
|
||||
}
|
||||
void proto(const std::filesystem::path& p,const std::vector<Bytes>& rows) {
|
||||
Bytes raw;for(const auto& r:rows)raw.insert(raw.end(),r.begin(),r.end());Bytes compressed;
|
||||
if(raw.size()<=238)compressed.push_back(uint8_t(17+raw.size()));
|
||||
else {compressed.push_back(0);size_t n=raw.size()-18;while(n>255){compressed.push_back(0);n-=255;}compressed.push_back(n);}
|
||||
compressed.insert(compressed.end(),raw.begin(),raw.end());compressed.insert(compressed.end(),{17,0,0});
|
||||
Bytes file{'M','I','P','X'};u32(file,1);u32(file,172);u32(file,rows.size());u32(file,20+compressed.size());
|
||||
file.insert(file.end(),{'M','C','O','Z'});u32(file,0);u32(file,compressed.size());u32(file,raw.size());file.insert(file.end(),{'M','C','O','Z'});file.insert(file.end(),compressed.begin(),compressed.end());write(p,file);
|
||||
}
|
||||
void tga(const std::filesystem::path& p) {Bytes b(18,0);b[2]=2;b[12]=64;b[14]=96;b[16]=24;b.resize(18+64*96*3,255);write(p,b);}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
auto root=std::filesystem::temp_directory_path()/std::filesystem::path("ava2-item-data-"+std::to_string(getpid()));std::filesystem::create_directories(root);
|
||||
try {
|
||||
{
|
||||
PythonRuntime python(argv[1],root);python.execute("import item\n");
|
||||
python.execute(R"PY(for f in (item.GetItemName,item.GetItemDescription,item.GetItemSummary,item.GetItemSize,item.GetItemType,item.GetItemSubType,item.GetIconImage,item.GetIconImageFileName):
|
||||
try: f()
|
||||
except RuntimeError: pass
|
||||
else: raise AssertionError('missing selected item must raise')
|
||||
item.SelectItem(19)
|
||||
assert item.SelectItemWiki(19)==0
|
||||
assert item.SelectItemWiki(27003)==0
|
||||
)PY");
|
||||
int type,sub;std::string name;require(!GetItemTypeAndSubType(19,&type,&sub)&&GetWeaponModelPathByVnum(19).empty(),"fabricated seeded weapon remains");
|
||||
textfile(root/"locale/en/item_names.txt","19\tFabricated Name\n");require(!GetItemNameAndType(19,&name,&type),"item_names lazy autoload remains");
|
||||
textfile(root/"list","500\tWEAPON\ticon/list.tga\tmodel/explicit.gr2\n600\tARMOR\ticon/missing.tga\n700\tUSE\ticon/list.tga\textra\tinvalid\n500\tIGNORED\ticon/list2.tga\n\t800\tunused\ticon/list.tga\t\n900\tunused\t\"icon/with space.tga\"\n");
|
||||
require(LoadItemList("list"),"item list fixture rejected");python.execute("item.SelectItem(500)\nassert item.GetItemName()=='' and item.GetItemType()==0 and item.GetItemSize()==(1,0), (item.GetItemName(),item.GetItemType(),item.GetItemSize())\nassert item.GetIconImageFileName()=='Noname'\nassert item.SelectItemWiki(700)==0 and item.SelectItemWiki(800)==1 and item.SelectItemWiki(900)==1\n");
|
||||
require(GetWeaponModelPathByVnum(500).empty(),"three-field list did not clear previous model");
|
||||
textfile(root/"desc","500\tignored name\t\"Description\"\t\"Summary\"\n600\tignored\t\"Unclosed\t\n777\tx\tShould not create\tx\n900\tignored\t\tSummary only\n");require(LoadItemDescriptions("desc"),"description fixture rejected");
|
||||
python.execute("item.SelectItem(500)\nassert item.GetItemDescription()=='Description' and item.GetItemSummary()=='Summary' and item.GetItemName()=='', (item.GetItemDescription(),item.GetItemSummary(),item.GetItemName())\nitem.SelectItem(600)\nassert item.GetItemDescription()=='Unclosed' and item.GetItemSummary()==''\nassert item.SelectItemWiki(777)==0\nitem.SelectItem(900)\nassert item.GetItemDescription()=='' and item.GetItemSummary()=='Summary only'\n");
|
||||
tga(root/"icon/list2.tga");tga(root/"icon/item/01002.tga");tga(root/"icon/item/02000.tga");tga(root/"icon/item/27995.tga");
|
||||
// Unsorted rows: same-name icon fallback follows original source order, not map order.
|
||||
proto(root/"proto",{row(1002,"Same","First"),row(1001,"Same","Second"),row(2009,"Different","Base"),row(3333,"Missing","Bowl"),row(500,"List","Listed",2,2)});
|
||||
require(LoadItemTable("proto"),"prototype fixture rejected");
|
||||
python.execute("item.SelectItem(1001)\nassert item.GetItemName()=='Second' and item.GetIconImageFileName()=='icon/item/01002.tga', (item.GetItemName(),item.GetIconImageFileName())\nitem.SelectItem(2009)\nassert item.GetIconImageFileName()=='icon/item/02000.tga'\nitem.SelectItem(3333)\nassert item.GetIconImageFileName()=='icon/item/27995.tga'\nitem.SelectItem(500)\nassert item.GetItemType()==2 and item.GetItemSize()==(1,2) and item.GetIconImageFileName()=='icon/list2.tga'\nassert item.GetItemDescription()=='Description' and item.GetItemSummary()=='Summary'\nassert item.GetSocket(0)==123\nitem.GetIconImage()\nassert item.GetItemSize()==(1,2)\nitem.SelectItem(999999)\nassert item.GetItemName()=='Listed'\n");
|
||||
require(!LoadItemList("absent")&&!LoadItemDescriptions("absent")&&!LoadItemTable("absent"),"missing loader must fail");textfile(root/"bad","invalid proto");require(!LoadItemTable("bad"),"bad proto accepted");python.execute("assert item.GetItemName()=='Listed' and item.LoadItemTable('bad') is None\n");
|
||||
textfile(root/"list","500\tignored\ticon/list2.tga\tmodel/new.gr2\n");require(LoadItemList("list"),"reload list failed");require(GetWeaponModelPathByVnum(500)=="model/new.gr2","explicit model path ignored");python.execute("assert item.GetItemType()==2 and item.GetItemName()=='Listed' and item.GetSocket(0)==0 and item.GetItemDescription()==''\n");
|
||||
ResetItemDatabase();require(!GetItemTypeAndSubType(500,&type,&sub),"database reset retained records");python.execute("assert item.SelectItemWiki(500)==0\n");
|
||||
}
|
||||
std::filesystem::remove_all(root);std::cout<<"AVA2 item resource loading and selected data parity passed\n";
|
||||
}catch(const std::exception& e){std::filesystem::remove_all(root);std::cerr<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#include "item_sound.h"
|
||||
#include "python_runtime.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include "eter_net/PythonSafeBox.h"
|
||||
#include "eter_net/PythonExchange.h"
|
||||
#include "eter_sound/SoundManager.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
using namespace ava2;
|
||||
using Bytes=std::vector<uint8_t>;
|
||||
void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);}
|
||||
void u32(Bytes& b,uint32_t v) {for(unsigned i=0;i<4;++i)b.push_back(uint8_t(v>>(8*i)));}
|
||||
void wav(const std::filesystem::path& path) {
|
||||
Bytes b{'R','I','F','F'};u32(b,38);b.insert(b.end(),{'W','A','V','E','f','m','t',' '});u32(b,16);
|
||||
b.insert(b.end(),{1,0,1,0});u32(b,8000);u32(b,16000);b.insert(b.end(),{2,0,16,0,'d','a','t','a'});u32(b,2);b.insert(b.end(),{0,0});
|
||||
std::ofstream out(path,std::ios::binary);out.write(reinterpret_cast<const char*>(b.data()),b.size());
|
||||
}
|
||||
void proto(const std::filesystem::path& path,uint32_t id,uint8_t type,uint8_t sub) {
|
||||
// Independent172-byte AVA2 r152 record and literal LZO stream, no source assets.
|
||||
Bytes raw;u32(raw,id);raw.resize(172);raw[4]='F';raw[29]='F';raw[54]=type;raw[55]=sub;raw[57]=1;
|
||||
Bytes compressed{189};compressed.insert(compressed.end(),raw.begin(),raw.end());compressed.insert(compressed.end(),{17,0,0});
|
||||
Bytes payload{'M','C','O','Z'};payload.insert(payload.end(),compressed.begin(),compressed.end());
|
||||
Bytes file{'M','I','P','X'};u32(file,1);u32(file,172);u32(file,1);u32(file,uint32_t(16+payload.size()));
|
||||
file.insert(file.end(),{'M','C','O','Z'});u32(file,0);u32(file,uint32_t(compressed.size()));u32(file,172);file.insert(file.end(),payload.begin(),payload.end());
|
||||
std::ofstream out(path,std::ios::binary);out.write(reinterpret_cast<const char*>(file.data()),file.size());
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
auto root=std::filesystem::temp_directory_path()/std::filesystem::path("ava2-item-sound-"+std::to_string(getpid()));std::filesystem::create_directories(root);
|
||||
try {
|
||||
{
|
||||
PythonRuntime python(argv[1],root);
|
||||
python.execute("import item\nfor i in range(8): item.SetUseSoundFileName(i,'use'+str(i))\nfor i in range(5): item.SetDropSoundFileName(i,'drop'+str(i))\nitem.SetUseSoundFileName(-1,'bad')\nitem.SetDropSoundFileName(5,'bad')\nitem.SetUseSoundFileName(8,'bad')\n");
|
||||
uint32_t id=500000;
|
||||
for(auto [type,sub,use,drop]:{
|
||||
std::tuple{1,0,3,2},std::tuple{1,1,3,2},std::tuple{1,2,4,3},std::tuple{1,3,3,2},std::tuple{1,4,3,2},std::tuple{1,5,3,2},std::tuple{1,6,1,0},std::tuple{1,7,3,2},std::tuple{1,8,3,2},std::tuple{1,9,1,0},
|
||||
std::tuple{2,0,2,1},std::tuple{2,1,1,0},std::tuple{2,2,1,0},std::tuple{2,3,1,0},std::tuple{2,4,1,0},std::tuple{2,5,5,4},std::tuple{2,6,5,4},std::tuple{2,7,1,0},
|
||||
std::tuple{3,0,-1,0},std::tuple{3,1,7,0},std::tuple{3,7,6,0},std::tuple{3,11,1,0},std::tuple{28,0,1,0},std::tuple{16,0,1,0}}) {
|
||||
proto(root/"proto",id,type,sub);python.execute("item.LoadItemTable('proto')\nitem.SelectItem("+std::to_string(id)+")\n");
|
||||
python.execute("before=(item.GetItemType(),item.GetItemSubType())\n");auto selected=GetItemUseSound(id);
|
||||
require(use<0?!selected:selected=="use"+std::to_string(use),"original use classification mismatch");
|
||||
require(GetItemDropSound(id)=="drop"+std::to_string(drop),"original drop classification mismatch");
|
||||
GetItemUseSound(500000);python.execute("assert (item.GetItemType(),item.GetItemSubType())==before\n");++id;
|
||||
}
|
||||
require(!GetItemUseSound(0xffffffff)&&!GetItemDropSound(0xffffffff),"missing item must stay silent");
|
||||
require(GetPotionSound()=="use6","potion uses sound enum rather than item USE_POTION subtype");
|
||||
python.execute("item.SetUseSoundFileName(6,'')\nitem.SetDropSoundFileName(0,'')\n");require(GetPotionSound().empty()&&GetItemDropSound(500006)=="","empty sound filenames retained");
|
||||
auto& sound=SoundManager::Instance();sound.Destroy();sound.SetSoundVolume(1);
|
||||
auto& net=PythonNetworkStream::Instance();net.ResetConnection();
|
||||
TItemData data{};data.vnum=500002;SetPlayerItemData(1,0,data);
|
||||
auto& box=CPythonSafeBox::Instance();box.OpenSafeBox(1);box.OpenMall(1);box.SetItemData(0,data);box.SetMallItemData(0,data);
|
||||
for(unsigned op=0;op<4;++op) {
|
||||
auto path=root/("drop"+std::to_string(op)+".wav");wav(path);
|
||||
python.execute("item.SetDropSoundFileName(item.DROPSOUND_BOW,'"+path.string()+"')\n");
|
||||
if(op==0)net.SendSafeBoxCheckinPacket(1,0,0);
|
||||
if(op==1)net.SendSafeBoxCheckoutPacket(0,1,0);
|
||||
if(op==2)net.SendSafeBoxItemMovePacket(0,1,2);
|
||||
if(op==3)net.SendMallCheckoutPacket(0,1,0);
|
||||
require(sound.GetCachedSoundCount()==op+1,"storage sound did not reach playback manager");
|
||||
require(net.PopSendPackets().size()==1,"storage sound changed wire sending");
|
||||
}
|
||||
net.SendSafeBoxCheckoutPacket(255,1,0);net.SendMallCheckoutPacket(255,1,0);require(sound.GetCachedSoundCount()==4,"invalid storage slot played audio");net.ClearSendQueue();
|
||||
auto path=root/"potion.wav";wav(path);python.execute("item.SetUseSoundFileName(item.USESOUND_POTION,'"+path.string()+"')\n");
|
||||
PlayItemUseSound(500018);require(sound.GetCachedSoundCount()==4,"potion played locally before server effect");
|
||||
PlayUsePotionSound();require(sound.GetCachedSoundCount()==5,"potion playback missing");
|
||||
python.execute("for method in (item.SetUseSoundFileName,item.SetDropSoundFileName):\n try: method('bad','x')\n except TypeError: pass\n else: raise AssertionError('expected original bad argument error')\n");
|
||||
// Inventory requests: sound follows the original action/equipment guards.
|
||||
SNetworkActorData actor{};actor.m_dwVID=77;actor.m_dwRace=999999;NetworkActorManager::Instance().AppendActor(actor);net.SetMainActorVID(77);
|
||||
SetPlayerItemData(1,180,data);SetPlayerItemData(1,215,data);SetPlayerItemData(1,216,data);
|
||||
require(IsPlayerEquipmentItem(1,180)&&IsPlayerEquipmentItem(1,215)&&!IsPlayerEquipmentItem(1,216)&&!IsPlayerEquipmentItem(6,180),"original equipment cell bounds");
|
||||
python.execute("import net,shop\nclass Game:\n def __init__(self): self.events=[]\n def BINARY_AppendNotifyMessage(self,message): self.events.append(message)\ngame=Game()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)\nshop.Close()\n");
|
||||
auto inventoryPath=root/"inventory.wav";wav(inventoryPath);SetItemUseSound(USESOUND_BOW,inventoryPath.string());SetItemDropSound(DROPSOUND_BOW,inventoryPath.string());
|
||||
auto& trade=CPythonExchange::Instance();trade.Start();
|
||||
net.SendItemUsePacket(1,180);net.SendItemMovePacket(1,180,1,0,1);
|
||||
require(net.PopSendPackets().empty()&&sound.GetCachedSoundCount()==5,"trading equip action must reject before sound/send");
|
||||
python.execute("assert game.events==['CANNOT_EQUIP_EXCHANGE']*2\ngame.events=[]\nshop.Open()\n");
|
||||
trade.End();net.SendItemUsePacket(1,180);net.SendItemMovePacket(1,180,1,0,1);
|
||||
require(net.PopSendPackets().empty()&&sound.GetCachedSoundCount()==5,"shopping equip action must reject before sound/send");
|
||||
python.execute("assert game.events==['CANNOT_EQUIP_SHOP']*2\ngame.events=[]\n");
|
||||
// Source is an inventory cell: Windows does not apply the equip restriction to destination-only moves.
|
||||
net.SendItemMovePacket(1,0,1,180,1);require(net.PopSendPackets().size()==1&&sound.GetCachedSoundCount()==6,"inventory-to-equipment move source guard mismatch");
|
||||
python.execute("assert game.events==[]\nshop.Close()\n");
|
||||
net.SendItemUsePacket(1,180);net.SendItemMovePacket(1,180,1,0,1);require(net.PopSendPackets().size()==2,"allowed equipment requests missing");
|
||||
auto blockedPath=root/"blocked.wav";wav(blockedPath);SetItemUseSound(USESOUND_BOW,blockedPath.string());SetItemDropSound(DROPSOUND_BOW,blockedPath.string());
|
||||
NetworkActorManager::Instance().GetActorInstance(77)->Stun();net.SendItemUsePacket(1,0);net.SendItemMovePacket(1,0,1,1,1);
|
||||
require(net.PopSendPackets().empty()&&sound.GetCachedSoundCount()==6,"unable-to-act request must stay silent");
|
||||
sound.Destroy();net.ResetConnection();
|
||||
}
|
||||
std::filesystem::remove_all(root);std::cout<<"AVA2 item sound selection and storage playback parity passed\n";
|
||||
}catch(const std::exception& e){std::filesystem::remove_all(root);std::cerr<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "python_runtime.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
using Bytes=std::vector<uint8_t>;
|
||||
void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);}
|
||||
void put(Bytes& b,uint64_t v,unsigned width=4) {for(unsigned i=0;i<width;++i)b.push_back(uint8_t(v>>(8*i)));}
|
||||
void text(Bytes& b,const std::string& s,size_t width) {for(size_t i=0;i<width;++i)b.push_back(i<s.size()?s[i]:0);}
|
||||
Bytes frame(uint8_t sub,const Bytes& data) {Bytes b{93};put(b,6+data.size());b.push_back(sub);b.insert(b.end(),data.begin(),data.end());return b;}
|
||||
void send(uint8_t sub,const Bytes& data) {auto& s=PythonNetworkStream::Instance();s.PushRecvData(frame(sub,data));s.ProcessRecvData();}
|
||||
Bytes item() {
|
||||
Bytes b;put(b,0xffffffff);put(b,0x80000001);put(b,uint64_t(-900000000000LL),8);put(b,uint32_t(-4));b.push_back(255);
|
||||
put(b,uint32_t(-5));put(b,123);put(b,900000000000ULL,8);put(b,222);put(b,333);put(b,uint32_t(-8));return b;
|
||||
}
|
||||
Bytes log(const std::string& name="Hero") {
|
||||
Bytes b;put(b,100);text(b,name,25);text(b,"2026-10-06",21);put(b,uint32_t(-10));text(b,"127.0.0.1",16);
|
||||
put(b,300);put(b,0xffffffff);put(b,uint32_t(-2));put(b,uint64_t(-700000000000LL),8);return b;
|
||||
}
|
||||
Bytes load(int categories) {Bytes b;put(b,900000000000ULL,8);put(b,uint32_t(-10));put(b,uint32_t(categories));return b;}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
PythonRuntime python(argv[1],argv[2]);auto& s=PythonNetworkStream::Instance();s.ResetConnection();s.SetPhase(PHASE_GAME);
|
||||
python.execute(R"PY(import net
|
||||
class Game:
|
||||
def __init__(self): self.events=[]
|
||||
def __getattr__(self,name):
|
||||
def event(*args): self.events.append((name,)+args)
|
||||
return event
|
||||
game=Game()
|
||||
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)
|
||||
item=(-1,-2147483647,-900000000000,255,-5,-4,123,900000000000,-8)
|
||||
log=('2026-10-06',-10,'Hero','127.0.0.1',-1,-2,-700000000000)
|
||||
)PY");
|
||||
require(item().size()==49 && log().size()==90,"itemshop independent fixture sizes");
|
||||
auto wire=frame(6,item());wire.push_back(44);s.PushRecvData(wire.data(),wire.size()-2);s.ProcessRecvData();python.execute("assert game.events==[]\n");s.PushRecvData(wire.data()+wire.size()-2,2);s.ProcessRecvData();require(s.PopSendBytes()==Bytes{254},"itemshop lost coalesced ping");
|
||||
python.execute("assert game.events==[('ItemShopUpdateItem',)+item]\ngame.events=[]\n");
|
||||
Bytes coin;put(coin,uint64_t(-100000000000LL),8);coin.push_back(0);send(3,coin);python.execute("assert game.events==[('ItemShopSetDragonCoin',-100000000000)]\ngame.events=[]\n");coin.back()=2;auto row=log();coin.insert(coin.end(),row.begin(),row.end());send(3,coin);
|
||||
python.execute("assert game.events==[('ItemShopAppendLog',)+log,('ItemShopSetDragonCoin',-100000000000)]\ngame.events=[]\n");
|
||||
Bytes logs;put(logs,2);logs.insert(logs.end(),row.begin(),row.end());logs.insert(logs.end(),row.begin(),row.end());send(1,logs);
|
||||
python.execute("assert game.events==[('ItemShopHideLoading',),('ItemShopLogClear',),('ItemShopAppendLog',)+log,('ItemShopAppendLog',)+log,('ItemShopPurchasesWindow',)]\ngame.events=[]\n");logs.clear();put(logs,0);send(1,logs);
|
||||
python.execute("assert game.events==[('ItemShopHideLoading',),('ItemShopLogClear',),('ItemShopPurchasesWindow',)]\ngame.events=[]\n");
|
||||
auto data=load(2);data.insert(data.end(),{3,2,4,2});auto it=item();data.insert(data.end(),it.begin(),it.end());data.insert(data.end(),it.begin(),it.end());data.insert(data.end(),{5,0,8,0});send(0,data);
|
||||
python.execute("assert game.events==[('ItemShopSetDragonCoin',900000000000),('ItemShopHideLoading',),('ItemShopClear',-10),('ItemShopAppendItem',3,4)+item,('ItemShopAppendItem',3,4)+item,('ItemShopOpenMainPage',),('ItemShopOpenMainPage',)]\ngame.events=[]\n");
|
||||
send(0,load(9999));python.execute("assert game.events==[('ItemShopSetDragonCoin',900000000000),('ItemShopHideLoading',),('ItemShopClear',-10),('ItemShopOpenMainPage',)]\ngame.events=[]\n");send(0,load(0));
|
||||
python.execute("assert game.events==[('ItemShopSetDragonCoin',900000000000),('ItemShopHideLoading',),('ItemShopClear',-10)]\ngame.events=[]\n");
|
||||
row=log(std::string(25,'x'));std::fill(row.begin()+29,row.begin()+50,'y');std::fill(row.begin()+54,row.begin()+70,'z');logs.clear();put(logs,1);logs.insert(logs.end(),row.begin(),row.end());send(1,logs);
|
||||
python.execute("assert game.events[2]==('ItemShopAppendLog','y'*21,-10,'x'*25,'z'*16,-1,-2,-700000000000)\ngame.events=[]\n");
|
||||
for(uint8_t sub:{2,4,5,255}) {send(sub,{44});require(s.PopSendBytes()==Bytes{254},"unhandled itemshop subheader consumed payload");}
|
||||
python.execute("assert game.events==[]\n");
|
||||
// Invalid arrays and fields cannot read into a following packet or allocate unbounded memory.
|
||||
logs.clear();put(logs,0xffffffff);send(1,logs);python.execute("assert game.events==[('ItemShopHideLoading',),('ItemShopLogClear',)]\ngame.events=[]\n");
|
||||
logs.clear();put(logs,1);auto bad=frame(1,logs);bad.push_back(44);s.PushRecvData(bad);s.ProcessRecvData();require(s.PopSendBytes().empty(),"short logs consumed next frame");python.execute("assert game.events==[('ItemShopHideLoading',),('ItemShopLogClear',)]\ngame.events=[]\n");
|
||||
bad=frame(6,{1});bad.push_back(44);s.PushRecvData(bad);s.ProcessRecvData();require(s.PopSendBytes().empty(),"short update consumed next frame");python.execute("assert game.events==[]\n");
|
||||
coin.clear();put(coin,1,8);coin.push_back(1);send(3,coin);python.execute("assert game.events==[]\n");
|
||||
send(0,load(-1));python.execute("assert game.events==[('ItemShopSetDragonCoin',900000000000),('ItemShopHideLoading',),('ItemShopClear',-10)]\ngame.events=[]\ndef broken(*args): raise ValueError('expected callback failure')\ngame.ItemShopAppendLog=broken\n");
|
||||
coin=Bytes{};put(coin,7,8);coin.push_back(1);row=log();coin.insert(coin.end(),row.begin(),row.end());send(3,coin);python.execute("assert game.events==[('ItemShopSetDragonCoin',7)]\n");
|
||||
require(s.GetUnportedPackets().empty(),"itemshop still routed through skip handler");s.ResetConnection();
|
||||
std::cout<<"AVA2 itemshop wire and Python callback parity passed\n";
|
||||
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
@@ -46,5 +46,12 @@ int main() {
|
||||
try { valid.select(1);return 7; } catch(const std::invalid_argument&) {}
|
||||
valid.select(0);auto sent=valid.take_output();
|
||||
if(sent.size()!=1 || ava2::wire::decrypt(sent[0],client_key)!=ava2::wire::Bytes{6,0,0xca,0,0,0,0,0}) return 6;
|
||||
// 128 KB game receive buffer (networkmodule.py SetTCPRecvBufferSize): partial takes keep the rest queued.
|
||||
auto rx=ava2::wire::derive_receive_key(client_key);
|
||||
ava2::wire::Bytes loading{253,4};for(int i=0;i<14;++i) loading.push_back(std::uint8_t(i));
|
||||
valid.feed(ava2::wire::encrypt(loading,rx));
|
||||
if(valid.state()!=ava2::LoginSession::State::Loading || valid.receive_space()!=ava2::LoginSession::kRecvBufferSize-14) return 8;
|
||||
if(valid.take_game_input(0).size()!=0 || valid.take_game_input(5)!=ava2::wire::Bytes{0,1,2,3,4}) return 9;
|
||||
if(valid.take_game_input()!=ava2::wire::Bytes{5,6,7,8,9,10,11,12,13} || valid.receive_space()!=ava2::LoginSession::kRecvBufferSize) return 10;
|
||||
std::cout<<"Original AVA2 client/server layout, cipher and character selection oracle passed\n";
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include "test_rundir.h"
|
||||
|
||||
using namespace ava2;
|
||||
|
||||
@@ -49,7 +50,7 @@ void TestGuildMarkImageAtlas() {
|
||||
// Load authentic 10_0.tga
|
||||
bool loaded = atlas.LoadTGA("mark/10_0.tga");
|
||||
if (!loaded) loaded = atlas.LoadTGA("build/dev/mark/10_0.tga");
|
||||
if (!loaded) loaded = atlas.LoadTGA("/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/mark/10_0.tga");
|
||||
if (!loaded) loaded = atlas.LoadTGA(ava2_test::PackMaker() + "/../mark/10_0.tga");
|
||||
assert(loaded && "Failed to load authentic 10_0.tga mark atlas");
|
||||
|
||||
// Check non-zero pixel in atlas
|
||||
@@ -161,6 +162,7 @@ void TestGuildMarkManager() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (!ava2_test::EnterTestRunDir()) return ava2_test::kSkip;
|
||||
std::cout << "=== Running Guild Mark & MarkManager Engine Tests ===" << std::endl;
|
||||
TestGuildMarkPrimitives();
|
||||
TestGuildMarkBlockCRC();
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "messenger_state.h"
|
||||
#include "python_runtime.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
||||
std::vector<uint8_t> frame(uint8_t sub,const std::vector<uint8_t>& data) {
|
||||
const auto size=uint16_t(4+data.size());
|
||||
std::vector<uint8_t> result{74,uint8_t(size),uint8_t(size>>8),sub};
|
||||
result.insert(result.end(),data.begin(),data.end());return result;
|
||||
}
|
||||
void send(uint8_t sub,const std::vector<uint8_t>& data) {
|
||||
auto& stream=PythonNetworkStream::Instance();stream.PushRecvData(frame(sub,data));stream.ProcessRecvData();
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
{
|
||||
PythonRuntime python(argv[1],argv[2]);
|
||||
auto& stream=PythonNetworkStream::Instance();stream.ResetConnection();stream.SetPhase(PHASE_GAME);
|
||||
python.execute("import messenger,net,weakref,gc\nassert messenger.IsFriendByName('Alice')==0\nassert messenger.IsFriendByName() is None\nassert messenger.RemoveFriend(1) is None\nassert messenger.SetMessengerHandler() is None\nclass Handler:\n def __init__(self):\n self.events=[]\n def OnLogin(self,group,name):\n if group==0: assert messenger.IsFriendByName(name)==1\n self.events.append(('login',group,name))\n def OnLogout(self,group,name):\n if group==0: assert messenger.IsFriendByName(name)==1\n self.events.append(('logout',group,name))\n def OnMobile(self,group,name,state):\n assert messenger.IsFriendByName(name)==1\n self.events.append(('mobile',group,name,state))\n def RefreshTargetBoardByName(self,name):\n self.events.append(('target',name))\n def OnRemoveList(self,group,name):\n self.events.append(('remove',group,name))\n def OnRemoveAllList(self,group):\n self.events.append(('removeall',group))\nh=Handler()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,h)\nmessenger.SetMessengerHandler(h)\n");
|
||||
// connected bit0 is online, bit1 mobile; online/mobile list callback order.
|
||||
auto list=frame(0,{3,5,'A','l','i','c','e',0,3,'B','o','b',2,3,'E','v','e'});
|
||||
list.push_back(44);stream.PushRecvData(list.data(),list.size()-2);stream.ProcessRecvData();
|
||||
python.execute("assert h.events==[]\nassert messenger.IsFriendByName('Alice')==0\n");
|
||||
stream.PushRecvData(list.data()+list.size()-2,2);stream.ProcessRecvData();
|
||||
require(stream.PopSendBytes()==std::vector<uint8_t>{254},"messenger list lost following ping");
|
||||
python.execute("assert h.events==[('login',0,'Alice'),('mobile',0,'Alice',1),('logout',0,'Bob'),('logout',0,'Eve'),('mobile',0,'Eve',1)]\nassert messenger.IsFriendByName('Bob')==1\nassert messenger.IsFriendByName('alice')==0\nh.events=[]\n");
|
||||
send(1,{5,'C','a','r','o','l'});send(2,{5,'A','l','i','c','e'});send(4,{255,3,'B','o','b'});
|
||||
python.execute("assert h.events==[('login',0,'Carol'),('target','Carol'),('logout',0,'Alice'),('mobile',0,'Bob',255)]\nassert messenger.IsFriendByName('Alice')==1\nmessenger.RemoveFriend('Alice','ignored')\nassert messenger.IsFriendByName('Alice')==0\nh.events=[]\n");
|
||||
auto& state=GetMessengerState();state.AppendGuildMember("Zulu");state.AppendGuildMember("Zulu");state.LoginGuildMember("Alpha");
|
||||
python.execute("assert h.events==[('logout',1,'Zulu'),('login',1,'Alpha')]\nh.events=[]\nmessenger.RefreshGuildMember()\nassert h.events==[('login',1,'Alpha'),('logout',1,'Zulu')]\nh.events=[]\n");
|
||||
state.RemoveGuildMember("Missing");state.RemoveGuildMember("Alpha");state.RemoveAllGuildMember();
|
||||
python.execute("assert h.events==[('remove',1,'Missing'),('remove',1,'Alpha'),('removeall',1)]\nh.events=[]\nmessenger.Destroy()\nassert messenger.IsFriendByName('Bob')==0\nmessenger.RefreshGuildMember()\nassert h.events==[]\n");
|
||||
send(2,{3,'B','o','b'});
|
||||
python.execute("assert h.events==[('logout',0,'Bob')]\n");
|
||||
// The original ignores INVITE; its unconsumed byte still reaches the dispatcher.
|
||||
send(3,{44});require(stream.PopSendBytes()==std::vector<uint8_t>{254},"invite payload handling changed");
|
||||
// Malformed lengths cannot consume bytes from a coalesced next packet.
|
||||
auto bad=frame(1,{24,'x'});bad.push_back(44);stream.PushRecvData(bad);stream.ProcessRecvData();
|
||||
require(stream.PopSendBytes().empty(),"malformed messenger name consumed next frame");
|
||||
python.execute("assert h.events==[('logout',0,'Bob')]\n");
|
||||
send(1,{25});send(0,{1});
|
||||
python.execute("assert h.events==[('logout',0,'Bob')]\nclass Broken:\n def OnLogin(self,*args):\n raise ValueError('expected callback failure')\nmessenger.SetMessengerHandler(Broken())\n");
|
||||
send(1,{1,'X'});python.execute("assert messenger.IsFriendByName('X')==1\n");
|
||||
python.execute("transient=Handler()\nref=weakref.ref(transient)\nmessenger.SetMessengerHandler(transient)\ndel transient\ngc.collect()\nassert ref() is not None\nmessenger.Destroy()\nassert ref() is not None\nmessenger.SetMessengerHandler(None)\ngc.collect()\nassert ref() is None\n");
|
||||
stream.ResetConnection();
|
||||
}
|
||||
{ PythonRuntime python(argv[1],argv[2]);python.execute("import messenger\nassert messenger.IsFriendByName('X')==0\nmessenger.RefreshGuildMember()\n"); }
|
||||
std::cout<<"AVA2 messenger state, wire and Python parity passed\n";
|
||||
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
// CPythonMiniMap / miniMap against the original AVA2 PythonMiniMap.cpp + PythonMiniMapModule.cpp:
|
||||
// LoadAtlas from setting.txt + atlas.sub, the <map>_point.txt marks (case-sensitive types, start/end
|
||||
// blocks), Update's mark classification and radius, observers, targets, GetInfo/GetAtlasInfo tuples,
|
||||
// guild areas, way/signal points, the atlas window callbacks and the module surface.
|
||||
#include "python_minimap.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "python_runtime.h"
|
||||
#include "guild_state.h"
|
||||
#include "eter_net/NetworkActorManager.h"
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace ava2;
|
||||
namespace fs = std::filesystem;
|
||||
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
||||
void spit(const fs::path& p,const std::string& s) { fs::create_directories(p.parent_path());std::ofstream f(p,std::ios::binary);f<<s; }
|
||||
std::string tga(unsigned w,unsigned h) {
|
||||
std::string t(18,'\0');t[2]=2;t[12]=char(w&0xff);t[13]=char(w>>8);t[14]=char(h&0xff);t[15]=char(h>>8);t[16]=32;t[17]=8;
|
||||
return t+std::string(size_t(w)*h*4,'\x7f');
|
||||
}
|
||||
bool near(float a,float b) { return std::fabs(a-b)<1e-3f; }
|
||||
uint32_t g_now=1000;
|
||||
uint32_t now() { return g_now; }
|
||||
SNetworkActorData actor(uint32_t vid,uint8_t type,uint32_t race,long x,long y,const char* name) {
|
||||
SNetworkActorData a{};a.m_dwVID=vid;a.m_bType=type;a.m_dwRace=race;a.m_lCurX=x;a.m_lCurY=y;a.m_stName=name;return a;
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
const fs::path root=fs::temp_directory_path()/"ava2_minimap_test";
|
||||
fs::remove_all(root);fs::create_directories(root);
|
||||
fs::current_path(root);
|
||||
spit(root/"locale/en/atlasinfo.txt","testmap 409600 204800 2 3\n");
|
||||
spit(root/"map/testmap/setting.txt","ScriptType MapSetting\nMapSize 2 3\nBasePosition 409600 204800\n");
|
||||
spit(root/"map/testmap/001002/height.raw",std::string(2*131*131,'\0'));
|
||||
spit(root/"testmap/atlas.tga",tga(256,384));
|
||||
spit(root/"testmap/atlas.sub","title subImage\nversion 2.0\nimage atlas.tga\nleft 0\ntop 0\nright 256\nbottom 384\n");
|
||||
spit(root/"ymir work/ui/minimap/whitemark_new.tga",tga(8,8));
|
||||
spit(root/"ymir work/ui/minimap/boss_mark_new.tga",tga(12,12));
|
||||
spit(root/"locale/en/map/testmap_point.txt",
|
||||
"0 NPC 2560 5120 Guard\n1\tWARP\t25600\t51200\t\"Gate A\"\n2 MONSTER 1 1 Mob\n3 npc 1 1 lower\n4 NPC 1\n"
|
||||
"start 5\nWARP 100 200 Blk\nend\n");
|
||||
|
||||
PythonRuntime python(argv[1],root);
|
||||
auto& mm=CPythonMiniMap::Instance();
|
||||
mm.SetTimeSourceForTest(now);
|
||||
|
||||
// Module surface: the 27 Windows functions, no RegisterColor; no map yet.
|
||||
python.execute(
|
||||
"import miniMap as m\n"
|
||||
"names=('SetScale','ScaleUp','ScaleDown','SetMiniMapSize','SetCenterPosition','Destroy','Create','Update','Render',"
|
||||
"'Show','Hide','isShow','GetInfo','LoadAtlas','UpdateAtlas','RenderAtlas','ShowAtlas','HideAtlas','isShowAtlas','IsAtlas',"
|
||||
"'GetAtlasInfo','GetAtlasSize','AddWayPoint','RemoveWayPoint','RegisterAtlasWindow','UnregisterAtlasWindow','GetGuildAreaID')\n"
|
||||
"assert sorted(n for n in dir(m) if not n.startswith('_') and not n.startswith('TYPE_'))==sorted(names)\n"
|
||||
"assert (m.TYPE_OPC,m.TYPE_NPC,m.TYPE_WARP,m.TYPE_WAYPOINT,m.TYPE_PARTY,m.TYPE_EMPIRE)==(0,3,5,6,7,8)\n"
|
||||
"assert m.GetAtlasSize()==(0,0,0) and m.IsAtlas()==0 and m.isShow()==0 and m.isShowAtlas()==0\n"
|
||||
"assert m.LoadAtlas() is None and m.IsAtlas()==0\n"
|
||||
"assert m.SetScale('x') is None\n"
|
||||
"m.Create()\n");
|
||||
|
||||
// Main actor + the classification set around (40000,60000).
|
||||
auto& actors=NetworkActorManager::Instance();
|
||||
actors.Clear();
|
||||
actors.AppendActor(actor(1,6,0,40000,60000,"Hero"));actors.SetMainActorVID(1);
|
||||
actors.AppendActor(actor(2,6,0,42000,60000,"Other"));
|
||||
actors.AppendActor(actor(3,6,0,40000,59000,"Mate"));
|
||||
auto ghost=actor(4,6,0,40500,60500,"Ghost");ghost.m_affectFlags[0]=1u<<NetworkActorManager::AFFECT_INVISIBILITY;actors.AppendActor(ghost);
|
||||
actors.AppendActor(actor(5,2,8001,39000,60000,"Stone"));
|
||||
actors.AppendActor(actor(6,1,30005,41000,61000,"Shop"));
|
||||
actors.AppendActor(actor(7,1,20000,39500,61000,"Npc"));
|
||||
actors.AppendActor(actor(8,0,101,40000,63000,"Wolf"));
|
||||
actors.AppendActor(actor(9,0,691,38000,58000,"Boss"));
|
||||
actors.AppendActor(actor(10,1,691,41000,59000,"BossNpc"));
|
||||
actors.AppendActor(actor(11,3,0,39000,59000,"Warp"));
|
||||
actors.AppendActor(actor(12,0,101,47000,60000,"Far"));
|
||||
actors.AppendActor(actor(13,0,101,45000,65000,"Corner"));
|
||||
NetworkActorManager::SetPartyMemberQuery([](uint32_t vid){return vid==3;});
|
||||
|
||||
require(WarpBackgroundMap(409600+40000,204800+60000),"warp");
|
||||
auto v=mm.GetTestView();
|
||||
require(v.atlasBaseX==409600 && v.atlasBaseY==204800 && v.atlasMaxX==51200.0f && v.atlasMaxY==76800.0f,"setting.txt base/size");
|
||||
// 0 NPC, 1 WARP kept; MONSTER dropped, "npc" and the lower-cased "warp" of the start block do not match, short row skipped.
|
||||
require(v.npcMarks==1 && v.warpMarks==1 && v.bossMarks==0,"point.txt marks");
|
||||
|
||||
mm.Update(40000,60000);
|
||||
v=mm.GetTestView();
|
||||
require(v.scale==2.0f && v.radius==64.0f && near(v.centerCellX,72.0f) && near(v.centerCellY,44.0f),"center/radius");
|
||||
require(v.otherPC->size()==1 && v.partyPC->size()==1 && v.metin->size()==1 && v.offlineShop->size()==1,"pc/stone/shop");
|
||||
require(v.npc->size()==2 && v.monster->size()==1 && v.boss->size()==1 && v.warp->size()==1,"npc/monster/boss/warp");
|
||||
require(near((*v.otherPC)[0].m_fX,80.0f) && near((*v.otherPC)[0].m_fY,60.0f),"other pc mark");
|
||||
require((*v.partyPC)[0].m_eNameColor==NetworkActorManager::NAMECOLOR_PARTY && near((*v.partyPC)[0].m_fY,50.0f),"party mark");
|
||||
|
||||
// Observer: 1 s lerp towards the destination.
|
||||
mm.AddObserver(50,40000,61000);
|
||||
mm.MoveObserver(50,41000,61000);
|
||||
g_now+=500;
|
||||
mm.Update(40000,60000);
|
||||
v=mm.GetTestView();
|
||||
require(v.observers==1 && v.partyPC->size()==2 && near((*v.partyPC)[1].m_fX,65.0f) && near((*v.partyPC)[1].m_fY,70.0f),"observer lerp");
|
||||
mm.RemoveObserver(50);
|
||||
|
||||
// Targets: a location target clamps to the 55px window (+2), a VID target follows its actor.
|
||||
mm.CreateTarget(900,"T");
|
||||
mm.UpdateTarget(900,409600+50000,204800+60000);
|
||||
mm.UpdateTarget(900,409600-1,204800+60000); // below base: ignored
|
||||
mm.UpdateTarget(900,-5,204800+60000); // unsigned: above base+max, ignored
|
||||
mm.CreateTarget(901,"V",8);
|
||||
mm.UpdateTarget(901,409600,204800); // actor exists: ignored
|
||||
mm.Update(40000,60000);
|
||||
float tx=0,ty=0;
|
||||
require(mm.GetTargetMiniMapPosition(900,&tx,&ty) && near(tx,117.0f) && near(ty,62.0f),"location target");
|
||||
require(mm.GetTargetMiniMapPosition(901,&tx,&ty) && near(tx,60.0f) && near(ty,90.0f),"vid target");
|
||||
mm.DeleteTarget(900);mm.DeleteTarget(901);
|
||||
require(!mm.GetTargetMiniMapPosition(900,&tx,&ty),"delete target");
|
||||
|
||||
// Atlas marks from HEADER_GC_NPC_POSITION: the warp name is cut at the first space.
|
||||
mm.ClearAtlasMarkInfo();
|
||||
mm.RegisterAtlasMark(1,20000,"Guard",2560,5120,0);
|
||||
mm.RegisterAtlasMark(3,0,"North Gate",10000,10000,0);
|
||||
mm.RegisterAtlasMark(0,691,"Boss",30000,30000,120);
|
||||
GetGuildState().names[77]="Clan";
|
||||
mm.RegisterGuildArea(1,77,1000,1000,2000,2000);
|
||||
mm.RegisterGuildArea(2,78,20000,40000,1000,1000);
|
||||
mm.AddSignalPoint(100,100);
|
||||
require(mm.GetTestView().wayPoints==1,"signal waypoint");
|
||||
mm.ClearAllSignalPoint();
|
||||
require(mm.GetTestView().wayPoints==0,"signal cleared");
|
||||
|
||||
const auto& ma=*actors.GetActorData(1);(void)ma;
|
||||
char script[4096];
|
||||
std::snprintf(script,sizeof(script),
|
||||
"npc=%ld\nwarp=%ld\nwp=%ld\nparty=%ld\nother=%ld\nhero=%ld\n"
|
||||
"class Atlas:\n def __init__(self):\n self.shown=0\n self.center=None\n"
|
||||
" def Show(self):\n self.shown+=1\n def SetCenterPositionAdjust(self,x,y):\n self.center=(x,y)\n"
|
||||
"a=Atlas()\nm.RegisterAtlasWindow(a)\n"
|
||||
"assert m.GetAtlasSize()==(1,256,384) and m.IsAtlas()==1\n"
|
||||
"m.ShowAtlas()\nm.UpdateAtlas()\nm.RenderAtlas(10,20)\nassert m.isShowAtlas()==1\n"
|
||||
"assert m.GetAtlasInfo(22.8,45.6)==(1,'Guard',25,51,npc,0,0),m.GetAtlasInfo(22.8,45.6)\n"
|
||||
"assert m.GetAtlasInfo(60,70)==(1,'North',100,100,warp,0,0),m.GetAtlasInfo(60,70)\n"
|
||||
"assert m.GetAtlasInfo(160,170)==(1,'Boss',300,300,-1,0,120)\n"
|
||||
"assert m.GetAtlasInfo(10+200,20+300)==(1,'Hero',400,600,hero,0,0)\n"
|
||||
"assert m.GetAtlasInfo(20,30)==(1,'Clan',20,20,party,77,0),m.GetAtlasInfo(20,30)\n"
|
||||
"assert m.GetAtlasInfo(10+102,20+202)==(1,'empty_guild_area',205,405,party,0,0)\n"
|
||||
"assert m.GetAtlasInfo(250,400)==(0,'',0,0,0,0,0)\n"
|
||||
"m.AddWayPoint(5,6000.0,6000.0,'wp')\nm.AddWayPoint(5,1.0,1.0,'dup')\n"
|
||||
"assert m.GetAtlasInfo(40,50)==(1,'wp',60,60,wp,0,0)\n"
|
||||
"m.RemoveWayPoint(5)\nassert m.GetAtlasInfo(40,50)==(0,'',0,0,0,0,0)\n"
|
||||
"assert m.GetGuildAreaID(1500,1500)==77 and m.GetGuildAreaID(999,1500)==-1 and m.GetGuildAreaID(-1.0,0)==-1\n"
|
||||
"m.LoadAtlas()\nassert a.shown==1\n"
|
||||
"m.Show()\nassert m.isShow()==1\nm.Render(100,200)\n"
|
||||
"assert m.GetInfo(164,264)==(1,'Hero',400,600,hero),m.GetInfo(164,264)\n"
|
||||
"assert m.GetInfo(184,264)==(1,'Other',420,600,other),m.GetInfo(184,264)\n"
|
||||
"assert m.GetInfo(100,200)==(0,'',0,0,0)\n"
|
||||
"m.SetScale(9)\nm.ScaleDown()\nm.ScaleDown()\nm.ScaleDown()\nm.ScaleDown()\n"
|
||||
"assert m.GetInfo(184,264)==(0,'',0,0,0)\n",
|
||||
long(int32_t(NetworkActorManager::GetIndexedNameColor(NetworkActorManager::NAMECOLOR_NPC))),
|
||||
long(int32_t(NetworkActorManager::GetIndexedNameColor(NetworkActorManager::NAMECOLOR_WARP))),
|
||||
long(int32_t(NetworkActorManager::GetIndexedNameColor(NetworkActorManager::NAMECOLOR_WAYPOINT))),
|
||||
long(int32_t(NetworkActorManager::GetIndexedNameColor(NetworkActorManager::NAMECOLOR_PARTY))),
|
||||
long(int32_t(NetworkActorManager::GetIndexedNameColor(actors.GetNameColorIndex(2)))),
|
||||
long(int32_t(NetworkActorManager::GetIndexedNameColor(actors.GetNameColorIndex(1)))));
|
||||
python.execute(script);
|
||||
v=mm.GetTestView();
|
||||
require(v.scale==0.5f && v.radius==16.0f,"scale clamp");
|
||||
mm.SetAtlasCenterPosition(3,4);
|
||||
python.execute("assert a.center==(3,4)\nm.UnregisterAtlasWindow()\nm.Destroy()\n"
|
||||
"assert m.isShow()==0 and m.IsAtlas()==0 and m.GetAtlasSize()==(1,0,0)\n");
|
||||
// LoadAtlas cleared the guild areas; Destroy keeps the atlas mark vectors, as on Windows.
|
||||
v=mm.GetTestView();
|
||||
require(v.guildAreas==0 && v.npcMarks==1 && v.wayPoints==0 && v.scale==2.0f,"destroy");
|
||||
|
||||
actors.Clear();
|
||||
NetworkActorManager::SetPartyMemberQuery(nullptr);
|
||||
fs::current_path(fs::temp_directory_path());
|
||||
fs::remove_all(root);
|
||||
std::cout<<"AVA2 miniMap parity passed\n";
|
||||
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
#include "python_runtime.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
using Bytes=std::vector<uint8_t>;
|
||||
void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);}
|
||||
void put(Bytes& b,uint64_t v,unsigned width=4) {for(unsigned i=0;i<width;++i)b.push_back(uint8_t(v>>(8*i)));}
|
||||
void text(Bytes& b,const std::string& s,size_t width) {for(size_t i=0;i<width;++i)b.push_back(i<s.size()?s[i]:0);}
|
||||
Bytes frame(uint8_t sub,const Bytes& payload) {Bytes b{47};put(b,4+payload.size(),2);b.push_back(sub);b.insert(b.end(),payload.begin(),payload.end());return b;}
|
||||
void send(uint8_t sub,const Bytes& data) {auto& s=PythonNetworkStream::Instance();s.PushRecvData(frame(sub,data));s.ProcessRecvData();}
|
||||
Bytes item(uint32_t vnum=0x80000001) {
|
||||
Bytes b;put(b,123);put(b,vnum);put(b,uint64_t(-900000000000LL),8);put(b,uint32_t(-3));b.push_back(77);
|
||||
for(int i=0;i<8;++i)put(b,uint32_t(-i-1));
|
||||
for(int i=0;i<15;++i){b.push_back(uint8_t(i+1));put(b,uint16_t(-i-1),2);}
|
||||
b.push_back(2);text(b,std::string(25,'x'),25);put(b,0xffffffff);return b;
|
||||
}
|
||||
Bytes log(const std::string& name,int64_t price) {Bytes b;text(b,name,25);text(b,"date",25);put(b,0xffffffff);put(b,0x80000000);put(b,uint64_t(price),8);return b;}
|
||||
Bytes start() {
|
||||
Bytes b;put(b,0xffffffff);auto row=item();b.insert(b.end(),row.begin(),row.end());b.resize(4+80*128,0);
|
||||
put(b,0xffffffff);text(b,std::string(46,'t'),46);put(b,uint64_t(-700000000000LL),8);put(b,0x80000000);
|
||||
for(int i=0;i<80;++i){auto entry=log(i==79?"last":"first",i==79?10:i==0?-20:0);b.insert(b.end(),entry.begin(),entry.end());}
|
||||
put(b,0xffffffffffffffffULL,8);put(b,uint32_t(-12));put(b,0xffffffff);b.push_back(2);return b;
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
PythonRuntime python(argv[1],argv[2]);auto& s=PythonNetworkStream::Instance();s.ResetConnection();s.SetPhase(PHASE_GAME);
|
||||
python.execute(R"PY(import net,shop
|
||||
class Game:
|
||||
def __init__(self): self.events=[]
|
||||
def __getattr__(self,name):
|
||||
def event(*args):
|
||||
self.events.append((name,)+args)
|
||||
if name=='StartOfflineShop': assert shop.GetOfflineShopItemVnum(0)==-2147483647
|
||||
return event
|
||||
game=Game()
|
||||
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)
|
||||
shop.Clear()
|
||||
assert shop.GetSign()=='NONE' and shop.HasOfflineShop()==0 and shop.IsOfflineShop()==0
|
||||
assert shop.GetOfflineShopItemBuyerName(0)=='None' and shop.GetOfflineShopItemAttribute(0,0)==(0,0)
|
||||
shop.AddOfflineShopItemStock(1,4,7,900000000000)
|
||||
assert shop.GetOfflineShopItemPriceReal(1,4)==900000000000
|
||||
)PY");
|
||||
auto payload=start();require(payload.size()==15603&&item().size()==128&&log("",0).size()==66,"offline independent fixture sizes");
|
||||
auto wire=frame(0,payload);wire.push_back(44);s.PushRecvData(wire.data(),wire.size()-2);s.ProcessRecvData();python.execute("assert game.events==[]\n");s.PushRecvData(wire.data()+wire.size()-2,2);s.ProcessRecvData();require(s.PopSendBytes()==Bytes{254},"offline fragmented start lost ping");
|
||||
python.execute(R"PY(assert game.events==[('ClearOfflineShopLog',),('AppendShopLog','last','date',-1,-2147483648,10),('AppendShopLog','first','date',-1,-2147483648,-20),('StartOfflineShop',-1,1)]
|
||||
assert shop.IsOfflineShop()==0 and shop.HasOfflineShop()==0
|
||||
assert shop.GetSign()=='t'*46 and shop.GetDisplayedCount()==-1 and shop.GetRealWatcherCount()==-2147483648
|
||||
assert shop.GetCurrentOfflineShopMoney()==-700000000000 and shop.GetShopFlag()==-1 and shop.GetShopType()==-1 and shop.GetShopTime()==-12
|
||||
assert shop.GetOfflineShopItemID(0)==shop.GetOfflineShopItemVnum(0)==-2147483647
|
||||
assert shop.GetOfflineShopItemCount(0)==-3 and shop.GetOfflineShopItemPrice(0)==-900000000000
|
||||
assert shop.GetOfflineShopItemMetinSocket(0,7)==-8 and shop.GetOfflineShopItemMetinSocket(0,8)==0
|
||||
assert shop.GetOfflineShopItemAttribute(0,14)==(15,-15) and shop.GetOfflineShopItemAttribute(0,15)==(0,0)
|
||||
assert shop.GetOfflineShopItemStatus(0)==2 and shop.GetOfflineShopID(0)==-1 and shop.GetOfflineShopItemBuyerName(0)=='x'*25
|
||||
assert shop.GetOfflineShopItemVnum(80)==0 and shop.GetOfflineShopItemVnum(-1)==0
|
||||
assert shop.GetOfflineShopItemPriceReal(1,4)==0
|
||||
game.events=[]
|
||||
)PY");
|
||||
Bytes update{1};auto row=item(0);update.insert(update.end(),row.begin(),row.end());put(update,17);put(update,18);text(update,"Updated",46);put(update,900000000000ULL,8);auto entry=log("buyer",30);update.insert(update.end(),entry.begin(),entry.end());put(update,5,8);put(update,uint32_t(-7));put(update,6);require(update.size()==273,"update fixture size");send(2,update);
|
||||
python.execute("assert game.events==[('AppendShopLogFirst','buyer','date',-1,-2147483648,30),('RefreshOfflineShop',)]\nassert shop.GetOfflineShopItemBuyerName(1)=='None' and shop.GetCurrentOfflineShopMoney()==900000000000\nassert shop.GetSign()=='Updated' and shop.GetShopFlag()==5 and shop.GetShopTime()==-7 and shop.GetShopType()==6\ngame.events=[]\n");
|
||||
// UPDATE stores second-tab data and does not append a zero-price log.
|
||||
update[0]=81;row=item(1234);std::copy(row.begin(),row.end(),update.begin()+1);
|
||||
std::fill(update.begin()+249,update.begin()+257,0);send(2,update);
|
||||
python.execute("assert shop.GetOfflineShopItemVnum(81)==1234 and game.events==[('RefreshOfflineShop',)]\ngame.events=[]\n");
|
||||
send(14,{1,44});require(s.PopSendBytes()==Bytes{254},"scalar offline branch consumed trailing payload");
|
||||
for(uint8_t flag:{1,2,0}) {send(14,{flag});python.execute(flag==1?"assert shop.HasOfflineShop()==1\n":"assert shop.HasOfflineShop()==0\n");}
|
||||
Bytes scalar;put(scalar,uint64_t(-90),8);send(13,scalar);scalar.clear();put(scalar,20);send(15,scalar);scalar.clear();put(scalar,30);send(16,scalar);scalar.clear();put(scalar,40);put(scalar,50);send(17,scalar);scalar.clear();text(scalar,"Title",46);send(18,scalar);
|
||||
python.execute("assert shop.GetCurrentOfflineShopMoney()==-90 and shop.GetDisplayedCount()==40 and shop.GetRealWatcherCount()==50 and shop.GetSign()=='Title'\nassert game.events==[('RefreshOfflineShop',)]*5\ngame.events=[]\n");
|
||||
for(uint8_t sub:{5,9,7,8,19,4,6,255})send(sub,{44});
|
||||
require(s.PopSendBytes().empty(),"unknown/error offline subheader did not consume payload");
|
||||
python.execute("assert game.events==[('OnShopError','NOT_ENOUGH_MONEY'),('OnShopError','SOLDOUT'),('OnShopError','INVENTORY_FULL'),('OnShopError','INVALID_POS'),('OnShopError','NOT_ENOUGH_LUCKY')]\ngame.events=[]\nshop.SetShopFlag(-1)\nshop.SetShopType(-2)\nshop.SetShopTime(-3)\nassert shop.GetShopFlag()==-1 and shop.GetShopType()==-2 and shop.GetShopTime()==-3\n");
|
||||
send(1,{});python.execute("assert game.events==[('ClearOfflineShopLog',),('EndOfflineShop',)]\nassert shop.GetOfflineShopItemVnum(0)==0 and shop.GetSign()=='NONE' and shop.GetShopFlag()==0 and shop.GetShopTime()==0 and shop.GetShopType()==0\ngame.events=[]\n");
|
||||
python.execute(R"PY(shop.AddOfflineShopItemStock(1,8,20,10)
|
||||
shop.AddOfflineShopItemStock(1,4,9,900000000000)
|
||||
shop.AddOfflineShopItemStock(1,4,2,-900000000000)
|
||||
shop.AddOfflineShopItemStock(257,65544,21,20)
|
||||
assert shop.GetOfflineShopItemPriceReal(1,8)==20
|
||||
shop.AddOfflineShopItemStock(2,5,3,30)
|
||||
shop.DelOfflineShopItemStock(2,5)
|
||||
shop.BuildOfflineShop('a'*60,-1,258)
|
||||
)PY");
|
||||
Bytes expected(53,0);expected[0]=58;std::fill(expected.begin()+1,expected.begin()+46,'a');expected[47]=2;std::fill(expected.begin()+48,expected.begin()+52,255);expected[52]=2;
|
||||
for(auto [cell,price,display]:{std::tuple{4,-900000000000LL,2},std::tuple{8,20LL,21}}) {put(expected,0);put(expected,0);expected.push_back(1);put(expected,cell,2);put(expected,uint64_t(price),8);expected.push_back(display);}
|
||||
require(s.PopSendBytes()==expected,"build offline shop wire/sort/replace mismatch");
|
||||
python.execute("shop.ChangeDecoration('literal %s',258,259)\n");expected.assign(110,0);expected[0]=57;expected[1]=12;std::string sign="literal %s";std::copy(sign.begin(),sign.end(),expected.begin()+58);expected[108]=2;expected[109]=3;require(s.PopSendBytes()==expected,"decoration wire mismatch");
|
||||
python.execute("shop.ClearOfflineShopStock()\nassert shop.GetOfflineShopItemPriceReal(1,4)==0\nshop.BuildOfflineShop('',0,0)\n");expected.assign(53,0);expected[0]=58;require(s.PopSendBytes()==expected,"empty stock build mismatch");
|
||||
// Short payloads reject without mutating state or reading a following frame.
|
||||
for(uint8_t sub:{0,2,13,14,15,16,17,18}) {auto bad=frame(sub,{});bad.push_back(44);s.PushRecvData(bad);s.ProcessRecvData();require(s.PopSendBytes().empty(),"short offline payload consumed next frame");}
|
||||
python.execute("assert game.events==[]\n");require(s.GetUnportedPackets().empty(),"offline shop still skipped");s.ResetConnection();
|
||||
std::cout<<"AVA2 offline shop state, wire and Python callback parity passed\n";
|
||||
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
+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");
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "quest_state.h"
|
||||
#include "python_runtime.h"
|
||||
#include "python_net.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
||||
std::vector<uint8_t> packet(uint16_t id,uint8_t flags,const std::vector<uint8_t>& payload) {
|
||||
auto size=uint16_t(6+payload.size());
|
||||
return {81,uint8_t(size),uint8_t(size>>8),uint8_t(id),uint8_t(id>>8),flags};
|
||||
}
|
||||
void append(std::vector<uint8_t>& p,const std::string& field,size_t size) {
|
||||
auto start=p.size();p.resize(start+size,0);
|
||||
std::copy_n(field.begin(),std::min(field.size(),size),p.begin()+start);
|
||||
}
|
||||
void u32(std::vector<uint8_t>& p,uint32_t n) { for(unsigned i=0;i<4;++i)p.push_back(uint8_t(n>>(i*8))); }
|
||||
void send(uint16_t id,uint8_t flags,const std::vector<uint8_t>& payload) {
|
||||
auto p=packet(id,flags,payload);p.insert(p.end(),payload.begin(),payload.end());
|
||||
PythonNetworkStream::Instance().PushRecvData(p);PythonNetworkStream::Instance().ProcessRecvData();
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
QuestState fixture;QuestRecord q;q.index=10;q.clockValue=20;q.title="First";
|
||||
fixture.apply(1,q,127,100);q.index=20;fixture.apply(1,q,127,101);
|
||||
q.index=10;q.title="Replaced";fixture.apply(1,q,127,102);
|
||||
require(fixture.records[0].index==20 && fixture.records[1].title=="Replaced","wire begin did not replace/reorder");
|
||||
q.title="Duplicate";fixture.apply(1,q,127,103,true);
|
||||
require(fixture.records[1].title=="Replaced","quest.Add duplicate changed state");
|
||||
q.title.clear();q.clockValue=0;q.counterValue=-3;fixture.apply(2,q,32,110);
|
||||
require(fixture.find(10)->title=="Replaced" && fixture.find(10)->startTime==102 && fixture.find(10)->counterValue==-3,"partial update semantics");
|
||||
require(QuestState::remaining(*fixture.find(10),130)==-8,"expired countdown clamped");
|
||||
q.clockValue=-1;fixture.apply(2,q,8,140);
|
||||
require(QuestState::remaining(*fixture.find(10),150)==0,"negative clock must return zero");
|
||||
PythonRuntime python(argv[1],argv[2]);
|
||||
auto& stream=PythonNetworkStream::Instance();stream.ResetConnection();stream.SetPhase(PHASE_GAME);
|
||||
python.execute("import quest, net\nassert quest.GetQuestCount()==0\nclass Callbacks:\n def __init__(self):\n self.refresh=0\n self.translations=[]\n def RefreshQuest(self):\n self.refresh+=1\n def GetQuestLetterName(self,*args):\n self.translations.append(args)\n kind,index,flags,title,clock,counter,icon,cv,nv=args\n quest.Add(kind,index,'Translated',clock,cv,counter,nv,icon,flags)\ncb=Callbacks()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,cb)\n");
|
||||
std::vector<uint8_t> payload{1};append(payload,"Title",31);append(payload,"Clock",17);u32(payload,60);append(payload,"Counter",17);u32(payload,uint32_t(-9));append(payload,"icon.tga",25);
|
||||
auto p=packet(65535,127,payload);p.insert(p.end(),payload.begin(),payload.end());p.push_back(44);
|
||||
stream.PushRecvData(p.data(),p.size()-2);stream.ProcessRecvData();
|
||||
python.execute("assert quest.GetQuestCount()==0\nassert cb.refresh==0\n");
|
||||
stream.PushRecvData(p.data()+p.size()-2,2);stream.ProcessRecvData();
|
||||
require(stream.PopSendBytes()==std::vector<uint8_t>{254},"quest frame lost following ping");
|
||||
python.execute("assert quest.GetQuestCount()==1\nassert quest.GetQuestIndex(0)==65535\nassert quest.GetQuestData(0)==('Title',0,'Counter',-9)\nassert quest.GetQuestLastTime(0)==('Clock',60)\nassert cb.refresh==1\n");
|
||||
require(GetQuestState().find(65535)->counterValue==-9,"signed counter");
|
||||
payload.clear();append(payload,"",31);u32(payload,0);send(65535,2|32,payload);
|
||||
require(GetQuestState().find(65535)->title=="Title" && GetQuestState().find(65535)->counterValue==0,"empty title/value update");
|
||||
payload={1};append(payload,"^LOCALE_TITLE",31);send(7,1|2,payload);
|
||||
python.execute("assert cb.translations==[(1,7,3,'^LOCALE_TITLE','','','',0,0)]\nassert quest.GetQuestIndex(1)==7\nquest.Add(1,7,'Ignored','',0,'',0,'',0)\nassert quest.GetQuestCount()==2\nquest.Add(2,-1,'Unsigned','',-1,'',0,'',8,123)\nassert quest.GetQuestIndex(2)==-1\nassert quest.GetQuestLastTime(2)==('',0)\nfor getter in [quest.GetQuestIndex,quest.GetQuestData,quest.GetQuestLastTime]:\n try:\n getter(-1)\n raise AssertionError('invalid quest index accepted')\n except RuntimeError:\n pass\n");
|
||||
send(65535,1,{0});
|
||||
python.execute("assert quest.GetQuestCount()==2\nassert quest.GetQuestIndex(0)==7\nassert cb.refresh==4\n");
|
||||
// Truncated flag-selected title cannot consume a coalesced next packet.
|
||||
send(9,2,{});
|
||||
python.execute("assert quest.GetQuestCount()==2\nassert cb.refresh==4\nquest.Clear()\nassert quest.GetQuestCount()==0\n");
|
||||
stream.ResetConnection();std::cout<<"AVA2 quest state, wire and Python parity passed\n";
|
||||
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "shop_search_state.h"
|
||||
#include "python_runtime.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
||||
void put(std::vector<uint8_t>& p,uint64_t v,unsigned n) { for(unsigned i=0;i<n;++i)p.push_back(uint8_t(v>>(8*i))); }
|
||||
std::vector<uint8_t> item() {
|
||||
std::vector<uint8_t> p;put(p,0xffffffff,4);put(p,0x80000001,4);put(p,uint64_t(-1234567890123LL),8);put(p,uint32_t(-9),4);p.push_back(255);
|
||||
for(unsigned i=0;i<8;++i)put(p,uint32_t(-100-int(i)),4);
|
||||
for(unsigned i=0;i<15;++i) { p.push_back(uint8_t(240+i));put(p,uint16_t(-300-int(i)),2); }
|
||||
p.push_back(7);const size_t start=p.size();p.resize(start+25,0);p[start]='S';p[start+1]='e';p[start+2]='l';p[start+3]='l';p[start+4]='e';p[start+5]='r';
|
||||
put(p,0x80000002,4);return p;
|
||||
}
|
||||
std::vector<uint8_t> reply(uint16_t count) {
|
||||
std::vector<uint8_t> p{156};put(p,7+128u*count,4);put(p,count,2);
|
||||
for(unsigned i=0;i<count;++i) { auto r=item();p.insert(p.end(),r.begin(),r.end()); }
|
||||
return p;
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
{
|
||||
PythonRuntime python(argv[1],argv[2]);auto& s=PythonNetworkStream::Instance();s.ResetConnection();s.SetPhase(PHASE_GAME);
|
||||
python.execute("import privateShopSearch as search,net\nassert search.GetItemCount()==0\nassert not hasattr(search,'GetSearchItemTransmutation')\nassert not hasattr(search,'GetSearchItemPerma')\nassert search.GetSearchItemNewName(-1)=='^'\nassert search.GetSearchItemAttribute() is None\nassert search.GetSearchItemAttribute(-1,15)==(0,0)\nassert search.GetSearchItemMetinSocket(-1,8) is None\nclass Window:\n def __init__(self): self.counts=[]\n def RefreshShopSearch(self): self.counts.append(search.GetItemCount())\nw=Window()\nnet.SetPhaseWindow(net.PHASE_WINDOW_GAME,w)\n");
|
||||
auto p=reply(2);p.push_back(44);s.PushRecvData(p.data(),p.size()-2);s.ProcessRecvData();
|
||||
python.execute("assert search.GetItemCount()==0\nassert w.counts==[]\n");
|
||||
s.PushRecvData(p.data()+p.size()-2,2);s.ProcessRecvData();require(s.PopSendBytes()==std::vector<uint8_t>{254},"search frame lost following ping");
|
||||
python.execute("assert search.GetItemCount()==2\nassert w.counts==[2]\nassert search.GetSearchItemID(0)==-1\nassert search.GetSearchItemVnum(0)==-2147483647\nassert search.GetSearchItemPrice(0)==-1234567890123\nassert search.GetSearchItemCount(0)==-9\nassert search.GetSearchItemShopVID(0)==-2147483646\nassert search.GetSearchItemPos(0)==255\nassert search.GetSearchItemSeller(0)=='Seller'\nassert search.GetSearchItemMetinSocket(1,7)==-107\nassert search.GetSearchItemAttribute(1,14)==(254,-314)\nassert search.GetSearchItemNewName(0)=='^'\nfor getter in [search.GetSearchItemID,search.GetSearchItemSeller]:\n try:\n getter(-1)\n raise AssertionError('invalid index accepted')\n except RuntimeError:\n pass\n");
|
||||
auto more=reply(1),empty=reply(0);more.insert(more.end(),empty.begin(),empty.end());s.PushRecvData(more);s.ProcessRecvData();
|
||||
python.execute("assert search.GetItemCount()==3\nassert w.counts==[2,3]\n");
|
||||
// Count claims one record but the declared packet ends before it: retain prior results.
|
||||
const std::vector<uint8_t> malformed{156,7,0,0,0,1,0,44};s.PushRecvData(malformed);s.ProcessRecvData();
|
||||
require(s.PopSendBytes().empty(),"search malformed length consumed coalesced ping");
|
||||
python.execute("assert search.GetItemCount()==3\nassert w.counts==[2,3]\nsearch.ClearSearchItems()\nassert search.GetItemCount()==0\nassert w.counts==[2,3]\nargs=[-2,3,257,-1,258,259,260,261,262,263,264,265,266,267,268,269,-5,9223372036854775807,'Sword']\nassert net.SendPrivateShopSearchInfo() is None\nnet.SendPrivateShopSearchInfo(*args)\n");
|
||||
require(s.PopSendBytes().empty(),"search sent without main actor");
|
||||
SNetworkActorData actor{};actor.m_dwVID=1001;actor.m_dwRace=0;actor.m_stName="SearchFixture";NetworkActorManager::Instance().AppendActor(actor);s.SetMainActorVID(1001);
|
||||
python.execute("net.SendPrivateShopSearchInfo(*args)\n");
|
||||
auto packets=s.PopSendPacketsWithSequence();require(packets.size()==1 && !packets[0].second,"search request incorrectly sequenced");
|
||||
std::vector<uint8_t> expected{143};put(expected,uint32_t(-2),4);put(expected,3,4);expected.resize(59,0);const char input[]="Sword";std::copy_n(input,5,expected.begin()+9);
|
||||
expected.insert(expected.end(),{1,255,2,3,4,5,6,7,8,9,12,10,11,13});put(expected,uint64_t(-5),8);put(expected,0x7fffffffffffffffULL,8);
|
||||
require(packets[0].first==expected && expected.size()==89,"search request field layout/conversions");
|
||||
s.ClearSendQueue();auto instance=NetworkActorManager::Instance().GetActorInstance(1001);require(bool(instance),"missing actor");instance->SetSleep(true);
|
||||
python.execute("net.SendPrivateShopSearchInfo(*args)\n");require(s.PopSendBytes().empty(),"controlled actor searched");instance->SetSleep(false);
|
||||
python.execute("args[-1]='X'*50\ntry:\n net.SendPrivateShopSearchInfo(*args)\n raise AssertionError('oversized text accepted')\nexcept ValueError:\n pass\n");require(s.PopSendBytes().empty(),"invalid search emitted bytes");
|
||||
s.PushRecvData(reply(1));s.ProcessRecvData();s.ResetConnection();NetworkActorManager::Instance().Clear();
|
||||
}
|
||||
{ PythonRuntime python(argv[1],argv[2]);python.execute("import privateShopSearch as search\nassert search.GetItemCount()==0\n"); }
|
||||
std::cout<<"AVA2 shop search state, wire and Python parity passed\n";
|
||||
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
// CPythonSkill / skill module against the original AVA2 PythonSkill.cpp: skilldesc icon paths per
|
||||
// job column, RegisterSkill per-skill files, the never-filled requirement data, icon handles and
|
||||
// instances, GetGradeData's std::string varargs quirk and the TEST dump.
|
||||
#include "python_native_modules.h"
|
||||
#include "python_runtime.h"
|
||||
#include "skill_description.h"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
using namespace ava2;
|
||||
namespace fs = std::filesystem;
|
||||
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
||||
void spit(const fs::path& p,const std::string& s) { fs::create_directories(p.parent_path());std::ofstream f(p,std::ios::binary);f<<s; }
|
||||
std::string slurp(const fs::path& p) { std::ifstream f(p,std::ios::binary);std::stringstream s;s<<f.rdbuf();return s.str(); }
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
const fs::path cwd=fs::current_path();
|
||||
try {
|
||||
const fs::path root=fs::temp_directory_path()/"ava2_skill_test";
|
||||
fs::remove_all(root);fs::create_directories(root);
|
||||
// id job name grade1 grade2 desc cond0..2 (9) attributes weapons icon motion
|
||||
spit(root/"locale/skilldesc.txt",
|
||||
"1\tWARRIOR\tBase\tMid\t\tCut\tc1\t\t\t\tTOGGLE\tSWORD|BOW\tsamyeon\t2\n"
|
||||
"2\tSUPPORT\tLeadershipSkill\t\t\tLead\t\t\t\t\tPASSIVE|CANNOT_LEVEL_UP\t\tleadership\n"
|
||||
"3\twarrior\tLower\t\t\tlower-case job: no m_PathNameMap entry\t\t\t\t\t\t\tlower\n"
|
||||
"130\tHORSE\tRiding\t\t\tRide\t\t\t\t\t\t\triding\n"
|
||||
"131\tHORSE\tHorseSkillLongName\t\t\tHorse\t\t\t\t\t\t\thorse_icon\n");
|
||||
spit(root/"skill/fire.txt",
|
||||
"type\tactive\n"
|
||||
"attribute\tTIME_INCREASE_SKILL\tNEED_TARGET\n"
|
||||
"needweapon\tFAN\tBELL\n"
|
||||
"949name\tFireKr\n"
|
||||
"name\tFireEn\n"
|
||||
"description\t\"burns things\"\n"
|
||||
"iconfilename\tskill/fire.sub\n"
|
||||
"List\t949GradeData\n{\n\t\"G1\"\t\"skill/fire_01.sub\"\n\t\"G2\"\t\"skill/fire_02.sub\"\n}\n"
|
||||
"List\tAffectData\n{\n\t\"Damage\"\t\"10*k\"\t\"20*k\"\n}\n"
|
||||
"maxlevel\t30\nleveluppoint\t2\nmotionindex\t7\nmotionindexforme\t9\n");
|
||||
spit(root/"skill/broken.txt","type\tactive\nname\tNoIcon\n");
|
||||
|
||||
PythonRuntime python(argv[1],root);
|
||||
require(LoadSkillDescriptions("locale/skilldesc.txt"),"skilldesc");
|
||||
auto* active=FindSkillDescription(1);
|
||||
require(active && active->imageFile.empty(),"active skills have no pImage");
|
||||
require(active->gradeImageFiles[0]=="d:/ymir work/ui/skill/warrior/samyeon_01.sub" &&
|
||||
active->gradeImageFiles[2]=="d:/ymir work/ui/skill/warrior/samyeon_03.sub" && active->gradeImageFiles[3].empty(),"grade icons");
|
||||
auto* support=FindSkillDescription(2);
|
||||
require(support->imageFile=="d:/ymir work/ui/skill/common/support/leadership.sub" &&
|
||||
support->gradeImageFiles[0]==support->imageFile && support->gradeImageFiles[2]==support->imageFile,"normal icon");
|
||||
require(FindSkillDescription(3)->gradeImageFiles[0].empty() && FindSkillDescription(3)->imageFile.empty(),"job map is case-sensitive");
|
||||
require(FindSkillDescription(130)->gradeImageFiles[1]=="d:/ymir work/ui/skill/common/support/riding_02.sub" &&
|
||||
FindSkillDescription(130)->imageFile.empty(),"riding grade icons");
|
||||
require(FindSkillDescription(131)->imageFile=="d:/ymir work/ui/skill/common/horse/horse_icon.sub","horse icon");
|
||||
|
||||
fs::current_path(root);
|
||||
python.execute(
|
||||
"import skill\n"
|
||||
"def raises(f,*a):\n try:\n f(*a)\n except RuntimeError:\n return True\n return False\n"
|
||||
// Requirement data is never loaded, so every query has the constructor-state answer.
|
||||
"assert skill.IsSkillRequirement(1)==0 and raises(skill.IsSkillRequirement,99)\n"
|
||||
"assert skill.GetSkillRequirementData(1)==(None,0)\n"
|
||||
"assert skill.GetSkillRequireStatCount(1)==0 and skill.GetSkillRequireStatData(1,5)==(0,0)\n"
|
||||
"assert skill.CanLevelUpSkill(1,19)==1 and skill.CanLevelUpSkill(1,20)==0\n"
|
||||
"assert skill.CanLevelUpSkill(2,0)==0 and raises(skill.CanLevelUpSkill,99,0)\n"
|
||||
"assert skill.IsLevelUpSkill(1)==1 and skill.CheckRequirementSueccess(1)==1 and skill.GetNeedCharacterLevel(1)==0\n"
|
||||
"assert raises(skill.GetNeedCharacterLevel,99) and raises(skill.CheckRequirementSueccess,99)\n"
|
||||
"assert skill.CanUseSkill(1)==1 and skill.CanUseSkill(2)==0 and raises(skill.CanUseSkill,99)\n"
|
||||
// Icons: no image assets in this mount, so NULL handles; unknown skills are 0, not errors.
|
||||
"assert skill.GetIconName(1)=='' and skill.GetIconName(99)==''\n"
|
||||
"assert skill.GetIconImage(99)==0 and skill.GetIconImageNew(99,0)==0\n"
|
||||
"assert skill.GetIconImage(2)==0 and skill.GetIconImageNew(1,-5)==0 and skill.GetIconImageNewEx('missing.sub')==0\n"
|
||||
"h=skill.GetIconInstance(1)\nh2=skill.GetIconInstanceNew(1,7)\n"
|
||||
"assert h and h2 and h!=h2\n"
|
||||
"skill.DeleteIconInstance(h)\nskill.DeleteIconInstance(h2)\nskill.DeleteIconInstance(h)\nskill.DeleteIconInstance(12345)\n"
|
||||
"assert raises(skill.GetIconInstance,99) and raises(skill.GetIconInstanceNew,99,0)\n"
|
||||
// GetGradeData: the first four bytes of the MSVC std::string (inline buffer for short names).
|
||||
"assert skill.GetGradeData(1,0)==0x65736142, hex(skill.GetGradeData(1,0))\n"
|
||||
"assert skill.GetGradeData(1,1)==ord('M')|ord('i')<<8|ord('d')<<16\n"
|
||||
"assert skill.GetGradeData(2,0)==0x6461654C\n" // 15 chars: still the inline buffer
|
||||
"assert skill.GetGradeData(131,0)==0\n" // 16+ chars: heap pointer, 0 here
|
||||
"try:\n skill.GetGradeData(1,3)\n raise AssertionError\nexcept RuntimeError, e:\n assert str(e)=='Strange grade index [1]', str(e)\n"
|
||||
// RegisterSkill: per-skill file relative to SetPathName; 949 keys win; no overwrite.
|
||||
"skill.SetPathName('skill/')\n"
|
||||
"skill.RegisterSkill(200,'fire.txt')\n"
|
||||
"assert skill.GetSkillName(200)=='FireKr' and skill.GetSkillDescription(200)=='burns things'\n"
|
||||
"assert skill.GetIconName(200)=='d:/ymir work/ui/skill/fire.sub'\n"
|
||||
"assert skill.GetSkillMaxLevel(200)==30 and skill.GetSkillLevelUpPoint(200)==2\n"
|
||||
"assert skill.GetSkillAffectDescriptionCount(200)==1\n"
|
||||
"assert skill.GetGradeData(200,1)==ord('G')|ord('2')<<8\n"
|
||||
"skill.RegisterSkill(1,'fire.txt')\nassert skill.GetSkillName(1)=='Base'\n"
|
||||
"try:\n skill.RegisterSkill(201,'broken.txt')\n raise AssertionError\nexcept RuntimeError, e:\n"
|
||||
" assert str(e)=='skill.RegisterSkill - Failed to find skill data file : 201, skill/broken.txt', str(e)\n"
|
||||
"assert raises(skill.RegisterSkill,202,'nothere.txt')\n"
|
||||
"skill.LoadSkillData()\nskill.ClearSkillData()\n"
|
||||
"skill.TEST()\n");
|
||||
auto* fire=FindSkillDescription(200);
|
||||
require(fire && fire->needWeapon==(16u|32u) && fire->attributes==((1u<<15)|1u) && fire->motion==7 && fire->motionForMe==9,"RegisterSkill fields");
|
||||
require(fire->gradeImageFiles[0]=="d:/ymir work/ui/skill/fire_01.sub" && fire->gradeImageFiles[2].empty() &&
|
||||
fire->imageFile=="d:/ymir work/ui/skill/fire.sub","RegisterSkill icons");
|
||||
const std::string dump=slurp(root/"test.txt");
|
||||
std::istringstream lines(dump);std::string first,line,fireRow;std::getline(lines,first);
|
||||
while(std::getline(lines,line))if(line.rfind("FireKr",0)==0)fireRow=line;
|
||||
// ARROW shares SWORD's bit, so the map walk prints both.
|
||||
if(first!="Base\t\t\tCut\tc1\t\t\t\tTOGGLE\tARROW|BOW|SWORD\t\t2\t\t\t\t") { std::cerr<<'['<<first<<"]\n";throw std::runtime_error("TEST row"); }
|
||||
if(fireRow!="FireKr\t\t\tburns things\t\t\t\t\tNEED_TARGET|TIME_INCREASE_SKILL\tBELL|FAN\tfire\t7\t9\tDamage\t10*k\t20*k\t\t") {
|
||||
std::cerr<<'['<<fireRow<<"]\n";throw std::runtime_error("TEST fire row");
|
||||
}
|
||||
fs::current_path(cwd);
|
||||
fs::remove_all(root);
|
||||
std::cout<<"AVA2 skill parity passed\n";
|
||||
} catch(const std::exception& e) { fs::current_path(cwd);std::cerr<<e.what()<<'\n';return 1; }
|
||||
}
|
||||
@@ -102,9 +102,15 @@ void TestWindMotionSimulation() {
|
||||
float base_x1 = draws_t1[0].positions[0];
|
||||
assert(std::abs(base_x0 - base_x1) < 0.01f && "Tree trunk base must be firmly anchored at ground");
|
||||
|
||||
// Check top canopy vertex sways with wind
|
||||
float top_x0 = draws_t0[1].positions[0];
|
||||
float top_x1 = draws_t1[1].positions[0];
|
||||
// Check top canopy vertex sways with wind (flex grows with height², so pick the
|
||||
// highest canopy vertex; vertex 0 is the bottom edge of the lowest cluster).
|
||||
const auto& canopy0 = draws_t0[1].positions;
|
||||
size_t top = 0;
|
||||
for (size_t i = 0; i < canopy0.size() / 3; ++i) {
|
||||
if (canopy0[i * 3 + 1] > canopy0[top * 3 + 1]) top = i;
|
||||
}
|
||||
float top_x0 = canopy0[top * 3 + 0];
|
||||
float top_x1 = draws_t1[1].positions[top * 3 + 0];
|
||||
float delta_sway = std::abs(top_x0 - top_x1);
|
||||
assert(delta_sway > 0.5f && "Tree canopy must visibly sway with wind");
|
||||
std::cout << " -> Wind displacement at canopy tip: " << delta_sway << " units (sway verified!)" << std::endl;
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
#include "switchbot_state.h"
|
||||
#include "python_runtime.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
using namespace ava2;
|
||||
using Bytes=std::vector<uint8_t>;
|
||||
void require(bool ok,const char* why) {if(!ok)throw std::runtime_error(why);}
|
||||
void u32(Bytes& b,uint32_t v) {for(unsigned i=0;i<4;++i)b.push_back(uint8_t(v>>(8*i)));}
|
||||
void u16(Bytes& b,uint16_t v) {b.push_back(uint8_t(v));b.push_back(uint8_t(v>>8));}
|
||||
Bytes frame(uint8_t sub,const Bytes& data) {Bytes b{171};u32(b,uint32_t(7+data.size()));b.insert(b.end(),{sub,0});b.insert(b.end(),data.begin(),data.end());return b;}
|
||||
void send(uint8_t sub,const Bytes& data) {auto& s=PythonNetworkStream::Instance();s.PushRecvData(frame(sub,data));s.ProcessRecvData();}
|
||||
void attr(Bytes& data,uint8_t set,int type,int value) {data.push_back(set);u32(data,uint32_t(type));u32(data,uint32_t(value));}
|
||||
void proto(const std::filesystem::path& path,uint32_t id,uint8_t type,uint8_t sub) {
|
||||
// Independent172-byte AVA2 r152 record and literal LZO stream, no source assets.
|
||||
Bytes raw;u32(raw,id);raw.resize(172);raw[4]='F';raw[29]='F';raw[54]=type;raw[55]=sub;raw[57]=1;
|
||||
Bytes compressed{189};compressed.insert(compressed.end(),raw.begin(),raw.end());compressed.insert(compressed.end(),{17,0,0});
|
||||
Bytes payload{'M','C','O','Z'};payload.insert(payload.end(),compressed.begin(),compressed.end());
|
||||
Bytes file{'M','I','P','X'};u32(file,1);u32(file,172);u32(file,1);u32(file,uint32_t(16+payload.size()));
|
||||
file.insert(file.end(),{'M','C','O','Z'});u32(file,0);u32(file,uint32_t(compressed.size()));u32(file,172);file.insert(file.end(),payload.begin(),payload.end());
|
||||
std::ofstream out(path,std::ios::binary);out.write(reinterpret_cast<const char*>(file.data()),file.size());
|
||||
}
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
auto root=std::filesystem::temp_directory_path()/std::filesystem::path("ava2-switchbot-"+std::to_string(getpid()));std::filesystem::create_directories(root);
|
||||
try {
|
||||
{
|
||||
PythonRuntime python(argv[1],root);auto& s=PythonNetworkStream::Instance();s.ResetConnection();s.SetPhase(PHASE_GAME);
|
||||
python.execute(R"PY(import switchbot as sw,player,net,item
|
||||
assert sw.SLOT_COUNT==5 and sw.ALTERNATIVE_COUNT==2
|
||||
assert sw.IsActive(5)==0 and sw.IsFinished(5)==0
|
||||
assert sw.GetAttribute(5,1,4)==(0,0)
|
||||
assert sw.IsActive() is None and sw.SetAttribute() is None
|
||||
assert sw.GetAttributesForSet(0)==[] and sw.GetAttributeMaxValue(0,1)==0
|
||||
class Game:
|
||||
def __init__(self): self.events=[]
|
||||
def RefreshSwitchbotWindow(self): self.events.append('window')
|
||||
def RefreshInventory(self):
|
||||
assert player.GetItemCount(11,5)==700
|
||||
assert player.GetItemMetinSocket(11,5,7)==0
|
||||
self.events.append('inventory')
|
||||
def RefreshSwitchbotItem(self,slot): self.events.append(('item',slot))
|
||||
game=Game()
|
||||
net.SetPhaseWindow(net.PHASE_WINDOW_GAME,game)
|
||||
player.SetGameWindow(game)
|
||||
sw.SetAttribute(256,256,256,257,65535)
|
||||
assert sw.GetAttribute(0,0,0)==(1,-1)
|
||||
sw.SetAttribute(5,1,4,9,40000)
|
||||
assert sw.GetAttribute(5,1,4)==(9,-25536)
|
||||
assert sw.GetAttribute(0,0,5)==(0,0) and sw.GetAttribute(-1,0,0)==(0,0)
|
||||
sw.Start(0)
|
||||
assert sw.IsActive(0)==0
|
||||
sw.Stop(0)
|
||||
)PY");
|
||||
auto packets=s.PopSendPacketsWithSequence();Bytes expected{171,37,0,0,0,0,0,1,255,255};expected.resize(37);
|
||||
require(packets.size()==2 && packets[0].first==expected && packets[1].first==Bytes{171,7,0,0,0,1,0} && packets[0].second && packets[1].second,"switchbot native-less send/sequence mismatch");
|
||||
Bytes table;u32(table,123);table.insert(table.end(),{0,0,0,0,0,2,0,0,0,0,0,255});for(unsigned i=0;i<6;++i)u32(table,100+i);
|
||||
for(unsigned i=0;i<60;++i) {table.push_back(uint8_t(i+1));u16(table,uint16_t(-int(i+1)));}
|
||||
require(table.size()==220,"literal table size");auto wire=frame(0,table);wire.push_back(44);
|
||||
s.PushRecvData(wire.data(),226);s.ProcessRecvData();python.execute("assert game.events==[]\n");s.PushRecvData(wire.data()+226,2);s.ProcessRecvData();require(s.PopSendBytes()==Bytes{254},"switchbot table consumed next ping");
|
||||
python.execute("assert sw.IsActive(5)==1 and sw.IsFinished(5)==1\nassert sw.GetAttribute(5,1,4)==(60,-60) and game.events==['window']\nsw.Stop(5)\nassert sw.IsActive(5)==1\nsw.ClearSlot(5)\nassert sw.IsActive(5)==0 and sw.IsFinished(5)==1 and sw.GetAttribute(5,1,4)==(0,0)\n");s.PopSendBytes();
|
||||
require(GetSwitchbotState().table.items[5]==0 && GetSwitchbotState().table.player_id==123,"clear slot/table state mismatch");
|
||||
TItemData item{};item.vnum=555;item.count=1;item.flags=123;SetPlayerItemData(11,5,item);
|
||||
Bytes update{5};u32(update,999);u16(update,700);for(unsigned i=0;i<8;++i)u32(update,uint32_t(-int(i+1)));for(unsigned i=0;i<15;++i){update.push_back(uint8_t(i+1));u16(update,uint16_t(-int(i+10)));}send(1,update);
|
||||
auto got=GetPlayerItemData(11,5);require(got.vnum==555 && got.count==700 && got.flags==123 && got.alSockets[7]==-8 && got.aAttr[14].bType==15 && got.aAttr[14].sValue==-24,"switchbot item update replaced vnum or lost extended arrays");
|
||||
python.execute("assert game.events[-2:]==['inventory',('item',5)]\n");
|
||||
Bytes attributes;for(int set=0;set<15;++set)attr(attributes,uint8_t(set),1,100+set);attr(attributes,0,4,40000);attr(attributes,0,257,999);send(2,attributes);
|
||||
// Load small independent prototypes to verify actual equipped-item classification.
|
||||
const std::vector<std::pair<int,int>> types{{1,0},{1,6},{36,0},{2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,8},{2,7},{28,0},{28,1},{28,2},{28,3},{0,0}};
|
||||
const int sets[]{0,-1,11,1,5,6,2,3,4,7,13,-1,1,5,6,2,-1};
|
||||
for(size_t i=0;i<types.size();++i) {
|
||||
const uint32_t id=600000+uint32_t(i);proto(root/"fixture_proto",id,uint8_t(types[i].first),uint8_t(types[i].second));python.execute("item.LoadItemTable('fixture_proto')\n");TItemData item{};item.vnum=id;SetPlayerItemData(11,0,item);
|
||||
require(GetSwitchbotState().AttributeSet(0)==sets[i],"item attribute-set classification mismatch");
|
||||
python.execute("assert sw.GetAttributeMaxValue(0,1)=="+std::to_string(sets[i]<0?0:sets[i]==0?999:100+sets[i])+"\n");
|
||||
}
|
||||
TItemData weapon{};weapon.vnum=600000;SetPlayerItemData(11,0,weapon);
|
||||
python.execute("assert sw.GetAttributesForSet(0)==[(1,999),(4,-25536)]\nassert sw.GetAttributeMaxValue(0,4)==40000\nassert sw.GetAttributesForSet(6)==[]\nsw.Start(6)\nsw.Stop(6)\nsw.Start(7)\nsw.Stop(-1)\n");packets=s.PopSendPacketsWithSequence();require(packets.size()==2 && packets[0].first==Bytes{171,37,0,0,0,0,6} && packets[1].first==Bytes{171,7,0,0,0,1,6},"slot6 header-only original quirk changed");
|
||||
send(2,{});python.execute("assert sw.GetAttributesForSet(0)==[] and sw.GetAttributeMaxValue(0,1)==0\n");
|
||||
// Original leaves unknown-subheader and short attribute tails for the dispatcher.
|
||||
send(255,{44});require(s.PopSendBytes()==Bytes{254},"unknown switchbot subheader consumed payload");send(2,{44});require(s.PopSendBytes()==Bytes{254},"attribute tail consumed");
|
||||
auto bad=frame(0,{1});bad.push_back(44);s.PushRecvData(bad);s.ProcessRecvData();require(s.PopSendBytes().empty(),"bad table consumed next packet");
|
||||
python.execute("assert sw.GetAttribute(0,0,0)==(1,-1)\ndef broken(): raise ValueError('expected failure')\ngame.RefreshSwitchbotWindow=broken\n");send(0,table);python.execute("assert sw.IsActive(5)==1\n");
|
||||
require(s.GetUnportedPackets().empty(),"switchbot still uses skip handler");s.ResetConnection();
|
||||
}
|
||||
{PythonRuntime python(argv[1],root);python.execute("import switchbot as sw\nassert sw.IsActive(5)==0 and sw.IsFinished(5)==0 and sw.GetAttribute(0,0,0)==(0,0)\n");}
|
||||
std::filesystem::remove_all(root);std::cout<<"AVA2 switchbot state, wire and Python parity passed\n";
|
||||
}catch(const std::exception& e){std::filesystem::remove_all(root);std::cerr<<e.what()<<'\n';return 1;}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// CPythonSystem / systemSetting against the original AVA2 PythonSystem.cpp + PythonSystemModule.cpp:
|
||||
// metin2.cfg parsing and the exact SaveConfig text, interface.cfg as raw little-endian int32,
|
||||
// display-mode merging, SetConfig/GetConfig and the module surface.
|
||||
#include "python_system.h"
|
||||
#include "python_runtime.h"
|
||||
#include "eter_sound/SoundManager.h"
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
using namespace ava2;
|
||||
namespace fs = std::filesystem;
|
||||
void require(bool ok,const char* why) { if(!ok)throw std::runtime_error(why); }
|
||||
std::string slurp(const fs::path& p) { std::ifstream f(p,std::ios::binary);std::stringstream s;s<<f.rdbuf();return s.str(); }
|
||||
void spit(const fs::path& p,const std::string& s) { std::ofstream f(p,std::ios::binary);f<<s; }
|
||||
int main(int argc,char** argv) {
|
||||
if(argc!=3)return 2;
|
||||
try {
|
||||
const fs::path dir=fs::temp_directory_path()/"ava2_system_setting_test";
|
||||
fs::remove_all(dir);fs::create_directories(dir);
|
||||
CPythonSystem::SetConfigDirectory(dir.string());
|
||||
auto& sys=CPythonSystem::Instance();
|
||||
|
||||
// No files: SetDefaultConfig, isInterfaceConfig false.
|
||||
sys.Reload();
|
||||
require(sys.GetWidth()==1024 && sys.GetHeight()==768 && sys.GetBPP()==32,"default resolution");
|
||||
require(!sys.isInterfaceConfig() && sys.GetShadowLevel()==3 && sys.GetSoundVolume()==5,"defaults");
|
||||
require(sys.GetFOVLevel()==30.0f && sys.GetObjectDistance()==25600.0f && !sys.IsShowOutline(),"defaults 2");
|
||||
|
||||
// metin2.cfg: case-insensitive keys, old integer MUSIC_VOLUME, SAVE_ID, a value-less line that
|
||||
// keeps the previous value buffer (sscanf leaves it), OBJECT_DIST capped, and a blank line
|
||||
// (sscanf EOF) that ends the parse.
|
||||
spit(dir/"metin2.cfg",
|
||||
"width 1280\nHEIGHT\t720\nMUSIC_VOLUME 3\nVOICE_VOLUME 4\nSHADOW_LEVEL 2\nIS_SAVE_ID 1\nSAVE_ID hero\n"
|
||||
"SHOW_OUTLINE 1\nSHOW_SHADOW\nVIEW_CHAT 2\nperspective 45.5\nshop_range 3\nOBJECT_DIST 99999\nPRE_LOADING_DELAY_TIME 7\n"
|
||||
"\nWIDTH 640\n");
|
||||
unsigned char raw[200]={};
|
||||
auto put=[&](int idx,int field,int32_t v){ for(int i=0;i<4;++i) raw[(idx*5+field)*4+i]=uint8_t(uint32_t(v)>>(i*8)); };
|
||||
put(CPythonSystem::WINDOW_CHAT,0,1);put(CPythonSystem::WINDOW_CHAT,2,-20);put(CPythonSystem::WINDOW_CHAT,4,300);
|
||||
spit(dir/"interface.cfg",std::string(reinterpret_cast<char*>(raw),sizeof(raw)));
|
||||
sys.Reload();
|
||||
require(sys.GetWidth()==1280 && sys.GetHeight()==720,"cfg resolution");
|
||||
require(std::fabs(sys.GetMusicVolume()-std::pow(10.0f,-0.4f))<1e-6f,"old music volume");
|
||||
require(sys.GetSoundVolume()==4 && sys.GetShadowLevel()==2 && sys.IsSaveID()==1,"cfg ints");
|
||||
require(std::string(sys.GetSaveID())=="hero","save id");
|
||||
require(sys.IsShowOutline() && !sys.IsViewChat(),"flags are ==1");
|
||||
require(sys.GetFOVLevel()==45.5f && sys.GetShopNamesRange()==3 && sys.GetObjectDistance()==25600.0f,"floats");
|
||||
require(g_iLoadingDelayTime==7,"loading delay");
|
||||
require(sys.IsShadow(),"value-less SHOW_SHADOW reuses the previous '1'");
|
||||
require(sys.isInterfaceConfig() && sys.GetWindowStatusReference(CPythonSystem::WINDOW_CHAT).ixPosition==-20,"interface.cfg");
|
||||
require(SoundManager::Instance().GetMusicVolume()==sys.GetMusicVolume(),"ChangeSystem music volume");
|
||||
|
||||
// Display list: <800x600 and 24 bpp dropped, refresh rates merged per resolution.
|
||||
sys.ClearDisplaySettings();
|
||||
sys.AddDisplayMode(640,480,32,60);sys.AddDisplayMode(1024,768,24,60);
|
||||
sys.AddDisplayMode(1024,768,32,60);sys.AddDisplayMode(1280,720,32,60);sys.AddDisplayMode(1280,720,32,75);
|
||||
sys.AddDisplayMode(1280,720,32,60);
|
||||
require(sys.GetResolutionCount()==2 && sys.GetFrequencyCount(1)==2 && sys.GetFrequencyCount(5)==0,"display list");
|
||||
require(sys.GetResolutionIndex(1280,720,32)==1 && sys.GetResolutionIndex(1,1,32)==0 && sys.GetFrequencyIndex(1,75)==1,"indexes");
|
||||
|
||||
PythonRuntime python(argv[1],argv[2]);
|
||||
python.execute(
|
||||
"import systemSetting as s\n"
|
||||
"assert (s.WINDOW_STATUS,s.WINDOW_MINIMAP,s.WINDOW_CHAT)==(0,8,9)\n"
|
||||
"for n in ('SetCollectEquipment','IsCollectEquipment','SetFastPickup','IsEnabledFastPickup'):\n assert not hasattr(s,n),n\n"
|
||||
"assert (s.GetWidth(),s.GetHeight())==(1280,720)\n"
|
||||
"assert s.GetCurrentResolution()==(1280,720,32)\n"
|
||||
"assert s.GetResolutionCount()==2 and s.GetResolution(1)==(1280,720,32) and s.GetResolution(9)==(0,0,0)\n"
|
||||
"assert s.GetFrequency(1,1)==75 and s.GetFrequency(1,2)==0\n"
|
||||
"assert s.GetWindowStatus(s.WINDOW_CHAT)==(1,0,-20,0,300)\n"
|
||||
"s.SaveWindowStatus(s.WINDOW_QUICK,1,1,5,6,7)\nassert s.GetWindowStatus(s.WINDOW_QUICK)==(1,1,5,6,7)\n"
|
||||
"assert s.isSaveID()==1 and s.GetSaveID()=='hero'\n"
|
||||
"s.SetSaveID(0,'other')\nassert s.GetSaveID()=='hero'\n"
|
||||
"s.SetSaveID(1,'abcdefghijklmnopqrstuvwxyz')\nassert s.GetSaveID()=='abcdefghijklmnopqrs'\n"
|
||||
"s.SetSoundVolumef(0.5)\nassert s.GetSoundVolume()==2\n"
|
||||
"s.SetMusicVolume(0.25)\nassert abs(s.GetMusicVolume()-0.25)<1e-6\n"
|
||||
"s.SetShadowLevel(0)\nassert s.GetShadowLevel()==2\n"
|
||||
"s.SetShadowLevel(9)\nassert s.GetShadowLevel()==5\n"
|
||||
"s.SetViewChatFlag(2)\nassert s.IsViewChat()==0\ns.SetViewChatFlag(1)\nassert s.IsViewChat()==1\n"
|
||||
"s.SetShowOutlineFlag(0)\nassert s.IsShowOutline()==0\n"
|
||||
"s.SetShadow(1)\nassert s.IsShadow()==1\n"
|
||||
"s.SetFOVLevel(120.0)\nassert s.GetFOVLevel()==100.0\ns.SetFOVLevel(10)\nassert s.GetFOVLevel()==30.0\n"
|
||||
"s.SetMapObjectDistance(30000.0)\nassert s.GetMapObjectDistance()==25600.0\n"
|
||||
"s.SetShopNamesRange(258)\nassert s.GetShopNamesRange()==2\n"
|
||||
"s.SetQuestIconMode(5)\nassert s.GetQuestIconMode()==1\n"
|
||||
"s.SetPetRender(0)\nassert s.GetPetRender()==0\n"
|
||||
"s.SetDungeonTrack(1)\nassert s.GetDungeonTrack()==1\n"
|
||||
"s.SetShowMobLevel(0)\nassert s.IsShowMobLevel()==0\n"
|
||||
"assert s.SetViewChatFlag('x') is None\n"
|
||||
// SetConfig keeps the old config on a bad resolution/frequency index.
|
||||
"s.SetConfig(7,0,1,3,0,1,2,1,4)\nassert s.GetCurrentResolution()==(1280,720,32)\n"
|
||||
"s.SetConfig(0,0,1,3,0,1,2,1,4)\nassert s.GetCurrentResolution()==(1024,768,32)\n"
|
||||
"assert s.IsSoftwareCursor()==1 and s.GetSoundVolume()==2\n"
|
||||
"assert abs(s.GetMusicVolume()-1.0)<1e-6\n"
|
||||
// 32-bit varargs quirk: the double music volume fills two int slots (1.0 = 0x3FF00000:0).
|
||||
"assert s.GetConfig()==(0,0,1,0,0,0x3FF00000,2,1),s.GetConfig()\n"
|
||||
"class H:\n def __init__(self):\n self.n=0\n def OnSaveInterfaceStatus(self):\n self.n+=1\n s.SaveWindowStatus(s.WINDOW_STATUS,1,0,11,12,13)\n"
|
||||
"h=H()\ns.SetInterfaceHandler(h)\n");
|
||||
sys.ApplyConfig();
|
||||
require(sys.GetAppliedGamma()==0.7f,"gamma 1 -> 0.7");
|
||||
sys.SaveInterfaceStatus();
|
||||
python.execute("assert h.n==1\ns.DestroyInterfaceHandler()\n");
|
||||
const std::string iface=slurp(dir/"interface.cfg");
|
||||
require(iface.size()==200 && iface[0]==1 && iface[8]==11 && iface[16]==13,"interface.cfg layout");
|
||||
require(uint8_t(iface[(9*5+2)*4])==0xEC && uint8_t(iface[(9*5+2)*4+3])==0xFF,"negative int32 LE");
|
||||
sys.SaveInterfaceStatus();
|
||||
python.execute("assert h.n==1\n");
|
||||
|
||||
python.execute("assert s.SaveConfig()==1\n");
|
||||
const std::string expected=
|
||||
"WIDTH\t\t\t\t\t\t1024\nHEIGHT\t\t\t\t\t\t768\nBPP\t\t\t\t\t\t32\nFREQUENCY\t\t\t\t\t60\n"
|
||||
"SOFTWARE_CURSOR\t\t\t1\nOBJECT_CULLING\t\t\t\t0\nVISIBILITY\t\t\t\t\t4\nMUSIC_VOLUME\t\t\t\t1.000\n"
|
||||
"VOICE_VOLUME\t\t\t\t2\nGAMMA\t\t\t\t\t\t1\nIS_SAVE_ID\t\t\t\t\t1\nSAVE_ID\t\t\t\t\tabcdefghijklmnopqrs\n"
|
||||
"PRE_LOADING_DELAY_TIME\t\t7\nDECOMPRESSED_TEXTURE\t\t0\n"
|
||||
"SHOW_MOBLEVEL\t\t0\n"
|
||||
"SHOW_OUTLINE\t\t\t\t0\nUSE_DEFAULT_IME\t\t0\nSOFTWARE_TILING\t\t0\nSHADOW_LEVEL\t\t\t5\n"
|
||||
"SNOW_TEXTURE_MODE\t\t\t0\nSHOW_SHADOW\t\t\t\t1\nshop_range\t2\n"
|
||||
"QUEST_LETTER\t\t\t\t1\nCOUNTRY_FLAG\t\t\t\t1\nAFFECT_ICONS\t\t\t\t1\nperspective\t30.0\n"
|
||||
"effect_level\t0\npet_status\t0\nmount_status\t1\nnpc_status\t1\nnight_mode\t0\nspecial_message\t1\n"
|
||||
"DUNGEON_TRACK\t1\nBOSS_TRACK\t0\nOBJECT_DIST\t25600.00000\n\n";
|
||||
const std::string saved=slurp(dir/"metin2.cfg");
|
||||
if(saved!=expected) { std::cerr<<saved; throw std::runtime_error("SaveConfig text"); }
|
||||
// Round trip: what SaveConfig wrote loads back to the same state.
|
||||
sys.Reload();
|
||||
require(sys.GetWidth()==1024 && sys.IsSoftwareCursor() && sys.GetShadowLevel()==5 && sys.IsShadow(),"round trip");
|
||||
require(!sys.IsShowMobLevel() && sys.GetDungeonTrack() && !sys.GetPetRender(),"round trip flags");
|
||||
|
||||
fs::remove_all(dir);
|
||||
std::cout<<"AVA2 systemSetting parity passed\n";
|
||||
} catch(const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Shared by the asset-backed tests (render_3d, mark_manager, python, window_tree).
|
||||
// They resolve original client paths ("ymir work/...", "locale/...", "mark/...")
|
||||
// against the working directory, like the Windows client root. CTest passes
|
||||
// AVA2_TEST_RUNDIR, a directory built by tools/make_test_rundir.py.
|
||||
#pragma once
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace ava2_test {
|
||||
|
||||
// CTest SKIP_RETURN_CODE: the run directory is not available.
|
||||
constexpr int kSkip = 77;
|
||||
|
||||
// Enters AVA2_TEST_RUNDIR when it is set. Returns false when it is set but
|
||||
// missing (the caller should exit kSkip); unset keeps the current directory.
|
||||
inline bool EnterTestRunDir() {
|
||||
const char* rundir = std::getenv("AVA2_TEST_RUNDIR");
|
||||
if (!rundir || !*rundir) return true;
|
||||
std::error_code ec;
|
||||
if (!std::filesystem::is_directory(rundir, ec)) {
|
||||
std::cerr << "SKIP: AVA2_TEST_RUNDIR " << rundir
|
||||
<< " missing; run tools/make_test_rundir.py" << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::filesystem::current_path(rundir, ec);
|
||||
return !ec;
|
||||
}
|
||||
|
||||
// Decoded AVA2 pack_maker tree (Maps/, property/, Sound/...). AVA2_PACK_MAKER
|
||||
// overrides the original developer path.
|
||||
inline std::string PackMaker() {
|
||||
if (const char* env = std::getenv("AVA2_PACK_MAKER"); env && *env) return env;
|
||||
return "/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker";
|
||||
}
|
||||
|
||||
} // namespace ava2_test
|
||||
@@ -63,3 +63,214 @@ static_assert(ava2::skill_constants::SKILL_GRADE_COUNT == ava2_windows_skill::SK
|
||||
static_assert(ava2::skill_constants::SKILL_GRADE_STEP_COUNT == ava2_windows_skill::SKILL_GRADE_STEP_COUNT);
|
||||
static_assert(ava2::skill_constants::SKILL_GRADEGAP == ava2_windows_skill::SKILL_GRADEGAP);
|
||||
static_assert(ava2::skill_constants::SKILL_EFFECT_COUNT == ava2_windows_skill::SKILL_EFFECT_COUNT);
|
||||
|
||||
#include "quest_state.h"
|
||||
static_assert(sizeof(ava2::TPacketGCQuestInfo)==sizeof(ava2_windows_quest::TPacketGCQuestInfo));
|
||||
static_assert(offsetof(ava2::TPacketGCQuestInfo,index)==offsetof(ava2_windows_quest::TPacketGCQuestInfo,index));
|
||||
static_assert(offsetof(ava2::TPacketGCQuestInfo,flag)==offsetof(ava2_windows_quest::TPacketGCQuestInfo,flag));
|
||||
#define QUEST_FLAG_CHECK(name) static_assert(int(ava2::name)==int(ava2_windows_quest::name))
|
||||
QUEST_FLAG_CHECK(QUEST_SEND_IS_BEGIN);QUEST_FLAG_CHECK(QUEST_SEND_TITLE);
|
||||
QUEST_FLAG_CHECK(QUEST_SEND_CLOCK_NAME);QUEST_FLAG_CHECK(QUEST_SEND_CLOCK_VALUE);
|
||||
QUEST_FLAG_CHECK(QUEST_SEND_COUNTER_NAME);QUEST_FLAG_CHECK(QUEST_SEND_COUNTER_VALUE);
|
||||
QUEST_FLAG_CHECK(QUEST_SEND_ICON_FILE);
|
||||
|
||||
#define MESSENGER_TYPE_CHECK(name) static_assert(sizeof(ava2::name)==sizeof(ava2_windows_messenger::name))
|
||||
MESSENGER_TYPE_CHECK(TPacketGCMessenger);MESSENGER_TYPE_CHECK(TPacketGCMessengerListOffline);
|
||||
MESSENGER_TYPE_CHECK(TPacketGCMessengerListOnline);MESSENGER_TYPE_CHECK(TPacketGCMessengerLogin);
|
||||
MESSENGER_TYPE_CHECK(TPacketGCMessengerLogout);
|
||||
static_assert(offsetof(ava2::TPacketGCMessenger,subheader)==offsetof(ava2_windows_messenger::TPacketGCMessenger,subheader));
|
||||
#define MESSENGER_FLAG_CHECK(name) static_assert(int(ava2::name)==int(ava2_windows_messenger::name))
|
||||
MESSENGER_FLAG_CHECK(MESSENGER_SUBHEADER_GC_LIST);MESSENGER_FLAG_CHECK(MESSENGER_SUBHEADER_GC_LOGIN);
|
||||
MESSENGER_FLAG_CHECK(MESSENGER_SUBHEADER_GC_LOGOUT);MESSENGER_FLAG_CHECK(MESSENGER_SUBHEADER_GC_INVITE);
|
||||
MESSENGER_FLAG_CHECK(MESSENGER_SUBHEADER_GC_MOBILE);
|
||||
MESSENGER_FLAG_CHECK(MESSENGER_CONNECTED_STATE_OFFLINE);MESSENGER_FLAG_CHECK(MESSENGER_CONNECTED_STATE_ONLINE);
|
||||
MESSENGER_FLAG_CHECK(MESSENGER_CONNECTED_STATE_MOBILE);
|
||||
|
||||
static_assert(sizeof(ava2::TInfoDateCubeRenewal)==sizeof(ava2_windows_cube::TInfoDateCubeRenewal));
|
||||
static_assert(sizeof(ava2::TPacketGCCubeRenewalReceive)==sizeof(ava2_windows_cube::TPacketGCCubeRenewalReceive));
|
||||
static_assert(sizeof(ava2::TPacketCGCubeRenewalSend)==sizeof(ava2_windows_cube::TPacketCGCubeRenewalSend));
|
||||
#define CUBE_FIELD_CHECK(name) static_assert(offsetof(ava2::TInfoDateCubeRenewal,name)==offsetof(ava2_windows_cube::TInfoDateCubeRenewal,name))
|
||||
CUBE_FIELD_CHECK(npc_vnum);CUBE_FIELD_CHECK(index);CUBE_FIELD_CHECK(vnum_reward);CUBE_FIELD_CHECK(count_reward);
|
||||
CUBE_FIELD_CHECK(item_reward_stackable);CUBE_FIELD_CHECK(vnum_material_1);CUBE_FIELD_CHECK(count_material_1);
|
||||
CUBE_FIELD_CHECK(vnum_material_2);CUBE_FIELD_CHECK(count_material_2);CUBE_FIELD_CHECK(vnum_material_3);CUBE_FIELD_CHECK(count_material_3);
|
||||
CUBE_FIELD_CHECK(vnum_material_4);CUBE_FIELD_CHECK(count_material_4);CUBE_FIELD_CHECK(vnum_material_5);CUBE_FIELD_CHECK(count_material_5);
|
||||
CUBE_FIELD_CHECK(gold);CUBE_FIELD_CHECK(percent);CUBE_FIELD_CHECK(category);
|
||||
#define CUBE_FLAG_CHECK(name) static_assert(int(ava2::name)==int(ava2_windows_cube::name))
|
||||
CUBE_FLAG_CHECK(CUBE_RENEWAL_SUB_HEADER_OPEN_RECEIVE);CUBE_FLAG_CHECK(CUBE_RENEWAL_SUB_HEADER_CLEAR_DATES_RECEIVE);
|
||||
CUBE_FLAG_CHECK(CUBE_RENEWAL_SUB_HEADER_DATES_RECEIVE);CUBE_FLAG_CHECK(CUBE_RENEWAL_SUB_HEADER_DATES_LOADING);
|
||||
CUBE_FLAG_CHECK(CUBE_RENEWAL_SUB_HEADER_MAKE_ITEM);CUBE_FLAG_CHECK(CUBE_RENEWAL_SUB_HEADER_CLOSE);
|
||||
|
||||
#define SEARCH_TYPE_CHECK(name) static_assert(sizeof(ava2::name)==sizeof(ava2_windows_search::name))
|
||||
SEARCH_TYPE_CHECK(TOfflineShopItemData);SEARCH_TYPE_CHECK(TPacketGCShopSearchItemSet);SEARCH_TYPE_CHECK(TPacketCGShopSearch);
|
||||
#define SEARCH_ITEM_CHECK(name) static_assert(offsetof(ava2::TOfflineShopItemData,name)==offsetof(ava2_windows_search::TOfflineShopItemData,name))
|
||||
SEARCH_ITEM_CHECK(id);SEARCH_ITEM_CHECK(vnum);SEARCH_ITEM_CHECK(price);SEARCH_ITEM_CHECK(count);SEARCH_ITEM_CHECK(display_pos);
|
||||
SEARCH_ITEM_CHECK(alSockets);SEARCH_ITEM_CHECK(aAttr);SEARCH_ITEM_CHECK(status);SEARCH_ITEM_CHECK(szBuyerName);SEARCH_ITEM_CHECK(owner_id);
|
||||
#define SEARCH_REQUEST_CHECK(name) static_assert(offsetof(ava2::TPacketCGShopSearch,name)==offsetof(ava2_windows_search::TPacketCGShopSearch,name))
|
||||
SEARCH_REQUEST_CHECK(ItemCat);SEARCH_REQUEST_CHECK(SubCat);SEARCH_REQUEST_CHECK(searchInput);SEARCH_REQUEST_CHECK(avg);
|
||||
SEARCH_REQUEST_CHECK(skill);SEARCH_REQUEST_CHECK(abs);SEARCH_REQUEST_CHECK(level);SEARCH_REQUEST_CHECK(refine);
|
||||
SEARCH_REQUEST_CHECK(sex);SEARCH_REQUEST_CHECK(enchant);SEARCH_REQUEST_CHECK(alchemy);SEARCH_REQUEST_CHECK(character);SEARCH_REQUEST_CHECK(price);
|
||||
|
||||
#define GUILD_TYPE_CHECK(type) static_assert(sizeof(ava2::type)==sizeof(ava2_windows_guild::type))
|
||||
GUILD_TYPE_CHECK(TPacketGCGuild);GUILD_TYPE_CHECK(TPacketGCGuildSubGrade);GUILD_TYPE_CHECK(TPacketGCGuildSubMember);
|
||||
GUILD_TYPE_CHECK(TPacketGCGuildInfo);GUILD_TYPE_CHECK(TPacketGCGuildWar);GUILD_TYPE_CHECK(TPacketGuildWarPoint);
|
||||
#define GUILD_FIELD(type,field) static_assert(offsetof(ava2::type,field)==offsetof(ava2_windows_guild::type,field))
|
||||
GUILD_FIELD(TPacketGCGuildSubGrade,auth_flag);GUILD_FIELD(TPacketGCGuildSubMember,dwOffer);GUILD_FIELD(TPacketGCGuildSubMember,byNameFlag);
|
||||
GUILD_FIELD(TPacketGCGuildInfo,guild_id);GUILD_FIELD(TPacketGCGuildInfo,name);GUILD_FIELD(TPacketGCGuildInfo,gold);GUILD_FIELD(TPacketGCGuildInfo,hasLand);
|
||||
GUILD_FIELD(TPacketGCGuildWar,bWarState);GUILD_FIELD(TPacketGuildWarPoint,lPoint);
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_LOGIN)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_LOGIN));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_LOGOUT)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_LOGOUT));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_LIST)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_LIST));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_GRADE)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_GRADE));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_ADD)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_ADD));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_REMOVE)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_REMOVE));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_GRADE_NAME)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_GRADE_NAME));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_GRADE_AUTH)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_GRADE_AUTH));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_INFO)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_INFO));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_COMMENTS)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_COMMENTS));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_CHANGE_EXP)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_CHANGE_EXP));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_CHANGE_MEMBER_GRADE)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_CHANGE_MEMBER_GRADE));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_SKILL_INFO)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_SKILL_INFO));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_CHANGE_MEMBER_GENERAL)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_CHANGE_MEMBER_GENERAL));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_GUILD_INVITE)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_GUILD_INVITE));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_WAR)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_WAR));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_GUILD_NAME)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_GUILD_NAME));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_GUILD_WAR_LIST)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_GUILD_WAR_LIST));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_GUILD_WAR_END_LIST)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_GUILD_WAR_END_LIST));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_WAR_POINT)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_WAR_POINT));
|
||||
static_assert(int(ava2::GUILD_SUBHEADER_GC_MONEY_CHANGE)==int(ava2_windows_guild::GUILD_SUBHEADER_GC_MONEY_CHANGE));
|
||||
static_assert(int(ava2::GUILD_AUTH_ADD_MEMBER)==int(ava2_windows_guild::GUILD_AUTH_ADD_MEMBER));
|
||||
static_assert(int(ava2::GUILD_AUTH_REMOVE_MEMBER)==int(ava2_windows_guild::GUILD_AUTH_REMOVE_MEMBER));
|
||||
static_assert(int(ava2::GUILD_AUTH_NOTICE)==int(ava2_windows_guild::GUILD_AUTH_NOTICE));
|
||||
static_assert(int(ava2::GUILD_AUTH_SKILL)==int(ava2_windows_guild::GUILD_AUTH_SKILL));
|
||||
static_assert(int(ava2::GUILD_WAR_NONE)==int(ava2_windows_guild::GUILD_WAR_NONE));
|
||||
static_assert(int(ava2::GUILD_WAR_SEND_DECLARE)==int(ava2_windows_guild::GUILD_WAR_SEND_DECLARE));
|
||||
static_assert(int(ava2::GUILD_WAR_REFUSE)==int(ava2_windows_guild::GUILD_WAR_REFUSE));
|
||||
static_assert(int(ava2::GUILD_WAR_RECV_DECLARE)==int(ava2_windows_guild::GUILD_WAR_RECV_DECLARE));
|
||||
static_assert(int(ava2::GUILD_WAR_WAIT_START)==int(ava2_windows_guild::GUILD_WAR_WAIT_START));
|
||||
static_assert(int(ava2::GUILD_WAR_CANCEL)==int(ava2_windows_guild::GUILD_WAR_CANCEL));
|
||||
static_assert(int(ava2::GUILD_WAR_ON_WAR)==int(ava2_windows_guild::GUILD_WAR_ON_WAR));
|
||||
static_assert(int(ava2::GUILD_WAR_END)==int(ava2_windows_guild::GUILD_WAR_END));
|
||||
static_assert(int(ava2::GUILD_WAR_DURATION)==int(ava2_windows_guild::GUILD_WAR_DURATION));
|
||||
|
||||
#define BATTLE_TYPE(type) static_assert(sizeof(ava2::type)==sizeof(ava2_windows_battlepass::type))
|
||||
BATTLE_TYPE(TInfoBattlePassItem);BATTLE_TYPE(TInfoBattlePass);BATTLE_TYPE(TPacketGCBattlePass);BATTLE_TYPE(TPacketCGBattlePass);
|
||||
static_assert(offsetof(ava2::TInfoBattlePass,items)==offsetof(ava2_windows_battlepass::TInfoBattlePass,data_item));
|
||||
#define BATTLE_FIELD(type,field) static_assert(offsetof(ava2::type,field)==offsetof(ava2_windows_battlepass::type,field))
|
||||
BATTLE_FIELD(TPacketGCBattlePass,time);BATTLE_FIELD(TPacketGCBattlePass,data);BATTLE_FIELD(TPacketCGBattlePass,index);
|
||||
BATTLE_FIELD(TInfoBattlePass,count);BATTLE_FIELD(TInfoBattlePass,count_actual);BATTLE_FIELD(TInfoBattlePass,reward_status);
|
||||
static_assert(int(ava2::BATTLEPASS_SUB_HEADER_OPEN)==int(ava2_windows_battlepass::BATTLEPASS_SUB_HEADER_OPEN));
|
||||
static_assert(int(ava2::BATTLEPASS_SUB_HEADER_CLEAR)==int(ava2_windows_battlepass::BATTLEPASS_SUB_HEADER_CLEAR));
|
||||
static_assert(int(ava2::BATTLEPASS_SUB_HEADER_INFO)==int(ava2_windows_battlepass::BATTLEPASS_SUB_HEADER_INFO));
|
||||
static_assert(int(ava2::BATTLEPASS_SUB_HEADER_INFO_EXTRA)==int(ava2_windows_battlepass::BATTLEPASS_SUB_HEADER_INFO_EXTRA));
|
||||
static_assert(int(ava2::BATTLEPASS_SUB_HEADER_LOADING)==int(ava2_windows_battlepass::BATTLEPASS_SUB_HEADER_LOADING));
|
||||
static_assert(int(ava2::BATTLEPASS_SUB_HEADER_REWARD)==int(ava2_windows_battlepass::BATTLEPASS_SUB_HEADER_REWARD));
|
||||
static_assert(int(ava2::BATTLEPASS_SUB_HEADER_UPDATE_CLEAR)==int(ava2_windows_battlepass::BATTLEPASS_SUB_HEADER_UPDATE_CLEAR));
|
||||
static_assert(int(ava2::BATTLEPASS_SUB_HEADER_UPDATE)==int(ava2_windows_battlepass::BATTLEPASS_SUB_HEADER_UPDATE));
|
||||
static_assert(int(ava2::BATTLEPASS_SUB_HEADER_UPDATE_LOADING)==int(ava2_windows_battlepass::BATTLEPASS_SUB_HEADER_UPDATE_LOADING));
|
||||
static_assert(int(ava2::BATTLEPASS_SUB_HEADER_MP)==int(ava2_windows_battlepass::BATTLEPASS_SUB_HEADER_MP));
|
||||
|
||||
#define DROP_TYPE(type) static_assert(sizeof(ava2::type)==sizeof(ava2_windows_drop::type))
|
||||
DROP_TYPE(TInfoDropItemSystem);DROP_TYPE(TPacketGCDropItemReceive);DROP_TYPE(TPacketCGDropItemSend);
|
||||
#define DROP_FIELD(type,field) static_assert(offsetof(ava2::type,field)==offsetof(ava2_windows_drop::type,field))
|
||||
DROP_FIELD(TInfoDropItemSystem,id_mob);DROP_FIELD(TInfoDropItemSystem,prob_item);DROP_FIELD(TInfoDropItemSystem,count_item);
|
||||
DROP_FIELD(TPacketGCDropItemReceive,info_drop);DROP_FIELD(TPacketCGDropItemSend,vnum_item);
|
||||
static_assert(int(ava2::DROP_ITEM_SUB_HEADER_OPEN)==int(ava2_windows_drop::DROP_ITEM_SUB_HEADER_OPEN));
|
||||
static_assert(int(ava2::DROP_ITEM_SUB_HEADER_SEARCH)==int(ava2_windows_drop::DROP_ITEM_SUB_HEADER_SEARCH));
|
||||
static_assert(int(ava2::DROP_ITEM_SUB_HEADER_OPEN_RECEIVE)==int(ava2_windows_drop::DROP_ITEM_SUB_HEADER_OPEN_RECEIVE));
|
||||
static_assert(int(ava2::DROP_ITEM_SUB_HEADER_DATES_RECEIVE)==int(ava2_windows_drop::DROP_ITEM_SUB_HEADER_DATES_RECEIVE));
|
||||
static_assert(int(ava2::DROP_ITEM_SUB_HEADER_DATES_CLEAR_RECEIVE)==int(ava2_windows_drop::DROP_ITEM_SUB_HEADER_DATES_CLEAR_RECEIVE));
|
||||
static_assert(int(ava2::DROP_ITEM_SUB_HEADER_DATES_LOADING)==int(ava2_windows_drop::DROP_ITEM_SUB_HEADER_DATES_LOADING));
|
||||
|
||||
#define DUNGEON_TYPE(type) static_assert(sizeof(ava2::type)==sizeof(ava2_windows_dungeon::type))
|
||||
DUNGEON_TYPE(TFDateInfoPacket);DUNGEON_TYPE(TFDateInfoRanking);DUNGEON_TYPE(TFDateMision);DUNGEON_TYPE(TPacketGCDungeonInfoReceive);
|
||||
static_assert(sizeof(ava2::TPacketCGDungeonInfo)==sizeof(ava2_windows_dungeon::TPacketCGDungeonInfoSend));
|
||||
static_assert(offsetof(ava2::TFDateInfoPacket,id)==offsetof(ava2_windows_dungeon::TFDateInfoPacket,id_dungeon));
|
||||
#define DUNGEON_FIELD(type,field) static_assert(offsetof(ava2::type,field)==offsetof(ava2_windows_dungeon::type,field))
|
||||
DUNGEON_FIELD(TFDateInfoPacket,name);DUNGEON_FIELD(TFDateInfoPacket,respawn);DUNGEON_FIELD(TFDateInfoPacket,entrance);DUNGEON_FIELD(TFDateInfoPacket,id_boss);
|
||||
DUNGEON_FIELD(TFDateInfoRanking,name_r);DUNGEON_FIELD(TFDateInfoRanking,extra_r);DUNGEON_FIELD(TFDateMision,status_mision);
|
||||
DUNGEON_FIELD(TPacketGCDungeonInfoReceive,dateinfo);DUNGEON_FIELD(TPacketGCDungeonInfoReceive,dateinfo_ranking);DUNGEON_FIELD(TPacketGCDungeonInfoReceive,dateinfom);
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_OPEN)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_OPEN));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_TELEPORT)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_TELEPORT));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_MISION)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_MISION));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_OPEN_SEND)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_OPEN_SEND));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_DATES_SEND)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_DATES_SEND));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_DATES_CLEAR)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_DATES_CLEAR));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_DATES_RANKING_CLEAR)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_DATES_RANKING_CLEAR));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_DATES_RANKING_SEND)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_DATES_RANKING_SEND));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_DATES_RANKING_LOAD)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_DATES_RANKING_LOAD));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_RANKING)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_RANKING));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_DATES_MISION_CLEAR)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_DATES_MISION_CLEAR));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_DATES_MISION_SEND)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_DATES_MISION_SEND));
|
||||
static_assert(int(ava2::DUNGEON_INFO_SUB_HEADER_DATES_MISION_LOAD)==int(ava2_windows_dungeon::DUNGEON_INFO_SUB_HEADER_DATES_MISION_LOAD));
|
||||
|
||||
#define SWITCH_TYPE(type) static_assert(sizeof(ava2::type)==sizeof(ava2_windows_switchbot::type))
|
||||
SWITCH_TYPE(TPacketCGSwitchbot);SWITCH_TYPE(TPacketGCSwitchbot);SWITCH_TYPE(TSwitchbotUpdateItem);SWITCH_TYPE(TSwitchbotTable);SWITCH_TYPE(TSwitchbotAttributeAlternativeTable);
|
||||
static_assert(sizeof(ava2::TSwitchbotAttributeTable)==sizeof(ava2_windows_switchbot::TSwitchbottAttributeTable));
|
||||
#define SWITCH_FIELD(type,field) static_assert(offsetof(ava2::type,field)==offsetof(ava2_windows_switchbot::type,field))
|
||||
SWITCH_FIELD(TSwitchbotTable,active);SWITCH_FIELD(TSwitchbotTable,finished);SWITCH_FIELD(TSwitchbotTable,items);SWITCH_FIELD(TSwitchbotTable,alternatives);
|
||||
SWITCH_FIELD(TSwitchbotUpdateItem,alSockets);SWITCH_FIELD(TSwitchbotUpdateItem,aAttr);SWITCH_FIELD(TPacketGCSwitchbot,size);SWITCH_FIELD(TPacketGCSwitchbot,slot);
|
||||
static_assert(int(ava2::SWITCHBOT_SLOT_COUNT)==int(ava2_windows_switchbot::SWITCHBOT_SLOT_COUNT));
|
||||
static_assert(int(ava2::SWITCHBOT_SLOT_COUNT_REAL)==int(ava2_windows_switchbot::SWITCHBOT_SLOT_COUNT_REAL));
|
||||
static_assert(int(ava2::SWITCHBOT_ALTERNATIVE_COUNT)==int(ava2_windows_switchbot::SWITCHBOT_ALTERNATIVE_COUNT));
|
||||
static_assert(int(ava2::MAX_NORM_ATTR_NUM)==int(ava2_windows_switchbot::MAX_NORM_ATTR_NUM));
|
||||
static_assert(int(ava2::SUBHEADER_CG_SWITCHBOT_START)==int(ava2_windows_switchbot::SUBHEADER_CG_SWITCHBOT_START));
|
||||
static_assert(int(ava2::SUBHEADER_CG_SWITCHBOT_STOP)==int(ava2_windows_switchbot::SUBHEADER_CG_SWITCHBOT_STOP));
|
||||
static_assert(int(ava2::SUBHEADER_GC_SWITCHBOT_UPDATE)==int(ava2_windows_switchbot::SUBHEADER_GC_SWITCHBOT_UPDATE));
|
||||
static_assert(int(ava2::SUBHEADER_GC_SWITCHBOT_UPDATE_ITEM)==int(ava2_windows_switchbot::SUBHEADER_GC_SWITCHBOT_UPDATE_ITEM));
|
||||
static_assert(int(ava2::SUBHEADER_GC_SWITCHBOT_SEND_ATTRIBUTE_INFORMATION)==int(ava2_windows_switchbot::SUBHEADER_GC_SWITCHBOT_SEND_ATTRIBUTE_INFORMATION));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_WEAPON)==int(ava2_windows_switchbot::ATTRIBUTE_SET_WEAPON));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_BODY)==int(ava2_windows_switchbot::ATTRIBUTE_SET_BODY));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_WRIST)==int(ava2_windows_switchbot::ATTRIBUTE_SET_WRIST));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_FOOTS)==int(ava2_windows_switchbot::ATTRIBUTE_SET_FOOTS));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_NECK)==int(ava2_windows_switchbot::ATTRIBUTE_SET_NECK));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_HEAD)==int(ava2_windows_switchbot::ATTRIBUTE_SET_HEAD));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_SHIELD)==int(ava2_windows_switchbot::ATTRIBUTE_SET_SHIELD));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_EAR)==int(ava2_windows_switchbot::ATTRIBUTE_SET_EAR));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_COSTUME_BODY)==int(ava2_windows_switchbot::ATTRIBUTE_SET_COSTUME_BODY));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_COSTUME_HEAD)==int(ava2_windows_switchbot::ATTRIBUTE_SET_COSTUME_HEAD));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_COSTUME_WEAPON)==int(ava2_windows_switchbot::ATTRIBUTE_SET_COSTUME_WEAPON));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_NEW_RINGS)==int(ava2_windows_switchbot::ATTRIBUTE_SET_NEW_RINGS));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_GLOVE)==int(ava2_windows_switchbot::ATTRIBUTE_SET_GLOVE));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_PENDANT)==int(ava2_windows_switchbot::ATTRIBUTE_SET_PENDANT));
|
||||
static_assert(int(ava2::ATTRIBUTE_SET_MAX_NUM)==int(ava2_windows_switchbot::ATTRIBUTE_SET_MAX_NUM));
|
||||
|
||||
#define ISHOP_TYPE(type) static_assert(sizeof(ava2::type)==sizeof(ava2_windows_itemshop::type))
|
||||
ISHOP_TYPE(TIShopData);ISHOP_TYPE(TIShopLogData);ISHOP_TYPE(TPacketGCItemShop);
|
||||
#define ISHOP_FIELD(type,field) static_assert(offsetof(ava2::type,field)==offsetof(ava2_windows_itemshop::type,field))
|
||||
ISHOP_FIELD(TIShopData,itemPrice);ISHOP_FIELD(TIShopData,discount);ISHOP_FIELD(TIShopData,offerTime);ISHOP_FIELD(TIShopData,sellCount);ISHOP_FIELD(TIShopData,maxSellCount);
|
||||
ISHOP_FIELD(TIShopLogData,playerName);ISHOP_FIELD(TIShopLogData,buyDate);ISHOP_FIELD(TIShopLogData,buyTime);ISHOP_FIELD(TIShopLogData,ipAdress);ISHOP_FIELD(TIShopLogData,itemPrice);
|
||||
static_assert(int(ava2::ITEMSHOP_LOAD)==int(ava2_windows_itemshop::ITEMSHOP_LOAD));
|
||||
static_assert(int(ava2::ITEMSHOP_LOG)==int(ava2_windows_itemshop::ITEMSHOP_LOG));
|
||||
static_assert(int(ava2::ITEMSHOP_BUY)==int(ava2_windows_itemshop::ITEMSHOP_BUY));
|
||||
static_assert(int(ava2::ITEMSHOP_DRAGONCOIN)==int(ava2_windows_itemshop::ITEMSHOP_DRAGONCOIN));
|
||||
static_assert(int(ava2::ITEMSHOP_RELOAD)==int(ava2_windows_itemshop::ITEMSHOP_RELOAD));
|
||||
static_assert(int(ava2::ITEMSHOP_LOG_ADD)==int(ava2_windows_itemshop::ITEMSHOP_LOG_ADD));
|
||||
static_assert(int(ava2::ITEMSHOP_UPDATE_ITEM)==int(ava2_windows_itemshop::ITEMSHOP_UPDATE_ITEM));
|
||||
|
||||
#define OFFLINE_TYPE_CHECK(name) static_assert(sizeof(ava2::name)==sizeof(ava2_windows_offline_shop::name))
|
||||
OFFLINE_TYPE_CHECK(TPacketGCShop);OFFLINE_TYPE_CHECK(TShopLog);OFFLINE_TYPE_CHECK(TShopDecoration);
|
||||
OFFLINE_TYPE_CHECK(TOfflineShopItemTable);OFFLINE_TYPE_CHECK(TPacketCGMyOfflineShop);
|
||||
OFFLINE_TYPE_CHECK(TPacketGCOfflineShopStart);OFFLINE_TYPE_CHECK(TPacketGCOfflineShopUpdateItem);
|
||||
#define OFFLINE_ENUM_CHECK(name) static_assert(int(ava2::name)==int(ava2_windows_offline_shop::name))
|
||||
OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_START);OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_END);
|
||||
OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_UPDATE_ITEM);OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY);
|
||||
OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_SOLD_OUT);OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_INVENTORY_FULL);
|
||||
OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_INVALID_POS);OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_REFRESH_MONEY);
|
||||
OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_CHECK_RESULT);OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_REFRESH_DISPLAY_COUNT);
|
||||
OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_REALWATCHER_COUNT);OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_REFRESH_COUNT);
|
||||
OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_CHANGE_TITLE);OFFLINE_ENUM_CHECK(SHOP_SUBHEADER_GC_NOT_ENOUGH_LUCKY);
|
||||
#define OFFLINE_OFFSET_CHECK(type,field) static_assert(offsetof(ava2::type,field)==offsetof(ava2_windows_offline_shop::type,field))
|
||||
OFFLINE_OFFSET_CHECK(TPacketGCOfflineShopStart,items);OFFLINE_OFFSET_CHECK(TPacketGCOfflineShopStart,title);
|
||||
OFFLINE_OFFSET_CHECK(TPacketGCOfflineShopStart,log);OFFLINE_OFFSET_CHECK(TPacketGCOfflineShopStart,flag);
|
||||
OFFLINE_OFFSET_CHECK(TPacketGCOfflineShopStart,IsOwner);OFFLINE_OFFSET_CHECK(TPacketGCOfflineShopUpdateItem,item);
|
||||
OFFLINE_OFFSET_CHECK(TPacketGCOfflineShopUpdateItem,title);OFFLINE_OFFSET_CHECK(TPacketGCOfflineShopUpdateItem,price);
|
||||
OFFLINE_OFFSET_CHECK(TPacketGCOfflineShopUpdateItem,log);OFFLINE_OFFSET_CHECK(TOfflineShopItemTable,price);
|
||||
OFFLINE_OFFSET_CHECK(TPacketCGMyOfflineShop,shopVnum);OFFLINE_OFFSET_CHECK(TShopDecoration,vnum);
|
||||
|
||||
#include "item_sound.h"
|
||||
#define ITEM_SOUND_ENUM_CHECK(name) static_assert(int(ava2::name)==int(ava2_windows_item_sound::name))
|
||||
ITEM_SOUND_ENUM_CHECK(USESOUND_NONE);ITEM_SOUND_ENUM_CHECK(USESOUND_DEFAULT);ITEM_SOUND_ENUM_CHECK(USESOUND_ARMOR);
|
||||
ITEM_SOUND_ENUM_CHECK(USESOUND_WEAPON);ITEM_SOUND_ENUM_CHECK(USESOUND_BOW);ITEM_SOUND_ENUM_CHECK(USESOUND_ACCESSORY);
|
||||
ITEM_SOUND_ENUM_CHECK(USESOUND_POTION);ITEM_SOUND_ENUM_CHECK(USESOUND_PORTAL);ITEM_SOUND_ENUM_CHECK(USESOUND_NUM);
|
||||
ITEM_SOUND_ENUM_CHECK(DROPSOUND_DEFAULT);ITEM_SOUND_ENUM_CHECK(DROPSOUND_ARMOR);ITEM_SOUND_ENUM_CHECK(DROPSOUND_WEAPON);
|
||||
ITEM_SOUND_ENUM_CHECK(DROPSOUND_BOW);ITEM_SOUND_ENUM_CHECK(DROPSOUND_ACCESSORY);ITEM_SOUND_ENUM_CHECK(DROPSOUND_NUM);
|
||||
|
||||
Reference in New Issue
Block a user