Merge pull request #7693 from Robyt3/Tools-Invalid-Map-Item-Fixes

Fix map tools crashing on maps with unknown UUID-based map items
This commit is contained in:
Dennis Felsing 2023-12-22 15:21:20 +00:00 committed by GitHub
commit 3fa130f3b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 12 deletions

View file

@ -219,14 +219,15 @@ int main(int argc, const char **argv)
{
int Type, ID;
void *pItem = g_DataReader.GetItem(Index, &Type, &ID);
int Size = g_DataReader.GetItemSize(Index);
// filter ITEMTYPE_EX items, they will be automatically added again
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
int Size = g_DataReader.GetItemSize(Index);
Success &= CheckImageDimensions(pItem, Type, pSourceFileName);
CMapItemImage NewImageItem;

View file

@ -377,8 +377,13 @@ void SaveOutputMap(CDataFileReader &InputMap, CDataFileWriter &OutputMap, CMapIt
int ID, Type;
void *pItem = InputMap.GetItem(i, &Type, &ID);
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
if(i == NewItemNumber)
pItem = pNewItem;

View file

@ -140,13 +140,14 @@ int main(int argc, const char **argv)
{
int Type, ID;
void *pPtr = Reader.GetItem(Index, &Type, &ID);
int Size = Reader.GetItemSize(Index);
// filter ITEMTYPE_EX items, they will be automatically added again
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
// for all layers, check if it uses a image and set the corresponding flag
if(Type == MAPITEMTYPE_LAYER)
{
@ -203,6 +204,7 @@ int main(int argc, const char **argv)
++i;
}
int Size = Reader.GetItemSize(Index);
Writer.AddItem(Type, ID, Size, pPtr);
}

View file

@ -168,8 +168,13 @@ void SaveOutputMap(CDataFileReader &InputMap, CDataFileWriter &OutputMap)
int ID, Type;
void *pItem = InputMap.GetItem(i, &Type, &ID);
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
if(g_apNewItem[i])
pItem = g_apNewItem[i];

View file

@ -150,9 +150,12 @@ int main(int argc, const char **argv)
int Type, ID;
void *pItem = g_DataReader.GetItem(Index, &Type, &ID);
// filter ITEMTYPE_EX items, they will be automatically added again
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
int Size = g_DataReader.GetItemSize(Index);

View file

@ -32,9 +32,12 @@ static int ResaveMap(const char *pSourceMap, const char *pDestinationMap, IStora
int Type, ID;
const void *pPtr = Reader.GetItem(Index, &Type, &ID);
// filter ITEMTYPE_EX items, they will be automatically added again
if(Type == ITEMTYPE_EX)
// Filter items with unknown type, as we can't write them back.
// Filter ITEMTYPE_EX items, they will be automatically added again.
if(Type < 0 || Type == ITEMTYPE_EX)
{
continue;
}
int Size = Reader.GetItemSize(Index);
Writer.AddItem(Type, ID, Size, pPtr);