UnrealModFramework
Mod framework API
Loading...
Searching...
No Matches
ModExtensionPayload.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/ArrayView.h"
7#include "ModAPIObject.h"
8#include "StructUtils/InstancedStruct.h"
9#include "UObject/WeakObjectPtrTemplates.h"
10#include "UObject/StrongObjectPtr.h"
11
12class UWorld;
13
14namespace Mod::Extension
15{
17class MODAPI_API FPayload
18{
19public:
21 FPayload() = default;
23 static FPayload FromStruct(const UScriptStruct& Type, const void* Value);
25 template <class T> static FPayload FromStruct(const T& Value)
26 {
27 return FromStruct(*T::StaticStruct(), &Value);
28 }
29
30 static FPayload FromObject(const UObject* Value);
32 static FPayload FromNativeCall(TArray<uint8> Value);
34 TConstArrayView<uint8> GetNativeCall() const
35 {
36 return NativeCall;
37 }
38
39 const FInstancedStruct& GetStruct() const
40 {
41 return Struct;
42 }
43
49
50public:
51 const UObject* GetObject() const
52 {
53 return Object.Get();
54 }
55 bool IsNullObject() const
56 {
57 return Object.IsExplicitlyNull();
58 }
59 void SetView(API::FObjectBinding Binding)
60 {
61 View = MoveTemp(Binding);
62 }
63
64private:
65 FInstancedStruct Struct;
66 TWeakObjectPtr<const UObject> Object;
67 TOptional<API::FObjectBinding> View;
68 TArray<uint8> NativeCall;
69};
70
73{
75 FSoftObjectPath Struct;
77 FSoftClassPath Object;
79 FString Layout;
83 FName TypeId;
85 FString Signature;
87 int32 NativeCallSize = 0;
88
89 bool IsStruct() const
90 {
91 return !Struct.IsNull();
92 }
93 bool IsObject() const
94 {
95 return !Object.IsNull();
96 }
97 MODAPI_API bool Matches(const FPayload& Value, const UWorld* World) const;
99 MODAPI_API bool MatchesBlueprint(const UScriptStruct& Type) const;
101 MODAPI_API bool Prepare();
102
103private:
104 FString BlueprintLayout;
105 TStrongObjectPtr<UScriptStruct> StructType;
106 TStrongObjectPtr<UClass> ObjectType;
107};
108
110MODAPI_API FString DescribePayloadStruct(const UScriptStruct& Struct);
111} // namespace Mod::Extension
@ BindingExpired
A scope, caller, registry, or registration has been revoked.
Definition ModAPIResult.h:17
MODAPI_API FString DescribePayloadStruct(const UScriptStruct &Struct)
Describes the supported reflected fields of a host value struct.
static FPayload FromNativeCall(TArray< uint8 > Value)
Owns the packed inputs and result of a C++ Hook.
FPayload()=default
Creates an empty payload.
static FPayload FromStruct(const UScriptStruct &Type, const void *Value)
Copies a value of the supplied struct type into owned storage.
const FInstancedStruct & GetStruct() const
Reads a copied struct while this payload remains alive.
Definition ModExtensionPayload.h:39
TModResult< API::FObjectBinding > GetObjectView() const
Projects an object to a revocable, read-only binding for this callback.
Definition ModExtensionPayload.h:44
static FPayload FromStruct(const T &Value)
Copies a reflected native struct into owned storage.
Definition ModExtensionPayload.h:25
static FPayload FromObject(const UObject *Value)
Captures an object weakly for the duration of the World operation.
TConstArrayView< uint8 > GetNativeCall() const
Reads the bytes of a C++ Hook value.
Definition ModExtensionPayload.h:34
A synchronous API result containing either a value or a stable error.
Definition ModAPIResult.h:47
static TModResult Failure(Mod::API::EError InError)
Constructs a failed result.
Definition ModAPIResult.h:64
static TModResult Success(T InValue)
Constructs a successful result.
Definition ModAPIResult.h:53
The reflected identity and generated validation for a payload projection.
Definition ModExtensionPayload.h:73
FString Signature
Calling-table signature of that view.
Definition ModExtensionPayload.h:85
MODAPI_API bool Prepare()
Resolves and validates the generated type before dispatch begins.
FName BlueprintType
Generated SDK struct name for a value payload.
Definition ModExtensionPayload.h:81
MODAPI_API bool MatchesBlueprint(const UScriptStruct &Type) const
Checks the generated SDK value fields against the host contract.
FString Layout
Generated member schema for Blueprint and C ABI value copies.
Definition ModExtensionPayload.h:79
int32 NativeCallSize
Packed arguments and result size for a C++ Hook.
Definition ModExtensionPayload.h:87
FSoftClassPath Object
Exact UObject class path, when used by the contract.
Definition ModExtensionPayload.h:77
FSoftObjectPath Struct
Exact script struct path, when used by the contract.
Definition ModExtensionPayload.h:75
FName TypeId
Generated read-only view identity for a UObject payload.
Definition ModExtensionPayload.h:83