From dfc51f4912777b5b17f401795bc04fbddeb1dc0d Mon Sep 17 00:00:00 2001 From: dbalatoni13 <40299962+dbalatoni13@users.noreply.github.com> Date: Fri, 11 Apr 2025 13:51:56 +0200 Subject: [PATCH] hsfload fixes --- extern/aurora | 2 +- include/game/hsfformat.h | 3 +++ include/port/byteswap.h | 15 +++++++++++++++ src/REL/bootDll/main.c | 5 +++-- src/game/hsfload.c | 40 +++++++++++++++++++++++++++++----------- src/port/byteswap.cpp | 31 +++++++++++++++++++++++++++++++ src/port/stubs.c | 10 +++++----- 7 files changed, 87 insertions(+), 19 deletions(-) diff --git a/extern/aurora b/extern/aurora index d9de6603..3b56e337 160000 --- a/extern/aurora +++ b/extern/aurora @@ -1 +1 @@ -Subproject commit d9de6603c79917a5353abd3a9cc26ec557ceee05 +Subproject commit 3b56e337c08a1dd4946c226298011364c319c7a2 diff --git a/include/game/hsfformat.h b/include/game/hsfformat.h index 7f356143..22ad98ab 100644 --- a/include/game/hsfformat.h +++ b/include/game/hsfformat.h @@ -350,6 +350,9 @@ typedef struct hsf_track { float value; void *data; }; +#ifdef TARGET_PC + void *dataTop; +#endif } HsfTrack; typedef struct hsf_motion { diff --git a/include/port/byteswap.h b/include/port/byteswap.h index aaf461b2..1d7549d9 100644 --- a/include/port/byteswap.h +++ b/include/port/byteswap.h @@ -215,6 +215,20 @@ typedef struct HsfBitmapKey32b { u32 data; } HsfBitmapKey32b; +typedef struct HsfFace32b { + s16 type; + s16 mat; + union { + struct { + s16 indices[3][4]; + u32 count; + u32 data; + } strip; + s16 indices[4][4]; + }; + Vec nbt; +} HsfFace32b; + void byteswap_u16(u16 *src); void byteswap_s16(s16 *src); void byteswap_u32(u32 *src); @@ -248,6 +262,7 @@ void byteswap_hsfobject(HsfObject32b *src, HsfObject *dest); void byteswap_hsfbitmapkey(HsfBitmapKey32b *src, HsfBitmapKey *dest); void byteswap_hsftrack(HsfTrack32b *src, HsfTrack *dest); void byteswap_hsfmotion(HsfMotion32b *src, HsfMotion *dest); +void byteswap_hsfface(HsfFace32b *src, HsfFace *dest); #ifdef __cplusplus } diff --git a/src/REL/bootDll/main.c b/src/REL/bootDll/main.c index 0617bb56..f6b09479 100644 --- a/src/REL/bootDll/main.c +++ b/src/REL/bootDll/main.c @@ -371,8 +371,10 @@ void ObjectSetup(void) s16 group; s16 sprite; AnimData *data; +#ifdef TARGET_PC + return; +#else option = 0; -#ifdef __MWERKS__ if (OSGetResetCode() != OS_RESET_RESTART) { return; } @@ -425,7 +427,6 @@ void ObjectSetup(void) HuPrcVSleep(); } #ifdef __MWERKS__ - // TODO PC if (!option) { OSSetProgressiveMode(OS_PROGRESSIVE_MODE_ON); VIConfigure(&GXNtsc480Prog); diff --git a/src/game/hsfload.c b/src/game/hsfload.c index f9809ea0..0a4882fd 100644 --- a/src/game/hsfload.c +++ b/src/game/hsfload.c @@ -272,7 +272,7 @@ static void MaterialLoad(void) new_mat->refAlpha = curr_mat->refAlpha; new_mat->unk2C = curr_mat->unk2C; new_mat->numAttrs = curr_mat->numAttrs; - new_mat->attrs = (s32 *)(NSymIndex+((uintptr_t)curr_mat->attrs)); + new_mat->attrs = (s32 *)(NSymIndex+((u32)curr_mat->attrs)); rgba[i].r = new_mat->litColor[0]; rgba[i].g = new_mat->litColor[1]; rgba[i].b = new_mat->litColor[2]; @@ -458,6 +458,14 @@ static void NormalLoad(void) new_normal->count = file_normal->count; new_normal->name = SetName((u32 *)&file_normal->name); new_normal->data = (void *)((uintptr_t)data+(uintptr_t)temp_data); +#ifdef TARGET_PC + if (cenv_count != 0) { + for (i = 0; i < new_normal->count; i++) { + HsfVector3f *normalData = &((HsfVector3f *)new_normal->data)[i]; + byteswap_hsfvec3f(normalData); + } + } +#endif } } } @@ -530,9 +538,10 @@ static void FaceLoad(void) if(head.face.count) { #ifdef TARGET_PC HsfBuffer32b *file_face_real = (HsfBuffer32b *)((uintptr_t)fileptr + head.face.ofs); + HsfFace32b *file_facedata_real = (HsfFace32b *)&file_face_real[head.face.count]; temp_face = file_face = FaceTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfBuffer) * head.face.count, MEMORY_DEFAULT_NUM); for (i = 0; i < head.face.count; i++) { - byteswap_hsfbuffer(&file_face[i], &file_face[i]); + byteswap_hsfbuffer(&file_face_real[i], &file_face[i]); } #else temp_face = file_face = (HsfBuffer *)((u32)fileptr+head.face.ofs); @@ -541,9 +550,7 @@ static void FaceLoad(void) new_face = temp_face; Model.face = new_face; Model.faceCnt = head.face.count; -#ifdef TARGET_PC - data = (void *)&file_face_real[head.face.count]; -#else +#ifdef __MWERKS__ file_face = (HsfBuffer *)((u32)fileptr+head.face.ofs); data = (HsfFace *)&file_face[head.face.count]; #endif @@ -551,22 +558,30 @@ static void FaceLoad(void) temp_data = file_face->data; new_face->name = SetName((u32 *)&file_face->name); new_face->count = file_face->count; +#ifdef TARGET_PC + { + HsfFace32b *facedata_start = (HsfFace32b *)((uintptr_t)file_facedata_real + (uintptr_t)temp_data); + data = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfFace) * new_face->count, MEMORY_DEFAULT_NUM); + for (j = 0; j < new_face->count; j++) { + byteswap_hsfface(&facedata_start[j], &data[j]); + } + new_face->data = data; + strip = (u8 *)(&facedata_start[new_face->count]); + } +#else new_face->data = (void *)((uintptr_t)data+(uintptr_t)temp_data); strip = (u8 *)(&((HsfFace *)new_face->data)[new_face->count]); +#endif } new_face = temp_face; for(i=0; i