Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tombraider.bfft 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. /*
  2. * tombraider.bfft - Tomb Raider 1 - 3 Level File Format Description
  3. * 2014, Thomas Buck <xythobuz@xythobuz.de>
  4. *
  5. * Based on the TR Rosetta Stone (http://www.tnlc.com/eep/tr/TRosettaStone.html)
  6. * Developed for Binspector (https://github.com/binspector/binspector)
  7. */
  8. // ########## General data structures ##########
  9. // Rectangular faces
  10. struct face4_t {
  11. // These are indices into the appropriate vertex list
  12. unsigned 16 little vertices[4];
  13. /*
  14. * Index into the object texture list (for textured objects)
  15. * or into the 8 or 16bit palette (for colored object).
  16. * When coloring is used, texture contains two indices:
  17. * (texture & 0x00FF) = index into 8bit palette
  18. * ((texture & 0xFF00) >> 8) = index into 16bit palette
  19. */
  20. unsigned 16 little texture;
  21. summary texture, ": ", vertices[0], " - ", vertices[1], " - ", vertices[2], " - ", vertices[3];
  22. }
  23. // Triangular faces
  24. struct face3_t {
  25. // See face4_t for a description of the elements
  26. unsigned 16 little vertices[3];
  27. unsigned 16 little texture;
  28. summary vertices[0], " - ", vertices[1], " - ", vertices[2];
  29. }
  30. struct vertex_t {
  31. // These coordinates are relative!
  32. signed 16 little x;
  33. signed 16 little y;
  34. signed 16 little z;
  35. summary "X: ", x, " Y: ", y, " Z: ", z;
  36. }
  37. // ########## Room data structures ##########
  38. struct room_vertex_t {
  39. /*
  40. * Position of this vertex, relative to the x/z coordinates
  41. * of the room this vertex is a part of.
  42. */
  43. vertex_t vertex;
  44. /*
  45. * Room lighting is internal vertex lighting, except
  46. * for necessarily external sources like flares.
  47. * Room ambient lights and point sources are ignored.
  48. */
  49. signed 16 little lighting1;
  50. // TR1 lacks these attributes
  51. if (TRversion > 1) {
  52. /*
  53. * A set of flags for special rendering effects:
  54. * 0x8000 - Has something to do with water surfaces
  55. * 0x4000 - Underwater lighting modulation and movement,
  56. * if viewed from above the water surface.
  57. * 0x2000 - Water/Quicksand surface movement
  58. * 0x0010 - Normal
  59. */
  60. unsigned 16 little attributes;
  61. // Almost always equal to lighting1
  62. signed 16 little lighting2;
  63. }
  64. summary summaryof(vertex);
  65. }
  66. struct room_sprite_t {
  67. // Index into the vertex list of the current room
  68. signed 16 little vertex;
  69. // Index into the sprite texture list
  70. signed 16 little texture;
  71. summary vertex, "-", texture;
  72. }
  73. struct room_door_t {
  74. // Which room this portal leads to
  75. unsigned 16 little adjoiningRoom;
  76. /*
  77. * Which way the portal faces (points away from adjacent room,
  78. * to be seen though it must point toward the viewpoint)
  79. */
  80. vertex_t normal;
  81. // The corners of this portal (right-hand rule applies wrt normal)
  82. vertex_t vertices[4];
  83. summary "To: ", adjoiningRoom;
  84. }
  85. struct room_sector_t {
  86. unsigned 16 little floorDataIndex;
  87. unsigned 16 little boxIndex;
  88. unsigned 8 little roomBelow;
  89. signed 8 little floor;
  90. unsigned 8 little roomAbove;
  91. signed 8 little ceiling;
  92. summary "Be.: ", roomBelow, " Ab.: ", roomAbove;
  93. }
  94. struct room_light_t {
  95. signed 32 little x;
  96. signed 32 little y;
  97. signed 32 little z;
  98. unsigned 16 little intensity1;
  99. if (TRversion > 1)
  100. unsigned 16 little intensity2;
  101. unsigned 32 little fade1;
  102. if (TRversion > 1)
  103. unsigned 32 little fade2;
  104. summary "X: ", x, " Y: ", y, " Z: ", z;
  105. }
  106. struct room_mesh_t {
  107. unsigned 32 little x;
  108. unsigned 32 little y;
  109. unsigned 32 little z;
  110. unsigned 16 little rotation;
  111. unsigned 16 little intensity1;
  112. if (TRversion > 1)
  113. unsigned 16 little intensity2;
  114. unsigned 16 little objectID;
  115. summary "ID: ", objectID, " X: ", x, " Y: ", y, " Z: ", z;
  116. }
  117. struct room_t {
  118. // Room Header
  119. signed 32 little x;
  120. signed 32 little z;
  121. signed 32 little yBottom;
  122. signed 32 little yTop;
  123. unsigned 32 little numDataToFollow;
  124. unsigned 16 little numVertices;
  125. room_vertex_t vertices[numVertices];
  126. unsigned 16 little numRectangles;
  127. face4_t rectangles[numRectangles];
  128. unsigned 16 little numTriangles;
  129. face3_t triangles[numTriangles];
  130. unsigned 16 little numSprites;
  131. room_sprite_t sprites[numSprites];
  132. unsigned 16 little numDoors;
  133. room_door_t doors[numDoors];
  134. unsigned 16 little numZSector;
  135. unsigned 16 little numXSector;
  136. room_sector_t sectorData[numZSector * numXSector];
  137. signed 16 little intensity1;
  138. if (TRversion > 1)
  139. signed 16 little intensity2;
  140. if (TRversion == 2)
  141. signed 16 little lightMode;
  142. unsigned 16 little numLights;
  143. room_light_t lights[numLights];
  144. unsigned 16 little numStaticMeshes;
  145. room_mesh_t staticMeshes[numStaticMeshes];
  146. signed 16 little alternateRoom;
  147. unsigned 16 little flags;
  148. if (TRversion == 3)
  149. unsigned 24 little roomLightColor;
  150. summary "X: ", x, " Ybot: ", yBottom, " Ytop: ", yTop, " Z: ", z;
  151. }
  152. // ########## Actor data structures ##########
  153. struct animation_t {
  154. unsigned 32 little frameOffset;
  155. unsigned 8 little frameRate;
  156. unsigned 8 little frameSize;
  157. unsigned 16 little stateID;
  158. skip unknown[8];
  159. unsigned 16 little frameStart;
  160. unsigned 16 little frameEnd;
  161. unsigned 16 little nextAnimation;
  162. unsigned 16 little nextFrame;
  163. unsigned 16 little numStateChanges;
  164. unsigned 16 little stateChangeOffset;
  165. unsigned 16 little numAnimCommands;
  166. unsigned 16 little animCommandOffset;
  167. summary "State: ", stateID, " To: ", nextAnimation, "-", nextFrame;
  168. }
  169. struct state_change_t {
  170. unsigned 16 little stateID;
  171. unsigned 16 little numAnimDispatches;
  172. unsigned 16 little animDispatchOffset;
  173. summary "State: ", stateID;
  174. }
  175. struct anim_dispatch_t {
  176. signed 16 little low;
  177. signed 16 little high;
  178. signed 16 little nextAnimation;
  179. signed 16 little nextFrame;
  180. summary low, "-", high, " To: ", nextAnimation, "-", nextFrame;
  181. }
  182. struct moveable_t {
  183. unsigned 32 little objectID;
  184. unsigned 16 little numMeshes;
  185. unsigned 16 little startingMesh;
  186. unsigned 32 little meshTree;
  187. unsigned 32 little frameOffset;
  188. unsigned 16 little animation;
  189. summary "ID: ", objectID, " Anim: ", animation;
  190. }
  191. // ########## Other data structures ##########
  192. struct static_mesh_t {
  193. unsigned 32 little objectID;
  194. unsigned 16 little mesh;
  195. vertex_t boundingBox[4];
  196. unsigned 16 little flags;
  197. summary "ID: ", objectID;
  198. }
  199. struct object_texture_vert_t {
  200. unsigned 8 little xCoordinate;
  201. unsigned 8 little xPixel;
  202. unsigned 8 little yCoordinate;
  203. unsigned 8 little yPixel;
  204. summary xCoordinate, "-", yCoordinate, ", ", xPixel, "-", yPixel;
  205. }
  206. struct object_texture_t {
  207. unsigned 16 little attribute;
  208. unsigned 16 little tile;
  209. object_texture_vert_t vertices[4];
  210. summary "Tile: ", tile;
  211. }
  212. struct sprite_texture_t {
  213. unsigned 16 little tile;
  214. unsigned 8 little x;
  215. unsigned 8 little y;
  216. unsigned 16 little width;
  217. unsigned 16 little height;
  218. signed 16 little leftSide;
  219. signed 16 little topSide;
  220. signed 16 little rightSide;
  221. signed 16 little bottomSide;
  222. summary x, "-", y, ", ", width, "-", height;
  223. }
  224. struct sprite_sequence_t {
  225. signed 32 little objectID;
  226. signed 16 little negativeLength;
  227. signed 16 little offset;
  228. summary "ID: ", objectID;
  229. }
  230. struct camera_t {
  231. signed 32 little x;
  232. signed 32 little y;
  233. signed 32 little z;
  234. signed 16 little room;
  235. unsigned 16 little unknown;
  236. summary "X: ", x, " Y: ", y, " Z: ", z;
  237. }
  238. struct sound_source_t {
  239. signed 32 little x;
  240. signed 32 little y;
  241. signed 32 little z;
  242. unsigned 16 little soundID;
  243. unsigned 16 little flags;
  244. summary "X: ", x, " Y: ", y, " Z: ", z;
  245. }
  246. struct box_t {
  247. if (TRversion > 1) {
  248. /*
  249. * In TR2 & TR3, these values are based on sectors,
  250. * so they need to be scaled (* 1024 units)
  251. */
  252. unsigned 8 little zMin;
  253. unsigned 8 little zMax;
  254. unsigned 8 little xMin;
  255. unsigned 8 little xMax;
  256. } else {
  257. // In TR1 there is no scaling
  258. signed 32 little zMin;
  259. signed 32 little zMax;
  260. signed 32 little xMin;
  261. signed 32 little xMax;
  262. }
  263. // Y value (no scaling)
  264. signed 16 little trueFloor;
  265. /*
  266. * Index into overlaps. The high bit is sometimes set,
  267. * this occurs in front of swinging doors and the like
  268. */
  269. signed 16 little overlapIndex;
  270. summary "X: ", xMin, "-", xMax, " Z: ", zMin, "-", zMax;
  271. }
  272. struct item_t {
  273. signed 16 little objectID;
  274. signed 16 little room;
  275. signed 32 little x;
  276. signed 32 little y;
  277. signed 32 little z;
  278. signed 16 little angle;
  279. signed 16 little intensity1;
  280. if (TRversion > 1)
  281. signed 16 little intensity2;
  282. unsigned 16 little flags;
  283. summary "ID: ", objectID, " X: ", x, " Y: ", y, " Z: ", z;
  284. }
  285. struct cinematic_frame_t {
  286. signed 16 little rotY;
  287. signed 16 little rotZ;
  288. signed 16 little rotZ2;
  289. signed 16 little posZ;
  290. signed 16 little posY;
  291. signed 16 little posX;
  292. signed 16 little unknown;
  293. signed 16 little rotX;
  294. }
  295. struct sound_details_t {
  296. signed 16 little sample;
  297. signed 16 little volume;
  298. signed 16 little unknown1;
  299. signed 16 little unknown2;
  300. summary "Sample: ", sample, ", Vol: ", volume * 100 / 32767, "%";
  301. }
  302. // ########## Main file layout ##########
  303. struct main {
  304. unsigned 32 little version;
  305. if (version == 0x20) {
  306. notify "Tomb Raider 1 file detected...";
  307. const TRversion = 1;
  308. } else if (version == 0x2D) {
  309. notify "Tomb Raider 2 file detected...";
  310. const TRversion = 2;
  311. } else if ((version == 0xFF080038) || (version == 0xFF180038)) {
  312. notify "Tomb Raider 3 file detected...";
  313. const TRversion = 3;
  314. } else if ((version == 0xFFFFFFF0) || (version == 0x00345254)) {
  315. die "Tomb Raider 4 file detected but not supported!";
  316. } else {
  317. die "Unknown version number found!";
  318. }
  319. // TR2 & TR3 have their 8 & 16bit palettes here
  320. if (TRversion > 1)
  321. skip palettes[256 * 7];
  322. // 8bit textures
  323. unsigned 32 little numTextiles;
  324. skip textiles[256 * 256 * numTextiles];
  325. // TR1 does not have any 16bit textures
  326. if (TRversion > 1)
  327. skip textiles16[256 * 256 * numTextiles * 2];
  328. unsigned 32 little unused;
  329. unsigned 16 little numRooms;
  330. room_t rooms[numRooms];
  331. unsigned 32 little numFloorData;
  332. skip floorData[numFloorData * 2];
  333. unsigned 32 little numMeshData;
  334. skip meshData[numMeshData * 2];
  335. unsigned 32 little numMeshPointers;
  336. unsigned 32 little meshPointers[numMeshPointers];
  337. unsigned 32 little numAnimations;
  338. animation_t animations[numAnimations];
  339. unsigned 32 little numStateChanges;
  340. state_change_t stateChanges[numStateChanges];
  341. unsigned 32 little numAnimDispatches;
  342. anim_dispatch_t animDispatches[numAnimDispatches];
  343. unsigned 32 little numAnimCommands;
  344. signed 16 little animCommands[numAnimCommands];
  345. unsigned 32 little numMeshTrees;
  346. signed 32 little meshTrees[numMeshTrees];
  347. unsigned 32 little numFrames;
  348. skip frames[numFrames * 2];
  349. unsigned 32 little numMoveables;
  350. moveable_t moveables[numMoveables];
  351. unsigned 32 little numStaticMeshes;
  352. static_mesh_t staticMeshes[numStaticMeshes];
  353. // TR1 & TR2 have their object textures placed here
  354. if (TRversion < 3) {
  355. unsigned 32 little numObjectTextures;
  356. object_texture_t objectTextures[numObjectTextures];
  357. }
  358. unsigned 32 little numSpriteTextures;
  359. sprite_texture_t spriteTextures[numSpriteTextures];
  360. unsigned 32 little numSpriteSequences;
  361. sprite_sequence_t spriteSequences[numSpriteSequences];
  362. unsigned 32 little numCameras;
  363. camera_t cameras[numCameras];
  364. unsigned 32 little numSoundSources;
  365. sound_source_t soundSources[numSoundSources];
  366. unsigned 32 little numBoxes;
  367. box_t boxes[numBoxes];
  368. unsigned 32 little numOverlaps;
  369. skip overlaps[numOverlaps * 2];
  370. // TR1 has 6 bytes per zone entry, TR2 & TR3 have 10
  371. if (TRversion > 1)
  372. skip zones[numBoxes * 10 * 2];
  373. else
  374. skip zones[numBoxes * 6 * 2];
  375. unsigned 32 little numAnimatedTextures;
  376. skip animatedTextures[numAnimatedTextures * 2];
  377. // TR3 has its object textures placed here
  378. if (TRversion == 3) {
  379. unsigned 32 little numObjectTextures;
  380. object_texture_t objectTextures[numObjectTextures];
  381. }
  382. unsigned 32 little numItems;
  383. item_t items[numItems];
  384. skip lightMap[32 * 256];
  385. // TR1 places its 8bit palette here
  386. if (TRversion == 1)
  387. skip palette[256 * 3];
  388. unsigned 16 little numCinematicFrames;
  389. cinematic_frame_t cinematicFrames[numCinematicFrames];
  390. unsigned 16 little numDemoData;
  391. skip demoData[numDemoData];
  392. // TR1s sound map has 256 entries, TR2 & TR3 have 370
  393. if (TRversion > 1)
  394. signed 16 little soundMap[370];
  395. else
  396. signed 16 little soundMap[256];
  397. unsigned 32 little numSoundDetails;
  398. sound_details_t soundDetails[numSoundDetails];
  399. // TR1 has the sample data embedded here (WAV files)
  400. if (TRversion == 1) {
  401. unsigned 32 little numWAVSamples;
  402. skip wavSamples[numWAVSamples];
  403. }
  404. unsigned 32 little numSampleIndices;
  405. unsigned 32 little sampleIndices[numSampleIndices];
  406. }