Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support LUS archivemanager refactor #3912

Merged
merged 23 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libultraship
Submodule libultraship updated 39 files
+2 −3 extern/CMakeLists.txt
+4 −1 include/libultraship/classes.h
+20 −11 src/CMakeLists.txt
+12 −2 src/Context.cpp
+0 −3 src/audio/Audio.cpp
+1 −1 src/audio/Audio.h
+29 −107 src/graphic/Fast3D/gfx_dxgi.cpp
+5 −4 src/graphic/Fast3D/gfx_opengl.cpp
+30 −0 src/graphic/Fast3D/gfx_sdl2.cpp
+4 −3 src/public/bridge/resourcebridge.cpp
+0 −1 src/public/bridge/resourcebridge.h
+0 −547 src/resource/Archive.cpp
+0 −67 src/resource/Archive.h
+18 −2 src/resource/File.h
+1 −1 src/resource/GameVersions.h
+0 −1 src/resource/Resource.cpp
+1 −12 src/resource/Resource.h
+1 −0 src/resource/ResourceFactory.h
+42 −81 src/resource/ResourceLoader.cpp
+3 −5 src/resource/ResourceLoader.h
+16 −42 src/resource/ResourceManager.cpp
+9 −10 src/resource/ResourceManager.h
+29 −0 src/resource/ResourceType.h
+242 −0 src/resource/archive/Archive.cpp
+63 −0 src/resource/archive/Archive.h
+225 −0 src/resource/archive/ArchiveManager.cpp
+50 −0 src/resource/archive/ArchiveManager.h
+38 −0 src/resource/archive/O2rArchive.cpp
+32 −0 src/resource/archive/O2rArchive.h
+105 −0 src/resource/archive/OtrArchive.cpp
+39 −0 src/resource/archive/OtrArchive.h
+6 −12 src/resource/factory/TextureFactory.cpp
+19 −13 src/utils/binarytools/MemoryStream.cpp
+2 −1 src/utils/binarytools/MemoryStream.h
+5 −6 src/window/gui/GameOverlay.cpp
+5 −7 src/window/gui/Gui.cpp
+1 −3 src/window/gui/Gui.h
+0 −102 src/window/gui/InputViewer.cpp
+0 −12 src/window/gui/InputViewer.h
4 changes: 2 additions & 2 deletions soh/soh/Enhancements/debugger/dlViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ std::map<int, std::string> cmdMap = {
};

