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