mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-07-08 01:31:53 +08:00
Compare commits
2 Commits
3f155fbe51
...
02707fc867
| Author | SHA1 | Date | |
|---|---|---|---|
| 02707fc867 | |||
| 0a8df19d19 |
@@ -46,7 +46,7 @@ zstd = { version = "0.13", optional = true }
|
||||
default = ["all-fmt", "image-jpg", "image-webp"]
|
||||
all-fmt = ["all-script", "all-img", "all-arc", "all-audio"]
|
||||
all-script = ["artemis", "bgi", "cat-system", "circus", "entis-gls", "escude", "ex-hibit", "hexen-haus", "kirikiri", "softpal", "will-plus", "yaneurao", "yaneurao-itufuru"]
|
||||
all-img = ["bgi-img", "cat-system-img", "circus-img", "kirikiri-img"]
|
||||
all-img = ["bgi-img", "cat-system-img", "circus-img", "emote-img", "kirikiri-img"]
|
||||
all-arc = ["artemis-arc", "bgi-arc", "cat-system-arc", "circus-arc", "escude-arc"]
|
||||
all-audio = ["bgi-audio", "circus-audio"]
|
||||
artemis = ["utils-escape"]
|
||||
@@ -62,13 +62,14 @@ circus = []
|
||||
circus-arc = ["circus"]
|
||||
circus-audio = ["circus", "flate2", "int-enum", "utils-pcm"]
|
||||
circus-img = ["circus", "image", "flate2", "zstd"]
|
||||
emote-img = ["emote-psb", "image", "libtlg-rs", "url"]
|
||||
entis-gls = ["xml5ever", "markup5ever", "markup5ever_rcdom"]
|
||||
escude = ["int-enum"]
|
||||
escude-arc = ["escude", "rand", "utils-bit-stream"]
|
||||
ex-hibit = []
|
||||
hexen-haus = ["memchr", "utils-str"]
|
||||
kirikiri = ["emote-psb", "fancy-regex", "flate2", "json", "utils-escape"]
|
||||
kirikiri-img = ["kirikiri", "emote-psb", "image", "libtlg-rs", "url"]
|
||||
kirikiri-img = ["kirikiri", "image", "libtlg-rs"]
|
||||
softpal = ["int-enum"]
|
||||
will-plus = ["utils-str"]
|
||||
yaneurao = []
|
||||
|
||||
15
README.md
15
README.md
@@ -124,6 +124,15 @@ msg-tool create -t <script-type> <input> <output>
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| `circus-crx` | `circus-img` | Circus Image File (.crx) | ✔️ | ✔️ | ❌ | ❌ | ✔️ | |
|
||||
| `circus-crxd` | `circus-img` | Circus Differential Image File (.crx) | ✔️ | ❌ | ❌ | ❌ | ❌ | |
|
||||
### Emote
|
||||
| Image Type | Feature Name | Name | Export | Import | Export Multiple | Import Multiple | Create | Remarks |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| `emote-pimg`/`pimg` | `emote-img` | Emote Multiple Image File (.pimg) | ❌ | ❌ | ✔️ | ❌ | ❌ | |
|
||||
| `emote-dref`/`dref` | `emote-img` | Emote DPAK-referenced Image File (.dref) | ✔️ | ❌ | ❌ | ❌ | ❌ | |
|
||||
### Entis GLS engine
|
||||
| Script Type | Feature Name | Name | Export | Import | Custom Export | Custom Import | Create | Remarks |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| `entis-gls` | `entis-gls` | Entis GLS engine XML Script (.srcxml) | ✔️ | ✔️ | ❌ | ❌ | ❌ | |
|
||||
### Escu:de
|
||||
| Script Type | Feature Name | Name | Export | Import | Custom Export | Custom Import | Create | Remarks |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
@@ -133,10 +142,6 @@ msg-tool create -t <script-type> <input> <output>
|
||||
| Archive Type | Feature Name | Name | Unpack | Pack | Remarks |
|
||||
|---|---|---|---|---|---|
|
||||
| `escude-arc` | `escude-arc` | Escu:de Archive File (.bin) | ✔️ | ✔️ | |
|
||||
### Entis GLS engine
|
||||
| Script Type | Feature Name | Name | Export | Import | Custom Export | Custom Import | Create | Remarks |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| `entis-gls` | `entis-gls` | Entis GLS engine XML Script (.srcxml) | ✔️ | ✔️ | ❌ | ❌ | ❌ | |
|
||||
### ExHibit
|
||||
| Script Type | Feature Name | Name | Export | Import | Custom Export | Custom Import | Create | Remarks |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
@@ -156,8 +161,6 @@ msg-tool create -t <script-type> <input> <output>
|
||||
| Image Type | Feature Name | Name | Export | Import | Export Multiple | Import Multiple | Create | Remarks |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
| `kirikiri-tlg`/`kr-tlg` | `kirikiri-img` | Kirikiri TLG Image File (.tlg) | ✔️ | ✔️ | ❌ | ❌ | ✔️ | tlg6 is not supported when importing/creating image |
|
||||
| `kirikiri-pimg`/`kr-pimg` | `kirikiri-img` | Kirikiri Multiple Image File (.pimg) | ❌ | ❌ | ✔️ | ❌ | ❌ | |
|
||||
| `kirikiri-dref`/`kr-dref` | `kirikiri-img` | Kirikiri DPAK-referenced Image File (.dref) | ✔️ | ❌ | ❌ | ❌ | ❌ | |
|
||||
### Softpal
|
||||
| Script Type | Feature Name | Name | Export | Import | Custom Export | Custom Import | Create | Remarks |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Kirikiri DPAK-referenced Image File (.dref)
|
||||
//! Emote DPAK-referenced Image File (.dref)
|
||||
use crate::ext::io::*;
|
||||
use crate::ext::psb::*;
|
||||
use crate::scripts::base::*;
|
||||
@@ -13,7 +13,7 @@ use std::path::{Path, PathBuf};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Kirikiri DREF Script Builder
|
||||
/// Emote DREF Script Builder
|
||||
pub struct DrefBuilder {}
|
||||
|
||||
impl DrefBuilder {
|
||||
@@ -47,7 +47,7 @@ impl ScriptBuilder for DrefBuilder {
|
||||
}
|
||||
|
||||
fn script_type(&self) -> &'static ScriptType {
|
||||
&ScriptType::KirikiriDref
|
||||
&ScriptType::EmoteDref
|
||||
}
|
||||
|
||||
fn is_image(&self) -> bool {
|
||||
@@ -177,7 +177,7 @@ impl DpakLoader {
|
||||
}
|
||||
}
|
||||
|
||||
/// Kirikiri DREF Script
|
||||
/// Emote DREF Script
|
||||
pub struct Dref {
|
||||
urls: Vec<Url>,
|
||||
dir: PathBuf,
|
||||
2
src/scripts/emote/mod.rs
Normal file
2
src/scripts/emote/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod dref;
|
||||
pub mod pimg;
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Kirikiri Multiple Image File (.pimg)
|
||||
//! Emote Multiple Image File (.pimg)
|
||||
use crate::ext::io::*;
|
||||
use crate::ext::psb::*;
|
||||
use crate::scripts::base::*;
|
||||
@@ -13,7 +13,7 @@ use std::io::{Read, Seek};
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Kirikiri PImg Script Builder
|
||||
/// Emote PImg Script Builder
|
||||
pub struct PImgBuilder {}
|
||||
|
||||
impl PImgBuilder {
|
||||
@@ -75,7 +75,7 @@ impl ScriptBuilder for PImgBuilder {
|
||||
}
|
||||
|
||||
fn script_type(&self) -> &'static ScriptType {
|
||||
&ScriptType::KirikiriPimg
|
||||
&ScriptType::EmotePimg
|
||||
}
|
||||
|
||||
fn is_this_format(&self, filename: &str, buf: &[u8], buf_len: usize) -> Option<u8> {
|
||||
@@ -97,7 +97,7 @@ impl ScriptBuilder for PImgBuilder {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Kirikiri PImg Script
|
||||
/// Emote PImg Script
|
||||
pub struct PImg {
|
||||
psb: VirtualPsbFixed,
|
||||
overlay: Option<bool>,
|
||||
@@ -1,4 +1,2 @@
|
||||
//! Kirikiri Images
|
||||
pub mod dref;
|
||||
pub mod pimg;
|
||||
pub mod tlg;
|
||||
|
||||
@@ -8,6 +8,8 @@ pub mod bgi;
|
||||
pub mod cat_system;
|
||||
#[cfg(feature = "circus")]
|
||||
pub mod circus;
|
||||
#[cfg(feature = "emote-img")]
|
||||
pub mod emote;
|
||||
#[cfg(feature = "entis-gls")]
|
||||
pub mod entis_gls;
|
||||
#[cfg(feature = "escude")]
|
||||
@@ -70,10 +72,10 @@ lazy_static::lazy_static! {
|
||||
Box::new(kirikiri::ks::KsBuilder::new()),
|
||||
#[cfg(feature = "kirikiri-img")]
|
||||
Box::new(kirikiri::image::tlg::TlgImageBuilder::new()),
|
||||
#[cfg(feature = "kirikiri-img")]
|
||||
Box::new(kirikiri::image::pimg::PImgBuilder::new()),
|
||||
#[cfg(feature = "kirikiri-img")]
|
||||
Box::new(kirikiri::image::dref::DrefBuilder::new()),
|
||||
#[cfg(feature = "emote-img")]
|
||||
Box::new(emote::pimg::PImgBuilder::new()),
|
||||
#[cfg(feature = "emote-img")]
|
||||
Box::new(emote::dref::DrefBuilder::new()),
|
||||
#[cfg(feature = "kirikiri")]
|
||||
Box::new(kirikiri::mdf::MdfBuilder::new()),
|
||||
#[cfg(feature = "will-plus")]
|
||||
|
||||
16
src/types.rs
16
src/types.rs
@@ -428,6 +428,14 @@ pub enum ScriptType {
|
||||
#[cfg(feature = "circus-img")]
|
||||
/// Circus Differential Image
|
||||
CircusCrxd,
|
||||
#[cfg(feature = "emote-img")]
|
||||
#[value(alias("pimg"))]
|
||||
/// Emote PIMG image
|
||||
EmotePimg,
|
||||
#[cfg(feature = "emote-img")]
|
||||
#[value(alias("dref"))]
|
||||
/// Emote DREF(DPAK-referenced) image
|
||||
EmoteDref,
|
||||
#[cfg(feature = "entis-gls")]
|
||||
/// Entis GLS srcxml Script
|
||||
EntisGls,
|
||||
@@ -462,14 +470,6 @@ pub enum ScriptType {
|
||||
#[value(alias("kr-tlg"))]
|
||||
/// Kirikiri TLG image
|
||||
KirikiriTlg,
|
||||
#[cfg(feature = "kirikiri-img")]
|
||||
#[value(alias("kr-pimg"))]
|
||||
/// Kirikiri PIMG image
|
||||
KirikiriPimg,
|
||||
#[cfg(feature = "kirikiri-img")]
|
||||
#[value(alias("kr-dref"))]
|
||||
/// Kirikiri DREF(DPAK-referenced) image
|
||||
KirikiriDref,
|
||||
#[cfg(feature = "kirikiri")]
|
||||
#[value(alias("kr-mdf"))]
|
||||
/// Kirikiri MDF (zlib compressed) file
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use anyhow::Result;
|
||||
use windows_sys::Win32::Foundation::{ERROR_NO_UNICODE_TRANSLATION, GetLastError};
|
||||
use windows_sys::Win32::Globalization::{
|
||||
CP_UTF7, CP_UTF8, MB_ERR_INVALID_CHARS, MultiByteToWideChar, WideCharToMultiByte,
|
||||
CP_UTF7, CP_UTF8, MB_ERR_INVALID_CHARS, MultiByteToWideChar, WC_ERR_INVALID_CHARS,
|
||||
WideCharToMultiByte,
|
||||
};
|
||||
use windows_sys::Win32::System::Diagnostics::Debug::{
|
||||
FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_IGNORE_INSERTS, FormatMessageW,
|
||||
@@ -47,11 +49,22 @@ impl std::fmt::Display for WinError {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode_to_string(cp: u32, data: &[u8], check: bool) -> Result<String, WinError> {
|
||||
fn is_special_code_page(cp: u32) -> bool {
|
||||
matches!(
|
||||
cp,
|
||||
50220 | 50221 | 50222 | 50225 | 50227 | 50229 | 57002..=57011 | 65000 | 42
|
||||
)
|
||||
}
|
||||
|
||||
pub fn decode_to_string(cp: u32, data: &[u8], check: bool) -> Result<String> {
|
||||
if data.is_empty() {
|
||||
return Ok(String::new());
|
||||
}
|
||||
let dwflags = if check { MB_ERR_INVALID_CHARS } else { 0 };
|
||||
let dwflags = if check && !is_special_code_page(cp) {
|
||||
MB_ERR_INVALID_CHARS
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let needed_len = unsafe {
|
||||
MultiByteToWideChar(
|
||||
cp,
|
||||
@@ -63,12 +76,12 @@ pub fn decode_to_string(cp: u32, data: &[u8], check: bool) -> Result<String, Win
|
||||
)
|
||||
};
|
||||
if needed_len == 0 {
|
||||
return Err(WinError::from_last_error());
|
||||
return Err(WinError::from_last_error().into());
|
||||
}
|
||||
let last_error = unsafe { GetLastError() };
|
||||
if last_error == ERROR_NO_UNICODE_TRANSLATION {
|
||||
if check {
|
||||
return Err(WinError::new(last_error));
|
||||
return Err(WinError::new(last_error).into());
|
||||
} else {
|
||||
eprintln!(
|
||||
"Warning: Some characters could not be decoded in code page {}: {:?}",
|
||||
@@ -90,20 +103,25 @@ pub fn decode_to_string(cp: u32, data: &[u8], check: bool) -> Result<String, Win
|
||||
)
|
||||
};
|
||||
if result == 0 {
|
||||
return Err(WinError::from_last_error());
|
||||
return Err(WinError::from_last_error().into());
|
||||
}
|
||||
Ok(String::from_utf16_lossy(&wc))
|
||||
}
|
||||
|
||||
pub fn encode_string(cp: u32, data: &str, check: bool) -> Result<Vec<u8>, WinError> {
|
||||
pub fn encode_string(cp: u32, data: &str, check: bool) -> Result<Vec<u8>> {
|
||||
if data.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let dwflags = if check && (cp == 65001 || cp == 54936) {
|
||||
WC_ERR_INVALID_CHARS
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let wstr = data.encode_utf16().collect::<Vec<u16>>();
|
||||
let needed_len = unsafe {
|
||||
WideCharToMultiByte(
|
||||
cp,
|
||||
0,
|
||||
dwflags,
|
||||
wstr.as_ptr(),
|
||||
wstr.len() as i32,
|
||||
std::ptr::null_mut(),
|
||||
@@ -113,7 +131,7 @@ pub fn encode_string(cp: u32, data: &str, check: bool) -> Result<Vec<u8>, WinErr
|
||||
)
|
||||
};
|
||||
if needed_len == 0 {
|
||||
return Err(WinError::from_last_error());
|
||||
return Err(WinError::from_last_error().into());
|
||||
}
|
||||
let mut mb = Vec::with_capacity(needed_len as usize);
|
||||
mb.resize(needed_len as usize, 0);
|
||||
@@ -121,7 +139,7 @@ pub fn encode_string(cp: u32, data: &str, check: bool) -> Result<Vec<u8>, WinErr
|
||||
let result = unsafe {
|
||||
WideCharToMultiByte(
|
||||
cp,
|
||||
0,
|
||||
dwflags,
|
||||
wstr.as_ptr(),
|
||||
wstr.len() as i32,
|
||||
mb.as_mut_ptr(),
|
||||
@@ -136,7 +154,11 @@ pub fn encode_string(cp: u32, data: &str, check: bool) -> Result<Vec<u8>, WinErr
|
||||
};
|
||||
if used_default_char != 0 {
|
||||
if check {
|
||||
return Err(WinError::new(0));
|
||||
return Err(anyhow::anyhow!(
|
||||
"Some characters could not be encoded in code page {}: {}",
|
||||
cp,
|
||||
data
|
||||
));
|
||||
} else {
|
||||
eprintln!(
|
||||
"Warning: Some characters could not be encoded in code page {}: {}",
|
||||
@@ -146,7 +168,7 @@ pub fn encode_string(cp: u32, data: &str, check: bool) -> Result<Vec<u8>, WinErr
|
||||
}
|
||||
}
|
||||
if result == 0 {
|
||||
return Err(WinError::from_last_error());
|
||||
return Err(WinError::from_last_error().into());
|
||||
}
|
||||
Ok(mb)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user