NativeInteraction API
Interface ID 14, version 2.0. Include <ROCK/NativeInteraction.h>. Namespace rock::api::native_interaction. Permissions: Read (1), Write (2); registration needs both. A native extension of ROCK's physics step: callbacks in ROCK's physics frame, Havok substep and world retirement; driving ROCK's weapon bodies by weapon slot; and extension handling of grab selection, extraction, grenade proximity and impact. SCISSORS is built on it.
This is a native-level interface. Extensions create, read and retire their own bodies and constraints and read Havok directly, using the world and bhkWorld of the current Frame. Native addresses are borrowed only inside the callback that supplied them.
Entry points
| Function | Permission | Thread / phase | Purpose |
|---|---|---|---|
registerExtension | Read + Write | Game, outside callbacks (a Core callback may register before the first frame) | Installs the extension's callbacks, up to kMaxExtensions (8). |
unregisterExtension | owner | Game | Runs retire and removes the extension. |
setDynamicObstacleLayers | Write | Update or WeaponUpdate | Which actor layers ROCK's dynamic hand and weapon bodies collide with. |
activateWeapon | Write | Update, WeaponUpdate or PreCollide | Wakes the slot's weapon body. |
setWeaponContactExclusion | Write | Update or WeaponUpdate | One target body the slot's weapon body stops colliding with. |
clearWeaponContactExclusion | Write | Update or WeaponUpdate | Removes it. |
hasWeaponContactExclusion | Read | Update or WeaponUpdate | Whether a body is excluded. |
copyWeaponSources | Read | WeaponUpdate | The generated weapon bodies and their source names, up to kMaxWeaponSources (128). |
getSourceGeometry | Read | WeaponUpdate | A body's source in weapon space, and with a direction its bounds and support point. |
setStaticContactPass | Write | Update | Replaces the owner's list of bodies that stop contacting static bodies (walls, fixed furniture, terrain) and keep every other contact. Zero bodies clears it; all extensions' lists combine up to kMaxStaticContactPassBodies. |
A faulting callback removes its extension.
Callbacks
Every callback is optional and receives context.
| Callback | When |
|---|---|
update(frame) | Once per ROCK physics frame. |
preCollide(frame) | Each Havok substep, before collision. |
retire(frame) | The world goes away or the extension is removed; remove everything held in that world. |
weaponUpdate(weaponFrame, command) | Each frame per driven weapon slot. |
weaponPreCollide(frame, slot) | Each substep; nonzero keeps driving. |
weaponContact(contact) | A contact of the slot's weapon body. Any physics thread: publish through a bounded thread-safe channel. |
handContact(contact) | A contact of a dynamic hand body (right 0, left 1; palm, finger or forearm) with a body on a layer enabled by setDynamicObstacleLayers, whether or not the hand holds anything. Every registered extension receives it; same rules as weaponContact. |
weaponRetire(frame, slot) | Before ROCK retires the slot's weapon body; remove your constraints on it. |
classifySelection, validateSelection, extractSelection | Grab selection and item extraction. |
proximityTarget, impactEffect | Grenade proximity and impact. |
Weapon driver
One extension at a time drives weapons by registering weaponUpdate (then weaponPreCollide and weaponRetire are required; another driver gets OwnerConflict). In weaponUpdate, WeaponFrame gives the slot, its dynamic body, the generation, the pose ROCK is about to drive to and the primary grip. Returning DriveResult::Controlled in WeaponCommand replaces the drive target and the visual weapon pose for that frame.
Weapon calls take weaponSlot below kMaxWeaponSlots. Slot 0 is the primary weapon and slot 1 the second equipped weapon; each slot has its own weapon body, callbacks, drive command and contact exclusion. For slot 1, primaryGripLocal is the holding hand on that weapon. A slot without a weapon body returns TargetUnavailable (clearing it is a no-op). A BodyIdentity must match the live body field for field.
Obstacles
setDynamicObstacleLayers(owner, mask) takes a layer bit mask of 8 (Biped), 33 (BipedNoCC) and kPassiveObstacleLayer (55); any other bit returns InvalidArgument. The masks of all extensions combine. Extension bodies on kPassiveObstacleLayer should use collision group kPassiveObstacleGroup (0x0010): ROCK's dynamic proxies never use it, and the engine filter drops pairs within one group, so those bodies do not collide with each other.
Selection and gameplay
ROCK asks extensions in registration order; the first that handles a selection (SelectionKind other than Unhandled), proximity or impact query answers it. A selection's ticket holds extension-owned values only; re-resolve on action. SelectionQuery::stage is BeforeCoreTypes when ROCK asks before its own object types and AfterCoreTypes after them.
SelectionKind | Meaning |
|---|---|
Unhandled 0 | Not this extension's body; ROCK asks the next one. |
Blocked 1 | The body may not be grabbed. |
DirectConnectedBody 2 | ROCK holds the body as part of its connected body set (a ragdoll limb, for example), driving with the set's mass and moving the set onto the hand. |
DirectDetachedBody 3 | ROCK holds the body on its own, as a detached body. |
ExtractableItem 4 | ROCK calls extractSelection and holds the extracted reference. |
DirectLiveLimb 5 | A limb of a living actor whose ragdoll the extension drives toward its animation. ROCK holds it like DirectConnectedBody but drives with the limb's own mass and never moves the actor's body set onto the hand. |
ROCK accepts kinds up to kLastSelectionKind (DirectLiveLimb).
Records and values
| Record | Fields |
|---|---|
Frame | phase, sample, world, bhkWorld, hmdPosition, deltaSeconds, gameToHavok, havokToGame, substepSeconds, worldReady, menuBlocked, hmdValid, timingValid, timingFallback |
BodyIdentity | body, motion, collisionObject, ownerNode, shape, group (filter >> 16) |
WeaponFrame | weaponSlot, body, frame, generation, form, supportOwnsPose, requestedWeapon, centerWeaponLocal, primaryGripLocal, primaryGripValid, recoveryDistanceGame |
WeaponCommand | result (Unchanged, Controlled), requestedWeapon, presentation |
Contact | weaponSlot, weapon, frame, target, targetLayer, pointWorld, normalValid, normalWorld (unit, target surface toward the weapon), pointCount |
HandContact | hand, part (Palm, Finger, Forearm), frame, handBody, target, targetLayer, pointWorld, normalValid, normalWorld (toward the hand), pointCount |
WeaponSource, SourceGeometry | source: body, generation, name[64]; geometry: valid, triangleCount, generation, sourceInWeapon, boundsLocal, supportPointLocal |
SelectionQuery, SelectionReply | query: body, reference, world, hitNode, hitPoint, hasHitPoint, farSelection, stage; reply: kind, owner, visualNode, ticket[8], reason[64] |
ExtractedReference | nativeHandle, referenceForm, itemForm |
ProximityQuery, ProximityResult | query: radiusGame, reference; result: handled, targetForm, scanned, truncated |
ImpactQuery, ImpactResult | query: authoredDamage, source, target; result: handled, targetForm |
Phase: Update 1, PreCollide 2, Retire 4, WeaponUpdate 5, WeaponContact 6, WeaponRetire 7, Selection 8, Extraction 9, Gameplay 10, HandContact 11. kInvalidBody (0x7FFFFFFF) marks a missing body. packTransform and unpackTransform convert between Transform and a native NiTransform value by value; native NiMatrix3 rows carry a fourth padding lane, so never copy nine floats directly. Phase 3 (Render) and DriveResult 2 (RetireWeapon) are retired and never reused.
Declarations
Complete public declarations: ROCK/NativeInteraction.h
#pragma once
#include "Abi.h"
// FO4VR-native extension of ROCK's physics step: callbacks in ROCK's physics
// frame, Havok substep and world retirement; driving ROCK's weapon bodies by
// weapon slot; and extension handling of grab selection, extraction, grenade
// proximity and impact. Extensions own their bodies and constraints and read
// Havok directly. Native addresses are borrowed only inside the callback that
// supplied them; they are not save identities and never cross threads.
#pragma pack(push, 8)
namespace rock::api::native_interaction {
inline constexpr InterfaceId kInterfaceId = InterfaceId::NativeInteraction;
inline constexpr std::uint32_t kMajor = 2;
inline constexpr std::uint32_t kMinor = 0;
inline constexpr std::uint32_t kSupportedPermissions = 3;
inline constexpr std::uint32_t kInvalidBody = 0x7FFF'FFFF;
inline constexpr std::uint32_t kMaxExtensions = 8;
inline constexpr std::uint32_t kMaxWeaponSources = 128;
inline constexpr std::uint32_t kPassiveObstacleLayer = 55;
// Collision group for extension bodies on kPassiveObstacleLayer. ROCK's
// dynamic proxies never use it: the engine filter drops same-group pairs.
inline constexpr std::uint32_t kPassiveObstacleGroup = 0x0010;
// Most bodies setStaticContactPass takes, over all extensions.
inline constexpr std::uint32_t kMaxStaticContactPassBodies = 128;
// Value-only marshalling: real NiMatrix3 rows contain a fourth padding lane.
// Never memcpy nine floats from/to that native matrix storage.
template <class NativeTransform> Transform packTransform(const NativeTransform& native) {
Transform value{};
for (int row = 0; row < 3; ++row)
for (int column = 0; column < 3; ++column) value.rotate[row * 3 + column] = native.rotate.entry[row][column];
value.translate[0] = native.translate.x;
value.translate[1] = native.translate.y;
value.translate[2] = native.translate.z;
value.scale = native.scale;
return value;
}
template <class NativeTransform> NativeTransform unpackTransform(const Transform& value) {
NativeTransform native{};
for (int row = 0; row < 3; ++row)
for (int column = 0; column < 3; ++column) native.rotate.entry[row][column] = value.rotate[row * 3 + column];
if constexpr (std::extent_v<decltype(native.rotate.entry), 1> > 3)
for (int row = 0; row < 3; ++row) native.rotate.entry[row][3] = 0;
native.translate = { value.translate[0], value.translate[1], value.translate[2] };
native.scale = value.scale;
return native;
}
// Value 3 (the retired Render phase) is never reused.
enum class Phase : std::uint32_t
{
Update = 1,
PreCollide = 2,
Retire = 4,
WeaponUpdate = 5,
WeaponContact = 6,
WeaponRetire = 7,
Selection = 8,
Extraction = 9,
Gameplay = 10,
HandContact = 11,
};
// world and bhkWorld are the live hknpWorld and bhkWorld of this step.
struct Frame
{
std::uint32_t size{ sizeof(Frame) };
std::uint32_t version{ 1 };
Phase phase{ Phase::Update };
Sample sample{};
std::uintptr_t world{ 0 };
std::uintptr_t bhkWorld{ 0 };
Point3 hmdPosition{};
float deltaSeconds{ 0.0f };
float gameToHavok{ 0.0f };
float havokToGame{ 0.0f };
float substepSeconds{ 0.0f };
std::uint32_t worldReady{ 0 };
std::uint32_t menuBlocked{ 0 };
std::uint32_t hmdValid{ 0 };
std::uint32_t timingValid{ 0 };
std::uint32_t timingFallback{ 0 };
};
// A live Havok body. ROCK compares every field with the body before acting,
// so a reused body id never matches. group is filter >> 16.
struct BodyIdentity
{
std::uint32_t body{ kInvalidBody };
std::uint32_t motion{ kInvalidBody };
std::uintptr_t collisionObject{ 0 };
std::uintptr_t ownerNode{ 0 };
std::uintptr_t shape{ 0 };
std::uint32_t group{ 0 };
bool operator==(const BodyIdentity&) const = default;
};
// ------------------------------------------------------------------
// Weapon driving
// ------------------------------------------------------------------
struct WeaponSource
{
std::uint32_t size{ sizeof(WeaponSource) };
std::uint32_t version{ 1 };
std::uint32_t body{ kInvalidBody };
std::uint64_t generation{ 0 };
char name[64]{};
};
// A generated weapon body's source in weapon space; bounds and the support
// point in the direction asked for are filled only when one is given.
struct SourceGeometry
{
std::uint32_t size{ sizeof(SourceGeometry) };
std::uint32_t version{ 1 };
std::uint32_t valid{ 0 };
std::uint32_t triangleCount{ 0 };
std::uint64_t generation{ 0 };
Transform sourceInWeapon{};
Bounds3 boundsLocal{};
Point3 supportPointLocal{};
};
// The weapon slot's dynamic body and the pose ROCK is about to drive it to.
struct WeaponFrame
{
std::uint32_t size{ sizeof(WeaponFrame) };
std::uint32_t version{ 1 };
std::uint32_t weaponSlot{ 0 };
std::uint32_t body{ kInvalidBody };
Frame frame{};
std::uint64_t generation{ 0 };
std::uint32_t form{ 0 };
std::uint32_t supportOwnsPose{ 0 };
Transform requestedWeapon{};
Point3 centerWeaponLocal{};
Point3 primaryGripLocal{};
std::uint32_t primaryGripValid{ 0 };
float recoveryDistanceGame{ 0.0f };
};
// Value 2 (the never-accepted RetireWeapon) is never reused.
enum class DriveResult : std::uint32_t
{
Unchanged = 0,
Controlled = 1,
};
// Controlled replaces the drive target and the visual weapon pose for
// this frame; Unchanged leaves ROCK's.
//
// lodged (with Controlled): the weapon is held by lodgeTarget's body, as a
// blade stuck in a limb. If the last hand lets go while the mark is from
// this frame or the last, and Weapon Equip Mode drops the weapon, ROCK
// places it at that command's presentation, without the hand's throw, and
// keeps it lodged: the loose
// weapon follows that body, takes the body's collision group so it never
// touches that actor, and stays until a hand takes it, the body goes away
// (it follows the same bone's new body when there is one), or it is
// pushed off. Then it falls as an ordinary loose weapon.
struct WeaponCommand
{
std::uint32_t size{ sizeof(WeaponCommand) };
std::uint32_t version{ 1 };
DriveResult result{ DriveResult::Unchanged };
Transform requestedWeapon{};
Transform presentation{};
std::uint32_t lodged{ 0 };
BodyIdentity lodgeTarget{};
};
// One contact of the slot's weapon body. normalWorld is the unit normal of
// the target surface toward the weapon, when normalValid. Havok builds
// contacts before the shapes meet (speculative points ahead of fast
// motion): separationGame is the signed distance of the manifold's
// closest point, game units, negative while the shapes overlap, when
// separationValid.
struct Contact
{
std::uint32_t size{ sizeof(Contact) };
std::uint32_t version{ 1 };
std::uint32_t weaponSlot{ 0 };
std::uint32_t weapon{ kInvalidBody };
Frame frame{};
std::uint32_t target{ kInvalidBody };
std::uint32_t targetLayer{ 0 };
Point3 pointWorld{};
std::uint32_t normalValid{ 0 };
Point3 normalWorld{};
std::uint32_t pointCount{ 0 };
std::uint32_t separationValid{ 0 };
float separationGame{ 0.0f };
};
// The part of a dynamic hand body that touched: the palm, a finger or
// the forearm.
enum class HandPart : std::uint32_t
{
Palm = 0,
Finger = 1,
Forearm = 2,
};
// One contact of a dynamic hand body with a body on a layer the
// extensions enabled through setDynamicObstacleLayers, whether or not that
// hand holds anything. hand is 0 for the right hand, 1 for the left.
// normalWorld is the unit normal of the target surface toward the hand,
// when normalValid; separationGame as Contact's.
struct HandContact
{
std::uint32_t size{ sizeof(HandContact) };
std::uint32_t version{ 1 };
std::uint32_t hand{ 0 };
HandPart part{ HandPart::Palm };
Frame frame{};
std::uint32_t handBody{ kInvalidBody };
std::uint32_t target{ kInvalidBody };
std::uint32_t targetLayer{ 0 };
Point3 pointWorld{};
std::uint32_t normalValid{ 0 };
Point3 normalWorld{};
std::uint32_t pointCount{ 0 };
std::uint32_t separationValid{ 0 };
float separationGame{ 0.0f };
};
// ------------------------------------------------------------------
// Selection, extraction, proximity, impact
// ------------------------------------------------------------------
enum class SelectionKind : std::uint32_t
{
Unhandled = 0,
Blocked = 1,
DirectConnectedBody = 2,
DirectDetachedBody = 3,
ExtractableItem = 4,
// A limb of a living actor whose ragdoll the extension drives toward
// its animation. ROCK holds it like DirectConnectedBody, but drives
// with the limb's own mass (the actor's motors pull back) and never
// moves the actor's body set onto the hand.
DirectLiveLimb = 5,
};
// Highest SelectionKind ROCK accepts from an extension.
inline constexpr SelectionKind kLastSelectionKind = SelectionKind::DirectLiveLimb;
enum class SelectionStage : std::uint32_t
{
BeforeCoreTypes = 0,
AfterCoreTypes = 1,
};
struct SelectionQuery
{
std::uint32_t size{ sizeof(SelectionQuery) };
std::uint32_t version{ 1 };
std::uint32_t body{ kInvalidBody };
std::uintptr_t reference{ 0 };
std::uintptr_t world{ 0 };
std::uintptr_t hitNode{ 0 };
Point3 hitPoint{};
std::uint32_t hasHitPoint{ 0 };
std::uint32_t farSelection{ 0 };
SelectionStage stage{ SelectionStage::BeforeCoreTypes };
};
struct SelectionReply
{
std::uint32_t size{ sizeof(SelectionReply) };
std::uint32_t version{ 1 };
SelectionKind kind{ SelectionKind::Unhandled };
OwnerToken owner{ 0 };
std::uintptr_t visualNode{ 0 };
// Extension-owned value ticket. Addresses may be opaque identity
// values, never pointers to dereference later. Re-resolve on action.
std::uint32_t ticket[8]{};
char reason[64]{};
};
struct ExtractedReference
{
std::uint32_t size{ sizeof(ExtractedReference) };
std::uint32_t version{ 1 };
std::uint32_t nativeHandle{ 0 };
std::uint32_t referenceForm{ 0 };
std::uint32_t itemForm{ 0 };
};
struct ProximityQuery
{
std::uint32_t size{ sizeof(ProximityQuery) };
std::uint32_t version{ 1 };
float radiusGame{ 0.0f };
std::uintptr_t reference{ 0 };
};
struct ProximityResult
{
std::uint32_t size{ sizeof(ProximityResult) };
std::uint32_t version{ 1 };
std::uint32_t handled{ 0 };
std::uint32_t targetForm{ 0 };
std::uint32_t scanned{ 0 };
std::uint32_t truncated{ 0 };
};
struct ImpactQuery
{
std::uint32_t size{ sizeof(ImpactQuery) };
std::uint32_t version{ 1 };
float authoredDamage{ 0.0f };
std::uintptr_t source{ 0 };
std::uintptr_t target{ 0 };
};
struct ImpactResult
{
std::uint32_t size{ sizeof(ImpactResult) };
std::uint32_t version{ 1 };
std::uint32_t handled{ 0 };
std::uint32_t targetForm{ 0 };
};
// ------------------------------------------------------------------
// Callbacks
// ------------------------------------------------------------------
using ExtractionCallback = Status(ROCK_CALL*)(const SelectionQuery*, const SelectionReply*, ExtractedReference*, void*) noexcept;
/*
* Every callback is optional. update runs once per ROCK physics frame,
* preCollide on each Havok substep before collision, retire when the world
* goes away or the extension is removed: remove everything the extension
* holds in that world there.
*
* One extension at a time drives weapons (weaponUpdate; then
* weaponPreCollide and weaponRetire are required). weaponPreCollide
* returns nonzero to keep driving this substep. weaponRetire runs before
* ROCK retires the slot's weapon body: remove every constraint on it.
* handContact reaches every extension that registers it, on the
* physics thread, like weaponContact.
* extractSelection requires classifySelection and validateSelection.
* The first extension that handles a selection, proximity or impact query
* answers it. A faulting callback removes its extension.
*/
struct Callbacks
{
std::uint32_t size{ sizeof(Callbacks) };
std::uint32_t version{ 1 };
void* context{ nullptr };
void(ROCK_CALL* update)(const Frame*, void*) noexcept {};
void(ROCK_CALL* preCollide)(const Frame*, void*) noexcept {};
void(ROCK_CALL* retire)(const Frame*, void*) noexcept {};
void(ROCK_CALL* weaponUpdate)(const WeaponFrame*, WeaponCommand*, void*) noexcept {};
std::uint32_t(ROCK_CALL* weaponPreCollide)(const Frame*, std::uint32_t weaponSlot, void*) noexcept {};
void(ROCK_CALL* weaponContact)(const Contact*, void*) noexcept {};
void(ROCK_CALL* weaponRetire)(const Frame*, std::uint32_t weaponSlot, void*) noexcept {};
void(ROCK_CALL* classifySelection)(const SelectionQuery*, SelectionReply*, void*) noexcept {};
ExtractionCallback extractSelection{};
std::uint32_t(ROCK_CALL* validateSelection)(const SelectionQuery*, const SelectionReply*, void*) noexcept {};
void(ROCK_CALL* proximityTarget)(const ProximityQuery*, ProximityResult*, void*) noexcept {};
void(ROCK_CALL* impactEffect)(const ImpactQuery*, ImpactResult*, void*) noexcept {};
void(ROCK_CALL* handContact)(const HandContact*, void*) noexcept {};
};
/*
* register/unregister: game thread, outside callbacks (a Core callback
* may register before the first frame); unregister runs retire.
* The other calls are valid only inside the owner's callbacks:
* setDynamicObstacleLayers and the contact exclusion calls in Update or
* WeaponUpdate; activateWeapon also in PreCollide; copyWeaponSources and
* getSourceGeometry in WeaponUpdate of that slot. Otherwise WrongThread.
* Weapon calls take weaponSlot < kMaxWeaponSlots (InvalidArgument
* otherwise) and are the weapon driver's. Slot 0 is the primary weapon,
* slot 1 the second equipped (akimbo) weapon; each has its own weapon
* body, callbacks, drive command and contact exclusion. A slot without a
* weapon body returns TargetUnavailable, and clearing it is a no-op.
*/
struct Api
{
static constexpr InterfaceId interfaceId = kInterfaceId;
static constexpr std::uint32_t majorVersion = kMajor;
static constexpr std::uint32_t minorVersion = kMinor;
Status(ROCK_CALL* registerExtension)(OwnerToken owner, const Callbacks* callbacks) noexcept;
Status(ROCK_CALL* unregisterExtension)(OwnerToken owner) noexcept;
// Which actor layers (8 Biped, 32 DeadBip, 33 BipedNoCC and
// kPassiveObstacleLayer) ROCK's dynamic hand and weapon bodies collide
// with, as a layer bit mask; any other bit returns InvalidArgument.
// An admitted 8, 32 or 33 stops touching ROCK's keyframed hand and
// weapon bodies, so dynamic limbs there are pushed only with real mass.
Status(ROCK_CALL* setDynamicObstacleLayers)(OwnerToken owner, std::uint64_t layerMask) noexcept;
Status(ROCK_CALL* activateWeapon)(OwnerToken owner, std::uint32_t weaponSlot) noexcept;
// One target body the slot's weapon body stops colliding with.
Status(ROCK_CALL* setWeaponContactExclusion)(OwnerToken owner, std::uint32_t weaponSlot, const BodyIdentity* target) noexcept;
Status(ROCK_CALL* clearWeaponContactExclusion)(OwnerToken owner, std::uint32_t weaponSlot) noexcept;
Status(ROCK_CALL* hasWeaponContactExclusion)(OwnerToken owner, std::uint32_t weaponSlot, const BodyIdentity* target, std::uint32_t* outExcluded) noexcept;
// Reports the total in outCount and copies min(capacity, total).
Status(ROCK_CALL* copyWeaponSources)(OwnerToken owner, std::uint32_t weaponSlot, WeaponSource* outSources, std::uint32_t capacity, std::uint32_t* outCount) noexcept;
Status(ROCK_CALL* getSourceGeometry)(OwnerToken owner, std::uint32_t weaponSlot, std::uint32_t body, const Point3* direction, SourceGeometry* outGeometry) noexcept;
// Update only: these bodies stop contacting static bodies (walls, fixed
// furniture, terrain) and keep every other contact. Replaces the owner's
// list; zero bodies clears it, as does Retire. A list that would take the
// extensions past kMaxStaticContactPassBodies returns CapacityFull.
Status(ROCK_CALL* setStaticContactPass)(OwnerToken owner, const std::uint32_t* bodies, std::uint32_t count) noexcept;
};
static_assert(std::is_standard_layout_v<Api> && sizeof(Api) == 10 * sizeof(void*));
static_assert(std::is_trivially_copyable_v<Callbacks> && std::is_trivially_copyable_v<BodyIdentity>);
}
#pragma pack(pop)