4 Commits

9 changed files with 473 additions and 1 deletions

View File

@@ -73,7 +73,7 @@ default = ["all-fmt", "image-jpg", "image-jxl", "image-webp", "audio-flac", "jie
# Zig can not build libjxl
zig = ["all-fmt", "image-jpg", "image-webp", "audio-flac", "jieba"]
all-fmt = ["all-script", "all-img", "all-arc", "all-audio"]
all-script = ["artemis", "artemis-panmimisoft", "bgi", "cat-system", "circus", "entis-gls", "escude", "ex-hibit", "favorite", "hexen-haus", "kirikiri", "musica", "qlie", "silky", "softpal", "will-plus", "yaneurao", "yaneurao-itufuru"]
all-script = ["artemis", "artemis-panmimisoft", "bgi", "cat-system", "circus", "entis-gls", "escude", "ex-hibit", "favorite", "hexen-haus", "kirikiri", "musica", "qlie", "silky", "softpal", "will-plus", "yaneurao", "yaneurao-itufuru", "yuris"]
all-img = ["bgi-img", "cat-system-img", "circus-img", "emote-img", "hexen-haus-img", "kirikiri-img", "qlie-img", "softpal-img", "will-plus-img"]
all-arc = ["artemis-arc", "bgi-arc", "cat-system-arc", "circus-arc", "escude-arc", "ex-hibit-arc", "hexen-haus-arc", "kirikiri-arc", "musica-arc", "qlie-arc", "softpal-arc"]
all-audio = ["bgi-audio", "circus-audio"]
@@ -117,6 +117,7 @@ will-plus = ["utils-str"]
will-plus-img = ["will-plus", "image"]
yaneurao = []
yaneurao-itufuru = ["yaneurao", "utils-xored-stream"]
yuris = []
# basic feature
image = ["png"]
image-jpg = ["mozjpeg"]

View File

@@ -262,3 +262,10 @@ msg-tool create -t <script-type> <input> <output>
| Archive Type | Feature Name | Name | Unpack | Pack | Remarks |
|---|---|---|---|---|---|
| `yaneurao-itufuru-arc`/`itufuru-arc` | `yaneurao-itufuru-arc` | Yaneurao Itufuru Archive File (.scd) | ✔️ | ✔️ | |
### Yu-Ris
| Script Type | Feature Name | Name | Export | Import | Export Multiple | Import Multiple | Custom Export | Custom Import | Create | Remarks |
|---|---|---|---|---|---|---|---|---|---|---|
| `yuris-yscm` | `yuris` | Yu-Ris YSCM(opcodes metadata) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ❌ | ❌ | |
| `yuris-yser` | `yuris` | Yu-Ris YSER(error message) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ❌ | ❌ | |
| `yuris-yscfg` | `yuris` | Yu-Ris YSCFG(config) file (.ybn) | ❌ | ❌ | ❌ | ❌ | ✔️ | ❌ | ❌ | |

View File

@@ -34,6 +34,8 @@ pub mod softpal;
pub mod will_plus;
#[cfg(feature = "yaneurao")]
pub mod yaneurao;
#[cfg(feature = "yuris")]
pub mod yuris;
pub use base::{Script, ScriptBuilder};
@@ -174,6 +176,12 @@ lazy_static::lazy_static! {
Box::new(qlie::image::dpng::DpngImageBuilder::new()),
#[cfg(feature = "qlie-img")]
Box::new(qlie::image::abmp10::Abmp10ImageBuilder::new()),
#[cfg(feature = "yuris")]
Box::new(yuris::yscm::YSCMBuilder::new()),
#[cfg(feature = "yuris")]
Box::new(yuris::yser::YSERBuilder::new()),
#[cfg(feature = "yuris")]
Box::new(yuris::yscfg::YSCFGBuilder::new()),
];
/// A list of all script extensions.
pub static ref ALL_EXTS: Vec<String> =

5
src/scripts/yuris/mod.rs Normal file
View File

@@ -0,0 +1,5 @@
//! Yu-Ris Engine Scripts
mod types;
pub mod yscfg;
pub mod yscm;
pub mod yser;

View File

@@ -0,0 +1,23 @@
use crate::ext::io::*;
use crate::types::*;
use crate::utils::encoding::*;
use crate::utils::struct_pack::*;
use anyhow::Result;
use msg_tool_macro::*;
use serde::{Deserialize, Serialize};
use std::io::{Read, Seek, Write};
#[derive(Debug, StructUnpack, StructPack, Deserialize, Serialize)]
pub struct ArgumentMeta {
#[cstring]
pub name: String,
pub data: u16,
}
#[derive(Debug, StructPack, StructUnpack, Deserialize, Serialize)]
pub struct CodeMeta {
#[cstring]
pub name: String,
#[pvec(u8)]
pub arguments: Vec<ArgumentMeta>,
}

144
src/scripts/yuris/yscfg.rs Normal file
View File

@@ -0,0 +1,144 @@
//! Yu-Ris YSCFG files
use crate::ext::io::*;
use crate::scripts::base::*;
use crate::types::*;
use crate::utils::encoding::*;
use crate::utils::struct_pack::*;
use anyhow::Result;
use msg_tool_macro::*;
use serde::{Deserialize, Serialize};
use std::io::{Read, Seek, Write};
#[derive(Debug)]
pub struct YSCFGBuilder {}
impl YSCFGBuilder {
/// Creates a new instance of `YSERBuilder`
pub const fn new() -> Self {
YSCFGBuilder {}
}
}
impl ScriptBuilder for YSCFGBuilder {
fn default_encoding(&self) -> Encoding {
Encoding::Cp932
}
fn build_script(
&self,
buf: Vec<u8>,
_filename: &str,
encoding: Encoding,
_archive_encoding: Encoding,
config: &ExtraConfig,
_archive: Option<&Box<dyn Script>>,
) -> Result<Box<dyn Script + Send + Sync>> {
Ok(Box::new(YSCFG::new(MemReader::new(buf), encoding, config)?))
}
fn extensions(&self) -> &'static [&'static str] {
&["ybn"]
}
fn is_this_format(&self, _filename: &str, buf: &[u8], buf_len: usize) -> Option<u8> {
if buf_len >= 4 && buf.starts_with(b"YSCF") {
return Some(20);
}
None
}
fn script_type(&self) -> &'static ScriptType {
&ScriptType::YurisYSCFG
}
}
#[derive(Debug, StructPack, StructUnpack, Deserialize, Serialize)]
struct YSCFGData {
engine: u32,
unk0: u32,
compile: u32,
screen_width: u32,
screen_height: u32,
enable: u32,
image_type_slots: [u8; 8],
sound_type_slots: [u8; 4],
thread: u32,
debug_mode: u32,
sound: u32,
window_resize: u32,
window_frame: u32,
file_priority_dev: u32,
file_priority_debug: u32,
file_priority_release: u32,
unk1: u32,
// #TODO: Better version handle
#[skip_pack_if(self.engine < 500)]
#[skip_unpack_if(engine < 500)]
unk2: u32,
#[skip_pack_if(self.engine < 500)]
#[skip_unpack_if(engine < 500)]
unk3: u32,
#[skip_pack_if(self.engine < 500)]
#[skip_unpack_if(engine < 500)]
unk4: u32,
#[pstring(u16)]
caption: String,
}
#[derive(Debug)]
pub struct YSCFG {
data: YSCFGData,
custom_yaml: bool,
}
impl YSCFG {
pub fn new<T: Read + Seek>(
mut reader: T,
encoding: Encoding,
config: &ExtraConfig,
) -> Result<Self> {
let mut sig = [0; 4];
reader.read_exact(&mut sig)?;
if &sig != b"YSCF" {
anyhow::bail!("Unsupported YSCFG file.");
}
let data = YSCFGData::unpack(&mut reader, false, encoding, &None)?;
Ok(Self {
data,
custom_yaml: config.custom_yaml,
})
}
}
impl Script for YSCFG {
fn default_output_script_type(&self) -> OutputScriptType {
OutputScriptType::Custom
}
fn is_output_supported(&self, output: OutputScriptType) -> bool {
matches!(output, OutputScriptType::Custom)
}
fn default_format_type(&self) -> FormatOptions {
FormatOptions::None
}
fn custom_output_extension(&self) -> &'static str {
if self.custom_yaml { "yaml" } else { "json" }
}
fn custom_export(&self, filename: &std::path::Path, encoding: Encoding) -> Result<()> {
let s = if self.custom_yaml {
serde_yaml_ng::to_string(&self.data)
.map_err(|e| anyhow::anyhow!("Failed to serialize to YAML: {}", e))?
} else {
serde_json::to_string_pretty(&self.data)
.map_err(|e| anyhow::anyhow!("Failed to serialize to JSON: {}", e))?
};
let mut writer = crate::utils::files::write_file(filename)?;
let s = encode_string(encoding, &s, false)?;
writer.write_all(&s)?;
writer.flush()?;
Ok(())
}
}

