Skip to content

Commit 3c6b641

Browse files
committed
Added hkWorld::stepDeltaTime hook
Some fun can be had with this I'm sure
1 parent cd91fa9 commit 3c6b641

File tree

4 files changed

+377
-0
lines changed

4 files changed

+377
-0
lines changed

game/common/havok/hkWorld.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "hkWorld.hpp"
2+
3+
#include "memory/module.hpp"
4+
5+
HOOK_DECLARE_CLASS_MEMBER(0x00C78040, hkWorld, stepDeltaTime);
6+
7+
hkStepResult __thiscall hkWorld::stepDeltaTime(float physicsDeltaTime)
8+
{
9+
this;
10+
11+
//float physicsDeltaTime_ = 1.0f / 30.0f;
12+
//c_console::write_line("hkWorld::stepDeltaTime: %f in %f out", physicsDeltaTime, physicsDeltaTime_);
13+
//physicsDeltaTime = physicsDeltaTime_;
14+
15+
hkStepResult result = HK_STEP_RESULT_SUCCESS;
16+
HOOK_INVOKE_CLASS_MEMBER(result =, hkWorld, stepDeltaTime, physicsDeltaTime);
17+
return result;
18+
}
19+

game/common/havok/hkWorld.hpp

Lines changed: 350 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,350 @@
1+
#pragma once
2+
3+
#include "hkArray.hpp"
4+
#include "hkBase.hpp"
5+
#include "hkMath.hpp"
6+
7+
enum hkStepResult
8+
{
9+
HK_STEP_RESULT_SUCCESS = 0x0,
10+
HK_STEP_RESULT_MEMORY_FAILURE_BEFORE_INTEGRATION = 0x1,
11+
HK_STEP_RESULT_MEMORY_FAILURE_DURING_COLLIDE = 0x2,
12+
HK_STEP_RESULT_MEMORY_FAILURE_DURING_TOI_SOLVE = 0x3,
13+
};
14+
15+
struct hkSimulation;
16+
struct hkSimulationIsland;
17+
struct hkRigidBody;
18+
struct hkWorldMaintenanceMgr;
19+
struct hkWorldMemoryWatchDog;
20+
struct hkBroadPhase;
21+
struct hkTypedBroadPhaseDispatcher;
22+
struct hkPhantomBroadPhaseListener;
23+
struct hkEntityEntityBroadPhaseListener;
24+
struct hkBroadPhaseBorderListener;
25+
struct hkProcessCollisionInput;
26+
struct hkCollisionFilter;
27+
struct hkCollisionDispatcher;
28+
struct hkConvexListFilter;
29+
struct hkWorldOperationQueue;
30+
struct hkDebugInfoOnPendingOperationQueues;
31+
struct hkCriticalSection;
32+
struct hkPhantom;
33+
struct hkActionListener;
34+
struct hkEntity;
35+
struct hkBroadPhaseBorder;
36+
37+
struct hkMultiThreadLock
38+
{
39+
unsigned int m_threadId;
40+
short m_lockCount;
41+
unsigned short m_lockBitStack;
42+
};
43+
44+
struct hkStepInfo
45+
{
46+
hkPadSpu<float> m_startTime;
47+
hkPadSpu<float> m_endTime;
48+
hkPadSpu<float> m_deltaTime;
49+
hkPadSpu<float> m_invDeltaTime;
50+
};
51+
52+
struct hkSolverInfo
53+
{
54+
struct DeactivationInfo
55+
{
56+
float m_linearVelocityThresholdInv;
57+
float m_angularVelocityThresholdInv;
58+
float m_slowObjectVelocityMultiplier;
59+
float m_relativeSleepVelocityThreshold;
60+
unsigned short m_stepsToDeactivate;
61+
float m_maxDistSqrd[2];
62+
hkHalf m_maxRotSqrd[2];
63+
};
64+
65+
float m_one;
66+
float m_tau;
67+
float m_damping;
68+
float m_frictionTau;
69+
hkVector4 m_globalAccelerationPerSubStep;
70+
hkVector4 m_globalAccelerationPerStep;
71+
hkVector4 m_integrateVelocityFactor;
72+
hkVector4 m_invIntegrateVelocityFactor;
73+
float m_dampDivTau;
74+
float m_tauDivDamp;
75+
float m_dampDivFrictionTau;
76+
float m_frictionTauDivDamp;
77+
float m_contactRestingVelocity;
78+
hkSolverInfo::DeactivationInfo m_deactivationInfo[6];
79+
float m_deltaTime;
80+
float m_invDeltaTime;
81+
long m_numSteps;
82+
long m_numMicroSteps;
83+
float m_invNumMicroSteps;
84+
float m_invNumSteps;
85+
hkBool m_forceCoherentConstraintOrderingInSolver;
86+
unsigned char m_deactivationNumInactiveFramesSelectFlag[2];
87+
unsigned char m_deactivationIntegrateCounter;
88+
};
89+
90+
struct hkWorldDynamicsStepInfo
91+
{
92+
hkStepInfo m_stepInfo;
93+
hkSolverInfo m_solverInfo;
94+
};
95+
96+
struct hkWorld :
97+
public hkReferencedObject
98+
{
99+
public:
100+
hkStepResult __thiscall stepDeltaTime(float physicsDeltaTime);
101+
102+
struct PropertyLock
103+
{
104+
unsigned int m_key;
105+
hkMultiThreadLock m_multiThreadLock;
106+
};
107+
108+
hkSimulation* m_simulation;
109+
hkVector4 m_gravity;
110+
hkSimulationIsland* m_fixedIsland;
111+
hkRigidBody* m_fixedRigidBody;
112+
hkArray<hkSimulationIsland> m_activeSimulationIslands;
113+
hkArray<hkSimulationIsland> m_inactiveSimulationIslands;
114+
hkArray<hkSimulationIsland> m_dirtySimulationIslands;
115+
hkWorldMaintenanceMgr* m_maintenanceMgr;
116+
hkWorldMemoryWatchDog* m_memoryWatchDog;
117+
hkBroadPhase* m_broadPhase;
118+
hkTypedBroadPhaseDispatcher* m_broadPhaseDispatcher;
119+
hkPhantomBroadPhaseListener* m_phantomBroadPhaseListener;
120+
hkEntityEntityBroadPhaseListener* m_entityEntityBroadPhaseListener;
121+
hkBroadPhaseBorderListener* m_broadPhaseBorderListener;
122+
hkProcessCollisionInput* m_collisionInput;
123+
hkCollisionFilter* m_collisionFilter;
124+
hkCollisionDispatcher* m_collisionDispatcher;
125+
hkConvexListFilter* m_convexListFilter;
126+
hkWorldOperationQueue* m_pendingOperations;
127+
long m_pendingOperationsCount;
128+
long m_criticalOperationsLockCount;
129+
long m_criticalOperationsLockCountForPhantoms;
130+
hkBool m_blockExecutingPendingOperations;
131+
hkBool m_criticalOperationsAllowed;
132+
hkDebugInfoOnPendingOperationQueues* m_pendingOperationQueues;
133+
long m_pendingOperationQueueCount;
134+
hkMultiThreadLock m_multiThreadLock;
135+
hkBool m_processActionsInSingleThread;
136+
unsigned int m_minDesiredIslandSize;
137+
hkCriticalSection* m_modifyConstraintCriticalSection;
138+
hkCriticalSection* m_worldLock;
139+
hkCriticalSection* m_islandDirtyListCriticalSection;
140+
hkCriticalSection* m_propertyMasterLock;
141+
hkArray<PropertyLock> m_propertyLocks;
142+
hkBool m_wantSimulationIslands;
143+
float m_snapCollisionToConvexEdgeThreshold;
144+
float m_snapCollisionToConcaveEdgeThreshold;
145+
hkBool m_enableToiWeldRejection;
146+
hkBool m_wantDeactivation;
147+
hkBool m_wantOldStyleDeactivation;
148+
hkBool m_shouldActivateOnRigidBodyTransformChange;
149+
float m_highFrequencyDeactivationPeriod;
150+
float m_lowFrequencyDeactivationPeriod;
151+
float m_deactivationReferenceDistance;
152+
float m_toiCollisionResponseRotateNormal;
153+
long m_simulationType;
154+
unsigned int m_lastEntityUid;
155+
hkArray<hkPhantom> m_phantoms;
156+
hkArray<hkActionListener> m_actionListeners;
157+
hkArray<hkEntity> m_entityListeners;
158+
unsigned char m_phantomListeners[12];
159+
unsigned char m_constraintListeners[12];
160+
unsigned char m_worldDeletionListeners[12];
161+
unsigned char m_islandActivationListeners[12];
162+
unsigned char m_worldPostSimulationListeners[12];
163+
unsigned char m_worldPostIntegrateListeners[12];
164+
unsigned char m_worldPostCollideListeners[12];
165+
unsigned char m_islandPostIntegrateListeners[12];
166+
unsigned char m_islandPostCollideListeners[12];
167+
unsigned char m_collisionListeners[12];
168+
hkBroadPhaseBorder* m_broadPhaseBorder;
169+
hkWorldDynamicsStepInfo m_dynamicsStepInfo;
170+
hkVector4 m_broadPhaseExtents[2];
171+
long m_broadPhaseNumMarkers;
172+
long m_sizeOfToiEventQueue;
173+
long m_broadPhaseQuerySize;
174+
long m_broadPhaseUpdateSize;
175+
signed char m_contactPointGeneration;
176+
};
177+
static_assert(sizeof(hkWorld) == 0x320);
178+
static_assert(0x008 == __builtin_offsetof(hkWorld, m_simulation));
179+
static_assert(0x010 == __builtin_offsetof(hkWorld, m_gravity));
180+
static_assert(0x020 == __builtin_offsetof(hkWorld, m_fixedIsland));
181+
static_assert(0x024 == __builtin_offsetof(hkWorld, m_fixedRigidBody));
182+
static_assert(0x028 == __builtin_offsetof(hkWorld, m_activeSimulationIslands));
183+
static_assert(0x034 == __builtin_offsetof(hkWorld, m_inactiveSimulationIslands));
184+
static_assert(0x040 == __builtin_offsetof(hkWorld, m_dirtySimulationIslands));
185+
static_assert(0x04C == __builtin_offsetof(hkWorld, m_maintenanceMgr));
186+
static_assert(0x050 == __builtin_offsetof(hkWorld, m_memoryWatchDog));
187+
static_assert(0x054 == __builtin_offsetof(hkWorld, m_broadPhase));
188+
static_assert(0x058 == __builtin_offsetof(hkWorld, m_broadPhaseDispatcher));
189+
static_assert(0x05C == __builtin_offsetof(hkWorld, m_phantomBroadPhaseListener));
190+
static_assert(0x060 == __builtin_offsetof(hkWorld, m_entityEntityBroadPhaseListener));
191+
static_assert(0x064 == __builtin_offsetof(hkWorld, m_broadPhaseBorderListener));
192+
static_assert(0x068 == __builtin_offsetof(hkWorld, m_collisionInput));
193+
static_assert(0x06C == __builtin_offsetof(hkWorld, m_collisionFilter));
194+
static_assert(0x070 == __builtin_offsetof(hkWorld, m_collisionDispatcher));
195+
static_assert(0x074 == __builtin_offsetof(hkWorld, m_convexListFilter));
196+
static_assert(0x078 == __builtin_offsetof(hkWorld, m_pendingOperations));
197+
static_assert(0x07C == __builtin_offsetof(hkWorld, m_pendingOperationsCount));
198+
static_assert(0x080 == __builtin_offsetof(hkWorld, m_criticalOperationsLockCount));
199+
static_assert(0x084 == __builtin_offsetof(hkWorld, m_criticalOperationsLockCountForPhantoms));
200+
static_assert(0x088 == __builtin_offsetof(hkWorld, m_blockExecutingPendingOperations));
201+
static_assert(0x089 == __builtin_offsetof(hkWorld, m_criticalOperationsAllowed));
202+
static_assert(0x08C == __builtin_offsetof(hkWorld, m_pendingOperationQueues));
203+
static_assert(0x090 == __builtin_offsetof(hkWorld, m_pendingOperationQueueCount));
204+
static_assert(0x094 == __builtin_offsetof(hkWorld, m_multiThreadLock));
205+
static_assert(0x09C == __builtin_offsetof(hkWorld, m_processActionsInSingleThread));
206+
static_assert(0x0A0 == __builtin_offsetof(hkWorld, m_minDesiredIslandSize));
207+
static_assert(0x0A4 == __builtin_offsetof(hkWorld, m_modifyConstraintCriticalSection));
208+
static_assert(0x0A8 == __builtin_offsetof(hkWorld, m_worldLock));
209+
static_assert(0x0AC == __builtin_offsetof(hkWorld, m_islandDirtyListCriticalSection));
210+
static_assert(0x0B0 == __builtin_offsetof(hkWorld, m_propertyMasterLock));
211+
static_assert(0x0B4 == __builtin_offsetof(hkWorld, m_propertyLocks));
212+
static_assert(0x0C0 == __builtin_offsetof(hkWorld, m_wantSimulationIslands));
213+
static_assert(0x0C4 == __builtin_offsetof(hkWorld, m_snapCollisionToConvexEdgeThreshold));
214+
static_assert(0x0C8 == __builtin_offsetof(hkWorld, m_snapCollisionToConcaveEdgeThreshold));
215+
static_assert(0x0CC == __builtin_offsetof(hkWorld, m_enableToiWeldRejection));
216+
static_assert(0x0CD == __builtin_offsetof(hkWorld, m_wantDeactivation));
217+
static_assert(0x0CE == __builtin_offsetof(hkWorld, m_wantOldStyleDeactivation));
218+
static_assert(0x0CF == __builtin_offsetof(hkWorld, m_shouldActivateOnRigidBodyTransformChange));
219+
static_assert(0x0D0 == __builtin_offsetof(hkWorld, m_highFrequencyDeactivationPeriod));
220+
static_assert(0x0D4 == __builtin_offsetof(hkWorld, m_lowFrequencyDeactivationPeriod));
221+
static_assert(0x0D8 == __builtin_offsetof(hkWorld, m_deactivationReferenceDistance));
222+
static_assert(0x0DC == __builtin_offsetof(hkWorld, m_toiCollisionResponseRotateNormal));
223+
static_assert(0x0E0 == __builtin_offsetof(hkWorld, m_simulationType));
224+
static_assert(0x0E4 == __builtin_offsetof(hkWorld, m_lastEntityUid));
225+
static_assert(0x0E8 == __builtin_offsetof(hkWorld, m_phantoms));
226+
static_assert(0x0F4 == __builtin_offsetof(hkWorld, m_actionListeners));
227+
static_assert(0x100 == __builtin_offsetof(hkWorld, m_entityListeners));
228+
static_assert(0x10C == __builtin_offsetof(hkWorld, m_phantomListeners));
229+
static_assert(0x118 == __builtin_offsetof(hkWorld, m_constraintListeners));
230+
static_assert(0x124 == __builtin_offsetof(hkWorld, m_worldDeletionListeners));
231+
static_assert(0x130 == __builtin_offsetof(hkWorld, m_islandActivationListeners));
232+
static_assert(0x13C == __builtin_offsetof(hkWorld, m_worldPostSimulationListeners));
233+
static_assert(0x148 == __builtin_offsetof(hkWorld, m_worldPostIntegrateListeners));
234+
static_assert(0x154 == __builtin_offsetof(hkWorld, m_worldPostCollideListeners));
235+
static_assert(0x160 == __builtin_offsetof(hkWorld, m_islandPostIntegrateListeners));
236+
static_assert(0x16C == __builtin_offsetof(hkWorld, m_islandPostCollideListeners));
237+
static_assert(0x178 == __builtin_offsetof(hkWorld, m_collisionListeners));
238+
static_assert(0x184 == __builtin_offsetof(hkWorld, m_broadPhaseBorder));
239+
static_assert(0x190 == __builtin_offsetof(hkWorld, m_dynamicsStepInfo));
240+
static_assert(0x2E0 == __builtin_offsetof(hkWorld, m_broadPhaseExtents));
241+
static_assert(0x300 == __builtin_offsetof(hkWorld, m_broadPhaseNumMarkers));
242+
static_assert(0x304 == __builtin_offsetof(hkWorld, m_sizeOfToiEventQueue));
243+
static_assert(0x308 == __builtin_offsetof(hkWorld, m_broadPhaseQuerySize));
244+
static_assert(0x30C == __builtin_offsetof(hkWorld, m_broadPhaseUpdateSize));
245+
static_assert(0x310 == __builtin_offsetof(hkWorld, m_contactPointGeneration));
246+
247+
struct hkSimulation :
248+
public hkReferencedObject
249+
{
250+
enum LastProcessingStep
251+
{
252+
INTEGRATE = 0,
253+
COLLIDE = 1,
254+
};
255+
hkWorld* m_world;
256+
LastProcessingStep m_lastProcessingStep;
257+
float m_currentTime;
258+
float m_currentPsiTime;
259+
float m_physicsDeltaTime;
260+
float m_simulateUntilTime;
261+
float m_frameMarkerPsiSnap;
262+
hkStepResult m_previousStepResult;
263+
};
264+
static_assert(sizeof(hkSimulation) == 0x28);
265+
266+
struct hkConstraintInfo
267+
{
268+
long m_maxSizeOfSchema;
269+
long m_sizeOfSchemas;
270+
long m_numSolverResults;
271+
long m_numSolverElemTemps;
272+
};
273+
static_assert(sizeof(hkConstraintInfo) == 0x10);
274+
275+
struct hkConstraintOwner :
276+
public hkReferencedObject
277+
{
278+
hkConstraintInfo m_constraintInfo;
279+
};
280+
static_assert(sizeof(hkConstraintOwner) == 0x18);
281+
282+
struct hkAction :
283+
public hkReferencedObject
284+
{
285+
hkWorld* m_world;
286+
hkSimulationIsland* m_island;
287+
unsigned int m_userData;
288+
char const* m_name;
289+
};
290+
static_assert(sizeof(hkAction) == 0x18);
291+
292+
struct hkAgentNnSector
293+
{
294+
char m_data[512];
295+
};
296+
static_assert(sizeof(hkAgentNnSector) == 0x200);
297+
298+
struct hkAgentNnTrack
299+
{
300+
unsigned int m_bytesUsedInLastSector;
301+
hkInplaceArray<hkAgentNnSector*, 1> m_sectors;
302+
};
303+
304+
struct hkSimulationIsland :
305+
public hkConstraintOwner
306+
{
307+
hkWorld* m_world;
308+
long m_numConstraints;
309+
unsigned short m_storageIndex;
310+
unsigned short m_dirtyListIndex;
311+
unsigned char m_splitCheckFrameCounter;
312+
unsigned char m_highFrequencyDeactivationCounter;
313+
unsigned char m_lowFrequencyDeactivationCounter;
314+
char m_splitCheckRequested : 2;
315+
char m_sparseEnabled : 2;
316+
char m_actionListCleanupNeeded : 2;
317+
char m_allowIslandLocking : 2;
318+
char m_isInActiveIslandsArray : 2;
319+
char m_active : 2;
320+
char m_inIntegrateJob : 2;
321+
hkMultiThreadLock m_multiThreadLock;
322+
float m_timeSinceLastHighFrequencyCheck;
323+
float m_timeSinceLastLowFrequencyCheck;
324+
hkArray<hkAction*> m_actions;
325+
float m_timeOfDeactivation;
326+
hkInplaceArray<hkEntity*, 1> m_entities;
327+
hkAgentNnTrack m_agentTrack;
328+
};
329+
static_assert(sizeof(hkSimulationIsland) == 0x70);
330+
static_assert(0x18 == __builtin_offsetof(hkSimulationIsland, m_world));
331+
static_assert(0x1C == __builtin_offsetof(hkSimulationIsland, m_numConstraints));
332+
static_assert(0x20 == __builtin_offsetof(hkSimulationIsland, m_storageIndex));
333+
static_assert(0x22 == __builtin_offsetof(hkSimulationIsland, m_dirtyListIndex));
334+
static_assert(0x24 == __builtin_offsetof(hkSimulationIsland, m_splitCheckFrameCounter));
335+
static_assert(0x25 == __builtin_offsetof(hkSimulationIsland, m_highFrequencyDeactivationCounter));
336+
static_assert(0x26 == __builtin_offsetof(hkSimulationIsland, m_lowFrequencyDeactivationCounter));
337+
//static_assert(0x27 == __builtin_offsetof(hkSimulationIsland, m_splitCheckRequested));
338+
//static_assert(0x27 == __builtin_offsetof(hkSimulationIsland, m_sparseEnabled));
339+
//static_assert(0x27 == __builtin_offsetof(hkSimulationIsland, m_actionListCleanupNeeded));
340+
//static_assert(0x27 == __builtin_offsetof(hkSimulationIsland, m_allowIslandLocking));
341+
//static_assert(0x28 == __builtin_offsetof(hkSimulationIsland, m_isInActiveIslandsArray));
342+
//static_assert(0x28 == __builtin_offsetof(hkSimulationIsland, m_active));
343+
//static_assert(0x28 == __builtin_offsetof(hkSimulationIsland, m_inIntegrateJob));
344+
static_assert(0x2C == __builtin_offsetof(hkSimulationIsland, m_multiThreadLock));
345+
static_assert(0x34 == __builtin_offsetof(hkSimulationIsland, m_timeSinceLastHighFrequencyCheck));
346+
static_assert(0x38 == __builtin_offsetof(hkSimulationIsland, m_timeSinceLastLowFrequencyCheck));
347+
static_assert(0x3C == __builtin_offsetof(hkSimulationIsland, m_actions));
348+
static_assert(0x48 == __builtin_offsetof(hkSimulationIsland, m_timeOfDeactivation));
349+
static_assert(0x4C == __builtin_offsetof(hkSimulationIsland, m_entities));
350+
static_assert(0x5C == __builtin_offsetof(hkSimulationIsland, m_agentTrack));

game/game.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ copy /b $(ProjectDir)source\config\version.cpp +,, $(ProjectDir)source\config\ve
193193
</PreBuildEvent>
194194
</ItemDefinitionGroup>
195195
<ItemGroup>
196+
<ClCompile Include="common\havok\hkWorld.cpp" />
196197
<ClCompile Include="source\ai\activities.cpp" />
197198
<ClCompile Include="source\ai\actors.cpp" />
198199
<ClCompile Include="source\ai\actor_dynamic_firing_position.cpp" />
@@ -799,6 +800,7 @@ copy /b $(ProjectDir)source\config\version.cpp +,, $(ProjectDir)source\config\ve
799800
<ClInclude Include="common\havok\hkMonitor.hpp" />
800801
<ClInclude Include="common\havok\hkShape.hpp" />
801802
<ClInclude Include="common\havok\hkThread.hpp" />
803+
<ClInclude Include="common\havok\hkWorld.hpp" />
802804
<ClInclude Include="source\ai\activities.hpp" />
803805
<ClInclude Include="source\ai\actor_firing_position.hpp" />
804806
<ClInclude Include="source\ai\actor_moving.hpp" />

0 commit comments

Comments
 (0)