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

Discussion in 'Tutorials & Resources' started by Psy, Aug 20, 2009.

  1. Psy

    aa Psy The Imp Queen

    Messages:
    1,705
    Positive Ratings:
    1,464
    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.

    [​IMG]

    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.

    [​IMG]

    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.

    [​IMG]

    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.

    [​IMG]

    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.

    [​IMG]


    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.

    [​IMG]

    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.

    [​IMG]

    Save and open up GUIStudioMDL.


    Step 4: Recompile the model

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

    [​IMG]

    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.

    [​IMG]

    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.

    [​IMG]

    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'.

    [​IMG]

    Ta-da! It's complete and by ticking the 'Physics Model' checkbox we can tell that even the collision model is there!
     
    • Thanks Thanks x 29
    Last edited: Aug 25, 2009
  2. Owlruler

    Owlruler L12: Fabulous Member

    Messages:
    964
    Positive Ratings:
    271
    Thanks!
     
  3. Mick-a-nator

    aa Mick-a-nator

    Messages:
    640
    Positive Ratings:
    314
    Cheers, I think I'll be needing this soon.
     
  4. Mick-a-nator

    aa Mick-a-nator

    Messages:
    640
    Positive Ratings:
    314
    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.
     
    • Thanks Thanks x 3
    Last edited: Aug 20, 2009
  5. Psy

    aa Psy The Imp Queen

    Messages:
    1,705
    Positive Ratings:
    1,464
    Thanks. I've updated the post to reflect where MDLDecompiler should really go. :)
     
  6. The Political Gamer

    aa The Political Gamer

    Messages:
    4,468
    Positive Ratings:
    1,680
  7. Micnax

    aa Micnax L0: Terribly Lazy Mapper

    Messages:
    1,947
    Positive Ratings:
    1,214
    How would you go about giving a model another skin?
     
  8. A Boojum Snark

    aa A Boojum Snark Toraipoddodezain Mazahabado

    Messages:
    4,769
    Positive Ratings:
    5,498
    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++
     
  9. Psy

    aa Psy The Imp Queen

    Messages:
    1,705
    Positive Ratings:
    1,464
    Point to the where the new texture is under $cdmaterials.
     
  10. Rexy

    aa Rexy The Kwisatz Haderach

    Messages:
    1,795
    Positive Ratings:
    2,355
    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.
     
  11. Micnax

    aa Micnax L0: Terribly Lazy Mapper

    Messages:
    1,947
    Positive Ratings:
    1,214
    Where do you get the model's textures in the first place? :p
     
  12. Terr

    aa Terr Cranky Coder

    Messages:
    1,591
    Positive Ratings:
    405
    Great timing, there's a certain banister I've been meaning to try to shorten in Blender :)
     
    Last edited: Aug 20, 2009
  13. Psy

    aa Psy The Imp Queen

    Messages:
    1,705
    Positive Ratings:
    1,464
    GCFScape search for the name of the model when inside the 'materials\models' folder.
     
  14. Mick-a-nator

    aa Mick-a-nator

    Messages:
    640
    Positive Ratings:
    314
    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
     
    • Thanks Thanks x 2
    Last edited: Aug 20, 2009
  15. Acumen

    aa Acumen Annoyer

    Messages:
    704
    Positive Ratings:
    593
    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: Aug 21, 2009
  16. Galago

    Galago L2: Junior Member

    Messages:
    90
    Positive Ratings:
    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?
     
  17. Acumen

    aa Acumen Annoyer

    Messages:
    704
    Positive Ratings:
    593
    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 ?
     
    • Thanks Thanks x 1
  18. Galago

    Galago L2: Junior Member

    Messages:
    90
    Positive Ratings:
    5
    I suppose I could wait, but this project needs to be completed rather soon. Also, I suck at rigging.
     
  19. Mick-a-nator

    aa Mick-a-nator

    Messages:
    640
    Positive Ratings:
    314
    hi, me again :p

    what do I do with "ERROR: cannot find bone static_prop for bbox" ?
     
  20. Psy

    aa Psy The Imp Queen

    Messages:
    1,705
    Positive Ratings:
    1,464
    Does the model still work?