diff --git a/README.md b/README.md index 18e09e6..aafae83 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ msg-tool create -t | Archive Type | Feature Name | Name | Unpack | Pack | Remarks | |---|---|---|---|---|---| -| `escude-arc` | `escude-arc` | Escu:de Archive File (.arc) | ✔️ | ✔️ | | +| `escude-arc` | `escude-arc` | Escu:de Archive File (.bin) | ✔️ | ✔️ | | ### ExHibit | Script Type | Feature Name | Name | Export | Import | Custom Export | Custom Import | Create | Remarks | |---|---|---|---|---|---|---|---|---| diff --git a/src/scripts/escude/archive.rs b/src/scripts/escude/archive.rs index d0df97d..df3cb50 100644 --- a/src/scripts/escude/archive.rs +++ b/src/scripts/escude/archive.rs @@ -1,3 +1,4 @@ +//! Escu:de Archive File (.bin) use super::crypto::*; use crate::ext::io::*; use crate::scripts::base::*; @@ -10,9 +11,11 @@ use std::io::{Read, Seek, SeekFrom, Write}; use std::sync::{Arc, Mutex}; #[derive(Debug)] +/// Escu:de Archive Builder pub struct EscudeBinArchiveBuilder {} impl EscudeBinArchiveBuilder { + /// Creates a new instance of `EscudeBinArchiveBuilder` pub const fn new() -> Self { EscudeBinArchiveBuilder {} } @@ -161,6 +164,7 @@ impl ArchiveContent for Entry { } #[derive(Debug)] +/// Escu:de Binary Archive pub struct EscudeBinArchive { reader: Arc>, file_count: u32, @@ -169,6 +173,11 @@ pub struct EscudeBinArchive { } impl EscudeBinArchive { + /// Creates a new `EscudeBinArchive` from a reader + /// + /// * `reader` - The reader to read the archive from + /// * `archive_encoding` - The encoding used for the archive filenames + /// * `config` - Extra configuration options pub fn new(mut reader: T, archive_encoding: Encoding, _config: &ExtraConfig) -> Result { let mut header = [0u8; 8]; reader.read_exact(&mut header)?; @@ -289,6 +298,7 @@ impl<'a, T: Iterator, R: Read + Seek> Iterator } } +/// Escu:de Binary Archive Writer pub struct EscudeBinArchiveWriter { writer: T, headers: HashMap, @@ -297,6 +307,12 @@ pub struct EscudeBinArchiveWriter { } impl EscudeBinArchiveWriter { + /// Creates a new `EscudeBinArchiveWriter` + /// + /// * `writer` - The writer to write the archive to + /// * `files` - The list of files to include in the archive + /// * `encoding` - The encoding used for the archive filenames + /// * `config` - Extra configuration options pub fn new( mut writer: T, files: &[&str], @@ -368,6 +384,7 @@ impl Archive for EscudeBinArchiveWriter { } } +/// Escu:de Binary Archive File with LZW Compression pub struct EscudeBinArchiveFileWithLzw<'a, T: Write + Seek> { writer: EscudeBinArchiveFile<'a, T>, buf: MemWriter, @@ -435,6 +452,7 @@ impl<'a, T: Write + Seek> Drop for EscudeBinArchiveFileWithLzw<'a, T> { } } +/// Escu:de Binary Archive File pub struct EscudeBinArchiveFile<'a, T: Write + Seek> { header: &'a mut BinEntry, writer: &'a mut T, diff --git a/src/scripts/escude/list.rs b/src/scripts/escude/list.rs index b25e328..32de8a0 100644 --- a/src/scripts/escude/list.rs +++ b/src/scripts/escude/list.rs @@ -1,3 +1,4 @@ +//! Escu:de List File (.bin) use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -9,9 +10,11 @@ use serde::{Deserialize, Serialize}; use std::io::{Read, Seek, Write}; #[derive(Debug)] +/// Escu:de List Builder pub struct EscudeBinListBuilder {} impl EscudeBinListBuilder { + /// Creates a new instance of `EscudeBinListBuilder` pub const fn new() -> Self { EscudeBinListBuilder {} } @@ -68,11 +71,19 @@ impl ScriptBuilder for EscudeBinListBuilder { } #[derive(Debug)] +/// Escu:de Binary List pub struct EscudeBinList { + /// List of entries in the Escu:de list pub entries: Vec, } impl EscudeBinList { + /// Creates a new `EscudeBinList` from the given data + /// + /// * `data` - The reader to read the data from + /// * `filename` - The name of the file + /// * `encoding` - The encoding + /// * `config` - Extra configuration options pub fn new( data: Vec, filename: &str, @@ -111,6 +122,10 @@ impl EscudeBinList { Ok(s) } + /// Attempts to decode the entries in the list based on the filename and encoding + /// + /// * `filename` - The name of the file + /// * `encoding` - The encoding to use for decoding pub fn try_decode(&mut self, filename: &str, encoding: Encoding) -> Result<()> { let filename = std::path::Path::new(filename); if let Some(filename) = filename.file_name() { @@ -343,18 +358,22 @@ impl Script for EscudeBinList { } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Script entry in the Escu:de list pub struct ScriptT { #[fstring = 64] #[fstring_pad = 0x20] /// File name pub file: String, + /// Script ID pub source: u32, #[fstring = 64] #[fstring_pad = 0x20] + /// Script title pub title: String, } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Name entry in the Escu:de list pub struct NameT { #[fstring = 64] #[fstring_pad = 0x20] @@ -369,6 +388,7 @@ pub struct NameT { } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Variable entry in the Escu:de list pub struct VarT { /// Variable name #[fstring = 32] @@ -381,6 +401,7 @@ pub struct VarT { } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Scene entry in the Escu:de list pub struct SceneT { /// The scene script ID pub script: u32, @@ -398,14 +419,20 @@ pub struct SceneT { #[derive(Debug, Serialize, Deserialize, StructPack)] #[serde(tag = "type", content = "data")] +/// Enum for different types of script data in the Escu:de list (enum._scr.bin) pub enum EnumScr { + /// Scripts data Scripts(Vec), + /// Names data Names(Vec), + /// Variables data Vars(Vec), + /// Scenes data Scenes(Vec), } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Background entry in the Escu:de list pub struct BgT { /// Background image name #[fstring = 32] @@ -417,16 +444,24 @@ pub struct BgT { file: String, #[fstring = 128] #[fstring_pad = 0x20] + /// Background options option: String, + /// Background covered flag coverd: u32, + /// Background color color: u32, + /// Background ID id: u32, + /// Background location ID loc: u32, + /// Background order in the scene order: i32, + /// Background link ID link: u32, } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Event image entry in the Escu:de list pub struct EvT { /// Event image name #[fstring = 32] @@ -438,35 +473,53 @@ pub struct EvT { file: String, #[fstring = 128] #[fstring_pad = 0x20] + /// Event image options option: String, + /// Event image covered flag coverd: u32, + /// Event image color color: u32, + /// Event image ID id: u32, + /// Event image location ID loc: u32, + /// Event image order in the scene order: i32, + /// Event image link ID link: u32, } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Stage entry in the Escu:de list pub struct StT { #[fstring = 32] #[fstring_pad = 0x20] + /// Stage name name: String, #[fstring = 64] #[fstring_pad = 0x20] + /// Stage file name file: String, #[fstring = 128] #[fstring_pad = 0x20] + /// Stage options option: String, + /// Stage covered flag coverd: u32, + /// Stage color color: u32, + /// Stage ID id: u32, + /// Stage location ID loc: u32, + /// Stage order in the scene order: i32, + /// Stage link ID link: u32, } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Effect image entry in the Escu:de list pub struct EfxT { /// Effect image name #[fstring = 32] @@ -476,12 +529,17 @@ pub struct EfxT { #[fstring = 64] #[fstring_pad = 0x20] file: String, + /// Effect image options spot: i32, + /// Effect image x position dx: i32, + /// Effect image y position dy: i32, + /// Effect image loop flag r#loop: bool, #[fvec = 3] #[serde(skip, default = "exft_padding")] + /// padding for alignment padding: Vec, } @@ -490,91 +548,128 @@ fn exft_padding() -> Vec { } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Point pub struct Point { + /// X coordinate x: i16, + /// Y coordinate y: i16, } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Location entry in the Escu:de list pub struct LocT { + /// List of points #[fvec = 8] pt: Vec, } #[derive(Debug, Serialize, Deserialize, StructPack)] #[serde(tag = "type", content = "data")] +/// Enum for different types of graphics data in the Escu:de list (enum_gfx.bin) pub enum EnumGfx { + /// Backgrounds data Bgs(Vec), + /// Event images data Evs(Vec), + /// Stages data Sts(Vec), + /// Effects data Efxs(Vec), + /// Locations data Locs(Vec), } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Background music entry in the Escu:de list pub struct BgmT { #[fstring = 64] #[fstring_pad = 0x20] + /// Background music name pub name: String, #[fstring = 64] #[fstring_pad = 0x20] + /// Background music file name pub file: String, #[fstring = 64] #[fstring_pad = 0x20] + /// Background music title pub title: String, + /// Background music order in the scene pub order: i32, } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Ambient sound entry in the Escu:de list pub struct AmbT { #[fstring = 64] #[fstring_pad = 0x20] + /// Ambient sound name pub name: String, #[fstring = 64] #[fstring_pad = 0x20] + /// Ambient sound file name pub file: String, } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Sound effect entry in the Escu:de list pub struct SeT { #[fstring = 64] #[fstring_pad = 0x20] + /// Sound effect name pub name: String, #[fstring = 64] #[fstring_pad = 0x20] + /// Sound effect file name pub file: String, } #[derive(Debug, Serialize, Deserialize, StructPack, StructUnpack)] +/// Sound effect (SFX) entry in the Escu:de list pub struct SfxT { #[fstring = 64] #[fstring_pad = 0x20] + /// SFX name pub name: String, #[fstring = 64] #[fstring_pad = 0x20] + /// SFX file name pub file: String, } #[derive(Debug, Serialize, Deserialize, StructPack)] #[serde(tag = "type", content = "data")] +/// Enum for different types of sound data in the Escu:de list (enum_snd.bin) pub enum EnumSnd { + /// Background music data Bgm(Vec), + /// Ambient sound data Amb(Vec), + /// Sound effect data Se(Vec), + /// Sound effect (SFX) data Sfx(Vec), } #[derive(Debug, Serialize, Deserialize, StructPack)] #[serde(tag = "type", content = "data")] +/// Enum for different types of data in the Escu:de list pub enum ListData { + /// Script data Scr(EnumScr), + /// Graphics data Gfx(EnumGfx), + /// Sound data Snd(EnumSnd), + /// Unknown data Unknown(Vec), } #[derive(Debug, Serialize, Deserialize)] +/// Entry in the Escu:de list pub struct ListEntry { id: u32, + /// The data associated with the entry pub data: ListData, } diff --git a/src/scripts/escude/mod.rs b/src/scripts/escude/mod.rs index 74c148f..c83de15 100644 --- a/src/scripts/escude/mod.rs +++ b/src/scripts/escude/mod.rs @@ -1,3 +1,4 @@ +//! Escu:de Scripts #[cfg(feature = "escude-arc")] pub mod archive; #[cfg(feature = "escude-arc")] diff --git a/src/scripts/escude/script.rs b/src/scripts/escude/script.rs index 759c9cf..491686e 100644 --- a/src/scripts/escude/script.rs +++ b/src/scripts/escude/script.rs @@ -1,3 +1,4 @@ +//! Escu:de Script File (.bin) use super::list::{EnumScr, EscudeBinList, ListData, NameT}; use super::ops::base::CustomOps; use crate::ext::io::*; @@ -13,9 +14,11 @@ use std::io::{Read, Seek, SeekFrom}; use unicode_segmentation::UnicodeSegmentation; #[derive(Debug)] +/// Builder for Escu:de binary script files pub struct EscudeBinScriptBuilder {} impl EscudeBinScriptBuilder { + /// Creates a new instance of `EscudeBinScriptBuilder` pub const fn new() -> Self { EscudeBinScriptBuilder {} } @@ -55,6 +58,7 @@ impl ScriptBuilder for EscudeBinScriptBuilder { } #[derive(Debug)] +/// Escu:de binary script file pub struct EscudeBinScript { vms: Vec, unk1: u32, @@ -84,6 +88,11 @@ fn load_enum_script( } impl EscudeBinScript { + /// Creates a new `EscudeBinScript` + /// + /// * `data` - The reader to read the data from + /// * `encoding` - The encoding of the script + /// * `config` - Extra configuration options pub fn new(data: Vec, encoding: Encoding, config: &ExtraConfig) -> Result { let mut reader = MemReader::new(data); let mut magic = [0u8; 8]; @@ -335,12 +344,12 @@ enum BaseOp { FileLine, } -pub trait ReadParam { +pub(crate) trait ReadParam { fn read_param(&mut self) -> Result; } #[derive(Debug)] -pub struct VM<'a, T: std::fmt::Debug> { +pub(crate) struct VM<'a, T: std::fmt::Debug> { pub reader: MemReaderRef<'a>, pub data: Vec, pub stack: Vec, diff --git a/src/scripts/ex_hibit/mod.rs b/src/scripts/ex_hibit/mod.rs index 6559c77..f5c070b 100644 --- a/src/scripts/ex_hibit/mod.rs +++ b/src/scripts/ex_hibit/mod.rs @@ -1 +1,2 @@ +//! ExHibit Scripts pub mod rld; diff --git a/src/scripts/ex_hibit/rld.rs b/src/scripts/ex_hibit/rld.rs index 32ded51..696ba9d 100644 --- a/src/scripts/ex_hibit/rld.rs +++ b/src/scripts/ex_hibit/rld.rs @@ -1,3 +1,4 @@ +//! ExHibit Script File (.rld) use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -11,9 +12,11 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; #[derive(Debug)] +/// Builder for ExHibit RLD script files pub struct RldScriptBuilder {} impl RldScriptBuilder { + /// Creates a new instance of `RldScriptBuilder` pub fn new() -> Self { Self {} } @@ -170,6 +173,7 @@ impl StructUnpack for OpExt { } #[derive(Debug)] +/// ExHibit RLD script file pub struct RldScript { data: MemReader, decrypted: bool, @@ -183,6 +187,12 @@ pub struct RldScript { } impl RldScript { + /// Creates a new `RldScript` + /// + /// * `buf` - The buffer containing the RLD script data + /// * `filename` - The name of the file + /// * `encoding` - The encoding of the script + /// * `config` - Extra configuration options pub fn new( buf: Vec, filename: &str, @@ -522,6 +532,7 @@ impl Script for RldScript { } } +/// Load the keys from a file pub fn load_keys(path: Option<&String>) -> Result>> { if let Some(path) = path { let f = crate::utils::files::read_file(path)?; diff --git a/src/scripts/hexen_haus/bin.rs b/src/scripts/hexen_haus/bin.rs index 9e12bf1..983668c 100644 --- a/src/scripts/hexen_haus/bin.rs +++ b/src/scripts/hexen_haus/bin.rs @@ -1,3 +1,4 @@ +//! HexenHaus Script File (.bin) use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -7,9 +8,11 @@ use anyhow::Result; use std::io::Read; #[derive(Debug)] +/// HexenHaus Script Builder pub struct BinScriptBuilder {} impl BinScriptBuilder { + /// Creates a new instance of `BinScriptBuilder` pub fn new() -> Self { BinScriptBuilder {} } @@ -56,12 +59,18 @@ struct BinString { } #[derive(Debug)] +/// HexenHaus Bin Script pub struct BinScript { data: MemReader, strs: Vec, } impl BinScript { + /// Creates a new `BinScript` + /// + /// * `buf` - The buffer containing the bin script data + /// * `encoding` - The encoding of the script + /// * `config` - Extra configuration options pub fn new(buf: Vec, encoding: Encoding, _config: &ExtraConfig) -> Result { let mut data = MemReader::new(buf); let mut header = [0; 4]; diff --git a/src/scripts/hexen_haus/mod.rs b/src/scripts/hexen_haus/mod.rs index b6db8d7..7aba5e6 100644 --- a/src/scripts/hexen_haus/mod.rs +++ b/src/scripts/hexen_haus/mod.rs @@ -1 +1,2 @@ +//! HexenHaus Scripts pub mod bin; diff --git a/src/scripts/kirikiri/image/dref.rs b/src/scripts/kirikiri/image/dref.rs index 2c18371..4021a68 100644 --- a/src/scripts/kirikiri/image/dref.rs +++ b/src/scripts/kirikiri/image/dref.rs @@ -1,3 +1,4 @@ +//! Kirikiri DPAK-referenced Image File (.dref) use crate::ext::io::*; use crate::ext::psb::*; use crate::scripts::base::*; @@ -12,9 +13,11 @@ use std::path::{Path, PathBuf}; use url::Url; #[derive(Debug)] +/// Kirikiri DREF Script Builder pub struct DrefBuilder {} impl DrefBuilder { + /// Creates a new instance of `DrefBuilder` pub fn new() -> Self { Self {} } @@ -174,6 +177,7 @@ impl DpakLoader { } } +/// Kirikiri DREF Script pub struct Dref { urls: Vec, dir: PathBuf, @@ -190,6 +194,13 @@ impl std::fmt::Debug for Dref { } impl Dref { + /// Create a new dref script + /// + /// * `buf` - The buffer containing the dref script data + /// * `encoding` - The encoding of the script + /// * `filename` - The name of the file + /// * `config` - Extra configuration options + /// * `archive` - Optional archive containing additional resources pub fn new( buf: Vec, encoding: Encoding, diff --git a/src/scripts/kirikiri/image/mod.rs b/src/scripts/kirikiri/image/mod.rs index 50e80f0..792470a 100644 --- a/src/scripts/kirikiri/image/mod.rs +++ b/src/scripts/kirikiri/image/mod.rs @@ -1,3 +1,4 @@ +//! Kirikiri Images pub mod dref; pub mod pimg; pub mod tlg; diff --git a/src/scripts/kirikiri/image/pimg.rs b/src/scripts/kirikiri/image/pimg.rs index 5449acb..2386cb5 100644 --- a/src/scripts/kirikiri/image/pimg.rs +++ b/src/scripts/kirikiri/image/pimg.rs @@ -1,3 +1,4 @@ +//! Kirikiri Multiple Image File (.pimg) use crate::ext::io::*; use crate::ext::psb::*; use crate::scripts::base::*; @@ -12,9 +13,11 @@ use std::io::{Read, Seek}; use std::path::Path; #[derive(Debug)] +/// Kirikiri PImg Script Builder pub struct PImgBuilder {} impl PImgBuilder { + /// Creates a new instance of `PImgBuilder` pub const fn new() -> Self { Self {} } @@ -94,12 +97,18 @@ impl ScriptBuilder for PImgBuilder { } #[derive(Debug)] +/// Kirikiri PImg Script pub struct PImg { psb: VirtualPsbFixed, overlay: Option, } impl PImg { + /// Create a new PImg script + /// + /// * `reader` - The reader containing the PImg script data + /// * `filename` - The name of the file + /// * `config` - Extra configuration options pub fn new(reader: R, filename: &str, config: &ExtraConfig) -> Result { let mut psb = PsbReader::open_psb(reader) .map_err(|e| anyhow::anyhow!("Failed to open PSB from {}: {:?}", filename, e))?; diff --git a/src/scripts/kirikiri/image/tlg.rs b/src/scripts/kirikiri/image/tlg.rs index 67ddf55..11dc8d8 100644 --- a/src/scripts/kirikiri/image/tlg.rs +++ b/src/scripts/kirikiri/image/tlg.rs @@ -1,3 +1,4 @@ +//! Kirikiri TLG Image File (.tlg) use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -6,9 +7,11 @@ use libtlg_rs::*; use std::io::{Read, Seek}; #[derive(Debug)] +/// Kirikiri TLG Script Builder pub struct TlgImageBuilder {} impl TlgImageBuilder { + /// Creates a new instance of `TlgImageBuilder` pub const fn new() -> Self { TlgImageBuilder {} } @@ -54,11 +57,16 @@ impl ScriptBuilder for TlgImageBuilder { } #[derive(Debug)] +/// Kirikiri TLG Script pub struct TlgImage { data: Tlg, } impl TlgImage { + /// Create a new TLG script + /// + /// * `data` - The reader containing the TLG script data + /// * `config` - Extra configuration options pub fn new(data: T, _config: &ExtraConfig) -> Result { let tlg = load_tlg(data)?; Ok(TlgImage { data: tlg }) diff --git a/src/scripts/kirikiri/ks.rs b/src/scripts/kirikiri/ks.rs index 364d7bf..1923af5 100644 --- a/src/scripts/kirikiri/ks.rs +++ b/src/scripts/kirikiri/ks.rs @@ -1,3 +1,4 @@ +//! Kirikiri Script File (.ks) use crate::ext::fancy_regex::*; use crate::scripts::base::*; use crate::types::*; @@ -11,9 +12,11 @@ use std::ops::{Deref, DerefMut, Index, IndexMut}; use std::sync::Arc; #[derive(Debug)] +/// Kirikiri Script Builder pub struct KsBuilder {} impl KsBuilder { + /// Creates a new instance of `KsBuilder` pub fn new() -> Self { Self {} } @@ -45,12 +48,15 @@ impl ScriptBuilder for KsBuilder { } } -trait Node { +/// Kirikiri Script Node Trait +pub trait Node { + /// Serializes the node to ks format fn serialize(&self) -> String; } #[derive(Clone, Debug)] -struct CommentNode(String); +/// Comment Node +pub struct CommentNode(pub String); impl Node for CommentNode { fn serialize(&self) -> String { @@ -59,9 +65,12 @@ impl Node for CommentNode { } #[derive(Clone, Debug)] -struct LabelNode { - name: String, - page: Option, +/// Label Node +pub struct LabelNode { + /// The name of the label + pub name: String, + /// The page of the label + pub page: Option, } impl Node for LabelNode { @@ -75,7 +84,8 @@ impl Node for LabelNode { } #[derive(Clone, Debug)] -struct TextNode(String); +/// Text Node +pub struct TextNode(pub String); impl Node for TextNode { fn serialize(&self) -> String { @@ -85,7 +95,8 @@ impl Node for TextNode { } #[derive(Clone, Debug)] -struct EmptyLineNode; +/// Empty Line Node +pub struct EmptyLineNode; impl Node for EmptyLineNode { fn serialize(&self) -> String { @@ -94,15 +105,21 @@ impl Node for EmptyLineNode { } #[derive(Clone, Debug)] -enum TagAttr { +/// Represents a tag attribute's value +pub enum TagAttr { + /// true if no value is specified True, + /// String value of the attribute Str(String), } #[derive(Clone, Debug)] -struct TagNode { - name: String, - attributes: Vec<(String, TagAttr)>, +/// Tag Node +pub struct TagNode { + /// The name of the tag + pub name: String, + /// The attributes of the tag + pub attributes: Vec<(String, TagAttr)>, } impl TagNode { @@ -140,6 +157,7 @@ impl TagNode { parts.join(" ") } + /// Sets an attribute for the tag, replacing it if it already exists. pub fn set_attr(&mut self, key: &str, value: String) { if let Some(attr) = self.attributes.iter_mut().find(|(k, _)| k == key) { attr.1 = TagAttr::Str(value); @@ -170,8 +188,10 @@ impl Node for TagNode { } #[derive(Clone)] -struct CommandNode { - inner: TagNode, +/// Command Node +pub struct CommandNode { + /// Same as TagNode, but used for commands + pub inner: TagNode, } impl Deref for CommandNode { @@ -209,7 +229,8 @@ impl Node for CommandNode { } #[derive(Clone, Debug)] -struct ScriptBlockNode(String); +/// Script Block Node +pub struct ScriptBlockNode(pub String); impl Node for ScriptBlockNode { fn serialize(&self) -> String { @@ -218,8 +239,11 @@ impl Node for ScriptBlockNode { } #[derive(Clone, Debug)] -enum ParsedLineNode { +/// Parsed Line Node +pub enum ParsedLineNode { + /// Text node containing plain text Text(TextNode), + /// Tag node Tag(TagNode), } @@ -252,7 +276,8 @@ impl Node for ParsedLineNode { } #[derive(Clone, Debug)] -struct ParsedLine(Vec); +/// Parsed Line +pub struct ParsedLine(pub Vec); impl ParsedLine { fn to_xml(&self) -> String { @@ -289,20 +314,29 @@ impl Node for ParsedLine { } #[derive(Clone, Debug)] -enum ParsedScriptNode { +/// Parsed Script Node +pub enum ParsedScriptNode { + /// Comment node Comment(CommentNode), + /// Label node Label(LabelNode), + /// Command node Command(CommandNode), + /// Script block node ScriptBlock(ScriptBlockNode), + /// Line Line(ParsedLine), + /// Empty line node EmptyLine(EmptyLineNode), } impl ParsedScriptNode { + /// Returns true if the node is empty line node pub fn is_empty(&self) -> bool { matches!(self, ParsedScriptNode::EmptyLine(_)) } + /// Sets an attribute for the command node, replacing it if it already exists. pub fn set_attr(&mut self, key: &str, value: String) { if let ParsedScriptNode::Command(command) = self { command.set_attr(key, value); @@ -324,7 +358,8 @@ impl Node for ParsedScriptNode { } #[derive(Clone, Debug)] -struct ParsedScript(Vec); +/// Parsed ks script +pub struct ParsedScript(pub Vec); impl Deref for ParsedScript { type Target = Vec; @@ -374,11 +409,15 @@ lazy_static::lazy_static! { static ref ATTR_RE: Regex = Regex::new("([a-zA-Z0-9_]+)(?:=(\"[^\"]*\"|'[^']*'|[^\\s\\]]+))?").unwrap(); } -struct Parser { +/// Parser for Kirikiri Script (.ks) +pub struct Parser { lines: Vec, } impl Parser { + /// Creates a new parser for the given script + /// + /// * `script` - The script to parse pub fn new(script: &str) -> Self { let lines = script.lines().map(|s| s.to_string()).collect(); Self { lines } @@ -422,7 +461,10 @@ impl Parser { }) } - fn parse(&self, preserve_empty_lines: bool) -> Result { + /// Parses the script and returns a `ParsedScript` + /// + /// * `preserve_empty_lines` - If true, empty lines will be preserved in the parsed script + pub fn parse(&self, preserve_empty_lines: bool) -> Result { let mut parsed_scripts = Vec::new(); let mut in_script_block = false; let mut script_buffer = Vec::new(); @@ -657,6 +699,7 @@ impl XMLTextParser { } #[derive(Debug)] +/// Kirikiri Script pub struct KsScript { bom: BomType, tree: ParsedScript, @@ -666,6 +709,11 @@ pub struct KsScript { } impl KsScript { + /// Creates a new `KsScript` from the given reader and encoding + /// + /// * `reader` - The reader containing the script data + /// * `encoding` - The encoding of the script + /// * `config` - Extra configuration options pub fn new(reader: Vec, encoding: Encoding, config: &ExtraConfig) -> Result { let (text, bom) = decode_with_bom_detect(encoding, &reader, true)?; let parser = Parser::new(&text); diff --git a/src/scripts/kirikiri/mdf.rs b/src/scripts/kirikiri/mdf.rs index e4ebfd1..f60c375 100644 --- a/src/scripts/kirikiri/mdf.rs +++ b/src/scripts/kirikiri/mdf.rs @@ -1,3 +1,4 @@ +//! Kirikiri Zlib-Compressed File use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -5,9 +6,11 @@ use anyhow::Result; use std::io::Read; #[derive(Debug)] +/// Kirikiri MDF Script Builder pub struct MdfBuilder {} impl MdfBuilder { + /// Creates a new instance of `MdfBuilder` pub fn new() -> Self { Self {} } @@ -48,12 +51,17 @@ impl ScriptBuilder for MdfBuilder { } #[derive(Debug)] +/// Kirikiri MDF Script pub struct Mdf { data: MemReader, ext: String, } impl Mdf { + /// Creates a new `Mdf` script from the given buffer and filename + /// + /// * `buf` - The buffer containing the MDF data + /// * `filename` - The name of the file (used for extension detection) pub fn new(buf: Vec, filename: &str) -> Result { let mut data = MemReader::new(buf); let mut header = [0u8; 4]; @@ -71,7 +79,7 @@ impl Mdf { }) } - pub fn unpack(mut data: MemReaderRef) -> Result> { + pub(crate) fn unpack(mut data: MemReaderRef) -> Result> { let size = data.read_u32()?; let mut decoder = flate2::read::ZlibDecoder::new(data); let mut result = Vec::new(); diff --git a/src/scripts/kirikiri/mod.rs b/src/scripts/kirikiri/mod.rs index ed32a2f..5f37844 100644 --- a/src/scripts/kirikiri/mod.rs +++ b/src/scripts/kirikiri/mod.rs @@ -1,3 +1,4 @@ +//! Kirikiri Scripts #[cfg(feature = "kirikiri-img")] pub mod image; pub mod ks; @@ -7,6 +8,7 @@ pub mod simple_crypt; use std::collections::HashMap; use std::sync::Arc; +/// Read a Kirikiri Comu JSON file. (For CIRCUS games) pub fn read_kirikiri_comu_json(path: &str) -> anyhow::Result>> { let mut reader = std::fs::File::open(path)?; let data = serde_json::from_reader(&mut reader)?; diff --git a/src/scripts/kirikiri/scn.rs b/src/scripts/kirikiri/scn.rs index 7041cd5..805e3f8 100644 --- a/src/scripts/kirikiri/scn.rs +++ b/src/scripts/kirikiri/scn.rs @@ -1,3 +1,4 @@ +//! Kirikiri Scene File (.scn) use super::mdf::Mdf; use crate::ext::io::*; use crate::ext::psb::*; @@ -12,9 +13,11 @@ use std::path::Path; use std::sync::Arc; #[derive(Debug)] +/// Kirikiri Scene Script Builder pub struct ScnScriptBuilder {} impl ScnScriptBuilder { + /// Creates a new instance of `ScnScriptBuilder` pub fn new() -> Self { Self {} } @@ -102,6 +105,7 @@ impl ScriptBuilder for ScnScriptBuilder { } #[derive(Debug)] +/// Kirikiri Scene Script pub struct ScnScript { psb: VirtualPsbFixed, language_index: usize, @@ -111,6 +115,11 @@ pub struct ScnScript { } impl ScnScript { + /// Creates a new `ScnScript` from the given reader and filename + /// + /// * `reader` - The reader containing the PSB or MDF data + /// * `filename` - The name of the file (used for error reporting and extension detection) + /// * `config` - Extra configuration options pub fn new( mut reader: R, filename: &str, diff --git a/src/scripts/kirikiri/simple_crypt.rs b/src/scripts/kirikiri/simple_crypt.rs index 5a7d234..44ca275 100644 --- a/src/scripts/kirikiri/simple_crypt.rs +++ b/src/scripts/kirikiri/simple_crypt.rs @@ -1,3 +1,4 @@ +//! Kirikiri Simple Crypt Text File use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -6,9 +7,11 @@ use overf::wrapping; use std::io::Read; #[derive(Debug)] +/// Kirikiri Simple Crypt Script Builder pub struct SimpleCryptBuilder {} impl SimpleCryptBuilder { + /// Creates a new instance of `SimpleCryptBuilder` pub fn new() -> Self { Self {} } @@ -55,6 +58,7 @@ impl ScriptBuilder for SimpleCryptBuilder { } #[derive(Debug)] +/// Kirikiri Simple Crypt Script pub struct SimpleCrypt { /// Crypt mode crypt: u8, @@ -63,6 +67,10 @@ pub struct SimpleCrypt { } impl SimpleCrypt { + /// Creates a new `SimpleCrypt` script from the given buffer and filename + /// + /// * `buf` - The buffer containing the SimpleCrypt data + /// * `filename` - The name of the file pub fn new(buf: Vec, filename: &str) -> Result { let mut reader = MemReader::new(buf); let mut header = [0u8; 5]; @@ -86,7 +94,7 @@ impl SimpleCrypt { }) } - pub fn unpack(crypt: u8, data: MemReaderRef) -> Result> { + pub(crate) fn unpack(crypt: u8, data: MemReaderRef) -> Result> { match crypt { 0 => Self::unpack_mode0(data), 1 => Self::unpack_mode1(data), diff --git a/src/scripts/will_plus/mod.rs b/src/scripts/will_plus/mod.rs index cb99c19..f8bc38a 100644 --- a/src/scripts/will_plus/mod.rs +++ b/src/scripts/will_plus/mod.rs @@ -1 +1,2 @@ +//! WillPlus Scripts pub mod ws2; diff --git a/src/scripts/will_plus/ws2.rs b/src/scripts/will_plus/ws2.rs index 55818c8..49b0127 100644 --- a/src/scripts/will_plus/ws2.rs +++ b/src/scripts/will_plus/ws2.rs @@ -1,3 +1,4 @@ +//! WillPlus Script File (.ws2) use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -7,9 +8,11 @@ use anyhow::Result; use std::io::{Seek, SeekFrom, Write}; #[derive(Debug)] +/// WillPlus Script Builder pub struct Ws2ScriptBuilder {} impl Ws2ScriptBuilder { + /// Creates a new instance of `Ws2ScriptBuilder` pub fn new() -> Self { Ws2ScriptBuilder {} } @@ -131,6 +134,7 @@ struct Ws2String { } #[derive(Debug)] +/// WillPlus Script (without disassembly) pub struct Ws2Script { data: MemReader, strs: Vec, @@ -139,6 +143,12 @@ pub struct Ws2Script { } impl Ws2Script { + /// Creates a new `Ws2Script` + /// + /// * `buf` - The buffer containing the script data + /// * `encoding` - The encoding used for the script + /// * `config` - Extra configuration options + /// * `decrypted` - Whether the script is decrypted or not pub fn new( buf: Vec, encoding: Encoding, diff --git a/src/scripts/yaneurao/itufuru/archive.rs b/src/scripts/yaneurao/itufuru/archive.rs index 86103ba..07544d1 100644 --- a/src/scripts/yaneurao/itufuru/archive.rs +++ b/src/scripts/yaneurao/itufuru/archive.rs @@ -1,3 +1,4 @@ +//! Yaneurao Itufuru Archive File (.scd) use super::crypto::*; use crate::ext::io::*; use crate::scripts::base::*; @@ -11,9 +12,11 @@ use std::io::{Read, Seek, SeekFrom, Write}; use std::sync::{Arc, Mutex}; #[derive(Debug)] +/// Yaneurao Itufuru Archive Builder pub struct ItufuruArchiveBuilder {} impl ItufuruArchiveBuilder { + /// Creates a new instance of `ItufuruArchiveBuilder` pub const fn new() -> Self { ItufuruArchiveBuilder {} } @@ -166,6 +169,7 @@ impl ArchiveContent for Entry { } #[derive(Debug)] +/// Yaneurao Itufuru Archive Script pub struct ItufuruArchive { reader: Arc>>, first_file_offset: u32, @@ -173,6 +177,11 @@ pub struct ItufuruArchive { } impl ItufuruArchive { + /// Creates a new `ItufuruArchive` + /// + /// * `reader` - The reader to read the archive data from + /// * `archive_encoding` - The encoding used for the archive + /// * `config` - Extra configuration options pub fn new(mut reader: T, archive_encoding: Encoding, _config: &ExtraConfig) -> Result { let mut header = [0u8; 4]; reader.read_exact(&mut header)?; @@ -269,6 +278,7 @@ impl Script for ItufuruArchive } } +/// Archive Writer for Itufuru Archive pub struct ItufuruArchiveWriter { writer: T, headers: HashMap, @@ -277,6 +287,12 @@ pub struct ItufuruArchiveWriter { } impl ItufuruArchiveWriter { + /// Creates a new `ItufuruArchiveWriter` + /// + /// * `writer` - The writer to write the archive data to + /// * `files` - List of file names to include in the archive + /// * `encoding` - The encoding used for the archive + /// * `config` - Extra configuration options pub fn new( mut writer: T, files: &[&str], @@ -341,6 +357,7 @@ impl Archive for ItufuruArchiveWriter { } } +/// File Writer for Itufuru Archive pub struct ItufuruArchiveWriterEntry<'a, T: Write + Seek> { writer: Crypto<&'a mut T>, header: &'a mut CustomHeader, diff --git a/src/scripts/yaneurao/itufuru/mod.rs b/src/scripts/yaneurao/itufuru/mod.rs index 4bc5865..53fd370 100644 --- a/src/scripts/yaneurao/itufuru/mod.rs +++ b/src/scripts/yaneurao/itufuru/mod.rs @@ -1,3 +1,4 @@ +//! Yaneurao Itufuru Scripts pub mod archive; mod crypto; pub mod script; diff --git a/src/scripts/yaneurao/itufuru/script.rs b/src/scripts/yaneurao/itufuru/script.rs index cda92dc..b8ca3de 100644 --- a/src/scripts/yaneurao/itufuru/script.rs +++ b/src/scripts/yaneurao/itufuru/script.rs @@ -1,3 +1,4 @@ +//! Yaneurao Itufuru Script File use crate::ext::io::*; use crate::scripts::base::*; use crate::types::*; @@ -5,9 +6,11 @@ use crate::utils::encoding::{decode_to_string, encode_string}; use anyhow::Result; #[derive(Debug)] +/// Yaneurao Itufuru Script Builder pub struct ItufuruScriptBuilder {} impl ItufuruScriptBuilder { + /// Creates a new instance of `ItufuruScriptBuilder` pub const fn new() -> Self { ItufuruScriptBuilder {} } @@ -47,6 +50,7 @@ struct ItufuruString { } #[derive(Debug)] +/// Yaneurao Itufuru Script pub struct ItufuruScript { data: MemReader, strings: Vec, @@ -54,6 +58,11 @@ pub struct ItufuruScript { } impl ItufuruScript { + /// Creates a new `ItufuruScript` + /// + /// * `buf` - The buffer containing the script data + /// * `encoding` - The encoding used for the script + /// * `config` - Extra configuration options pub fn new(buf: Vec, encoding: Encoding, _config: &ExtraConfig) -> Result { let mut reader = MemReader::new(buf); let mut strings = Vec::new(); diff --git a/src/scripts/yaneurao/mod.rs b/src/scripts/yaneurao/mod.rs index d5bc7ee..f167ee2 100644 --- a/src/scripts/yaneurao/mod.rs +++ b/src/scripts/yaneurao/mod.rs @@ -1,2 +1,3 @@ +//! Yaneurao Scripts #[cfg(feature = "yaneurao-itufuru")] pub mod itufuru; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 77eb5d4..166f3e9 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -12,7 +12,7 @@ pub mod escape; pub mod files; #[cfg(feature = "image")] pub mod img; -pub mod macros; +mod macros; pub mod name_replacement; #[cfg(feature = "utils-pcm")] pub mod pcm;