From b7b7b48151bff2e0adad28e83f94f863322c5fa6 Mon Sep 17 00:00:00 2001 From: Stephan Vedder Date: Mon, 21 Apr 2025 21:34:43 +0200 Subject: [PATCH] [ZH][BFME] Validate map chunk versions in debug --- .../Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp | 1 + .../Code/GameEngine/Source/GameLogic/Map/SidesList.cpp | 1 + .../Source/W3DDevice/GameClient/WorldHeightMap.cpp | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 45cf9f7ad3..1b821fc23e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -134,6 +134,7 @@ PolygonTrigger *PolygonTrigger::getPolygonTriggerByID(Int triggerID) */ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChunkInfo *info, void *userData) { + DEBUG_ASSERTCRASH(info->version <= K_TRIGGERS_VERSION_4, ("PolygonTriggers chunk version newer than supported.")); Int count; Int numPoints; Int triggerID; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp index 6361cb8969..3260b8d10b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp @@ -242,6 +242,7 @@ void SidesList::clear(void) */ Bool SidesList::ParseSidesDataChunk(DataChunkInput &file, DataChunkInfo *info, void *userData) { + DEBUG_ASSERTCRASH(info->version <= K_SIDES_DATA_VERSION_3, ("Sides chunk version newer than supported.")); DEBUG_ASSERTCRASH(TheSidesList, ("TheSidesList is null")); if (TheSidesList==NULL) diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp index fd73bd0160..af516769fe 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp @@ -762,6 +762,7 @@ void WorldHeightMap::setCliffState(Int xIndex, Int yIndex, Bool state) Bool WorldHeightMap::ParseWorldDictDataChunk(DataChunkInput &file, DataChunkInfo *info, void *userData) { + DEBUG_ASSERTCRASH(info->version <= K_WORLDDICT_VERSION_1, ("WorldDict chunk version newer than supported.")); Dict d = file.readDict(); *MapObject::getWorldDict() = d; Bool exists; @@ -781,6 +782,7 @@ Bool WorldHeightMap::ParseWorldDictDataChunk(DataChunkInput &file, DataChunkInfo */ Bool WorldHeightMap::ParseLightingDataChunk(DataChunkInput &file, DataChunkInfo *info, void *userData) { + DEBUG_ASSERTCRASH(info->version <= K_LIGHTING_VERSION_3, ("Lighting chunk version newer than supported.")); TheWritableGlobalData->m_timeOfDay = (TimeOfDay)file.readInt(); Int i; GlobalData::TerrainLighting initLightValues = { { 0,0,0},{0,0,0},{0,0,-1.0f}}; @@ -889,6 +891,7 @@ Bool WorldHeightMap::ParseHeightMapDataChunk(DataChunkInput &file, DataChunkInfo */ Bool WorldHeightMap::ParseHeightMapData(DataChunkInput &file, DataChunkInfo *info, void *userData) { + DEBUG_ASSERTCRASH(info->version <= K_HEIGHT_MAP_VERSION_4, ("HeightMap chunk version newer than supported.")); m_width = file.readInt(); m_height = file.readInt(); if (info->version >= K_HEIGHT_MAP_VERSION_3) { @@ -963,6 +966,7 @@ Bool WorldHeightMap::ParseSizeOnlyInChunk(DataChunkInput &file, DataChunkInfo *i */ Bool WorldHeightMap::ParseSizeOnly(DataChunkInput &file, DataChunkInfo *info, void *userData) { + DEBUG_ASSERTCRASH(info->version <= K_HEIGHT_MAP_VERSION_4, ("HeightMap chunk version newer than supported.")); m_width = file.readInt(); m_height = file.readInt(); if (info->version >= K_HEIGHT_MAP_VERSION_3) { @@ -1070,6 +1074,7 @@ void WorldHeightMap::readTexClass(TXTextureClass *texClass, TileData **tileData) */ Bool WorldHeightMap::ParseBlendTileData(DataChunkInput &file, DataChunkInfo *info, void *userData) { + DEBUG_ASSERTCRASH(info->version <= K_BLEND_TILE_VERSION_8, ("BlendTile chunk version newer than supported.")); int i, j; Int len = file.readInt(); if (m_dataSize != len) { @@ -1250,6 +1255,7 @@ Bool WorldHeightMap::ParseObjectDataChunk(DataChunkInput &file, DataChunkInfo *i */ Bool WorldHeightMap::ParseObjectData(DataChunkInput &file, DataChunkInfo *info, void *userData, Bool readDict) { + DEBUG_ASSERTCRASH(info->version <= K_OBJECTS_VERSION_3, ("Objects chunk version newer than supported.")); MapObject *pPrevious = (MapObject *)file.m_currentObject; Coord3D loc;