WLD file format

Editor
Aug 5, 2015 at 2:51 PM
Hi,

Do you have info about the wld file format ? I used the link your provided (http://seancode.com/terrafirma/world.html) but it seems outdated by 1 year.
Coordinator
Aug 5, 2015 at 3:02 PM
Edited Aug 6, 2015 at 12:32 AM
Other than the source code, no. I started out using his documentation, but as new Terraria updates changed the format, I just started using ILSpy to peek at the Terraria world loading code. I haven't bothered to document it, too busy with other priorities. But hey, it's open-source. I welcome anyone that's interested to donate some documentation. :)
Editor
Aug 5, 2015 at 3:16 PM
Thanks for the answer. I'll take a look.
Editor
Aug 6, 2015 at 4:36 PM
Hi,

I have the description of first 121 byte of a wld file. that's a great step for me.

The 1st section is called the FileFormatHeader

int     curRelease  0x9B = 155 = "1.3.0.7"
ulong   MagicNumber "relogic" in ASCII. The meaning of the 8th byte is unknown to me at that moment.
uint    Revision    Incremented every time the file is saved
ulong   IsFavorite  It's a boolean encoded on 64 bits.
short   NumberOfSection 0xA = 10
int[10] OffsetOfNextSection It's an array that contains the start address of the next section in the file.
short   Number of tileFrameImportant 0x1A3 = 419
bool[424]   It's a copy of the array tileFrameImportant. It is set to true for each tile that is animated (torch, etc.), larger than 1 block (life crystal, etc.), has alternative sprite (altars [demon/crimson], table (wood/boreal/cactus/...], etc.). 424 is the next multiple of 8 after 419.
Here are the indexes of tileFrameImportant that are set to TRUE (for version 1.3.0.7) :
003 004 005 010 011 012 013 014 015 016 017 018 019 020 021 024 026 027 028 029 031 033 034 035 036 042 050 055 061 071 072 073 074 077 078 079 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 110 113 114 125 126 128 129 132 133 134 135 136 137 138 139 141 142 143 144 149 165 171 172 173 174 178 184 185 186 187 201 207 209 210 212 215 216 217 218 219 220 227 228 231 233 235 236 237 238 239 240 241 242 243 244 245 246 247 254 269 270 271 275 276 277 278 279 280 281 282 283 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 314 316 317 318 319 320 323 324 334 334 335 337 338 339 349 354 355 356 358 359 360 361 362 363 364 372 373 374 375 376 377 378 380 386 387 388 389 390 391 392 393 394 395 405 406 410 411 412 413 414

For indexes 0 to 15 we obtain : [0001 1100 0011 1111], let's read from 15 to 0 and it translates in hexa to [FC38]. If you look inside a WLD file you'll see at offsets 0x44 and 0x45 the values are 0x38 and 0xFC.

Some resources that helped me

i'll try to understand the rest of the file which is made of different sections

  • Section 2 - WorldHeader
  • Section 3 - WorldTiles
  • Section 4 - Chests
  • Section 5 - Signs
  • Section 6 - NPCs
  • Section 7 - Entities
  • Section 8 - Footer
  • Section 9 - footerHeader
Editor
Aug 13, 2015 at 8:30 PM
Section 2 is boring as hell.

I've skipped it and went to the most interesting part, section 3, the tiles. I've finished documenting this section (in a .txt on my PC). It was exciting having to read a few hex-lines and manually confirm what i found.

Since you said you'll welcome anyone that's interested to donate some documentation. i have a few questions
  • Do you want to open a documentation page for it ?
  • Do you want a specific format for the documentation ?
I' hope Terraria 1.4 is released soon and that they change the WLD format because i loved doing that reverse engineering thing. :)
Coordinator
Aug 13, 2015 at 8:40 PM
Looks great so far! I've made you an Editor on the project, which means you should be able to add/edit documentation wiki pages. I'm fine with whatever format.
Marked as answer by jcoon on 11/15/2016 at 11:45 AM