[IGfxWorld] Fix runtime data overflow

This commit is contained in:
momo5502 2017-03-20 21:07:55 +01:00
parent 2690b6dab7
commit 19b6203272
7 changed files with 24 additions and 8 deletions

View File

@ -52,6 +52,11 @@ namespace Assets
image->loaded = true; image->loaded = true;
image->loadDef->flags = 0; image->loadDef->flags = 0;
if(image->loadDef->resourceSize != image->dataLen1)
{
Components::Logger::Error("Resource size doesn't match the data length (%s)!\n", name.data());
}
if (Utils::String::StartsWith(name, "*lightmap")) if (Utils::String::StartsWith(name, "*lightmap"))
{ {
image->loadDef->dimensions[0] = 0; image->loadDef->dimensions[0] = 0;

View File

@ -909,7 +909,7 @@ namespace Assets
SaveLogExit(); SaveLogExit();
} }
void IGfxWorld::saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, Components::ZoneBuilder::Zone* builder) void IGfxWorld::saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, int cellCount, Components::ZoneBuilder::Zone* builder)
{ {
AssertSize(Game::GfxWorldDpvsDynamic, 48); AssertSize(Game::GfxWorldDpvsDynamic, 48);
@ -921,14 +921,14 @@ namespace Assets
if (asset->dynEntCellBits[0]) if (asset->dynEntCellBits[0])
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->dynEntCellBits[0], asset->dynEntClientWordCount[0]); buffer->save(asset->dynEntCellBits[0], 4, asset->dynEntClientWordCount[0] * cellCount);
Utils::Stream::ClearPointer(&dest->dynEntCellBits[0]); Utils::Stream::ClearPointer(&dest->dynEntCellBits[0]);
} }
if (asset->dynEntCellBits[1]) if (asset->dynEntCellBits[1])
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->dynEntCellBits[1], asset->dynEntClientWordCount[1]); buffer->save(asset->dynEntCellBits[1], 4, asset->dynEntClientWordCount[1] * cellCount);
Utils::Stream::ClearPointer(&dest->dynEntCellBits[1]); Utils::Stream::ClearPointer(&dest->dynEntCellBits[1]);
} }
@ -1188,14 +1188,14 @@ namespace Assets
if (asset->cellCasterBits) if (asset->cellCasterBits)
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->cellCasterBits, cellCount * ((cellCount + 31) >> 5)); buffer->save(asset->cellCasterBits, 4, cellCount * ((cellCount + 31) >> 5));
Utils::Stream::ClearPointer(&dest->cellCasterBits); Utils::Stream::ClearPointer(&dest->cellCasterBits);
} }
if (asset->cellHasSunLitSurfsBits) if (asset->cellHasSunLitSurfsBits)
{ {
buffer->align(Utils::Stream::ALIGN_4); buffer->align(Utils::Stream::ALIGN_4);
buffer->saveArray(asset->cellHasSunLitSurfsBits, ((cellCount + 31) >> 5)); buffer->save(asset->cellHasSunLitSurfsBits, 4, ((cellCount + 31) >> 5));
Utils::Stream::ClearPointer(&dest->cellHasSunLitSurfsBits); Utils::Stream::ClearPointer(&dest->cellHasSunLitSurfsBits);
} }
@ -1332,7 +1332,7 @@ namespace Assets
} }
this->saveGfxWorldDpvsStatic(asset, &asset->dpvs, &dest->dpvs, asset->dpvsPlanes.cellCount, builder); this->saveGfxWorldDpvsStatic(asset, &asset->dpvs, &dest->dpvs, asset->dpvsPlanes.cellCount, builder);
this->saveGfxWorldDpvsDynamic(&asset->dpvsDyn, &dest->dpvsDyn, builder); this->saveGfxWorldDpvsDynamic(&asset->dpvsDyn, &dest->dpvsDyn, asset->dpvsPlanes.cellCount, builder);
if (asset->heroOnlyLights) if (asset->heroOnlyLights)
{ {

View File

@ -16,7 +16,7 @@ namespace Assets
void saveGfxLightGrid(Game::GfxLightGrid* asset, Game::GfxLightGrid* dest, Components::ZoneBuilder::Zone* builder); void saveGfxLightGrid(Game::GfxLightGrid* asset, Game::GfxLightGrid* dest, Components::ZoneBuilder::Zone* builder);
void savesunflare_t(Game::sunflare_t* asset, Game::sunflare_t* dest, Components::ZoneBuilder::Zone* builder); void savesunflare_t(Game::sunflare_t* asset, Game::sunflare_t* dest, Components::ZoneBuilder::Zone* builder);
void saveGfxWorldDpvsStatic(Game::GfxWorld* world, Game::GfxWorldDpvsStatic* asset, Game::GfxWorldDpvsStatic* dest, int planeCount, Components::ZoneBuilder::Zone* builder); void saveGfxWorldDpvsStatic(Game::GfxWorld* world, Game::GfxWorldDpvsStatic* asset, Game::GfxWorldDpvsStatic* dest, int planeCount, Components::ZoneBuilder::Zone* builder);
void saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, Components::ZoneBuilder::Zone* builder); void saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, int cellCount, Components::ZoneBuilder::Zone* builder);
void loadGfxWorldDraw(Game::GfxWorldDraw* asset, Components::ZoneBuilder::Zone* builder, Utils::Stream::Reader* reader); void loadGfxWorldDraw(Game::GfxWorldDraw* asset, Components::ZoneBuilder::Zone* builder, Utils::Stream::Reader* reader);
void loadGfxWorldDpvsStatic(Game::GfxWorld* world, Game::GfxWorldDpvsStatic* asset, Components::ZoneBuilder::Zone* builder, Utils::Stream::Reader* reader); void loadGfxWorldDpvsStatic(Game::GfxWorld* world, Game::GfxWorldDpvsStatic* asset, Components::ZoneBuilder::Zone* builder, Utils::Stream::Reader* reader);

