Ensure main menu in MAIN_STATE before multiplayer
Add EnsureMainMenuMainState to try returning the main menu to MAIN_STATE by repeatedly invoking onCancelPress (up to 12 attempts with args true,false). Modify OpenMultiplayerMenu to early-return on null, call the new helper and log a warning if it cannot restore MAIN_STATE before proceeding, and preserve the existing uiMovie handling.
This commit is contained in:
@@ -356,9 +356,45 @@ namespace F4T::MainMenuInject
|
|||||||
TryInjectForStartMenu(a_this);
|
TryInjectForStartMenu(a_this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EnsureMainMenuMainState(RE::MainMenu* a_mainMenu)
|
||||||
|
{
|
||||||
|
if (!a_mainMenu || !a_mainMenu->menuObj.IsObject()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsMainStateForMenu(a_mainMenu)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr auto kMaxCancelAttempts = 12;
|
||||||
|
const std::array<Scaleform::GFx::Value, 2> cancelArgs{
|
||||||
|
Scaleform::GFx::Value{ true },
|
||||||
|
Scaleform::GFx::Value{ false }
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int attempt = 0; attempt < kMaxCancelAttempts; ++attempt) {
|
||||||
|
if (IsMainStateForMenu(a_mainMenu)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
a_mainMenu->menuObj.Invoke("onCancelPress", nullptr, cancelArgs.data(), cancelArgs.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
return IsMainStateForMenu(a_mainMenu);
|
||||||
|
}
|
||||||
|
|
||||||
void OpenMultiplayerMenu(RE::MainMenu* a_mainMenu)
|
void OpenMultiplayerMenu(RE::MainMenu* a_mainMenu)
|
||||||
{
|
{
|
||||||
if (a_mainMenu && a_mainMenu->uiMovie) {
|
if (!a_mainMenu) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!EnsureMainMenuMainState(a_mainMenu)) {
|
||||||
|
LogWarning("Could not return MainMenu to MAIN_STATE before opening multiplayer browser.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a_mainMenu->uiMovie) {
|
||||||
Scaleform::GFx::Value bgsCode;
|
Scaleform::GFx::Value bgsCode;
|
||||||
if (a_mainMenu->menuObj.IsObject() &&
|
if (a_mainMenu->menuObj.IsObject() &&
|
||||||
a_mainMenu->menuObj.GetMember("BGSCodeObj", &bgsCode) &&
|
a_mainMenu->menuObj.GetMember("BGSCodeObj", &bgsCode) &&
|
||||||
|
|||||||
Reference in New Issue
Block a user