Monday 22 April 2019

2: Tomb Raider 3 source code notes

Further investigation of the Tomb Raider 3 source code that was leaked online. See the first post in this series for details. [link]

I am studying the modified version mentioned in the comments of the first post (“TR3_ok”) because this version can be successfully built in Visual Studio 2013 as is. I wasn’t the genius who modified the code though.

To run the game, copy the “data” and “pix” folders from the retail version into the project’s folder.

Note on my PC I had to locate the project folder on a USB drive because the setup dialog for the game didn’t have any display resolution options if I used a project folder located on my system.

The leaked source code is not the version used for the retail game. It is an earlier version and some things are unfinished. The members of the discord channel refer to this version as Tomb Raider 2.1.

Be aware that the code contains some rude/offensive language by original programmers in the comments.

It seems that the source code was used for the PC and PSX versions of the game since blocks of code are contained in #ifdef PC_VERSION and #ifdef PSX_VERSION compiler directives. The modified version of the code I am using builds the PC version.


In the last post it was found that the game loop repeatedly calls two functions:
  • ControlPhase() in “CONTROL.C”
  • DrawPhaseGame() in “DRAW.C”
DrawPhaseGame() is where the visible rooms of the level are drawn, in DrawRooms() in “DRAW.C”.

In DrawRooms(), after the rooms are drawn the effects are drawn by the code below.
if(bEffectOn)
{
     //nPolyType = FX_POLY;
     S_DrawSparks();
     S_DrawSplashes();
     S_DrawBat();
     DoRain();
     DoSnow();
     DoUwEffect();
     S_DrawFootPrints();
}
According to this code rain and snow should be drawn for every outside room. If you run the exe however there are no weather effects.

In the retail version there is rain in the jungle level and snow in the Antarctic level so this is further evidence that this source code isn’t the final version.

Investigation found that the snow wasn’t drawn because DoSnow() is an empty function in “drawsnow.cpp”. The code for the PSX version snow however is present in “SNOW.C”.

The rain wasn’t drawn because in DoRain() in “drawrain.cpp” the camera position is never set to the game’s camera. The rain is drawn off screen somewhere.

Hardcoding the camera position as below for the jungle level start enables the rain to be seen.
CamPos.x = 28160; CamPos.y = -1280; CamPos.z = 28060; //sapper

if(IsRoomOutside(CamPos.x+x, CamPos.y+y, CamPos.z+z))
The rain effect is different to the PC retail version.

In the effects code above it can be seen that there is a call to S_DrawFootPrints() in “drawfootprnt.cpp”.

This is another difference with the retail version. In this version Lara’s footprints are drawn in the jungle level for example. The footprints are white so it is speculated that this effect was removed from the PC version due to the unavailability of the correct blending mode.

From the footprint code it can be seen that the maximum number of footprints is 32 and only “active” footprints are drawn. Whether a footprint is active is determined in the control phase and depends on the texture sound as well as other factors.


part 3

2 comments:

  1. As you mention in your notes, you can build the modified version of the code with VS 2013. However, if I try to do so, I always end up with an error. Is there something else to do?

    ReplyDelete
    Replies
    1. I can't recall having to do anything else but maybe I had something already installed in VS. I'll try again and see if it works as is.

      Delete