Mod SDK: Arc Overlays (#2280)

* Mod SDK: Arc Overlays

* Use DVD Functions for Arc overlays

* Re-add Fetchcontent for json.hpp

* Fix build for actions

* Make sure buffer usues aligned length

* Add include so msvc compiles

* Arc Overlays fixes: remove _arc suffix, handle getting overlayed file size from arcs, copy data correctly, etc.

* Reload overlayed data during loading screens

* Rename sync function

* Free overlayed files on load instead of re-loading them

* Rework arc overlays & load overlay files into host memory

---------

Co-authored-by: Luke Street <luke@street.dev>
This commit is contained in:
jdflyer
2026-08-19 23:47:57 -07:00
committed by GitHub
parent 386d2f964b
commit 5a4e6f3254
13 changed files with 474 additions and 29 deletions
+5
View File
@@ -311,6 +311,11 @@ u32 dLib_getExpandSizeFromAramArchive(JKRAramArchive* i_aramArchive, char const*
JUT_ASSERT(1260, readAddress == header);
JKRArchive::SDIFileEntry* entry = i_aramArchive->findFsResource(param_2, 0);
JUT_ASSERT(1263, entry != NULL);
#if TARGET_PC
if (u32 size; i_aramArchive->getOverlayFileSize(entry, &size)) {
return ALIGN_NEXT(size, 32);
}
#endif
u32 uVar1 = ALIGN_NEXT(JKRDecompExpandSize(header), 32);
u32 uVar5 = ALIGN_NEXT(entry->data_size, 32);
return uVar1 > uVar5 ? uVar1 : uVar5;
+2 -2
View File
@@ -335,7 +335,7 @@ int dRes_info_c::loadResource() {
#endif
void* res = mArchive->getIdxResource(fileIndex);
#if TARGET_PC
u32 size = mArchive->findIdxResource(fileIndex)->data_size;
u32 size = mArchive->getFileSize(mArchive->findIdxResource(fileIndex));
std::string fileName = mArchive->mStringTable +
(mArchive->findIdxResource(fileIndex)->type_flags_and_name_offset & 0xFFFFFF);
DuskLog.debug("Loading Resource: {} (Size: {})", fileName, size);
@@ -369,7 +369,7 @@ int dRes_info_c::loadResource() {
parentHeap = NULL;
}
int rt = dComIfG_setObjectRes(arcName, res, entry->data_size, parentHeap);
int rt = dComIfG_setObjectRes(arcName, res, DUSK_IF_ELSE(mArchive->getFileSize(entry),entry->data_size), parentHeap);
JUT_ASSERT(788, rt);
} else if (nodeType == 'BMDP') {
#if DEBUG
+16 -14
View File
@@ -1,8 +1,9 @@
#include "registry.hpp"
#include "slot_map.hpp"
#include "aurora/dvd.h"
#include <borealis/log.hpp>
#include "JSystem/JKernel/JKRArchive.h"
#include "aurora/dvd.h"
#include "dusk/mods/loader/loader.hpp"
#include "mods/svc/overlay.h"
@@ -24,7 +25,7 @@ constexpr borealis::Log Log{"dusk::mods::overlay"};
struct OverlayFileData {
std::string bundlePath;
std::shared_ptr<ModBundle> bundle;
std::shared_ptr<const std::vector<u8> > buffer;
std::shared_ptr<const std::vector<u8>> buffer;
};
// Keyed by the id passed to Aurora as per-file userdata. Guarded by s_overlayMutex: Aurora may
@@ -98,6 +99,7 @@ void append_runtime_overlays(std::vector<AuroraOverlayFile>& files, LoadedMod& m
for (const auto* slot : slots) {
const auto id = s_nextOverlayId++;
if (slot->buffer != nullptr) {
s_overlayFiles.emplace(id, OverlayFileData{{}, nullptr, slot->buffer});
} else {
@@ -110,7 +112,7 @@ void append_runtime_overlays(std::vector<AuroraOverlayFile>& files, LoadedMod& m
struct OpenOverlayFile {
std::vector<u8> ownedData;
std::shared_ptr<const std::vector<u8> > shared;
std::shared_ptr<const std::vector<u8>> shared;
size_t pos = 0;
[[nodiscard]] const std::vector<u8>& data() const {
@@ -200,6 +202,7 @@ void overlay_sync_files() {
Log.debug("Registering {} overlay file(s).", files.size());
aurora_dvd_overlay_files(files.data(), files.size(), nullptr);
JKRArchive::notifyOverlayFilesChanged();
for (const auto& file : files) {
std::free(const_cast<char*>(file.fileName));
@@ -220,13 +223,13 @@ uint64_t overlay_add_file(
uint64_t overlay_add_buffer(LoadedMod& mod, std::string discPath, std::vector<u8> data) {
const auto size = data.size();
const auto handle = s_runtimeOverlays.emplace(mod,
RuntimeOverlaySlot{
.discPath = std::move(discPath),
.buffer = std::make_shared<const std::vector<u8>>(std::move(data)),
.size = size,
.order = s_nextRuntimeOrder++,
});
const auto handle = s_runtimeOverlays.emplace(
mod, RuntimeOverlaySlot{
.discPath = std::move(discPath),
.buffer = std::make_shared<const std::vector<u8>>(std::move(data)),
.size = size,
.order = s_nextRuntimeOrder++,
});
s_overlaysDirty = true;
return handle;
}
@@ -275,13 +278,12 @@ ModResult overlay_add_file(
try {
size = mod->bundle->getFileSize(bundlePath);
} catch (const std::exception& e) {
Log.error(
"[{}] overlay add_file '{}' failed: {}", mod->metadata.id, bundlePath, e.what());
Log.error("[{}] overlay add_file '{}' failed: {}", mod->metadata.id, bundlePath, e.what());
return MOD_UNAVAILABLE;
}
if (size > kMaxOverlayFileSize) {
Log.error("[{}] overlay add_file '{}' failed: file too large ({} bytes)",
mod->metadata.id, bundlePath, size);
Log.error("[{}] overlay add_file '{}' failed: file too large ({} bytes)", mod->metadata.id,
bundlePath, size);
return MOD_INVALID_ARGUMENT;
}