From 2bb38d56e546597d0b36b7cdda1c2d5eca2cffd4 Mon Sep 17 00:00:00 2001 From: nihonium Date: Fri, 1 Nov 2024 09:28:16 +0100 Subject: [PATCH] fix(glue): only run LinkProtocolIPC in the game process --- code/components/glue/src/ConnectToNative.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/code/components/glue/src/ConnectToNative.cpp b/code/components/glue/src/ConnectToNative.cpp index 0f5cf31f1e..0c56a3baec 100644 --- a/code/components/glue/src/ConnectToNative.cpp +++ b/code/components/glue/src/ConnectToNative.cpp @@ -52,6 +52,7 @@ #include +#include "CfxState.h" #include "GameInit.h" #include "CnlEndpoint.h" #include "PacketHandler.h" @@ -1579,9 +1580,8 @@ void Component_RunPreInit() } } -static InitFunction connectInitFunction([]() -{ #if __has_include() +static InitFunction buildSaverInitFunction([]() { rage::OnInitFunctionStart.Connect([](rage::InitFunctionType type) { if (type == rage::INIT_BEFORE_MAP_LOADED) @@ -1589,8 +1589,19 @@ static InitFunction connectInitFunction([]() SaveBuildNumber(xbr::GetRequestedGameBuild()); } }); +}); #endif +static InitFunction linkProtocolIPCInitFunction([]() +{ + // Only run LinkProtocolIPC in the game process + if (!CfxState::Get()->IsGameProcess()) + { + return; + } + + cfx::glue::LinkProtocolIPC::Initialize(); + cfx::glue::LinkProtocolIPC::OnConnectTo.Connect([](const std::string_view& connectMsg) { auto connectData = nlohmann::json::parse(connectMsg); @@ -1606,8 +1617,6 @@ static InitFunction connectInitFunction([]() SetForegroundWindow(CoreGetGameWindow()); }); - cfx::glue::LinkProtocolIPC::Initialize(); - GetEarlyGameFrame().Connect([]() { if (Instance::Get()->GetGameLoaded())