Fix lnkIsLink

If the link table indicates the existence of an entry, but the volume
containing that entry is missing, this command returns 1.
This commit is contained in:
kichikuou
2025-01-08 16:15:37 +09:00
parent d6adb3241c
commit 780d30c01f
6 changed files with 36 additions and 30 deletions
+1 -3
View File
@@ -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);
}
+12
View File
@@ -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
+2
View File
@@ -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);
+8 -24
View File
@@ -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);
}
+9 -1
View File
@@ -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];
+4 -2
View File
@@ -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__ */