Add new options

This commit is contained in:
2025-09-20 14:24:47 +08:00
parent 9b41742c0b
commit e794d558a8
4 changed files with 34 additions and 3 deletions

View File

@@ -476,6 +476,10 @@ pub struct Arg {
#[arg(long, global = true)]
/// Disable multiple messages section support.
pub no_multi_message: bool,
#[cfg(feature = "softpal")]
#[arg(long, global = true, visible_alias = "softpal-idx")]
/// Whether to add message index to Softpal src script when exporting.
pub softpal_add_message_index: bool,
#[command(subcommand)]
/// Command
pub command: Command,

View File

@@ -2734,6 +2734,8 @@ fn main() {
psb_process_tlg: !arg.psb_no_process_tlg,
#[cfg(feature = "softpal-img")]
pgd_fake_compress: !arg.pgd_compress,
#[cfg(feature = "softpal-img")]
softpal_add_message_index: arg.softpal_add_message_index,
});
match &arg.command {
args::Command::Export { input, output } => {

View File

@@ -64,6 +64,7 @@ pub struct SoftpalScript {
texts: MemReader,
encoding: Encoding,
label_offsets: Vec<u32>,
add_message_index: bool,
}
impl SoftpalScript {
@@ -72,7 +73,7 @@ impl SoftpalScript {
buf: Vec<u8>,
filename: &str,
encoding: Encoding,
_config: &ExtraConfig,
config: &ExtraConfig,
archive: Option<&Box<dyn Script>>,
) -> Result<Self> {
let texts = Self::load_texts_data(Self::load_file(filename, archive, "TEXT.DAT")?)?;
@@ -85,6 +86,7 @@ impl SoftpalScript {
encoding,
texts,
label_offsets,
add_message_index: config.softpal_add_message_index,
})
}
@@ -157,11 +159,21 @@ impl Script for SoftpalScript {
fn extract_messages(&self) -> Result<Vec<Message>> {
let mut messages = Vec::new();
let mut name = None;
let max_len = self.texts.data.len() as u32;
for str in &self.strs {
let addr = self.data.cpeek_u32_at(str.offset as u64)?;
if addr - 4 > max_len {
continue;
}
let idx = self.texts.cpeek_u32_at(addr as u64)?;
let text = self.texts.cpeek_cstring_at(addr as u64 + 4)?;
let text =
decode_to_string(self.encoding, text.as_bytes(), false)?.replace("<br>", "\n");
let text = if self.add_message_index {
format!("[{}]{}", idx, text)
} else {
text
};
match str.typ {
StringType::Name => {
if text.is_empty() {
@@ -186,11 +198,21 @@ impl Script for SoftpalScript {
let mut label = None;
let mut name = None;
let mut result = HashMap::new();
let max_len = self.texts.data.len() as u32;
for str in &self.strs {
let addr = self.data.cpeek_u32_at(str.offset as u64)?;
if addr - 4 > max_len {
continue;
}
let idx = self.texts.cpeek_u32_at(addr as u64)?;
let text = self.texts.cpeek_cstring_at(addr as u64 + 4)?;
let text =
let ptext =
decode_to_string(self.encoding, text.as_bytes(), false)?.replace("<br>", "\n");
let text = if self.add_message_index {
format!("[{}]{}", idx, ptext)
} else {
ptext.clone()
};
match str.typ {
StringType::Name => {
if text.is_empty() {
@@ -213,7 +235,7 @@ impl Script for SoftpalScript {
result.insert(key, messages);
messages = Vec::new();
}
label = Some(text);
label = Some(ptext);
}
}
}

View File

@@ -454,6 +454,9 @@ pub struct ExtraConfig {
/// Whether to use fake compression for Softpal Pgd images. Enabled by default.
/// WARN: Compress may cause image broken.
pub pgd_fake_compress: bool,
#[cfg(feature = "softpal")]
/// Whether to add message index to Softpal src script when exporting.
pub softpal_add_message_index: bool,
}
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]