Generic compiling/decompiling

A Tutorial for Source Engine

“ A well rounded and balanced tutorial covering all the basics that one needs to start compiling and decompiling models. It is well presented and formatted, easy to follow and understand, with some nice tips at the end and could serve as a starting point for anyone showing interest in modeling for the Source engine. ”

Updates

Markups
  • Changed some stuff to markup
  • Righted some wrongs
  • guide on making $modelname better
Even more readable by changing the `'` to code characters. The SDK is now in the `common` folder. Explaining how `$modelname` can be aimed a little better so less fussing.
Devieus avatar
Devieus username pic Joined 8y ago
Moderator
ONLINE
84,520 points Ranked 43rd
69 medals 6 legendary 12 rare
  • 1st Place - Tutorial Contest Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2015 Medal icon
  • Returned 5000 times Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
  • 2017 Top Contributor Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2017 Medal icon
Devieus avatar
Devieus
4y
Crowbar
  • Added crowbar info
Crowbar is a new compiling/decompiling tool.
Devieus avatar
Devieus username pic Joined 8y ago
Moderator
ONLINE
84,520 points Ranked 43rd
69 medals 6 legendary 12 rare
  • 1st Place - Tutorial Contest Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2015 Medal icon
  • Returned 5000 times Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
  • 2017 Top Contributor Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2017 Medal icon
Devieus avatar
Devieus
5y

For source engine in general, for reference

Index

Decompiling

  1. Getting the models
  2. Setting up Crowbar
  3. Extraction
  4. Recompiling

  5. Batch script
  6. Crowbar
  7. Blender
  8. WallWorm
  9. Miscelaneous

  10. VPK and steampipe
  11. Common QC commands
  12. Common Errors




Decompiling

Requirements


Part 1: Getting models

Decompiling a model isn't hard, but to start off, you'll need to files to decompile first, if you've downloaded a model replacement mod and they're not in a VPK, you'll already have these files, and you don't need GCFScape (see next paragraph), otherwise you'll need to know the locations of the GCF or VPK archives.

