Merge pull request #7681 from Robyt3/Mapitems-Sound-DataSize-Check

Use `GetDataSize` instead of `CMapItemSound::m_SoundDataSize`
This commit is contained in:
Edgar 2023-12-20 10:37:54 +00:00 committed by GitHub
commit 95cd183e1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 7 deletions

View file

@ -51,8 +51,9 @@ void CMapSounds::OnMapLoad()
}
else
{
void *pData = pMap->GetData(pSound->m_SoundData);
m_aSounds[i] = Sound()->LoadOpusFromMem(pData, pSound->m_SoundDataSize);
const int SoundDataSize = pMap->GetDataSize(pSound->m_SoundData);
const void *pData = pMap->GetData(pSound->m_SoundData);
m_aSounds[i] = Sound()->LoadOpusFromMem(pData, SoundDataSize);
pMap->UnloadData(pSound->m_SoundData);
}
ShowWarning = ShowWarning || m_aSounds[i] == -1;

View file

@ -146,6 +146,7 @@ bool CEditorMap::Save(const char *pFileName)
Item.m_External = 0;
Item.m_SoundName = Writer.AddDataString(pSound->m_aName);
Item.m_SoundData = Writer.AddData(pSound->m_DataSize, pSound->m_pData);
// Value is not read in new versions, but we still need to write it for compatibility with old versions.
Item.m_SoundDataSize = pSound->m_DataSize;
Writer.AddItem(MAPITEMTYPE_SOUND, i, sizeof(Item), &Item);
@ -575,9 +576,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio
}
else
{
pSound->m_DataSize = pItem->m_SoundDataSize;
// copy sample data
pSound->m_DataSize = DataFile.GetDataSize(pItem->m_SoundData);
void *pData = DataFile.GetData(pItem->m_SoundData);
pSound->m_pData = malloc(pSound->m_DataSize);
mem_copy(pSound->m_pData, pData, pSound->m_DataSize);

View file

@ -520,6 +520,9 @@ struct CMapItemSound
int m_SoundName;
int m_SoundData;
// Deprecated. Do not read this value, it could be wrong.
// Use GetDataSize instead, which returns the de facto size.
// Value must still be written for compatibility.
int m_SoundDataSize;
};

View file

@ -102,12 +102,13 @@ bool Process(IStorage *pStorage, const char *pMapName, const char *pPathSave)
continue;
}
const int SoundDataSize = Reader.GetDataSize(pItem->m_SoundData);
char aBuf[IO_MAX_PATH_LENGTH];
str_format(aBuf, sizeof(aBuf), "%s/%s.opus", pPathSave, pName);
dbg_msg("map_extract", "writing sound: %s (%d B)", aBuf, pItem->m_SoundDataSize);
dbg_msg("map_extract", "writing sound: %s (%d B)", aBuf, SoundDataSize);
IOHANDLE Opus = io_open(aBuf, IOFLAG_WRITE);
io_write(Opus, (unsigned char *)Reader.GetData(pItem->m_SoundData), pItem->m_SoundDataSize);
io_write(Opus, Reader.GetData(pItem->m_SoundData), SoundDataSize);
io_close(Opus);
}