Question

I'm trying to learn the level format in one of my favourite games, which is almost totally undocumented. Basically the only document that describes the level format is simply by saying things like First 12 bytes: header
4 following bytes: number of materials
x next bytes: array of materials,
and things like that.

I'm very inexperienced in hex and don't completely understand what they're saying. However, there is a level editor, and the source is freely available on google code. I was thinking of adding this in to my visual studio and trying to learn the level format by reading how the level editor opens the files.

However, another problem, I don't know c++ (I know python). This means I probably won't be able to locate which part of the code reads the bytes and whatnot.

What I'm looking for, is something that will allow me to follow the flow of the code, in its execution. Essentially something that acts similar to setting a breakpoint on every line, and having it show me what specific portion of code is executing when reading the file contents. However, obviously setting breakpoints on every line is very messy and slow. I'm looking for something that will simply show me what code is being run when I open the file in the editor.

Does anyone know what I could do? Thanks.

Was it helpful?

Solution

You're looking for a feature to step from one statement to the next; every debugger I know has such a feature. You start by setting a single breakpoint at the beginning of the interesting region, and starting from there you "step" through your code.

E.g. in Visual C++ 2010, the key F10 does one step; you can also "step into" the next statement (e.g. a method call) with F11.

In your case, set the breakpoint to where the reading of the level file starts, and continue from there. To find the place where the file is read can be a hard problem as well - depending on the clearness of the code; but if it's well written code, there should be a method with "read" in the name or "load" or something similar - you'll figure it out!

You might have to know at least some basic C++ syntax to be able to follow what's going, though.

I would also recommend reading up on Debugging HowTo's (e.g this one).

OTHER TIPS

The document wich you find so obscure, is just the level format specifications, in most cases the specifications are all you need. You need as well some little extra experience with file reading.

When reading a file you have to warry about few things.

1) When reading byte by byte (8 bits) order is no changed.

2) When reading 32bits at a time byte order can change according to endianness of machine.

(for example 0x12345678 becomes 0x78563412 when endiannes changes)

There was a very old tutorial that can help you loading 3D models that helped me to start working with files:

http://www.spacesimulator.net/wiki/index.php?title=Tutorials:3ds_Loader

this is usefull because you have part of the specifications (like in original documentation) and it shows how you can create a loader just starting from specifications. That's all you need. That's C but there is no big difference from C++ in this case.

If you need some other simple file format specification with related file loader for making things clearer to you, you can also look at libktx and ktx specifications:

http://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/

If I remember correctly there's also a unofficial C++ KTX loader you can look at if you itend to write C++ oop code rather than C.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top