Creating a binary file inspector for reverse engineering games 3d models
This last 2 weeks I have been developing a program to help me reverse engineer some 3d models from video games and I thought on writing how all this adventure went.
Here is a pic of the final product:
And here is the link to the source code
Motivation
With all these videos coming out where a developer in his spare time remakes an old game in UnrealEngine, I wanted to try to do the same with a game I used to play a lot as a kid, 2009's PURE, an ATV racing game that wasn't that well known, but should have been given the fun and adrenaline feeling that the game gives you.
Remaking an entire game from scratch is an intensive task, so I'll narrow it down to simply remaking the demo, and to do this I need a game engine and the original assets (to then improve them if necessary). The game engine could be UnrealEngine or Unity. But what about the original assets?
The original assets are in a binary file, in a format that I will have to learn to read to recover the 3D model.
What do I need to inspect 3d model files?
Reading a binary file is not an easy task because what happens with these files is the interpretation, the same byte can be a vertex position on the X axis or a colour channel in an image.
The first thing we need to do is see this file content to search for patterns, we can do this with any hex editor. But if we can use any hex editor why create this program?
The thing is that searching for patterns using a hex editor is not as easy to see and will not allow us to quickly iterate over new patterns. If we had a way to see the pattern we think we have found, it would be much faster to repeat the pattern search. We need a way to specify the pattern and a 3D viewport to see this pattern in action.
Now I hear you say "But Pablo, it's 2023, there should be a program like this somewhere, right?"
Well yes and no. While I did find some programs like Hex2Obj and 3dModelResearcher, these are no longer supported by their respective authors, they are closed source so improving on them is impossible and, as if all this was not enough, Hex2Obj is hard to come by now that XeNTaX.com is closed.
The 3d viewport
I've made some 3d model viewers in the past, so I knew that I needed to use Opengl4 as the GPU API and SDL2 if I wanted to do this the fast way.
The pattern input
To take the pattern as input I was inspired by 3dModelReasearcher, a great tool to do this but it lacked custom annotations in the file to find patterns in a more comfortable way. So I got the ImGUI library and got to work. This is what I ended up with:
The hex viewer
This is the part of the program that made me ditch 3dModelResearcher, so I better get it right, haha. To make the hex editor I started off of mem_editor for ImGUI. This component is great, but like any free hex editor, it didn't have the cool features I want, annotating zones in the hex viewer and visualizing the data I'm reading with my guess pattern.
Naturally, I forked mem_editor, created a new branch called mem_viewer, and added these features. The thing is, I wasn't very familiar with how ImGUI worked, so it took me a while to read some of their code to understand how to create this beautiful landscape of colourful hexadecimal characters:
The way this works is that you add a note with the "+" button and then choose a color, set the direction in which the note begins and ends, and most importantly, add a description of the area you are annotating.
Conclusion
There is a gap in the market for tools for researching 3D models and even more so now with the fall of XeNTaX. Starting this journey has not been easy, but it has been fun and there is a lot to improve, especially on the GUI side. Binary files are difficult to read, but they are more compact and safer for releasing copyrighted assets. Reverse engineering is not illegal, but using these assets may cause problems for us, so no commercial use or distribution of these assets will be made. The tool is now usable and ready to help me reverse engineer PURE model files.
Coming next. Reverse engineering the .model binary format from PURE(2009)
Backend Engineer
1 年Sos crack Pablo! ??
Estudiante de Tecnicatura superior en Programación
1 年Intersante post ? ? ? ?