@@ -12,6 +12,7 @@ NativeCodeGen is a code generation tool for RDR3 (Red Dead Redemption 3) native
1212- Parses C-style enum definitions with hexadecimal values
1313- Parses C-style struct definitions with field attributes
1414- Generates TypeScript wrapper classes with proper type mappings
15+ - Generates Lua wrapper classes with proper type annotations
1516- Generates JSON database for web-based documentation
1617- Generates Protocol Buffer binary files for efficient data transfer
1718- Validates native definitions with error accumulation and reporting
@@ -84,9 +85,10 @@ dotnet run --project src/NativeCodeGen.Cli -- generate -i <input> -o <output> [o
8485
8586| Option | Description | Default |
8687| --------| -------------| ---------|
87- | ` -f, --format ` | Output format: ` typescript ` , ` json ` , ` proto ` | ` typescript ` |
88+ | ` -f, --format ` | Output format: ` typescript ` , ` lua ` , ` json ` , ` proto ` | ` typescript ` |
8889| ` -n, --namespaces ` | Filter specific namespaces (comma-separated) | All namespaces |
89- | ` --raw ` | Generate raw native declarations without wrapper classes (TypeScript only) | ` false ` |
90+ | ` --raw ` | Generate raw native declarations without wrapper classes (TypeScript/Lua) | ` false ` |
91+ | ` --single-file ` | Combine all natives into a single file (requires ` --raw ` ) | ` false ` |
9092| ` --strict ` | Treat warnings as errors | ` false ` |
9193
9294#### Examples
@@ -97,12 +99,36 @@ Generate TypeScript wrapper classes:
9799nativegen generate -i /path/to/rdr3-natives -o ./output -f typescript
98100```
99101
100- Generate raw TypeScript declarations (no classes):
102+ Generate raw TypeScript declarations (no classes, one file per namespace ):
101103
102104``` bash
103105nativegen generate -i /path/to/rdr3-natives -o ./output -f typescript --raw
104106```
105107
108+ Generate raw TypeScript declarations (single file with all natives):
109+
110+ ``` bash
111+ nativegen generate -i /path/to/rdr3-natives -o ./output -f typescript --raw --single-file
112+ ```
113+
114+ Generate Lua wrapper classes:
115+
116+ ``` bash
117+ nativegen generate -i /path/to/rdr3-natives -o ./output -f lua
118+ ```
119+
120+ Generate raw Lua declarations (no classes, one file per namespace):
121+
122+ ``` bash
123+ nativegen generate -i /path/to/rdr3-natives -o ./output -f lua --raw
124+ ```
125+
126+ Generate raw Lua declarations (single file with all natives):
127+
128+ ``` bash
129+ nativegen generate -i /path/to/rdr3-natives -o ./output -f lua --raw --single-file
130+ ```
131+
106132Generate JSON database:
107133
108134``` bash
@@ -141,6 +167,64 @@ dotnet run --project src/NativeCodeGen.Cli -- validate -i <input> [options]
141167nativegen validate -i /path/to/rdr3-natives --strict
142168```
143169
170+ ## Generation Modes
171+
172+ The ` --raw ` and ` --single-file ` flags control how native functions are generated:
173+
174+ ### Default Mode (Classes)
175+
176+ Without flags, generates OOP-style wrapper classes where natives are organized as methods on entity classes:
177+
178+ ``` typescript
179+ // classes/Entity.ts
180+ export class Entity implements IHandle {
181+ constructor (public handle : number ) {}
182+
183+ getCoords(alive : boolean ): Vector3 {
184+ return Vector3 .fromArray (inv <number []>(' 0x...' , this .handle , alive , rav ()));
185+ }
186+ }
187+
188+ // Usage
189+ const ped = new Ped (pedHandle );
190+ const coords = ped .getCoords (true );
191+ ```
192+
193+ ### Raw Mode (` --raw ` )
194+
195+ Generates standalone exported functions with handles as plain numbers. One file per namespace:
196+
197+ ``` typescript
198+ // natives/ENTITY.ts
199+ export function GetEntityCoords(entity : number , alive : boolean ): Vector3 {
200+ return Vector3 .fromArray (inv (' 0x...' , entity , alive , rav ()));
201+ }
202+
203+ // Usage
204+ const coords = GetEntityCoords (pedHandle , true );
205+ ```
206+
207+ ### Single File Mode (` --raw --single-file ` )
208+
209+ Generates all natives in a single file as global functions. Useful for smaller bundles:
210+
211+ ``` typescript
212+ // natives.ts
213+ globalThis .GetEntityCoords = function (entity : number , alive : boolean ): Vector3 {
214+ return Vector3 .fromArray (inv (' 0x...' , entity , alive , rav ()));
215+ };
216+
217+ // Usage (functions are on globalThis)
218+ const coords = GetEntityCoords (pedHandle , true );
219+ ```
220+
221+ ### Lua Modes
222+
223+ Lua follows the same pattern:
224+
225+ - ** Raw mode** : Module tables per namespace (` Water.GetWaterHeight(...) ` )
226+ - ** Single file mode** : Global functions (` GetWaterHeight(...) ` )
227+
144228## Output Formats
145229
146230### TypeScript (default)
@@ -167,7 +251,7 @@ output/
167251 └── *.ts # Static utility classes
168252```
169253
170- With ` --raw ` flag, generates standalone functions without class wrappers:
254+ With ` --raw ` flag, generates standalone functions without class wrappers (one file per namespace) :
171255
172256```
173257output/
@@ -176,7 +260,63 @@ output/
176260├── enums/
177261├── structs/
178262└── natives/
179- └── *.ts # Raw native function exports
263+ └── *.ts # Raw native function exports per namespace
264+ ```
265+
266+ With ` --raw --single-file ` flags, generates all natives in a single file:
267+
268+ ```
269+ output/
270+ ├── index.ts
271+ ├── types/
272+ ├── enums/
273+ ├── structs/
274+ └── natives.ts # All native functions in one file
275+ ```
276+
277+ ### Lua
278+
279+ Generates typed wrapper classes with LuaLS annotations:
280+
281+ ```
282+ output/
283+ ├── init.lua # Re-exports all modules
284+ ├── types/
285+ │ ├── IHandle.lua # Handle interface
286+ │ ├── Vector3.lua # Vector3 class
287+ │ └── BufferedClass.lua # Base class for structs
288+ ├── enums/
289+ │ └── *.lua # Enum definitions
290+ ├── structs/
291+ │ └── *.lua # Struct classes (BufferedClass)
292+ ├── classes/
293+ │ ├── Entity.lua # Base entity class
294+ │ ├── Ped.lua # Ped class (extends Entity)
295+ │ ├── Vehicle.lua # Vehicle class (extends Entity)
296+ │ └── *.lua # Other handle classes
297+ └── namespaces/
298+ └── *.lua # Static utility classes
299+ ```
300+
301+ With ` --raw ` flag, generates standalone functions (one file per namespace):
302+
303+ ```
304+ output/
305+ ├── fxmanifest.lua
306+ ├── enums/
307+ ├── structs/
308+ └── natives/
309+ └── *.lua # Raw native function exports per namespace (module tables)
310+ ```
311+
312+ With ` --raw --single-file ` flags, generates all natives in a single file:
313+
314+ ```
315+ output/
316+ ├── fxmanifest.lua
317+ ├── enums/
318+ ├── structs/
319+ └── natives.lua # All native functions in one file (global functions)
180320```
181321
182322### JSON
@@ -300,5 +440,8 @@ NativeCodeGen/
300440 ├── NativeCodeGen.TypeScript/ # TypeScript generation
301441 │ ├── Generation/ # Code generators
302442 │ └── Utilities/ # Name conversion, etc.
443+ ├── NativeCodeGen.Lua/ # Lua generation
444+ │ ├── Generation/ # Code generators
445+ │ └── Utilities/ # Name conversion, etc.
303446 └── NativeCodeGen.Cli/ # Command-line interface
304447```
0 commit comments