Learning Unity (Part 4)

If your just stumbling across this multi-part blog series, you can start from the beginning here: Part 1, Part 2, Part 3. In the my last post, I detailed how I was planning to map textures to each side of the cubes in the Descent levels. I integrated my code into the DescentLevelViewer program and then I dumped the texture names from the PIG file into a text file. The text file has the texture files named in order. Then I added all the PNG files that were extracted from the PIG file. In order for Unity to load the texture using the Resource.Load() method, you must put your PNG files inside of the Assets/Resources/Textures directory. If the sub-directories don’t exist, then you’ll need to create them. Calling a PNG file using the Resource.Load() method requires the filename without the extension. Unity will load the PNG files and create meta files to match each texture.

I discovered one problem immediately. I mentioned this issue in one of my previous posts: There are some textures that belong to animations and the names are repeated. So I dumped them and assigned an “_0” and “_1” etc. to each sequence of the animation. That means that I had to doctor the text file containing the texture names. I added the “_0” to the first textures for each animation for now. I’ll deal with animated textures later.

I ran my code and here was the result:

Level 1 Bad Textures

Obviously something was wrong. First, there are some white tunnels. Those are missing textures. Then the blue textures with the green triangle…

Sigh. Those are robot textures:

rbot37.png

That image belongs to this robot:

Class 2 Drone

I started looking at the primary texture numbers assigned to each side and they did not match the texture from the PIG file. Using the DLE level editor, I loaded level 1 and looked at the textures assigned to cube 0. The left wall of cube 0 had a texture of rock001. The HOG file RDL data said that cube 0 was primary texture 0. Rock001 was texture number 721. I added 721 to the texture index and produced this:

Level 1 Bad Textures

The exit tunnel should consist of exit01.png images. It appears that ceil027.png is being used for the exit tunnel walls. This told me that there must be a translation table that converts from the texture numbers used in the cubes and the list of textures in the PIG file.

I dug through the source code and came across a section that had a comment like this:

//=============== GENERATE TEXTURE TRANSLATION TABLE ===============

I looked at the code and it appears to be looking up the textures by name and then using the index to build a translation table. Unfortunately, there are no names stored in the RDL files (or any other file in the HOG file). The PIG file didn’t seem to contain any translation tables either. I decided to cut my losses at this point and hand-code a translation table. For this, I created code that would dump the distinct list of textures that had no translation entries for all levels. For each texture dumped, I printed the level name, the cube number and the wall name. Then I looked each one up on the DLE level editor and recorded the name. Then I looked up the name in my texture text file and copied the index into my translation table. After hours of manual-labor, this was my result:

Level 1 Correct Textures

Here’s a sample of level 12:

Level 12

There are other texture attributes that will need to be dealt with. For one, there is a transparency flag and a super transparent flag. I’m not sure what the difference is between the two. I do know that there are some walls that you can see and shoot through. Here’s an example:

Screenshot from the actual game level 14

You can see through the grates on the ceiling of this level. These grates are first seen at the beginning of level 14 in the floor:

Screenshot from the actual game level 14

This wall occurs in this area inside the red ellipse:

My Unity Level Viewer

If I were planning to build out the entire game to mimic what the original game did, I would start by enumerating every feature and detail I can find. Then organize a list of tasks (stories) to complete in a logical order. Trello is usually my tool of choice for doing this, but this is really more of a hobby than a job. My goal is to learn some techniques in Unity and maybe use them into a new type of game.

What’s next? I think my next task will be to reverse the textures to point in. Then I’m going to attempt to read the joystick inputs and try out some collision detection and navigation. If I can get a ship to fly around in the tunnels, then I can navigate around inside levels. I might add some menus as well. It would be nice to switch levels without editing the code. I still have some cleanup work to do, like applying the Descent UVL numbers to the textures and I need to fix the textures that did not dump correctly from the PIG file. That will take some analysis of the C source code to determine what I’m missing. I might also animate some textures, just to see if there is an easy way to do it in Unity, or if I just have to reassign the textures at specified time intervals.

Eventually, I’d like to decode the robot data and see if I can reconstruct the robots. I have already looked at the robot data in the HOG file and and it looks like quite a task. Correctly rendering the robots will be the primary task, followed by animating them. This will involve a lot of C code reverse engineering to see how the developers encoded the robot behaviors.

Where to Get the Source Code

You can download the source code that was used in these blog posts. Feel free to use this code any way you like. The code is at my GitHub account: click here. This blog post was built with this version: click here. If you know anything about the Descent I data files and how the textures are translated, leave a comment and I’ll add your information to my next post (leave a link if you want me to link back to your blog).

Leave a Reply