Difference between revisions of "SA SCM"

From GTAMods Wiki
Jump to navigation Jump to search
m
(Renewed the whole article according to proper symbols.)
Line 1: Line 1:
{{Cleanup-rewrite}}
+
(02 00 01)h + 32-bit offset    '''GOTO''' next header chunk
{{Script-stub}}
+
byte                          Target game ('s' - San Andreas for SA, unused at runtime)
A scm file is a binary file with certain structure. The common information about what this file is for can be found [[Mission_Scripting_(Overview)|here]]. The scm file structure looks like the following:
+
  (Global variable space)      Space for global variable storage (first global offset is 8)
 +
(02 00 01)h + 32-bit offset    '''GOTO''' next header chunk
 +
byte                          Chunk index (always 0, unused at runtime)
 +
  32-bit int                  Number of used objects (at least 1)
 +
  (Used object array)          24-byte object name * number of used objects (first object name is empty and therefore unused)
 +
(02 00 01)h + 32-bit offset    '''GOTO''' next header chunk (third header chunk is compiled only in script multifile)
 +
byte                          Chunk index (always 1, unused at runtime)
 +
  32-bit int                  Main script size
 +
  32-bit int                  Largest mission script size
 +
  16-bit int                  Number of mission scripts (200 in total)
 +
  16-bit int                  Number of exclusive mission scripts (3 in total)
 +
  32-bit int                  Largest number of mission script local variables
 +
  (Multi script array)        32-bit offset * number of mission scripts
 +
(02 00 01)h + 32-bit offset    '''GOTO''' next header chunk
 +
byte                          Chunk index (always 2, unused at runtime)
 +
  32-bit int                  Largest streamed script size
 +
  32-bit int                  Number of streamed scripts
 +
  (Streamed script array)      28-byte structure * number of streamed scripts (last one is '''AAA''' test script{{ref|1}})
 +
    20 bytes                  Filename (without extension)
 +
    32-bit offset              File offset (from script multifile end onwards, mostly leftover)
 +
    32-bit int                Script size
 +
(02 00 01)h + 32-bit offset    '''GOTO''' next header chunk{{ref|2}}
 +
byte                          Chunk index (always 3, unused at runtime)
 +
  32-bit int                  Unknown (file offset of '''AAA''' test script, designed to be 0?{{ref|3}} Unused at runtime)
 +
(02 00 01)h + 32-bit offset    '''GOTO''' main script space{{ref|2}}
 +
byte                          Chunk index (always 4, unused at runtime)
 +
  32-bit int                  Size of global variable space (unused at runtime)
 +
  32-bit int                  Unknown (some checksum related to streamed script array? Unused at runtime)
 +
(Main script space)            Space of main script (equal to size defined earlier)
 +
(Mission scripts space)        Space of mission scripts (each one is stored at file offsets defined earlier)
 +
(Streamed scripts space)      Space of streamed scripts (as above but external and non-contiguous for script multifile)
  
(02 00 01)h + 32-bit int    Jump to second segment
+
{{note|1}} '''AAA''' streamed script is apparently a test script, meaningful for debug builds, which contains no intermediate code and is supposed to store the 8 bytes coming with the sixth header chunk of the script multifile relevant to match the [[Cd image]] where all streamed scripts have been compiled and archived into (notoriously in [[script.img]]). It is advisable to compare data on the basis of the script size rather than of a fixed length (the way it might have been designed to);
byte                        Target game ('s' - San Andreas for SA)
 
  (Global vars)              Space for variable saving
 
(02 00 01)h + 32-bit int    Jump to third segment
 
byte                        Segment id
 
  32-bit int                Number of models
 
  (Model names)              24-byte model names * number of models (model 0 name is empty and therefore unused)
 
(02 00 01)h + 32-bit int    Jump to fourth segment
 
byte                        Segment id
 
  32-bit int                MAIN size
 
  32-bit int                Largest mission size
 
  16-bit int                Number of total missions
 
  16-bit int                Number of exclusive missions
 
  32-bit int                Highest number of locals used in mission/exernal
 
  (Mission addresses)        32-bit addresses * number of missions
 
(02 00 01)h + 32-bit int    Jump to fifth segment
 
byte                        Segment id
 
  32-bit int                Largest external size
 
  32-bit int                Number of externals
 
  (External data):          28 byte external data * number of externals
 
    20 bytes                 Name of external
 
    32-bit int              Offset of external
 
    32-bit int              Size of external
 
