Difference between revisions of "SCO"

From GTAMods Wiki
Jump to navigation Jump to search
(the collapsible table much more preferable for the full list)
Line 29: Line 29:
 
===Opcodes===
 
===Opcodes===
  
Opcode's can have varying size's, but all opcodes are identified by their first byte. There are 80 opcodes which can occur, any opcode above 80 is a Push opcode which pushes it's own number - 96 onto the stack.
+
Opcodes can have varying sizes, but all opcodes are identified by their first byte. There are 80 opcodes which can occur, any opcode above 80 is a Push opcode which pushes '''it's own number - 96''' onto the stack.
  
====Add====
+
{|{{Prettytable}} class="collapsible"
 
+
!ID
'''1'''. Adds the top 2 items on the stack.
+
!Name
1 byte in length.
+
!Description
 
+
!Length
====Sub====
+
|-
 
+
|1|| Add || Adds the top 2 items on the stack || 1 byte
'''2'''.Subtracts the top 2 items on the stack.
+
|-
1 byte in length.
+
|2||Sub || Subtracts the top 2 items on the stack || 1 byte
 
+
|-
====Mul====
+
|3|| Mul || Multiplies the top 2 items on the stack || 1 byte
 
+
|-
'''3'''. Multiplies the top 2 items on the stack.
+
|4|| Div || Divides the top 2 items on the stack || 1 byte
1 byte in length.
+
|-
 
+
|5|| Mod || Mods the top 2 items on the stack || 1 byte
====Div====
+
|-
 
+
|6|| IsZero || Checks the first item on the stack to see if it equals 0 || 1 byte
'''4'''. Divides the top 2 items on the stack.
+
|-
1 byte in length.
+
|7|| Neg || Reverses the sign on the item on the top of the stack || 1 byte
 
+
|-
====Mod====
+
|8|| CmpEq || Compares the top 2 integers on the stack to see if they are equal || 1 byte
 
+
|-
'''5'''. Mods the top 2 items on the stack.
+
|9|| CmpNe || Compares the top 2 integers on the stack to see if they are not equal || 1 byte
1 byte in length.
+
|-
 
+
|10|| CmpGt || Compares the top 2 integers on the stack to see if the first one is greater than the second one || 1 byte
====IsZero====
+
|-
 
+
|11|| CmpGe || Compares the top 2 integers on the stack to see if the first one is greater than or equal to the second one || 1 byte
'''6'''. Checks the first item on the stack to see if it equals 0.
+
|-
1 byte in length.
+
|12|| CmpLt || Compares the top 2 integers on the stack to see if the first one is less than the second one || 1 byte
 
+
|-
====Neg====
+
|13|| CmpLe || Compares the top 2 integers on the stack to see if the first one is less than or equal to the second one || 1 byte
 
+
|-
'''7'''. Reverses the sign on the item on the top of the stack.
+
|14|| AddF || Adds the top 2 floats on the stack || 1 byte
1 byte in length.
+
|-
 
+
|15|| SubF || Subtracts the top 2 floats on the stack || 1 byte
====CmpEq====
+
|-
 
+
|16|| MulF || Multiplies the top 2 floats on the stack || 1 byte
'''8'''. Compare's the top 2 integers on the stack to see if they are equal.
+
|-
1 byte in length.
+
|17|| DivF || Divides the top 2 floats on the stack || 1 byte
 
+
|-
====CmpNe====
+
|18|| ModF || Mods the top 2 floats on the stack || 1 byte
 
+
|-
'''9'''. Compare's the top 2 integers on the stack to see if they are not equal.
+
|19|| NegF || Reverses the sign on the first float on the stack || 1 byte
1 byte in length.
+
|-
 
+
|20|| CmpEqF || Compares the top 2 floats on the stack to see if they are equal || 1 byte
====CmpGt====
+
|}
 
 
'''10'''. Compare's the top 2 integers on the stack to see if the first one is greater than the second one.
 
1 byte in length.
 
 
 
====CmpGe====
 
 
 
'''11'''. Compare's the top 2 integers on the stack to see if the first one is greater than or equal to the second one.
 
1 byte in length.
 
 
 
====CmpLt====
 
 
 
'''12'''. Compare's the top 2 integers on the stack to see if the first one is less than the second one.
 
1 byte in length.
 
 
 
====CmpLe====
 
 
 
'''13'''. Compare's the top 2 integers on the stack to see if the first one is less than or equal to the second one.
 
1 byte in length.
 
 
 
====AddF====
 
 
 
