From 5f9201ab5a6e5de1675a0723d1792a566d942e9e Mon Sep 17 00:00:00 2001 From: RobbyV2 Date: Fri, 31 Jul 2026 07:46:01 -0400 Subject: [PATCH 1/2] phys: match System contact listener flags and body teardown --- data/uking_functions.csv | 14 +++--- .../Physics/System/physContactListener.h | 8 ++++ src/KingSystem/Physics/System/physSystem.cpp | 45 +++++++++++++++++++ src/KingSystem/Physics/System/physSystem.h | 7 ++- 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 390b92ce2..bc4d0c2dd 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -94007,9 +94007,9 @@ Address,Quality,Size,Name 0x000000710121677c,U,000012,PhysicsMemSys::setPauseState 0x0000007101216788,O,000008,_ZNK4ksys4phys6System8isPausedEv 0x0000007101216790,U,000092,PhysicsMemSys::__auto17 -0x00000071012167ec,U,000020,PhysicsMemSys::__auto11 -0x0000007101216800,U,000020,PhysicsMemSys::setEntityContactListenerField91 -0x0000007101216814,U,000016,_ZNK4ksys4phys6System31getEntityContactListenerField91Ev +0x00000071012167ec,O,000020,_ZN4ksys4phys6System45setDisableSensorContactPointInfoNotificationsEb +0x0000007101216800,O,000020,_ZN4ksys4phys6System31setEntityContactListenerField91Eb +0x0000007101216814,O,000016,_ZNK4ksys4phys6System31getEntityContactListenerField91Ev 0x0000007101216824,U,000004,nullsub_6154 0x0000007101216828,U,000004,nullsub_4711 0x000000710121682c,U,000032, @@ -94029,7 +94029,7 @@ Address,Quality,Size,Name 0x00000071012169b4,O,000012,_ZN4ksys4phys6System34makeContactLayerCollisionInfoGroupEPN4sead4HeapENS0_12ContactLayerEiRKNS2_14SafeStringBaseIcEE 0x00000071012169c0,O,000008,_ZN4ksys4phys6System34freeContactLayerCollisionInfoGroupEPNS0_30ContactLayerCollisionInfoGroupE 0x00000071012169c8,O,000088,_ZN4ksys4phys6System14trackLayerPairENS0_12ContactLayerES2_ -0x0000007101216a20,U,000136,_ZN4ksys4phys6System32removeRigidBodyFromContactSystemEPNS0_9RigidBodyE +0x0000007101216a20,O,000136,_ZN4ksys4phys6System32removeRigidBodyFromContactSystemEPNS0_9RigidBodyE 0x0000007101216aa8,U,000008, 0x0000007101216ab0,U,000008, 0x0000007101216ab8,U,000008, @@ -94039,10 +94039,10 @@ Address,Quality,Size,Name 0x0000007101216af4,U,000276, 0x0000007101216c08,O,000080,_ZNK4ksys4phys6System18isHavokMainHeapOomEv 0x0000007101216c58,U,000008,PhysicsMemSys::setRigidBodyDividedMeshShapeMgr -0x0000007101216c60,U,000020,phys::System::setEntityContactListenerField90 -0x0000007101216c74,U,000016,_ZNK4ksys4phys6System31getEntityContactListenerField90Ev +0x0000007101216c60,O,000020,_ZN4ksys4phys6System31setEntityContactListenerField90Eb +0x0000007101216c74,O,000016,_ZNK4ksys4phys6System31getEntityContactListenerField90Ev 0x0000007101216c84,O,000032,_ZNK4ksys4phys6System21getRagdollCtrlKeyListEv -0x0000007101216ca4,U,000072,_ZNK4ksys4phys6System17isActorSystemIdleEv +0x0000007101216ca4,O,000072,_ZNK4ksys4phys6System17isActorSystemIdleEv 0x0000007101216cec,O,000148,_ZNK4ksys4phys6System18getPhysicsTempHeapENS0_11LowPriorityE 0x0000007101216d80,U,000112, 0x0000007101216df0,U,000152,PhysicsMemSys::__auto9 diff --git a/src/KingSystem/Physics/System/physContactListener.h b/src/KingSystem/Physics/System/physContactListener.h index 086f4131a..71d3882b5 100644 --- a/src/KingSystem/Physics/System/physContactListener.h +++ b/src/KingSystem/Physics/System/physContactListener.h @@ -42,6 +42,14 @@ class ContactListener : public hkpContactListener, public sead::hostio::Node { void unregisterCollisionWithBody(RigidBody* body); + bool get90() const { return _90; } + void set90(bool value) { _90 = value; } + bool get91() const { return _91; } + void set91(bool value) { _91 = value; } + void setDisableContactPointInfoNotifications(bool value) { + mDisableContactPointInfoNotifications = value; + } + void contactPointCallback(const hkpContactPointEvent& event) override; void collisionAddedCallback(const hkpCollisionEvent& event) override; void collisionRemovedCallback(const hkpCollisionEvent& event) override; diff --git a/src/KingSystem/Physics/System/physSystem.cpp b/src/KingSystem/Physics/System/physSystem.cpp index acc926fc5..baf3d0ace 100644 --- a/src/KingSystem/Physics/System/physSystem.cpp +++ b/src/KingSystem/Physics/System/physSystem.cpp @@ -1,10 +1,12 @@ #include "KingSystem/Physics/System/physSystem.h" #include #include +#include "KingSystem/ActorSystem/actBaseProcMgr.h" #include "KingSystem/Physics/Cloth/physClothResource.h" #include "KingSystem/Physics/Ragdoll/physRagdollControllerKeyList.h" #include "KingSystem/Physics/Ragdoll/physRagdollResource.h" #include "KingSystem/Physics/RigidBody/TeraMesh/physTeraMeshRigidBodyResource.h" +#include "KingSystem/Physics/RigidBody/physRigidBody.h" #include "KingSystem/Physics/RigidBody/physRigidBodyResource.h" #include "KingSystem/Physics/StaticCompound/physStaticCompound.h" #include "KingSystem/Physics/SupportBone/physSupportBoneResource.h" @@ -154,4 +156,47 @@ sead::Heap* System::getPhysicsTempHeap(LowPriority low_priority) const { return mPhysicsTempDefaultHeap; } +void System::removeRigidBodyFromContactSystem(RigidBody* body) { + const auto layer_type = getContactLayerType(body->getContactLayer()); + + if (mPaused) + mContactMgr->removeContactPointsWithBody(body); + + mContactListeners[static_cast(layer_type)]->unregisterCollisionWithBody(body); + mContactMgr->removeCollisionEntriesWithBody(body); + mContactMgr->removeImpulseEntriesWithBody(body); +} + +void System::setEntityContactListenerField90(bool value) { + mContactListeners[static_cast(ContactLayerType::Entity)]->set90(value); +} + +bool System::getEntityContactListenerField90() const { + return mContactListeners[static_cast(ContactLayerType::Entity)]->get90(); +} + +void System::setEntityContactListenerField91(bool value) { + mContactListeners[static_cast(ContactLayerType::Entity)]->set91(value); +} + +bool System::getEntityContactListenerField91() const { + return mContactListeners[static_cast(ContactLayerType::Entity)]->get91(); +} + +void System::setDisableSensorContactPointInfoNotifications(bool disable) { + mContactListeners[static_cast(ContactLayerType::Sensor)] + ->setDisableContactPointInfoNotifications(disable); +} + +bool System::isActorSystemIdle() const { + const bool flag = _62 || _61; + + auto* mgr = act::BaseProcMgr::instance(); + if (!mgr) + return true; + + const bool idle = mgr->getStatus() != act::BaseProcMgr::Status::ProcessingActorJobs; + return flag || idle; +} + } // namespace ksys::phys diff --git a/src/KingSystem/Physics/System/physSystem.h b/src/KingSystem/Physics/System/physSystem.h index 9c48510de..461de0f0f 100644 --- a/src/KingSystem/Physics/System/physSystem.h +++ b/src/KingSystem/Physics/System/physSystem.h @@ -129,6 +129,9 @@ class System { // 0x0000007101216814 bool getEntityContactListenerField91() const; + // 0x00000071012167ec + void setDisableSensorContactPointInfoNotifications(bool disable); + // 0x000000710121682c void incrementWorldUnkCounter(ContactLayerType layer_type); // 0x000000710121684c @@ -141,7 +144,9 @@ class System { private: u8 _28[0x60 - 0x28]; bool mPaused; - u8 _61[0x64 - 0x61]; + u8 _61; + u8 _62; + u8 _63; float _64 = 1.0 / 30.0; float _68 = 1.0 / 30.0; float _6c = 1.0; From 24c381b41152062928dd5b3182f72faf35074ab2 Mon Sep 17 00:00:00 2001 From: RobbyV2 Date: Mon, 3 Aug 2026 14:59:10 -0500 Subject: [PATCH 2/2] phys: address contact listener review --- data/uking_functions.csv | 4 ++-- .../Physics/System/physContactListener.h | 6 +++--- .../Physics/System/physEntityContactListener.cpp | 8 ++++---- src/KingSystem/Physics/System/physSystem.cpp | 16 +++++++++------- src/KingSystem/Physics/System/physSystem.h | 9 ++++----- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index bc4d0c2dd..afb94a0cd 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -94039,8 +94039,8 @@ Address,Quality,Size,Name 0x0000007101216af4,U,000276, 0x0000007101216c08,O,000080,_ZNK4ksys4phys6System18isHavokMainHeapOomEv 0x0000007101216c58,U,000008,PhysicsMemSys::setRigidBodyDividedMeshShapeMgr -0x0000007101216c60,O,000020,_ZN4ksys4phys6System31setEntityContactListenerField90Eb -0x0000007101216c74,O,000016,_ZNK4ksys4phys6System31getEntityContactListenerField90Ev +0x0000007101216c60,O,000020,_ZN4ksys4phys6System26setMagneMassScalingEnabledEb +0x0000007101216c74,O,000016,_ZNK4ksys4phys6System25isMagneMassScalingEnabledEv 0x0000007101216c84,O,000032,_ZNK4ksys4phys6System21getRagdollCtrlKeyListEv 0x0000007101216ca4,O,000072,_ZNK4ksys4phys6System17isActorSystemIdleEv 0x0000007101216cec,O,000148,_ZNK4ksys4phys6System18getPhysicsTempHeapENS0_11LowPriorityE diff --git a/src/KingSystem/Physics/System/physContactListener.h b/src/KingSystem/Physics/System/physContactListener.h index 71d3882b5..11344186d 100644 --- a/src/KingSystem/Physics/System/physContactListener.h +++ b/src/KingSystem/Physics/System/physContactListener.h @@ -42,8 +42,8 @@ class ContactListener : public hkpContactListener, public sead::hostio::Node { void unregisterCollisionWithBody(RigidBody* body); - bool get90() const { return _90; } - void set90(bool value) { _90 = value; } + bool isMagneMassScalingEnabled() const { return mMagneMassScalingEnabled; } + void setMagneMassScalingEnabled(bool enabled) { mMagneMassScalingEnabled = enabled; } bool get91() const { return _91; } void set91(bool value) { _91 = value; } void setDisableContactPointInfoNotifications(bool value) { @@ -133,7 +133,7 @@ class ContactListener : public hkpContactListener, public sead::hostio::Node { u32 mTrackedLayersBufferSize{}; u32 mLayerCount{}; sead::CriticalSection mCS; - bool _90 = false; + bool mMagneMassScalingEnabled = false; bool _91 = false; bool mDisableContactPointInfoNotifications = false; }; diff --git a/src/KingSystem/Physics/System/physEntityContactListener.cpp b/src/KingSystem/Physics/System/physEntityContactListener.cpp index a5ccdda64..678ba2e16 100644 --- a/src/KingSystem/Physics/System/physEntityContactListener.cpp +++ b/src/KingSystem/Physics/System/physEntityContactListener.cpp @@ -275,7 +275,7 @@ static void updateMotionAccessorFlagsForMagneMassScaling(RigidBody* body_a, Rigi void EntityContactListener::setMagneMassScalingForContactIfNeeded(const hkpCollisionEvent& event, RigidBody* body_a, RigidBody* body_b) { - if (!System::instance()->getEntityContactListenerField90()) + if (!System::instance()->isMagneMassScalingEnabled()) return; if (!needsMagneMassScaling(event, body_a, body_b)) @@ -490,19 +490,19 @@ bool EntityContactListener::regularContactPointCallback(const hkpContactPointEve auto* modifier = hkpWorldConstraintUtil::findModifier( constraint, hkpConstraintAtom::TYPE_MODIFIER_VISCOUS_SURFACE); - const bool field90 = System::instance()->getEntityContactListenerField90(); + const bool magne_mass_scaling_enabled = System::instance()->isMagneMassScalingEnabled(); if (modifier && constraint->getUserData() & 1) { clearCallbackDelay(event); - if (field90 && hasEntityWithMotionFlag80(event)) { + if (magne_mass_scaling_enabled && hasEntityWithMotionFlag80(event)) { updateMotionFlagsAtEndOfStep(event, body_a, body_b); } else { body_a->getEntityMotionAccessor()->getContactFlags().makeAllZero(); body_b->getEntityMotionAccessor()->getContactFlags().makeAllZero(); removeViscousSurfaceModifier(event); } - } else if (field90 && needsMagneMassScaling(event, body_a, body_b) && + } else if (magne_mass_scaling_enabled && needsMagneMassScaling(event, body_a, body_b) && !shouldProcessEntityContact(body_a, body_b)) { updateMotionAccessorFlagsForMagneMassScaling(body_a, body_b); setMagneMassScalingForContact(event, body_a, body_b); diff --git a/src/KingSystem/Physics/System/physSystem.cpp b/src/KingSystem/Physics/System/physSystem.cpp index baf3d0ace..3a78a07ca 100644 --- a/src/KingSystem/Physics/System/physSystem.cpp +++ b/src/KingSystem/Physics/System/physSystem.cpp @@ -167,12 +167,14 @@ void System::removeRigidBodyFromContactSystem(RigidBody* body) { mContactMgr->removeImpulseEntriesWithBody(body); } -void System::setEntityContactListenerField90(bool value) { - mContactListeners[static_cast(ContactLayerType::Entity)]->set90(value); +void System::setMagneMassScalingEnabled(bool enabled) { + mContactListeners[static_cast(ContactLayerType::Entity)]->setMagneMassScalingEnabled( + enabled); } -bool System::getEntityContactListenerField90() const { - return mContactListeners[static_cast(ContactLayerType::Entity)]->get90(); +bool System::isMagneMassScalingEnabled() const { + return mContactListeners[static_cast(ContactLayerType::Entity)] + ->isMagneMassScalingEnabled(); } void System::setEntityContactListenerField91(bool value) { @@ -189,14 +191,14 @@ void System::setDisableSensorContactPointInfoNotifications(bool disable) { } bool System::isActorSystemIdle() const { - const bool flag = _62 || _61; + const bool is_idle = _62 || _61; auto* mgr = act::BaseProcMgr::instance(); if (!mgr) return true; - const bool idle = mgr->getStatus() != act::BaseProcMgr::Status::ProcessingActorJobs; - return flag || idle; + const bool actor_jobs_idle = mgr->getStatus() != act::BaseProcMgr::Status::ProcessingActorJobs; + return is_idle || actor_jobs_idle; } } // namespace ksys::phys diff --git a/src/KingSystem/Physics/System/physSystem.h b/src/KingSystem/Physics/System/physSystem.h index 461de0f0f..c77f96897 100644 --- a/src/KingSystem/Physics/System/physSystem.h +++ b/src/KingSystem/Physics/System/physSystem.h @@ -115,11 +115,10 @@ class System { RagdollControllerKeyList* getRagdollCtrlKeyList() const; - // TODO: rename // 0x0000007101216c60 - void setEntityContactListenerField90(bool value); + void setMagneMassScalingEnabled(bool enabled); // 0x0000007101216c74 - bool getEntityContactListenerField90() const; + bool isMagneMassScalingEnabled() const; // 0x0000007101216ca4 bool isActorSystemIdle() const; @@ -144,8 +143,8 @@ class System { private: u8 _28[0x60 - 0x28]; bool mPaused; - u8 _61; - u8 _62; + bool _61; + bool _62; u8 _63; float _64 = 1.0 / 30.0; float _68 = 1.0 / 30.0;