If you've downloaded a mod, you can look through the files of the archive until you'll stumble upon a set of files with the extensions .mdl, .vvd, .sw.vtx, .dx80.vtx, dx90.vtx and .phy. Several of these are required to decompile a model, for the sake of simplicity it's safe to say it's easier to just use them all (if you're missing .dx80.vtx, copy .dx90.vtx and rename the extension appropriately). Unpack them to someplace easy to find if they're still trapped in their archive. Take note of their location (i.e. keep the folder open) afterwards, you're going to need it for step 2.

If you don't have the models, which is the case for editing default models, open the VPK/GCF archive with GCFScape.VPK archives are in common\\[game]\\[game abbreviation], you'll want to open pak01_dir.vpk or \\[game abbreviation]_pak_dir.vpk most of the time, the others are usually seemingly empty. The GCF archives are in your steamapps folder, if you can't find a models folder, try a different archive, if you can't find what you're looking for try thinking outside the box or search the tree systematically;

Select the files with the extensions .mdl, .vvd, .sw.vtx, .dx80.vtx, dx90.vtx and .phy and put them in a folder (preferably a folder on your desktop, but not directly on your desktop, if you don't have .dx80.vtx, copy .dx90.vtx and rename the extension to make it fit), open the folder and open crowbar.

Setting up Crowbar

With the window containing your model files still open somewhere, browse to the folder containing Crowbar and open it. Drag the .mdl file onto the Crowbar window and tick the right boxes. If you're looking to replace a model from scratch, you'll want to have QC file enabled at least as well as Reference mesh SMD file for reference (otherwise applying your model is going to be a lot of guess work). For Counter Strike: Source (and a few other games) you'll also want Bone animation SMD files, which contains the animations needed that you can either replace with your own (in which case it serves as reference timelines), or keep intact to preview animations.

You could also untick QC file if all you want is the .smd files for use in other mods.

Extraction

Click decompile. If everything's going alright, it should work without a hitch and you now have decompiled model files, along with a .qc file, and some animation(s) file(s) and a physmodel SMD, whatever you told Crowbar to give you; check the destination folder if that really is the case.




Recompiling

Batch script compiler

My preferred way that's nice and fast is through the use of a .bat file, or a Windows batch script. Open notepad (or something alike) and paste this in it:

"C:\\Program Files (x86)\\Steam\\steamapps\\common\\\\[game]\\bin\\studiomdl.exe" -game "C:\\Program Files (x86)\\Steam\\steamapps\\\\[name]\\\\[game]\\\\[game abbreviation]" %1

pause
Alternatively for older games:

"C:\\Program Files (x86)\\Steam\\steamapps\\common\\sourceSDK\\bin\\orangebox\\bin\\studiomdl.exe" -game "C:\\Program Files (x86)\\Steam\\steamapps\\common\\\\[game]\\\\[game abbreviation]" %1
pause

To use this properly, replace \\[game] and \\[game abbreviation] with the proper names, if you're on a 32-bit windows machine, remove the (x86) bit; if you installed Steam elsewhere, go ahead and change that too. Then pause statement makes the script wait for input before ending execution, which is useful for finding errors if you have them. After you've saved in the same folder as your mdldecompiler.qc as compiler.bat or something, simply double-click it and let the magic happen. After you're done with it, you can put it in a different folder where you can use it again for quick recycling.

The %1 part means you can drop your .qc file onto your .bat and it'll take it as argument, alternatively you can rename that bit to match your .qc, in case you want to compile a batch of .qc files. Also make sure it's for the right engine, as it is now it'll use the game's tools, so if you're getting jiggy with an older mod, use ep1 instead, use source2006 for BMS, you can get these by downloading the proper SDK Base from the tools section of your library.

Crowbar


To decompile with Crowbar, drag the .qc file into the window or onto crowbar.exe. you'll probably have to set up your games first, in the boxes you see after choosing setup games, you need to put the paths to gameinfo.txt in the first one and to studiomdl.exe in the second, these are usually in C:\\Program Files (x86)\\Steam\\steamapps\\common\\[game name]\\[game abbreviation]\\ganeinfo.txt and C:\\Program Files (x86)\\Steam\\steamapps\\common\\[game name]\\bin\\studiomdl.exe respectively.

Blender


The 3D model editor program Blender, along with the proper plug-ins, can also compile any model directly, which is useful for making fine adjustments to the model directly when something wrong's been spotted in the model viewer and it's become a bit of a nuisance to keep feeding the .bat file. First you enter an Engine Path, which is C:\\Program Files (x86)\\Steam\\steamapps\\common\\[game name]\\bin, in the event of mods, that game name is SourceSDK\\bin\\[mod engine], in the end it should point to the folder containing a studiomdl.exe or resourcecompiler.exe for Source 2. After that you have to give it a game to compile for, for base games this path is usually C:\\Program Files (x86)\\Steam\\steamapps\\common\\[game name]\\[game abbreviation], which is the directory containing a gameinfo.txt file; for mods this is instead in C:\\Program Files (x86)\\Steam\\steamapps\\sourcemods\\[game name]\\[game abbreviation].

Now it's time to feed a QC file, which can be relative to the .blend, then you can compile. it's more of a front-end, which means you'll have to export the model yourself every time before change can be noticed, but this button is just a few pixels away.

Wallworm for 3DSMax


for 3DSMax users, there's WallWorm, a nifty tool that will compile your model without having to do much of anything except having the model itself; it creates a QC file and the textures for you.




Miscelaneous

VPK and steampipe

You can turn your mod into an add-on by turning the folder you so aptly named something sensible into a .vpk archive of its own, this can be done by simply dropping that folder onto vpk.exe, this program is in \\[game name]\\bin, after which you can safely delete the folder. The process can also be done in reverse to get the folder back without having to open it with GCFScape

Common QC commands

  • $modelname: the name of the model itself, starts relative to root/models and must end with .mdl (remember that the custom folder in your custom folder is also a root).
    • A neat trick will make you compile directly in a custom folder where applicable, namely by prepending the path with ..\\custom\\[mod folder name]\\models; the .. bit tells the compiler "Go up a folder", which is root, from there it goes into the custom folder.
  • $model/$body: the name of the mesh and the .smd that contains it in that order; models with facial animations require $model, for $staticprop models $body is recommended.
  • $cd: changes the directory where the .smd files are, one is usually given during decompile, but if you place the .qc in the same folder as all source files, this can and should be removed.
  • $cdmaterials: the directory where the .vmt files are to be found by the model, starts relative to root\\materials and shouldn't contain the actual material name as those are already stored in the .smd files themselves; more can be added if need be.
  • $sequence/$animation: animations your mesh might have, every model needs at least one. $animation is more extended, though they can be used in conjunction.
  • $collisionmodel: contains the collision data, a simplified mesh that represents the boundaries of where the model can touch the world/another prop. Can contain several options enclosed in curly-brackets, the most common of which is $concave and $mass, which are used for models with holes and props that can be pushed respectively.
  • $texturegroup: for models with multiple skins, most extensively used in Team Fortress 2 for team coloring (tutorial here), but can be used for any prop that'll have a different look and even for replacing a model by hiding one mesh and showing another.

Common errors

leaked model

This happens when the QC points to a file that doesn't exist. Either the file has the wrong name or is a different folder entirely

bbox set error

This means the mdldecompiler.qc file came across a $hbox statement that doesn't comply with the model, namely the bone it's referring to doesn't exist in the model. To fix it, simply remove the offending line, the compiler usually states which bone to pick.

animations

Animations can be completely broken on default v_model weapons during decompile and sometimes there's not much you can do about the animations themselves to make a quick fix, but there is a possibility that there is.

Open the offending animation with your favorite plain-text editor and look for values at around 1000 or above (or -1000 and below), take note of the bone number that's affected (the first number of the line, it's usually the root bone causing this) and look for another line with nominal numbers (usually around 0) at the same bone, if you can't find any, use a different animation file, if you can't find any in those, it's probably faster to simply ignore the animations and remove them, you won't be needing them for the next best thing.

The next best thing is to edit the mdldecompile.qc file to make use of the original animations, this theoretically gives better results than the method above, but will clutter your folders with dependency files. If you haven't already, open the mdldecompiler.qc file, remove every line mentioning $sequence and $animation with extreme prejudice and put in their stead the following:

$includemodel "path\\to\\model\\x_weaponname_anims.mdl"

Change the path to where you want it to be, it's usually best to make this the same as where you put your end result, change the name to something sensible, such as what you put in $modelname with _anims after it.

To make this work you'll need to do some more stuff after compiling, namely get a copy of the .mdl file you decompiled (i.e. has the animations), append the name of the file with _anims and put it in the same folder as your final .mdl. it's important to note this can be done after compiling since $includemodel doesn't actually include the model during compiling but rather make a dependency on that file existing.

For CS:S (and maybe some others too) it could happen your gun will be invisible when doing this, it's not actually gone, just rotated. To fix this, add a rotate 90 statement in every $sequence anywhere after the .smd; if that still doesn't work try -90 instead.

Access Violations

This could literally be anything, but it's always something in your QC file; try removing lines one by one to see which one is the cause.

Q_AppendSlash cannot be found in vstdlib.dll

Install your decompiler properly, read the readme, if your decompiler isn't in sourcesdk\\bin\\ep1\\bin, try putting it there; if that doesn't work, launch the SDK.

Black and magenta checkered models

This isn't really in the scope of de/recompiling, but basically it means your model can't find the right .vmt(s), or the .vmt can't find the .vtf file(s). The former can be caused by having incorrect material names on the .smd, or an incorrect $cdmaterials that doesn't point in exactly the right direction. The latter is the same, but in the .vmt instead.

Posts

1-10 of 23
1
Pages
Go to page:
  • Reverend V92 avatar
    Reverend V92 username pic Joined 8y ago
    Away
    3,488 points Ranked 1446th
    22 medals 3 rare
    • 2nd Place - A Bananite's Guide to... Contest Medal icon
    • 6 years a member Medal icon
    • Returned 1000 times Medal icon
    • Building Bridges Entrant Medal icon
    • Became a Studio Leader Medal icon
    • Reached 1,000 Points Medal icon
    9moEdited 9mo
    I'd recommend ditching the entire sections on CannonFodder's decompiler and GUIStudioMDL and replacing it with Crowbar, as it makes most of those issues with decompiling and compiling a thing of the past.
    • Interesting x 1
    Source Engine Wizard avatar
    Mantra
    Source Engine Wizard
  • also, these programs are broken
    • Disagree x 1
    I Hate My Life.
  • Doctor Twilight avatar
    Doctor Twilight Joined 1y ago
    Safe
    144 points Ranked 24353rd
    9moEdited 9mo
  • Devieus avatar
    Devieus username pic Joined 8y ago
    Moderator
    ONLINE
    84,520 points Ranked 43rd
    69 medals 6 legendary 12 rare
    • 1st Place - Tutorial Contest Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2015 Medal icon
    • Returned 5000 times Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
    • 2017 Top Contributor Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2017 Medal icon
    2y
    Posted by E.Lopez

    Please add an update :

    If anyone have this error in Crowbar : ERROR: Model version -1692393424 not currently supported 

    You should modificated the .mdl file with Notepad++ ( no windows notepad ) . Replace the     IDST0      to    IDST,
    That error shouldn't exist since Cannonfodder's version. I've decompiled models with IDST0 with crowbar before just fine. What model are you having this problem with?
    Sentinel of the TV remote avatar
    Mantra
    Sentinel of the TV remote
  • E.Lopez avatar
    E.Lopez Joined 7y ago
    Offline
    776 points Ranked 6482nd
    6 medals 1 rare
    • 6 years a member Medal icon
    • One month a member Medal icon
    • 6 months a member Medal icon
    • 1 year a member Medal icon
    • 2 years a member Medal icon
    • 4 years a member Medal icon
    2y
    Please add an update :

    If anyone have this error in Crowbar : ERROR: Model version -1692393424 not currently supported 

    You should modificated the .mdl file with Notepad++ ( no windows notepad ) . Replace the     IDST0      to    IDST,
    We...
  • Devieus avatar
    Devieus username pic Joined 8y ago
    Moderator
    ONLINE
    84,520 points Ranked 43rd
    69 medals 6 legendary 12 rare
    • 1st Place - Tutorial Contest Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2015 Medal icon
    • Returned 5000 times Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
    • 2017 Top Contributor Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2017 Medal icon
    5y
    > **Posted by #trigger_hurt** > > **Posted by Devieus** > > > > **Posted by #trigger_hurt** > > > > > I'm trying to make a team-themed minigun that allows my custom glove colors, but every time I try to re-compile it, the model is invisible. I tried the -anims.mdl thing but that did not work. I also tried rotating it, but no rotations seemed to work. I tried 90, -90, and 180 (basically the only three you can do), but the model is still mostly invisible. Any suggestions? > > > > Is the console giving anything? > > Sorry for the late response, but no, the console gives no warnings or any signs of imperfections. This seems to happen with the medic viewmodels as well (I tried to make a team-themed bonesaw but the same issue occured) > > And also, just a random fact I discovered, despite the fact that the pyro's axe has a c-model that works perfectly (tested in garry's mod using pac3), and on top of that a w-model, it still uses the v-model. I mean seriously... It sounds like you did everything right, but that doesn't mean you actually did just that. I could take a look at the files, see if that'll help.
    Sentinel of the TV remote avatar
    Mantra
    Sentinel of the TV remote
  • #trigger_hurt avatar
    #trigger_hurt Joined 5y ago
    Offline
    5y
    > **Posted by Devieus** > > **Posted by #trigger_hurt** > > > I'm trying to make a team-themed minigun that allows my custom glove colors, but every time I try to re-compile it, the model is invisible. I tried the -anims.mdl thing but that did not work. I also tried rotating it, but no rotations seemed to work. I tried 90, -90, and 180 (basically the only three you can do), but the model is still mostly invisible. Any suggestions? > > Is the console giving anything? Sorry for the late response, but no, the console gives no warnings or any signs of imperfections. This seems to happen with the medic viewmodels as well (I tried to make a team-themed bonesaw but the same issue occured) And also, just a random fact I discovered, despite the fact that the pyro's axe has a c-model that works perfectly (tested in garry's mod using pac3), and on top of that a w-model, it still uses the v-model. I mean seriously...
    professional(?) shitposter
  • Devieus avatar
    Devieus username pic Joined 8y ago
    Moderator
    ONLINE
    84,520 points Ranked 43rd
    69 medals 6 legendary 12 rare
    • 1st Place - Tutorial Contest Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2015 Medal icon
    • Returned 5000 times Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
    • 2017 Top Contributor Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2017 Medal icon
    5y
    > **Posted by #trigger_hurt** > I'm trying to make a team-themed minigun that allows my custom glove colors, but every time I try to re-compile it, the model is invisible. I tried the -anims.mdl thing but that did not work. I also tried rotating it, but no rotations seemed to work. I tried 90, -90, and 180 (basically the only three you can do), but the model is still mostly invisible. Any suggestions? Is the console giving anything?
    Sentinel of the TV remote avatar
    Mantra
    Sentinel of the TV remote
  • #trigger_hurt avatar
    #trigger_hurt Joined 5y ago
    Offline
    5y
    I'm trying to make a team-themed minigun that allows my custom glove colors, but every time I try to re-compile it, the model is invisible. I tried the -anims.mdl thing but that did not work. I also tried rotating it, but no rotations seemed to work. I tried 90, -90, and 180 (basically the only three you can do), but the model is still mostly invisible. Any suggestions?
    professional(?) shitposter
  • Devieus avatar
    Devieus username pic Joined 8y ago
    Moderator
    ONLINE
    84,520 points Ranked 43rd
    69 medals 6 legendary 12 rare
    • 1st Place - Tutorial Contest Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2015 Medal icon
    • Returned 5000 times Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
    • 2017 Top Contributor Medal icon
    • 15+ Entries! GameBanana’s Christmas Giveaway 2017 Medal icon
    5y
    > **Posted by Batnik_Ref.smd** > > You talk in riddles))) That's mostly because your English isn't making clear what exactly your problem is.
    Sentinel of the TV remote avatar
    Mantra
    Sentinel of the TV remote

