From cacfbe3d7a8e871d9dfd0fb6d3c3dc4b3e104852 Mon Sep 17 00:00:00 2001 From: RobbyV2 Date: Thu, 30 Jul 2026 18:13:02 -0400 Subject: [PATCH 1/2] phys: match StaticCompoundUtil shape helpers --- data/uking_functions.csv | 8 +- .../StaticCompound/physStaticCompoundUtil.cpp | 92 +++++++++++++++++++ .../StaticCompound/physStaticCompoundUtil.h | 4 +- 3 files changed, 98 insertions(+), 6 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 390b92ce2..ac4ac0175 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -84881,9 +84881,9 @@ Address,Quality,Size,Name 0x0000007100fd0698,U,000004,j__ZdlPv_1016 0x0000007100fd069c,O,000372,_ZN4ksys4phys18motionTypeFromTextERKN4sead14SafeStringBaseIcEE 0x0000007100fd0810,U,000092, -0x0000007100fd086c,U,000356, -0x0000007100fd09d0,U,000076, -0x0000007100fd0a1c,U,000016,_ZN4ksys4phys36getCollisionFilterInfoFromCollidableEPNS0_23RigidBodyCollisionMasksEPjRK13hkpCollidablePKj +0x0000007100fd086c,O,000356,_ZN4ksys4phys29getMaterialMaskFromCollidableEPNS0_23RigidBodyCollisionMasksEPjRK8hkpShapePKj +0x0000007100fd09d0,O,000076,_ZN4ksys4phys32getBodyGroupAndObjectFromSCShapeEPPNS0_28StaticCompoundRigidBodyGroupEPPNS_3map6ObjectERK8hkpShapePKj +0x0000007100fd0a1c,O,000016,_ZN4ksys4phys36getCollisionFilterInfoFromCollidableEPNS0_23RigidBodyCollisionMasksEPjRK13hkpCollidablePKj 0x0000007100fd0a2c,U,000680, 0x0000007100fd0cd4,U,000036,_ZN4ksys19PlayerTrackReporterC1Ev 0x0000007100fd0cf8,U,000064,PlayerTrackReporter::dtor @@ -106571,7 +106571,7 @@ Address,Quality,Size,Name 0x000000710164ed44,U,002824, 0x000000710164f84c,U,000272, 0x000000710164f95c,U,000004,nullsub_5216 -0x000000710164f960,U,000312, +0x000000710164f960,L,000312,_ZNK24hkpBvCompressedMeshShape20getPrimitiveUserDataEj 0x000000710164fa98,U,000060, 0x000000710164fad4,U,000468, 0x000000710164fca8,U,000240, diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.cpp b/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.cpp index 72d1bcbb2..db099bacf 100644 --- a/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.cpp +++ b/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.cpp @@ -1 +1,93 @@ #include "KingSystem/Physics/StaticCompound/physStaticCompoundUtil.h" +#include +#include +#include +#include +#include "KingSystem/Physics/RigidBody/physRigidBody.h" +#include "KingSystem/Physics/StaticCompound/physStaticCompoundMgr.h" +#include "KingSystem/Physics/System/physSystem.h" + +namespace ksys::phys { + +u32 getMaterialMaskFromCollidable(RigidBodyCollisionMasks* p_masks, u32* p_collision_filter_info, + const hkpShape& shape, const u32* shape_key) { + auto no_material = [&] { + p_masks->material_mask = 0; + *p_collision_filter_info = 0; + return 1; + }; + + if (shape.getType() == hkcdShapeType::BV_COMPRESSED_MESH) { + if (*shape_key == HK_INVALID_SHAPE_KEY) + return no_material(); + + const auto& mesh = static_cast(shape); + if (mesh.getCollisionFilterInfoMode() == + hkpBvCompressedMeshShape::PER_PRIMITIVE_DATA_PALETTE) { + *p_collision_filter_info = mesh.getCollisionFilterInfo(*shape_key); + } + + if (mesh.getUserDataMode() != hkpBvCompressedMeshShape::PER_PRIMITIVE_DATA_NONE) { + p_masks->material_mask = mesh.getPrimitiveUserData(*shape_key); + return 0; + } + + p_masks->material_mask = mesh.getUserData(); + return 0; + } + + if (shape.getType() == hkcdShapeType::STATIC_COMPOUND) { + if (*shape_key == HK_INVALID_SHAPE_KEY) + return no_material(); + + const auto& compound = static_cast(shape); + int instance_id; + hkpShapeKey child_key; + compound.decomposeShapeKey(*shape_key, instance_id, child_key); + const auto& instance = compound.getInstances()[instance_id]; + *p_collision_filter_info = compound.getCollisionFilterInfo(*shape_key); + return getMaterialMaskFromCollidable(p_masks, p_collision_filter_info, *instance.getShape(), + &child_key); + } + + if (shape.getType() == hkcdShapeType::LIST) { + if (*shape_key == HK_INVALID_SHAPE_KEY) + return no_material(); + + hkpShapeBuffer buffer; + const auto& list = static_cast(shape); + return getMaterialMaskFromCollidable(p_masks, p_collision_filter_info, + *list.getChildShape(*shape_key, buffer), shape_key); + } + + p_masks->material_mask = shape.getUserData(); + return 0; +} + +void getBodyGroupAndObjectFromSCShape(StaticCompoundRigidBodyGroup** p_body_group, + map::Object** p_object, const hkpShape& shape, + const u32* shape_key) { + if (shape.getType() != hkcdShapeType::STATIC_COMPOUND) { + *p_body_group = nullptr; + return; + } + + auto* mgr = System::instance()->getStaticCompoundMgr(); + if (!mgr) { + *p_body_group = nullptr; + return; + } + + mgr->getBodyGroupAndMapObject(p_body_group, p_object, + static_cast(shape), shape_key); +} + +u32 getCollisionFilterInfoFromCollidable(RigidBodyCollisionMasks* p_masks, + u32* p_collision_filter_info, + const hkpCollidable& collidable, const u32* shape_key) { + *p_collision_filter_info = collidable.getCollisionFilterInfo(); + return getMaterialMaskFromCollidable(p_masks, p_collision_filter_info, *collidable.getShape(), + shape_key); +} + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.h b/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.h index 976a68893..d100c8514 100644 --- a/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.h +++ b/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.h @@ -20,8 +20,8 @@ u32 getMaterialMaskFromShape(const hkpShape& shape, const u32* shape_key, const sead::Vector3f& position); // 0x0000007100fd086c -bool getMaterialMaskFromCollidable(RigidBodyCollisionMasks* p_masks, u32* p_collision_filter_info, - const hkpShape& shape, const u32* shape_key); +u32 getMaterialMaskFromCollidable(RigidBodyCollisionMasks* p_masks, u32* p_collision_filter_info, + const hkpShape& shape, const u32* shape_key); // 0x0000007100fd09d0 void getBodyGroupAndObjectFromSCShape(StaticCompoundRigidBodyGroup** p_body_group, From 884442ab36b667a8a9a788a90df31691be543d64 Mon Sep 17 00:00:00 2001 From: RobbyV2 Date: Mon, 3 Aug 2026 14:50:37 -0500 Subject: [PATCH 2/2] phys: use switch for shape dispatch --- .../StaticCompound/physStaticCompoundUtil.cpp | 13 ++++++++----- .../Physics/StaticCompound/physStaticCompoundUtil.h | 4 ---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.cpp b/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.cpp index db099bacf..0b69eae5c 100644 --- a/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.cpp +++ b/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.cpp @@ -17,7 +17,8 @@ u32 getMaterialMaskFromCollidable(RigidBodyCollisionMasks* p_masks, u32* p_colli return 1; }; - if (shape.getType() == hkcdShapeType::BV_COMPRESSED_MESH) { + switch (shape.getType()) { + case hkcdShapeType::BV_COMPRESSED_MESH: { if (*shape_key == HK_INVALID_SHAPE_KEY) return no_material(); @@ -36,7 +37,7 @@ u32 getMaterialMaskFromCollidable(RigidBodyCollisionMasks* p_masks, u32* p_colli return 0; } - if (shape.getType() == hkcdShapeType::STATIC_COMPOUND) { + case hkcdShapeType::STATIC_COMPOUND: { if (*shape_key == HK_INVALID_SHAPE_KEY) return no_material(); @@ -50,7 +51,7 @@ u32 getMaterialMaskFromCollidable(RigidBodyCollisionMasks* p_masks, u32* p_colli &child_key); } - if (shape.getType() == hkcdShapeType::LIST) { + case hkcdShapeType::LIST: { if (*shape_key == HK_INVALID_SHAPE_KEY) return no_material(); @@ -60,8 +61,10 @@ u32 getMaterialMaskFromCollidable(RigidBodyCollisionMasks* p_masks, u32* p_colli *list.getChildShape(*shape_key, buffer), shape_key); } - p_masks->material_mask = shape.getUserData(); - return 0; + default: + p_masks->material_mask = shape.getUserData(); + return 0; + } } void getBodyGroupAndObjectFromSCShape(StaticCompoundRigidBodyGroup** p_body_group, diff --git a/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.h b/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.h index d100c8514..60ace851a 100644 --- a/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.h +++ b/src/KingSystem/Physics/StaticCompound/physStaticCompoundUtil.h @@ -15,20 +15,16 @@ namespace ksys::phys { class StaticCompoundRigidBodyGroup; struct RigidBodyCollisionMasks; -// 0x0000007100fd0810 u32 getMaterialMaskFromShape(const hkpShape& shape, const u32* shape_key, const sead::Vector3f& position); -// 0x0000007100fd086c u32 getMaterialMaskFromCollidable(RigidBodyCollisionMasks* p_masks, u32* p_collision_filter_info, const hkpShape& shape, const u32* shape_key); -// 0x0000007100fd09d0 void getBodyGroupAndObjectFromSCShape(StaticCompoundRigidBodyGroup** p_body_group, map::Object** p_object, const hkpShape& shape, const u32* shape_key); -// 0x0000007100fd0a1c u32 getCollisionFilterInfoFromCollidable(RigidBodyCollisionMasks* p_masks, u32* p_collision_filter_info, const hkpCollidable& collidable, const u32* shape_key);