View File

@ -98,6 +98,11 @@ namespace Components
Logger::Print("Saving...\n"); Logger::Print("Saving...\n");
this->saveData(); this->saveData();
if(this->buffer.hasBlock())
{
Logger::Error("Non-popped blocks left!\n");
}
Logger::Print("Compressing...\n"); Logger::Print("Compressing...\n");
this->writeZone(); this->writeZone();
} }

View File

@ -98,7 +98,7 @@ namespace Utils
for (unsigned int i = 0; i < row.size(); ++i) for (unsigned int i = 0; i < row.size(); ++i)
{ {
if (row[i] == ',' && !isString) // FLush entry if (row[i] == ',' && !isString) // Flush entry
{ {
_row.push_back(element); _row.push_back(element);
element.clear(); element.clear();

View File

@ -246,6 +246,11 @@ namespace Utils
return false; return false;
} }
bool Stream::hasBlock()
{
return !this->streamStack.empty();
}
bool Stream::isValidBlock(Game::XFILE_BLOCK_TYPES stream) bool Stream::isValidBlock(Game::XFILE_BLOCK_TYPES stream)
{ {
return (stream < Game::MAX_XFILE_COUNT && stream >= Game::XFILE_BLOCK_TEMP); return (stream < Game::MAX_XFILE_COUNT && stream >= Game::XFILE_BLOCK_TEMP);

View File

@ -117,6 +117,7 @@ namespace Utils
void increaseBlockSize(unsigned int size); void increaseBlockSize(unsigned int size);
Game::XFILE_BLOCK_TYPES getCurrentBlock(); Game::XFILE_BLOCK_TYPES getCurrentBlock();
unsigned int getBlockSize(Game::XFILE_BLOCK_TYPES stream); unsigned int getBlockSize(Game::XFILE_BLOCK_TYPES stream);
bool hasBlock();
DWORD getPackedOffset(); DWORD getPackedOffset();