diff --git a/OTRExporter b/OTRExporter index 375489d5f..854685155 160000 --- a/OTRExporter +++ b/OTRExporter @@ -1 +1 @@ -Subproject commit 375489d5f1f5fa4b9144ac9669c411e3b149f32a +Subproject commit 854685155a6addaf72ec2415ac481a08ace9f9ce diff --git a/libultraship b/libultraship index 3d2b4da8e..7a88bfc08 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 3d2b4da8e327a6a096993996c5280c069a92c03f +Subproject commit 7a88bfc08cbe44fd682b8f6f66b9d32d44b699bc diff --git a/mm/2s2h/BenPort.cpp b/mm/2s2h/BenPort.cpp index a63e696ab..10a567c68 100644 --- a/mm/2s2h/BenPort.cpp +++ b/mm/2s2h/BenPort.cpp @@ -1080,6 +1080,25 @@ extern "C" size_t ResourceMgr_GetArraySizeByName(const char* path) { return res->Scalars.size(); } + +// Loads U8 data from an Array resource into an externally managed buffer, or mallocs a new buffer +// if the passed in a nullptr. This malloced buffer must be freed by the caller. +extern "C" u8* ResourceMgr_LoadArrayByNameAsU8(const char* path, u8* buffer) { + auto res = std::static_pointer_cast(GetResourceByName(path)); + + if (buffer == nullptr) { + buffer = (u8*)malloc(sizeof(u8) * res->Scalars.size()); + } + + for (size_t i = 0; i < res->Scalars.size(); i++) { + buffer[i] = res->Scalars[i].u8; + } + + return buffer; +} + +// Loads Vec3s data from an Array resource. +// mallocs a new buffer that must be freed by the caller. extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) { auto res = std::static_pointer_cast(GetResourceByName(path)); diff --git a/mm/2s2h/BenPort.h b/mm/2s2h/BenPort.h index 6aa243e42..81b5975b3 100644 --- a/mm/2s2h/BenPort.h +++ b/mm/2s2h/BenPort.h @@ -87,6 +87,7 @@ Gfx* ResourceMgr_LoadGfxByCRC(uint64_t crc); Gfx* ResourceMgr_LoadGfxByName(const char* path); void ResourceMgr_PatchGfxByName(const char* path, const char* patchName, int index, Gfx instruction); void ResourceMgr_UnpatchGfxByName(const char* path, const char* patchName); +u8* ResourceMgr_LoadArrayByNameAsU8(const char* path, u8* buffer); char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path); char* ResourceMgr_LoadArrayByName(const char* path); size_t ResourceMgr_GetArraySizeByName(const char* path); diff --git a/mm/2s2h/resource/importer/ArrayFactory.cpp b/mm/2s2h/resource/importer/ArrayFactory.cpp index 9772da149..5ed029e97 100644 --- a/mm/2s2h/resource/importer/ArrayFactory.cpp +++ b/mm/2s2h/resource/importer/ArrayFactory.cpp @@ -43,12 +43,34 @@ std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std: ScalarData data; switch (array->ArrayScalarType) { + case ScalarType::ZSCALAR_S8: + data.s8 = reader->ReadInt8(); + break; + case ScalarType::ZSCALAR_U8: + case ScalarType::ZSCALAR_X8: + data.u8 = reader->ReadUByte(); + break; case ScalarType::ZSCALAR_S16: data.s16 = reader->ReadInt16(); break; case ScalarType::ZSCALAR_U16: + case ScalarType::ZSCALAR_X16: data.u16 = reader->ReadUInt16(); break; + case ScalarType::ZSCALAR_S32: + data.s32 = reader->ReadInt32(); + break; + case ScalarType::ZSCALAR_U32: + case ScalarType::ZSCALAR_X32: + data.u32 = reader->ReadUInt32(); + break; + case ScalarType::ZSCALAR_S64: + data.s64 = reader->ReadInt64(); + break; + case ScalarType::ZSCALAR_U64: + case ScalarType::ZSCALAR_X64: + data.u64 = reader->ReadUInt64(); + break; default: // OTRTODO: IMPLEMENT OTHER TYPES! break; @@ -61,4 +83,4 @@ std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std: return array; } -} // namespace SOH \ No newline at end of file +} // namespace SOH diff --git a/mm/src/code/z_player_lib.c b/mm/src/code/z_player_lib.c index 71947ca65..e90fda727 100644 --- a/mm/src/code/z_player_lib.c +++ b/mm/src/code/z_player_lib.c @@ -2124,13 +2124,17 @@ void Player_DrawZoraShield(PlayState* play, Player* player) { f32 scale = player->unk_B62 * (10.0f / 51.0f); s32 i; + // 2S2H [Port] Graph allocated buffer to be used with ResourceMgr_LoadArrayByNameAsU8 to avoid + // needing to use malloc/free with Scalar based Array resources + u8* alphaU8Buffer = GRAPH_ALLOC(play->state.gfxCtx, 80 * sizeof(u8)); + OPEN_DISPS(play->state.gfxCtx); AnimatedMat_DrawXlu(play, Lib_SegmentedToVirtual(&object_link_zora_Matanimheader_012A80)); Matrix_Scale(scale, scale, scale, MTXMODE_APPLY); // clang-format off - vtx = ResourceMgr_LoadVtxByName(Lib_SegmentedToVirtual(&object_link_zora_Vtx_011210)); phi_a0 = (u8*)ResourceMgr_LoadArrayByName(Lib_SegmentedToVirtual(&object_link_zora_U8_011710)); + vtx = ResourceMgr_LoadVtxByName(Lib_SegmentedToVirtual(&object_link_zora_Vtx_011210)); phi_a0 = ResourceMgr_LoadArrayByNameAsU8(Lib_SegmentedToVirtual(&object_link_zora_U8_011710), alphaU8Buffer); // clang-format on // ARRAY_COUNT(object_link_zora_Vtx_011210)