From f7d7ae49b0dd9c11be5c8d368f1ae536cc1f420f Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Sat, 4 May 2024 03:27:46 -0600 Subject: [PATCH] Updated to work with latest libultraship --- CMakeLists.txt | 15 ++++++--- bin/segment2.c | 3 -- include/PR/gu.h | 2 ++ include/sm64.h | 3 -- libultraship | 2 +- src/engine/graph_node.h | 5 +++ src/game/hud.c | 3 -- src/game/ingame_menu.c | 6 ---- src/game/print.c | 2 -- src/port/Engine.cpp | 36 ++++++++++---------- src/port/GBIMiddleware.cpp | 4 +-- src/port/game/GeoLayoutParser.cpp | 6 ++-- src/port/importer/AnimationFactory.cpp | 27 ++++----------- src/port/importer/AnimationFactory.h | 15 +++------ src/port/importer/AudioBankFactory.cpp | 38 +++++++--------------- src/port/importer/AudioBankFactory.h | 15 +++------ src/port/importer/AudioSampleFactory.cpp | 27 ++++----------- src/port/importer/AudioSampleFactory.h | 15 +++------ src/port/importer/AudioSequenceFactory.cpp | 27 ++++----------- src/port/importer/AudioSequenceFactory.h | 15 +++------ src/port/importer/DialogFactory.cpp | 26 +++------------ src/port/importer/DialogFactory.h | 15 +++------ src/port/importer/DictionaryFactory.cpp | 26 ++++----------- src/port/importer/DictionaryFactory.h | 15 +++------ src/port/importer/ResourceType.h | 24 ++++++++++++++ src/port/importer/ResourceUtil.h | 22 +++++++++++++ src/port/importer/types/Animation.cpp | 2 +- src/port/importer/types/Animation.h | 3 +- src/port/importer/types/AudioBank.cpp | 2 +- src/port/importer/types/AudioBank.h | 2 +- src/port/importer/types/AudioSample.cpp | 2 +- src/port/importer/types/AudioSample.h | 2 +- src/port/importer/types/AudioSequence.cpp | 2 +- src/port/importer/types/AudioSequence.h | 2 +- src/port/importer/types/Dialog.cpp | 2 +- src/port/importer/types/Dialog.h | 2 +- src/port/importer/types/Dictionary.cpp | 2 +- src/port/importer/types/Dictionary.h | 2 +- src/port/ui/ImguiUI.cpp | 7 ++-- 39 files changed, 173 insertions(+), 253 deletions(-) create mode 100644 src/port/importer/ResourceType.h create mode 100644 src/port/importer/ResourceUtil.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3527f9e6..aaaccdf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,8 +33,12 @@ set(VCPKG_TRIPLET x64-mingw-static) set(VCPKG_TARGET_TRIPLET x64-mingw-static) endif() +if(NOT CMAKE_BUILD_TYPE ) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE) +endif() + vcpkg_bootstrap() -vcpkg_install_packages(fontconfig sdl2 zlib bzip2 libpng getopt dirent libusb pthread glew glfw3) +vcpkg_install_packages(fontconfig sdl2 zlib bzip2 libzip libpng getopt dirent libusb pthread glew glfw3) endif() if (MSVC) @@ -45,7 +49,7 @@ endif() # Set game compilation version set(VERSION us) -set(USE_NETWORKING ON) +set(USE_NETWORKING OFF) # Add compile definitions for the target add_compile_definitions( @@ -56,6 +60,9 @@ add_compile_definitions( _LANGUAGE_C _USE_MATH_DEFINES CIMGUI_DEFINE_ENUMS_AND_STRUCTS + IMGUI_DEFINE_MATH_OPERATORS + AVOID_UB=1 + ENABLE_OPENGL=1 ) # Find necessary libraries @@ -137,10 +144,10 @@ if (MSVC) if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") string(CONCAT "MSVC_RUNTIME_LIBRARY_STR" $<$: - MultiThreadedDebug + MultiThreadedDebug > $<$: - MultiThreaded + MultiThreaded > $<$,$>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}> ) diff --git a/bin/segment2.c b/bin/segment2.c index 9e2783ba..184d39ce 100644 --- a/bin/segment2.c +++ b/bin/segment2.c @@ -1319,7 +1319,6 @@ const Gfx dl_ia_text_end[] = { #elif defined(VERSION_US) const Gfx dl_ia_text_begin_us[] = { gsDPPipeSync(), - gsSPDisableFiltering(1), gsSPClearGeometryMode(G_LIGHTING), gsDPSetCombineMode(G_CC_FADEA, G_CC_FADEA), gsDPSetEnvColor(255, 255, 255, 255), @@ -1331,7 +1330,6 @@ const Gfx dl_ia_text_begin_us[] = { const Gfx dl_ia_text_begin_jp[] = { gsDPPipeSync(), - gsSPDisableFiltering(1), gsSPClearGeometryMode(G_LIGHTING), gsDPSetCombineMode(G_CC_FADEA, G_CC_FADEA), gsDPSetEnvColor(255, 255, 255, 255), @@ -1399,7 +1397,6 @@ const Gfx dl_ia_text_end[] = { gsSPSetGeometryMode(G_LIGHTING | G_SHADING_SMOOTH), gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2), gsDPSetTextureFilter(G_TF_BILERP), - gsSPDisableFiltering(0), gsSPEndDisplayList(), }; #endif diff --git a/include/PR/gu.h b/include/PR/gu.h index 713d76d3..119f13b6 100644 --- a/include/PR/gu.h +++ b/include/PR/gu.h @@ -6,6 +6,7 @@ #define GU_PI 3.1415926 /* Functions */ +#ifndef __cplusplus void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, float near, float far, float scale); void guPerspective(Mtx *m, u16 *perspNorm, float fovy, float aspect, float near, @@ -26,3 +27,4 @@ void guLookAtReflect (Mtx *m, LookAt *l, float xEye, float yEye, float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp); #endif +#endif diff --git a/include/sm64.h b/include/sm64.h index 2ef6c697..166ee531 100644 --- a/include/sm64.h +++ b/include/sm64.h @@ -470,9 +470,6 @@ #define C_BUTTONS (U_CBUTTONS | D_CBUTTONS | L_CBUTTONS | R_CBUTTONS ) -extern void osInvalDCache(void *, size_t); -extern void osInvalICache(void *, size_t); -extern void osWritebackDCache(void *, size_t); extern void osWritebackDCacheAll(void); extern s32 osPiStartDma(OSIoMesg *mb, s32 priority, s32 direction, uintptr_t devAddr, void *vAddr, size_t nbytes, OSMesgQueue *mq); extern void osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgCnt); diff --git a/libultraship b/libultraship index c9cd89e7..39b5d3f1 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit c9cd89e70e9a8368ea6ce7a89adbe573cff029e9 +Subproject commit 39b5d3f1acfa53d3a2d0723a9831411005401562 diff --git a/src/engine/graph_node.h b/src/engine/graph_node.h index 08b99f03..c97bc474 100644 --- a/src/engine/graph_node.h +++ b/src/engine/graph_node.h @@ -9,6 +9,11 @@ #include "types.h" #include "game/memory.h" +#ifdef _WIN32 +#undef near +#undef far +#endif + #define GRAPH_RENDER_ACTIVE (1 << 0) #define GRAPH_RENDER_CHILDREN_FIRST (1 << 1) #define GRAPH_RENDER_BILLBOARD (1 << 2) diff --git a/src/game/hud.c b/src/game/hud.c index eb94390b..babebbe9 100644 --- a/src/game/hud.c +++ b/src/game/hud.c @@ -445,8 +445,6 @@ void render_hud(void) { create_dl_ortho_matrix(); #endif - gSPDisableFiltering(gDisplayListHead++, TRUE); - if (gCurrentArea != NULL && gCurrentArea->camera->mode == CAMERA_MODE_INSIDE_CANNON) { render_hud_cannon_reticle(); } @@ -476,6 +474,5 @@ void render_hud(void) { render_hud_timer(); } - gSPDisableFiltering(gDisplayListHead++, FALSE); } } diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c index eadde543..da75de76 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c @@ -413,7 +413,6 @@ void print_generic_string(s16 x, s16 y, const u8 *str) { #ifndef VERSION_EU create_dl_translation_matrix(MENU_MTX_PUSH, x, y, 0.0f); - gSPDisableFiltering(gDisplayListHead++, TRUE); #endif while (str[strPos] != DIALOG_CHAR_TERMINATOR) { @@ -488,7 +487,6 @@ void print_generic_string(s16 x, s16 y, const u8 *str) { #ifndef VERSION_EU gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); - gSPDisableFiltering(gDisplayListHead++, FALSE); #endif } @@ -517,7 +515,6 @@ void print_hud_lut_string(s8 hudLUT, s16 x, s16 y, const u8 *str) { u32 curX = x; u32 curY = y; - gSPDisableFiltering(gDisplayListHead++, TRUE); u32 xStride; // X separation if (hudLUT == HUD_LUT_JPMENU) { @@ -586,7 +583,6 @@ void print_hud_lut_string(s8 hudLUT, s16 x, s16 y, const u8 *str) { } strPos++; } - gSPDisableFiltering(gDisplayListHead++, FALSE); } #ifdef VERSION_EU @@ -611,7 +607,6 @@ void print_menu_generic_string(s16 x, s16 y, const u8 *str) { u32 curX = x; u32 curY = y; void **fontLUT = segmented_to_virtual(ROM_JP ? menu_font_lut_jp : menu_font_lut_us); - gSPDisableFiltering(gDisplayListHead++, TRUE); while (str[strPos] != DIALOG_CHAR_TERMINATOR) { switch (str[strPos]) { @@ -662,7 +657,6 @@ void print_menu_generic_string(s16 x, s16 y, const u8 *str) { strPos++; } - gSPDisableFiltering(gDisplayListHead++, FALSE); } void print_credits_string(s16 x, s16 y, const u8 *str) { diff --git a/src/game/print.c b/src/game/print.c index 69f29dc1..a979eb13 100644 --- a/src/game/print.c +++ b/src/game/print.c @@ -398,7 +398,6 @@ void render_text_labels(void) { gSPPerspNormalize((Gfx *) (gDisplayListHead++), 0xFFFF); gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(mtx), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH); gSPDisplayList(gDisplayListHead++, dl_hud_img_begin); - gSPDisableFiltering(gDisplayListHead++, TRUE); for (i = 0; i < sTextLabelsCount; i++) { for (j = 0; j < sTextLabels[i]->length; j++) { @@ -428,7 +427,6 @@ void render_text_labels(void) { mem_pool_free(gEffectsMemoryPool, sTextLabels[i]); } - gSPDisableFiltering(gDisplayListHead++, FALSE); gSPDisplayList(gDisplayListHead++, dl_hud_img_end); sTextLabelsCount = 0; diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index cd380462..e1286bea 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -4,11 +4,12 @@ #include "port/importer/AudioBankFactory.h" #include "port/importer/AudioSampleFactory.h" #include "port/importer/AudioSequenceFactory.h" +#include "port/importer/DialogFactory.h" +#include "port/importer/DictionaryFactory.h" +#include "port/importer/ResourceType.h" #include "audio/GameAudio.h" #include "ZAPDUtils/Utils/StringHelper.h" #include "texts_table.h" -#include "port/importer/DialogFactory.h" -#include "port/importer/DictionaryFactory.h" #include "port/Enhancements/game-interactor/GameInteractor.h" #include "port/Enhancements/mods.h" #include @@ -49,18 +50,13 @@ GameEngine::GameEngine(): dictionary(nullptr) { {0xFF2B5A63, 0xE3DAA4E}, 3); this->context->GetWindow()->SetTargetFps(60); this->context->GetWindow()->SetMaximumFrameLatency(1); - this->context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( - LUS::ResourceType::SAnim, "Animation", std::make_shared()); - this->context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( - LUS::ResourceType::Bank, "Bank", std::make_shared()); - this->context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( - LUS::ResourceType::Sample, "Sample", std::make_shared()); - this->context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( - LUS::ResourceType::Sequence, "Sequence", std::make_shared()); - this->context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( - LUS::ResourceType::SDialog, "Dialog", std::make_shared()); - this->context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( - LUS::ResourceType::Dictionary, "Dictionary", std::make_shared()); + auto loader = context->GetResourceManager()->GetResourceLoader(); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Animation", static_cast(SM64::ResourceType::Anim), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "AudioBank", static_cast(SM64::ResourceType::Bank), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "AudioSample", static_cast(SM64::ResourceType::Sample), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "AudioSequence", static_cast(SM64::ResourceType::Sequence), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Dialog", static_cast(SM64::ResourceType::SDialog), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Dictionary", static_cast(SM64::ResourceType::Dictionary), 0); } void GameEngine::Create(){ @@ -163,14 +159,16 @@ void GameEngine::EndAudioFrame(){ void GameEngine::AudioInit() { const auto resourceMgr = LUS::Context::GetInstance()->GetResourceManager(); resourceMgr->LoadDirectory("sound"); + const auto banksFiles = resourceMgr->GetArchiveManager()->ListFiles("sound/banks/*"); + const auto sequences_files = resourceMgr->GetArchiveManager()->ListFiles("sound/sequences/*"); - for(const auto banksFiles = resourceMgr->GetArchive()->ListFiles("sound/banks/*"); auto& bank : *banksFiles){ + for(auto& bank : *banksFiles){ auto path = "__OTR__" + bank; const auto ctl = static_cast(ResourceGetDataByName(path.c_str())); this->bankMapTable[bank] = ctl->bankId; } - for(const auto sequences_files = resourceMgr->GetArchive()->ListFiles("sound/sequences/*"); auto& sequence : *sequences_files){ + for( auto& sequence : *sequences_files){ auto path = "__OTR__" + sequence; auto seq = static_cast(ResourceGetDataByName(path.c_str())); this->sequencesMapTable[seq->id] = path; @@ -206,7 +204,7 @@ uint8_t GameEngine::GetBankIdByName(const std::string& name) { } uint32_t GameEngine::GetGameVersion() { - return LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions()[0]; + return LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->GetGameVersions()[0]; } void GameEngine::RunCommands(Gfx* Commands) { @@ -357,7 +355,7 @@ extern "C" void GameEngine_UnloadSequence(uint8_t seqId) { } extern "C" uint32_t GameEngine_GetGameVersion() { - return LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions()[0]; + return LUS::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->GetGameVersions()[0]; } extern "C" uint8_t* GameEngine_LoadActName(uint32_t actId){ @@ -384,5 +382,5 @@ extern "C" uint8_t* GameEngine_LoadTranslation(const char* key) { } extern "C" int GameEngine_OTRSigCheck(const char* data) { - return LUS::ResourceManager::OtrSignatureCheck(data); + return LUS::Context::GetInstance()->GetResourceManager()->OtrSignatureCheck(data); } \ No newline at end of file diff --git a/src/port/GBIMiddleware.cpp b/src/port/GBIMiddleware.cpp index ab8f0e0a..a4411541 100644 --- a/src/port/GBIMiddleware.cpp +++ b/src/port/GBIMiddleware.cpp @@ -33,9 +33,9 @@ extern "C" void gSPInvalidateTexCache(Gfx* pkt, uintptr_t texAddr) { if (texAddr != 0 && GameEngine_OTRSigCheck(imgData)) { auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResource(imgData); - if (res->GetInitData()->Type == LUS::ResourceType::DisplayList) + if (res->GetInitData()->Type == (uint32_t) LUS::ResourceType::DisplayList) texAddr = (uintptr_t)&((std::static_pointer_cast(res))->Instructions[0]); - else if (res->GetInitData()->Type == LUS::ResourceType::Array) + else if (res->GetInitData()->Type == (uint32_t) LUS::ResourceType::Array) texAddr = (uintptr_t)(std::static_pointer_cast(res))->Vertices.data(); else { texAddr = (uintptr_t) res->GetRawPointer(); diff --git a/src/port/game/GeoLayoutParser.cpp b/src/port/game/GeoLayoutParser.cpp index aa2b0226..ee46ccfc 100644 --- a/src/port/game/GeoLayoutParser.cpp +++ b/src/port/game/GeoLayoutParser.cpp @@ -177,15 +177,15 @@ void process_cmd_node_perspective() { const auto param = GeoLayoutParser::mReader->ReadUByte(); const auto fov = GeoLayoutParser::mReader->ReadInt16(); - const auto near = GeoLayoutParser::mReader->ReadInt16(); - const auto far = GeoLayoutParser::mReader->ReadInt16(); + const auto _near = GeoLayoutParser::mReader->ReadInt16(); + const auto _far = GeoLayoutParser::mReader->ReadInt16(); if (param != 0) { const auto func = GeoLayoutParser::mReader->ReadUInt32(); frustumFunc = GetFunctionByAddr(func); } - GraphNodePerspective* graphNode = init_graph_node_perspective(gGraphNodePool, nullptr, fov, near, far, frustumFunc, 0); + GraphNodePerspective* graphNode = init_graph_node_perspective(gGraphNodePool, nullptr, fov, _near, _far, frustumFunc, 0); register_scene_graph_node(&graphNode->fnNode.node); } diff --git a/src/port/importer/AnimationFactory.cpp b/src/port/importer/AnimationFactory.cpp index a57cd3da..32d7e932 100644 --- a/src/port/importer/AnimationFactory.cpp +++ b/src/port/importer/AnimationFactory.cpp @@ -2,30 +2,13 @@ #include "port/importer/types/Animation.h" #include "spdlog/spdlog.h" -std::shared_ptr CubeOS::AnimationFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load Animation with version {}", resource->GetInitData()->ResourceVersion); +std::shared_ptr SM64::AnimationFactoryV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } - factory->ParseFileBinary(reader, resource); - - return resource; -} - -void CubeOS::AnimationFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr animation = std::static_pointer_cast(resource); - - ResourceVersionFactory::ParseFileBinary(reader, animation); + std::shared_ptr animation = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); animation->mData.flags = reader->ReadInt16(); animation->mData.animYTransDivisor = reader->ReadInt16(); @@ -49,4 +32,6 @@ void CubeOS::AnimationFactoryV0::ParseFileBinary(std::shared_ptrmData.index = (uint16_t*)animation->indices.data(); animation->mData.values = (int16_t*)animation->values.data(); + + return animation; } \ No newline at end of file diff --git a/src/port/importer/AnimationFactory.h b/src/port/importer/AnimationFactory.h index 4d56b61b..b3cf6b69 100644 --- a/src/port/importer/AnimationFactory.h +++ b/src/port/importer/AnimationFactory.h @@ -1,16 +1,11 @@ #pragma once -#include "ResourceFactory.h" +#include "Resource.h" +#include "ResourceFactoryBinary.h" -namespace CubeOS{ -class AnimationFactory : public LUS::ResourceFactory { +namespace SM64 { +class AnimationFactoryV0 : public LUS::ResourceFactoryBinary { public: - std::shared_ptr - ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; -}; - -class AnimationFactoryV0 : public LUS::ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } diff --git a/src/port/importer/AudioBankFactory.cpp b/src/port/importer/AudioBankFactory.cpp index cbd79cf1..60af6cfc 100644 --- a/src/port/importer/AudioBankFactory.cpp +++ b/src/port/importer/AudioBankFactory.cpp @@ -2,33 +2,15 @@ #include "port/importer/types/AudioBank.h" #include "spdlog/spdlog.h" #include "resourcebridge.h" +#include "ResourceUtil.h" -std::shared_ptr CubeOS::AudioBankFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load AudioBank with version {}", resource->GetInitData()->ResourceVersion); +std::shared_ptr SM64::AudioBankFactoryV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } - factory->ParseFileBinary(reader, resource); - - return resource; -} - - - -void CubeOS::AudioBankFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr bank = std::static_pointer_cast(resource); - - ResourceVersionFactory::ParseFileBinary(reader, bank); + std::shared_ptr bank = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); uint8_t bankId = reader->ReadUInt32(); uint32_t instrumentCount = reader->ReadUInt32(); @@ -61,19 +43,19 @@ void CubeOS::AudioBankFactoryV0::ParseFileBinary(std::shared_ptrReadString(); - instrument->lowNotesSound.sample = static_cast(ResourceGetDataByName(lowSampleName.c_str())); + instrument->lowNotesSound.sample = LoadChild(lowSampleName.c_str()); instrument->lowNotesSound.tuning = reader->ReadFloat(); } if(hasMed){ std::string normalSampleName = reader->ReadString(); - instrument->normalNotesSound.sample = static_cast(ResourceGetDataByName(normalSampleName.c_str())); + instrument->normalNotesSound.sample = LoadChild(normalSampleName.c_str()); instrument->normalNotesSound.tuning = reader->ReadFloat(); } if(hasHi){ std::string highSampleName = reader->ReadString(); - instrument->highNotesSound.sample = static_cast(ResourceGetDataByName(highSampleName.c_str())); + instrument->highNotesSound.sample = LoadChild(highSampleName.c_str()); instrument->highNotesSound.tuning = reader->ReadFloat(); } @@ -98,7 +80,7 @@ void CubeOS::AudioBankFactoryV0::ParseFileBinary(std::shared_ptrReadString(); - drum->sound.sample = static_cast(ResourceGetDataByName(sampleName.c_str())); + drum->sound.sample = LoadChild(sampleName.c_str()); drum->sound.tuning = reader->ReadFloat(); bank->drums.push_back(drum); @@ -109,4 +91,6 @@ void CubeOS::AudioBankFactoryV0::ParseFileBinary(std::shared_ptrmData.numDrums = drumCount; bank->mData.instruments = bank->instruments.data(); bank->mData.drums = bank->drums.data(); + + return bank; } \ No newline at end of file diff --git a/src/port/importer/AudioBankFactory.h b/src/port/importer/AudioBankFactory.h index a8b39a2b..8179be92 100644 --- a/src/port/importer/AudioBankFactory.h +++ b/src/port/importer/AudioBankFactory.h @@ -1,16 +1,11 @@ #pragma once -#include "ResourceFactory.h" +#include "Resource.h" +#include "ResourceFactoryBinary.h" -namespace CubeOS{ -class AudioBankFactory : public LUS::ResourceFactory { +namespace SM64 { +class AudioBankFactoryV0 : public LUS::ResourceFactoryBinary { public: - std::shared_ptr - ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; -}; - -class AudioBankFactoryV0 : public LUS::ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } diff --git a/src/port/importer/AudioSampleFactory.cpp b/src/port/importer/AudioSampleFactory.cpp index d913a8b9..987a9f26 100644 --- a/src/port/importer/AudioSampleFactory.cpp +++ b/src/port/importer/AudioSampleFactory.cpp @@ -3,30 +3,13 @@ #include "port/importer/types/AudioSample.h" #include "spdlog/spdlog.h" -std::shared_ptr CubeOS::AudioSampleFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load AudioBank with version {}", resource->GetInitData()->ResourceVersion); +std::shared_ptr SM64::AudioSampleFactoryV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } - factory->ParseFileBinary(reader, resource); - - return resource; -} - -void CubeOS::AudioSampleFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr bank = std::static_pointer_cast(resource); - - ResourceVersionFactory::ParseFileBinary(reader, bank); + std::shared_ptr bank = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); bank->loop.start = reader->ReadUInt32(); bank->loop.end = reader->ReadUInt32(); @@ -59,4 +42,6 @@ void CubeOS::AudioSampleFactoryV0::ParseFileBinary(std::shared_ptrmData.book = &bank->book; bank->mData.sampleAddr = (uint8_t*) sampleData; bank->mData.sampleSize = sampleSize; + + return bank; } \ No newline at end of file diff --git a/src/port/importer/AudioSampleFactory.h b/src/port/importer/AudioSampleFactory.h index 9c99f2d2..e91c6f94 100644 --- a/src/port/importer/AudioSampleFactory.h +++ b/src/port/importer/AudioSampleFactory.h @@ -1,16 +1,11 @@ #pragma once -#include "ResourceFactory.h" +#include "Resource.h" +#include "ResourceFactoryBinary.h" -namespace CubeOS{ -class AudioSampleFactory : public LUS::ResourceFactory { +namespace SM64 { +class AudioSampleFactoryV0 : public LUS::ResourceFactoryBinary { public: - std::shared_ptr - ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; -}; - -class AudioSampleFactoryV0 : public LUS::ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } diff --git a/src/port/importer/AudioSequenceFactory.cpp b/src/port/importer/AudioSequenceFactory.cpp index f260617c..43d3f422 100644 --- a/src/port/importer/AudioSequenceFactory.cpp +++ b/src/port/importer/AudioSequenceFactory.cpp @@ -4,30 +4,13 @@ #include "port/Engine.h" #include "port/importer/types/AudioBank.h" -std::shared_ptr CubeOS::AudioSequenceFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load AudioBank with version {}", resource->GetInitData()->ResourceVersion); +std::shared_ptr SM64::AudioSequenceFactoryV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } - factory->ParseFileBinary(reader, resource); - - return resource; -} - -void CubeOS::AudioSequenceFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr bank = std::static_pointer_cast(resource); - - ResourceVersionFactory::ParseFileBinary(reader, bank); + std::shared_ptr bank = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); uint8_t id = reader->ReadUInt32(); size_t bankCount = reader->ReadUInt32(); @@ -45,4 +28,6 @@ void CubeOS::AudioSequenceFactoryV0::ParseFileBinary(std::shared_ptrmData.banks = bank->banks.data(); bank->mData.data = bank->sampleData.data(); bank->mData.id = id; + + return bank; } \ No newline at end of file diff --git a/src/port/importer/AudioSequenceFactory.h b/src/port/importer/AudioSequenceFactory.h index 1944094c..7920494a 100644 --- a/src/port/importer/AudioSequenceFactory.h +++ b/src/port/importer/AudioSequenceFactory.h @@ -1,16 +1,11 @@ #pragma once -#include "ResourceFactory.h" +#include "Resource.h" +#include "ResourceFactoryBinary.h" -namespace CubeOS{ -class AudioSequenceFactory : public LUS::ResourceFactory { +namespace SM64 { +class AudioSequenceFactoryV0 : public LUS::ResourceFactoryBinary { public: - std::shared_ptr - ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; -}; - -class AudioSequenceFactoryV0 : public LUS::ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } diff --git a/src/port/importer/DialogFactory.cpp b/src/port/importer/DialogFactory.cpp index bf7bffad..c2e3531d 100644 --- a/src/port/importer/DialogFactory.cpp +++ b/src/port/importer/DialogFactory.cpp @@ -2,30 +2,13 @@ #include "port/importer/types/Dialog.h" #include "spdlog/spdlog.h" -std::shared_ptr CubeOS::DialogFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load Dialog with version {}", resource->GetInitData()->ResourceVersion); +std::shared_ptr SM64::DialogFactoryV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } - factory->ParseFileBinary(reader, resource); - - return resource; -} - -void CubeOS::DialogFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr dialog = std::static_pointer_cast(resource); - - ResourceVersionFactory::ParseFileBinary(reader, dialog); + std::shared_ptr dialog = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); dialog->mData.unused = reader->ReadUInt32(); dialog->mData.linesPerBox = reader->ReadInt8(); @@ -38,4 +21,5 @@ void CubeOS::DialogFactoryV0::ParseFileBinary(std::shared_ptr } dialog->mData.str = dialog->mText.data(); + return dialog; } \ No newline at end of file diff --git a/src/port/importer/DialogFactory.h b/src/port/importer/DialogFactory.h index 89c79c68..55d2aa58 100644 --- a/src/port/importer/DialogFactory.h +++ b/src/port/importer/DialogFactory.h @@ -1,16 +1,11 @@ #pragma once -#include "ResourceFactory.h" +#include "Resource.h" +#include "ResourceFactoryBinary.h" -namespace CubeOS{ -class DialogFactory : public LUS::ResourceFactory { +namespace SM64 { +class DialogFactoryV0 : public LUS::ResourceFactoryBinary { public: - std::shared_ptr - ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; -}; - -class DialogFactoryV0 : public LUS::ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } diff --git a/src/port/importer/DictionaryFactory.cpp b/src/port/importer/DictionaryFactory.cpp index 56e9f0ca..b338b7c7 100644 --- a/src/port/importer/DictionaryFactory.cpp +++ b/src/port/importer/DictionaryFactory.cpp @@ -2,30 +2,14 @@ #include "port/importer/types/Dictionary.h" #include "spdlog/spdlog.h" -std::shared_ptr CubeOS::DictionaryFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load Dialog with version {}", resource->GetInitData()->ResourceVersion); +std::shared_ptr SM64::DictionaryFactoryV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } - factory->ParseFileBinary(reader, resource); - - return resource; -} - -void CubeOS::DictionaryFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr dictionary = std::static_pointer_cast(resource); - - ResourceVersionFactory::ParseFileBinary(reader, dictionary); + std::shared_ptr dictionary = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); size_t numEntries = reader->ReadUInt32(); for(size_t i = 0; i < numEntries; i++){ @@ -37,4 +21,6 @@ void CubeOS::DictionaryFactoryV0::ParseFileBinary(std::shared_ptrmData[key] = value; } + + return dictionary; } \ No newline at end of file diff --git a/src/port/importer/DictionaryFactory.h b/src/port/importer/DictionaryFactory.h index d2466bc0..7bdb7150 100644 --- a/src/port/importer/DictionaryFactory.h +++ b/src/port/importer/DictionaryFactory.h @@ -1,16 +1,11 @@ #pragma once -#include "ResourceFactory.h" +#include "Resource.h" +#include "ResourceFactoryBinary.h" -namespace CubeOS{ -class DictionaryFactory : public LUS::ResourceFactory { +namespace SM64 { +class DictionaryFactoryV0 : public LUS::ResourceFactoryBinary { public: - std::shared_ptr - ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; -}; - -class DictionaryFactoryV0 : public LUS::ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } diff --git a/src/port/importer/ResourceType.h b/src/port/importer/ResourceType.h new file mode 100644 index 00000000..27ad27e1 --- /dev/null +++ b/src/port/importer/ResourceType.h @@ -0,0 +1,24 @@ +#pragma once + +namespace SM64 { +enum class ResourceType { + // SM64 + Bank = 0x42414E4B, // BANK + Sample = 0x41554643, // AIFC + Sequence = 0x53455143, // SEQC + Anim = 0x414E494D, // ANIM + BehaviorScript = 0x42485653, // BHVS + SDialog = 0x53444C47, // SDLG + Dictionary = 0x44494354, // DICT + GeoLayout = 0x47454F20, // GEO + Collision = 0x434F4C20, // COL + LevelScript = 0x4C564C53, // LVLS + MacroObject = 0x4D41434F, // MACO + Movtex = 0x4D4F5654, // MOVT + MovtexQuad = 0x4D4F5651, // MOVQ + Painting = 0x504E5420, // PNT + PaintingData = 0x504E5444, // PNTD + Trajectory = 0x5452414A, // TRAJ + WaterDroplet = 0x57545244, // WTRD +}; +} // namespace SOH diff --git a/src/port/importer/ResourceUtil.h b/src/port/importer/ResourceUtil.h new file mode 100644 index 00000000..57d29400 --- /dev/null +++ b/src/port/importer/ResourceUtil.h @@ -0,0 +1,22 @@ +#pragma once + +#include "resourcebridge.h" +#include "Context.h" + +namespace SM64 { +template T LoadChild(uint64_t crc) { + auto path = ResourceGetNameByCrc(crc); + if (path == nullptr) { + return nullptr; + } + auto asset = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(path); + return asset ? static_cast(asset->GetRawPointer()) : nullptr; +} +template T LoadChild(const char* path) { + if (path == nullptr) { + return nullptr; + } + auto asset = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(path); + return asset ? static_cast(asset->GetRawPointer()) : nullptr; +} +} diff --git a/src/port/importer/types/Animation.cpp b/src/port/importer/types/Animation.cpp index ddf6b5d1..14153247 100644 --- a/src/port/importer/types/Animation.cpp +++ b/src/port/importer/types/Animation.cpp @@ -1,6 +1,6 @@ #include "Animation.h" -namespace CubeOS { +namespace SM64 { AnimationData* Animation::GetPointer() { return &mData; } diff --git a/src/port/importer/types/Animation.h b/src/port/importer/types/Animation.h index 21c99480..5d4a48ed 100644 --- a/src/port/importer/types/Animation.h +++ b/src/port/importer/types/Animation.h @@ -1,10 +1,11 @@ #pragma once #include + #include #include -namespace CubeOS { +namespace SM64 { struct AnimationData { /*0x00*/ int16_t flags; /*0x02*/ int16_t animYTransDivisor; diff --git a/src/port/importer/types/AudioBank.cpp b/src/port/importer/types/AudioBank.cpp index d8f5d167..f91b767d 100644 --- a/src/port/importer/types/AudioBank.cpp +++ b/src/port/importer/types/AudioBank.cpp @@ -1,6 +1,6 @@ #include "AudioBank.h" -namespace CubeOS { +namespace SM64 { CtlEntry* AudioBank::GetPointer() { return &mData; } diff --git a/src/port/importer/types/AudioBank.h b/src/port/importer/types/AudioBank.h index bb3c965c..fcce8d26 100644 --- a/src/port/importer/types/AudioBank.h +++ b/src/port/importer/types/AudioBank.h @@ -42,7 +42,7 @@ struct CtlEntry { }; // size = 0xC -namespace CubeOS { +namespace SM64 { class AudioBank : public LUS::Resource { diff --git a/src/port/importer/types/AudioSample.cpp b/src/port/importer/types/AudioSample.cpp index 54324305..cbdbd657 100644 --- a/src/port/importer/types/AudioSample.cpp +++ b/src/port/importer/types/AudioSample.cpp @@ -1,6 +1,6 @@ #include "AudioSample.h" -namespace CubeOS { +namespace SM64 { AudioBankSample* AudioSample::GetPointer() { return &mData; } diff --git a/src/port/importer/types/AudioSample.h b/src/port/importer/types/AudioSample.h index 25dc9243..9c118c2b 100644 --- a/src/port/importer/types/AudioSample.h +++ b/src/port/importer/types/AudioSample.h @@ -27,7 +27,7 @@ struct AudioBankSample { uint32_t sampleSize; // never read. either 0 or 1 mod 9, depending on padding }; -namespace CubeOS { +namespace SM64 { class AudioSample : public LUS::Resource { diff --git a/src/port/importer/types/AudioSequence.cpp b/src/port/importer/types/AudioSequence.cpp index 6c781c9a..263530cf 100644 --- a/src/port/importer/types/AudioSequence.cpp +++ b/src/port/importer/types/AudioSequence.cpp @@ -1,6 +1,6 @@ #include "AudioSequence.h" -namespace CubeOS { +namespace SM64 { AudioSequenceData* AudioSequence::GetPointer() { return &mData; } diff --git a/src/port/importer/types/AudioSequence.h b/src/port/importer/types/AudioSequence.h index 5001e60b..965d6d7a 100644 --- a/src/port/importer/types/AudioSequence.h +++ b/src/port/importer/types/AudioSequence.h @@ -10,7 +10,7 @@ struct AudioSequenceData { uint8_t id; }; -namespace CubeOS { +namespace SM64 { class AudioSequence : public LUS::Resource { public: diff --git a/src/port/importer/types/Dialog.cpp b/src/port/importer/types/Dialog.cpp index 413eab68..10919e3c 100644 --- a/src/port/importer/types/Dialog.cpp +++ b/src/port/importer/types/Dialog.cpp @@ -1,6 +1,6 @@ #include "Dialog.h" -namespace CubeOS { +namespace SM64 { DialogEntry* Dialog::GetPointer() { return &mData; } diff --git a/src/port/importer/types/Dialog.h b/src/port/importer/types/Dialog.h index 776b1d49..9958e184 100644 --- a/src/port/importer/types/Dialog.h +++ b/src/port/importer/types/Dialog.h @@ -12,7 +12,7 @@ struct DialogEntry { }; -namespace CubeOS { +namespace SM64 { class Dialog : public LUS::Resource { public: diff --git a/src/port/importer/types/Dictionary.cpp b/src/port/importer/types/Dictionary.cpp index 41540064..7becc5b1 100644 --- a/src/port/importer/types/Dictionary.cpp +++ b/src/port/importer/types/Dictionary.cpp @@ -1,6 +1,6 @@ #include "Dictionary.h" -namespace CubeOS { +namespace SM64 { GameDictionary* Dictionary::GetPointer() { return &mData; } diff --git a/src/port/importer/types/Dictionary.h b/src/port/importer/types/Dictionary.h index 317f06fa..1c1ad807 100644 --- a/src/port/importer/types/Dictionary.h +++ b/src/port/importer/types/Dictionary.h @@ -4,7 +4,7 @@ #include #include -namespace CubeOS { +namespace SM64 { typedef std::unordered_map> GameDictionary; diff --git a/src/port/ui/ImguiUI.cpp b/src/port/ui/ImguiUI.cpp index e628f13e..3d85aa63 100644 --- a/src/port/ui/ImguiUI.cpp +++ b/src/port/ui/ImguiUI.cpp @@ -115,8 +115,7 @@ void DrawSettingsMenu(){ } static std::unordered_map audioBackendNames = { - { LUS::AudioBackend::WASAPI, "Windows Audio Session API" }, - { LUS::AudioBackend::PULSE, "PulseAudio" }, + { LUS::AudioBackend::WASAPI, "Windows Audio Session API" }, { LUS::AudioBackend::SDL, "SDL" }, }; @@ -366,8 +365,8 @@ void DrawSettingsMenu(){ void DrawMenuBarIcon() { static bool gameIconLoaded = false; if (!gameIconLoaded) { - LUS::Context::GetInstance()->GetWindow()->GetGui()->LoadTexture("Game_Icon", "textures/icons/gIcon.png"); - gameIconLoaded = true; + // LUS::Context::GetInstance()->GetWindow()->GetGui()->LoadGuiTexture("Game_Icon", "textures/icons/gIcon.png", ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); + // gameIconLoaded = true; } if (LUS::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName("Game_Icon")) {