Launcher : carte « Parties du menu F12 » et emplacement 97 réservé

Suit a63dd6f (parties illimitées avec miniature, dossier parties/) :
- parties.rs lit les .sav (mêmes contrôles d'en-tête que le jeu), leur image
  320×200 et la partie ; auto.sav est ignoré (déjà montré via SAVEGM.99).
- Nouvelle carte sous Sauvegardes : image du jeu au moment de la sauvegarde,
  date, lieu ; Jouer (copie dans SAVEGM.97 puis --charger 97, comme le menu
  F12), Supprimer (corbeille après confirmation), Tout afficher au-delà de 6.
- saves.rs : SAVEGM.97 rejoint 98 et 99 hors de la liste des parties et de la
  renumérotation (test).
- GUIDE FR/EN, SETTINGS.en.md (section Saved games, format des .sav).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
linkatplugandClaude Opus 5.5 committed 2026-12-05 14:25:02 +01:00
1 parent 967e54dbfb
commit ba60063cf7
6 files changed
+368 -4

No files matched your search

+7
View File
@@ -378,6 +378,13 @@ from your games (it never replaces them). It shows at the top of the card, frame
**Play** button. **Resume my game** picks it when it is more recent than your last game. A box on the
card (or F12, Game tab) turns it off. Slot `SAVEGM.98` is used by the bug reports' **Replay** button.
**F12 menu saves**: in game, F12, Jeu tab, **Sauvegarder la partie** makes a new save each time,
with no limit and without overwriting anything, along with a picture of the game at that moment.
The launcher's **F12 menu saves** card lists them (newest first) with that picture, the location and
the date: **Play** starts the game on it, **Delete** moves the file to the bin after a confirmation.
They're kept in `%APPDATA%\DoubleTroubleRecomp\parties`, apart from the original game's saves; to
load one, the launcher (like the F12 menu) goes through the reserved slot `SAVEGM.97`.
Loading at startup (that button and **Resume my game**) needs an engine that knows the `--charger`
option: if the compiled game is older, the launcher says so; just rebuild it after updating the
project.
+8
View File
@@ -388,6 +388,14 @@ encadrée de jaune, avec son bouton **Jouer**. **Reprendre ma partie** la choisi
récente que votre dernière partie. Une case de la carte (ou F12, onglet Jeu) la désactive.
L'emplacement `SAVEGM.98` sert au bouton **Rejouer** des rapports de bug.
**Parties du menu F12** : en jeu, F12, onglet Jeu, **Sauvegarder la partie** crée une nouvelle
partie à chaque appui, sans limite et sans rien écraser, avec l'image du jeu au moment de la
sauvegarde. La carte **Parties du menu F12** du launcher les liste (les plus récentes d'abord) avec
cette image, le lieu et la date : **Jouer** lance le jeu dessus, **Supprimer** met le fichier à la
corbeille après confirmation. Elles sont rangées dans `%APPDATA%\DoubleTroubleRecomp\parties`, à
part des sauvegardes du jeu d'origine ; pour en charger une, le launcher (comme le menu F12) passe
par l'emplacement réservé `SAVEGM.97`.
Le chargement au démarrage (ce bouton et **Reprendre ma partie**) demande un moteur qui connaît
l'option `--charger` : si le jeu compilé est plus ancien, le launcher le signale, et il suffit de le
recompiler après la mise à jour du projet.
+34 -2
View File
@@ -130,11 +130,43 @@ fade. The mod format is described in [MODS.en.md](MODS.en.md).
| `skip_speech` | `0` / `1` | `0` | A left click during a line skips it: the voice is cut and the speech bubble disappears. That click isn't passed on to the game, so it starts no action. In the original game, a click during a line does nothing (F12 menu, Jeu tab: « Passer les dialogues au clic »; launcher: **Game**) |
| `walk_speed` | `normal`, `fast`, `faster` | `normal` | Bud's walking speed: normal, × 1.5 or × 2. It only applies to moves the player asks for, not to cutscenes. While Bud walks, the whole game logic runs faster; music and voices don't change (F12 menu, Jeu tab: « Vitesse de marche de Bud »; launcher: **Game**) |
The automatic save goes to `SAVEGM.99`, in the saves folder. It uses the game's format and goes through a temporary file, so a crash can't leave it half written. It isn't counted in `NOFILES.DTA`: the game's Load panel doesn't show it, and it replaces none of the player's games. To load it:
The automatic save goes to `SAVEGM.99`, in the saves folder, and to `partiesuto.sav` with a thumbnail (see « Saved games » below). It uses the game's format and goes through a temporary file, so a crash can't leave it half written. It isn't counted in `NOFILES.DTA`: the game's Load panel doesn't show it, and it replaces none of the player's games. To load it:
- during play: F12 menu, Jeu tab, « Charger la sauvegarde auto ». The line shows the saved location. The game leaves the current location as if through an exit and resumes the saved game;
- during play: F12 menu, Jeu tab, « Parties sauvegardées ». It comes first in the list;
- at startup: `--charger 99` (the launcher's **Play** button on the automatic save, or **Resume my game** when it is the most recent).
## Saved games
The original game keeps its saves in `SAVEGM.01` to `SAVEGM.NN`, through its options panel. Those saves stay where they are and nothing changes for them. The F12 menu adds its own saves, as many as you like, each with a thumbnail:
- **Sauvegarder la partie** (Jeu tab) writes a new save each time; nothing is overwritten. It isn't possible during a cutscene or a line of dialogue, nor before the game has started;
- **Parties sauvegardées** opens the list: the automatic save first, then the newest. Each box shows the game picture at the time of the save, the date and the location. **Charger** resumes the chosen game (Enter does the same): the game leaves the current location as if through an exit. **Supprimer** (or Backspace) asks for confirmation, then deletes the file. The automatic save can't be deleted from here.
The launcher lists the same saves in its **F12 menu saves** card (**Play**, **Delete** to the bin).
The files are in the `parties` folder next to `settings.ini` (on Windows: `%APPDATA%\DoubleTroubleRecomp\parties`):
| File | Content |
|---|---|
| `partie-YYYYMMDD-HHMMSS.sav` | Save made by the player (`-2`, `-3`… if two are made in the same second) |
| `auto.sav` | Automatic save, rewritten at each change of location |
Format of a `.sav` (66,832 bytes, little-endian integers):
| Bytes | Content |
|---|---|
| 0–7 | `DTRSAVE1` |
| 8 | Header size: 64 |
| 12 | Location |
| 16 | Date (seconds since 1970, 64-bit) |
| 24 | Game state size: 2000 |
| 28, 32 | Picture size: 320, 200 |
| 64 | The game state: the 2000 bytes of a `SAVEGM.NN` |
| 2064 | Picture palette: 256 RGB colours, 8 bits each |
| 2832 | Game picture: 320 × 200 pixels, one byte per pixel |
The picture is the last clearly visible view of the game, not one taken during a fade to black. It is the original 320 × 200, even with the HD pack. When loading, the 2000 bytes of the game state are copied to `SAVEGM.97`, and the game loads them like its own saves: the loading logic stays the game's own. `SAVEGM.97` isn't counted in `NOFILES.DTA`.
### `[debug]`
| Key | Values | Default | Effect |
+161
View File
@@ -12,6 +12,7 @@
mod art;
mod mods;
mod music;
mod parties;
mod preview;
mod reports;
mod saves;
@@ -840,6 +841,12 @@ struct App {
progress: Option<Progress>,
/// rapports de bug du jeu, le plus récent d'abord ; suppression à confirmer ; message du dernier geste
reports: Vec<reports::Report>,
/// parties du menu F12 (dossier parties/), la plus récente d'abord, et leurs miniatures
parties: Vec<parties::Partie>,
partie_tex: std::collections::HashMap<PathBuf, Option<egui::TextureHandle>>,
partie_confirm: Option<PathBuf>,
partie_msg: Option<(bool, String)>,
parties_all: bool,
report_confirm: Option<PathBuf>,
report_msg: Option<(bool, String)>,
/// taille de la fenêtre (points egui) au moment où le zoom automatique a été changé : tant qu'elle n'a
@@ -1021,6 +1028,11 @@ impl App {
progress: None,
reports: reports::list(),
report_confirm: None,
parties: parties::list(),
partie_tex: Default::default(),
partie_confirm: None,
partie_msg: None,
parties_all: false,
report_msg: None,
zoom_wait: None,
pos_fix: None,
@@ -1613,6 +1625,153 @@ impl App {
if let Some(d) = self.saves_dir() {
self.saves = saves::list(&d);
}
self.parties = parties::list();
}
fn partie_thumb(&mut self, path: &Path) -> Option<egui::TextureHandle> {
if !self.partie_tex.contains_key(path) {
let name = format!("partie:{}", path.display());
let t = parties::thumb(path).map(|img| self.ctx.load_texture(name, to_image(&img), egui::TextureOptions::LINEAR));
self.partie_tex.insert(path.to_path_buf(), t);
}
self.partie_tex.get(path).cloned().flatten()
}
/// parties enregistrées depuis le menu F12 du jeu (illimitées, avec l'image du jeu au moment de la sauvegarde)
fn parties_card(&mut self, ui: &mut egui::Ui) {
let en = self.cfg.lang == Lang::En;
let tr = |fr: &'static str, e: &'static str| if en { e } else { fr };
const SHOWN: usize = 6;
let total = self.parties.len();
let shown = if self.parties_all { total } else { total.min(SHOWN) };
let rows: Vec<(PathBuf, u32, String)> = self.parties[..shown]
.iter()
.map(|p| {
let t = std::time::UNIX_EPOCH + std::time::Duration::from_secs(p.time.max(0) as u64);
(p.path.clone(), p.location, stamp(t, false))
})
.collect();
let thumbs: Vec<Option<egui::TextureHandle>> = rows.iter().map(|r| self.partie_thumb(&r.0)).collect();
let can_play = self.checks.can_load && self.checks.built && self.checks.game_dir.is_some() && self.busy == Busy::No && !self.game_running;
let confirm = self.partie_confirm.clone();
let msg = self.partie_msg.clone();
enum Act {
Play(PathBuf),
Ask(PathBuf),
Cancel,
Trash(PathBuf),
All(bool),
OpenFolder,
Refresh,
}
let mut act: Option<Act> = None;
card(ui, |ui| {
title(ui, tr("Parties du menu F12", "F12 menu saves"));
ui.label(RichText::new(tr(
"En jeu : F12, onglet Jeu, « Sauvegarder la partie ». Autant de parties que vous voulez, chacune avec l'image du moment.",
"In game: F12, Jeu tab, “Sauvegarder la partie”. As many saves as you like, each with a picture of the moment.",
)).weak());
if rows.is_empty() {
ui.label(RichText::new(tr("Aucune partie pour l'instant.", "No save yet.")).weak());
}
for ((path, loc, date), tex) in rows.iter().zip(&thumbs) {
ui.horizontal(|ui| {
let (r, _) = ui.allocate_exact_size(egui::vec2(96.0, 60.0), egui::Sense::hover());
match tex {
Some(t) => paint_cover(ui.painter(), r, t, 1.0, 0.0),
None => {
ui.painter().rect_filled(r, CornerRadius::ZERO, CARD_DARK);
}
}
ui.painter().rect_stroke(r, CornerRadius::ZERO, Stroke::new(1.5, Color32::BLACK), egui::StrokeKind::Inside);
ui.vertical(|ui| {
ui.label(RichText::new(date).strong());
ui.label(RichText::new(format!("{} {loc}", tr("Lieu", "Location"))).weak());
});
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if confirm.as_ref() == Some(path) {
if ui.button(tr("Annuler", "Cancel")).clicked() {
act = Some(Act::Cancel);
}
if ui.button(RichText::new(tr("Mettre à la corbeille", "Move to the bin")).color(BAD)).clicked() {
act = Some(Act::Trash(path.clone()));
}
} else {
if ui.small_button(tr("Supprimer", "Delete")).clicked() {
act = Some(Act::Ask(path.clone()));
}
if can_play
&& ui
.add(egui::Button::new(RichText::new(tr("Jouer", "Play")).strong().color(Color32::BLACK)).fill(ACCENT))
.on_hover_text(tr("Lance le jeu directement sur cette partie.", "Starts the game straight on this save."))
.clicked()
{
act = Some(Act::Play(path.clone()));
}
}
});
});
}
ui.add_space(4.0);
ui.horizontal_wrapped(|ui| {
if total > SHOWN {
let label = if shown < total {
format!("{} ({total})", tr("Tout afficher", "Show all"))
} else {
tr("Afficher moins", "Show less").to_string()
};
if ui.button(label).clicked() {
act = Some(Act::All(shown < total));
}
}
if ui.button(tr("Ouvrir le dossier", "Open folder")).clicked() {
act = Some(Act::OpenFolder);
}
if ui.button(tr("Actualiser", "Refresh")).clicked() {
act = Some(Act::Refresh);
}
});
if let Some((ok, m)) = &msg {
ui.label(RichText::new(m).color(if *ok { OK } else { BAD }));
}
});
let Some(a) = act else { return };
match a {
Act::Play(path) => {
// la partie passe par l'emplacement 97 des sauvegardes (réservé, caché de la liste), comme dans le jeu
let Some(dir) = self.saves_dir() else { return };
let _ = std::fs::create_dir_all(&dir);
match parties::export_state(&path, &dir.join(format!("SAVEGM.{}", saves::MENU_SLOT))) {
Ok(()) => {
self.partie_msg = None;
self.play_slot(Some(saves::MENU_SLOT));
}
Err(e) => self.partie_msg = Some((false, format!("{} : {e}", path.display()))),
}
}
Act::Ask(path) => self.partie_confirm = Some(path),
Act::Cancel => self.partie_confirm = None,
Act::Trash(path) => {
self.partie_confirm = None;
self.partie_msg = if parties::trash(&path) {
Some((true, tr("Partie mise à la corbeille.", "Save moved to the bin.").to_string()))
} else {
Some((false, tr("Impossible de supprimer cette partie.", "Couldn't delete this save.").to_string()))
};
self.partie_tex.remove(&path);
self.parties = parties::list();
}
Act::All(all) => self.parties_all = all,
Act::OpenFolder => {
if let Some(d) = parties::dir() {
saves::open_folder(&d);
}
}
Act::Refresh => {
self.partie_msg = None;
self.parties = parties::list();
}
}
}
fn thumb(&mut self, loc: u32) -> Option<egui::TextureHandle> {
@@ -2697,6 +2856,8 @@ impl App {
ui.add_space(10.0);
self.saves_card(ui);
ui.add_space(10.0);
self.parties_card(ui);
ui.add_space(10.0);
self.reports_card(ui);
return;
}
+153
View File
@@ -0,0 +1,153 @@
//! Parties sauvegardées du menu F12 (runtime/saves.c) : %APPDATA%\DoubleTroubleRecomp\parties\partie-AAAAMMJJ-HHMMSS[-N].sav,
//! plus auto.sav (la sauvegarde automatique, déjà montrée par le launcher via SAVEGM.99 : ignorée ici).
//! Un fichier = en-tête de 64 octets (« DTRSAVE1 », taille d'en-tête, lieu, date time_t sur 64 bits, taille de la
//! partie, largeur, hauteur), puis la partie au format SAVEGM.NN (2 000 octets), la palette (768 octets RGB) et
//! l'image du jeu (320×200, un octet par pixel). Pour la jouer, le launcher copie la partie dans SAVEGM.97
//! (emplacement réservé au chargement de ces parties) et lance le jeu avec --charger 97.
use std::path::{Path, PathBuf};
const MAGIC: &[u8; 8] = b"DTRSAVE1";
const HDR: usize = 64;
const STATE: usize = 2000;
const W: usize = 320;
const H: usize = 200;
const SIZE: usize = HDR + STATE + 768 + W * H;
pub struct Partie {
pub path: PathBuf,
pub location: u32,
/// secondes depuis 1970
pub time: i64,
}
pub fn dir() -> Option<PathBuf> {
crate::settings::path().and_then(|p| p.parent().map(|d| d.join("parties")))
}
fn u32_at(b: &[u8], o: usize) -> u32 {
u32::from_le_bytes([b[o], b[o + 1], b[o + 2], b[o + 3]])
}
/// lit et vérifie l'en-tête (mêmes contrôles que le jeu) ; renvoie (lieu, date)
fn header(path: &Path) -> Option<(u32, i64)> {
use std::io::Read;
let mut f = std::fs::File::open(path).ok()?;
if f.metadata().ok()?.len() != SIZE as u64 {
return None;
}
let mut h = [0u8; HDR];
f.read_exact(&mut h).ok()?;
let ok = &h[0..8] == MAGIC
&& u32_at(&h, 8) as usize == HDR
&& u32_at(&h, 24) as usize == STATE
&& u32_at(&h, 28) as usize == W
&& u32_at(&h, 32) as usize == H;
let loc = u32_at(&h, 12);
let time = (u32_at(&h, 16) as u64 | (u32_at(&h, 20) as u64) << 32) as i64;
(ok && (1..=98).contains(&loc)).then_some((loc, time))
}
/// parties du joueur, la plus récente d'abord (sans auto.sav)
pub fn list() -> Vec<Partie> {
dir().map(|d| list_in(&d)).unwrap_or_default()
}
pub fn list_in(d: &Path) -> Vec<Partie> {
let mut v: Vec<Partie> = std::fs::read_dir(d)
.map(|rd| {
rd.flatten()
.filter_map(|e| {
let name = e.file_name().to_string_lossy().to_string();
if !(name.starts_with("partie-") && name.ends_with(".sav")) {
return None;
}
let path = e.path();
let (location, time) = header(&path)?;
Some(Partie { path, location, time })
})
.collect()
})
.unwrap_or_default();
v.sort_by(|a, b| b.time.cmp(&a.time).then_with(|| b.path.cmp(&a.path)));
v
}
/// l'image du jeu au moment de la sauvegarde
pub fn thumb(path: &Path) -> Option<crate::art::Rgba> {
let b = std::fs::read(path).ok()?;
if b.len() != SIZE {
return None;
}
let pal = &b[HDR + STATE..HDR + STATE + 768];
let pix = &b[HDR + STATE + 768..];
let mut px = Vec::with_capacity(W * H * 4);
for &i in pix {
let c = i as usize * 3;
px.extend_from_slice(&[pal[c], pal[c + 1], pal[c + 2], 255]);
}
Some(crate::art::Rgba { w: W, h: H, px })
}
/// copie la partie au format du jeu dans `dst` (SAVEGM.97)
pub fn export_state(path: &Path, dst: &Path) -> std::io::Result<()> {
let b = std::fs::read(path)?;
if b.len() != SIZE {
return Err(std::io::Error::other("fichier de partie invalide"));
}
std::fs::write(dst, &b[HDR..HDR + STATE])
}
/// met le fichier à la corbeille (récupérable)
pub fn trash(path: &Path) -> bool {
let p = path.display().to_string().replace('\'', "''");
let script = format!(
"Add-Type -AssemblyName Microsoft.VisualBasic; \
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile('{p}', 'OnlyErrorDialogs', 'SendToRecycleBin')"
);
std::process::Command::new("powershell")
.args(["-NoProfile", "-NonInteractive", "-Command", &script])
.stdin(std::process::Stdio::null())
.status()
.is_ok_and(|s| s.success())
&& !path.exists()
}
#[cfg(test)]
mod tests {
use super::*;
fn fake(loc: u32, time: i64) -> Vec<u8> {
let mut b = vec![0u8; SIZE];
b[0..8].copy_from_slice(MAGIC);
b[8..12].copy_from_slice(&(HDR as u32).to_le_bytes());
b[12..16].copy_from_slice(&loc.to_le_bytes());
b[16..24].copy_from_slice(&time.to_le_bytes());
b[24..28].copy_from_slice(&(STATE as u32).to_le_bytes());
b[28..32].copy_from_slice(&(W as u32).to_le_bytes());
b[32..36].copy_from_slice(&(H as u32).to_le_bytes());
b[HDR] = 7; // premier octet de la partie
b[HDR + STATE + 3] = 200; // couleur 1 : rouge 200
b[HDR + STATE + 768] = 1; // premier pixel : couleur 1
b
}
#[test]
fn reads_parties() {
let d = std::env::temp_dir().join(format!("dtr-parties-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&d);
std::fs::create_dir_all(&d).unwrap();
std::fs::write(d.join("partie-20261205-140000.sav"), fake(32, 1_000)).unwrap();
std::fs::write(d.join("partie-20261205-150000.sav"), fake(5, 2_000)).unwrap();
std::fs::write(d.join("auto.sav"), fake(9, 3_000)).unwrap();
std::fs::write(d.join("partie-20261205-160000.sav"), b"court").unwrap();
let l = list_in(&d);
assert_eq!(l.iter().map(|p| (p.location, p.time)).collect::<Vec<_>>(), vec![(5, 2_000), (32, 1_000)]);
let t = thumb(&l[0].path).unwrap();
assert_eq!((t.w, t.h, &t.px[0..4]), (320, 200, &[200u8, 0, 0, 255][..]));
export_state(&l[0].path, &d.join("SAVEGM.97")).unwrap();
let s = std::fs::read(d.join("SAVEGM.97")).unwrap();
assert_eq!((s.len(), s[0]), (2000, 7));
let _ = std::fs::remove_dir_all(&d);
}
}
+5 -2
View File
@@ -25,9 +25,11 @@ pub struct Listing {
const NOFILES: &str = "NOFILES.DTA";
/// emplacements réservés, hors des parties du joueur (ni comptés dans NOFILES.DTA, ni renumérotés) :
/// 99 = sauvegarde automatique du jeu, 98 = partie d'un rapport de bug rejouée par le launcher
/// 99 = sauvegarde automatique du jeu, 98 = partie d'un rapport de bug rejouée par le launcher,
/// 97 = partie du menu F12 (dossier parties/) en cours de chargement
pub const AUTO_SLOT: u32 = 99;
pub const REPORT_SLOT: u32 = 98;
pub const MENU_SLOT: u32 = 97;
fn slot_of(name: &str) -> Option<u32> {
let up = name.to_ascii_uppercase();
@@ -49,7 +51,7 @@ pub fn list(dir: &Path) -> Listing {
for e in rd.flatten() {
let name = e.file_name().to_string_lossy().to_string();
let Some(slot) = slot_of(&name) else { continue };
if slot >= REPORT_SLOT && slot != AUTO_SLOT {
if slot >= MENU_SLOT && slot != AUTO_SLOT {
continue;
}
let data = std::fs::read(e.path()).unwrap_or_default();
@@ -182,6 +184,7 @@ mod tests {
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("SAVEGM.01"), save(3)).unwrap();
std::fs::write(dir.join("SAVEGM.02"), save(9)).unwrap();
std::fs::write(dir.join("SAVEGM.97"), save(20)).unwrap();
std::fs::write(dir.join("SAVEGM.98"), save(32)).unwrap();
std::fs::write(dir.join("SAVEGM.99"), save(15)).unwrap();
let l = list(&dir);