From 93127f1cede729f63649e469ad3e3f84e052fe4c Mon Sep 17 00:00:00 2001 From: hzqst <113660872@qq.com> Date: Sun, 25 Feb 2024 00:43:41 +0800 Subject: [PATCH] Add BlockAllChatMsgs. --- CGALib/gameinterface.cpp | 14 +++++ CGALib/gameinterface.h | 1 + CGAssistant/chatform.cpp | 31 ++++++++++ CGAssistant/chatform.h | 4 ++ CGAssistant/chatform.ui | 36 +++++++++-- CGAssistant/lang.qm | Bin 27550 -> 27634 bytes CGAssistant/lang.ts | 10 ++- CGAssistant/main.cpp | 10 ++- CGAssistant/mainwindow.cpp | 2 + CGAssistant/mainwindow.h | 1 + CGAssistant/player.cpp | 1 - CGAssistant/player.h | 2 + cgahook/gameservice.cpp | 122 ++++++++++++++++++++----------------- cgahook/gameservice.h | 9 ++- cgahook/server.cpp | 5 +- 15 files changed, 177 insertions(+), 71 deletions(-) diff --git a/CGALib/gameinterface.cpp b/CGALib/gameinterface.cpp index 8517596..441c2c9 100644 --- a/CGALib/gameinterface.cpp +++ b/CGALib/gameinterface.cpp @@ -121,6 +121,8 @@ 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_FORWARD(NotifyServerShutdown, int); TIMAX_DEFINE_FORWARD(NotifyBattleAction, int); TIMAX_DEFINE_FORWARD(NotifyBattleMotionPacket, std::string); @@ -1465,6 +1467,18 @@ namespace CGA } return false; } + virtual bool SetBlockAllChatMsg(bool bShouldBlock) + { + if (m_connected) { + try { + info = m_client.call(std::chrono::milliseconds(10000), m_endpoint, CGAServiceProtocol::SetBlockAllChatMsg, bShouldBlock); + 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()); } + catch (msgpack::parse_error &e) { OutputDebugStringA("parse exception from " __FUNCTION__); OutputDebugStringA(e.what()); } + } + return false; + } virtual bool RegisterServerShutdownNotify(const std::function &callback) { if (m_connected) diff --git a/CGALib/gameinterface.h b/CGALib/gameinterface.h index f44da5f..d1d59e7 100644 --- a/CGALib/gameinterface.h +++ b/CGALib/gameinterface.h @@ -1240,6 +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 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 afbb40e..e641e48 100644 --- a/CGAssistant/chatform.cpp +++ b/CGAssistant/chatform.cpp @@ -1,6 +1,7 @@ #include "chatform.h" #include "ui_chatform.h" +#include #include extern CGA::CGAInterface *g_CGAInterface; @@ -13,6 +14,10 @@ ChatForm::ChatForm(QWidget *parent) : m_ChatMaxLines = 100; ui->textEdit_chat->document()->setMaximumBlockCount(m_ChatMaxLines); + + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(OnAutoChat())); + timer->start(1000); } ChatForm::~ChatForm() @@ -20,6 +25,14 @@ ChatForm::~ChatForm() delete ui; } +void ChatForm::OnAutoChat() +{ + if(g_CGAInterface->IsConnected()) + { + g_CGAInterface->SetBlockAllChatMsg(true); + } +} + void ChatForm::on_lineEdit_returnPressed() { auto saystring = ui->lineEdit->text().toStdString(); @@ -36,6 +49,10 @@ void ChatForm::OnNotifyGetPlayerInfo(QSharedPointer player) m_player = player; } +void ChatForm::OnNotifyFillChatSettings(bool blockallchatmsgs) +{ + ui->checkBox_BlockAllChatMsgs->setChecked(blockallchatmsgs); +} void ChatForm::OnNotifyFillStaticSettings(int freezetime, int chatmaxlines) { @@ -132,10 +149,24 @@ bool ChatForm::ParseChatSettings(const QJsonValue &val) if(!val.isObject()) return false; + auto obj = val.toObject(); + + if(obj.contains("blockallchatmsgs")) + ui->checkBox_BlockAllChatMsgs->setChecked(obj.take("blockallchatmsgs").toBool()); + return true; } void ChatForm::SaveChatSettings(QJsonObject &obj) { + obj.insert("blockallchatmsgs", ui->checkBox_BlockAllChatMsgs->isChecked()); +} +void ChatForm::on_checkBox_BlockAllChatMsgs_stateChanged(int state) +{ + if(g_CGAInterface->IsConnected()) + { + g_CGAInterface->SetBlockAllChatMsg(state ? true : false); + } } + diff --git a/CGAssistant/chatform.h b/CGAssistant/chatform.h index 1f8d496..ac08e67 100644 --- a/CGAssistant/chatform.h +++ b/CGAssistant/chatform.h @@ -20,6 +20,7 @@ class ChatForm : public QWidget ~ChatForm(); public slots: + void OnNotifyFillChatSettings(bool blockallchatmsgs); void OnNotifyFillStaticSettings(int freezetime, int chatmaxlines); void OnNotifyGetPlayerInfo(QSharedPointer player); void OnNotifyChatMsg(int unitid, QString msg, int size, int color); @@ -29,6 +30,9 @@ public slots: private slots: void on_lineEdit_returnPressed(); + void on_checkBox_BlockAllChatMsgs_stateChanged(int state); + + void OnAutoChat(); private: Ui::ChatForm *ui; QSharedPointer m_player; diff --git a/CGAssistant/chatform.ui b/CGAssistant/chatform.ui index 4704fce..5ca907d 100644 --- a/CGAssistant/chatform.ui +++ b/CGAssistant/chatform.ui @@ -26,11 +26,37 @@ - - - [Enter] to send chat - - + + + + + [Enter] to send chat message + + + + + + + + 0 + 0 + + + + + 128 + 0 + + + + Qt::LeftToRight + + + Block all chat messages + + + + diff --git a/CGAssistant/lang.qm b/CGAssistant/lang.qm index 1566991b7dd415e1e52f4cb9db0645405ce45cac..687a7da7bd65ac9110c1c63bc4ba6c56b453815b 100644 GIT binary patch delta 2558 zcmY*bXINBc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[回车] 发送聊天消息 + [回车] 发送聊天消息 Display Time @@ -856,6 +856,14 @@ Chat database will not work properly. Chat database will not work properly. 创建索引uploadtime失败,消息数据库可能无法正常工作。 + + [Enter] to send chat message + [回车] 发送聊天消息 + + + Block all chat messages + 屏蔽所有聊天消息 + ItemForm diff --git a/CGAssistant/main.cpp b/CGAssistant/main.cpp index ec43293..fa264cb 100644 --- a/CGAssistant/main.cpp +++ b/CGAssistant/main.cpp @@ -116,6 +116,8 @@ int main(int argc, char *argv[]) QCommandLineOption chatmaxlines("chatmaxlines", "", "chatmaxlines", "100"); + QCommandLineOption blockallchatmsgs("blockallchatmsgs"); + QCommandLineParser parser; parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); @@ -151,6 +153,7 @@ int main(int argc, char *argv[]) parser.addOption(consolemaxlines); parser.addOption(scriptfreezeduration); parser.addOption(chatmaxlines); + parser.addOption(blockallchatmsgs); parser.process(a); QTranslator translator; @@ -168,7 +171,6 @@ int main(int argc, char *argv[]) MainWindow w; - for(unsigned int qport = 14396; qport < 14396 + 1000; ++qport) { if(qserver.listen(QHostAddress::LocalHost, qport, [&w](QHttpRequest* req, QHttpResponse* res) { @@ -264,6 +266,8 @@ int main(int argc, char *argv[]) w.show(); + w.NotifyFillStaticSettings(parser.value(killfreeze).toInt(), parser.value(chatmaxlines).toInt()); + w.NotifyFillAutoLogin(parser.value(gameType).toInt(), parser.value(loginUser), parser.value(loginPwd), @@ -293,9 +297,9 @@ int main(int argc, char *argv[]) parser.value(consolemaxlines).toInt(), parser.value(scriptfreezeduration).toInt() ); - w.NotifyFillLoadSettings(parser.value(loadsettings)); + w.NotifyFillChatSettings(parser.isSet(blockallchatmsgs) ? true : false); - w.NotifyFillStaticSettings(parser.value(killfreeze).toInt(), parser.value(chatmaxlines).toInt()); + w.NotifyFillLoadSettings(parser.value(loadsettings)); return a.exec(); } diff --git a/CGAssistant/mainwindow.cpp b/CGAssistant/mainwindow.cpp index 839f156..3c27afa 100644 --- a/CGAssistant/mainwindow.cpp +++ b/CGAssistant/mainwindow.cpp @@ -80,6 +80,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(playerFrom, &PlayerForm::SaveItemTweaker, itemForm, &ItemForm::SaveItemTweaker); connect(playerFrom, &PlayerForm::SaveBattleSettings, autoBattleForm, &AutoBattleForm::SaveBattleSettings); connect(playerFrom, &PlayerForm::SaveChatSettings, chatForm, &ChatForm::SaveChatSettings); + connect(this, &MainWindow::NotifyChangeWindow, processFrom, &ProcessForm::OnNotifyChangeWindow); connect(this, &MainWindow::NotifyFillAutoLogin, accountForm, &AccountForm::OnNotifyFillAutoLogin); @@ -87,6 +88,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(this, &MainWindow::NotifyFillLoadSettings, playerFrom, &PlayerForm::OnNotifyFillLoadSettings); connect(this, &MainWindow::NotifyFillStaticSettings, processWorker, &CProcessWorker::OnNotifyFillStaticSettings); connect(this, &MainWindow::NotifyFillStaticSettings, chatForm, &ChatForm::OnNotifyFillStaticSettings); + connect(this, &MainWindow::NotifyFillChatSettings, chatForm, &ChatForm::OnNotifyFillChatSettings); connect(playerWorker, &CPlayerWorker::NotifyGetSkillsInfo, autoBattleForm, &AutoBattleForm::OnNotifyGetSkillsInfo, Qt::ConnectionType::QueuedConnection); connect(playerWorker, &CPlayerWorker::NotifyGetPetsInfo, autoBattleForm, &AutoBattleForm::OnNotifyGetPetsInfo, Qt::ConnectionType::QueuedConnection); diff --git a/CGAssistant/mainwindow.h b/CGAssistant/mainwindow.h index eaa630e..ea76f71 100644 --- a/CGAssistant/mainwindow.h +++ b/CGAssistant/mainwindow.h @@ -36,6 +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 NotifyFillStaticSettings(int freezetime, int chatmaxlines); void HttpGetGameProcInfo(QJsonDocument* doc); void HttpGetSettings(QJsonDocument* doc); diff --git a/CGAssistant/player.cpp b/CGAssistant/player.cpp index cd0e1d9..decaf6b 100644 --- a/CGAssistant/player.cpp +++ b/CGAssistant/player.cpp @@ -276,7 +276,6 @@ void CPlayerWorker::OnDownloadMap(int xsize, int ysize) m_IsDownloadingMap = true; } - void CPlayerWorker::OnQueueAntiAFKKick() { if(!m_bAntiAFKKick) diff --git a/CGAssistant/player.h b/CGAssistant/player.h index fa0292d..e74e96a 100644 --- a/CGAssistant/player.h +++ b/CGAssistant/player.h @@ -283,6 +283,7 @@ public slots: void OnSetNoSwitchAnim(int state); void OnSetGameTextUI(int state); void OnSetAntiAFKKick(int state); + void OnSetBlockAllChatMsgs(int state); void OnDownloadMap(int xsize, int ysize); void OnTabChanged(int tabindex); void OnSetUseFoodAt(QString str); @@ -330,6 +331,7 @@ public slots: bool m_bHighSpeedBattle; bool m_bGameTextUI; bool m_bAntiAFKKick; + QSharedPointer m_player; QSharedPointer m_pets; diff --git a/cgahook/gameservice.cpp b/cgahook/gameservice.cpp index 627053a..d77141e 100644 --- a/cgahook/gameservice.cpp +++ b/cgahook/gameservice.cpp @@ -507,7 +507,7 @@ int __fastcall NewOnLoginResult(void *pthis, int dummy, int a1, int result, cons puts(sb.GetString()); fflush(stdout); - WriteLog("NtTerminateProcess\n"); + //WriteLog("NtTerminateProcess\n"); NtTerminateProcess((HANDLE)-1, 0); return 0; } @@ -710,7 +710,7 @@ void CGAService::NewBATTLE_PlayerAction() } if (prevPlayerStatus != 1 && playerStatus == 1) { - WriteLog("CGA_NotifyBattleAction player\n"); + //WriteLog("CGA_NotifyBattleAction player\n"); int flags = FL_BATTLE_ACTION_ISPLAYER; if (m_btl_double_action) @@ -724,14 +724,14 @@ void CGAService::NewBATTLE_PlayerAction() { if (m_btl_pet_skill_packet_send) { - WriteLog("m_btl_pet_skill_packet_send = true\n"); + //WriteLog("m_btl_pet_skill_packet_send = true\n"); *g_btl_action_done = 1; m_btl_pet_skill_packet_send = false; return; } else { - WriteLog("CGA_NotifyBattleAction pet\n"); + //WriteLog("CGA_NotifyBattleAction pet\n"); } //Notify pet action int flags = 0; @@ -753,15 +753,15 @@ void __cdecl NewNET_WriteEndBattlePacket_cgitem(int a1, int a2) { g_CGAService.NET_WriteEndBattlePacket_cgitem(a1, a2); - WriteLog("NewNET_WriteEndBattlePacket_cgitem\n"); + //WriteLog("NewNET_WriteEndBattlePacket_cgitem\n"); CGA_NotifyBattleAction(FL_BATTLE_ACTION_END); } void CGAService::NewNET_ParseTradeItemsPackets(int a1, const char *buf) { - WriteLog("NewNET_ParseTradeItemsPackets\n"); - WriteLog(buf); + //WriteLog("NewNET_ParseTradeItemsPackets\n"); + //WriteLog(buf); NET_ParseTradeItemsPackets(a1, buf); @@ -818,9 +818,9 @@ void CGAService::NewNET_ParseTradePetPackets(int a1, int index, const char *buf) { NET_ParseTradePetPackets(a1, index, buf); - WriteLog("NewNET_ParseTradePetPackets\n"); + //WriteLog("NewNET_ParseTradePetPackets\n"); - WriteLog2(buf); + //WriteLog2(buf); char name[256]; @@ -872,9 +872,9 @@ void CGAService::NewNET_ParseTradePetSkillPackets(int a1, int index, const char { NET_ParseTradePetSkillPackets(a1, index, buf); - WriteLog("NewNET_ParseTradePetSkillPackets\n"); + //WriteLog("NewNET_ParseTradePetSkillPackets\n"); - WriteLog2(buf); + //WriteLog2(buf); cga_trade_stuff_info_t info(TRADE_STUFFS_PETSKILL); @@ -902,7 +902,7 @@ void __cdecl NewNET_ParseTradePetSkillPackets(int a1, int index, const char *buf void CGAService::NewNET_ParseTradeGoldPackets(int a1, int gold) { - WriteLog("NewNET_ParseTradeGoldPackets\n"); + //WriteLog("NewNET_ParseTradeGoldPackets\n"); NET_ParseTradeGoldPackets(a1, gold); @@ -920,7 +920,7 @@ void __cdecl NewNET_ParseTradeGoldPackets(int a1, int gold) void CGAService::NewNET_ParseTradePlayers(int a1, const char *src, char *src2) { - WriteLog("NewNET_ParseTradePlayers\n"); + //WriteLog("NewNET_ParseTradePlayers\n"); NET_ParseTradePlayers(a1, src, src2); @@ -968,7 +968,7 @@ void __cdecl NewNET_ParseTradePlayers(int a1, const char *src, char *src2) void CGAService::NewNET_ParseHealPlayers(int a1, const char *src) { - WriteLog("NewNET_ParseHealPlayers %s\n", src); + //WriteLog("NewNET_ParseHealPlayers %s\n", src); NET_ParseHealPlayers(a1, src); @@ -1057,7 +1057,7 @@ void __cdecl NewNET_ParseHealPlayers(int a1, const char *src) void CGAService::NewNET_ParseHealUnits(int a1, const char *src) { - WriteLog("NewNET_ParseHealUnits\n"); + //WriteLog("NewNET_ParseHealUnits\n"); NET_ParseHealUnits(a1, src); @@ -1178,7 +1178,7 @@ void __cdecl NewNET_ParseHealUnits(int a1, const char *src) void CGAService::NewNET_ParseItemPlayers(int a1, const char *src) { - WriteLog("NewNET_ParseItemPlayers\n"); + //WriteLog("NewNET_ParseItemPlayers\n"); NET_ParseItemPlayers(a1, src); @@ -1267,7 +1267,7 @@ void __cdecl NewNET_ParseItemPlayers(int a1, const char *src) void CGAService::NewNET_ParseItemUnits(int a1, const char *src) { - WriteLog("NewNET_ParseItemUnits\n"); + //WriteLog("NewNET_ParseItemUnits\n"); NET_ParseItemUnits(a1, src); @@ -1379,7 +1379,7 @@ void __cdecl NewNET_ParseItemUnits(int a1, const char *src) void CGAService::NewNET_ParseBattlePackets(int a1, const char *buf) { - WriteLog("NewNET_ParseBattlePackets %s %s\n", (*g_playerBase)->name, buf); + //WriteLog("NewNET_ParseBattlePackets %s %s\n", (*g_playerBase)->name, buf); if (*buf == 'M') { @@ -1400,7 +1400,7 @@ void CGAService::NewNET_ParseBattlePackets(int a1, const char *buf) m_btl_delayanimpacket.a1 = a1; strcpy(m_btl_delayanimpacket.buf, buf); m_btl_delayanimpacket.lasttick = GetTickCount(); - WriteLog("anim packet delayed\n"); + //WriteLog("anim packet delayed\n"); } return; } @@ -1413,7 +1413,7 @@ void CGAService::NewNET_ParseBattlePackets(int a1, const char *buf) { NET_ParseBattlePackets(m_btl_delayanimpacket.a1, m_btl_highspeed_enable ? "M|" : m_btl_delayanimpacket.buf); m_btl_delayanimpacket.isdelay = false; - WriteLog("delay anim played\n"); + //WriteLog("delay anim played\n"); } } @@ -1600,14 +1600,14 @@ void CGAService::NewNET_ParseWorkingResult(int a1, int success, int type, const void __cdecl NewNET_ParseWorkingResult(int a1, int success, int type, const char *buf) { - //WriteLog("type=%d, success=%d, buf=%s\n", type, success, buf); + ////WriteLog("type=%d, success=%d, buf=%s\n", type, success, buf); g_CGAService.NewNET_ParseWorkingResult(a1, success, type, buf); } void CGAService::NewNET_ParseChatMsg(int a1, int unitid, const char *buf, int color, int size) { - WriteLog("NewNET_ParseChatMsg u=%d, buf=%s, color=%d, size=%d\n", unitid, buf, color, size); + //WriteLog("NewNET_ParseChatMsg u=%d, buf=%s, color=%d, size=%d\n", unitid, buf, color, size); if (buf[0] == 'P' && buf[1] == '|') { @@ -1620,6 +1620,9 @@ 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) + return; + g_CGAService.NewNET_ParseChatMsg(a1, unitid, buf, color, size); } @@ -1631,7 +1634,7 @@ void CGAService::NewNET_ParseSysMsg(int a1, const char *buf) cga_chat_msg_t msg(-1, boost::locale::conv::to_utf(temp, "GBK"), 0, 0); CGA_NotifyChatMsg(msg); - WriteLog("NewNET_ParseSysMsg %s\n", temp); + //WriteLog("NewNET_ParseSysMsg %s\n", temp); NET_ParseSysMsg(a1, buf); } @@ -1643,7 +1646,7 @@ void __cdecl NewNET_ParseSysMsg(int a1, const char *buf) void CGAService::NewNET_ParseReadyTrade() { - WriteLog("NewNET_ParseConfirmTrade\n"); + //WriteLog("NewNET_ParseConfirmTrade\n"); NET_ParseReadyTrade(); @@ -1657,7 +1660,7 @@ void __cdecl NewNET_ParseReadyTrade() void CGAService::NewNET_ParseConfirmTrade(int a1, int a2) { - WriteLog("NewNET_ParseConfirmTrade\n"); + //WriteLog("NewNET_ParseConfirmTrade\n"); NET_ParseConfirmTrade(a1, a2); @@ -1683,7 +1686,7 @@ void __cdecl NewNET_ParseMeetEnemy(int a1, int a2, int a3) void CGAService::NewNET_ParseDownloadMap(int sock, int index1, int index3, int xbase, int ybase, int xtop, int ytop, const char *buf) { - //WriteLog("NewNET_ParseDownloadMap %d %d %d %d %d %d\n", index1, index3, xbase, ybase, xtop, ytop); + ////WriteLog("NewNET_ParseDownloadMap %d %d %d %d %d %d\n", index1, index3, xbase, ybase, xtop, ytop); cga_download_map_t msg(index1, index3, xbase, ybase, xtop, ytop); CGA_NotifyDownloadMap(msg); @@ -2250,7 +2253,7 @@ int __cdecl NewIsMapObjectEntrance(int xpos, int ypos) void CGAService::NewNET_WritePrepareCraftItemPacket_cgitem(int a1, int a2) { - //WriteLog("NewNET_WritePrepareCraftItemPacket_cgitem %d\n", a2); + ////WriteLog("NewNET_WritePrepareCraftItemPacket_cgitem %d\n", a2); if (m_work_immediate) { if (m_work_immediate_state == 2) @@ -2278,7 +2281,7 @@ void __cdecl NewNET_WritePrepareCraftItemPacket_cgitem(int a1, int a2) void CGAService::NewNET_WriteWorkPacket_cgitem(int a1, int skill, int a3, int a4, const char *buf) { - //WriteLog("NET_WriteWorkPacket_cgitem %d %d %d %s\n", skill, a3, a4, buf); + ////WriteLog("NET_WriteWorkPacket_cgitem %d %d %d %s\n", skill, a3, a4, buf); if (m_work_immediate && m_work_immediate_state == 1) { m_work_immediate_state = 2; @@ -3462,9 +3465,10 @@ void CGAService::Initialize(game_type type) m_ui_create_character = false; m_run_game_pid = 0; m_run_game_tid = 0; - m_ui_battle_action = 0; - m_ui_battle_hevent = CreateEventA(NULL, FALSE, FALSE, NULL); + //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; if (*g_mutex) { @@ -3530,9 +3534,10 @@ void CGAService::Initialize(game_type type) m_ui_create_character = false; m_run_game_pid = 0; m_run_game_tid = 0; - m_ui_battle_action = 0; - m_ui_battle_hevent = CreateEventA(NULL, FALSE, FALSE, NULL); + //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; DetourTransactionBegin(); DetourAttach(&(void *&)BATTLE_PlayerAction, ::NewBATTLE_PlayerAction); @@ -3658,7 +3663,7 @@ void CGAService::DrawCustomText() { if (m_btl_highspeed_enable && m_btl_delayanimpacket.isdelay && GetTickCount() > m_btl_delayanimpacket.lasttick + 3500) { - WriteLog("end of battle with exception\n"); + //WriteLog("end of battle with exception\n"); m_btl_delayanimpacket.lasttick = 0; m_btl_delayanimpacket.isdelay = false; NET_ParseBattlePackets(m_btl_delayanimpacket.a1, "M|END|"); @@ -5214,6 +5219,11 @@ void CGAService::AddAllTradeItems(void) m_trade_add_all_stuffs = true; } +void CGAService::SetBlockAllChatMsg(bool bShouldBlock) +{ + m_ui_block_all_chatmsgs = true; +} + bool CGAService::WM_BattleNormalAttack(int target) { if (!IsInGame()) @@ -5230,7 +5240,7 @@ bool CGAService::WM_BattleNormalAttack(int target) *g_btl_action_done = 1; COMMON_PlaySound(57, 320, 240); - WriteLog("BattleNormalAttack %d\n", target); + //WriteLog("BattleNormalAttack %d\n", target); return true; } @@ -5254,7 +5264,7 @@ bool CGAService::WM_BattleSkillAttack(int skillpos, int skilllv, int target) if (!g_skill_base[skillpos].name[0]) { - WriteLog("skill %d not valid\n", skillpos); + //WriteLog("skill %d not valid\n", skillpos); return false; } @@ -5268,7 +5278,7 @@ bool CGAService::WM_BattleSkillAttack(int skillpos, int skilllv, int target) NET_WritePacket(*g_net_buffer, *g_net_socket, net_header_battle, buf); //*g_btl_action_done = 1; //COMMON_PlaySound(57, 320, 240); - WriteLog("BattleSkillAttack %d %d %d\n", skillpos, skilllv, target); + //WriteLog("BattleSkillAttack %d %d %d\n", skillpos, skilllv, target); return TRUE; } @@ -5277,18 +5287,18 @@ bool CGAService::WM_BattleSkillAttack(int skillpos, int skilllv, int target) if (!(*g_btl_skill_allowbit & (1 << skillpos)))//skill not allowed!!! { - WriteLog("skill %d not allowed\n", skillpos); + //WriteLog("skill %d not allowed\n", skillpos); return false; } if (g_skill_base[skillpos].level < skilllv) { - WriteLog("skill lv%d not enough\n", skilllv); + //WriteLog("skill lv%d not enough\n", skilllv); return false; } if (g_skill_base[skillpos].sub[skilllv].available == 0) { - WriteLog("skill lv%d not available, downgrade\n", skilllv); + //WriteLog("skill lv%d not available, downgrade\n", skilllv); bool available = false; for (int lv = skilllv - 1; lv >= 0; --lv) { @@ -5302,7 +5312,7 @@ bool CGAService::WM_BattleSkillAttack(int skillpos, int skilllv, int target) if (!available) { - WriteLog("skill lv%d not available\n", skilllv); + //WriteLog("skill lv%d not available\n", skilllv); return false; } } @@ -5322,7 +5332,7 @@ bool CGAService::WM_BattleSkillAttack(int skillpos, int skilllv, int target) if (!available) { - WriteLog("skill lv%d no enough mp\n", skilllv); + //WriteLog("skill lv%d no enough mp\n", skilllv); return false; } } @@ -5336,7 +5346,7 @@ bool CGAService::WM_BattleSkillAttack(int skillpos, int skilllv, int target) *g_btl_action_done = 1; COMMON_PlaySound(57, 320, 240); - WriteLog("BattleSkillAttack2 %d %d %d\n", skillpos, skilllv, target); + //WriteLog("BattleSkillAttack2 %d %d %d\n", skillpos, skilllv, target); return true; } @@ -5348,7 +5358,7 @@ bool CGAService::BattleSkillAttack(int skillpos, int skilllv, int target, bool p target |= 0x10000000; } - //WriteLog("BattleSkillAttack %d %d %d\n", skillpos, skilllv, target); + ////WriteLog("BattleSkillAttack %d %d %d\n", skillpos, skilllv, target); return SendMessageA(g_MainHwnd, WM_CGA_BATTLE_SKILLATTACK, skillpos | (skilllv << 8), target) ? true : false; } @@ -5539,13 +5549,13 @@ bool CGAService::WM_BattlePetSkillAttack(int skillpos, int target) m_btl_pet_skill_packet_send = true; } - WriteLog("BattlePetSkillAttack FF\n"); + //WriteLog("BattlePetSkillAttack FF\n"); return true; } if (!(*g_btl_petskill_allowbit & (1 << skillpos)))//skill not allowed!!! { - WriteLog("pet skill %d not allowed\n", skillpos); + //WriteLog("pet skill %d not allowed\n", skillpos); return false; } @@ -5570,7 +5580,7 @@ bool CGAService::WM_BattlePetSkillAttack(int skillpos, int target) m_btl_pet_skill_packet_send = true; } - WriteLog("BattlePetSkillAttack %d %d %d\n", skillpos, target, packetOnly ? 1 : 0); + //WriteLog("BattlePetSkillAttack %d %d %d\n", skillpos, target, packetOnly ? 1 : 0); return true; } @@ -5859,7 +5869,7 @@ bool CGAService::WM_SellNPCStore(cga_sell_items_t *items) if (*g_npc_dialog_type != 7 && *g_npc_dialog_type != 6 && *g_npc_dialog_type != 22 && *g_npc_dialog_type != 20 && *g_npc_dialog_type != 31) { - //WriteLog("type mismatch %d\n", *g_npc_dialog_type); + ////WriteLog("type mismatch %d\n", *g_npc_dialog_type); return false; } @@ -5869,7 +5879,7 @@ bool CGAService::WM_SellNPCStore(cga_sell_items_t *items) { if (items->at(i).itemid != 0 && (*g_playerBase)->iteminfos[items->at(i).itempos].item_id != items->at(i).itemid) { - //WriteLog("id mismatch %d %d\n", items->at(i).itemid, (*g_playerBase)->iteminfos[items->at(i).itempos].item_id); + ////WriteLog("id mismatch %d %d\n", items->at(i).itemid, (*g_playerBase)->iteminfos[items->at(i).itempos].item_id); return false; } bool allow = false; @@ -5877,7 +5887,7 @@ bool CGAService::WM_SellNPCStore(cga_sell_items_t *items) { if (g_npcdlg_item_base[j].valid && g_npcdlg_item_base[j].itempos == items->at(i).itempos) { - //WriteLog("j=%d g_npcdlg_item_base[j].itempos=%d\n", j, g_npcdlg_item_base[j].itempos); + ////WriteLog("j=%d g_npcdlg_item_base[j].itempos=%d\n", j, g_npcdlg_item_base[j].itempos); allow = true; break; } @@ -5907,11 +5917,11 @@ bool CGAService::WM_SellNPCStore(cga_sell_items_t *items) { if (items->at(i).itemid != 0 && (*g_playerBase)->iteminfos[items->at(i).itempos].item_id != items->at(i).itemid) { - //WriteLog("id mismatch %d %d %d\n", items->at(i).itemid, (*g_playerBase)->iteminfos[items->at(i).itempos].item_id, items->at(i).itemid); + ////WriteLog("id mismatch %d %d %d\n", items->at(i).itemid, (*g_playerBase)->iteminfos[items->at(i).itempos].item_id, items->at(i).itemid); return false; } if ((*g_playerBase)->iteminfos[items->at(i).itempos].count != 0 && (*g_playerBase)->iteminfos[items->at(i).itempos].count < items->at(i).count) { - //WriteLog("count mismatch %d %d\n", (*g_playerBase)->iteminfos[items->at(i).itempos].count, items->at(i).count); + ////WriteLog("count mismatch %d %d\n", (*g_playerBase)->iteminfos[items->at(i).itempos].count, items->at(i).count); return false; } sprintf(buf, "%d\\z%d", items->at(i).itempos, items->at(i).count); @@ -6314,7 +6324,7 @@ bool CGAService::WM_StartWork(int skill_index, int sub_index) break; } if (!isavailable) { - WriteLog("WM_StartWork WORK_TYPE_HEALING subindex %d not available", sub_index); + //WriteLog("WM_StartWork WORK_TYPE_HEALING subindex %d not available", sub_index); return false; } @@ -6334,7 +6344,7 @@ bool CGAService::WM_StartWork(int skill_index, int sub_index) int sub_index2 = sub_index & 0xFF; int sub_type = (sub_index >> 8) & 0xFF; if (sub_index2 < 0 || sub_index2 > 50 || !g_skill_base[skill_index].craft[sub_index2].available) { - WriteLog("WM_StartWork subtype %d, subindex %d not available", sub_type, sub_index2); + //WriteLog("WM_StartWork subtype %d, subindex %d not available", sub_type, sub_index2); return false; } UI_OpenCraftDialog(skill_index, sub_index, sub_type); @@ -6362,7 +6372,7 @@ bool CGAService::WM_StartWork(int skill_index, int sub_index) break; } if (!isavailable) { - WriteLog("WM_StartWork WORK_TYPE_PET subindex %d not available", sub_index); + //WriteLog("WM_StartWork WORK_TYPE_PET subindex %d not available", sub_index); return false; } @@ -7229,7 +7239,7 @@ void CGAService::WM_FixMapWarpStuck(int type) { if (type == 0) { - WriteLog("FixMapWarpStuck type 0\n"); + //WriteLog("FixMapWarpStuck type 0\n"); *g_disable_move = 0; if (m_game_type == cg_item_6000) @@ -7239,7 +7249,7 @@ void CGAService::WM_FixMapWarpStuck(int type) } else if (type == 1) { - WriteLog("FixMapWarpStuck type 1\n"); + //WriteLog("FixMapWarpStuck type 1\n"); if (IsMapObjectEntrance(g_player_xpos->decode(), g_player_ypos->decode())) { diff --git a/cgahook/gameservice.h b/cgahook/gameservice.h index d8b8270..e2b6506 100644 --- a/cgahook/gameservice.h +++ b/cgahook/gameservice.h @@ -1159,6 +1159,7 @@ namespace CGA int IsItemTypeAssessable(int type); void AddAllTradeItems(void); + void SetBlockAllChatMsg(bool bShouldBlock); bool WM_BattleNormalAttack(int target); bool WM_BattleSkillAttack(int skillpos, int skilllv, int target); bool WM_BattleGuard(); @@ -1307,18 +1308,20 @@ namespace CGA int m_run_game_pid; int m_run_game_tid; - int m_ui_battle_action; + /*int m_ui_battle_action; struct { int change_petid; int select_skill_index; bool select_skill_ok; int select_target; - }m_ui_battle_action_param; - HANDLE m_ui_battle_hevent; + }m_ui_battle_action_param;*/ + //HANDLE m_ui_battle_hevent; bool m_trade_add_all_stuffs; + bool m_ui_block_all_chatmsgs; + game_type m_game_type; HFONT m_hFont; diff --git a/cgahook/server.cpp b/cgahook/server.cpp index 2868063..1f59506 100644 --- a/cgahook/server.cpp +++ b/cgahook/server.cpp @@ -127,11 +127,11 @@ void CGA_CreateSharedData(int port) { ULONG ProcessId = GetCurrentProcessId(); - WCHAR szLockName[32]; + WCHAR szLockName[64]; wsprintfW(szLockName, L"CGASharedDataLock_%d", ProcessId); g_hDataLock = CreateMutexW(NULL, TRUE, szLockName); - WCHAR szMappingName[32]; + WCHAR szMappingName[64]; wsprintfW(szMappingName, L"CGASharedData_%d", ProcessId); g_hFileMapping = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(CGA::CGAShare_t), szMappingName); if (g_hFileMapping && GetLastError() != ERROR_ALREADY_EXISTS) @@ -300,6 +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->start();