void PerformDisplayListSearch() {
auto result = LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->ListFiles("*" + std::string(searchString) + "*DL*");
auto result = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->ListFiles("*" + std::string(searchString) + "*DL*");

std::regex dlSearch(".*((DL)|(DL_.*))$");

Expand Down Expand Up @@ -134,7 +134,7 @@ void DLViewerWindow::DrawElement() {
try {
auto res = std::static_pointer_cast<LUS::DisplayList>(LUS::Context::GetInstance()->GetResourceManager()->LoadResource(activeDisplayList));

if (res->GetInitData()->Type != LUS::ResourceType::DisplayList) {
if (res->GetInitData()->Type != static_cast<uint32_t>(LUS::ResourceType::DisplayList)) {
ImGui::Text("Resource type is not a Display List. Please choose another.");
ImGui::End();
return;
Expand Down
16 changes: 8 additions & 8 deletions soh/soh/Enhancements/tts/tts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,24 +1037,24 @@ void InitTTSBank() {
break;
}

auto sceneFile = LUS::Context::GetInstance()->GetResourceManager()->LoadFile("accessibility/texts/scenes" + languageSuffix);
auto sceneFile = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFileRaw("accessibility/texts/scenes" + languageSuffix);
if (sceneFile != nullptr) {
sceneMap = nlohmann::json::parse(sceneFile->Buffer, nullptr, true, true);
sceneMap = nlohmann::json::parse(*sceneFile->Buffer.get(), nullptr, true, true);
}

auto miscFile = LUS::Context::GetInstance()->GetResourceManager()->LoadFile("accessibility/texts/misc" + languageSuffix);
auto miscFile = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFileRaw("accessibility/texts/misc" + languageSuffix);
if (miscFile != nullptr) {
miscMap = nlohmann::json::parse(miscFile->Buffer, nullptr, true, true);
miscMap = nlohmann::json::parse(*miscFile->Buffer.get(), nullptr, true, true);
}

auto kaleidoFile = LUS::Context::GetInstance()->GetResourceManager()->LoadFile("accessibility/texts/kaleidoscope" + languageSuffix);
auto kaleidoFile = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFileRaw("accessibility/texts/kaleidoscope" + languageSuffix);
if (kaleidoFile != nullptr) {
kaleidoMap = nlohmann::json::parse(kaleidoFile->Buffer, nullptr, true, true);
kaleidoMap = nlohmann::json::parse(*kaleidoFile->Buffer.get(), nullptr, true, true);
}

auto fileChooseFile = LUS::Context::GetInstance()->GetResourceManager()->LoadFile("accessibility/texts/filechoose" + languageSuffix);
auto fileChooseFile = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFileRaw("accessibility/texts/filechoose" + languageSuffix);
if (fileChooseFile != nullptr) {
fileChooseMap = nlohmann::json::parse(fileChooseFile->Buffer, nullptr, true, true);
fileChooseMap = nlohmann::json::parse(*fileChooseFile->Buffer.get(), nullptr, true, true);
}
}

Expand Down
59 changes: 29 additions & 30 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,19 +319,19 @@ OTRGlobals::OTRGlobals() {

SPDLOG_INFO("Starting Ship of Harkinian version {}", (char*)gBuildVersion);

context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_Animation, "Animation", std::make_shared<LUS::AnimationFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_PlayerAnimation, "PlayerAnimation", std::make_shared<LUS::PlayerAnimationFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_Room, "Room", std::make_shared<LUS::SceneFactory>()); // Is room scene? maybe?
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_CollisionHeader, "CollisionHeader", std::make_shared<LUS::CollisionHeaderFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_Skeleton, "Skeleton", std::make_shared<LUS::SkeletonFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_SkeletonLimb, "SkeletonLimb", std::make_shared<LUS::SkeletonLimbFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_Path, "Path", std::make_shared<LUS::PathFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_Cutscene, "Cutscene", std::make_shared<LUS::CutsceneFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_Text, "Text", std::make_shared<LUS::TextFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_AudioSample, "AudioSample", std::make_shared<LUS::AudioSampleFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_AudioSoundFont, "AudioSoundFont", std::make_shared<LUS::AudioSoundFontFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_AudioSequence, "AudioSequence", std::make_shared<LUS::AudioSequenceFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_Background, "Background", std::make_shared<LUS::BackgroundFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Animation), std::make_shared<LUS::AnimationFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_PlayerAnimation), std::make_shared<LUS::PlayerAnimationFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Room), std::make_shared<LUS::SceneFactory>()); // Is room scene? maybe?
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_CollisionHeader), std::make_shared<LUS::CollisionHeaderFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Skeleton), std::make_shared<LUS::SkeletonFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_SkeletonLimb), std::make_shared<LUS::SkeletonLimbFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Path), std::make_shared<LUS::PathFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Cutscene), std::make_shared<LUS::CutsceneFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Text), std::make_shared<LUS::TextFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_AudioSample), std::make_shared<LUS::AudioSampleFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_AudioSoundFont), std::make_shared<LUS::AudioSoundFontFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_AudioSequence), std::make_shared<LUS::AudioSequenceFactory>());
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Background), std::make_shared<LUS::BackgroundFactory>());

