Skip to content

Commit fe3a8a0

Browse files
committed
v3.1.0
1 parent 8a63347 commit fe3a8a0

File tree

8 files changed

+78
-28
lines changed

8 files changed

+78
-28
lines changed

BetterChat.cpp

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ unsigned char numTeam;
3737
int blueScore;
3838
int orangeScore;
3939
bool gameInProgress;
40+
bool endGameScreen;
4041
bool waitingForKickoff;
4142
bool goal;
4243
bool assist;
@@ -68,8 +69,17 @@ void BetterChat::onLoad()
6869
else {
6970
gameInProgress = false;
7071
}
71-
72-
gameWrapper->HookEventWithCaller<ActorWrapper>("Function GameEvent_TA.Countdown.BeginState", bind(&BetterChat::gameBegin, this));
72+
endGameScreen = false;
73+
74+
gameWrapper->HookEvent("Function ProjectX.EngineShare_X.EventPreLoadMap", bind([this]() {
75+
if (gameWrapper->IsInReplay() || gameWrapper->IsInFreeplay()) { return; }
76+
gameWrapper->HookEvent("Function GameEvent_Soccar_TA.Active.StartRound", bind([this]() {
77+
gameWrapper->SetTimeout([&](...) { gameBegin(); }, 2.0f);
78+
}));
79+
}));
80+
gameWrapper->HookEventPost("Function GameEvent_Soccar_TA.WaitingForPlayers.BeginState", bind([this]() {
81+
gameWrapper->SetTimeout([&](...) { onNewGame(); }, 0.5f);
82+
}));
7383
gameWrapper->HookEventWithCallerPost<ServerWrapper>("Function TAGame.GFxHUD_TA.HandleStatTickerMessage", bind(&BetterChat::onStatTickerMessage, this, std::placeholders::_1, std::placeholders::_2));
7484
gameWrapper->HookEventWithCaller<ActorWrapper>("Function TAGame.HUDBase_TA.OnChatMessage", bind(&BetterChat::chatMessageEvent, this, std::placeholders::_1, std::placeholders::_2));
7585
gameWrapper->HookEventWithCallerPost<ActorWrapper>("Function TAGame.Replay_TA.StopPlayback", bind(&BetterChat::addKickoffMessages, this));
@@ -83,9 +93,12 @@ void BetterChat::onLoad()
8393
}
8494

