Modding CB in 2019 - An updated guide for 1.3.11

#1
READ ALL OF THIS.
I want to get something out of the way here. Containment Breach is a very old and very unstable game by modern standards. Getting it to compile is very hard compared to other games, it's written with outdated (or now nonexistent!!) software, and for anything above Windows 7 you'll have to fight to get it to obey you. I got it working on Windows 10, but it took a full week.

With that, I want to state something: sometimes, no matter what you do, you just cannot win. Maybe your game won't compile. Maybe it throws dumb errors or doesn't load textures. There is absolutely nothing you can do in a lot of scenarios, because the engine the game runs on just flat-out isn't designed to work on modern systems. I feel very blessed that it compiles without a hitch on mine, but I can almost guarantee that, for most people, you're going to run into some issues with no obvious solutions.

It's possible you won't even be able to work with it at all. The worst thing here is that there's nothing you can do to fix that short of installing Windows Vista or Windows XP, which Blitz was built for, and working there instead. If you really want to mod CB, and your system doesn't like it, you're going to have to fight, and hard, to do that.

Still here? Understand the risks? Alright, let's go. You've been warned.

Intro
So, for whatever reason, you want to mod CB in 2019. As of this post, the final version of the game in Blitz3D is 1.3.11. 1.4 isn't due for some time, and will be on a completely new engine. There are plenty of guides and resources, but nearly all of them are very outdated (for 1.2 and even further back) and it takes a very long time to figure out some things on your own unless you're very dedicated.

I did all of that on my own, and after almost a full week, I was finally able to start making changes to the game code and assets, and not have it bug out when compiling, and even now I still struggle to get some things working. I decided to compile it all here to spare future generations of modders the pain that I had to go through myself. So, without further ado, here's how to download Containment Breach's source code and start modding it.

Background Info
There are a few things you should know about Containment Breach before we get started. First, it's old. Really old. Its map files were created with a software that no longer exists for public download, and it's built on a shoddy engine that's gone free and open-source. These softwares were 3D World Builder and Blitz3D respectively, and CB strains both to their metaphorical limits, because they're very weak pieces of software compared to modern standards.

If you have experience programming before, it'll come in handy here. Blitz3D uses its own language called Blitz Basic, which is terrible, but the CB team managed to hack it together into a working game, somehow. For instance, here's the code that makes 173 move rooms, slightly modified for a personal mod:
Spoiler

Code: Select all

								If dist > 50 Then
									If Rand(70)=1 Then
										If PlayerRoom\RoomTemplate\Name <> "exit1" And PlayerRoom\RoomTemplate\Name <> "gatea" And PlayerRoom\RoomTemplate\Name <> "room049" And PlayerRoom\RoomTemplate\Name <> "pocketdimension" And PlayerRoom\RoomTemplate\Name <> "dimension1499" Then
											For w.waypoints = Each WayPoints
												If w\door=Null And Rand(5)=1 Then
													x = Abs(EntityX(Collider)-EntityX(w\obj,True))
													If x < 25.0 And x > 15.0 Then
														z = Abs(EntityZ(Collider)-EntityZ(w\obj,True))
														If z < 25 And z > 15.0 Then
															DebugLog "MOVING 173 TO "+w\room\roomtemplate\name
															PositionEntity n\Collider, EntityX(w\obj,True), EntityY(w\obj,True)+0.25,EntityZ(w\obj,True)
															ResetEntity n\Collider
															Exit
														EndIf
													EndIf
														
												EndIf
											Next
										EndIf
									EndIf
								ElseIf dist > HideDistance*0.8 ;3-6 rooms away from the player -> move randomly from waypoint to another
									If Rand(70)=1 Then TeleportCloser(n)
								Else ;less than 3 rooms away -> actively move towards the player
									n\State = CurveValue(SoundVol, n\State, 3)
I won't walk you through it, because my job here isn't to teach you how to code, but how to compile CB from source and get it working there. Blitz Basic is basically an esoteric language by this point (a language made as a joke or to test boundaries) and the best thing to do to learn it is to mess around with it and see how things work.

With the technical specs of CB out of the way, we can move on to the meat:

Prerequisites
To get Containment Breach working, you can't use the default game download, which doesn't include the source code. To do that, you'll need to download the source code from GitHub. Unzip the folder "scpcb-master" in a place of your choice; this will be your working directory to house the source code for the game and where you'll be keeping the changes to the game.

But wait, the source code alone isn't enough. You also need to download and install the game engine, Blitz3D, to compile the game. This isn't even enough on its own; we'll need to actually modify the engine itself in a little while in order to get the game working, but, for now, you're fine.

If you're interested in mapping, https://github.com/juanjp600/sledge/archive/rmesh.zip, and you'll need to compile it yourself. The program used to make Containment Breach's original rooms, called 3D World Builder, is no longer available. On top of that, even if you can find a download for it, it fails to run on anything above Windows 7, crashing whenever you try to open any file. Sledge itself is an alternative to the Hammer editor for Goldsource games like the original Half-Life and Counter-Strike. This particular variant has been heavily hacked to open and work with Containment Breach's map files, but it has a limitation too: once you export a file, you cannot edit that file anymore. You need to hold onto the original one and export it every time. I'll cover compiling Sledge in a later section.