150
src/scripts/yuris/yscm.rs Normal file
View File

@@ -0,0 +1,150 @@
//! Yu-Ris YSCM files
use super::types::*;
use crate::ext::io::*;
use crate::scripts::base::*;
use crate::types::*;
use crate::utils::encoding::*;
use crate::utils::struct_pack::*;
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::io::{Read, Seek};
#[derive(Debug)]
pub struct YSCMBuilder {}
impl YSCMBuilder {
/// Creates a new instance of `YSCMBuilder`
pub const fn new() -> Self {
YSCMBuilder {}
}
}
impl ScriptBuilder for YSCMBuilder {
fn default_encoding(&self) -> Encoding {
Encoding::Cp932
}
fn build_script(
&self,
buf: Vec<u8>,
_filename: &str,
encoding: Encoding,
_archive_encoding: Encoding,
config: &ExtraConfig,
_archive: Option<&Box<dyn Script>>,
) -> Result<Box<dyn Script + Send + Sync>> {
Ok(Box::new(YSCM::new(MemReader::new(buf), encoding, config)?))
}
fn extensions(&self) -> &'static [&'static str] {
&["ybn"]
}
fn is_this_format(&self, _filename: &str, buf: &[u8], buf_len: usize) -> Option<u8> {
if buf_len >= 4 && buf.starts_with(b"YSCM") {
return Some(20);
}
None
}
fn script_type(&self) -> &'static ScriptType {
&ScriptType::YurisYSCM
}
}
#[derive(Debug, Deserialize, Serialize)]
pub(crate) struct YSCMData {
pub engine: u32,
pub opcode_length: u32,
pub unk: u32,
pub opcodes: Vec<CodeMeta>,
pub errmsgs: Vec<String>,
pub unk_tbl: Vec<u8>,
}
impl StructUnpack for YSCMData {
fn unpack<R: Read + Seek>(
reader: &mut R,
big: bool,
encoding: Encoding,
info: &Option<Box<dyn std::any::Any>>,
) -> Result<Self> {
let engine = u32::unpack(reader, big, encoding, info)?;
let opcode_length = u32::unpack(reader, big, encoding, info)?;
let unk = u32::unpack(reader, big, encoding, info)?;
let opcodes = reader.read_struct_vec(opcode_length as usize, big, encoding, info)?;
let target_len = reader.stream_length()? - 0x100;
let mut errmsgs = Vec::new();
while reader.stream_position()? < target_len {
let s = reader.read_cstring()?;
errmsgs.push(decode_to_string(encoding, s.as_bytes(), true)?);
}
let unk_tbl = reader.read_exact_vec(0x100)?;
Ok(Self {
engine,
opcode_length,
unk,
opcodes,
errmsgs,
unk_tbl,
})
}
}
#[derive(Debug)]
pub struct YSCM {
pub(crate) data: YSCMData,
custom_yaml: bool,
}
impl YSCM {
pub fn new<T: Read + Seek>(
mut reader: T,
encoding: Encoding,
config: &ExtraConfig,
) -> Result<Self> {
let mut sig = [0; 4];
reader.read_exact(&mut sig)?;
if &sig != b"YSCM" {
anyhow::bail!("Unsupported YSCM file.");
}
let data = YSCMData::unpack(&mut reader, false, encoding, &None)?;
Ok(Self {
data,
custom_yaml: config.custom_yaml,
})
}
}
impl Script for YSCM {
fn default_output_script_type(&self) -> OutputScriptType {
OutputScriptType::Custom
}
fn is_output_supported(&self, output: OutputScriptType) -> bool {
matches!(output, OutputScriptType::Custom)
}
fn default_format_type(&self) -> FormatOptions {
FormatOptions::None
}
fn custom_output_extension(&self) -> &'static str {
if self.custom_yaml { "yaml" } else { "json" }
}
fn custom_export(&self, filename: &std::path::Path, encoding: Encoding) -> Result<()> {
let s = if self.custom_yaml {
serde_yaml_ng::to_string(&self.data)
.map_err(|e| anyhow::anyhow!("Failed to serialize to YAML: {}", e))?
} else {
serde_json::to_string_pretty(&self.data)
.map_err(|e| anyhow::anyhow!("Failed to serialize to JSON: {}", e))?
};
let mut writer = crate::utils::files::write_file(filename)?;
let s = encode_string(encoding, &s, false)?;
writer.write_all(&s)?;
writer.flush()?;
Ok(())
}
}

