From 1488d7ea7104bc97aac0e770ea8586282afb2807 Mon Sep 17 00:00:00 2001 From: hzqst <113660872@qq.com> Date: Sun, 25 Feb 2024 01:10:18 +0800 Subject: [PATCH] 1 --- CGALib/gameinterface.cpp | 6 +++--- CGALib/gameinterface.h | 2 +- CGAssistant/chatform.cpp | 42 +++++++++++++++++++++++++++++++++------- CGAssistant/chatform.h | 2 +- CGAssistant/chatform.ui | 7 +++++-- CGAssistant/main.cpp | 10 ++++++++-- CGAssistant/mainwindow.h | 2 +- cgahook/gameservice.cpp | 10 +++++----- cgahook/gameservice.h | 4 ++-- cgahook/server.cpp | 2 +- 10 files changed, 62 insertions(+), 25 deletions(-) diff --git a/CGALib/gameinterface.cpp b/CGALib/gameinterface.cpp index 441c2c9..3fd3a0f 100644 --- a/CGALib/gameinterface.cpp +++ b/CGALib/gameinterface.cpp @@ -121,7 +121,7 @@ namespace CGAServiceProtocol TIMAX_DEFINE_PROTOCOL(LoginGameServer, void(std::string, std::string, int, int, int, int)); TIMAX_DEFINE_PROTOCOL(CreateCharacter, void(cga_create_chara_t)); TIMAX_DEFINE_PROTOCOL(GetGameServerInfo, cga_game_server_info_t()); - TIMAX_DEFINE_PROTOCOL(SetBlockAllChatMsg, void(bool)); + TIMAX_DEFINE_PROTOCOL(SetBlockChatMsgs, void(int)); TIMAX_DEFINE_FORWARD(NotifyServerShutdown, int); TIMAX_DEFINE_FORWARD(NotifyBattleAction, int); @@ -1467,11 +1467,11 @@ namespace CGA } return false; } - virtual bool SetBlockAllChatMsg(bool bShouldBlock) + virtual bool SetBlockChatMsgs(int state) { if (m_connected) { try { - info = m_client.call(std::chrono::milliseconds(10000), m_endpoint, CGAServiceProtocol::SetBlockAllChatMsg, bShouldBlock); + m_client.call(std::chrono::milliseconds(10000), m_endpoint, CGAServiceProtocol::SetBlockChatMsgs, state); return true; } catch (timax::rpc::exception const &e) { if (e.get_error_code() != timax::rpc::error_code::TIMEOUT) m_connected = false; OutputDebugStringA("rpc exception from " __FUNCTION__); OutputDebugStringA(e.get_error_message().c_str()); } diff --git a/CGALib/gameinterface.h b/CGALib/gameinterface.h index d1d59e7..56f73c6 100644 --- a/CGALib/gameinterface.h +++ b/CGALib/gameinterface.h @@ -1240,7 +1240,7 @@ namespace CGA virtual bool SendMail(int index, const std::string &msg, bool &result) = 0; virtual bool SendPetMail(int index, int petid, int itempos, const std::string &msg, bool &result) = 0; virtual bool GetGameServerInfo(cga_game_server_info_t &info) = 0; - virtual bool SetBlockAllChatMsg(bool bShouldBlock) = 0; + virtual bool SetBlockChatMsgs(int state) = 0; virtual bool RegisterServerShutdownNotify(const std::function &callback) = 0; virtual bool RegisterBattleActionNotify(const std::function &callback) = 0; diff --git a/CGAssistant/chatform.cpp b/CGAssistant/chatform.cpp index e641e48..d10a363 100644 --- a/CGAssistant/chatform.cpp +++ b/CGAssistant/chatform.cpp @@ -29,7 +29,7 @@ void ChatForm::OnAutoChat() { if(g_CGAInterface->IsConnected()) { - g_CGAInterface->SetBlockAllChatMsg(true); + g_CGAInterface->SetBlockChatMsgs((int)ui->checkBox_BlockChatMsgs->checkState()); } } @@ -49,9 +49,20 @@ void ChatForm::OnNotifyGetPlayerInfo(QSharedPointer player) m_player = player; } -void ChatForm::OnNotifyFillChatSettings(bool blockallchatmsgs) +void ChatForm::OnNotifyFillChatSettings(int blockchatmsgs) { - ui->checkBox_BlockAllChatMsgs->setChecked(blockallchatmsgs); + if(blockchatmsgs == 2) + { + ui->checkBox_BlockChatMsgs->setCheckState(Qt::CheckState::Checked); + } + else if(blockchatmsgs == 1) + { + ui->checkBox_BlockChatMsgs->setCheckState(Qt::CheckState::PartiallyChecked); + } + else if(blockchatmsgs == 0) + { + ui->checkBox_BlockChatMsgs->setCheckState(Qt::CheckState::Unchecked); + } } void ChatForm::OnNotifyFillStaticSettings(int freezetime, int chatmaxlines) @@ -151,22 +162,39 @@ bool ChatForm::ParseChatSettings(const QJsonValue &val) auto obj = val.toObject(); - if(obj.contains("blockallchatmsgs")) - ui->checkBox_BlockAllChatMsgs->setChecked(obj.take("blockallchatmsgs").toBool()); + if(obj.contains("blockchatmsgs")) + { + int val = obj.take("blockchatmsgs").toInt(); + if(1) + { + if(val == 2) + { + ui->checkBox_BlockChatMsgs->setCheckState(Qt::CheckState::Checked); + } + else if(val == 1) + { + ui->checkBox_BlockChatMsgs->setCheckState(Qt::CheckState::PartiallyChecked); + } + else if(val == 0) + { + ui->checkBox_BlockChatMsgs->setCheckState(Qt::CheckState::Unchecked); + } + } + } return true; } void ChatForm::SaveChatSettings(QJsonObject &obj) { - obj.insert("blockallchatmsgs", ui->checkBox_BlockAllChatMsgs->isChecked()); + obj.insert("blockchatmsgs", (int)ui->checkBox_BlockChatMsgs->checkState()); } void ChatForm::on_checkBox_BlockAllChatMsgs_stateChanged(int state) { if(g_CGAInterface->IsConnected()) { - g_CGAInterface->SetBlockAllChatMsg(state ? true : false); + g_CGAInterface->SetBlockChatMsgs(state); } } diff --git a/CGAssistant/chatform.h b/CGAssistant/chatform.h index ac08e67..dd908ec 100644 --- a/CGAssistant/chatform.h +++ b/CGAssistant/chatform.h @@ -20,7 +20,7 @@ class ChatForm : public QWidget ~ChatForm(); public slots: - void OnNotifyFillChatSettings(bool blockallchatmsgs); + void OnNotifyFillChatSettings(int blockchatmsgs); void OnNotifyFillStaticSettings(int freezetime, int chatmaxlines); void OnNotifyGetPlayerInfo(QSharedPointer player); void OnNotifyChatMsg(int unitid, QString msg, int size, int color); diff --git a/CGAssistant/chatform.ui b/CGAssistant/chatform.ui index 5ca907d..fa6143a 100644 --- a/CGAssistant/chatform.ui +++ b/CGAssistant/chatform.ui @@ -35,7 +35,7 @@ - + 0 @@ -52,7 +52,10 @@ Qt::LeftToRight - Block all chat messages + Block chat messages + + + true diff --git a/CGAssistant/main.cpp b/CGAssistant/main.cpp index fa264cb..23bd102 100644 --- a/CGAssistant/main.cpp +++ b/CGAssistant/main.cpp @@ -116,7 +116,7 @@ int main(int argc, char *argv[]) QCommandLineOption chatmaxlines("chatmaxlines", "", "chatmaxlines", "100"); - QCommandLineOption blockallchatmsgs("blockallchatmsgs"); + QCommandLineOption blockchatmsgs("blockchatmsgs", "", "blockchatmsgs"); QCommandLineParser parser; @@ -297,7 +297,13 @@ int main(int argc, char *argv[]) parser.value(consolemaxlines).toInt(), parser.value(scriptfreezeduration).toInt() ); - w.NotifyFillChatSettings(parser.isSet(blockallchatmsgs) ? true : false); + bool bHasBlockchatmsgs = false; + int val_blockchatmsgs = -1; + if(parser.isSet(blockchatmsgs)) + { + val_blockchatmsgs = parser.value(blockchatmsgs).toInt(&bHasBlockchatmsgs); + } + w.NotifyFillChatSettings(val_blockchatmsgs); w.NotifyFillLoadSettings(parser.value(loadsettings)); diff --git a/CGAssistant/mainwindow.h b/CGAssistant/mainwindow.h index ea76f71..bee91e4 100644 --- a/CGAssistant/mainwindow.h +++ b/CGAssistant/mainwindow.h @@ -36,7 +36,7 @@ class MainWindow : public QMainWindow QString create_chara_points, QString create_chara_elements, QString create_chara_name); void NotifyFillLoadScript(QString path, int autorestart, bool freezestop, bool injuryprot, bool soulprot, int consolemaxlines, int scriptfreezeduration); void NotifyFillLoadSettings(QString path); - void NotifyFillChatSettings(bool blockallchatmsgs); + void NotifyFillChatSettings(int blockchatmsgs); void NotifyFillStaticSettings(int freezetime, int chatmaxlines); void HttpGetGameProcInfo(QJsonDocument* doc); void HttpGetSettings(QJsonDocument* doc); diff --git a/cgahook/gameservice.cpp b/cgahook/gameservice.cpp index d77141e..389a3b3 100644 --- a/cgahook/gameservice.cpp +++ b/cgahook/gameservice.cpp @@ -1620,7 +1620,7 @@ void CGAService::NewNET_ParseChatMsg(int a1, int unitid, const char *buf, int co void __cdecl NewNET_ParseChatMsg(int a1, int unitid, const char *buf, int color, int size) { - if (g_CGAService.m_ui_block_all_chatmsgs && buf[0] == 'P' && buf[1] == '|' && unitid != -1) + if (g_CGAService.m_ui_block_chatmsgs > 0 && buf[0] == 'P' && buf[1] == '|' && unitid != -1) return; g_CGAService.NewNET_ParseChatMsg(a1, unitid, buf, color, size); @@ -3468,7 +3468,7 @@ void CGAService::Initialize(game_type type) //m_ui_battle_action = 0; //m_ui_battle_hevent = CreateEventA(NULL, FALSE, FALSE, NULL); m_trade_add_all_stuffs = false; - m_ui_block_all_chatmsgs = false; + m_ui_block_chatmsgs = 0; if (*g_mutex) { @@ -3537,7 +3537,7 @@ void CGAService::Initialize(game_type type) //m_ui_battle_action = 0; //m_ui_battle_hevent = CreateEventA(NULL, FALSE, FALSE, NULL); m_trade_add_all_stuffs = false; - m_ui_block_all_chatmsgs = false; + m_ui_block_chatmsgs = 0; DetourTransactionBegin(); DetourAttach(&(void *&)BATTLE_PlayerAction, ::NewBATTLE_PlayerAction); @@ -5219,9 +5219,9 @@ void CGAService::AddAllTradeItems(void) m_trade_add_all_stuffs = true; } -void CGAService::SetBlockAllChatMsg(bool bShouldBlock) +void CGAService::SetBlockChatMsgs(int state) { - m_ui_block_all_chatmsgs = true; + m_ui_block_chatmsgs = state; } bool CGAService::WM_BattleNormalAttack(int target) diff --git a/cgahook/gameservice.h b/cgahook/gameservice.h index e2b6506..037be38 100644 --- a/cgahook/gameservice.h +++ b/cgahook/gameservice.h @@ -1159,7 +1159,7 @@ namespace CGA int IsItemTypeAssessable(int type); void AddAllTradeItems(void); - void SetBlockAllChatMsg(bool bShouldBlock); + void SetBlockChatMsgs(int state); bool WM_BattleNormalAttack(int target); bool WM_BattleSkillAttack(int skillpos, int skilllv, int target); bool WM_BattleGuard(); @@ -1320,7 +1320,7 @@ namespace CGA bool m_trade_add_all_stuffs; - bool m_ui_block_all_chatmsgs; + int m_ui_block_chatmsgs; game_type m_game_type; diff --git a/cgahook/server.cpp b/cgahook/server.cpp index 1f59506..de125fc 100644 --- a/cgahook/server.cpp +++ b/cgahook/server.cpp @@ -300,7 +300,7 @@ DWORD WINAPI CGAServerThread(LPVOID) server->register_handler("SendMail", timax::bind(&CGAService::SendMail, &g_CGAService)); server->register_handler("SendPetMail", timax::bind(&CGAService::SendPetMail, &g_CGAService)); server->register_handler("GetGameServerInfo", timax::bind(&CGAService::GetGameServerInfo, &g_CGAService)); - server->register_handler("SetBlockAllChatMsg", timax::bind(&CGAService::SetBlockAllChatMsg, &g_CGAService)); + server->register_handler("SetBlockChatMsgs", timax::bind(&CGAService::SetBlockChatMsgs, &g_CGAService)); server->start();