fix: from_csplus_stagetbl ignores `encoding`

This commit is contained in:
poly000 2024-03-24 20:58:40 +08:00
parent cff5fd59e1
commit 2bc138e796
No known key found for this signature in database
1 changed files with 12 additions and 7 deletions

View File

@ -263,12 +263,12 @@ fn zero_index(s: &[u8]) -> usize {
}
fn from_encoding(s: &[u8], encoding: Option<TextScriptEncoding>) -> String {
let encoding: Option<&encoding_rs::Encoding> = encoding.map(TextScriptEncoding::into);
if let Some(encoding) = encoding {
encoding.decode_without_bom_handling(s).0.into_owned()
} else {
from_shift_jis(s)
let encoding: &encoding_rs::Encoding = encoding.into();
return encoding.decode_without_bom_handling(s).0.into_owned();
}
from_shift_jis(s)
}
fn from_shift_jis(s: &[u8]) -> String {
@ -276,6 +276,11 @@ fn from_shift_jis(s: &[u8]) -> String {
}
fn from_csplus_stagetbl(s: &[u8], is_switch: bool, encoding: Option<TextScriptEncoding>) -> String {
if let Some(encoding) = encoding {
let encoding: &encoding_rs::Encoding = encoding.into();
return encoding.decode_without_bom_handling(s).0.into_owned();
}
if is_switch {
from_utf8(s).unwrap_or("").trim_matches('\0').to_string()
} else {
@ -459,9 +464,9 @@ impl StageData {
let tileset = from_encoding(&ts_buf[0..zero_index(&ts_buf)], encoding);
let map = from_encoding(&map_buf[0..zero_index(&map_buf)], encoding);
let background = from_encoding(&back_buf[0..zero_index(&back_buf)], encoding);
let npc1 = from_encoding(&npc1_buf[0..zero_index(&npc1_buf)],encoding);
let npc2 = from_encoding(&npc2_buf[0..zero_index(&npc2_buf)],encoding);
let name = from_encoding(&name_buf[0..zero_index(&name_buf)],encoding);
let npc1 = from_encoding(&npc1_buf[0..zero_index(&npc1_buf)], encoding);
let npc2 = from_encoding(&npc2_buf[0..zero_index(&npc2_buf)], encoding);
let name = from_encoding(&name_buf[0..zero_index(&name_buf)], encoding);
let stage = StageData {
name: name.clone(),