* Load a chunk of data (eg vehicles, stations, etc.) * @param ch The chunkhandler that will be used for the operation */
| 2146 | * @param ch The chunkhandler that will be used for the operation |
| 2147 | */ |
| 2148 | static void SlLoadChunk(const ChunkHandler &ch) |
| 2149 | { |
| 2150 | uint8_t m = SlReadByte(); |
| 2151 | |
| 2152 | _sl.block_mode = m & CH_TYPE_MASK; |
| 2153 | _sl.obj_len = 0; |
| 2154 | _sl.expect_table_header = (_sl.block_mode == CH_TABLE || _sl.block_mode == CH_SPARSE_TABLE); |
| 2155 | |
| 2156 | /* The header should always be at the start. Read the length; the |
| 2157 | * Load() should as first action process the header. */ |
| 2158 | if (_sl.expect_table_header) { |
| 2159 | if (SlIterateArray() != INT32_MAX) SlErrorCorrupt("Table chunk without header"); |
| 2160 | } |
| 2161 | |
| 2162 | switch (_sl.block_mode) { |
| 2163 | case CH_TABLE: |
| 2164 | case CH_ARRAY: |
| 2165 | _sl.array_index = 0; |
| 2166 | ch.Load(); |
| 2167 | if (_next_offs != 0) SlErrorCorrupt("Invalid array length"); |
| 2168 | break; |
| 2169 | case CH_SPARSE_TABLE: |
| 2170 | case CH_SPARSE_ARRAY: |
| 2171 | ch.Load(); |
| 2172 | if (_next_offs != 0) SlErrorCorrupt("Invalid array length"); |
| 2173 | break; |
| 2174 | case CH_RIFF: { |
| 2175 | /* Read length */ |
| 2176 | size_t len = (SlReadByte() << 16) | ((m >> 4) << 24); |
| 2177 | len += SlReadUint16(); |
| 2178 | _sl.obj_len = len; |
| 2179 | size_t start_pos = _sl.reader->GetSize(); |
| 2180 | size_t endoffs = start_pos + len; |
| 2181 | ch.Load(); |
| 2182 | |
| 2183 | if (_sl.reader->GetSize() != endoffs) { |
| 2184 | SlErrorCorruptFmt("Invalid chunk size in RIFF in {} - expected {}, got {}", ch.GetName(), len, _sl.reader->GetSize() - start_pos); |
| 2185 | } |
| 2186 | break; |
| 2187 | } |
| 2188 | default: |
| 2189 | SlErrorCorrupt("Invalid chunk type"); |
| 2190 | break; |
| 2191 | } |
| 2192 | |
| 2193 | if (_sl.expect_table_header) SlErrorCorrupt("Table chunk without header"); |
| 2194 | } |
| 2195 | |
| 2196 | /** |
| 2197 | * Load a chunk of data for checking savegames. |
no test coverage detected