gSaveStateMgr = std::make_shared<SaveStateMgr>();
gRandomizer = std::make_shared<Randomizer>();
Expand All @@ -354,7 +354,7 @@ OTRGlobals::OTRGlobals() {
cameraStrings[i] = dup;
}

auto versions = context->GetResourceManager()->GetArchive()->GetGameVersions();
auto versions = context->GetResourceManager()->GetArchiveManager()->GetGameVersions();

for (uint32_t version : versions) {
if (!ValidHashes.contains(version)) {
Expand Down Expand Up @@ -836,7 +836,7 @@ extern "C" RandomizerGet RetrieveRandomizerGetFromItemID(ItemID itemID) {
}

extern "C" void OTRExtScanner() {
auto lst = *LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->ListFiles("*").get();
auto lst = *LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->ListFiles().get();

for (auto& rPath : lst) {
std::vector<std::string> raw = StringHelper::Split(rPath, ".");
Expand All @@ -859,22 +859,21 @@ OTRVersion ReadPortVersionFromOTR(std::string otrPath) {
OTRVersion version = {};

// Use a temporary archive instance to load the otr and read the version file
auto archive = std::make_shared<LUS::Archive>(otrPath, "", std::unordered_set<uint32_t>(), false);
if (archive->IsMainMPQValid()) {
auto t = archive->LoadFile("portVersion", false);
auto archive = LUS::OtrArchive(otrPath);
if (archive.LoadRaw()) {
auto t = archive.LoadFileRaw("portVersion");
if (t != nullptr && t->IsLoaded) {
auto stream = std::make_shared<LUS::MemoryStream>(t->Buffer.data(), t->Buffer.size());
auto stream = std::make_shared<LUS::MemoryStream>(t->Buffer->data(), t->Buffer->size());
auto reader = std::make_shared<LUS::BinaryReader>(stream);
LUS::Endianness endianness = (LUS::Endianness)reader->ReadUByte();
reader->SetEndianness(endianness);
version.major = reader->ReadUInt16();
version.minor = reader->ReadUInt16();
version.patch = reader->ReadUInt16();
}
archive.UnloadRaw();
}

archive = nullptr;

return version;
}

Expand Down Expand Up @@ -1412,15 +1411,15 @@ extern "C" uint16_t OTRGetPixelDepth(float x, float y) {
}

extern "C" uint32_t ResourceMgr_GetNumGameVersions() {
return LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions().size();
return LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->GetGameVersions().size();
}

extern "C" uint32_t ResourceMgr_GetGameVersion(int index) {
return LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions()[index];
return LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->GetGameVersions()[index];
}

extern "C" uint32_t ResourceMgr_GetGamePlatform(int index) {
uint32_t version = LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions()[index];
uint32_t version = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->GetGameVersions()[index];

switch (version) {
case OOT_NTSC_US_10:
Expand All @@ -1443,7 +1442,7 @@ extern "C" uint32_t ResourceMgr_GetGamePlatform(int index) {
}

extern "C" uint32_t ResourceMgr_GetGameRegion(int index) {
uint32_t version = LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions()[index];
uint32_t version = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->GetGameVersions()[index];

switch (version) {
case OOT_NTSC_US_10:
Expand Down Expand Up @@ -1529,7 +1528,7 @@ extern "C" void ResourceMgr_UnloadResource(const char* resName) {
// OTRTODO: There is probably a more elegant way to go about this...
// Kenix: This is definitely leaking memory when it's called.
extern "C" char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize) {
auto lst = LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->ListFiles(searchMask);
auto lst = LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->ListFiles(searchMask);
char** result = (char**)malloc(lst->size() * sizeof(char*));

for (size_t i = 0; i < lst->size(); i++) {
Expand Down Expand Up @@ -1619,7 +1618,7 @@ extern "C" uint8_t ResourceMgr_TexIsRaw(const char* texPath) {

extern "C" uint8_t ResourceMgr_ResourceIsBackground(char* texPath) {
auto res = GetResourceByNameHandlingMQ(texPath);
return res->GetInitData()->Type == LUS::ResourceType::SOH_Background;
return res->GetInitData()->Type == static_cast<uint32_t>(LUS::ResourceType::SOH_Background);
}

extern "C" char* ResourceMgr_LoadJPEG(char* data, size_t dataSize)
Expand Down Expand Up @@ -1667,9 +1666,9 @@ extern "C" uint16_t ResourceMgr_LoadTexHeightByName(char* texPath);
extern "C" char* ResourceMgr_LoadTexOrDListByName(const char* filePath) {
auto res = GetResourceByNameHandlingMQ(filePath);

if (res->GetInitData()->Type == LUS::ResourceType::DisplayList)
if (res->GetInitData()->Type == static_cast<uint32_t>(LUS::ResourceType::DisplayList))
return (char*)&((std::static_pointer_cast<LUS::DisplayList>(res))->Instructions[0]);
else if (res->GetInitData()->Type == LUS::ResourceType::Array)
else if (res->GetInitData()->Type == static_cast<uint32_t>(LUS::ResourceType::Array))
return (char*)(std::static_pointer_cast<LUS::Array>(res))->Vertices.data();
else {
return (char*)GetResourceDataByNameHandlingMQ(filePath);
Expand All @@ -1679,7 +1678,7 @@ extern "C" char* ResourceMgr_LoadTexOrDListByName(const char* filePath) {
extern "C" char* ResourceMgr_LoadIfDListByName(const char* filePath) {
auto res = GetResourceByNameHandlingMQ(filePath);

if (res->GetInitData()->Type == LUS::ResourceType::DisplayList)
if (res->GetInitData()->Type == static_cast<uint32_t>(LUS::ResourceType::DisplayList))
return (char*)&((std::static_pointer_cast<LUS::DisplayList>(res))->Instructions[0]);

return nullptr;
Expand Down
3 changes: 1 addition & 2 deletions soh/soh/SohMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ void DrawSettingsMenu() {

static std::unordered_map<LUS::AudioBackend, const char*> audioBackendNames = {
{ LUS::AudioBackend::WASAPI, "Windows Audio Session API" },
{ LUS::AudioBackend::PULSE, "PulseAudio" },
{ LUS::AudioBackend::SDL, "SDL" },
{ LUS::AudioBackend::SDL, "SDL" }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is because Kenix3/libultraship#421 is on latest LUS main

};

ImGui::Text("Audio API (Needs reload)");
Expand Down
2 changes: 1 addition & 1 deletion soh/soh/resource/importer/SceneFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ std::shared_ptr<ISceneCommand> SceneFactoryV0::ParseSceneCommand(std::shared_ptr
if (commandFactory != nullptr) {
auto initData = std::make_shared<ResourceInitData>();
initData->Id = scene->GetInitData()->Id;
initData->Type = ResourceType::SOH_SceneCommand;
initData->Type = static_cast<uint32_t>(ResourceType::SOH_SceneCommand);
initData->Path = scene->GetInitData()->Path + "/SceneCommand" + std::to_string(index);
initData->ResourceVersion = scene->GetInitData()->ResourceVersion;
result = std::static_pointer_cast<ISceneCommand>(commandFactory->ReadResource(initData, reader));
Expand Down
2 changes: 1 addition & 1 deletion soh/soh/z_message_OTR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void SetMessageEntry(MessageTableEntry& entry, const LUS::MessageEntry& m
}

static void OTRMessage_LoadCustom(const std::string& folderPath, MessageTableEntry*& table, size_t tableSize) {
auto lst = *LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->ListFiles(folderPath).get();
auto lst = *LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->ListFiles(folderPath).get();

for (auto& tPath : lst) {
auto file = std::static_pointer_cast<LUS::Text>(LUS::Context::GetInstance()->GetResourceManager()->LoadResource(tPath));
Expand Down
Loading