AVA2 client Windows parity passes (gr2 BitKnit2/64-bit, GamePhase handlers, python modules)
- gr2: BitKnit2 decompression, 64-bit LE files, compressed curves - net: remaining GamePhase handlers, generated GC packet table - python: event/chat/chr/minimap/guild/quest/messenger/shop-search and other native modules ported against the AVA2 Windows client - render: D3D8 fixed-function lighting in Gr2ModelRenderer, terrain without baked shade; cape/NPC equipment attachment - tests + audits updated; docs/PORT-PLAN.md and WINDOWS-PARITY.md Batch 4 (render pipeline: background.*, app.RenderGame/UpdateGame, camera bindings, main.cpp fake-content removal) is still in progress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9f748eb05a
commit
9077aa389a
@@ -0,0 +1,287 @@
|
||||
// Port of AVA2 UserInterface/PythonNetworkStreamCommand.cpp (ServerCommand / SplitToken)
|
||||
// and the emoticon helpers from PythonNetworkStreamPhaseGame.cpp / PythonNetworkStream.cpp.
|
||||
// Commands that only forward to the game window are 1:1; commands that need actor/effect
|
||||
// state the port does not have yet (emotions, StoneDetect, stamina) are TraceError'd and
|
||||
// listed in docs/WINDOWS-PARITY.md.
|
||||
#include "PythonNetworkStream.h"
|
||||
#include "ava2_text_file.h"
|
||||
#include "shared/common/PythonUtils.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <strings.h>
|
||||
|
||||
namespace ava2 {
|
||||
namespace {
|
||||
|
||||
using CTokenVector = std::vector<std::string>;
|
||||
|
||||
bool SplitToken(const char* c_szLine, CTokenVector* pstTokenVector, const char* c_szDelimeter = " ") {
|
||||
pstTokenVector->reserve(10);
|
||||
pstTokenVector->clear();
|
||||
|
||||
std::string strLine = c_szLine;
|
||||
size_t basePos = 0;
|
||||
do {
|
||||
size_t beginPos = strLine.find_first_not_of(c_szDelimeter, basePos);
|
||||
if (beginPos == std::string::npos)
|
||||
return false;
|
||||
|
||||
size_t endPos;
|
||||
if (strLine[beginPos] == '"') {
|
||||
++beginPos;
|
||||
endPos = strLine.find_first_of("\"", beginPos);
|
||||
if (endPos == std::string::npos)
|
||||
return false;
|
||||
basePos = endPos + 1;
|
||||
} else {
|
||||
endPos = strLine.find_first_of(c_szDelimeter, beginPos);
|
||||
basePos = endPos;
|
||||
}
|
||||
|
||||
pstTokenVector->push_back(strLine.substr(beginPos, endPos == std::string::npos ? std::string::npos : endPos - beginPos));
|
||||
|
||||
if (strLine.find_first_not_of(c_szDelimeter, basePos) == std::string::npos)
|
||||
break;
|
||||
} while (basePos < strLine.length());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TraceError(const std::string& text) { std::cerr << "[AVA2 TraceError] " << text << std::endl; }
|
||||
|
||||
} // namespace
|
||||
|
||||
void PythonNetworkStream::ServerCommand(const std::string& command) {
|
||||
const char* c_szCommand = command.c_str();
|
||||
// #0000811: [M2EU]
|
||||
if (strcasecmp(c_szCommand, "ConsoleEnable") == 0)
|
||||
return;
|
||||
|
||||
PyObject* gameWnd = m_phaseWindows[5]; // PHASE_WINDOW_GAME
|
||||
if (gameWnd) {
|
||||
bool isTrue;
|
||||
if (PyCallClassMemberFunc(gameWnd, "BINARY_ServerCommand_Run", Py_BuildValue("(s)", c_szCommand), &isTrue) && isTrue)
|
||||
return;
|
||||
} else if (m_poSerCommandParserWnd) {
|
||||
bool isTrue;
|
||||
if (PyCallClassMemberFunc(m_poSerCommandParserWnd, "BINARY_ServerCommand_Run", Py_BuildValue("(s)", c_szCommand), &isTrue) && isTrue)
|
||||
return;
|
||||
}
|
||||
|
||||
CTokenVector TokenVector;
|
||||
if (!SplitToken(c_szCommand, &TokenVector))
|
||||
return;
|
||||
if (TokenVector.empty())
|
||||
return;
|
||||
|
||||
// Windows indexes TokenVector without a bound check for several commands; a
|
||||
// missing token reads as "" (atoi -> 0) here instead of undefined behaviour.
|
||||
auto arg = [&](size_t i) { return i < TokenVector.size() ? TokenVector[i].c_str() : ""; };
|
||||
auto strangeCount = [&] { TraceError("CPythonNetworkStream::ServerCommand(c_szCommand=" + command + ") - Strange Parameter Count"); };
|
||||
auto call = [&](const char* func, PyObject* args) { PyCallClassMemberFunc(gameWnd, func, args); };
|
||||
const char* szCmd = TokenVector[0].c_str();
|
||||
|
||||
if (!strcasecmp(szCmd, "quit")) {
|
||||
m_unknownPacketQuit = true; // PostQuitMessage(0)
|
||||
} else if (!strcasecmp(szCmd, "BettingMoney")) {
|
||||
if (2 != TokenVector.size()) { strangeCount(); return; }
|
||||
} else if (!strcasecmp(szCmd, "gift")) {
|
||||
call("Gift_Show", Py_BuildValue("()"));
|
||||
} else if (!strcasecmp(szCmd, "cube")) {
|
||||
if (TokenVector.size() < 2) { strangeCount(); return; }
|
||||
const std::string& sub = TokenVector[1];
|
||||
if ("open" == sub) {
|
||||
if (3 > TokenVector.size()) { strangeCount(); return; }
|
||||
call("BINARY_Cube_Open", Py_BuildValue("(i)", atoi(arg(2))));
|
||||
} else if ("close" == sub) {
|
||||
call("BINARY_Cube_Close", Py_BuildValue("()"));
|
||||
} else if ("info" == sub) {
|
||||
if (5 != TokenVector.size()) { strangeCount(); return; }
|
||||
call("BINARY_Cube_UpdateInfo", Py_BuildValue("(iii)", atoi(arg(2)), atoi(arg(3)), atoi(arg(4))));
|
||||
} else if ("success" == sub) {
|
||||
if (4 != TokenVector.size()) { strangeCount(); return; }
|
||||
call("BINARY_Cube_Succeed", Py_BuildValue("(ii)", atoi(arg(2)), atoi(arg(3))));
|
||||
} else if ("fail" == sub) {
|
||||
call("BINARY_Cube_Failed", Py_BuildValue("()"));
|
||||
} else if ("r_list" == sub) {
|
||||
if (5 != TokenVector.size()) { strangeCount(); return; }
|
||||
call("BINARY_Cube_ResultList", Py_BuildValue("(is)", atoi(arg(2)), arg(4)));
|
||||
} else if ("m_info" == sub) {
|
||||
if (5 != TokenVector.size()) { strangeCount(); return; }
|
||||
call("BINARY_Cube_MaterialInfo", Py_BuildValue("(iis)", atoi(arg(2)), atoi(arg(3)), arg(4)));
|
||||
}
|
||||
} else if (!strcasecmp(szCmd, "ObserverCount")) {
|
||||
if (2 != TokenVector.size()) { strangeCount(); return; }
|
||||
call("BINARY_BettingGuildWar_UpdateObserverCount", Py_BuildValue("(i)", atoi(arg(1))));
|
||||
} else if (!strcasecmp(szCmd, "ObserverMode")) {
|
||||
if (2 != TokenVector.size()) { strangeCount(); return; }
|
||||
const int uMode = atoi(arg(1));
|
||||
m_isObserverMode = uMode != 0; // IAbstractPlayer::SetObserverMode
|
||||
call("BINARY_BettingGuildWar_SetObserverMode", Py_BuildValue("(i)", uMode));
|
||||
} else if (!strcasecmp(szCmd, "OfflineShopSetFlag")) {
|
||||
// ENABLE_OFFLINESHOP_SYSTEM: CPythonShop::SetShopFlag is not ported; the window refresh is.
|
||||
call("RefreshOfflineShop", Py_BuildValue("()"));
|
||||
} else if (!strcasecmp(szCmd, "ObserverTeamInfo")) {
|
||||
} else if (!strcasecmp(szCmd, "cards")) {
|
||||
if (TokenVector.size() < 2) { strangeCount(); return; }
|
||||
const std::string& sub = TokenVector[1];
|
||||
if ("open" == sub) {
|
||||
call("BINARY_Cards_Open", Py_BuildValue("(i)", atoi(arg(2))));
|
||||
} else if ("info" == sub) {
|
||||
if (14 != TokenVector.size()) { strangeCount(); return; }
|
||||
call("BINARY_Cards_UpdateInfo", Py_BuildValue("(iiiiiiiiiiii)", atoi(arg(2)), atoi(arg(3)), atoi(arg(4)), atoi(arg(5)),
|
||||
atoi(arg(6)), atoi(arg(7)), atoi(arg(8)), atoi(arg(9)), atoi(arg(10)), atoi(arg(11)), atoi(arg(12)), atoi(arg(13))));
|
||||
} else if ("finfo" == sub || "reward" == sub) {
|
||||
if (9 != TokenVector.size()) { strangeCount(); return; }
|
||||
call("finfo" == sub ? "BINARY_Cards_FieldUpdateInfo" : "BINARY_Cards_PutReward",
|
||||
Py_BuildValue("(iiiiiii)", atoi(arg(2)), atoi(arg(3)), atoi(arg(4)), atoi(arg(5)), atoi(arg(6)), atoi(arg(7)), atoi(arg(8))));
|
||||
} else if ("icon" == sub) {
|
||||
if (2 != TokenVector.size()) { strangeCount(); return; }
|
||||
call("BINARY_Cards_ShowIcon", Py_BuildValue("()"));
|
||||
}
|
||||
}
|
||||
// ENABLE_ZODIAC_MISSION
|
||||
else if (!strcasecmp(szCmd, "ZodiacDayorNight")) {
|
||||
call("ZodiacDayorNight", Py_BuildValue("()"));
|
||||
} else if (!strcasecmp(szCmd, "ZodiacJumpButtonClose")) {
|
||||
call("ZodiacJumpButtonClose", Py_BuildValue("()"));
|
||||
} else if (!strcasecmp(szCmd, "ZodiacJumpButtonShow")) {
|
||||
call("ZodiacJumpButtonShow", Py_BuildValue("()"));
|
||||
} else if (!strcasecmp(szCmd, "ZodiacInfo")) {
|
||||
// BYTE time/floor/nextfloor
|
||||
call("Refresh12ziTimer", Py_BuildValue("(iii)", uint8_t(atoi(arg(1))), uint8_t(atoi(arg(2))), uint8_t(atoi(arg(3)))));
|
||||
} else if (!strcasecmp(szCmd, "OpenUI12zi")) {
|
||||
call("OpenUI12zi", Py_BuildValue("(iiii)", atoi(arg(1)), atoi(arg(2)), atoi(arg(3)), atoi(arg(4))));
|
||||
} else if (!strcasecmp(szCmd, "OpenReviveDialog")) {
|
||||
call("OpenReviveDialog", Py_BuildValue("(i)", atoi(arg(1))));
|
||||
} else if (!strcasecmp(szCmd, "OpenReviveDialog_me")) {
|
||||
call("OpenReviveDialog_me", Py_BuildValue("(i)", atoi(arg(1))));
|
||||
} else if (!strcasecmp(szCmd, "SetBeadCount")) {
|
||||
call("SetBeadCount", Py_BuildValue("(i)", atoi(arg(1))));
|
||||
} else if (!strcasecmp(szCmd, "NextBeadUpdateTime")) {
|
||||
call("NextBeadUpdateTime", Py_BuildValue("(i)", atoi(arg(1))));
|
||||
} else if (!strcasecmp(szCmd, "GetMissionInformation")) {
|
||||
call("GetMissionInformation", Py_BuildValue("(ii)", atoi(arg(1)), atoi(arg(2))));
|
||||
} else if (!strcasecmp(szCmd, "StoneDetect")) {
|
||||
if (4 != TokenVector.size()) { strangeCount(); return; }
|
||||
// Needs CInstanceBase pixel position + CEffectManager compass effects.
|
||||
TraceError("ServerCommand StoneDetect not ported (effect): " + command);
|
||||
} else if (!strcasecmp(szCmd, "StartStaminaConsume")) {
|
||||
if (3 != TokenVector.size()) { strangeCount(); return; }
|
||||
TraceError("ServerCommand StartStaminaConsume not ported (player stamina): " + command);
|
||||
} else if (!strcasecmp(szCmd, "StopStaminaConsume")) {
|
||||
if (2 != TokenVector.size()) { strangeCount(); return; }
|
||||
TraceError("ServerCommand StopStaminaConsume not ported (player stamina): " + command);
|
||||
} else if (!strcasecmp(szCmd, "sms")) {
|
||||
m_bMobileFlag = true;
|
||||
} else if (!strcasecmp(szCmd, "nosms")) {
|
||||
m_bMobileFlag = false;
|
||||
} else if (!strcasecmp(szCmd, "mobile_auth")) {
|
||||
call("OnMobileAuthority", Py_BuildValue("()"));
|
||||
} else if (!strcasecmp(szCmd, "messenger_auth")) {
|
||||
call("OnMessengerAddFriendQuestion", Py_BuildValue("(s)", arg(1)));
|
||||
} else if (!strcasecmp(szCmd, "combo")) {
|
||||
// IAbstractPlayer::SetComboSkillFlag (skill slot level) is not ported; the stream flag is.
|
||||
m_bComboSkillFlag = atoi(arg(1)) != 0;
|
||||
} else if (!strcasecmp(szCmd, "setblockmode")) {
|
||||
call("OnBlockMode", Py_BuildValue("(i)", atoi(arg(1))));
|
||||
} else {
|
||||
// french_kiss..dig_motion are strcmpi branches; the rest is s_emotionDict (case sensitive).
|
||||
static const char* const namedEmotions[] = {
|
||||
"french_kiss", "kiss", "slap", "clap", "cheer1", "cheer2", "dance1", "dance2", "dig_motion",
|
||||
};
|
||||
static const char* const dictEmotions[] = {
|
||||
"dance3", "dance4", "dance5", "dance6", "congratulation", "forgive", "angry", "attractive",
|
||||
"sad", "shy", "cheerup", "banter", "joy",
|
||||
};
|
||||
bool isEmotion = false;
|
||||
for (const char* emotion : namedEmotions) isEmotion = isEmotion || !strcasecmp(szCmd, emotion);
|
||||
for (const char* emotion : dictEmotions) isEmotion = isEmotion || TokenVector[0] == emotion;
|
||||
if (isEmotion)
|
||||
TraceError("ServerCommand emotion not ported (CInstanceBase::ActEmotion): " + command);
|
||||
else
|
||||
TraceError("Unknown Server Command " + command + " | " + TokenVector[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void PythonNetworkStream::RegisterEmoticonString(const std::string& emoticon) {
|
||||
if (m_emoticonStrings.size() >= 128) { // CInstanceBase::EMOTICON_NUM
|
||||
TraceError("Can't register emoticon std::string... vector is full (size:" + std::to_string(m_emoticonStrings.size()) + ")");
|
||||
return;
|
||||
}
|
||||
m_emoticonStrings.push_back(emoticon);
|
||||
}
|
||||
|
||||
// CPythonNetworkStream::LoadInsultList + CInsultChecker (AVA2 PythonNetworkStreamPhaseLoading.cpp,
|
||||
// InsultChecker.cpp). Non-Japan LocaleService: lead byte = high bit, compare = strnicmp.
|
||||
bool PythonNetworkStream::LoadInsultList(const std::string& text) {
|
||||
m_insults.clear();
|
||||
for (const std::string& line : ava2TextLines(text))
|
||||
if (line.length() > 0)
|
||||
m_insults.push_back(line);
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool GetInsultLength(const std::vector<std::string>& insults, const char* word, size_t* len) {
|
||||
for (const std::string& insult : insults) {
|
||||
if (0 == strncasecmp(word, insult.c_str(), insult.length())) {
|
||||
*len = insult.length();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void PythonNetworkStream::FilterInsult(char* szLine, size_t uLineLen) const {
|
||||
for (size_t uPos = 0; uPos < uLineLen;) {
|
||||
uint8_t bChr = uint8_t(szLine[uPos]);
|
||||
size_t uInsultLen;
|
||||
if (GetInsultLength(m_insults, szLine + uPos, &uInsultLen)) {
|
||||
memset(szLine + uPos, '*', uInsultLen);
|
||||
uPos += uInsultLen;
|
||||
} else {
|
||||
uPos += (bChr & 0x80) ? 2 : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::IsInsultIn(const char* c_szLine) const {
|
||||
const size_t uLineLen = strlen(c_szLine);
|
||||
size_t len;
|
||||
for (size_t uPos = 0; uPos < uLineLen;) {
|
||||
uint8_t bChr = uint8_t(c_szLine[uPos]);
|
||||
if (GetInsultLength(m_insults, c_szLine + uPos, &len))
|
||||
return true;
|
||||
uPos += (bChr & 0x80) ? 2 : 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Windows returns false while the filter is *enabled* (original inverted check kept).
|
||||
bool PythonNetworkStream::IsChatInsultIn(const char* c_szMsg) const {
|
||||
if (m_isEnableChatInsultFilter)
|
||||
return false;
|
||||
return IsInsultIn(c_szMsg);
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::ParseEmoticon(const char* pChatMsg, uint32_t* pdwEmoticon) const {
|
||||
for (uint32_t index = 0; index < m_emoticonStrings.size(); ++index) {
|
||||
if (strlen(pChatMsg) > m_emoticonStrings[index].size())
|
||||
continue;
|
||||
if (strstr(pChatMsg, m_emoticonStrings[index].c_str()) != pChatMsg)
|
||||
continue;
|
||||
*pdwEmoticon = index;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PythonNetworkStream::SendEmoticon(unsigned emoticon) {
|
||||
if (emoticon < m_emoticonStrings.size())
|
||||
SendChatPacket(m_emoticonStrings[emoticon]);
|
||||
}
|
||||
|
||||
} // namespace ava2
|
||||
Reference in New Issue
Block a user