Skip to content

Commit

Permalink
Merge Only run LinkProtocolIPC in the game process (mr-584)
Browse files Browse the repository at this point in the history
2bb38d5 - fix(glue): only run LinkProtocolIPC in the game process
  • Loading branch information
prikolium-cfx committed Nov 1, 2024
2 parents 7ab2d51 + 2bb38d5 commit 94e3b9d
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 94e3b9d

Please sign in to comment.