.t## holds the tilemap for a map (see Map Format for lump naming).
In older versions, it starts with a BSAVE Header; in newer versions, it starts with 7 garbage bytes (which are likely zero). In either case, a 4 byte header with the size of the map follows immediately after that.
The number of layers is NOT stored anywhere. It is inferred from the size of the lump. Note: it seems that very old games always have 32000 bytes of tile data (after the 7 byte BSAVE header (containing correct length) and 4 byte dimension header).
The minimum map size is 16x10 tiles. The maximum number of tiles that Custom will allow a map to be resized to is 100,000 tiles (per layer); however this is an arbitrary limitation in the resize menu (that might be raised in future), so you should accept maps of any size.
|BYTE * w * h * numlayers||w*h bytes for layer 0, w*h bytes for layer 1, etc...|
Tiles are stored in left-to-right rows, from top to bottom. 0-159 are regular tiles, 160-207 are animating tiles in set 0 and 208-255 are animating tiles in set 1.
Very old games have a single layer followed by garbage to make up 32000 bytes of tile data (total lump size of 32011 bytes). Somewhat newer games have a single layer, not followed by garbage. Newer still games have 3 layers, even if only 1 of them is used and the user never asked for them (the others will not be marked visible in MAP). Newest of all (starting with Ypsiliform) maps may have from 1 to 8 layers, and default to 1 instead of 3 layers.