Parties sauvegardées illimitées, avec miniature (menu F12, onglet Jeu)

- saves.c : une partie par fichier dans « parties » à côté de settings.ini
  (partie-AAAAMMJJ-HHMMSS.sav, auto.sav). En-tête de 64 octets, les 2000
  octets d'un SAVEGM.NN, puis l'image 320×200 du jeu et sa palette. Écriture
  par fichier temporaire. Format : docs/SETTINGS.md.
- L'image est la dernière vue bien visible (copiée une image sur 8, pas
  pendant un fondu au noir).
- Chargement : la partie est copiée dans SAVEGM.97 et le jeu la charge comme
  les siennes (FN_PARTIE_CHARGE) ; SAVEGM.97 n'entre pas dans NOFILES.DTA.
- Sauvegarde refusée pendant une scène ou une réplique.
- Onglet Jeu : « Sauvegarder la partie » (nouvelle partie à chaque appui) et
  « Parties sauvegardées » : grille de miniatures, Charger, Supprimer (avec
  confirmation ; pas la sauvegarde auto), Retour. Elle remplace « Charger la
  sauvegarde auto » : auto.sav est en tête de liste.
- La sauvegarde automatique écrit aussi auto.sav (SAVEGM.99 reste, pour
  --charger 99).
- host_headless : --parties D (défaut parties_essai), --sauver I,
  --charger-partie I,K, page P_6 avec --menu-bmp.
- Vérifié sans fenêtre (cuisine) : parties identiques à SAVEGM.07 sur les
  0x744 octets lus ; sortie vers le lieu 31 puis chargement : retour au
  lieu 32, SAVEGM.97 identique à la partie, NOFILES.DTA inchangé.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
linkatplugandClaude Opus 5.5 committed 2026-12-05 14:18:33 +01:00
1 parent 603bedbe90
commit a63dd6f641
13 files changed
+704 -47

No files matched your search

