[Tutorial] The complete guide to decompiling and recompiling models!

Psy

The Imp Queen
aa
Apr 9, 2008
1,706
1,491
In chat theres always people asking how to reskin models. It's something that's quite difficult to explain in chat due to it being quite a laborious process so here's the complete guide on how to decompile and recompile a model with new skins!

The Process

The process is quite simple. Here's a simple list.

  1. Extract the model
  2. Hex edit it
  3. Decompile it
  4. Edit it's QC
  5. Recompile it
  6. DONE!

So that's the process in it's simplest form.

For this tutorial we will recompile one of the props_mining rocks with a new name. ;)

What you need

Tools


TIP: Place GUIStudioMDL in the 'sourcesdk/bin/orangebox/bin/' folder and MDLDecompiler in the 'sourcesdk/bin/ep1/bin' folder and create shortcuts for both of them on the desktop so they're easier to get to. ;)


Step 1: Extract the model

First off, load up GCFScape then open up 'team fortress 2 content.gcf' which can be found in the 'steam/steamapps/' folder. Then you can navigate to the models using the menu or you could simply search for the model we are looking for. To do this choose Edit > Find then type 'rock001'.

Now you'll have a list of files like so.

gcfscape_1.PNG


You will see a whole bunch of files with the name 'rock001' and all these files are neccesary to successfully recompile it.

Select them all then right-click and choose 'Extract...'/i]. Place them any place you like and that's that! :)


Step 2: Hex edit the model

Cannonfodder's MDLDecompiler was coded for use with EP1 models but models in the Orangebox engine use a different model version which the decompiler cannot understand but - do not fret! - there is a simple way around this which requires the ever useful Notepad++.

Now, open it up then load up 'rock001.mdl' and what you'll get is a lovely bunch of seemingly random characters as shown below.

hex1.PNG


What you need to do is change the 5th character to a comma (,) like so.

TIP: Not all models will have the character '0' for the 5th byte but you still perform the exact same edit.

hex2.PNG


Save up and you're ready to decompile. :D


Step 3: Decompile the model

Open up Cannonfodder's MDLDecompiler and you'll be presented with this.

decompile1.PNG


First of all, make sure you untick 'Use Steam File Access...' else you'll most likely get some error message about it being unable to access a Steam app.

It's fairly straightforward what you have to do. Choose where the model file is (rock001.mdl) and choose where you want the decompiled version to go. Once this is done hit the big magic button labeled 'Extract'.

Upon the completion of this process you should end up with the following files in the folder destination you set earlier.

decompile2.PNG



Step 3: Edit the .QC

Open up Notepad++ if you already haven't and open the 'mdldecompiler.qc' file in the folder with the decompiled files and here's what you should see.

qc1.PNG


If you're not familiar with .QC files then here's a quick run down of the most important properties.

  • $cd this points to the location of the files to decompile
  • $modelname this is the name of the model once it is compiled
  • $model 'body this points to the location of the SMD which is the model itself
  • $cdmaterials this points to the location of the model's texture(s)
  • $sequence this defines the animations of the model and even if is static it will have an 'idle' animation
  • $collisionmodel this points to the collision model obviously
  • $scale this property can be used to scale models up or down. Useful for recompiling props for skybox usage
  • For more commands visit this VDC page.

For this tutorial we are simply going to recompile the model with a different name. To do this simply edit '$modelname' to '$modelname "props_recompiled\rock001_recompile.mdl"'.

Write '$staticprop' so that it is registered as a prop_static and heed this warning...

TIP: Recompiled models with $staticprop are always rotated -270 degrees around the Z axis. To fix this add the property '$origin 0 0 0 270' within the QC.

Now you should (hopefully) have something like this.

qc2.PNG


Save and open up GUIStudioMDL.


Step 4: Recompile the model

First you may notice if you haven't run GUIStudioMDL is this warning.

recompile1.PNG


Do not fear! All you need to do is click 'OK' and when you're in the program go to Config > Set Orange Box Tools Path and point to 'sourcesdk\bin\orangebox\bin' (lots of bin folders as you can see) :p

Once set up, choose the 'Orange Box' radio button and on the left-side you'll see a drop-down list with all the games you own running the Orangebox engine.