8595
void BetterChat::onUnload()
86-
{
96+
{
8797
LOG("Plugin Off");
98+
gameWrapper->UnhookEvent("Function ProjectX.EngineShare_X.EventPreLoadMap");
8899
gameWrapper->UnhookEvent("Function GameEvent_TA.Countdown.BeginState");
100+
gameWrapper->UnhookEvent("Function GameEvent_Soccar_TA.Active.StartRound");
101+
gameWrapper->UnhookEvent("Function GameEvent_Soccar_TA.WaitingForPlayers.BeginState");
89102
gameWrapper->UnhookEvent("Function TAGame.GFxHUD_TA.HandleStatTickerMessage");
90103
gameWrapper->UnhookEvent("Function TAGame.HUDBase_TA.OnChatMessage");
91104
gameWrapper->UnhookEvent("Function TAGame.Replay_TA.StopPlayback");
@@ -398,20 +411,32 @@ void BetterChat::setConfig() {
398411
LOG("Config: " + config);
399412
}
400413

401-
// Game begin
402-
void BetterChat::gameBegin() {
403-
if (!gameWrapper->IsInOnlineGame() || gameWrapper->IsInReplay()) { return; }
414+
void BetterChat::onNewGame() {
415+
if (!gameWrapper->IsInOnlineGame() || gameWrapper->IsInReplay()) { LOG("Not in Online Game"); return; }
404416
gameWrapper->UnregisterDrawables();
405-
CarWrapper localCar = gameWrapper->GetLocalCar();
406-
if (!localCar) { return; }
407417
if (gameInProgress) { return; }
408418
else {
419+
LOG("[EVENT] New game");
420+
409421
gameInProgress = true;
422+
endGameScreen = false;
410423

411424
setConfig();
412425

413426
resetWhitelist();
414427
playersInfos.clear();
428+
429+
gameWrapper->HookEvent("Function GameEvent_TA.Countdown.BeginState", bind(&BetterChat::gameBegin, this));
430+
}
431+
}
432+
433+
// Game begin
434+
void BetterChat::gameBegin() {
435+
if (!gameWrapper->IsInOnlineGame() || gameWrapper->IsInReplay()) { return; }
436+
if (!gameInProgress) { onNewGame(); gameWrapper->UnhookEvent("Function GameEvent_Soccar_TA.Active.StartRound"); }
437+
CarWrapper localCar = gameWrapper->GetLocalCar();
438+
if (!localCar) { return; }
439+
else {
415440
LOG("[EVENT] Game start");
416441

417442
numTeam = gameWrapper->GetLocalCar().GetPRI().GetTeamNum();
@@ -427,6 +452,8 @@ void BetterChat::gameBegin() {
427452
lastToucherID = -1;
428453
lastSaveTime = chrono::system_clock::now();
429454
save = false;
455+
456+
gameWrapper->UnhookEvent("Function GameEvent_TA.Countdown.BeginState");
430457
}
431458
}
432459

@@ -437,7 +464,7 @@ void BetterChat::onStatTickerMessage(ServerWrapper caller, void* params) {
437464

438465
std::string name = event.GetEventName();
439466

440-
if (!gameWrapper->IsInOnlineGame() || !gameInProgress) { return; }
467+
if (!gameWrapper->IsInOnlineGame() || !gameInProgress || endGameScreen) { return; }
441468

442469
ServerWrapper server = gameWrapper->GetCurrentGameState();
443470

@@ -465,7 +492,7 @@ void BetterChat::onStatTickerMessage(ServerWrapper caller, void* params) {
465492

466493
// Goal
467494
void BetterChat::onGoal() {
468-
if (!gameWrapper->IsInOnlineGame() || !goal || !gameInProgress) { return; }
495+
if (!gameWrapper->IsInOnlineGame() || !goal || !gameInProgress || endGameScreen) { return; }
469496
whitelist.clear();
470497
goal = false;
471498

@@ -519,7 +546,7 @@ void BetterChat::onGoal() {
519546

520547
// Kick-off
521548
void BetterChat::hitBall(CarWrapper car, void* params) {
522-
if (!gameWrapper->IsInOnlineGame() || !gameInProgress) { return; }
549+
if (!gameWrapper->IsInOnlineGame() || !gameInProgress || endGameScreen) { return; }
523550

524551
if (waitingForKickoff == true) {
525552
waitingForKickoff = false;
@@ -545,7 +572,7 @@ void BetterChat::hitBall(CarWrapper car, void* params) {
545572

546573
// Timer update
547574
void BetterChat::onTimerUpdate() {
548-
if (!gameWrapper->IsInOnlineGame() || !gameInProgress) { return; }
575+
if (!gameWrapper->IsInOnlineGame() || !gameInProgress || endGameScreen) { return; }
549576
if (save && chrono::system_clock::now() > lastSaveTime + chrono::seconds(getParamsInJson(config).aftersavetime)) {
550577
save = false;
551578
resetWhitelist();
@@ -554,15 +581,15 @@ void BetterChat::onTimerUpdate() {
554581

555582
// Overtime
556583
void BetterChat::onOvertimeStarted() {
557-
if (!gameWrapper->IsInOnlineGame() || !gameInProgress) { return; }
584+
if (!gameWrapper->IsInOnlineGame() || !gameInProgress || endGameScreen) { return; }
558585
LOG("[EVENT] Overtime");
559586
whitelist.clear();
560587
addKickoffMessages();
561588
}
562589

563590
// Replay end
564591
void BetterChat::addKickoffMessages() {
565-
if (!gameWrapper->IsInOnlineGame() || !gameInProgress) { return; }
592+
if (!gameWrapper->IsInOnlineGame() || !gameInProgress || endGameScreen) { return; }
566593
waitingForKickoff = true;
567594
map<string, bool> beforeKickoffMsg = readMapInJson(config, "beforeKickoff");
568595
for (const auto& pair : beforeKickoffMsg) {
@@ -581,13 +608,14 @@ void BetterChat::gameEnd() {
581608
if (gameInProgress) {
582609
resetWhitelist();
583610
LOG("[EVENT] Game end");
611+
endGameScreen = true;
584612
gameWrapper->RegisterDrawable(bind(&BetterChat::ShowToxicityScores, this, std::placeholders::_1));
585613
}
586614
}
587615

588616
// Display the table with the number of blocked messages per player during the game
589617
void BetterChat::ShowToxicityScores(CanvasWrapper canvas) {
590-
if (getParamsInJson(config).chatfilter && getParamsInJson(config).toxicityscores && cvarManager->getCvar("betterchat_enabled").getBoolValue()) {
618+
if (getParamsInJson(config).toxicityscores && cvarManager->getCvar("betterchat_enabled").getBoolValue()) {
591619
canvas.SetColor(LinearColor(255, 255, 255, 255));
592620

593621
int x = cvarManager->getCvar("betterchat_score_X").getIntValue();
@@ -652,6 +680,9 @@ void BetterChat::ShowToxicityScores(CanvasWrapper canvas) {
652680
void BetterChat::gameDestroyed() {
653681
LOG("[EVENT] Game destroyed");
654682
gameInProgress = false;
683+
endGameScreen = false;
684+
gamemode = "";
685+
playersInfos.clear();
655686
gameWrapper->UnregisterDrawables(); // Erase the table
656687
}
657688

@@ -668,6 +699,8 @@ void BetterChat::handleMsg(bool cancel, std::string playerName) {
668699
if (playersInfos[playerName].numMsg == 1) { // If it is the first message sent by this player
669700
playersInfos[playerName].teamNum = (unsigned char)Params->Team;
670701
}
702+
703+
gameWrapper->UnhookEvent("Function TAGame.GFxData_Chat_TA.OnChatMessage");
671704
});
672705
}
673706

@@ -738,10 +771,6 @@ void BetterChat::chatMessageEvent(ActorWrapper caller, void* params) {
738771
}
739772
handleMsg(cancel, playerName);
740773
}
741-
742-
gameWrapper->HookEventWithCallerPost<ActorWrapper>("Function TAGame.HUDBase_TA.OnChatMessage", [this](ActorWrapper caller, void* params, ...) {
743-
gameWrapper->UnhookEvent("Function TAGame.GFxData_Chat_TA.OnChatMessage");
744-
});
745774
}
746775

747776
#pragma endregion Game_Functions

BetterChat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class BetterChat: public BakkesMod::Plugin::BakkesModPlugin, public BakkesMod::P
248248

249249
void handleMsg(bool cancel, std::string playerName);
250250

251+
void onNewGame();
251252
void setConfig();
252253
void refreshConfig();
253254
void gameBegin();

BetterChatGUI.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,22 @@ void BetterChat::RenderSettings() {
197197
if (pluginParams.chatfilter) {
198198
ImGui::Text("\n");
199199

200-
ImGui::BeginChild("Quickchats", ImVec2(755, 450), true, ImGuiWindowFlags_MenuBar); ;
200+
// Menu Bar
201+
ImGui::BeginChild("Config Table", ImVec2(775, 450), true, ImGuiWindowFlags_MenuBar);
201202
if (ImGui::BeginMenuBar())
202203
{
203204
ImGui::Text("Configuration");
204205
ImGui::EndMenuBar();
205206
}
206207

207-
float headerOffsetX;
208-
float headerOffsetY = ImGui::GetTextLineHeight() * 0.5f + 2;
208+
// Headers child
209+
ImGui::BeginChild("Headers", ImVec2(0, 35), false);
209210

210211
ImGui::Columns(7, nullptr);
211212

213+
float headerOffsetX;
214+
float headerOffsetY = ImGui::GetTextLineHeight() * 0.5f + 2;
215+
212216
ImGui::SetColumnWidth(-1, 150);
213217
headerOffsetX = (ImGui::GetColumnWidth() - ImGui::CalcTextSize("Quickchats").x) * 0.5f;
214218
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + headerOffsetX - 6);
@@ -254,18 +258,29 @@ void BetterChat::RenderSettings() {
254258
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + headerOffsetX - 6);
255259
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + headerOffsetY);
256260
ImGui::Text("After a save");
257-
ImGui::NextColumn();
261+
262+
ImGui::Columns(1, nullptr);
263+
ImGui::EndChild();
264+
258265
ImGui::Separator();
266+
ImGui::Dummy(ImVec2(0, 3));
267+
268+
// Table content
269+
270+
ImGui::BeginChild("TableContent", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
271+
ImGui::Columns(7, nullptr);
259272

260273
for (const auto& chat : idQuickchats) {
261274
for (const string column : categories) {
262275
ImGui::PushID(column.c_str());
263276
if (column == "quickchats") {
277+
ImGui::SetColumnWidth(-1, 150);
264278
float textOffsetX = (ImGui::GetColumnWidth() - ImGui::CalcTextSize(chat.second.c_str()).x) * 0.5f;
265279
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + textOffsetX - 6);
266280
ImGui::Text(chat.second.c_str());
267281
}
268282
else {
283+
ImGui::SetColumnWidth(-1, 100);
269284
const string msg = chat.first;
270285
map<string, bool> map = maps[column];
271286
bool check = map[msg];
@@ -297,8 +312,10 @@ void BetterChat::RenderSettings() {
297312
ImGui::NextColumn();
298313
}
299314
}
300-
ImGui::EndChild();
301315
ImGui::Columns(1, nullptr);
316+
ImGui::EndChild();
317+
318+
ImGui::EndChild();
302319

303320
// Message filter options
304321
ImGui::Text("\nMessage filter options:");
@@ -322,8 +339,10 @@ void BetterChat::RenderSettings() {
322339
if (ImGui::Checkbox("Do not count a pass if an opponent touch it", &pluginParams.unwanted_pass)) {
323340
editParamInJson(config, "unwanted_pass", pluginParams.unwanted_pass);
324341
}
342+
}
325343

326-
// Toxicity Scores
344+
// Toxicity scores
345+
if (pluginParams.antispam || pluginParams.chatfilter) {
327346
ImGui::Text("\n");
328347
if (ImGui::Checkbox("Toxicity scores", &pluginParams.toxicityscores)) {
329348
editParamInJson(config, "toxicityscores", pluginParams.toxicityscores);
@@ -332,6 +351,7 @@ void BetterChat::RenderSettings() {
332351
ImGui::SetTooltip("Enable/Disable Toxicity Scores (at the end of the game)");
333352
}
334353
}
354+
335355
// Delete config button
336356
if (config != "Default config") {
337357
ImGui::Text("\n");

plugins/BetterChat.dll

-34 KB
Binary file not shown.

plugins/BetterChat.exp

0 Bytes
Binary file not shown.

plugins/BetterChat.lib

0 Bytes
Binary file not shown.

plugins/BetterChat.pdb

496 KB
Binary file not shown.

version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22
#define VERSION_MAJOR 3
3-
#define VERSION_MINOR 0
4-
#define VERSION_PATCH 4
5-
#define VERSION_BUILD 432
3+
#define VERSION_MINOR 1
4+
#define VERSION_PATCH 0
5+
#define VERSION_BUILD 530
66

77
#define stringify(a) stringify_(a)
88
#define stringify_(a) #a

0 commit comments

Comments
 (0)