# L4D2 Combustable Lemons Tutorial.

Inspired by Cave Johnson’s rants about combustable lemons from Portal2, I thought it would be kinda funny to make some for L4D2. It was! (is?)

You can grab the finished article here:
I worked this out as I went, and avoided as much as possible using Maya/Max or any other large modelling program, so if anyone’s got better advice for some sections than hammering everything with a hex editor, I’m all ears!

## Outline:

-Extract the models/textures from the package.
-Hex the .mdl to resolve inconsistencies.
-Decompile the .mdl.
-Edit the model properties.
-Edit the models.
-Recompile the models.
-Edit the textures.
-Profit.

### Tools You Will need:

You’ll need a couple of tools and dirty hacks to get some of these older tools to decompile stuff.. but thankfully, the SDK tools will happily recompile older stuff without fiddling with the contents!
Nem’s GCFScape
http://nemesis.thewavelength.net/index.php?p=26
-To extract .VPK files, and other packages
Nem’s VTF Plug=In for photoshop:
http://nemesis.thewavelength.net/index.php?c=154
-This is for altering the textures.
Hex Workshop:
http://www.hexworkshop.com/
-The demo should be fine.
Source SDK
-grab this via Steam
-grab this via Steam
MilkShape 3D:
-Freeware model editor (For HL2 SMD files)
MDLDecompiler / StudioCompiler:
http://www.chaosincarnate.net/cannonfodder/cftools.htm
Don’t worry if you’ve not used them before, I’ll try to provide a brief description of each along the way, and account for various errors you might encounter.

### Step 1 – Read this explantion.

What we’ll be doing is replacing the gas can model from L4D1/2 with a lemon model, altering the textures, and maybe a couple of the material properties. We’ll then package this in an addon, et voila, combustable lemons.
You could do the same for fireworks or whatever (wish I had, they’re much prettier), but let’s stick with the gas can at the moment.
Start by making these folders:
c:\combustable_lemon_original\
c:\combustable_lemon_mod\
c:\combustable_lemon_temp\
We’ll use these while making the mod to hold the extracted files, the mod, and temporary files we’re working on.

### Step 2 – Extracting the model.

Fire up GCFScape, and load the file:
Now navigate to /Models/Props_Junk/ and scroll down to Gascan001*….
Extract gasCan001a.dx90.vtx, gasCan001a.mdl,  gasCan001a.phy,  gascan001a.vtx and gasCan001a.vvd.
to   c:\combustible_lemon_original\models\props_junk\…
That way we’ll have a backup with the original folder structure.
It is important that we remember to use  \models\props_junk\ in the final addon.
Now, still inside GCFScape, goto the   /materials/models/props_junk/ folder, and scroll down to phys_objects02a…
Extract  phys_objects02a.vmt, phys_objects021.vtf, and phys_objects02a_normal.vtf
to c:\combustable_lemon_original\materials\models\props_junk\…
From now on, we have a permanent copy of the model files for gas can, incase we need to go back, and more importantly to work on.

### Step 3 – Let’s decompile the model.

