From f31f250258674b76b8734e227cbe176c19ba06d9 Mon Sep 17 00:00:00 2001 From: dbalatoni13 <40299962+dbalatoni13@users.noreply.github.com> Date: Thu, 10 Apr 2025 01:09:20 +0200 Subject: [PATCH] Port some of hsfload.c --- include/game/hsfformat.h | 10 +- include/port/byteswap.h | 157 ++++++++++++++- src/game/ClusterExec.c | 54 ++--- src/game/hsfload.c | 335 +++++++++++++++++++++++++++---- src/game/hsfmotion.c | 371 +++++++++++++++++++++------------- src/port/byteswap.cpp | 419 ++++++++++++++++++++++++++++++++++++--- 6 files changed, 1118 insertions(+), 228 deletions(-) diff --git a/include/game/hsfformat.h b/include/game/hsfformat.h index 36c083a9..7f356143 100644 --- a/include/game/hsfformat.h +++ b/include/game/hsfformat.h @@ -227,9 +227,8 @@ typedef struct hsf_cluster { s32 target; }; HsfPart *part; - float unk10; - float unk14[1]; // unknown array size - u8 unk18[124]; + float index; + float weight[32]; // unknown array size u8 adjusted; u8 unk95; u16 type; @@ -261,7 +260,7 @@ typedef struct hsf_object_data { } mesh; struct hsf_object *replica; }; - + HsfBuffer *face; HsfBuffer *vertex; HsfBuffer *normal; @@ -397,6 +396,9 @@ typedef struct hsf_data { HsfObject *object; HsfMapAttr *mapAttr; HsfMatrix *matrix; +#ifdef TARGET_PC + void **symbol; +#endif s16 sceneCnt; s16 attributeCnt; s16 materialCnt; diff --git a/include/port/byteswap.h b/include/port/byteswap.h index 26286fab..09ee44e4 100644 --- a/include/port/byteswap.h +++ b/include/port/byteswap.h @@ -9,8 +9,149 @@ extern "C" #include "game/animdata.h" #include "game/hsfformat.h" +typedef struct HsfCluster32b { + u32 name[2]; + u32 targetName; + u32 part; + float index; + float weight[32]; + u8 adjusted; + u8 unk95; + u16 type; + u32 vertexCnt; + u32 vertex; +} HsfCluster32b; + +typedef struct HsfAttribute32b { + u32 name; + u32 unk04; + u8 unk8[4]; + float unk0C; + u8 unk10[4]; + float unk14; + u8 unk18[8]; + float unk20; + u8 unk24[4]; + float unk28; + float unk2C; + float unk30; + float unk34; + u8 unk38[44]; + u32 wrap_s; + u32 wrap_t; + u8 unk6C[12]; + u32 unk78; + u32 flag; + u32 bitmap; +} HsfAttribute32b; + +typedef struct HsfMaterial32b { + u32 name; + u8 unk4[4]; + u16 pass; + u8 vtxMode; + u8 litColor[3]; + u8 color[3]; + u8 shadowColor[3]; + float hilite_scale; + float unk18; + float invAlpha; + float unk20[2]; + float refAlpha; + float unk2C; + u32 flags; + u32 numAttrs; + u32 attrs; +} HsfMaterial32b; + +typedef struct HsfMapAttr32b { + float minX; + float minZ; + float maxX; + float maxZ; + u32 data; + u32 dataLen; +} HsfMapAttr32b; + +typedef struct HsfBuffer32b { + u32 name; + s32 count; + u32 data; +} HsfBuffer32b; + +typedef struct HsfPalette32b { + u32 name; + s32 unk; + u32 palSize; + u32 data; +} HsfPalette32b; + +typedef struct HsfBitmap32b { + u32 name; + u32 maxLod; + u8 dataFmt; + u8 pixSize; + s16 sizeX; + s16 sizeY; + s16 palSize; + GXColor tint; + u32 palData; + u32 unk; + u32 data; +} HsfBitmap32b; + +typedef struct HsfPart32b { + u32 name; + u32 count; + u32 vertex; +} HsfPart32b; + +typedef struct HsfSkeleton32b { + u32 name; + HsfTransform transform; +} HsfSkeleton32b; + +typedef struct HsfShape32b { + u32 name; + union { + u16 count16[2]; + u32 vertexCnt; + }; + u32 vertex; +} HsfShape32b; + +typedef struct HsfCenv32b { + u32 name; + u32 singleData; + u32 dualData; + u32 multiData; + u32 singleCount; + u32 dualCount; + u32 multiCount; + u32 vtxCount; + u32 copyCount; +} HsfCenv32b; + +typedef struct HsfObject32b { + u32 name; + u32 type; + u32 constData; + u32 flags; + // TODO PC + union { + HsfObjectData data; + HsfCamera camera; + HsfLight light; + }; +} HsfObject32b; + +void byteswap_u16(u16 *src); +void byteswap_s16(s16 *src); void byteswap_u32(u32 *src); void byteswap_s32(s32 *src); +void byteswap_hsfvec3f(HsfVector3f *src); +void byteswap_hsfvec2f(HsfVector2f *src); + void byteswap_animdata(void *src, AnimData* dest); void byteswap_animbankdata(void *src, AnimBankData *dest); void byteswap_animpatdata(void *src, AnimPatData *dest); @@ -18,8 +159,22 @@ void byteswap_animbmpdata(void *src, AnimBmpData *dest); void byteswap_animframedata(AnimFrameData *src); void byteswap_animlayerdata(AnimLayerData *src); - void byteswap_hsfheader(HsfHeader *src); +void byteswap_hsfcluster(HsfCluster32b *src, HsfCluster *dest); +void byteswap_hsfattribute(HsfAttribute32b *src, HsfAttribute *dest); +void byteswap_hsfmaterial(HsfMaterial32b *src, HsfMaterial *dest); +void byteswap_hsfscene(HsfScene *src); +void byteswap_hsfbuffer(HsfBuffer32b *src, HsfBuffer *dest); +void byteswap_hsfmatrix(HsfMatrix *src); +void byteswap_hsfpalette(HsfPalette32b *src, HsfPalette *dest); +void byteswap_hsfpart(HsfPart32b *src, HsfPart *dest); +void byteswap_hsfbitmap(HsfBitmap32b *src, HsfBitmap *dest); +void byteswap_hsfmapattr(HsfMapAttr32b *src, HsfMapAttr *dest); +void byteswap_hsfskeleton(HsfSkeleton32b *src, HsfSkeleton *dest); +void byteswap_hsfshape(HsfShape32b *src, HsfShape *dest); +void byteswap_hsfcenvsingle(HsfCenvSingle *src); +void byteswap_hsfcenv(HsfCenv32b *src, HsfCenv *dest); +void byteswap_hsfobject(HsfObject32b *src, HsfObject *dest); #ifdef __cplusplus } diff --git a/src/game/ClusterExec.c b/src/game/ClusterExec.c index 7a25f91d..eff1ded2 100644 --- a/src/game/ClusterExec.c +++ b/src/game/ClusterExec.c @@ -3,7 +3,8 @@ #include "game/hsfmotion.h" #include "game/sprite.h" -float GetClusterCurve(HsfTrack *arg0, float arg1) { +float GetClusterCurve(HsfTrack *arg0, float arg1) +{ float *var_r30; switch (arg0->curveType) { @@ -18,7 +19,8 @@ float GetClusterCurve(HsfTrack *arg0, float arg1) { return 0.0f; } -float GetClusterWeightCurve(HsfTrack *arg0, float arg1) { +float GetClusterWeightCurve(HsfTrack *arg0, float arg1) +{ float *var_r30; switch (arg0->curveType) { @@ -33,7 +35,8 @@ float GetClusterWeightCurve(HsfTrack *arg0, float arg1) { return 0.0f; } -void SetClusterMain(HsfCluster *arg0) { +void SetClusterMain(HsfCluster *arg0) +{ float var_f30; float var_f31; s32 temp_r24; @@ -53,51 +56,53 @@ void SetClusterMain(HsfCluster *arg0) { temp_r30 = *arg0->vertex; var_f30 = 0.0f; for (i = 0; i < arg0->vertexCnt; i++) { - var_f30 += arg0->unk14[i]; + var_f30 += arg0->weight[i]; } for (i = 0; i < temp_r27->count; i++, var_r28++) { temp_r29 = *var_r28; - Vertextop[temp_r29].x = ((Vec*) temp_r30->data)[i].x; - Vertextop[temp_r29].y = ((Vec*) temp_r30->data)[i].y; - Vertextop[temp_r29].z = ((Vec*) temp_r30->data)[i].z; + Vertextop[temp_r29].x = ((Vec *)temp_r30->data)[i].x; + Vertextop[temp_r29].y = ((Vec *)temp_r30->data)[i].y; + Vertextop[temp_r29].z = ((Vec *)temp_r30->data)[i].z; } for (i = 1; i < arg0->vertexCnt; i++) { temp_r30 = arg0->vertex[i]; var_r28 = temp_r27->vertex; - var_f31 = arg0->unk14[i]; + var_f31 = arg0->weight[i]; if (var_f31 < 0.0f) { var_f31 = 0.0f; - } else if (var_f30 > 1.0f) { + } + else if (var_f30 > 1.0f) { var_f31 /= var_f30; } for (j = 0; j < temp_r27->count; j++, var_r28++) { temp_r29 = *var_r28; - Vertextop[temp_r29].x += var_f31 * (((Vec*) temp_r30->data)[j].x - Vertextop[temp_r29].x); - Vertextop[temp_r29].y += var_f31 * (((Vec*) temp_r30->data)[j].y - Vertextop[temp_r29].y); - Vertextop[temp_r29].z += var_f31 * (((Vec*) temp_r30->data)[j].z - Vertextop[temp_r29].z); + Vertextop[temp_r29].x += var_f31 * (((Vec *)temp_r30->data)[j].x - Vertextop[temp_r29].x); + Vertextop[temp_r29].y += var_f31 * (((Vec *)temp_r30->data)[j].y - Vertextop[temp_r29].y); + Vertextop[temp_r29].z += var_f31 * (((Vec *)temp_r30->data)[j].z - Vertextop[temp_r29].z); } } return; } - temp_r24 = arg0->unk10; + temp_r24 = arg0->index; var_r23 = temp_r24 + 1; if (var_r23 >= arg0->vertexCnt) { var_r23 = temp_r24; } - var_f31 = arg0->unk10 - temp_r24; + var_f31 = arg0->index - temp_r24; temp_r30 = arg0->vertex[temp_r24]; temp_r25 = arg0->vertex[var_r23]; var_r28 = temp_r27->vertex; for (i = 0; i < temp_r27->count; i++, var_r28++) { temp_r29 = *var_r28; - Vertextop[temp_r29].x = ((Vec*) temp_r30->data)[i].x + var_f31 * (((Vec*) temp_r25->data)[i].x - ((Vec*) temp_r30->data)[i].x); - Vertextop[temp_r29].y = ((Vec*) temp_r30->data)[i].y + var_f31 * (((Vec*) temp_r25->data)[i].y - ((Vec*) temp_r30->data)[i].y); - Vertextop[temp_r29].z = ((Vec*) temp_r30->data)[i].z + var_f31 * (((Vec*) temp_r25->data)[i].z - ((Vec*) temp_r30->data)[i].z); + Vertextop[temp_r29].x = ((Vec *)temp_r30->data)[i].x + var_f31 * (((Vec *)temp_r25->data)[i].x - ((Vec *)temp_r30->data)[i].x); + Vertextop[temp_r29].y = ((Vec *)temp_r30->data)[i].y + var_f31 * (((Vec *)temp_r25->data)[i].y - ((Vec *)temp_r30->data)[i].y); + Vertextop[temp_r29].z = ((Vec *)temp_r30->data)[i].z + var_f31 * (((Vec *)temp_r25->data)[i].z - ((Vec *)temp_r30->data)[i].z); } } } -void ClusterProc(ModelData *arg0) { +void ClusterProc(ModelData *arg0) +{ s32 temp_r24; s32 i; s32 j; @@ -122,9 +127,9 @@ void ClusterProc(ModelData *arg0) { Vertextop = temp_r31->data.vertex->data; if (temp_r31->data.cenvCnt) { for (k = 0; k < temp_r31->data.vertex->count; k++) { - Vertextop[k].x = ((Vec*) temp_r31->data.file[0])[k].x; - Vertextop[k].y = ((Vec*) temp_r31->data.file[0])[k].y; - Vertextop[k].z = ((Vec*) temp_r31->data.file[0])[k].z; + Vertextop[k].x = ((Vec *)temp_r31->data.file[0])[k].x; + Vertextop[k].y = ((Vec *)temp_r31->data.file[0])[k].y; + Vertextop[k].z = ((Vec *)temp_r31->data.file[0])[k].z; } } SetClusterMain(var_r29); @@ -136,7 +141,8 @@ void ClusterProc(ModelData *arg0) { } } -void ClusterMotionExec(ModelData *arg0) { +void ClusterMotionExec(ModelData *arg0) +{ float temp_f31; s32 i; s32 j; @@ -161,12 +167,12 @@ void ClusterMotionExec(ModelData *arg0) { switch (var_r31->type) { case 5: temp_r26 = &temp_r28->cluster[var_r31->target_s16]; - temp_r26->unk10 = GetClusterCurve(var_r31, temp_f31); + temp_r26->index = GetClusterCurve(var_r31, temp_f31); break; case 6: var_r30 = var_r31; temp_r26 = &temp_r28->cluster[var_r30->target_s16]; - temp_r26->unk14[var_r30->unk04] = GetClusterCurve(var_r30, temp_f31); + temp_r26->weight[var_r30->unk04] = GetClusterCurve(var_r30, temp_f31); break; } } diff --git a/src/game/hsfload.c b/src/game/hsfload.c index d4472e0f..4830ba7a 100644 --- a/src/game/hsfload.c +++ b/src/game/hsfload.c @@ -3,6 +3,7 @@ #include "ctype.h" #ifdef TARGET_PC +#include "game/memory.h" #include "port/byteswap.h" #endif @@ -26,6 +27,15 @@ HsfBuffer *vtxtop; HsfCluster *ClusterTop; HsfAttribute *AttributeTop; HsfMaterial *MaterialTop; +#ifdef TARGET_PC +HsfBuffer *NormalTop; +HsfBuffer *StTop; +HsfBuffer *ColorTop; +HsfBuffer *FaceTop; +HsfCenv *CenvTop; +HsfPart *PartTop; +HsfBitmap *BitmapTop; +#endif static void FileLoad(void *data); static HsfData *SetHsfModel(void); @@ -118,17 +128,38 @@ void ClusterAdjustObject(HsfData *model, HsfData *src_model) static void FileLoad(void *data) { +#ifdef TARGET_PC + s32 i; +#endif fileptr = data; memcpy(&head, fileptr, sizeof(HsfHeader)); memset(&Model, 0, sizeof(HsfData)); #ifdef TARGET_PC byteswap_hsfheader(&head); -#endif + NSymIndex = HuMemDirectMallocNum(HEAP_DATA, sizeof(void*) * head.symbol.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.symbol.count; i++) { + byteswap_u32(&((void **)((uintptr_t)fileptr + head.symbol.ofs))[i]); + } + StringTable = (char *)((uintptr_t)fileptr+head.string.ofs); + ClusterTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfCluster) * head.cluster.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.cluster.count; i++) { + byteswap_hsfcluster(&((HsfCluster32b *)((uintptr_t)fileptr + head.cluster.ofs))[i], &ClusterTop[i]); + } + AttributeTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfAttribute) * head.attribute.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.attribute.count; i++) { + byteswap_hsfattribute(&((HsfAttribute32b *)((uintptr_t)fileptr + head.attribute.ofs))[i], &AttributeTop[i]); + } + MaterialTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfMaterial) * head.material.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.material.count; i++) { + byteswap_hsfmaterial(&((HsfMaterial32b *)((uintptr_t)fileptr + head.material.ofs))[i], &MaterialTop[i]); + } +#else NSymIndex = (void **)((uintptr_t)fileptr+head.symbol.ofs); StringTable = (char *)((uintptr_t)fileptr+head.string.ofs); ClusterTop = (HsfCluster *)((uintptr_t)fileptr+head.cluster.ofs); AttributeTop = (HsfAttribute *)((uintptr_t)fileptr + head.attribute.ofs); MaterialTop = (HsfMaterial *)((uintptr_t)fileptr + head.material.ofs); +#endif } static HsfData *SetHsfModel(void) @@ -173,6 +204,9 @@ static HsfData *SetHsfModel(void) data->shapeCnt = Model.shapeCnt; data->mapAttr = Model.mapAttr; data->mapAttrCnt = Model.mapAttrCnt; +#ifdef TARGET_PC + data->symbol = NSymIndex; +#endif return data; } @@ -193,7 +227,11 @@ static void MaterialLoad(void) s32 i; s32 j; if(head.material.count) { - HsfMaterial *file_mat = (HsfMaterial *)((u32)fileptr+head.material.ofs); +#ifdef TARGET_PC + HsfMaterial *file_mat = MaterialTop; +#else + HsfMaterial *file_mat = (HsfMaterial *)((uintptr_t)fileptr+head.material.ofs); +#endif HsfMaterial *curr_mat; HsfMaterial *new_mat; for(i=0; iname = SetName((u32 *)&curr_mat->name); @@ -225,13 +267,16 @@ 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+((u32)curr_mat->attrs)); + new_mat->attrs = (s32 *)(NSymIndex+((uintptr_t)curr_mat->attrs)); rgba[i].r = new_mat->litColor[0]; rgba[i].g = new_mat->litColor[1]; rgba[i].b = new_mat->litColor[2]; rgba[i].a = 255; for(j=0; jnumAttrs; j++) { +#ifdef __MWERKS__ + // TODO PC new_mat->attrs[j] = new_mat->attrs[j]; +#endif } } } @@ -244,7 +289,11 @@ static void AttributeLoad(void) HsfAttribute *temp_attr; s32 i; if(head.attribute.count) { +#ifdef TARGET_PC + temp_attr = file_attr = AttributeTop; +#else temp_attr = file_attr = (HsfAttribute *)((u32)fileptr+head.attribute.ofs); +#endif new_attr = temp_attr; Model.attribute = new_attr; Model.attributeCnt = head.attribute.count; @@ -261,10 +310,18 @@ static void AttributeLoad(void) static void SceneLoad(void) { +#ifdef TARGET_PC + s32 i; +#endif HsfScene *file_scene; HsfScene *new_scene; if(head.scene.count) { - file_scene = (HsfScene *)((u32)fileptr+head.scene.ofs); + file_scene = (HsfScene *)((uintptr_t)fileptr+head.scene.ofs); +#ifdef TARGET_PC + for (i = 0; i < head.scene.count; i++) { + byteswap_hsfscene(&file_scene[i]); + } +#endif new_scene = file_scene; new_scene->end = file_scene->end; new_scene->start = file_scene->start; @@ -283,18 +340,29 @@ static void ColorLoad(void) HsfBuffer *temp_color; if(head.color.count) { +#ifdef TARGET_PC + temp_color = file_color = ColorTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfBuffer) * head.color.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.color.count; i++) { + byteswap_hsfbuffer(&((HsfBuffer32b *)((uintptr_t)fileptr + head.color.ofs))[i], &file_color[i]); + } +#else temp_color = file_color = (HsfBuffer *)((u32)fileptr+head.color.ofs); data = &file_color[head.color.count]; for(i=0; idata; new_color->name = SetName((u32 *)&file_color->name); - new_color->data = (void *)((u32)data+(u32)color_data); + new_color->data = (void *)((uintptr_t)data+(uintptr_t)color_data); } } } @@ -309,25 +377,39 @@ static void VertexLoad(void) void *temp_data; if(head.vertex.count) { +#ifdef TARGET_PC + vtxtop = file_vertex = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfBuffer) * head.vertex.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.vertex.count; i++) { + byteswap_hsfbuffer(&((HsfBuffer32b *)((uintptr_t)fileptr + head.vertex.ofs))[i], &file_vertex[i]); + } +#else vtxtop = file_vertex = (HsfBuffer *)((u32)fileptr+head.vertex.ofs); data = (void *)&file_vertex[head.vertex.count]; for(i=0; icount; j++) { - data_elem = (HsfVector3f *)(((u32)data)+((u32)file_vertex->data)+(j*sizeof(HsfVector3f))); + data_elem = (HsfVector3f *)(((uintptr_t)data)+((uintptr_t)file_vertex->data)+(j*sizeof(HsfVector3f))); } } +#endif new_vertex = vtxtop; Model.vertex = new_vertex; Model.vertexCnt = head.vertex.count; +#ifdef TARGET_PC + VertexDataTop = data = (void *)&((HsfBuffer32b *)((uintptr_t)fileptr + head.vertex.ofs))[head.vertex.count]; +#else file_vertex = (HsfBuffer *)((u32)fileptr+head.vertex.ofs); VertexDataTop = data = (void *)&file_vertex[head.vertex.count]; +#endif for(i=0; idata; new_vertex->count = file_vertex->count; new_vertex->name = SetName((u32 *)&file_vertex->name); - new_vertex->data = (void *)((u32)data+(u32)temp_data); + new_vertex->data = (void *)((uintptr_t)data + (uintptr_t)temp_data); for(j=0; jcount; j++) { - data_elem = (HsfVector3f *)(((u32)data)+((u32)temp_data)+(j*sizeof(HsfVector3f))); + data_elem = (HsfVector3f *)((uintptr_t)data + (uintptr_t)temp_data + (j * sizeof(HsfVector3f))); +#ifdef TARGET_PC + byteswap_hsfvec3f(data_elem); +#endif ((HsfVector3f *)new_vertex->data)[j].x = data_elem->x; ((HsfVector3f *)new_vertex->data)[j].y = data_elem->y; ((HsfVector3f *)new_vertex->data)[j].z = data_elem->z; @@ -348,18 +430,29 @@ static void NormalLoad(void) if(head.normal.count) { s32 cenv_count = head.cenv.count; +#ifdef TARGET_PC + temp_normal = file_normal = NormalTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfBuffer) * head.normal.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.normal.count; i++) { + byteswap_hsfbuffer(&((HsfBuffer32b *)((uintptr_t)fileptr + head.normal.ofs))[i], &file_normal[i]); + } +#else temp_normal = file_normal = (HsfBuffer *)((u32)fileptr+head.normal.ofs); data = (void *)&file_normal[head.normal.count]; +#endif new_normal = temp_normal; Model.normal = new_normal; Model.normalCnt = head.normal.count; +#ifdef TARGET_PC + VertexDataTop = data = (void *)&((HsfBuffer32b *)((uintptr_t)fileptr + head.normal.ofs))[head.normal.count]; +#else file_normal = (HsfBuffer *)((u32)fileptr+head.normal.ofs); NormalDataTop = data = (void *)&file_normal[head.normal.count]; +#endif for(i=0; idata; new_normal->count = file_normal->count; new_normal->name = SetName((u32 *)&file_normal->name); - new_normal->data = (void *)((u32)data+(u32)temp_data); + new_normal->data = (void *)((uintptr_t)data+(uintptr_t)temp_data); } } } @@ -375,6 +468,12 @@ static void STLoad(void) void *temp_data; if(head.st.count) { +#ifdef TARGET_PC + temp_st = file_st = StTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfBuffer) * head.st.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.st.count; i++) { + byteswap_hsfbuffer(&((HsfBuffer32b *)((uintptr_t)fileptr + head.st.ofs))[i], &file_st[i]); + } +#else temp_st = file_st = (HsfBuffer *)((u32)fileptr+head.st.ofs); data = (void *)&file_st[head.st.count]; for(i=0; idata)+(j*sizeof(HsfVector2f))); } } +#endif new_st = temp_st; Model.st = new_st; Model.stCnt = head.st.count; +#ifdef TARGET_PC + data = (void *)&((HsfBuffer32b *)((uintptr_t)fileptr + head.st.ofs))[head.st.count]; +#else file_st = (HsfBuffer *)((u32)fileptr+head.st.ofs); data = (void *)&file_st[head.st.count]; +#endif for(i=0; idata; new_st->count = file_st->count; new_st->name = SetName((u32 *)&file_st->name); - new_st->data = (void *)((u32)data+(u32)temp_data); + new_st->data = (void *)((uintptr_t)data + (uintptr_t)temp_data); for(j=0; jcount; j++) { - data_elem = (HsfVector2f *)(((u32)data)+((u32)temp_data)+(j*sizeof(HsfVector2f))); + data_elem = (HsfVector2f *)((uintptr_t)data + (uintptr_t)temp_data + (j*sizeof(HsfVector2f))); +#ifdef TARGET_PC + byteswap_hsfvec2f(data_elem); +#endif ((HsfVector2f *)new_st->data)[j].x = data_elem->x; ((HsfVector2f *)new_st->data)[j].y = data_elem->y; } @@ -415,26 +522,48 @@ static void FaceLoad(void) s32 j; if(head.face.count) { +#ifdef TARGET_PC + 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(&((HsfBuffer32b *)((uintptr_t)fileptr + head.face.ofs))[i], &file_face[i]); + } +#else temp_face = file_face = (HsfBuffer *)((u32)fileptr+head.face.ofs); data = (HsfFace *)&file_face[head.face.count]; +#endif new_face = temp_face; Model.face = new_face; Model.faceCnt = head.face.count; +#ifdef TARGET_PC + data = (void *)&((HsfBuffer32b *)((uintptr_t)fileptr + head.face.ofs))[head.face.count]; +#else file_face = (HsfBuffer *)((u32)fileptr+head.face.ofs); data = (HsfFace *)&file_face[head.face.count]; +#endif for(i=0; idata; new_face->name = SetName((u32 *)&file_face->name); new_face->count = file_face->count; - new_face->data = (void *)((u32)data+(u32)temp_data); + new_face->data = (void *)((uintptr_t)data+(uintptr_t)temp_data); strip = (u8 *)(&((HsfFace *)new_face->data)[new_face->count]); } new_face = temp_face; for(i=0; idata; for(j=0; jcount; j++, new_face_strip++, file_face_strip++) { +#ifdef TARGET_PC + byteswap_s16(&file_face_strip->type); +#endif if(AS_U16(file_face_strip->type) == 4) { - new_face_strip->strip.data = (s16 *)(strip+(u32)file_face_strip->strip.data*(sizeof(s16)*4)); + new_face_strip->strip.data = (s16 *)(strip+(uintptr_t)file_face_strip->strip.data*(sizeof(s16)*4)); +#ifdef TARGET_PC + { + s32 k; + for (k = 0; k < new_face_strip->strip.count; k++) { + byteswap_s16(&new_face_strip->strip.data[k]); + } + } +#endif } } } @@ -495,8 +624,8 @@ static void DispObject(HsfObject *parent, HsfObject *object) } else { new_object->data.attribute = NULL; } - new_object->data.file[0] = (void *)((u32)fileptr+(u32)data->file[0]); - new_object->data.file[1] = (void *)((u32)fileptr+(u32)data->file[1]); + new_object->data.file[0] = (void *)((uintptr_t)fileptr+(u32)data->file[0]); + new_object->data.file[1] = (void *)((uintptr_t)fileptr+(u32)data->file[1]); new_object->data.base.pos.x = data->base.pos.x; new_object->data.base.pos.y = data->base.pos.y; new_object->data.base.pos.z = data->base.pos.z; @@ -691,7 +820,14 @@ static void ObjectLoad(void) s32 obj_type; if(head.object.count) { +#ifdef TARGET_PC + objtop = object = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfObject) * head.object.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.object.count; i++) { + byteswap_hsfobject(&((HsfObject32b *)((uintptr_t)fileptr + head.object.ofs))[i], &objtop[i]); + } +#else objtop = object = (HsfObject *)((u32)fileptr+head.object.ofs); +#endif for(i=0; iname = SetName((u32 *)&object->name); @@ -729,24 +865,36 @@ static void CenvLoad(void) s32 i; if(head.cenv.count) { +#ifdef TARGET_PC + cenv_file = CenvTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfCenv) * head.cenv.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.cenv.count; i++) { + byteswap_hsfcenv(&((HsfCenv32b *)((uintptr_t)fileptr + head.cenv.ofs))[i], &cenv_file[i]); + } + data_base = &((HsfCenv *)((uintptr_t)fileptr + head.cenv.ofs))[head.cenv.count]; +#else cenv_file = (HsfCenv *)((u32)fileptr+head.cenv.ofs); data_base = &cenv_file[head.cenv.count]; +#endif weight_base = data_base; cenv_new = cenv_file; Model.cenvCnt = head.cenv.count; Model.cenv = cenv_file; for(i=0; iname = SetName((u32 *)&part_file[i].name); part_new->count = part_file[i].count; - part_new->vertex = &data[(u32)part_file[i].vertex]; + part_new->vertex = &data[(uintptr_t)part_file[i].vertex]; for(j=0; jcount; j++) { part_new->vertex[j] = part_new->vertex[j]; +#ifdef TARGET_PC + byteswap_u16(&part_new->vertex[j]); +#endif } } } @@ -845,7 +1014,11 @@ static void ClusterLoad(void) s32 i, j; if(head.cluster.count) { +#ifdef TARGET_PC + cluster_new = cluster_file = ClusterTop; +#else cluster_new = cluster_file = (HsfCluster *)((u32)fileptr+head.cluster.ofs); +#endif Model.clusterCnt = head.cluster.count; Model.cluster = cluster_file; for(i=0; idata = &data[(u32)mapattr_file->data]; } @@ -925,14 +1116,25 @@ static void BitmapLoad(void) s32 i; if(head.bitmap.count) { +#ifdef TARGET_PC + bitmap_temp = bitmap_file = BitmapTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfBitmap) * head.bitmap.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.bitmap.count; i++) { + byteswap_hsfbitmap(&((HsfBitmap32b *)((uintptr_t)fileptr + head.bitmap.ofs))[i], &bitmap_file[i]); + } +#else bitmap_temp = bitmap_file = (HsfBitmap *)((u32)fileptr+head.bitmap.ofs); data = &bitmap_file[head.bitmap.count]; for(i=0; iname = SetName((u32 *)&bitmap_file->name); bitmap_new->dataFmt = bitmap_file->dataFmt; @@ -940,11 +1142,11 @@ static void BitmapLoad(void) bitmap_new->sizeX = bitmap_file->sizeX; bitmap_new->sizeY = bitmap_file->sizeY; bitmap_new->palSize = bitmap_file->palSize; - palette = SearchPalettePtr((u32)bitmap_file->palData); + palette = SearchPalettePtr((uintptr_t)bitmap_file->palData); if(palette) { bitmap_new->palData = palette->data; } - bitmap_new->data = (void *)((u32)data+(u32)bitmap_file->data); + bitmap_new->data = (void *)((uintptr_t)data+(uintptr_t)bitmap_file->data); } } } @@ -962,24 +1164,38 @@ static void PaletteLoad(void) u16 *data; if(head.palette.count) { +#ifdef TARGET_PC + palette_temp = palette_file = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfPalette) * head.palette.count, MEMORY_DEFAULT_NUM); + for (i = 0; i < head.palette.count; i++) { + byteswap_hsfpalette(&((HsfPalette32b *)((uintptr_t)fileptr + head.palette.ofs))[i], &palette_file[i]); + } +#else palette_temp = palette_file = (HsfPalette *)((u32)fileptr+head.palette.ofs); data_base = (u16 *)&palette_file[head.palette.count]; for(i=0; idata); + temp_data = (u16 *)((uintptr_t)data_base+(uintptr_t)palette_file->data); } +#endif Model.palette = palette_temp; Model.paletteCnt = head.palette.count; palette_new = palette_temp; +#ifdef TARGET_PC + data_base = (u16 *)&((HsfPalette32b *)((uintptr_t)fileptr + head.palette.ofs))[head.palette.count]; +#else palette_file = (HsfPalette *)((u32)fileptr+head.palette.ofs); data_base = (u16 *)&palette_file[head.palette.count]; +#endif for(i=0; idata); + temp_data = (u16 *)((uintptr_t)data_base+(uintptr_t)palette_file->data); data = temp_data; palette_new->name = SetName((u32 *)&palette_file->name); palette_new->data = data; palette_new->palSize = palette_file->palSize; for(j=0; jpalSize; j++) { data[j] = data[j]; +#ifdef TARGET_PC + byteswap_u16(&data[j]); +#endif } } } @@ -1344,7 +1560,7 @@ static void MotionLoad(void) MotionOnly = FALSE; MotionModel = NULL; if(head.motion.count) { - temp_motion = file_motion = (HsfMotion *)((u32)fileptr+head.motion.ofs); + temp_motion = file_motion = (HsfMotion *)((uintptr_t)fileptr+head.motion.ofs); new_motion = temp_motion; Model.motion = new_motion; Model.motionCnt = file_motion->numTracks; @@ -1410,8 +1626,13 @@ static void MatrixLoad(void) HsfMatrix *matrix_file; if(head.matrix.count) { - matrix_file = (HsfMatrix *)((u32)fileptr+head.matrix.ofs); +#ifdef TARGET_PC + matrix_file = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfMatrix) * head.matrix.count, MEMORY_DEFAULT_NUM); + byteswap_hsfmatrix((HsfMatrix *)((uintptr_t)fileptr + head.matrix.ofs)); +#else + matrix_file = (HsfMatrix *)((uintptr_t)fileptr+head.matrix.ofs); matrix_file->data = (Mtx *)((u32)fileptr+head.matrix.ofs+sizeof(HsfMatrix)); +#endif Model.matrix = matrix_file; Model.matrixCnt = head.matrix.count; } @@ -1436,7 +1657,11 @@ static HsfBuffer *SearchVertexPtr(s32 id) if(id == -1) { return NULL; } - vertex = (HsfBuffer *)((u32)fileptr+head.vertex.ofs); +#ifdef TARGET_PC + vertex = vtxtop; +#else + vertex = (HsfBuffer *)((uintptr_t)fileptr+head.vertex.ofs); +#endif vertex += id; return vertex; } @@ -1447,7 +1672,11 @@ static HsfBuffer *SearchNormalPtr(s32 id) if(id == -1) { return NULL; } - normal = (HsfBuffer *)((u32)fileptr+head.normal.ofs); +#ifdef TARGET_PC + normal = NormalTop; +#else + normal = (HsfBuffer *)((uintptr_t)fileptr+head.normal.ofs); +#endif normal += id; return normal; } @@ -1458,7 +1687,11 @@ static HsfBuffer *SearchStPtr(s32 id) if(id == -1) { return NULL; } - st = (HsfBuffer *)((u32)fileptr+head.st.ofs); +#ifdef TARGET_PC + st = StTop; +#else + st = (HsfBuffer *)((uintptr_t)fileptr+head.st.ofs); +#endif st += id; return st; } @@ -1469,7 +1702,11 @@ static HsfBuffer *SearchColorPtr(s32 id) if(id == -1) { return NULL; } - color = (HsfBuffer *)((u32)fileptr+head.color.ofs); +#ifdef TARGET_PC + color = ColorTop; +#else + color = (HsfBuffer *)((uintptr_t)fileptr+head.color.ofs); +#endif color += id; return color; } @@ -1480,7 +1717,11 @@ static HsfBuffer *SearchFacePtr(s32 id) if(id == -1) { return NULL; } - face = (HsfBuffer *)((u32)fileptr+head.face.ofs); +#ifdef TARGET_PC + face = FaceTop; +#else + face = (HsfBuffer *)((uintptr_t)fileptr+head.face.ofs); +#endif face += id; return face; } @@ -1491,7 +1732,11 @@ static HsfCenv *SearchCenvPtr(s32 id) if(id == -1) { return NULL; } - cenv = (HsfCenv *)((u32)fileptr+head.cenv.ofs); +#ifdef TARGET_PC + cenv = CenvTop; +#else + cenv = (HsfCenv *)((uintptr_t)fileptr + head.cenv.ofs); +#endif cenv += id; return cenv; } @@ -1502,7 +1747,11 @@ static HsfPart *SearchPartPtr(s32 id) if(id == -1) { return NULL; } - part = (HsfPart *)((u32)fileptr+head.part.ofs); +#ifdef TARGET_PC + part = PartTop; +#else + part = (HsfPart *)((uintptr_t)fileptr+head.part.ofs); +#endif part += id; return part; } @@ -1524,7 +1773,11 @@ static HsfBitmap *SearchBitmapPtr(s32 id) if(id == -1) { return NULL; } - bitmap = (HsfBitmap *)((u32)fileptr+head.bitmap.ofs); +#ifdef TARGET_PC + bitmap = BitmapTop; +#else + bitmap = (HsfBitmap *)((uintptr_t)fileptr+head.bitmap.ofs); +#endif bitmap += id; return bitmap; } @@ -1539,4 +1792,4 @@ static char *GetMotionString(u16 *str_ofs) { char *ret = &StringTable[*str_ofs]; return ret; -} \ No newline at end of file +} diff --git a/src/game/hsfmotion.c b/src/game/hsfmotion.c index 010b5fb1..68dc376d 100644 --- a/src/game/hsfmotion.c +++ b/src/game/hsfmotion.c @@ -1,18 +1,19 @@ #include "game/hsfmotion.h" #include "game/ClusterExec.h" #include "game/EnvelopeExec.h" +#include "game/ShapeExec.h" #include "game/hsfdraw.h" #include "game/hsfload.h" #include "game/hsfman.h" #include "game/init.h" -#include "game/ShapeExec.h" + #include "ext_math.h" #include "string.h" -#define HU3D_MOTATTR_SHIFT_ALL (HU3D_MOTATTR_SHIFT_LOOP|HU3D_MOTATTR_SHIFT_PAUSE|HU3D_MOTATTR_SHIFT_REV) -#define HU3D_MOTATTR_NOSHIFT_ALL (HU3D_MOTATTR_LOOP|HU3D_MOTATTR_PAUSE|HU3D_MOTATTR_REV) -#define HU3D_MOTATTR_ALL (HU3D_MOTATTR_SHIFT_ALL|HU3D_MOTATTR_NOSHIFT_ALL) +#define HU3D_MOTATTR_SHIFT_ALL (HU3D_MOTATTR_SHIFT_LOOP | HU3D_MOTATTR_SHIFT_PAUSE | HU3D_MOTATTR_SHIFT_REV) +#define HU3D_MOTATTR_NOSHIFT_ALL (HU3D_MOTATTR_LOOP | HU3D_MOTATTR_PAUSE | HU3D_MOTATTR_REV) +#define HU3D_MOTATTR_ALL (HU3D_MOTATTR_SHIFT_ALL | HU3D_MOTATTR_NOSHIFT_ALL) static s32 SearchObjectIndex(HsfData *arg0, u32 arg1); static s32 SearchAttributeIndex(HsfData *arg0, u32 arg1); @@ -21,17 +22,19 @@ MotionData Hu3DMotion[HU3D_MOTION_MAX]; static HsfBitmap *bitMapPtr; -void Hu3DMotionInit(void) { +void Hu3DMotionInit(void) +{ MotionData *var_r31; s16 i; - var_r31 = (MotionData*) Hu3DData; + var_r31 = (MotionData *)Hu3DData; for (i = 0; i < HU3D_MOTION_MAX; i++, var_r31++) { var_r31->unk_04 = 0; } } -s16 Hu3DMotionCreate(void *arg0) { +s16 Hu3DMotionCreate(void *arg0) +{ MotionData *var_r31; s16 i; @@ -51,7 +54,8 @@ s16 Hu3DMotionCreate(void *arg0) { return i; } -s16 Hu3DMotionModelCreate(s16 arg0) { +s16 Hu3DMotionModelCreate(s16 arg0) +{ ModelData *temp_r29 = &Hu3DData[arg0]; MotionData *var_r31; s16 i; @@ -73,7 +77,8 @@ s16 Hu3DMotionModelCreate(s16 arg0) { return i; } -s32 Hu3DMotionKill(s16 arg0) { +s32 Hu3DMotionKill(s16 arg0) +{ ModelData *var_r30; MotionData *temp_r31; s16 i; @@ -93,14 +98,16 @@ s32 Hu3DMotionKill(s16 arg0) { } if (temp_r31->unk_02 == -1) { HuMemDirectFree(temp_r31->unk_04); - } else { + } + else { Hu3DData[temp_r31->unk_02].unk_20 = -1; } temp_r31->unk_04 = NULL; return 1; } -void Hu3DMotionAllKill(void) { +void Hu3DMotionAllKill(void) +{ MotionData *var_r27; s16 i; @@ -112,7 +119,8 @@ void Hu3DMotionAllKill(void) { } } -void Hu3DMotionSet(s16 arg0, s16 arg1) { +void Hu3DMotionSet(s16 arg0, s16 arg1) +{ Hu3DData[arg0].unk_0C = -1; Hu3DData[arg0].unk_08 = arg1; Hu3DData[arg0].unk_64 = 0.0f; @@ -120,29 +128,35 @@ void Hu3DMotionSet(s16 arg0, s16 arg1) { Hu3DData[arg0].unk_70 = Hu3DMotionMaxTimeGet(arg0); } -void Hu3DMotionOverlaySet(s16 arg0, s16 arg1) { +void Hu3DMotionOverlaySet(s16 arg0, s16 arg1) +{ Hu3DData[arg0].unk_0A = arg1; Hu3DData[arg0].unk_74 = 0.0f; Hu3DData[arg0].unk_78 = 1.0f; } -void Hu3DMotionOverlayReset(s16 arg0) { +void Hu3DMotionOverlayReset(s16 arg0) +{ Hu3DData[arg0].unk_0A = -1; } -float Hu3DMotionOverlayTimeGet(s16 arg0) { +float Hu3DMotionOverlayTimeGet(s16 arg0) +{ return Hu3DData[arg0].unk_74; } -void Hu3DMotionOverlayTimeSet(s16 arg0, float arg1) { +void Hu3DMotionOverlayTimeSet(s16 arg0, float arg1) +{ Hu3DData[arg0].unk_74 = arg1; } -void Hu3DMotionOverlaySpeedSet(s16 arg0, float arg1) { +void Hu3DMotionOverlaySpeedSet(s16 arg0, float arg1) +{ Hu3DData[arg0].unk_78 = arg1; } -void Hu3DMotionShiftSet(s16 arg0, s16 arg1, float arg2, float arg3, u32 arg4) { +void Hu3DMotionShiftSet(s16 arg0, s16 arg1, float arg2, float arg3, u32 arg4) +{ ModelData *temp_r31 = &Hu3DData[arg0]; MotionData *sp10 = &Hu3DMotion[arg1]; s32 var_r30; @@ -167,7 +181,8 @@ void Hu3DMotionShiftSet(s16 arg0, s16 arg1, float arg2, float arg3, u32 arg4) { temp_r31->motion_attr &= ~HU3D_MOTATTR_ALL; temp_r31->motion_attr |= var_r30; temp_r31->motion_attr &= ~HU3D_MOTATTR; - } else { + } + else { temp_r31->motion_attr &= ~HU3D_MOTATTR_SHIFT_ALL; } temp_r31->unk_0C = arg1; @@ -191,7 +206,8 @@ void Hu3DMotionShiftSet(s16 arg0, s16 arg1, float arg2, float arg3, u32 arg4) { temp_r31->motion_attr &= ~HU3D_MOTATTR; } -void Hu3DMotionShapeSet(s16 arg0, s16 arg1) { +void Hu3DMotionShapeSet(s16 arg0, s16 arg1) +{ Hu3DData[arg0].unk_0E = arg1; Hu3DData[arg0].unk_94 = 0.0f; Hu3DData[arg0].unk_98 = 1.0f; @@ -199,34 +215,40 @@ void Hu3DMotionShapeSet(s16 arg0, s16 arg1) { Hu3DData[arg0].unk_A0 = Hu3DMotionShapeMaxTimeGet(arg0); } -s16 Hu3DMotionShapeIDGet(s16 arg0) { +s16 Hu3DMotionShapeIDGet(s16 arg0) +{ return Hu3DData[arg0].unk_0E; } -void Hu3DMotionShapeSpeedSet(s16 arg0, float arg1) { +void Hu3DMotionShapeSpeedSet(s16 arg0, float arg1) +{ ModelData *temp_r31 = &Hu3DData[arg0]; temp_r31->unk_98 = arg1; } -void Hu3DMotionShapeTimeSet(s16 arg0, float arg1) { +void Hu3DMotionShapeTimeSet(s16 arg0, float arg1) +{ Hu3DData[arg0].unk_94 = arg1; } -float Hu3DMotionShapeMaxTimeGet(s16 arg0) { +float Hu3DMotionShapeMaxTimeGet(s16 arg0) +{ ModelData *temp_r31 = &Hu3DData[arg0]; return Hu3DMotionMotionMaxTimeGet(temp_r31->unk_0E); } -void Hu3DMotionShapeStartEndSet(s16 arg0, float arg1, float arg2) { +void Hu3DMotionShapeStartEndSet(s16 arg0, float arg1, float arg2) +{ ModelData *temp_r31 = &Hu3DData[arg0]; temp_r31->unk_9C = arg1; temp_r31->unk_A0 = arg2; } -s16 Hu3DMotionClusterSet(s16 arg0, s16 arg1) { +s16 Hu3DMotionClusterSet(s16 arg0, s16 arg1) +{ ModelData *temp_r31 = &Hu3DData[arg0]; s16 i; @@ -245,7 +267,8 @@ s16 Hu3DMotionClusterSet(s16 arg0, s16 arg1) { return -1; } -s16 Hu3DMotionClusterNoSet(s16 arg0, s16 arg1, s16 arg2) { +s16 Hu3DMotionClusterNoSet(s16 arg0, s16 arg1, s16 arg2) +{ ModelData *temp_r31 = &Hu3DData[arg0]; Hu3DMotionClusterReset(arg0, arg2); @@ -257,11 +280,13 @@ s16 Hu3DMotionClusterNoSet(s16 arg0, s16 arg1, s16 arg2) { return arg2; } -void Hu3DMotionShapeReset(s16 arg0) { +void Hu3DMotionShapeReset(s16 arg0) +{ Hu3DData[arg0].unk_0E = -1; } -void Hu3DMotionClusterReset(s16 arg0, s16 arg1) { +void Hu3DMotionClusterReset(s16 arg0, s16 arg1) +{ ModelData *temp_r31 = &Hu3DData[arg0]; s16 i; @@ -270,7 +295,8 @@ void Hu3DMotionClusterReset(s16 arg0, s16 arg1) { temp_r31->unk_10[i] = -1; } temp_r31->attr &= ~HU3D_ATTR_CLUSTER_ON; - } else { + } + else { temp_r31->unk_10[arg1] = -1; for (i = 0; i < 4; i++) { if (temp_r31->unk_10[i] != -1) { @@ -281,19 +307,22 @@ void Hu3DMotionClusterReset(s16 arg0, s16 arg1) { } } -s16 Hu3DMotionIDGet(s16 arg0) { +s16 Hu3DMotionIDGet(s16 arg0) +{ ModelData *temp_r31 = &Hu3DData[arg0]; return temp_r31->unk_08; } -s16 Hu3DMotionShiftIDGet(s16 arg0) { +s16 Hu3DMotionShiftIDGet(s16 arg0) +{ ModelData *temp_r31 = &Hu3DData[arg0]; return temp_r31->unk_0C; } -void Hu3DMotionTimeSet(s16 arg0, float arg1) { +void Hu3DMotionTimeSet(s16 arg0, float arg1) +{ ModelData *temp_r31 = &Hu3DData[arg0]; if (Hu3DMotionMaxTimeGet(arg0) <= arg1) { @@ -303,7 +332,7 @@ void Hu3DMotionTimeSet(s16 arg0, float arg1) { arg1 = 0.0f; } temp_r31->unk_64 = arg1; - if (temp_r31->hsfData != (HsfData*) -1 && temp_r31->hsfData->cenvCnt != 0 && (temp_r31->motion_attr & HU3D_MOTATTR_PAUSE)) { + if (temp_r31->hsfData != (HsfData *)-1 && temp_r31->hsfData->cenvCnt != 0 && (temp_r31->motion_attr & HU3D_MOTATTR_PAUSE)) { Hu3DMotionExec(arg0, temp_r31->unk_08, arg1, 0); if (temp_r31->unk_0C != -1) { Hu3DSubMotionExec(arg0); @@ -312,19 +341,22 @@ void Hu3DMotionTimeSet(s16 arg0, float arg1) { } } -float Hu3DMotionTimeGet(s16 arg0) { +float Hu3DMotionTimeGet(s16 arg0) +{ ModelData *temp_r31 = &Hu3DData[arg0]; return temp_r31->unk_64; } -float Hu3DMotionShiftTimeGet(s16 arg0) { +float Hu3DMotionShiftTimeGet(s16 arg0) +{ ModelData *temp_r31 = &Hu3DData[arg0]; return temp_r31->unk_84; } -float Hu3DMotionMaxTimeGet(s16 arg0) { +float Hu3DMotionMaxTimeGet(s16 arg0) +{ ModelData *temp_r31 = &Hu3DData[arg0]; MotionData *temp_r30; HsfMotion *temp_r29; @@ -339,7 +371,8 @@ float Hu3DMotionMaxTimeGet(s16 arg0) { return temp_r28; } -float Hu3DMotionShiftMaxTimeGet(s16 arg0) { +float Hu3DMotionShiftMaxTimeGet(s16 arg0) +{ ModelData *temp_r31 = &Hu3DData[arg0]; MotionData *temp_r30; HsfMotion *temp_r29; @@ -354,14 +387,16 @@ float Hu3DMotionShiftMaxTimeGet(s16 arg0) { return temp_r28; } -void Hu3DMotionShiftStartEndSet(s16 arg0, float arg1, float arg2) { +void Hu3DMotionShiftStartEndSet(s16 arg0, float arg1, float arg2) +{ ModelData *temp_r31 = &Hu3DData[arg0]; temp_r31->unk_8C = arg1; temp_r31->unk_90 = arg2; } -float Hu3DMotionMotionMaxTimeGet(s16 arg0) { +float Hu3DMotionMotionMaxTimeGet(s16 arg0) +{ MotionData *temp_r31 = &Hu3DMotion[arg0]; HsfMotion *temp_r30; s16 temp_r29; @@ -374,41 +409,48 @@ float Hu3DMotionMotionMaxTimeGet(s16 arg0) { return temp_r29; } -void Hu3DMotionStartEndSet(s16 arg0, float arg1, float arg2) { +void Hu3DMotionStartEndSet(s16 arg0, float arg1, float arg2) +{ ModelData *temp_r31 = &Hu3DData[arg0]; temp_r31->unk_6C = arg1; temp_r31->unk_70 = arg2; } -s32 Hu3DMotionEndCheck(s16 arg0) { +s32 Hu3DMotionEndCheck(s16 arg0) +{ if (!(Hu3DData[arg0].motion_attr & HU3D_MOTATTR_REV)) { return (Hu3DMotionMaxTimeGet(arg0) <= Hu3DMotionTimeGet(arg0)); - } else { + } + else { return (Hu3DMotionTimeGet(arg0) <= 0.0f); } } -void Hu3DMotionSpeedSet(s16 arg0, float arg1) { +void Hu3DMotionSpeedSet(s16 arg0, float arg1) +{ ModelData *temp_r31 = &Hu3DData[arg0]; temp_r31->unk_68 = arg1; } -void Hu3DMotionShiftSpeedSet(s16 arg0, float arg1) { +void Hu3DMotionShiftSpeedSet(s16 arg0, float arg1) +{ ModelData *temp_r31 = &Hu3DData[arg0]; temp_r31->unk_88 = arg1; } -void Hu3DMotionNoMotSet(s16 arg0, char *arg1, u32 arg2) { +void Hu3DMotionNoMotSet(s16 arg0, char *arg1, u32 arg2) +{ HsfConstData *var_r29; HsfObject *temp_r3; temp_r3 = Hu3DModelObjPtrGet(arg0, arg1); if (temp_r3->constData == 0) { - var_r29 = ObjConstantMake(temp_r3, (u32) Hu3DData[arg0].unk_48); - } else { + var_r29 = ObjConstantMake(temp_r3, (u32)Hu3DData[arg0].unk_48); + } + else { var_r29 = temp_r3->constData; } var_r29->flags |= arg2; @@ -432,7 +474,8 @@ void Hu3DMotionNoMotSet(s16 arg0, char *arg1, u32 arg2) { } } -void Hu3DMotionNoMotReset(s16 arg0, char *arg1, u32 arg2) { +void Hu3DMotionNoMotReset(s16 arg0, char *arg1, u32 arg2) +{ HsfObject *temp_r31; HsfConstData *temp_r30; @@ -441,14 +484,16 @@ void Hu3DMotionNoMotReset(s16 arg0, char *arg1, u32 arg2) { temp_r30->flags &= ~arg2; } -void Hu3DMotionForceSet(s16 arg0, char *arg1, u32 arg2, float arg3) { +void Hu3DMotionForceSet(s16 arg0, char *arg1, u32 arg2, float arg3) +{ HsfConstData *var_r29; HsfObject *temp_r3; temp_r3 = Hu3DModelObjPtrGet(arg0, arg1); if (temp_r3->constData == 0) { - var_r29 = ObjConstantMake(temp_r3, (u32) Hu3DData[arg0].unk_48); - } else { + var_r29 = ObjConstantMake(temp_r3, (u32)Hu3DData[arg0].unk_48); + } + else { var_r29 = temp_r3->constData; } var_r29->flags |= arg2; @@ -472,7 +517,8 @@ void Hu3DMotionForceSet(s16 arg0, char *arg1, u32 arg2, float arg3) { } } -void Hu3DMotionNext(s16 arg0) { +void Hu3DMotionNext(s16 arg0) +{ ModelData *temp_r31 = &Hu3DData[arg0]; HsfMotion *temp_r29; MotionData *temp_r27; @@ -487,18 +533,22 @@ void Hu3DMotionNext(s16 arg0) { if (!(temp_r28 & HU3D_MOTATTR_PAUSE)) { if (!(temp_r28 & HU3D_MOTATTR_REV)) { temp_r31->unk_64 += temp_r31->unk_68 * minimumVcountf; - } else { + } + else { temp_r31->unk_64 -= temp_r31->unk_68 * minimumVcountf; } if (temp_r28 & HU3D_MOTATTR_LOOP) { if (temp_r31->unk_64 < temp_r31->unk_6C) { temp_r31->unk_64 = temp_r31->unk_70 - (temp_r31->unk_6C - temp_r31->unk_64); - } else if (temp_r31->unk_64 >= temp_r31->unk_70) { + } + else if (temp_r31->unk_64 >= temp_r31->unk_70) { temp_r31->unk_64 = temp_r31->unk_6C + (temp_r31->unk_64 - temp_r31->unk_70); } - } else if (temp_r31->unk_64 < 0.0f) { + } + else if (temp_r31->unk_64 < 0.0f) { temp_r31->unk_64 = 0.0f; - } else if (temp_r31->unk_64 >= temp_r31->unk_70) { + } + else if (temp_r31->unk_64 >= temp_r31->unk_70) { temp_r31->unk_64 = temp_r31->unk_70; } } @@ -509,18 +559,22 @@ void Hu3DMotionNext(s16 arg0) { if (!(temp_r28 & HU3D_MOTATTR_OVL_PAUSE)) { if (!(temp_r28 & HU3D_MOTATTR_OVL_REV)) { temp_r31->unk_74 += temp_r31->unk_78 * minimumVcountf; - } else { + } + else { temp_r31->unk_74 -= temp_r31->unk_78 * minimumVcountf; } if (temp_r28 & HU3D_MOTATTR_OVL_LOOP) { if (temp_r31->unk_74 < 0.0f) { temp_r31->unk_74 = temp_r29->len; - } else if (temp_r31->unk_74 >= temp_r29->len) { + } + else if (temp_r31->unk_74 >= temp_r29->len) { temp_r31->unk_74 = 0.0f; } - } else if (temp_r31->unk_74 < 0.0f) { + } + else if (temp_r31->unk_74 < 0.0f) { temp_r31->unk_74 = 0.0f; - } else if (temp_r31->unk_74 >= temp_r29->len) { + } + else if (temp_r31->unk_74 >= temp_r29->len) { temp_r31->unk_74 = temp_r29->len; } } @@ -553,18 +607,22 @@ void Hu3DMotionNext(s16 arg0) { temp_r27 = &Hu3DMotion[temp_r31->unk_0C]; if (!(temp_r31->motion_attr & HU3D_MOTATTR_SHIFT_REV)) { temp_r31->unk_84 += temp_r31->unk_88 * minimumVcountf; - } else { + } + else { temp_r31->unk_84 -= temp_r31->unk_88 * minimumVcountf; } if (temp_r31->motion_attr & HU3D_MOTATTR_SHIFT_LOOP) { if (temp_r31->unk_84 < temp_r31->unk_8C) { temp_r31->unk_84 = temp_r31->unk_90; - } else if (temp_r31->unk_84 >= temp_r31->unk_90) { + } + else if (temp_r31->unk_84 >= temp_r31->unk_90) { temp_r31->unk_84 = temp_r31->unk_8C; } - } else if (temp_r31->unk_84 < temp_r31->unk_8C) { + } + else if (temp_r31->unk_84 < temp_r31->unk_8C) { temp_r31->unk_84 = temp_r31->unk_8C; - } else if (temp_r31->unk_84 >= temp_r31->unk_90) { + } + else if (temp_r31->unk_84 >= temp_r31->unk_90) { temp_r31->unk_84 = temp_r31->unk_90; } } @@ -574,18 +632,22 @@ void Hu3DMotionNext(s16 arg0) { temp_r29 = temp_r27->unk_04->motion; if (!(temp_r28 & HU3D_MOTATTR_SHAPE_REV)) { temp_r31->unk_94 += temp_r31->unk_98 * minimumVcountf; - } else { + } + else { temp_r31->unk_94 -= temp_r31->unk_98 * minimumVcountf; } if (temp_r28 & HU3D_MOTATTR_SHAPE_LOOP) { if (temp_r31->unk_94 < temp_r31->unk_9C) { temp_r31->unk_94 = temp_r31->unk_A0; - } else if (temp_r31->unk_94 >= temp_r31->unk_A0) { + } + else if (temp_r31->unk_94 >= temp_r31->unk_A0) { temp_r31->unk_94 = temp_r31->unk_9C; } - } else if (temp_r31->unk_94 < temp_r31->unk_9C) { + } + else if (temp_r31->unk_94 < temp_r31->unk_9C) { temp_r31->unk_94 = temp_r31->unk_9C; - } else if (temp_r31->unk_94 >= temp_r31->unk_A0) { + } + else if (temp_r31->unk_94 >= temp_r31->unk_A0) { temp_r31->unk_94 = temp_r31->unk_A0; } } @@ -596,18 +658,22 @@ void Hu3DMotionNext(s16 arg0) { temp_r29 = temp_r27->unk_04->motion; if (!(temp_r31->cluster_attr[i] & HU3D_CLUSTER_ATTR_REV)) { temp_r31->unk_A4[i] += temp_r31->unk_B4[i] * minimumVcountf; - } else { + } + else { temp_r31->unk_A4[i] -= temp_r31->unk_B4[i] * minimumVcountf; } if (temp_r31->cluster_attr[i] & HU3D_CLUSTER_ATTR_LOOP) { if (temp_r31->unk_A4[i] < 0.0f) { temp_r31->unk_A4[i] = temp_r29->len; - } else if (temp_r31->unk_A4[i] >= temp_r29->len) { + } + else if (temp_r31->unk_A4[i] >= temp_r29->len) { temp_r31->unk_A4[i] = 0.0f; } - } else if (temp_r31->unk_A4[i] < 0.0f) { + } + else if (temp_r31->unk_A4[i] < 0.0f) { temp_r31->unk_A4[i] = 0.0f; - } else if (temp_r31->unk_A4[i] >= temp_r29->len) { + } + else if (temp_r31->unk_A4[i] >= temp_r29->len) { temp_r31->unk_A4[i] = temp_r29->len; } } @@ -615,7 +681,8 @@ void Hu3DMotionNext(s16 arg0) { } } -void Hu3DMotionExec(s16 arg0, s16 arg1, float arg2, s32 arg3) { +void Hu3DMotionExec(s16 arg0, s16 arg1, float arg2, s32 arg3) +{ MotionData *sp18; HsfData *sp14; HsfTrack *sp10; @@ -666,10 +733,12 @@ void Hu3DMotionExec(s16 arg0, s16 arg1, float arg2, s32 arg3) { if (!(temp_r24 & 0x200)) { temp_r31->data.curr.rot.z = temp_r31->data.base.rot.z; } - } else { + } + else { temp_r31->data.curr = temp_r31->data.base; } - } else { + } + else { temp_r31->data.curr = temp_r31->data.base; } } @@ -682,33 +751,40 @@ void Hu3DMotionExec(s16 arg0, s16 arg1, float arg2, s32 arg3) { temp_r31 = &temp_r29->object[var_r30->target]; if (var_r30->channel == 0x28) { temp_r31->data.mesh.baseMorph = GetCurve(var_r30, arg2); - } else if (temp_r31->type == 7) { + } + else if (temp_r31->type == 7) { if (temp_r27->attr & HU3D_ATTR_CAMERA_MOTON) { SetObjCameraMotion(arg0, var_r30, GetCurve(var_r30, arg2)); } - } else if (temp_r31->type == 8) { + } + else if (temp_r31->type == 8) { SetObjLightMotion(arg0, var_r30, GetCurve(var_r30, arg2)); - } else if (var_r30->channel == 0x18) { + } + else if (var_r30->channel == 0x18) { if (temp_r31->constData) { temp_r28 = temp_r31->constData; if (GetCurve(var_r30, arg2) == 1.0f) { temp_r28->flags &= ~0x1000; - } else { + } + else { temp_r28->flags |= 0x1000; } } - } else if (var_r30->channel == 0x1A) { + } + else if (var_r30->channel == 0x1A) { if (temp_r31->constData) { temp_r28 = temp_r31->constData; if (GetCurve(var_r30, arg2) == 1.0f) { temp_r28->flags &= ~0x2000; - } else { + } + else { temp_r28->flags |= 0x2000; } } - } else { + } + else { temp_r17 = GetObjTRXPtr(temp_r31, var_r30->channel); - if (temp_r17 != (float*) -1) { + if (temp_r17 != (float *)-1) { *temp_r17 = GetCurve(var_r30, arg2); } } @@ -731,14 +807,14 @@ void Hu3DMotionExec(s16 arg0, s16 arg1, float arg2, s32 arg3) { case 5: if (!(temp_r27->attr & HU3D_ATTR_CURVE_MOTOFF)) { var_r23 = &temp_r29->cluster[var_r30->target_s16]; - var_r23->unk10 = GetClusterCurve(var_r30, arg2); + var_r23->index = GetClusterCurve(var_r30, arg2); } break; case 6: if (!(temp_r27->attr & HU3D_ATTR_CURVE_MOTOFF)) { temp_r22 = var_r30; var_r23 = &temp_r29->cluster[temp_r22->target_s16]; - var_r23->unk14[temp_r22->unk04] = GetClusterWeightCurve(temp_r22, arg2); + var_r23->weight[temp_r22->unk04] = GetClusterWeightCurve(temp_r22, arg2); } break; case 10: @@ -753,7 +829,8 @@ void Hu3DMotionExec(s16 arg0, s16 arg1, float arg2, s32 arg3) { } } -void Hu3DCameraMotionExec(s16 arg0) { +void Hu3DCameraMotionExec(s16 arg0) +{ ModelData *temp_r30; MotionData *temp_r28; HsfData *temp_r27; @@ -776,7 +853,8 @@ void Hu3DCameraMotionExec(s16 arg0) { } } -void Hu3DSubMotionExec(s16 arg0) { +void Hu3DSubMotionExec(s16 arg0) +{ ModelData *temp_r30; MotionData *temp_r22; HsfData *temp_r28; @@ -806,7 +884,8 @@ void Hu3DSubMotionExec(s16 arg0) { } if (temp_r30->unk_80) { var_f30 = temp_r30->unk_7C / temp_r30->unk_80; - } else { + } + else { var_f30 = 1.0f; } for (var_r27 = 0; var_r27 < temp_r25->numTracks; var_r27++, var_r29++) { @@ -816,7 +895,7 @@ void Hu3DSubMotionExec(s16 arg0) { temp_r26 = &temp_r28->object[var_r29->target]; temp_r24 = var_r29->channel; temp_r31 = GetObjTRXPtr(temp_r26, temp_r24); - if (temp_r31 != (float*) -1) { + if (temp_r31 != (float *)-1) { if (temp_r24 == 0x1C || temp_r24 == 0x1D || temp_r24 == 0x1E) { var_f31 = GetCurve(var_r29, temp_r30->unk_84); if (var_f31 < 0.0f) { @@ -829,11 +908,13 @@ void Hu3DSubMotionExec(s16 arg0) { if (*temp_r31 > (180.0f + var_f31)) { *temp_r31 -= 360.0f; } - } else if (*temp_r31 < (var_f31 - 180.0f)) { + } + else if (*temp_r31 < (var_f31 - 180.0f)) { var_f31 -= 360.0f; } *temp_r31 = (1.0f - var_f30) * *temp_r31 + var_f30 * var_f31; - } else { + } + else { *temp_r31 = (1.0f - var_f30) * *temp_r31 + var_f30 * GetCurve(var_r29, temp_r30->unk_84); } } @@ -844,41 +925,43 @@ void Hu3DSubMotionExec(s16 arg0) { } #ifdef __MWERKS__ -__declspec(weak) float *GetObjTRXPtr(HsfObject *arg0, u16 arg1) { +__declspec(weak) float *GetObjTRXPtr(HsfObject *arg0, u16 arg1) +{ #else -float *GetObjTRXPtr(HsfObject *arg0, u16 arg1) { +float *GetObjTRXPtr(HsfObject *arg0, u16 arg1) +{ #endif HsfConstData *temp_r31 = arg0->constData; switch (arg1) { case 8: if (temp_r31 && (temp_r31->flags & 0x10)) { - return (float*) -1; + return (float *)-1; } return &arg0->data.curr.pos.x; case 9: if (temp_r31 && (temp_r31->flags & 0x20)) { - return (float*) -1; + return (float *)-1; } return &arg0->data.curr.pos.y; case 10: if (temp_r31 && (temp_r31->flags & 0x40)) { - return (float*) -1; + return (float *)-1; } return &arg0->data.curr.pos.z; case 28: if (temp_r31 && (temp_r31->flags & 0x80)) { - return (float*) -1; + return (float *)-1; } return &arg0->data.curr.rot.x; case 29: if (temp_r31 && (temp_r31->flags & 0x100)) { - return (float*) -1; + return (float *)-1; } return &arg0->data.curr.rot.y; case 30: if (temp_r31 && (temp_r31->flags & 0x200)) { - return (float*) -1; + return (float *)-1; } return &arg0->data.curr.rot.z; case 31: @@ -888,11 +971,12 @@ float *GetObjTRXPtr(HsfObject *arg0, u16 arg1) { case 33: return &arg0->data.curr.scale.z; default: - return (float*) -1; + return (float *)-1; } } -void SetObjMatMotion(s16 arg0, HsfTrack *arg1, float arg2) { +void SetObjMatMotion(s16 arg0, HsfTrack *arg1, float arg2) +{ HsfMaterial *temp_r31; HsfData *temp_r29; ModelData *temp_r30; @@ -904,7 +988,8 @@ void SetObjMatMotion(s16 arg0, HsfTrack *arg1, float arg2) { var_f31 = arg2; if (arg2 > 1.0f) { var_f31 = 1.0f; - } else if (arg2 < 0.0f) { + } + else if (arg2 < 0.0f) { var_f31 = 0.0f; } switch (arg1->channel) { @@ -946,7 +1031,8 @@ void SetObjMatMotion(s16 arg0, HsfTrack *arg1, float arg2) { } } -void SetObjAttrMotion(s16 arg0, HsfTrack *arg1, float arg2) { +void SetObjAttrMotion(s16 arg0, HsfTrack *arg1, float arg2) +{ ModelData *temp_r28; HsfData *temp_r27; HsfAttribute *temp_r30; @@ -959,7 +1045,8 @@ void SetObjAttrMotion(s16 arg0, HsfTrack *arg1, float arg2) { var_f30 = arg2; if (arg2 > 1.0f) { var_f30 = 1.0f; - } else if (arg2 < 0.0f) { + } + else if (arg2 < 0.0f) { var_f30 = 0.0f; } switch (arg1->channel) { @@ -974,18 +1061,20 @@ void SetObjAttrMotion(s16 arg0, HsfTrack *arg1, float arg2) { case 0x21: case 0x43: if (temp_r30->unk04 == 0) { - var_r31 = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfdrawStruct01), (u32) Hu3DData[arg0].unk_48); + var_r31 = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfdrawStruct01), (u32)Hu3DData[arg0].unk_48); temp_r30->unk04 = var_r31; var_r31->unk00 = 0; var_r31->unk08 = var_r31->unk0C = var_r31->unk10 = 0.0f; var_r31->unk14 = var_r31->unk18 = var_r31->unk1C = 0.0f; var_r31->unk20 = var_r31->unk24 = var_r31->unk28 = 1.0f; - } else { + } + else { var_r31 = temp_r30->unk04; } if (arg1->channel != 0x43) { var_r31->unk00 |= 4; - } else { + } + else { var_r31->unk00 |= 8; } break; @@ -1033,7 +1122,8 @@ void SetObjAttrMotion(s16 arg0, HsfTrack *arg1, float arg2) { } } -void SetObjCameraMotion(s16 arg0, HsfTrack *arg1, float arg2) { +void SetObjCameraMotion(s16 arg0, HsfTrack *arg1, float arg2) +{ ModelData *temp_r29; Vec sp18; Vec spC; @@ -1049,7 +1139,8 @@ void SetObjCameraMotion(s16 arg0, HsfTrack *arg1, float arg2) { var_f31 = arg2; if (arg2 > 1.0f) { var_f31 = 1.0f; - } else if (arg2 < 0.0f) { + } + else if (arg2 < 0.0f) { var_f31 = 0.0f; } switch (arg1->channel) { @@ -1125,7 +1216,8 @@ void SetObjCameraMotion(s16 arg0, HsfTrack *arg1, float arg2) { } } -void SetObjLightMotion(s16 arg0, HsfTrack *arg1, float arg2) { +void SetObjLightMotion(s16 arg0, HsfTrack *arg1, float arg2) +{ s16 var_r29; ModelData *temp_r30; HsfData *temp_r28; @@ -1143,7 +1235,8 @@ void SetObjLightMotion(s16 arg0, HsfTrack *arg1, float arg2) { if (var_r24->type == 8) { if (i != arg1->target) { var_r29++; - } else { + } + else { break; } } @@ -1153,7 +1246,8 @@ void SetObjLightMotion(s16 arg0, HsfTrack *arg1, float arg2) { var_f30 = arg2; if (arg2 > 1.0f) { var_f30 = 1.0f; - } else if (arg2 < 0.0f) { + } + else if (arg2 < 0.0f) { var_f30 = 0.0f; } switch (arg1->channel) { @@ -1182,7 +1276,8 @@ void SetObjLightMotion(s16 arg0, HsfTrack *arg1, float arg2) { } } -float GetCurve(HsfTrack *arg0, float arg1) { +float GetCurve(HsfTrack *arg0, float arg1) +{ float *var_r30; switch (arg0->curveType) { @@ -1202,7 +1297,8 @@ float GetCurve(HsfTrack *arg0, float arg1) { return 0.0f; } -float GetConstant(s32 arg0, float *arg1, float arg2) { +float GetConstant(s32 arg0, float *arg1, float arg2) +{ float *var_r31; s16 i; @@ -1218,7 +1314,8 @@ float GetConstant(s32 arg0, float *arg1, float arg2) { return var_r31[-1]; } -float GetLinear(s32 arg0, float arg1[][2], float arg2) { +float GetLinear(s32 arg0, float arg1[][2], float arg2) +{ float var_f31; float var_f30; s16 temp_r30; @@ -1239,9 +1336,11 @@ float GetLinear(s32 arg0, float arg1[][2], float arg2) { } #ifdef __MWERKS__ -__declspec(weak) float GetBezier(s32 arg0, HsfTrack *arg1, float arg2) { +__declspec(weak) float GetBezier(s32 arg0, HsfTrack *arg1, float arg2) +{ #else -float GetBezier(s32 arg0, HsfTrack *arg1, float arg2) { +float GetBezier(s32 arg0, HsfTrack *arg1, float arg2) +{ #endif float temp_f24; float temp_f29; @@ -1251,8 +1350,8 @@ float GetBezier(s32 arg0, HsfTrack *arg1, float arg2) { float temp_f25; float temp_f30; float temp_f31; - float (*var_r31)[4]; - float (*var_r29)[4]; + float(*var_r31)[4]; + float(*var_r29)[4]; s32 i; var_r31 = arg1->data; @@ -1264,7 +1363,7 @@ float GetBezier(s32 arg0, HsfTrack *arg1, float arg2) { i = 0; } if (i == -1) { - var_r31 = (float(*)[4]) arg1->data + arg1->start; + var_r31 = (float(*)[4])arg1->data + arg1->start; var_r29 = var_r31 - 1; for (i = arg1->start; i < arg0; i++, var_r31++) { if (arg2 >= var_r29[0][0] && arg2 < var_r31[0][0]) { @@ -1294,13 +1393,12 @@ float GetBezier(s32 arg0, HsfTrack *arg1, float arg2) { temp_f27 = 3.0f * temp_f30; temp_f26 = temp_f31 * temp_f30; temp_f25 = temp_f31 * temp_f28; - return var_r31[0][1] * (temp_f25 - temp_f27 + 1.0f) - + var_r31[1][1] * (-temp_f25 + temp_f27) - + var_r31[0][2] * (temp_f26 - temp_f28 + temp_f31) + return var_r31[0][1] * (temp_f25 - temp_f27 + 1.0f) + var_r31[1][1] * (-temp_f25 + temp_f27) + var_r31[0][2] * (temp_f26 - temp_f28 + temp_f31) + var_r31[1][3] * (temp_f26 - temp_f30); } -HsfBitmap *GetBitMap(s32 arg0, UnknownHsfMotionStruct01 *arg1, float arg2) { +HsfBitmap *GetBitMap(s32 arg0, UnknownHsfMotionStruct01 *arg1, float arg2) +{ s16 var_r31; if (arg2 == 0.0f || arg0 == 1) { @@ -1314,7 +1412,8 @@ HsfBitmap *GetBitMap(s32 arg0, UnknownHsfMotionStruct01 *arg1, float arg2) { return arg1[-1].unk04; } -s16 Hu3DJointMotion(s16 arg0, void *arg1) { +s16 Hu3DJointMotion(s16 arg0, void *arg1) +{ s16 var_r29; var_r29 = Hu3DMotionCreate(arg1); @@ -1322,7 +1421,8 @@ s16 Hu3DJointMotion(s16 arg0, void *arg1) { return var_r29; } -void JointModel_Motion(s16 arg0, s16 arg1) { +void JointModel_Motion(s16 arg0, s16 arg1) +{ ModelData *temp_r24; MotionData *temp_r23; HsfData *temp_r26; @@ -1357,7 +1457,8 @@ void JointModel_Motion(s16 arg0, s16 arg1) { temp_r21 = SearchAttributeIndex(temp_r26, var_r31->target_s16); if (temp_r21 != -1) { var_r31->param = temp_r21; - } else { + } + else { var_r31->param = -1; } } @@ -1366,7 +1467,8 @@ void JointModel_Motion(s16 arg0, s16 arg1) { } } -void Hu3DMotionCalc(s16 arg0) { +void Hu3DMotionCalc(s16 arg0) +{ ModelData *temp_r31 = &Hu3DData[arg0]; if ((temp_r31->attr & HU3D_ATTR_DISPOFF) || (temp_r31->attr & HU3D_ATTR_HOOK)) { @@ -1387,11 +1489,12 @@ void Hu3DMotionCalc(s16 arg0) { if (temp_r31->unk_0E != -1) { if (temp_r31->unk_08 == -1) { Hu3DMotionExec(arg0, temp_r31->unk_0E, temp_r31->unk_94, 0); - } else { + } + else { Hu3DMotionExec(arg0, temp_r31->unk_0E, temp_r31->unk_94, 1); } } - if (!(temp_r31->attr & (HU3D_ATTR_ENVELOPE_OFF|HU3D_ATTR_HOOKFUNC)) || !(temp_r31->motion_attr & HU3D_MOTATTR_PAUSE)) { + if (!(temp_r31->attr & (HU3D_ATTR_ENVELOPE_OFF | HU3D_ATTR_HOOKFUNC)) || !(temp_r31->motion_attr & HU3D_MOTATTR_PAUSE)) { InitVtxParm(temp_r31->hsfData); if (temp_r31->unk_0E != -1) { ShapeProc(temp_r31->hsfData); @@ -1407,7 +1510,8 @@ void Hu3DMotionCalc(s16 arg0) { temp_r31->attr |= HU3D_ATTR_MOT_EXEC; } -static s32 SearchObjectIndex(HsfData *arg0, u32 arg1) { +static s32 SearchObjectIndex(HsfData *arg0, u32 arg1) +{ s32 i; char *temp_r28; HsfObject *var_r30; @@ -1422,7 +1526,8 @@ static s32 SearchObjectIndex(HsfData *arg0, u32 arg1) { return -1; } -static s32 SearchAttributeIndex(HsfData *arg0, u32 arg1) { +static s32 SearchAttributeIndex(HsfData *arg0, u32 arg1) +{ HsfAttribute *var_r31; size_t temp_r28; char *temp_r27; diff --git a/src/port/byteswap.cpp b/src/port/byteswap.cpp index 027978a2..4c6b901f 100644 --- a/src/port/byteswap.cpp +++ b/src/port/byteswap.cpp @@ -1,3 +1,4 @@ +#include "game/hsfformat.h" #include #include #include @@ -5,8 +6,7 @@ #include #include -extern "C" -{ +extern "C" { #include "port/byteswap.h" typedef struct AnimData32b { @@ -54,7 +54,7 @@ template [[nodiscard]] constexpr T bswap16(T val) noexcept union { u16 u; T t; - } v{.t = val}; + } v { .t = val }; #if __GNUC__ v.u = __builtin_bswap16(v.u); #elif _WIN32 @@ -71,14 +71,13 @@ template [[nodiscard]] constexpr T bswap32(T val) noexcept union { u32 u; T t; - } v{.t = val}; + } v { .t = val }; #if __GNUC__ v.u = __builtin_bswap32(v.u); #elif _WIN32 v.u = _byteswap_ulong(v.u); #else - v.u = ((v.u & 0x0000FFFF) << 16) | ((v.u & 0xFFFF0000) >> 16) | ((v.u & 0x00FF00FF) << 8) | - ((v.u & 0xFF00FF00) >> 8); + v.u = ((v.u & 0x0000FFFF) << 16) | ((v.u & 0xFFFF0000) >> 16) | ((v.u & 0x00FF00FF) << 8) | ((v.u & 0xFF00FF00) >> 8); #endif return v.t; } @@ -104,14 +103,11 @@ static std::unordered_set sVisitedPtrs; template T *offset_ptr(B &base, T *ptr) { - return reinterpret_cast(reinterpret_cast(&base) + - reinterpret_cast(ptr)); + return reinterpret_cast(reinterpret_cast(&base) + reinterpret_cast(ptr)); } template T *offset_ptr(B &base, T *ptr, void *extra) { - return reinterpret_cast(reinterpret_cast(&base) + - reinterpret_cast(ptr) + - reinterpret_cast(extra)); + return reinterpret_cast(reinterpret_cast(&base) + reinterpret_cast(ptr) + reinterpret_cast(extra)); } template static inline void bswap(B &base, T &data); @@ -122,15 +118,12 @@ template void bswap(B &base, P *&ptr) template void bswap(B &base, T *&ptr, s32 count) { ptr = bswap32(ptr); - if (ptr == nullptr) - { + if (ptr == nullptr) { return; } T *objBase = offset_ptr(base, ptr); - for (s32 i = 0; i < count; ++i) - { - if (sVisitedPtrs.contains(objBase)) - { + for (s32 i = 0; i < count; ++i) { + if (sVisitedPtrs.contains(objBase)) { continue; } sVisitedPtrs.insert(objBase); @@ -141,13 +134,11 @@ template void bswap(B &base, T *&ptr, s32 count) template void bswap_list(B &base, T **&ptr) { ptr = bswap32(ptr); - if (ptr == nullptr) - { + if (ptr == nullptr) { return; } T **objBase = offset_ptr(base, ptr); - while (*objBase != nullptr) - { + while (*objBase != nullptr) { bswap(base, *objBase, 1); ++objBase; } @@ -155,8 +146,7 @@ template void bswap_list(B &base, T **&ptr) template void bswap_list(B &base, T *(&ptr)[]) { T **objBase = ptr; - while (*objBase != nullptr) - { + while (*objBase != nullptr) { bswap(base, *objBase, 1); ++objBase; } @@ -164,8 +154,7 @@ template void bswap_list(B &base, T *(&ptr)[]) template void bswap_flat(B &base, T *start, s32 count) { T *objBase = start; - for (s32 i = 0; i < count; ++i) - { + for (s32 i = 0; i < count; ++i) { bswap(base, objBase[i]); } } @@ -342,6 +331,282 @@ template void bswap(B &base, HsfHeader &obj) bswap(base, obj.string); } +template void bswap(B &base, HsfCluster32b &obj, HsfCluster &dest) +{ + bswap(base, obj.name[0]); + bswap(base, obj.name[1]); + bswap(base, obj.targetName); + bswap(base, obj.part); + bswap(base, obj.index); + bswap_flat(base, obj.weight, sizeof(obj.weight) / sizeof(float)); + bswap(base, obj.type); + bswap(base, obj.vertexCnt); + bswap(base, obj.vertex); + + dest.name[0] = reinterpret_cast(obj.name[0]); + dest.name[1] = reinterpret_cast(obj.name[1]); + + dest.targetName = reinterpret_cast(obj.targetName); + dest.index = obj.index; + std::copy(std::begin(obj.weight), std::end(obj.weight), dest.weight); + + dest.adjusted = obj.adjusted; + dest.unk95 = obj.unk95; + dest.type = obj.type; + dest.vertexCnt = obj.vertexCnt; + dest.vertex = reinterpret_cast(obj.vertex); +} + +template void bswap(B &base, HsfAttribute32b &obj, HsfAttribute &dest) +{ + bswap(base, obj.name); + bswap(base, obj.unk04); + bswap(base, obj.unk0C); + bswap(base, obj.unk14); + bswap(base, obj.unk20); + bswap(base, obj.unk28); + bswap(base, obj.unk2C); + bswap(base, obj.unk30); + bswap(base, obj.unk34); + bswap(base, obj.wrap_s); + bswap(base, obj.wrap_t); + bswap(base, obj.unk78); + bswap(base, obj.flag); + bswap(base, obj.bitmap); + + dest.name = reinterpret_cast(obj.name); + dest.unk04 = reinterpret_cast(obj.unk04); + std::copy(std::begin(obj.unk8), std::end(obj.unk8), dest.unk8); + dest.unk0C = obj.unk0C; + std::copy(std::begin(obj.unk10), std::end(obj.unk10), dest.unk10); + dest.unk14 = obj.unk14; + std::copy(std::begin(obj.unk18), std::end(obj.unk18), dest.unk18); + dest.unk20 = obj.unk20; + std::copy(std::begin(obj.unk24), std::end(obj.unk24), dest.unk24); + dest.unk28 = obj.unk28; + dest.unk2C = obj.unk2C; + dest.unk30 = obj.unk30; + dest.unk34 = obj.unk34; + std::copy(std::begin(obj.unk38), std::end(obj.unk38), dest.unk38); + dest.wrap_s = obj.wrap_s; + dest.wrap_t = obj.wrap_t; + std::copy(std::begin(obj.unk6C), std::end(obj.unk6C), dest.unk6C); + dest.unk78 = obj.unk78; + dest.flag = obj.flag; + dest.bitmap = reinterpret_cast(obj.bitmap); +} + +template void bswap(B &base, HsfMaterial32b &obj, HsfMaterial &dest) +{ + bswap(base, obj.name); + bswap(base, obj.pass); + bswap(base, obj.hilite_scale); + bswap(base, obj.unk18); + bswap(base, obj.invAlpha); + bswap_flat(base, obj.unk20, sizeof(obj.unk20) / sizeof(float)); + bswap(base, obj.refAlpha); + bswap(base, obj.unk2C); + bswap(base, obj.flags); + bswap(base, obj.numAttrs); + bswap(base, obj.attrs); + + dest.name = reinterpret_cast(obj.name); + std::copy(std::begin(obj.unk4), std::end(obj.unk4), dest.unk4); + dest.pass = obj.pass; + dest.vtxMode = obj.vtxMode; + std::copy(std::begin(obj.litColor), std::end(obj.litColor), dest.litColor); + std::copy(std::begin(obj.color), std::end(obj.color), dest.color); + std::copy(std::begin(obj.shadowColor), std::end(obj.shadowColor), dest.shadowColor); + dest.hilite_scale = obj.hilite_scale; + dest.unk18 = obj.unk18; + dest.invAlpha = obj.invAlpha; + std::copy(std::begin(obj.unk20), std::end(obj.unk20), dest.unk20); + dest.refAlpha = obj.refAlpha; + dest.unk2C = obj.unk2C; + dest.flags = obj.flags; + dest.numAttrs = obj.numAttrs; + dest.attrs = reinterpret_cast(obj.attrs); +} + +template void bswap(B &base, HsfScene &obj) +{ + u32 fogType = static_cast(obj.fogType); + fogType = bswap32(fogType); + obj.fogType = static_cast(fogType); + bswap(base, obj.start); + bswap(base, obj.end); +} + +template void bswap(B &base, HsfBuffer32b &obj, HsfBuffer &dest) +{ + bswap(base, obj.name); + bswap(base, obj.count); + bswap(base, obj.data); + + dest.name = reinterpret_cast(obj.name); + dest.count = obj.count; + dest.data = reinterpret_cast(obj.data); +} + +template void bswap(B &base, HsfMatrix &obj) +{ + bswap(base, obj.base_idx); + bswap(base, obj.count); + + obj.data = (Mtx *)((uintptr_t)&obj + sizeof(0xC)); // hardcoded for 64 bit support + for (s32 i = 0; i < obj.count; i++) { + for (s32 j = 0; j < 3; j++) { + bswap_flat(base, obj.data[i][j], 4); + } + } +} + +template void bswap(B &base, HsfPalette32b &obj, HsfPalette &dest) +{ + bswap(base, obj.name); + bswap(base, obj.unk); + bswap(base, obj.palSize); + bswap(base, obj.data); + + dest.name = reinterpret_cast(obj.name); + dest.unk = obj.unk; + dest.palSize = obj.palSize; + dest.data = reinterpret_cast(obj.data); +} + +template void bswap(B &base, HsfPart32b &obj, HsfPart &dest) +{ + bswap(base, obj.name); + bswap(base, obj.count); + bswap(base, obj.vertex); + + dest.name = reinterpret_cast(obj.name); + dest.count = obj.count; + dest.vertex = reinterpret_cast(obj.vertex); +} + +template void bswap(B &base, HsfBitmap32b &obj, HsfBitmap &dest) +{ + bswap(base, obj.name); + bswap(base, obj.maxLod); + bswap(base, obj.sizeX); + bswap(base, obj.sizeY); + bswap(base, obj.palSize); + bswap(base, obj.palData); + bswap(base, obj.unk); + bswap(base, obj.data); + + dest.name = reinterpret_cast(obj.name); + dest.maxLod = obj.maxLod; + dest.dataFmt = obj.dataFmt; + dest.pixSize = obj.pixSize; + dest.sizeX = obj.sizeX; + dest.sizeY = obj.sizeY; + dest.palSize = obj.palSize; + dest.tint = obj.tint; + dest.palData = reinterpret_cast(obj.palData); + dest.unk = obj.unk; + dest.data = reinterpret_cast(obj.data); +} + +template void bswap(B &base, HsfMapAttr32b &obj, HsfMapAttr &dest) +{ + bswap(base, obj.minX); + bswap(base, obj.minZ); + bswap(base, obj.maxX); + bswap(base, obj.maxZ); + bswap(base, obj.data); + bswap(base, obj.dataLen); + + dest.minX = obj.minX; + dest.minZ = obj.minZ; + dest.maxX = obj.maxZ; + dest.data = reinterpret_cast(obj.data); + dest.dataLen = obj.dataLen; +} + +template void bswap(B &base, HsfTransform &obj) +{ + bswap(base, obj.pos); + bswap(base, obj.rot); + bswap(base, obj.scale); +} + +template void bswap(B &base, HsfSkeleton32b &obj, HsfSkeleton &dest) +{ + bswap(base, obj.name); + bswap(base, obj.transform); + + dest.name = reinterpret_cast(obj.name); + dest.transform = obj.transform; +} + +template void bswap(B &base, HsfShape32b &obj, HsfShape &dest) +{ + bswap(base, obj.name); + bswap(base, obj.vertex); + + dest.name = reinterpret_cast(obj.name); + dest.vertex = reinterpret_cast(obj.vertex); +} + +template void bswap(B &base, HsfCenvSingle &obj) +{ + bswap(base, obj.target); + bswap(base, obj.pos); + bswap(base, obj.posCnt); + bswap(base, obj.normal); + bswap(base, obj.normalCnt); +} + +template void bswap(B &base, HsfCenv32b &obj, HsfCenv &dest) +{ + bswap(base, obj.name); + bswap(base, obj.singleData); + bswap(base, obj.dualData); + bswap(base, obj.multiData); + bswap(base, obj.singleCount); + bswap(base, obj.dualCount); + bswap(base, obj.multiCount); + bswap(base, obj.vtxCount); + bswap(base, obj.copyCount); + + dest.name = reinterpret_cast(obj.name); + dest.singleData = reinterpret_cast(obj.singleData); + dest.dualData = reinterpret_cast(obj.dualData); + dest.multiData = reinterpret_cast(obj.multiData); + dest.singleCount = obj.singleCount; + dest.dualCount = obj.dualCount; + dest.multiCount = obj.multiCount; + dest.vtxCount = obj.vtxCount; + dest.copyCount = obj.copyCount; +} + +template void bswap(B &base, HsfObject32b &obj, HsfObject &dest) +{ + bswap(base, obj.name); + bswap(base, obj.type); + bswap(base, obj.constData); + bswap(base, obj.flags); + + dest.name = reinterpret_cast(obj.name); + dest.type = obj.type; + dest.constData = reinterpret_cast(obj.constData); + dest.flags = obj.flags; +} + +void byteswap_u16(u16 *src) +{ + bswap(*src, *src); + sVisitedPtrs.clear(); +} + +void byteswap_s16(s16 *src) +{ + bswap(*src, *src); + sVisitedPtrs.clear(); +} + void byteswap_u32(u32 *src) { bswap(*src, *src); @@ -354,6 +619,20 @@ void byteswap_s32(s32 *src) sVisitedPtrs.clear(); } +void byteswap_hsfvec3f(HsfVector3f *src) +{ + auto *vec = reinterpret_cast(src); + bswap(*vec, *vec); + sVisitedPtrs.clear(); +} + +void byteswap_hsfvec2f(HsfVector2f *src) +{ + auto *vec = reinterpret_cast(src); + bswap(*vec, *vec); + sVisitedPtrs.clear(); +} + void byteswap_animdata(void *src, AnimData *dest) { auto *anim = reinterpret_cast(src); @@ -399,3 +678,93 @@ void byteswap_hsfheader(HsfHeader *src) bswap(*src, *src); sVisitedPtrs.clear(); } + +void byteswap_hsfcluster(HsfCluster32b *src, HsfCluster *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfattribute(HsfAttribute32b *src, HsfAttribute *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfmaterial(HsfMaterial32b *src, HsfMaterial *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfscene(HsfScene *src) +{ + bswap(*src, *src); + sVisitedPtrs.clear(); +} + +void byteswap_hsfbuffer(HsfBuffer32b *src, HsfBuffer *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfmatrix(HsfMatrix *src) +{ + bswap(*src, *src); + sVisitedPtrs.clear(); +} + +void byteswap_hsfpalette(HsfPalette32b *src, HsfPalette *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfpart(HsfPart32b *src, HsfPart *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfbitmap(HsfBitmap32b *src, HsfBitmap *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfmapattr(HsfMapAttr32b *src, HsfMapAttr *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfskeleton(HsfSkeleton32b *src, HsfSkeleton *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfshape(HsfShape32b *src, HsfShape *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfcenvsingle(HsfCenvSingle *src) +{ + bswap(*src, *src); + sVisitedPtrs.clear(); +} + +void byteswap_hsfcenv(HsfCenv32b *src, HsfCenv *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} + +void byteswap_hsfobject(HsfObject32b *src, HsfObject *dest) +{ + bswap(*src, *src, *dest); + sVisitedPtrs.clear(); +} \ No newline at end of file