BunnyFl's firmware 13.42 check shows that the distortion, wide-near and
2D VR command queries give NOT_INITIALIZED for handle 0 before
sceHmdInitialize only when the title's compiled SDK version is below
4.50. From 4.50 the library first checks state it sets up when it
starts, which isn't measured, so handle 0 before initialization now
throws there, as it does after initialization and as all six queries
do on main. The SDK version is read from the process parameters, as
libSceHmd2 does.
guest_hmd checks handle 0 before initialization at SDK 0x044fffff and
0x04500000.
Source: https://github.com/boykopovar/AnyPS5/pull/9577#issuecomment-6343495321 (BunnyFl)
BunnyFl ran firmware 13.42's libSceHmd exports under an emulator. The
distortion and wide-near correction queries look the handle up before
checking initialization: a handle other than the one sceHmdOpen stored,
which stays 0 without a headset, returns HANDLE_INVALID even before
sceHmdInitialize. sceHmdGet2dVrCommand checks its arguments first:
PARAMETER_NULL for a null descriptor or command buffer or a null
pointer at descriptor offset 0, 8 or 0x20, and PARAMETER_INVALID for a
non-zero field at 0x34 or 0x38.
The queries and their sceHmdDistortion* aliases now answer in that
order. What handle 0 gets after initialization isn't measured, so it
throws NotImplemented_nid_no_patch instead of returning HANDLE_INVALID.
Nothing runs in VR2D without a headset, so sceHmdInternalIsGameVr2d,
IsMiniAppVr2d, IsCommonDlgVr2d and IsCommonDlgMiniAppVr2d return false,
the answer the console gives to the same four queries in libSceHmd2.
sceHmdOpen never issues a handle without a headset, so the distortion
correction, wide-near correction and 2D VR command queries, and their
sceHmdDistortion* export aliases, answer as the other handle queries:
NOT_INITIALIZED before sceHmdInitialize and HANDLE_INVALID after it,
leaving the command buffer unwritten.
No handle is ever open, as sceHmdOpen reports the headset disconnected, so they return HANDLE_INVALID after initialization and NOT_INITIALIZED before it, without writing their outputs.