Skip to content

Commit

Permalink
tweak(ros): more launch order race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
blattersturm committed Jan 25, 2022
1 parent 59a379e commit 57eeb38
Showing 1 changed file with 25 additions and 52 deletions.
77 changes: 25 additions & 52 deletions code/components/ros-patches-five/src/ros/SubprocessTool.cpp
Expand Up @@ -185,11 +185,8 @@ struct MyListener : public IPC::Listener, public IPC::MessageReplyDeserializer
#endif
;

static bool verified;
static bool launched;
static bool installing;
static bool verifying;
static bool launchedVerify;
static bool launching;
static bool signInComplete;
static bool signInComplete2;
Expand All @@ -213,60 +210,41 @@ struct MyListener : public IPC::Listener, public IPC::MessageReplyDeserializer
}
};

auto checkVerify = [this, targetTitle]()
auto checkLaunch = [this, targetTitle]()
{
if (updateState != "notUpdating")
{
return;
}

if (signInComplete2 && !verified && !launchedVerify && verifying)
{
Sleep(500);

if (updateState != "notUpdating")
{
return;
}

child->SendJSCallback("RGSC_RAISE_UI_EVENT", json::object({ { "EventId", 2 }, // LauncherV3UiEvent

{ "Data", json::object({ { "Action", "Verify" },
{ "Parameter", json::object({
{ "titleName", targetTitle },
}) } }) } })
.dump());

launchedVerify = true;
}
};

auto checkLaunch = [this, targetTitle]()
{
if (signInComplete2 && !launched && launching && verified)
if (signInComplete2 && !launched && launching)
{
launched = true;

for (int i = 0; i < 3; i++)
std::thread([this, targetTitle]()
{
if (launchDone || g_launchDone)
for (int i = 0; i < 3; i++)
{
break;
}
if (launchDone || g_launchDone)
{
break;
}

child->SendJSCallback("RGSC_SET_CLOUD_SAVE_ENABLED", json::object({ { "Enabled", false },
{ "RosTitleName", targetTitle } })
.dump());
child->SendJSCallback("RGSC_SET_CLOUD_SAVE_ENABLED", json::object({ { "Enabled", false },
{ "RosTitleName", targetTitle } })
.dump());

child->SendJSCallback("RGSC_RAISE_UI_EVENT", json::object({ { "EventId", 2 }, // LauncherV3UiEvent
child->SendJSCallback("RGSC_RAISE_UI_EVENT", json::object({ { "EventId", 2 }, // LauncherV3UiEvent

{ "Data", json::object({ { "Action", "Launch" },
{ "Parameter", json::object({ { "titleName", targetTitle },
{ "args", "" } }) } }) } })
.dump());
{ "Data", json::object({ { "Action", "Launch" },
{ "Parameter", json::object({ { "titleName", targetTitle },
{ "args", "" } }) } }) } })
.dump());

Sleep(10000);
}
Sleep(10000);
}
})
.detach();
}
};

Expand Down Expand Up @@ -314,17 +292,19 @@ struct MyListener : public IPC::Listener, public IPC::MessageReplyDeserializer
.dump());

signInComplete = true;
signInComplete2 = true;
checkInstall();
checkVerify();
}
else if (c == "TitlePlayTime")
{
signInComplete2 = true;
checkLaunch();
}
else if (c == "SetTitleInfo") {
if (p.value("titleName", "") == targetTitle) {
updateState = p["status"].value("updateState", "");

if (p["status"].value("entitlement", false) && !p["status"].value("install", false) &&
p["status"].value("releaseState", "preload") == "available" && !verified) {
p["status"].value("releaseState", "preload") == "available") {
installing = true;
checkInstall();
}
Expand All @@ -334,15 +314,8 @@ struct MyListener : public IPC::Listener, public IPC::MessageReplyDeserializer
p["status"].value("updateState", "") == "verifyQueued"))
{
launching = true;
verifying = true;
checkVerify();
checkLaunch();
}

if (p["status"].value("updateState", "") == "verifying")
{
verified = true;
}
}
}
}
Expand Down

0 comments on commit 57eeb38

Please sign in to comment.