MCPcopy Create free account
hub / github.com/cemu-project/Cemu / LoadMainExecutable

Function LoadMainExecutable

src/Cafe/CafeSystem.cpp:134–197  ·  view source on GitHub ↗

load executable into virtual memory and set entrypoint

Source from the content-addressed store, hash-verified

132
133// load executable into virtual memory and set entrypoint
134void 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

Callers 1

SetupExecutableFunction · 0.85

Calls 15

ScanForRPXFunction · 0.85
cemuLog_waitForFlushFunction · 0.85
cemu_assertFunction · 0.85
fsc_extractFileFunction · 0.85
SetEntryPointFunction · 0.85
ELF_LoadFromMemoryFunction · 0.85
RPLLoader_AddDependencyFunction · 0.85
RPLLoader_LoadFromMemoryFunction · 0.85
cemuLog_createLogFileFunction · 0.85
RPLLoader_SetMainModuleFunction · 0.85

Tested by

no test coverage detected