@@ -37,6 +37,7 @@ unsigned char numTeam;
3737int blueScore;
3838int orangeScore;
3939bool gameInProgress;
40+ bool endGameScreen;
4041bool waitingForKickoff;
4142bool goal;
4243bool 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
8595void 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
467494void 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
521548void 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
547574void 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
556583void 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
564591void 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
589617void 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) {
652680void 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
0 commit comments