UnrealModFramework
Mod framework API
Loading...
Searching...
No Matches
ModAPIRegistry.h
Go to the documentation of this file.
1// Copyright (c) 2026 Nelaric Contributors
3#pragma once
4
5#include "ModAPIBlueprint.h"
6#include "ModAPIObject.h"
7#include "UObject/SoftObjectPath.h"
8
9class ULocalPlayer;
11class UWorld;
12struct FModExtensionWorld;
13
14namespace Mod::API
15{
16struct FRegistryState;
17struct FScopeState;
18struct FCallerState;
19struct FRegistrationState;
20
22enum class EScope : uint8
23{
28};
29
32{
34 const TCHAR* ExportId;
36 const TCHAR* ExportVersion;
38 const TCHAR* Signature;
39};
40
43{
45 FName TypeId;
47 UClass* Class = nullptr;
51 FString Signature;
53 const void* Calls = nullptr;
55 TArray<FAPIDescriptor> APIs;
57 bool bAllowWorldless = false;
59 bool bFullView = false;
63 TConstArrayView<FBlueprintFunction> BlueprintFunctions;
65 FSoftClassPath BlueprintClass;
66};
67
69class MODAPI_API FRegistration
70{
71public:
73 FRegistration() = default;
79 FRegistration(FRegistration&& Other) noexcept;
86 void Reset();
87
88private:
89 FRegistration(const FRegistration&) = delete;
90 FRegistration& operator=(const FRegistration&) = delete;
91
92 friend class FRegistry;
93 friend class FGeneratedHostRegistration;
94 TSharedPtr<FRegistrationState> State;
95};
96
98class FScope
99{
100private:
101 friend class FRegistry;
102 TSharedPtr<FScopeState> State;
103};
104
107{
108private:
109 friend class FRegistry;
110 friend struct FHostAccess;
111 friend struct FNativeAccess;
112 TSharedPtr<FCallerState> State;
113};
114
116class MODAPI_API FRegistry
117{
118public:
138 TModResult<FScope> OpenPlayerScope(ULocalPlayer* Player, const FScope& WorldScope);
149 TModResult<FCaller> CreateCaller(const FScope& Scope, TSet<FName> Permissions);
161 TModResult<FRegistration> RegisterProvider(FName TypeId, const FScope& Scope, UObject* Instance);
168 TModResult<FObjectBinding> BindProvider(FName TypeId, const TCHAR* Signature, const FCaller& Caller);
169
170public:
171 TModResult<FRegistration> RegisterService(FName Service, FName TypeId, const TCHAR* Signature, const FScope& Scope,
172 UObject* Instance, TWeakPtr<FModExtensionWorld> World = {});
173 TModResult<FRegistration> RegisterStagedService(FName Service, FName TypeId, const TCHAR* Signature,
174 const FScope& Scope, UObject* Instance,
175 TWeakPtr<FModExtensionWorld> World);
176 bool HasServiceType(FName TypeId, const TCHAR* Signature) const;
177 TModResult<FObjectBinding> BindPayload(const FCaller& Caller, UObject& Object, FName TypeId,
178 const TCHAR* Signature);
180 TModResult<FObjectBinding> BindWorldObject(const FCaller& Caller, UObject& Object, FName TypeId,
181 const TCHAR* Signature, bool bReadOnly, bool bWorldOwned = false);
183 UClass* FindWorldType(FName TypeId, FString& OutSignature) const;
185 FSoftClassPath FindBlueprintWorldType(FName TypeId, FString& OutSignature) const;
187 const FString* FindLocalPlayerSignature(FName TypeId) const;
188 TModResult<FObjectBinding> BindService(FName Service, FName TypeId, const TCHAR* Signature, const FCaller& Caller);
189
190private:
191 TModResult<FRegistration> RegisterProvider(FName Service, FName TypeId, const TCHAR* Signature, const FScope& Scope,
192 UObject* Instance, bool bAllowBeforeBeginPlay = false,
193 TWeakPtr<FModExtensionWorld> World = {});
194 TModResult<FObjectBinding> BindProvider(FName Service, FName TypeId, const TCHAR* Signature, const FCaller& Caller);
195 FRegistry(const FRegistry&) = delete;
196 FRegistry& operator=(const FRegistry&) = delete;
197
198 friend struct FNativeAccess;
199 friend class ::UModAPIHostSubsystem;
200 TModResult<FRegistration> RegisterLocalPlayerProvider(FName TypeId, const FScope& Scope);
201 TSharedPtr<FRegistryState> State;
202};
203
209template <class T> auto BindView(FRegistry& Registry, const FCaller& Caller)
210{
211 using FView = FModRuntimeObject<T>;
212 auto Binding = Registry.BindProvider(TBindingTraits<T>::TypeId(), TBindingTraits<T>::Signature, Caller);
213 if (!Binding.IsSuccess())
214 {
215 return TModResult<FView>::Failure(Binding.GetError());
216 }
217 return TModResult<FView>::Success(FViewFactory::Make<T>(MoveTemp(Binding.GetValue())));
218}
219} // namespace Mod::API
auto BindView(FRegistry &Registry, const FCaller &Caller)
Binds a generated service view once for a host-issued caller.
Definition ModAPIRegistry.h:209
EScope
Supported scope kinds for the synchronous UObject backend.
Definition ModAPIRegistry.h:23
@ Player
A provider belonging to a particular local player and world.
Definition ModAPIRegistry.h:27
@ World
An object belonging to a live world.
Definition ModAPIRegistry.h:25
The primary template has no API; MHT supplies closed specializations.
Definition ModAPIObject.h:50
A host-issued caller identity and permission grant.
Definition ModAPIRegistry.h:107
FRegistration(FRegistration &&Other) noexcept
Transfers registration ownership.
~FRegistration()
Revokes the registration.
FRegistration()=default
Creates an empty registration.
FRegistration & operator=(FRegistration &&Other) noexcept
Transfers registration ownership and revokes the previous value.
void Reset()
Revokes all bindings derived from this registration on the game thread.
Owns a session's generated definitions, providers, scopes, and callers.
Definition ModAPIRegistry.h:117
TModResult< void > RevokeCaller(const FCaller &Caller)
Revokes a caller and all views issued to it.
TModResult< FCaller > CreateCaller(const FScope &Scope, TSet< FName > Permissions)
Issues a caller with explicit host-granted permissions.
FRegistry()
Creates a registry on the game thread.
TModResult< FRegistration > RegisterProvider(FName TypeId, const FScope &Scope, UObject *Instance)
Registers an explicit service instance in a scope.
~FRegistry()
Revokes all derived bindings on the game thread.
TModResult< FObjectBinding > BindProvider(FName TypeId, const TCHAR *Signature, const FCaller &Caller)
Binds a registered provider once for a caller.
FSoftClassPath FindBlueprintWorldType(FName TypeId, FString &OutSignature) const
Reads an exported Blueprint World type without loading its class.
TModResult< FObjectBinding > BindWorldObject(const FCaller &Caller, UObject &Object, FName TypeId, const TCHAR *Signature, bool bReadOnly, bool bWorldOwned=false)
Projects a host-approved object into the caller's World view.
TModResult< FScope > OpenWorldScope(UWorld *World)
Opens a scope for a live world.
UClass * FindWorldType(FName TypeId, FString &OutSignature) const
Returns the registered World projection class to host code.
TModResult< FRegistration > RegisterType(FTypeDescriptor Descriptor)
Registers one generated type and its concrete calling table.
TModResult< FScope > OpenPlayerScope(ULocalPlayer *Player, const FScope &WorldScope)
Opens a local player scope in a particular world.
TModResult< void > CloseScope(const FScope &Scope)
Closes a scope and invalidates its bindings.
const FString * FindLocalPlayerSignature(FName TypeId) const
Finds an explicitly exported local-player provider signature.
A host-issued scope; a player scope also references its world scope.
Definition ModAPIRegistry.h:99
A synchronous API result containing either a value or a stable error.
Definition ModAPIResult.h:47
static TModResult Failure(Mod::API::EError InError)
Constructs a failed result.
Definition ModAPIResult.h:64
static TModResult Success(T InValue)
Constructs a successful result.
Definition ModAPIResult.h:53
Owns the generated API registry for one game instance.
Definition ModAPIHostSubsystem.h:52
A generated definition for registration and compatibility checks.
Definition ModAPIRegistry.h:32
const TCHAR * ExportVersion
Declared export version.
Definition ModAPIRegistry.h:36
const TCHAR * ExportId
Stable export ID.
Definition ModAPIRegistry.h:34
const TCHAR * Signature
Normalized generated signature.
Definition ModAPIRegistry.h:38
Host-only token access for generated fixed-signature C ABI bridges.
Definition ModAPINative.h:20
One generated object type and its immutable calling table.
Definition ModAPIRegistry.h:43
bool bFullView
Preserves read-only authority when this full view is projected.
Definition ModAPIRegistry.h:59
bool bAllowWorldless
Permits non-actor objects with no world in a world-bound view.
Definition ModAPIRegistry.h:57
UClass * Class
Actual host class.
Definition ModAPIRegistry.h:47
FString Signature
Generated calling table signature.
Definition ModAPIRegistry.h:51
FName TypeId
Stable source type identity.
Definition ModAPIRegistry.h:45
FSoftClassPath BlueprintClass
Cooked class identity resolved when a Blueprint provider is registered.
Definition ModAPIRegistry.h:65
const void * Calls
Module-owned table; valid until registration is revoked.
Definition ModAPIRegistry.h:53
TArray< FAPIDescriptor > APIs
Definitions owned by this type.
Definition ModAPIRegistry.h:55
bool bLocalPlayerSubsystem
Resolves this player-scoped service from the chosen local player.
Definition ModAPIRegistry.h:61
TConstArrayView< FBlueprintFunction > BlueprintFunctions
Module-owned reflection descriptions for Blueprint methods.
Definition ModAPIRegistry.h:63
EScope Scope
Required object scope.
Definition ModAPIRegistry.h:49
static auto Make(FObjectBinding Binding)
Constructs a typed view from an already authorized binding.
Definition ModAPIObject.h:52
Specialized by MHT with stable type and calling-table identities.
Definition ModAPIObject.h:14