Skip to content

Commit 14e09e4

Browse files
author
ReimousTH
committed
BulletCollisionFix
1 parent b9d30a6 commit 14e09e4

4 files changed

Lines changed: 62 additions & 105 deletions

File tree

MarathonRecomp/api/Sonicteam/SoX/Physics/Havok/WorldHavok.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
#include <Marathon.inl>
44
#include <Sonicteam/SoX/Physics/World.h>
5+
#include <hk330/hkpWorld.h>
56

67
namespace Sonicteam::SoX::Physics::Havok
78
{
89
class WorldHavok : public World
910
{
1011
public:
11-
MARATHON_INSERT_PADDING(0x18);
12+
xpointer<hk330::hkpWorld> m_pWorld;
13+
MARATHON_INSERT_PADDING(0x14);
1214
bool m_IsDynamicUpdateRate;
1315
};
1416
}

MarathonRecomp/api/hk330/hkMultiThreadCheck.h

Lines changed: 0 additions & 12 deletions
This file was deleted.

MarathonRecomp/api/hk330/hkpWorld.h

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,59 @@
44
#include <hk330/hkReferencedObject.h>
55
#include <Sonicteam/SoX/Math/Vector.h>
66
#include <hk330/hkArray.h>
7-
#include <hk330/hkMultiThreadCheck.h>
87

98
namespace hk330
109
{
1110
class hkpRigidBody;
1211
class hkpPhantom;
1312
class hkpRigidBody;
1413
class hkpCollisionFilter;
14+
class hkpsimulation;
15+
class hkpSimulationIsland;
16+
class hkpBroadPhase;
17+
class hkpTypedBroadPhaseDispatcher;
18+
class hkpProcessCollisionInput;
19+
class hkpCollisionDispatcher;
20+
class hkpWorldMaintenanceMgr;
21+
class hkWorldMemoryAvailableWatchDog;
22+
class hkpPhantomBroadPhaseListener;
23+
class hkpEntityEntityBroadPhaseListener;
24+
class hkpBroadPhaseBorderListener;
25+
class hkpWorldOperationQueue;
1526
class hkpWorld : public hkReferencedObject
1627
{
1728
public:
18-
xpointer<void> m_simulation;
29+
30+
xpointer<hkpsimulation> m_simulation;
31+
MARATHON_INSERT_PADDING(20);
1932
Sonicteam::SoX::Math::Vector m_gravity;
20-
xpointer<void> m_fixedIsland;
33+
xpointer<hkpSimulationIsland> m_fixedIsland;
2134
xpointer<hkpRigidBody> m_fixedRigidBody;
22-
hkArray<void> m_activeSimulationIslands;
23-
hkArray<void> m_inactiveSimulationIslands;
24-
hkArray<void> m_dirtySimulationIslands;
25-
xpointer<void> m_maintenanceMgr;
26-
xpointer<void> m_memoryWatchDog;
27-
MARATHON_INSERT_PADDING(8);
28-
xpointer<void> m_broadPhase; //should be at this right position
29-
xpointer<void> m_broadPhaseDispatcher;
30-
xpointer<void> m_phantomBroadPhaseListener;
31-
xpointer<void> m_entityEntityBroadPhaseListener;
32-
xpointer<void> m_broadPhaseBorderListener;
33-
//xpointer<void> m_multithreadedSimulationJobData;
34-
//Some of them are are not need (duno why) 4 bytes
35-
xpointer<void> m_collisionInput;
35+
hkArray<hkpSimulationIsland*> m_activeSimulationIslands;
36+
hkArray<hkpSimulationIsland*> m_inactiveSimulationIslands;
37+
hkArray<hkpSimulationIsland*> m_dirtySimulationIslands;
38+
xpointer<hkpWorldMaintenanceMgr> m_maintenanceMgr;
39+
xpointer<hkWorldMemoryAvailableWatchDog> m_memoryWatchDog;
40+
xpointer<hkpBroadPhase> m_broadPhase;
41+
xpointer<hkpTypedBroadPhaseDispatcher> m_broadPhaseDispatcher;
42+
xpointer<hkpPhantomBroadPhaseListener> m_phantomBroadPhaseListener;
43+
xpointer<hkpEntityEntityBroadPhaseListener> m_entityEntityBroadPhaseListener;
44+
xpointer<hkpBroadPhaseBorderListener> m_broadPhaseBorderListener;
45+
xpointer<hkpProcessCollisionInput> m_collisionInput;
3646
xpointer<hkpCollisionFilter> m_collisionFilter;
37-
// xpointer<void> m_collisionDispatcher; probably (not need)
38-
xpointer<void> m_convexListFilter;
39-
MARATHON_INSERT_PADDING(8);
40-
xpointer<void> m_pendingOperations; // Correct Place
41-
be<int32_t> m_pendingOperationsCount; //Correct Place
47+
xpointer<hkpCollisionDispatcher> m_collisionDispatcher;
48+
xpointer<hkpWorldOperationQueue> m_pendingOperations;
49+
be<int32_t> m_pendingOperationsCount;
4250
be<int32_t> m_criticalOperationsLockCount;
4351
be<int32_t> m_criticalOperationsLockCountForPhantoms;
44-
be<bool> m_blockExecutingPendingOperations; //Correct Place
45-
be<bool> m_criticalOperationsAllowed;
46-
xpointer<void> hkpDebugInfoOnPendingOperationQueues;
47-
be<int32_t> m_pendingOperationQueueCount;
48-
hkMultiThreadCheck m_multiThreadCheck;
49-
be<bool> m_processActionsInSingleThread;
50-
be<uint32_t> m_minDesiredIslandSize;
51-
xpointer<void> m_modifyConstraintCriticalSection;
52-
xpointer<void> m_worldLock;
53-
xpointer<void> m_islandDirtyListCriticalSection;
54-
xpointer<void> m_propertyMasterLock;
55-
be<bool> m_wantSimulationIslands;
56-
be<float> m_snapCollisionToConvexEdgeThreshold;
57-
be<float> m_snapCollisionToConcaveEdgeThreshold;
58-
be<float> m_enableToiWeldRejection;
59-
be<float> m_wantDeactivation;
60-
be<float> m_shouldActivateOnRigidBodyTransformChange;
61-
be<float> m_highFrequencyDeactivationPeriod;
62-
be<float> m_lowFrequencyDeactivationPeriod;
63-
be<float> m_deactivationReferenceDistance;
64-
be<float> m_toiCollisionResponseRotateNormal;
65-
be<int32_t> m_simulationType;
66-
be<uint32_t> m_lastEntityUid;
67-
hkArray<xpointer<hkpPhantom>> hkpPhantom;
68-
52+
bool m_blockExecutingPendingOperations;
53+
bool m_criticalOperationsAllowed;
54+
MARATHON_INSERT_PADDING(0x2C);
55+
hkArray<hkpPhantom*> m_phantoms; //0xCC
6956

70-
//sub_828306E0
71-
//hkWorld_updateFilterOnSinglePhantom 8282D528
72-
//hkpworld::internal_executePendingOperations 8282DB94
73-
void updateCollisionFilterOnPhantom(hk330::hkpPhantom* phantom, uint32_t updateShapeCollectionFilter);
57+
void updateCollisionFilterOnWorld(uint32_t updateMode,uint32_t updateShapeCollectionFilter)
58+
{
59+
GuestToHostFunction<void>(sub_82832910, this, updateMode, updateShapeCollectionFilter);
60+
}
7461
};
7562
}

