Skip to content

Instantly share code, notes, and snippets.

@jamesu
Created November 30, 2024 21:55
Show Gist options
  • Save jamesu/45d50d47d17a2ecf9ee0213b603dda3c to your computer and use it in GitHub Desktop.
Save jamesu/45d50d47d17a2ecf9ee0213b603dda3c to your computer and use it in GitHub Desktop.
# 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