load executable into virtual memory and set entrypoint
| 132 | |
| 133 | // load executable into virtual memory and set entrypoint |
| 134 | void LoadMainExecutable() |
| 135 | { |
| 136 | isLaunchTypeELF = false; |
| 137 | // when launching from a disc image _pathToExecutable is initially empty |
| 138 | if (_pathToExecutable.empty()) |
| 139 | { |
| 140 | // try to get the RPX path from the meta files |
| 141 | // todo |
| 142 | // otherwise search for first file with .rpx extension in the code folder |
| 143 | if (!ScanForRPX()) |
| 144 | { |
| 145 | cemuLog_log(LogType::Force, "Unable to find RPX executable"); |
| 146 | cemuLog_waitForFlush(); |
| 147 | cemu_assert(false); |
| 148 | } |
| 149 | } |
| 150 | // extract and load RPX |
| 151 | uint32 rpxSize = 0; |
| 152 | uint8* rpxData = fsc_extractFile(_pathToExecutable.c_str(), &rpxSize); |
| 153 | if (rpxData == nullptr) |
| 154 | { |
| 155 | cemuLog_log(LogType::Force, "Failed to load \"{}\"", _pathToExecutable); |
| 156 | cemuLog_waitForFlush(); |
| 157 | cemu_assert(false); |
| 158 | } |
| 159 | currentUpdatedApplicationHash = generateHashFromRawRPXData(rpxData, rpxSize); |
| 160 | // determine if this file is an ELF |
| 161 | const uint8 elfHeaderMagic[9] = { 0x7F,0x45,0x4C,0x46,0x01,0x02,0x01,0x00,0x00 }; |
| 162 | if (rpxSize >= 10 && memcmp(rpxData, elfHeaderMagic, sizeof(elfHeaderMagic)) == 0) |
| 163 | { |
| 164 | // ELF |
| 165 | SetEntryPoint(ELF_LoadFromMemory(rpxData, rpxSize, _pathToExecutable.c_str())); |
| 166 | isLaunchTypeELF = true; |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | // RPX |
| 171 | RPLLoader_AddDependency(_pathToExecutable.c_str()); |
| 172 | applicationRPX = RPLLoader_LoadFromMemory(rpxData, rpxSize, (char*)_pathToExecutable.c_str()); |
| 173 | if (!applicationRPX) |
| 174 | { |
| 175 | wxMessageBox(_("Failed to run this title because the executable is damaged")); |
| 176 | cemuLog_createLogFile(false); |
| 177 | cemuLog_waitForFlush(); |
| 178 | exit(0); |
| 179 | } |
| 180 | RPLLoader_SetMainModule(applicationRPX); |
| 181 | SetEntryPoint(RPLLoader_GetModuleEntrypoint(applicationRPX)); |
| 182 | } |
| 183 | free(rpxData); |
| 184 | // get RPX hash of game without update |
| 185 | uint32 baseRpxSize = 0; |
| 186 | uint8* baseRpxData = fsc_extractFile(!_pathToBaseExecutable.empty() ? _pathToBaseExecutable.c_str() : _pathToExecutable.c_str(), &baseRpxSize, FSC_PRIORITY_BASE); |
| 187 | if (baseRpxData == nullptr) |
| 188 | { |
| 189 | currentBaseApplicationHash = currentUpdatedApplicationHash; |
| 190 | } |
| 191 | else |
no test coverage detected