So, that *SHOULD* be all you need to work with CB's files. Now we'll move onto the juicy bit: compiling the source.

Compiling CB's Source
For the sake of brevity, I'm going to put this in a bulleted format.
  1. Find where Blitz3D is installed. For me, it's "C:/Program Files (x86)/Blitz3D". Open that directory.
  2. Open up the source code directly for Containment Breach.
  3. We're going to replace two things in Blitz3D. First, find the file called "mavless_bin.zip" in CB, and open it. Extract the "bin" folder into Blitz3D's root directly. Hit Yes to replace everything when it asks you to.
  4. Now, open the "userlibs" folder in Blitz3D, and go back to the source for CB. Find every file that ends with ".decls" - these are declarations for things that Containment Breach uses. Select all of them, and copy them into the "userlibs" folder for Blitz3D.
  5. With Blitz3D installed, double-click the file "Main.bb" in CB's source code.
  6. Click the Program tab, and click Create Executable. Name it whatever you want and save it in the source code directory.
If you've done everything correctly, Blitz3D will work its outdated magic and create an executable of the game for you. If you don't get any errors, congratulations! You just compiled the source code for Containment Breach!

Editing the Code
Everything other than maps, textures, models, and sounds in CB is handled through its code. For most things, you'll want to edit the code directly. Because Blitz3D's editor is terrible, I HIGHLY recommend that you install Notepad++ and edit it there instead. It's much faster, flexible, and robust than the built-in editor, and it doesn't seem to have any issues. You'll still need to compile Main.bb from the Blitz editor, but your text editor of choice should be used to make all changes.

Editing the code is as simple as finding what you want to change and modifying some values. If you're lost on how, read the code around it. Do some heavy copy-pasting and changing the values, and try to get it to work!

Locations for some common things you might want to change:
  • SCP-914 outputs: Main.bb, starting at line 9411.
  • SCP-173 AI: NPCs.bb, starting at line 682. (heh)
  • Item spawns in rooms: MapSystem.bb. Try looking around.

Common Errors
Problem: Function "fsound_init" not found
Solution: You didn't install the .decls correctly in Blitz3D. Read step 4 of the compiling guide. If it doesn't work, restart your computer and try again.

Problem: Function "texturebumpenvmat" not found
Solution: You didn't replace Blitz3D's bin files. Read step 3 of the compiling guide, and try again.

Problem: Expecting ")"
Solution: You're trying to compile from a file other than Main.bb. You can only compile the game from Main.bb.

Using Sledge
If for whatever insane reason you want to try mapping, you'll need the source code for Sledge (mentioned earlier) and you'll need to compile it manually. In order to do that, you'll need to download Visual Studio Community. I use 2015, but 2017 should work too. Once you have it installed, open up the file "Sledge.sln" and wait. It'll look intimidating, but what you need to do is simple. In the Solution Explorer, where the files are listed, look for the C# symbol that says "Sledge.Editor", right-click it, and hit Build. If you see something like "X successful, 0 failed, 0 up-to-date, 0 skilled" then you've done it right.

From there, go to the Sledge.Editor folder, click on bin/Debug, and find Sledge.Editor.exe. There's the main editor and it's how you'll do stuff. The interface is fairly standard, but it has a learning curve. If you want to edit files, you open them; when you're ready to export them, then click the Run button. Usually, this would run the scene, but it's been hacked to export the map as a file that's compatible with Containment Breach. If all's done well, you'll have an rmesh file that you can put into your directory. If you want to move around the map, use WASD to move your camera, and arrow keys to rotate it.

There's a caveat, though. Most of CB's rooms don't actually have the editable variants anymore. Sledge has been tweaked to accept the ".3dw" file, which was how the maps were created, but most of these files don't actually exist publicly, or haven't been shared. I'll update this section if this changes, but for the time being, you have no access to almost all vanilla rooms. If you want to change them, you need to recreate them completely. From scratch.

Oh, and by the way, make sure to click Tools -> Options -> Directories, and set your Textures directory to "cb source folder/GFX/Map" and the Models directory to "cb source folder/GFX/Map/Props".

See why I warned you?

Closing Thoughts
First of all, this entire effort wouldn't have been possible without juanjp600, who's the sole reason that CB is even moddable at all in this day and age. You're the man, dude.

Secondly: don't expect anything you make to get a lot of public attention. CB still has a community, but very simple edits will attract very little attention from most people. If you want to mod CB, make sure that it's actually worthwhile, or just a personal project (which is what I work on.) The vast majority of CB mods are just meme mods that are lazy texture and sound edits, and if you're just making mods to do that, then don't expect thousands of hits.

And finally: thanks for trying to keep this game fresh. The community is small, but dedicated, and there are still people that play the game to this day and have insane dedication to it.. Making a serious effort to change it up is a welcome thing.

Thank you for reading. If you need any kind of help, I *highly* recommend that you join the Undertow Games discord server , which is by far the best place to get help from people who know much more than I do. If you're lost, go to #scpcb-development and ask around. They'll hook you up,
cron