First PAPER consumer
This observer registers one owner with RuntimeState and FrameCallbacks, and copies PAPER's runtime state once per frame on FrameComplete. It changes nothing in the game.
ReloadObserver.cpp
#include <Windows.h>
#include <PAPER/Client.h>
namespace api = paper::api;
class ReloadObserver {
api::Client client_;
std::uint64_t callback_{};
api::RuntimeState lastState_{};
bool valid_{};
static void PAPER_CALL onEvent(const api::Event* event, void* userData) noexcept
{
if (!event || event->kind != api::EventKind::FrameComplete) return;
auto& self = *static_cast<ReloadObserver*>(userData);
// event->runtime is a value copy for this frame; the event itself is
// borrowed only for this call.
self.lastState_ = event->runtime;
self.valid_ = true;
}
public:
// Game thread, once game data is loaded and PAPER is ready.
api::Status start() noexcept
{
auto* module = GetModuleHandleW(L"PAPER.dll");
auto query = module ? reinterpret_cast<api::QueryInterfaceV1>(GetProcAddress(module, api::kQueryExportName)) : nullptr;
if (!query) return api::Status::NotReady; // PAPER absent: run without it
constexpr auto wanted = static_cast<std::uint32_t>(api::ConsumerCapability::RuntimeState) |
static_cast<std::uint32_t>(api::ConsumerCapability::FrameCallbacks);
auto status = client_.connect(query, "Example reload observer", wanted);
if (status == api::Status::Ok && (client_.grantedCapabilities() & wanted) != wanted)
status = api::Status::PermissionDenied;
if (status == api::Status::Ok)
status = client_.providerApi()->registerEventCallback(client_.owner(), &onEvent, this, &callback_);
if (status != api::Status::Ok) (void)stop();
return status;
}
// Game thread. Closing the owner also removes its callbacks, leases and
// authority requests.
api::Status stop() noexcept
{
const auto status = client_.close();
if (status != api::Status::Ok) return status;
callback_ = 0;
valid_ = false;
return api::Status::Ok;
}
// Game thread; this object is not thread-safe.
bool copyLastState(api::RuntimeState& output) const noexcept
{
if (!valid_) return false;
output = lastState_;
return true;
}
};
Notes
Client::connectqueries Provider 2.0 and callsregisterConsumer;Client::acquirequeries any further interface, such asphysical_reload::Api. A PAPER that does not serve major 2 returnsUnsupportedMajor;UnsupportedMinororTableTooSmallmean the installed PAPER is older than your headers.stop()must run on the game thread, and before the object is destroyed:Clienthas no destructor that unregisters. Ifstop()fails, keep the object alive and retry.- The owner name is your mod's identity. A second
connectwith the same name returnsOwnerConflict. - Every record you pass or receive is value-initialized (
{}); itssizeandversiondefaults are what PAPER expects. - A normal
RuntimeResetevent preserves registrations and callbacks but clears leases and observations; invalidate local data and rearm deliberately. A full provider reinitialization needs a newconnect. FrameCompleteis the control and lease boundary. A final native-pose observer also requestsNativePosePipelineand handlesPresentationComplete.
PAPER's own build compiles a minimal consumer (tests/ConsumerExample.cpp, a physical-reload owner) against these headers in its public header tests.