From 780d30c01f09c06794400ce6580c84eaeaecbbf9 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Wed, 8 Jan 2025 16:11:33 +0900 Subject: [PATCH] Fix lnkIsLink If the link table indicates the existence of an entry, but the volume containing that entry is missing, this command returns 1. --- modules/SACT/SACT.c | 4 +--- src/ald_manager.c | 12 ++++++++++++ src/ald_manager.h | 2 ++ src/cmd2F.c | 32 ++++++++------------------------ src/dri.c | 10 +++++++++- src/dri.h | 6 ++++-- 6 files changed, 36 insertions(+), 30 deletions(-) diff --git a/modules/SACT/SACT.c b/modules/SACT/SACT.c index e43cc2d..a8e17da 100644 --- a/modules/SACT/SACT.c +++ b/modules/SACT/SACT.c @@ -1800,9 +1800,7 @@ static void MusicCheck() { int wNum = getCaliValue(); int *vRND = getCaliVariable(); - dridata *dfile = ald_getdata(DRIFILE_BGM, wNum - 1); - *vRND = dfile ? 1 : 0; - ald_freedata(dfile); + *vRND = ald_exists(DRIFILE_BGM, wNum - 1) ? 1 : 0; TRACE("SACT.MusicCheck %d,%p:", wNum, vRND); } diff --git a/src/ald_manager.c b/src/ald_manager.c index 46127f6..5a66888 100644 --- a/src/ald_manager.c +++ b/src/ald_manager.c @@ -45,6 +45,18 @@ static void ald_free(dridata *dfile) { free(dfile); } +bool ald_is_linked(DRIFILETYPE type, int no) { + if (type >= DRIFILETYPEMAX || !dri[type]) + return false; + return dri_is_linked(dri[type], no); +} + +bool ald_exists(DRIFILETYPE type, int no) { + if (type >= DRIFILETYPEMAX || !dri[type]) + return false; + return dri_exists(dri[type], no); +} + /* * load dri data * type: data type diff --git a/src/ald_manager.h b/src/ald_manager.h index eea99eb..31e8993 100644 --- a/src/ald_manager.h +++ b/src/ald_manager.h @@ -39,6 +39,8 @@ typedef enum { } DRIFILETYPE; void ald_init(int type, const char **file, int cnt, boolean use_mmap); +bool ald_is_linked(DRIFILETYPE type, int no); +bool ald_exists(DRIFILETYPE type, int no); dridata *ald_getdata(DRIFILETYPE type, int no); void ald_freedata(dridata *data); int ald_get_maxno(DRIFILETYPE type); diff --git a/src/cmd2F.c b/src/cmd2F.c index b959348..e2ed936 100644 --- a/src/cmd2F.c +++ b/src/cmd2F.c @@ -1040,8 +1040,7 @@ void commands2F64() { int eNum = getCaliValue(); int *vResult = getCaliVariable(); DRIFILETYPE t = DRIFILE_DATA; - dridata *dfile; - + switch(eType) { case 0: t = DRIFILE_DATA; @@ -1062,16 +1061,9 @@ void commands2F64() { t = DRIFILE_RSC; break; } - - dfile = ald_getdata(t, eNum -1); - if (dfile == NULL) { - *vResult = 0; - } else { - *vResult = 1; - } - - ald_freedata(dfile); - + + *vResult = ald_is_linked(t, eNum - 1) ? 1 : 0; + TRACE("lnkIsLink %d, %d, %d:", eType, eNum, *vResult); } @@ -1081,8 +1073,7 @@ void commands2F65() { int *vResult = getCaliVariable(); DRIFILETYPE t = DRIFILE_DATA; - dridata *dfile; - + switch(eType) { case 0: t = DRIFILE_DATA; @@ -1103,16 +1094,9 @@ void commands2F65() { t = DRIFILE_RSC; break; } - - dfile = ald_getdata(t, eNum -1); - if (dfile == NULL) { - *vResult = 0; - } else { - *vResult = 1; - } - - ald_freedata(dfile); - + + *vResult = ald_exists(t, eNum - 1) ? 1 : 0; + TRACE("lnkIsData %d, %d, %d:", eType, eNum, *vResult); } diff --git a/src/dri.c b/src/dri.c index d12ba90..cf545ec 100644 --- a/src/dri.c +++ b/src/dri.c @@ -114,8 +114,16 @@ drifiles *dri_init(const char **file, int cnt, boolean use_mmap) { return d; } +bool dri_is_linked(drifiles *d, int no) { + return no >= 0 && no < d->nr_files && d->link[no * 3]; +} + +bool dri_exists(drifiles *d, int no) { + return dri_is_linked(d, no) && d->offset[no]; +} + dridata *dri_getdata(drifiles *d, int no) { - if (no < 0 || no >= d->nr_files || !d->link[no * 3] || !d->offset[no]) + if (!dri_exists(d, no)) return NULL; int volume = d->link[no * 3]; diff --git a/src/dri.h b/src/dri.h index 7c4304f..cbe1312 100644 --- a/src/dri.h +++ b/src/dri.h @@ -50,7 +50,9 @@ struct _dridata { }; typedef struct _dridata dridata; -extern drifiles *dri_init(const char **file, int cnt, boolean use_mmap); -extern dridata *dri_getdata(drifiles *d, int no); +drifiles *dri_init(const char **file, int cnt, boolean use_mmap); +bool dri_is_linked(drifiles *d, int no); +bool dri_exists(drifiles *d, int no); +dridata *dri_getdata(drifiles *d, int no); #endif /* !__DRI__ */