UnrealModFramework
Mod framework API
Loading...
Searching...
No Matches
ModExtensionLibrary.h
Go to the documentation of this file.
1// Copyright (c) 2026 Nelaric Contributors
3#pragma once
4
5#include "Kismet/BlueprintFunctionLibrary.h"
6
7#include "ModExtensionLibrary.generated.h"
8
9class UModBehavior;
10class UModInstance;
11
13DECLARE_DYNAMIC_DELEGATE(FModBehaviorEvent);
14
16UENUM(BlueprintType)
17enum class EModExtensionStage : uint8
18{
20 Pre,
22 Post,
24 Event,
26 On,
27};
28
30UENUM(BlueprintType)
31enum class EModExtensionOperation : uint8
32{
36 ModifyInputs,
38 Cancel,
40 ModifyResult,
42 Replace,
43};
44
46USTRUCT(BlueprintType)
48{
49 GENERATED_BODY()
50
51 UPROPERTY()
52 FName Id;
53 UPROPERTY()
54 uint64 Generation = 0;
55 UPROPERTY()
56 uint64 Serial = 0;
57};
58
60USTRUCT(BlueprintType)
62{
63 GENERATED_BODY()
64
65 UPROPERTY()
66 FName ViewId;
67 UPROPERTY()
68 uint64 Context = 0;
69 UPROPERTY()
70 uint64 Object = 0;
71};
72
74UCLASS(MinimalAPI)
75class UModExtensionLibrary final : public UBlueprintFunctionLibrary
76{
77 GENERATED_BODY()
78
79public:
94 UFUNCTION(BlueprintCallable, Category = "Mod|Extension")
95 static MODLOADER_API int32 RegisterModExtension(UModInstance* Owner, FName Id, FName Key, FName Function,
97 int32 Priority, const TArray<FString>& Before,
98 const TArray<FString>& After, float CancelValue,
99 FModExtensionToken& Token);
100
105 UFUNCTION(BlueprintCallable, Category = "Mod|Extension")
106 static MODLOADER_API void UnregisterModExtension(UModInstance* Owner, const FModExtensionToken& Token);
107
118 UFUNCTION(BlueprintCallable, Category = "Mod|Service")
119 static MODLOADER_API int32 ProvideModService(UModInstance* Owner, FName Id, FName TypeId, const FString& Signature,
120 const FString& Version, FName Permission, UObject* Instance);
121
123 UFUNCTION(BlueprintCallable, Category = "Mod|Service")
124 static MODLOADER_API void WithdrawModService(UModInstance* Owner, FName Id);
125
135 UFUNCTION(BlueprintCallable, Category = "Mod|Extension")
136 static MODLOADER_API bool AcquireModService(UModInstance* Owner, FName Id, FName TypeId, const FString& Signature,
137 int64& Context, int64& Object);
138
143 UFUNCTION(BlueprintCallable, Category = "Mod|Behavior", meta = (DefaultToSelf = "Owner"))
144 static MODLOADER_API int32 NextModHook(UObject* Owner);
145
146public:
148 static MODLOADER_API int32 RegisterModBehavior(UObject& Owner, FName Id, const TCHAR* Signature, FName Function,
149 EModExtensionStage Stage, FName SourceType);
150
152 static MODLOADER_API bool GetModBehaviorSource(UObject& Owner, FName TypeId, const TCHAR* Signature,
153 FModPayloadObject& OutSource);
154
156 static bool FindBehaviorObject(UObject& Owner, FName Alias, FName TypeId, bool bPlayerProvider, uint64& Context,
157 uint64& Object);
159 static int32 BindBehaviorEvent(UModBehavior& Behavior, FName Id, const TCHAR* Signature, FName SourceType,
160 const FModBehaviorEvent& Delegate, FModExtensionToken& Token);
162 static void UnbindBehaviorEvent(UModBehavior& Behavior, const FModExtensionToken& Token);
163
164 struct FBridge
165 {
166 int32 (*Register)(UModInstance&, FName, FName, FName, EModExtensionStage, EModExtensionOperation, int32,
167 const TArray<FString>&, const TArray<FString>&, float, FModExtensionToken&);
168 void (*Unregister)(UModInstance&, const FModExtensionToken&);
169 int32 (*Provide)(UModInstance&, FName, FName, const FString&, const FString&, FName, UObject*);
170 void (*Withdraw)(UModInstance&, FName);
171 int32 (*RegisterBehavior)(UObject&, FName, const TCHAR*, FName, EModExtensionStage, FName);
172 bool (*BehaviorSource)(UObject&, FName, const TCHAR*, FModPayloadObject&);
173 int32 (*ContinueBehavior)(UObject&);
174 bool (*FindObject)(UObject&, FName, FName, bool, uint64&, uint64&);
175 int32 (*BindEvent)(UModBehavior&, FName, const TCHAR*, FName, const FModBehaviorEvent&, FModExtensionToken&);
176 void (*UnbindEvent)(UModBehavior&, const FModExtensionToken&);
177 };
178 static MODLOADER_API void SetBridge(FBridge Bridge);
179};
EModExtensionStage
A game-thread callback stage in the World extension bus.
Definition ModExtensionLibrary.h:18
EModExtensionOperation
A requested modification of one generated Hook value.
Definition ModExtensionLibrary.h:32
@ Observe
Observation only.
Definition ModExtensionLibrary.h:34
DECLARE_DYNAMIC_DELEGATE(FModBehaviorEvent)
Receives a published event on its Mod behavior.
A Mod-owned behavior instance attached to its authorized World.
Definition ModBehavior.h:13
Registers generated extension callbacks for cooked Mod Blueprints.
Definition ModExtensionLibrary.h:76
static MODLOADER_API int32 RegisterModBehavior(UObject &Owner, FName Id, const TCHAR *Signature, FName Function, EModExtensionStage Stage, FName SourceType)
Registers an override against its published behavior contract.
static MODLOADER_API int32 NextModHook(UObject *Owner)
Continues the current wrapping Hook with its existing input.
static MODLOADER_API bool GetModBehaviorSource(UObject &Owner, FName TypeId, const TCHAR *Signature, FModPayloadObject &OutSource)
Borrows the current callback's source through a published World interface.
static MODLOADER_API bool AcquireModService(UModInstance *Owner, FName Id, FName TypeId, const FString &Signature, int64 &Context, int64 &Object)
Acquires a declared service for generated SDK calls.
static int32 BindBehaviorEvent(UModBehavior &Behavior, FName Id, const TCHAR *Signature, FName SourceType, const FModBehaviorEvent &Delegate, FModExtensionToken &Token)
Binds a delegate through the World extension dispatcher.
static MODLOADER_API void WithdrawModService(UModInstance *Owner, FName Id)
Revokes the named service when it is owned by this Mod.
static void UnbindBehaviorEvent(UModBehavior &Behavior, const FModExtensionToken &Token)
Unsubscribes a delegate owned by the behavior.
static MODLOADER_API void UnregisterModExtension(UModInstance *Owner, const FModExtensionToken &Token)
Requests unsubscription on the game thread.
static bool FindBehaviorObject(UObject &Owner, FName Alias, FName TypeId, bool bPlayerProvider, uint64 &Context, uint64 &Object)
Finds an object or player provider allowed by the World policy.
static MODLOADER_API int32 ProvideModService(UModInstance *Owner, FName Id, FName TypeId, const FString &Signature, const FString &Version, FName Permission, UObject *Instance)
Provides a named World service during On Mod Register.
static MODLOADER_API int32 RegisterModExtension(UModInstance *Owner, FName Id, FName Key, FName Function, EModExtensionStage Stage, EModExtensionOperation Operation, int32 Priority, const TArray< FString > &Before, const TArray< FString > &After, float CancelValue, FModExtensionToken &Token)
Registers a synchronous function on the game thread.
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
Definition ModExtensionLibrary.h:165