Decompiling Dota 2 assets

24 October 2019

NOTE Some things mentioned are a bit out of date, the VRF bugs fixed have been fixed on the official release, see https://github.com/SteamDatabase/ValveResourceFormat

Described here is a method of extracting 3D models from the game Dota 2. The approach offers access to many interesting objects from the game like trees, buildings, effects and equipment.

The technique is called decompiling, which involves downloading the game via Steam and analysing the game files (the game files on a Steam installation are ‘compiled’). With the use of the ValveResourceFormat application described below it is possible to extract and export data from these files and import them into Blender. The technique is limited to educational (or game-modding) purposes since all the game assets belong to Valve. I’ve included a few notes about copyright below.

ValveResourceFormat application (VRF-app)

The program I’m using is an open source application called ValveResourceFormat (VRF-app) that runs on Windows, the project is hosted on Github. It understands various compiled file formats (see the VRF Githhub page for an overview) with ability to browse, visualise and export graphical assets that are suitable for Blender and other high-level graphics applications.

Download the VRF-app here (Windows only): http://cgdmg.com/files/ValveResourceViewer.zip

With Dota 2 installed on Steam you can check the game properties to find the installation directory, the default directory is

C:\Program Files (x86)\Steam\steamapps\common\dota 2 beta\game\dota

There are actually two levels of extraction that are needed to be performed on the raw files. The first is an unpacking step which is handled automatically by the VRF-app. In the game directory there are a series of files named pak01_000.vpk to pak01_163.vpk, and there is a single file called pak01_dir.vpk. The extension VPK stands for “Valve Package”. On running VRF-app choose File > Open and select pak01_dir.vpk. The VPK-app will populate with a directory structure that contain the ‘resource types’ summarised on the VRF Github page.

The most important resource type are vmesh files because they encode geometry (i.e. the mesh). In the case of the Dota 2 files the extension used is vmesh_c because they have been compiled in C, but the two extensions mean the same thing.

We can now browse the directory hierarchy and where we find any vmesh_c files double-click on them to visualise the model. Below I’ve chosen the file

models/props_structures/wooden_sentry_tower001_model.vmesh_c

We can export this model to a directory of choice, Export > wooden_sentry_tower001_model.vmesh_c will generate the following 4 files

wooden_sentry_tower001_color_psd_6ba07874.png
wooden_sentry_tower001_misc_color_psd_4f7f501e.png
wooden_sentry_tower001_model.mtl
wooden_sentry_tower001_model.obj

The two png files are image textures, they are meant to be mapped to various parts of the mesh. The obj file describes the mesh itself and contains coordinates of the mesh and texture mapping. The mtl file has something to do with materials (I don’t know exactly at the moment). Both the mtl file and obj file can be opened with a text editor. Inspecting the obj file there are a series of triplets v, vn, vt that look like this

v -126.000000 -98.800000 -0.108735
vn 0.000000 0.000000 0.000000
vt 0.747070 -0.336670

v is vertex position (x,y,z), vn is the corresponding vertex normal (x,y,z), and vt is the texture mapping (u,v). Currently there is a bug in the VRF-app that makes all vn coordinates (0,0,0), but vertex normals are used for light-reflection so it doesn’t prevent us from obtaining the mesh. (It might also be possible to recalculate the normals from the mesh itself, or fix the VRF-app, I’m looking in to it).

NOTE I haven’t been able to recover the texture mapping yet either. The normals of a model have to do with shading (it produces surface irregularity), texture mapping can be thought of as surface colour. Between the two texture mapping plays a greater role in the appearance of a model.

The mesh can be imported in Blender by choosing File > Import > Wavefront (.obj), the model shown consists of about 4500 triangular faces.

NOTE To get the model to stand upright in Blender select the object and press in sequence r for rotate, x about x-axis, 2 7 0 the number of degrees, and ⏎ Enter

Download the Blender file here: http://cgdmg.com/files/wooden_sentry_tower001.blend © Valve

Browsing around the Dota 2 files it’s possible to find some interesting stuff!

VRF-app usage

When viewing a model in the VRF-app the following keys control the camera

a move camera left
d move camera right
w zoom in
s zoom out
q move camera up
z move camera down

Holding left-mouse-button and moving the mouse will change the pitch and yaw of the camera (equivalent to looking around)

VRF-app bugs

Note if you use the VRF-app from the developers website (on Github) there is a bug that prevents the application from exporting meshes. I’ve fixed this bug (partially) and patched the software so you need to download my version of the VRF-app as in the link above http://cgdmg.com/files/ValveResourceViewer.zip

Another bug (that I haven’t fixed) but is not so critical is related to viewing the models. On clicking a vmesh file a new tab opens in VRF-app for viewing the model. You can view multiple models and multiple tabs will open. It is convenient to close these tabs again. However, if you close the last viewer-tab the rendering system will shut down and you won’t be able to view any more models (requires restarting the VRF-app). So i.e. after opening the first model leave its viewer tab open for the whole session (it is ok to close the views of other models).

Note about Valve and copyright

One of the reasons I’m looking at Dota 2 is because Valve has an active game modding community and have been tolerant to uses of their assets. Based on how Valve treats the community we are considering decompiling the source code for limited non-commercial and educational purposes acceptable.

It is for instance acceptable to discuss Valve file formats on the Valve Developer Community website https://developer.valvesoftware.com/wiki/VPK (run by Valve)

Valve allows reuse of their assets as in-game mods. For example ‘Dota Auto Chess’ was a successful third-party Dota 2 mod released in 2019.

Valve also encourages the community to submit item sets like armor and equipment. According to the website thousands of such items have been submitted, and many of them adopted as in-game content. See http://www.dota2.com/workshop

To help the community develop these items the hero models are already freely available (no need to decompile!) http://www.dota2.com/workshop/requirements