Mission Scripting (Overview): Difference between revisions

No edit summary
m (removing template:note, removed: {{note|lcsfloat}} (11))
Line 145: Line 145:
|}
|}


{{note|lcsfloat}} To get the value of a packed float, read the needed amount of bytes (1, 2 or 3) from a scm to a byte[4] array starting from the 3rd, 2nd or 1st element of it respectively. 0 byte of the array is always empty. Then cast this array as a float and that's it.<!-- the description suxxx. need some code -->
To get the value of a packed float, read the needed amount of bytes (1, 2 or 3) from a scm to a byte[4] array starting from the 3rd, 2nd or 1st element of it respectively. 0 byte of the array is always empty. Then cast this array as a float and that's it.<!-- the description suxxx. need some code -->


{{Incomplete}}
{{Incomplete}}
Line 169: Line 169:
There are two kinds of the strings used.
There are two kinds of the strings used.


{{note|str8}} '''Short string'''. This is the most common type of a string, that is used in every game since GTA III. The term ''short'' means that this string is strongly limited to its length. Maximum symbols it could contain is 7 and the last one (8th) is a [[Wikipedia:null terminator|null terminator]] byte. When compiled such strings occupy 8 bytes of a [[SCM]] file no matter if the string is actually shorter (the rest of bytes is filled with zero bytes).  
'''Short string'''. This is the most common type of a string, that is used in every game since GTA III. The term ''short'' means that this string is strongly limited to its length. Maximum symbols it could contain is 7 and the last one (8th) is a [[Wikipedia:null terminator|null terminator]] byte. When compiled such strings occupy 8 bytes of a [[SCM]] file no matter if the string is actually shorter (the rest of bytes is filled with zero bytes).  


{{note|sa16}} SA scripting engine also has data type 15 that denotes the short string containing up to 15 symbols. This kind of strings is only supported by [[Sanny Builder]]. They are handled in a same manner as 8-bytes strings, but occupy 16 bytes of a SCM file.
SA scripting engine also has data type 15 that denotes the short string containing up to 15 symbols. This kind of strings is only supported by [[Sanny Builder]]. They are handled in a same manner as 8-bytes strings, but occupy 16 bytes of a SCM file.
{|
{|
!width="250px" align="left"|String
!width="250px" align="left"|String
Line 182: Line 182:
| <span style="color:red">'SAVE_YOUR_SOULS!'</span>||{{Hint|0F|data type}}&nbsp;&nbsp;&nbsp;{{hint|53 41 56 45 5F 4F 55 52 5F 53 4F 55 4C 53 21 00|string}}
| <span style="color:red">'SAVE_YOUR_SOULS!'</span>||{{Hint|0F|data type}}&nbsp;&nbsp;&nbsp;{{hint|53 41 56 45 5F 4F 55 52 5F 53 4F 55 4C 53 21 00|string}}
|}
|}
{{note|str16}} '''Long string'''. This type was first introduced in San Andreas. Maximum length depends on the opcode{{Ref|longstringslimits|[*]}}.  
'''Long string'''. This type was first introduced in San Andreas. Maximum length depends on the opcode{{Ref|longstringslimits|[*]}}.  


{{Incomplete}}
{{Incomplete}}


==== Arrays ====
==== Arrays ====
{{note|varray}} Native ''[[Wikipedia:Array|arrays]]'' support was introduced in GTA SA, however there were different implementations of [[VC Arrays|arrays in Vice City]]. In SA SCM arrays are assembled as 2 UINT16s and 2 bytes:
Native ''[[Wikipedia:Array|arrays]]'' support was introduced in GTA SA, however there were different implementations of [[VC Arrays|arrays in Vice City]]. In SA SCM arrays are assembled as 2 UINT16s and 2 bytes:
  2b - UINT16 - array offset{{ref|arrayoffset|[*]}}
  2b - UINT16 - array offset{{ref|arrayoffset|[*]}}
  2b - UINT16 - array index{{ref|arrayindex|[*]}}
  2b - UINT16 - array index{{ref|arrayindex|[*]}}
Line 193: Line 193:
  1b - BYTE  - flags{{ref|arrayflags|[*]}}
  1b - BYTE  - flags{{ref|arrayflags|[*]}}


{{note|arrayoffset}} An array offset basically is a variable number. If it's a global array, the offset is a global variable index from which the array begins. For example, if the global array offset is 150 (<code>{{hint|96 00|little-endian}}</code>) it means that the first element of the array is <span style="color:blue">$150</span>, the second one is <span style="color:blue">$151</span>, etc. Same valid for the local arrays (offset is a local variable index). <!-- global variables are multiplied by 4-->
An array offset basically is a variable number. If it's a global array, the offset is a global variable index from which the array begins. For example, if the global array offset is 150 (<code>{{hint|96 00|little-endian}}</code>) it means that the first element of the array is <span style="color:blue">$150</span>, the second one is <span style="color:blue">$151</span>, etc. Same valid for the local arrays (offset is a local variable index). <!-- global variables are multiplied by 4-->


{{note|arrayindex}} An array index is a variable number (global or local one) that holds the value of array index. For example, if array index is 3 (<code>{{hint|03 00|little-endian}}</code>), the game will read either global variable <span style="color:blue">$3</span> or local variable <span style="color:blue">3@</span> depending on the flags. This variable holds the number which is array element ID to work with. For example, if the array index is <span style="color:blue">$3</span>, and <span style="color:blue">$3</span> holds number <span style="color:maroon">5</span>, the game will read 5th element of the array.
An array index is a variable number (global or local one) that holds the value of array index. For example, if array index is 3 (<code>{{hint|03 00|little-endian}}</code>), the game will read either global variable <span style="color:blue">$3</span> or local variable <span style="color:blue">3@</span> depending on the flags. This variable holds the number which is array element ID to work with. For example, if the array index is <span style="color:blue">$3</span>, and <span style="color:blue">$3</span> holds number <span style="color:maroon">5</span>, the game will read 5th element of the array.


{{note|arrayflags}} Flags  
Flags  
{|class="prettytable"
{|class="prettytable"
|-
|-
Line 218: Line 218:


=== Notes ===
=== Notes ===
{{note|vcstr}} In GTA III and GTA Vice City short strings (8 bytes) have no data type preceeding it. If the byte does not fit data type range (0..6 for GTA III and GTA Vice City), it's recognized as a beginning of a string and next 8 bytes are read.
In GTA III and GTA Vice City short strings (8 bytes) have no data type preceeding it. If the byte does not fit data type range (0..6 for GTA III and GTA Vice City), it's recognized as a beginning of a string and next 8 bytes are read.


{{note|partype0}} Some opcodes have variable amount of parameters. Most known opcode is [[004F]] that creates a new [[thread]] and passes arguments to it. The number of such parameters could vary, so the special data type denotes the end of parameters.
Some opcodes have variable amount of parameters. Most known opcode is [[004F]] that creates a new [[thread]] and passes arguments to it. The number of such parameters could vary, so the special data type denotes the end of parameters.


The maximum amount of parameters for any opcode is 16 for GTA III and GTA Vice City, 32 for GTA San Andreas.
The maximum amount of parameters for any opcode is 16 for GTA III and GTA Vice City, 32 for GTA San Andreas.


{{note|05B6}} {{Icon|SA}} Opcode [[05B6]] is a special opcode that  defines a table. Immediately after opcode number the stream of data (128 bytes) follow, without a data type.
{{Icon|SA}} Opcode [[05B6]] is a special opcode that  defines a table. Immediately after opcode number the stream of data (128 bytes) follow, without a data type.


== Cracking the SCM ==
== Cracking the SCM ==