(02 00 01)h + 32-bit int    Jump to sixth segment
 
byte                        Segment id
 
  32-bit int                (Unused, always 0)
 
(02 00 01)h + 32-bit int    Jump to seventh segment
 
byte                        Segment id
 
  32-bit int                Size of global var space
 
    8-bit int                Number of allocated externals (with [[07D3]], [[0884]], [[0928]] or [[0929]])? (unused, always 3Eh)
 
    8-bit int                Number of unused externals ('''HOME_BRAINS''' and '''AAA''')? (unused, always 2)
 
  16-bit int                (Unused, always 0)
 
(MAIN code)                  MAIN section, equal to size defined earlier
 
(Mission code)               The mission data, missions stored at offsets defined earlier
 
  
The '''AAA''' external script is very odd as the sixth segment is copied inside. The following bytes are just padding to align the file size to the nearest 2KB, like also in the working externals.
+
{{note|2}} The header chunk is fetched as normal code and may be mandatory only in script multifile if streamed scripts are present or, even more strict, if '''AAA''' test script is compiled;
  
==See also==
+
{{note|3}} A hint or what matters to get the test script filename ('''AAA''' might be purely conventional). If the file offset does not match the one of the very last streamed script, a binary search of the entire array with an element less could be performed.
* [[SCM language]]
 
  
 
[[Category:Mission Script]] [[Category:File Formats]]
 
[[Category:Mission Script]] [[Category:File Formats]]

Revision as of 10:55, 23 January 2017

(02 00 01)h + 32-bit offset    GOTO next header chunk
byte                           Target game ('s' - San Andreas for SA, unused at runtime)
  (Global variable space)      Space for global variable storage (first global offset is 8)
(02 00 01)h + 32-bit offset    GOTO next header chunk
byte                           Chunk index (always 0, unused at runtime)
  32-bit int                   Number of used objects (at least 1)
  (Used object array)          24-byte object name * number of used objects (first object name is empty and therefore unused)
(02 00 01)h + 32-bit offset    GOTO next header chunk (third header chunk is compiled only in script multifile)
byte                           Chunk index (always 1, unused at runtime)
  32-bit int                   Main script size
  32-bit int                   Largest mission script size
  16-bit int                   Number of mission scripts (200 in total)
  16-bit int                   Number of exclusive mission scripts (3 in total)
  32-bit int                   Largest number of mission script local variables
  (Multi script array)         32-bit offset * number of mission scripts
(02 00 01)h + 32-bit offset    GOTO next header chunk
byte                           Chunk index (always 2, unused at runtime)
  32-bit int                   Largest streamed script size
  32-bit int                   Number of streamed scripts
  (Streamed script array)      28-byte structure * number of streamed scripts (last one is AAA test script[1])
    20 bytes                   Filename (without extension)
    32-bit offset              File offset (from script multifile end onwards, mostly leftover)
    32-bit int                 Script size
(02 00 01)h + 32-bit offset    GOTO next header chunk[2]
byte                           Chunk index (always 3, unused at runtime)
  32-bit int                   Unknown (file offset of AAA test script, designed to be 0?[3] Unused at runtime)
(02 00 01)h + 32-bit offset    GOTO main script space[2]
byte                           Chunk index (always 4, unused at runtime)
  32-bit int                   Size of global variable space (unused at runtime)
  32-bit int                   Unknown (some checksum related to streamed script array? Unused at runtime)
(Main script space)            Space of main script (equal to size defined earlier)
(Mission scripts space)        Space of mission scripts (each one is stored at file offsets defined earlier)
(Streamed scripts space)       Space of streamed scripts (as above but external and non-contiguous for script multifile)

^ AAA streamed script is apparently a test script, meaningful for debug builds, which contains no intermediate code and is supposed to store the 8 bytes coming with the sixth header chunk of the script multifile relevant to match the Cd image where all streamed scripts have been compiled and archived into (notoriously in script.img). It is advisable to compare data on the basis of the script size rather than of a fixed length (the way it might have been designed to);

^ The header chunk is fetched as normal code and may be mandatory only in script multifile if streamed scripts are present or, even more strict, if AAA test script is compiled;

^ A hint or what matters to get the test script filename (AAA might be purely conventional). If the file offset does not match the one of the very last streamed script, a binary search of the entire array with an element less could be performed.