Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Feb 24, 2024
1 parent 93127f1 commit 1488d7e
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 25 deletions.
6 changes: 3 additions & 3 deletions CGALib/gameinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()); }
Expand Down
2 changes: 1 addition & 1 deletion CGALib/gameinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(int)> &callback) = 0;
virtual bool RegisterBattleActionNotify(const std::function<void(int)> &callback) = 0;
Expand Down
42 changes: 35 additions & 7 deletions CGAssistant/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void ChatForm::OnAutoChat()
{
if(g_CGAInterface->IsConnected())
{
g_CGAInterface->SetBlockAllChatMsg(true);
g_CGAInterface->SetBlockChatMsgs((int)ui->checkBox_BlockChatMsgs->checkState());
}
}

Expand All @@ -49,9 +49,20 @@ void ChatForm::OnNotifyGetPlayerInfo(QSharedPointer<CGA_PlayerInfo_t> 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)
Expand Down Expand Up @@ -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);
}
}

2 changes: 1 addition & 1 deletion CGAssistant/chatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CGA_PlayerInfo_t> player);
void OnNotifyChatMsg(int unitid, QString msg, int size, int color);
Expand Down
7 changes: 5 additions & 2 deletions CGAssistant/chatform.ui
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_BlockAllChatMsgs">
<widget class="QCheckBox" name="checkBox_BlockChatMsgs">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -52,7 +52,10 @@
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Block all chat messages</string>
<string>Block chat messages</string>
</property>
<property name="tristate">
<bool>true</bool>
</property>
</widget>
</item>
Expand Down
10 changes: 8 additions & 2 deletions CGAssistant/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int main(int argc, char *argv[])

QCommandLineOption chatmaxlines("chatmaxlines", "", "chatmaxlines", "100");

QCommandLineOption blockallchatmsgs("blockallchatmsgs");
QCommandLineOption blockchatmsgs("blockchatmsgs", "", "blockchatmsgs");

QCommandLineParser parser;

Expand Down Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion CGAssistant/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions cgahook/gameservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cgahook/gameservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion cgahook/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 1488d7e

Please sign in to comment.