Sunday 31 May 2020

Building Tomb Raider III in Visual Studio 2019

This post will outline the steps involved in building the leaked Tomb Raider 3 code in Visual Studio 2019 Community Edition.


 You will need to have installed Visual C++. Run the Visual Studio Installer to install C++ if you did not install it initially. Select More>Modify and install the C++ Workload.
 
Download the code [link] and unzip the files. Note this is not the final Tomb Raider 3 code but an earlier version and is not the original leaked code but a modified version that can be built with modern Visual C++.

Start Visual Studio, click  “Open a project or solution”, navigate to the folder you unzipped and select the TOMBRAID.sln file.

Open

tombraid

The solution file was made with an earlier version of Visual Studio so you will be asked to upgrade the project.

retarget

I accepted the default values and clicked OK. Note you should have installed a Windows SDK with the Visual C++ workload. If not use the Visual Studio Installer to install the Windows SDK component.

If you have earlier versions of Visual Studio installed you can choose older Platform Toolset and SDK versions. These can also be changed in the project’s Property Pages under the General section.

Now try and build the code by clicking Build>Build Solution or Build>Build TOMBRAID.

build
The build fails but only with one error.

error

A missing file required for building the Playstation (PSX) version of TR3 so we do not need it for our PC build. The PSX version is not able to be built using this code.

Double click on the error to have the line of code open in the code editor and comment out the line by typing two forward slashes at the start of the line.

comment

Build the solution again.

Check the output window for success. The output also shows the location of the executable we built.

success

By default we built a Debug version of TOMBRAID.exe therefore we can debug the program.

Before we run it we need to copy some files from the retail game.
Go to Project>TOMBRAID Properties to open the Property Pages for the project.

properties

Select Debugging and see that the Working Directory is $(ProjectDir) which is the directory where the project file is saved (TR3_ok) and is different to where the executable is saved (TR3_ok\Debug).

workingdir

We need to create a folder in the working directory and name it “data”. Inside the “data” folder we copy at least the following files from the retail game’s data folder.
  • JUNGLE.TR2
  • MAIN.SFX
  • TITLE.TR2
  • TOMBPC.DAT
You could instead copy the whole data folder.

data

If you run Tomb Raider III by double clicking TOMBRAID.exe you will need to copy the “data” folder to the same directory as the exe.

Now we can debug TOMBRAID.exe by by clicking the “Local Windows Debugger” button (green arrow).

debugger

The Tomb Raider Setup dialog appears. Note this is a very limited version. I usually change the resolution to match my default monitor resolution so my desktop does not reset. Tomb Raider III runs fullscreen.

setup

Before I click “OK” I create a second desktop (Windows 10) and drag the Tomb Raider III and Tomb Raider III Setup windows to the new desktop.

This is because if I set a breakpoint in the debugger, when it is hit, the Tomb Raider screen goes black and I am unable to access Visual Studio. I have found by having Visual Studio in a separate desktop I can switch desktops to access it.

taskview

newdesktop

drag

Select Desktop 2.

desktop2

Click OK on the setup to run Tomb Raider III.


tr3

When I exit the game normally sometimes I get a DirectX exception. I tried building with older SDKs and Platform Toolsets (as old as VS2013 and SDK 8.1) but was unable to eliminate this error.

This error should not interfere with debugging however. Note that after you return to the game after hitting a breakpoint that the game no longer responds to any input which is annoying.

These posts document my studies of the code.



2 comments:

  1. Hey sapper,
    I stumbled upon your blog by searching for the TR3 source code.
    Now I try to get TR5 to work the source code was released this year.
    I don't know if it's possible to get it working I got so far that the game is starting and loading screen showing up and getting the dblog (debugging tool) tool to work.

    https://www.mediafire.com/file/brqsly585rbn5jy/TOMB5_Src.7z/file

    ReplyDelete