Created
November 30, 2024 21:55
-
-
Save jamesu/45d50d47d17a2ecf9ee0213b603dda3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HexFiend script to parse ThinkTanks .ter files | |
section "Header" { | |
# Read the version (int32) | |
set version [int8 version] | |
set gridShift 8 | |
set lmShift 9 | |
# If version > 3, parse additional fields | |
if {$version > 3} { | |
set gridShift [int32 gridShift] | |
set lmShift [int32 lmShift] | |
int8 tile | |
} | |
} | |
section "Grid" { | |
# Calculate grid size | |
set gridSize [expr {1 << $gridShift}] | |
set heightmapSize [expr {$gridSize * $gridSize}] | |
set heightmapSizeBytes [expr {$heightmapSize*2}] | |
bytes $heightmapSizeBytes "Heightmap" | |
bytes $heightmapSize "Materialmap" | |
} | |
set boolFlags [list false false false false false false false false] | |
# Read material names | |
for {set i 0} {$i < 8} {incr i} { | |
# Read the string length (uint8) | |
set stringLength [uint8] | |
if {$stringLength > 0} { | |
ascii $stringLength "Material $i" | |
} | |
# Update the corresponding flag and string in the lists | |
if {($stringLength != 0)} { | |
set boolFlags [lreplace $boolFlags $i $i true] | |
} | |
} | |
# Read material maps | |
for {set i 0} {$i < 8} {incr i} { | |
if {[lindex $boolFlags $i]} { | |
bytes [expr {$gridSize * $gridSize}] "Material alpha map $i" | |
} | |
} | |
# Read scripts | |
set stringLength [uint32] | |
if {$stringLength > 0} { | |
ascii $stringLength "Texture Script" | |
} | |
set stringLength [uint32] | |
if {$stringLength > 0} { | |
ascii $stringLength "Heightfield Script" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment