Tuesday, 20 March 2018

Tomb Raider 3 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.

vcsix

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()” in “Setup.c”.

“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”.


part 2

How to build source code in VS 2019

10 comments:

  1. Please share TR source code?

    ReplyDelete
  2. Are you member of tombraiderforums.com?
    If so send me private message.

    ReplyDelete
    Replies
    1. Here is version of source code modified so debug version can be compiled and built in modern Visual Studio.

      https://cdn.discordapp.com/attachments/417080820034174986/417459100381609984/TR3_ok.zip

      Here is another version that may be the original source code released.

      https://mega.nz/#!WgZRECjI!wgw5j0E0dArdLgWAb4njysb6hB6Ts291Nk1bsbWI2YM

      Delete
  3. Excuse me!!! Is there a way how we can build up the E3 version of Tomb Raider 3 (Run the Gauntlet) from using this source code?

    ReplyDelete
    Replies
    1. I don't know. I wouldn't know how to do it. Maybe the Tomb Editor programmers would know how.

      Delete
  4. Do you know if the str files need to be converted to a Windows Style as well?

    ReplyDelete
    Replies
    1. Sorry I don't know. I used the source code from discord link in first comment and didn't have to change line endings.

      Delete
  5. Do you know how all of the Tomb Raider 2 data was taken to build up everything for the E3 version of Tomb Raider 3? ��

    ReplyDelete
  6. How many source codes are there for Tomb Raider 3?

    ReplyDelete