MCPcopy Create free account
hub / github.com/FlagBrew/PKSM / applyScript

Method applyScript

3ds/source/gui/screen/ScriptScreen.cpp:330–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328}
329
330void ScriptScreen::applyScript()
331{
332 std::string scriptFile = currDirString + '/' + currFiles[hid.fullIndex()].first;
333 if (scriptFile.rfind(".c") == scriptFile.size() - 2)
334 {
335 parsePicoCScript(scriptFile);
336 return;
337 }
338 auto scriptData = scriptRead(scriptFile);
339
340 if (scriptData.empty())
341 {
342 return;
343 }
344
345 for (size_t i = 0; i < std::min(MAGIC.size(), scriptData.size()); i++)
346 {
347 if (scriptData[i] != MAGIC[i])
348 {
349 Gui::warn(i18n::localize("SCRIPTS_INVALID"));
350 return;
351 }
352 }
353
354 size_t index = MAGIC.size();
355 while (index < scriptData.size())
356 {
357 u32 offset = LittleEndian::convertTo<u32>(scriptData.data() + index);
358 u32 length = LittleEndian::convertTo<u32>(scriptData.data() + index + 4);
359 u32 repeat = LittleEndian::convertTo<u32>(scriptData.data() + index + 8 + length);
360
361 if (TitleLoader::save->generation() == pksm::Generation::FOUR)
362 {
363 u32 sbo = ((pksm::Sav4*)TitleLoader::save.get())->getSBO();
364 u32 gbo = ((pksm::Sav4*)TitleLoader::save.get())->getGBO();
365 if (TitleLoader::save->boxOffset(0, 0) - sbo <= offset &&
366 TitleLoader::save->boxOffset(TitleLoader::save->maxBoxes(), 0) - sbo >= offset)
367 {
368 offset += sbo;
369 }
370 else
371 {
372 offset += gbo;
373 }
374 }
375
376 for (size_t i = 0; i < repeat; i++)
377 {
378 std::copy(scriptData.data() + index + 8, scriptData.data() + index + 8 + length,
379 &TitleLoader::save->rawData()[offset + i * length]);
380 }
381
382 index += 12 + length;
383 }
384}
385
386void ScriptScreen::parsePicoCScript(std::string& file)
387{

Callers

nothing calls this directly

Calls 6

scriptReadFunction · 0.85
fullIndexMethod · 0.80
generationMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected