Core API
Interface ID 1, version 2.0. Include <ROCK/Core.h> (and <ROCK/Client.h> for the helper). Namespace rock::api::core. Permissions: Read (1), Callbacks (4). Core registers your mod as an owner, binds the other interfaces to it and publishes ROCK's lifecycle state. Follow the discovery rules and the runtime contract.
Connect
- Resolve
ROCKAPI_QueryInterfaceV1(kQueryExportName) from the loadedROCK.dll. If ROCK is not loaded, keep running without its features. rock::api::Client::connect(query, "Your mod")queries Core 2.0 and callsregisterConsumer. A mod built for provider API 1 is refused by ROCK 1.0 withUnsupportedMajor.client.acquire(permissions, table)queries and binds each other interface.client.close()on the game thread unregisters the owner and releases everything it holds.
Every owner holds Core with Read from registration. Bind Core again with Read | Callbacks (5) to register frame callbacks.
Entry points
| Function | Permission | Thread | Purpose |
|---|---|---|---|
getModVersion | Read | Any | ROCK's version string, valid for the process lifetime. |
isProviderReady | Read | Any | 1 when ROCK's interaction runtime is ready. |
getSnapshot | Read | Any | The latest publication's lifecycle state; NotReady before the first publication. |
registerConsumer | none | Any, outside ROCK callbacks | Registers a new owner. OwnerConflict when the mod name is taken; CapacityFull beyond kMaxOwners (64). |
unregisterConsumer | none | Game | Releases every resource and callback of the owner. |
registerFrameCallback | Callbacks | Game (also at startup) | Calls callback(snapshot, userData) once per ROCK publication, up to kMaxFrameCallbacks (16). |
unregisterFrameCallback | Callbacks | Game | Stops future calls; does not wait for one in progress. |
bindInterface | none | Any | Binds a discovered interface major with permission bits. Busy if already bound at another major or with permissions this call would drop. |
getSample | Read | Any | Identity of the current publication. |
Snapshot
Snapshot holds sample (frame, publication sequence, generations), lifecycleFlags (LifecycleFlag: WorldAvailable, SkeletonReady, ProviderReady, MenuBlocking, ConfigBlocking, LoadingOrWorldTransition, GeneratedBodiesValid, PhysicsWriteAllowed, VisualWriteAllowed), lastLifecycleReason (LifecycleReason), and ROCK's own readiness this frame: frikSkeletonReady, menuBlocking, configBlocking, providerReady, stableFrameCount, deltaSeconds. The lifecycle flags come from ROCK's lifecycle state machine and can lag the readiness fields during transitions. Frame callbacks receive the same record, borrowed for the call.
LifecycleReason: GameLoaded, SkeletonReady, SkeletonDestroying, PowerArmorChanged, WorldAvailable, WorldChanged, WorldUnavailable, ProviderReady, ProviderLost, MenuBlocked, ConfigBlocked, GeneratedBodiesRebuilt, GeneratedBodiesInvalidated, TransitionSettled, Shutdown.
Records
Registration:modName[64], nonempty UTF-8, NUL-terminated within the array. It is the owner's identity: one owner per name.Owner:ownerToken,providerGeneration.
rock::api::core::Snapshot snapshot{};
if (client.core()->getSnapshot(client.owner(), &snapshot) == rock::api::Status::Ok &&
snapshot.providerReady && !snapshot.menuBlocking) {
// act this frame
}
Declarations
Complete public declarations: ROCK/Core.h
#pragma once
#include "Abi.h"
#pragma pack(push, 8)
namespace rock::api::core {
inline constexpr InterfaceId kInterfaceId = InterfaceId::Core;
inline constexpr std::uint32_t kMajor = 2;
inline constexpr std::uint32_t kMinor = 0;
inline constexpr std::uint32_t kMaxOwners = 64;
inline constexpr std::uint32_t kMaxFrameCallbacks = 16;
enum class LifecycleFlag : std::uint32_t
{
None = 0,
WorldAvailable = 1u << 0,
SkeletonReady = 1u << 1,
ProviderReady = 1u << 2,
MenuBlocking = 1u << 3,
ConfigBlocking = 1u << 4,
LoadingOrWorldTransition = 1u << 5,
GeneratedBodiesValid = 1u << 6,
PhysicsWriteAllowed = 1u << 7,
VisualWriteAllowed = 1u << 8,
};
enum class LifecycleReason : std::uint32_t
{
None = 0,
GameLoaded = 1,
SkeletonReady = 2,
SkeletonDestroying = 3,
PowerArmorChanged = 4,
WorldAvailable = 5,
WorldChanged = 6,
WorldUnavailable = 7,
ProviderReady = 8,
ProviderLost = 9,
MenuBlocked = 10,
ConfigBlocked = 11,
GeneratedBodiesRebuilt = 12,
GeneratedBodiesInvalidated = 13,
TransitionSettled = 14,
Shutdown = 15,
};
// modName: nonempty UTF-8, NUL-terminated within the array.
struct Registration
{
std::uint32_t size{ sizeof(Registration) };
std::uint32_t version{ 1 };
char modName[64]{};
};
struct Owner
{
std::uint32_t size{ sizeof(Owner) };
std::uint32_t version{ 1 };
OwnerToken ownerToken{ 0 };
std::uint32_t providerGeneration{ 0 };
};
// ROCK's lifecycle state for one publication. The readiness fields are the
// provider's own view this frame; lifecycleFlags (LifecycleFlag) is the
// lifecycle state machine, which can lag them during transitions.
struct Snapshot
{
std::uint32_t size{ sizeof(Snapshot) };
std::uint32_t version{ 1 };
Sample sample{};
std::uint32_t lifecycleFlags{ 0 };
LifecycleReason lastLifecycleReason{ LifecycleReason::None };
std::uint32_t frikSkeletonReady{ 0 };
std::uint32_t menuBlocking{ 0 };
std::uint32_t configBlocking{ 0 };
std::uint32_t providerReady{ 0 };
std::uint32_t stableFrameCount{ 0 };
float deltaSeconds{ 0.0f };
};
// Game thread, once per ROCK publication. The snapshot is borrowed for the
// call. Unregister stops future calls but does not wait for one already
// started; callback and userData must stay valid through it. A faulting
// callback revokes everything its owner holds.
using FrameCallback = void(ROCK_CALL*)(const Snapshot*, void*);
// Permission bits are local to this interface major. Discovery grants none.
enum class Permission : std::uint32_t { Read = 1, Callbacks = 4 };
inline constexpr std::uint32_t kSupportedPermissions = 5;
struct Api
{
static constexpr InterfaceId interfaceId = kInterfaceId;
static constexpr std::uint32_t majorVersion = kMajor;
static constexpr std::uint32_t minorVersion = kMinor;
// Any thread (Read). outValue stays valid for the process lifetime.
Status(ROCK_CALL* getModVersion)(OwnerToken owner, const char** outValue) noexcept;
Status(ROCK_CALL* isProviderReady)(OwnerToken owner, std::uint32_t* outValue) noexcept;
// Any thread (Read). The latest publication's lifecycle state.
Status(ROCK_CALL* getSnapshot)(OwnerToken owner, Snapshot* outSnapshot) noexcept;
// Any thread outside a ROCK callback. One owner per mod name; a name
// already registered is refused with OwnerConflict.
Status(ROCK_CALL* registerConsumer)(const Registration* registration, Owner* outOwner) noexcept;
// Game thread. Releases every resource and callback of the owner.
Status(ROCK_CALL* unregisterConsumer)(OwnerToken owner) noexcept;
// Game thread (Callbacks).
Status(ROCK_CALL* registerFrameCallback)(OwnerToken owner, FrameCallback callback, void* userData, std::uint64_t* outCallbackToken) noexcept;
Status(ROCK_CALL* unregisterFrameCallback)(OwnerToken owner, std::uint64_t callbackToken) noexcept;
// Binds an interface major discovered through ROCKAPI_QueryInterfaceV1
// to the owner with the requested permission bits.
Status(ROCK_CALL* bindInterface)(OwnerToken owner, InterfaceId interfaceId, std::uint32_t exactMajor, std::uint32_t permissions) noexcept;
// Any thread. Identity of the current publication.
Status(ROCK_CALL* getSample)(OwnerToken owner, Sample* outSample) noexcept;
};
}
#pragma pack(pop)
Complete public declarations: ROCK/Discovery.h
#pragma once
#include "Abi.h"
#pragma pack(push, 8)
namespace rock::api {
struct InterfaceDescriptorV1 {
std::uint32_t size{sizeof(InterfaceDescriptorV1)};
InterfaceId interfaceId{};
std::uint32_t major{};
std::uint32_t minor{};
std::uint32_t tableByteSize{};
std::uint32_t requiredCoreMajor{1};
std::uint32_t requiredCoreMinor{};
std::uint32_t reserved{};
const void* table{};
};
using QueryInterfaceV1 = Status(ROCK_CALL*)(InterfaceId, std::uint32_t exactMajor,
std::uint32_t minimumMinor, std::uint32_t minimumTableBytes,
const InterfaceDescriptorV1** outDescriptor) noexcept;
inline constexpr char kQueryExportName[] = "ROCKAPI_QueryInterfaceV1";
static_assert(sizeof(InterfaceDescriptorV1)==40);
}
#pragma pack(pop)
Complete public declarations: ROCK/Client.h
#pragma once
#include "Discovery.h"
#include "Core.h"
#include <cstring>
namespace rock::api {
// Consumer-side helper only. It is not part of the DLL ABI and imports no
// feature tables beyond Core. Pass the query export resolved from ROCK.dll.
class Client {
QueryInterfaceV1 _query{};
const core::Api* _core{};
OwnerToken _owner{};
public:
Client()=default;
Client(const Client&)=delete;
Client& operator=(const Client&)=delete;
// Close on the game thread before destroying callback userdata. Plugin
// DLL unload with live callbacks is outside this process-lifetime API.
Status connect(QueryInterfaceV1 query,const char* name) noexcept {
if (_owner) return Status::Busy;
if (!query || !name) return Status::InvalidArgument;
core::Registration registration{};
std::size_t length=0;
while (length<sizeof(registration.modName) && name[length]) ++length;
if (!length || length==sizeof(registration.modName)) return Status::InvalidArgument;
std::memcpy(registration.modName,name,length);
const InterfaceDescriptorV1* descriptor{};
auto status=query(core::kInterfaceId,core::kMajor,core::kMinor,sizeof(core::Api),&descriptor);
if (status!=Status::Ok) return status;
if (!descriptor || descriptor->size!=sizeof(InterfaceDescriptorV1) ||
descriptor->interfaceId!=core::kInterfaceId || descriptor->major!=core::kMajor ||
descriptor->tableByteSize<sizeof(core::Api) || !descriptor->table) return Status::InvalidSize;
const auto* coreApi=static_cast<const core::Api*>(descriptor->table);
core::Owner owner{};
status=coreApi->registerConsumer(®istration,&owner);
if (status!=Status::Ok) return status;
_query=query; _core=coreApi; _owner=owner.ownerToken;
return Status::Ok;
}
template<class Table> Status acquire(std::uint32_t permissions,const Table*& output) const noexcept {
output=nullptr;
if (!_owner || !_query) return Status::OwnerNotRegistered;
const InterfaceDescriptorV1* descriptor{};
auto status=_query(Table::interfaceId,Table::majorVersion,Table::minorVersion,sizeof(Table),&descriptor);
if (status!=Status::Ok) return status;
if (!descriptor || descriptor->size!=sizeof(InterfaceDescriptorV1) ||
descriptor->interfaceId!=Table::interfaceId || descriptor->major!=Table::majorVersion ||
descriptor->minor<Table::minorVersion || descriptor->tableByteSize<sizeof(Table) ||
descriptor->requiredCoreMajor!=core::kMajor || descriptor->requiredCoreMinor>core::kMinor || !descriptor->table) return Status::InvalidSize;
status=_core->bindInterface(_owner,Table::interfaceId,Table::majorVersion,permissions);
if (status==Status::Ok) output=static_cast<const Table*>(descriptor->table);
return status;
}
Status close() noexcept {
if (!_owner) return Status::Ok;
const auto status=_core->unregisterConsumer(_owner);
if (status==Status::Ok || status==Status::OwnerNotRegistered) {
_owner=0; _core=nullptr; _query=nullptr;
}
return status;
}
[[nodiscard]] OwnerToken owner() const noexcept { return _owner; }
[[nodiscard]] const core::Api* core() const noexcept { return _core; }
};
}