Reading state of simulation using SimConnect_RequestSystemState

Hi all, I am trying to read the simulation state using
SimConnect_RequestSystemState. The intention is to know when the user is
actually flying the aircraft or navigating the UI. Code is as follows:

MSFS_CALLBACK bool GaugeCallback(FsContext ctx, int service_id, void* pData)
{
    switch (service_id)
    {
        case PANEL_SERVICE_PRE_UPDATE:
        {
            SimConnect_RequestSystemState(hSimConnect, REQ_SYSTEM_STATE, "Sim");
        }
        break;
            
        default:
            break;
    }
}

... 

void CALLBACK SimconnectDispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext)
{
    switch (pData->dwID)
    {
        case SIMCONNECT_RECV_ID_SYSTEM_STATE:
        {
            const auto pState = static_cast(pData);

            if (pState->dwRequestID != SIMCONNECT_RECV_ID_NULL)
            {
                switch (pState->dwRequestID)
                {
                case REQ_SYSTEM_STATE:
                {
                    const bool value = pState->dwInteger != 0 ? true : false;
                    int a = 0;
                    if (value)
                        a = 10;
                    else
                        a = 20;
                }
                break;

                default:
                    break;
                }
            }
        }
        
        default:
            break;
    }
}        

int a stuff was just added to check if value was set/cleared appropriately.
There’s also more code on these functions - I have removed unrelated calls
from the code snippets above. No matter what I do the value boolean is never
cleared. It remais true whatever I do. What am I doing wrong? Any insights
will be much appreciated. Thanks!

I’m not certain about this one in particular, but I’d avoid polling the state
in pre-update because it is supposed to be supported via the alternative
SimStart/Stop: Sim | Requests the state of the simulation. If 1 is returned,
the user is in control of the aircraft, if 0 is returned, the user is
navigating the UI. This is the same state that notifications can be subscribed
to with the “SimStart” and “SimStop” string with the
SimConnect_SubscribeToSystemEvent
function.
—|—
But following the link and the docs, this doesn’t seem to be much helping
differentiating whether you’re un UI or in game?! SimStart | The simulator
is running. Typically the user is actively controlling the aircraft on the
ground or in the air. However, in some cases additional pairs of
SimStart/SimStop events are sent. For example, when a flight is reset the
events that are sent are SimStop, SimStart, SimStop, SimStart. Also when a
flight is started with the SHOW_OPENING_SCREEN value set to zero, then an
additional SimStart/SimStop pair are sent before a second SimStart event is
sent when the scenery is fully loaded. The opening screen provides the options
to change aircraft, departure airport, and so on.
—|—
SimStop | The simulator is not running. Typically the user is loading a
flight, navigating the shell or in a dialog.

Unfortunately the new MSFS menus do not send the usual state changes through
SimConnect. It has been reported some time ago.

You can use the simvar PLANE IN PARKING STATE to determine if in the menus. This seems to be 1 or True when in the main menu system, and 0 or False otherwise. At least this was the case pre-SU12 - I haven’t checked this since SU12 but presume still valid… You can also use the simvar CAMERA STATE, which will hold a value of 15 when in the main menu, 12 in World Map. etc (see
the documentation for a complete list of values). .

Hi John-

using “CAMERA STATE” works fine with In-Game RTC enabled, but with that disabled, it returns 2 (i.e. COCKPIT) during the READY TO FLY screen, throwing our logic off entirely.

@FlyingRaccoon had noted he’d file a bug for it, but there’s no news since.

Any updates on this @EPellissier or @Arzop ?

Thanks!

You are a life saver :slight_smile: was going crazy trying to figure out how to determine when the sim is in World Map.

Also, there is an easy way to determine if you are in the menus. The Sim loads an .FLT called MAINMENU.FLT when it enters the menus, so by subscribing to the FlightLoaded SystemEvent you can easily keep track of it