UnrealModFramework
Mod framework API
Loading...
Searching...
No Matches
ModInstance.h
Go to the documentation of this file.
1// Copyright (c) 2026 Nelaric Contributors
3#pragma once
4
5#include "Engine/GameInstance.h"
6#include "UObject/Object.h"
7
8#include "ModInstance.generated.h"
9
11USTRUCT(BlueprintType)
12struct MODLOADER_API FModLoadNotification
13{
14 GENERATED_BODY()
15
16
17 UPROPERTY(BlueprintReadOnly, Category = "Mod|Lifecycle")
18 FString ModId;
19
21 UPROPERTY(BlueprintReadOnly, Category = "Mod|Lifecycle")
22 FString Version;
23
25 UPROPERTY(BlueprintReadOnly, Category = "Mod|Lifecycle")
26 FString InputName;
27
29 UPROPERTY(BlueprintReadOnly, Category = "Mod|Lifecycle")
30 bool bSucceeded = false;
31
33 UPROPERTY(BlueprintReadOnly, Category = "Mod|Lifecycle")
34 bool bAlreadyMounted = false;
35
37 UPROPERTY(BlueprintReadOnly, Category = "Mod|Lifecycle")
38 bool bStartup = false;
39
41 UPROPERTY(BlueprintReadOnly, Category = "Mod|Lifecycle")
42 int32 ErrorCode = 0;
43
45 UPROPERTY(BlueprintReadOnly, Category = "Mod|Lifecycle")
46 FString Reason;
47};
48
50UCLASS(Abstract, BlueprintType, Blueprintable, MinimalAPI, meta = (DontUseGenericSpawnObject))
51class UModInstance : public UObject
52{
53 GENERATED_BODY()
54
55public:
57 MODLOADER_API UWorld* GetWorld() const override;
58
62 MODLOADER_API FString GetModId() const;
63
71 MODLOADER_API bool AcquireWorldAPI(FName TypeId, const TCHAR* Signature, uint64& OutContext, uint64& OutObject);
72
78 static MODLOADER_API void* ResolveHostAPI(const char* Module, const char* Symbol);
79
88 MODLOADER_API bool AcquireModService(FName ServiceId, FName TypeId, const TCHAR* Signature, uint64& OutContext,
89 uint64& OutObject);
90
91public:
93 UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Mod|Lifecycle",
94 meta = (DisplayName = "On Mod Load Completed"))
95 MODLOADER_API void ExecuteOnModLoadCompleted(const FModLoadNotification& Result);
96 virtual void ExecuteOnModLoadCompleted_Implementation(const FModLoadNotification& Result)
97 {
98 OnModLoadCompleted(Result);
99 }
100
102 UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Mod|Lifecycle",
103 meta = (DisplayName = "On Mod Before Unload"))
104 MODLOADER_API void ExecuteOnModBeforeUnload();
105 virtual void ExecuteOnModBeforeUnload_Implementation()
106 {
108 }
109
111 UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Mod|Lifecycle",
112 meta = (DisplayName = "On Mod Register"))
113 MODLOADER_API void ExecuteOnModRegister();
114 virtual void ExecuteOnModRegister_Implementation()
115 {
117 }
118
120 UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Mod|Lifecycle", meta = (DisplayName = "On Mod Bind"))
121 MODLOADER_API void ExecuteOnModBind();
122 virtual void ExecuteOnModBind_Implementation()
123 {
124 OnModBind();
125 }
126
127 using FAcquireModService = bool (*)(UModInstance&, FName, FName, const TCHAR*, uint64&, uint64&);
128 static MODLOADER_API void SetServiceBridge(FAcquireModService Acquire);
129 using FAcquireWorldAPI = bool (*)(UModInstance&, FName, const TCHAR*, uint64&, uint64&);
130 using FResolveHostAPI = void* (*)(const char*, const char*);
131 using FRevokeWorldAPIs = void (*)(UModInstance&);
132 static MODLOADER_API void SetHostAPIBridge(FAcquireWorldAPI Acquire, FResolveHostAPI Resolve,
133 FRevokeWorldAPIs Revoke);
134
135 static MODLOADER_API void SetExtensionWorld(UModInstance& Instance, UWorld& World, FString ModId);
136 MODLOADER_API void RegisterExtensions();
137 MODLOADER_API void BindExtensions();
138 MODLOADER_API void ReleaseExtensions(bool bNotify = true);
139
140protected:
146 virtual void OnModLoadCompleted(const FModLoadNotification& Result)
147 {
149 }
150
155 UFUNCTION(BlueprintImplementableEvent, Category = "Mod|Lifecycle",
156 meta = (DisplayName = "On Mod Load Completed (Legacy)"))
157 MODLOADER_API void ReceiveModLoadCompleted(const FModLoadNotification& Result);
158
165 virtual void OnModBeforeUnload()
166 {
168 }
169
171 UFUNCTION(BlueprintImplementableEvent, Category = "Mod|Lifecycle",
172 meta = (DisplayName = "On Mod Before Unload (Legacy)"))
173 MODLOADER_API void ReceiveModBeforeUnload();
174
176 UFUNCTION(BlueprintImplementableEvent, Category = "Mod|Lifecycle",
177 meta = (DisplayName = "On Mod Register (Legacy)"))
178 MODLOADER_API void ReceiveModRegister();
179
181 virtual void OnModRegister()
182 {
184 }
185
187 UFUNCTION(BlueprintImplementableEvent, Category = "Mod|Lifecycle", meta = (DisplayName = "On Mod Bind (Legacy)"))
188 MODLOADER_API void ReceiveModBind();
189
191 virtual void OnModBind()
192 {
194 }
195
196private:
197 friend class UModLifecycleSubsystem;
198 void RevokeWorldAPIs();
199};
A game-thread Mod entry point owned by one game instance.
Definition ModInstance.h:52
MODLOADER_API void ReceiveModRegister()
Registers this mod's extensions while its World is preparing.
MODLOADER_API bool AcquireModService(FName ServiceId, FName TypeId, const TCHAR *Signature, uint64 &OutContext, uint64 &OutObject)
Acquires a declared cross-Mod service on the game thread.
virtual void OnModBind()
Binds compiled C++ consumers after all providers are registered.
Definition ModInstance.h:191
MODLOADER_API void ReceiveModBeforeUnload()
Blueprint event dispatched before this Mod's content is unloaded.
virtual void OnModRegister()
Registers compiled C++ extensions before the World is ready.
Definition ModInstance.h:181
MODLOADER_API void ExecuteOnModBeforeUnload()
Dispatches unload notification to Blueprint or the C++ override.
MODLOADER_API void ReceiveModLoadCompleted(const FModLoadNotification &Result)
Blueprint event for a completed Mod load.
MODLOADER_API FString GetModId() const
Returns this instance's active package ID on the game thread.
MODLOADER_API UWorld * GetWorld() const override
Returns the extension World or the World of the owning game instance.
virtual void OnModBeforeUnload()
Releases game state and references before this Mod is unloaded.
Definition ModInstance.h:165
MODLOADER_API void ExecuteOnModBind()
Dispatches the mod bind callback to Blueprint or the native override.
MODLOADER_API void ExecuteOnModRegister()
Dispatches the mod register callback to Blueprint or the native override.
MODLOADER_API bool AcquireWorldAPI(FName TypeId, const TCHAR *Signature, uint64 &OutContext, uint64 &OutObject)
Acquires a host-approved world provider on the game thread.
static MODLOADER_API void * ResolveHostAPI(const char *Module, const char *Symbol)
Resolves a host API table query on the game thread.
virtual void OnModLoadCompleted(const FModLoadNotification &Result)
Receives the result of a load operation on the game thread.
Definition ModInstance.h:146
MODLOADER_API void ReceiveModBind()
Acquires declared services after all providers register.
MODLOADER_API void ExecuteOnModLoadCompleted(const FModLoadNotification &Result)
Dispatches load completion to Blueprint or the C++ override.
Blueprint payload for one finished Mod load attempt.
Definition ModInstance.h:13
bool bSucceeded
Whether the mount succeeded or was already present.
Definition ModInstance.h:30
FString InputName
Name of the archive or of the directory that could not be scanned.
Definition ModInstance.h:26
FString ModId
The identity read from the archive, when available.
Definition ModInstance.h:18
FString Reason
Failure reason supplied by ModLoader.
Definition ModInstance.h:46
FString Version
The version read from the archive, when available.
Definition ModInstance.h:22
bool bStartup
Whether the result came from the configured startup scan.
Definition ModInstance.h:38
int32 ErrorCode
Stable ModLoader error code, zero on success.
Definition ModInstance.h:42
bool bAlreadyMounted
Whether the exact archive was already present before this operation.
Definition ModInstance.h:34