Swords of Glass puzzle format
There are many puzzles throughout the dungeon of Swords of Glass. These puzzles range from the simple to complex, but all of their text is stored in the Puzzles.dat file. Each puzzle is 400 bytes long and consists of 18 lines and 22 bytes of unknown data. Each line is 1 byte for the length and 20 bytes for the text. The file is fixed-width and stores 37 puzzles.
|UINT8 Puzzle line length||The number of characters to read from the puzzle line.|
|char Puzzle line||The puzzle line.|
|18 lines per puzzle.|
|UINT8 Puzzle line count||how many of the 18 lines are actually used by the puzzle.|
|22 unknown bytes.||Seems to be garbage containing snippets of source code. Mostly repeats for every record, but sometimes changes.|
|37 puzzles in the file.|
This FreeBASIC program will export each of the game's puzzles into a text file.
Dim As Integer PuzzleNo, LineNo, ByteNo Dim As String PuzzleLines(0 To 17) Dim As UByte Unknown Dim As UByte LineLength(0 To 17) Dim As UByte PuzzleLineCount Open "Puzzles.dat" For Binary As #1 Open "Puzzles.txt" For Binary As #2 For PuzzleNo = 0 To 36 ' Read all the lines. For LineNo = 0 To 17 Get #1, , LineLength(LineNo) PuzzleLines(LineNo) = Space(20) Get #1, , PuzzleLines(LineNo) PuzzleLines(LineNo) = Left(PuzzleLines(LineNo), LineLength(LineNo)) Next LineNo ' Read the line count. Get #1, , PuzzleLineCount ' Read the unknown portion and throw it away. For ByteNo = 0 To 21 Get #1, , Unknown Next ByteNo ' Export the puzzle. Put #2, , "Puzzle: " + Str(PuzzleNo) + Chr(13) + Chr(10) Put #2, , Chr(13) + Chr(10) ' Export the lines. For LineNo = 0 To PuzzleLineCount - 1 Put #2, , PuzzleLines(LineNo) + Chr(13) + Chr(10) Next LineNo Put #2, , Chr(13) + Chr(10) Put #2, , Chr(13) + Chr(10) Put #2, , Chr(13) + Chr(10) Next PuzzleNo
This format was reverse engineered by TheAlmightyGuru. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)