MarathonRecomp/patches/fps_patches.cpp

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <api/Marathon.h>
22
#include <user/config.h>
3+
#include <app.h>
4+
35

46
// Sonicteam::SoX::Physics::Havok::WorldHavok::Update
57
PPC_FUNC_IMPL(__imp__sub_82587AA8);
@@ -89,52 +91,30 @@ void ObjEspSwing_DecayRateFix(PPCRegister& f0, PPCRegister& f13, PPCRegister& de
8991

9092
void ObjVehicleBike_BulletDisableCollisionLayer(PPCRegister& r3)
9193
{
92-
if (Config::FPS <= 60.0)
93-
return;
94+
if (Config::FPS <= 60.0) return;
95+
96+
auto pVehicleBike = reinterpret_cast<Sonicteam::ObjectVehicleBike*>(g_memory.Translate(r3.u32));
97+
auto pNamedActorEntity = static_cast<Sonicteam::NamedActor*>(pVehicleBike->m_pDependency.get());
98+
99+
auto pEnemyShotNormal = static_cast<Sonicteam::Enemy::EnemyShotNormal*>(pNamedActorEntity->GetFirstDependent());
100+
sub_822C1FA8(*GetPPCContext(), g_memory.base);
94101

95-
auto ctx = GetPPCContext();
96-
auto base = g_memory.base;
97-
auto pVehicleBike = (Sonicteam::ObjectVehicleBike*)(g_memory.Translate(r3.u32));
98-
auto pNamedActorEntity = (Sonicteam::NamedActor*)(pVehicleBike->m_pDependency.get());
99-
auto pEnemyShotNormal = (Sonicteam::Enemy::EnemyShotNormal*)pNamedActorEntity->GetFirstDependent();
100-
sub_822C1FA8(*ctx, g_memory.base);
101-
auto pEnemyShotNormalAfter = (Sonicteam::Enemy::EnemyShotNormal*)pNamedActorEntity->GetFirstDependent();
102-
while (pEnemyShotNormal != pEnemyShotNormalAfter)
102+
// Process rigids created after the function call
103+
auto pCurrentShot = static_cast<Sonicteam::Enemy::EnemyShotNormal*>(pNamedActorEntity->GetFirstDependent());
104+
auto IsUpdatePhysicsWorld = false;
105+
while (pEnemyShotNormal != pCurrentShot)
103106
{
104-
pEnemyShotNormal = ((Sonicteam::Enemy::EnemyShotNormal*)pEnemyShotNormal->m_pSiblingPrev.get());
107+
pEnemyShotNormal = static_cast<Sonicteam::Enemy::EnemyShotNormal*>(pEnemyShotNormal->m_pSiblingPrev.get());
105108
auto pObject = reinterpret_cast<Sonicteam::SoX::Object*>(pEnemyShotNormal);
106109

107-
if (pObject->m_pVftable.ptr.get() == 0x820200C8)
110+
if (pObject->m_pVftable.ptr.get() == 0x820200C8 && pEnemyShotNormal->m_spPhantom)
108111
{
109-
auto hkpCollideable = &pEnemyShotNormal->m_spPhantom->m_pRigidBody->m_collidable;
110-
auto owner = hkpCollideable->m_parent.get();
111-
// pEnemyShotNormal->m_spPhantom->m_spWorldHavok->
112-
113-
printf("hkpCollideable %x\n", hkpCollideable);
114-
printf("owner %x\n", owner);
115-
printf("m_collisionFilterInfo : %x\n", pEnemyShotNormal->m_spPhantom->m_pRigidBody->m_collidable.m_broadPhaseHandle.m_collisionFilterInfo.get());
116-
printf("hkPhantom : %x\n", pEnemyShotNormal->m_spPhantom->m_pRigidBody->m_collidable);
117-
pEnemyShotNormal->m_spPhantom->m_pRigidBody->m_collidable.m_broadPhaseHandle.m_collisionFilterInfo = 0xFFFF0000;
118-
printf("pObject : %x\n", pObject);
112+
auto& collideable = pEnemyShotNormal->m_spPhantom->m_pRigidBody->m_collidable;
113+
collideable.m_broadPhaseHandle.m_collisionFilterInfo = 0xFFFF5E00;
114+
IsUpdatePhysicsWorld = true;
119115
}
120-
121-
}
122-
123-
/*
124-
if (pVehicleBike->m_pVehicleMissileCtrlAutomatic->m_IsShot)
125-
{
126-
pEnemyShotNormal->m_spPhantom->m_pRigidBody->m_collidable.m_broadPhaseHandle.m_collisionFilterInfo = 0x5E00;
127-
printf("SHOT\n");
128116
}
129-
*/
130-
printf("pEntityB : %x\n", pNamedActorEntity);
131-
printf("pEntityF : %x\n", pEnemyShotNormalAfter);
132-
133-
printf("NamedActor : %s\n", pNamedActorEntity->m_Name.c_str());
134-
printf("NamedActor : %s\n", pNamedActorEntity->m_Name.c_str());
135-
printf("pEntity : %x\n", pEnemyShotNormal);
136-
printf("m_pVehicleMissileCtrlAutomatic : %x\n", pVehicleBike->m_pVehicleMissileCtrlAutomatic->m_pMyPhantom.get());
137-
printf("m_pShotInfo : %x\n", pVehicleBike->m_pVehicleMissileCtrlAutomatic->m_pShotInfo.get());
138-
printf("m_pShotParameter : %x\n", pVehicleBike->m_pVehicleMissileCtrlAutomatic->m_pShotParameter.get());
139-
117+
if (IsUpdatePhysicsWorld)
118+
App::s_pApp->m_pDoc->GetDocMode<Sonicteam::GameMode>()->m_pGameImp->GetPhysicsWorld<Sonicteam::SoX::Physics::Havok::WorldHavok>()->m_pWorld.get()->updateCollisionFilterOnWorld(1, 1);
119+
140120
}

0 commit comments

Comments
 (0)