Files
metin2-client/tests/port/port_login_flow_test.cpp
T

2233 lines
122 KiB
C++

// 批次 2V1-d/2V2: the real 40250 login → select → loading → game path, offline.
//
// The 40250 root scripts (intrologin.py, introselect.py, introloading.py, networkmodule.py) drive the
// ported CPythonNetworkStream and CAccountConnector against FakeLoginServer (port_login_flow_server.h),
// which answers the way the 40250 game server does. The test only plays the player:
//
// 1. frames advance the logo phase into introLogin.LoginWindow;
// 2. LoginWindow.Connect(id, pwd) → net.ConnectToAccountServer: handshake + key agreement with the
// auth server, CG_LOGIN3, GC_AUTH_SUCCESS; the account connector hands the login key to the stream,
// which connects to the game server and sends CG_LOGIN2;
// 3. GC_EMPIRE, PHASE_SELECT, GC_LOGIN_SUCCESS_NEWSLOT open introSelect.SelectCharacterWindow;
// 4. SelectCharacterWindow.StartGame() → (3 s later) net.DirectEnter(0): the stream reconnects to the
// slot's addr/port, logs in again, and in direct-enter mode the select phase goes straight to
// introLoading.LoadingWindow, which sends CG_CHARACTER_SELECT;
// 5. PHASE_LOADING, GC_MAIN_CHARACTER, GC_CHARACTER_POINTS: the loading phase answers the main
// character with CG_CLIENT_VERSION(2), the server's proof the client reached Loading;
// 6. (批次 2V2) the loading steps end in net.StartGame(): networkModule.SetGamePhase opens
// game.GameWindow, whose Open sends CG_ENTERGAME;
// 7. the server's Entergame answer (the actor's insert packets, PHASE_GAME, the Entergame burst) is
// read by the ported GamePhase without an unknown packet, and a final ping gets its pong.
//
// The server checks every sequence byte against the 40250 table, so a skipped or extra sequenced
// packet fails the run.
//
// port_login_flow_test <40250 Client dir> <python27.zip> [live]
//
// With `live` (批次 2V1-e, ctest port.login_live) the same path runs against a real 40250 server and
// the client's own state is the proof: the character list arrived, the loading window got
// LoadData from GC_MAIN_CHARACTER, which CPythonNetworkStream::RecvMainCharacter answers with
// CG_CLIENT_VERSION, game.GameWindow is open, which sent CG_ENTERGAME, and 10 s of the real game
// phase later it is still open and connected with no unknown packet. Everything about the
// server comes from the environment and nothing of it is printed:
//
// MT_LIVE_HOST, MT_LIVE_LOGIN, MT_LIVE_PASSWORD required; without them the test is skipped
// MT_LIVE_AUTH_PORT (11000), MT_LIVE_GAME_PORT (13000, channel 1), MT_LIVE_SLOT (0)
//
// Exit 77 (ctest SKIP) when the client is missing, unless MT_ASSETS_STRICT=1, which fails instead.
#include "ScriptLib/StdAfx.h"
#include "../../src/platform/ScriptLib/PythonBoot.h"
#define MT_NATIVE_HAS_LIVE_CLIENT 1
#include "../../src/host/touch_controller.h"
#include "../../src/platform/ScriptLib/PythonHost.h"
#include "../../src/platform/UserInterface/ServerClock.h"
#include "../../src/platform/UserInterface/UserInterface.h"
#include "../../src/platform/EterBase/TraceErrorObserver.h"
#include "../../src/platform/EterLib/RenderCommands3D.h"
#include "GameLib/StdAfx.h"
#include "GameLib/RaceManager.h"
#include "GameLib/RaceData.h"
#include "GameLib/RaceMotionData.h"
#include "GameLib/FlyingData.h"
#include "GameLib/FlyingObjectManager.h"
#include "EffectLib/EffectManager.h"
#include "EffectLib/EffectInstance.h"
#include "EterLib/Camera.h"
#include "GameLib/ItemManager.h"
#include "UserInterface/PythonItem.h"
#include "UserInterface/StdAfx.h"
#include "UserInterface/PythonNetworkStream.h"
#include "UserInterface/PythonPlayer.h"
#include "UserInterface/PythonExchange.h"
#include "UserInterface/PythonTextTail.h"
#include "UserInterface/PythonCharacterManager.h"
#include "UserInterface/InstanceBase.h"
#include "UserInterface/PythonBackground.h"
#include "UserInterface/PythonMessenger.h"
#include "UserInterface/PythonGuild.h"
#include "UserInterface/MarkManager.h"
#include "UserInterface/PythonSystem.h"
#include "MilesLib/SoundManager.h"
#include "EterGrnLib/StdAfx.h"
#include "EterGrnLib/LODController.h"
#include "EterGrnLib/ModelInstance.h"
#include "EterGrnLib/Model.h"
#include "port_login_flow_server.h"
#include <memory>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
#include <unistd.h>
static int g_failures = 0;
#define CHECK(cond) \
do { \
if (!(cond)) { \
std::fprintf(stderr, "%s:%d: CHECK(%s)\n", __FILE__, __LINE__, #cond); \
++g_failures; \
} \
} while (0)
// TraceError lines; the script thread writes them while the host thread waits for its baton.
static std::mutex g_syserr_mutex;
static std::vector<std::string> g_syserr;
// The two headers CheckPacket saw last (UserInterface/PythonNetworkStream.cpp).
extern int g_iLastPacket[2];
// CPythonNetworkStream::RecvDefaultPacket's CP949 "unhandled packet header %d, state %s": a phase
// dispatcher dropped the whole recv buffer.
static const char kUnhandledPacket[] = "\xc3\xb3\xb8\xae\xb5\xc7\xc1\xf6 \xbe\xca\xc0\xba \xc6\xd0\xc5\xb6 \xc7\xec\xb4\xf5";
static void on_trace_error(const char* line)
{
std::lock_guard<std::mutex> lock(g_syserr_mutex);
g_syserr.emplace_back(line);
// RecvDefaultPacket does not print the preceding headers; the packet before a stray header is
// the one whose size disagrees with the server.
if (std::string(line).find(kUnhandledPacket) != std::string::npos)
std::fprintf(stderr, "port_login_flow_test: unhandled packet after headers %d, %d\n", g_iLastPacket[0], g_iLastPacket[1]);
}
static int count_syserr(const char* needle)
{
std::lock_guard<std::mutex> lock(g_syserr_mutex);
int n = 0;
for (const auto& line : g_syserr)
n += line.find(needle) != std::string::npos;
return n;
}
static bool py(const std::string& source)
{
std::string error;
std::string code = source;
if (std::getenv("MT_TEST_WIKI")) {
code = "# -*- coding: utf-8 -*-\ntry:\n";
size_t start=0;
while (start<source.size()) {
size_t end=source.find('\n',start);
if (end==std::string::npos) end=source.size();
code += " "+source.substr(start,end-start)+"\n";
start=end+1;
}
code += "except BaseException as _wiki_error:\n import sys\n sys.stderr.write('wiki integration error: '+repr(_wiki_error)+'\\n')\n raise\n";
}
if (PythonBoot::RunLine(code.c_str(), &error))
return true;
std::fprintf(stderr, "python: %s\n%s\n", source.c_str(), error.c_str());
return false;
}
// Evaluates a Python expression on the host thread without raising.
static bool py_true(const char* expression)
{
PyObject* globals = PyModule_GetDict(PyImport_AddModule((char*) "__main__"));
PyObject* result = PyRun_String(expression, Py_eval_input, globals, globals);
if (!result)
{
PyErr_Clear();
return false;
}
const bool truth = PyObject_IsTrue(result) == 1;
Py_DECREF(result);
return truth;
}
// Runs frames (~60 per second of wall time) until `done` or the deadline.
static bool pump_until(double seconds, const std::function<bool()>& done)
{
const auto deadline = std::chrono::steady_clock::now() + std::chrono::duration<double>(seconds);
while (std::chrono::steady_clock::now() < deadline && PythonBoot::IsAppLooping())
{
PythonBoot::UIUpdate();
if (done())
return true;
std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
return done();
}
// Runs a fixed number of frames: the wait between a mouse move and its click must not depend on how
// many frames a loaded machine fits into a wall-clock slice (ctest -j).
// CPythonNetworkStream::GamePhase (40250) refreshes the inventory/safebox windows at most every 300 ms,
// so a slot can still be empty in the UI after player/safebox state already holds the item.
static void pump_ui_refresh()
{
pump_until(0.35, [] { return false; });
}
static void pump_frames(int count)
{
for (int i = 0; i < count && PythonBoot::IsAppLooping(); ++i)
{
PythonBoot::UIUpdate();
std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
}
static void dump(FakeLoginServer& server)
{
std::fprintf(stderr, "server events:");
for (const auto& e : server.Events())
std::fprintf(stderr, " %s", e.c_str());
std::fprintf(stderr, "\nserver error: %s\n", server.Error().c_str());
}
static std::string env(const char* name, const char* fallback = "")
{
const char* value = std::getenv(name);
return value && *value ? value : fallback;
}
// Hands a C string to __main__ as a Python object, so account data never goes through source text.
static void py_set(const char* name, const std::string& value)
{
PyObject* object = PyString_FromString(value.c_str());
PyDict_SetItemString(PyModule_GetDict(PyImport_AddModule((char*) "__main__")), name, object);
Py_DECREF(object);
}
int main(int argc, char** argv)
{
const char* strict = std::getenv("MT_ASSETS_STRICT");
const bool is_strict = strict && std::string(strict) == "1";
const std::string client = argc > 1 ? argv[1] : "";
const std::string stdlib = argc > 2 ? argv[2] : PythonHost::DefaultStdLibPath();
const bool live = argc > 3 && std::string(argv[3]) == "live";
if (client.empty() || chdir(client.c_str()) != 0 || access("pack/Index", 0) != 0)
{
std::fprintf(stderr, "port_login_flow_test: no 40250 Client/pack at '%s'\n", client.c_str());
return is_strict ? 1 : 77;
}
std::string host = "127.0.0.1", login = FakeLoginServer::kLogin, password = FakeLoginServer::kPassword;
int auth_port = 0, game_port = 0, slot = 0;
std::unique_ptr<FakeLoginServer> server;
if (live)
{
host = env("MT_LIVE_HOST");
login = env("MT_LIVE_LOGIN");
password = env("MT_LIVE_PASSWORD");
if (host.empty() || login.empty() || password.empty())
{
std::fprintf(stderr, "port_login_flow_test: live mode needs MT_LIVE_HOST, MT_LIVE_LOGIN, MT_LIVE_PASSWORD\n");
return 77;
}
auth_port = std::atoi(env("MT_LIVE_AUTH_PORT", "11000").c_str());
game_port = std::atoi(env("MT_LIVE_GAME_PORT", "13000").c_str());
slot = std::atoi(env("MT_LIVE_SLOT", "0").c_str());
}
else
{
server = std::make_unique<FakeLoginServer>();
if (!server->Start())
{
std::fprintf(stderr, "port_login_flow_test: cannot listen on loopback\n");
return 1;
}
auth_port = server->AuthPort();
game_port = server->GamePort();
}
auto failed = [&] { return server && server->Failed(); };
SetTraceErrorObserver(on_trace_error);
PackSingletons();
CHECK(PackInitialize("pack"));
std::string error;
const bool started = PythonBoot::Start(stdlib.c_str(), &error);
if (!started)
std::fprintf(stderr, "PythonBoot::Start: %s\n", error.c_str());
CHECK(started);
// 40250 keeps a server-supplied base plus local elapsed time. Check both units before the
// fake server's GC_TIME packet replaces this base during the game phase.
SetPlatformServerTime(123456789);
CHECK(GetPlatformServerTime() >= 123456789 && GetPlatformServerTime() < 123457789);
CHECK(GetPlatformServerTimeStamp() >= 123456789 && GetPlatformServerTimeStamp() <= 123456791);
PythonBoot::SetUISize(800, 600);
const bool mobile_test = std::getenv("MT_TEST_MOBILE") != nullptr;
PythonBoot::SetTouchInput(mobile_test);
const bool ran = PythonBoot::RunMainScript("", &error);
if (!ran)
std::fprintf(stderr, "RunMainScript: %s\n", error.c_str());
CHECK(ran && PythonBoot::IsAppLooping());
CHECK(py("import __main__, networkModule, introLogin, introSelect, introLoading\n"
"__main__._stream = [o for o in __import__('gc').get_objects() if isinstance(o, networkModule.MainStream)][0]"));
CHECK(pump_until(20, [] { return py_true("isinstance(_stream.curPhaseWindow, introLogin.LoginWindow)"); }));
// 2. The login button's path (LoginWindow.Connect), pointed at the fake or the live server.
py_set("_host", host);
py_set("_login", login);
py_set("_password", password);
char ports[128];
std::snprintf(ports, sizeof(ports), "_auth_port, _game_port, _slot = %d, %d, %d", auth_port, game_port, slot);
CHECK(py(ports));
CHECK(py("_stream.SetConnectInfo(_host, _game_port, _host, _auth_port)"));
// Typed into the login board through the 40250 IME (WM_CHAR -> CPythonIME::WMChar, WM_KEYDOWN ->
// OnIMEKeyDown): Tab moves to the password line, Return runs __OnClickLoginButton -> Connect.
// The IME only reaches a rendering EditLine: open the login board as the server list's OK button does.
CHECK(py("_w = _stream.curPhaseWindow\n"
"_w._LoginWindow__OpenLoginBoard()\n"
"_w.idEditLine.SetText('')\n"
"_w.pwdEditLine.SetText('')\n"
"_w.idEditLine.SetFocus()"));
auto type = [](const std::string& text) {
for (unsigned char c : text)
PythonBoot::UIChar(c);
};
type(login + "xy");
PythonBoot::UIIMEKeyDown(VK_LEFT);
PythonBoot::UIIMEKeyDown(VK_DELETE); // y
PythonBoot::UIChar(VK_BACK); // x
CHECK(py("assert _w.idEditLine.GetText() == _login, repr(_w.idEditLine.GetText())"));
PythonBoot::UIChar(VK_TAB);
type(password);
CHECK(py("assert _w.pwdEditLine.GetText() == _password, len(_w.pwdEditLine.GetText())\n"
"del __main__._login, __main__._password, __main__._w"));
PythonBoot::UIChar(VK_RETURN);
// 3. The character list.
const bool selecting = pump_until(live ? 30 : 20, [&] {
return failed() || ((!server || server->Has("game1:login2")) &&
py_true("isinstance(_stream.curPhaseWindow, introSelect.SelectCharacterWindow)"));
});
CHECK(selecting && !failed());
CHECK(!PythonBoot::InGamePhase());
if (!selecting)
{
// The login window reports failures in its popup (LOGIN_FAILURE, connect errors).
py("import sys\n"
"_w = _stream.curPhaseWindow\n"
"_msg = _stream.popupWindow and _stream.popupWindow.IsShow() and _stream.popupWindow.GetChild('message').GetText()\n"
"sys.stderr.write('phase window %s, popup %r\\n' % (_w.__class__.__name__, _msg))");
}
if (server)
{
CHECK(server->Has("auth:login3") && server->Has("auth:closed"));
CHECK(py("import net\n"
"_name = net.GetAccountCharacterSlotDataString(0, net.ACCOUNT_CHARACTER_SLOT_NAME)\n"
"assert _name == '" + std::string(FakeLoginServer::kCharacterName) + "', _name\n"
"assert net.GetEmpireID() == 1"));
}
else if (selecting)
{
CHECK(py("import net\n"
"assert net.GetAccountCharacterSlotDataString(_slot, net.ACCOUNT_CHARACTER_SLOT_NAME), 'slot is empty'\n"
"assert net.GetEmpireID() in (1, 2, 3), net.GetEmpireID()"));
}
// 3b. intrologin's channel status list (__RequestServerStateList / NotifyChannelState): ServerStateChecker
// connects to the first channel, sends CG_STATE_CHECKER and reports each channel the answer lists
// by port. TChannelStatus::nPort is a short, so the fake server's ephemeral state port (> 32767)
// never matches its own channel; offline the proof is the second channel (13002) it also lists.
// Live the game port answers for the channels the db knows, the game port among them.
if (!std::getenv("MT_TEST_PINCH") && !std::getenv("MT_TEST_AUTOHUNT_BATCH"))
{
const int state_port = server ? server->StatePort() : game_port;
const int key = server ? 2 : 1;
char channels[256];
std::snprintf(channels, sizeof(channels),
"ServerStateChecker.AddChannel(1, _host, %d)\nServerStateChecker.AddChannel(2, _host, %d)\n"
"_channel_key = %d\n",
state_port, FakeLoginServer::kOtherChannelPort, key);
CHECK(py(std::string("import ServerStateChecker\n"
"class _ChannelStates:\n"
" def __init__(self): self.states = {}\n"
" def NotifyChannelState(self, key, state): self.states[key] = state\n"
"_channel_states = _ChannelStates()\n"
"ServerStateChecker.Create(_channel_states)\n"
"ServerStateChecker.Initialize()\n") +
channels + "ServerStateChecker.Request()"));
CHECK(pump_until(10, [] { return py("ServerStateChecker.Update()") && py_true("_channel_key in _channel_states.states"); }));
py("import sys\nsys.stderr.write('port_login_flow_test: channel states %r\\n' % _channel_states.states)");
CHECK(py_true("_channel_states.states.get(_channel_key, 0) > 0"));
if (server)
CHECK(server->Has("state:checker"));
}
// 3c. SetSelectCharacterPhase ran localeInfo.LoadLocaleData() → app.LoadLocaleData(app.GetLocalePath()):
// CItemManager read item_list.txt/item_proto/itemdesc.txt and CPythonNonPlayer read mob_proto.
{
CItemData* sword = nullptr;
CHECK(CItemManager::Instance().GetItemDataPointer(19, &sword) && sword);
if (sword)
{
std::printf("port_login_flow_test: item 19 %s type %u refine %u\n", sword->GetName(), sword->GetType(), sword->GetRefine());
CHECK(sword->GetType() == CItemData::ITEM_TYPE_WEAPON && sword->GetRefine() == 9);
CHECK(sword->GetModelThing() != nullptr);
}
CHECK(py("import nonplayer\n"
"_mob = nonplayer.GetMonsterName(101)\n"
"assert _mob, 'mob 101 has no name'\n"
"import sys\nsys.stderr.write('port_login_flow_test: mob 101 %s\\n' % _mob)"));
// CPythonSkill read skilldesc.txt and skilltable.txt (RegisterSkillDesc/RegisterSkillTable); skill 1's
// cool time is skilltable's constant "12".
CHECK(py("import skill\n"
"assert skill.GetSkillName(1, 0) and (__import__('os').getenv('MT_LIVE_BIOLOG') or __import__('os').getenv('MT_TEST_WIKI') or skill.GetSkillName(1, 0) == 'Three-Way Cut'), skill.GetSkillName(1, 0)\n"
"assert skill.GetSkillType(1) == skill.SKILL_TYPE_ACTIVE, skill.GetSkillType(1)\n"
"assert skill.GetSkillCoolTime(1, 1.0) == 12, skill.GetSkillCoolTime(1, 1.0)"));
}
// 4-5. Start the game on the slot: DirectEnter, the second game login and the loading phase.
if (selecting)
{
CHECK(py("_stream.curPhaseWindow.SelectSlot(_slot)\n_stream.curPhaseWindow.StartGame()"));
// GC_MAIN_CHARACTER → LoadingWindow.LoadData(x, y), then CG_CLIENT_VERSION in the same call.
const char* loaded = "isinstance(_stream.curPhaseWindow, introLoading.LoadingWindow) and "
"getattr(_stream.curPhaseWindow, 'playerX', None) is not None";
const bool loading = pump_until(live ? 40 : 30, [&] {
return failed() || (server ? server->Has("game2:client_version") : py_true(loaded));
});
CHECK(loading && !failed());
CHECK(py_true(loaded));
// CG_CLIENT_VERSION is sent before introLoading's background-load steps. Wait for those
// script frames rather than racing the server thread's receipt of the version packet.
CHECK(pump_until(live ? 10 : 5, [&] { return failed() || !PythonBoot::CurrentMapName().empty(); }) &&
!PythonBoot::CurrentMapName().empty());
// 6. introLoading's update steps end in net.StartGame(); the next CPythonNetworkStream::Process calls
// networkModule's SetGamePhase, which builds game.GameWindow (interfaceModule.MakeInterface) and
// opens it, and GameWindow.Open sends CG_ENTERGAME.
CHECK(py("import game"));
const char* gaming = "isinstance(_stream.curPhaseWindow, game.GameWindow) and _stream.curPhaseWindow.IsShow()";
const bool entered = pump_until(30, [&] {
return failed() || (py_true(gaming) && (!server || server->Has("game2:entergame")));
});
CHECK(entered && !failed());
// CG_ENTERGAME's PHASE_GAME answer switches the stream to "Game" a round trip after the window opens.
CHECK(pump_until(5, [] { return PythonBoot::InGamePhase(); }) && !PythonBoot::CurrentMapName().empty());
// 7. (批次 2V2-b) The server answers CG_ENTERGAME with the character's own insert packets and
// PHASE_GAME, then the Entergame burst (PVP/land list, time, channel, greet chat, ...). GamePhase
// has to read all of it: an unknown or mis-sized packet makes CheckPacket log "Unknown packet
// header" and drop the receive buffer. Offline the fake server ends with a ping the client
// must answer; live the stream has to stay in the game window and connected for 10 s.
const bool burst = pump_until(live ? 10 : 30, [&] {
return failed() || (server && server->Has("game2:burst_pong"));
});
CHECK(live || (burst && !failed()));
// The fake server's GC_TIME is milliseconds since this test server started, so its
// value is small. The sentinel set before login must have been replaced by RecvTimePacket.
CHECK(live || (GetPlatformServerTime() < 120000 && GetPlatformServerTimeStamp() < 120000));
CHECK(py_true(gaming));
CHECK(py("import net\nassert net.IsConnect(), 'disconnected in the game phase'"));
// PORT: focused negotiated quiver fixture; never executes live mutations.
if (server && std::getenv("MT_TEST_QUIVER")) {
auto type=[] {auto* actor=CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kMainVID);return actor?int(actor->GetArrowType()):-1;};
CHECK(pump_until(8,[&] {return type()==9 || failed();}));
CHECK(type()==9 && !failed());
if (std::getenv("MT_TEST_QUIVER_MOTION")) {
CHECK(py("import app\nassert not app.ENABLE_CHEQUE_SYSTEM and not app.ENABLE_WON_EXCHANGE_WINDOW"));
// Do not call Register here: loading-phase registration itself must have worked.
CHECK(py("import mt_quiver_motion\nassert mt_quiver_motion.loaded == {1: True, 5: True}"));
CHECK(py("_bag=_stream.curPhaseWindow.interface.wndInventory\nassert len(_bag.inventoryTab)==5\n_bag.SetInventoryPage(4)\nassert _bag.GetInventoryPageIndex()==4\n_bag.SetInventoryPage(0)"));
for (DWORD raceID:{1u,5u}) {
CRaceData* race=nullptr;CRaceMotionData* motion=nullptr;
CHECK(CRaceManager::Instance().GetRaceDataPointer(raceID,&race));
if(race) {
CHECK(race->GetMotionDataPointer(CRaceMotionData::MODE_BOW_SPECIAL,
CRaceMotionData::NAME_COMBO_ATTACK_1,0,&motion));
CHECK(motion);
if(motion) {
bool found=false;
for(DWORD i=0;i<motion->GetMotionEventDataCount();++i) {
const CRaceMotionData::TMotionEventData* event=nullptr;
CHECK(motion->GetMotionEventDataPointer(BYTE(i),&event));
if(event && event->iType==CRaceMotionData::MOTION_EVENT_TYPE_FLY) {
auto* fly=static_cast<const CRaceMotionData::TMotionFlyEventData*>(event);
CHECK(fly->strFlyFileName=="d:/ymir work/pc/assassin/effect/arrow_02.msf");
CHECK(fly->dwFlyIndex!=0);
CFlyingData data;CHECK(data.LoadScriptFile(fly->strFlyFileName.c_str()));
found=true;
}
}
CHECK(found);
}
}
}
auto* actor=CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kMainVID);
CHECK(actor && actor->HasQuiverMotion());
if(actor)CHECK(actor->GetGraphicThingInstancePtr()->GetMotionMode()==CRaceMotionData::MODE_BOW_SPECIAL);
}
for (int expected:{6,0,9}) {
CHECK(py("net.SendChatPacket('/quiver_test "+std::to_string(expected)+"')"));
CHECK(pump_until(5,[&] {return type()==expected || failed();}));
CHECK(type()==expected && !failed());
if(std::getenv("MT_TEST_QUIVER_MOTION")) {
auto* actor=CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kMainVID);
CHECK(actor);
if(actor)CHECK(actor->GetGraphicThingInstancePtr()->GetMotionMode()==
(expected==9?CRaceMotionData::MODE_BOW_SPECIAL:CRaceMotionData::MODE_BOW));
}
}
CHECK(py("import app\napp.Exit()"));
pump_until(2,[] {return !PythonBoot::IsAppLooping();});
PythonBoot::Stop();
std::printf("quiver negotiated packet fixture: %s\n",g_failures?"FAILED":"PASS");
return g_failures?1:0;
}
if (server && std::getenv("MT_TEST_TRADE_LEVEL")) {
if(std::getenv("MT_TEST_TARGET_ELEMENT")) {
CHECK(py("import game, uiTarget, mt_target_element as _element, nonplayer\n"
"_board=_stream.curPhaseWindow.targetBoard\n"
"assert game.uiTarget is uiTarget, 'game target module differs'\n"
"assert type(_board).SetEnemyVID.im_func is _element.Hooked_SetEnemyVID, 'target hook not installed'\n"
"_race_flag=nonplayer.GetMonsterRaceFlag\n"
"try:\n"
" for _bit,_name in enumerate(('elect','fire','ice','wind','earth','dark'),11):\n"
" nonplayer.GetMonsterRaceFlag=lambda race,bit=_bit:1<<bit\n"
" _board.SetEnemyVID("+std::to_string(FakeLoginServer::kMobVID)+")\n"
" assert _board.elementImage.IsShow(), _name\n"
" assert _board.elementImage.GetWidth()>0\n"
" nonplayer.GetMonsterRaceFlag=lambda race:0\n"
" _board.SetEnemyVID("+std::to_string(FakeLoginServer::kMobVID)+")\n"
" assert not _board.elementImage.IsShow()\n"
" _board.SetTargetVID("+std::to_string(FakeLoginServer::kMainVID)+")\n"
" assert not _board.elementImage.IsShow()\n"
" _board.ResetTargetBoard()\n"
" assert not _board.elementImage.IsShow()\n"
"finally:\n nonplayer.GetMonsterRaceFlag=_race_flag"));
}
for(int expected:{87,0,0,31}) {
CHECK(py("import net\nnet.SendExchangeStartPacket("+std::to_string(FakeLoginServer::kMainVID)+")"));
CHECK(pump_until(3,[] {return CPythonExchange::Instance().isTrading();}));
CHECK(CPythonExchange::Instance().GetLevelFromSelf()==10);
CHECK(CPythonExchange::Instance().GetLevelFromTarget()==DWORD(expected));
CHECK(py("import exchange\n_trade=_stream.curPhaseWindow.interface.dlgExchange\nassert _trade.IsShow()\n_title=_trade.TitleName.GetText()\n"+
(expected?"assert '"+std::to_string(expected)+"' in _title":"assert _title==exchange.GetNameFromTarget()")));
CHECK(py("net.SendExchangeExitPacket()"));
CHECK(pump_until(3,[] {return !CPythonExchange::Instance().isTrading();}));
CHECK(CPythonExchange::Instance().GetLevelFromTarget()==0 && CPythonExchange::Instance().GetLevelFromSelf()==0);
}
CHECK(!failed());
CHECK(py("import app\napp.Exit()"));
pump_until(2,[] {return !PythonBoot::IsAppLooping();});PythonBoot::Stop();
std::printf("trade authoritative level fixture: %s\n",g_failures?"FAILED":"PASS");
return g_failures?1:0;
}
if (server && std::getenv("MT_TEST_CUBE")) {
// PORT: opt-in verification of the merged CH5/AVA2 pack overlay and
// the real CPythonResource PNG factory, not a header-only decoder.
if(std::getenv("MT_TEST_CH5_PACKS")) {
CHECK(py("import grpImage, item\n"
"for _pack_png, _pack_dims in [('cream/pages/page_1_down.png',(26,26)),('d:/ymir work/ui/game/battle_pass/gauge/gauge_bpass.png',(16,8))]:\n"
" _pack_image=grpImage.Generate(_pack_png)\n"
" try:\n"
" assert (grpImage.GetWidth(_pack_image),grpImage.GetHeight(_pack_image))==_pack_dims\n"
" finally:\n"
" grpImage.Delete(_pack_image)\n"
"for _pack_vnum, _pack_type in [(6884,18),(11300,2),(19529,36)]:\n"
" item.SelectItem(_pack_vnum)\n"
" assert item.GetItemType()==_pack_type and item.GetItemSubType()==0, (_pack_vnum,item.GetItemType(),item.GetItemSubType())\n"));
}
CHECK(py("import cube_renewal, app, player\nassert not app.ENABLE_CUBE_RENEWAL_WORLDARD\n_cube_gold=player.GetElk()\n_cube_materials=player.GetItemCountByVnum(30006)\ncube_renewal.LoadCatalogue(20383)"));
CHECK(pump_until(8,[] {return py_true("cube_renewal.CountDates()==1");}));
CHECK(py("assert cube_renewal.GetDates(0)==(19,1,False,30006,1,0,0,0,0,0,0,0,0,100,50,'WORLDARD')"));
if(std::getenv("MT_TEST_CUBE_LAYOUT")) {
CHECK(py("_stream.curPhaseWindow.BINARY_Cube_Open(20383)"));
CHECK(pump_until(8,[] {return py_true("cube_renewal._window is not None and cube_renewal._window.IsShow() and cube_renewal._readonly");}));
CHECK(py("cube_renewal.CubeRenewalMakeItem(0,3)"));
} else CHECK(py("cube_renewal.CheckBatch(0,3)"));
CHECK(pump_until(8,[] {return py_true("cube_renewal._last_preflight is not None");}));
CHECK(py("assert cube_renewal._last_error is None\nassert cube_renewal._last_preflight['gold_required']==300\nassert cube_renewal._last_preflight['mutation_enabled']==0\nassert player.GetElk()==_cube_gold\nassert player.GetItemCountByVnum(30006)==_cube_materials\nassert cube_renewal.CheckBatch(0,101)==0\ncube_renewal.CubeRenewalClose()\nassert cube_renewal.CountDates()==0\napp.Exit()"));
pump_until(2,[] {return !PythonBoot::IsAppLooping();});PythonBoot::Stop();
std::printf("cube read-only catalogue/preflight fixture: %s\n",g_failures?"FAILED":"PASS");return g_failures?1:0;
}
if (server && std::getenv("MT_TEST_AUTOHUNT_BATCH")) {
CHECK(CPythonPlayer::Instance().NEW_GetMainActorPtr());
CHECK(CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kMobVID));
#include "autohunt_pickup_checks.inc"
CHECK(!failed());
CHECK(py("import app\napp.Exit()"));
pump_until(2, [] { return !PythonBoot::IsAppLooping(); });
PythonBoot::Stop();
std::printf("autohunt batch fixture: %s\n", g_failures ? "FAILED" : "PASS");
return g_failures ? 1 : 0;
}
// Opt-in, dedicated fixture account only: real server biolog smoke, no generic gameplay mutations.
if (live && std::getenv("MT_LIVE_BIOLOG")) {
CHECK(pump_until(5, [] { return py_true("not _stream.curtain.IsShow()"); }));
CHECK(py("import mt_biolog, player\nmt_biolog.Toggle()"));
CHECK(pump_until(8, [] { return py_true("mt_biolog.g_window.hasState"); }));
CHECK(py("_bio=mt_biolog.g_window\nimport sys\nsys.stderr.write('AVA2 bio index=%d count=%d material=%d remaining=%d\\n' % (_bio.index,_bio.count,player.GetItemCountByVnum(30006),_bio.Remaining()))"));
const std::string mode=env("MT_LIVE_BIOLOG");
if (mode=="resume") {
CHECK(py_true("_bio.index==1 and player.GetItemCountByVnum(30006)==1 and _bio.Remaining()>0"));
} else if(mode=="gift4") {
CHECK(py_true("_bio.index==4 and _bio.Phase()=='stone' and _bio.CanAct()"));
CHECK(py("_bio.Act()"));
CHECK(pump_until(5, [] { return py_true("_bio.Phase()=='gift'"); }));
CHECK(py("_bio.Gift(0)"));
CHECK(pump_until(5, [] { return py_true("_bio.index==5 and player.GetStatus(240)==4"); }));
CHECK(py("net.SendChatPacket('/bio gift 0')"));
pump_until(0.4, [] { return false; });
CHECK(py_true("_bio.index==5 and player.GetStatus(240)==4"));
} else if(mode=="reset") {
CHECK(py_true("_bio.index==5 and player.GetStatus(240)==4"));
CHECK(py("_note_before=player.GetItemCountByVnum(70028)\nnet.SendItemUsePacket(1)"));
CHECK(pump_until(5, [] { return py_true("_bio.mode=='reset' and _bio.ResetIndex()==4"); }));
CHECK(py("assert player.GetItemCountByVnum(70028)==_note_before\n_bio.Gift(1)"));
CHECK(pump_until(5, [] { return py_true("_bio.bonuses[3]==2 and player.GetStatus(240)==0 and player.GetStatus(241)==4"); }));
CHECK(py_true("player.GetItemCountByVnum(70028)==_note_before-1"));
} else if(mode=="gift13") {
CHECK(py_true("_bio.index==13 and _bio.Phase()=='gift'"));
CHECK(py("assert player.GetItemCountByVnum(70028)==_note_before\n_bio.Gift(1)"));
CHECK(pump_until(5, [] { return py_true("_bio.index==14 and _bio.Phase()=='complete' and player.GetStatus(43)==10"); }));
} else if(mode=="complete") {
CHECK(pump_until(5, [] { return py_true("_bio.index==14 and _bio.bonuses[12]==2 and 13 in _bio.ResetEntries()"); }));
CHECK(py_true("player.GetStatus(43)==10"));
} else if(mode=="shop") {
CHECK(py("_bio.Shop()\n_bio.browse=13\n_bio.Refresh()\nassert mt_biolog.SHOP[13]['vnum']==300004\nassert _bio.CanAct()\n_bio.Act()"));
CHECK(pump_until(5, [] { return py_true("player.GetItemCountByVnum(300004)==1 and player.GetItemCountByVnum(30091)==0"); }));
} else {
CHECK(py_true("_bio.index==1 and _bio.count==0 and _bio.CanAct()"));
CHECK(py("_bio.Act()"));
CHECK(pump_until(5, [] { return py_true("player.GetItemCountByVnum(30006)==1 and _bio.Remaining()>0"); }));
CHECK(py_true("_bio.Remaining()<=601"));
if(mode=="aux") {
CHECK(py_true("_bio.count==1 and player.GetItemCountByVnum(71035)==0 and _bio.CanAct()"));
CHECK(py("_bio.Act()"));
CHECK(pump_until(5, [] { return py_true("player.GetItemCountByVnum(30006)==0 and player.GetItemCountByVnum(30250)==0"); }));
} else {
CHECK(py_true("not _bio.CanAct()"));
CHECK(py("net.SendChatPacket('/bio mission 1 1')"));
pump_until(0.5, [] { return false; });
CHECK(py_true("player.GetItemCountByVnum(30006)==1"));
}
}
CHECK(py("import app\napp.Exit()"));
pump_until(2, [] { return !PythonBoot::IsAppLooping(); });
PythonBoot::Stop();
std::printf("biolog live fixture: %s\n", g_failures ? "FAILED" : "PASS");
return g_failures ? 1 : 0;
}
if (mobile_test && std::getenv("MT_TEST_PINCH")) {
CHECK(pump_until(5, [] { return py_true("not _stream.curtain.IsShow()"); }));
CHECK(py("import mt_mobile_hud; _hud=mt_mobile_hud.g_hud\n"
"assert not _hud.menuExpanded and all(not b.IsShow() for b in _hud.side)\n"
"assert _hud.shop.IsShow() and _hud.more.IsShow()\n"
"_hud.ToggleMore()\n"
"assert _hud.menuExpanded and all(b.IsShow() for b in _hud.side)\n"
"_hud.ToggleMore()\n"
"assert not _hud.menuExpanded and all(not b.IsShow() for b in _hud.side)"));
CHECK(py("import player\nassert _hud.top[1].IsShow() and not any(b.IsShow() for b in [_hud.top[0],_hud.top[2],_hud.top[3]])\n"
"_hud.ToggleMore()\n"
"assert all(b.IsShow() for b in _hud.drawer) and _hud.menuBackdrop.IsShow()\n"
"_hud.top[1].action()\n"
"assert not _hud.menuExpanded and not _hud.menuBackdrop.IsShow()\n"
"assert _hud.window.interface.wndInventory.IsShow()\n"
"_hud.window.interface.wndInventory.Hide()\n"
"assert _hud.status.gauge.IsShow() and _hud.status.frame.IsShow()"));
CHECK(py("_hud.ToggleMore()\n_menu_b=_hud.drawer[0]"));
std::string drawerXY;
CHECK(PythonBoot::Evaluate("'%d %d' % _menu_b.GetGlobalPosition()", &drawerXY, nullptr));
int drawerX=0,drawerY=0;
CHECK(std::sscanf(drawerXY.c_str(), "'%d %d'", &drawerX, &drawerY)==2 ||
std::sscanf(drawerXY.c_str(), "%d %d", &drawerX, &drawerY)==2);
PythonBoot::UIMouseMove(drawerX+24,drawerY+24);
CHECK(py_true("__import__('wndMgr').IsPickedWindow(_menu_b.hWnd)"));
CHECK(PythonBoot::IsPointInsideActiveUI(drawerX-3,drawerY-3));
CHECK(py("_hud.ToggleMore()"));
// Main entries, the complete drawer and the editing window fit narrow/wide layouts.
for (const auto dimensions : {std::pair{640,360}, std::pair{800,600}, std::pair{1169,600}}) {
PythonBoot::SetUISize(dimensions.first, dimensions.second);
CHECK(py("import wndMgr\n_hud.OnUpdate()\n"
"_hud.ToggleMore()\n"
"for b in [_hud.top[1],_hud.shop,_hud.more]+_hud.drawer:\n"
" x,y=b.GetGlobalPosition(); assert x>=0 and y>=0 and x+b.GetWidth()<=wndMgr.GetScreenWidth() and y+b.GetHeight()<=wndMgr.GetScreenHeight()\n"
"_hud.ToggleMore()\n"
"_hud.chat.OpenChat(); _hud.OnUpdate()\n"
"assert _hud.chat.GetGlobalPosition()[0]+_hud.chat.GetWidth()<=wndMgr.GetScreenWidth()\n"
"_hud.chat.CloseChat(); _hud.OnUpdate()"));
}
PythonBoot::SetUISize(800,600);
CHECK(py("_hud.OnUpdate()"));
// Preview only clips rendering: preserve complete chat history and restore full-screen scissor.
CHECK(py("import chat\n"
"_preview_id=20261019\n"
"chat.CreateChatSet(_preview_id)\n"
"chat.SetPosition(_preview_id,20,200)\n"
"chat.SetHeight(_preview_id,300)\n"
"for i in range(8): chat.AppendChat(chat.CHAT_TYPE_INFO, 'PREVIEW_%d_'%i+'long message '*40)\n"
"chat.Update(_preview_id)\n"
"_history_count=chat.GetLineCount(_preview_id)"));
UIRenderSetSize(800,600);
UIRenderBeginFrame();
CHECK(py("chat.RenderPreview(_preview_id,10,150,100,45)"));
const auto previewCommands = UIRenderCommands();
CHECK(!previewCommands.empty());
for (const auto& command : previewCommands) {
CHECK(command.clip_x1 == 10 && command.clip_y1 == 150);
CHECK(command.clip_x2 == 110 && command.clip_y2 == 195);
}
UIRenderBeginFrame();
CHECK(py("chat.Render(_preview_id)\nassert chat.GetLineCount(_preview_id)==_history_count"));
CHECK(!UIRenderCommands().empty());
for (const auto& command : UIRenderCommands())
CHECK(command.clip_x1==0 && command.clip_x2==800 && command.clip_y1==0 && command.clip_y2==600);
TouchController touch;
touch.set_enabled(true);
touch.update_screen_size(800, 600);
// PORT scene pinch: start across both halves, spread closer, close farther.
CHECK(!PythonBoot::IsPointInsideActiveUI(480, 240));
CHECK(!PythonBoot::IsPointInsideActiveUI(320, 240));
auto* camera = CCameraManager::Instance().GetCurrentCamera();
const float originalDistance = camera->GetDistance();
CHECK(touch.on_finger_down(201, 0.4f, 0.4f));
CHECK(touch.on_finger_down(202, 0.6f, 0.4f));
const float beforePinch = camera->GetDistance();
touch.on_finger_motion(202, 0.7f, 0.4f);
CHECK(camera->GetDistance() < beforePinch * 0.8f);
const float closeDistance = camera->GetDistance();
touch.on_finger_motion(202, 0.6f, 0.4f);
CHECK(camera->GetDistance() > closeDistance * 1.2f);
CHECK(std::abs(camera->GetDistance() - beforePinch) < 1.0f);
touch.on_finger_up(201, 0.4f, 0.4f); // remaining finger becomes look, never tap
touch.on_finger_motion(202, 0.62f, 0.4f);
CHECK(std::abs(camera->GetDistance() - beforePinch) < 1.0f);
touch.on_finger_up(202, 0.62f, 0.4f);
touch.update();
CHECK(std::abs(camera->GetDistance() - beforePinch) < 1.0f);
// Reverse ownership order; right scene finger plus left scene finger also pinches.
touch.on_finger_down(203, 0.6f, 0.4f);
touch.on_finger_down(204, 0.4f, 0.4f);
touch.on_finger_motion(204, 0.3f, 0.4f);
CHECK(camera->GetDistance() < beforePinch * 0.8f);
touch.on_finger_up(204, 0.3f, 0.4f);
touch.on_finger_up(203, 0.6f, 0.4f);
camera->SetDistance(originalDistance);
touch.on_finger_down(207, 0.6f, 0.4f);
touch.on_finger_down(208, 0.4f, 0.4f);
touch.cancel_gestures();
touch.on_finger_motion(208, 0.2f, 0.4f);
CHECK(std::abs(camera->GetDistance() - originalDistance) < 1.0f);
// A moving joystick is not stolen by a second thumb looking around.
touch.on_finger_down(205, 0.3f, 0.45f);
touch.on_finger_motion(205, 0.35f, 0.45f);
touch.on_finger_down(206, 0.6f, 0.4f);
touch.on_finger_motion(206, 0.7f, 0.4f);
CHECK(std::abs(camera->GetDistance() - originalDistance) < 1.0f);
touch.on_finger_up(205, 0.35f, 0.45f);
touch.on_finger_up(206, 0.7f, 0.4f);
CHECK(py("import app; app.Exit()"));
pump_until(2, [] { return !PythonBoot::IsAppLooping(); });
PythonBoot::Stop();
if (server) server->Stop();
std::printf("mobile scene pinch: %s\n", g_failures ? "FAILED" : "PASS");
return g_failures ? 1 : 0;
}
if (mobile_test) {
// Input remains blocked by the original phase curtain until its fade finishes.
CHECK(pump_until(5, [] { return py_true("not _stream.curtain.IsShow()"); }));
CHECK(py("import mt_mobile_hud, ui, player\n"
"_hud = mt_mobile_hud.g_hud\n"
"_hud.taskbar.Show()\n"
"_hud.OnUpdate()\n"
"_hud.window.interface.wndInventory.Hide()"));
CHECK(py_true("_hud.IsShow()"));
CHECK(py_true("not ui.Window.IsShow(_hud.taskbar)"));
CHECK(py_true("len(_hud.top) == 4 and len(_hud.side) == 4"));
CHECK(py_true("all(button.GetWidth() >= 48 for button in _hud.top + _hud.side)"));
CHECK(py_true("_hud.status.values[0] == player.GetStatus(player.HP)"));
CHECK(py_true("_hud.experience is _hud.taskbar.expGaugeBoard and _hud.experience.IsShow()"));
CHECK(py_true("len(_hud.taskbar.expGauge) == 4"));
CHECK(py_true("_hud.status.gauge is _hud.taskbar.GetChild('Gauge_Board')"));
CHECK(py_true("_hud.experience.GetGlobalPosition()[1] > 500"));
TouchController touch;
touch.set_enabled(true);
touch.update_screen_size(800, 600);
std::string menuXY;
CHECK(PythonBoot::Evaluate("'%d %d' % _hud.top[1].GetGlobalPosition()", &menuXY, nullptr));
int menuX = 0, menuY = 0;
CHECK(std::sscanf(menuXY.c_str(), "'%d %d'", &menuX, &menuY) == 2 ||
std::sscanf(menuXY.c_str(), "%d %d", &menuX, &menuY) == 2);
const float nx = float(menuX + 24) / 800, ny = float(menuY + 24) / 600;
CHECK(touch.on_finger_down(102, nx, ny));
CHECK(py_true("__import__('wndMgr').IsPickedWindow(_hud.top[1].hWnd)"));
CHECK(touch.on_finger_up(102, nx, ny));
CHECK(py_true("_hud.window.interface.wndInventory.IsShow()"));
CHECK(py("_hud.window.interface.wndInventory.Hide()\n"
"_hud.taskbar.Hide()\n"
"assert not _hud.IsShow()\n"
"_hud.taskbar.Show()\n"
"assert _hud.IsShow()"));
}
if (!live) {
CHECK(pump_until(5, [] { return py_true("not _stream.curtain.IsShow()"); }));
CHECK(py("import mt_biolog\nassert mt_biolog.g_window and mt_biolog.g_entry\n"
"mt_biolog.g_entry.OnUpdate()"));
// Exercise the actual minimap entry hit target, not a direct Toggle callback.
std::string entryXY;
CHECK(PythonBoot::Evaluate("'%d %d' % mt_biolog.g_entry.GetGlobalPosition()", &entryXY, nullptr));
int entryX = 0, entryY = 0;
CHECK(std::sscanf(entryXY.c_str(), "'%d %d'", &entryX, &entryY) == 2 ||
std::sscanf(entryXY.c_str(), "%d %d", &entryX, &entryY) == 2);
PythonBoot::UIMouseMove(entryX + 30, entryY + 24);
CHECK(py_true("__import__('wndMgr').IsPickedWindow(mt_biolog.g_entry.hWnd)"));
PythonBoot::UIMouseButton(1, true, entryX + 30, entryY + 24);
PythonBoot::UIMouseButton(1, false, entryX + 30, entryY + 24);
CHECK(pump_until(3, [] { return py_true("mt_biolog.g_window.IsShow() and mt_biolog.g_window.hasState"); }));
CHECK(py("_bio=mt_biolog.g_window\nimport player\n_old_level=player.GetStatus(player.LEVEL)\nplayer.SetStatus(player.LEVEL,105)\n_bio.options=[True,False,True]\n_bio.Refresh()\nassert _bio.count==3 and _bio.CanAct()\nassert not _bio.SetData('99 0 0'.split())\n_bio.Act()\nassert not _bio.CanAct()\n_bio.Act()"));
CHECK(pump_until(3, [] { return py_true("_bio.count==4"); }));
CHECK(py_true("not _bio.CanAct() and _bio.Remaining()>0"));
CHECK(py("assert _bio.SetData('9 11 0'.split())\nassert _bio.Phase()=='gift'\nassert sum(button.IsShow() for button in _bio.choices)==3\nassert _bio.SetData('13 36 0'.split())\nassert sum(button.IsShow() for button in _bio.choices)==2\nplayer.SetStatus(player.LEVEL,_old_level)\n_bio.Hide()"));
}
if (!live && std::getenv("MT_TEST_WIKI")) {
CHECK(py("import mt_wiki, mt_wiki_data, mt_biolog, player\n"
"assert mt_wiki.g_window and mt_wiki.g_entry\n"
"assert mt_wiki.ServerCapabilities()['live_drops'] is None\n"
"mt_wiki.g_entry.OnUpdate()"));
std::string xy;
CHECK(PythonBoot::Evaluate("'%d %d' % mt_wiki.g_entry.GetGlobalPosition()", &xy, nullptr));
int x=0,y=0;
CHECK(std::sscanf(xy.c_str(), "'%d %d'", &x,&y)==2 || std::sscanf(xy.c_str(), "%d %d", &x,&y)==2);
PythonBoot::UIMouseMove(x+30,y+24);
CHECK(py_true("__import__('wndMgr').IsPickedWindow(mt_wiki.g_entry.hWnd)"));
PythonBoot::UIMouseButton(1,true,x+30,y+24);
PythonBoot::UIMouseButton(1,false,x+30,y+24);
CHECK(py("_wiki=mt_wiki.g_window\nassert _wiki.IsShow() and _wiki.catalogue, _wiki.error\n"
"assert _wiki.catalogue.FindItem(300004)['name']==u'\\u6989\\u6728\\u6811\\u679d', repr(_wiki.catalogue.FindItem(300004)['name'])\n"
"_wiki.search.SetText(player.AutoHuntLocalize('榉木'))\n_wiki.search.eventReturn()\n"
"assert len(_wiki.results)==1 and _wiki.results[0]['id']==300004\n"
"_wiki.SelectResult(0)\nassert _wiki.selected==('items',300004)\n"
"import item\nitem.SelectItem(19)\n_selected_name=item.GetItemName()\n"
"assert item.FeatureGetIconPath(300004)\nassert not item.FeatureGetIconPath(4294967295)\n"
"assert item.GetItemName()==_selected_name\n"
"_wiki.Open(10)\nassert any(link==11 for text,link in _wiki.links)\n"
"_wiki.Follow(next(i for i,p in enumerate(_wiki.links) if p[1]==11))\n"
"assert _wiki.selected==('items',11)\n_wiki.Back()\nassert _wiki.selected==('items',10)\n"
"_wiki.search.SetText('')\n_wiki.SetMode('mobs')\nassert _wiki.results\n"
"_wiki.NextCategory()\n_wiki.NextCategory()\nassert all(r['kind']=='STONE' for r in _wiki.results)\n"
"_wiki.Page(999999)\nassert len(_wiki.results)<=_wiki.rowCount\n"
"_wiki.Hide()\nassert not _wiki.IsShow()\n"
"_bio.Toggle()\n_bio.SetData('5 0 0'.split())\n_bio.Refresh()\n"
"assert _bio.iconVnum==300004\n"));
CHECK(PythonBoot::Evaluate("'%d %d' % _bio.materialLink.GetGlobalPosition()", &xy, nullptr));
CHECK(std::sscanf(xy.c_str(), "'%d %d'", &x,&y)==2 || std::sscanf(xy.c_str(), "%d %d", &x,&y)==2);
PythonBoot::UIMouseMove(x+24,y+24);
PythonBoot::UIMouseButton(1,true,x+24,y+24);
PythonBoot::UIMouseButton(1,false,x+24,y+24);
CHECK(py("assert _wiki.IsShow() and _wiki.selected==('items',300004)\n_wiki.Hide()\n_bio.Hide()"));
PythonBoot::SetUISize(640,360);
CHECK(py("_wiki.Open(10)\n_wiki.OnUpdate()\n"
"assert _wiki.GetWidth()<=624 and _wiki.GetHeight()<=344\n"
"assert _wiki.rowCount==2\n"
"assert _wiki.categoryButton.GetLocalPosition()[0]+_wiki.categoryButton.GetWidth()<_wiki.split\n"
"assert _wiki.listButtons[1].GetLocalPosition()[1]+44<=_wiki.prev.GetLocalPosition()[1]\n"
"_wiki.Hide()\n"
"import json\nassert json.loads('{\"schema\":1}')['schema']==1\n"
"_missing=mt_wiki.WikiWindow()\n_saved_path=mt_wiki.PATH\nmt_wiki.PATH='wiki/not-installed.txt'\n"
"_missing.Open()\nassert _missing.error and not _missing.catalogue\n"
"_missing.Destroy()\nmt_wiki.PATH=_saved_path"));
PythonBoot::SetUISize(800,600);
CHECK(py("_wiki.Open(30006)\n_wiki.QueryRemote('sources',30006)"));
CHECK(pump_until(7,[]{return py_true("_wiki.remoteData is not None");}));
CHECK(py("assert mt_wiki.ServerCapabilities()['live_drops']\nassert _wiki.remoteData['rows'][0][0]==101\n"
"_wiki.Follow(next(i for i,p in enumerate(_wiki.links) if isinstance(p[1],tuple) and p[1][0]=='mobs'))\n"
"assert _wiki.selected==('mobs',101)\n_wiki.QueryRemote('mob',101)"));
CHECK(pump_until(5,[]{return py_true("_wiki.remoteData is not None");}));
CHECK(py("assert _wiki.remoteData['total']==10 and len(_wiki.remoteData['rows'])==8\n_wiki.QueryRemote('mob',101,8)"));
CHECK(pump_until(5,[]{return py_true("_wiki.remoteData is not None and _wiki.remoteData['offset']==8");}));
CHECK(py("assert len(_wiki.remoteData['rows'])==2\n_wiki.Back()\n_wiki.QueryRemote('chest',50011)"));
CHECK(pump_until(5,[]{return py_true("_wiki.remoteData is not None and _wiki.remoteData['kind']=='chest'");}));
CHECK(py("assert _wiki.remoteData['mode']==10\nassert _wiki.remoteData['rows'][1][0]==1\n"
"assert any(p[0].startswith(u'金币') for p in _wiki.links)\n_wiki.Hide()\n"
"import mt_details\nmt_details.Toggle()"));
CHECK(pump_until(5,[]{return py_true("mt_details.g_window.values is not None");}));
CHECK(py("assert mt_details.g_window.values['stone']==10\n"
"assert mt_details.g_window.values['maxhp']==1500\n"
"assert mt_details.g_window.values['resist_human']==4\nmt_details.g_window.Hide()"));
CHECK(count_syserr("mt_feature_service: install failed")==0);
CHECK(py("import mt_dungeons\nmt_dungeons.Toggle()"));
CHECK(pump_until(5,[]{return py_true("mt_dungeons.g_window.values is not None");}));
CHECK(py("assert mt_wiki.ServerCapabilities()['dungeons']\n"
"_dungeon=mt_dungeons.g_window\nassert _dungeon.values['lair_tickets']==3\n"
"assert _dungeon.values['weekly_end']>_dungeon.values['lair_end']\n"
"_dungeon.Remind()\nassert _dungeon.reminder[0]==0\n"
"_dungeon.Select(1)\n_dungeon.Entry()\n_dungeon.Hide()"));
CHECK(py("import mt_calendar\nmt_calendar.Toggle()"));
CHECK(pump_until(5,[]{return py_true("mt_calendar.g_window.data is not None");}));
CHECK(py("assert mt_wiki.ServerCapabilities()['calendar']\n"
"_calendar=mt_calendar.g_window\nassert _calendar.data['rows'][0][6]==1\n"
"_calendar.Watch(1)\nassert _calendar.watch['id']==2\n"
"_calendar.Remind()\nassert _calendar.watch is None\n_calendar.Hide()"));
CHECK(count_syserr("mt_calendar: install failed")==0);
CHECK(count_syserr("mt_dungeons: install failed")==0);
CHECK(count_syserr("mt_details: install failed")==0);
CHECK(count_syserr("mt_wiki_entries: install failed")==0);
CHECK(count_syserr("mt_wiki: install failed")==0);
CHECK(count_syserr("mt_wiki_data: install failed")==0);
}
CHECK(count_syserr("Unknown packet header") == 0);
CHECK(count_syserr(kUnhandledPacket) == 0);
CHECK(count_syserr("does not handle this header") == 0);
// The fake greet notice went through RecvChatPacket into the ported CPythonChat, where
// uichat's chat set (created by the game interface) counts it.
CHECK(live || py("import chat\nassert any(chat.GetLineCount(i) > 0 for i in range(4)), 'greet notice not in chat'"));
// playerSettingModule ran its race registration through the real chrmgr module: the warrior
// (race 0) has a general-mode wait motion in its CRaceData.
CHECK(py("import chr, chrmgr\nassert not hasattr(chr, '__port_stub__') and not hasattr(chrmgr, '__port_stub__')"));
CRaceData* race = nullptr;
const CRaceData::TMotionVector* waits = nullptr;
CHECK(CRaceManager::Instance().GetRaceDataPointer(0, &race) && race &&
race->GetMotionVectorPointer(CRaceMotionData::MODE_GENERAL, CRaceMotionData::NAME_WAIT, &waits) &&
waits && !waits->empty());
// (批次 2V2-d) GC_CHARACTER_ADD for the player's own VID went through RecvCharacterAppendPacket and
// CNetworkActorManager into CPythonCharacterManager: the main instance exists and SetRace ran on it
// (offline the fake server sends a warrior, race 0), and CHAR_ADDITIONAL_INFO found the actor.
CInstanceBase* main_instance = CPythonCharacterManager::Instance().GetMainInstancePtr();
CHECK(main_instance != nullptr);
CHECK(live || (main_instance && main_instance->GetRace() == 0));
CHECK(count_syserr("TPacketGCCharacterAdditionalInfo") == 0);
// (批次 2V2-d.2) SetRace/SetShape loaded the body .gr2 through the Granny runtime into PART_MAIN, and
// game.GameWindow's OnUpdate/OnRender (app.UpdateGame/RenderGame) play the WAIT motion: the
// sampled bone matrices change between frames.
CGrannyLODController* lod = main_instance ?
main_instance->GetGraphicThingInstanceRef().GetLODControllerPointer(CRaceData::PART_MAIN) : nullptr;
CGrannyModelInstance* model_instance = lod ? lod->GetModelInstance() : nullptr;
CGrannyModel* model = model_instance ? model_instance->GetModel() : nullptr;
CHECK(model && model->GetMeshCount() > 0);
// The material's diffuse map resolved through GrannyGetMaterialTextureByType to a loaded image.
CGrannyMaterialPalette* palette = model ? const_cast<CGrannyMaterialPalette*>(&model->GetMaterialPalette()) : nullptr;
CHECK(palette && palette->GetMaterialCount() > 0 && palette->GetMaterialRef(0).GetImagePointer(0));
const int bone_count = model ? model->GetGrannyModelPointer()->Skeleton->BoneCount : 0;
CHECK(bone_count > 1);
auto bones = [&] {
std::vector<float> out;
for (int i = 0; i < bone_count; ++i)
{
const float* m = model_instance->GetBoneMatrixPointer(i);
out.insert(out.end(), m, m + 16);
}
return out;
};
if (bone_count > 1)
{
const std::vector<float> before = bones();
CHECK(pump_until(3, [&] { return bones() != before; }));
}
// (批次 2V2-e.1) RenderGame drew the character through CStateManager into the recording device:
// a frame holds a textured, lit triangle draw (the PNT vertex format of RenderWithOneTexture)
// under CPythonGraphic::SetPerspective's right-handed projection (_34 = -1), and the camera that
// __UpdateCamera centred on the main actor puts every vertex of it on screen.
auto on_screen = [](const Render3DDraw& d) {
auto mul = [](const float* v, const float* m, float* o) {
for (int c = 0; c < 4; ++c)
o[c] = v[0] * m[c] + v[1] * m[4 + c] + v[2] * m[8 + c] + v[3] * m[12 + c];
};
for (size_t i = 0; i + 2 < d.positions.size(); i += 3)
{
const float local[4] = {d.positions[i], d.positions[i + 1], d.positions[i + 2], 1.0f};
float world[4], view[4], clip[4];
mul(local, d.world, world);
mul(world, d.view, view);
mul(view, d.proj, clip);
if (clip[3] <= 0.0f || std::fabs(clip[0]) > clip[3] || std::fabs(clip[1]) > clip[3])
return false;
}
return true;
};
auto character_draw = [&] {
for (const Render3DDraw& d : Render3DDraws())
if (!d.pretransformed && !d.lines && !d.indices.empty() && !d.texture0.empty() &&
!d.normals.empty() && !d.uv0.empty() && d.proj[11] == -1.0f && on_screen(d))
return true;
return false;
};
CHECK(pump_until(3, character_draw));
// 7. (批次 2V3) Keyboard movement through the original path: the key reaches game.GameWindow's
// onPressKeyDict, MoveUp calls player.SetSingleDIKKeyState(DIK_UP, True), CPythonPlayer turns
// it into NEW_MoveToDirection on the main instance, and CPythonPlayerEventHandler::OnMove sends
// CG_MOVE FUNC_MOVE. Releasing the key stops the actor (OnStop: FUNC_WAIT at the new position).
TPixelPosition start = {};
if (main_instance)
main_instance->NEW_GetPixelPosition(&start);
auto walked = [&] {
TPixelPosition now = {};
main_instance->NEW_GetPixelPosition(&now);
return std::hypot(now.x - start.x, now.y - start.y);
};
PythonBoot::UIKey(DIK_UP, true);
CHECK(main_instance && pump_until(3, [&] { return walked() > 100.0f; }));
PythonBoot::UIKey(DIK_UP, false);
CHECK(main_instance && pump_until(2, [&] { return !main_instance->IsWalking(); }));
const float distance = main_instance ? walked() : 0.0f;
std::printf("port_login_flow_test: DIK_UP walked %.0f cm\n", distance);
if (server)
{
// The fake server records "game2:move <func> <arg> <rot> <x> <y>"; x, y are the TPixelPosition
// (y negated back, as SendCharacterStatePacket does) plus the map base the server gave.
auto moves = [&] {
std::vector<std::string> out;
for (const auto& e : server->Events())
if (e.rfind("game2:move ", 0) == 0)
out.push_back(e);
return out;
};
CHECK(pump_until(2, [&] { auto m = moves(); return m.size() >= 2 && m.back().rfind("game2:move 0 ", 0) == 0; }));
const auto m = moves();
CHECK(!m.empty() && m.front().rfind("game2:move 1 0 ", 0) == 0);
for (const auto& e : m)
std::printf("port_login_flow_test: %s\n", e.c_str());
}
// The terrain attribute map (attr.atr) under the actor: CInstanceBase's block/water/ban-PK checks read it
// through CPythonBackground::isAttrOn. The actor stands on a free cell; its 256x256 tile has blocked cells.
if (main_instance)
{
TPixelPosition here = {};
main_instance->NEW_GetPixelPosition(&here);
CPythonBackground& bg = CPythonBackground::Instance();
CHECK(!bg.isAttrOn(here.x, here.y, CTerrainImpl::ATTRIBUTE_BLOCK));
const int tx = int(here.x) / CTerrainImpl::TERRAIN_XSIZE * CTerrainImpl::TERRAIN_XSIZE;
const int ty = int(here.y) / CTerrainImpl::TERRAIN_YSIZE * CTerrainImpl::TERRAIN_YSIZE;
int blocked = 0;
for (int y = 0; y < CTerrainImpl::TERRAIN_YSIZE; y += CTerrainImpl::HALF_CELLSCALE)
for (int x = 0; x < CTerrainImpl::TERRAIN_XSIZE; x += CTerrainImpl::HALF_CELLSCALE)
blocked += bg.isAttrOn(tx + x, ty + y, CTerrainImpl::ATTRIBUTE_BLOCK) ? 1 : 0;
std::printf("port_login_flow_test: %d blocked attribute cells in the actor's terrain\n", blocked);
CHECK(blocked > 0);
}
// playersettingmodule.py registered the indexed fly data (effect.RegisterIndexedFlyData → CFlyingManager →
// CFlyingData::LoadScriptFile): the .msf parses, and registering the name again finds it already present.
{
const char* msf = "d:/ymir work/effect/etc/gathering/ga_piece_yellow_small2.msf";
CFlyingData* data = CFlyingData::New();
CHECK(data->LoadScriptFile(msf));
CFlyingData::Delete(data);
CHECK(!CFlyingManager::Instance().RegisterFlyingData(msf));
}
// EffectLib: playersettingmodule.py registered the level-up effect (chrmgr.RegisterEffect → CEffectManager::
// RegisterEffect2, including the .mse files the .msf fly data attach by relative name). Created at the
// actor, RenderGame's CEffectManager::Render draws its particles as textured, alpha-blended world draws.
if (main_instance)
{
const char* mse = "d:/ymir work/effect/etc/levelup_1/level_up.mse";
TPixelPosition here = {};
main_instance->NEW_GetPixelPosition(&here);
CEffectManager& effects = CEffectManager::Instance();
const int index = effects.CreateEffect(mse, D3DXVECTOR3(here.x, -here.y, here.z), D3DXVECTOR3(0, 0, 0));
CHECK(index >= 0 && effects.IsAliveEffect(index));
auto effect_draw = [] {
for (const Render3DDraw& d : Render3DDraws())
if (!d.pretransformed && d.alpha_blend && d.texture0.find("effect\\etc\\levelup_1\\") != std::string::npos)
return true;
return false;
};
CHECK(pump_until(3, effect_draw));
effects.DestroyEffectInstance(index);
}
// item module (PythonItemModule.cpp) over the loaded item_proto: SelectItem + the selected item's fields.
CHECK(py("import item\n"
"item.SelectItem(19)\n"
"assert item.GetItemName() and (__import__('os').getenv('MT_TEST_WIKI') or item.GetItemName() == 'Sword+9'), item.GetItemName()\n"
"assert item.GetItemType() == item.ITEM_TYPE_WEAPON and item.GetItemSubType() == item.WEAPON_SWORD\n"
"assert item.GetValue(3) > 0, 'min attack'"));
// skill icons: RegisterSkillDesc loaded each skill's .sub icons; an active skill has one per grade
// (__RegisterGradeIconImage) and no plain icon, as in 40250. The icon instance handle survives the 64-bit
// round trip (Py_BuildPointer).
CHECK(py("import skill\n"
"assert skill.GetIconImage(1) == 0\n"
"assert skill.GetIconImageNew(1, 0) != 0, 'skill 1 has no grade icon'\n"
"_icon = skill.GetIconInstanceNew(1, 0)\n"
"assert _icon != 0\n"
"skill.DeleteIconInstance(_icon)"));
// miniMap module (PythonMiniMapModule.cpp): uiminimap.MiniMap created and showed it. The warp loaded the
// outdoor map through CPythonBackground::Warp -> CMapManager::LoadMap -> CMapOutdoor, so the map is outdoor
// and CPythonMiniMap::LoadAtlas found the map's atlas image (its size is the atlas bitmap's).
CHECK(CPythonBackground::Instance().IsMapOutdoor());
CHECK(py("import miniMap, background\n"
"assert miniMap.isShow()\n"
"(bGet, x, y) = miniMap.GetAtlasSize()\n"
"assert bGet and x > 0 and y > 0, (bGet, x, y)\n"
"print 'port_login_flow_test: atlas %dx%d' % (x, y)\n"
"assert background.GetCurrentMapName() != '', background.GetCurrentMapName()"));
// Ground items (CPythonItem): the fake server put vnum 19 next to the actor at entergame (GC_ITEM_GROUND_ADD
// + GC_ITEM_OWNERSHIP). player.PickCloseItem finds it within __GetPickableDistance, sends CG_ITEM_PICKUP,
// and the server's GC_ITEM_GROUND_DEL removes it.
if (server)
{
CPythonItem& ground = CPythonItem::Instance();
TPixelPosition item_pos = {};
const char* owner = nullptr;
CHECK(ground.GetGroundItemPosition(FakeLoginServer::kGroundItemVID, &item_pos));
CHECK(ground.GetOwnership(FakeLoginServer::kGroundItemVID, &owner) && owner &&
std::string(owner) == FakeLoginServer::kCharacterName);
CHECK(ground.GetVirtualNumberOfGroundItem(FakeLoginServer::kGroundItemVID) == FakeLoginServer::kGroundItemVnum);
std::printf("port_login_flow_test: ground item at %.0f %.0f\n", item_pos.x, item_pos.y);
// CPythonItem::CreateItem registered the item's name tail (CPythonTextTail::RegisterItemTextTail) next to
// the actor's character tail. Shown and projected, the name is pickable on screen: textTail.Pick is how
// game.GameWindow.OnRender finds the item under the cursor while names are shown.
auto tail_info = [] {
std::string info;
CPythonTextTail::Instance().GetInfo(&info);
return info;
};
std::printf("port_login_flow_test: %s\n", tail_info().c_str());
CHECK(tail_info().find("ItemTail (Map 1,") != std::string::npos);
CHECK(tail_info().find("ChrTail (Map 5,") != std::string::npos); // the actor, the stray dog, the shopkeeper, the quest elder and the storekeeper
// Holding ALT (game.GameWindow.ShowName) makes OnRender show every tail in range and project it after
// app.RenderGame; the item tail keeps that screen rect, which is what textTail.Pick tests.
PythonBoot::UIKey(DIK_LMENU, true);
pump_frames(6);
PythonBoot::UIKey(DIK_LMENU, false);
int picked = -1, pick_x = 0, pick_y = 0;
for (int y = 0; y < 1200 && picked < 0; y += 2)
for (int x = 0; x < 1600 && picked < 0; x += 2)
if ((picked = CPythonTextTail::Instance().Pick(x, y)) >= 0)
pick_x = x, pick_y = y;
std::printf("port_login_flow_test: item name tail picked at %d %d\n", pick_x, pick_y);
CHECK(picked == (int) FakeLoginServer::kGroundItemVID);
CHECK(py("import player\nplayer.PickCloseItem()"));
const std::string pickup = "game2:pickup " + std::to_string(FakeLoginServer::kGroundItemVID);
CHECK(pump_until(2, [&] { return server->Has(pickup); }));
CHECK(pump_until(2, [&] { return !ground.GetGroundItemPosition(FakeLoginServer::kGroundItemVID, &item_pos); }));
CHECK(tail_info().find("ItemTail (Map 0,") != std::string::npos);
}
// Exchange (CPythonExchange + exchange module): net.SendExchangeStartPacket → the fake partner's GC_EXCHANGE
// START/ITEM_ADD/GOLD_ADD fill the target side and open uiexchange; net.SendExchangeExitPacket → END.
if (server)
{
CHECK(py("import net\nnet.SendExchangeStartPacket(" + std::to_string(FakeLoginServer::kMainVID) + ")"));
CHECK(pump_until(2, [&] { return CPythonExchange::Instance().GetElkFromTarget() == FakeLoginServer::kExchangeGold; }));
CHECK(py("import exchange\n"
"assert exchange.isTrading() == 1\n"
"assert exchange.GetItemVnumFromTarget(0) == " + std::to_string(FakeLoginServer::kExchangeItemVnum) + "\n"
"assert exchange.GetItemCountFromTarget(0) == 1\n"
"assert exchange.GetElkFromSelf() == 0"));
CHECK(py("import net\nnet.SendExchangeExitPacket()"));
CHECK(pump_until(2, [&] { return !CPythonExchange::Instance().isTrading(); }));
CHECK(server->Has("game2:exchange 0 " + std::to_string(FakeLoginServer::kMainVID)));
CHECK(server->Has("game2:exchange 5"));
// uiexchange.CloseDialog armed wndMgr.OnceIgnoreMouseLeftButtonUpEvent (in the client that release belongs
// to the click that closed the dialog); spend it so step 8's click-release is not swallowed.
PythonBoot::UIMouseButton(1, false, 400, 520);
// Chat (批次 4-a): Return on the focused game.GameWindow → OnIMEReturn → interface.ToggleChat opens the
// chat line; the typed text goes through CPythonIME, a second Return sends CG_CHAT (TALKING) and the fake
// server echoes GC_CHAT back.
CHECK(py_true("not _stream.curPhaseWindow.interface.IsOpenChat()"));
PythonBoot::UIChar(VK_RETURN);
CHECK(pump_until(1, [] { return py_true("_stream.curPhaseWindow.interface.IsOpenChat()"); }));
for (char c : std::string("hello"))
PythonBoot::UIChar((unsigned char)c);
pump_until(0.05, [] { return false; });
PythonBoot::UIChar(VK_RETURN);
CHECK(pump_until(2, [&] { return server->Has("game2:chat 0 hello"); }));
// uichat.__SendTalkingChatPacket only resets the line; a Return on the empty line closes it (eventReturn).
CHECK(py_true("_stream.curPhaseWindow.interface.IsOpenChat() and __import__('ime').GetText(0) == ''"));
// Touch hosts raise the system keyboard only for a tap on the focused, visible EditLine. A chat line
// that keeps the focus under a hidden board (interfacemodule.__HideWindows for an NPC dialog, then the
// focus handed back by UnlockWindow/DeactivateWindow) must not, wherever the tap lands.
{
std::string xywh;
CHECK(py("_line = _stream.curPhaseWindow.interface.wndChat.chatInputSet.chatLine"));
CHECK(PythonBoot::Evaluate("'%d %d %d %d' % (_line.GetGlobalPosition() + (_line.GetWidth(), _line.GetHeight()))",
&xywh, nullptr));
int x = 0, y = 0, w = 0, h = 0;
std::sscanf(xywh.c_str(), "%d %d %d %d", &x, &y, &w, &h);
const int cx = x + w / 2, cy = y + h / 2;
CHECK(w > 0 && h > 0);
CHECK(PythonBoot::TextInputFocused());
CHECK(PythonBoot::IsPointInsideFocusedWindow(cx, cy));
CHECK(!PythonBoot::IsPointInsideFocusedWindow(790, 10));
CHECK(py("_stream.curPhaseWindow.interface.wndChat.Hide()"));
CHECK(PythonBoot::TextInputFocused());
CHECK(!PythonBoot::IsPointInsideFocusedWindow(cx, cy));
CHECK(py("_stream.curPhaseWindow.interface.wndChat.Show()"));
CHECK(PythonBoot::IsPointInsideFocusedWindow(cx, cy));
}
PythonBoot::UIChar(VK_RETURN);
CHECK(pump_until(1, [] { return py_true("not _stream.curPhaseWindow.interface.IsOpenChat()"); }));
}
// 8. (批次 2V3) Click-to-move: a left click on the ground below the actor reaches game.GameWindow's
// OnMouseLeftButtonDown → player.SetMouseState(MBT_LEFT, MBS_PRESS); CPythonPlayer picks the ground
// through the cursor ray (CScreen::SetCursorPosition → CPythonBackground::GetPickingPoint) and the
// actor walks to it, sending CG_MOVE FUNC_MOVE, then FUNC_WAIT on arrival.
const size_t moves_before = server ? server->Events().size() : 0;
if (main_instance)
main_instance->NEW_GetPixelPosition(&start);
PythonBoot::UIMouseButton(1, true, 400, 220);
pump_frames(6);
PythonBoot::UIMouseButton(1, false, 400, 220);
CHECK(main_instance && pump_until(3, [&] { return walked() > 100.0f; }));
CHECK(main_instance && pump_until(10, [&] { return !main_instance->IsWalking(); }));
std::printf("port_login_flow_test: click walked %.0f cm\n", main_instance ? walked() : 0.0f);
if (server)
{
auto click_moves = [&] {
std::vector<std::string> out;
const auto events = server->Events();
for (size_t i = moves_before; i < events.size(); ++i)
if (events[i].rfind("game2:move ", 0) == 0)
out.push_back(events[i]);
return out;
};
CHECK(pump_until(2, [&] { auto m = click_moves(); return m.size() >= 2 && m.back().rfind("game2:move 0 ", 0) == 0; }));
const auto m = click_moves();
CHECK(!m.empty() && m.front().rfind("game2:move 1 0 ", 0) == 0);
for (const auto& e : m)
std::printf("port_login_flow_test: %s\n", e.c_str());
}
}
if (server) server->combatFixtureDamage = false;
#include "autohunt_pull_checks.inc"
#include "autohunt_recovery_checks.inc"
#include "autohunt_crowd_checks.inc"
if (server) server->combatFixtureDamage = true;
// 9. (批次 4-b) Combat: a left click on the stray dog reaches CPythonPlayer::__OnClickActor, which targets it
// (CG_TARGET → GC_TARGET, uitarget shows the HP board) and walks into range to attack. Each attack frame's
// hit (CPythonPlayerEventHandler::OnHit) sends CG_ATTACK; the fake server answers GC_DAMAGE_INFO + GC_TARGET,
// and GC_DEAD on the third hit.
if (server)
{
CInstanceBase* mob = CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kMobVID);
CHECK(mob != nullptr);
if (mob)
{
CHECK(!mob->IsDead());
// Project the dog's body with RenderGame's perspective and the current camera (after the frame the
// graphic state holds the UI's ortho projection).
auto dog_on_screen = [&] {
UI::CWindowManager& wm = UI::CWindowManager::Instance();
D3DXMATRIX proj, identity;
D3DXMatrixPerspectiveFovRH(&proj, D3DXToRadian(30.0f), wm.GetAspect(), 100.0f,
CPythonBackground::Instance().GetFarClip());
D3DXMatrixIdentity(&identity);
D3DVIEWPORT8 viewport = {0, 0, (DWORD) wm.GetScreenWidth(), (DWORD) wm.GetScreenHeight(), 0.0f, 1.0f};
const D3DXVECTOR3 body = mob->GetGraphicThingInstanceRef().GetPosition() + D3DXVECTOR3(0.0f, 0.0f, 40.0f);
D3DXVECTOR3 screen;
D3DXVec3Project(&screen, &body, &viewport, &proj,
&CCameraManager::Instance().GetCurrentCamera()->GetViewMatrix(), &identity);
return std::make_pair((int) screen.x, (int) screen.y);
};
auto [sx, sy] = dog_on_screen();
std::printf("port_login_flow_test: stray dog on screen at %d %d\n", sx, sy);
PythonBoot::UIMouseMove(sx, sy);
pump_frames(6);
// game.GameWindow.OnMouseLeftButtonDown → player.SetMouseState(MBT_LEFT, MBS_PRESS): MBF_SMART on an
// actor is __OnPressActor, which walks into range (__ReserveClickActor) and attacks while the button is
// held; the cursor follows the dog as the camera follows the actor, as a player's hand would.
PythonBoot::UIMouseButton(1, true, sx, sy);
const std::string mob_vid = std::to_string(FakeLoginServer::kMobVID);
CHECK(pump_until(2, [&] { return server->Has("game2:target " + mob_vid); }));
CHECK(pump_until(2, [] { return py_true("_stream.curPhaseWindow.targetBoard.IsShow()"); }));
CHECK(pump_until(10, [&] {
std::tie(sx, sy) = dog_on_screen();
PythonBoot::UIMouseMove(sx, sy);
return mob->IsDead();
}));
PythonBoot::UIMouseButton(1, false, sx, sy);
size_t attacks = 0;
for (const auto& e : server->Events())
if (e == "game2:attack 0 " + mob_vid)
++attacks;
std::printf("port_login_flow_test: %zu attack(s) until the stray dog died\n", attacks);
CHECK(attacks >= (size_t) FakeLoginServer::kMobHits);
// Camera mouse wheel zoom test:
// Test zooming in (Wheel UP, positive delta) and zooming out (Wheel DOWN, negative delta).
{
CCamera* pkCmrCur = CCameraManager::Instance().GetCurrentCamera();
CHECK(pkCmrCur != nullptr);
if (pkCmrCur)
{
const float initial_dist = pkCmrCur->GetDistance();
std::printf("port_login_flow_test: initial camera distance = %f\n", initial_dist);
// Zoom IN: positive wheel delta
PythonBoot::UIMouseWheel(120);
pump_frames(6);
const float zoomed_in_dist = pkCmrCur->GetDistance();
std::printf("port_login_flow_test: zoomed in camera distance = %f\n", zoomed_in_dist);
CHECK(zoomed_in_dist < initial_dist);
// Zoom OUT: negative wheel delta
PythonBoot::UIMouseWheel(-240);
pump_frames(6);
const float zoomed_out_dist = pkCmrCur->GetDistance();
std::printf("port_login_flow_test: zoomed out camera distance = %f\n", zoomed_out_dist);
CHECK(zoomed_out_dist > zoomed_in_dist);
}
}
// P-grade skill test: verify P-grade skill (geomgyeong / Aura of the Sword) uses Grade 3 motion (geomgyeong_4.msa),
// spawns effect instances (geom_4_badak.mse, geom_4_sword_making.mse), and renders them.
{
CPythonPlayer& rkPlayer = CPythonPlayer::Instance();
rkPlayer.SetStatus(POINT_SP, 1000);
rkPlayer.SetStatus(POINT_MAX_SP, 1000);
rkPlayer.SetStatus(POINT_HP, 1000);
rkPlayer.SetStatus(POINT_MAX_HP, 1000);
CInstanceBase* pkInstMain = rkPlayer.NEW_GetMainActorPtr();
CHECK(pkInstMain != nullptr);
if (pkInstMain)
{
pkInstMain->ChangeWeapon(19);
rkPlayer.SetSkill(4, 4); // slot 4 = geomgyeong
rkPlayer.SetSkillLevel_(4, 3, 40); // Grade 3 (P), Level 40
CHECK(rkPlayer.GetSkillGrade(4) == 3);
rkPlayer.ClickSkillSlot(4);
CHECK(pkInstMain->IsUsingSkill());
bool has_effects = false;
for (int step = 0; step < 10; ++step)
{
pump_frames(6);
if (CEffectInstance::GetRenderingEffectCount() > 0)
has_effects = true;
}
CHECK(has_effects);
}
}
}
}
// 10. (批次 4-c) NPC shop: a click on the general store walks up to it (__OnClickActor) and sends CG_ON_CLICK;
// the fake server's GC_SHOP START fills CPythonShop and game.StartShop opens uishop.ShopDialog next to the
// inventory. A right click on shelf slot 0 buys (uishop.UnselectItemSlot → net.SendShopBuyPacket); the
// potion lands in inventory cell 0 and the gold drops. Picking it up in the inventory and dropping it on an
// empty shelf slot sells it (SelectEmptySlot → SellAttachedItem → SendShopSellPacketNew); ESC closes the
// shop (CG_SHOP END → GC_SHOP END).
if (server)
{
CInstanceBase* keeper = CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kShopVID);
CHECK(keeper != nullptr);
if (keeper)
{
auto keeper_on_screen = [&] {
UI::CWindowManager& wm = UI::CWindowManager::Instance();
D3DXMATRIX proj, identity;
D3DXMatrixPerspectiveFovRH(&proj, D3DXToRadian(30.0f), wm.GetAspect(), 100.0f,
CPythonBackground::Instance().GetFarClip());
D3DXMatrixIdentity(&identity);
D3DVIEWPORT8 viewport = {0, 0, (DWORD) wm.GetScreenWidth(), (DWORD) wm.GetScreenHeight(), 0.0f, 1.0f};
const D3DXVECTOR3 body = keeper->GetGraphicThingInstanceRef().GetPosition() + D3DXVECTOR3(0.0f, 0.0f, 100.0f);
D3DXVECTOR3 screen;
D3DXVec3Project(&screen, &body, &viewport, &proj,
&CCameraManager::Instance().GetCurrentCamera()->GetViewMatrix(), &identity);
return std::make_pair((int) screen.x, (int) screen.y);
};
auto [kx, ky] = keeper_on_screen();
std::printf("port_login_flow_test: shopkeeper on screen at %d %d\n", kx, ky);
PythonBoot::UIMouseMove(kx, ky);
pump_frames(6);
PythonBoot::UIMouseButton(1, true, kx, ky);
pump_frames(6);
PythonBoot::UIMouseButton(1, false, kx, ky);
CHECK(pump_until(5, [&] { return server->Has("game2:click " + std::to_string(FakeLoginServer::kShopVID)); }));
CHECK(pump_until(2, [] { return py_true("__import__('shop').IsOpen() and _stream.curPhaseWindow.interface.dlgShop.IsShow()"); }));
CHECK(py("import shop\n"
"assert shop.GetItemID(0) == " + std::to_string(FakeLoginServer::kShopItemVnum) + ", shop.GetItemID(0)\n"
"assert shop.GetItemPrice(0) == " + std::to_string(FakeLoginServer::kShopItemPrice) + "\n"
"assert shop.IsPrivateShop() == 0\n"
"assert _stream.curPhaseWindow.interface.wndInventory.IsShow()"));
// Slot 0 is the top-left cell of each grid.
auto slot0 = [](const char* grid) {
std::string xy;
CHECK(PythonBoot::Evaluate((std::string("'%d %d' % _stream.curPhaseWindow.interface.") + grid + ".GetGlobalPosition()").c_str(), &xy, nullptr));
int x = 0, y = 0;
std::sscanf(xy.c_str(), "%d %d", &x, &y);
return std::make_pair(x + 16, y + 16);
};
auto click = [](int button, std::pair<int, int> at) {
PythonBoot::UIMouseMove(at.first, at.second);
pump_until(0.05, [] { return false; });
PythonBoot::UIMouseButton(button, true, at.first, at.second);
pump_until(0.05, [] { return false; });
PythonBoot::UIMouseButton(button, false, at.first, at.second);
pump_until(0.05, [] { return false; });
};
const auto shelf0 = slot0("dlgShop.itemSlotWindow");
const auto bag0 = slot0("wndInventory.wndItem");
std::printf("port_login_flow_test: shelf slot at %d %d, bag slot at %d %d\n", shelf0.first, shelf0.second, bag0.first, bag0.second);
click(2, shelf0);
CHECK(pump_until(2, [&] { return server->Has("game2:shop 1 1 0"); }));
const std::string bought_gold = std::to_string(FakeLoginServer::kStartGold - (int) FakeLoginServer::kShopItemPrice);
CHECK(pump_until(2, [&] {
return py_true(("__import__('player').GetItemIndex(0) == " + std::to_string(FakeLoginServer::kShopItemVnum) +
" and __import__('player').GetElk() == " + bought_gold).c_str());
}));
pump_ui_refresh();
if (mobile_test) {
CHECK(py("import mt_mobile_inventory, mouseModule, player\n"
"_bag = _stream.curPhaseWindow.interface.wndInventory"));
// Existing game rules forbid taking equipment off while shopping.
PythonBoot::UIKey(DIK_ESCAPE, true);
PythonBoot::UIKey(DIK_ESCAPE, false);
CHECK(pump_until(2, [] { return py_true("not shop.IsOpen()"); }));
pump_ui_refresh(); // let the server's SHOP_END finish before reopening the bag
CHECK(py("_bag.Show()\n_bag.SetTop()"));
TouchController touch;
touch.set_enabled(true);
touch.update_screen_size(800, 600);
auto tap_at = [&](std::pair<int, int> at) {
CHECK(touch.on_finger_down(301, float(at.first)/800, float(at.second)/600));
CHECK(touch.on_finger_up(301, float(at.first)/800, float(at.second)/600));
pump_frames(1);
};
auto drag_to = [&](std::pair<int, int> from, std::pair<int, int> to) {
CHECK(touch.on_finger_down(302, float(from.first)/800, float(from.second)/600));
CHECK(touch.on_finger_motion(302, float(to.first)/800, float(to.second)/600));
CHECK(py_true("mouseModule.mouseController.isAttached()"));
CHECK(touch.on_finger_up(302, float(to.first)/800, float(to.second)/600));
};
const auto weapon = std::make_pair(bag0.first+64, bag0.second);
tap_at(weapon);
CHECK(py_true("_bag.tooltipItem.IsShow() and not mouseModule.mouseController.isAttached()"));
CHECK(!server->Has("game2:item_use 2"));
tap_at(weapon);
CHECK(pump_until(2, [&] { return server->Has("game2:item_use 2") &&
py_true("player.GetItemIndex(2) == 0 and player.GetItemIndex(player.EQUIPMENT_SLOT_START+4) == 19"); }));
pump_ui_refresh();
auto equipped = slot0("wndInventory.wndEquip");
equipped.first += 3; equipped.second += 3; // weapon cell's original local (3,3)
tap_at(equipped);
tap_at(equipped);
CHECK(pump_until(2, [&] { return server->Has("game2:item_use 229") &&
py_true("player.GetItemIndex(2) == 19 and player.GetItemIndex(player.EQUIPMENT_SLOT_START+4) == 0"); }));
CHECK(py("net.SendOnClickPacket(" + std::to_string(FakeLoginServer::kShopVID) + ")"));
CHECK(pump_until(2, [] { return py_true("shop.IsOpen()"); }));
pump_ui_refresh();
const auto bag1 = std::make_pair(bag0.first+32, bag0.second);
drag_to(bag0, bag1);
CHECK(pump_until(2, [&] { return server->Has("game2:item_move 0 1") &&
py_true("player.GetItemIndex(0) == 0 and player.GetItemIndex(1) == 27001"); }));
pump_ui_refresh();
drag_to(bag1, bag0);
CHECK(pump_until(2, [&] { return server->Has("game2:item_move 1 0") &&
py_true("player.GetItemIndex(0) == 27001 and player.GetItemIndex(1) == 0"); }));
pump_ui_refresh();
// A page change invalidates the first tap, even when the second touch is at the same pixels.
tap_at(weapon);
const auto before_stale = server->Events().size();
CHECK(py("_bag.SetInventoryPage(1)"));
tap_at(weapon);
CHECK(py("_bag.SetInventoryPage(0)\nassert not mouseModule.mouseController.isAttached()"));
pump_frames(2);
auto recent = server->Events();
for (size_t i = before_stale; i < recent.size(); ++i)
CHECK(recent[i].find(":item_use ") == std::string::npos);
pump_ui_refresh();
auto shop_blank = slot0("dlgShop"); // title/body background, not a shelf slot
// A stale drag must not sell whatever is now in that slot.
CHECK(touch.on_finger_down(303, float(bag0.first)/800, float(bag0.second)/600));
CHECK(touch.on_finger_motion(303, float(shop_blank.first)/800, float(shop_blank.second)/600));
CHECK(py("_bag.SetInventoryPage(1)"));
CHECK(touch.on_finger_up(303, float(shop_blank.first)/800, float(shop_blank.second)/600));
CHECK(py("assert not mouseModule.mouseController.isAttached()\n"
"assert not __import__('constInfo').GET_ITEM_QUESTION_DIALOG_STATUS()\n"
"_bag.SetInventoryPage(0)"));
pump_ui_refresh();
drag_to(bag0, shop_blank);
CHECK(py_true("_bag.questionDialog and _bag.questionDialog.IsShow()"));
CHECK(!server->Has("game2:shop 3 0 1"));
CHECK(py("_bag.OnCloseQuestionDialog()"));
CHECK(py_true("player.GetItemIndex(0) == 27001"));
drag_to(bag0, shop_blank);
CHECK(py("_bag.SellItem()"));
} else {
click(1, bag0);
CHECK(py_true("__import__('mouseModule').mouseController.isAttached()"));
click(1, std::make_pair(shelf0.first + 32, shelf0.second));
}
CHECK(pump_until(2, [&] { return server->Has("game2:shop 3 0 1"); }));
const std::string sold_gold = std::to_string(FakeLoginServer::kStartGold - (int) FakeLoginServer::kShopItemPrice + FakeLoginServer::kShopSellPrice);
CHECK(pump_until(2, [&] {
return py_true(("__import__('player').GetItemIndex(0) == 0 and __import__('player').GetElk() == " + sold_gold).c_str());
}));
if (mobile_test) {
CHECK(py("_stream.curPhaseWindow.interface.dlgShop.Close()"));
} else {
PythonBoot::UIKey(DIK_ESCAPE, true);
PythonBoot::UIKey(DIK_ESCAPE, false);
}
CHECK(pump_until(2, [&] { return server->Has("game2:shop 0"); }));
CHECK(pump_until(2, [] { return py_true("not __import__('shop').IsOpen() and not _stream.curPhaseWindow.interface.dlgShop.IsShow()"); }));
}
}
// Quest dialogue (CPythonEventManager + CPythonQuest + event module): clicking the quest NPC (kQuestVID)
// triggers CHARACTER::OnClick → CQuestManager::Click which sends GC_SCRIPT. The client parses the script
// through CPythonEventManager / parser.cpp and opens uiQuest.QuestDialog.
// 1. Initial page: say + select ([QUESTION 1;Yes|2;No]).
// Clicking "Yes" (answer 0) sends CG_SCRIPT_ANSWER 0.
// 2. Second page: say + [NEXT].
// Clicking Next sends CG_SCRIPT_ANSWER 254 (> 250).
// 3. Final page: say + [DONE].
// Clicking OK closes the dialogue.
if (server)
{
py("if _stream.curPhaseWindow.interface.wndInventory.IsShow(): _stream.curPhaseWindow.interface.wndInventory.Hide()");
CInstanceBase* elder = CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kQuestVID);
CHECK(elder != nullptr);
if (elder)
{
auto elder_on_screen = [&] {
UI::CWindowManager& wm = UI::CWindowManager::Instance();
D3DXMATRIX proj, identity;
D3DXMatrixPerspectiveFovRH(&proj, D3DXToRadian(30.0f), wm.GetAspect(), 100.0f,
CPythonBackground::Instance().GetFarClip());
D3DXMatrixIdentity(&identity);
D3DVIEWPORT8 viewport = {0, 0, (DWORD) wm.GetScreenWidth(), (DWORD) wm.GetScreenHeight(), 0.0f, 1.0f};
const D3DXVECTOR3 body = elder->GetGraphicThingInstanceRef().GetPosition() + D3DXVECTOR3(0.0f, 0.0f, 100.0f);
D3DXVECTOR3 screen;
D3DXVec3Project(&screen, &body, &viewport, &proj,
&CCameraManager::Instance().GetCurrentCamera()->GetViewMatrix(), &identity);
return std::make_pair((int) screen.x, (int) screen.y);
};
// CPythonPlayer::__SendClickActorPacket enforces a 1000ms TCP rate-limit between NPC clicks
pump_until(1.0, [] { return false; });
auto [ex, ey] = elder_on_screen();
std::printf("port_login_flow_test: quest elder on screen at %d %d\n", ex, ey);
auto click_elder = [&] {
std::tie(ex, ey) = elder_on_screen();
PythonBoot::UIMouseMove(ex, ey);
pump_until(0.05, [] { return false; });
PythonBoot::UIMouseButton(1, true, ex, ey);
pump_until(0.05, [] { return false; });
PythonBoot::UIMouseButton(1, false, ex, ey);
};
click_elder();
CHECK(pump_until(5, [&] {
if (server->Has("game2:click " + std::to_string(FakeLoginServer::kQuestVID)))
return true;
click_elder();
return false;
}));
CHECK(pump_until(2, [] {
return py_true("len(_stream.curPhaseWindow.interface.wndQuestWindow) > 0 and "
"list(_stream.curPhaseWindow.interface.wndQuestWindow.values())[-1].btnAnswer is not None and "
"len(list(_stream.curPhaseWindow.interface.wndQuestWindow.values())[-1].btnAnswer) >= 2");
}));
auto press_enter = [] {
PythonBoot::UIKey(DIK_RETURN, true);
pump_until(0.05, [] { return false; });
PythonBoot::UIKey(DIK_RETURN, false);
pump_until(0.05, [] { return false; });
};
// Page 1: DIK_RETURN triggers focusBtn.CallEvent() for choice 0 ("Yes").
press_enter();
CHECK(pump_until(2, [&] { return server->Has("game2:answer 0"); }));
// Page 2: [NEXT]
CHECK(pump_until(2, [] {
return py_true("len(_stream.curPhaseWindow.interface.wndQuestWindow) > 0 and "
"list(_stream.curPhaseWindow.interface.wndQuestWindow.values())[-1].btnNext is not None");
}));
// Page 2: DIK_RETURN on Next button triggers OnPressEscapeKey() which selects 254 and closes.
press_enter();
CHECK(pump_until(2, [&] { return server->Has("game2:answer 254"); }));
// Page 3: [DONE]
CHECK(pump_until(2, [] {
return py_true("len(_stream.curPhaseWindow.interface.wndQuestWindow) > 0 and "
"list(_stream.curPhaseWindow.interface.wndQuestWindow.values())[-1].btnNext is not None and "
"getattr(list(_stream.curPhaseWindow.interface.wndQuestWindow.values())[-1], 'nextButtonType', None) == 1");
}));
// Page 3: DIK_RETURN on Done button closes the dialogue without further packets.
press_enter();
CHECK(pump_until(2, [] {
return py_true("len(_stream.curPhaseWindow.interface.wndQuestWindow) == 0");
}));
}
}
// Safebox (CPythonSafeBox + safebox module): clicking the storekeeper (kSafeboxVID)
// triggers CHARACTER::OnClick → ShowMeSafeboxPassword server command. The client opens
// PasswordDialog. Typing the password sends /safebox_password <pass>, opening SafeboxWindow.
// We verify:
// 1. Click Storekeeper, receive password dialog.
// 2. Press DIK_RETURN to submit password, server answers GC_SAFEBOX_SIZE (1 page = 45 slots),
// GC_SAFEBOX_MONEY_CHANGE (500) and initial item (kSafeboxItemVnum = 10 in slot 0).
// 3. Verify SafeboxWindow is open, safebox.GetCurrentSafeboxSize() == 45, safebox.GetItemID(0) == 10.
// 4. Checkout: drag safebox slot 0 to inventory slot 0.
// Server answers GC_SAFEBOX_DEL 0 and GC_ITEM_SET (inventory cell 0 = 10).
// Verify safebox slot 0 is empty (0) and player inventory slot 0 has 10.
// 5. Checkin: drag inventory slot 0 to safebox slot 0.
// Server answers GC_ITEM_DEL (inventory cell 0) and GC_SAFEBOX_SET (safebox cell 0 = 10).
// Verify player inventory slot 0 is empty (0) and safebox slot 0 has 10.
// 6. Close safebox via ESC: client sends /safebox_close, server replies CloseSafebox,
// SafeboxWindow closes.
if (server)
{
CInstanceBase* storekeeper = CPythonCharacterManager::Instance().GetInstancePtr(FakeLoginServer::kSafeboxVID);
CHECK(storekeeper != nullptr);
if (storekeeper)
{
auto storekeeper_on_screen = [&] {
UI::CWindowManager& wm = UI::CWindowManager::Instance();
D3DXMATRIX proj, identity;
D3DXMatrixPerspectiveFovRH(&proj, D3DXToRadian(30.0f), wm.GetAspect(), 100.0f,
CPythonBackground::Instance().GetFarClip());
D3DXMatrixIdentity(&identity);
D3DVIEWPORT8 viewport = {0, 0, (DWORD) wm.GetScreenWidth(), (DWORD) wm.GetScreenHeight(), 0.0f, 1.0f};
const D3DXVECTOR3 body = storekeeper->GetGraphicThingInstanceRef().GetPosition() + D3DXVECTOR3(0.0f, 0.0f, 100.0f);
D3DXVECTOR3 screen;
D3DXVec3Project(&screen, &body, &viewport, &proj,
&CCameraManager::Instance().GetCurrentCamera()->GetViewMatrix(), &identity);
return std::make_pair((int) screen.x, (int) screen.y);
};
auto [sx, sy] = storekeeper_on_screen();
std::printf("port_login_flow_test: storekeeper on screen at %d %d\n", sx, sy);
PythonBoot::UIMouseMove(sx, sy);
pump_frames(6);
PythonBoot::UIMouseButton(1, true, sx, sy);
pump_frames(6);
PythonBoot::UIMouseButton(1, false, sx, sy);
CHECK(pump_until(5, [&] { return server->Has("game2:click " + std::to_string(FakeLoginServer::kSafeboxVID)); }));
CHECK(pump_until(2, [] {
return py_true("_stream.curPhaseWindow.interface.dlgPassword.IsShow()");
}));
// Submit password dialog with VK_RETURN (IME return on focused edit line)
PythonBoot::UIChar(VK_RETURN);
CHECK(pump_until(2, [&] { return server->Has("game2:safebox_password "); }));
CHECK(pump_until(2, [] {
return py_true("_stream.curPhaseWindow.interface.wndSafebox.IsShow()");
}));
CHECK(pump_until(2, [] {
return py_true(("__import__('safebox').GetCurrentSafeboxSize() == 45 and "
"__import__('safebox').GetItemID(0) == " + std::to_string(FakeLoginServer::kSafeboxItemVnum) + " and "
"__import__('safebox').GetMoney() == " + std::to_string(FakeLoginServer::kSafeboxMoney)).c_str());
}));
// Ensure inventory is visible for slot drag-and-drop
py("_stream.curPhaseWindow.interface.wndInventory.Show()");
CHECK(pump_until(2, [] {
return py_true("_stream.curPhaseWindow.interface.wndInventory.IsShow()");
}));
auto slot0 = [](const char* grid) {
std::string xy;
CHECK(PythonBoot::Evaluate((std::string("'%d %d' % _stream.curPhaseWindow.interface.") + grid + ".GetGlobalPosition()").c_str(), &xy, nullptr));
int x = 0, y = 0;
std::sscanf(xy.c_str(), "%d %d", &x, &y);
return std::make_pair(x + 16, y + 16);
};
auto click = [](int btn, std::pair<int, int> pos) {
PythonBoot::UIMouseMove(pos.first, pos.second);
pump_until(0.05, [] { return false; });
PythonBoot::UIMouseButton(btn, true, pos.first, pos.second);
pump_until(0.05, [] { return false; });
PythonBoot::UIMouseButton(btn, false, pos.first, pos.second);
pump_until(0.05, [] { return false; });
};
const auto safe0 = slot0("wndSafebox.wndItem");
const auto bag0 = slot0("wndInventory.wndItem");
std::printf("port_login_flow_test: safebox slot 0 at %d %d, bag slot 0 at %d %d\n", safe0.first, safe0.second, bag0.first, bag0.second);
// Checkout: drag from safebox slot 0 to inventory slot 0
pump_ui_refresh();
click(1, safe0);
CHECK(py_true("__import__('mouseModule').mouseController.isAttached()"));
click(1, bag0);
CHECK(pump_until(2, [&] { return server->Has("game2:safebox_checkout 0 -> 0"); }));
CHECK(pump_until(2, [&] {
return py_true(("__import__('safebox').GetItemID(0) == 0 and "
"__import__('player').GetItemIndex(0) == " + std::to_string(FakeLoginServer::kSafeboxItemVnum)).c_str());
}));
// Checkin: drag from inventory slot 0 back to safebox slot 0
pump_ui_refresh();
click(1, bag0);
CHECK(py_true("__import__('mouseModule').mouseController.isAttached()"));
click(1, safe0);
CHECK(pump_until(2, [&] { return server->Has("game2:safebox_checkin 0 -> 0"); }));
CHECK(pump_until(2, [&] {
return py_true(("__import__('player').GetItemIndex(0) == 0 and "
"__import__('safebox').GetItemID(0) == " + std::to_string(FakeLoginServer::kSafeboxItemVnum)).c_str());
}));
// Close Safebox via ESC
PythonBoot::UIKey(DIK_ESCAPE, true);
pump_until(0.05, [] { return false; });
PythonBoot::UIKey(DIK_ESCAPE, false);
pump_until(0.05, [] { return false; });
CHECK(pump_until(2, [&] { return server->Has("game2:safebox_close"); }));
CHECK(pump_until(2, [] {
return py_true("not _stream.curPhaseWindow.interface.wndSafebox.IsShow()");
}));
}
}
// 13. (批次 4-f) Messenger / Guild / GuildMark:
// The fake server sent friend list ("TestFriend") and guild info/name ("TestGuild", ID 1)
// during the entergame burst.
// Verify:
// - CPythonMessenger / messenger module: IsFriendByName, RemoveFriend
// - CPythonGuild / guild module: IsGuildEnable, GetGuildID, GetGuildName, GetGuildMoney, HasGuildLand
// - CGuildMarkManager: AddMarkIDByGuildID, GetMarkID, GuildIDToMarkID, GetMarkIndexByMarkID
if (server)
{
CHECK(py("import messenger, guild"));
// Messenger
CHECK(CPythonMessenger::Instance().IsFriendByName(FakeLoginServer::kFriendName));
CHECK(py_true("messenger.IsFriendByName('TestFriend') == 1"));
CHECK(py_true("messenger.IsFriendByName('NonExistent') == 0"));
// Guild
CHECK(CPythonGuild::Instance().IsGuildEnable());
CHECK(CPythonGuild::Instance().GetGuildID() == FakeLoginServer::kGuildID);
std::string guild_name;
CHECK(CPythonGuild::Instance().GetGuildName(FakeLoginServer::kGuildID, &guild_name) && guild_name == FakeLoginServer::kGuildName);
CHECK(py_true("guild.IsGuildEnable() == 1"));
CHECK(py_true("guild.GetGuildID() == 1"));
CHECK(py_true("guild.GetGuildName() == 'TestGuild'"));
CHECK(py_true("guild.GetGuildName(1) == 'TestGuild'"));
CHECK(py_true("guild.GetGuildMoney() == 123456"));
CHECK(py_true("guild.HasGuildLand() == 1"));
// GuildMark
CGuildMarkManager::Instance().AddMarkIDByGuildID(FakeLoginServer::kGuildID, 42);
CHECK(CGuildMarkManager::Instance().GetMarkID(FakeLoginServer::kGuildID) == 42);
CHECK(py_true("guild.GuildIDToMarkID(1) == 42"));
CHECK(py_true("guild.GetMarkIndexByMarkID(42) == 42"));
// Messenger RemoveFriend
CHECK(py("import messenger\nmessenger.RemoveFriend('TestFriend')"));
CHECK(!CPythonMessenger::Instance().IsFriendByName(FakeLoginServer::kFriendName));
CHECK(py_true("messenger.IsFriendByName('TestFriend') == 0"));
}
// 14. (批次 4-g) System Settings & Combat Damage Floating Text (CPythonSystem / systemSetting):
// Verify:
// - systemSetting module imported cleanly without __port_stub__
// - CPythonSystem resolution enumeration (via CDummyDirect3D8): GetResolutionCount, GetResolution
// - Width, Height, BPP
// - Combat floating damage flag: IsShowDamage, SetShowDamageFlag, CPythonSystem::Instance().IsShowDamage()
// - Other system setting flags: IsViewChat, SetViewChatFlag, IsAlwaysShowName, SetAlwaysShowNameFlag, IsShowSalesText, SetShowSalesTextFlag
// - Music/Sound volume: GetMusicVolume, SetMusicVolume, GetSoundVolume, SetSoundVolumef
// - Config save & load: GetConfig, SaveConfig
{
CHECK(py("import systemSetting"));
CHECK(py_true("not hasattr(systemSetting, '__port_stub__')"));
// Resolution enumeration & screen size
CHECK(CPythonSystem::Instance().GetResolutionCount() > 0);
CHECK(py_true("systemSetting.GetResolutionCount() > 0"));
CHECK(py_true("systemSetting.GetWidth() > 0 and systemSetting.GetHeight() > 0"));
CHECK(py_true("len(systemSetting.GetResolution(0)) == 3"));
// Combat damage text flag
CPythonSystem::Instance().SetShowDamageFlag(true);
CHECK(CPythonSystem::Instance().IsShowDamage());
CHECK(py_true("systemSetting.IsShowDamage() == 1"));
CHECK(py("systemSetting.SetShowDamageFlag(0)"));
CHECK(!CPythonSystem::Instance().IsShowDamage());
CHECK(py_true("systemSetting.IsShowDamage() == 0"));
CHECK(py("systemSetting.SetShowDamageFlag(1)"));
CHECK(CPythonSystem::Instance().IsShowDamage());
CHECK(py_true("systemSetting.IsShowDamage() == 1"));
// Chat view flag
CHECK(py("systemSetting.SetViewChatFlag(0)"));
CHECK(!CPythonSystem::Instance().IsViewChat());
CHECK(py_true("systemSetting.IsViewChat() == 0"));
CHECK(py("systemSetting.SetViewChatFlag(1)"));
CHECK(CPythonSystem::Instance().IsViewChat());
CHECK(py_true("systemSetting.IsViewChat() == 1"));
// Always show name flag
CHECK(py("systemSetting.SetAlwaysShowNameFlag(0)"));
CHECK(!CPythonSystem::Instance().IsAlwaysShowName());
CHECK(py_true("systemSetting.IsAlwaysShowName() == 0"));
CHECK(py("systemSetting.SetAlwaysShowNameFlag(1)"));
CHECK(CPythonSystem::Instance().IsAlwaysShowName());
CHECK(py_true("systemSetting.IsAlwaysShowName() == 1"));
// Sales text flag
CHECK(py("systemSetting.SetShowSalesTextFlag(0)"));
CHECK(!CPythonSystem::Instance().IsShowSalesText());
CHECK(py_true("systemSetting.IsShowSalesText() == 0"));
CHECK(py("systemSetting.SetShowSalesTextFlag(1)"));
CHECK(CPythonSystem::Instance().IsShowSalesText());
CHECK(py_true("systemSetting.IsShowSalesText() == 1"));
// Extended FOV flag (F06)
CHECK(py_true("app.ENABLE_FOV_OPTION == 1"));
CHECK(py_true("app.ENABLE_HIGHLIGHT_NEW_ITEM == 1"));
CHECK(py_true("systemSetting.IsExtendedFOV() == 0"));
CHECK(CPythonSystem::Instance().GetFOV() == 30.0f);
CHECK(py("systemSetting.SetExtendedFOV(1)"));
CHECK(CPythonSystem::Instance().IsExtendedFOV());
CHECK(py_true("systemSetting.IsExtendedFOV() == 1"));
CHECK(CPythonSystem::Instance().GetFOV() == 40.0f);
CHECK(py("systemSetting.SetExtendedFOV(0)"));
CHECK(!CPythonSystem::Instance().IsExtendedFOV());
CHECK(CPythonSystem::Instance().GetFOV() == 30.0f);
// New item highlight (F05)
if (server)
{
CHECK(py_true("_stream.curPhaseWindow.interface.wndInventory is not None"));
CHECK(py("_stream.curPhaseWindow.BINARY_Highlight_Item(1, 3)")); // inventory cell 3 (has 30006 material)
CHECK(py_true("3 in getattr(_stream.curPhaseWindow.interface.wndInventory, 'liHighlightedItems', {})"));
// Page flip
CHECK(py("_stream.curPhaseWindow.interface.wndInventory.SetInventoryPage(1)"));
CHECK(py_true("3 in getattr(_stream.curPhaseWindow.interface.wndInventory, 'liHighlightedItems', {})"));
CHECK(py("_stream.curPhaseWindow.interface.wndInventory.SetInventoryPage(0)"));
// Hover dismisses
CHECK(py("_stream.curPhaseWindow.interface.wndInventory.OverInItem(3)"));
CHECK(py_true("3 not in getattr(_stream.curPhaseWindow.interface.wndInventory, 'liHighlightedItems', {})"));
// Out of bounds cell (>= 225) safely rejected without crashing or corrupting
CHECK(py("_stream.curPhaseWindow.BINARY_Highlight_Item(1, 225)"));
CHECK(py_true("225 not in getattr(_stream.curPhaseWindow.interface.wndInventory, 'liHighlightedItems', {})"));
}
// F03: Monster element icon & nonplayer constants
CHECK(py_true("app.ENABLE_ELEMENTAL_TARGET == 1"));
CHECK(py_true("nonplayer.RACE_FLAG_ATT_ELEC == 2048"));
CHECK(py_true("nonplayer.RACE_FLAG_ATT_FIRE == 4096"));
CHECK(py_true("nonplayer.RACE_FLAG_ATT_ICE == 8192"));
CHECK(py_true("nonplayer.RACE_FLAG_ATT_WIND == 16384"));
CHECK(py_true("nonplayer.RACE_FLAG_ATT_EARTH == 32768"));
CHECK(py_true("nonplayer.RACE_FLAG_ATT_DARK == 65536"));
CHECK(py("import mt_target_element"));
CHECK(py_true("mt_target_element.GetElementalFilename(0) == ''"));
CHECK(py_true("mt_target_element.SUB_RACE_FLAG_TO_FILENAME[nonplayer.RACE_FLAG_ATT_FIRE] == 'd:/ymir work/ui/game/12zi/element/fire.sub'"));
// F04: Trade level display
CHECK(py_true("app.ENABLE_LEVEL_IN_TRADE == 1"));
CHECK(py("import exchange"));
CPythonExchange::Instance().Clear();
CHECK(CPythonExchange::Instance().GetLevelFromSelf() == 0);
CHECK(CPythonExchange::Instance().GetLevelFromTarget() == 0);
CHECK(py_true("exchange.GetLevelFromSelf() == 0"));
CHECK(py_true("exchange.GetLevelFromTarget() == 0"));
CPythonExchange::Instance().SetSelfLevel(75);
CPythonExchange::Instance().SetTargetLevel(99);
CHECK(CPythonExchange::Instance().GetLevelFromSelf() == 75);
CHECK(CPythonExchange::Instance().GetLevelFromTarget() == 99);
CHECK(py_true("exchange.GetLevelFromSelf() == 75"));
CHECK(py_true("exchange.GetLevelFromTarget() == 99"));
CPythonExchange::Instance().Clear();
CHECK(CPythonExchange::Instance().GetLevelFromSelf() == 0);
CHECK(CPythonExchange::Instance().GetLevelFromTarget() == 0);
CHECK(py_true("exchange.GetLevelFromSelf() == 0"));
CHECK(py_true("exchange.GetLevelFromTarget() == 0"));
// F07: Advanced skybox
CHECK(py_true("app.ENABLE_ADVANCED_SKYBOX == 1"));
// F08: Minimap click teleportation
CHECK(py_true("app.ENABLE_MINIMAP_TELEPORT_CLICK == 1"));
CHECK(py("import uiminimap, mt_minimap_buttons"));
CHECK(py_true("hasattr(uiminimap.AtlasWindow, 'OnMouseLeftButtonUp')"));
CHECK(py_true("hasattr(uiminimap.AtlasWindow, 'OnMouseLeftButtonUpEvent')"));
// F13 - F20, F21, F23: Equipment & Enhancement Deep Features
CHECK(CItemData::WEAPON_QUIVER == 9);
CHECK(CItemData::WEARABLE_GLOVE == (1 << 16));
CHECK(CItemData::WEARABLE_PENDANT == (1 << 17));
CHECK(c_Equipment_Glove == c_Equipment_Start + 37);
CHECK(CItemData::APPLY_ACCEDRAIN_RATE == 97);
CHECK(CItemData::APPLY_RESIST_MAGIC_REDUCTION == 98);
CHECK(CItemData::APPLY_RANDOM == 118);
CHECK(CItemData::APPLY_MOUNT == 118);
CHECK(CItemData::SEAL_DATE_DEFAULT_TIMESTAMP == -1);
CHECK(CItemData::SEAL_DATE_UNLIMITED_TIMESTAMP == 0);
// Python app constants
CHECK(py_true("app.ENABLE_ACCE_COSTUME_SYSTEM == 1"));
CHECK(py_true("app.ENABLE_PENDANT_SYSTEM == 1"));
CHECK(py_true("app.ENABLE_WEAPON_COSTUME_SYSTEM == 1"));
CHECK(py_true("app.ENABLE_MOUNT_COSTUME_SYSTEM == 1"));
// Incomplete server-backed interfaces must not advertise usable gameplay.
CHECK(py_true("app.ENABLE_CHANGELOOK_SYSTEM == 0"));
CHECK(py_true("app.ENABLE_SOULBIND_SYSTEM == 0"));
CHECK(py_true("app.ENABLE_BINDING_SYSTEM == 0"));
CHECK(py_true("app.ENABLE_GLOVE_SYSTEM == 0"));
CHECK(py_true("app.ENABLE_QUIVER_SYSTEM == 0"));
CHECK(py_true("app.ENABLE_MAGIC_REDUCTION_SYSTEM == 0"));
CHECK(py_true("app.ENABLE_DS_CHANGE_ATTR == 0"));
CHECK(py_true("app.ENABLE_CUBE_RENEWAL_WORLDARD == 0"));
// Python item constants & methods
CHECK(py_true("item.EQUIPMENT_GLOVE == player.EQUIPMENT_SLOT_START + 37"));
CHECK(py_true("item.WEAPON_QUIVER == 9"));
CHECK(py_true("item.WEARABLE_GLOVE == 65536"));
CHECK(py_true("item.WEARABLE_PENDANT == 131072"));
CHECK(py_true("item.APPLY_ACCEDRAIN_RATE == 97"));
CHECK(py_true("item.APPLY_RESIST_MAGIC_REDUCTION == 98"));
CHECK(py_true("item.E_SEAL_DATE_DEFAULT_TIMESTAMP == -1"));
CHECK(py_true("item.E_SEAL_DATE_UNLIMITED_TIMESTAMP == 0"));
CHECK(py_true("item.GetDefaultSealDate() == -1"));
CHECK(py_true("item.GetUnlimitedSealDate() == 0"));
// Python player methods
CHECK(py_true("hasattr(player, 'GetItemSealDate')"));
CHECK(py_true("hasattr(player, 'GetItemUnSealLeftTime')"));
CHECK(py_true("hasattr(player, 'CanSealItem')"));
CHECK(py_true("hasattr(player, 'GetItemBind')"));
CHECK(py_true("hasattr(player, 'GetItemTransmutation')"));
CHECK(py_true("player.GetItemSealDate(player.INVENTORY, 0) == -1"));
CHECK(py_true("player.GetItemTransmutation(player.INVENTORY, 0) == 0"));
CHECK(py_true("player.DS_SUB_HEADER_DO_CHANGE_ATTR == 5"));
// Python effect module
CHECK(py("import effect"));
CHECK(py_true("hasattr(effect, 'FLY_QUIVER_ATTACK_NORMAL')"));
// Python cube_renewal module
CHECK(py("import cube_renewal"));
CHECK(py_true("cube_renewal.CountDates() == 0"));
CHECK(py_true("cube_renewal.GetDates(0)[0] == 0"));
CHECK(py("try:\n cube_renewal.CubeRenewalMakeItem(0, 1)\nexcept RuntimeError:\n pass\nelse:\n raise AssertionError('unsupported craft silently succeeded')\n"));
// F24: Full server ranking system (uirank)
CHECK(py_true("app.ENABLE_RANKING_SYSTEM == 1"));
CHECK(py_true("constInfo.ENABLE_MULTI_RANKING == 1"));
CHECK(py("import uirank"));
CHECK(py("r = uirank.RankingGUI(); r.Open(); r.Close()"));
// F30: Won & Cheque currency system
CHECK(POINT_CHEQUE == 249);
CHECK(py_true("app.ENABLE_CHEQUE_SYSTEM == 0"));
CHECK(py_true("player.CHEQUE == 249"));
CHECK(py_true("hasattr(player, 'GetCheque')"));
CHECK(py_true("player.GetCheque() == 0"));
CHECK(py_true("hasattr(exchange, 'GetChequeFromSelf')"));
CHECK(py_true("hasattr(exchange, 'GetChequeFromTarget')"));
CHECK(py_true("exchange.GetChequeFromSelf() == 0"));
CHECK(py_true("exchange.GetChequeFromTarget() == 0"));
CPythonExchange::Instance().SetChequeToSelf(50);
CPythonExchange::Instance().SetChequeToTarget(100);
CHECK(py_true("exchange.GetChequeFromSelf() == 50"));
CHECK(py_true("exchange.GetChequeFromTarget() == 100"));
CPythonExchange::Instance().Clear();
CHECK(py_true("exchange.GetChequeFromSelf() == 0"));
CHECK(py_true("exchange.GetChequeFromTarget() == 0"));
// Won UI components
CHECK(py("import uiPickETC; p = uiPickETC.PickETCDialog(); p.LoadDialog(); p.Open(100); p.Close()"));
CHECK(py("import uiWonExchange; w = uiWonExchange.WonExchangeWindow(); w.Open(); w.Close()"));
// Sound & music volume
CHECK(py("systemSetting.SetMusicVolume(0.5)"));
CHECK(CPythonSystem::Instance().GetMusicVolume() == 0.5f);
CHECK(py_true("abs(systemSetting.GetMusicVolume() - 0.5) < 0.01"));
CHECK(py("systemSetting.SetSoundVolumef(0.8)"));
CHECK(py_true("systemSetting.GetSoundVolume() >= 0"));
// Config tuple: (res_index, freq_index, is_software_cursor, shadow_level, view_chat, always_show_name, show_damage, show_sales_text)
CHECK(py_true("len(systemSetting.GetConfig()) == 8"));
CHECK(py_true("systemSetting.SaveConfig() == 1"));
unlink("metin2.cfg");
}
// 15. Verify audio & sound manager module (PythonSoundManagerModule / snd)
// - Module existence and no stub flag: import snd; not hasattr(snd, '__port_stub__')
// - Music volume controls: SetMusicVolume, SetMusicVolumef
// - Sound volume controls: SetSoundVolume, SetSoundVolumef
// - Scale controls: SetSoundScale, SetAmbienceSoundScale
// - Sound playback calls: PlaySound, PlaySound3D, StopAllSound
// - Music playback and fading: PlayMusic, FadeInMusic, FadeLimitOutMusic, FadeOutMusic, FadeOutAllMusic
// - CSoundManager C++ singleton state reflection
{
CHECK(py("import snd"));
CHECK(py_true("not hasattr(snd, '__port_stub__')"));
// Music volume
CHECK(py("snd.SetMusicVolume(0.7)"));
CHECK(py("snd.SetMusicVolumef(0.7)"));
CHECK(std::abs(CSoundManager::Instance().GetMusicVolume() - 0.7f) < 0.05f);
// Sound volume
CHECK(py("snd.SetSoundVolume(3)"));
CHECK(py("snd.SetSoundVolumef(0.6)"));
CHECK(CSoundManager::Instance().GetSoundVolume() > 0.0f);
const float savedMusic = CSoundManager::Instance().GetMusicVolume();
const float savedSound = CSoundManager::Instance().GetSoundVolume();
CSoundManager::Instance().SaveVolume();
CSoundManager::Instance().SaveVolume();
CHECK(CSoundManager::Instance().GetMusicVolume() == 0.0f);
CHECK(CSoundManager::Instance().GetSoundVolume() == 0.0f);
CSoundManager::Instance().RestoreVolume();
CHECK(std::abs(CSoundManager::Instance().GetMusicVolume() - savedMusic) < 0.001f);
CHECK(std::abs(CSoundManager::Instance().GetSoundVolume() - savedSound) < 0.001f);
// Scales
CHECK(py("snd.SetSoundScale(250.0)"));
CHECK(CSoundManager::Instance().GetSoundScale() == 250.0f);
CHECK(py("snd.SetAmbienceSoundScale(1500.0)"));
// Playback APIs execute cleanly
CHECK(py("snd.PlaySound('sound/ui/click.wav')"));
CHECK(py("snd.PlaySound3D(100.0, 200.0, 0.0, 'sound/ui/click.wav')"));
CHECK(py("snd.PlayMusic('BGM/login_window.mp3')"));
CHECK(py("snd.FadeInMusic('BGM/login_window.mp3')"));
CHECK(py("snd.FadeLimitOutMusic('BGM/login_window.mp3', 0.2)"));
CHECK(py("snd.FadeOutMusic('BGM/login_window.mp3')"));
CHECK(py("snd.FadeOutAllMusic()"));
CHECK(py("snd.StopAllSound()"));
}
// -------------------------------------------------------------------------
// F31: 单账号 5 角色位与选角兼容协议 (ENABLE_PLAYER_PER_ACCOUNT5)
// -------------------------------------------------------------------------
{
// 1. Python 导出验证
CHECK(py("import app, net\n"
"assert app.ENABLE_PLAYER_PER_ACCOUNT5 == 0, 'unsupported fifth slot advertised'\n"
"import introselect\n"
"assert introselect.SelectCharacterWindow.SLOT_COUNT == 4, 'current server supports four slots'\n"
"assert len(introselect.SelectCharacterWindow.SLOT_ROTATION) == 4, 'current selection requires four angles'\n"));
// 2. 槽位范围与边界安全检查 (0..4 合法, 5 越界)
CPythonNetworkStream& stream = CPythonNetworkStream::Instance();
CHECK(stream.GetAccountCharacterSlotDatau(0, CPythonNetworkStream::ACCOUNT_CHARACTER_SLOT_ID) == 1); // 登录成功包设置的第 1 角色
CHECK(stream.GetAccountCharacterSlotDatau(4, CPythonNetworkStream::ACCOUNT_CHARACTER_SLOT_ID) == 0); // 4 槽服务器模式下第 5 槽为空
CHECK(std::string(stream.GetAccountCharacterSlotDataz(4, CPythonNetworkStream::ACCOUNT_CHARACTER_SLOT_NAME)).empty());
CHECK(stream.GetAccountCharacterSlotDatau(5, CPythonNetworkStream::ACCOUNT_CHARACTER_SLOT_ID) == 0); // 越界槽位安全防御
CHECK(std::string(stream.GetAccountCharacterSlotDataz(5, CPythonNetworkStream::ACCOUNT_CHARACTER_SLOT_NAME)).empty());
// 3. 模拟第 5 槽 (slot 4) 角色创建成功更新
// 直接验证 slot 4 数据写入与 API 反射
CHECK(py("assert net.GetAccountCharacterSlotDataInteger(4, net.ACCOUNT_CHARACTER_SLOT_ID) == 0\n"
"assert net.GetAccountCharacterSlotDataString(4, net.ACCOUNT_CHARACTER_SLOT_NAME) == ''\n"
"assert net.GetAccountCharacterSlotDataInteger(5, net.ACCOUNT_CHARACTER_SLOT_ID) == 0\n"));
}
// -------------------------------------------------------------------------
// F33: 征服者等级与独立属性系统 (ENABLE_CONQUEROR_LEVEL / Sungma)
// -------------------------------------------------------------------------
{
// 1. Python 宏导出与接口可用性
CHECK(py("import app, player\n"
"assert app.ENABLE_CONQUEROR_LEVEL == 0, 'unsupported conqueror progression advertised'\n"
"assert app.ENABLE_CONQUEROR_UI == 0, 'unsupported conqueror UI advertised'\n"
"assert hasattr(player, 'CONQUEROR_LEVEL'), 'player.CONQUEROR_LEVEL missing'\n"
"assert hasattr(player, 'SUNGMA_STR') and hasattr(player, 'SUNGMA_HP') and hasattr(player, 'SUNGMA_MOVE') and hasattr(player, 'SUNGMA_IMMUNE') and hasattr(player, 'SUNGMA_INMUNE'), 'SUNGMA points missing'\n"
"assert hasattr(player, 'GetConquerorEXP'), 'player.GetConquerorEXP missing'\n"
"assert hasattr(player, 'IsConqueror'), 'player.IsConqueror missing'\n"));
// 2. 基础等级状态与默认非征服者断言
CPythonPlayer& rkPlayer = CPythonPlayer::Instance();
CHECK(!rkPlayer.IsConqueror());
CHECK(rkPlayer.GetConquerorLevel() == 0);
CHECK(py_true("player.IsConqueror() == 0"));
CHECK(py_true("player.GetStatus(player.CONQUEROR_LEVEL) == 0"));
// 3. 模拟进入征服者阶段并获得 Sungma 属性点
rkPlayer.SetStatus(POINT_CONQUEROR_LEVEL, 12);
rkPlayer.SetStatus(POINT_CONQUEROR_EXP, 1234567);
rkPlayer.SetStatus(POINT_CONQUEROR_NEXT_EXP, 5000000);
rkPlayer.SetStatus(POINT_CONQUEROR_POINT, 8);
rkPlayer.SetStatus(POINT_SUNGMA_STR, 30);
rkPlayer.SetStatus(POINT_SUNGMA_HP, 20);
rkPlayer.SetStatus(POINT_SUNGMA_MOVE, 15);
rkPlayer.SetStatus(POINT_SUNGMA_INMUNE, 10);
CHECK(rkPlayer.IsConqueror());
CHECK(rkPlayer.GetConquerorLevel() == 12);
CHECK(py_true("player.IsConqueror() == 1"));
CHECK(py_true("player.GetStatus(player.CONQUEROR_LEVEL) == 12"));
CHECK(py_true("player.GetConquerorEXP() == 1234567"));
CHECK(py_true("player.GetStatus(player.CONQUEROR_EXP) == 1234567"));
CHECK(py_true("player.GetStatus(player.CONQUEROR_NEXT_EXP) == 5000000"));
CHECK(py_true("player.GetStatus(player.CONQUEROR_POINT) == 8"));
CHECK(py_true("player.GetStatus(player.SUNGMA_STR) == 30"));
CHECK(py_true("player.GetStatus(player.SUNGMA_HP) == 20"));
CHECK(py_true("player.GetStatus(player.SUNGMA_MOVE) == 15"));
CHECK(py_true("player.GetStatus(player.SUNGMA_INMUNE) == 10"));
CHECK(py_true("player.GetStatus(player.SUNGMA_IMMUNE) == 10"));
// 4. 重置回原始状态,验证还原隔离
rkPlayer.SetStatus(POINT_CONQUEROR_LEVEL, 0);
rkPlayer.SetStatus(POINT_CONQUEROR_EXP, 0);
rkPlayer.SetStatus(POINT_CONQUEROR_NEXT_EXP, 0);
rkPlayer.SetStatus(POINT_CONQUEROR_POINT, 0);
rkPlayer.SetStatus(POINT_SUNGMA_STR, 0);
rkPlayer.SetStatus(POINT_SUNGMA_HP, 0);
rkPlayer.SetStatus(POINT_SUNGMA_MOVE, 0);
rkPlayer.SetStatus(POINT_SUNGMA_INMUNE, 0);
CHECK(!rkPlayer.IsConqueror());
}
// -------------------------------------------------------------------------
// F32: 狼人新职业 (Wolfman / JOB_WOLFMAN / 爪武器 / 爪抗性与流血)
// -------------------------------------------------------------------------
{
// 1. Python 宏导出与常量
CHECK(py("import app, item, chr, playerSettingModule\n"
"assert hasattr(app, 'ENABLE_WOLFMAN_CHARACTER') and app.ENABLE_WOLFMAN_CHARACTER == 1, 'ENABLE_WOLFMAN_CHARACTER missing'\n"
"assert app.DISABLE_WOLFMAN_ON_CREATE == 1, 'unsupported wolfman creation advertised'\n"
"assert hasattr(item, 'WEAPON_CLAW') and item.WEAPON_CLAW == 8, 'item.WEAPON_CLAW != 8'\n"
"assert hasattr(item, 'ITEM_ANTIFLAG_WOLFMAN') and item.ITEM_ANTIFLAG_WOLFMAN == (1 << 18), 'ITEM_ANTIFLAG_WOLFMAN mismatch'\n"
"assert hasattr(item, 'ANTIFLAG_WOLFMAN') and item.ANTIFLAG_WOLFMAN == (1 << 18), 'ANTIFLAG_WOLFMAN mismatch'\n"
"assert hasattr(item, 'APPLY_RESIST_CLAW') and item.APPLY_RESIST_CLAW == 96, 'APPLY_RESIST_CLAW mismatch'\n"
"assert hasattr(item, 'APPLY_RESIST_WOLFMAN') and item.APPLY_RESIST_WOLFMAN == 96, 'APPLY_RESIST_WOLFMAN mismatch'\n"
"assert hasattr(item, 'APPLY_BLEEDING_REDUCE') and item.APPLY_BLEEDING_REDUCE == 92, 'APPLY_BLEEDING_REDUCE mismatch'\n"
"assert hasattr(item, 'APPLY_BLEEDING_PCT') and item.APPLY_BLEEDING_PCT == 93, 'APPLY_BLEEDING_PCT mismatch'\n"
"assert hasattr(playerSettingModule, 'JOB_WOLFMAN') and playerSettingModule.JOB_WOLFMAN == 4, 'playerSettingModule.JOB_WOLFMAN != 4'\n"
"assert hasattr(playerSettingModule, 'RACE_WOLFMAN_M') and playerSettingModule.RACE_WOLFMAN_M == 8, 'playerSettingModule.RACE_WOLFMAN_M != 8'\n"));
// 2. 种族与职业/性别映射 (Race 8 -> Job 4, Sex 1 男)
CHECK(RaceToJob(8) == 4);
CHECK(RaceToSex(8) == 1);
CHECK(RaceToJob(0) == 0); // 战神保持兼容
CHECK(RaceToJob(4) == 0); // 战神女
CHECK(py_true("chr.RaceToJob(8) == 4"));
CHECK(py_true("chr.RaceToSex(8) == 1"));
// 3. C++ 常量断言
CHECK(NRaceData::JOB_WOLFMAN == 4);
CHECK(CItemData::WEAPON_CLAW == 8);
CHECK(CItemData::ITEM_ANTIFLAG_WOLFMAN == (1 << 18));
CHECK(CItemData::APPLY_RESIST_CLAW == 96);
CHECK(CItemData::APPLY_BLEEDING_REDUCE == 92);
CHECK(CItemData::APPLY_BLEEDING_PCT == 93);
}
// -------------------------------------------------------------------------
// F22: 神话龙魂石品级与槽位扩展 (ENABLE_DS_GRADE_MYTH / 6品级槽位)
// -------------------------------------------------------------------------
{
// 1. Python 宏导出与常量
CHECK(py("import app, player, item, dragon_soul_refine_settings\n"
"assert app.ENABLE_DS_GRADE_MYTH == 0, 'unsupported myth grade advertised'\n"
"assert app.ENABLE_DS_GRADE_MYTHIC == 0, 'unsupported myth grade advertised'\n"
"assert player.DRAGON_SOUL_PAGE_COUNT == 5, 'server-compatible grade stride must be 5'\n"
"assert player.DRAGON_SOUL_PAGE_SIZE == 32, 'DRAGON_SOUL_PAGE_SIZE != 32'\n"
"assert player.DRAGON_SOUL_SLOT_COUNT == 960, 'server-compatible inventory must be 960 cells'\n"
"assert player.DRAGON_SOUL_GRADE_MYTH == 5, 'player.DRAGON_SOUL_GRADE_MYTH != 5'\n"
"assert player.DRAGON_SOUL_GRADE_MYTHIC == 5, 'player.DRAGON_SOUL_GRADE_MYTHIC != 5'\n"
"assert player.DRAGON_SOUL_GRADE_MAX == 6, 'player.DRAGON_SOUL_GRADE_MAX != 6'\n"
"assert item.DRAGON_SOUL_GRADE_MYTH == 5, 'item.DRAGON_SOUL_GRADE_MYTH != 5'\n"
"assert item.DRAGON_SOUL_GRADE_MAX == 6, 'item.DRAGON_SOUL_GRADE_MAX != 6'\n"
"assert len(dragon_soul_refine_settings.default_strength_max_table) == 5, 'active strength table must have five grades'\n"
"assert len(dragon_soul_refine_settings.default_grade_need_count) == 4, 'active upgrade table must have four transitions'\n"
"assert len(dragon_soul_refine_settings.default_grade_fee) == 4, 'active fee table must have four transitions'\n"));
// 2. C++ 枚举与槽位边界防御 (0..1151 合法, 1152 越界拒绝)
CHECK(DRAGON_SOUL_GRADE_MYTH == 5);
CHECK(DRAGON_SOUL_GRADE_MYTHIC == 5);
CHECK(DRAGON_SOUL_GRADE_MAX == 6);
CHECK(c_DragonSoul_Inventory_Count == 960);
TItemPos dsValid0(DRAGON_SOUL_INVENTORY, 0);
TItemPos dsValidLast(DRAGON_SOUL_INVENTORY, 959);
TItemPos dsOverflow(DRAGON_SOUL_INVENTORY, 960);
CHECK(dsValid0.IsValidCell());
CHECK(dsValidLast.IsValidCell());
CHECK(!dsOverflow.IsValidCell());
}
if (server)
{
const std::vector<std::string> expected = {
"auth:handshake", "auth:login3", "game1:handshake", "game1:login2", "auth:closed",
"game1:closed", "game2:handshake", "game2:login2", "game2:select", "game2:client_version", "game2:entergame",
"game2:burst_sent", "game2:burst_pong",
};
auto events = server->Events();
// auth:closed races game1's handshake; compare the order within each connection.
for (const char* prefix : {"auth:", "game1:", "game2:"})
{
std::vector<std::string> want, got;
for (const auto& e : expected)
if (e.rfind(prefix, 0) == 0)
want.push_back(e);
for (const auto& e : events)
if (e.rfind(prefix, 0) == 0 && e.find(":move ") == std::string::npos &&
e.find(":pickup ") == std::string::npos && e.find(":item_use ") == std::string::npos &&
e.find(":item_move ") == std::string::npos &&
e.find(":exchange ") == std::string::npos && e.find(":chat ") == std::string::npos &&
e.find(":target ") == std::string::npos && e.find(":attack ") == std::string::npos &&
e.find(":click ") == std::string::npos && e.find(":shop ") == std::string::npos &&
e.find(":answer ") == std::string::npos && e.find(":safebox_") == std::string::npos)
got.push_back(e);
CHECK(want == got);
}
if (g_failures)
dump(*server);
}
if (mobile_test) {
TouchController touch;
touch.set_enabled(true);
touch.update_screen_size(800, 600);
CHECK(!PythonBoot::IsPointInsideActiveUI(240, 270));
CHECK(touch.on_finger_down(101, 0.3f, 0.45f));
touch.on_finger_motion(101, 0.325f, 0.46666667f);
touch.update_screen_size(800, 600); // renderer does this each frame
std::vector<UIRenderCommand> overlay;
touch.append_ui_commands(overlay);
bool kept_origin = false;
for (const auto& cmd : overlay)
if (cmd.argb == 0x52997847 && cmd.kind == UIRenderCommand::Line)
// The base circle's first segment starts at (origin.x + radius, origin.y).
kept_origin |= std::abs(cmd.x1 - (240.0f + mt_host::make_touch_layout(800, 600, 0, 48).scale * 65.0f)) < 0.1f &&
std::abs(cmd.y1 - 270.0f) < 0.1f;
CHECK(kept_origin);
touch.on_finger_up(101, 0.325f, 0.46666667f);
}
CHECK(py("import app\napp.Exit()"));
pump_until(2, [] { return !PythonBoot::IsAppLooping(); });
CHECK(!PythonBoot::IsAppLooping());
PythonBoot::Stop();
if (server)
server->Stop();
if (g_failures)
std::fprintf(stderr, "%d check(s) failed\n", g_failures);
else
std::printf("port_login_flow_test: ok%s\n", live ? " (live)" : "");
return g_failures ? 1 : 0;
}