Skip to content

Commit

Permalink
fix(glue): only run LinkProtocolIPC in the game process
Browse files Browse the repository at this point in the history
  • Loading branch information
nihonium-cfx committed Nov 1, 2024
1 parent 37b6ac9 commit 2bb38d5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions code/components/glue/src/ConnectToNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

#include <MinMode.h>

#include "CfxState.h"
#include "GameInit.h"
#include "CnlEndpoint.h"
#include "PacketHandler.h"
Expand Down Expand Up @@ -1579,18 +1580,28 @@ void Component_RunPreInit()
}
}

static InitFunction connectInitFunction([]()
{
#if __has_include(<gameSkeleton.h>)
static InitFunction buildSaverInitFunction([]() {
rage::OnInitFunctionStart.Connect([](rage::InitFunctionType type)
{
if (type == rage::INIT_BEFORE_MAP_LOADED)
{
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);
Expand All @@ -1606,8 +1617,6 @@ static InitFunction connectInitFunction([]()
SetForegroundWindow(CoreGetGameWindow());
});

cfx::glue::LinkProtocolIPC::Initialize();

GetEarlyGameFrame().Connect([]()
{
if (Instance<ICoreGameInit>::Get()->GetGameLoaded())
Expand Down

0 comments on commit 2bb38d5

Please sign in to comment.