Tuesday, 20 March 2018

Tomb Raider source code notes

The source code for TR2/TR3 was briefly leaked online in March 2018 (see info).

This post will document my studies of the code.

First step is to get the project opened in an IDE.

I have Visual C++ 6.0 running on Windows 98 in a Vmware virtual machine.

The workspace file (.dsw) and project file (.dsp) were not recognized initially.

I found I had to convert the line endings in each file from Unix style to Windows style. I used Programmer’s Notepad to do this.

VC++ 6.0 said the project was created in a previous version so I guess the project was created in Visual Studio 97.


VC++ 6.0 has rather limited tools for exploring code so I opened the original workspace file  (with corrected line endings) in VS 2013 Community. The project is converted but does not build successfully – too many errors.

C++ programs start executing at the “main” function or “WinMain” function for Windows C++ programs.

I found the “WinMain” function in “main.cpp” in the “PC Specific” folder.

This calls the “GameMain()” function which you can jump to by right clicking on the function name and selecting “Go to Definition”. This finds the “GameMain()” function in “smain.cpp”.

This is where the script file , “tombPC.dat”, is loaded.

“GameMain()” calls “GF_DoLevelSequence()” to start the game which is found in “gameflow.c”.

“GF_DoLevelSequence()” calls “GF_InterpretSequence()” which is also in “gameflow.c”.

“GF_InterpretSequence()” calls “StartGame()” in “Game.cpp”.

“StartGame()” is where the level is loaded, in “InitialiseLevel()”.

“StartGame()” calls “GameLoop()” also found in “Game.cpp”.

The program keeps executing in the while loop found in “GameLoop()” until the game is over.

Two functions are called repeatedly in the game loop.

“ControlPhase()” found in “Control.c” and “DrawPhaseGame()” found in “Draw.c”.

to be continued …

Wednesday, 13 September 2017

3DS max 2016 Metasequoia (.MQO) Importer

Since the website with the Metasequoia importers/exporters for modern versions of 3DS max has disappeared I tried my hand at compiling sio29’s 3DS max 9 code for 3DS max 2016.

Sunday, 18 June 2017

Github Desktop Program Tutorial

Github Desktop is a GUI program for git version control that is distributed by Github.com.

The video below explains how to use it the best in my opinion.


Markdown cheatsheet for writing readme.md is here. [link]

Friday, 26 May 2017


Version: 0.71
Status: Released

An attempt to replicate aktrekker’s TR2PRJ program for the TRLE community.

I noticed aktrekker’s program gets some of the geometry incorrect, especially some split sectors and some sectors beneath horizontal doors.

Unlike aktrekker’s program I only extract geometry so rooms will have to be manually reconnected, retextured, and triggers, objects and lights added.

aktrekker’s program seems to convert black in the textures to magenta instead of alpha to magenta so I fixed this too.

Source and release at GitHub. [link]

If building from source you need to download the Vampyre Imaging Library. The latest released version does not compile under Delphi XE7 so get the version from Mercurial repository. [link]

Since I don’t know how aktrekker extracted textures and created doors I may in future add ability to import TR2PRJ’s prj file and inject this data into the prj I create.

  • Open .TR4 file
  • Click Save As to save .prj and .tga file

Monday, 1 May 2017

Delphi TOpenDialog option ofExtensionDifferent

ofExtensionDifferent doesn’t appear to be set in Windows 8.1.

The following example from [link] fails.

procedure TForm1.Button1Click(Sender: TObject);
Done: Boolean;
filenamestring : String;
  OpenPictureDialog1.DefaultExt := GraphicExtension(TIcon);
  filenamestring := GraphicFileMask(TIcon);
  OpenPictureDialog1.FileName := filenamestring;
  OpenPictureDialog1.Filter := GraphicFilter(TIcon);
  OpenPictureDialog1.Options := [ ofFileMustExist, ofHideReadOnly, ofNoChangeDir ];
  Done := False;
  while not Done do
  if OpenPictureDialog1.Execute then
    if not (ofExtensionDifferent in OpenPictureDialog1.Options) then
      Done := True;
//      OpenPictureDialog1.Options := OpenPictureDialog1.Options - ofExtensionDifferent;
  else { User cancelled }
    Done := True;
CodeTyphon (Lazarus fork) doesn't have this problem. 

Tuesday, 18 April 2017

FBX ASCII 7300 (2013) File Format