Embed

Share banner
Image URL:
HTML embed code:
BB embed code:
Markdown embed code:

Credits

Original Authors
Devieus avatar
Devieus username pic Joined 8y ago
Moderator
Offline
84,520 points Ranked 43rd
69 medals 6 legendary 12 rare
  • 1st Place - Tutorial Contest Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2015 Medal icon
  • Returned 5000 times Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
  • 2017 Top Contributor Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2017 Medal icon
Writings

Submitter


Devieus avatar
Devieus username pic Joined 8y ago
Moderator
ONLINE
84,520 points Ranked 43rd
69 medals 6 legendary 12 rare
  • 1st Place - Tutorial Contest Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2015 Medal icon
  • Returned 5000 times Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
  • 2017 Top Contributor Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2017 Medal icon

Creator
Sign up to access this!
Sign up to access this!
Sign up to access this!

Game

Sign up to access this!

Category

Details

Difficulty Level
Beginner Difficulty

Attributes

Share

  • Share on Reddit
  • Share on Twitter
  • Share on Facebook
  • Share on Google+

Stats

  • 18,795 Views
  • 24 Posts
  • 5y Submitted
  • 2mo Modified
  • 4y Updated

Scores

82 bScore
9.5 Rating

4 voters

Sign up to access this!

More from Submitter

WiPs by Submitter

bcp.crwdcntrl.net tracking pixel