fix(config): import original INI semantics

Load case-insensitive Language, Speed, and singular Sound values from an adjacent or embedded TDKPIN.INI before portable JSON exists, preserving Win16 defaults and clamps. Separate runtime playback from stored settings so F12 remains a silent, non-persistent toggle exactly like the original.

Test Plan:
- cargo test --all-targets
- cargo clippy --all-targets --all-features -- -D warnings
- rumdl check CHANGELOG.md RECONSTRUCTION.md README.md
- git diff --check
This commit is contained in:
2026-08-23 19:12:31 +02:00
parent fae322bb91
commit 0e7208e03a
5 changed files with 94 additions and 28 deletions
+4
View File
@@ -10,6 +10,10 @@ and this project adheres to
### Fixed
- Import exact `[Settings]` `Language`, `Speed`, and singular `Sound` values
from an adjacent/original TDKPIN.INI before creating portable JSON. Fresh
installs now inherit the distributed German help setting; F12 is again a
silent runtime-only toggle and cannot leak into a later save.
- Replace modern high-score/name overlays with the reconstructed `HighScore`
child: exact DAT993 360x300 background, heading/row coordinates, unpadded
scores, and DIALOG 32514 caption, prompt, 21-character edit, OK, and Cancel.
+3 -2
View File
@@ -76,8 +76,9 @@ box closes the program.
## Saved data
Settings and the ten-entry high-score table are stored as `save.json` in the
platform's normal per-user application-data directory. On first run, the table
is imported from the original `HISCORES.DAT` included with this reconstruction.
platform's normal per-user application-data directory. On first run, settings
are imported from an adjacent original INI (or the embedded distributed
TDKPIN.INI), and the table is imported from the original `HISCORES.DAT`.
## Reconstruction status
+1 -1
View File
@@ -28,7 +28,7 @@ implementation.
| Rules | Recovered gameplay paths | Player count, controls, the five three-line bumper-value groups, four three-line TDK-diamond groups, five doubling-value lock holes, wheel-reset target, seven-way effect selector/consumer including multiball, permanent double scoring, and four exact media/extra-ball thresholds follow original help/code paths, globals, and object flags. The ninth diamond pays the original 24,464 completion value; the following completed bank enables double scoring, and later completions add 100,000 to the per-player secondary score. Bumpers 51-53 and targets 140-147/150-152 use the original 5/20/10 active-callback countdowns and exact overlay-A render rectangles. Record 121 runs the six-callback DAT600 target rotation with exact 91x90 frames/target points and rotates the five contact/item values at state 6. Completing all five lock holes suspends physics for the full 281-callback panel animation, clears contact/item state at the recovered boundaries, and uses the exact WAVE 2013/2012/stop sequence. Turn changes mirror the original save/load of all 175 collision record states: wheel/top targets, active/contact slots, selected effect, and multiball readiness remain attached to their player. Claw contact and all initially active type-4 targets use recovered records. The top three targets score 500 each and independently enable the left, center, or right magnetic field record. Each rectangular field requires the previous position inside, applies its Real48/random pull, and deactivates when raw `1000:9b69` finds the resulting `07db/07df` prediction outside any edge. The claw state machine and release table have live differential coverage for all four random terminals. |
| Numeric scoring | Recovered gameplay values | Static scores come from the initialized 175-object ledger. Dynamic bumper progression, target-bank completion, diamond awards, 10k-160k lock bonuses, 310k transfer, six effect values, multiball mode, and all four media thresholds are transcribed from `1000:b476`, `1000:c4e1`, `1000:bc36`, and live state probes. The central helper suppresses all mutation during Tilt, applies a 2x active-multiball factor, and then independently applies the permanent 2x factor, allowing the original 4x stack. Lock and effect awards share the original per-player secondary score and display multiplier; the fifth hole transfers and clears it, increments the multiplier, and grants the recovered ball award. Score mutation uses the original 32-bit wrapping behavior, and each add operation can advance at most one media threshold. |
| High scores | Recovered visible flow; portable storage | The original 276-byte table is decoded as ten `IWIK`-XOR-obfuscated little-endian scores plus ten 22-byte names. Each player is checked immediately when their own last ball is lost; qualifying scores use the original signed-high/unsigned-low comparison and a `TDK Pinball Player`-prefilled DIALOG 32514 flow with the exact caption, prompt, 21-character limit, OK/Cancel semantics, and allowance for an empty accepted name. The `HighScore` child uses exact DAT993 at 360x300, heading `(180,27)`, name/rank X=30, right-aligned score X=320, and ten 20-pixel rows before play resumes. Persisted updates use portable JSON rather than rewriting the Win16 file. |
| Configuration | Behaviorally compatible | Sound, language, and five detail levels are retained. Storage moves from a local Win16 INI file to the platform user-data directory. |
| Configuration | Recovered behavior; portable follow-up storage | Before portable JSON exists, Rust reads the original case-insensitive `[Settings]` keys `Language`, `Speed`, and singular `Sound` from the executable-adjacent INI, falling back to the embedded distributed TDKPIN.INI. Values retain the Win16 defaults/clamps; the shipped file therefore selects German, speed 3, and sound-on because its plural `Sounds` line does not override singular `Sound`. F12 toggles only runtime playback without UI or persistence. Later explicit F10 changes use the platform user-data directory. |
| Windows UI shell | Original gameplay surface with native host shell | Win16 window ownership and GDI calls are replaced by a fixed native window, but the visible game, help resources, automatic per-player high-score flow, original keys, and 640x460 logical pixels are retained. Idle mode advances on the selected detail callback and reproduces `idle_transition_tick`: target/word-quad/record-strip chases, magnetic flashes, four-point chase, DAT801-809 item progression, and the circular BITMAP500 `WELCOME TO THE MACHINE` marquee composited over exact DAT997 regions. F2/F3 remain unassigned as in normal original operation; optional portable settings and table viewers use F10/F9 and do not replace gameplay input. |
## Extracted asset inventory
+11 -23
View File
@@ -108,6 +108,7 @@ pub struct App {
assets: Assets,
persistence: Persistence,
saved: SavedData,
sounds_enabled: bool,
render_target: RenderTarget,
screen: Screen,
return_screen: Screen,
@@ -116,8 +117,6 @@ pub struct App {
loading_started: f64,
loading_until: f64,
last_help_click: f64,
message: String,
message_until: f64,
name: String,
pending_score: u32,
attract: AttractAnimation,
@@ -128,6 +127,7 @@ impl App {
let assets = Assets::load().await;
let persistence = Persistence::new();
let saved = persistence.load();
let sounds_enabled = saved.settings.sounds;
let render_target = render_target(640, 460);
render_target.texture.set_filter(FilterMode::Nearest);
let loading_started = get_time();
@@ -135,6 +135,7 @@ impl App {
assets,
persistence,
saved,
sounds_enabled,
render_target,
screen: Screen::Loading,
return_screen: Screen::Attract,
@@ -143,8 +144,6 @@ impl App {
loading_started,
loading_until: loading_started + 1.1,
last_help_click: -1.0,
message: String::new(),
message_until: 0.0,
name: String::new(),
pending_score: 0,
attract: AttractAnimation::default(),
@@ -224,15 +223,7 @@ impl App {
fn handle_global_input(&mut self) {
if is_key_pressed(KeyCode::F12) {
self.saved.settings.sounds = !self.saved.settings.sounds;
if self.saved.settings.sounds {
"SOUND ON"
} else {
"SOUND OFF"
}
.clone_into(&mut self.message);
self.message_until = get_time() + 1.2;
self.save();
self.sounds_enabled = !self.sounds_enabled;
}
if is_key_pressed(KeyCode::F1) && self.screen != Screen::NameEntry {
if self.screen == Screen::Help {
@@ -274,7 +265,7 @@ impl App {
if is_key_pressed(KeyCode::KpAdd) || is_key_pressed(KeyCode::Equal) {
self.game = Some(Game::new(1));
self.screen = Screen::Playing;
self.assets.play(2001, self.saved.settings.sounds);
self.assets.play(2001, self.sounds_enabled);
}
}
@@ -285,7 +276,7 @@ impl App {
.as_mut()
.is_some_and(Game::add_player_before_launch)
{
self.assets.play(2001, self.saved.settings.sounds);
self.assets.play(2001, self.sounds_enabled);
}
let left_flipper = is_key_down(KeyCode::LeftControl)
|| is_key_down(KeyCode::A)
@@ -340,7 +331,7 @@ impl App {
return;
}
if let Some(resource) = event.sound_resource() {
self.assets.play(resource, self.saved.settings.sounds);
self.assets.play(resource, self.sounds_enabled);
}
}
@@ -390,7 +381,8 @@ impl App {
self.saved.settings.speed = u8::try_from(speed.clamp(1, 5)).unwrap_or(3);
}
1 => {
self.saved.settings.sounds = !self.saved.settings.sounds;
self.sounds_enabled = !self.sounds_enabled;
self.saved.settings.sounds = self.sounds_enabled;
}
_ => {
let current = Language::ALL
@@ -405,7 +397,7 @@ impl App {
self.saved.settings.language = Language::ALL[next];
}
}
self.assets.play(2012, self.saved.settings.sounds);
self.assets.play(2012, self.sounds_enabled);
self.save();
}
@@ -484,10 +476,6 @@ impl App {
Screen::HighScores => self.draw_high_scores(),
Screen::NameEntry => self.draw_name_entry(),
}
if get_time() < self.message_until {
draw_panel(232.0, 205.0, 176.0, 48.0);
draw_centered(&self.message, 229.0, 24, BLACK);
}
}
fn draw_attract(&self) {
@@ -1080,7 +1068,7 @@ impl App {
format!("GRAPHICS DETAIL / SPEED: {}", self.saved.settings.speed),
format!(
"SOUND: {}",
if self.saved.settings.sounds {
if self.sounds_enabled {
"ON"
} else {
"OFF"
+75 -2
View File
@@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
use std::{fs, io, path::PathBuf};
const ORIGINAL_HIGHSCORES: &[u8] = include_bytes!("../assets/original/HISCORES.DAT");
const ORIGINAL_INI: &str = include_str!("../../original/TDKPIN.INI");
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum Language {
@@ -67,7 +68,7 @@ pub struct SavedData {
impl Default for SavedData {
fn default() -> Self {
Self {
settings: Settings::default(),
settings: parse_original_settings(ORIGINAL_INI),
high_scores: parse_original_high_scores(ORIGINAL_HIGHSCORES),
}
}
@@ -90,7 +91,11 @@ impl Persistence {
fs::read_to_string(&self.path)
.ok()
.and_then(|text| serde_json::from_str(&text).ok())
.unwrap_or_default()
.unwrap_or_else(|| SavedData {
settings: load_adjacent_original_settings()
.unwrap_or_else(|| parse_original_settings(ORIGINAL_INI)),
high_scores: parse_original_high_scores(ORIGINAL_HIGHSCORES),
})
}
pub fn save(&self, data: &SavedData) -> io::Result<()> {
@@ -112,6 +117,51 @@ impl Persistence {
}
}
fn load_adjacent_original_settings() -> Option<Settings> {
let executable = std::env::current_exe().ok()?;
let exact_name = executable.with_extension("INI");
let original_name = executable.parent()?.join("TDKPIN.INI");
[exact_name, original_name]
.into_iter()
.find_map(|path| fs::read_to_string(path).ok())
.map(|text| parse_original_settings(&text))
}
pub fn parse_original_settings(text: &str) -> Settings {
let mut settings = Settings::default();
let mut in_settings = false;
for line in text.lines() {
let line = line.trim();
if line.starts_with('[') && line.ends_with(']') {
in_settings = line[1..line.len() - 1].eq_ignore_ascii_case("Settings");
continue;
}
if !in_settings || line.is_empty() || line.starts_with(';') {
continue;
}
let Some((key, value)) = line.split_once('=') else {
continue;
};
let Ok(value) = value.trim().parse::<i32>() else {
continue;
};
if key.trim().eq_ignore_ascii_case("Language") {
settings.language = match value {
2 => Language::German,
3 => Language::French,
4 => Language::Italian,
5 => Language::Spanish,
_ => Language::English,
};
} else if key.trim().eq_ignore_ascii_case("Speed") {
settings.speed = u8::try_from(value).ok().filter(|speed| (1..=5).contains(speed)).unwrap_or(3);
} else if key.trim().eq_ignore_ascii_case("Sound") {
settings.sounds = value != 0;
}
}
settings
}
pub fn parse_original_high_scores(bytes: &[u8]) -> Vec<HighScore> {
const HEADER: usize = 16;
const COUNT: usize = 10;
@@ -194,6 +244,29 @@ mod tests {
);
}
#[test]
fn imports_the_distributed_original_ini_with_win16_key_names() {
let settings = parse_original_settings(ORIGINAL_INI);
assert_eq!(settings.speed, 3);
assert_eq!(settings.language, Language::German);
assert!(settings.sounds, "the original reads singular Sound, not Sounds");
}
#[test]
fn original_ini_values_are_case_insensitive_and_clamped() {
let settings = parse_original_settings(
"[settings]\nlanguage=5\nSPEED=9\nSound=0\nSounds=1\n",
);
assert_eq!(settings.speed, 3);
assert_eq!(settings.language, Language::Spanish);
assert!(!settings.sounds);
let defaults = parse_original_settings("[Settings]\nLanguage=-1\nSpeed=0\n");
assert_eq!(defaults.speed, 3);
assert_eq!(defaults.language, Language::English);
assert!(defaults.sounds);
}
#[test]
fn rejects_a_table_without_the_original_signature() {
let mut corrupt = ORIGINAL_HIGHSCORES.to_vec();