fix zora magic shield alpha (#768)
Some checks failed
generate-builds / generate-2ship-otr (push) Failing after 0s
generate-builds / build-macos (push) Has been skipped
generate-builds / build-linux (push) Has been skipped
generate-builds / build-windows (push) Has been skipped

This commit is contained in:
Archez 2024-09-12 16:32:19 -04:00 committed by GitHub
parent a5059beaeb
commit 137ca0de12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 50 additions and 4 deletions

@ -1 +1 @@
Subproject commit 375489d5f1f5fa4b9144ac9669c411e3b149f32a
Subproject commit 854685155a6addaf72ec2415ac481a08ace9f9ce

@ -1 +1 @@
Subproject commit 3d2b4da8e327a6a096993996c5280c069a92c03f
Subproject commit 7a88bfc08cbe44fd682b8f6f66b9d32d44b699bc

View File

@ -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<SOH::Array>(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<SOH::Array>(GetResourceByName(path));

View File

@ -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);

View File

@ -43,12 +43,34 @@ std::shared_ptr<Ship::IResource> 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<Ship::IResource> ResourceFactoryBinaryArrayV0::ReadResource(std:
return array;
}
} // namespace SOH
} // namespace SOH

View File

@ -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)