Warning
HERE BE DRAGONS
Hooks into Source engine physics to provide crash mitigation / physics simulation control. Used on Metastruct for past ~10 years for crash mitigation.
Intercepts PhysFrame, PhysIsInCallback, PhysOnCleanupDeleteList, and "IVP tree expansion" to:
- Pause/unpause physics simulation from Lua (
_G.SetShouldSimulate,_G.GetShouldSimulate) - Time individual physics frames (
GetPhysFrameLength) (now implemented in GMod) - Suppress physics cleanup when the server is about to crash (used by
gmsv_segfault) - Detect "runaway" "IVP tree expansion" and fire a Lua callback (
PhysFailed) (false positives?)
Also includes:
stop_physics_damnit: Callable from C to prevent physics cleanup deletion during crash handling.
Lua API (registered on successful init)
| Lua function | C function | Description |
|---|---|---|
SetShouldSimulate(bool) |
SetShouldSimulate |
Pause/resume physics simulation |
GetShouldSimulate() |
GetShouldSimulate |
Returns whether physics is simulating |
GetPhysFrameLength() |
GetPhysFrameLength |
Returns last physics frame time in seconds |
PhysFailed() |
(callback) | Called when IVP tree expansion exceeds safe limits |
Build
- Install premake
- Copy this repo inside the gbins alongside all the other binary modules
- Run
build.cmdorbuildas appropriate
Install
- Put
gmsv_physframe_linux.dllintogarrysmod/lua/bin/ - Install autorun lua to server.
- Depends on symbol signatures from
server_srv.soandvphysics_srv.so— x86-64 branch not supported. - Physics pausing works by patching the
m_bPausedfield at offset+0x58onCPhysicsHook, uhoh.
Garry, Metastruct, FreezeBug, BlueShank, MetaMan, SpiralP, CapsAdmin, etc, etc etc