UnrealModFramework
Mod framework API
Loading...
Searching...
No Matches
ModExtensionSubsystem.h
Go to the documentation of this file.
1// Copyright (c) 2026 Nelaric Contributors
3#pragma once
4
5#include "ModAPIObject.h"
6#include "ModExtension.h"
7#include "ModExtensionABI.h"
8#include "ModLoader.h"
9#include "Subsystems/WorldSubsystem.h"
10
11#include "ModExtensionSubsystem.generated.h"
12
13class UDataAsset;
14class ULevel;
15class ULocalPlayer;
16class UModBehavior;
17class UModInstance;
18class FModBehaviorEvent;
20class USceneComponent;
21struct FModExtensionWorld;
23
24namespace Mod::Extension
25{
28
30using FContentKey = TPair<FName, FName>;
31
33enum class EContentStatus : uint8
34{
41};
42
45{
47 FString ModId;
48 FSoftObjectPath Path;
49 TArray<FString> Candidates;
51 bool bUsedFallback = false;
52};
53
56{
57 UClass* AssetType = nullptr;
58 TMap<FName, FSoftObjectPath> Defaults;
59 bool bAllowProvide = true;
60 bool bAllowReplace = false;
63 bool bAllowDisable = false;
64 bool bRequired = true;
66 FSoftObjectPath Fallback;
68 TFunction<bool(const UObject&)> ValidateAsset;
70 bool bLoadOnDemand = false;
71};
72
75{
77 FName TypeId;
81 TWeakObjectPtr<UObject> Object;
83 FSoftClassPath Class;
85 bool bCreate = false;
87 bool bRetain = false;
89 bool bReadOnly = true;
90};
91
94{
96 FName TypeId;
100 TWeakObjectPtr<ULocalPlayer> Player;
101};
102
105{
106 TMap<FString, TSet<FName>> Grants;
108 TMap<FName, FNativeObjectRule> NativeObjects;
110 TMap<FName, FNativePlayerRule> NativePlayers;
112 TSet<FString> EnabledMods;
113 TMap<FContentKey, FString> ContentWinners;
121 TFunction<bool(FString&)> ValidatePreparation;
123 TFunction<bool(FString&)> StageSavedState;
124};
125
136
139{
141 bool bAllowSpawnActor = true;
143 TWeakObjectPtr<USceneComponent> Attachment;
145 UClass* DataAssetType = nullptr;
146};
147
150{
152 FString ModId;
154 FName PatchId;
156 FString Revision;
158 FName Anchor;
160 uint64 WorldGeneration = 0;
163};
164
167{
169 TWeakObjectPtr<UDataAsset> Asset;
172};
173
184
187
190{
191 FName Id;
192 FName TypeId;
193 FString Version;
194 FString Signature;
195 FName Permission;
196};
197
198} // namespace Mod::Extension
199
201UCLASS(MinimalAPI)
202class UModExtensionSubsystem final : public UWorldSubsystem
203{
204 GENERATED_BODY()
205
206public:
212 MODAPI_API bool DefineContentSlot(FName Id, Mod::Extension::FContentSlot Slot);
221 MODAPI_API bool RegisterAnchor(FName Id, ULevel& Level, const FTransform& Transform, FName Permission,
224 MODAPI_API void RemoveAnchor(FName Id, ULevel& Level);
226 MODAPI_API TOptional<Mod::Extension::FPatchOrigin> GetPatchOrigin(const UObject& Effect) const;
228 MODAPI_API Mod::Extension::FPatchData ResolvePatchData(FName Anchor, FName DataId) const;
234 MODAPI_API bool Prepare(Mod::Extension::FWorldPolicy Policy, FString& OutError);
236 MODAPI_API bool IsReady() const;
238 MODAPI_API FString GetGameplayDigest() const;
240 MODAPI_API TMap<FString, FString> GetPackageRevisions() const;
244 MODAPI_API void SetFailureHandler(Mod::Extension::FOnWorldFailure Handler);
246 MODAPI_API bool MatchesGameplayDigest(const FString& Digest) const;
248 MODAPI_API Mod::Extension::FResolvedContent ResolveContent(FName Slot, FName Id) const;
251 Register(UModInstance& Owner, FName Id, const FString& Signature, Mod::Extension::FHandler Handler);
253 MODAPI_API void Unregister(UModInstance& Owner, const Mod::Extension::FSubscription& Token);
259 UObject* Instance);
261 MODAPI_API void Withdraw(UModInstance& Owner, FName Id);
263 MODAPI_API TModResult<Mod::API::FObjectBinding> Bind(UModInstance& Consumer, FName Id, FName TypeId,
264 const TCHAR* Signature);
271 MODAPI_API uint32 ReflectNativeMod(const FString& ModId, const UMF_NativeReflectionRequestV2& Request,
274 MODAPI_API void Stop();
275
276public:
277 virtual void Initialize(FSubsystemCollectionBase& Collection) override;
278 virtual void Deinitialize() override;
279 static MODAPI_API Mod::Extension::FHookResult Invoke(UObject& Source, FName Id, Mod::Extension::FEndpoint& Endpoint,
280 float Value,
281 TFunctionRef<Mod::Extension::FCoreResult(float)> Core,
282 TFunctionRef<bool(float)> ValidateInput,
283 TFunctionRef<bool(float)> ValidateResult);
284 static MODAPI_API Mod::API::EError Emit(UObject& Source, FName Id, Mod::Extension::FEndpoint& Endpoint,
285 float Value);
286 template <class T>
287 static MODAPI_API Mod::Extension::THookResult<T>
288 InvokeScalar(UObject& Source, FName Id, Mod::Extension::FEndpoint& Endpoint, T Value,
289 TFunctionRef<Mod::Extension::TCoreResult<T>(T)> Core, TFunctionRef<bool(T)> ValidateInput,
290 TFunctionRef<bool(T)> ValidateResult);
291 template <class T>
292 static MODAPI_API Mod::API::EError EmitScalar(UObject& Source, FName Id, Mod::Extension::FEndpoint& Endpoint,
293 T Value);
294 MODAPI_API Mod::Extension::FHookResult InvokeBlueprint(UObject& Source, FName Id, float Value);
295 template <class T> Mod::Extension::THookResult<T> InvokeBlueprintScalar(UObject& Source, FName Id, T Value);
296 template <class T> Mod::API::EError PublishBlueprintScalar(UObject& Source, FName Id, T Value);
297 MODAPI_API Mod::API::EError PublishBlueprint(UObject& Source, FName Id, float Value);
298 Mod::Extension::THookResult<Mod::Extension::FPayload> InvokeBlueprintPayload(UObject& Source, FName Id,
300 bool AcquireNativeService(UModInstance& Consumer, FName Id, FName TypeId, const TCHAR* Signature,
301 uint64& OutContext, uint64& OutObject);
303 RegisterBlueprint(UModInstance& Owner, FName Id, FName Key, FName Function, Mod::Extension::EStage Stage,
304 Mod::Extension::EOperation Operation, Mod::Extension::FOrder Order, float CancelValue);
305
307 Mod::API::EError RegisterBlueprintBehavior(UObject& Owner, FName Id, const TCHAR* Signature, FName Function,
308 Mod::Extension::EStage Stage, FName SourceType);
309
311 bool GetBlueprintBehaviorSource(UObject& Owner, FName TypeId, const TCHAR* Signature, FModPayloadObject& OutSource);
312
314 bool FindBlueprintBehaviorObject(UObject& Owner, FName Alias, FName TypeId, bool bPlayerProvider, uint64& Context,
315 uint64& Object);
317 Mod::API::EError BindBlueprintBehaviorEvent(UModBehavior& Behavior, FName Id, const TCHAR* Signature,
318 FName SourceType, const FModBehaviorEvent& Delegate,
319 FModExtensionToken& Token);
322
325
326protected:
327 virtual bool DoesSupportWorldType(EWorldType::Type WorldType) const override;
328
329private:
330 void UnregisterOwned(UObject& Owner, const Mod::Extension::FSubscription& Token, const UObject* Target);
331 friend class UModAPIHostSubsystem;
334 void OnWorldTearDown(UWorld* World);
335 void OnWorldTickStart(UWorld* World, ELevelTick TickType, float DeltaSeconds);
336 void OnLevelRemoved(ULevel* Level, UWorld* World);
337 TModResult<Mod::Extension::FSubscription> RegisterOwned(UObject& Owner, FName Id, const FString& Signature,
339 bool GetCallerGrants(const UModInstance& Owner, TSet<FName>& Grants) const;
340 TSharedPtr<FModExtensionWorld> State;
341 FDelegateHandle TearDownHandle;
342 FDelegateHandle TickHandle;
343 FDelegateHandle LevelRemovedHandle;
344};
EError
Recoverable failures of generated synchronous API calls.
Definition ModAPIResult.h:11
@ None
The operation succeeded.
Definition ModAPIResult.h:13
ESubscriptionStatus
Publication state of a subscription token.
Definition ModExtensionSubsystem.h:128
@ Pending
The requested handler is waiting for the dispatch boundary.
Definition ModExtensionSubsystem.h:132
@ Inactive
The token has expired, was removed, or its batch was rejected.
Definition ModExtensionSubsystem.h:130
@ Active
The handler belongs to the current published snapshot.
Definition ModExtensionSubsystem.h:134
DECLARE_DELEGATE_OneParam(FOnWorldFailure, const FWorldFailure &)
Receives an extension failure after gameplay entry points are closed.
EContentStatus
The result of resolving a logical content ID.
Definition ModExtensionSubsystem.h:34
@ Missing
The content could not resolve.
Definition ModExtensionSubsystem.h:36
@ Available
The selected asset is ready.
Definition ModExtensionSubsystem.h:40
@ Disabled
The selected action is disable.
Definition ModExtensionSubsystem.h:38
TPair< FName, FName > FContentKey
A stable key for content selected by a game-defined slot.
Definition ModExtensionSubsystem.h:30
TCoreResult< float > FCoreResult
Float Core result used by the original extension contract.
Definition ModExtension.h:182
THookResult< float > FHookResult
Float Hook result used by the original extension contract.
Definition ModExtension.h:180
EOperation
Operations the host can grant for an individual Hook.
Definition ModExtension.h:96
EStage
The synchronous stages at which Mods can participate.
Definition ModExtension.h:83
Reads and publishes complete save envelopes on the game thread.
Definition ModExtensionSave.h:98
Game Thread handshake on UE's pending connection.
Definition ModExtensionSession.h:19
One World payload with owned struct storage or a weak object identity.
Definition ModExtensionPayload.h:18
A synchronous API result containing either a value or a stable error.
Definition ModAPIResult.h:47
A Mod-owned behavior instance attached to its authorized World.
Definition ModBehavior.h:13
Prepares and owns the extension plan for a single game World.
Definition ModExtensionSubsystem.h:203
MODAPI_API bool IsReady() const
Reports whether this World may start extension-aware gameplay.
MODAPI_API Mod::Extension::FResolvedContent ResolveContent(FName Slot, FName Id) const
Reads the selected content and its source on the game thread.
MODAPI_API TMap< FString, FString > GetPackageRevisions() const
Copies the selected package revisions for game save metadata.
MODAPI_API FString GetGameplayDigest() const
Returns the published plan digest on the game thread, or an empty ID.
MODAPI_API void Withdraw(UModInstance &Owner, FName Id)
Revokes the named service owned by this mod on the game thread.
Mod::API::EError RegisterBlueprintBehavior(UObject &Owner, FName Id, const TCHAR *Signature, FName Function, Mod::Extension::EStage Stage, FName SourceType)
Registers a Blueprint behavior override during World preparation.
MODAPI_API bool MatchesGameplayDigest(const FString &Digest) const
Returns whether this World accepted an authoritative plan digest.
MODAPI_API uint32 ReflectNativeMod(const FString &ModId, const UMF_NativeReflectionRequestV2 &Request, UMF_NativeReflectionReplyV2 &Reply)
Inspects one active native Mod's own objects on the Game Thread.
MODAPI_API void SetFailureHandler(Mod::Extension::FOnWorldFailure Handler)
Installs a game-thread callback for the terminal failure of this World.
MODAPI_API bool Prepare(Mod::Extension::FWorldPolicy Policy, FString &OutError)
Prepares mounted extensions on the game thread.
bool FindBlueprintBehaviorObject(UObject &Owner, FName Alias, FName TypeId, bool bPlayerProvider, uint64 &Context, uint64 &Object)
Finds a behavior target through the game-authored World alias policy.
MODAPI_API TModResult< Mod::Extension::FSubscription > Register(UModInstance &Owner, FName Id, const FString &Signature, Mod::Extension::FHandler Handler)
Registers a callback for the current mod and returns its revocation token.
Mod::API::EError BindBlueprintBehaviorEvent(UModBehavior &Behavior, FName Id, const TCHAR *Signature, FName SourceType, const FModBehaviorEvent &Delegate, FModExtensionToken &Token)
Registers a delegate on an authorized behavior.
Mod::API::EError ContinueBlueprintBehavior(UObject &Owner)
Invokes the active synchronous Blueprint Wrap continuation.
void UnbindBlueprintBehaviorEvent(UModBehavior &Behavior, const FModExtensionToken &Token)
Removes a registration belonging to the behavior.
MODAPI_API bool RegisterAnchor(FName Id, ULevel &Level, const FTransform &Transform, FName Permission, Mod::Extension::FPatchAnchorRules Rules={})
Registers an anchor on the game thread.
MODAPI_API void RemoveAnchor(FName Id, ULevel &Level)
Releases one anchor's effects at a game-thread safe point.
MODAPI_API TModResult< void > Provide(UModInstance &Owner, const Mod::Extension::FService &Service, UObject *Instance)
Publishes a service from this mod's registration callback.
MODAPI_API Mod::Extension::FWorldFailure GetFailure() const
Returns the terminal extension failure on the game thread, if any.
MODAPI_API TOptional< Mod::Extension::FPatchOrigin > GetPatchOrigin(const UObject &Effect) const
Reports the provenance of a tracked Patch Actor or component.
MODAPI_API TModResult< Mod::API::FObjectBinding > Bind(UModInstance &Consumer, FName Id, FName TypeId, const TCHAR *Signature)
Obtains a generated, revocable service binding on the game thread.
MODAPI_API Mod::Extension::ESubscriptionStatus GetSubscriptionStatus(const UModInstance &Owner, const Mod::Extension::FSubscription &Token) const
Reports the token's publication state on the game thread.
MODAPI_API bool DefineContentSlot(FName Id, Mod::Extension::FContentSlot Slot)
Defines a content slot on the game thread before Prepare.
MODAPI_API void Stop()
Stops entry and releases resources once in-flight callbacks return.
bool GetBlueprintBehaviorSource(UObject &Owner, FName TypeId, const TCHAR *Signature, FModPayloadObject &OutSource)
Returns the active behavior callback's opaque source view.
MODAPI_API Mod::Extension::FPatchData ResolvePatchData(FName Anchor, FName DataId) const
Reads active Patch data and provenance on the game thread.
MODAPI_API void Unregister(UModInstance &Owner, const Mod::Extension::FSubscription &Token)
Requests ordinary unsubscription at the next game-thread safe point.
A game-thread Mod entry point owned by one game instance.
Definition ModInstance.h:52
Identifies a registration owned by one mod and World.
Definition ModExtensionLibrary.h:48
A read-only object borrowed for one extension callback.
Definition ModExtensionLibrary.h:62
Host rules for one slot, including its base game defaults.
Definition ModExtensionSubsystem.h:56
TFunction< bool(const UObject &)> ValidateAsset
Applies game-specific rules to loaded assets on the game thread.
Definition ModExtensionSubsystem.h:68
bool bAllowReplaceProvided
Allows replacement of an ID supplied by a declared dependency.
Definition ModExtensionSubsystem.h:62
bool bLoadOnDemand
Loads optional content on first resolution instead of at the gate.
Definition ModExtensionSubsystem.h:70
FSoftObjectPath Fallback
Optional host asset used when an optional winner cannot be loaded.
Definition ModExtensionSubsystem.h:66
A cached link from a host call site to the current World's channel.
Definition ModExtension.h:345
One resolved handler bound to its original owner and exact signature.
Definition ModExtension.h:200
Game-owned authorization and conflict choices for one World.
Definition ModExtensionSubsystem.h:75
bool bCreate
Whether this alias may construct a plain UObject.
Definition ModExtensionSubsystem.h:85
FName Permission
Grant required to use this alias.
Definition ModExtensionSubsystem.h:79
bool bReadOnly
Whether this alias permits only const exported calls.
Definition ModExtensionSubsystem.h:89
TWeakObjectPtr< UObject > Object
Live object offered by this alias, when configured.
Definition ModExtensionSubsystem.h:81
bool bRetain
Whether a Mod may keep the object alive through a strong reference.
Definition ModExtensionSubsystem.h:87
FSoftClassPath Class
Exact class path offered for loading or creation, when configured.
Definition ModExtensionSubsystem.h:83
FName TypeId
The exact exported World view shared with the native Mod.
Definition ModExtensionSubsystem.h:77
An explicitly offered native local-player provider.
Definition ModExtensionSubsystem.h:94
TWeakObjectPtr< ULocalPlayer > Player
The local player scoped to this World.
Definition ModExtensionSubsystem.h:100
FName TypeId
The exact exported local-player provider type.
Definition ModExtensionSubsystem.h:96
FName Permission
Grant required to use this alias.
Definition ModExtensionSubsystem.h:98
How to order this registration relative to other participating Mods.
Definition ModExtension.h:148
Host-owned operations enabled for an anchor.
Definition ModExtensionSubsystem.h:139
TWeakObjectPtr< USceneComponent > Attachment
Optional registered scene component approved as an attachment parent.
Definition ModExtensionSubsystem.h:143
bool bAllowSpawnActor
Authorizes spawning a Mod Actor in this anchor's level.
Definition ModExtensionSubsystem.h:141
UClass * DataAssetType
Optional UDataAsset subclass accepted by the anchor's data registry.
Definition ModExtensionSubsystem.h:145
An asset registered by an active World Patch.
Definition ModExtensionSubsystem.h:167
TWeakObjectPtr< UDataAsset > Asset
Cooked asset held while the registration is active.
Definition ModExtensionSubsystem.h:169
FPatchOrigin Origin
Owning package revision and anchor activation.
Definition ModExtensionSubsystem.h:171
Provenance for an effect created by the current World Patch plan.
Definition ModExtensionSubsystem.h:150
FName Anchor
Host-defined anchor identity.
Definition ModExtensionSubsystem.h:158
FString Revision
Exact archive SHA-256 for the applied revision.
Definition ModExtensionSubsystem.h:156
FString ModId
Package that requested the Actor.
Definition ModExtensionSubsystem.h:152
uint64 AnchorGeneration
Generation of the anchor activation that owns the effect.
Definition ModExtensionSubsystem.h:162
uint64 WorldGeneration
Generation of the World that produced the Actor.
Definition ModExtensionSubsystem.h:160
FName PatchId
ID declared by that package.
Definition ModExtensionSubsystem.h:154
The winning content and its provenance, valid in the current World.
Definition ModExtensionSubsystem.h:45
bool bUsedFallback
Whether the game supplied the asset after the selected asset failed.
Definition ModExtensionSubsystem.h:51
Describes a precompiled cross-Mod service supplied by one Mod instance.
Definition ModExtensionSubsystem.h:190
Revocation identity, valid only for the issuing World generation.
Definition ModExtension.h:288
Describes why an extension World lost its gameplay gate.
Definition ModExtensionSubsystem.h:176
FString Detail
Human-readable origin and failure details.
Definition ModExtensionSubsystem.h:180
Mod::API::EError Error
Stable reason for closing the plan.
Definition ModExtensionSubsystem.h:178
bool bRestartRequired
A new process is required to release uncertain state.
Definition ModExtensionSubsystem.h:182
Rules supplied by the game before preparing a World.
Definition ModExtensionSubsystem.h:105
TSet< FString > EnabledMods
Restricts participation when the set is populated.
Definition ModExtensionSubsystem.h:112
TFunction< FString(const Mod::Loader::FMountedPackage &)> GameplayReleaseId
Resolves an admitted archive to a stable gameplay release ID.
Definition ModExtensionSubsystem.h:119
Mod::Loader::FPackageSelection Selection
An explicit filter also supports a session with zero enabled mods.
Definition ModExtensionSubsystem.h:115
TMap< FName, FNativeObjectRule > NativeObjects
Explicit names and grants for native object lookup and construction.
Definition ModExtensionSubsystem.h:108
TFunction< bool(FString &)> StageSavedState
Stages validated save data against resolved logical content.
Definition ModExtensionSubsystem.h:123
FString ExpectedGameplayDigest
Optional authoritative fingerprint to match before opening gameplay.
Definition ModExtensionSubsystem.h:117
TFunction< bool(FString &)> ValidatePreparation
Optional host admission check before loading extension resources.
Definition ModExtensionSubsystem.h:121
TMap< FName, FNativePlayerRule > NativePlayers
Explicit aliases for generated local-player provider calls.
Definition ModExtensionSubsystem.h:110
Result of the host's original operation.
Definition ModExtension.h:165
Status and complete result of a generated Hook call.
Definition ModExtension.h:156
Content described by a mounted mod package.
Definition ModLoader.h:113
Host selection applied before mounting or freezing a session.
Definition ModLoader.h:76
A host-owned buffer for reflection output.
Definition ModExtensionABI.h:297
Borrowed inputs to a Mod-owned reflection or archive operation.
Definition ModExtensionABI.h:285