• 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.

[SOLVED] Tool for Editing MDL Binary content (Bug: Invalid section length for section error)

RicherSims

Resource contributor
Messages
560
Country
dominica
I'm coding a tool to perform a batch edit of the Friendly Names in the MDLN section of MDL files. (Becasue sometimes I have files with different file names but identical friendly names, and I need to batch process them in ModelConverterX, but MCX will overwrite previous files as they all have the same friendly name).

I've mostly worked with text files before and I'm teaching myself to work with binary files for the first time.
I understand from reading the MDL File Format documentation that the files are split into sections each with 3 parts: A four letter section name, an integer representing the length of the content, and the content itself.
I've managed to find the MDLN section and can successfully edit the integer representing the length of the friendly name and edit the friendly name itself.
My problem arises when I try to read the rest of the file after the friendly name and copy it downwards (as you can't really
insert in a binary file).
Despite my best effors to read and write the data exactly where it previously occurred after the MDLN section, on re-opening the file in MCX, it reports the following error:

MDLXReader Error Invalid section length for section MDLD
However, comparing the edited file to the original in a Hex or Text Editor the ONLY change I can see is the changed friendly name, and the changed integer representing the new length of the friendly name.
The MDLD section should not have changed at all. The rest of the bytes are unchanged. Simply shifted downwards.
I am stumped.

Here is the code I use in the relevant section (yes I code in Pascal).


Code:
//integer value size of NewName
datalength := length(NewName);
//difference between space left for old name and space required for new name
InsertLength := datalength-aSection.size;   //asection.size = length of old friendly name
//write new data length
FS.write(datalength, sizeof(datalength));
//Save current position in binary file to come back to later
InsertPosition := FS.Position;

{We will need to read all characters from current position + length of oldname (i.e. section.size) to EOF and copy them downwards "Insert" spaces to make space for NewName length}
//We are now at the beginning of the Section Length integer for MDLN. Seek forward to the next section(i.e PARA)
FS.Seek(aSection.size, soFromCurrent);
//prepare array of bytes for rest of file
data := nil;
SetLength(data, FS.Size);
For idx := 1 to length(data) do
    data[idx] := 0;
//read all characters from current position to EOF and save how many bytes we've read in datalength
datalength := FS.Read(data, FS.size);

//seek back to insertion point which is beginning of friendly name in MDLN section
FS.Position := InsertPosition;

//convert NewName to character bytes and write
for idx := 1 to length(NewName) do
begin
    b := Byte(NewName[idx]);
    FS.Write(b,sizeof(b));
end;

//append rest of file
FS.Write(data, datalength);

Attached are 2 files:
The edited one has a friendly name changed from "1" to "1_09".

What am I missing? Any guidance on this would be greatly appreciated.
 

Attachments

  • 1_09.mdl
    73.9 KB · Views: 126
  • 1_09_original.mdl
    73.9 KB · Views: 123

RicherSims

Resource contributor
Messages
560
Country
dominica
I got the idea to compare my edit to an edit done in MCX.
It appears that when the friendly name in the MDLN section is changed, the integer in the first RIFF section also changes (apparently by the size of the change in the MDLN section) though I cannot figure out why.
Does this section integer cover the size of the content of all the section sizes in the file? Or the size of the entire file in bytes? (I doubt its the latter). The Wiki is not clear on this.
If so, why does it affect the MDLD section?

I feel like I may be close.
 

RicherSims

Resource contributor
Messages
560
Country
dominica
Turns out I was right. The RIFF header content length integer had to be increased by the same amount as the MDLN section content length.

Thanks for your help guys. This was a nice convo. :p
 
Messages
11
Country
unitedkingdom
Im having the exact same issue with a model i converted yesterday, it had no animations so i added animations from mcx and exported it with no errors, then when im importing it MCX gives the "Invalid Section Length for XYZ" error. whats the issue with it and how can i work around it?
 

RicherSims

Resource contributor
Messages
560
Country
dominica
Im having the exact same issue with a model i converted yesterday, it had no animations so i added animations from mcx and exported it with no errors, then when im importing it MCX gives the "Invalid Section Length for XYZ" error. whats the issue with it and how can i work around it?
If this is an error that occurs after a model is exported with MCX (and not from a tool that you programmed yourself), then it would probably be best to post this question with sample models directly in the MCX forum. Perhaps the creator (Arno) will be able to assist.
 
Top