From af104e48ea66113f395f00c4e6100f23143ab6a6 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Fri, 26 Jun 2026 12:42:07 +0800 Subject: [PATCH] Add dedup for YuRIS YSTB Arg data --- Cargo.toml | 2 +- src/scripts/kirikiri/archive/xp3/crypt/mod.rs | 4 +++- src/scripts/kirikiri/archive/xp3/crypt/nvl.rs | 11 +++++++++-- src/scripts/yuris/ystb.rs | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a75d63..c20defa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -125,7 +125,7 @@ will-plus = ["utils-str"] will-plus-img = ["will-plus", "image"] yaneurao = [] yaneurao-itufuru = ["yaneurao", "utils-xored-stream"] -yuris = ["dep:chrono", "dep:hex", "utils-serde-base64bytes", "utils-xored-stream"] +yuris = ["dep:chrono", "dep:hex", "dep:memchr", "utils-serde-base64bytes", "utils-xored-stream"] yuris-arc = ["yuris", "dep:adler", "dep:crc32fast", "flate2", "dep:int-enum", "dep:pelite", "utils-murmur2", "dep:xxhash-rust", "xxhash-rust/xxh32", "zopfli"] yuris-img = ["yuris", "image", "qoi", "webp"] # basic feature diff --git a/src/scripts/kirikiri/archive/xp3/crypt/mod.rs b/src/scripts/kirikiri/archive/xp3/crypt/mod.rs index 23df966..5947d08 100644 --- a/src/scripts/kirikiri/archive/xp3/crypt/mod.rs +++ b/src/scripts/kirikiri/archive/xp3/crypt/mod.rs @@ -532,7 +532,9 @@ impl Schema { Box::new(Xor2Crypt::new(self.base.clone(), *key1, *key2)) } CryptType::LeaveSLeaveCrypt => Box::new(LeaveSLeaveCrypt::new(self.base.clone())), - CryptType::NVLCrypt { key } => Box::new(nvl::NVLCrypt::new(self.base.clone(), &key.bytes)?), + CryptType::NVLCrypt { key } => { + Box::new(nvl::NVLCrypt::new(self.base.clone(), &key.bytes)?) + } }) } } diff --git a/src/scripts/kirikiri/archive/xp3/crypt/nvl.rs b/src/scripts/kirikiri/archive/xp3/crypt/nvl.rs index 8e26921..240586d 100644 --- a/src/scripts/kirikiri/archive/xp3/crypt/nvl.rs +++ b/src/scripts/kirikiri/archive/xp3/crypt/nvl.rs @@ -13,7 +13,7 @@ impl NVLCrypt { } Ok(Self { base, - key: key.try_into()? + key: key.try_into()?, }) } @@ -39,7 +39,14 @@ impl Crypt for NVLCrypt { let hash_key = reader.read_u32()?; let name_hash = reader.read_u32()?; let extension_hash = reader.read_u32()?; - Ok((format!("{:08x}.{:08x}", hash_key ^ name_hash, hash_key ^ extension_hash), 12)) + Ok(( + format!( + "{:08x}.{:08x}", + hash_key ^ name_hash, + hash_key ^ extension_hash + ), + 12, + )) } fn decrypt_supported(&self) -> bool { true diff --git a/src/scripts/yuris/ystb.rs b/src/scripts/yuris/ystb.rs index acdbac2..7f12d22 100644 --- a/src/scripts/yuris/ystb.rs +++ b/src/scripts/yuris/ystb.rs @@ -1594,6 +1594,7 @@ impl Script for YSTB { let mut cpos = f.pos as u64; f.pos += args_index_size as usize; let bpos = f.pos as u32; + let mut cache = Vec::new(); for (base, args) in inst_data.iter_mut() { let meta = @@ -1614,10 +1615,16 @@ impl Script for YSTB { continue; } + if let Some(offset) = memchr::memmem::find(&cache, &arg.1) { + f.write_u32_at(cpos, offset as u32)?; + cpos += 4; + continue; + } let offset = f.pos as u32 - bpos; f.write_u32_at(cpos, offset)?; cpos += 4; f.write_all(&arg.1)?; + cache.extend_from_slice(&arg.1); } } @@ -1764,6 +1771,7 @@ impl Script for YSTB { let mut cpos = f.pos as u64; f.pos += data.header.args_index_size as usize; let bpos = f.pos as u32; + let mut cache = Vec::new(); for i in data.insts.iter_mut() { let meta = self.com.opcodes.get(i.opcode as usize).ok_or_else(|| { @@ -1780,10 +1788,16 @@ impl Script for YSTB { cpos += 4; continue; } + if let Some(offset) = memchr::memmem::find(&cache, &arg.data) { + f.write_u32_at(cpos, offset as u32)?; + cpos += 4; + continue; + } let offset = f.pos as u32 - bpos; f.write_u32_at(cpos, offset)?; cpos += 4; f.write_all(&arg.data)?; + cache.extend_from_slice(&arg.data); } } data.header.args_data_size = f.pos as u32 - bpos;