'''14'''. Adds the top 2 floats on the stack.
 
1 byte in length.
 
 
 
====SubF====
 
 
 
'''15'''. Subtracts the top 2 floats on the stack.
 
1 byte in length.
 
 
 
====MulF====
 
 
 
'''16'''. Multiplies the top 2 floats on the stack.
 
1 byte in length.
 
 
 
====DivF====
 
 
 
'''17'''. Divides the top 2 floats on the stack.
 
1 byte in length.
 
 
 
====ModF====
 
 
 
'''18'''. Mods the top 2 floats on the stack.
 
1 byte in length.
 
 
 
====NegF====
 
 
 
'''19'''. Reverses the sign on the first float on the stack.
 
1 byte in length.
 
 
 
====CmpEqF====
 
 
 
'''20'''. Compares the top 2 floats on the stack to see if they are equal.
 
1 byte in length.
 
  
 
{{GTA4-navi}}
 
{{GTA4-navi}}
 
[[Category:Mission Script]][[Category:File Formats]]
 
[[Category:Mission Script]][[Category:File Formats]]

Revision as of 11:36, 3 February 2009

SCO files contain GTA 4's game scripts. Its new format replaces old scm one.

File Format

A SCO file is layed out into 4 segments. First the Header containing information about the SCO file. Then the Code Segment which contains the opcode's which govern how the script behaves. The next segment is the Local Variable container which contains enough space to hold the local variables. The last is the Global Variable container, which contains enough space to house the global variables, as well as setting them by default.

Header

There are 2 types of SCO files, an encrypted and unencrypted one. Each file however shares the same unencrypted header structure, and you can use this to determine which type of SCO file you are dealing with. The size of this header is 24 bytes.

4b - CHAR[4]/UINT32 - SCO Identifier
4b - UINT32 - Code Size
4b - UINT32 - Local Var Size
4b - UINT32 - Global Var Size
4b - UINT32 - Script Flags
4b - UINT32 - Signature

The SCO Identifier will be "SCR\r" (or 0xD524353) in an unencrypted version, and "scr"+0xE (or 0xE726373) in an encrypted version. The Code Size refers to the amount of bytes the code section takes up. The Local Var Size refers to the amount of local variables the SCO file contains. The segment for local variables starts at the end of Header + Code Size, and continues for 4x the local variable size (due to the local variables being stored in 4 byte segments). The Global Var Size refers to the amount of global variables the SCO file contains. The segment for global variables starts at the end of Header + Code Size + Local Var Size * 4, and continues for 4x the global variable size (due to the global variables being stored in 4 byte segments). The Script Flags are boolean bits which are currently unexplained. The Signature only differs in navgen_main, but could possibly set the script priority.

Code Segment

The Code Segment contains the opcodes which govern the scripts behaviour.

Opcodes

Opcodes can have varying sizes, but all opcodes are identified by their first byte. There are 80 opcodes which can occur, any opcode above 80 is a Push opcode which pushes it's own number - 96 onto the stack.

ID Name Description Length
1 Add Adds the top 2 items on the stack 1 byte
2 Sub Subtracts the top 2 items on the stack 1 byte
3 Mul Multiplies the top 2 items on the stack 1 byte
4 Div Divides the top 2 items on the stack 1 byte
5 Mod Mods the top 2 items on the stack 1 byte
6 IsZero Checks the first item on the stack to see if it equals 0 1 byte
7 Neg Reverses the sign on the item on the top of the stack 1 byte
8 CmpEq Compares the top 2 integers on the stack to see if they are equal 1 byte
9 CmpNe Compares the top 2 integers on the stack to see if they are not equal 1 byte
10 CmpGt Compares the top 2 integers on the stack to see if the first one is greater than the second one 1 byte
11 CmpGe Compares the top 2 integers on the stack to see if the first one is greater than or equal to the second one 1 byte
12 CmpLt Compares the top 2 integers on the stack to see if the first one is less than the second one 1 byte
13 CmpLe Compares the top 2 integers on the stack to see if the first one is less than or equal to the second one 1 byte
14 AddF Adds the top 2 floats on the stack 1 byte
15 SubF Subtracts the top 2 floats on the stack 1 byte
16 MulF Multiplies the top 2 floats on the stack 1 byte
17 DivF Divides the top 2 floats on the stack 1 byte
18 ModF Mods the top 2 floats on the stack 1 byte
19 NegF Reverses the sign on the first float on the stack 1 byte
20 CmpEqF Compares the top 2 floats on the stack to see if they are equal 1 byte