I've recently been working on a tool which creates .TER files, but there are two parts of the header which I'm not sure how to calculate (I've been using this as a reference: http://www.ande.pytalhost.eu/ter_file_format.htm):
1) Visible Grid coordinates. The best I can come up with is that the first short indicates a positive value, and the second indicates a negative. These two values are summed, giving one of the offsets. This seems ok for smaller maps, but when they get larger, such as 1024 x 1024, my theory doesn't work any more.
2) Total Grid Size. No matter how large I create a map, the value is always 262144 (0x40000). Square rooting gives 512, but again I'm not sure if this helps or not.
Two extra points. Firstly, the SWBF2 .TER files seem to have an extra byte with value 0x07 just before the list of textures. The other is that the int at offset 0x4 has a value of 22 instead of 21. I appreciate these are probably just because I'm working with SWBF2 and the reference I'm using is for SWBF, but I figured the more information I can provide the better my chances of you being able to help.
Thanks in advance.


