Created
May 11, 2017 05:46
-
-
Save ashquarky/6575e8b4e4877cbb9bf8711921e1a66a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void nn::hai::launch::PrepareLaunch(unsigned int* out, void* buffer, unsigned int val) { | |
nn::hai::error::Error errorInstance; //stack | |
nn::hai::error::Init(&errorInstance); | |
if (errorInstance) goto quit; //will skip StopIfRequired call | |
if (!buffer) { | |
//much nn::hai::error::Error handling ensues; "Invalid buffer" | |
goto quit; | |
} | |
int slotno = 0; //register | |
unsigned int nn_act_status; //also on stack | |
nn_act_status = nn::act::Initialize(); | |
if (nn_act_status & /*who knows? clrrwi. RA, RS, 31... 31?*/) { | |
slotno = nn::act::GetSlotNo(); | |
} | |
nn::act::Finalize(); | |
if (!(nn_act_status & /*same again*/)) { | |
//Error handling; "failed to initialize nn::act" | |
goto quit; | |
} | |
unsigned int nn_pdm_status; //register | |
nn_pdm_status = nn::pdm::Initialize(); | |
if (!(nn_pdm_status & /*again*/)) { | |
//Error handling; "failed to initialize nn::pdm" | |
goto quit; | |
} | |
nn::pdm::NotifyEnterHaiModeEvent(); | |
nn::pdm::Finalize(); | |
unsigned int screenState = CMPTCheckScreenState(); //register | |
if (!screenState) { | |
//Error handling | |
if (screenState == -9) { | |
//"HDMI seems not beeing linked to TV\n" [sic] | |
//Unlike the other error handlers, this does *not* set a fatal error | |
goto quit; | |
} else { | |
//"failed to check screen state" | |
goto quit; | |
} | |
} | |
if (!CMPTAcctSetEulaBySlotNo(slotno)) { | |
//Error handling: "failed to set EULA for current account" | |
goto quit; | |
} | |
//This variable is a damn mystery. | |
unsigned int enableDisableFlag = 0; | |
int sysConfigStatus = getSysConfig(&enableDisableFlag); //something to do with the system config, "_SCIReadSysConfig" and "slc:ums.keep_alive" are the important bits | |
if (sysConfigStatus != 1) { | |
//Error handling: "failed to get enable/disable flag of US" | |
goto quit; | |
} | |
unsigned int apd_param = 0; //stack, this C++ compiler is high or something | |
if (IM_GetNVParameterWithoutHandleAndItb(3, &apd_param)) { | |
//Error handling: "failed to get APD params" | |
goto quit; | |
} | |
unsigned int apd_param2 = 0; | |
if (!param) { | |
if (IM_GetNVParameterWithoutHandleAndItb(4, &apd_param2)) { | |
//Error handling; as above | |
goto quit; | |
} | |
} | |
//There's a mystery write here invoving apd_param2 and enableDisableFlag's evil +1 cousin | |
if (CMPTExSetWorkBuffer(buffer, val)) { | |
//Error handling: "failed to set work buffer for prepare l" [sic] | |
goto quit; | |
} | |
if (CMPTExPrepareLaunch(3, &enableDisableFlag, 5)) { | |
//Error handling: "failed to prepare compat mode launch" | |
//not fatal if return code was -0xA | |
goto quit; | |
} | |
quit: | |
nn::hai::error::StopIfRequired(&errorInstance); | |
unsigned int* mystery_stack_ptr; //completely random place on stack, see for yourself | |
for (int i = 5; i != 0; i--) { //praise bdnz | |
*out = *mystery_stack_ptr; | |
out += 4; //add 4 bytes, not 4 ints | |
mystery_stack_ptr += 4; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment