Insert BGL CODE into MODEL file
Copy the modified code from myairplane.bgl and paste it into myairplane.mdl.
Since you have to work with the FSDS-generated binary coded model file, you should get familiar with the structure of an FSDS model file as well as the SCASM binary opcodes used in the file.
What you are going to do next is, in simple terms, copy a large block of binary code from your scenery file (myairplane.bgl) and paste it into the appropriate spot in your model file (myairplane.mdl).
The steps involved in using a hex editor to make this "code transfer" are pretty straightforward, but there is plenty of room for error if you aren't careful.
You are not going to copy the entire BGL file into the MDL file.
Everything from the opening line in the SCA file down to the BGLVersion ( 0732 ) command remains unchanged, so you won't need to copy any of that code.
Open your hex editor and load the two files myairplane.bgl from your SCASM folder, and myairplane.mdl from your CFS2 folder .../Aircraft/My Airplane/model.
Search the myairplane.bgl file for the following binary code sequence ...
This is your starting point - the opcode for the SCASM command ... BGLVersion( 0732 )
It's impossible to specify the exact address of this command, but you should find it somewhere between
0x00000100 and 0x0000010A
Set your cursor at the byte "BC" in this code sequence and highlight everything to the end of the BGL file. Copy this block of data.
Now open myairplane.mdl and search for the same binary code sequence ... BC00 3207. To be sure you have the right spot, scroll down a bit and you should see the text name of one of your model's texture files. It will be a name ending with the extension".bmp."
Set your cursor at the byte "BC" in this code sequence and highlight everything to the end of the MDL file. Now, paste the block of binary code you just copied from the BGL file.
You're almost done. All that remains is to update two key offset values in your new model file and you are ready for a test flight.
First, you have to change the RIFF offset at address 0x00005004 ( 20484 dec ). There is no end-file marker in a RIFF file, so this 32-bit unsigned integer value tells CFS2 exactly where to find the end of the RIFF file. The value is added to the RIFF offset address to mark the file's end point.
Second, you have to change the BGL offset. The beginning of the BGL section depends on the length of the preceeding parameters dictionary. Its start is indicated by the 3-character string "BGL " (There is a blank space after the letter "L"). The offset address is at the first byte following the string "BGL ".
00005488 2C00 0000 4372 6561 7465 6420 6279 2046 5320 4465 ,...Created by FS De
0000549C 7369 676E 2053 7475 6469 6F0A 436F 7079 7269 6768 sign Studio.Copyrigh
000054B0 7420 3230 3033 0000 4247 4C20 7423 1100 3A00 3800 t 2003..BGL t#..:.8.
This 32-bit unsigned integer value tells CFS2 exactly where to find the end of the BGL opcode, which is the same byte pointed to by the RIFF offset. The value is added to the BGL offset address to mark the end of the BGL code.
Write down the values for the RIFF offset address and the BGL offset address for your model file. You'll use them often.
Scroll down to the end of the MDL file in the hex editor and write down the address of the last SCASM opcode for a Return command (2200) followed by a null word. For example,
AE00 2200 0000 ...
In SCASM code, this would be ...
AE00 2200 2200 0000 ...
That last Return command marks the effective end of the BGL code section and the model file. Think of it as the "EOF" address. Write down this address.
For the RIFF offset, subtract the RIFF offset address 0x00005004 (20484 dec) from the "EOF" address you just wrote down. This is the new RIFF offset value that you have to place back into the address 0x00005004 (20484 dec).
For the BGL offset, subtract the offset address from the "EOF" address you just wrote down. This is the new BGL offset value.
Whenever you use a hex editor to modify the model file (.mdl), you must recalculate and manually update the end of file offsets for the RIFF file at 00005004 (20484 dec) and the BGL section.
If either of these offsets are wrong by just 1 byte, CFS2 will not render the model properly!
After updating the RIFF and BGL offsets, save your model file.
Congratulations! You're done. If you did everything correctly, your new special effects model is ready to fly.
Now it's on to STEP 6, where you will verify the changes you've made to the model file actually work and test fly the results!