Skip to content

Commit

Permalink
Fix ChatMessageEntered delegate receiving null player controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Nov 12, 2023
1 parent c5ac578 commit 03225ab
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Mods/SML/Source/SML/Private/Player/SMLRemoteCallObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#include "Command/ChatCommandLibrary.h"
#include "FGChatManager.h"
#include "FGPlayerController.h"
#include "Patching/NativeHookManager.h"
#include "SatisfactoryModLoader.h"
#include "Net/UnrealNetwork.h"
#include "Registry/RemoteCallObjectRegistry.h"

USMLRemoteCallObject::USMLRemoteCallObject() {
CommandSender = CreateDefaultSubobject<UPlayerCommandSender>(TEXT("PlayerCommandSender"));
Expand Down Expand Up @@ -47,16 +46,16 @@ void USMLRemoteCallObject::RegisterChatCommandPatch() {

AFGPlayerController::PlayerControllerBegunPlay.AddLambda( []( AFGPlayerController* PlayerController )
{
PlayerController->ChatMessageEntered.AddLambda( [&]( const FChatMessageStruct& ChatMessage, bool& bCancelChatMessage )
PlayerController->ChatMessageEntered.AddLambda( [=]( const FChatMessageStruct& ChatMessage, bool& bCancelChatMessage )
{
if (ChatMessage.MessageString.StartsWith(TEXT("/")))
{
const FString CommandLine = ChatMessage.MessageString.TrimStartAndEnd().RightChop(1);
if ( USMLRemoteCallObject* RemoteCallObject = PlayerController->GetRemoteCallObjectOfClass<USMLRemoteCallObject>() )
{
RemoteCallObject->HandleChatCommand(CommandLine);
bCancelChatMessage = true;
}
const FString CommandLine = ChatMessage.MessageString.TrimStartAndEnd().RightChop(1);
if ( USMLRemoteCallObject* RemoteCallObject = PlayerController->GetRemoteCallObjectOfClass<USMLRemoteCallObject>() )
{
RemoteCallObject->HandleChatCommand(CommandLine);
bCancelChatMessage = true;
}
}
} );
} );
Expand Down

0 comments on commit 03225ab

Please sign in to comment.