• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX A way to read GUID from MDL [VB.NET]

Messages
76
Country
greece
Hey all! I m creating an aplication that makes the compiling process easier. I need to know how to read an MDL's GUID in VB.NET (or a C# example would me nice) and then show the number to a textbox. I will much appreciate your help!

Regards,
Dimitris
 
Have you looked at the mdl format in the Wiki? That describes the layout of an mdl file and where to find the GUID.
 
Hello!

Yes I have already did that. But I can't understand it.
It says:
MDLG
This section stores the object GUID. The GUID is stored in the following parts:
unsigned long data1
unsigned short data2
unsigned short data3
unsigned char data4[8]
In hexadecimal form the GUID is then written as:
{data1-data2-data3-data4[0:1]-data4[2:7]}
okay now I have to read the file line by line like a txt file or is there any special way for this ?
 
You will need to read the mdl file as an array of bytes. The way to decompile such a file is to use a pointer. Start at with the pointer at zero and then work through the byte array picking off the correct number of bytes that are required for each type. This is what I use in my decompiler. It is in C#
Code:
private void readMDLG(byte[] rawData) {
            guid = new Guid(ByteArray.Get(rawData, mdlgPointer + 4, 16));
        }

In this case ByteArray.Get(...) cuts out 16 bytes starting at the pointer+4 from the model. rawData is a byte array representing the contents of the model file.

The GUID class accepts different parameter types for input including an array of bytes.
 
Hi,

Maybe you can use this basic class I use in one of my tools. I have stripped out some code you don't need, so I hope it still compiles :).

Instead of reading the GUID like this and form a string. You can also just read 32 bytes and pass that into the constructor of the .NET GUID class.

Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ASToFra.LibraryCreatorXML
{
    public class MDLObject
    {
        // Enumeration of the support FS versions
        public enum FsVersion
        {          
            unknown = 0,
            Fs2004 = 9,
            FsX = 10,
        }

        // Local variables
        FsVersion mdlVersion = FsVersion.unknown;
        string sGUID;
        string sName;
        string sShortName;
        string sPath;
        BinaryReader mdlReader;
        
        public MDLObject(string mdlFile)
        {

            sPath = mdlFile;

            // Set default values
            mdlVersion = FsVersion.unknown;
            sGUID = null;
            sShortName = Path.GetFileNameWithoutExtension(mdlFile);
            sName = sShortName;

            try
            {
                mdlReader = new BinaryReader(File.Open(mdlFile, FileMode.Open),System.Text.Encoding.Default);

                string sRIFF = new string(mdlReader.ReadChars(4));
                mdlReader.ReadInt32(); // skip length
                string sHEAD = new string(mdlReader.ReadChars(4));

                // If this is a valid RIFF file
                if (sRIFF == "RIFF")
                {
                    // If Fs2004
                    if (sHEAD == "MDL9")
                    {
                        mdlVersion = FsVersion.Fs2004;
                        readInformation(mdlReader);
                    }
                    // If FsX
                    else if (sHEAD == "MDLX")
                    {
                        mdlVersion = FsVersion.FsX;
                        readInformation(mdlReader);
                    }
                }
                mdlReader.Close();
            }catch{
                // Something wrong, but I am not going to do anything
                // special now
            }
        }

        public void readInformation(BinaryReader mdlReader)
        {
            string sLABL;
            int length;

            while (mdlReader.PeekChar() != -1)
            {
                sLABL = new string(mdlReader.ReadChars(4));
                length = mdlReader.ReadInt32();

                // If this is the GUID, read it
                if (sLABL == "MDLG")
                {
                    uint g1, g21, g22; //, g31, g32, g4;
                    byte[] g3;
                    string g3s, g4s;
                    g1 = mdlReader.ReadUInt32();
                    g21 = mdlReader.ReadUInt16();
                    g22 = mdlReader.ReadUInt16();
                    g3 = mdlReader.ReadBytes(8);
                    g3s = g3[0].ToString("X").PadLeft(2, '0') + g3[1].ToString("X").PadLeft(2, '0');
                    g4s = g3[2].ToString("X").PadLeft(2, '0') + g3[3].ToString("X").PadLeft(2, '0') +
                        g3[4].ToString("X").PadLeft(2, '0') + g3[5].ToString("X").PadLeft(2, '0') +
                        g3[6].ToString("X").PadLeft(2, '0') + g3[7].ToString("X").PadLeft(2, '0');

                    sGUID = "{" + g1.ToString("X").PadLeft(8, '0') + "-" +
                                  g21.ToString("X").PadLeft(4, '0') + "-" +
                                  g22.ToString("X").PadLeft(4, '0') + "-" +
                                  g3s + "-" + g4s + "}";
                }
                // If this is the name, read it
                else if (sLABL == "MDLN")
                {
                    sName = new string(mdlReader.ReadChars(length));
                }
                // Else just skip the section
                else
                {
                    mdlReader.ReadBytes(length);
                }
            }
        }

        public string filename
        {
            get
            {
                return Path.GetFileName(sPath);
            }
        }

        public string filenameWithoutExtension
        {
            get
            {

                return Path.GetFileNameWithoutExtension(sPath);
            }
        }

        public string path
        {
            get
            {
                return sPath;
            }
        }

        public FsVersion version
        {
            get
            {
                return mdlVersion;
            }
        }

        public string GUID
        {
            get
            {
                return sGUID;
            }
            set
            {
                sGUID = value;
            }
        }

        public string name
        {
            get
            {
                return sName;
            }
        }

        public string shortName
        {
            get
            {
                return sShortName;
            }
        }
    }
}
 
Thanks Arno! I converted the code from C# to VB.NET with success, now the only problem is that I m getting error to:
Code:
        Public ReadOnly Property filename() As String
            Get
                Return [COLOR="Red"]Path.GetFileName[/COLOR](sPath)
            End Get
        End Property
        Public ReadOnly Property filenameWithoutExtension() As String
            Get
                Return [COLOR="Red"]Path.GetFileNameWithoutExtension[/COLOR](sPath)
            End Get
        End Property
The errors are:
Error 1 'GetFileName' is not a member of 'String'.
Error 2 'GetFileNameWithoutExtension' is not a member of 'String'.

I searched to MS web site but their ways didn't help. Hope you can help a bit more :D
Regards,
 
Hi,

In C# Path is a class in System.IO and it can do manipulations with with a path stored as a string. It is a default .NET class.

From your messages it seems Path is defined as a string for you, maybe that is the problem. But I am not so familiar with VB.NET.
 
System.IO.Path is a static helper Class that, as Arno says, should be available to VB.Net. Try fully qualifying it by using System.IO.Path instead of just Path
 
Back
Top