From 144e23ddd5c2f23a75e43a4ec61b18564ba47e27 Mon Sep 17 00:00:00 2001 From: halleyscometsw Date: Fri, 11 Jul 2008 06:34:09 +0000 Subject: [PATCH] support Gameexe.ini for nwa loops as well git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@304 51a99a44-fe44-0410-b1ba-c3e57ba2b86b --- src/meta/nwa.c | 118 ++++++++++++++++++++++++++++++++++++++++++++---- src/vgmstream.c | 5 +- src/vgmstream.h | 3 +- 3 files changed, 116 insertions(+), 10 deletions(-) diff --git a/src/meta/nwa.c b/src/meta/nwa.c index 17fa9359..c4e517fc 100644 --- a/src/meta/nwa.c +++ b/src/meta/nwa.c @@ -24,7 +24,9 @@ VGMSTREAM * init_vgmstream_nwa(STREAMFILE *streamFile) { int channel_count; int loop_flag = 0; int32_t loop_start_sample; - int ini_found = 0; + int32_t loop_end_sample; + int nwainfo_ini_found = 0; + int gameexe_ini_found = 0; /* check extension, case insensitive */ streamFile->get_name(streamFile,filename,sizeof(filename)); @@ -71,7 +73,7 @@ VGMSTREAM * init_vgmstream_nwa(STREAMFILE *streamFile) { off_t file_size; off_t found_off; - ini_found = 1; + nwainfo_ini_found = 1; ext = filename_extension(namebase); length = ext-1-namebase; @@ -111,6 +113,100 @@ VGMSTREAM * init_vgmstream_nwa(STREAMFILE *streamFile) { } /* if opened INI ok */ } /* INI block */ + /* try to locate Gameexe.ini in the same directory */ + { + char ininame[260]; + char * ini_lastslash; + char * namebase; + STREAMFILE *inistreamfile; + + strncpy(ininame,filename,sizeof(ininame)); + ininame[sizeof(ininame)-1]='\0'; /* a pox on the stdlib! */ + + ini_lastslash = strrchr(ininame,DIRSEP); + if (!ini_lastslash) { + strncpy(ininame,"Gameexe.ini",sizeof(ininame)); + namebase = filename; + } else { + strncpy(ini_lastslash+1,"Gameexe.ini", + sizeof(ininame)-(ini_lastslash+1-ininame)); + namebase = ini_lastslash+1-ininame+filename; + } + ininame[sizeof(ininame)-1]='\0'; /* curse you, strncpy! */ + + inistreamfile = streamFile->open(streamFile,ininame,4096); + + if (inistreamfile) { + /* ini found, try to find our name */ + const char * ext; + int length; + int found; + off_t offset; + off_t file_size; + off_t found_off; + + gameexe_ini_found = 1; + + ext = filename_extension(namebase); + length = ext-1-namebase; + file_size = get_streamfile_size(inistreamfile); + + /* format of line is: + * #DSTRACK = 00000000 - eeeeeeee - ssssssss = "name" = "name2?" + * ^22 ^33 ^45 ^57 + */ + + for (found = 0, offset = 0; !found && offsetlayout_type = layout_none; } - if (ini_found) { - vgmstream->meta_type = meta_NWA_INI; + if (nwainfo_ini_found) { + vgmstream->meta_type = meta_NWA_NWAINFOINI; + if (loop_flag) { + vgmstream->loop_start_sample = loop_start_sample; + vgmstream->loop_end_sample = vgmstream->num_samples; + } + } else if (gameexe_ini_found) { + vgmstream->meta_type = meta_NWA_GAMEEXEINI; + if (loop_flag) { + vgmstream->loop_start_sample = loop_start_sample; + vgmstream->loop_end_sample = loop_end_sample; + } } else { vgmstream->meta_type = meta_NWA; } - if (loop_flag) { - vgmstream->loop_start_sample = loop_start_sample; - vgmstream->loop_end_sample = vgmstream->num_samples; - } /* open the file for reading by each channel */ { diff --git a/src/vgmstream.c b/src/vgmstream.c index dd2812e8..00db1060 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -1118,9 +1118,12 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) { case meta_NWA: snprintf(temp,TEMPSIZE,"Visual Art's NWA header"); break; - case meta_NWA_INI: + case meta_NWA_NWAINFOINI: snprintf(temp,TEMPSIZE,"Visual Art's NWA header and NWAINFO.INI for looping"); break; + case meta_NWA_GAMEEXEINI: + snprintf(temp,TEMPSIZE,"Visual Art's NWA header and Gameexe.ini for looping"); + break; default: snprintf(temp,TEMPSIZE,"THEY SHOULD HAVE SENT A POET"); } diff --git a/src/vgmstream.h b/src/vgmstream.h index 0c9b26ae..3a2ba677 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -183,7 +183,8 @@ typedef enum { meta_RIFF_WAVE, /* RIFF, for WAVs */ meta_RIFF_WAVE_POS, /* .wav + .pos for looping */ meta_NWA, /* Visual Art's NWA */ - meta_NWA_INI, /* NWA w/ NWAINFO.INI for looping */ + meta_NWA_NWAINFOINI, /* NWA w/ NWAINFO.INI for looping */ + meta_NWA_GAMEEXEINI, /* NWA w/ Gameexe.ini for looping */ } meta_t; typedef struct {