Mods (remplacement de fichiers) et pack HD des décors
- mods/<nom>/files/ : remplace tout fichier lu par le jeu, sans toucher aux originaux ; ordre alphabétique des mods, le dernier l'emporte ; dossiers _x et .x ignorés. - mods/<nom>/hd/<PCX>.png : décors HD. Le moteur décode le PCX d'origine, le retrouve dans l'écran 320×200 (décalage de défilement compris, pièces LOCxxA/B/C/D) et ne laisse voir l'image HD que là où le décor d'origine est visible ; personnages, objets et panneau restent ceux du jeu. Les fondus de palette suivent. - Décodeur PNG intégré (inflate inclus), vérifié contre zlib sur tous les formats. - Rendu : couche HD avec mipmaps sous l'image du jeu (alpha = masque) pour les filtres net, lissé et xBR ; le CRT garde l'image d'origine. - Réglages : [display] hd_pack, [mods] enabled/dir/disabled (valeurs texte, clés reconnues par section) ; menu F12 « Décors HD (mods) ». - Options : --mods DOSSIER, --sans-mods, --sans-hd (session seulement). - tools/hd_export.py --upscayl : pack HD complet avec Upscayl (Real-ESRGAN). - docs/MODS.md, docs/SETTINGS.md ; mods/ exclu du dépôt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0c929244aa
commit
37acf64362
17 files changed
+1342
-52
No files matched your search
@@ -36,6 +36,9 @@ SAVEGM.*
|
|||||||
*.raw
|
*.raw
|
||||||
*.ENC
|
*.ENC
|
||||||
|
|
||||||
|
# Mods et packs HD (images dérivées du jeu) : jamais dans le dépôt
|
||||||
|
mods/
|
||||||
|
|
||||||
# Dépendances tierces téléchargées (SDL2, etc.)
|
# Dépendances tierces téléchargées (SDL2, etc.)
|
||||||
third_party/
|
third_party/
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ if /i not "%ARG1%"=="nogen" (
|
|||||||
if not exist build\obj mkdir build\obj
|
if not exist build\obj mkdir build\obj
|
||||||
|
|
||||||
set CFLAGS=/nologo /O2 /GS- /W3 /wd4146 /wd4244 /wd4018 /wd4102 /wd4101 /wd4189 /MP /utf-8 /Iruntime /Ibuild\gen_tucker /Ibuild\gen_intro /I%SDL%\include /D_CRT_SECURE_NO_WARNINGS /Fobuild\obj\
|
set CFLAGS=/nologo /O2 /GS- /W3 /wd4146 /wd4244 /wd4018 /wd4102 /wd4101 /wd4189 /MP /utf-8 /Iruntime /Ibuild\gen_tucker /Ibuild\gen_intro /I%SDL%\include /D_CRT_SECURE_NO_WARNINGS /Fobuild\obj\
|
||||||
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\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\mods.c runtime\hd.c runtime\png.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 || exit /b 1
|
cl %CFLAGS% /c runtime\host_headless.c runtime\host_sdl.c runtime\gfx_gl.c || exit /b 1
|
||||||
|
|
||||||
if not exist build\lib mkdir build\lib
|
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\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\mods.obj build\obj\hd.obj build\obj\png.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
|
link /nologo /STACK:67108864 /OUT:build\tucker_headless.exe build\obj\host_headless.obj build\lib\jeu.lib || exit /b 1
|
||||||
link /nologo /STACK:67108864 /SUBSYSTEM:CONSOLE /OUT:build\tucker.exe build\obj\host_sdl.obj build\obj\gfx_gl.obj build\lib\jeu.lib %SDL%\lib\x64\SDL2.lib opengl32.lib || exit /b 1
|
link /nologo /STACK:67108864 /SUBSYSTEM:CONSOLE /OUT:build\tucker.exe build\obj\host_sdl.obj build\obj\gfx_gl.obj build\lib\jeu.lib %SDL%\lib\x64\SDL2.lib opengl32.lib || exit /b 1
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
# Mods et pack HD
|
||||||
|
|
||||||
|
Les mods ajoutent ou remplacent du contenu **sans modifier les fichiers du jeu** : le moteur lit les fichiers d'un mod à la place des originaux pendant la partie. Rien n'est redistribué avec le projet. Le dossier `mods/` est exclu du dépôt git, parce que les images HD sont dérivées des fichiers du jeu de chaque joueur.
|
||||||
|
|
||||||
|
## Emplacement
|
||||||
|
|
||||||
|
Par défaut, le jeu cherche `mods/` à côté de l'exécutable, puis dans le dossier parent (cas de `build\tucker.exe` : `mods/` à la racine du projet), puis dans le dossier courant. La clé `[mods] dir` de `settings.ini` ou l'option `--mods DOSSIER` donnent un autre dossier (voir [SETTINGS.md](SETTINGS.md)).
|
||||||
|
|
||||||
|
```
|
||||||
|
mods/
|
||||||
|
hd_upscayl/ un mod = un dossier (son nom sert d'identifiant)
|
||||||
|
mod.ini facultatif : nom, auteur, description (lu par le launcher)
|
||||||
|
hd/
|
||||||
|
LOC01.png décor HD de LOC01.PCX
|
||||||
|
LOC03A.png pièce en plusieurs morceaux : un PNG par morceau
|
||||||
|
LOC03B.png
|
||||||
|
voix_fr/
|
||||||
|
files/
|
||||||
|
SPEECH/SAM0001.WAV remplace le fichier du jeu de même chemin
|
||||||
|
```
|
||||||
|
|
||||||
|
- `files/` : chaque fichier remplace celui du jeu qui a le même chemin relatif. La casse est indifférente. Tout fichier que le jeu ouvre en lecture peut être remplacé : images, sons, textes, etc.
|
||||||
|
- `hd/` : images HD des décors (voir plus bas). Le nom est celui du PCX d'origine, avec l'extension `.png`.
|
||||||
|
- Les mods sont appliqués dans l'ordre alphabétique de leur nom de dossier. Pour un même fichier, **le dernier l'emporte**. Préfixez par exemple `10_`, `20_` pour fixer l'ordre.
|
||||||
|
- Un dossier dont le nom commence par `_` ou `.` est ignoré, ce qui permet de mettre un mod de côté.
|
||||||
|
- `[mods] disabled=nom1,nom2` désactive des mods sans les déplacer. `[mods] enabled=0` ou `--sans-mods` les désactive tous.
|
||||||
|
|
||||||
|
Le journal (sortie d'erreur) liste les mods trouvés :
|
||||||
|
|
||||||
|
```
|
||||||
|
[mods] hd_upscayl : actif
|
||||||
|
[mods] 0 fichier(s) remplacé(s), 122 image(s) HD
|
||||||
|
```
|
||||||
|
|
||||||
|
### `mod.ini` (facultatif)
|
||||||
|
|
||||||
|
Le jeu ne lit pas ce fichier. Il est réservé au launcher, pour afficher les mods :
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[mod]
|
||||||
|
name=Décors HD (Upscayl)
|
||||||
|
author=…
|
||||||
|
description=Décors agrandis ×4 avec Real-ESRGAN
|
||||||
|
```
|
||||||
|
|
||||||
|
## Pack HD
|
||||||
|
|
||||||
|
Le pack HD remplace à l'écran les **décors** du jeu par des images haute définition, à n'importe quelle résolution. Le jeu continue de tourner en 320×200 : personnages, objets animés, curseur, panneau d'actions et textes restent les siens et sont posés par-dessus le décor HD.
|
||||||
|
|
||||||
|
### Fonctionnement
|
||||||
|
|
||||||
|
1. Quand le jeu ouvre un décor `LOCxx.PCX` pour lequel un mod fournit `hd/LOCxx.png`, le moteur décode le PCX d'origine. Les pièces en plusieurs morceaux (`LOC03A`, `LOC03B`…), ouverts à la suite, forment une bande de 640, 960 ou 1280 pixels de large.
|
||||||
|
2. À chaque image, le moteur cherche ce décor, et son décalage de défilement, dans l'écran 320×200 du jeu.
|
||||||
|
3. Chaque pixel de l'écran identique au pixel du décor d'origine laisse voir l'image HD. Les autres pixels (personnages, objets, panneau) restent ceux du jeu.
|
||||||
|
4. Les fondus de palette (entrée et sortie de pièce, nuit…) sont appliqués à l'image HD.
|
||||||
|
|
||||||
|
Le moteur n'a besoin d'aucune connaissance du jeu, et un pack incomplet fonctionne : un décor sans PNG reste en 320×200. Les filtres `nearest`, `smooth` et `xbr` s'appliquent à la couche du jeu. Le filtre `crt` affiche l'image d'origine, sans le pack HD. L'option « Décors HD (mods) » du menu F12 (clé `hd_pack`) active ou coupe le pack en cours de partie.
|
||||||
|
|
||||||
|
### Règles pour les images
|
||||||
|
|
||||||
|
- Une image par PCX, **même cadrage** que l'original : toute l'image 320×200, y compris la partie basse.
|
||||||
|
- Taille libre, ratio 16:10 : 1280×800 (×4) est un bon choix, 2560×1600 fonctionne aussi. Toutes les images d'une même pièce doivent avoir la même taille.
|
||||||
|
- PNG 8 ou 16 bits : RVB, RVBA, niveaux de gris ou palette, non entrelacé. Le canal alpha est ignoré.
|
||||||
|
- Si un mod remplace un PCX par `files/`, l'image HD de même nom est calée sur le PCX remplacé : un mod qui redessine un décor doit fournir aussi son PNG HD, ou être utilisé sans pack HD.
|
||||||
|
- Les zones où le jeu dessine des objets animés avec leur propre fond (horloge, lampe…) restent en basse résolution : c'est le jeu qui y dessine.
|
||||||
|
|
||||||
|
### Créer un pack avec Upscayl
|
||||||
|
|
||||||
|
[Upscayl](https://upscayl.org) (Real-ESRGAN) agrandit les décors ×4 en quelques secondes. Si Upscayl est installé, une commande crée un pack complet à partir des fichiers du jeu :
|
||||||
|
|
||||||
|
```
|
||||||
|
python tools/hd_export.py ..\extracted\iso\TUCKER mods\hd_upscayl\hd --upscayl
|
||||||
|
```
|
||||||
|
|
||||||
|
- `--upscayl MODELE` choisit le modèle. Par défaut `digital-art-4x`, adapté aux décors dessinés. Autres modèles : `ultrasharp-4x`, `remacri-4x`, `high-fidelity-4x`, `upscayl-standard-4x`, `upscayl-lite-4x`, `ultramix-balanced-4x`.
|
||||||
|
- Upscayl est cherché dans `Program Files`, dans `%LOCALAPPDATA%\Programs`, ou à l'emplacement donné par `UPSCAYL_BIN` ou `--upscayl-bin CHEMIN`.
|
||||||
|
- Pour comparer deux modèles, générez-les dans deux mods et désactivez-en un avec `[mods] disabled=`.
|
||||||
|
|
||||||
|
### Créer un pack avec un autre outil
|
||||||
|
|
||||||
|
```
|
||||||
|
python tools/hd_export.py ..\extracted\iso\TUCKER export_png
|
||||||
|
```
|
||||||
|
|
||||||
|
Cette commande exporte les décors en PNG 320×200. Agrandissez-les avec l'outil de votre choix (retouche à la main, waifu2x, ESRGAN…), puis déposez-les dans `mods/<nom>/hd/` sous le même nom. `--echelle 2` ou `--echelle 4` produit directement un agrandissement Scale2x, sans flou, pour essayer un pack tout de suite. `--motif` choisit les fichiers (par défaut `LOC*`).
|
||||||
|
|
||||||
|
## Pour le launcher
|
||||||
|
|
||||||
|
- Lister les mods : sous-dossiers de `mods/` dont le nom ne commence ni par `_` ni par `.`, avec `mod.ini` pour le nom affiché. Un mod a des décors HD s'il contient `hd/*.png`.
|
||||||
|
- Activer ou désactiver un mod : écrire la liste dans `[mods] disabled` de `settings.ini`. La liste est prise en compte au lancement suivant.
|
||||||
|
- Pack HD on/off : clé `[display] hd_pack`, également réglable en jeu (F12).
|
||||||
|
- Options pour une seule session : `--mods DOSSIER`, `--sans-mods`, `--sans-hd`.
|
||||||
+24
-4
@@ -14,9 +14,9 @@ Le jeu (`build\tucker.exe`), son menu en jeu (touche **F12**) et le launcher lis
|
|||||||
## Format
|
## Format
|
||||||
|
|
||||||
- Texte UTF-8, une clé par ligne : `cle=valeur`.
|
- Texte UTF-8, une clé par ligne : `cle=valeur`.
|
||||||
- Les sections `[display]` et `[audio]` servent seulement à ranger. Les noms de clés sont uniques, quelle que soit la section.
|
- Sections : `[display]`, `[audio]`, `[mods]`. Une clé n'est reconnue que dans sa section. En ligne de commande (`--set`), on peut écrire `cle` ou `section.cle` (par exemple `mods.dir`).
|
||||||
- Les lignes qui commencent par `#` ou `;` sont des commentaires.
|
- Les lignes qui commencent par `#` ou `;` sont des commentaires.
|
||||||
- Quand le jeu enregistre, il ne réécrit que la valeur de ses propres clés. L'ordre, les commentaires et les clés qu'il ne connaît pas restent intacts. Le launcher peut donc ajouter les siennes (par exemple `hd_pack`, ou une section `[mods]`) sans qu'elles soient effacées.
|
- Quand le jeu enregistre, il ne réécrit que la valeur de ses propres clés. L'ordre, les commentaires et les clés qu'il ne connaît pas restent intacts. Le launcher peut donc ajouter les siennes sans qu'elles soient effacées.
|
||||||
- Une clé absente ou invalide prend sa valeur par défaut. Une valeur numérique hors limites est ramenée dans les limites.
|
- Une clé absente ou invalide prend sa valeur par défaut. Une valeur numérique hors limites est ramenée dans les limites.
|
||||||
- Le jeu enregistre à la fermeture du menu F12 et après un passage en plein écran avec F11.
|
- Le jeu enregistre à la fermeture du menu F12 et après un passage en plein écran avec F11.
|
||||||
|
|
||||||
@@ -29,12 +29,18 @@ window_scale=3
|
|||||||
filter=xbr
|
filter=xbr
|
||||||
aspect_43=1
|
aspect_43=1
|
||||||
vsync=0
|
vsync=0
|
||||||
|
hd_pack=1
|
||||||
|
|
||||||
[audio]
|
[audio]
|
||||||
master_volume=100
|
master_volume=100
|
||||||
music_volume=80
|
music_volume=80
|
||||||
voice_volume=100
|
voice_volume=100
|
||||||
sfx_volume=90
|
sfx_volume=90
|
||||||
|
|
||||||
|
[mods]
|
||||||
|
enabled=1
|
||||||
|
dir=
|
||||||
|
disabled=
|
||||||
```
|
```
|
||||||
|
|
||||||
## Clés
|
## Clés
|
||||||
@@ -48,6 +54,7 @@ sfx_volume=90
|
|||||||
| `filter` | `nearest`, `smooth`, `xbr`, `crt` | `nearest` | Filtre d'image (voir ci-dessous) |
|
| `filter` | `nearest`, `smooth`, `xbr`, `crt` | `nearest` | Filtre d'image (voir ci-dessous) |
|
||||||
| `aspect_43` | `0` / `1` | `1` | `1` : image 320×200 étirée en 4:3, comme sur un écran VGA. `0` : pixels carrés (16:10) |
|
| `aspect_43` | `0` / `1` | `1` | `1` : image 320×200 étirée en 4:3, comme sur un écran VGA. `0` : pixels carrés (16:10) |
|
||||||
| `vsync` | `0` / `1` | `0` | Synchronisation verticale |
|
| `vsync` | `0` / `1` | `0` | Synchronisation verticale |
|
||||||
|
| `hd_pack` | `0` / `1` | `1` | Décors HD fournis par les mods (voir [MODS.md](MODS.md)). Sans effet si aucun mod ne fournit d'images HD, et avec le filtre `crt` |
|
||||||
|
|
||||||
Filtres :
|
Filtres :
|
||||||
|
|
||||||
@@ -69,6 +76,16 @@ Les booléens acceptent aussi `true`/`false` et `on`/`off`. Le jeu réécrit tou
|
|||||||
|
|
||||||
Les volumes sont des pourcentages de curseur. Le mixeur applique une courbe quadratique pour que le curseur paraisse régulier à l'oreille.
|
Les volumes sont des pourcentages de curseur. Le mixeur applique une courbe quadratique pour que le curseur paraisse régulier à l'oreille.
|
||||||
|
|
||||||
|
### `[mods]`
|
||||||
|
|
||||||
|
| Clé | Valeurs | Défaut | Effet |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `enabled` | `0` / `1` | `1` | `0` : aucun mod n'est chargé (ni fichiers remplacés, ni décors HD) |
|
||||||
|
| `dir` | chemin | vide | Dossier des mods. Vide : `mods` à côté de l'exécutable, sinon `mods` dans le dossier parent (cas de `build\tucker.exe`), sinon `mods` dans le dossier courant |
|
||||||
|
| `disabled` | noms séparés par des virgules | vide | Mods (noms de dossiers) à ignorer, par exemple `disabled=hd_upscayl,voix_fr` |
|
||||||
|
|
||||||
|
Les mods sont lus au démarrage : un changement de `[mods]` prend effet au lancement suivant. `hd_pack`, lui, s'applique tout de suite depuis le menu F12. Le format des mods est décrit dans [MODS.md](MODS.md).
|
||||||
|
|
||||||
## Ligne de commande
|
## Ligne de commande
|
||||||
|
|
||||||
Les options d'affichage valent **pour la session seulement**. Elles ne sont pas écrites dans le fichier, sauf si le joueur change ensuite ce réglage dans le menu F12. Le launcher peut donc imposer une valeur au lancement sans écraser le choix fait en jeu. Pour changer un réglage durablement, il doit écrire dans `settings.ini`.
|
Les options d'affichage valent **pour la session seulement**. Elles ne sont pas écrites dans le fichier, sauf si le joueur change ensuite ce réglage dans le menu F12. Le launcher peut donc imposer une valeur au lancement sans écraser le choix fait en jeu. Pour changer un réglage durablement, il doit écrire dans `settings.ini`.
|
||||||
@@ -82,13 +99,16 @@ Les options d'affichage valent **pour la session seulement**. Elles ne sont pas
|
|||||||
| `--filtre NOM` | `filter=NOM` |
|
| `--filtre NOM` | `filter=NOM` |
|
||||||
| `--format43 0\|1` | `aspect_43=0\|1` |
|
| `--format43 0\|1` | `aspect_43=0\|1` |
|
||||||
| `--vsync 0\|1` | `vsync=0\|1` |
|
| `--vsync 0\|1` | `vsync=0\|1` |
|
||||||
| `--set cle=valeur` | N'importe quelle clé du tableau, par exemple `--set music_volume=50` |
|
| `--mods DOSSIER` | `[mods] dir=DOSSIER` (`--mods ""` : détection automatique) |
|
||||||
|
| `--sans-mods` | `[mods] enabled=0` |
|
||||||
|
| `--sans-hd` | `hd_pack=0` |
|
||||||
|
| `--set cle=valeur` | N'importe quelle clé du tableau, par exemple `--set music_volume=50` ou `--set mods.disabled=hd_upscayl` |
|
||||||
|
|
||||||
Une option avec une valeur invalide est ignorée, et un message part sur la sortie d'erreur.
|
Une option avec une valeur invalide est ignorée, et un message part sur la sortie d'erreur.
|
||||||
|
|
||||||
Autres options du jeu, inchangées :
|
Autres options du jeu, inchangées :
|
||||||
|
|
||||||
- `--cd`, `--exe`, `--hd`, `--root`, `--saves` : dossiers et fichiers du jeu ;
|
- `--cd`, `--exe`, `--hd`, `--root`, `--saves` : dossiers et fichiers du jeu (`--hd` est le dossier d'installation du jeu, sans rapport avec le pack HD) ;
|
||||||
- `--son` ;
|
- `--son` ;
|
||||||
- `--sans-intro` ;
|
- `--sans-intro` ;
|
||||||
- `--intro` ;
|
- `--intro` ;
|
||||||
|
|||||||
+25
-6
@@ -11,6 +11,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "rt.h"
|
#include "rt.h"
|
||||||
|
#include "mods.h"
|
||||||
|
#include "hd.h"
|
||||||
|
|
||||||
RtConfig rt_cfg;
|
RtConfig rt_cfg;
|
||||||
|
|
||||||
@@ -57,18 +59,26 @@ static int is_save_name(const char *base) {
|
|||||||
return !strncmp(base, "SAVEGM.", 7) || !strcmp(base, "NOFILES.DTA");
|
return !strncmp(base, "SAVEGM.", 7) || !strcmp(base, "NOFILES.DTA");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* nom DOS -> chemin hôte ; renvoie 0 si introuvable (lecture) */
|
/* nom DOS -> chemin relatif dans le dossier du jeu, en majuscules (« C:\TUCKER\speech\x.wav » -> « SPEECH\X.WAV ») */
|
||||||
int dos_map_path(const char *dos, char *out, size_t n, int for_write) {
|
static char *game_rel(const char *dos, char *p, size_t n) {
|
||||||
char p[260], *s, *base;
|
char *s;
|
||||||
const char *dirs[3];
|
|
||||||
int i;
|
|
||||||
size_t k;
|
size_t k;
|
||||||
for (k = 0; dos[k] && k + 1 < sizeof p; k++) p[k] = (char)toupper((unsigned char)(dos[k] == '/' ? '\\' : dos[k]));
|
for (k = 0; dos[k] && k + 1 < n; k++) p[k] = (char)toupper((unsigned char)(dos[k] == '/' ? '\\' : dos[k]));
|
||||||
p[k] = 0;
|
p[k] = 0;
|
||||||
s = p;
|
s = p;
|
||||||
if (s[0] && s[1] == ':') s += 2;
|
if (s[0] && s[1] == ':') s += 2;
|
||||||
while (*s == '\\') s++;
|
while (*s == '\\') s++;
|
||||||
if (!strncmp(s, "TUCKER\\", 7)) s += 7;
|
if (!strncmp(s, "TUCKER\\", 7)) s += 7;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* nom DOS -> chemin hôte ; renvoie 0 si introuvable (lecture). Ordre : sauvegardes, mods, jeu installé, CD, racine */
|
||||||
|
int dos_map_path(const char *dos, char *out, size_t n, int for_write) {
|
||||||
|
char p[260], *s, *base;
|
||||||
|
const char *dirs[3];
|
||||||
|
int i;
|
||||||
|
size_t k;
|
||||||
|
s = game_rel(dos, p, sizeof p);
|
||||||
base = strrchr(s, '\\');
|
base = strrchr(s, '\\');
|
||||||
base = base ? base + 1 : s;
|
base = base ? base + 1 : s;
|
||||||
if (is_save_name(base)) {
|
if (is_save_name(base)) {
|
||||||
@@ -77,6 +87,10 @@ int dos_map_path(const char *dos, char *out, size_t n, int for_write) {
|
|||||||
}
|
}
|
||||||
if (for_write) return 0;
|
if (for_write) return 0;
|
||||||
if (!strcmp(s, "G.IN") && rt_cfg.mute) return 0;
|
if (!strcmp(s, "G.IN") && rt_cfg.mute) return 0;
|
||||||
|
if (mods_find_file(s, out, n)) {
|
||||||
|
if (rt_cfg.verbose) fprintf(stderr, "[mods] %s -> %s\n", s, out);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
dirs[0] = rt_cfg.hd_dir; dirs[1] = rt_cfg.cd_dir; dirs[2] = rt_cfg.root_dir;
|
dirs[0] = rt_cfg.hd_dir; dirs[1] = rt_cfg.cd_dir; dirs[2] = rt_cfg.root_dir;
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
@@ -114,6 +128,10 @@ static void dos_open(int create) {
|
|||||||
dos_error(2); return;
|
dos_error(2); return;
|
||||||
}
|
}
|
||||||
f = fopen(path, "rb");
|
f = fopen(path, "rb");
|
||||||
|
if (f) {
|
||||||
|
char rel[260];
|
||||||
|
hd_file_opened(game_rel(name, rel, sizeof rel), path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!f) { dos_error(2); return; }
|
if (!f) { dos_error(2); return; }
|
||||||
h = alloc_handle(f, create || mode != 0);
|
h = alloc_handle(f, create || mode != 0);
|
||||||
@@ -475,6 +493,7 @@ void dos_reset(void) {
|
|||||||
int i;
|
int i;
|
||||||
for (i = 5; i < NFILES; i++) if (files[i]) { fclose(files[i]); files[i] = NULL; }
|
for (i = 5; i < NFILES; i++) if (files[i]) { fclose(files[i]); files[i] = NULL; }
|
||||||
memset(file_writable, 0, sizeof file_writable);
|
memset(file_writable, 0, sizeof file_writable);
|
||||||
|
hd_reset();
|
||||||
memset(sel_tab_base, 0, sizeof sel_tab_base);
|
memset(sel_tab_base, 0, sizeof sel_tab_base);
|
||||||
memset(sel_used, 0, sizeof sel_used);
|
memset(sel_used, 0, sizeof sel_used);
|
||||||
memset(pm_vec_off, 0, sizeof pm_vec_off);
|
memset(pm_vec_off, 0, sizeof pm_vec_off);
|
||||||
|
|||||||
+7
-1
@@ -7,9 +7,15 @@ typedef struct { int x, y, w, h; } GfxRect; /* origine en haut à gauche, en p
|
|||||||
|
|
||||||
int gfx_init(void); /* 0 si OpenGL 3.3 indisponible ou shader invalide */
|
int gfx_init(void); /* 0 si OpenGL 3.3 indisponible ou shader invalide */
|
||||||
void gfx_shutdown(void);
|
void gfx_shutdown(void);
|
||||||
void gfx_set_game(const uint32_t *argb, int w, int h); /* image du jeu, 0xAARRGGBB */
|
void gfx_set_game(const uint32_t *argb, int w, int h); /* image du jeu, 0xAARRGGBB (alpha 0 : décor HD visible) */
|
||||||
void gfx_set_overlay(const uint32_t *argb, int w, int h); /* surimpression, alpha non prémultiplié */
|
void gfx_set_overlay(const uint32_t *argb, int w, int h); /* surimpression, alpha non prémultiplié */
|
||||||
GfxRect gfx_fit(int out_w, int out_h, int aspect_w, int aspect_h); /* plus grand rectangle centré à ce format */
|
GfxRect gfx_fit(int out_w, int out_h, int aspect_w, int aspect_h); /* plus grand rectangle centré à ce format */
|
||||||
/* dessine une image complète (sans échange de tampons) :
|
/* dessine une image complète (sans échange de tampons) :
|
||||||
* game_aspect_h = 240 (4:3) ou 200 (pixels carrés) ; veil 0..1 assombrit tout ; overlay_alpha 0 = pas de surimpression */
|
* game_aspect_h = 240 (4:3) ou 200 (pixels carrés) ; veil 0..1 assombrit tout ; overlay_alpha 0 = pas de surimpression */
|
||||||
void gfx_draw(int out_w, int out_h, int filter, int game_aspect_h, float veil, float overlay_alpha);
|
void gfx_draw(int out_w, int out_h, int filter, int game_aspect_h, float veil, float overlay_alpha);
|
||||||
|
|
||||||
|
/* Pack HD : jusqu'à GFX_HD_PARTS images de décor côte à côte, chacune couvrant 320×200 pixels d'origine */
|
||||||
|
#define GFX_HD_PARTS 4
|
||||||
|
int gfx_hd_load(int part, const uint32_t *argb, int w, int h); /* 0 si l'image est trop grande pour le GPU */
|
||||||
|
/* état de l'image suivante : offset = colonne d'origine affichée à gauche ; tint = facteur de couleur (fondus) */
|
||||||
|
void gfx_hd_frame(int active, int parts, int offset, const float tint[3]);
|
||||||
+91
-11
@@ -5,6 +5,8 @@
|
|||||||
* lissé : « sharp bilinear » : agrandissement entier puis bilinéaire sur le reste (pas de flou, pas de pixels inégaux)
|
* lissé : « sharp bilinear » : agrandissement entier puis bilinéaire sur le reste (pas de flou, pas de pixels inégaux)
|
||||||
* xBR : détection de contours façon xBR niveau 2, rendue ×4 dans une texture intermédiaire, puis « lissé »
|
* xBR : détection de contours façon xBR niveau 2, rendue ×4 dans une texture intermédiaire, puis « lissé »
|
||||||
* CRT : lignes de balayage dont l'épaisseur dépend de la luminosité, masque à grille, légère courbure
|
* CRT : lignes de balayage dont l'épaisseur dépend de la luminosité, masque à grille, légère courbure
|
||||||
|
* Pack HD : les images HD du décor sont dessinées d'abord, puis l'image du jeu par-dessus, dont le canal alpha
|
||||||
|
* (masque de hd.c) vaut 0 là où le décor d'origine est visible. Le CRT ignore le pack HD.
|
||||||
* Puis voile (menu) et surimpression. Toutes les couleurs passent par la palette VGA déjà convertie par l'hôte. */
|
* Puis voile (menu) et surimpression. Toutes les couleurs passent par la palette VGA déjà convertie par l'hôte. */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -29,7 +31,7 @@
|
|||||||
X(PFNGLDELETEVERTEXARRAYSPROC, glDeleteVertexArrays) X(PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers) \
|
X(PFNGLDELETEVERTEXARRAYSPROC, glDeleteVertexArrays) X(PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers) \
|
||||||
X(PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer) X(PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D) \
|
X(PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer) X(PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D) \
|
||||||
X(PFNGLCHECKFRAMEBUFFERSTATUSPROC, glCheckFramebufferStatus) X(PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers) \
|
X(PFNGLCHECKFRAMEBUFFERSTATUSPROC, glCheckFramebufferStatus) X(PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers) \
|
||||||
X(PFNGLACTIVETEXTUREPROC, glActiveTexture)
|
X(PFNGLACTIVETEXTUREPROC, glActiveTexture) X(PFNGLGENERATEMIPMAPPROC, glGenerateMipmap)
|
||||||
|
|
||||||
#define X(type, name) static type p_##name;
|
#define X(type, name) static type p_##name;
|
||||||
GL_FUNCS
|
GL_FUNCS
|
||||||
@@ -58,7 +60,7 @@ static const char *VS =
|
|||||||
static const char *FS_NEAREST = FS_HEAD
|
static const char *FS_NEAREST = FS_HEAD
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" ivec2 p = ivec2(clamp(floor(v_uv * u_src_size), vec2(0.0), u_src_size - 1.0));\n"
|
" ivec2 p = ivec2(clamp(floor(v_uv * u_src_size), vec2(0.0), u_src_size - 1.0));\n"
|
||||||
" o_color = vec4(texelFetch(u_src, p, 0).rgb, 1.0);\n"
|
" o_color = texelFetch(u_src, p, 0);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
/* agrandissement entier implicite, interpolation limitée à la bordure entre deux pixels source */
|
/* agrandissement entier implicite, interpolation limitée à la bordure entre deux pixels source */
|
||||||
@@ -69,7 +71,7 @@ static const char *FS_SMOOTH = FS_HEAD
|
|||||||
" vec2 c = fract(t) - 0.5;\n"
|
" vec2 c = fract(t) - 0.5;\n"
|
||||||
" vec2 r = 0.5 - 0.5 / k;\n"
|
" vec2 r = 0.5 - 0.5 / k;\n"
|
||||||
" vec2 f = (c - clamp(c, -r, r)) * k + 0.5;\n"
|
" vec2 f = (c - clamp(c, -r, r)) * k + 0.5;\n"
|
||||||
" o_color = vec4(texture(u_src, (floor(t) + f) / u_src_size).rgb, 1.0);\n"
|
" o_color = texture(u_src, (floor(t) + f) / u_src_size);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
static const char *FS_OVERLAY = FS_HEAD
|
static const char *FS_OVERLAY = FS_HEAD
|
||||||
@@ -81,12 +83,31 @@ static const char *FS_OVERLAY = FS_HEAD
|
|||||||
static const char *FS_SOLID = FS_HEAD
|
static const char *FS_SOLID = FS_HEAD
|
||||||
"void main() { o_color = u_color; }\n";
|
"void main() { o_color = u_color; }\n";
|
||||||
|
|
||||||
|
/* Décor HD : jusqu'à 4 images côte à côte (320 colonnes d'origine chacune), décalées de u_offset colonnes.
|
||||||
|
* Les dérivées sont prises sur la coordonnée continue, pour que le niveau de mipmap ne saute pas au raccord. */
|
||||||
|
static const char *FS_HD = FS_HEAD
|
||||||
|
"uniform sampler2D u_hd0, u_hd1, u_hd2, u_hd3;\n"
|
||||||
|
"uniform float u_offset;\n"
|
||||||
|
"uniform int u_parts;\n"
|
||||||
|
"void main() {\n"
|
||||||
|
" float gx = (v_uv.x * 320.0 + u_offset) / 320.0;\n"
|
||||||
|
" int i = clamp(int(floor(gx)), 0, u_parts - 1);\n"
|
||||||
|
" vec2 uv = vec2(gx - float(i), v_uv.y);\n"
|
||||||
|
" vec2 dx = dFdx(vec2(gx, v_uv.y)), dy = dFdy(vec2(gx, v_uv.y));\n"
|
||||||
|
" vec4 c;\n"
|
||||||
|
" if (i == 0) c = textureGrad(u_hd0, uv, dx, dy);\n"
|
||||||
|
" else if (i == 1) c = textureGrad(u_hd1, uv, dx, dy);\n"
|
||||||
|
" else if (i == 2) c = textureGrad(u_hd2, uv, dx, dy);\n"
|
||||||
|
" else c = textureGrad(u_hd3, uv, dx, dy);\n"
|
||||||
|
" o_color = vec4(c.rgb * u_color.rgb, 1.0);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
/* Contours façon xBR (niveau 2) : pour chacun des 4 coins du pixel E, on compare deux sommes pondérées de
|
/* Contours façon xBR (niveau 2) : pour chacun des 4 coins du pixel E, on compare deux sommes pondérées de
|
||||||
* différences de couleur le long des deux diagonales ; si le contour traverse le coin, on mélange E avec
|
* différences de couleur le long des deux diagonales ; si le contour traverse le coin, on mélange E avec
|
||||||
* le voisin le plus proche, suivant une droite à 45°, ou à 30°/60° quand le contour se prolonge. */
|
* le voisin le plus proche, suivant une droite à 45°, ou à 30°/60° quand le contour se prolonge. */
|
||||||
static const char *FS_XBR = FS_HEAD
|
static const char *FS_XBR = FS_HEAD
|
||||||
"vec3 Y[25];\n"
|
"vec3 Y[25];\n"
|
||||||
"vec3 P[25];\n"
|
"vec4 P[25];\n"
|
||||||
"vec3 yuv(vec3 c) {\n"
|
"vec3 yuv(vec3 c) {\n"
|
||||||
" return vec3(dot(c, vec3(0.299, 0.587, 0.114)), dot(c, vec3(-0.169, -0.331, 0.5)), dot(c, vec3(0.5, -0.419, -0.081)));\n"
|
" return vec3(dot(c, vec3(0.299, 0.587, 0.114)), dot(c, vec3(-0.169, -0.331, 0.5)), dot(c, vec3(0.5, -0.419, -0.081)));\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
@@ -104,10 +125,10 @@ static const char *FS_XBR = FS_HEAD
|
|||||||
" for (int j = -2; j <= 2; j++)\n"
|
" for (int j = -2; j <= 2; j++)\n"
|
||||||
" for (int i = -2; i <= 2; i++) {\n"
|
" for (int i = -2; i <= 2; i++) {\n"
|
||||||
" int k = (i + 2) + (j + 2) * 5;\n"
|
" int k = (i + 2) + (j + 2) * 5;\n"
|
||||||
" P[k] = texelFetch(u_src, clamp(base + ivec2(i, j), ivec2(0), mx), 0).rgb;\n"
|
" P[k] = texelFetch(u_src, clamp(base + ivec2(i, j), ivec2(0), mx), 0);\n"
|
||||||
" Y[k] = yuv(P[k]);\n"
|
" Y[k] = yuv(P[k].rgb);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" vec3 res = P[12];\n"
|
" vec4 res = P[12];\n"
|
||||||
" for (int r = 0; r < 4; r++) {\n"
|
" for (int r = 0; r < 4; r++) {\n"
|
||||||
" if (r == 0) { AX = ivec2(1, 0); AY = ivec2(0, 1); }\n"
|
" if (r == 0) { AX = ivec2(1, 0); AY = ivec2(0, 1); }\n"
|
||||||
" else if (r == 1) { AX = ivec2(0, 1); AY = ivec2(-1, 0); }\n"
|
" else if (r == 1) { AX = ivec2(0, 1); AY = ivec2(-1, 0); }\n"
|
||||||
@@ -127,10 +148,10 @@ static const char *FS_XBR = FS_HEAD
|
|||||||
" float a = smoothstep(1.5 - w, 1.5 + w, fp.x + fp.y);\n"
|
" float a = smoothstep(1.5 - w, 1.5 + w, fp.x + fp.y);\n"
|
||||||
" if (left) a = max(a, smoothstep(1.0 - w, 1.0 + w, 0.5 * fp.x + fp.y));\n"
|
" if (left) a = max(a, smoothstep(1.0 - w, 1.0 + w, 0.5 * fp.x + fp.y));\n"
|
||||||
" if (up) a = max(a, smoothstep(1.0 - w, 1.0 + w, fp.x + 0.5 * fp.y));\n"
|
" if (up) a = max(a, smoothstep(1.0 - w, 1.0 + w, fp.x + 0.5 * fp.y));\n"
|
||||||
" vec3 px = df(E, F) <= df(E, H) ? P[F] : P[H];\n"
|
" vec4 px = df(E, F) <= df(E, H) ? P[F] : P[H];\n"
|
||||||
" res = mix(res, px, a);\n"
|
" res = mix(res, px, a);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" o_color = vec4(res, 1.0);\n"
|
" o_color = res;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
/* Écran cathodique : calcul en lumière linéaire, deux lignes source voisines dont le faisceau (gaussien)
|
/* Écran cathodique : calcul en lumière linéaire, deux lignes source voisines dont le faisceau (gaussien)
|
||||||
@@ -174,13 +195,16 @@ static const char *FS_CRT = FS_HEAD
|
|||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ état */
|
/* ------------------------------------------------------------------ état */
|
||||||
enum { PG_NEAREST, PG_SMOOTH, PG_XBR, PG_CRT, PG_OVERLAY, PG_SOLID, PG_COUNT };
|
enum { PG_NEAREST, PG_SMOOTH, PG_XBR, PG_CRT, PG_OVERLAY, PG_SOLID, PG_HD, PG_COUNT };
|
||||||
typedef struct { GLuint id; GLint src, src_size, out_size, alpha, color, flip; } Prog;
|
typedef struct { GLuint id; GLint src, src_size, out_size, alpha, color, flip; } Prog;
|
||||||
static float pass_flip = 1.f; /* -1 : la cible est une texture intermédiaire (lue ensuite à l'endroit) */
|
static float pass_flip = 1.f; /* -1 : la cible est une texture intermédiaire (lue ensuite à l'endroit) */
|
||||||
static Prog prog[PG_COUNT];
|
static Prog prog[PG_COUNT];
|
||||||
static GLuint vao, tex_game, tex_ovl, tex_xbr, fbo_xbr;
|
static GLuint vao, tex_game, tex_ovl, tex_xbr, fbo_xbr;
|
||||||
static int game_w = 320, game_h = 200;
|
static int game_w = 320, game_h = 200;
|
||||||
#define XBR_SCALE 4
|
#define XBR_SCALE 4
|
||||||
|
static GLuint tex_hd[GFX_HD_PARTS];
|
||||||
|
static int hd_w[GFX_HD_PARTS];
|
||||||
|
static struct { int active, parts, offset; float tint[3]; } hd;
|
||||||
|
|
||||||
static GLuint compile(GLenum type, const char *body) {
|
static GLuint compile(GLenum type, const char *body) {
|
||||||
const char *src[2] = {"#version 330 core\nprecision highp float;\n", body};
|
const char *src[2] = {"#version 330 core\nprecision highp float;\n", body};
|
||||||
@@ -238,7 +262,7 @@ static GLuint make_tex(int w, int h, GLint filter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int gfx_init(void) {
|
int gfx_init(void) {
|
||||||
const char *const fs[PG_COUNT] = {FS_NEAREST, FS_SMOOTH, FS_XBR, FS_CRT, FS_OVERLAY, FS_SOLID};
|
const char *const fs[PG_COUNT] = {FS_NEAREST, FS_SMOOTH, FS_XBR, FS_CRT, FS_OVERLAY, FS_SOLID, FS_HD};
|
||||||
int i;
|
int i;
|
||||||
#define X(type, name) \
|
#define X(type, name) \
|
||||||
if (!(p_##name = (type)SDL_GL_GetProcAddress(#name))) { fprintf(stderr, "[gfx] fonction GL absente : %s\n", #name); return 0; }
|
if (!(p_##name = (type)SDL_GL_GetProcAddress(#name))) { fprintf(stderr, "[gfx] fonction GL absente : %s\n", #name); return 0; }
|
||||||
@@ -271,6 +295,7 @@ void gfx_shutdown(void) {
|
|||||||
if (tex_game) glDeleteTextures(1, &tex_game);
|
if (tex_game) glDeleteTextures(1, &tex_game);
|
||||||
if (tex_ovl) glDeleteTextures(1, &tex_ovl);
|
if (tex_ovl) glDeleteTextures(1, &tex_ovl);
|
||||||
if (tex_xbr) glDeleteTextures(1, &tex_xbr);
|
if (tex_xbr) glDeleteTextures(1, &tex_xbr);
|
||||||
|
for (i = 0; i < GFX_HD_PARTS; i++) if (tex_hd[i]) glDeleteTextures(1, &tex_hd[i]);
|
||||||
if (vao) p_glDeleteVertexArrays(1, &vao);
|
if (vao) p_glDeleteVertexArrays(1, &vao);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,6 +309,52 @@ void gfx_set_overlay(const uint32_t *argb, int w, int h) {
|
|||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, argb);
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, argb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gfx_hd_load(int part, const uint32_t *argb, int w, int h) {
|
||||||
|
GLint max = 0;
|
||||||
|
if (part < 0 || part >= GFX_HD_PARTS) return 0;
|
||||||
|
hd_w[part] = 0;
|
||||||
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
|
||||||
|
if (w > max || h > max) { fprintf(stderr, "[gfx] image HD %dx%d trop grande (max %d)\n", w, h, max); return 0; }
|
||||||
|
if (!tex_hd[part]) glGenTextures(1, &tex_hd[part]);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_hd[part]);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, argb);
|
||||||
|
p_glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
hd_w[part] = w;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gfx_hd_frame(int active, int parts, int offset, const float tint[3]) {
|
||||||
|
int i;
|
||||||
|
hd.active = active && parts > 0 && parts <= GFX_HD_PARTS;
|
||||||
|
for (i = 0; hd.active && i < parts; i++) if (!hd_w[i]) hd.active = 0;
|
||||||
|
hd.parts = parts;
|
||||||
|
hd.offset = offset;
|
||||||
|
for (i = 0; i < 3; i++) hd.tint[i] = tint ? tint[i] : 1.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_hd(GfxRect g, int out_h) {
|
||||||
|
static const char *names[GFX_HD_PARTS] = {"u_hd0", "u_hd1", "u_hd2", "u_hd3"};
|
||||||
|
const Prog *p = &prog[PG_HD];
|
||||||
|
int i;
|
||||||
|
glViewport(g.x, out_h - g.y - g.h, g.w, g.h);
|
||||||
|
p_glUseProgram(p->id);
|
||||||
|
for (i = 0; i < GFX_HD_PARTS; i++) {
|
||||||
|
p_glActiveTexture(GL_TEXTURE0 + i);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_hd[i < hd.parts ? i : 0]);
|
||||||
|
p_glUniform1i(p_glGetUniformLocation(p->id, names[i]), i);
|
||||||
|
}
|
||||||
|
p_glActiveTexture(GL_TEXTURE0);
|
||||||
|
p_glUniform1f(p_glGetUniformLocation(p->id, "u_offset"), (float)hd.offset);
|
||||||
|
p_glUniform1i(p_glGetUniformLocation(p->id, "u_parts"), hd.parts);
|
||||||
|
p_glUniform4f(p->color, hd.tint[0], hd.tint[1], hd.tint[2], 1.f);
|
||||||
|
if (p->flip >= 0) p_glUniform1f(p->flip, 1.f);
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
}
|
||||||
|
|
||||||
GfxRect gfx_fit(int out_w, int out_h, int aw, int ah) {
|
GfxRect gfx_fit(int out_w, int out_h, int aw, int ah) {
|
||||||
GfxRect r;
|
GfxRect r;
|
||||||
if ((long long)out_w * ah > (long long)out_h * aw) { r.h = out_h; r.w = (int)((long long)out_h * aw / ah); }
|
if ((long long)out_w * ah > (long long)out_h * aw) { r.h = out_h; r.w = (int)((long long)out_h * aw / ah); }
|
||||||
@@ -314,21 +385,30 @@ void gfx_draw(int out_w, int out_h, int filter, int game_aspect_h, float veil, f
|
|||||||
glViewport(0, 0, out_w, out_h);
|
glViewport(0, 0, out_w, out_h);
|
||||||
glClearColor(0, 0, 0, 1);
|
glClearColor(0, 0, 0, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
if (hd.active && filter != FILTER_CRT) {
|
||||||
|
draw_hd(g, out_h);
|
||||||
|
glEnable(GL_BLEND); /* image du jeu par-dessus, transparente là où le décor HD la remplace */
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
switch (filter) {
|
switch (filter) {
|
||||||
case FILTER_SMOOTH: pass(&prog[PG_SMOOTH], tex_game, game_w, game_h, g, out_h); break;
|
case FILTER_SMOOTH: pass(&prog[PG_SMOOTH], tex_game, game_w, game_h, g, out_h); break;
|
||||||
case FILTER_CRT: pass(&prog[PG_CRT], tex_game, game_w, game_h, g, out_h); break;
|
case FILTER_CRT: pass(&prog[PG_CRT], tex_game, game_w, game_h, g, out_h); break;
|
||||||
case FILTER_XBR: {
|
case FILTER_XBR: {
|
||||||
GfxRect f = {0, 0, game_w * XBR_SCALE, game_h * XBR_SCALE};
|
GfxRect f = {0, 0, game_w * XBR_SCALE, game_h * XBR_SCALE};
|
||||||
|
GLboolean blend = glIsEnabled(GL_BLEND);
|
||||||
|
glDisable(GL_BLEND); /* l'alpha est recopié tel quel dans la texture intermédiaire */
|
||||||
p_glBindFramebuffer(GL_FRAMEBUFFER, fbo_xbr);
|
p_glBindFramebuffer(GL_FRAMEBUFFER, fbo_xbr);
|
||||||
pass_flip = -1.f;
|
pass_flip = -1.f;
|
||||||
pass(&prog[PG_XBR], tex_game, game_w, game_h, f, f.h);
|
pass(&prog[PG_XBR], tex_game, game_w, game_h, f, f.h);
|
||||||
pass_flip = 1.f;
|
pass_flip = 1.f;
|
||||||
p_glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
p_glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
if (blend) glEnable(GL_BLEND);
|
||||||
pass(&prog[PG_SMOOTH], tex_xbr, f.w, f.h, g, out_h);
|
pass(&prog[PG_SMOOTH], tex_xbr, f.w, f.h, g, out_h);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: pass(&prog[PG_NEAREST], tex_game, game_w, game_h, g, out_h); break;
|
default: pass(&prog[PG_NEAREST], tex_game, game_w, game_h, g, out_h); break;
|
||||||
}
|
}
|
||||||
|
glDisable(GL_BLEND);
|
||||||
if (veil > 0 || overlay_alpha > 0) {
|
if (veil > 0 || overlay_alpha > 0) {
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|||||||
+213
@@ -0,0 +1,213 @@
|
|||||||
|
/* Pack HD : voir hd.h. */
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "hd.h"
|
||||||
|
#include "mods.h"
|
||||||
|
#include "rt.h"
|
||||||
|
|
||||||
|
#define W0 320
|
||||||
|
#define H0 200
|
||||||
|
#define NSTRIPS 4
|
||||||
|
#define NSAMPLES 512
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int id, parts;
|
||||||
|
char stem[16]; /* nom sans la lettre finale (LOC03 pour LOC03A, LOC03B…) */
|
||||||
|
char last; /* lettre du dernier morceau, 0 si nom sans lettre */
|
||||||
|
char png[HD_MAX_PARTS][600];
|
||||||
|
uint8_t *pix; /* parts × 320 × 200, ligne par ligne */
|
||||||
|
uint8_t pal[768]; /* palette 8 bits du premier morceau */
|
||||||
|
uint8_t used[256]; /* indices présents dans le décor */
|
||||||
|
int last_off, last_score;
|
||||||
|
} Strip;
|
||||||
|
|
||||||
|
static Strip strips[NSTRIPS]; /* strips[0] = le plus récent */
|
||||||
|
static int enabled = 1, next_id = 1;
|
||||||
|
static int sx[NSAMPLES], sy[NSAMPLES];
|
||||||
|
static const char *png_ptr[HD_MAX_PARTS];
|
||||||
|
|
||||||
|
void hd_set_enabled(int on) { enabled = on; }
|
||||||
|
int hd_enabled(void) { return enabled; }
|
||||||
|
|
||||||
|
void hd_reset(void) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < NSTRIPS; i++) { free(strips[i].pix); memset(&strips[i], 0, sizeof strips[i]); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* PCX 320×200 8 bits → indices + palette ; 0 si format inattendu */
|
||||||
|
static int read_pcx(const char *path, uint8_t *pix, uint8_t *pal) {
|
||||||
|
FILE *f = fopen(path, "rb");
|
||||||
|
uint8_t *d;
|
||||||
|
long len;
|
||||||
|
int ok = 0;
|
||||||
|
if (!f) return 0;
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
len = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
d = (len > 128 + 769 && len < (1 << 22)) ? (uint8_t *)malloc((size_t)len) : NULL;
|
||||||
|
if (d && fread(d, 1, (size_t)len, f) == (size_t)len && d[0] == 10 && d[3] == 8 && d[65] == 1 && d[len - 769] == 12) {
|
||||||
|
int w = (d[8] | d[9] << 8) - (d[4] | d[5] << 8) + 1, h = (d[10] | d[11] << 8) - (d[6] | d[7] << 8) + 1;
|
||||||
|
int bpl = d[66] | d[67] << 8, y = 0, x = 0;
|
||||||
|
long i = 128, end = len - 769;
|
||||||
|
if (w == W0 && h == H0 && bpl >= W0) {
|
||||||
|
while (y < H0 && i < end) {
|
||||||
|
int b = d[i++], run = 1;
|
||||||
|
if (b >= 0xc0) { run = b & 0x3f; b = i < end ? d[i++] : 0; }
|
||||||
|
while (run-- > 0 && y < H0) {
|
||||||
|
if (x < W0) pix[y * W0 + x] = (uint8_t)b;
|
||||||
|
if (++x == bpl) { x = 0; y++; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memcpy(pal, d + len - 768, 768);
|
||||||
|
ok = y == H0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(d);
|
||||||
|
fclose(f);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* « LOC03A.PCX » → racine « LOC03 », lettre 'A' ; nom sans lettre finale → lettre 0 */
|
||||||
|
static void split_name(const char *base, char *stem, size_t n, char *letter) {
|
||||||
|
size_t len = 0;
|
||||||
|
while (base[len] && base[len] != '.') len++;
|
||||||
|
if (len >= n) len = n - 1;
|
||||||
|
memcpy(stem, base, len);
|
||||||
|
stem[len] = 0;
|
||||||
|
*letter = 0;
|
||||||
|
if (len >= 2 && stem[len - 1] >= 'A' && stem[len - 1] <= 'D' && isdigit((unsigned char)stem[len - 2])) {
|
||||||
|
*letter = stem[len - 1];
|
||||||
|
stem[len - 1] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void hd_file_opened(const char *rel, const char *host_path) {
|
||||||
|
const char *base = strrchr(rel, '\\');
|
||||||
|
char stem[16], letter, name[20], png[600];
|
||||||
|
uint8_t *part;
|
||||||
|
Strip *s = &strips[0];
|
||||||
|
size_t len;
|
||||||
|
base = base ? base + 1 : rel;
|
||||||
|
len = strlen(base);
|
||||||
|
if (len < 5 || strcmp(base + len - 4, ".PCX")) return; /* noté même désactivé : réactivable en jeu */
|
||||||
|
snprintf(name, sizeof name, "%.*s", (int)(len - 4), base);
|
||||||
|
if (!mods_find_hd(name, png, sizeof png)) return;
|
||||||
|
split_name(base, stem, sizeof stem, &letter);
|
||||||
|
/* morceau suivant d'une pièce en plusieurs parties (LOCxxB juste après LOCxxA…) */
|
||||||
|
if (!(letter && s->pix && s->last && letter == s->last + 1 && s->parts < HD_MAX_PARTS && !strcmp(s->stem, stem))) {
|
||||||
|
free(strips[NSTRIPS - 1].pix);
|
||||||
|
memmove(&strips[1], &strips[0], (NSTRIPS - 1) * sizeof strips[0]);
|
||||||
|
memset(s, 0, sizeof *s);
|
||||||
|
snprintf(s->stem, sizeof s->stem, "%s", stem);
|
||||||
|
}
|
||||||
|
part = (uint8_t *)malloc(W0 * H0);
|
||||||
|
if (!part) return;
|
||||||
|
{
|
||||||
|
static uint8_t other_pal[768]; /* les morceaux suivants partagent la palette du premier */
|
||||||
|
if (!read_pcx(host_path, part, s->parts ? other_pal : s->pal)) { free(part); return; }
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int n = s->parts + 1, y;
|
||||||
|
uint8_t *pix = (uint8_t *)malloc((size_t)n * W0 * H0);
|
||||||
|
if (!pix) { free(part); return; }
|
||||||
|
for (y = 0; y < H0; y++) {
|
||||||
|
if (s->parts) memcpy(pix + (size_t)y * n * W0, s->pix + (size_t)y * s->parts * W0, (size_t)s->parts * W0);
|
||||||
|
memcpy(pix + (size_t)y * n * W0 + (size_t)s->parts * W0, part + y * W0, W0);
|
||||||
|
}
|
||||||
|
for (y = 0; y < W0 * H0; y++) s->used[part[y]] = 1;
|
||||||
|
free(s->pix);
|
||||||
|
free(part);
|
||||||
|
s->pix = pix;
|
||||||
|
snprintf(s->png[s->parts], sizeof s->png[0], "%s", png);
|
||||||
|
s->parts = n;
|
||||||
|
s->last = letter;
|
||||||
|
s->id = next_id++;
|
||||||
|
s->last_score = 0;
|
||||||
|
if (rt_cfg.verbose) fprintf(stderr, "[hd] %s : morceau %d (%s)\n", stem, n, png);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void init_samples(void) {
|
||||||
|
uint32_t r = 12345;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < NSAMPLES; i++) {
|
||||||
|
r = r * 1103515245u + 12345u; sx[i] = (int)((r >> 8) % W0);
|
||||||
|
r = r * 1103515245u + 12345u; sy[i] = (int)((r >> 8) % H0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int score_at(const Strip *s, const uint8_t *fb, int off) {
|
||||||
|
int i, n = 0, w = s->parts * W0;
|
||||||
|
for (i = 0; i < NSAMPLES; i++) n += fb[sy[i] * W0 + sx[i]] == s->pix[sy[i] * w + sx[i] + off];
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* fondu : rapport entre palette courante et palette du décor, s'il s'agit bien d'un simple facteur */
|
||||||
|
static int palette_tint(const Strip *s, const uint8_t *dac, float tint[3]) {
|
||||||
|
double cur[3] = {0}, org[3] = {0}, err = 0, tot = 0;
|
||||||
|
int i, c;
|
||||||
|
for (i = 0; i < 256; i++)
|
||||||
|
if (s->used[i])
|
||||||
|
for (c = 0; c < 3; c++) {
|
||||||
|
int v = dac[i * 3 + c] & 63;
|
||||||
|
cur[c] += (v << 2 | v >> 4);
|
||||||
|
org[c] += s->pal[i * 3 + c];
|
||||||
|
}
|
||||||
|
for (c = 0; c < 3; c++) tint[c] = (float)((cur[c] + 1.0) / (org[c] + 1.0));
|
||||||
|
for (i = 0; i < 256; i++)
|
||||||
|
if (s->used[i])
|
||||||
|
for (c = 0; c < 3; c++) {
|
||||||
|
int v = dac[i * 3 + c] & 63;
|
||||||
|
err += fabs((v << 2 | v >> 4) - tint[c] * s->pal[i * 3 + c]);
|
||||||
|
tot += s->pal[i * 3 + c];
|
||||||
|
}
|
||||||
|
return tot <= 0 || err / tot < 0.12;
|
||||||
|
}
|
||||||
|
|
||||||
|
int hd_compose(const uint8_t *fb, const uint8_t *dac, uint8_t *mask, HdFrame *out) {
|
||||||
|
int k, best_k = -1, best_off = 0, best = 0, x, y, i;
|
||||||
|
memset(out, 0, sizeof *out);
|
||||||
|
if (!enabled || !strips[0].pix) return 0;
|
||||||
|
if (!sx[0] && !sy[0]) init_samples();
|
||||||
|
for (k = 0; k < NSTRIPS; k++) {
|
||||||
|
Strip *s = &strips[k];
|
||||||
|
int off, maxoff, sc;
|
||||||
|
if (!s->pix) continue;
|
||||||
|
maxoff = (s->parts - 1) * W0;
|
||||||
|
/* d'abord le décalage précédent : en général rien n'a bougé */
|
||||||
|
sc = score_at(s, fb, s->last_off);
|
||||||
|
if (s->last_score && sc * 10 >= s->last_score * 9) off = s->last_off;
|
||||||
|
else {
|
||||||
|
int o;
|
||||||
|
off = s->last_off;
|
||||||
|
for (o = 0; o <= maxoff; o++) {
|
||||||
|
int v = o == s->last_off ? sc : score_at(s, fb, o);
|
||||||
|
if (v > sc) { sc = v; off = o; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sc > best) { best = sc; best_k = k; best_off = off; }
|
||||||
|
s->last_off = off;
|
||||||
|
s->last_score = sc;
|
||||||
|
}
|
||||||
|
if (best_k < 0 || best * 100 < NSAMPLES * 35) return 0; /* le décor n'est pas à l'écran */
|
||||||
|
{
|
||||||
|
Strip *s = &strips[best_k];
|
||||||
|
int w = s->parts * W0;
|
||||||
|
if (!palette_tint(s, dac, out->tint)) return 0;
|
||||||
|
for (y = 0; y < H0; y++) {
|
||||||
|
const uint8_t *bg = s->pix + (size_t)y * w + best_off, *row = fb + y * W0;
|
||||||
|
uint8_t *m = mask + y * W0;
|
||||||
|
for (x = 0; x < W0; x++) m[x] = row[x] == bg[x] ? 0 : 255;
|
||||||
|
}
|
||||||
|
out->active = 1;
|
||||||
|
out->set_id = s->id;
|
||||||
|
out->parts = s->parts;
|
||||||
|
for (i = 0; i < s->parts; i++) png_ptr[i] = s->png[i];
|
||||||
|
for (i = 0; i < s->parts; i++) out->png[i] = png_ptr[i];
|
||||||
|
out->offset = best_off;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/* Pack HD : remplace à l'écran les décors du jeu par des images haute définition fournies par les mods.
|
||||||
|
*
|
||||||
|
* Principe (aucune connaissance du moteur du jeu n'est nécessaire) : quand le jeu ouvre une image PCX pour
|
||||||
|
* laquelle un mod fournit un PNG HD, on décode le PCX d'origine. À chaque image, on cherche ce décor (et son
|
||||||
|
* décalage de défilement, pour les pièces en plusieurs morceaux LOCxxA, LOCxxB…) dans l'écran 320×200 du jeu :
|
||||||
|
* les pixels identiques au décor d'origine sont remplacés par l'image HD, les autres (personnages, objets,
|
||||||
|
* panneau, textes) restent ceux du jeu. Les fondus de palette sont reportés sur l'image HD. */
|
||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define HD_MAX_PARTS 4
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int active; /* 1 : dessiner l'image HD sous l'image du jeu */
|
||||||
|
int set_id; /* change quand le jeu d'images change : textures à recharger */
|
||||||
|
int parts; /* morceaux côte à côte, de gauche à droite (320 pixels d'origine chacun) */
|
||||||
|
const char *png[HD_MAX_PARTS]; /* chemins des PNG HD */
|
||||||
|
int offset; /* défilement : colonne d'origine affichée à gauche de l'écran */
|
||||||
|
float tint[3]; /* multiplicateur de couleur (fondus) */
|
||||||
|
} HdFrame;
|
||||||
|
|
||||||
|
void hd_set_enabled(int on);
|
||||||
|
int hd_enabled(void);
|
||||||
|
void hd_reset(void);
|
||||||
|
void hd_file_opened(const char *rel, const char *host_path); /* appelé par dos.c à chaque ouverture */
|
||||||
|
/* fb : écran 320×200 en indices ; dac : palette VGA 6 bits ; mask : 320×200, 0 = HD, 255 = pixel du jeu */
|
||||||
|
int hd_compose(const uint8_t *fb, const uint8_t *dac, uint8_t *mask, HdFrame *out);
|
||||||
+71
-3
@@ -3,16 +3,21 @@
|
|||||||
* Réglages lus et écrits dans settings.ini (%APPDATA%\DoubleTroubleRecomp\ par défaut, ou --config FICHIER),
|
* Réglages lus et écrits dans settings.ini (%APPDATA%\DoubleTroubleRecomp\ par défaut, ou --config FICHIER),
|
||||||
* partagé avec le launcher. Options d'affichage en ligne de commande (valables pour la session, voir docs/SETTINGS.md) :
|
* partagé avec le launcher. Options d'affichage en ligne de commande (valables pour la session, voir docs/SETTINGS.md) :
|
||||||
* --echelle N --plein --fenetre --filtre nearest|smooth|xbr|crt --format43 0|1 --vsync 0|1
|
* --echelle N --plein --fenetre --filtre nearest|smooth|xbr|crt --format43 0|1 --vsync 0|1
|
||||||
* --set cle=valeur --config FICHIER */
|
* --set cle=valeur --config FICHIER
|
||||||
|
* Mods (voir docs/MODS.md) : --mods DOSSIER --sans-mods --sans-hd */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#define SDL_MAIN_HANDLED
|
#define SDL_MAIN_HANDLED
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "rt.h"
|
#include "rt.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
#include "hd.h"
|
||||||
|
#include "mods.h"
|
||||||
|
#include "png.h"
|
||||||
|
|
||||||
int host_quit;
|
int host_quit;
|
||||||
static SDL_Window *win;
|
static SDL_Window *win;
|
||||||
@@ -103,6 +108,7 @@ static void apply_display(void) {
|
|||||||
SDL_SetWindowPosition(win, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
SDL_SetWindowPosition(win, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||||
}
|
}
|
||||||
if (settings.vsync != done_vsync) SDL_GL_SetSwapInterval(settings.vsync ? 1 : 0);
|
if (settings.vsync != done_vsync) SDL_GL_SetSwapInterval(settings.vsync ? 1 : 0);
|
||||||
|
hd_set_enabled(settings.hd_pack);
|
||||||
done_scale = settings.window_scale; done_fmt = settings.aspect_43; done_full = settings.fullscreen;
|
done_scale = settings.window_scale; done_fmt = settings.aspect_43; done_full = settings.fullscreen;
|
||||||
done_vsync = settings.vsync;
|
done_vsync = settings.vsync;
|
||||||
}
|
}
|
||||||
@@ -161,6 +167,9 @@ static void parse_options(int argc, char **argv) {
|
|||||||
else if (!strcmp(a, "--filtre") && v) { if (!settings_override("filter", v)) usage_option(a, v); i++; }
|
else if (!strcmp(a, "--filtre") && v) { if (!settings_override("filter", v)) usage_option(a, v); i++; }
|
||||||
else if (!strcmp(a, "--format43") && v) { if (!settings_override("aspect_43", v)) usage_option(a, v); i++; }
|
else if (!strcmp(a, "--format43") && v) { if (!settings_override("aspect_43", v)) usage_option(a, v); i++; }
|
||||||
else if (!strcmp(a, "--vsync") && v) { if (!settings_override("vsync", v)) usage_option(a, v); i++; }
|
else if (!strcmp(a, "--vsync") && v) { if (!settings_override("vsync", v)) usage_option(a, v); i++; }
|
||||||
|
else if (!strcmp(a, "--mods") && v) { settings_override("mods.dir", v); i++; }
|
||||||
|
else if (!strcmp(a, "--sans-mods")) settings_override("mods.enabled", "0");
|
||||||
|
else if (!strcmp(a, "--sans-hd")) settings_override("hd_pack", "0");
|
||||||
else if (!strcmp(a, "--set") && v) { /* --set cle=valeur, pour n'importe quelle clé */
|
else if (!strcmp(a, "--set") && v) { /* --set cle=valeur, pour n'importe quelle clé */
|
||||||
char kv[128], *eq;
|
char kv[128], *eq;
|
||||||
snprintf(kv, sizeof kv, "%s", v);
|
snprintf(kv, sizeof kv, "%s", v);
|
||||||
@@ -172,6 +181,54 @@ static void parse_options(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ mods */
|
||||||
|
static int is_dir(const char *p) {
|
||||||
|
struct stat st;
|
||||||
|
return stat(p, &st) == 0 && (st.st_mode & S_IFDIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* dossier des mods : réglage mods.dir, sinon « mods » à côté de l'exécutable (ou du dossier build\), sinon ./mods */
|
||||||
|
static void init_mods(void) {
|
||||||
|
char dir[600];
|
||||||
|
if (!settings.mods_enabled) { fprintf(stderr, "[mods] désactivés\n"); return; }
|
||||||
|
if (settings.mods_dir[0]) snprintf(dir, sizeof dir, "%s", settings.mods_dir);
|
||||||
|
else {
|
||||||
|
char *base = SDL_GetBasePath();
|
||||||
|
snprintf(dir, sizeof dir, "mods");
|
||||||
|
if (base) {
|
||||||
|
char a[600], b[600];
|
||||||
|
snprintf(a, sizeof a, "%smods", base);
|
||||||
|
snprintf(b, sizeof b, "%s..%cmods", base, base[strlen(base) - 1]);
|
||||||
|
if (is_dir(a)) snprintf(dir, sizeof dir, "%s", a);
|
||||||
|
else if (is_dir(b)) snprintf(dir, sizeof dir, "%s", b);
|
||||||
|
SDL_free(base);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rt_cfg.verbose) fprintf(stderr, "[mods] dossier %s\n", dir);
|
||||||
|
mods_init(dir, settings.mods_disabled);
|
||||||
|
menu_hd_available = mods_hd_count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* textures du décor HD courant ; rechargées quand hd.c change de jeu d'images */
|
||||||
|
static int hd_loaded_id = -1, hd_loaded_ok;
|
||||||
|
|
||||||
|
static int load_hd_set(const HdFrame *f) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < f->parts; i++) {
|
||||||
|
int w, h;
|
||||||
|
const char *err = NULL;
|
||||||
|
uint64_t t = SDL_GetPerformanceCounter();
|
||||||
|
uint32_t *img = png_load(f->png[i], &w, &h, &err);
|
||||||
|
if (!img) { fprintf(stderr, "[hd] %s : %s\n", f->png[i], err ? err : "illisible"); return 0; }
|
||||||
|
if (!gfx_hd_load(i, img, w, h)) { free(img); return 0; }
|
||||||
|
free(img);
|
||||||
|
if (rt_cfg.verbose)
|
||||||
|
fprintf(stderr, "[hd] %s : %dx%d (%.0f ms)\n", f->png[i], w, h,
|
||||||
|
(double)(SDL_GetPerformanceCounter() - t) * 1000.0 / (double)SDL_GetPerformanceFrequency());
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ cycle de vie */
|
/* ------------------------------------------------------------------ cycle de vie */
|
||||||
int host_init(int argc, char **argv) {
|
int host_init(int argc, char **argv) {
|
||||||
int i;
|
int i;
|
||||||
@@ -205,6 +262,7 @@ int host_init(int argc, char **argv) {
|
|||||||
ovl_px = (uint32_t *)malloc((size_t)MENU_W * MENU_H * 4);
|
ovl_px = (uint32_t *)malloc((size_t)MENU_W * MENU_H * 4);
|
||||||
if (!ovl_px) return 0;
|
if (!ovl_px) return 0;
|
||||||
apply_display();
|
apply_display();
|
||||||
|
init_mods();
|
||||||
menu_draw_toast(ovl_px, "F12 : réglages");
|
menu_draw_toast(ovl_px, "F12 : réglages");
|
||||||
gfx_set_overlay(ovl_px, MENU_W, MENU_H);
|
gfx_set_overlay(ovl_px, MENU_W, MENU_H);
|
||||||
SDL_ShowCursor(SDL_DISABLE); /* le jeu dessine son propre curseur */
|
SDL_ShowCursor(SDL_DISABLE); /* le jeu dessine son propre curseur */
|
||||||
@@ -225,6 +283,8 @@ int host_init(int argc, char **argv) {
|
|||||||
void host_shutdown(void) {
|
void host_shutdown(void) {
|
||||||
if (adev) SDL_CloseAudioDevice(adev);
|
if (adev) SDL_CloseAudioDevice(adev);
|
||||||
gfx_shutdown();
|
gfx_shutdown();
|
||||||
|
hd_reset();
|
||||||
|
mods_shutdown();
|
||||||
free(ovl_px);
|
free(ovl_px);
|
||||||
if (glctx) SDL_GL_DeleteContext(glctx);
|
if (glctx) SDL_GL_DeleteContext(glctx);
|
||||||
if (win) SDL_DestroyWindow(win);
|
if (win) SDL_DestroyWindow(win);
|
||||||
@@ -238,16 +298,24 @@ uint64_t host_time_us(void) {
|
|||||||
/* ------------------------------------------------------------------ image */
|
/* ------------------------------------------------------------------ image */
|
||||||
void host_frame(void) {
|
void host_frame(void) {
|
||||||
static uint32_t px[320 * 200];
|
static uint32_t px[320 * 200];
|
||||||
|
static uint8_t mask[320 * 200];
|
||||||
uint32_t pal[256];
|
uint32_t pal[256];
|
||||||
const uint8_t *src = M + VGA_BASE;
|
const uint8_t *src = M + VGA_BASE;
|
||||||
float toast = 0;
|
float toast = 0;
|
||||||
int i;
|
int i, hd_on = 0;
|
||||||
|
HdFrame hf;
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
uint32_t r = vga_dac[i * 3] & 63, g = vga_dac[i * 3 + 1] & 63, b = vga_dac[i * 3 + 2] & 63;
|
uint32_t r = vga_dac[i * 3] & 63, g = vga_dac[i * 3 + 1] & 63, b = vga_dac[i * 3 + 2] & 63;
|
||||||
pal[i] = 0xff000000u | (r << 2 | r >> 4) << 16 | (g << 2 | g >> 4) << 8 | (b << 2 | b >> 4);
|
pal[i] = 0xff000000u | (r << 2 | r >> 4) << 16 | (g << 2 | g >> 4) << 8 | (b << 2 | b >> 4);
|
||||||
}
|
}
|
||||||
for (i = 0; i < 320 * 200; i++) px[i] = pal[src[i]];
|
if (settings.filter != FILTER_CRT && hd_compose(src, vga_dac, mask, &hf)) {
|
||||||
|
if (hf.set_id != hd_loaded_id) { hd_loaded_id = hf.set_id; hd_loaded_ok = load_hd_set(&hf); }
|
||||||
|
hd_on = hd_loaded_ok;
|
||||||
|
}
|
||||||
|
if (hd_on) for (i = 0; i < 320 * 200; i++) px[i] = (pal[src[i]] & 0xffffffu) | (uint32_t)mask[i] << 24;
|
||||||
|
else for (i = 0; i < 320 * 200; i++) px[i] = pal[src[i]];
|
||||||
gfx_set_game(px, 320, 200);
|
gfx_set_game(px, 320, 200);
|
||||||
|
gfx_hd_frame(hd_on, hd_on ? hf.parts : 0, hd_on ? hf.offset : 0, hd_on ? hf.tint : NULL);
|
||||||
if (toast_t0) { /* bulle « F12 : réglages » : 4 s, puis fondu d'1 s */
|
if (toast_t0) { /* bulle « F12 : réglages » : 4 s, puis fondu d'1 s */
|
||||||
double t = (double)(SDL_GetPerformanceCounter() - toast_t0) / (double)freq;
|
double t = (double)(SDL_GetPerformanceCounter() - toast_t0) / (double)freq;
|
||||||
if (t >= 5.0) toast_t0 = 0;
|
if (t >= 5.0) toast_t0 = 0;
|
||||||
|
|||||||
+68
-25
@@ -27,30 +27,42 @@ void settings_defaults(void) {
|
|||||||
settings.filter = FILTER_NEAREST;
|
settings.filter = FILTER_NEAREST;
|
||||||
settings.aspect_43 = 1;
|
settings.aspect_43 = 1;
|
||||||
settings.vsync = 0;
|
settings.vsync = 0;
|
||||||
|
settings.hd_pack = 1;
|
||||||
|
settings.mods_enabled = 1;
|
||||||
|
settings.mods_dir[0] = 0;
|
||||||
|
settings.mods_disabled[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int clampi(int v, int lo, int hi) { return v < lo ? lo : v > hi ? hi : v; }
|
static int clampi(int v, int lo, int hi) { return v < lo ? lo : v > hi ? hi : v; }
|
||||||
|
|
||||||
/* une entrée par clé du fichier ; names : valeurs textuelles (sinon entier) */
|
/* une entrée par clé du fichier ; names : valeurs textuelles (sinon entier) ; str : clé texte libre */
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *section, *key;
|
const char *section, *key;
|
||||||
int *val;
|
int *val;
|
||||||
int lo, hi;
|
int lo, hi;
|
||||||
const char *const *names;
|
const char *const *names;
|
||||||
|
char *str;
|
||||||
|
size_t str_n;
|
||||||
} keys[] = {
|
} keys[] = {
|
||||||
{"display", "fullscreen", &settings.fullscreen, 0, 1, NULL},
|
{"display", "fullscreen", &settings.fullscreen, 0, 1, NULL},
|
||||||
{"display", "window_scale", &settings.window_scale, 1, 16, NULL},
|
{"display", "window_scale", &settings.window_scale, 1, 16, NULL},
|
||||||
{"display", "filter", &settings.filter, 0, FILTER_COUNT - 1, filter_names},
|
{"display", "filter", &settings.filter, 0, FILTER_COUNT - 1, filter_names},
|
||||||
{"display", "aspect_43", &settings.aspect_43, 0, 1, NULL},
|
{"display", "aspect_43", &settings.aspect_43, 0, 1, NULL},
|
||||||
{"display", "vsync", &settings.vsync, 0, 1, NULL},
|
{"display", "vsync", &settings.vsync, 0, 1, NULL},
|
||||||
|
{"display", "hd_pack", &settings.hd_pack, 0, 1, NULL},
|
||||||
{"audio", "master_volume", &settings.vol[VOL_GENERAL], 0, 100, NULL},
|
{"audio", "master_volume", &settings.vol[VOL_GENERAL], 0, 100, NULL},
|
||||||
{"audio", "music_volume", &settings.vol[VOL_MUSIQUE], 0, 100, NULL},
|
{"audio", "music_volume", &settings.vol[VOL_MUSIQUE], 0, 100, NULL},
|
||||||
{"audio", "voice_volume", &settings.vol[VOL_VOIX], 0, 100, NULL},
|
{"audio", "voice_volume", &settings.vol[VOL_VOIX], 0, 100, NULL},
|
||||||
{"audio", "sfx_volume", &settings.vol[VOL_BRUITAGES], 0, 100, NULL},
|
{"audio", "sfx_volume", &settings.vol[VOL_BRUITAGES], 0, 100, NULL},
|
||||||
|
{"mods", "enabled", &settings.mods_enabled, 0, 1, NULL},
|
||||||
|
{"mods", "dir", NULL, 0, 0, NULL, settings.mods_dir, sizeof settings.mods_dir},
|
||||||
|
{"mods", "disabled", NULL, 0, 0, NULL, settings.mods_disabled, sizeof settings.mods_disabled},
|
||||||
};
|
};
|
||||||
#define N_KEYS ((int)(sizeof keys / sizeof keys[0]))
|
#define N_KEYS ((int)(sizeof keys / sizeof keys[0]))
|
||||||
|
|
||||||
static int file_val[N_KEYS], override_val[N_KEYS], overridden[N_KEYS];
|
static int file_val[N_KEYS], override_val[N_KEYS], overridden[N_KEYS];
|
||||||
|
static char file_str[N_KEYS][512], override_str[N_KEYS][512];
|
||||||
|
int menu_hd_available;
|
||||||
|
|
||||||
static char *trim(char *s) {
|
static char *trim(char *s) {
|
||||||
char *e;
|
char *e;
|
||||||
@@ -60,16 +72,25 @@ static char *trim(char *s) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int find_key(const char *k) {
|
/* clé « nom » (section quelconque) ou « section.nom » ; section != NULL : dans cette section seulement */
|
||||||
|
static int find_key_in(const char *section, const char *k) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < N_KEYS; i++) if (!strcmp(k, keys[i].key)) return i;
|
const char *dot = section ? NULL : strchr(k, '.');
|
||||||
|
for (i = 0; i < N_KEYS; i++) {
|
||||||
|
if (dot) {
|
||||||
|
if (strlen(keys[i].section) == (size_t)(dot - k) && !strncmp(k, keys[i].section, (size_t)(dot - k)) &&
|
||||||
|
!strcmp(dot + 1, keys[i].key)) return i;
|
||||||
|
} else if (!strcmp(k, keys[i].key) && (!section || !strcmp(section, keys[i].section))) return i;
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
static int find_key(const char *k) { return find_key_in(NULL, k); }
|
||||||
|
|
||||||
/* valeur textuelle → entier borné ; -1 si invalide */
|
/* valeur textuelle → entier borné ; -1 si invalide */
|
||||||
static int parse_value(int i, const char *v, int *out) {
|
static int parse_value(int i, const char *v, int *out) {
|
||||||
char *end;
|
char *end;
|
||||||
long n;
|
long n;
|
||||||
|
if (keys[i].str) return 0;
|
||||||
if (keys[i].names) {
|
if (keys[i].names) {
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j <= keys[i].hi; j++) if (!strcmp(v, keys[i].names[j])) { *out = j; return 1; }
|
for (j = 0; j <= keys[i].hi; j++) if (!strcmp(v, keys[i].names[j])) { *out = j; return 1; }
|
||||||
@@ -103,19 +124,27 @@ const char *settings_default_path(void) {
|
|||||||
return "settings.ini";
|
return "settings.ini";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_str(int i, const char *v) { snprintf(keys[i].str, keys[i].str_n, "%s", v); }
|
||||||
|
|
||||||
int settings_load(const char *path) {
|
int settings_load(const char *path) {
|
||||||
char line[512];
|
char line[700], section[64] = "";
|
||||||
int i;
|
int i;
|
||||||
FILE *f = fopen(path, "r");
|
FILE *f = fopen(path, "r");
|
||||||
for (i = 0; i < N_KEYS; i++) file_val[i] = *keys[i].val;
|
for (i = 0; i < N_KEYS; i++) {
|
||||||
|
if (keys[i].str) snprintf(file_str[i], sizeof file_str[i], "%s", keys[i].str);
|
||||||
|
else file_val[i] = *keys[i].val;
|
||||||
|
}
|
||||||
if (!f) return 0;
|
if (!f) return 0;
|
||||||
while (fgets(line, sizeof line, f)) {
|
while (fgets(line, sizeof line, f)) {
|
||||||
char *eq = strchr(line, '='), *k = trim(line);
|
char *k = trim(line), *eq;
|
||||||
int v;
|
int v;
|
||||||
if (!eq || *k == '#' || *k == ';' || *k == '[') continue;
|
if (*k == '[') { char *e = strchr(k, ']'); if (e) *e = 0; snprintf(section, sizeof section, "%s", k + 1); continue; }
|
||||||
|
if (!(eq = strchr(k, '=')) || *k == '#' || *k == ';') continue;
|
||||||
*eq = 0;
|
*eq = 0;
|
||||||
i = find_key(trim(k));
|
i = find_key_in(section, trim(k));
|
||||||
if (i >= 0 && parse_value(i, trim(eq + 1), &v)) *keys[i].val = file_val[i] = v;
|
if (i < 0) continue;
|
||||||
|
if (keys[i].str) { set_str(i, trim(eq + 1)); snprintf(file_str[i], sizeof file_str[i], "%s", keys[i].str); }
|
||||||
|
else if (parse_value(i, trim(eq + 1), &v)) *keys[i].val = file_val[i] = v;
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -123,8 +152,14 @@ int settings_load(const char *path) {
|
|||||||
|
|
||||||
int settings_override(const char *key, const char *value) {
|
int settings_override(const char *key, const char *value) {
|
||||||
int i = find_key(key), v;
|
int i = find_key(key), v;
|
||||||
if (i < 0 || !parse_value(i, value, &v)) return 0;
|
if (i < 0) return 0;
|
||||||
*keys[i].val = override_val[i] = v;
|
if (keys[i].str) {
|
||||||
|
set_str(i, value);
|
||||||
|
snprintf(override_str[i], sizeof override_str[i], "%s", keys[i].str);
|
||||||
|
} else {
|
||||||
|
if (!parse_value(i, value, &v)) return 0;
|
||||||
|
*keys[i].val = override_val[i] = v;
|
||||||
|
}
|
||||||
overridden[i] = 1;
|
overridden[i] = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -144,7 +179,7 @@ static void make_parent_dir(const char *path) {
|
|||||||
* seules les valeurs des clés connues changent ; les clés absentes sont ajoutées à leur section. */
|
* seules les valeurs des clés connues changent ; les clés absentes sont ajoutées à leur section. */
|
||||||
#define MAX_LINES 400
|
#define MAX_LINES 400
|
||||||
int settings_save(const char *path) {
|
int settings_save(const char *path) {
|
||||||
static char lines[MAX_LINES][512];
|
static char lines[MAX_LINES][600];
|
||||||
int n = 0, i, j, written[N_KEYS] = {0};
|
int n = 0, i, j, written[N_KEYS] = {0};
|
||||||
char cur_section[64] = "";
|
char cur_section[64] = "";
|
||||||
FILE *f = fopen(path, "r");
|
FILE *f = fopen(path, "r");
|
||||||
@@ -161,17 +196,19 @@ int settings_save(const char *path) {
|
|||||||
}
|
}
|
||||||
/* valeur à écrire : celle du joueur, sauf réglage imposé en ligne de commande et inchangé depuis */
|
/* valeur à écrire : celle du joueur, sauf réglage imposé en ligne de commande et inchangé depuis */
|
||||||
#define OUT_VAL(i) (overridden[i] && *keys[i].val == override_val[i] ? file_val[i] : *keys[i].val)
|
#define OUT_VAL(i) (overridden[i] && *keys[i].val == override_val[i] ? file_val[i] : *keys[i].val)
|
||||||
|
#define OUT_STR(i) (overridden[i] && !strcmp(keys[i].str, override_str[i]) ? file_str[i] : keys[i].str)
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
char tmp[512], *k, *eq;
|
char tmp[600], *k, *eq;
|
||||||
snprintf(tmp, sizeof tmp, "%s", lines[i]);
|
snprintf(tmp, sizeof tmp, "%s", lines[i]);
|
||||||
k = trim(tmp);
|
k = trim(tmp);
|
||||||
if (*k == '[') { char *e = strchr(k, ']'); if (e) *e = 0; snprintf(cur_section, sizeof cur_section, "%s", k + 1); continue; }
|
if (*k == '[') { char *e = strchr(k, ']'); if (e) *e = 0; snprintf(cur_section, sizeof cur_section, "%s", k + 1); continue; }
|
||||||
if (*k == '#' || *k == ';' || !(eq = strchr(k, '='))) continue;
|
if (*k == '#' || *k == ';' || !(eq = strchr(k, '='))) continue;
|
||||||
*eq = 0;
|
*eq = 0;
|
||||||
j = find_key(trim(k));
|
j = find_key_in(cur_section, trim(k));
|
||||||
if (j >= 0) {
|
if (j >= 0 && !written[j]) {
|
||||||
char v[64];
|
char v[512];
|
||||||
format_value(j, OUT_VAL(j), v, sizeof v);
|
if (keys[j].str) snprintf(v, sizeof v, "%s", OUT_STR(j));
|
||||||
|
else format_value(j, OUT_VAL(j), v, sizeof v);
|
||||||
snprintf(lines[i], sizeof lines[0], "%s=%s", keys[j].key, v);
|
snprintf(lines[i], sizeof lines[0], "%s=%s", keys[j].key, v);
|
||||||
written[j] = 1;
|
written[j] = 1;
|
||||||
}
|
}
|
||||||
@@ -179,10 +216,10 @@ int settings_save(const char *path) {
|
|||||||
/* clés manquantes : à la fin de leur section, ou dans une nouvelle section en fin de fichier */
|
/* clés manquantes : à la fin de leur section, ou dans une nouvelle section en fin de fichier */
|
||||||
for (j = 0; j < N_KEYS; j++) {
|
for (j = 0; j < N_KEYS; j++) {
|
||||||
int at = -1, in = 0;
|
int at = -1, in = 0;
|
||||||
char v[64];
|
char v[512];
|
||||||
if (written[j]) continue;
|
if (written[j]) continue;
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
char tmp[512], *k;
|
char tmp[600], *k;
|
||||||
snprintf(tmp, sizeof tmp, "%s", lines[i]);
|
snprintf(tmp, sizeof tmp, "%s", lines[i]);
|
||||||
k = trim(tmp);
|
k = trim(tmp);
|
||||||
if (*k == '[') {
|
if (*k == '[') {
|
||||||
@@ -200,12 +237,14 @@ int settings_save(const char *path) {
|
|||||||
}
|
}
|
||||||
if (n + 1 > MAX_LINES) break;
|
if (n + 1 > MAX_LINES) break;
|
||||||
memmove(lines[at + 1], lines[at], (size_t)(n - at) * sizeof lines[0]);
|
memmove(lines[at + 1], lines[at], (size_t)(n - at) * sizeof lines[0]);
|
||||||
format_value(j, OUT_VAL(j), v, sizeof v);
|
if (keys[j].str) snprintf(v, sizeof v, "%s", OUT_STR(j));
|
||||||
|
else format_value(j, OUT_VAL(j), v, sizeof v);
|
||||||
snprintf(lines[at], sizeof lines[0], "%s=%s", keys[j].key, v);
|
snprintf(lines[at], sizeof lines[0], "%s=%s", keys[j].key, v);
|
||||||
n++;
|
n++;
|
||||||
written[j] = 1;
|
written[j] = 1;
|
||||||
}
|
}
|
||||||
#undef OUT_VAL
|
#undef OUT_VAL
|
||||||
|
#undef OUT_STR
|
||||||
f = fopen(path, "w");
|
f = fopen(path, "w");
|
||||||
if (!f) { make_parent_dir(path); f = fopen(path, "w"); }
|
if (!f) { make_parent_dir(path); f = fopen(path, "w"); }
|
||||||
if (!f) return 0;
|
if (!f) return 0;
|
||||||
@@ -368,11 +407,13 @@ static Item items[] = {
|
|||||||
{"Filtre d'image", IT_CHOICE, &settings.filter, 0, FILTER_COUNT - 1, 1, filter_labels},
|
{"Filtre d'image", IT_CHOICE, &settings.filter, 0, FILTER_COUNT - 1, 1, filter_labels},
|
||||||
{"Format d'origine 4:3", IT_SWITCH, &settings.aspect_43, 0, 1, 1, NULL},
|
{"Format d'origine 4:3", IT_SWITCH, &settings.aspect_43, 0, 1, 1, NULL},
|
||||||
{"Synchro verticale", IT_SWITCH, &settings.vsync, 0, 1, 1, NULL},
|
{"Synchro verticale", IT_SWITCH, &settings.vsync, 0, 1, 1, NULL},
|
||||||
|
{"Décors HD (mods)", IT_SWITCH, &settings.hd_pack, 0, 1, 1, NULL},
|
||||||
{NULL, IT_BUTTONS, NULL, 0, 1, 1, NULL},
|
{NULL, IT_BUTTONS, NULL, 0, 1, 1, NULL},
|
||||||
};
|
};
|
||||||
#define N_ITEMS ((int)(sizeof items / sizeof items[0]))
|
#define N_ITEMS ((int)(sizeof items / sizeof items[0]))
|
||||||
#define FIRST_DISPLAY 4
|
#define FIRST_DISPLAY 4
|
||||||
#define ITEM_SCALE 5
|
#define ITEM_SCALE 5
|
||||||
|
#define ITEM_HD 9
|
||||||
|
|
||||||
static int sel, button, dragging = -1, max_scale = 4, last_mx = -1, last_my = -1;
|
static int sel, button, dragging = -1, max_scale = 4, last_mx = -1, last_my = -1;
|
||||||
|
|
||||||
@@ -380,7 +421,7 @@ static int sel, button, dragging = -1, max_scale = 4, last_mx = -1, last_my = -1
|
|||||||
#define PANEL_X0 150
|
#define PANEL_X0 150
|
||||||
#define PANEL_X1 810
|
#define PANEL_X1 810
|
||||||
#define PANEL_Y0 40
|
#define PANEL_Y0 40
|
||||||
#define PANEL_Y1 680
|
#define PANEL_Y1 700
|
||||||
#define ROW_H 40
|
#define ROW_H 40
|
||||||
#define CTRL_X0 (PANEL_X0 + 330)
|
#define CTRL_X0 (PANEL_X0 + 330)
|
||||||
#define CTRL_X1 (PANEL_X1 - 44)
|
#define CTRL_X1 (PANEL_X1 - 44)
|
||||||
@@ -392,7 +433,7 @@ static int sel, button, dragging = -1, max_scale = 4, last_mx = -1, last_my = -1
|
|||||||
static int row_y(int i) {
|
static int row_y(int i) {
|
||||||
if (i < FIRST_DISPLAY) return 154 + i * ROW_H;
|
if (i < FIRST_DISPLAY) return 154 + i * ROW_H;
|
||||||
if (i < N_ITEMS - 1) return 352 + (i - FIRST_DISPLAY) * ROW_H;
|
if (i < N_ITEMS - 1) return 352 + (i - FIRST_DISPLAY) * ROW_H;
|
||||||
return 570;
|
return 610;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int button_x(int b) {
|
static int button_x(int b) {
|
||||||
@@ -574,9 +615,11 @@ void menu_draw(uint32_t *px) {
|
|||||||
round_rect(PANEL_X0 + 20, y + 10, PANEL_X0 + 24, y + ROW_H - 10, 2, C_ACCENT, 255);
|
round_rect(PANEL_X0 + 20, y + 10, PANEL_X0 + 24, y + ROW_H - 10, 2, C_ACCENT, 255);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int dim = i == ITEM_SCALE && settings.fullscreen;
|
int dim = (i == ITEM_SCALE && settings.fullscreen) || (i == ITEM_HD && !menu_hd_available);
|
||||||
text(&font_normal, PANEL_X0 + 44, y + (ROW_H - font_normal.height) / 2, it->label,
|
int lw = text(&font_normal, PANEL_X0 + 44, y + (ROW_H - font_normal.height) / 2, it->label,
|
||||||
dim ? C_MUTED : C_TEXT, 255);
|
dim ? C_MUTED : C_TEXT, 255);
|
||||||
|
if (i == ITEM_HD && !menu_hd_available)
|
||||||
|
text(&font_small, PANEL_X0 + 44 + lw + 14, y + (ROW_H - font_small.height) / 2, "aucun pack installé", C_MUTED, 255);
|
||||||
switch (it->type) {
|
switch (it->type) {
|
||||||
case IT_SLIDER: draw_slider(y, it, active); break;
|
case IT_SLIDER: draw_slider(y, it, active); break;
|
||||||
case IT_SWITCH: draw_switch(y, *it->val, active); break;
|
case IT_SWITCH: draw_switch(y, *it->val, active); break;
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ typedef struct {
|
|||||||
int filter; /* FILTER_* */
|
int filter; /* FILTER_* */
|
||||||
int aspect_43; /* 1 = 320×200 étiré en 4:3 comme sur un écran VGA, 0 = pixels carrés */
|
int aspect_43; /* 1 = 320×200 étiré en 4:3 comme sur un écran VGA, 0 = pixels carrés */
|
||||||
int vsync; /* 0/1 */
|
int vsync; /* 0/1 */
|
||||||
|
int hd_pack; /* 0/1 : décors HD des mods (pack HD) */
|
||||||
|
int mods_enabled; /* 0/1 : 0 = aucun mod (ni fichiers remplacés, ni pack HD) */
|
||||||
|
char mods_dir[260]; /* dossier des mods ; vide = « mods » à côté de l'exécutable */
|
||||||
|
char mods_disabled[512];/* noms de mods désactivés, séparés par des virgules */
|
||||||
} Settings;
|
} Settings;
|
||||||
|
|
||||||
extern Settings settings;
|
extern Settings settings;
|
||||||
@@ -31,6 +35,7 @@ int settings_save(const char *path); /* réécrit les valeurs en gardan
|
|||||||
* sauf si le joueur le change ensuite dans le menu. 0 si clé ou valeur inconnue. */
|
* sauf si le joueur le change ensuite dans le menu. 0 si clé ou valeur inconnue. */
|
||||||
int settings_override(const char *key, const char *value);
|
int settings_override(const char *key, const char *value);
|
||||||
void settings_apply_audio(void); /* settings.vol → audio_volume / audio_master */
|
void settings_apply_audio(void); /* settings.vol → audio_volume / audio_master */
|
||||||
|
extern int menu_hd_available; /* nombre d'images HD fournies par les mods (0 : option grisée) */
|
||||||
|
|
||||||
typedef enum { MK_UP, MK_DOWN, MK_LEFT, MK_RIGHT, MK_OK, MK_BACK, MK_HOME, MK_END } MenuKey;
|
typedef enum { MK_UP, MK_DOWN, MK_LEFT, MK_RIGHT, MK_OK, MK_BACK, MK_HOME, MK_END } MenuKey;
|
||||||
|
|
||||||
|
|||||||
+245
@@ -0,0 +1,245 @@
|
|||||||
|
/* Index des fichiers fournis par les mods (voir mods.h). Construit une fois au démarrage :
|
||||||
|
* clé = chemin relatif en majuscules avec '\\', triée pour une recherche dichotomique. */
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "mods.h"
|
||||||
|
#include "rt.h"
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#else
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct { char *key, *path; int mod; } Entry;
|
||||||
|
typedef struct { Entry *e; int n, cap; } Index;
|
||||||
|
|
||||||
|
static Index idx_files, idx_hd;
|
||||||
|
static char **mod_names;
|
||||||
|
static int n_mods;
|
||||||
|
|
||||||
|
static char *dupstr(const char *s) {
|
||||||
|
size_t n = strlen(s) + 1;
|
||||||
|
char *d = (char *)malloc(n);
|
||||||
|
if (d) memcpy(d, s, n);
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void make_key(const char *rel, char *key, size_t n) {
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; rel[i] && i + 1 < n; i++) key[i] = (char)(rel[i] == '/' ? '\\' : toupper((unsigned char)rel[i]));
|
||||||
|
key[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add(Index *ix, const char *key, const char *path, int mod) {
|
||||||
|
if (ix->n == ix->cap) {
|
||||||
|
int cap = ix->cap ? ix->cap * 2 : 256;
|
||||||
|
Entry *e = (Entry *)realloc(ix->e, (size_t)cap * sizeof *e);
|
||||||
|
if (!e) return;
|
||||||
|
ix->e = e; ix->cap = cap;
|
||||||
|
}
|
||||||
|
ix->e[ix->n].key = dupstr(key);
|
||||||
|
ix->e[ix->n].path = dupstr(path);
|
||||||
|
ix->e[ix->n].mod = mod;
|
||||||
|
ix->n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ parcours de dossiers */
|
||||||
|
typedef void (*VisitFn)(const char *name, int is_dir, void *ctx);
|
||||||
|
|
||||||
|
static void list_dir(const char *dir, VisitFn fn, void *ctx) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
char spec[600];
|
||||||
|
struct _finddata_t fd;
|
||||||
|
intptr_t h;
|
||||||
|
snprintf(spec, sizeof spec, "%s\\*", dir);
|
||||||
|
h = _findfirst(spec, &fd);
|
||||||
|
if (h == -1) return;
|
||||||
|
do {
|
||||||
|
if (!strcmp(fd.name, ".") || !strcmp(fd.name, "..")) continue;
|
||||||
|
fn(fd.name, (fd.attrib & _A_SUBDIR) != 0, ctx);
|
||||||
|
} while (_findnext(h, &fd) == 0);
|
||||||
|
_findclose(h);
|
||||||
|
#else
|
||||||
|
DIR *d = opendir(dir);
|
||||||
|
struct dirent *e;
|
||||||
|
if (!d) return;
|
||||||
|
while ((e = readdir(d))) {
|
||||||
|
char p[1024];
|
||||||
|
struct stat st;
|
||||||
|
if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..")) continue;
|
||||||
|
snprintf(p, sizeof p, "%s/%s", dir, e->d_name);
|
||||||
|
if (stat(p, &st) == 0) fn(e->d_name, S_ISDIR(st.st_mode), ctx);
|
||||||
|
}
|
||||||
|
closedir(d);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct { Index *ix; int mod; char host[600]; char rel[300]; int depth; } Walk;
|
||||||
|
|
||||||
|
static void walk_visit(const char *name, int is_dir, void *ctx) {
|
||||||
|
Walk *w = (Walk *)ctx, sub = *w;
|
||||||
|
char key[300];
|
||||||
|
snprintf(sub.host, sizeof sub.host, "%s/%s", w->host, name);
|
||||||
|
if (w->rel[0]) snprintf(sub.rel, sizeof sub.rel, "%s\\%s", w->rel, name);
|
||||||
|
else snprintf(sub.rel, sizeof sub.rel, "%s", name);
|
||||||
|
if (is_dir) {
|
||||||
|
if (w->depth < 8) { sub.depth = w->depth + 1; list_dir(sub.host, walk_visit, &sub); }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
make_key(sub.rel, key, sizeof key);
|
||||||
|
add(w->ix, key, sub.host, w->mod);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void walk(Index *ix, int mod, const char *root) {
|
||||||
|
Walk w;
|
||||||
|
memset(&w, 0, sizeof w);
|
||||||
|
w.ix = ix; w.mod = mod;
|
||||||
|
snprintf(w.host, sizeof w.host, "%s", root);
|
||||||
|
list_dir(root, walk_visit, &w);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct { char **names; int n, cap; } NameList;
|
||||||
|
|
||||||
|
static void collect_mod(const char *name, int is_dir, void *ctx) {
|
||||||
|
NameList *l = (NameList *)ctx;
|
||||||
|
if (!is_dir || name[0] == '.' || name[0] == '_') return; /* _xxx : désactivé par convention */
|
||||||
|
if (l->n == l->cap) {
|
||||||
|
int cap = l->cap ? l->cap * 2 : 16;
|
||||||
|
char **p = (char **)realloc(l->names, (size_t)cap * sizeof *p);
|
||||||
|
if (!p) return;
|
||||||
|
l->names = p; l->cap = cap;
|
||||||
|
}
|
||||||
|
l->names[l->n++] = dupstr(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmp_name(const void *a, const void *b) {
|
||||||
|
const char *x = *(const char *const *)a, *y = *(const char *const *)b;
|
||||||
|
for (; *x && tolower((unsigned char)*x) == tolower((unsigned char)*y); x++, y++) {}
|
||||||
|
return tolower((unsigned char)*x) - tolower((unsigned char)*y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clé croissante, puis mod décroissant : le premier d'une série de doublons est le plus prioritaire */
|
||||||
|
static int cmp_entry(const void *a, const void *b) {
|
||||||
|
const Entry *x = (const Entry *)a, *y = (const Entry *)b;
|
||||||
|
int c = strcmp(x->key, y->key);
|
||||||
|
return c ? c : y->mod - x->mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void finish(Index *ix) {
|
||||||
|
int i, j = 0;
|
||||||
|
if (!ix->n) return;
|
||||||
|
qsort(ix->e, (size_t)ix->n, sizeof *ix->e, cmp_entry);
|
||||||
|
for (i = 0; i < ix->n; i++) {
|
||||||
|
if (j && !strcmp(ix->e[j - 1].key, ix->e[i].key)) { free(ix->e[i].key); free(ix->e[i].path); continue; }
|
||||||
|
ix->e[j++] = ix->e[i];
|
||||||
|
}
|
||||||
|
ix->n = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int listed(const char *csv, const char *name) {
|
||||||
|
const char *p = csv;
|
||||||
|
size_t n = strlen(name);
|
||||||
|
if (!csv) return 0;
|
||||||
|
while (*p) {
|
||||||
|
const char *e = strchr(p, ',');
|
||||||
|
size_t len;
|
||||||
|
while (*p == ' ') p++;
|
||||||
|
len = e ? (size_t)(e - p) : strlen(p);
|
||||||
|
while (len && p[len - 1] == ' ') len--;
|
||||||
|
if (len == n) {
|
||||||
|
size_t k;
|
||||||
|
for (k = 0; k < n && tolower((unsigned char)p[k]) == tolower((unsigned char)name[k]); k++) {}
|
||||||
|
if (k == n) return 1;
|
||||||
|
}
|
||||||
|
if (!e) break;
|
||||||
|
p = e + 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mods_init(const char *dir, const char *disabled) {
|
||||||
|
NameList l = {0};
|
||||||
|
int i;
|
||||||
|
mods_shutdown();
|
||||||
|
if (!dir || !*dir) return 0;
|
||||||
|
list_dir(dir, collect_mod, &l);
|
||||||
|
if (l.n) qsort(l.names, (size_t)l.n, sizeof *l.names, cmp_name);
|
||||||
|
mod_names = (char **)calloc((size_t)(l.n ? l.n : 1), sizeof *mod_names);
|
||||||
|
for (i = 0; i < l.n; i++) {
|
||||||
|
char p[600];
|
||||||
|
if (listed(disabled, l.names[i])) {
|
||||||
|
fprintf(stderr, "[mods] %s : désactivé\n", l.names[i]);
|
||||||
|
free(l.names[i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
snprintf(p, sizeof p, "%s/%s/files", dir, l.names[i]);
|
||||||
|
walk(&idx_files, n_mods, p);
|
||||||
|
snprintf(p, sizeof p, "%s/%s/hd", dir, l.names[i]);
|
||||||
|
walk(&idx_hd, n_mods, p);
|
||||||
|
mod_names[n_mods++] = l.names[i];
|
||||||
|
}
|
||||||
|
free(l.names);
|
||||||
|
finish(&idx_files);
|
||||||
|
finish(&idx_hd);
|
||||||
|
for (i = 0; i < n_mods; i++) fprintf(stderr, "[mods] %s : actif\n", mod_names[i]);
|
||||||
|
if (n_mods) fprintf(stderr, "[mods] %d fichier(s) remplacé(s), %d image(s) HD\n", idx_files.n, idx_hd.n);
|
||||||
|
return n_mods;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void free_index(Index *ix) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < ix->n; i++) { free(ix->e[i].key); free(ix->e[i].path); }
|
||||||
|
free(ix->e);
|
||||||
|
memset(ix, 0, sizeof *ix);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mods_shutdown(void) {
|
||||||
|
int i;
|
||||||
|
free_index(&idx_files);
|
||||||
|
free_index(&idx_hd);
|
||||||
|
for (i = 0; i < n_mods; i++) free(mod_names[i]);
|
||||||
|
free(mod_names);
|
||||||
|
mod_names = NULL;
|
||||||
|
n_mods = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const Entry *lookup(const Index *ix, const char *key) {
|
||||||
|
int lo = 0, hi = ix->n - 1;
|
||||||
|
while (lo <= hi) {
|
||||||
|
int mid = (lo + hi) / 2, c = strcmp(key, ix->e[mid].key);
|
||||||
|
if (!c) return &ix->e[mid];
|
||||||
|
if (c < 0) hi = mid - 1; else lo = mid + 1;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mods_find_file(const char *rel, char *out, size_t n) {
|
||||||
|
char key[300];
|
||||||
|
const Entry *e;
|
||||||
|
if (!idx_files.n) return 0;
|
||||||
|
make_key(rel, key, sizeof key);
|
||||||
|
e = lookup(&idx_files, key);
|
||||||
|
if (!e) return 0;
|
||||||
|
snprintf(out, n, "%s", e->path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mods_hd_count(void) { return idx_hd.n; }
|
||||||
|
|
||||||
|
int mods_find_hd(const char *name, char *out, size_t n) {
|
||||||
|
char key[300];
|
||||||
|
const Entry *e;
|
||||||
|
if (!idx_hd.n) return 0;
|
||||||
|
snprintf(key, sizeof key, "%s.PNG", name);
|
||||||
|
make_key(key, key, sizeof key);
|
||||||
|
e = lookup(&idx_hd, key);
|
||||||
|
if (!e) return 0;
|
||||||
|
snprintf(out, n, "%s", e->path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mods_count(void) { return n_mods; }
|
||||||
|
const char *mods_name(int i) { return i >= 0 && i < n_mods ? mod_names[i] : ""; }
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/* Mods : dossiers mods/<nom>/ dont les fichiers remplacent ceux du jeu, sans toucher aux originaux.
|
||||||
|
* mods/<nom>/files/... même nom et même chemin relatif que dans le jeu (LOC01.PCX, SPEECH/SAM0001.WAV)
|
||||||
|
* mods/<nom>/hd/... images HD : <NOM_DU_PCX>.png (LOC01.png, LOC03A.png)
|
||||||
|
* mods/<nom>/mod.ini facultatif (nom affiché, auteur, description) : lu par le launcher
|
||||||
|
* Les mods sont pris dans l'ordre alphabétique de leur dossier ; pour un même fichier, le dernier l'emporte.
|
||||||
|
* Détails : docs/MODS.md. */
|
||||||
|
#pragma once
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/* parcourt dir ; disabled = noms de dossiers séparés par des virgules (peut être NULL) ; renvoie le nombre de mods actifs */
|
||||||
|
int mods_init(const char *dir, const char *disabled);
|
||||||
|
void mods_shutdown(void);
|
||||||
|
/* rel : chemin relatif dans le jeu, séparateur '\\' ou '/', casse indifférente. 1 + chemin hôte si un mod le remplace */
|
||||||
|
int mods_find_file(const char *rel, char *out, size_t n);
|
||||||
|
/* name : nom de fichier du jeu sans dossier ni extension (LOC01). 1 + chemin du PNG HD le plus prioritaire */
|
||||||
|
int mods_find_hd(const char *name, char *out, size_t n);
|
||||||
|
int mods_count(void);
|
||||||
|
int mods_hd_count(void); /* nombre d'images HD indexées */
|
||||||
|
const char *mods_name(int i);
|
||||||
+273
@@ -0,0 +1,273 @@
|
|||||||
|
/* Décodeur PNG (voir png.h). Inflate (RFC 1951) à décodage canonique de Huffman par comptage des longueurs. */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "png.h"
|
||||||
|
|
||||||
|
/* ================================================================== inflate */
|
||||||
|
typedef struct {
|
||||||
|
const uint8_t *in;
|
||||||
|
size_t in_len, in_pos;
|
||||||
|
uint32_t bits;
|
||||||
|
int nbits;
|
||||||
|
uint8_t *out;
|
||||||
|
size_t out_len, out_pos;
|
||||||
|
int error;
|
||||||
|
} Inflate;
|
||||||
|
|
||||||
|
static int getbits(Inflate *s, int n) {
|
||||||
|
uint32_t v;
|
||||||
|
while (s->nbits < n) {
|
||||||
|
if (s->in_pos >= s->in_len) { s->error = 1; return 0; }
|
||||||
|
s->bits |= (uint32_t)s->in[s->in_pos++] << s->nbits;
|
||||||
|
s->nbits += 8;
|
||||||
|
}
|
||||||
|
v = s->bits & ((1u << n) - 1);
|
||||||
|
s->bits >>= n;
|
||||||
|
s->nbits -= n;
|
||||||
|
return (int)v;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct { short count[16], symbol[320]; } Huff;
|
||||||
|
|
||||||
|
static int huff_build(Huff *h, const uint8_t *len, int n) {
|
||||||
|
short offs[16];
|
||||||
|
int i, left = 1;
|
||||||
|
memset(h->count, 0, sizeof h->count);
|
||||||
|
for (i = 0; i < n; i++) h->count[len[i]]++;
|
||||||
|
if (h->count[0] == n) return 0;
|
||||||
|
for (i = 1; i < 16; i++) { left <<= 1; left -= h->count[i]; if (left < 0) return -1; }
|
||||||
|
offs[1] = 0;
|
||||||
|
for (i = 1; i < 15; i++) offs[i + 1] = (short)(offs[i] + h->count[i]);
|
||||||
|
for (i = 0; i < n; i++) if (len[i]) h->symbol[offs[len[i]]++] = (short)i;
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int huff_decode(Inflate *s, const Huff *h) {
|
||||||
|
int code = 0, first = 0, index = 0, l;
|
||||||
|
for (l = 1; l < 16; l++) {
|
||||||
|
code |= getbits(s, 1);
|
||||||
|
if (s->error) return -1;
|
||||||
|
if (code - h->count[l] < first) return h->symbol[index + (code - first)];
|
||||||
|
index += h->count[l];
|
||||||
|
first += h->count[l];
|
||||||
|
first <<= 1;
|
||||||
|
code <<= 1;
|
||||||
|
}
|
||||||
|
s->error = 1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const short LBASE[29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};
|
||||||
|
static const short LEXT[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
|
||||||
|
static const short DBASE[30] = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577};
|
||||||
|
static const short DEXT[30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
|
||||||
|
|
||||||
|
static int codes(Inflate *s, const Huff *lit, const Huff *dist) {
|
||||||
|
for (;;) {
|
||||||
|
int sym = huff_decode(s, lit);
|
||||||
|
if (s->error || sym < 0) return -1;
|
||||||
|
if (sym < 256) {
|
||||||
|
if (s->out_pos >= s->out_len) return -1;
|
||||||
|
s->out[s->out_pos++] = (uint8_t)sym;
|
||||||
|
} else if (sym == 256) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
int len, d;
|
||||||
|
size_t dd;
|
||||||
|
sym -= 257;
|
||||||
|
if (sym >= 29) return -1;
|
||||||
|
len = LBASE[sym] + getbits(s, LEXT[sym]);
|
||||||
|
d = huff_decode(s, dist);
|
||||||
|
if (s->error || d < 0 || d >= 30) return -1;
|
||||||
|
dd = (size_t)(DBASE[d] + getbits(s, DEXT[d]));
|
||||||
|
if (s->error || dd > s->out_pos || s->out_pos + (size_t)len > s->out_len) return -1;
|
||||||
|
while (len--) { s->out[s->out_pos] = s->out[s->out_pos - dd]; s->out_pos++; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int block_fixed(Inflate *s) {
|
||||||
|
static Huff lit, dist;
|
||||||
|
static int built;
|
||||||
|
if (!built) {
|
||||||
|
uint8_t l[320];
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 144; i++) l[i] = 8;
|
||||||
|
for (; i < 256; i++) l[i] = 9;
|
||||||
|
for (; i < 280; i++) l[i] = 7;
|
||||||
|
for (; i < 288; i++) l[i] = 8;
|
||||||
|
huff_build(&lit, l, 288);
|
||||||
|
for (i = 0; i < 30; i++) l[i] = 5;
|
||||||
|
huff_build(&dist, l, 30);
|
||||||
|
built = 1;
|
||||||
|
}
|
||||||
|
return codes(s, &lit, &dist);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int block_dynamic(Inflate *s) {
|
||||||
|
static const uint8_t order[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||||
|
uint8_t lengths[320];
|
||||||
|
Huff lencode, lit, dist;
|
||||||
|
int nlen = getbits(s, 5) + 257, ndist = getbits(s, 5) + 1, ncode = getbits(s, 4) + 4, i = 0;
|
||||||
|
if (s->error || nlen > 286 || ndist > 30) return -1;
|
||||||
|
memset(lengths, 0, sizeof lengths);
|
||||||
|
for (i = 0; i < ncode; i++) lengths[order[i]] = (uint8_t)getbits(s, 3);
|
||||||
|
if (huff_build(&lencode, lengths, 19) != 0) return -1;
|
||||||
|
i = 0;
|
||||||
|
while (i < nlen + ndist) {
|
||||||
|
int sym = huff_decode(s, &lencode), rep, v = 0;
|
||||||
|
if (sym < 0) return -1;
|
||||||
|
if (sym < 16) { lengths[i++] = (uint8_t)sym; continue; }
|
||||||
|
if (sym == 16) { if (!i) return -1; v = lengths[i - 1]; rep = 3 + getbits(s, 2); }
|
||||||
|
else if (sym == 17) rep = 3 + getbits(s, 3);
|
||||||
|
else rep = 11 + getbits(s, 7);
|
||||||
|
if (s->error || i + rep > nlen + ndist) return -1;
|
||||||
|
while (rep--) lengths[i++] = (uint8_t)v;
|
||||||
|
}
|
||||||
|
if (!lengths[256]) return -1;
|
||||||
|
if (huff_build(&lit, lengths, nlen) < 0) return -1;
|
||||||
|
if (huff_build(&dist, lengths + nlen, ndist) < 0) return -1;
|
||||||
|
return codes(s, &lit, &dist);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int inflate_buf(const uint8_t *in, size_t in_len, uint8_t *out, size_t out_len) {
|
||||||
|
Inflate s;
|
||||||
|
int last;
|
||||||
|
memset(&s, 0, sizeof s);
|
||||||
|
s.in = in; s.in_len = in_len; s.out = out; s.out_len = out_len;
|
||||||
|
do {
|
||||||
|
int type;
|
||||||
|
last = getbits(&s, 1);
|
||||||
|
type = getbits(&s, 2);
|
||||||
|
if (s.error) return -1;
|
||||||
|
if (type == 0) {
|
||||||
|
unsigned len;
|
||||||
|
s.bits = 0; s.nbits = 0; /* aligné sur l'octet */
|
||||||
|
if (s.in_pos + 4 > s.in_len) return -1;
|
||||||
|
len = s.in[s.in_pos] | s.in[s.in_pos + 1] << 8;
|
||||||
|
s.in_pos += 4;
|
||||||
|
if (s.in_pos + len > s.in_len || s.out_pos + len > s.out_len) return -1;
|
||||||
|
memcpy(s.out + s.out_pos, s.in + s.in_pos, len);
|
||||||
|
s.in_pos += len; s.out_pos += len;
|
||||||
|
} else if (type == 1) {
|
||||||
|
if (block_fixed(&s)) return -1;
|
||||||
|
} else if (type == 2) {
|
||||||
|
if (block_dynamic(&s)) return -1;
|
||||||
|
} else return -1;
|
||||||
|
} while (!last);
|
||||||
|
return s.out_pos == out_len ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================================== PNG */
|
||||||
|
static uint32_t be32(const uint8_t *p) { return (uint32_t)p[0] << 24 | (uint32_t)p[1] << 16 | (uint32_t)p[2] << 8 | p[3]; }
|
||||||
|
|
||||||
|
static int paeth(int a, int b, int c) {
|
||||||
|
int p = a + b - c, pa = abs(p - a), pb = abs(p - b), pc = abs(p - c);
|
||||||
|
return pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t *png_load(const char *path, int *pw, int *ph, const char **err) {
|
||||||
|
FILE *f = fopen(path, "rb");
|
||||||
|
uint8_t *file = NULL, *idat = NULL, *raw = NULL, pal[1024];
|
||||||
|
uint32_t *img = NULL, w = 0, h = 0;
|
||||||
|
size_t len, pos = 8, idat_len = 0;
|
||||||
|
int depth = 0, ctype = 0, interlace = 0, chans, bpp, npal = 0, has_trns = 0;
|
||||||
|
uint16_t trns_key[3] = {0};
|
||||||
|
const char *why = "fichier illisible";
|
||||||
|
memset(pal, 255, sizeof pal);
|
||||||
|
if (!f) goto done;
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
len = (size_t)ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
file = len > 8 && len < (256u << 20) ? (uint8_t *)malloc(len) : NULL;
|
||||||
|
if (!file || fread(file, 1, len, f) != len) goto done;
|
||||||
|
why = "pas un PNG";
|
||||||
|
if (memcmp(file, "\x89PNG\r\n\x1a\n", 8)) goto done;
|
||||||
|
idat = (uint8_t *)malloc(len);
|
||||||
|
if (!idat) goto done;
|
||||||
|
while (pos + 12 <= len) {
|
||||||
|
uint32_t clen = be32(file + pos);
|
||||||
|
const uint8_t *type = file + pos + 4, *d = file + pos + 8;
|
||||||
|
if (clen > len - pos - 12) { why = "bloc tronqué"; goto done; }
|
||||||
|
if (!memcmp(type, "IHDR", 4) && clen >= 13) {
|
||||||
|
w = be32(d); h = be32(d + 4); depth = d[8]; ctype = d[9]; interlace = d[12];
|
||||||
|
} else if (!memcmp(type, "PLTE", 4)) {
|
||||||
|
uint32_t i;
|
||||||
|
npal = (int)(clen / 3);
|
||||||
|
for (i = 0; i < clen / 3 && i < 256; i++) { pal[i * 4] = d[i * 3]; pal[i * 4 + 1] = d[i * 3 + 1]; pal[i * 4 + 2] = d[i * 3 + 2]; }
|
||||||
|
} else if (!memcmp(type, "tRNS", 4)) {
|
||||||
|
uint32_t i;
|
||||||
|
has_trns = 1;
|
||||||
|
if (ctype == 3) for (i = 0; i < clen && i < 256; i++) pal[i * 4 + 3] = d[i];
|
||||||
|
else if (ctype == 0 && clen >= 2) trns_key[0] = (uint16_t)(d[0] << 8 | d[1]);
|
||||||
|
else if (ctype == 2 && clen >= 6) for (i = 0; i < 3; i++) trns_key[i] = (uint16_t)(d[2 * i] << 8 | d[2 * i + 1]);
|
||||||
|
} else if (!memcmp(type, "IDAT", 4)) {
|
||||||
|
memcpy(idat + idat_len, d, clen);
|
||||||
|
idat_len += clen;
|
||||||
|
} else if (!memcmp(type, "IEND", 4)) break;
|
||||||
|
pos += 12 + clen;
|
||||||
|
}
|
||||||
|
why = "format PNG non pris en charge (8 ou 16 bits, non entrelacé)";
|
||||||
|
if (!w || !h || w > 16384 || h > 16384 || interlace || (depth != 8 && depth != 16)) goto done;
|
||||||
|
chans = ctype == 0 ? 1 : ctype == 2 ? 3 : ctype == 3 ? 1 : ctype == 4 ? 2 : ctype == 6 ? 4 : 0;
|
||||||
|
if (!chans || (ctype == 3 && (depth != 8 || !npal))) goto done;
|
||||||
|
bpp = chans * depth / 8;
|
||||||
|
raw = (uint8_t *)malloc((size_t)h * (1 + (size_t)w * bpp));
|
||||||
|
img = (uint32_t *)malloc((size_t)w * h * 4);
|
||||||
|
why = "mémoire insuffisante";
|
||||||
|
if (!raw || !img) goto fail;
|
||||||
|
why = "données compressées invalides";
|
||||||
|
if (idat_len < 2 || (idat[0] & 15) != 8 || inflate_buf(idat + 2, idat_len - 2, raw, (size_t)h * (1 + (size_t)w * bpp))) goto fail;
|
||||||
|
{
|
||||||
|
size_t stride = (size_t)w * bpp, y, x;
|
||||||
|
uint8_t *prev = NULL;
|
||||||
|
why = "filtre de ligne inconnu";
|
||||||
|
for (y = 0; y < h; y++) {
|
||||||
|
uint8_t *row = raw + y * (stride + 1), ft = row[0], *p = row + 1;
|
||||||
|
for (x = 0; x < stride; x++) {
|
||||||
|
int a = x >= (size_t)bpp ? p[x - bpp] : 0, b = prev ? prev[x] : 0, c = (prev && x >= (size_t)bpp) ? prev[x - bpp] : 0;
|
||||||
|
switch (ft) {
|
||||||
|
case 0: break;
|
||||||
|
case 1: p[x] = (uint8_t)(p[x] + a); break;
|
||||||
|
case 2: p[x] = (uint8_t)(p[x] + b); break;
|
||||||
|
case 3: p[x] = (uint8_t)(p[x] + ((a + b) >> 1)); break;
|
||||||
|
case 4: p[x] = (uint8_t)(p[x] + paeth(a, b, c)); break;
|
||||||
|
default: goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev = p;
|
||||||
|
for (x = 0; x < w; x++) {
|
||||||
|
const uint8_t *q = p + x * bpp;
|
||||||
|
int s = depth / 8; /* 16 bits : octet de poids fort */
|
||||||
|
uint32_t r, g, bl, al = 255;
|
||||||
|
if (ctype == 3) {
|
||||||
|
const uint8_t *e = pal + q[0] * 4;
|
||||||
|
r = e[0]; g = e[1]; bl = e[2]; al = e[3];
|
||||||
|
} else if (ctype == 0 || ctype == 4) {
|
||||||
|
r = g = bl = q[0];
|
||||||
|
if (ctype == 4) al = q[s];
|
||||||
|
else if (has_trns && (uint16_t)(s == 2 ? q[0] << 8 | q[1] : q[0]) == trns_key[0]) al = 0;
|
||||||
|
} else {
|
||||||
|
r = q[0]; g = q[s]; bl = q[2 * s];
|
||||||
|
if (ctype == 6) al = q[3 * s];
|
||||||
|
else if (has_trns && s == 1 && q[0] == trns_key[0] && q[1] == trns_key[1] && q[2] == trns_key[2]) al = 0;
|
||||||
|
}
|
||||||
|
img[y * w + x] = al << 24 | r << 16 | g << 8 | bl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
why = NULL;
|
||||||
|
goto done;
|
||||||
|
fail:
|
||||||
|
free(img);
|
||||||
|
img = NULL;
|
||||||
|
done:
|
||||||
|
if (f) fclose(f);
|
||||||
|
free(file);
|
||||||
|
free(idat);
|
||||||
|
free(raw);
|
||||||
|
if (err) *err = why;
|
||||||
|
if (img) { *pw = (int)w; *ph = (int)h; }
|
||||||
|
return img;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
/* Décodeur PNG minimal sans dépendance (inflate inclus) : 8 ou 16 bits par composante, niveaux de gris,
|
||||||
|
* RVB, palette, avec ou sans alpha, non entrelacé. Suffisant pour les images des packs HD. */
|
||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* renvoie un tableau w × h en 0xAARRGGBB (à libérer avec free), ou NULL ; err reçoit la raison */
|
||||||
|
uint32_t *png_load(const char *path, int *w, int *h, const char **err);
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
r"""Exporte les images PCX du jeu en PNG, point de départ d'un pack HD.
|
||||||
|
|
||||||
|
Les images viennent des fichiers du joueur et restent sur sa machine : rien n'est redistribué.
|
||||||
|
On les agrandit ensuite avec l'outil de son choix (dessin à la main, Real-ESRGAN, waifu2x, xBRZ…)
|
||||||
|
puis on les dépose dans mods/<nom_du_mod>/hd/ sous le même nom (LOC01.png). Voir docs/MODS.md.
|
||||||
|
|
||||||
|
python tools/hd_export.py DOSSIER_DU_JEU DOSSIER_SORTIE [--motif LOC*] [--echelle 1|2|4]
|
||||||
|
[--upscayl [MODELE]] [--upscayl-bin CHEMIN]
|
||||||
|
|
||||||
|
--motif noms de fichiers PCX à exporter (défaut : LOC*, les décors des pièces)
|
||||||
|
--echelle 1 = taille d'origine (à agrandir soi-même) ; 2 ou 4 = agrandissement Scale2x
|
||||||
|
intégré (contours en escalier adoucis, sans flou), pour tester un pack tout de suite
|
||||||
|
--upscayl agrandit ×4 avec Upscayl (Real-ESRGAN) s'il est installé ; modèle par défaut
|
||||||
|
digital-art-4x (autres : ultrasharp-4x, remacri-4x, high-fidelity-4x, upscayl-standard-4x…)
|
||||||
|
--upscayl-bin chemin de upscayl-bin.exe s'il n'est pas trouvé tout seul
|
||||||
|
|
||||||
|
Exemple (pack prêt à jouer) :
|
||||||
|
python tools/hd_export.py ..\extracted\iso\TUCKER mods\hd_upscayl\hd --upscayl
|
||||||
|
|
||||||
|
Seules les images plein écran 320×200 servent au pack HD : les autres sont ignorées.
|
||||||
|
"""
|
||||||
|
import argparse
|
||||||
|
import fnmatch
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import struct
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import zlib
|
||||||
|
|
||||||
|
|
||||||
|
def read_pcx(path):
|
||||||
|
"""PCX 8 bits 1 plan compressé RLE → (largeur, hauteur, indices, palette 768 octets)."""
|
||||||
|
d = open(path, "rb").read()
|
||||||
|
if len(d) < 128 + 769 or d[0] != 10 or d[3] != 8 or d[65] != 1:
|
||||||
|
raise ValueError("PCX 8 bits attendu : %s" % path)
|
||||||
|
x0, y0, x1, y1 = struct.unpack("<4H", d[4:12])
|
||||||
|
w, h = x1 - x0 + 1, y1 - y0 + 1
|
||||||
|
bpl = struct.unpack("<H", d[66:68])[0]
|
||||||
|
out, i, need = bytearray(), 128, bpl * h
|
||||||
|
while len(out) < need and i < len(d) - 769:
|
||||||
|
b = d[i]
|
||||||
|
i += 1
|
||||||
|
if b >= 0xC0:
|
||||||
|
out += bytes([d[i]]) * (b & 0x3F)
|
||||||
|
i += 1
|
||||||
|
else:
|
||||||
|
out.append(b)
|
||||||
|
out = out[:need].ljust(need, b"\0")
|
||||||
|
pix = b"".join(bytes(out[y * bpl:y * bpl + w]) for y in range(h))
|
||||||
|
if d[-769] != 12:
|
||||||
|
raise ValueError("palette absente : %s" % path)
|
||||||
|
return w, h, pix, d[-768:]
|
||||||
|
|
||||||
|
|
||||||
|
def scale2x(w, h, px):
|
||||||
|
"""Scale2x (EPX) sur une liste de couleurs : chaque pixel devient 2×2 selon ses voisins."""
|
||||||
|
out = [0] * (4 * w * h)
|
||||||
|
W = 2 * w
|
||||||
|
for y in range(h):
|
||||||
|
row, up, dn = y * w, max(y - 1, 0) * w, min(y + 1, h - 1) * w
|
||||||
|
for x in range(w):
|
||||||
|
p = px[row + x]
|
||||||
|
a = px[up + x]
|
||||||
|
b = px[row + min(x + 1, w - 1)]
|
||||||
|
c = px[row + max(x - 1, 0)]
|
||||||
|
d = px[dn + x]
|
||||||
|
e0 = e1 = e2 = e3 = p
|
||||||
|
if c == a and c != d and a != b: e0 = a
|
||||||
|
if a == b and a != c and b != d: e1 = b
|
||||||
|
if d == c and d != b and c != a: e2 = c
|
||||||
|
if b == d and b != a and d != c: e3 = d
|
||||||
|
o = 2 * y * W + 2 * x
|
||||||
|
out[o], out[o + 1], out[o + W], out[o + W + 1] = e0, e1, e2, e3
|
||||||
|
return 2 * w, 2 * h, out
|
||||||
|
|
||||||
|
|
||||||
|
def write_png(path, w, h, rgb):
|
||||||
|
raw = bytearray()
|
||||||
|
stride = 3 * w
|
||||||
|
for y in range(h):
|
||||||
|
raw.append(0)
|
||||||
|
raw += rgb[y * stride:(y + 1) * stride]
|
||||||
|
|
||||||
|
def chunk(tag, data):
|
||||||
|
c = tag + data
|
||||||
|
return struct.pack(">I", len(data)) + c + struct.pack(">I", zlib.crc32(c) & 0xFFFFFFFF)
|
||||||
|
|
||||||
|
png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0))
|
||||||
|
png += chunk(b"IDAT", zlib.compress(bytes(raw), 9)) + chunk(b"IEND", b"")
|
||||||
|
with open(path, "wb") as f:
|
||||||
|
f.write(png)
|
||||||
|
|
||||||
|
|
||||||
|
def find_upscayl(explicit):
|
||||||
|
"""upscayl-bin.exe : option, variable UPSCAYL_BIN, puis emplacements d'installation habituels."""
|
||||||
|
cands = [explicit, os.environ.get("UPSCAYL_BIN")]
|
||||||
|
for base in (os.environ.get("ProgramFiles"), os.environ.get("ProgramFiles(x86)"),
|
||||||
|
os.path.join(os.environ.get("LOCALAPPDATA", ""), "Programs")):
|
||||||
|
if base:
|
||||||
|
cands.append(os.path.join(base, "Upscayl", "resources", "bin", "upscayl-bin.exe"))
|
||||||
|
cands += ["/opt/Upscayl/resources/bin/upscayl-bin", "/Applications/Upscayl.app/Contents/Resources/bin/upscayl-bin",
|
||||||
|
shutil.which("upscayl-bin") or ""]
|
||||||
|
for c in cands:
|
||||||
|
if c and os.path.isfile(c):
|
||||||
|
return c
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||||
|
ap.add_argument("jeu")
|
||||||
|
ap.add_argument("sortie")
|
||||||
|
ap.add_argument("--motif", default="LOC*")
|
||||||
|
ap.add_argument("--echelle", type=int, choices=(1, 2, 4), default=1)
|
||||||
|
ap.add_argument("--upscayl", nargs="?", const="digital-art-4x", metavar="MODELE")
|
||||||
|
ap.add_argument("--upscayl-bin")
|
||||||
|
a = ap.parse_args()
|
||||||
|
try:
|
||||||
|
sys.stdout.reconfigure(errors="replace")
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
upscayl = None
|
||||||
|
if a.upscayl:
|
||||||
|
upscayl = find_upscayl(a.upscayl_bin)
|
||||||
|
if not upscayl:
|
||||||
|
sys.exit("Upscayl introuvable : indiquez --upscayl-bin CHEMIN (upscayl-bin.exe)")
|
||||||
|
models = os.path.join(os.path.dirname(os.path.dirname(upscayl)), "models")
|
||||||
|
if not os.path.isfile(os.path.join(models, a.upscayl + ".param")):
|
||||||
|
dispo = sorted(f[:-6] for f in os.listdir(models) if f.endswith(".param")) if os.path.isdir(models) else []
|
||||||
|
sys.exit("modèle Upscayl inconnu : %s (disponibles : %s)" % (a.upscayl, ", ".join(dispo) or "aucun"))
|
||||||
|
a.echelle = 1
|
||||||
|
final = a.sortie
|
||||||
|
if upscayl:
|
||||||
|
a.sortie = tempfile.mkdtemp(prefix="hd_export_")
|
||||||
|
os.makedirs(a.sortie, exist_ok=True)
|
||||||
|
names = sorted(n for n in os.listdir(a.jeu)
|
||||||
|
if n.upper().endswith(".PCX") and fnmatch.fnmatch(n.upper(), a.motif.upper() + ("" if a.motif.upper().endswith(".PCX") else ".PCX")))
|
||||||
|
if not names:
|
||||||
|
sys.exit("aucun PCX ne correspond à %s dans %s" % (a.motif, a.jeu))
|
||||||
|
for n in names:
|
||||||
|
w, h, pix, pal = read_pcx(os.path.join(a.jeu, n))
|
||||||
|
if (w, h) != (320, 200):
|
||||||
|
print("%s ignoré (%d×%d, pas un décor plein écran)" % (n, w, h))
|
||||||
|
continue
|
||||||
|
px = list(pix)
|
||||||
|
s = 1
|
||||||
|
while s < a.echelle:
|
||||||
|
w, h, px = scale2x(w, h, px)
|
||||||
|
s *= 2
|
||||||
|
rgb = bytearray(3 * w * h)
|
||||||
|
for i, c in enumerate(px):
|
||||||
|
rgb[3 * i:3 * i + 3] = pal[3 * c:3 * c + 3]
|
||||||
|
out = os.path.join(a.sortie, os.path.splitext(n)[0].upper() + ".png")
|
||||||
|
write_png(out, w, h, rgb)
|
||||||
|
print("%s -> %s (%d×%d)" % (n, out, w, h))
|
||||||
|
if upscayl:
|
||||||
|
os.makedirs(final, exist_ok=True)
|
||||||
|
print("Upscayl (%s) : %s -> %s" % (a.upscayl, a.sortie, final))
|
||||||
|
r = subprocess.run([upscayl, "-i", a.sortie, "-o", final, "-m", models, "-n", a.upscayl, "-s", "4", "-f", "png"],
|
||||||
|
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True, errors="replace")
|
||||||
|
shutil.rmtree(a.sortie, ignore_errors=True)
|
||||||
|
if r.returncode != 0:
|
||||||
|
sys.exit("Upscayl a échoué :\n" + r.stderr[-2000:])
|
||||||
|
print("%d image(s) HD dans %s" % (len([f for f in os.listdir(final) if f.lower().endswith(".png")]), final))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in new issue
Block a user