Add Starfox Adventures midi.wad support

This commit is contained in:
Jack Andersen 2016-07-03 12:41:31 -10:00
parent 5ad8c06b99
commit 3427515960
2 changed files with 112 additions and 2 deletions

View File

@ -724,8 +724,27 @@ struct AppCallback : boo::IApplicationCallback
int idx = 0;
for (const auto& pair : songs)
{
const amuse::ContainerRegistry::SongData& sngData = pair.second;
int16_t grpId = sngData.m_groupId;
int16_t setupId = sngData.m_setupId;
if (sngData.m_groupId == -1 && sngData.m_setupId != -1)
{
for (const auto& pair : allSongGroups)
{
for (const auto& setup : pair.second.second->m_midiSetups)
{
if (setup.first == sngData.m_setupId)
{
grpId = pair.first;
break;
}
}
if (grpId != -1)
break;
}
}
amuse::Printf(_S(" %d %s (Group %d, Setup %d)\n"), idx++,
pair.first.c_str(), pair.second.m_groupId, pair.second.m_setupId);
pair.first.c_str(), grpId, setupId);
}
int userSel = 0;
@ -757,7 +776,25 @@ struct AppCallback : boo::IApplicationCallback
}
}
/* Get group selection from user */
/* Get group selection via setup search */
if (m_groupId == -1 && m_setupId != -1)
{
for (const auto& pair : allSongGroups)
{
for (const auto& setup : pair.second.second->m_midiSetups)
{
if (setup.first == m_setupId)
{
m_groupId = pair.first;
break;
}
}
if (m_groupId != -1)
break;
}
}
/* Get group selection via user */
if (m_groupId != -1)
{
if (allSongGroups.find(m_groupId) != allSongGroups.end())

View File

@ -1679,6 +1679,72 @@ static std::vector<std::pair<SystemString, IntrusiveAudioGroupData>> LoadRS3(FIL
return ret;
}
static bool ValidateStarFoxAdvSongs(FILE* fp)
{
size_t endPos = FileLength(fp);
if (endPos > 2 * 1024 * 1024)
return false;
std::unique_ptr<uint8_t[]> data(new uint8_t[endPos]);
fread(data.get(), 1, endPos, fp);
const uint32_t* lengths = reinterpret_cast<const uint32_t*>(data.get());
size_t totalLen = 0;
int i=0;
for (; i<128 ; ++i)
{
uint32_t len = SBig(lengths[i]);
if (len == 0)
break;
totalLen += len;
totalLen = ((totalLen + 31) & ~31);
}
totalLen += (((i*4) + 31) & ~31);
return totalLen == endPos;
}
static std::vector<std::pair<SystemString, ContainerRegistry::SongData>> LoadStarFoxAdvSongs(FILE* midifp)
{
std::vector<std::pair<SystemString, ContainerRegistry::SongData>> ret;
size_t endPos = FileLength(midifp);
if (endPos > 2 * 1024 * 1024)
return {};
std::unique_ptr<uint8_t[]> data(new uint8_t[endPos]);
fread(data.get(), 1, endPos, midifp);
const uint32_t* lengths = reinterpret_cast<const uint32_t*>(data.get());
int i=0;
for (; i<128 ; ++i)
{
uint32_t len = SBig(lengths[i]);
if (len == 0)
break;
}
size_t sngCount = i;
size_t cur = (((sngCount*4) + 31) & ~31);
for (i=0; i<sngCount ; ++i)
{
uint32_t len = SBig(lengths[i]);
if (len == 0)
break;
SystemChar name[128];
SNPrintf(name, 128, _S("Song%u"), i);
std::unique_ptr<uint8_t[]> song(new uint8_t[len]);
memmove(song.get(), data.get() + cur, len);
ret.emplace_back(name, ContainerRegistry::SongData(std::move(song), len, -1, i));
cur += len;
cur = ((cur + 31) & ~31);
}
return ret;
}
ContainerRegistry::Type ContainerRegistry::DetectContainerType(const SystemChar* path)
{
FILE* fp;
@ -2062,6 +2128,13 @@ ContainerRegistry::LoadSongs(const SystemChar* path)
return ret;
}
if (ValidateStarFoxAdvSongs(fp))
{
auto ret = LoadStarFoxAdvSongs(fp);
fclose(fp);
return ret;
}
fclose(fp);
}