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

Function LoadSharedData

src/Cafe/CafeSystem.cpp:289–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287static_assert(sizeof(SharedDataEntry) == 0x1C);
288
289uint32 LoadSharedData()
290{
291 // check if font files are dumped
292 bool hasAllShareddataFiles = true;
293 for (sint32 i = 0; i < sizeof(shareddataDef) / sizeof(shareddataDef[0]); i++)
294 {
295 bool existsInMLC = fs::exists(ActiveSettings::GetMlcPath(shareddataDef[i].mlcPath));
296 bool existsInResources = fs::exists(ActiveSettings::GetDataPath(shareddataDef[i].resourcePath));
297
298 if (!existsInMLC && !existsInResources)
299 {
300 cemuLog_log(LogType::Force, "Shared font {} is not present", shareddataDef[i].fileName);
301 hasAllShareddataFiles = false;
302 break;
303 }
304 }
305 sint32 numEntries = sizeof(shareddataDef) / sizeof(shareddataDef[0]);
306 if (hasAllShareddataFiles)
307 {
308 // all shareddata font files are present -> load them
309 SharedDataEntry* shareddataTable = (SharedDataEntry*)memory_getPointerFromVirtualOffset(0xF8000000);
310 memset(shareddataTable, 0, sizeof(SharedDataEntry) * numEntries);
311 uint8* dataWritePtr = memory_getPointerFromVirtualOffset(0xF8000000 + sizeof(SharedDataEntry) * numEntries);
312 // setup entries
313 for (sint32 i = 0; i < numEntries; i++)
314 {
315 // try to read font from MLC first
316 auto path = ActiveSettings::GetMlcPath(shareddataDef[i].mlcPath);
317 FileStream* fontFile = FileStream::openFile2(path);
318 // alternatively fall back to our shared fonts
319 if (!fontFile)
320 {
321 path = ActiveSettings::GetDataPath(shareddataDef[i].resourcePath);
322 fontFile = FileStream::openFile2(path);
323 }
324 if (!fontFile)
325 {
326 cemuLog_log(LogType::Force, "Failed to load shared font {}", shareddataDef[i].fileName);
327 continue;
328 }
329 uint32 fileSize = fontFile->GetSize();
330 fontFile->readData(dataWritePtr, fileSize);
331 delete fontFile;
332 // setup entry
333 shareddataTable[i].name = shareddataDef[i].name;
334 shareddataTable[i].fileType = shareddataDef[i].fileType;
335 shareddataTable[i].kernelFilenamePtr = 0x00000000;
336 shareddataTable[i].data = dataWritePtr;
337 shareddataTable[i].size = fileSize;
338 shareddataTable[i].ukn14 = 0x00000000;
339 shareddataTable[i].ukn18 = 0x00000000;
340 // advance write offset and pad to 16 byte alignment
341 dataWritePtr += ((fileSize + 15) & ~15);
342 }
343 cemuLog_log(LogType::Force, "COS: System fonts found. Generated shareddata ({}KB)", (uint32)(dataWritePtr - (uint8*)shareddataTable) / 1024);
344 return memory_getVirtualOffsetFromPointer(dataWritePtr);
345 }
346 // alternative method: load RAM dump

Callers 1

SetupMemorySpaceFunction · 0.85

Calls 6

getBaseMethod · 0.80
cemuLog_logFunction · 0.50
GetSizeMethod · 0.45
readDataMethod · 0.45

Tested by

no test coverage detected