Now over at http://www.chaosincarnate.net/cannonfodder/cftools.htm, there are two tools for decompiling the model.  MDLDecompiler, and StudioCompiler.
Although StudioCompiler is newer, and combines a few tools, sometimes the older MDLDecompiler works a little better. Chances are you’ll have to use a combination of the two if you’re working with a lot of models.
I know for sure that at the time of writing, MDLDecompiler works on *this* particular model, so we’ll use that.
Error:  “The procedure entry point Q_AppendSlash…
Now, chances are MDLDecompiler will say something along the lines of “The procedure entry point Q_AppendSlash could not be located in the dynamic link library vstdlib.dll”
I’ve seen many workarounds for this, but the solution is to pair it up with a HL2 Episode 1 binary folder,  I.E. drop it into this folder, and use it there:
C:\Program Files\Steam\steamapps\sicklebrick\sourcesdk\bin\ep1\bin.
If you don’t have this folder, you can grab the Source SDK in the Steam Tools tab
So dump mdldecompiler.exe in there, and try running it. Joy? Hope so. At this point i’d make a shortcut so it doesn’t take 5 minutes to find the bloody thing..
Anyway, open it up and  Choose Model File:  C:\combustable_lemon_original\models\props_junk\gascan001a.mdl
Choose Output Directory:  c:\combustable_lemon_temp\
If you get a “Unable to load model” then we’ll have to do a quick fix on your .mdl file.
open C:\combustable_lemon_original\models\props_junk\gascan001a.mdl  in hex works or whatever
hex editor you prefer, and look at the header:
49 44 53 54 31 00 00 00  IDST1
You’ll want to change this to :
49 44 53 54 2C 00 00 00  IDST,
That’s right, we changed the 1 to a comma, changing the version number from 0x31 to the older 0x2C.
Don’t worry if you don’t understand this part. Just save the file, and close your hex editor.
Now open mdldecompiler again, and try the export with the settings from before:
No Reference Decompiler.
Well, that file doesn’t exist. Guess it would be tricky to decompile it.
MDLDecompiler’s looking for a DirectX8 file, and we only have DirectX9,
just make a copy of gascan001a.dx90.vtx  and rename it to  gascan001a.dx80.vtx
Error:  opening c:\combustable_lemon_temp\gascan001a_reference.smd
You forgot to make the c:\combustable_lemon_temp\ folder. Do so.
Error:
I hit enter and there’s nothing in the folder.
Yeah, for some reason, the “Exit” button is default. Push “Extract” with the mouse.
No Error? “Completed Dumping Model”?
Congrats, you made it through the minefield. So go look in your c:\combustable_lemon_temp\ folder…
In the folder, you’ll see mostly .smd files, and a .qc file. The .smd files are the models we’re going to edit, and the .QC file (Quake C script) is the settings file.

### Step 3 – Altering the model’s properties

Open the .QC file in notepad and take a wee look. The lines we’re interested in are:
$surfaceprop “metal” (near middle) and$mass 20.0
$rotdamping 1.00 (very bottom) change them to something like$surfaceprop “metal_bouncey”
$mass 5.0$rotdamping 0.50
While you’re in there, delete these sections:
$lod 20 { replacemodel “gascan001a_reference” “lod1_gascan001a_reference” }$lod 30
{
replacemodel “gascan001a_reference” “lod2_gascan001a_reference”
}
LOD is the Level Of Detail, meaning that at a distance, the model is replaced with a much less detailed version of the same thing. For us it’s just a nuissance, since we’d have to make 3 lemons, of differing details. Bleh! (Alternatively, when we’re saving the model later, replace the lod1_gascan001a_reference, and lod2_gascan001a_reference files with a copy of your altered gascan001a_reference.smd file)
Save up and continue.

### Step 4 – Altering the model itsself:

Pop open MilkShape 3D, and go
File -> Import -> Half-Life SMD, and open c:\combustable_lemon_temp\gascan001a_reference.smd
The texture isn’t going to work, as it’s not present, you can work around this yourself by making a .BMP copy of the .VTF file in the materials folder, but to be honest, it’s not important.
If you’re serious about doing this bit, then exporting to a wavefront .OBJ  and using a more comprehensive modelling program is yer best bet, it’s a much more widely documented and supported format, and you’ll likely have more joy with the normals, and bone joints. If you’re not comfortable with that, fiddle around with the existing model. If not, let’s hope you have some experience with vertex editing, ’cause we’re gonna haul the guts out of this thing down to a few vertices, make a cube, subdivide it, split it into sections, and round it out till it looks lemoney.
Look at the ‘Groups’ tab on the right you should see that the model belongs to an existing group, and if you look at the joints tab (farther right) you’ll see the ValveBiped.weapon_bone which  shows where the character holds the weapon (and as such which vertices are joined).
If you decide to wipe the existing model and say, spawn a new sphere, remember to re-group it, and re-join the weapon bone, so the character can actually carry it.
Right click on a viewport and make sure “draw backfaces” is not checked. Since polygons should only be viewable from one side, this will let you see if there are any holes in the object. So for example, one polygon might be facing entirely the wrong way, making it invisible.  Flipping these is called “Flipping the normals”.
To flip in milkshape, use the face tool, select a face, and try “Face to Font” or “Turn Edge”.
Though honestly, I’ve had more luck just bashing on and smoothing the thing, which often does it automatically. Anyway, you should now have something lemony shaped.
Note:
You can go file-save as-> and save as a .MS3D file at any point. It will still be safe enough to export back out as a .SMD at a later date!
Right, that you got a lemon?
File -> Export -> Half-Life SMD .
Remember to hit the “With Vertex Weights (HL2)” box!
Do the same thing with phymodel.smd.
This is the shape the physics engine will use here. So obviously, it can be roughly the same size, but much less detailed than the actual model.

