Skip to main content

rusteal_codegen/
schema.rs

1// JSON schema types matching UHT exporter output.
2
3#![allow(dead_code)] // Schema fields are deserialized from JSON; some reserved for future codegen use.
4
5use serde::{Deserialize, Deserializer};
6
7// ---------------------------------------------------------------------------
8// Top-level file wrappers
9// ---------------------------------------------------------------------------
10
11#[derive(Deserialize)]
12pub struct ClassesFile {
13    pub classes: Vec<ClassInfo>,
14}
15
16#[derive(Deserialize)]
17pub struct StructsFile {
18    pub structs: Vec<StructInfo>,
19}
20
21#[derive(Deserialize)]
22pub struct EnumsFile {
23    pub enums: Vec<EnumInfo>,
24}
25
26// ---------------------------------------------------------------------------
27// Class
28// ---------------------------------------------------------------------------
29
30#[derive(Deserialize, Clone)]
31pub struct ClassInfo {
32    pub name: String,
33    pub cpp_name: String,
34    pub package: String,
35    pub header: String,
36    /// Whether the header is one another module can include (in a Classes
37    /// or Public folder): the C++ wrappers of the class's functions need it.
38    #[serde(default = "default_true")]
39    pub header_public: bool,
40    #[serde(deserialize_with = "deser_flags_u32")]
41    pub class_flags: u32,
42    #[serde(rename = "super")]
43    pub super_class: Option<String>,
44    #[serde(default)]
45    pub interfaces: Vec<String>,
46    #[serde(default)]
47    pub props: Vec<PropertyInfo>,
48    #[serde(default)]
49    pub funcs: Vec<FunctionInfo>,
50}
51
52// ---------------------------------------------------------------------------
53// Struct
54// ---------------------------------------------------------------------------
55
56#[derive(Deserialize, Clone)]
57pub struct StructInfo {
58    pub name: String,
59    pub cpp_name: String,
60    pub package: String,
61    /// Include path of the declaring header; empty for `NoExport` structs,
62    /// whose real declaration lives elsewhere (e.g. `FVector` in Core).
63    #[serde(default)]
64    pub header: String,
65    /// Whether the header is one another module can include (see `ClassInfo`).
66    #[serde(default = "default_true")]
67    pub header_public: bool,
68    #[serde(deserialize_with = "deser_flags_u32")]
69    pub struct_flags: u32,
70    #[serde(rename = "super")]
71    pub super_struct: Option<String>,
72    #[serde(default)]
73    pub has_static_struct: bool,
74    #[serde(default)]
75    pub props: Vec<PropertyInfo>,
76}
77
78// ---------------------------------------------------------------------------
79// Enum
80// ---------------------------------------------------------------------------
81
82#[derive(Deserialize, Clone)]
83pub struct EnumInfo {
84    pub name: String,
85    pub cpp_name: String,
86    pub package: String,
87    pub underlying_type: String,
88    pub cpp_form: u32,
89    pub pairs: Vec<(String, i64)>,
90}
91
92// ---------------------------------------------------------------------------
93// Property (used in both class props and struct props)
94// ---------------------------------------------------------------------------
95
96#[derive(Deserialize, Clone)]
97pub struct PropertyInfo {
98    pub name: String,
99    #[serde(rename = "type")]
100    pub prop_type: String,
101    pub prop_flags: u64,
102    #[serde(default = "default_array_dim")]
103    pub array_dim: u32,
104    pub enum_name: Option<String>,
105    pub enum_cpp_name: Option<String>,
106    pub enum_cpp_form: Option<u32>,
107    pub enum_underlying_type: Option<String>,
108    pub class_name: Option<String>,
109    pub meta_class_name: Option<String>,
110    pub struct_name: Option<String>,
111    pub interface_name: Option<String>,
112    pub func_info: Option<serde_json::Value>,
113    pub inner_prop: Option<Box<PropertyInfo>>,
114    pub key_prop: Option<Box<PropertyInfo>>,
115    pub value_prop: Option<Box<PropertyInfo>>,
116    pub element_prop: Option<Box<PropertyInfo>>,
117    pub getter: Option<String>,
118    pub setter: Option<String>,
119    pub default: Option<String>,
120}
121
122fn default_array_dim() -> u32 {
123    1
124}
125
126// ---------------------------------------------------------------------------
127// Function
128// ---------------------------------------------------------------------------
129
130#[derive(Deserialize, Clone)]
131pub struct FunctionInfo {
132    pub name: String,
133    #[serde(deserialize_with = "deser_flags_u32")]
134    pub func_flags: u32,
135    #[serde(default)]
136    pub is_static: bool,
137    #[serde(default)]
138    pub params: Vec<ParamInfo>,
139    /// Original UE function name (before overload renaming). Set by filter.
140    #[serde(skip)]
141    pub ue_name: String,
142    /// For a function copied from an implemented interface: the native
143    /// interface type it is declared on (e.g. `IEnhancedInputSubsystemInterface`).
144    /// Set by the context.
145    #[serde(skip)]
146    pub interface: Option<String>,
147}
148
149// ---------------------------------------------------------------------------
150// Function parameter
151// ---------------------------------------------------------------------------
152
153#[derive(Deserialize, Clone)]
154pub struct ParamInfo {
155    pub name: String,
156    #[serde(rename = "type")]
157    pub prop_type: String,
158    pub prop_flags: u64,
159    pub enum_name: Option<String>,
160    pub enum_cpp_name: Option<String>,
161    pub enum_cpp_form: Option<u32>,
162    pub enum_underlying_type: Option<String>,
163    pub class_name: Option<String>,
164    pub meta_class_name: Option<String>,
165    pub struct_name: Option<String>,
166    pub interface_name: Option<String>,
167    pub func_info: Option<serde_json::Value>,
168    pub inner_prop: Option<Box<PropertyInfo>>,
169    pub key_prop: Option<Box<PropertyInfo>>,
170    pub value_prop: Option<Box<PropertyInfo>>,
171    pub element_prop: Option<Box<PropertyInfo>>,
172    pub default: Option<String>,
173}
174
175// ---------------------------------------------------------------------------
176// Flag constants — sourced from rusteal-ue-flags (single source of truth)
177// ---------------------------------------------------------------------------
178
179pub use rusteal_ue_flags::{
180    CPF_BLUEPRINT_ASSIGNABLE, CPF_BLUEPRINT_READ_ONLY, CPF_BLUEPRINT_VISIBLE, CPF_EDIT,
181    CPF_CONST_PARM, CPF_OUT_PARM, CPF_REFERENCE_PARM, CPF_RETURN_PARM,
182    CPF_NATIVE_ACCESS_SPECIFIER_PRIVATE as CPF_NATIVE_ACCESS_PRIVATE,
183    CPF_NATIVE_ACCESS_SPECIFIER_PROTECTED as CPF_NATIVE_ACCESS_PROTECTED,
184    FUNC_NATIVE, FUNC_STATIC, FUNC_BLUEPRINT_EVENT, FUNC_PROTECTED,
185};
186
187// ---------------------------------------------------------------------------
188// Serde helpers — the C# exporter sign-extends uint32 flags via
189// `(long)(int)flags`, so JSON values can be negative.  We read as i64
190// and truncate to u32 to recover the original bits.
191// ---------------------------------------------------------------------------
192
193fn default_true() -> bool {
194    true
195}
196
197fn deser_flags_u32<'de, D: Deserializer<'de>>(d: D) -> Result<u32, D::Error> {
198    let v = i64::deserialize(d)?;
199    Ok(v as u32)
200}