C:\CTF\K17\WHOLE_NEW_WORLD.EXE _□X

WHOLE NEW WORLD

misc

Challenge

A Terraria world save file (AWholeNewWorld.wld) with the flag painted directly into the terrain as placed tiles, buried among thousands of tiles of ordinary procedurally-generated map.

Solution

No off-the-shelf Terraria map viewer was available, so the world file's tile-section format has to be hand-parsed: per-column runs of tiles, each with a variable-length header (1–4 bytes) encoding whether the tile is active, its type (1 or 2 bytes depending on a high-type-id flag), optional frame U/V coordinates, wall id, liquid amount, and a run-length count for repeating the same tile down the column:

header1 = buf[pos]; pos += 1
… read header2/header3/header4 as chained flag bytes …
isActive = bool(header1 & 0x02)
if isActive:
    tileType = buf[pos] if not (header1 & 0x20) else (buf[pos+1] << 8) | buf[pos]
    … skip frame U/V and color bytes if present …
rle = … 0, 1, or 2 bytes depending on rleStorageType …
… replicate this tile's type/active state down `rle` more rows …

Decoding the whole 4200×1200 tile grid this way gives a type/active bitmap for every tile in the world. Rendering it is the last trick: color each tile deterministically by hashing its type id into an RNG seed, so the same block type always gets the same color no matter where it appears — against that noisy-but-consistent procedural backdrop, any tiles that were deliberately hand-placed to spell something stand out immediately to the eye:

random.seed(tile_type * 2654435761 % (2**32))
color = (random.randint(30,255), random.randint(30,255), random.randint(30,255))

Rendering the full map to a PNG this way makes the flag, painted directly into the tiles, plainly readable.