My First Mod


The simplest Gabriel Knight 3 mod you could probably do is to replace a texture with a new one. So that's what this tutorial will cover. Here's the basic process we need to go through to get the mod to work:

  1. Tell GK3 where to find our new texture
  2. Put the new texture at that location and give it the correct name
  3. Enjoy!

The Search Path

GK3 references files by name. To find any given file it needs it looks in several different places, checking each place to see if the file exists. Here's where GK3 looks for files:

  1. Inside any custom paths
  2. Inside the .brn files

What makes things nice for us modders is that GK3 always looks for files in those places in that order. This ordering is the key to this mod. What we want to do is to override the the textures that GK3 normally uses, and since those textures are all tucked away inside the .brn files (the last place GK3 looks) all we have to do is give the new texture the same name as the texture we want to replace, and then put our texture in a place that GK3 will check before looking in the .brn files.

There are two different ways to add a custom search path to GK3: editing the registry and creating/modifying the GK3.ini file. Editing the GK3.ini file is the safer of the two, so that's what this tutorial will cover. If you really want to know more about the registry method then check out the "REGISTRY SPEC.TXT" file inside the BRN files.

The GK3.ini file is just a plain text file located in the installation folder of GK3. If you don't already have it then create a new blank text file in your favorite text editor and name it "GK3.ini" and save it. Now whenever GK3 starts it will find that file and attempt to read various settings from it. One of those settings, the one we are interested in, is the CUSTOM PATHS setting.

Add the following to your GK3.ini file:

CUSTOM PATHS = .
	

Yes, that's a period after the equal sign. That tells GK3 to add the current directory, which should be the installation directory, to the search paths. If you'd rather use another directory then you'd just add the path to that directory after the equal sign instead of the period, making it look something like this:

CUSTOM PATHS = FolderWithAllMyStuff
	

Note: If you want to add more than one folder to the search paths you can separate them with a semicolon.

Out With the Old

A painting in the lobby Let's find a texture to replace. Why not that painting in the lobby? Maybe Jean wants something new to look at.

Fortunately for us the painting and the frame are two different objects, so we can swap out the painting texture without worrying about adjusting the frame. The name of the painting texture is LNDSCAP1.BMP. Remember that. It is important.

If you happen to have a copy of the Barn Browser handy it might be helpful to extract LNDSCAP1.BMP and take a look at it. You'll see that it's a meager 256 pixels wide and 128 pixels high. This seems small today, but in 1999 when GK3 came out and top of the line graphics cards were just beginning to approach 64 MB of VRAM this was a pretty good size.

Why 256x128? Why not 260x150 or any other arbitrary size? It's important for texture sizes to be powers-of-two. 64, 128, 256, 512, 1024- those are all powers-of-two. The reason is because video cards are much more efficient working with textures when the width and height is a power-of-two.

Also note that the aspect ratio of the image is 2:1, which is a bit wider than the texture actually appears in the game. That's just because the image we want to see in the game is a little wider than it is tall, and since the width and height of the texture must be a power-of-two it just makes more sense to make the texture something like 256x128 instead of a square 128x128. Not to worry, when the texture is applied to the painting hanging on the wall the video card will automatically resize the painting exactly the way it should be.

In With the New

Les Champs Elyees Enough of the old texture. Let's find a new one. We could use a higher-res copy of the same painting, but I couldn't find a copy of it, so instead we're going to use Les Champs Elyees by Jean-Antoine Watteau. I found a copy here.

Update: Finding hi-res versions of the paintings is easy now. Check out the Gabriel Knight 3 Gallery!

As it is the image isn't quite usable as a texture. We need to scale it to a more hardware-friendly size, but at the same time we don't want to scale it down too much so that we loose all the nice high-res detail. An aspect ratio of 2:1 would keep the texture basically the same shape as the original painting, and a resolution of 1024x512 would be significantly higher resolution than the original and meet the power-of-two requirement. 1024x1024 or 512x512 would also work.

Now that you have used your favorite image manipulation program (preferably not MS Paint) to scale the image to a good size it is time to put the texture into the game. Remember how the original texture was called LNDSCAP1.BMP? Give the new texture the same filename.

Now, where do we put this image? If you remember from earlier in the tutorial the very first place GK3 looks for files is in the "custom paths." Hopefully by this point you've given GK3 at least one custom path. Copy the new texture (which should be named LNDSCAP1.BMP) into one of those directories you (hopefully) have added to the search path. Then when GK3 looks for that file it will check the search path you specified, find your custom texture, and load it.

Behold

The new painting Now it's time to see what kind of modders we are. Run the game and go into the hotel lobby. If you see the new painting instead of the old one then we have succeeded. Get as close as you can to the new painting and admire how high-res it is. You can also see how the aspect ratio we used to save the image doesn't have anything to do with the aspect ratio of the painting in the game.

Something isn't right...

Before we celebrate too much it's only fair to point something out. Look at the original painting and look at the painting in the game. It's flipped! There is an interesting quirk in GK3 where bitmaps (and therefore textures) loaded straight from the disk are flipped. I'm not sure why that is, but that is.

Don't worry, it's easy to fix. In your favorite image manipulation program just do a "horizontal flip" and save. Now GK3 will display the texture, and the painting, perfectly.

Conclusion

Now we know how to replace textures. And the process is exactly the same for replacing any other file, whether it is a texture or a script or a 3D model. Just make sure your new asset has the same name as the original, put it where GK3 will find it, and presto, you're modding.

Before

Before Before

After

After After After

Notes