recompile2.PNG


Now, click File and open up the file 'mdldecompiler.qc' found in the folder.

Before you compile go to your 'tf/models/' folder (make one if you don't have one) and create the folder 'props_recompiled'.

With that done and out of the way click the magic button labeled 'Compile' and with any luck it shall start to compile the model. You should end up with the final line saying 'Completed "mdldecompiler.qc'.


Step 5: Checking the result!

Pop on over to your 'tf/models/props_recompiled' folder and you should see the following.

result1.PNG


Can it be true? Has it worked? There is only one way to find out. To the Source SDK!

Open up the Model Viewer then load up your new model under 'props_recompiled\rock001_recompile'.

result1.PNG


Ta-da! It's complete and by ticking the 'Physics Model' checkbox we can tell that even the collision model is there!
 
Last edited:

Owlruler

L12: Fabulous Member
Dec 10, 2008
964
275
Thanks!
 
Feb 18, 2009
640
629
Hmmm, I get an error when trying to use MDLdecompiler (its in the right place and is the latest version) which says "The procedure entry point Q_AppendSlash could not be located in the dynamic link library vstdlib.dll." What do I do to fix that?

EDIT: FIXED! just moved MDLCompiler.exe to the ep1 bin folder, try that anyone who also gets this message
NOTE: Putting it in the half-life 2 bin folder doesn't work either, ep1 bin appears to be the only solution.
 
Last edited:

Psy

The Imp Queen
aa
Apr 9, 2008
1,706
1,491
Thanks. I've updated the post to reflect where MDLDecompiler should really go. :)
 

A Boojum Snark

Toraipoddodezain Mazahabado
aa
Nov 2, 2007
4,775
7,669
You can also get syntax highlighting for Source stuff in Notepad++ with this. But the main reason I link to it is the bit at the bottom: you can compile the model directly through N++
 

Rexy

The Kwisatz Haderach
aa
Dec 22, 2008
1,798
2,533
For those of you afraid of hex editing, there's a much more simple process to be had by using Crafty (nem's tools) which will spit out .obj files for your 3D software to read.
 

Terr

Cranky Coder
aa
Jul 31, 2009
1,590
410
Great timing, there's a certain banister I've been meaning to try to shorten in Blender :)
 
Last edited:
Feb 18, 2009
640
629
I'd just like to make a note about Blender and SMDs (don't worry Psy, you haven't missed anything;)). This is probably already somewhere on the site but I thought mentioning it here would be a good idea as it is related.
If Blender users want to use the decompiled models to edit or use as a referance the you will need a script. However, there are 2. The first is everywhere, its called smd_mesh_importer.py when I used it it didn't work and kept throwing up errors in the console. After searching around a bit I found another. You can get it here and it comes with a rather handy texture name finding script that may speed up skin finding. It works wonderfully but can only import static models (*sarcasm* "Oh dear, what a shame, there are soooo many tf2 models with animations, that I MUST have!").
EDIT: One more thing, if you have the bmp of the model's texture in the same folder as the SMD then you can import it textured with that skin (Theoretically, I haven't tried it).
Hope that helps someone.

PS: That was a little long than it was going to be :p
 
Last edited:

Acumen

Annoyer
aa
Jun 11, 2009
704
628
alright, alright, i go and download this notepad++ thing now.
during the past days i felt more and more desparate to browse through some qc-files and always stumbled over the hex-editing process :)
i give in, now !

thanks for this insight tutorial, psy !
 
Last edited:

Galago

L2: Junior Member
Sep 29, 2008
90
5
For a recent project I've needed to decompile the TF2 characters [e.g. Pyro]. I successfully decompiled the model and opened it up in Softimage Mod Tool, but alas, Pyro isn't rigged! What do I do?
 

Acumen

Annoyer
aa
Jun 11, 2009
704
628
i'd suggest you just wait for the official valve character model sdk release that was somewhere announced ^^
otherwise you have to rig it yourself i guess ?
 

Galago

L2: Junior Member
Sep 29, 2008
90
5
i'd suggest you just wait for the official valve character model sdk release that was somewhere announced ^^
otherwise you have to rig it yourself i guess ?

I suppose I could wait, but this project needs to be completed rather soon. Also, I suck at rigging.