1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Fixed parsing of some user-made H3M maps

This commit is contained in:
Ivan Savenko
2023-09-20 22:00:03 +03:00
parent 02dfecd38b
commit 3f35ed000c
3 changed files with 58 additions and 27 deletions

View File

@@ -113,7 +113,12 @@ int32_t MapReaderH3M::readHeroPortrait()
if(result.getNum() == features.heroIdentifierInvalid)
return int32_t(-1);
assert(result.getNum() < features.heroesPortraitsCount);
if (result.getNum() >= features.heroesPortraitsCount)
{
logGlobal->warn("Map contains invalid hero portrait ID %d. Will be reset!", result.getNum() );
return int32_t(-1);
}
return remapper.remapPortrrait(result);
}
@@ -199,7 +204,12 @@ PlayerColor MapReaderH3M::readPlayer()
if (value == 255)
return PlayerColor::NEUTRAL;
assert(value < PlayerColor::PLAYER_LIMIT_I);
if (value >= PlayerColor::PLAYER_LIMIT_I)
{
logGlobal->warn("Map contains invalid player ID %d. Will be reset!", value );
return PlayerColor::NEUTRAL;
}
return PlayerColor(value);
}
@@ -210,7 +220,12 @@ PlayerColor MapReaderH3M::readPlayer32()
if (value == 255)
return PlayerColor::NEUTRAL;
assert(value < PlayerColor::PLAYER_LIMIT_I);
if (value >= PlayerColor::PLAYER_LIMIT_I)
{
logGlobal->warn("Map contains invalid player ID %d. Will be reset!", value );
return PlayerColor::NEUTRAL;
}
return PlayerColor(value);
}