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    #[serde(deserialize_with = "deser_flags_u32")]
37    pub class_flags: u32,
38    #[serde(rename = "super")]
39    pub super_class: Option<String>,
40    #[serde(default)]
41    pub interfaces: Vec<String>,
42    #[serde(default)]
43    pub props: Vec<PropertyInfo>,
44    #[serde(default)]
45    pub funcs: Vec<FunctionInfo>,
46}
47
48// ---------------------------------------------------------------------------
49// Struct
50// ---------------------------------------------------------------------------
51
52#[derive(Deserialize, Clone)]
53pub struct StructInfo {
54    pub name: String,
55    pub cpp_name: String,
56    pub package: String,
57    /// Include path of the declaring header; empty for `NoExport` structs,
58    /// whose real declaration lives elsewhere (e.g. `FVector` in Core).
59    #[serde(default)]
60    pub header: String,
61    #[serde(deserialize_with = "deser_flags_u32")]
62    pub struct_flags: u32,
63    #[serde(rename = "super")]
64    pub super_struct: Option<String>,
65    #[serde(default)]
66    pub has_static_struct: bool,
67    #[serde(default)]
68    pub props: Vec<PropertyInfo>,
69}
70
71// ---------------------------------------------------------------------------
72// Enum
73// ---------------------------------------------------------------------------
74
75#[derive(Deserialize, Clone)]
76pub struct EnumInfo {
77    pub name: String,
78    pub cpp_name: String,
79    pub package: String,
80    pub underlying_type: String,
81    pub cpp_form: u32,
82    pub pairs: Vec<(String, i64)>,
83}
84
85// ---------------------------------------------------------------------------
86// Property (used in both class props and struct props)
87// ---------------------------------------------------------------------------
88
89#[derive(Deserialize, Clone)]
90pub struct PropertyInfo {
91    pub name: String,
92    #[serde(rename = "type")]
93    pub prop_type: String,
94    pub prop_flags: u64,
95    #[serde(default = "default_array_dim")]
96    pub array_dim: u32,
97    pub enum_name: Option<String>,
98    pub enum_cpp_name: Option<String>,
99    pub enum_cpp_form: Option<u32>,
100    pub enum_underlying_type: Option<String>,
101    pub class_name: Option<String>,
102    pub meta_class_name: Option<String>,
103    pub struct_name: Option<String>,
104    pub interface_name: Option<String>,
105    pub func_info: Option<serde_json::Value>,
106    pub inner_prop: Option<Box<PropertyInfo>>,
107    pub key_prop: Option<Box<PropertyInfo>>,
108    pub value_prop: Option<Box<PropertyInfo>>,
109    pub element_prop: Option<Box<PropertyInfo>>,
110    pub getter: Option<String>,
111    pub setter: Option<String>,
112    pub default: Option<String>,
113}
114
115fn default_array_dim() -> u32 {
116    1
117}
118
119// ---------------------------------------------------------------------------
120// Function
121// ---------------------------------------------------------------------------
122
123#[derive(Deserialize, Clone)]
124pub struct FunctionInfo {
125    pub name: String,
126    #[serde(deserialize_with = "deser_flags_u32")]
127    pub func_flags: u32,
128    #[serde(default)]
129    pub is_static: bool,
130    #[serde(default)]
131    pub params: Vec<ParamInfo>,
132    /// Original UE function name (before overload renaming). Set by filter.
133    #[serde(skip)]
134    pub ue_name: String,
135    /// For a function copied from an implemented interface: the native
136    /// interface type it is declared on (e.g. `IEnhancedInputSubsystemInterface`).
137    /// Set by the context.
138    #[serde(skip)]
139    pub interface: Option<String>,
140}
141
142// ---------------------------------------------------------------------------
143// Function parameter
144// ---------------------------------------------------------------------------
145
146#[derive(Deserialize, Clone)]
147pub struct ParamInfo {
148    pub name: String,
149    #[serde(rename = "type")]
150    pub prop_type: String,
151    pub prop_flags: u64,
152    pub enum_name: Option<String>,
153    pub enum_cpp_name: Option<String>,
154    pub enum_cpp_form: Option<u32>,
155    pub enum_underlying_type: Option<String>,
156    pub class_name: Option<String>,
157    pub meta_class_name: Option<String>,
158    pub struct_name: Option<String>,
159    pub interface_name: Option<String>,
160    pub func_info: Option<serde_json::Value>,
161    pub inner_prop: Option<Box<PropertyInfo>>,
162    pub key_prop: Option<Box<PropertyInfo>>,
163    pub value_prop: Option<Box<PropertyInfo>>,
164    pub element_prop: Option<Box<PropertyInfo>>,
165    pub default: Option<String>,
166}
167
168// ---------------------------------------------------------------------------
169// Flag constants — sourced from rusteal-ue-flags (single source of truth)
170// ---------------------------------------------------------------------------
171
172pub use rusteal_ue_flags::{
173    CPF_BLUEPRINT_READ_ONLY, CPF_BLUEPRINT_VISIBLE,
174    CPF_CONST_PARM, CPF_OUT_PARM, CPF_REFERENCE_PARM, CPF_RETURN_PARM,
175    CPF_NATIVE_ACCESS_SPECIFIER_PRIVATE as CPF_NATIVE_ACCESS_PRIVATE,
176    CPF_NATIVE_ACCESS_SPECIFIER_PROTECTED as CPF_NATIVE_ACCESS_PROTECTED,
177    FUNC_NATIVE, FUNC_STATIC, FUNC_BLUEPRINT_EVENT,
178};
179
180// ---------------------------------------------------------------------------
181// Serde helpers — the C# exporter sign-extends uint32 flags via
182// `(long)(int)flags`, so JSON values can be negative.  We read as i64
183// and truncate to u32 to recover the original bits.
184// ---------------------------------------------------------------------------
185
186fn deser_flags_u32<'de, D: Deserializer<'de>>(d: D) -> Result<u32, D::Error> {
187    let v = i64::deserialize(d)?;
188    Ok(v as u32)
189}