UnrealModFramework
Mod framework API
Loading...
Searching...
No Matches
ModExportMetadataSchema.h
Go to the documentation of this file.
1// Copyright (c) 2026 Nelaric Contributors
3#pragma once
4
5#include <array>
6#include <cstdint>
7#include <span>
8#include <string_view>
9
10namespace Mod::ExportMetadata
11{
12namespace Schema
13{
15inline constexpr int SnapshotVersion = 5;
17inline constexpr const char* SnapshotPath = "Intermediate/ModTools/ModHeaderTool/MetadataOptions.json";
19inline constexpr const char* DefaultExportVersion = "1.0.0";
21inline constexpr const char* WorldScope = "World";
23inline constexpr const char* PlayerScope = "Player";
25inline constexpr const char* DefaultAPIThread = "GameThread";
27inline constexpr const char* DefaultAPIFailureRule = "ReturnError";
29inline constexpr const char* DefaultEventPublishRule = "Immediate";
31inline constexpr const char* NextTickEventPublishRule = "NextTick";
33inline constexpr const char* DefaultAuthority = "Server";
35inline constexpr std::array<std::string_view, 3> HookStages = {"Pre", "On", "Post"};
37inline constexpr std::array<std::string_view, 2> ExtensionAuthorities = {"Server", "Any"};
39inline constexpr std::array<std::string_view, 2> EventUnsubscribeRules = {"Deferred", "Immediate"};
40
43{
45 const char* Name;
47 const char* Stage;
48};
49
51inline constexpr std::array<FHookOperationSpec, 5> HookOperations = {{
52 {"ModifyInputs", "Pre"},
53 {"Cancel", "Pre"},
54 {"Wrap", "On"},
55 {"Replace", "On"},
56 {"ModifyResult", "Post"},
57}};
58
60inline constexpr bool IsHookStage(std::string_view Name)
61{
62 for (const std::string_view Stage : HookStages)
63 {
64 if (Stage == Name)
65 {
66 return true;
67 }
68 }
69 return false;
70}
71
73inline constexpr const FHookOperationSpec* FindHookOperation(std::string_view Name)
74{
75 for (const FHookOperationSpec& Operation : HookOperations)
76 {
77 if (Name == Operation.Name)
78 {
79 return &Operation;
80 }
81 }
82 return nullptr;
83}
84
109
112{
114 const char* Name;
118 const char* ChoiceKey;
122 const char* Default = nullptr;
123};
124
126inline constexpr std::array<FFieldSpec, 3> CommonFields = {{
127 {"ExportVersion", EFieldType::Version, nullptr, false, DefaultExportVersion},
128 {"DisplayName", EFieldType::NonEmptyText, nullptr, false},
129 {"Description", EFieldType::Text, nullptr, false},
130}};
131
132inline constexpr FFieldSpec CompatibleNames{"CompatibleNames", EFieldType::FunctionNameList, nullptr, false};
134inline constexpr std::array<FFieldSpec, 7> APIFields = {{
135 {"Scope", EFieldType::Choice, "APIScopes", false},
136 {"Thread", EFieldType::Choice, "APIThreads", false, DefaultAPIThread},
137 {"FailureRule", EFieldType::Choice, "APIFailureRules", false, DefaultAPIFailureRule},
138 {"FailureReturn", EFieldType::NonEmptyText, nullptr, false},
139 {"Permissions", EFieldType::ChoiceList, "APIPermissions", false},
140 {"FullView", EFieldType::ClassNameList, nullptr, false},
142}};
143
144inline constexpr std::array<FFieldSpec, 4> HookFields = {{
146 {"NoPre", EFieldType::Flag, nullptr, false},
147 {"NoOn", EFieldType::Flag, nullptr, false},
148 {"NoPost", EFieldType::Flag, nullptr, false},
149}};
150
151inline constexpr std::array<FFieldSpec, 10> EventFields = {{
152 {"SourceScope", EFieldType::Choice, "EventSourceScopes", false, WorldScope},
153 {"PublishRule", EFieldType::Choice, "EventPublishRules", false, DefaultEventPublishRule},
154 {"UnsubscribeRule", EFieldType::Choice, "EventUnsubscribeRules", false},
155 {"PayloadType", EFieldType::StructType, nullptr, false},
156 {"ExportId", EFieldType::NonEmptyText, nullptr, false},
157 {"Permission", EFieldType::NonEmptyText, nullptr, false},
158 {"PublishPermission", EFieldType::NonEmptyText, nullptr, false},
159 {"Authority", EFieldType::Choice, "ExtensionAuthorities", false, DefaultAuthority},
160 {"HostEndpoint", EFieldType::MemberName, nullptr, false},
161 {"HostCommitPayload", EFieldType::MemberName, nullptr, false},
162}};
163
164inline constexpr std::span<const FFieldSpec> FieldsFor(std::string_view Macro)
165{
166 if (Macro == "MOD_EXPORT_API")
167 {
168 return APIFields;
169 }
170 if (Macro == "MOD_EXPORT_EVENT")
171 {
172 return EventFields;
173 }
174 if (Macro == "MOD_EXPORT_HOOK")
175 {
176 return HookFields;
177 }
178 return {};
179}
180
182inline constexpr const FFieldSpec* FindField(std::string_view Macro, std::string_view Name)
183{
184 if (Macro == "MOD_EXPORT_API" || Macro == "MOD_EXPORT_EVENT")
185 {
186 for (const FFieldSpec& Field : CommonFields)
187 {
188 if (Name == Field.Name)
189 {
190 return &Field;
191 }
192 }
193 }
194 for (const FFieldSpec& Field : FieldsFor(Macro))
195 {
196 if (Name == Field.Name)
197 {
198 return &Field;
199 }
200 }
201 return nullptr;
202}
203
205inline std::uint64_t Fingerprint(std::string_view Bytes)
206{
207 std::uint64_t Hash = UINT64_C(14695981039346656037);
208 for (unsigned char Byte : Bytes)
209 {
210 Hash ^= Byte;
211 Hash *= UINT64_C(1099511628211);
212 }
213 return Hash;
214}
215} // namespace Schema
216} // namespace Mod::ExportMetadata
constexpr const char * PlayerScope
Scope of the API of a LocalPlayer subsystem.
Definition ModExportMetadataSchema.h:23
constexpr std::span< const FFieldSpec > FieldsFor(std::string_view Macro)
Returns the fields belonging to a declaration kind.
Definition ModExportMetadataSchema.h:164
constexpr const char * DefaultAPIThread
Supported API thread policy.
Definition ModExportMetadataSchema.h:25
constexpr const char * NextTickEventPublishRule
Delivers events on the next tick of their world.
Definition ModExportMetadataSchema.h:31
constexpr bool IsHookStage(std::string_view Name)
Checks a Hook stage name against the shared contract.
Definition ModExportMetadataSchema.h:60
constexpr const char * DefaultAPIFailureRule
Reports framework errors through the generated result.
Definition ModExportMetadataSchema.h:27
constexpr const char * DefaultAuthority
Default authority for extension dispatch.
Definition ModExportMetadataSchema.h:33
constexpr std::array< FFieldSpec, 7 > APIFields
Fields belonging to API declarations.
Definition ModExportMetadataSchema.h:134
constexpr std::array< FFieldSpec, 3 > CommonFields
Fields shared by API and Event declarations.
Definition ModExportMetadataSchema.h:126
constexpr std::array< FHookOperationSpec, 5 > HookOperations
Hook operations and their required stages in the extension contract.
Definition ModExportMetadataSchema.h:51
constexpr const char * WorldScope
Default scope for Blueprint APIs and the supported Event source scope.
Definition ModExportMetadataSchema.h:21
constexpr std::array< std::string_view, 2 > ExtensionAuthorities
Authority policies for synchronous World extensions.
Definition ModExportMetadataSchema.h:37
constexpr const char * DefaultExportVersion
Default declaration export version.
Definition ModExportMetadataSchema.h:19
EFieldType
Literal shapes supported by the declaration DSL.
Definition ModExportMetadataSchema.h:87
@ NonEmptyText
A nonempty string literal.
Definition ModExportMetadataSchema.h:91
@ MemberName
An unqualified C++ member identifier.
Definition ModExportMetadataSchema.h:105
@ Version
A two- or three-component numeric version string.
Definition ModExportMetadataSchema.h:93
@ ChoiceList
A parenthesized list of configured identifiers or strings.
Definition ModExportMetadataSchema.h:97
@ Choice
One configured identifier or string.
Definition ModExportMetadataSchema.h:95
@ ClassNameList
A parenthesized list of quoted C++ class names.
Definition ModExportMetadataSchema.h:101
@ Text
An arbitrary string literal.
Definition ModExportMetadataSchema.h:89
@ Flag
A bare field whose presence enables the option.
Definition ModExportMetadataSchema.h:107
@ FunctionNameList
A parenthesized list of quoted function names.
Definition ModExportMetadataSchema.h:103
@ StructType
A qualified C++ struct name.
Definition ModExportMetadataSchema.h:99
constexpr const char * DefaultEventPublishRule
Delivers events during the current game-thread dispatch.
Definition ModExportMetadataSchema.h:29
constexpr const FFieldSpec * FindField(std::string_view Macro, std::string_view Name)
Finds a field in the common and declaration-specific schemas.
Definition ModExportMetadataSchema.h:182
constexpr int SnapshotVersion
Version of the resolved UE metadata option snapshot.
Definition ModExportMetadataSchema.h:15
constexpr std::array< std::string_view, 3 > HookStages
Supported Hook stages in the metadata contract.
Definition ModExportMetadataSchema.h:35
constexpr FFieldSpec CompatibleNames
Former names accepted by API and Hook declarations.
Definition ModExportMetadataSchema.h:132
std::uint64_t Fingerprint(std::string_view Bytes)
Computes an FNV-1a fingerprint to detect changed snapshot inputs.
Definition ModExportMetadataSchema.h:205
constexpr const FHookOperationSpec * FindHookOperation(std::string_view Name)
Finds a Hook operation in the shared contract.
Definition ModExportMetadataSchema.h:73
constexpr const char * SnapshotPath
Default location relative to the project root.
Definition ModExportMetadataSchema.h:17
constexpr std::array< FFieldSpec, 10 > EventFields
Fields belonging to Event declarations.
Definition ModExportMetadataSchema.h:151
constexpr std::array< std::string_view, 2 > EventUnsubscribeRules
Policies for retiring an Event subscription during dispatch.
Definition ModExportMetadataSchema.h:39
constexpr std::array< FFieldSpec, 4 > HookFields
Fields belonging to Hook declarations.
Definition ModExportMetadataSchema.h:144
A declaration field and its choice source.
Definition ModExportMetadataSchema.h:112
bool bRequired
Whether the field must be explicitly supplied.
Definition ModExportMetadataSchema.h:120
const char * ChoiceKey
Snapshot choice key, or null for free text.
Definition ModExportMetadataSchema.h:118
const char * Default
Default scalar or single list entry, or null.
Definition ModExportMetadataSchema.h:122
EFieldType Type
Required literal shape.
Definition ModExportMetadataSchema.h:116
const char * Name
Field name in the declaration.
Definition ModExportMetadataSchema.h:114
A Hook operation and the stage that must be open to allow it.
Definition ModExportMetadataSchema.h:43
const char * Stage
Required stage name in the declaration.
Definition ModExportMetadataSchema.h:47
const char * Name
Operation name in the declaration.
Definition ModExportMetadataSchema.h:45