370 static uint8 _old_map3[OLD_MAP_SIZE * 2]; |
370 static uint8 _old_map3[OLD_MAP_SIZE * 2]; |
371 static bool _new_ttdpatch_format; |
371 static bool _new_ttdpatch_format; |
372 static uint32 _old_town_index; |
372 static uint32 _old_town_index; |
373 static uint16 _old_string_id; |
373 static uint16 _old_string_id; |
374 static uint16 _old_string_id_2; |
374 static uint16 _old_string_id_2; |
|
375 static uint16 _old_extra_chunk_nums; |
375 |
376 |
376 static void ReadTTDPatchFlags(void) |
377 static void ReadTTDPatchFlags(void) |
377 { |
378 { |
378 int i; |
379 int i; |
379 |
380 |
394 1 vehicle == 128 bytes */ |
395 1 vehicle == 128 bytes */ |
395 _bump_assert_value = (_old_vehicle_multiplier - 1) * 850 * 128; |
396 _bump_assert_value = (_old_vehicle_multiplier - 1) * 850 * 128; |
396 |
397 |
397 /* Check if we have a modern TTDPatch savegame (has extra data all around) */ |
398 /* Check if we have a modern TTDPatch savegame (has extra data all around) */ |
398 _new_ttdpatch_format = (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0); |
399 _new_ttdpatch_format = (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0); |
|
400 |
|
401 _old_extra_chunk_nums = _old_map3[_new_ttdpatch_format ? 0x1FFFE : 0x2]; |
399 |
402 |
400 /* Clean the misused places */ |
403 /* Clean the misused places */ |
401 for (i = 0; i < 17; i++) _old_map3[i] = 0; |
404 for (i = 0; i < 17; i++) _old_map3[i] = 0; |
402 for (i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0; |
405 for (i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0; |
403 |
406 |
1343 } |
1346 } |
1344 |
1347 |
1345 return !ls->failed; |
1348 return !ls->failed; |
1346 } |
1349 } |
1347 |
1350 |
|
1351 static bool LoadTTDPatchExtraChunks(LoadgameState *ls, int num) |
|
1352 { |
|
1353 ReadTTDPatchFlags(); |
|
1354 |
|
1355 DEBUG(oldloader, 2, "Found %d extra chunk(s)", _old_extra_chunk_nums); |
|
1356 |
|
1357 for (int i = 0; i != _old_extra_chunk_nums; i++) { |
|
1358 uint16 id = ReadUint16(ls); |
|
1359 uint32 len = ReadUint32(ls); |
|
1360 |
|
1361 switch (id) { |
|
1362 /* List of GRFIDs, used in the savegame |
|
1363 * They are saved in a 'GRFID:4 active:1' format, 5 bytes for each entry */ |
|
1364 case 0x2: |
|
1365 case 0x8004: { |
|
1366 /* Skip the first element: TTDP hack for the Action D special variables FFFF0000 01 */ |
|
1367 ReadUint32(ls); ReadByte(ls); len -= 5; |
|
1368 |
|
1369 ClearGRFConfigList(&_grfconfig); |
|
1370 GRFConfig *c = CallocT<GRFConfig>(1); |
|
1371 while (len != 0) { |
|
1372 uint32 grfid = ReadUint32(ls); |
|
1373 |
|
1374 if (ReadByte(ls) == 1) { |
|
1375 c->grfid = grfid; |
|
1376 c->filename = "TTDP game, no information"; |
|
1377 |
|
1378 AppendToGRFConfigList(&_grfconfig, c); |
|
1379 DEBUG(oldloader, 3, "TTDPatch game using GRF file with GRFID %0X", BSWAP32(c->grfid)); |
|
1380 } |
|
1381 len -= 5; |
|
1382 }; |
|
1383 free(c); |
|
1384 |
|
1385 /* Append static NewGRF configuration */ |
|
1386 AppendStaticGRFConfigs(&_grfconfig); |
|
1387 } break; |
|
1388 case 0x3: { /* TTDPatch version and configuration */ |
|
1389 uint32 ttdpv = ReadUint32(ls); |
|
1390 DEBUG(oldloader, 3, "Game saved with TTDPatch version %d.%d.%d r%d", GB(ttdpv, 24, 8), GB(ttdpv, 20, 4), GB(ttdpv, 16, 4), GB(ttdpv, 0, 16)); |
|
1391 len -= 4; |
|
1392 while (len-- != 0) ReadByte(ls); // skip the configuration |
|
1393 } break; |
|
1394 default: |
|
1395 DEBUG(oldloader, 4, "Skipping unknown extra chunk %X", id); |
|
1396 while (len-- != 0) ReadByte(ls); |
|
1397 break; |
|
1398 } |
|
1399 } |
|
1400 |
|
1401 return !ls->failed; |
|
1402 } |
|
1403 |
1348 static uint32 _old_cur_town_ctr; |
1404 static uint32 _old_cur_town_ctr; |
1349 static const OldChunks main_chunk[] = { |
1405 static const OldChunks main_chunk[] = { |
1350 OCL_ASSERT( 0 ), |
1406 OCL_ASSERT( 0 ), |
1351 OCL_VAR ( OC_FILE_U16 | OC_VAR_U32, 1, &_date ), |
1407 OCL_VAR ( OC_FILE_U16 | OC_VAR_U32, 1, &_date ), |
1352 OCL_VAR ( OC_UINT16, 1, &_date_fract ), |
1408 OCL_VAR ( OC_UINT16, 1, &_date_fract ), |
1456 OCL_CHUNK( 1, LoadOldMapPart2 ), |
1512 OCL_CHUNK( 1, LoadOldMapPart2 ), |
1457 |
1513 |
1458 OCL_ASSERT( 0x97179 ), |
1514 OCL_ASSERT( 0x97179 ), |
1459 |
1515 |
1460 /* Below any (if available) extra chunks from TTDPatch can follow */ |
1516 /* Below any (if available) extra chunks from TTDPatch can follow */ |
|
1517 OCL_CHUNK(1, LoadTTDPatchExtraChunks), |
1461 |
1518 |
1462 OCL_END() |
1519 OCL_END() |
1463 }; |
1520 }; |
1464 |
1521 |
1465 static bool LoadOldMain(LoadgameState *ls) |
1522 static bool LoadOldMain(LoadgameState *ls) |