diff --git a/src/ext/io.rs b/src/ext/io.rs index ae99e26..698e4c7 100644 --- a/src/ext/io.rs +++ b/src/ext/io.rs @@ -2458,7 +2458,7 @@ impl Seek for PrefixStream { /// A readable stream that concatenates multiple streams. #[derive(Debug)] pub struct MultipleReadStream<'a> { - streams: Vec>, + streams: Vec>, stream_lengths: Vec, total_length: u64, pos: u64, @@ -2476,7 +2476,7 @@ impl<'a> MultipleReadStream<'a> { } /// Adds a new stream to the end of the concatenated streams. - pub fn add_stream(&mut self, mut stream: T) -> Result<()> { + pub fn add_stream(&mut self, mut stream: T) -> Result<()> { let length = stream.stream_length()?; self.streams.push(Box::new(stream)); self.stream_lengths.push(self.total_length); @@ -2485,7 +2485,7 @@ impl<'a> MultipleReadStream<'a> { } /// Adds a new boxed stream to the end of the concatenated streams. - pub fn add_stream_boxed(&mut self, mut stream: Box) -> Result<()> { + pub fn add_stream_boxed(&mut self, mut stream: Box) -> Result<()> { let length = stream.stream_length()?; self.streams.push(stream); self.stream_lengths.push(self.total_length); diff --git a/src/scripts/artemis/archive/pf2.rs b/src/scripts/artemis/archive/pf2.rs index aa78e98..b97426c 100644 --- a/src/scripts/artemis/archive/pf2.rs +++ b/src/scripts/artemis/archive/pf2.rs @@ -38,7 +38,7 @@ impl ScriptBuilder for ArtemisPf2Builder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ArtemisPf2::new( MemReader::new(buf), archive_encoding, @@ -54,7 +54,7 @@ impl ScriptBuilder for ArtemisPf2Builder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let f = std::fs::File::open(filename)?; let f = std::io::BufReader::new(f); Ok(Box::new(ArtemisPf2::new( @@ -67,13 +67,13 @@ impl ScriptBuilder for ArtemisPf2Builder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ArtemisPf2::new( reader, archive_encoding, diff --git a/src/scripts/artemis/archive/pfs.rs b/src/scripts/artemis/archive/pfs.rs index 6053307..a46b65b 100644 --- a/src/scripts/artemis/archive/pfs.rs +++ b/src/scripts/artemis/archive/pfs.rs @@ -40,7 +40,7 @@ impl ScriptBuilder for ArtemisArcBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ArtemisArc::new( MemReader::new(buf), archive_encoding, @@ -56,7 +56,7 @@ impl ScriptBuilder for ArtemisArcBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let f = std::fs::File::open(filename)?; let f = std::io::BufReader::new(f); Ok(Box::new(ArtemisArc::new( @@ -69,13 +69,13 @@ impl ScriptBuilder for ArtemisArcBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ArtemisArc::new( reader, archive_encoding, diff --git a/src/scripts/artemis/asb.rs b/src/scripts/artemis/asb.rs index 99ee28c..2339bcd 100644 --- a/src/scripts/artemis/asb.rs +++ b/src/scripts/artemis/asb.rs @@ -37,7 +37,7 @@ impl ScriptBuilder for ArtemisAsbBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Asb::new(buf, encoding, config, filename)?)) } diff --git a/src/scripts/artemis/ast/mod.rs b/src/scripts/artemis/ast/mod.rs index 326a1bd..6497059 100644 --- a/src/scripts/artemis/ast/mod.rs +++ b/src/scripts/artemis/ast/mod.rs @@ -38,7 +38,7 @@ impl ScriptBuilder for AstScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(AstScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/artemis/panmimisoft/txt.rs b/src/scripts/artemis/panmimisoft/txt.rs index 500d86a..314c489 100644 --- a/src/scripts/artemis/panmimisoft/txt.rs +++ b/src/scripts/artemis/panmimisoft/txt.rs @@ -32,7 +32,7 @@ impl ScriptBuilder for TxtBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(TxtScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/artemis/txt.rs b/src/scripts/artemis/txt.rs index 7928128..a82e0c1 100644 --- a/src/scripts/artemis/txt.rs +++ b/src/scripts/artemis/txt.rs @@ -28,7 +28,7 @@ impl ScriptBuilder for ArtemisTxtBuilder { _archive_encoding: Encoding, _config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ArtemisTxtScript::new(buf, encoding)?)) } diff --git a/src/scripts/base.rs b/src/scripts/base.rs index 9a22b60..a61dfd8 100644 --- a/src/scripts/base.rs +++ b/src/scripts/base.rs @@ -57,7 +57,7 @@ pub trait ScriptBuilder: std::fmt::Debug { archive_encoding: Encoding, config: &ExtraConfig, archive: Option<&Box>, - ) -> Result>; + ) -> Result>; /// Builds a script from a file. /// @@ -73,7 +73,7 @@ pub trait ScriptBuilder: std::fmt::Debug { archive_encoding: Encoding, config: &ExtraConfig, archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let data = crate::utils::files::read_file(filename)?; self.build_script(data, filename, encoding, archive_encoding, config, archive) } @@ -88,13 +88,13 @@ pub trait ScriptBuilder: std::fmt::Debug { /// * `archive` - An optional archive to which the script belongs. fn build_script_from_reader<'a>( &self, - mut reader: Box, + mut reader: Box, filename: &str, encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let mut data = Vec::new(); reader .read_to_end(&mut data) diff --git a/src/scripts/bgi/archive/dsc.rs b/src/scripts/bgi/archive/dsc.rs index b12c9a7..4ed9449 100644 --- a/src/scripts/bgi/archive/dsc.rs +++ b/src/scripts/bgi/archive/dsc.rs @@ -587,7 +587,7 @@ impl ScriptBuilder for DscBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Dsc::new(buf, config)?)) } diff --git a/src/scripts/bgi/archive/v1.rs b/src/scripts/bgi/archive/v1.rs index 3c32cc6..c5adb18 100644 --- a/src/scripts/bgi/archive/v1.rs +++ b/src/scripts/bgi/archive/v1.rs @@ -40,7 +40,7 @@ impl ScriptBuilder for BgiArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiArchive::new( MemReader::new(data), archive_encoding, @@ -56,7 +56,7 @@ impl ScriptBuilder for BgiArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(BgiArchive::new( @@ -79,13 +79,13 @@ impl ScriptBuilder for BgiArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiArchive::new( reader, archive_encoding, diff --git a/src/scripts/bgi/archive/v2.rs b/src/scripts/bgi/archive/v2.rs index 086bc69..2d08b76 100644 --- a/src/scripts/bgi/archive/v2.rs +++ b/src/scripts/bgi/archive/v2.rs @@ -40,7 +40,7 @@ impl ScriptBuilder for BgiArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiArchive::new( MemReader::new(data), archive_encoding, @@ -56,7 +56,7 @@ impl ScriptBuilder for BgiArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(BgiArchive::new( @@ -79,13 +79,13 @@ impl ScriptBuilder for BgiArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiArchive::new( reader, archive_encoding, diff --git a/src/scripts/bgi/audio/audio.rs b/src/scripts/bgi/audio/audio.rs index 0f0c163..bccf594 100644 --- a/src/scripts/bgi/audio/audio.rs +++ b/src/scripts/bgi/audio/audio.rs @@ -29,7 +29,7 @@ impl ScriptBuilder for BgiAudioBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiAudio::new(MemReader::new(buf), config)?)) } @@ -40,7 +40,7 @@ impl ScriptBuilder for BgiAudioBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let file = std::fs::File::open(filename)?; let f = std::io::BufReader::new(file); Ok(Box::new(BgiAudio::new(f, config)?)) @@ -48,13 +48,13 @@ impl ScriptBuilder for BgiAudioBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiAudio::new(reader, config)?)) } diff --git a/src/scripts/bgi/bp.rs b/src/scripts/bgi/bp.rs index 2906536..135913f 100644 --- a/src/scripts/bgi/bp.rs +++ b/src/scripts/bgi/bp.rs @@ -30,7 +30,7 @@ impl ScriptBuilder for BGIBpScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BGIBpScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/bgi/bsi.rs b/src/scripts/bgi/bsi.rs index af77e95..af09937 100644 --- a/src/scripts/bgi/bsi.rs +++ b/src/scripts/bgi/bsi.rs @@ -31,7 +31,7 @@ impl ScriptBuilder for BGIBsiScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BGIBsiScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/bgi/image/cbg.rs b/src/scripts/bgi/image/cbg.rs index 10b4d65..fe14808 100644 --- a/src/scripts/bgi/image/cbg.rs +++ b/src/scripts/bgi/image/cbg.rs @@ -37,7 +37,7 @@ impl ScriptBuilder for BgiCBGBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiCBG::new(data, config)?)) } diff --git a/src/scripts/bgi/image/img.rs b/src/scripts/bgi/image/img.rs index a28c3cf..54dbeef 100644 --- a/src/scripts/bgi/image/img.rs +++ b/src/scripts/bgi/image/img.rs @@ -55,7 +55,7 @@ impl ScriptBuilder for BgiImageBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiImage::new(data, config)?)) } diff --git a/src/scripts/bgi/script.rs b/src/scripts/bgi/script.rs index 2e21138..69fe11e 100644 --- a/src/scripts/bgi/script.rs +++ b/src/scripts/bgi/script.rs @@ -37,7 +37,7 @@ impl ScriptBuilder for BGIScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BGIScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/cat_system/archive/int.rs b/src/scripts/cat_system/archive/int.rs index 6ec8855..dee20af 100644 --- a/src/scripts/cat_system/archive/int.rs +++ b/src/scripts/cat_system/archive/int.rs @@ -41,7 +41,7 @@ impl ScriptBuilder for CSIntArcBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CSIntArc::new( MemReader::new(data), archive_encoding, @@ -57,7 +57,7 @@ impl ScriptBuilder for CSIntArcBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(CSIntArc::new( @@ -80,13 +80,13 @@ impl ScriptBuilder for CSIntArcBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CSIntArc::new( reader, archive_encoding, diff --git a/src/scripts/cat_system/cst.rs b/src/scripts/cat_system/cst.rs index 3e6b65b..7955999 100644 --- a/src/scripts/cat_system/cst.rs +++ b/src/scripts/cat_system/cst.rs @@ -32,7 +32,7 @@ impl ScriptBuilder for CstScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CstScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/cat_system/cstl.rs b/src/scripts/cat_system/cstl.rs index e407ba3..d31aa81 100644 --- a/src/scripts/cat_system/cstl.rs +++ b/src/scripts/cat_system/cstl.rs @@ -31,7 +31,7 @@ impl ScriptBuilder for CstlScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CstlScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/cat_system/image/hg3.rs b/src/scripts/cat_system/image/hg3.rs index a36ddce..6c07f86 100644 --- a/src/scripts/cat_system/image/hg3.rs +++ b/src/scripts/cat_system/image/hg3.rs @@ -36,7 +36,7 @@ impl ScriptBuilder for Hg3ImageBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Hg3Image::new(data, config)?)) } diff --git a/src/scripts/circus/archive/crm.rs b/src/scripts/circus/archive/crm.rs index 38c1d2a..5693afd 100644 --- a/src/scripts/circus/archive/crm.rs +++ b/src/scripts/circus/archive/crm.rs @@ -35,7 +35,7 @@ impl ScriptBuilder for CrmArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CrmArchive::new( MemReader::new(data), archive_encoding, @@ -50,7 +50,7 @@ impl ScriptBuilder for CrmArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(CrmArchive::new( @@ -67,13 +67,13 @@ impl ScriptBuilder for CrmArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CrmArchive::new(reader, archive_encoding, config)?)) } diff --git a/src/scripts/circus/archive/dat.rs b/src/scripts/circus/archive/dat.rs index e97ae30..178df44 100644 --- a/src/scripts/circus/archive/dat.rs +++ b/src/scripts/circus/archive/dat.rs @@ -34,7 +34,7 @@ impl ScriptBuilder for DatArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(DatArchive::new( MemReader::new(data), archive_encoding, @@ -49,7 +49,7 @@ impl ScriptBuilder for DatArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(DatArchive::new( @@ -66,13 +66,13 @@ impl ScriptBuilder for DatArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(DatArchive::new(reader, archive_encoding, config)?)) } diff --git a/src/scripts/circus/archive/pck.rs b/src/scripts/circus/archive/pck.rs index 274dd5a..623eb4a 100644 --- a/src/scripts/circus/archive/pck.rs +++ b/src/scripts/circus/archive/pck.rs @@ -38,7 +38,7 @@ impl ScriptBuilder for PckArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PckArchive::new( MemReader::new(data), archive_encoding, @@ -53,7 +53,7 @@ impl ScriptBuilder for PckArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(PckArchive::new( @@ -70,13 +70,13 @@ impl ScriptBuilder for PckArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PckArchive::new(reader, archive_encoding, config)?)) } diff --git a/src/scripts/circus/audio/pcm.rs b/src/scripts/circus/audio/pcm.rs index f87c626..45eeeaf 100644 --- a/src/scripts/circus/audio/pcm.rs +++ b/src/scripts/circus/audio/pcm.rs @@ -35,7 +35,7 @@ impl ScriptBuilder for PcmBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Pcm::new(MemReader::new(buf), config)?)) } @@ -46,7 +46,7 @@ impl ScriptBuilder for PcmBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let file = std::fs::File::open(filename)?; let f = std::io::BufReader::new(file); Ok(Box::new(Pcm::new(f, config)?)) @@ -54,13 +54,13 @@ impl ScriptBuilder for PcmBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Pcm::new(reader, config)?)) } diff --git a/src/scripts/circus/image/crx.rs b/src/scripts/circus/image/crx.rs index fe2a1d5..d34ff90 100644 --- a/src/scripts/circus/image/crx.rs +++ b/src/scripts/circus/image/crx.rs @@ -114,7 +114,7 @@ impl ScriptBuilder for CrxImageBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CrxImage::new(MemReader::new(data), config)?)) } diff --git a/src/scripts/circus/image/crxd.rs b/src/scripts/circus/image/crxd.rs index 055d846..a55f1af 100644 --- a/src/scripts/circus/image/crxd.rs +++ b/src/scripts/circus/image/crxd.rs @@ -30,7 +30,7 @@ impl ScriptBuilder for CrxdImageBuilder { _archive_encoding: Encoding, config: &ExtraConfig, archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CrxdImage::new( MemReader::new(data), filename, diff --git a/src/scripts/circus/script.rs b/src/scripts/circus/script.rs index 7cdd617..63bd6b9 100644 --- a/src/scripts/circus/script.rs +++ b/src/scripts/circus/script.rs @@ -31,7 +31,7 @@ impl ScriptBuilder for CircusMesScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CircusMesScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/emote/dref.rs b/src/scripts/emote/dref.rs index 29f12e7..0caefbf 100644 --- a/src/scripts/emote/dref.rs +++ b/src/scripts/emote/dref.rs @@ -37,7 +37,7 @@ impl ScriptBuilder for DrefBuilder { _archive_encoding: Encoding, config: &ExtraConfig, archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Dref::new( buf, encoding, filename, config, archive, )?)) diff --git a/src/scripts/emote/pimg.rs b/src/scripts/emote/pimg.rs index 77eeebc..cbe5e83 100644 --- a/src/scripts/emote/pimg.rs +++ b/src/scripts/emote/pimg.rs @@ -38,7 +38,7 @@ impl ScriptBuilder for PImgBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PImg::new(MemReader::new(buf), filename, config)?)) } @@ -49,7 +49,7 @@ impl ScriptBuilder for PImgBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(PImg::new(MemReader::new(data), filename, config)?)) @@ -62,13 +62,13 @@ impl ScriptBuilder for PImgBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PImg::new(reader, filename, config)?)) } diff --git a/src/scripts/emote/psb.rs b/src/scripts/emote/psb.rs index 38f2055..f5c195f 100644 --- a/src/scripts/emote/psb.rs +++ b/src/scripts/emote/psb.rs @@ -39,19 +39,19 @@ impl ScriptBuilder for PsbBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Psb::new(MemReader::new(buf), encoding, config)?)) } fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Psb::new(reader, encoding, config)?)) } @@ -62,7 +62,7 @@ impl ScriptBuilder for PsbBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let file = std::fs::File::open(filename)?; let f = std::io::BufReader::new(file); Ok(Box::new(Psb::new(f, encoding, config)?)) diff --git a/src/scripts/entis_gls/csx/mod.rs b/src/scripts/entis_gls/csx/mod.rs index 5694a4e..4efadfb 100644 --- a/src/scripts/entis_gls/csx/mod.rs +++ b/src/scripts/entis_gls/csx/mod.rs @@ -56,7 +56,7 @@ impl ScriptBuilder for CSXScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CSXScript::new(buf, config)?)) } @@ -79,7 +79,7 @@ impl ScriptBuilder for CSXScriptBuilder { #[derive(Debug)] pub struct CSXScript { - img: Box, + img: Box, disasm: bool, custom_yaml: bool, } @@ -91,18 +91,18 @@ impl CSXScript { match ver { CSXScriptVersion::V1 => { Box::new(ECSExecutionImageV1::new(reader.to_ref(), config)?) - as Box + as Box } CSXScriptVersion::V2 => { Box::new(ECSExecutionImageV2::new(reader.to_ref(), config)?) - as Box + as Box } } } else { match ECSExecutionImageV1::new(reader.to_ref(), config) { Ok(img) => Box::new(img), Err(_) => Box::new(ECSExecutionImageV2::new(reader.to_ref(), config)?) - as Box, + as Box, } }; Ok(Self { diff --git a/src/scripts/entis_gls/srcxml.rs b/src/scripts/entis_gls/srcxml.rs index cf9bf03..f14fd2b 100644 --- a/src/scripts/entis_gls/srcxml.rs +++ b/src/scripts/entis_gls/srcxml.rs @@ -34,7 +34,7 @@ impl ScriptBuilder for SrcXmlScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(SrcXmlScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/escude/archive.rs b/src/scripts/escude/archive.rs index 8417624..bcaa8e6 100644 --- a/src/scripts/escude/archive.rs +++ b/src/scripts/escude/archive.rs @@ -38,7 +38,7 @@ impl ScriptBuilder for EscudeBinArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(EscudeBinArchive::new( MemReader::new(data), archive_encoding, @@ -53,7 +53,7 @@ impl ScriptBuilder for EscudeBinArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(EscudeBinArchive::new( @@ -74,13 +74,13 @@ impl ScriptBuilder for EscudeBinArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(EscudeBinArchive::new( reader, archive_encoding, diff --git a/src/scripts/escude/list.rs b/src/scripts/escude/list.rs index d5f6a43..04d00fe 100644 --- a/src/scripts/escude/list.rs +++ b/src/scripts/escude/list.rs @@ -33,7 +33,7 @@ impl ScriptBuilder for EscudeBinListBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(EscudeBinList::new( data, filename, encoding, config, )?)) diff --git a/src/scripts/escude/script.rs b/src/scripts/escude/script.rs index b819e00..feb6091 100644 --- a/src/scripts/escude/script.rs +++ b/src/scripts/escude/script.rs @@ -47,7 +47,7 @@ impl ScriptBuilder for EscudeBinScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(EscudeBinScript::new(data, encoding, config)?)) } diff --git a/src/scripts/ex_hibit/arc/grp.rs b/src/scripts/ex_hibit/arc/grp.rs index 2c29ab8..3c34e86 100644 --- a/src/scripts/ex_hibit/arc/grp.rs +++ b/src/scripts/ex_hibit/arc/grp.rs @@ -36,7 +36,7 @@ impl ScriptBuilder for ExHibitGrpArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ExHibitGrpArchive::new( MemReader::new(data), filename, @@ -52,7 +52,7 @@ impl ScriptBuilder for ExHibitGrpArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { return Err(anyhow::anyhow!( "Reading ExHibit GRP from stdin is not supported; provide a file path." @@ -71,13 +71,13 @@ impl ScriptBuilder for ExHibitGrpArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ExHibitGrpArchive::new( reader, filename, diff --git a/src/scripts/ex_hibit/rld.rs b/src/scripts/ex_hibit/rld.rs index d6a2efe..6fd589f 100644 --- a/src/scripts/ex_hibit/rld.rs +++ b/src/scripts/ex_hibit/rld.rs @@ -35,7 +35,7 @@ impl ScriptBuilder for RldScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(RldScript::new(buf, filename, encoding, config)?)) } diff --git a/src/scripts/favorite/hcb.rs b/src/scripts/favorite/hcb.rs index 2310028..deefb17 100644 --- a/src/scripts/favorite/hcb.rs +++ b/src/scripts/favorite/hcb.rs @@ -32,7 +32,7 @@ impl ScriptBuilder for HcbScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(HcbScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/hexen_haus/archive/arcc.rs b/src/scripts/hexen_haus/archive/arcc.rs index e4196a5..446e34e 100644 --- a/src/scripts/hexen_haus/archive/arcc.rs +++ b/src/scripts/hexen_haus/archive/arcc.rs @@ -35,7 +35,7 @@ impl ScriptBuilder for HexenHausArccArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(HexenHausArccArchive::new( MemReader::new(buf), archive_encoding, @@ -50,7 +50,7 @@ impl ScriptBuilder for HexenHausArccArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; return Ok(Box::new(HexenHausArccArchive::new( @@ -70,13 +70,13 @@ impl ScriptBuilder for HexenHausArccArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(HexenHausArccArchive::new( reader, archive_encoding, diff --git a/src/scripts/hexen_haus/archive/odio.rs b/src/scripts/hexen_haus/archive/odio.rs index 6944b29..93be839 100644 --- a/src/scripts/hexen_haus/archive/odio.rs +++ b/src/scripts/hexen_haus/archive/odio.rs @@ -41,7 +41,7 @@ impl ScriptBuilder for HexenHausOdioArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(HexenHausOdioArchive::new( MemReader::new(buf), archive_encoding, @@ -56,7 +56,7 @@ impl ScriptBuilder for HexenHausOdioArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; return Ok(Box::new(HexenHausOdioArchive::new( @@ -76,13 +76,13 @@ impl ScriptBuilder for HexenHausOdioArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(HexenHausOdioArchive::new( reader, archive_encoding, diff --git a/src/scripts/hexen_haus/archive/wag.rs b/src/scripts/hexen_haus/archive/wag.rs index bc9ddfc..40c3e25 100644 --- a/src/scripts/hexen_haus/archive/wag.rs +++ b/src/scripts/hexen_haus/archive/wag.rs @@ -42,7 +42,7 @@ impl ScriptBuilder for HexenHausWagArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(HexenHausWagArchive::new( MemReader::new(buf), archive_encoding, @@ -57,7 +57,7 @@ impl ScriptBuilder for HexenHausWagArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; return Ok(Box::new(HexenHausWagArchive::new( @@ -77,13 +77,13 @@ impl ScriptBuilder for HexenHausWagArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(HexenHausWagArchive::new( reader, archive_encoding, diff --git a/src/scripts/hexen_haus/bin.rs b/src/scripts/hexen_haus/bin.rs index 49992e7..a990311 100644 --- a/src/scripts/hexen_haus/bin.rs +++ b/src/scripts/hexen_haus/bin.rs @@ -31,7 +31,7 @@ impl ScriptBuilder for BinScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BinScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/hexen_haus/img/png.rs b/src/scripts/hexen_haus/img/png.rs index ae4ef9a..81c88de 100644 --- a/src/scripts/hexen_haus/img/png.rs +++ b/src/scripts/hexen_haus/img/png.rs @@ -30,7 +30,7 @@ impl ScriptBuilder for PngImageBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PngImage::new(MemReader::new(data), config)?)) } diff --git a/src/scripts/kirikiri/archive/xp3/archive.rs b/src/scripts/kirikiri/archive/xp3/archive.rs index 57d757d..520ca82 100644 --- a/src/scripts/kirikiri/archive/xp3/archive.rs +++ b/src/scripts/kirikiri/archive/xp3/archive.rs @@ -115,8 +115,8 @@ impl ExtraProp { #[derive(Debug)] #[allow(dead_code)] pub struct Xp3Archive<'a> { - pub inner: Arc>>, - pub crypt: Arc>, + pub inner: Arc>>, + pub crypt: Arc>, /// The offset which the archive file start. If the archive is embedded in another file (such as exe), this is the offset of the archive data within the larger file. pub base_offset: u64, /// The offset which index start. Releatived to whole file not just xp3 archive. diff --git a/src/scripts/kirikiri/archive/xp3/crypt/cx.rs b/src/scripts/kirikiri/archive/xp3/crypt/cx.rs index 62949cd..f62ef23 100644 --- a/src/scripts/kirikiri/archive/xp3/crypt/cx.rs +++ b/src/scripts/kirikiri/archive/xp3/crypt/cx.rs @@ -27,8 +27,8 @@ pub struct CxEncryption { odd_branch_order: Vec, even_branch_order: Vec, control_block: Arc>, - programs: Vec>, - program_builder: Box, + programs: Vec>, + program_builder: Box, base: BaseSchema, } @@ -79,7 +79,7 @@ impl CxEncryption { base: BaseSchema, schema: &CxSchema, filename: &str, - program_builder: Box, + program_builder: Box, ) -> Result { if schema.prolog_order.len() != 3 { return Err(anyhow::anyhow!("Prolog order must have 3 elements")); @@ -126,12 +126,12 @@ impl CxEncryption { Ok(obj) } - fn new_program(&self, seed: u32) -> Box { + fn new_program(&self, seed: u32) -> Box { self.program_builder .build(seed, Arc::downgrade(&self.control_block)) } - fn generate_program(&self, seed: u32) -> Result> { + fn generate_program(&self, seed: u32) -> Result> { let mut program = self.new_program(seed); for stage in (1..=5).rev() { if self.emit_code(&mut program, stage) { @@ -180,7 +180,7 @@ impl CxEncryption { Err(anyhow::anyhow!("TPM file not found: {}", tpm_path)) } - fn emit_code(&self, program: &mut Box, stage: i32) -> bool { + fn emit_code(&self, program: &mut Box, stage: i32) -> bool { program.emit_nop(5) && program.emit(MovEdiArg, 4) && self.emit_body(program, stage) @@ -188,7 +188,7 @@ impl CxEncryption { && program.emit(Retn, 1) } - fn emit_body(&self, program: &mut Box, stage: i32) -> bool { + fn emit_body(&self, program: &mut Box, stage: i32) -> bool { if stage == 1 { return self.emit_prolog(program); } @@ -219,7 +219,7 @@ impl CxEncryption { self.emit_odd_branch(program) && program.emit(PopEbx, 1) } - fn emit_body2(&self, program: &mut Box, stage: i32) -> bool { + fn emit_body2(&self, program: &mut Box, stage: i32) -> bool { if stage == 1 { return self.emit_prolog(program); } @@ -230,7 +230,7 @@ impl CxEncryption { }; r && self.emit_even_branch(program) } - fn emit_prolog(&self, program: &mut Box) -> bool { + fn emit_prolog(&self, program: &mut Box) -> bool { match self.prolog_order[(program.get_random() % 3) as usize] { 2 => { program.emit_nop(5) @@ -247,7 +247,7 @@ impl CxEncryption { } } - fn emit_even_branch(&self, program: &mut Box) -> bool { + fn emit_even_branch(&self, program: &mut Box) -> bool { match self.even_branch_order[(program.get_random() & 7) as usize] { 0 => program.emit(NotEax, 2), 1 => program.emit(DecEax, 1), @@ -285,7 +285,7 @@ impl CxEncryption { } } - fn emit_odd_branch(&self, program: &mut Box) -> bool { + fn emit_odd_branch(&self, program: &mut Box) -> bool { match self.odd_branch_order[(program.get_random() % 6) as usize] { 0 => { program.emit(PushEcx, 1) @@ -435,11 +435,11 @@ impl Crypt for Arc { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = ( entry.file_hash, - Box::new(self.clone()) as Box, + Box::new(self.clone()) as Box, ); Ok(Box::new(CxEncryptionReader::new(stream, cur_seg, key))) } @@ -447,11 +447,11 @@ impl Crypt for Arc { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = ( entry.file_hash, - Box::new(self.clone()) as Box, + Box::new(self.clone()) as Box, ); Ok(Box::new(CxEncryptionReader::new(stream, cur_seg, key))) } @@ -526,11 +526,16 @@ impl Default for CxProgramBuilder { } trait ICxProgramBuilder: std::fmt::Debug { - fn build(&self, seed: u32, control_blocks: Weak>) -> Box; + fn build(&self, seed: u32, control_blocks: Weak>) + -> Box; } impl ICxProgramBuilder for CxProgramBuilder { - fn build(&self, seed: u32, control_blocks: Weak>) -> Box { + fn build( + &self, + seed: u32, + control_blocks: Weak>, + ) -> Box { Box::new(CxProgram { code: Vec::with_capacity(CX_PROGRAM_SIZE), control_block: control_blocks, @@ -739,11 +744,15 @@ struct CxEncryptionReader<'a, T> { seg_start: u64, seg_size: u64, pos: u64, - key: (u32, Box), + key: (u32, Box), } impl<'a, T: Read> CxEncryptionReader<'a, T> { - pub fn new(inner: T, seg: &Segment, key: (u32, Box)) -> Self { + pub fn new( + inner: T, + seg: &Segment, + key: (u32, Box), + ) -> Self { Self { inner, seg_start: seg.offset_in_file, @@ -818,7 +827,7 @@ impl SenrenCxCrypt { base: BaseSchema, schema: &CxSchema, filename: &str, - program_builder: Box, + program_builder: Box, names_section_id: String, ) -> Result { let cx = CxEncryption::new_inner(base, schema, filename, program_builder)?; @@ -920,11 +929,11 @@ impl Crypt for Arc { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = ( entry.file_hash, - Box::new(self.clone()) as Box, + Box::new(self.clone()) as Box, ); Ok(Box::new(CxEncryptionReader::new(stream, cur_seg, key))) } @@ -932,11 +941,11 @@ impl Crypt for Arc { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = ( entry.file_hash, - Box::new(self.clone()) as Box, + Box::new(self.clone()) as Box, ); Ok(Box::new(CxEncryptionReader::new(stream, cur_seg, key))) } @@ -1001,7 +1010,11 @@ impl CxProgramNanaBuilder { } impl ICxProgramBuilder for CxProgramNanaBuilder { - fn build(&self, seed: u32, control_blocks: Weak>) -> Box { + fn build( + &self, + seed: u32, + control_blocks: Weak>, + ) -> Box { Box::new(CxProgramNana::new(seed, control_blocks, self.random_seed)) } } @@ -1060,11 +1073,11 @@ impl Crypt for Arc { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = ( entry.file_hash, - Box::new(self.clone()) as Box, + Box::new(self.clone()) as Box, ); Ok(Box::new(CxEncryptionReader::new(stream, cur_seg, key))) } @@ -1072,11 +1085,11 @@ impl Crypt for Arc { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = ( entry.file_hash, - Box::new(self.clone()) as Box, + Box::new(self.clone()) as Box, ); Ok(Box::new(CxEncryptionReader::new(stream, cur_seg, key))) } @@ -1219,11 +1232,11 @@ impl Crypt for Arc { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = ( entry.file_hash, - Box::new(self.clone()) as Box, + Box::new(self.clone()) as Box, ); Ok(Box::new(CxEncryptionReader::new(stream, cur_seg, key))) } @@ -1231,11 +1244,11 @@ impl Crypt for Arc { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = ( entry.file_hash, - Box::new(self.clone()) as Box, + Box::new(self.clone()) as Box, ); Ok(Box::new(CxEncryptionReader::new(stream, cur_seg, key))) } @@ -1497,11 +1510,11 @@ impl Crypt for Arc { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = ( entry.file_hash, - Box::new(self.clone()) as Box, + Box::new(self.clone()) as Box, ); Ok(Box::new(CxEncryptionReader::new(stream, cur_seg, key))) } @@ -1509,11 +1522,11 @@ impl Crypt for Arc { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = ( entry.file_hash, - Box::new(self.clone()) as Box, + Box::new(self.clone()) as Box, ); Ok(Box::new(CxEncryptionReader::new(stream, cur_seg, key))) } diff --git a/src/scripts/kirikiri/archive/xp3/crypt/cz.rs b/src/scripts/kirikiri/archive/xp3/crypt/cz.rs index b5f97f3..1a0d125 100644 --- a/src/scripts/kirikiri/archive/xp3/crypt/cz.rs +++ b/src/scripts/kirikiri/archive/xp3/crypt/cz.rs @@ -105,7 +105,7 @@ impl Crypt for KissCrypt { fn need_filter(&self, _filename: &str, buf: &[u8], buf_len: usize) -> bool { buf_len >= 4 && buf.starts_with(CZ_MAGIC) } - fn filter<'a>(&self, mut entry: Entry<'a>) -> Result> { + fn filter<'a>(&self, mut entry: Entry<'a>) -> Result> { let mut header = [0u8; 15]; entry.read_exact(&mut header)?; let typ = [header[4] ^ 0x11, header[5] ^ 0x7F, header[6] ^ 0x9A]; @@ -140,8 +140,8 @@ impl Crypt for KissCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = entry.file_hash ^ (entry.file_hash >> 19) ^ 0x4A9EEFF0; Ok(Box::new(KissCryptReader::new(stream, cur_seg, key))) } @@ -149,8 +149,8 @@ impl Crypt for KissCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = entry.file_hash ^ (entry.file_hash >> 19) ^ 0x4A9EEFF0; Ok(Box::new(KissCryptReader::new(stream, cur_seg, key))) } diff --git a/src/scripts/kirikiri/archive/xp3/crypt/mod.rs b/src/scripts/kirikiri/archive/xp3/crypt/mod.rs index 2595ae9..005609e 100644 --- a/src/scripts/kirikiri/archive/xp3/crypt/mod.rs +++ b/src/scripts/kirikiri/archive/xp3/crypt/mod.rs @@ -81,8 +81,8 @@ pub trait Crypt: std::fmt::Debug { &self, _entry: &Xp3Entry, _cur_seg: &Segment, - _stream: Box, - ) -> Result> { + _stream: Box, + ) -> Result> { Err(anyhow::anyhow!("This crypt does not support decrypt")) } @@ -91,8 +91,8 @@ pub trait Crypt: std::fmt::Debug { &self, _entry: &Xp3Entry, _cur_seg: &Segment, - _stream: Box, - ) -> Result> { + _stream: Box, + ) -> Result> { Err(anyhow::anyhow!( "This crypt does not support decrypt with seek" )) @@ -119,14 +119,17 @@ pub trait Crypt: std::fmt::Debug { } /// Apply extra processing to the decrypted content of the file. - fn filter<'a>(&self, _entry: Entry<'a>) -> Result> { + fn filter<'a>(&self, _entry: Entry<'a>) -> Result> { Err(anyhow::anyhow!( "This crypt does not support content filter after decrypt" )) } /// Apply extra processing to the decrypted content of the file, with seek support. - fn filter_with_seek<'a>(&self, _entry: Entry<'a>) -> Result> { + fn filter_with_seek<'a>( + &self, + _entry: Entry<'a>, + ) -> Result> { Err(anyhow::anyhow!( "This crypt does not support content filter with seek after decrypt" )) @@ -265,7 +268,11 @@ pub struct Schema { } impl Schema { - pub fn create_crypt(&self, filename: &str, config: &ExtraConfig) -> Result> { + pub fn create_crypt( + &self, + filename: &str, + config: &ExtraConfig, + ) -> Result> { Ok(match &self.crypt { CryptType::NoCrypt => Box::new(NoCrypt::new()), CryptType::FateCrypt => Box::new(FateCrypt::new(self.base.clone())), @@ -593,16 +600,16 @@ macro_rules! seek_crypt_base_impl { &self, _entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new($reader::new(stream, cur_seg))) } fn decrypt_with_seek<'a>( &self, _entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new($reader::new(stream, cur_seg))) } } @@ -683,8 +690,8 @@ macro_rules! seek_crypt_filehash_key_u8_base_impl { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new($reader::new( stream, cur_seg, @@ -695,8 +702,8 @@ macro_rules! seek_crypt_filehash_key_u8_base_impl { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new($reader::new( stream, cur_seg, @@ -751,16 +758,16 @@ macro_rules! seek_crypt_key_base_impl { &self, _entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new($reader::new(stream, cur_seg, self.key))) } fn decrypt_with_seek<'a>( &self, _entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new($reader::new(stream, cur_seg, self.key))) } } @@ -822,8 +829,8 @@ impl Crypt for FlyingShineCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new(FlyingShineCryptReader::new( stream, cur_seg, @@ -834,8 +841,8 @@ impl Crypt for FlyingShineCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new(FlyingShineCryptReader::new( stream, cur_seg, @@ -882,16 +889,16 @@ macro_rules! seek_crypt_filehash_key_base_impl { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new($reader::new(stream, cur_seg, entry.file_hash))) } fn decrypt_with_seek<'a>( &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new($reader::new(stream, cur_seg, entry.file_hash))) } } @@ -1137,8 +1144,8 @@ impl Crypt for TokidokiCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new(TokidokiCryptReader::new( stream, cur_seg, @@ -1149,8 +1156,8 @@ impl Crypt for TokidokiCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new(TokidokiCryptReader::new( stream, cur_seg, @@ -1246,8 +1253,8 @@ impl Crypt for AkabeiCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new(AkabeiCryptReader::new( stream, cur_seg, @@ -1258,8 +1265,8 @@ impl Crypt for AkabeiCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new(AkabeiCryptReader::new( stream, cur_seg, @@ -1356,8 +1363,8 @@ impl Crypt for SmileCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = entry.file_hash ^ self.key_xor; Ok(Box::new(SmileCryptReader::new( stream, @@ -1369,8 +1376,8 @@ impl Crypt for SmileCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let key = entry.file_hash ^ self.key_xor; Ok(Box::new(SmileCryptReader::new( stream, @@ -1499,8 +1506,8 @@ impl Crypt for PuCaCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { if let Some(pos) = self.hash_table.iter().position(|&h| h == entry.file_hash) { Ok(Box::new(PuCaCryptReader::new( stream, @@ -1519,8 +1526,8 @@ impl Crypt for PuCaCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { if let Some(pos) = self.hash_table.iter().position(|&h| h == entry.file_hash) { Ok(Box::new(PuCaCryptReader::new( stream, @@ -1657,8 +1664,8 @@ impl Crypt for RhapsodyCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new(RhapsodyCryptReader::new( stream, cur_seg, @@ -1669,8 +1676,8 @@ impl Crypt for RhapsodyCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new(RhapsodyCryptReader::new( stream, cur_seg, @@ -1725,8 +1732,8 @@ impl Crypt for MadoCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new(MadoCryptReader::new( stream, cur_seg, @@ -1737,8 +1744,8 @@ impl Crypt for MadoCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { Ok(Box::new(MadoCryptReader::new( stream, cur_seg, @@ -1811,8 +1818,8 @@ impl Crypt for SmxCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let start_key = (entry.file_hash >> self.key_seq[0]) as u8; Ok(Box::new(SmxCryptReader::new( stream, @@ -1824,8 +1831,8 @@ impl Crypt for SmxCrypt { &self, entry: &Xp3Entry, cur_seg: &Segment, - stream: Box, - ) -> Result> { + stream: Box, + ) -> Result> { let start_key = (entry.file_hash >> self.key_seq[0]) as u8; Ok(Box::new(SmxCryptReader::new( stream, diff --git a/src/scripts/kirikiri/archive/xp3/mod.rs b/src/scripts/kirikiri/archive/xp3/mod.rs index a654c44..9f10333 100644 --- a/src/scripts/kirikiri/archive/xp3/mod.rs +++ b/src/scripts/kirikiri/archive/xp3/mod.rs @@ -101,7 +101,7 @@ impl ScriptBuilder for Xp3ArchiveBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Xp3Archive::new( MemReader::new(buf), config, @@ -116,20 +116,20 @@ impl ScriptBuilder for Xp3ArchiveBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let file = std::fs::File::open(filename)?; Ok(Box::new(Xp3Archive::new(file, config, filename)?)) } fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Xp3Archive::new(reader, config, filename)?)) } @@ -174,7 +174,7 @@ pub struct Xp3Archive<'a> { } impl<'a> Xp3Archive<'a> { - pub fn new( + pub fn new( stream: T, config: &ExtraConfig, filename: &str, @@ -341,13 +341,13 @@ fn detect_script_type(filename: &str, buf: &[u8], buf_len: usize) -> Option { - reader: Arc>>, + reader: Arc>>, index: archive::Xp3Entry, - crypt: Arc>, + crypt: Arc>, /// used to cache segment reader that can't seek. Such as decompressor reader or some decrypter reader. - cache: Option>, + cache: Option>, /// used to store decrypted stream of current segment when the cryptor support seek when decrypting. - crypt_stream: Option>, + crypt_stream: Option>, pos: u64, base_offset: u64, entries_pos: Vec, @@ -376,10 +376,10 @@ impl<'a> std::fmt::Debug for Entry<'a> { impl<'a> Entry<'a> { fn new( - reader: Arc>>, + reader: Arc>>, index: archive::Xp3Entry, base_offset: u64, - crypt: Arc>, + crypt: Arc>, skip_decrypt: bool, force_decrypt: bool, ) -> Self { @@ -465,13 +465,13 @@ impl<'a> Read for Entry<'a> { && (self.index.is_encrypted() || (self.force_decrypt && self.crypt.decrypt_supported())) { if seg.is_compressed || !self.crypt.decrypt_seek_supported() { - let mut cache: Box = if seg.is_compressed { + let mut cache: Box = if seg.is_compressed { let mut inner = MutexWrapper::new(self.reader.clone(), start_pos).take(read_size); let decompressed = if inner.peek_and_equal(ZSTD_SIGNATURE).is_ok() { - Box::new(ZstdDecoder::new(inner)?) as Box + Box::new(ZstdDecoder::new(inner)?) as Box } else { - Box::new(ZlibDecoder::new(inner)) as Box + Box::new(ZlibDecoder::new(inner)) as Box }; let decrypted = self.crypt @@ -482,7 +482,7 @@ impl<'a> Read for Entry<'a> { format!("Decryption failed: {}", e), ) })?; - Box::new(decrypted) as Box + Box::new(decrypted) as Box } else { let inner = MutexWrapper::new(self.reader.clone(), start_pos).take(read_size); let decrypted = self @@ -494,7 +494,7 @@ impl<'a> Read for Entry<'a> { format!("Decryption failed: {}", e), ) })?; - Box::new(decrypted) as Box + Box::new(decrypted) as Box }; if skip_pos != 0 { let mut e = EmptyWriter::new(); @@ -528,9 +528,9 @@ impl<'a> Read for Entry<'a> { if seg.is_compressed { let mut inner = MutexWrapper::new(self.reader.clone(), start_pos).take(read_size); let mut cache = if inner.peek_and_equal(ZSTD_SIGNATURE).is_ok() { - Box::new(ZstdDecoder::new(inner)?) as Box + Box::new(ZstdDecoder::new(inner)?) as Box } else { - Box::new(ZlibDecoder::new(inner)) as Box + Box::new(ZlibDecoder::new(inner)) as Box }; if skip_pos != 0 { let mut e = EmptyWriter::new(); diff --git a/src/scripts/kirikiri/archive/xp3/read.rs b/src/scripts/kirikiri/archive/xp3/read.rs index bfa8239..5a29921 100644 --- a/src/scripts/kirikiri/archive/xp3/read.rs +++ b/src/scripts/kirikiri/archive/xp3/read.rs @@ -8,12 +8,12 @@ use std::io::{Read, Seek, SeekFrom}; use std::sync::{Arc, Mutex}; impl<'a> Xp3Archive<'a> { - pub fn new( + pub fn new( stream: T, config: &ExtraConfig, filename: &str, ) -> Result { - let crypt: Box = if let Some(game_title) = &config.xp3_game_title { + let crypt: Box = if let Some(game_title) = &config.xp3_game_title { query_crypt_schema(game_title) .ok_or_else(|| { anyhow::anyhow!("Unsupported game title for XP3 archive: {}", game_title) diff --git a/src/scripts/kirikiri/image/tlg.rs b/src/scripts/kirikiri/image/tlg.rs index c6b1666..c5e9062 100644 --- a/src/scripts/kirikiri/image/tlg.rs +++ b/src/scripts/kirikiri/image/tlg.rs @@ -31,7 +31,7 @@ impl ScriptBuilder for TlgImageBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(TlgImage::new(MemReader::new(data), config)?)) } diff --git a/src/scripts/kirikiri/ks.rs b/src/scripts/kirikiri/ks.rs index 2bbba8b..b0e268f 100644 --- a/src/scripts/kirikiri/ks.rs +++ b/src/scripts/kirikiri/ks.rs @@ -36,7 +36,7 @@ impl ScriptBuilder for KsBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(KsScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/kirikiri/mdf.rs b/src/scripts/kirikiri/mdf.rs index f60c375..32ef8cc 100644 --- a/src/scripts/kirikiri/mdf.rs +++ b/src/scripts/kirikiri/mdf.rs @@ -29,7 +29,7 @@ impl ScriptBuilder for MdfBuilder { _archive_encoding: Encoding, _config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Mdf::new(buf, filename)?)) } diff --git a/src/scripts/kirikiri/scn.rs b/src/scripts/kirikiri/scn.rs index 8cef46d..c69e07b 100644 --- a/src/scripts/kirikiri/scn.rs +++ b/src/scripts/kirikiri/scn.rs @@ -38,7 +38,7 @@ impl ScriptBuilder for ScnScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ScnScript::new( MemReader::new(buf), filename, @@ -53,7 +53,7 @@ impl ScriptBuilder for ScnScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(ScnScript::new( @@ -70,13 +70,13 @@ impl ScriptBuilder for ScnScriptBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ScnScript::new(reader, filename, config)?)) } diff --git a/src/scripts/kirikiri/simple_crypt.rs b/src/scripts/kirikiri/simple_crypt.rs index 44ca275..a018c3a 100644 --- a/src/scripts/kirikiri/simple_crypt.rs +++ b/src/scripts/kirikiri/simple_crypt.rs @@ -30,7 +30,7 @@ impl ScriptBuilder for SimpleCryptBuilder { _archive_encoding: Encoding, _config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(SimpleCrypt::new(buf, filename)?)) } diff --git a/src/scripts/kirikiri/tjs2.rs b/src/scripts/kirikiri/tjs2.rs index 3a7dc1f..a22ad46 100644 --- a/src/scripts/kirikiri/tjs2.rs +++ b/src/scripts/kirikiri/tjs2.rs @@ -32,7 +32,7 @@ impl ScriptBuilder for Tjs2Builder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Tjs2::new(buf, encoding, config)?)) } diff --git a/src/scripts/kirikiri/tjs_ns0.rs b/src/scripts/kirikiri/tjs_ns0.rs index 41d93b0..07e7aa2 100644 --- a/src/scripts/kirikiri/tjs_ns0.rs +++ b/src/scripts/kirikiri/tjs_ns0.rs @@ -35,7 +35,7 @@ impl ScriptBuilder for TjsNs0Builder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(TjsNs0::new(buf, filename, encoding, config)?)) } diff --git a/src/scripts/musica/archive/paz.rs b/src/scripts/musica/archive/paz.rs index 2eec13a..4497275 100644 --- a/src/scripts/musica/archive/paz.rs +++ b/src/scripts/musica/archive/paz.rs @@ -133,7 +133,7 @@ impl ScriptBuilder for PazArcBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PazArc::new( MemReader::new(buf), filename, @@ -149,7 +149,7 @@ impl ScriptBuilder for PazArcBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let f = std::fs::File::open(filename)?; let f = std::io::BufReader::new(f); Ok(Box::new(PazArc::new( @@ -162,13 +162,13 @@ impl ScriptBuilder for PazArcBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PazArc::new( reader, filename, @@ -254,7 +254,7 @@ pub struct PazArc<'a> { const AUDIO_PAZ_NAMES: &[&str] = &["bgm", "se", "voice", "pmbgm", "pmse", "pmvoice"]; impl<'a> PazArc<'a> { - pub fn new( + pub fn new( reader: T, filename: &str, archive_encoding: Encoding, diff --git a/src/scripts/musica/sc.rs b/src/scripts/musica/sc.rs index 87be167..aa5ae02 100644 --- a/src/scripts/musica/sc.rs +++ b/src/scripts/musica/sc.rs @@ -29,7 +29,7 @@ impl ScriptBuilder for MusicaBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(MusicaScript::new(buf, encoding, config)?)) } diff --git a/src/scripts/qlie/archive/pack/encryption.rs b/src/scripts/qlie/archive/pack/encryption.rs index bc64235..97154c5 100644 --- a/src/scripts/qlie/archive/pack/encryption.rs +++ b/src/scripts/qlie/archive/pack/encryption.rs @@ -42,7 +42,7 @@ pub fn create_encryption( major: u8, minor: u8, game_key: Option>, -) -> Result> { +) -> Result> { match (major, minor) { (3, 1) => Ok(Box::new(Encryption31::new())), (3, 0) => Ok(Box::new(Encryption30::new(game_key))), diff --git a/src/scripts/qlie/archive/pack/mod.rs b/src/scripts/qlie/archive/pack/mod.rs index 5660b2a..e4e0bf3 100644 --- a/src/scripts/qlie/archive/pack/mod.rs +++ b/src/scripts/qlie/archive/pack/mod.rs @@ -41,7 +41,7 @@ impl ScriptBuilder for QliePackArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(QliePackArchive::new( MemReader::new(data), archive_encoding, @@ -57,7 +57,7 @@ impl ScriptBuilder for QliePackArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(QliePackArchive::new( @@ -80,13 +80,13 @@ impl ScriptBuilder for QliePackArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(QliePackArchive::new( reader, archive_encoding, @@ -145,9 +145,9 @@ pub fn is_this_format + ?Sized>(path: &P) -> Result { +pub struct QliePackArchive<'b, T: Read + Seek + std::fmt::Debug + Send + Sync + 'b> { header: QlieHeader, - encryption: Box, + encryption: Box, reader: Arc>, qkey: Option, entries: Vec, @@ -155,7 +155,7 @@ pub struct QliePackArchive<'b, T: Read + Seek + std::fmt::Debug + 'b> { _mark: std::marker::PhantomData<&'b ()>, } -impl<'b, T: Read + Seek + std::fmt::Debug + 'b> QliePackArchive<'b, T> { +impl<'b, T: Read + Seek + std::fmt::Debug + Send + Sync + 'b> QliePackArchive<'b, T> { pub fn new( mut reader: T, archive_encoding: Encoding, @@ -205,7 +205,7 @@ impl<'b, T: Read + Seek + std::fmt::Debug + 'b> QliePackArchive<'b, T> { let mut entries = if major >= 2 { Self::read_entries(&mut reader, key, &header, archive_encoding, &encryption)? } else { - let possible_encs: [Box; 3] = [ + let possible_encs: [Box; 3] = [ Box::new(encryption::Encryption10::new()), Box::new(encryption::Encryption20::new_no_hash()), Box::new(encryption::Encryption20::new()), @@ -263,7 +263,7 @@ impl<'b, T: Read + Seek + std::fmt::Debug + 'b> QliePackArchive<'b, T> { key: u32, header: &QlieHeader, archive_encoding: Encoding, - encryption: &Box, + encryption: &Box, ) -> Result> { let mut entries = Vec::new(); reader.seek(SeekFrom::Start(header.index_offset))?; @@ -301,7 +301,7 @@ impl<'b, T: Read + Seek + std::fmt::Debug + 'b> QliePackArchive<'b, T> { } } -impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for QliePackArchive<'b, T> { +impl<'b, T: Read + Seek + std::fmt::Debug + Send + Sync + 'b> Script for QliePackArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/qlie/image/abmp10.rs b/src/scripts/qlie/image/abmp10.rs index aa2ec1c..efff060 100644 --- a/src/scripts/qlie/image/abmp10.rs +++ b/src/scripts/qlie/image/abmp10.rs @@ -31,7 +31,7 @@ impl ScriptBuilder for Abmp10ImageBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Abmp10Image::new( MemReader::new(buf), encoding, diff --git a/src/scripts/qlie/image/dpng.rs b/src/scripts/qlie/image/dpng.rs index eae0c41..3a01488 100644 --- a/src/scripts/qlie/image/dpng.rs +++ b/src/scripts/qlie/image/dpng.rs @@ -64,7 +64,7 @@ impl ScriptBuilder for DpngImageBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(DpngImage::new(MemReader::new(buf), config)?)) } diff --git a/src/scripts/qlie/script.rs b/src/scripts/qlie/script.rs index 527bdb8..a614d17 100644 --- a/src/scripts/qlie/script.rs +++ b/src/scripts/qlie/script.rs @@ -30,7 +30,7 @@ impl ScriptBuilder for QlieScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(QlieScript::new( MemReader::new(buf), encoding, diff --git a/src/scripts/silky/map.rs b/src/scripts/silky/map.rs index cb496f5..d62b216 100644 --- a/src/scripts/silky/map.rs +++ b/src/scripts/silky/map.rs @@ -29,7 +29,7 @@ impl ScriptBuilder for MapBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Map::new(buf, encoding, config)?)) } diff --git a/src/scripts/silky/mes.rs b/src/scripts/silky/mes.rs index ba3dd7c..6aa6573 100644 --- a/src/scripts/silky/mes.rs +++ b/src/scripts/silky/mes.rs @@ -4,8 +4,8 @@ use crate::scripts::base::*; use crate::types::*; use crate::utils::encoding::*; use anyhow::Result; -use std::cell::RefCell; use std::io::Write; +use std::sync::Mutex; use unicode_segmentation::UnicodeSegmentation; #[derive(Debug)] @@ -32,7 +32,7 @@ impl ScriptBuilder for MesBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Mes::new(buf, encoding, config)?)) } @@ -156,7 +156,7 @@ impl<'a> TextParser<'a> { #[derive(Debug)] pub struct Mes { - disasm: RefCell>, + disasm: Mutex>, encoding: Encoding, texts: Vec, } @@ -167,7 +167,8 @@ impl Mes { let num_message = reader.cpeek_u32()?; let code_offset = 4 + num_message as u64 * 4; let first_line_offset = reader.cpeek_u32_at(4)? as u64 + code_offset; - let mut disasm: Box = if reader.cpeek_u8_at(first_line_offset)? == 0x19 + let mut disasm: Box = if reader.cpeek_u8_at(first_line_offset)? + == 0x19 && reader.cpeek_u32_at(first_line_offset + 1)? == 0 { Box::new(Ai6WinDisasm::new(reader)?) @@ -177,14 +178,17 @@ impl Mes { disasm.read_header()?; let texts = disasm.read_code()?; Ok(Self { - disasm: RefCell::new(disasm), + disasm: Mutex::new(disasm), encoding, texts, }) } fn code_to_text(&self, str: &SlikyString) -> Result { - let mut disasm = self.disasm.try_borrow_mut()?; + let mut disasm = self + .disasm + .lock() + .map_err(|_| anyhow::anyhow!("Failed to acquire disassembler lock"))?; let mut result = String::new(); disasm.stream_mut().pos = str.start as usize; let end = str.start as usize + str.len as usize; @@ -290,8 +294,12 @@ impl Script for Mes { encoding: Encoding, replacement: Option<&'a ReplacementTable>, ) -> Result<()> { - let opcodes = self.disasm.try_borrow()?.opcodes(); - let mut inp = self.disasm.try_borrow()?.stream().clone(); + let disasm = self + .disasm + .lock() + .map_err(|_| anyhow::anyhow!("Failed to acquire disassembler lock"))?; + let opcodes = disasm.opcodes(); + let mut inp = disasm.stream().clone(); inp.pos = 0; let mut patcher = BinaryPatcher::new(inp.to_ref(), file, |add| Ok(add), |add| Ok(add))?; let mut mess = messages.iter(); @@ -348,15 +356,15 @@ impl Script for Mes { return Err(anyhow::anyhow!("Too many messages")); } patcher.copy_up_to(inp.data.len() as u64)?; - let code_offset = self.disasm.try_borrow()?.code_offset(); - for &address_offset in self.disasm.try_borrow()?.little_endian_addresses() { + let code_offset = disasm.code_offset(); + for &address_offset in disasm.little_endian_addresses() { let orig_address = inp.cpeek_u32_at(address_offset as u64)? as u64; let orig_offset = orig_address + code_offset as u64; let new_offset = patcher.map_offset(orig_offset)?; let new_address = new_offset - code_offset as u64; patcher.patch_u32(address_offset as u64, new_address as u32)?; } - for &address_offset in self.disasm.try_borrow()?.big_endian_addresses() { + for &address_offset in disasm.big_endian_addresses() { let orig_address = inp.cpeek_u32_be_at(address_offset as u64)? as u64; let orig_offset = orig_address + code_offset as u64; let new_offset = patcher.map_offset(orig_offset)?; diff --git a/src/scripts/softpal/arc/pac.rs b/src/scripts/softpal/arc/pac.rs index de9ee81..2763a30 100644 --- a/src/scripts/softpal/arc/pac.rs +++ b/src/scripts/softpal/arc/pac.rs @@ -56,7 +56,7 @@ impl ScriptBuilder for SoftpalPacBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(SoftpalPacArchive::new( MemReader::new(buf), archive_encoding, @@ -72,7 +72,7 @@ impl ScriptBuilder for SoftpalPacBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let file = std::fs::File::open(filename)?; let reader = std::io::BufReader::new(file); Ok(Box::new(SoftpalPacArchive::new( @@ -85,13 +85,13 @@ impl ScriptBuilder for SoftpalPacBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(SoftpalPacArchive::new( reader, archive_encoding, diff --git a/src/scripts/softpal/img/pgd/ge.rs b/src/scripts/softpal/img/pgd/ge.rs index 81273a7..4f68a64 100644 --- a/src/scripts/softpal/img/pgd/ge.rs +++ b/src/scripts/softpal/img/pgd/ge.rs @@ -28,7 +28,7 @@ impl ScriptBuilder for PgdGeBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PgdGe::new(MemReader::new(buf), config)?)) } diff --git a/src/scripts/softpal/img/pgd/pgd3.rs b/src/scripts/softpal/img/pgd/pgd3.rs index c6faea7..91a2861 100644 --- a/src/scripts/softpal/img/pgd/pgd3.rs +++ b/src/scripts/softpal/img/pgd/pgd3.rs @@ -29,7 +29,7 @@ impl ScriptBuilder for Pgd3Builder { _archive_encoding: Encoding, config: &ExtraConfig, archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Pgd3::new( MemReader::new(buf), filename, diff --git a/src/scripts/softpal/scr/mod.rs b/src/scripts/softpal/scr/mod.rs index 15beceb..f2ed15d 100644 --- a/src/scripts/softpal/scr/mod.rs +++ b/src/scripts/softpal/scr/mod.rs @@ -34,7 +34,7 @@ impl ScriptBuilder for SoftpalScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(SoftpalScript::new( buf, filename, encoding, config, archive, )?)) diff --git a/src/scripts/will_plus/img/wip.rs b/src/scripts/will_plus/img/wip.rs index 926e52f..74044c4 100644 --- a/src/scripts/will_plus/img/wip.rs +++ b/src/scripts/will_plus/img/wip.rs @@ -33,7 +33,7 @@ impl ScriptBuilder for WillPlusWipImageBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(WillPlusWipImage::new( MemReader::new(data), config, diff --git a/src/scripts/will_plus/ws2.rs b/src/scripts/will_plus/ws2.rs index 5791d83..68a351a 100644 --- a/src/scripts/will_plus/ws2.rs +++ b/src/scripts/will_plus/ws2.rs @@ -32,7 +32,7 @@ impl ScriptBuilder for Ws2ScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if !config.will_plus_ws2_no_disasm { match Ws2DisasmScript::new(&buf, encoding, config, false) { Ok(script) => return Ok(Box::new(script)), diff --git a/src/scripts/yaneurao/itufuru/archive.rs b/src/scripts/yaneurao/itufuru/archive.rs index c6a70ac..e028673 100644 --- a/src/scripts/yaneurao/itufuru/archive.rs +++ b/src/scripts/yaneurao/itufuru/archive.rs @@ -39,7 +39,7 @@ impl ScriptBuilder for ItufuruArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ItufuruArchive::new( MemReader::new(data), archive_encoding, @@ -54,7 +54,7 @@ impl ScriptBuilder for ItufuruArchiveBuilder { archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { if filename == "-" { let data = crate::utils::files::read_file(filename)?; Ok(Box::new(ItufuruArchive::new( @@ -75,13 +75,13 @@ impl ScriptBuilder for ItufuruArchiveBuilder { fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ItufuruArchive::new( reader, archive_encoding, diff --git a/src/scripts/yaneurao/itufuru/script.rs b/src/scripts/yaneurao/itufuru/script.rs index 895f8d2..6ef73aa 100644 --- a/src/scripts/yaneurao/itufuru/script.rs +++ b/src/scripts/yaneurao/itufuru/script.rs @@ -29,7 +29,7 @@ impl ScriptBuilder for ItufuruScriptBuilder { _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ItufuruScript::new(data, encoding, config)?)) }