This commit is contained in:
2023-05-06 20:29:49 +02:00
parent 25f24ee5c3
commit 85cdecca12
5 changed files with 104 additions and 15 deletions

View File

@@ -2,7 +2,7 @@ use crate::formats::datafile::FileEntry;
use crate::formats::level::LevelLayer;
use crate::formats::rle::RleImage;
use crate::formats::sprites::Sprites;
use crate::formats::txt::{decrypt_txt, DecryptError};
use crate::formats::txt::{decrypt_exposed_txt, decrypt_txt, DecryptError};
use crate::formats::ui_xml::UiTag;
use binrw::BinRead;
use encoding_rs::WINDOWS_1252;
@@ -93,6 +93,10 @@ where
Ok(DatafileFile::Sprites(
Sprites::parse(decr.as_str()).map_err(custom_err)?,
))
} else if stem.starts_with("profile") || stem.starts_with("highscores") {
Ok(DatafileFile::Txt(
decrypt_exposed_txt(decr).map_err(custom_err)?,
))
} else {
Ok(DatafileFile::Txt(decr))
}

View File

@@ -7,6 +7,7 @@ pub enum UiTag {
Image(UiImage),
TextButton(UiTextButton),
TextArea(UiTextArea),
TextField(UiTextField),
StaticText(UiStaticText),
ToggleButton(UiToggleButton),
}
@@ -20,6 +21,24 @@ pub struct UiMenu {
pub children: Vec<UiTag>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct UiTextField {
pub name: Option<String>,
pub text: String,
#[serde(deserialize_with = "deserialize_vec2")]
pub position: [i32; 2],
#[serde(rename = "bufferVar")]
pub buffer_var: String,
#[serde(deserialize_with = "deserialize_vec4")]
pub area: [i32; 4],
#[serde(rename = "halign", default)]
pub horizontal_align: HorizontalAlign,
#[serde(rename = "fademode")]
pub fade_mode: FadeMode,
#[serde(rename = "OnSelect")]
pub on_select: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct UiImage {
pub texture: String,
@@ -172,12 +191,18 @@ where
to_vec2::<D>(String::deserialize(deserializer)?)
}
fn to_vec2<'de, D>(buf: String) -> Result<[i32; 2], D::Error>
fn deserialize_vec4<'de, D>(deserializer: D) -> Result<[i32; 4], D::Error>
where
D: Deserializer<'de>,
{
let mut values: Vec<Result<i32, D::Error>> = buf
.split(',')
to_vec4::<D>(String::deserialize(deserializer)?)
}
fn to_vec<'de, D>(buf: String) -> Result<Vec<i32>, D::Error>
where
D: Deserializer<'de>,
{
buf.split(',')
.into_iter()
.map(|value| {
// there's some typos so we have to cover that...
@@ -186,9 +211,29 @@ where
.parse::<i32>()
.map_err(|err| Error::custom(err.to_string()))
})
.collect();
let y = values.pop().ok_or(Error::custom("InvalidField"))??;
let x = values.pop().ok_or(Error::custom("InvalidField"))??;
.collect()
}
fn to_vec4<'de, D>(buf: String) -> Result<[i32; 4], D::Error>
where
D: Deserializer<'de>,
{
let mut values = to_vec::<D>(buf)?;
let w = values.pop().ok_or(Error::custom("InvalidField"))?;
let z = values.pop().ok_or(Error::custom("InvalidField"))?;
let y = values.pop().ok_or(Error::custom("InvalidField"))?;
let x = values.pop().ok_or(Error::custom("InvalidField"))?;
Ok([x, y, z, w])
}
fn to_vec2<'de, D>(buf: String) -> Result<[i32; 2], D::Error>
where
D: Deserializer<'de>,
{
let mut values = to_vec::<D>(buf)?;
let y = values.pop().ok_or(Error::custom("InvalidField"))?;
let x = values.pop().ok_or(Error::custom("InvalidField"))?;
Ok([x, y])
}

View File

@@ -3,7 +3,7 @@ use godot::builtin::{Array, Dictionary, GodotString, ToVariant, Vector2};
use godot::engine::control::LayoutPreset;
use godot::engine::global::HorizontalAlignment;
use godot::engine::node::InternalMode;
use godot::engine::{load, Button, Control, Label, Node, SpinBox, TextureRect};
use godot::engine::{load, Button, Control, Label, LineEdit, Node, SpinBox, TextureRect};
use godot::obj::{Gd, Inherits, Share};
use itertools::Itertools;
@@ -43,6 +43,19 @@ pub fn convert_ui(ui: UiTag, base_path: &str) -> Gd<Node> {
attach_children(&mut text_area, area.children, base_path);
text_area.upcast()
}
UiTag::TextField(field) => {
let mut text_field = LineEdit::new_alloc();
if let Some(name) = field.name {
text_field.set_name(name.into());
}
text_field.set_text(field.text.into());
text_field.set_horizontal_alignment(field.horizontal_align.into());
text_field.set_position(to_vec2([field.area[0], field.area[1]]), false);
text_field.set_size(to_vec2([field.area[2], field.area[3]]), false);
text_field.set_meta("buffer_var".into(), field.buffer_var.to_variant());
attach_call_meta(&mut text_field, field.on_select);
text_field.upcast()
}
UiTag::ToggleButton(toggle) => {
let mut spin_box = SpinBox::new_alloc();
spin_box.set_position(to_vec2(toggle.position), false);

View File

@@ -66,9 +66,7 @@ fn extract(datafile: &Datafile, file: &mut File) {
}
fn main() {
let file_name = Some(NullString::from(
"data\\menu\\screens\\options_controls.xml",
));
let file_name = Some(NullString::from("data\\profile_00.txt"));
let dat_path = "E:\\Games\\Schatzjäger\\data\\datafile.dat";
let mut file = File::open(dat_path).unwrap();
@@ -102,7 +100,10 @@ fn main() {
let sprites = Sprites::parse(decr.as_str()).unwrap();
println!("{:#?}", sprites);
} else {
println!("{}", decrypt_txt(data.into_iter()).unwrap())
println!(
"{}",
decrypt_exposed_txt(decrypt_txt(data.into_iter()).unwrap()).unwrap()
)
}
}
Some("rle") => {