decoding and writing Temple.dat files, trying to be clever.  ugly code