rakata_formats/lib.rs
1//! Binary and text format readers/writers for KotOR resources.
2//!
3//! Modules in this crate are implementation-focused and designed to support
4//! deterministic roundtrip behavior.
5
6#![forbid(unsafe_code)]
7#![warn(clippy::as_conversions)]
8#![deny(missing_docs)]
9
10#[cfg(feature = "tracing")]
11macro_rules! trace_debug {
12 ($($arg:tt)*) => {
13 tracing::debug!($($arg)*);
14 };
15}
16
17#[cfg(not(feature = "tracing"))]
18macro_rules! trace_debug {
19 ($($arg:tt)*) => {};
20}
21
22#[cfg(feature = "tracing")]
23macro_rules! trace_warn {
24 ($($arg:tt)*) => {
25 tracing::warn!($($arg)*);
26 };
27}
28
29#[cfg(not(feature = "tracing"))]
30macro_rules! trace_warn {
31 ($($arg:tt)*) => {};
32}
33
34pub(crate) use trace_debug;
35pub(crate) use trace_warn;
36
37/// BIF archive support.
38pub mod bif;
39/// Shared binary utilities and lightweight format codec traits.
40pub mod binary;
41/// BWM/WOK binary walkmesh support.
42pub mod bwm;
43/// DDS texture-container support.
44pub mod dds;
45/// ERF-family archive support.
46pub mod erf;
47/// GFF binary container support.
48pub mod gff;
49/// GFF schema types for field validation.
50pub mod gff_schema;
51/// KEY index support.
52pub mod key;
53/// LIP binary lip-sync support.
54pub mod lip;
55/// LTR binary letter-table support.
56pub mod ltr;
57/// LYT ASCII layout support.
58pub mod lyt;
59/// MDL binary model support.
60pub mod mdl;
61/// RIM archive support.
62pub mod rim;
63/// SSF binary sound-set support.
64pub mod ssf;
65/// TGA texture-image support.
66pub mod tga;
67/// Talk table (TLK) binary support.
68pub mod tlk;
69/// TPC binary texture-container support.
70pub mod tpc;
71/// 2DA binary table support.
72pub mod twoda;
73/// TXI ASCII texture-info support.
74pub mod txi;
75/// VIS ASCII visibility support.
76pub mod vis;
77/// WAV audio container support.
78pub mod wav;
79
80/// Reads BIF binary data from a reader at the current stream position.
81pub use bif::read_bif;
82/// Reads BIF binary data directly from bytes.
83pub use bif::read_bif_from_bytes;
84/// Writes BIF binary data to an output writer.
85pub use bif::write_bif;
86/// Serializes BIF binary data into a byte vector.
87pub use bif::write_bif_to_vec;
88/// In-memory BIF archive type.
89pub use bif::Bif;
90/// BIF binary parsing/serialization error type.
91pub use bif::BifBinaryError;
92/// BIF on-disk container kind.
93pub use bif::BifContainer;
94/// In-memory BIF resource entry type.
95pub use bif::BifResource;
96/// BIF resource storage-table descriptor.
97pub use bif::BifResourceStorage;
98/// Trait for decoding format values from byte slices.
99pub use binary::DecodeBinary;
100/// Trait for encoding format values into byte vectors.
101pub use binary::EncodeBinary;
102/// Reads BWM data from a reader at the current stream position.
103pub use bwm::read_bwm;
104/// Reads an ASCII BWM from a reader.
105pub use bwm::read_bwm_ascii;
106/// Reads BWM data directly from bytes.
107pub use bwm::read_bwm_from_bytes;
108/// Writes BWM data to an output writer.
109pub use bwm::write_bwm;
110/// Writes a BWM to an ASCII writer.
111pub use bwm::write_bwm_ascii;
112/// Serializes BWM data into a byte vector.
113pub use bwm::write_bwm_to_vec;
114/// In-memory BWM container type.
115pub use bwm::Bwm;
116/// One AABB-node row.
117pub use bwm::BwmAabbNode;
118/// One adjacency row.
119pub use bwm::BwmAdjacency;
120/// BWM ASCII parsing error type.
121pub use bwm::BwmAsciiError;
122/// BWM binary parsing/serialization error type.
123pub use bwm::BwmBinaryError;
124/// One edge-transition row.
125pub use bwm::BwmEdge;
126/// One face row in BWM tables.
127pub use bwm::BwmFace;
128/// Known walkmesh type values.
129pub use bwm::BwmType;
130/// Lossless walkmesh-type wrapper.
131pub use bwm::BwmTypeCode;
132/// Three-dimensional vector value for BWM data.
133pub use bwm::BwmVec3;
134/// Reads DDS data from a reader at the current stream position.
135pub use dds::read_dds;
136/// Reads DDS data directly from bytes.
137pub use dds::read_dds_from_bytes;
138/// Writes DDS data to an output writer.
139pub use dds::write_dds;
140/// Serializes DDS data into a byte vector.
141pub use dds::write_dds_to_vec;
142/// In-memory DDS container type.
143pub use dds::Dds;
144/// DDS binary parsing/serialization error type.
145pub use dds::DdsBinaryError;
146/// DDS caps2 bitflag re-export.
147pub use dds::DdsCaps2;
148/// DDS D3D-format enum re-export.
149pub use dds::DdsD3dFormat;
150/// Constructor parameter set for D3D DDS creation.
151pub use dds::DdsNewD3dParams;
152/// Reads ERF-family binary data from a reader at the current stream position.
153pub use erf::read_erf;
154/// Reads ERF-family binary data directly from bytes.
155pub use erf::read_erf_from_bytes;
156/// Reads ERF-family binary data directly from bytes with explicit read options.
157pub use erf::read_erf_from_bytes_with_options;
158/// Reads ERF-family binary data from a reader with explicit read options.
159pub use erf::read_erf_with_options;
160/// Reads save-archive data from a reader, accepting `MOD ` and `SAV ` input.
161pub use erf::read_save_archive;
162/// Reads save-archive data directly from bytes, accepting `MOD ` and `SAV ` input.
163pub use erf::read_save_archive_from_bytes;
164/// Writes ERF-family binary data to an output writer.
165pub use erf::write_erf;
166/// Serializes ERF-family binary data into a byte vector.
167pub use erf::write_erf_to_vec;
168/// Serializes ERF-family binary data into a byte vector with explicit options.
169pub use erf::write_erf_to_vec_with_options;
170/// Writes ERF-family binary data to an output writer with explicit options.
171pub use erf::write_erf_with_options;
172/// Writes save-archive data to an output writer using canonical `MOD ` output.
173pub use erf::write_save_archive;
174/// Serializes save-archive data into a byte vector using canonical `MOD ` output.
175pub use erf::write_save_archive_to_vec;
176/// In-memory ERF-family archive type.
177pub use erf::Erf;
178/// ERF-family parsing/serialization error type.
179pub use erf::ErfBinaryError;
180/// Supported ERF-family file signatures.
181pub use erf::ErfFileType;
182/// In-memory ERF localized string entry type.
183pub use erf::ErfLocalizedString;
184/// ERF reader behavior profile.
185pub use erf::ErfReadMode;
186/// ERF reader option set.
187pub use erf::ErfReadOptions;
188/// In-memory ERF resource entry type.
189pub use erf::ErfResource;
190/// ERF writer behavior profile.
191pub use erf::ErfWriteMode;
192/// ERF writer option set.
193pub use erf::ErfWriteOptions;
194/// MOD write layout policy.
195pub use erf::ModLayout;
196/// Reads GFF binary data from a reader at the current stream position.
197pub use gff::read_gff;
198/// Reads GFF binary data directly from bytes.
199pub use gff::read_gff_from_bytes;
200/// Writes GFF binary data to an output writer.
201pub use gff::write_gff;
202/// Serializes GFF binary data into a byte vector.
203pub use gff::write_gff_to_vec;
204/// In-memory GFF container type.
205pub use gff::Gff;
206/// GFF binary parsing/serialization error type.
207pub use gff::GffBinaryError;
208/// In-memory GFF field type.
209pub use gff::GffField;
210/// In-memory localized-string payload type.
211pub use gff::GffLocalizedString;
212/// In-memory localized-string substring entry type.
213pub use gff::GffLocalizedSubstring;
214/// In-memory GFF struct type.
215pub use gff::GffStruct;
216/// In-memory GFF value type.
217pub use gff::GffValue;
218/// Map a [`GffValue`] variant to its corresponding [`GffType`].
219pub use gff_schema::gff_value_type;
220/// Schema definition for a single GFF field.
221pub use gff_schema::FieldSchema;
222/// Trait providing the engine-derived field schema for a GFF resource type.
223pub use gff_schema::GffSchema;
224/// Expected GFF field type, mirroring [`GffValue`] variants.
225pub use gff_schema::GffType;
226/// Packs KEY `(bif_index, resource_index)` parts into `resource_id`.
227pub use key::pack_resource_id;
228/// Reads KEY binary data from a reader at the current stream position.
229pub use key::read_key;
230/// Reads KEY binary data directly from bytes.
231pub use key::read_key_from_bytes;
232/// Writes KEY binary data to an output writer.
233pub use key::write_key;
234/// Serializes KEY binary data into a byte vector.
235pub use key::write_key_to_vec;
236/// In-memory KEY container type.
237pub use key::Key;
238/// In-memory KEY file-table entry type.
239pub use key::KeyBifEntry;
240/// KEY binary parsing/serialization error type.
241pub use key::KeyBinaryError;
242/// In-memory KEY resource entry type.
243pub use key::KeyResourceEntry;
244/// Reads LIP binary data from a reader at the current stream position.
245pub use lip::read_lip;
246/// Reads LIP binary data directly from bytes.
247pub use lip::read_lip_from_bytes;
248/// Writes LIP binary data to an output writer.
249pub use lip::write_lip;
250/// Serializes LIP binary data into a byte vector.
251pub use lip::write_lip_to_vec;
252/// In-memory LIP container type.
253pub use lip::Lip;
254/// LIP binary parsing/serialization error type.
255pub use lip::LipBinaryError;
256/// In-memory LIP keyframe type.
257pub use lip::LipKeyframe;
258/// Known LIP viseme shape IDs.
259pub use lip::LipShape;
260/// Lossless LIP shape code wrapper.
261pub use lip::LipShapeCode;
262/// Reads LTR binary data from a reader at the current stream position.
263pub use ltr::read_ltr;
264/// Reads LTR binary data directly from bytes.
265pub use ltr::read_ltr_from_bytes;
266/// Writes LTR binary data to an output writer.
267pub use ltr::write_ltr;
268/// Serializes LTR binary data into a byte vector.
269pub use ltr::write_ltr_to_vec;
270/// In-memory LTR container type.
271pub use ltr::Ltr;
272/// LTR binary parsing/serialization error type.
273pub use ltr::LtrBinaryError;
274/// In-memory LTR probability block type.
275pub use ltr::LtrProbabilityBlock;
276/// LTR canonical character-count constant.
277pub use ltr::LTR_CHARACTER_COUNT;
278/// Reads LYT ASCII data from a reader at the current stream position.
279pub use lyt::read_lyt;
280/// Reads LYT ASCII data directly from bytes.
281pub use lyt::read_lyt_from_bytes;
282/// Writes LYT ASCII data to an output writer.
283pub use lyt::write_lyt;
284/// Serializes LYT ASCII data into a byte vector.
285pub use lyt::write_lyt_to_vec;
286/// In-memory LYT container type.
287pub use lyt::Lyt;
288/// In-memory LYT door-hook type.
289pub use lyt::LytDoorHook;
290/// LYT ASCII parsing/serialization error type.
291pub use lyt::LytError;
292/// In-memory LYT obstacle type.
293pub use lyt::LytObstacle;
294/// In-memory LYT room type.
295pub use lyt::LytRoom;
296/// In-memory LYT track type.
297pub use lyt::LytTrack;
298/// Quaternion type used by LYT door-hook orientation.
299pub use lyt::Quaternion;
300/// Three-dimensional vector type used by LYT entries.
301pub use lyt::Vec3;
302/// Assign inverted counter values to all mesh nodes in DFS tree order.
303pub use mdl::assign_inverted_counters;
304/// Reads MDL binary data from a reader.
305pub use mdl::read_mdl;
306/// Reads MDL ASCII data from a buffered reader.
307pub use mdl::read_mdl_ascii;
308/// Reads MDL ASCII data from a string.
309pub use mdl::read_mdl_ascii_from_str;
310/// Reads MDL binary data from bytes.
311pub use mdl::read_mdl_from_bytes;
312/// Writes MDL binary data to a writer.
313pub use mdl::write_mdl;
314/// Writes MDL ASCII data to a writer.
315pub use mdl::write_mdl_ascii;
316/// Serializes MDL ASCII data into a string.
317pub use mdl::write_mdl_ascii_to_string;
318/// Writes MDL binary data to a byte vector.
319pub use mdl::write_mdl_to_vec;
320/// Writes MDL binary data with companion MDX vertex data to byte vectors.
321pub use mdl::write_mdl_with_mdx_to_vec;
322/// A node in the AABB binary search tree used by walkmesh collision meshes.
323pub use mdl::AabbNode;
324/// In-memory MDL container type.
325pub use mdl::Mdl;
326/// In-memory MDL AABB walkmesh node data type.
327pub use mdl::MdlAabb;
328/// In-memory MDL animation event type.
329pub use mdl::MdlAnimEvent;
330/// In-memory MDL animated mesh type.
331pub use mdl::MdlAnimMesh;
332/// In-memory MDL animation node type.
333pub use mdl::MdlAnimNode;
334/// In-memory MDL animation sequence type.
335pub use mdl::MdlAnimation;
336/// MDL ASCII serialization error type.
337pub use mdl::MdlAsciiError;
338/// In-memory MDL camera node data type.
339pub use mdl::MdlCamera;
340/// In-memory MDL controller type.
341pub use mdl::MdlController;
342/// MDL controller type enum.
343pub use mdl::MdlControllerType;
344/// In-memory MDL dangly mesh node data type.
345pub use mdl::MdlDangly;
346/// In-memory MDL emitter node data type.
347pub use mdl::MdlEmitter;
348/// MDL parsing error type.
349pub use mdl::MdlError;
350/// In-memory MDL face type (32-byte MaxFace format).
351pub use mdl::MdlFace;
352/// In-memory MDL keyframe type.
353pub use mdl::MdlKey;
354/// In-memory MDL light node data type.
355pub use mdl::MdlLight;
356/// In-memory MDL mesh type.
357pub use mdl::MdlMesh;
358/// In-memory MDL node type.
359pub use mdl::MdlNode;
360/// MDL node type-specific data enum.
361pub use mdl::MdlNodeData;
362/// In-memory MDL reference node data type.
363pub use mdl::MdlReference;
364/// In-memory MDL lightsaber blade mesh type.
365pub use mdl::MdlSaber;
366/// In-memory MDL skinned mesh type.
367pub use mdl::MdlSkin;
368/// Result of writing an MDL model with its companion MDX vertex data.
369pub use mdl::MdlWriteResult;
370/// Reads RIM binary data from a reader at the current stream position.
371pub use rim::read_rim;
372/// Reads RIM binary data directly from bytes.
373pub use rim::read_rim_from_bytes;
374/// Writes RIM binary data to an output writer.
375pub use rim::write_rim;
376/// Serializes RIM binary data into a byte vector.
377pub use rim::write_rim_to_vec;
378/// In-memory RIM archive type.
379pub use rim::Rim;
380/// RIM binary parsing/serialization error type.
381pub use rim::RimBinaryError;
382/// In-memory RIM resource entry type.
383pub use rim::RimResource;
384/// Reads SSF binary data from a reader at the current stream position.
385pub use ssf::read_ssf;
386/// Reads SSF binary data directly from bytes.
387pub use ssf::read_ssf_from_bytes;
388/// Writes SSF binary data to an output writer.
389pub use ssf::write_ssf;
390/// Serializes SSF binary data into a byte vector.
391pub use ssf::write_ssf_to_vec;
392/// In-memory SSF container type.
393pub use ssf::Ssf;
394/// SSF binary parsing/serialization error type.
395pub use ssf::SsfBinaryError;
396/// SSF sound-slot identifiers.
397pub use ssf::SsfSoundSlot;
398/// Reads TGA data from a reader at the current stream position.
399pub use tga::read_tga;
400/// Reads TGA data directly from bytes.
401pub use tga::read_tga_from_bytes;
402/// Reads TGA data directly from bytes with explicit options.
403pub use tga::read_tga_from_bytes_with_options;
404/// Reads TGA data from a reader at the current stream position with explicit options.
405pub use tga::read_tga_with_options;
406/// Writes TGA data to an output writer.
407pub use tga::write_tga;
408/// Serializes TGA data into a byte vector.
409pub use tga::write_tga_to_vec;
410/// In-memory TGA image type.
411pub use tga::Tga;
412/// TGA parsing/serialization error type.
413pub use tga::TgaBinaryError;
414/// Source TGA bit depth metadata.
415pub use tga::TgaBitsPerPixel;
416/// Source TGA compression metadata.
417pub use tga::TgaCompression;
418/// Source TGA data-type metadata.
419pub use tga::TgaDataType;
420/// Source TGA header metadata.
421pub use tga::TgaHeader;
422/// Source TGA origin metadata.
423pub use tga::TgaOrigin;
424/// TGA reader input policy.
425pub use tga::TgaReadMode;
426/// TGA reader option set.
427pub use tga::TgaReadOptions;
428/// Reads TLK binary data from a reader at the current stream position.
429pub use tlk::read_tlk;
430/// Reads TLK binary data directly from bytes.
431pub use tlk::read_tlk_from_bytes;
432/// Writes TLK binary data to an output writer.
433pub use tlk::write_tlk;
434/// Serializes TLK binary data into a byte vector.
435pub use tlk::write_tlk_to_vec;
436/// In-memory TLK container type.
437pub use tlk::Tlk;
438/// TLK binary parsing/serialization error type.
439pub use tlk::TlkBinaryError;
440/// In-memory TLK entry type.
441pub use tlk::TlkEntry;
442/// Reads TPC binary data from a reader at the current stream position.
443pub use tpc::read_tpc;
444/// Reads TPC binary data directly from bytes.
445pub use tpc::read_tpc_from_bytes;
446/// Writes TPC binary data to an output writer.
447pub use tpc::write_tpc;
448/// Serializes TPC binary data into a byte vector.
449pub use tpc::write_tpc_to_vec;
450/// In-memory TPC container type.
451pub use tpc::Tpc;
452/// TPC binary parsing/serialization error type.
453pub use tpc::TpcBinaryError;
454/// TPC header fields.
455pub use tpc::TpcHeader;
456/// Header-derived TPC pixel-format classification.
457pub use tpc::TpcHeaderPixelFormat;
458/// Raw TPC pixel-format code.
459pub use tpc::TpcPixelFormatCode;
460/// Reads binary 2DA data from a reader at the current stream position.
461pub use twoda::read_twoda;
462/// Reads binary 2DA data directly from bytes.
463pub use twoda::read_twoda_from_bytes;
464/// Reads binary 2DA data directly from bytes with explicit text options.
465pub use twoda::read_twoda_from_bytes_with_options;
466/// Reads binary 2DA data from a reader at the current stream position with explicit text options.
467pub use twoda::read_twoda_with_options;
468/// Writes binary 2DA data to an output writer.
469pub use twoda::write_twoda;
470/// Serializes binary 2DA data into a byte vector.
471pub use twoda::write_twoda_to_vec;
472/// Serializes binary 2DA data into a byte vector with explicit text options.
473pub use twoda::write_twoda_to_vec_with_options;
474/// Writes binary 2DA data to an output writer with explicit text options.
475pub use twoda::write_twoda_with_options;
476/// In-memory 2DA table type.
477pub use twoda::TwoDa;
478/// 2DA binary parsing/serialization error type.
479pub use twoda::TwoDaBinaryError;
480/// Binary 2DA reader/writer text options.
481pub use twoda::TwoDaBinaryOptions;
482/// In-memory 2DA row type.
483pub use twoda::TwoDaRow;
484/// Reads TXI ASCII data from a reader at the current stream position.
485pub use txi::read_txi;
486/// Reads TXI ASCII data directly from bytes.
487pub use txi::read_txi_from_bytes;
488/// Reads TXI ASCII data directly from bytes with explicit command-token mode.
489pub use txi::read_txi_from_bytes_with_options;
490/// Reads TXI ASCII data from a reader with explicit command-token mode.
491pub use txi::read_txi_with_options;
492/// Writes TXI ASCII data to an output writer.
493pub use txi::write_txi;
494/// Serializes TXI ASCII data into a byte vector.
495pub use txi::write_txi_to_vec;
496/// Serializes TXI ASCII data into a byte vector with explicit command-token mode.
497pub use txi::write_txi_to_vec_with_options;
498/// Writes TXI ASCII data to an output writer with explicit command-token mode.
499pub use txi::write_txi_with_options;
500/// In-memory TXI container type.
501pub use txi::Txi;
502/// One TXI UV coordinate entry.
503pub use txi::TxiCoordinate;
504/// One TXI coordinate block command.
505pub use txi::TxiCoordinateBlock;
506/// One TXI command entry.
507pub use txi::TxiDirective;
508/// One TXI ordered entry.
509pub use txi::TxiEntry;
510/// TXI ASCII parsing/serialization error type.
511pub use txi::TxiError;
512/// TXI parser option set.
513pub use txi::TxiReadOptions;
514/// TXI writer option set.
515pub use txi::TxiWriteOptions;
516/// Reads VIS ASCII data from a reader at the current stream position.
517pub use vis::read_vis;
518/// Reads VIS ASCII data directly from bytes.
519pub use vis::read_vis_from_bytes;
520/// Writes VIS ASCII data to an output writer.
521pub use vis::write_vis;
522/// Serializes VIS ASCII data into a byte vector.
523pub use vis::write_vis_to_vec;
524/// In-memory VIS graph type.
525pub use vis::Vis;
526/// VIS ASCII parsing/serialization error type.
527pub use vis::VisError;
528/// Reads WAV data from a reader at the current stream position.
529pub use wav::read_wav;
530/// Reads WAV data directly from bytes.
531pub use wav::read_wav_from_bytes;
532/// Writes WAV data to an output writer using game-compatible wrapping.
533pub use wav::write_wav;
534/// Serializes WAV data into a byte vector using game-compatible wrapping.
535pub use wav::write_wav_to_vec;
536/// Serializes WAV data into a byte vector with explicit mode options.
537pub use wav::write_wav_to_vec_with_options;
538/// Writes WAV data to an output writer with explicit mode options.
539pub use wav::write_wav_with_options;
540/// In-memory WAV container type.
541pub use wav::Wav;
542/// WAV audio payload kind.
543pub use wav::WavAudioFormat;
544/// Known WAVE encoding tags.
545pub use wav::WavEncoding;
546/// Lossless WAVE encoding tag wrapper.
547pub use wav::WavEncodingCode;
548/// WAV parsing/serialization error type.
549pub use wav::WavError;
550/// KotOR WAV wrapper kind.
551pub use wav::WavType;
552/// WAVE-format metadata fields.
553pub use wav::WavWaveMetadata;
554/// WAV wrapper variant detected in source bytes.
555pub use wav::WavWrapperKind;
556/// WAV writer output mode.
557pub use wav::WavWriteMode;
558/// WAV writer option set.
559pub use wav::WavWriteOptions;