### Step 5 – Compiling the model!

(Left 4 Dead Authoring Tools on steam)
Hope so, ’cause you’re going to need one part to compile with!
In your combustable lemon temp folder, make a new text file, let’s call it say…”compile.txt”, then rename it to “compile.bat”, right clicky and edit in notepad.
Paste in the following:
pause
Run the .bat file then, and wait for any errors.
If studiomdl (the compiler) complains about not being able to find anything, check your .QC file, the first line should read :
\$cd “C:\combustable_lemon_temp”
Or whichever folder you decided to use.
Where did the files go?
Have a wee look in:
You should now have your shiney new copies of: gascan001a.dx90.vtx, gascan001a.mdl, gascan001a.phy and gascan001a.vvd !
Here’s the thing with Left4Dead2, you can’t just place stuff in the addons folder without compressing it to test first, and you can’t just place it in the /models/ folder to override anymore either.  So let’s copy these files into
C:\combustable_lemon_mod\models\props_junk\

### Step 6 – The texture.

Since we can’t test the model without packing it, it makes sense just to do the textures now.
Install photoshop 6, and Nem’s VTF plug-in for photoshop.
Don’t worry, PS6 isn’t quite the behemoth of CS1,2,3,4,5. It does basically everything you’d expect of CS5, but remarkably, it’s only 60mb versus 1 gigabyte.
So copy the materials from
C:\combustable_lemon_original\materials\models\props_junk
over to
C:\combustable_lemon_mod\materials\models\props_junk
Start by importing phys_objects02a.vtf into photoshop.
(just drag it into the main window)
Hit B to get the brush tool, “]” to get a nice big size, and select a lemoney color.
That’s pretty much it. Lemons are yellowey. Doesn’t really matter about the UV mapping, since, well.. it’s all yellow anyway. Save the file and exit.
Secondly, open the phys_objects02a_normal.vtf file, and this time, set the color to the same color as the blank parts. Hit “I” to get the dropper tool, select the color, and then color it with the brush tool again. Save the file.
Almost done, let’s make it into an addon.

### Step 7 – Creating the addon info file.

Create a text file:
Paste the following in. (Thank you templates!)
{
addonContent_BackgroundMovie 0 //Provides a replacement for the background movie.
addonContent_Survivor 0 //Provides a new survivor model. 0=false, 1=true, String in quotes if replaces specific single character, i.e. “Francis”
addonContent_BossInfected 0 //Provides a new boss infected model. Break these out?
addonContent_CommonInfected 0 //Provides a new common infected model
addonContent_WeaponModel 1 //Provides a new appearance to existing weapons, but does not change their function
addonContent_weapon 1   //provides new weapons or new zombie killing functionality, i.e. guns, explosives, booby traps, hot tar,
addonContent_Skin 1   //0 if no new skin textures for existing models. 1 if multiple skin pack. String in quotes if specific single skin
}
You can trim this as you see fit, but I left some stuff here and there as an example.
Save up, and proceed to the last step!

### Step 8 – Compile

Open the folder:
Now drag your combustable_lemon_mod folder onto the file “VPK.exe” (you won’t have this if you forgot to download the authoring tools, see above).
Check yer C: drive, and there should be a file “combustable_lemon_mod.vpk”
Quick, quick, drop that into:
And start the game!

### Spawning the lemons ingame:

To extract an existing vpk, drak that onto VPK.exe and it will be unpacked in the same folder.
To spawn a gascan really quickly, hit the tilde (~) key, and do:
sv_cheats 1
give weapon_gascan
or
prop_physics_create props_junk/gascan001a.mdl
If you do for example
bind “h” “give weapon_gacan”
you can tap H repeatedly, and spawn loads of bouncy cans =)
To use multiplayer:
Using sv_cheats via a server you created on the lobby will not work.
Instead, the host types the map name, i.e.
map c2m1_highway
Then sets
sv_consistency 0       (if the game asks for it)
and
sv_cheats 1          (if you wanna allow cheats)
Other player connect by doing:
“connect 97.102.34.40”
where “97.102.34.40” is of course the host’s IP address.