125
src/scripts/yuris/yser.rs Normal file
View File

@@ -0,0 +1,125 @@
//! Yu-Ris YSER files
use crate::ext::io::*;
use crate::scripts::base::*;
use crate::types::*;
use crate::utils::encoding::*;
use crate::utils::struct_pack::*;
use anyhow::Result;
use msg_tool_macro::*;
use serde::{Deserialize, Serialize};
use std::io::{Read, Seek, Write};
#[derive(Debug)]
pub struct YSERBuilder {}
impl YSERBuilder {
/// Creates a new instance of `YSERBuilder`
pub const fn new() -> Self {
YSERBuilder {}
}
}
impl ScriptBuilder for YSERBuilder {
fn default_encoding(&self) -> Encoding {
Encoding::Cp932
}
fn build_script(
&self,
buf: Vec<u8>,
_filename: &str,
encoding: Encoding,
_archive_encoding: Encoding,
config: &ExtraConfig,
_archive: Option<&Box<dyn Script>>,
) -> Result<Box<dyn Script + Send + Sync>> {
Ok(Box::new(YSER::new(MemReader::new(buf), encoding, config)?))
}
fn extensions(&self) -> &'static [&'static str] {
&["ybn"]
}
fn is_this_format(&self, _filename: &str, buf: &[u8], buf_len: usize) -> Option<u8> {
if buf_len >= 4 && buf.starts_with(b"YSER") {
return Some(20);
}
None
}
fn script_type(&self) -> &'static ScriptType {
&ScriptType::YurisYSER
}
}
#[derive(Debug, StructPack, StructUnpack, Deserialize, Serialize)]
struct StringData {
unk: u32,
#[cstring]
s: String,
}
#[derive(Debug, StructPack, StructUnpack, Deserialize, Serialize)]
struct YSERData {
engine: u32,
#[pvec(u64)]
strings: Vec<StringData>,
}
#[derive(Debug)]
pub struct YSER {
data: YSERData,
custom_yaml: bool,
}
impl YSER {
pub fn new<T: Read + Seek>(
mut reader: T,
encoding: Encoding,
config: &ExtraConfig,
) -> Result<Self> {
let mut sig = [0; 4];
reader.read_exact(&mut sig)?;
if &sig != b"YSER" {
anyhow::bail!("Unsupported YSER file.");
}
let data = YSERData::unpack(&mut reader, false, encoding, &None)?;
Ok(Self {
data,
custom_yaml: config.custom_yaml,
})
}
}
impl Script for YSER {
fn default_output_script_type(&self) -> OutputScriptType {
OutputScriptType::Custom
}
fn is_output_supported(&self, output: OutputScriptType) -> bool {
matches!(output, OutputScriptType::Custom)
}
fn default_format_type(&self) -> FormatOptions {
FormatOptions::None
}
fn custom_output_extension(&self) -> &'static str {
if self.custom_yaml { "yaml" } else { "json" }
}
fn custom_export(&self, filename: &std::path::Path, encoding: Encoding) -> Result<()> {
let s = if self.custom_yaml {
serde_yaml_ng::to_string(&self.data)
.map_err(|e| anyhow::anyhow!("Failed to serialize to YAML: {}", e))?
} else {
serde_json::to_string_pretty(&self.data)
.map_err(|e| anyhow::anyhow!("Failed to serialize to JSON: {}", e))?
};
let mut writer = crate::utils::files::write_file(filename)?;
let s = encode_string(encoding, &s, false)?;
writer.write_all(&s)?;
writer.flush()?;
Ok(())
}
}

View File

@@ -908,6 +908,15 @@ pub enum ScriptType {
#[value(alias("itufuru-arc"))]
/// Yaneurao Itufuru script archive
YaneuraoItufuruArc,
#[cfg(feature = "yuris")]
/// Yu-Ris YSCM(opcodes metadata) file (.ybn)
YurisYSCM,
#[cfg(feature = "yuris")]
/// Yu-Ris YSER(error message) file (.ybn)
YurisYSER,
#[cfg(feature = "yuris")]
/// Yu-Ris YSCFG(config) file (.ybn)
YurisYSCFG,
}
#[derive(Clone, Debug, Serialize, Deserialize)]