UnrealModFramework
Mod framework API
Loading...
Searching...
No Matches
ModAPIHostSubsystem.h
Go to the documentation of this file.
1// Copyright (c) 2026 Nelaric Contributors
3#pragma once
4
5#include "ModAPINative.h"
6#include "Delegates/Delegate.h"
7#include "Subsystems/GameInstanceSubsystem.h"
8
9#include "ModAPIHostSubsystem.generated.h"
10
11class UModInstance;
12struct FModExtensionSession;
13struct FModExtensionWorld;
14
15namespace Mod::API
16{
27
38
41{
43 UWorld* World = nullptr;
45 TSet<FName> Permissions;
46};
47} // namespace Mod::API
48
50UCLASS(MinimalAPI)
51class UModAPIHostSubsystem : public UGameInstanceSubsystem
52{
53 GENERATED_BODY()
54
55public:
61 MODAPI_API TModResult<Mod::API::FRegistration> RegisterWorldProvider(FName TypeId, UObject* Instance);
62
70 MODAPI_API TModResult<Mod::API::FWorldCaller> OpenWorldCaller(UWorld* World, FName TypeId, const TCHAR* Signature,
71 TSet<FName> Permissions);
72
75 FName);
76
80 MODAPI_API void SetWorldCallerPolicy(FAuthorizeWorldCaller Policy);
81
90 OpenLocalPlayer(ULocalPlayer* Player, FName TypeId, const TCHAR* Signature, TSet<FName> Permissions);
91
98 template <class T>
99 TModResult<Mod::API::FLocalPlayerCaller> OpenLocalPlayer(ULocalPlayer* Player, TSet<FName> Permissions)
100 {
101 using FTraits = Mod::API::TBindingTraits<T>;
102 return OpenLocalPlayer(Player, FTraits::TypeId(), FTraits::Signature, MoveTemp(Permissions));
103 }
104
110
114 MODAPI_API bool EndExtensionSession();
115
116public:
117 virtual void Initialize(FSubsystemCollectionBase& Collection) override;
118 virtual void Deinitialize() override;
119 static void* ResolveHostQuery(const char* Module, const char* Symbol);
120 TModResult<Mod::API::FWorldCaller> AuthorizeWorldCaller(UModInstance& Mod, FName TypeId, const TCHAR* Signature);
121 void RevokeModCallers(UModInstance& Mod);
122 MODAPI_API Mod::API::FRegistry* GetRegistry() const
123 {
124 return Registry.Get();
125 }
126 MODAPI_API TModResult<Mod::API::FScope> FindOrOpenWorldScope(UWorld* World);
127
128private:
129 friend struct FModExtensionWorld;
130 TSharedPtr<FModExtensionSession> ExtensionSession;
131
132 struct FPlayerScope
133 {
134 TWeakObjectPtr<UWorld> World;
135 Mod::API::FScope Scope;
136 FDelegateHandle ControllerChanged;
137 TMap<FName, Mod::API::FRegistration> Providers;
138 };
139
140 TModResult<FPlayerScope*> OpenPlayerScope(ULocalPlayer* Player, UWorld* World);
141 void CloseLocalPlayer(ULocalPlayer* Player);
142 void OnWorldCleanup(UWorld* World, bool bSessionEnded, bool bCleanupResources);
143 void ReleasePlayerScope(const TWeakObjectPtr<ULocalPlayer>& Player, const FPlayerScope& Entry);
144
145 TUniquePtr<Mod::API::FRegistry> Registry;
146 TArray<Mod::API::FRegistration> Types;
147 TMap<TWeakObjectPtr<UWorld>, Mod::API::FScope> Worlds;
148 TMap<TWeakObjectPtr<ULocalPlayer>, FPlayerScope> Players;
149 TSharedPtr<const FAuthorizeWorldCaller> WorldCallerPolicy;
150 TMap<TWeakObjectPtr<UModInstance>, TMap<FName, Mod::API::FWorldCaller>> ModCallers;
151};
A host-issued caller identity and permission grant.
Definition ModAPIRegistry.h:107
An opaque, non-owning object binding with a cached typed calling table.
Definition ModAPIObject.h:18
Owns a session's generated definitions, providers, scopes, and callers.
Definition ModAPIRegistry.h:117
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
Owns the generated API registry for one game instance.
Definition ModAPIHostSubsystem.h:52
DECLARE_DELEGATE_RetVal_TwoParams(TModResult< Mod::API::FWorldAPIGrant >, FAuthorizeWorldCaller, const UModInstance &, FName)
Handles a game-thread request for a mounted mod's native API caller.
MODAPI_API void SetWorldCallerPolicy(FAuthorizeWorldCaller Policy)
Sets the Mod authorization policy on the game thread.
MODAPI_API TModResult< Mod::API::FLocalPlayerCaller > OpenLocalPlayer(ULocalPlayer *Player, FName TypeId, const TCHAR *Signature, TSet< FName > Permissions)
Binds a generated local-player service.
MODAPI_API bool EndExtensionSession()
Releases the selected Mod set on the game thread.
MODAPI_API TModResult< Mod::API::FWorldCaller > OpenWorldCaller(UWorld *World, FName TypeId, const TCHAR *Signature, TSet< FName > Permissions)
Issues a caller and provider token on the game thread.
MODAPI_API TModResult< Mod::API::FRegistration > RegisterWorldProvider(FName TypeId, UObject *Instance)
Registers a live world provider on the game thread.
TModResult< Mod::API::FLocalPlayerCaller > OpenLocalPlayer(ULocalPlayer *Player, TSet< FName > Permissions)
Binds a typed local-player service.
Definition ModAPIHostSubsystem.h:99
MODAPI_API TModResult< void > RevokeCaller(const Mod::API::FCaller &Caller)
Revokes one caller and all of its bindings.
A game-thread Mod entry point owned by one game instance.
Definition ModInstance.h:52
An authorized caller and its generated player service binding.
Definition ModAPIHostSubsystem.h:19
FNativeContext Native
Context and scope tokens for a native client.
Definition ModAPIHostSubsystem.h:25
FCaller Caller
Revocable caller identity.
Definition ModAPIHostSubsystem.h:21
FObjectBinding Binding
Binding suitable for the generated view factory.
Definition ModAPIHostSubsystem.h:23
Process-local tokens issued by the host for an authorized caller.
Definition ModAPINative.h:11
Selects the world provider and exact permissions for an authorized mod.
Definition ModAPIHostSubsystem.h:41
TSet< FName > Permissions
Permission identifiers approved by the host.
Definition ModAPIHostSubsystem.h:45
UWorld * World
World containing the registered provider.
Definition ModAPIHostSubsystem.h:43
A world-scoped caller and the native tokens for one authorized provider.
Definition ModAPIHostSubsystem.h:30
uint64 Object
Object token for the selected provider.
Definition ModAPIHostSubsystem.h:36
FCaller Caller
Revocable identity owned by the host.
Definition ModAPIHostSubsystem.h:32
FNativeContext Native
Context and scope tokens owned by the caller.
Definition ModAPIHostSubsystem.h:34
Specialized by MHT with stable type and calling-table identities.
Definition ModAPIObject.h:14