Ripping Models From Directx9 Games Part 1 – The Basics

Ripping Models

If you’re like me you’ve seen games with really cool looking models and wondered how they were put together.  You might have searched online and seen a couple of tools that allowed you to get the models you were interested in.  And once you did that you couldn’t help but wonder how the process of ripping models from a game goes down.

In this tutorial I’ll show you what it takes to code a program for ripping models, something like this, and send you on your way to experiment with the world of directx9.

I’ll be splitting this tutorial into parts since otherwise it would get pretty long.  This first part will cover the concepts involved so that you can have the understanding required to implement a 3d ripper for directx9 for ripping models in directx.

ripping models

Basic Directx9 Overview

Directx is a graphics API published by Microsoft.  The great majority of games these days rely on it, with a minority of games relying on a competing open source library called opengl.  There are many versions of Directx, the current one being Directx11.  For our purposes we will be working with directx9, and some of the stuff discussed here will not be directly applicable to 10 and 11 since the API has changed significantly in those releases. A basic understanding of directx9 is necessary for ripping models.

If you want to know more about directx here is a good place to start.

We will not be going indepth into how to use directx, and that is something I recommend you become familiar with before trying to write software for ripping models from directx games.  But I will give a brief explanation of the moving parts we need to work with to make it all work out later on in this tutorial.  Although the process of ripping models is not very complicated once you have a good understanding of directx9, it could be a nightmare if you are not familiar with directx rendering.  Below I give you a brief introduction to directx9 so that you have enough of a working knowledge to start ripping models.

Directx9 Rendering

A few things happen when a 3d model gets rendered in directx.  First, the vertexbuffer gets populated and bound to a stream on the d3d device.  Second, the index buffer gets populated and bound to the device.  And finally, DrawIndexedPrimitive gets called to draw the primitive represented by the vertices in the indexed buffer.  It is these buffers that are critical in the process of ripping models.

A vertexbuffer is just a buffer in memory that contains the vertex data for the models being rendered.  3D geometry is represented by primitives, and primitives are composed of 3d vertices (x,y, and z coordinates).  A primitive is just a geometric figure, directx9 supports these primitives. Mostly we’re only concerned with D3DPT_TRIANGLELIST, D3DPT_TRIANGLESTRIP, which are just polygon representations.

Now you may be wondering, why do we need an index buffer pointing to the vertexbuffer? The answer is optimization.  Directx9 allows you to have varied sized vertices, a format which they refer to as flexible vertex format (FVF).  This means you can pack all kinds of information into a vertex, making it blow up in size to 60 or more bytes.  Indices, on the other hand, are usually words (2 bytes), so instead of duplicating shared vertices at the cost of 60 or 80 bytes, we instead duplicate indices at the cost of 2 bytes.  Over time it adds up.

In case this whole index buffer/vertex buffer has you confused think of it like this:



Index_buffer[0] = 0

Index_buffer[1] = 1

Index_buffer[2]  = 0

Vertex_buffer[0] = { 1, 3, -1}

Vertex_buffer[1] = {-1, 2, 0}

If we draw a triangle using the Index_buffer starting at 0 and going to the 3rd index, we’ll have a triangle composed of {1,3,-1}, {-1,2,0}, {1,3-1}, which is basically:

{Vertex_buffer[Index_buffer[0]], Vertex_buffer[Index_buffer[1]], Vertex_buffer[Index_buffer[2]]}, or

{Vertex_buffer[0], Vertex_buffer[1], Vertex_buffer[2]}

I think you can tell by now that the values stored inside the Index buffer are simply indices into the vertex buffer.  It can get a little bit more complicated than that, because directx9 supports offset indexing, which means you may need to add an offset to the values in the index buffer before indexing into the vertex buffer.  Say index_buffer[0] = 10.  If we’re drawing with an offset of 50, that means that instead of picking the vertex at vertex_buffer[10], you’d select the vertex at vertex_buffer[60], and so on for all other vertices on that draw call.

The last thing you need to understand conceptually before you can rip a 3d model from directx9 games is the concept of faces.  I don’t claim to be a mathematician, and if you look here you’ll see a much more complex definition, but as far as I’m concerned for our purposes a face is simply a 2d triangle, or polygon.  To make a triangle you need 3 vertices, or three points in space.  The process of ripping models is the process of capturing all this face information, storing it, and then rebuilding it back up in a way that makes sense.

ripping models

2 Faces(Polygons)


We’ve covered all the concepts you need to know in order to grasp how models are rendered in directx9 so that you can start ripping models.  This will give you the necessary foundation to build upon for part 2 of this tutorial, where I will show you how to go about writing code to get the index and vertex data that you need so that you can start ripping models, and outputting it to a format that can be easily interpreted by most 3d modeling tools out there.

One Response to Ripping Models From Directx9 Games Part 1 – The Basics

  1. […] you read part one of this tutorial you know that we need to get access to the index and vertex buffers which is where […]

Leave a Reply

Your email address will not be published. Required fields are marked *