Saving additional data in dll, how did they do it?

Let me tell you a little about where this question comes from. I'm playing the SDK Serious Sam 2, a first-person shooter that runs on Serious Engine 2. This engine represents something called MetaData. MetaData is used in the engine for serialization of classes and the ability to edit them in the editor environment (Serious Editor 2). So, for example, instead of:

class CSomeGameItem : CEntity
{
    public:
    int iHealthToGive;
}

      

What will not show up in the editor, you would do:

meta ver(1) class CSomeGameItem : CEntity _("Some game item")
{
public:
    meta int iHealthToGive; _("Amount of health to give")
}

      

Now when you make a level, you can insert a "Some game item" object into your level and edit the one property it has. Now I know that Croteam (the developers of the game and engine mentioned) use an additional compiler (Mdc, metadata) to add additional information about the classes and their variables to the dll files to make this metadata system possible. Does anyone know how they did it?

Oh btw, the keywords meta, ver () and _ () are # define'd nothing in their code, so the "normal" compiler ignores them.

0


source to share


4 answers


It looks somewhat similar to Qt moc (object meta compiler). In the case of Qt, it generates additional C ++ source files which are then compiled and linked together with the original source files.



A possible implementation in your example would be for the generated files to implement a set of functions that can be called to get more information, to set properties, etc.

0


source


If this engine is running on Windows, one idea that comes to mind is resources. There are Windows APIs for modifying the content of exe or dll resources. In addition, the API allows you to read resources from an "external" exe / dll. This way the additional compiler will store the metadata as resources in the compiled exe. And the development kit will read this metadata from the "base" exe / dll.



I now have a server of this stuff so I can be light years away from how it works.

+1


source


For a definitive answer, study the PE File Format . It is a low-level file format for Win32 binaries. i.e. DLL, EXE, COM, etc.

There are many books that describe the layout and functions of the PE file. And many tools that allow you to explore it.

The short answer is that, at its lowest level, the PE file format allows data to be inserted into a binary file that can be extracted at runtime. DLL and Exe often embed their own icons and localization text. They are often referred to as resources.

A good place to start is the Resource File section on MSDN. Also examine "Resource Scripts (* .rc files)" and "Resource Compiler (rc.exe)".

+1


source


Just strike in the dark as I've never looked at the sdk, but my guess is that there are two walk-through systems going on there - once with the C ++ compiler and once with a dedicated metadata processor that can find meta tags and handle associated names classes, instance member names, and _ () tags. Most likely some kind of config file is created and either left to the side or embedded in the resource file. A custom metadata run could also just be a C ++ code generator that generates code to enable pseudo-reflexion for each class.

0


source







All Articles