UnrealModFramework
Mod framework API
Loading...
Searching...
No Matches
ModLoader.h
Go to the documentation of this file.
1// Copyright (c) 2026 Nelaric Contributors
3#pragma once
4
5#include "Containers/Array.h"
6#include "Containers/Map.h"
7#include "Containers/Set.h"
8#include "Containers/UnrealString.h"
9#include "Delegates/Delegate.h"
10#include "Misc/Optional.h"
12#include "Templates/SharedPointer.h"
13#include "Modules/ModuleInterface.h"
14#include "UObject/NameTypes.h"
15
16namespace Mod::Loader
17{
18struct FNativeCode;
19
21enum class ELoadOrigin : uint8
22{
29};
30
73
76{
78 TOptional<TSet<FString>> Enabled;
80 TSet<FString> Required;
82 TMap<FString, FString> Archives;
83};
84
87{
89 FString ReleaseId;
92};
93
96{
98 TArray<FString> TrustedPackageSha256;
106 TMap<FString, TSet<FName>> Grants;
108 TMap<FString, FGameplayRelease> GameplayReleases;
109};
110
113{
115 FString ModId;
117 FString Version;
119 FString PackageRoot;
123 TArray<FName> PackageNames;
125 TArray<FString> LifecycleClasses;
133 bool bRequiredByHost = false;
136 {
137 return NativeCode.IsValid();
138 }
139
141 TSharedPtr<const FNativeCode, ESPMode::ThreadSafe> NativeCode;
142};
143
151MODLOADER_API bool ResolvePackageOrder(TConstArrayView<const FMountedPackage*> Candidates,
152 const FPackageSelection& Selection, TArray<int32>& OutOrder, FString& OutError);
153
155MODLOADER_API FString HashPackagePlan(const FString& CanonicalPlan);
156
159{
160};
161
164{
166 FString Path;
170 FString Detail;
174 bool bAlreadyMounted = false;
175
177 bool IsSuccess() const
178 {
179 return Error == ELoadError::None;
180 }
181};
182
190class MODLOADER_API IModLoaderModule : public IModuleInterface
191{
192public:
194 DECLARE_MULTICAST_DELEGATE_ThreeParams(FOnLoadCompleted, ELoadOrigin, const FString&, TConstArrayView<FLoadResult>);
195
198
204
212 virtual FLoadResult LoadPackage(const FString& Path, const FLoadPolicy& Policy) = 0;
213
224 virtual TArray<FLoadResult> LoadDirectory(const FString& Directory, const FLoadPolicy& Policy) = 0;
225
231 virtual TArray<FMountedPackage> GetMountedPackages() const = 0;
232
242 FOnLoadCompleted& OnLoadCompleted()
243 {
244 return LoadCompleted;
245 }
246
251 FOnBeforeUnload& OnBeforeUnload()
252 {
253 return BeforeUnload;
254 }
255
256public:
258 static bool ReadGameplayRelease(FGameplayRelease& OutRelease);
259 virtual TSharedPtr<const FMountedPackage> PinMountedPackage(const FString& ModId) = 0;
260 virtual TArray<FLoadResult> GetStartupResults() const = 0;
261 virtual TSharedRef<const FPackageSessionLease> PinPackageSession() = 0;
262 virtual bool IsRestartRequired() const = 0;
263 virtual void RequireRestart(const FString& Reason) = 0;
264 DECLARE_DELEGATE_RetVal_TwoParams(bool, FValidateExtensions, const FMountedPackage&, FString&);
265 FValidateExtensions& ValidateExtensions()
266 {
267 return ExtensionValidator;
268 }
269
270protected:
271 void BroadcastLoadCompleted(ELoadOrigin Origin, const FString& Path, TConstArrayView<FLoadResult> Results)
272 {
273 LoadCompleted.Broadcast(Origin, Path, Results);
274 }
275
276 void BroadcastBeforeUnload(const FMountedPackage& Package)
277 {
278 BeforeUnload.Broadcast(Package);
279 }
280
281private:
282 FOnLoadCompleted LoadCompleted;
283 FOnBeforeUnload BeforeUnload;
284 FValidateExtensions ExtensionValidator;
285};
286} // namespace Mod::Loader
MODLOADER_API FString HashPackagePlan(const FString &CanonicalPlan)
Hashes canonical UTF-8 plan data with SHA-256.
ELoadOrigin
Identifies the entry point that finished a load.
Definition ModLoader.h:22
@ Startup
The configured scan at game or PIE startup.
Definition ModLoader.h:24
@ DirectoryWatch
A package found by the mod directory watch.
Definition ModLoader.h:28
@ Manual
An explicit LoadPackage or LoadDirectory call.
Definition ModLoader.h:26
MODLOADER_API bool ResolvePackageOrder(TConstArrayView< const FMountedPackage * > Candidates, const FPackageSelection &Selection, TArray< int32 > &OutOrder, FString &OutError)
Resolves a package set in dependency order.
ELoadError
Stable results for package preparation and mounting.
Definition ModLoader.h:33
@ IntegrityFailure
A payload does not match its declared digest.
Definition ModLoader.h:55
@ CacheFailure
The verified cache could not be prepared.
Definition ModLoader.h:57
@ PlanRejected
The host could not prepare the selected dependency graph.
Definition ModLoader.h:71
@ LimitExceeded
The package set exceeds a loader limit.
Definition ModLoader.h:51
@ Incompatible
The package does not match the host release or supported features.
Definition ModLoader.h:47
@ RestartRequired
Engine mount state requires a process restart.
Definition ModLoader.h:67
@ InputUnavailable
The installed package directory or archive could not be read.
Definition ModLoader.h:43
@ InvalidArchive
The archive, manifest, or index is malformed or unsupported.
Definition ModLoader.h:45
@ None
Content is mounted.
Definition ModLoader.h:35
@ NotSelected
This candidate was excluded by the host's package selection.
Definition ModLoader.h:69
@ TimedOut
The preparation time budget was exhausted.
Definition ModLoader.h:53
@ InvalidContainer
Native container metadata is invalid or outside the mod namespace.
Definition ModLoader.h:63
@ InvalidPolicy
The host release policy is incomplete or invalid.
Definition ModLoader.h:41
@ MountFailed
The engine could not make the contents available.
Definition ModLoader.h:65
@ BackendUnavailable
The host does not expose the required container backend.
Definition ModLoader.h:61
@ Untrusted
The host allowlist or required grants rejected the archive.
Definition ModLoader.h:49
@ Busy
A load is already in progress.
Definition ModLoader.h:39
Loads approved cooked content in a game or editor PIE session.
Definition ModLoader.h:191
FOnBeforeUnload & OnBeforeUnload()
Gets the game-thread event for a package beginning unload.
Definition ModLoader.h:251
virtual TArray< FMountedPackage > GetMountedPackages() const =0
Copies mounted packages that can be activated.
virtual TArray< FLoadResult > LoadDirectory(const FString &Directory, const FLoadPolicy &Policy)=0
Mounts eligible .mod files directly inside a directory.
static bool ReadGameplayRelease(FGameplayRelease &OutRelease)
Resolves the host gameplay identity used for network admission.
static IModLoaderModule & Get()
Returns the service owned by the enabled ModLoader module.
virtual FLoadResult LoadPackage(const FString &Path, const FLoadPolicy &Policy)=0
Verifies and mounts one archive on the game thread.
FOnLoadCompleted & OnLoadCompleted()
Gets the startup and manual completion event.
Definition ModLoader.h:242
DECLARE_MULTICAST_DELEGATE_OneParam(FOnBeforeUnload, const FMountedPackage &)
Receives a mounted package while its content is still available.
DECLARE_MULTICAST_DELEGATE_ThreeParams(FOnLoadCompleted, ELoadOrigin, const FString &, TConstArrayView< FLoadResult >)
Receives the origin, input path, and results of a finished load.
Shared release identity assigned by the host to specific archive bytes.
Definition ModLoader.h:87
FString CompatibilityDigest
SHA-256 of their shared gameplay contract.
Definition ModLoader.h:91
FString ReleaseId
Stable ID shared by compatible target artifacts.
Definition ModLoader.h:89
Admission and trust settings supplied by the game.
Definition ModLoader.h:96
float PreparationTimeoutSeconds
Time budget in seconds for archive and cache preparation.
Definition ModLoader.h:100
TMap< FString, TSet< FName > > Grants
Capabilities granted at process admission.
Definition ModLoader.h:106
FPackageSelection Selection
Selection for this load and its directory watcher.
Definition ModLoader.h:104
TOptional< bool > bEnforcePackageAllowlist
Overrides the default of enforcing only a populated allowlist.
Definition ModLoader.h:102
TMap< FString, FGameplayRelease > GameplayReleases
Host-published gameplay release identities keyed by archive SHA-256.
Definition ModLoader.h:108
TArray< FString > TrustedPackageSha256
Exact SHA-256 values of complete packages approved by the host.
Definition ModLoader.h:98
Outcome for one input path, including its mounted content on success.
Definition ModLoader.h:164
FString Detail
Explanation for logs or user interfaces.
Definition ModLoader.h:170
ELoadError Error
Machine-readable failure category.
Definition ModLoader.h:168
FString Path
Archive path, or the directory for a scan-level failure.
Definition ModLoader.h:166
bool IsSuccess() const
Whether the requested content is available to the package loader.
Definition ModLoader.h:177
bool bAlreadyMounted
True when this exact archive was already mounted.
Definition ModLoader.h:174
FMountedPackage Package
Mounted content for a successful operation.
Definition ModLoader.h:172
Content described by a mounted mod package.
Definition ModLoader.h:113
FString ModId
Lowercase mod identifier.
Definition ModLoader.h:115
FPackageExtensions Extensions
Verified extension requirements and content declarations.
Definition ModLoader.h:127
FString PackageRoot
The package namespace fixed at cook time.
Definition ModLoader.h:119
TArray< FString > LifecycleClasses
Cooked Blueprint class paths for the mod's session entry points.
Definition ModLoader.h:125
FString Version
Published mod version.
Definition ModLoader.h:117
bool bRequiredByHost
Whether the admission policy requires this package to be present.
Definition ModLoader.h:133
TSharedPtr< const FNativeCode, ESPMode::ThreadSafe > NativeCode
Opaque content prepared by the loader for FNativeLibrary.
Definition ModLoader.h:141
TSet< FName > GrantedCapabilities
Capabilities granted by the policy that admitted this archive.
Definition ModLoader.h:129
FString ArchiveSha256
SHA-256 of the complete archive.
Definition ModLoader.h:121
bool HasNativeExtension() const
Whether this mod supplies an independent extension entry point.
Definition ModLoader.h:135
FGameplayRelease GameplayRelease
Shared release identity, defaulting to the exact archive digest.
Definition ModLoader.h:131
TArray< FName > PackageNames
Sorted cooked package names in this namespace.
Definition ModLoader.h:123
Verified declarations from the versioned package extension section.
Definition ModPackageExtensions.h:116
Host selection applied before mounting or freezing a session.
Definition ModLoader.h:76
TMap< FString, FString > Archives
Exact archive selections, keyed by lowercase Mod ID.
Definition ModLoader.h:82
TOptional< TSet< FString > > Enabled
An unset filter enables all eligible candidates.
Definition ModLoader.h:78
TSet< FString > Required
Packages whose absence blocks preparation.
Definition ModLoader.h:80
Keeps extension admission fixed while a GameInstance has a live session.
Definition ModLoader.h:159