+2 -2
View File
@@ -26,11 +26,11 @@ set COMMIT=inconnu
for /f %%c in ('git rev-parse --short HEAD 2^>nul') do set COMMIT=%%c
git diff --quiet HEAD -- runtime 2>nul || set COMMIT=%COMMIT%+
set CFLAGS=%CFLAGS% /DDTR_COMMIT=\"%COMMIT%\"
cl %CFLAGS% /c runtime\cpu.c runtime\fpu.c runtime\loader.c runtime\dos.c runtime\machine.c runtime\audio.c runtime\ail.c runtime\menu.c runtime\zones.c runtime\report.c runtime\crash.c runtime\mods.c runtime\hd.c runtime\png.c runtime\sprites.c runtime\overrides.c runtime\main.c build\gen_tucker\*.c build\gen_intro\*.c || exit /b 1
cl %CFLAGS% /c runtime\cpu.c runtime\fpu.c runtime\loader.c runtime\dos.c runtime\machine.c runtime\audio.c runtime\ail.c runtime\menu.c runtime\zones.c runtime\report.c runtime\saves.c runtime\crash.c runtime\mods.c runtime\hd.c runtime\png.c runtime\sprites.c runtime\overrides.c runtime\main.c build\gen_tucker\*.c build\gen_intro\*.c || exit /b 1
cl %CFLAGS% /c runtime\host_headless.c runtime\host_sdl.c runtime\gfx_gl.c runtime\hd_sprites.c runtime\dxt.c || exit /b 1
if not exist build\lib mkdir build\lib
lib /nologo /OUT:build\lib\jeu.lib build\obj\cpu.obj build\obj\fpu.obj build\obj\loader.obj build\obj\dos.obj build\obj\machine.obj build\obj\audio.obj build\obj\ail.obj build\obj\menu.obj build\obj\zones.obj build\obj\report.obj build\obj\crash.obj build\obj\mods.obj build\obj\hd.obj build\obj\png.obj build\obj\sprites.obj build\obj\overrides.obj build\obj\main.obj build\obj\tucker_*.obj build\obj\intro_*.obj || exit /b 1
lib /nologo /OUT:build\lib\jeu.lib build\obj\cpu.obj build\obj\fpu.obj build\obj\loader.obj build\obj\dos.obj build\obj\machine.obj build\obj\audio.obj build\obj\ail.obj build\obj\menu.obj build\obj\zones.obj build\obj\report.obj build\obj\saves.obj build\obj\crash.obj build\obj\mods.obj build\obj\hd.obj build\obj\png.obj build\obj\sprites.obj build\obj\overrides.obj build\obj\main.obj build\obj\tucker_*.obj build\obj\intro_*.obj || exit /b 1
link /nologo /STACK:67108864 /OUT:build\tucker_headless.exe build\obj\host_headless.obj build\lib\jeu.lib || exit /b 1
rem icone de l'exe (assets\icon, voir tools\make_icon.py) ; sans rc.exe, le jeu se compile sans icone
+1 -1
View File
@@ -61,7 +61,7 @@ INTRO.EXE stays local (`build/`). Mods replace files at runtime, never touching
- [x] Skip dialogue lines with a click; speed up Bud's walking
- [x] Start on a saved game (`--charger N`): "Resume my game" and a Play button per save in the
launcher; the engine loads the game through the game's own routine
- [ ] Autosave; unlimited save slots with thumbnails
- [x] Autosave; unlimited save slots with thumbnails
- [ ] Gamepad: joystick cursor, verb wheel
- [ ] Always-on subtitles
+1 -1
View File
@@ -64,7 +64,7 @@ jamais modifier les originaux.
- [x] Passer les dialogues au clic ; accélérer les déplacements de Bud
- [x] Démarrer sur une sauvegarde (`--charger N`) : « Reprendre ma partie » et bouton Jouer par
sauvegarde dans le launcher ; le moteur charge la partie par la routine du jeu
- [ ] Sauvegarde automatique ; emplacements illimités avec miniature
- [x] Sauvegarde automatique ; emplacements illimités avec miniature
- [ ] Manette : curseur au joystick, roue des verbes
- [ ] Sous-titres toujours affichés
+32 -2
View File
@@ -116,11 +116,41 @@ Les mods sont lus au démarrage : un changement de `[mods]` prend effet au lance
| `skip_speech` | `0` / `1` | `0` | Un clic gauche pendant une réplique la passe : la voix est coupée et la bulle disparaît. Ce clic n'est pas transmis au jeu, et ne lance donc pas d'action. Dans le jeu d'origine, un clic pendant une réplique ne fait rien (menu F12, onglet Jeu : « Passer les dialogues au clic ») |
| `walk_speed` | `normal`, `fast`, `faster` | `normal` | Vitesse de marche de Bud : normale, × 1,5 ou × 2. Elle ne s'applique qu'aux déplacements demandés par le joueur, pas aux scènes. Pendant la marche, toute la logique du jeu avance plus vite ; la musique et les voix ne changent pas (menu F12, onglet Jeu : « Vitesse de marche de Bud ») |
La sauvegarde automatique va dans `SAVEGM.99`, dans le dossier des sauvegardes. Elle est au format du jeu et passe par un fichier temporaire, pour qu'un plantage ne la laisse pas à moitié écrite. Elle n'est pas comptée dans `NOFILES.DTA` : le panneau Charger du jeu ne la montre pas, et elle ne remplace aucune partie du joueur. Pour la recharger :
La sauvegarde automatique va dans `SAVEGM.99`, dans le dossier des sauvegardes, et dans `parties\auto.sav` avec une miniature (voir « Parties sauvegardées » ci-dessous). Elle est au format du jeu et passe par un fichier temporaire, pour qu'un plantage ne la laisse pas à moitié écrite. Elle n'est pas comptée dans `NOFILES.DTA` : le panneau Charger du jeu ne la montre pas, et elle ne remplace aucune partie du joueur. Pour la recharger :
- en cours de partie : menu F12, onglet Jeu, « Charger la sauvegarde auto ». La ligne indique le lieu sauvegardé. Le jeu quitte le lieu courant comme par une sortie et reprend la partie sauvegardée ;
- en cours de partie : menu F12, onglet Jeu, « Parties sauvegardées ». Elle est la première de la liste ;
- au lancement : `--charger 99`.
## Parties sauvegardées
Le jeu d'origine garde ses parties dans `SAVEGM.01` à `SAVEGM.NN`, par son panneau d'options. Ces parties restent à leur place et rien n'y change. Le menu F12 ajoute ses propres parties, en nombre illimité, chacune avec une miniature :
- **Sauvegarder la partie** (onglet Jeu) écrit une nouvelle partie à chaque appui ; rien n'est écrasé. Ce n'est pas possible pendant une scène ou une réplique, ni avant le début de la partie ;
- **Parties sauvegardées** ouvre la liste : la sauvegarde automatique d'abord, puis les plus récentes. Chaque case montre l'image du jeu au moment de la sauvegarde, la date et le lieu. **Charger** reprend la partie choisie (Entrée fait de même) : le jeu quitte le lieu courant comme par une sortie. **Supprimer** (ou Retour arrière) demande une confirmation, puis efface le fichier. La sauvegarde automatique ne se supprime pas d'ici.
Les fichiers sont dans le dossier `parties` à côté de `settings.ini` (sous Windows : `%APPDATA%\DoubleTroubleRecomp\parties`) :
| Fichier | Contenu |
|---|---|
| `partie-AAAAMMJJ-HHMMSS.sav` | Partie sauvegardée par le joueur (`-2`, `-3`… si deux le sont dans la même seconde) |
| `auto.sav` | Sauvegarde automatique, réécrite à chaque changement de lieu |
Format d'un `.sav` (66 832 octets, entiers petit-boutistes) :
| Octets | Contenu |
|---|---|
| 0–7 | `DTRSAVE1` |
| 8 | Taille de l'en-tête : 64 |
| 12 | Lieu |
| 16 | Date (secondes depuis 1970, sur 64 bits) |
| 24 | Taille de la partie : 2000 |
| 28, 32 | Taille de l'image : 320, 200 |
| 64 | La partie : les 2000 octets d'un `SAVEGM.NN` |
| 2064 | Palette de l'image : 256 couleurs RVB sur 8 bits |
| 2832 | Image du jeu : 320 × 200 pixels, un octet par pixel |
L'image est la dernière vue bien visible du jeu, pas une image prise pendant un fondu au noir. Elle est en 320 × 200 d'origine, même avec le pack HD. Au chargement, les 2000 octets de la partie sont copiés dans `SAVEGM.97`, et le jeu les charge comme ses propres sauvegardes : la logique de chargement reste la sienne. `SAVEGM.97` n'est pas compté dans `NOFILES.DTA`.
### `[debug]`
| Clé | Valeurs | Défaut | Effet |
+1
View File
@@ -125,6 +125,7 @@
#define TUCKER_NOFILES_TAILLE 10 /* taille de NOFILES.DTA */
#define TUCKER_PARTIE_AUTO 99 /* SAVEGM.99 : sauvegarde automatique (hors NOFILES.DTA, invisible du jeu) */
#define TUCKER_PARTIE_RAPPORT 98 /* SAVEGM.98 : partie jointe aux rapports de bug */
#define TUCKER_PARTIE_MENU 97 /* SAVEGM.97 : partie du menu F12 en cours de chargement (saves.c) */
/* ================================================================== INTRO.EXE */
#define INTRO_FN_INT386X I_000222a4 /* int386x, même bibliothèque Watcom que FN_INT386X */
+32 -1
View File
@@ -12,7 +12,10 @@
* --charger-a I,N demande à l'image I le chargement de SAVEGM.NN, comme le menu F12 en cours de partie
* --menu-bmp P dessine les pages du menu (réglages, « Signaler un bug », rapport écrit) sur la dernière image,
* dans P_1.bmp, P_2.bmp, P_3.bmp (960×720), puis les onglets Jeu et Son dans P_4.bmp et P_5.bmp ;
* avec --rapport, la page 3 écrit vraiment le rapport
* avec --rapport, la page 3 écrit vraiment le rapport ; la page des parties sauvegardées dans P_6.bmp
* --parties D dossier des parties du menu F12 (saves.c), défaut parties_essai : jamais celui du joueur
* --sauver I sauvegarde une nouvelle partie à l'image I, comme « Sauvegarder la partie » (répétable)
* --charger-partie I,K charge à l'image I la K-ième partie de la liste du menu (0 : la première)
*/
#include <stdio.h>
#include <stdlib.h>
@@ -21,6 +24,7 @@
#include "rt.h"
#include "menu.h"
#include "report.h"
#include "saves.h"
int host_quit;
static uint64_t vtime;
@@ -36,10 +40,13 @@ static unsigned load_at;
static uint32_t watch_addr[8], watch_val[8];
static int nwatch;
static int load_slot_at;
static unsigned save_at[8], load_file_at;
static int nsave, load_file_k;
int host_init(int argc, char **argv) {
int i;
for (i = 1; i < argc; i++) if (!strcmp(argv[i], "--auto")) settings.autosave = 1;
saves_set_root("parties_essai");
for (i = 1; i + 1 < argc; i++) {
if (!strcmp(argv[i], "--images")) max_frames = (unsigned)atoi(argv[i + 1]);
else if (!strcmp(argv[i], "--tous")) every = (unsigned)atoi(argv[i + 1]);
@@ -55,6 +62,9 @@ int host_init(int argc, char **argv) {
}
}
else if (!strcmp(argv[i], "--menu-bmp")) menu_prefix = argv[i + 1];
else if (!strcmp(argv[i], "--parties")) saves_set_root(argv[i + 1]);
else if (!strcmp(argv[i], "--sauver") && nsave < 8) save_at[nsave++] = (unsigned)atoi(argv[i + 1]);
else if (!strcmp(argv[i], "--charger-partie")) sscanf(argv[i + 1], "%u,%d", &load_file_at, &load_file_k);
else if (!strcmp(argv[i], "--charger-a")) sscanf(argv[i + 1], "%u,%d", &load_at, &load_slot_at);
else if (!strcmp(argv[i], "--suivre")) {
const char *p = argv[i + 1];
@@ -168,6 +178,11 @@ static void menu_pages(void) {
if (r & MENU_REPORT)
menu_report_done(report_dir ? report_write(menu_report_type(), menu_report_comment(), NULL, 0, 0, NULL) : NULL);
write_menu_bmp(menu_prefix, 3);
menu_key(MK_BACK); menu_key(MK_BACK); /* retour aux réglages */
menu_key(MK_NEXT_TAB); /* onglet Jeu, sur la rangée des boutons */
menu_key(MK_UP); menu_key(MK_OK); /* « Parties sauvegardées » : Ouvrir */
menu_key(MK_RIGHT);
write_menu_bmp(menu_prefix, 6);
}
void host_frame(void) {
@@ -197,6 +212,22 @@ void host_frame(void) {
fprintf(stderr, "[essai] image %u, lieu %d : chargement de la partie %d demandé\n", frame, (int)RD32(0x4680cu), load_slot_at);
game_request_load(load_slot_at);
}
for (i = 0; i < nsave; i++)
if (frame == save_at[i]) {
SaveInfo si;
char why[64];
if (saves_write(&si)) fprintf(stderr, "[essai] image %u : %s écrite (lieu %d)\n", frame, si.file, si.lieu);
else { saves_can_save(why, sizeof why); fprintf(stderr, "[essai] image %u : sauvegarde refusée (%s)\n", frame, why); }
}
if (load_file_at && frame == load_file_at) {
int n;
SaveInfo *l = saves_list(&n);
if (load_file_k >= 0 && load_file_k < n)
fprintf(stderr, "[essai] image %u, lieu %d : chargement de %s (lieu %d) : %s\n", frame, (int)RD32(0x4680cu),
l[load_file_k].file, l[load_file_k].lieu, saves_load(l[load_file_k].file) ? "demandé" : "refusé");
else fprintf(stderr, "[essai] --charger-partie : %d parties seulement\n", n);
free(l);
}
if (frame >= max_frames) {
fprintf(stderr, "[essai] fin, image %u, lieu %d\n", frame, (int)RD32(0x4680cu));
if (mem_out) {
-1
View File
@@ -619,7 +619,6 @@ static void menu_modal(void) {
}
if (r & MENU_REPORT) { write_report(); dirty = 1; }
if (r & MENU_OPEN_DIR) open_folder(menu_report_dir());
if (r & MENU_LOAD_AUTO) game_load_autosave(); /* au prochain tour du jeu, menu fermé */
if (r & MENU_DISPLAY) apply_display();
if (r & MENU_QUIT) host_quit = 1;
if (r & MENU_CLOSE) open = 0;
+314 -18
View File
@@ -4,10 +4,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "menu.h"
#include "menu_font.h"
#include "zones.h"
#include "report.h"
#include "saves.h"
#include "rt.h"
#ifdef _WIN32
#include <direct.h>
@@ -449,7 +451,8 @@ static Item items[] = {
{"Passer les dialogues au clic", IT_SWITCH, &settings.skip_speech, 0, 1, 1, NULL},
{"Vitesse de marche de Bud", IT_CHOICE, &settings.walk_speed, 0, 2, 1, walk_labels},
{"Sauvegarde automatique", IT_SWITCH, &settings.autosave, 0, 1, 1, NULL},
{"Charger la sauvegarde auto", IT_ACTION, NULL, 0, 0, 0, NULL},
{"Sauvegarder la partie", IT_ACTION, NULL, 0, 0, 0, NULL},
{"Parties sauvegardées", IT_ACTION, NULL, 0, 0, 0, NULL},
{NULL, IT_BUTTONS, NULL, 0, 1, 1, NULL},
};
#define N_ITEMS ((int)(sizeof items / sizeof items[0]))
@@ -458,7 +461,8 @@ static Item items[] = {
#define ITEM_HD 11
#define ITEM_HD_LAST 14 /* Décors, personnages et objets, barre d'actions : sous l'interrupteur du pack */
#define FIRST_GAME 15
#define ITEM_LOAD_AUTO 18
#define ITEM_SAVE_NOW 18
#define ITEM_SAVES 19
/* onglets : chacun montre une suite d'éléments ; la rangée des boutons est commune */
#define N_TABS 3
@@ -468,12 +472,18 @@ static const int tab_first[N_TABS + 1] = {0, FIRST_DISPLAY, FIRST_GAME, N_ITEMS
static int tab = 1; /* gardé d'une ouverture du menu à l'autre */
static int sel, button, dragging = -1, last_mx = -1, last_my = -1;
enum { PAGE_MAIN, PAGE_REPORT, PAGE_DONE };
enum { PAGE_MAIN, PAGE_REPORT, PAGE_DONE, PAGE_SAVES };
static int page;
static void report_open(void);
static int report_key(MenuKey k);
static int report_mouse(int x, int y, int down, int moved);
static void report_draw(void);
static void saves_open(void);
static int saves_key(MenuKey k);
static int saves_mouse(int x, int y, int down, int moved, int wheel);
static void saves_draw(void);
static int saves_count = -1; /* parties dans le dossier (-1 : à compter) */
static char saved_msg[64]; /* « Sauvegardée à 14:32 » après Sauvegarder la partie */
/* géométrie */
#define PANEL_X0 150
@@ -525,13 +535,41 @@ static void set_tab(int t) {
if (sel >= 0 && sel != N_ITEMS - 1) sel = tab_first[tab];
}
/* « Charger la sauvegarde auto » : 1 si possible ; why : raison sinon, ou lieu de la sauvegarde */
static int autosave_ready(char *why, size_t n) {
int lieu = 0;
if (!game_in_location()) { snprintf(why, n, "pas de partie en cours"); return 0; }
if (!game_autosave_info(&lieu)) { snprintf(why, n, "aucune pour l'instant"); return 0; }
snprintf(why, n, "lieu %d", lieu);
return 1;
static int count_saves(void) {
if (saves_count < 0) { SaveInfo *l = saves_list(&saves_count); free(l); }
return saves_count;
}
/* éléments d'action : 1 si possible ; why : état (dernière sauvegarde, nombre de parties) ou raison */
static int action_ready(int i, char *why, size_t n) {
if (i == ITEM_SAVE_NOW) {
int ok = saves_can_save(why, n);
if (ok) snprintf(why, n, "%s", saved_msg);
return ok;
}
{
int c = count_saves();
if (c == 0) snprintf(why, n, "aucune pour l'instant");
else snprintf(why, n, c == 1 ? "%d partie" : "%d parties", c);
return 1; /* la page s'ouvre même vide */
}
}
static int save_now(void) {
SaveInfo si;
if (!saves_write(&si)) { snprintf(saved_msg, sizeof saved_msg, "échec de l'écriture"); return MENU_STAY; }
{
time_t t = (time_t)si.time;
struct tm tm;
#ifdef _WIN32
localtime_s(&tm, &t);
#else
localtime_r(&t, &tm);
#endif
snprintf(saved_msg, sizeof saved_msg, "sauvegardée à %02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec);
}
saves_count = -1;
return MENU_STAY;
}
static int button_x(int b) {
@@ -573,6 +611,7 @@ void menu_open(int screen_w, int screen_h, int usable_w, int usable_h) {
items[ITEM_SCALE].hi = n_res - 1;
sel = tab_first[tab]; button = 0; dragging = -1; last_mx = last_my = -1;
page = PAGE_MAIN;
saves_count = -1; saved_msg[0] = 0;
}
static int set_value(int i, int v) {
@@ -591,7 +630,11 @@ static int activate(void) {
if (sel == SEL_TABS) { sel = tab_first[tab]; return MENU_STAY; }
it = &items[sel];
switch (it->type) {
case IT_ACTION: return autosave_ready(why, sizeof why) ? MENU_LOAD_AUTO | MENU_CLOSE : MENU_STAY;
case IT_ACTION:
if (!action_ready(sel, why, sizeof why)) return MENU_STAY;
if (sel == ITEM_SAVE_NOW) return save_now();
saves_open();
return MENU_STAY;
case IT_SWITCH: return set_value(sel, !*it->val);
case IT_CHOICE: return set_value(sel, *it->val >= it->hi ? it->lo : *it->val + 1);
case IT_BUTTONS:
@@ -603,6 +646,7 @@ static int activate(void) {
int menu_key(MenuKey k) {
Item *it = sel >= 0 ? &items[sel] : NULL;
if (page == PAGE_SAVES) return saves_key(k);
if (page != PAGE_MAIN) return report_key(k);
if (k == MK_PREV_TAB || k == MK_NEXT_TAB) { set_tab(tab + (k == MK_NEXT_TAB ? 1 : -1)); return MENU_STAY; }
if (!it) { /* rangée des onglets */
@@ -662,6 +706,7 @@ static int hit(int x, int y, int *b) {
int menu_mouse(int x, int y, int down, int up, int wheel) {
int b, i, r = MENU_STAY, moved = x != last_mx || y != last_my;
last_mx = x; last_my = y;
if (page == PAGE_SAVES) return saves_mouse(x, y, down, moved, wheel);
if (page != PAGE_MAIN) return report_mouse(x, y, down, moved);
if (dragging < 0 && (i = tab_hit(x, y)) >= 0) { /* onglets */
if (moved) sel = SEL_TABS;
@@ -742,12 +787,12 @@ static void draw_choice(int y, const Item *it, int active, int dim) {
static int wrap_text(int x, int y, int w, const char *s, uint32_t rgb);
/* élément d'action : petit bouton « Charger » à droite, précédé de l'état (lieu, ou raison) */
static void draw_action(int y, int ready, int active, const char *info) {
int cy = y + ROW_H / 2, x1 = CTRL_X1, w = text_width(&font_small, "Charger") + 32, x0 = x1 - w;
static void draw_action(int y, int ready, int active, const char *label, const char *info) {
int cy = y + ROW_H / 2, x1 = CTRL_X1, w = text_width(&font_small, label) + 32, x0 = x1 - w;
if (ready) {
if (active) round_rect(x0, cy - 14, x1, cy + 14, 14, C_ACCENT, 255);
else outline_rect(x0, cy - 14, x1, cy + 14, 14, 1.5f, C_BORDER, 255);
text(&font_small, x0 + 16, cy - font_small.height / 2, "Charger", active ? C_DARK : C_TEXT, 255);
text(&font_small, x0 + 16, cy - font_small.height / 2, label, active ? C_DARK : C_TEXT, 255);
x0 -= 14;
} else x0 = x1;
text(&font_small, x0 - text_width(&font_small, info), cy - font_small.height / 2, info, C_MUTED, 255);
@@ -760,6 +805,7 @@ void menu_draw(uint32_t *px) {
round_rect(PANEL_X0 + 6, PANEL_Y0 + 10, PANEL_X1 + 6, PANEL_Y1 + 10, 22, 0, 90); /* ombre */
round_rect(PANEL_X0, PANEL_Y0, PANEL_X1, PANEL_Y1, 22, C_PANEL, 245);
outline_rect(PANEL_X0, PANEL_Y0, PANEL_X1, PANEL_Y1, 22, 2, C_BORDER, 255);
if (page == PAGE_SAVES) { saves_draw(); return; }
if (page != PAGE_MAIN) { report_draw(); return; }
text(&font_title, PANEL_X0 + 44, PANEL_Y0 + 26, "Réglages", C_ACCENT, 255);
round_rect(PANEL_X0 + 44, 114, PANEL_X1 - 44, 116, 1, C_BORDER, 255);
@@ -774,7 +820,9 @@ void menu_draw(uint32_t *px) {
wrap_text(PANEL_X0 + 44, row_y(tab_first[3] - 1) + ROW_H + 18, PANEL_X1 - PANEL_X0 - 88,
"La marche accélérée ne joue que sur les déplacements demandés, pas sur les scènes. "
"La sauvegarde automatique est écrite à chaque changement de lieu, dans un emplacement à part : "
"elle ne remplace aucune de vos parties.", C_MUTED);
"elle ne remplace aucune de vos parties. Les parties sauvegardées ici sont en nombre illimité, "
"chacune avec sa miniature, dans le dossier \"parties\" à côté des réglages ; celles du jeu "
"(panneau d'options) restent à leur place.", C_MUTED);
for (i = 0; i < N_ITEMS; i++) {
const Item *it = &items[i];
@@ -800,8 +848,8 @@ void menu_draw(uint32_t *px) {
int dim = (i == ITEM_SCALE && settings.fullscreen) || (i >= ITEM_HD && i <= ITEM_HD_LAST && !menu_hd_available)
|| (i > ITEM_HD && i <= ITEM_HD_LAST && !settings.hd_pack);
char why[64];
int ready = i == ITEM_LOAD_AUTO && autosave_ready(why, sizeof why);
if (i == ITEM_LOAD_AUTO) dim = !ready;
int ready = it->type == IT_ACTION && action_ready(i, why, sizeof why);
if (it->type == IT_ACTION) dim = !ready;
int lw = text(&font_normal, PANEL_X0 + 44, y + (ROW_H - font_normal.height) / 2, it->label,
dim ? C_MUTED : C_TEXT, 255);
if (i == ITEM_HD && !menu_hd_available)
@@ -810,7 +858,7 @@ void menu_draw(uint32_t *px) {
case IT_SLIDER: draw_slider(y, it, active); break;
case IT_SWITCH: draw_switch(y, *it->val, active); break;
case IT_CHOICE: draw_choice(y, it, active, dim); break;
case IT_ACTION: draw_action(y, ready, active, why); break;
case IT_ACTION: draw_action(y, ready, active, i == ITEM_SAVE_NOW ? "Sauvegarder" : "Ouvrir", why); break;
}
}
}
@@ -1085,3 +1133,251 @@ static void report_draw(void) {
r_hint(menu_text_wanted() ? "Tapez le commentaire · Entrée : suite · Échap : retour"
: "Flèches : choisir · Entrée : valider · Échap : retour");
}
/* ================================================================== page « Parties sauvegardées » */
#define S_COLS 3
#define S_ROWS 2
#define S_TW 176 /* miniature 4:3 */
#define S_TH 132
#define S_GAP_X 22
#define S_GY0 132
#define S_CELL_H 194
#define S_INFO_Y 536
#define S_CACHE 12
static SaveInfo *slist;
static int sn, ssel, stop, sfocus, sbutton, sconfirm; /* sfocus : 0 grille, 1 boutons */
static char smsg[96];
static struct { char file[64]; int ok; uint32_t px[S_TW * S_TH]; } scache[S_CACHE];
static int scache_next;
static void saves_reload(void) {
free(slist);
slist = saves_list(&sn);
saves_count = sn;
if (ssel >= sn) ssel = sn - 1;
if (ssel < 0) ssel = 0;
}
static void saves_open(void) {
int k;
for (k = 0; k < S_CACHE; k++) scache[k].file[0] = 0; /* auto.sav change à chaque lieu */
page = PAGE_SAVES;
ssel = 0; stop = 0; sconfirm = 0; smsg[0] = 0;
saves_reload();
sfocus = sn ? 0 : 1; sbutton = sn ? 0 : 2;
}
static void saves_close(void) { page = PAGE_MAIN; free(slist); slist = NULL; sn = 0; }
static int s_can_load(void) { return sn > 0 && game_in_location(); }
static int s_can_delete(void) { return sn > 0 && !slist[ssel].is_auto; }
static void s_scroll_to_sel(void) {
int row = ssel / S_COLS;
if (row < stop) stop = row;
if (row >= stop + S_ROWS) stop = row - S_ROWS + 1;
}
static int s_cell_x(int c) { return PANEL_X0 + 44 + c * (S_TW + S_GAP_X); }
static int s_cell_y(int r) { return S_GY0 + r * S_CELL_H; }
/* case visée (index dans la liste), ou -1 */
static int s_cell_hit(int x, int y) {
int r, c;
for (r = 0; r < S_ROWS; r++)
for (c = 0; c < S_COLS; c++) {
int i = (stop + r) * S_COLS + c, x0 = s_cell_x(c), y0 = s_cell_y(r);
if (i < sn && x >= x0 && x < x0 + S_TW && y >= y0 && y < y0 + S_TH + 48) return i;
}
return -1;
}
static int s_press(void) {
sconfirm = sbutton == 1 && sconfirm; /* tout autre bouton annule la confirmation */
switch (sbutton) {
case 0:
if (!s_can_load()) return MENU_STAY;
if (saves_load(slist[ssel].file)) { saves_close(); return MENU_CLOSE; }
snprintf(smsg, sizeof smsg, "Cette partie n'a pas pu être lue.");
return MENU_STAY;
case 1:
if (!s_can_delete()) return MENU_STAY;
if (!sconfirm) { sconfirm = 1; return MENU_STAY; }
sconfirm = 0;
if (!saves_delete(slist[ssel].file)) snprintf(smsg, sizeof smsg, "Cette partie n'a pas pu être supprimée.");
saves_reload();
if (!sn) { sfocus = 1; sbutton = 2; }
s_scroll_to_sel();
return MENU_STAY;
default:
saves_close();
return MENU_STAY;
}
}
static void s_move(int d) {
int n = ssel + d;
sconfirm = 0; smsg[0] = 0;
if (n < 0 || n >= sn) return;
ssel = n;
s_scroll_to_sel();
}
static int saves_key(MenuKey k) {
if (k == MK_BACK) { if (sconfirm) sconfirm = 0; else saves_close(); return MENU_STAY; }
if (sfocus == 1) {
switch (k) {
case MK_LEFT: case MK_RIGHT: sbutton = clampi(sbutton + (k == MK_RIGHT ? 1 : -1), 0, 2); sconfirm = 0; break;
case MK_UP: if (sn) { sfocus = 0; sconfirm = 0; } break;
case MK_OK: return s_press();
default: break;
}
return MENU_STAY;
}
switch (k) {
case MK_LEFT: s_move(-1); break;
case MK_RIGHT: s_move(1); break;
case MK_UP: s_move(-S_COLS); break;
case MK_DOWN:
if (ssel + S_COLS < sn) s_move(S_COLS);
else if (ssel / S_COLS < (sn - 1) / S_COLS) s_move(sn - 1 - ssel); /* dernière rangée incomplète */
else { sfocus = 1; sbutton = s_can_load() ? 0 : 2; }
break;
case MK_HOME: s_move(-ssel); break;
case MK_END: s_move(sn - 1 - ssel); break;
case MK_OK: sbutton = 0; return s_press();
case MK_ERASE: sbutton = 1; return s_press(); /* Retour arrière : supprimer (deux fois) */
default: break;
}
return MENU_STAY;
}
static int saves_mouse(int x, int y, int down, int moved, int wheel) {
int i = s_cell_hit(x, y), b = -1, j;
if (wheel) {
int rows = (sn + S_COLS - 1) / S_COLS;
stop = clampi(stop - wheel, 0, rows > S_ROWS ? rows - S_ROWS : 0);
return MENU_STAY;
}
if (y >= 624 && y < 624 + BTN_H) for (j = 0; j < N_BTN; j++) if (x >= button_x(j) && x < button_x(j) + BTN_W) b = j;
if (b >= 0) {
if (moved && b != sbutton) { sbutton = b; sconfirm = 0; }
sfocus = 1;
if (down) { sbutton = b; return s_press(); }
return MENU_STAY;
}
if (i >= 0 && down) { /* un clic choisit la partie ; Charger la charge */
if (i != ssel) { sconfirm = 0; smsg[0] = 0; }
ssel = i; sfocus = 0;
}
return MENU_STAY;
}
/* miniature réduite (moyenne des pixels couverts), gardée tant que la page reste ouverte */
static const uint32_t *s_thumb(const char *file) {
static uint8_t pal[768], pix[SAVE_THUMB_W * SAVE_THUMB_H];
int k, x, y;
for (k = 0; k < S_CACHE; k++) if (!strcmp(scache[k].file, file)) return scache[k].ok ? scache[k].px : NULL;
k = scache_next; scache_next = (scache_next + 1) % S_CACHE;
snprintf(scache[k].file, sizeof scache[k].file, "%s", file);
scache[k].ok = saves_thumb(file, pal, pix);
if (!scache[k].ok) return NULL;
for (y = 0; y < S_TH; y++) {
int y0 = y * SAVE_THUMB_H / S_TH, y1 = (y + 1) * SAVE_THUMB_H / S_TH;
if (y1 <= y0) y1 = y0 + 1;
for (x = 0; x < S_TW; x++) {
int x0 = x * SAVE_THUMB_W / S_TW, x1 = (x + 1) * SAVE_THUMB_W / S_TW, sx, sy, n = 0, r = 0, g = 0, b = 0;
if (x1 <= x0) x1 = x0 + 1;
for (sy = y0; sy < y1; sy++)
for (sx = x0; sx < x1; sx++) {
const uint8_t *c = pal + 3 * pix[sy * SAVE_THUMB_W + sx];
r += c[0]; g += c[1]; b += c[2]; n++;
}
scache[k].px[y * S_TW + x] = 0xff000000u | RGB(r / n, g / n, b / n);
}
}
return scache[k].px;
}
/* date de la sauvegarde : « 5 déc. 2026, 14:32 » */
static void s_date(int64_t t64, char *out, size_t n) {
static const char *const mois[12] = {"janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.",
"oct.", "nov.", "déc."};
time_t t = (time_t)t64;
struct tm tm;
#ifdef _WIN32
if (localtime_s(&tm, &t)) { snprintf(out, n, "?"); return; }
#else
if (!localtime_r(&t, &tm)) { snprintf(out, n, "?"); return; }
#endif
snprintf(out, n, "%d %s %d, %02d:%02d", tm.tm_mday, mois[tm.tm_mon % 12], tm.tm_year + 1900, tm.tm_hour, tm.tm_min);
}
static void saves_draw(void) {
int r, c, fx0 = PANEL_X0 + 44, fx1 = PANEL_X1 - 44;
char buf[128];
text(&font_title, fx0, PANEL_Y0 + 26, "Parties sauvegardées", C_ACCENT, 255);
round_rect(fx0, 114, fx1, 116, 1, C_BORDER, 255);
if (!sn) {
wrap_text(fx0, 150, fx1 - fx0, "Aucune partie sauvegardée pour l'instant. \"Sauvegarder la partie\", dans l'onglet "
"Jeu, en crée une à chaque fois ; la sauvegarde automatique apparaît ici après le premier changement "
"de lieu.", C_MUTED);
}
for (r = 0; r < S_ROWS; r++)
for (c = 0; c < S_COLS; c++) {
int i = (stop + r) * S_COLS + c, x0 = s_cell_x(c), y0 = s_cell_y(r), on = i == ssel;
const uint32_t *px;
if (i >= sn) continue;
px = s_thumb(slist[i].file);
if (px) {
int x, y;
for (y = 0; y < S_TH; y++) for (x = 0; x < S_TW; x++) fb[(y0 + y) * MENU_W + x0 + x] = px[y * S_TW + x];
} else {
round_rect(x0, y0, x0 + S_TW, y0 + S_TH, 6, C_DARK, 255);
text(&font_small, x0 + 12, y0 + S_TH / 2 - font_small.height / 2, "image illisible", C_MUTED, 255);
}
if (on) outline_rect(x0 - 5, y0 - 5, x0 + S_TW + 5, y0 + S_TH + 5, 8, sfocus == 0 ? 3.f : 2.f,
sfocus == 0 ? C_ACCENT : C_MUTED, 255);
else outline_rect(x0 - 1, y0 - 1, x0 + S_TW + 1, y0 + S_TH + 1, 3, 1.f, C_BORDER, 255);
s_date(slist[i].time, buf, sizeof buf);
text(&font_small, x0, y0 + S_TH + 8, buf, on ? C_TEXT : C_MUTED, 255);
if (slist[i].is_auto) snprintf(buf, sizeof buf, "Automatique · lieu %d", slist[i].lieu);
else snprintf(buf, sizeof buf, "Lieu %d", slist[i].lieu);
text(&font_small, x0, y0 + S_TH + 8 + font_small.height + 2, buf, slist[i].is_auto ? C_ACCENT : C_MUTED, 255);
}
if (sn > S_COLS * S_ROWS) { /* position dans la liste */
int first = stop * S_COLS + 1, last = (stop + S_ROWS) * S_COLS;
if (last > sn) last = sn;
snprintf(buf, sizeof buf, "%d–%d sur %d", first, last, sn);
text(&font_small, fx1 - text_width(&font_small, buf), PANEL_Y0 + 40, buf, C_MUTED, 255);
}
if (sconfirm && sn) {
s_date(slist[ssel].time, buf, sizeof buf);
{
char line[200];
snprintf(line, sizeof line, "Supprimer définitivement la partie du %s ? Appuyer encore sur \"Supprimer\" "
"pour confirmer, Échap pour annuler.", buf);
wrap_text(fx0, S_INFO_Y, fx1 - fx0, line, C_ACCENT);
}
} else if (smsg[0]) wrap_text(fx0, S_INFO_Y, fx1 - fx0, smsg, C_ACCENT);
else if (sn && !game_in_location())
wrap_text(fx0, S_INFO_Y, fx1 - fx0, "Le chargement est possible une fois la partie commencée.", C_MUTED);
else if (sn)
wrap_text(fx0, S_INFO_Y, fx1 - fx0, "Charger remplace la partie en cours : sauvegardez-la d'abord si besoin.", C_MUTED);
{
static const char *lab[N_BTN] = {"Charger", "Supprimer", "Retour"};
int b;
for (b = 0; b < N_BTN; b++) {
int x0 = button_x(b), on = sfocus == 1 && sbutton == b, y = 624;
int ok = b == 0 ? s_can_load() : b == 1 ? s_can_delete() : 1;
const char *l = b == 1 && sconfirm ? "Confirmer" : lab[b];
int tw = text_width(&font_normal, l);
if (on && ok) round_rect(x0, y, x0 + BTN_W, y + BTN_H, BTN_H / 2, C_ACCENT, 255);
else outline_rect(x0, y, x0 + BTN_W, y + BTN_H, BTN_H / 2, 2, on ? C_MUTED : C_BORDER, 255);
text(&font_normal, x0 + (BTN_W - tw) / 2, y + (BTN_H - font_normal.height) / 2, l,
on && ok ? C_DARK : ok ? C_TEXT : C_TRACK, 255);
}
}
r_hint("Flèches : choisir · Entrée : charger · Retour arrière : supprimer · Échap : retour");
}
+1 -2
View File
@@ -52,8 +52,7 @@ typedef enum { MK_UP, MK_DOWN, MK_LEFT, MK_RIGHT, MK_OK, MK_BACK, MK_HOME, MK_EN
/* ce que l'hôte doit faire après un événement */
enum { MENU_STAY = 0, MENU_CLOSE = 1, MENU_QUIT = 2, MENU_DISPLAY = 4 /* affichage à réappliquer */,
MENU_REPORT = 8 /* écrire le rapport de bug, puis menu_report_done */, MENU_OPEN_DIR = 16 /* ouvrir menu_report_dir() */,
MENU_LOAD_AUTO = 32 /* charger la sauvegarde automatique (game_load_autosave) */ };
MENU_REPORT = 8 /* écrire le rapport de bug, puis menu_report_done */, MENU_OPEN_DIR = 16 /* ouvrir menu_report_dir() */ };
/* screen : résolution de l'écran ; usable : place disponible pour la fenêtre (sans barre des tâches ni titre),
* en pixels ; sert à la liste des tailles de fenêtre */
+4 -17
View File
@@ -10,6 +10,7 @@
#include "sprites.h"
#include "menu.h"
#include "report.h"
#include "saves.h"
/* int386x(eax = n° d'interruption, edx = REGS entrée, ebx = REGS sortie, ecx = SREGS) -> eax = sortie.eax
* REGS : eax ebx ecx edx esi edi cflag (dwords) ; SREGS : es cs ss ds fs gs (mots).
@@ -245,23 +246,10 @@ static void autosave_write(void) {
if (fclose(f) != 0) { remove(tmp); return; }
remove(path); /* rename ne remplace pas un fichier sous Windows */
if (rename(tmp, path) != 0) remove(tmp);
saves_write_auto(); /* même partie, avec miniature, pour le menu F12 */
if (rt_cfg.verbose) fprintf(stderr, "[auto] lieu %d sauvegardé\n", (int)RD32(ADR_LIEU));
}
int game_autosave_info(int *lieu) {
char name[16], path[600];
uint8_t buf[TUCKER_PARTIE_TAILLE];
FILE *f;
size_t got;
snprintf(name, sizeof name, "SAVEGM.%02d", TUCKER_PARTIE_AUTO);
if (!save_path(name, path, sizeof path) || !(f = fopen(path, "rb"))) return 0;
got = fread(buf, 1, sizeof buf, f);
fclose(f);
if (got != sizeof buf) return 0;
memcpy(lieu, buf + TUCKER_PARTIE_OFS_LIEU, 4);
return lieu_valide((uint32_t)*lieu);
}
int game_in_location(void) { return M && rt_cfg.in_game && lieu_valide(RD32(ADR_LIEU)); }
/* chargement en cours de partie : le jeu quitte le lieu courant comme par une sortie, et la partie est
@@ -272,8 +260,6 @@ void game_request_load(int slot) {
WR32(ADR_LIEU_DEMANDE, RD32(ADR_LIEU));
}
void game_load_autosave(void) { game_request_load(TUCKER_PARTIE_AUTO); }
/* ------------------------------------------------------------------ confort de jeu
* Marche accélérée (game.walk_speed) : tant que Bud marche à la demande du joueur (pas pendant une scène),
* le minuteur du jeu bat plus vite. Toute la logique avance donc au même rythme relatif ; la musique et les
@@ -299,6 +285,7 @@ void game_frame(void) {
host_mouse(&x, &y, &b);
pressed = (b & 1) && !(prev & 1);
prev = b;
saves_frame(); /* image pour la miniature des parties (saves.c) */
if (click_masked && !(b & 3)) click_masked = 0;
if (!rt_cfg.in_game || !pressed || !settings.skip_speech || (int32_t)RD32(ADR_PAROLE_DUREE) <= 0) return;
audio_stop(AUDIO_SPEECH, 0);
@@ -320,7 +307,7 @@ void FN_CHANGE_LIEU(void) {
R(0) = (uint32_t)slot;
PUSH32(0); FN_PARTIE_CHARGE();
R(0) = keep;
if (slot != TUCKER_PARTIE_AUTO && slot != TUCKER_PARTIE_RAPPORT) nofiles_update(slot);
if (slot != TUCKER_PARTIE_AUTO && slot != TUCKER_PARTIE_RAPPORT && slot != TUCKER_PARTIE_MENU) nofiles_update(slot);
}
ORIG(FN_CHANGE_LIEU)();
}
-2
View File
@@ -37,9 +37,7 @@ typedef struct {
extern RtConfig rt_cfg;
/* sauvegarde automatique (overrides.c) */
int game_in_location(void); /* 1 si une partie est en cours dans un lieu */
int game_autosave_info(int *lieu); /* 1 si SAVEGM.99 existe et est valide ; *lieu : son lieu */
void game_request_load(int slot); /* charge SAVEGM.NN au prochain tour du jeu */
void game_load_autosave(void); /* game_request_load de la sauvegarde automatique */
int game_speed_percent(void); /* vitesse du minuteur du jeu, en % (marche de Bud accélérée) */
int game_mouse_buttons(int b); /* boutons de la souris vus par le jeu (clic qui passe une réplique) */
void game_frame(void); /* à chaque image, après les événements : clic qui passe une réplique */
+276
View File
@@ -0,0 +1,276 @@
/* Parties sauvegardées du menu F12 : voir saves.h. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "cpu.h"
#include "rt.h"
#include "addr.h"
#include "menu.h"
#include "report.h"
#include "saves.h"
#ifdef _WIN32
#include <direct.h>
#include <io.h>
#define MKDIR(d) _mkdir(d)
#define SEP "\\"
#else
#include <dirent.h>
#include <sys/stat.h>
#define MKDIR(d) mkdir(d, 0755)
#define SEP "/"
#endif
/* en-tête (petit-boutiste) */
#define MAGIC "DTRSAVE1"
#define HDR_SIZE 64
#define OFS_STATE HDR_SIZE
#define OFS_PAL (OFS_STATE + TUCKER_PARTIE_TAILLE)
#define OFS_PIX (OFS_PAL + 768)
#define FILE_SIZE (OFS_PIX + SAVE_THUMB_W * SAVE_THUMB_H)
#define AUTO_FILE "auto.sav"
static char root[600];
void saves_set_root(const char *dir) { snprintf(root, sizeof root, "%s", dir ? dir : ""); }
const char *saves_root(void) {
if (!root[0]) {
const char *cfg = settings_default_path();
const char *slash = strrchr(cfg, '\\'), *s2 = strrchr(cfg, '/');
if (s2 > slash) slash = s2;
if (slash) snprintf(root, sizeof root, "%.*s" SEP "parties", (int)(slash - cfg), cfg);
else snprintf(root, sizeof root, "parties");
}
return root;
}
static void make_dirs(const char *path) {
char tmp[700];
size_t i;
snprintf(tmp, sizeof tmp, "%s", path);
for (i = 1; tmp[i]; i++)
if ((tmp[i] == '\\' || tmp[i] == '/') && tmp[i - 1] != ':') { char c = tmp[i]; tmp[i] = 0; MKDIR(tmp); tmp[i] = c; }
MKDIR(tmp);
}
static void full_path(const char *file, char *out, size_t n) { snprintf(out, n, "%s" SEP "%s", saves_root(), file); }
static void put32(uint8_t *p, uint32_t v) { p[0] = (uint8_t)v; p[1] = (uint8_t)(v >> 8); p[2] = (uint8_t)(v >> 16); p[3] = (uint8_t)(v >> 24); }
static uint32_t get32(const uint8_t *p) { return p[0] | p[1] << 8 | p[2] << 16 | (uint32_t)p[3] << 24; }
static int lieu_ok(int lieu) { return lieu >= 1 && lieu <= 98; }
/* ------------------------------------------------------------------ dernière image bien visible */
static uint8_t view_pal[768], view_pix[SAVE_THUMB_W * SAVE_THUMB_H];
static int view_ok;
static int palette_visible(void) {
int i, top = 0;
for (i = 0; i < 768; i++) if ((vga_dac[i] & 63) > top) top = vga_dac[i] & 63;
return top >= 40; /* fondu au noir : toutes les couleurs baissent */
}
static void grab_view(void) {
int i;
for (i = 0; i < 768; i++) { int v = vga_dac[i] & 63; view_pal[i] = (uint8_t)(v << 2 | v >> 4); }
memcpy(view_pix, M + VGA_BASE, sizeof view_pix);
view_ok = 1;
}
void saves_frame(void) {
static unsigned n;
if (!M || !rt_cfg.in_game || ++n % 8) return; /* une image sur 8 suffit */
if (palette_visible()) grab_view();
}
/* ------------------------------------------------------------------ écriture */
static int write_file(const char *file, const uint8_t *state, int lieu, int64_t t) {
char path[700], tmp[720];
uint8_t *buf = (uint8_t *)calloc(1, FILE_SIZE);
FILE *f;
int ok;
if (!buf) return 0;
if (!view_ok && M) grab_view();
memcpy(buf, MAGIC, 8);
put32(buf + 8, HDR_SIZE);
put32(buf + 12, (uint32_t)lieu);
put32(buf + 16, (uint32_t)(uint64_t)t); put32(buf + 20, (uint32_t)((uint64_t)t >> 32));
put32(buf + 24, TUCKER_PARTIE_TAILLE);
put32(buf + 28, SAVE_THUMB_W); put32(buf + 32, SAVE_THUMB_H);
memcpy(buf + OFS_STATE, state, TUCKER_PARTIE_TAILLE);
memcpy(buf + OFS_PAL, view_pal, 768);
memcpy(buf + OFS_PIX, view_pix, sizeof view_pix);
make_dirs(saves_root());
full_path(file, path, sizeof path);
snprintf(tmp, sizeof tmp, "%s.tmp", path); /* fichier complet ou rien, même si le jeu s'arrête */
ok = (f = fopen(tmp, "wb")) != NULL;
if (ok) { ok = fwrite(buf, 1, FILE_SIZE, f) == FILE_SIZE; ok = fclose(f) == 0 && ok; }
free(buf);
if (!ok) { remove(tmp); return 0; }
remove(path); /* rename ne remplace pas un fichier sous Windows */
if (rename(tmp, path) != 0) { remove(tmp); return 0; }
return 1;
}
int saves_can_save(char *why, size_t n) {
if (!game_in_location()) { snprintf(why, n, "pas de partie en cours"); return 0; }
if (RD32(ADR_BUD_SCRIPT) || (int32_t)RD32(ADR_PAROLE_DUREE) > 0) { snprintf(why, n, "pas pendant une scène"); return 0; }
return 1;
}
int saves_write(SaveInfo *info) {
char why[64], file[64];
uint8_t state[TUCKER_PARTIE_TAILLE];
time_t now = time(NULL);
struct tm tm;
int i;
if (!saves_can_save(why, sizeof why)) return 0;
#ifdef _WIN32
localtime_s(&tm, &now);
#else
localtime_r(&now, &tm);
#endif
for (i = 1; i < 100; i++) { /* deux sauvegardes dans la même seconde : -2, -3… */
char path[700];
FILE *f;
int len = snprintf(file, sizeof file, "partie-%04d%02d%02d-%02d%02d%02d", tm.tm_year + 1900, tm.tm_mon + 1,
tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
if (i > 1) len += snprintf(file + len, sizeof file - (size_t)len, "-%d", i);
snprintf(file + len, sizeof file - (size_t)len, ".sav");
full_path(file, path, sizeof path);
if (!(f = fopen(path, "rb"))) break;
fclose(f);
}
game_state_snapshot(state);
if (!write_file(file, state, (int)RD32(ADR_LIEU), (int64_t)now)) return 0;
if (info) {
snprintf(info->file, sizeof info->file, "%s", file);
info->time = (int64_t)now; info->lieu = (int)RD32(ADR_LIEU); info->is_auto = 0;
}
if (rt_cfg.verbose) fprintf(stderr, "[parties] %s (lieu %d)\n", file, (int)RD32(ADR_LIEU));
return 1;
}
void saves_write_auto(void) {
uint8_t state[TUCKER_PARTIE_TAILLE];
game_state_snapshot(state);
write_file(AUTO_FILE, state, (int)RD32(ADR_LIEU), (int64_t)time(NULL));
}
/* ------------------------------------------------------------------ lecture */
static int read_header(const char *file, SaveInfo *si) {
char path[700];
uint8_t h[HDR_SIZE];
FILE *f;
size_t got;
long size;
full_path(file, path, sizeof path);
if (!(f = fopen(path, "rb"))) return 0;
got = fread(h, 1, sizeof h, f);
fseek(f, 0, SEEK_END);
size = ftell(f);
fclose(f);
if (got != sizeof h || memcmp(h, MAGIC, 8) || get32(h + 8) != HDR_SIZE || get32(h + 24) != TUCKER_PARTIE_TAILLE ||
get32(h + 28) != SAVE_THUMB_W || get32(h + 32) != SAVE_THUMB_H || size != FILE_SIZE)
return 0;
snprintf(si->file, sizeof si->file, "%s", file);
si->lieu = (int)get32(h + 12);
si->time = (int64_t)((uint64_t)get32(h + 16) | (uint64_t)get32(h + 20) << 32);
si->is_auto = !strcmp(file, AUTO_FILE);
return lieu_ok(si->lieu);
}
static int cmp_saves(const void *a, const void *b) {
const SaveInfo *x = (const SaveInfo *)a, *y = (const SaveInfo *)b;
if (x->is_auto != y->is_auto) return y->is_auto - x->is_auto;
if (x->time != y->time) return x->time < y->time ? 1 : -1;
return strcmp(y->file, x->file);
}
static int is_save_name(const char *name) {
size_t n = strlen(name);
if (!strcmp(name, AUTO_FILE)) return 1;
return n > 11 && n < 60 && !strncmp(name, "partie-", 7) && !strcmp(name + n - 4, ".sav");
}
SaveInfo *saves_list(int *n) {
SaveInfo *list = NULL, si;
int cap = 0;
*n = 0;
#ifdef _WIN32
{
char pat[700];
struct _finddata_t fd;
intptr_t h;
full_path("*.sav", pat, sizeof pat);
if ((h = _findfirst(pat, &fd)) == -1) return NULL;
do {
if ((fd.attrib & _A_SUBDIR) || !is_save_name(fd.name) || !read_header(fd.name, &si)) continue;
#else
{
DIR *d = opendir(saves_root());
struct dirent *e;
if (!d) return NULL;
while ((e = readdir(d)) != NULL) {
if (!is_save_name(e->d_name) || !read_header(e->d_name, &si)) continue;
#endif
if (*n == cap) {
SaveInfo *nl = (SaveInfo *)realloc(list, sizeof *list * (size_t)(cap = cap ? cap * 2 : 32));
if (!nl) break;
list = nl;
}
list[(*n)++] = si;
#ifdef _WIN32
} while (_findnext(h, &fd) == 0);
_findclose(h);
}
#else
}
closedir(d);
}
#endif
if (*n > 1) qsort(list, (size_t)*n, sizeof *list, cmp_saves);
return list;
}
static int read_block(const char *file, long ofs, void *out, size_t n) {
char path[700];
FILE *f;
int ok;
SaveInfo si;
if (!read_header(file, &si)) return 0;
full_path(file, path, sizeof path);
if (!(f = fopen(path, "rb"))) return 0;
ok = fseek(f, ofs, SEEK_SET) == 0 && fread(out, 1, n, f) == n;
fclose(f);
return ok;
}
int saves_thumb(const char *file, uint8_t *pal, uint8_t *pixels) {
return read_block(file, OFS_PAL, pal, 768) && read_block(file, OFS_PIX, pixels, SAVE_THUMB_W * SAVE_THUMB_H);
}
int saves_load(const char *file) {
uint8_t state[TUCKER_PARTIE_TAILLE];
char name[16], path[600];
FILE *f;
int ok;
if (!game_in_location() || !read_block(file, OFS_STATE, state, sizeof state)) return 0;
if (!lieu_ok((int)get32(state + TUCKER_PARTIE_OFS_LIEU))) return 0;
snprintf(name, sizeof name, "SAVEGM.%02d", TUCKER_PARTIE_MENU);
if (!dos_map_path(name, path, sizeof path, 1) || !(f = fopen(path, "wb"))) return 0;
ok = fwrite(state, 1, sizeof state, f) == sizeof state;
ok = fclose(f) == 0 && ok;
if (!ok) return 0;
if (rt_cfg.verbose) fprintf(stderr, "[parties] chargement de %s\n", file);
game_request_load(TUCKER_PARTIE_MENU);
return 1;
}
int saves_delete(const char *file) {
char path[700];
if (!is_save_name(file)) return 0;
full_path(file, path, sizeof path);
return remove(path) == 0;
}
+40
View File
@@ -0,0 +1,40 @@
/* Parties sauvegardées depuis le menu F12, en nombre illimité, chacune avec sa miniature.
* Un fichier par partie dans le dossier « parties » à côté de settings.ini :
* partie-AAAAMMJJ-HHMMSS.sav sauvegardes faites par le joueur
* auto.sav sauvegarde automatique (aussi écrite dans SAVEGM.99, pour --charger 99)
* Contenu : en-tête de 64 octets, les octets d'un SAVEGM.NN, puis l'image 320×200 du jeu (palette RVB et pixels).
* Pour charger une partie, ses octets sont copiés dans SAVEGM.97 et le jeu la charge comme les siennes
* (FN_PARTIE_CHARGE) : la logique de chargement reste celle du jeu. Format : docs/SETTINGS.md. */
#pragma once
#include <stdint.h>
#define SAVE_THUMB_W 320
#define SAVE_THUMB_H 200
typedef struct {
char file[64]; /* nom du fichier dans saves_root() */
int64_t time; /* date de la sauvegarde (secondes depuis 1970) */
int lieu;
int is_auto; /* 1 : auto.sav */
} SaveInfo;
void saves_set_root(const char *dir); /* dossier des parties ; par défaut « parties » à côté de settings.ini */
const char *saves_root(void);
/* liste des parties : auto.sav d'abord, puis les plus récentes. Tableau alloué (free), *n entrées */
SaveInfo *saves_list(int *n);
/* 1 si l'on peut sauvegarder maintenant ; sinon why reçoit la raison */
int saves_can_save(char *why, size_t n);
/* nouvelle partie sauvegardée ; renvoie 1 si écrite (info : ce qui a été écrit, peut être NULL) */
int saves_write(SaveInfo *info);
/* sauvegarde automatique : auto.sav, appelée au changement de lieu */
void saves_write_auto(void);
/* miniature : palette RVB 8 bits (768 octets) et pixels 320×200 ; 1 si lue */
int saves_thumb(const char *file, uint8_t *pal, uint8_t *pixels);
/* chargement : le jeu change de lieu au prochain tour (menu fermé) ; 0 si le fichier est invalide */
int saves_load(const char *file);
int saves_delete(const char *file);
/* à chaque image (game_frame) : garde la dernière image du jeu bien visible (pas pendant un fondu au noir),
* pour la miniature */
void saves_frame(void);