Difference between revisions of "Script Container"

From GTAMods Wiki
Jump to navigation Jump to search
(Opcode)
(Document new bit test instruction added in the latest GTA V PC version)
(10 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
<source lang="cpp">struct YSCHeader
 
<source lang="cpp">struct YSCHeader
 
{
 
{
QWORD Magic;// 0x00 - Seems to always hold the value D09E5A4001000000
+
QWORD pageBase;// 0x00
QWORD UnkPointer;// 0x08 -Points to a section in script thats always null
+
QWORD pageMapPointer;// 0x08
 
QWORD CodeBlocksBasePointer;// 0x10 Points to an array of code block offsets
 
QWORD CodeBlocksBasePointer;// 0x10 Points to an array of code block offsets
DWORD GlobalsVersion;// 0x18 - Unsure what exactly this means
+
DWORD GlobalsSignature;// 0x18
 
DWORD CodeSize;// 0x1C - The size of all the code tables
 
DWORD CodeSize;// 0x1C - The size of all the code tables
 
DWORD ParameterCount;// 0x20 - These are for starting a script with args. The args appear at the start of the script static variables
 
DWORD ParameterCount;// 0x20 - These are for starting a script with args. The args appear at the start of the script static variables
Line 29: Line 29:
 
DWORD Null4;//0x7C
 
DWORD Null4;//0x7C
 
};</source>
 
};</source>
All Pointer items are stored in the file as 0xXXXXXX50 and must therefore be masked with 0xFFFFFF to get their actual file offset.
+
All Pointer items are stored in the file as 0x50XXXXXX and must therefore be masked with 0xFFFFFF to get their actual file offset.
  
 
===Pages===
 
===Pages===
 
The Code and Strings used by the script are stored in pages, each one up to a maximum size of 0x4000 bytes. The number of pages used can be calculated based of the CodeSize/StringSize using this:
 
The Code and Strings used by the script are stored in pages, each one up to a maximum size of 0x4000 bytes. The number of pages used can be calculated based of the CodeSize/StringSize using this:
<source lang="cpp">int pagegCount = (totalSize + 0x3FFF) >> 14;</source>
+
<source lang="cpp">int pageCount = (totalSize + 0x3FFF) >> 14;</source>
 
The size of each of the pages can be calculated using this function
 
The size of each of the pages can be calculated using this function
 
<source lang="cpp">int pageSize(int pageIndex, int totalSize)
 
<source lang="cpp">int pageSize(int pageIndex, int totalSize)
 
{
 
{
if (pageIndex >= (totalSize >> 14)){
+
if (pageIndex > (totalSize >> 14) || pageIndex < 0){//page out of range
 +
return 0;
 +
}else if (pageIndex == (totalSize >> 14)){
 
return totalSize & 0x3FFF;
 
return totalSize & 0x3FFF;
 
}
 
}
 
return 0x4000;
 
return 0x4000;
 
}</source>
 
}</source>
 +
 
===Code===
 
===Code===
 
The Poistion of each of the code pages can be found by reading the positions stored in the array pointer to from CodeBlocksBasePointer, then you can read up to pageSize in that page. The code itself is a set of 127 opcodes that is ran on a stack machine.
 
The Poistion of each of the code pages can be found by reading the positions stored in the array pointer to from CodeBlocksBasePointer, then you can read up to pageSize in that page. The code itself is a set of 127 opcodes that is ran on a stack machine.
Line 53: Line 56:
 
!
 
!
 
|-
 
|-
|0|| nop || No operation || 1 byte
+
|0|| NOP || No operation || 1 byte
 +
|-
 +
|1|| IADD || Adds the top 2 items on the stack || 1 byte
 +
|-
 +
|2|| ISUB || Subtracts the top 2 items on the stack || 1 byte
 +
|-
 +
|3|| IMUL || Multiplies the top 2 items on the stack || 1 byte
 +
|-
 +
|4|| IDIV || Divides the top 2 items on the stack || 1 byte
 +
|-
 +
|5|| IMOD || Mods the top 2 items on the stack || 1 byte
 +
|-
 +
|6|| INOT || Checks the first item on the stack to see if it equals 0 || 1 byte
 +
|-
 +
|7|| INEG || Reverses the sign on the item on the top of the stack || 1 byte
 +
|-
 +
|8|| IEQ || Compares the top 2 integers on the stack to see if they are equal || 1 byte
 +
|-
 +
|9|| INE || Compares the top 2 integers on the stack to see if they are not equal || 1 byte
 +
|-
 +
|10|| IGT || Compares the top 2 integers on the stack to see if the first one is greater than the second one || 1 byte
 +
|-
 +
|11|| IGE || 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|| ILT || Compares the top 2 integers on the stack to see if the first one is less than the second one || 1 byte
 +
|-
 +
|13|| ILE || 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|| FADD || Adds the top 2 floats on the stack || 1 byte
 +
|-
 +
|15|| FSUB || Subtracts the top 2 floats on the stack || 1 byte
 +
|-
 +
|16|| FMUL || Multiplies the top 2 floats on the stack || 1 byte
 +
|-
 +
|17|| FDIV || Divides the top 2 floats on the stack || 1 byte
 +
|-
 +
|18|| FMOD || Mods the top 2 floats on the stack || 1 byte
 +
|-
 +
|19|| FNEG || Reverses the sign on the first float on the stack || 1 byte
 +
|-
 +
|20|| FEQ || Compares the top 2 floats on the stack to see if they are equal || 1 byte
 +
|-
 +
|21|| FNE || Compares the top 2 floats on the stack to see if they are not equal || 1 byte
 +
|-
 +
|22|| FGT || Compares the top 2 floats on the stack to see if the first one is greater than the second one || 1 byte
 +
|-
 +
|23|| FGE || Compares the top 2 floats on the stack to see if the first one is greater than or equal to the second one || 1 byte
 +
|-
 +
|24|| FLT || Compares the top 2 floats on the stack to see if the first one is less than the second one || 1 byte
 +
|-
 +
|25|| FLE || Compares the top 2 floats on the stack to see if the first one is less than or equal to the second one || 1 byte
 +
|-
 +
|26|| VADD || Adds the top 2 Vectors{{Ref|1}} on the stack || 1 byte
 +
|-
 +
|27|| VSUB || Subtracts the top 2 Vectors{{Ref|1}} on the stack || 1 byte
 +
|-
 +
|28|| VMUL || Multiplies the top 2 Vectors{{Ref|1}} on the stack || 1 byte
 +
|-
 +
|29|| VDIV || Divides the top 2 Vectors{{Ref|1}} on the stack || 1 byte
 +
|-
 +
|30|| VNEG || Reverses the sign on the first vector{{Ref|1}} on the stack || 1 byte
 +
|-
 +
|31|| IAND || Performs an [[Wikipedia:Logical_conjunction|And]] operation to the first 2 integers on the stack || 1 byte
 +
|-
 +
|32|| IOR || Performs an [[Wikipedia:Logical_disjunction|Or]] operation to the first 2 integers on the stack || 1 byte
 +
|-
 +
|33|| IXOR || Performs a [[Wikipedia:XOR|Xor]] operation to the first 2 integers on the stack || 1 byte
 +
|-
 +
|34|| I2F || Converts the top integer on the stack to a float, and puts that float on the stack || 1 byte
 +
|-
 +
|35|| F2I || Converts the top float on the stack to an integer, and puts that integer on the stack || 1 byte
 +
|-
 +
|36|| F2V || Converts the top float into a Vector containing 3 instances of the same float, and pushes the pointer to that Vector onto the top of the stack || 1 byte
 +
|-
 +
|37|| PUSH_CONST_U8 || Pushes a byte onto the stack, the byte is defined as the next byte after the opcode || 2 bytes
 +
|-
 +
|38|| PUSH_CONST_U8_U8 || Pushes 2 bytes onto the stack, the bytes are the next 2 bytes after the opcode || 3 bytes
 +
|-
 +
|39|| PUSH_CONST_U8_U8_U8 || Pushes 3 bytes onto the stack, the bytes are the next 3 bytes after the opcode || 4 bytes
 +
|-
 +
|40|| PUSH_CONST_U32 || Pushes an int onto the stack, the integer is defined in the next 4 bytes after the opcode || 5 bytes
 +
|-
 +
|41|| PUSH_CONST_F || Pushes a float onto the stack, the float is defined in the next 4 bytes after the opcode || 5 bytes
 +
|-
 +
|42|| DUP || Duplicates the first item on the stack, and pushes it back onto the stack || 1 byte
 +
|-
 +
|43|| DROP || Pops the top item off the stack || 1 byte
 +
|-
 +
|44|| NATIVE || Calls a [[native function]]. The number of arguments for the native to take is defined in the first 6 bits of the next byte after the opcode(0-63). The number of returns is stored in the following 2 bits(0-3). The hash of the native functions is stored in the native table at the index specified by the following 2 bytes(expressed as an unsigned short) || 4 bytes
 
|-
 
|-
|1|| iadd || Adds the top 2 items on the stack || 1 byte
+
|45|| ENTER || Indicates the beginning of an internal function. The byte after the opcode indicates the amount of arguments the function takes off the stack, and the next 2 bytes after that indicate the number of variables the function will have to generate on the stack. The following byte indicates how many bytes to skip past after the opcode(usually so a name can be appended to the function definition)|| 5 bytes + value of 5th byte
 
|-
 
|-
|2|| isub || Subtracts the top 2 items on the stack || 1 byte
+
|46|| LEAVE || Indicates the end of an internal function. The byte after the opcode indicates the amount of arguments that will have to be popped off the stack, and the next byte after that indicates the stack number of the return address || 3 bytes
 
|-
 
|-
|3|| imul || Multiplies the top 2 items on the stack || 1 byte
+
|47|| LOAD || Pops a pointer off the stack and pushes the value stored in that pointer back onto the stack || 1 byte
 
|-
 
|-
|4|| idiv || Divides the top 2 items on the stack || 1 byte
+
|48|| STORE || Pops 2 items off the stack and stores the second item at the location of the first item (the first item being a pointer) || 1 byte
 
|-
 
|-
|5|| imod || Mods the top 2 items on the stack || 1 byte
+
|49|| STORE_REV || Pops the first item off the stack and peeks at the second item on the stack, then stores the first item at the location pointed to by the second item on the stack || 1 byte
 
|-
 
|-
|6|| iszero || Checks the first item on the stack to see if it equals 0 || 1 byte
+
|50|| LOAD_N || Pops 2 items off the stack, the first being the number of items, second being the memory address. It then pushes that many items to the stack from the memory address || 1 byte
 
|-
 
|-
|7|| ineg || Reverses the sign on the item on the top of the stack || 1 byte
+
|51|| STORE_N || Pops 2 items off the stack, the first being the number of items, second being the memory address. It then pops that many items from the stack to the memory address || 1 byte
 
|-
 
|-
|8|| icmpeq || Compares the top 2 integers on the stack to see if they are equal || 1 byte
+
|52|| ARRAY_U8 || Pops 2 items off the stack, the first being an array index, second being the pointer to an array. It then pushes the pointer to theindex in the array to the top of the stack. The size each item in the array is determined by the byte following the opcode|| 2 bytes
 
|-
 
|-
|9|| icmpne || Compares the top 2 integers on the stack to see if they are not equal || 1 byte
+
|53|| ARRAY_U8_LOAD || Pops 2 items off the stack, the first being an array index, second being the pointer to an array. It then pushes the item at the array index to the top of the stack. The size each item in the array is determined by the byte following the opcode|| 2 bytes
 
|-
 
|-
|10|| icmpgt || Compares the top 2 integers on the stack to see if the first one is greater than the second one || 1 byte
+
|54|| ARRAY_U8_STORE || Pops 3 items off the stack, the first being the value to set, second being an array index and last being the pointer to an array. It the sets the value at the index in the array to first value. The size each item in the array is determined by the byte following the opcode|| 2 bytes
 
|-
 
|-
|11|| icmpge || 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
+
|55|| LOCAL_U8 || Pushes the pointer to the frame variable at the index specified by the byte following the opcode || 2 bytes
 
|-
 
|-
|12|| icmplt || Compares the top 2 integers on the stack to see if the first one is less than the second one || 1 byte
+
|56|| LOCAL_U8_LOAD || Pushes the value of the frame variable at the index specified by the byte following the opcode || 2 bytes
 
|-
 
|-
|13|| icmple || 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
+
|57|| LOCAL_U8_STORE || Pops an item off the stack, then sets the frame variable at the index specified by the byte following the opcode to the item || 2 bytes
 
|-
 
|-
|14|| fadd || Adds the top 2 floats on the stack || 1 byte
+
|58|| STATIC_U8 || Pushes the pointer to the static variable at the index specified by the byte following the opcode || 2 bytes
 
|-
 
|-
|15|| fsub || Subtracts the top 2 floats on the stack || 1 byte
+
|59|| STATIC_U8_LOAD || Pushes the value of the static variable at the index specified by the byte following the opcode || 2 bytes
 
|-
 
|-
|16|| fmul || Multiplies the top 2 floats on the stack || 1 byte
+
|60|| STATIC_U8_STORE || Pops an item off the stack, then sets the static variable at the index specified by the byte following the opcode to the item || 2 bytes
 
|-
 
|-
|17|| fdiv || Divides the top 2 floats on the stack || 1 byte
+
|61|| IADD_U8 || Adds the byte directly after the opcode to the integer value at the top of the stack, then pushes the new value to the top of the stack || 2 bytes
 
|-
 
|-
|18|| fmod || Mods the top 2 floats on the stack || 1 byte
+
|62|| IMUL_U8 || Multiplies the byte directly after the opcode to the integer value at the top of the stack, then pushes the new value to the top of the stack || 2 bytes
 
|-
 
|-
|19|| fneg || Reverses the sign on the first float on the stack || 1 byte
+
|63|| IOFFSET || Pops an index and a pointer to a struct off the stack, pushes the pointer to the item at 8 times the index in the struct || 1 byte
 
|-
 
|-
|20|| fcmpeq || Compares the top 2 floats on the stack to see if they are equal || 1 byte
+
|64|| IOFFSET_U8 || Pops an pointer to a struct off the stack, pushes the pointer to the item at the index specified by 8 times the byte following the opcode || 2 bytes
 
|-
 
|-
|21|| fcmpne || Compares the top 2 floats on the stack to see if they are not equal || 1 byte
+
|65|| IOFFSET_U8_LOAD || Pops an pointer to a struct off the stack, pushes the value of the item at the index specified by 8 times the byte following the opcode || 2 bytes
 
|-
 
|-
|22|| fcmpgt || Compares the top 2 floats on the stack to see if the first one is greater than the second one || 1 byte
+
|66|| IOFFSET_U8_STORE || Pops an value and a pointer to a struct off the stack, sets the item at the index specified by 8 times the byte following the opcode to the value popped of the stack || 2 bytes
 
|-
 
|-
|23|| fcmpge || Compares the top 2 floats on the stack to see if the first one is greater than or equal to the second one || 1 byte
+
|67|| PUSH_CONST_S16 || Pushes a signed short to the stack, the value is the 2 bytes following the opcode || 3 bytes
 
|-
 
|-
|24|| fcmplt || Compares the top 2 floats on the stack to see if the first one is less than the second one || 1 byte
+
|68|| IADD_S16 || Adds the short directly after the opcode to the integer value at the top of the stack, then pushes the new value to the top of the stack || 3 bytes
 
|-
 
|-
|25|| fcmple || Compares the top 2 floats on the stack to see if the first one is less than or equal to the second one || 1 byte
+
|69|| IMUL_S16 || Multiplies the short directly after the opcode to the integer value at the top of the stack, then pushes the new value to the top of the stack || 3 bytes
 
|-
 
|-
|26|| vadd || Adds the top 2 Vectors{{Ref|1}} on the stack || 1 byte
+
|70|| IOFFSET_S16 || Pops an pointer to a struct off the stack, pushes the pointer to the item at the index specified by 8 times the 2 bytes following the opcode || 3 bytes
 
|-
 
|-
|27|| vsub || Subtracts the top 2 Vectors{{Ref|1}} on the stack || 1 byte
+
|71|| IOFFSET_S16_LOAD || Pops an pointer to a struct off the stack, pushes the value of the item at the index specified by 8 times the 2 bytes following the opcode || 3 bytes
 
|-
 
|-
|28|| vmul || Multiplies the top 2 Vectors{{Ref|1}} on the stack || 1 byte
+
|72|| IOFFSET_S16_STORE || Pops an value and a pointer to a struct off the stack, sets the item at the index specified by 8 times the 2 bytes following the opcode to the value popped of the stack || 3 bytes
 
|-
 
|-
|29|| vdiv || Divides the top 2 Vectors{{Ref|1}} on the stack || 1 byte
+
|73|| ARRAY_U16 || Pops 2 items off the stack, the first being an array index, second being the pointer to an array. It then pushes the pointer to theindex in the array to the top of the stack. The size each item in the array is determined by the 2 bytes following the opcode|| 3 bytes
 
|-
 
|-
|30|| vneg || Reverses the sign on the first vector{{Ref|1}} on the stack || 1 byte
+
|74|| ARRAY_U16_LOAD || Pops 2 items off the stack, the first being an array index, second being the pointer to an array. It then pushes the item at the array index to the top of the stack. The size each item in the array is determined by the 2 bytes following the opcode|| 3 bytes
 
|-
 
|-
|31|| iand || Performs an [[Wikipedia:Logical_conjunction|And]] operation to the first 2 integers on the stack || 1 byte
+
|75|| ARRAY_U16_STORE || Pops 3 items off the stack, the first being the value to set, second being an array index and last being the pointer to an array. It the sets the value at the index in the array to first value. The size each item in the array is determined by the 2 bytes following the opcode|| 3 bytes
 
|-
 
|-
|32|| ior || Performs an [[Wikipedia:Logical_disjunction|Or]] operation to the first 2 integers on the stack || 1 byte
+
|76|| LOCAL_U16 || Pushes the pointer to the frame variable at the index specified by the 2 bytes following the opcode || 3 bytes
 
|-
 
|-
|33|| ixor || Performs a [[Wikipedia:XOR|Xor]] operation to the first 2 integers on the stack || 1 byte
+
|77|| LOCAL_U16_LOAD || Pushes the value of the frame variable at the index specified by the 2 bytes following the opcode || 3 bytes
 
|-
 
|-
|34|| itof || Converts the top integer on the stack to a float, and puts that float on the stack || 1 byte
+
|78|| LOCAL_U16_STORE || Pops an item off the stack, then sets the frame variable at the index specified by the 2 bytes following the opcode to the item || 3 bytes
 
|-
 
|-
|35|| ftoi || Converts the top float on the stack to an integer, and puts that integer on the stack || 1 byte
+
|79|| STATIC_U16 || Pushes the pointer to the static variable at the index specified by the 2 bytes following the opcode || 3 bytes
 
|-
 
|-
|36|| ftov || Converts the top float into a Vector containing 3 instances of the same float, and pushes the pointer to that Vector onto the top of the stack || 1 byte
+
|80|| STATIC_U16_LOAD || Pushes the value of the static variable at the index specified by the 2 bytes following the opcode || 3 bytes
 
|-
 
|-
|37|| pushb || Pushes a byte onto the stack, the byte is defined as the next byte after the opcode || 2 bytes
+
|81|| STATIC_U16_STORE || Pops an item off the stack, then sets the static variable at the index specified by the 2 bytes following the opcode to the item || 3 bytes
 
|-
 
|-
|38|| pushb2 || Pushes 2 bytes onto the stack, the bytes are the next 2 bytes after the opcode || 3 bytes
+
|82|| GLOBAL_U16 || Pushes the pointer to the global variable at the index specified by the 2 bytes following the opcode || 3 bytes
 
|-
 
|-
|39|| pushb3 || Pushes 3 bytes onto the stack, the bytes are the next 3 bytes after the opcode || 4 bytes
+
|83|| GLOBAL_U16_LOAD || Pushes the value of the global variable at the index specified by the 2 bytes following the opcode || 3 bytes
 
|-
 
|-
|40|| push || Pushes an int onto the stack, the integer is defined in the next 4 bytes after the opcode || 5 bytes
+
|84|| GLOBAL_U16_STORE || Pops an item off the stack, then sets the global variable at the index specified by the 2 bytes following the opcode to the item || 3 bytes
 
|-
 
|-
|41|| pushf || Pushes a float onto the stack, the float is defined in the next 4 bytes after the opcode || 5 bytes
+
|85|| J || Performs a relative jump to a new location in the code, the relative offset is the signed short following the opcode || 3 bytes
 
|-
 
|-
|42|| dup || Duplicates the first item on the stack, and pushes it back onto the stack || 1 byte
+
|86|| JZ || Performs a relative jump to a new location in the code if the item at the top of the stack is zero, the relative offset is the signed short following the opcode || 3 bytes
 
|-
 
|-
|43|| pop || Pops the top item off the stack || 1 byte
+
|87|| IEQ_JZ || Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is not equal to the second. The relative offset is the signed short following the opcode || 3 bytes
 
|-
 
|-
|44|| native || Calls a [[native function]]. The number of arguments for the native to take is defined in the first 6 bits of the next byte after the opcode(0-63). The number of returns is stored in the following 2 bits(0-3). The hash of the native functions is stored in the native table at the index specified by the following 2 bytes(expressed as an unsigned short) || 4 bytes
+
|88|| INE_JZ || Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is equal to the second. The relative offset is the signed short following the opcode || 3 bytes
 
|-
 
|-
|45|| enter || Indicates the beginning of an internal function. The byte after the opcode indicates the amount of arguments the function takes off the stack, and the next 2 bytes after that indicate the number of variables the function will have to generate on the stack. The following byte indicates how many bytes to skip past after the opcode(usually so a name can be appended to the function definition)|| 5 bytes + value of 5th byte
+
|89|| IGT_JZ || Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is less than or equal to the second. The relative offset is the signed short following the opcode || 3 bytes
 
|-
 
|-
|46|| ret || Indicates the end of an internal function. The byte after the opcode indicates the amount of arguments that will have to be popped off the stack, and the next byte after that indicates the stack number of the return address || 3 bytes
+
|90|| IGE_JZ || Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is less than the second. The relative offset is the signed short following the opcode || 3 bytes
 
|-
 
|-
|47|| pget || Pops a pointer off the stack and pushes the value stored in that pointer back onto the stack || 1 byte
+
|91|| ILT_JZ || Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is greater than or equal to the second. The relative offset is the signed short following the opcode || 3 bytes
 
|-
 
|-
|48|| pset || Pops 2 items off the stack and stores the second item at the location of the first item (the first item being a pointer) || 1 byte
+
|92|| ILE_JZ || Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is greater than the second. The relative offset is the signed short following the opcode || 3 bytes
 
|-
 
|-
|49|| peekset || Pops the first item off the stack and peeks at the second item on the stack, then stores the first item at the location pointed to by the second item on the stack || 1 byte
+
|93|| CALL || Calls a function within the script, and puts the return address on top of the stack. The location of the function is defined in the next 3 bytes after the opcode || 4 bytes
 
|-
 
|-
|50|| tostack || Pops 2 items off the stack, the first being the number of items, second being the memory address. It then pushes that many items to the stack from the memory address || 1 byte
+
|94|| GLOBAL_U24 || Pushes the pointer to the global variable at the index specified by the 3 bytes following the opcode || 4 bytes
 
|-
 
|-
|51|| fromstack || Pops 2 items off the stack, the first being the number of items, second being the memory address. It then pops that many items from the stack to the memory address || 1 byte
+
|95|| GLOBAL_U24_LOAD || Pushes the value of the global variable at the index specified by the 3 bytes following the opcode || 4 bytes
 
|-
 
|-
|52|| getarrayp1 || Pops 2 items off the stack, the first being an array index, second being the pointer to an array. It then pushes the pointer to theindex in the array to the top of the stack. The size each item in the array is determined by the byte following the opcode|| 2 byte
+
|96|| GLOBAL_U24_STORE || Pops an item off the stack, then sets the global variable at the index specified by the 3 bytes following the opcode to the item || 4 bytes
 
|-
 
|-
|53|| getarray1 || Pops 2 items off the stack, the first being an array index, second being the pointer to an array. It then pushes the item at the array index to the top of the stack. The size each item in the array is determined by the byte following the opcode|| 2 byte
+
|97|| PUSH_CONST_U24 || Pushes an unsigned 24 bit integer to the stack, the value is the 3 bytes following the opcode || 4 bytes
 
|-
 
|-
|54|| setarray1 || Pops 3 items off the stack, the first being the value to set, second being an array index and last being the pointer to an array. It the sets the value at the index in the array to first value. The size each item in the array is determined by the byte following the opcode|| 2 byte
+
|98|| SWITCH || Pops the item to compare off the stack, and then jumps to location corresponding to that item. After the opcode byte it contains a byte defining the number of possible entries, and after that the number of possible entries times 6 are taken up with repeating instances of 4 bytes of the index identifier, and 2 bytes of the relative jump offset to jump to if that index is correct (note jump offset is unsigned unlike branch instructions) || (Byte after opcode * 6) + 2 bytes
 
|-
 
|-
|55|| getframep1 || Pushes the pointer to the frame variable at the index specified by the byte following the opcode || 2 bytes
+
|99|| STRING || Pops an integer off the stack, then returns the pointer to the string stored at that index in the String Table || 1 byte
 
|-
 
|-
|56|| getframe1 || Pushes the value of the frame variable at the index specified by the byte following the opcode || 2 bytes
+
|100|| STRINGHASH || Pops the pointer to a string off the stack. The computes a jenkins-one-at-a-time hash on the string and pushes the result to the stack || 1 byte
 
|-
 
|-
|57|| setframe1 || Pops an item off the stack, then sets the frame variable at the index specified by the byte following the opcode to the item || 2 bytes
+
|101|| TEXT_LABEL_ASSIGN_STRING || Pops a pointer to a destination buffer and a string, copies the string to the destination buffer. The size of the buffer is specified in the byte following the opcode || 2 bytes
 
|-
 
|-
|58|| getstaticp1 || Pushes the pointer to the static variable at the index specified by the byte following the opcode || 2 bytes
+
|102|| TEXT_LABEL_ASSIGN_INT || Pops a pointer to a destination buffer and a integer, converts the integer to a string and stores it in the destination buffer. The size of the buffer is specified in the byte following the opcode || 2 bytes
 
|-
 
|-
|59|| getstatic1 || Pushes the value of the static variable at the index specified by the byte following the opcode || 2 bytes
+
|103|| TEXT_LABEL_APPEND_STRING || Pops a pointer to a destination buffer and a string, appends the string to the string in the destination buffer. The size of the buffer is specified in the byte following the opcode || 2 bytes
 
|-
 
|-
|60|| setstatic1 || Pops an item off the stack, then sets the static variable at the index specified by the byte following the opcode to the item || 2 bytes
+
|104|| TEXT_LABEL_APPEND_INT || Pops a pointer to a destination buffer and a integer, converts the integer to a string and appends it to the string in the destination buffer. The size of the buffer is specified in the byte following the opcode || 2 bytes
 
|-
 
|-
|61|| addi || Adds the byte directly after the opcode to the integer value at the top of the stack, then pushes the new value to the top of the stack || 2 bytes
+
|105|| TEXT_LABEL_COPY || Pops 3 items off the stack. Copies the third item's memory into the first item's memory with repeating defined by the second item. It then appends a null terminator to the first item's memory || 1 byte
 
|-
 
|-
|62|| multi || Multiplies the byte directly after the opcode to the integer value at the top of the stack, then pushes the new value to the top of the stack || 2 bytes
+
|106|| CATCH || Sets up a safe area that has the ability to catch errors - not used in release builds of GTA || 1 byte
 +
|-
 +
|107|| THROW || Indicates an area that handles a script error relative to the catch opcode - not used in release builds of GTA || 1 byte
 +
|-
 +
|108|| CALLINDIRECT || Calls a function within the script, and puts the return address on top of the stack. The location of the function is defined in the integer at the top of the stack || 1 byte
 +
|-
 +
|109|| PUSH_CONST_M1 || Pushes the integer -1 to the top of the stack || 1 byte
 +
|-
 +
|110|| PUSH_CONST_0 || Pushes the integer 0 to the top of the stack || 1 byte
 +
|-
 +
|111|| PUSH_CONST_1 || Pushes the integer 1 to the top of the stack || 1 byte
 +
|-
 +
|112|| PUSH_CONST_2 || Pushes the integer 2 to the top of the stack || 1 byte
 +
|-
 +
|113|| PUSH_CONST_3 || Pushes the integer 3 to the top of the stack || 1 byte
 +
|-
 +
|114|| PUSH_CONST_4 || Pushes the integer 4 to the top of the stack || 1 byte
 +
|-
 +
|115|| PUSH_CONST_5 || Pushes the integer 5 to the top of the stack || 1 byte
 +
|-
 +
|116|| PUSH_CONST_6 || Pushes the integer 6 to the top of the stack || 1 byte
 +
|-
 +
|117|| PUSH_CONST_7 || Pushes the integer 7 to the top of the stack || 1 byte
 +
|-
 +
|118|| PUSH_CONST_FM1 || Pushes the float -1.0 to the top of the stack || 1 byte
 +
|-
 +
|119|| PUSH_CONST_F0 || Pushes the float 0.0 to the top of the stack || 1 byte
 +
|-
 +
|120|| PUSH_CONST_F1 || Pushes the float 1.0 to the top of the stack || 1 byte
 +
|-
 +
|121|| PUSH_CONST_F2 || Pushes the float 2.0 to the top of the stack || 1 byte
 +
|-
 +
|122|| PUSH_CONST_F3 || Pushes the float 3.0 to the top of the stack || 1 byte
 +
|-
 +
|123|| PUSH_CONST_F4 || Pushes the float 4.0 to the top of the stack || 1 byte
 +
|-
 +
|124|| PUSH_CONST_F5 || Pushes the float 5.0 to the top of the stack || 1 byte
 +
|-
 +
|125|| PUSH_CONST_F6 || Pushes the float 6.0 to the top of the stack || 1 byte
 +
|-
 +
|126|| PUSH_CONST_F7 || Pushes the float 7.0 to the top of the stack || 1 byte
 +
|-
 +
|127|| IS_BIT_SET || '''Added in v1.0.2612.1'''. Pops the value and the bit to test from the stack and pushes the result of value & (1 << bit). Replaced the IS_BIT_SET native || 1 byte
 
|}
 
|}
tbc...
+
 
 +
===Native Functions===
 +
All Natives used by the script are stored in a table of hashes (seemingly random unlike on X360/PS3 versions where they were a jenkins hash of the native name). The address of the table and size can be read from the YSC Header. The native hashes are rotated right by the size of the codeSize + the index of the native in the table. To get the hash of a native from a native table index use this. The nativeTable can be got from reading the pointer from the header and masking it with 0xFFFFFF. Then returning that position in the YSC File.
 +
<source lang="cpp">QWORD getNativeHash(WORD index, const QWORD* nativeTable, DWORD codeSize)
 +
{
 +
BYTE rotate = (index + codeSize) & 0x3F;
 +
return nativeTable[index] << rotate | nativeTable[index] >> (64 - rotate);
 +
}</source>
 +
Since game version b350. Rockstar began changing the hashes of the natives each game update. Its unsure if they are random or not, but either way trying to disassemble scripts in patch b350 or later will require translating all hashes from the nativeTable(after rotating them) into their vanilla game hash. This can be done using the translation tables Alexander Blade provides in here: {{GTAF|717612|Script/Native Documentation}}
 +
 
 +
{{GTA5-navi}}
 +
[[Category:Mission Script]][[Category:File Formats]]

Revision as of 04:37, 1 May 2022

YSC files contain GTA V's game scripts. The new format is an adaptation of the script container format used in Red Dead Redemption.

File Format

The basic format of YSC starts with a header that's 0x80 bytes in size, there are still some unknowns in the header but for basic dissassembling you have enough information.

struct YSCHeader
{
	QWORD pageBase;// 0x00
	QWORD pageMapPointer;// 0x08
	QWORD CodeBlocksBasePointer;// 0x10 Points to an array of code block offsets
	DWORD GlobalsSignature;// 0x18
	DWORD CodeSize;// 0x1C - The size of all the code tables
	DWORD ParameterCount;// 0x20 - These are for starting a script with args. The args appear at the start of the script static variables
	DWORD StaticCount;// 0x24 - The number of static variables in the script
	DWORD GlobalCount;// 0x28 - This is used for scripts that seem to initialise global variable tables
	DWORD NativesCount;// 0x2C - The total amount of natives in the native table
	QWORD StaticsPointer;// 0x30 - The Offset in file where static variables are initialised
	QWORD GlobalsPointer;// 0x38 - The Offset in file where global variales are initilaised(only used for registration scripts)
	QWORD NativesPointer;// 0x40 - The Offset in file where the natives table is stored
	QWORD Null1;//0x48
	QWORD Null2;//0x50;
	DWORD ScriptNameHash;//0x58 - A Jenkins hash of the scripts name
	DWORD UnkUsually1;//0x5C
	QWORD ScriptNamePointer;//0x60 - Points to an offset in the file that has the name of the script
	QWORD StringBlocksBasePointer;//0x68 - Points to an array of string block offsets
	DWORD StringSize;//0x70 - The Size of all the string tables
	DWORD Null3;//0x74
	DWORD Null4;//0x78
	DWORD Null4;//0x7C
};

All Pointer items are stored in the file as 0x50XXXXXX and must therefore be masked with 0xFFFFFF to get their actual file offset.

Pages

The Code and Strings used by the script are stored in pages, each one up to a maximum size of 0x4000 bytes. The number of pages used can be calculated based of the CodeSize/StringSize using this:

int pageCount = (totalSize + 0x3FFF) >> 14;

The size of each of the pages can be calculated using this function

int pageSize(int pageIndex, int totalSize)
{
	if (pageIndex > (totalSize >> 14) || pageIndex < 0){//page out of range
		return 0;
	}else if (pageIndex == (totalSize >> 14)){
		return totalSize & 0x3FFF;
	}
	return 0x4000;
}

Code

The Poistion of each of the code pages can be found by reading the positions stored in the array pointer to from CodeBlocksBasePointer, then you can read up to pageSize in that page. The code itself is a set of 127 opcodes that is ran on a stack machine.

Opcodes

ID Name Description Length
0 NOP No operation 1 byte
1 IADD Adds the top 2 items on the stack 1 byte
2 ISUB Subtracts the top 2 items on the stack 1 byte
3 IMUL Multiplies the top 2 items on the stack 1 byte
4 IDIV Divides the top 2 items on the stack 1 byte
5 IMOD Mods the top 2 items on the stack 1 byte
6 INOT Checks the first item on the stack to see if it equals 0 1 byte
7 INEG Reverses the sign on the item on the top of the stack 1 byte
8 IEQ Compares the top 2 integers on the stack to see if they are equal 1 byte
9 INE Compares the top 2 integers on the stack to see if they are not equal 1 byte
10 IGT Compares the top 2 integers on the stack to see if the first one is greater than the second one 1 byte
11 IGE 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 ILT Compares the top 2 integers on the stack to see if the first one is less than the second one 1 byte
13 ILE 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 FADD Adds the top 2 floats on the stack 1 byte
15 FSUB Subtracts the top 2 floats on the stack 1 byte
16 FMUL Multiplies the top 2 floats on the stack 1 byte
17 FDIV Divides the top 2 floats on the stack 1 byte
18 FMOD Mods the top 2 floats on the stack 1 byte
19 FNEG Reverses the sign on the first float on the stack 1 byte
20 FEQ Compares the top 2 floats on the stack to see if they are equal 1 byte
21 FNE Compares the top 2 floats on the stack to see if they are not equal 1 byte
22 FGT Compares the top 2 floats on the stack to see if the first one is greater than the second one 1 byte
23 FGE Compares the top 2 floats on the stack to see if the first one is greater than or equal to the second one 1 byte
24 FLT Compares the top 2 floats on the stack to see if the first one is less than the second one 1 byte
25 FLE Compares the top 2 floats on the stack to see if the first one is less than or equal to the second one 1 byte
26 VADD Adds the top 2 Vectors[1] on the stack 1 byte
27 VSUB Subtracts the top 2 Vectors[1] on the stack 1 byte
28 VMUL Multiplies the top 2 Vectors[1] on the stack 1 byte
29 VDIV Divides the top 2 Vectors[1] on the stack 1 byte
30 VNEG Reverses the sign on the first vector[1] on the stack 1 byte
31 IAND Performs an And operation to the first 2 integers on the stack 1 byte
32 IOR Performs an Or operation to the first 2 integers on the stack 1 byte
33 IXOR Performs a Xor operation to the first 2 integers on the stack 1 byte
34 I2F Converts the top integer on the stack to a float, and puts that float on the stack 1 byte
35 F2I Converts the top float on the stack to an integer, and puts that integer on the stack 1 byte
36 F2V Converts the top float into a Vector containing 3 instances of the same float, and pushes the pointer to that Vector onto the top of the stack 1 byte
37 PUSH_CONST_U8 Pushes a byte onto the stack, the byte is defined as the next byte after the opcode 2 bytes
38 PUSH_CONST_U8_U8 Pushes 2 bytes onto the stack, the bytes are the next 2 bytes after the opcode 3 bytes
39 PUSH_CONST_U8_U8_U8 Pushes 3 bytes onto the stack, the bytes are the next 3 bytes after the opcode 4 bytes
40 PUSH_CONST_U32 Pushes an int onto the stack, the integer is defined in the next 4 bytes after the opcode 5 bytes
41 PUSH_CONST_F Pushes a float onto the stack, the float is defined in the next 4 bytes after the opcode 5 bytes
42 DUP Duplicates the first item on the stack, and pushes it back onto the stack 1 byte
43 DROP Pops the top item off the stack 1 byte
44 NATIVE Calls a native function. The number of arguments for the native to take is defined in the first 6 bits of the next byte after the opcode(0-63). The number of returns is stored in the following 2 bits(0-3). The hash of the native functions is stored in the native table at the index specified by the following 2 bytes(expressed as an unsigned short) 4 bytes
45 ENTER Indicates the beginning of an internal function. The byte after the opcode indicates the amount of arguments the function takes off the stack, and the next 2 bytes after that indicate the number of variables the function will have to generate on the stack. The following byte indicates how many bytes to skip past after the opcode(usually so a name can be appended to the function definition) 5 bytes + value of 5th byte
46 LEAVE Indicates the end of an internal function. The byte after the opcode indicates the amount of arguments that will have to be popped off the stack, and the next byte after that indicates the stack number of the return address 3 bytes
47 LOAD Pops a pointer off the stack and pushes the value stored in that pointer back onto the stack 1 byte
48 STORE Pops 2 items off the stack and stores the second item at the location of the first item (the first item being a pointer) 1 byte
49 STORE_REV Pops the first item off the stack and peeks at the second item on the stack, then stores the first item at the location pointed to by the second item on the stack 1 byte
50 LOAD_N Pops 2 items off the stack, the first being the number of items, second being the memory address. It then pushes that many items to the stack from the memory address 1 byte
51 STORE_N Pops 2 items off the stack, the first being the number of items, second being the memory address. It then pops that many items from the stack to the memory address 1 byte
52 ARRAY_U8 Pops 2 items off the stack, the first being an array index, second being the pointer to an array. It then pushes the pointer to theindex in the array to the top of the stack. The size each item in the array is determined by the byte following the opcode 2 bytes
53 ARRAY_U8_LOAD Pops 2 items off the stack, the first being an array index, second being the pointer to an array. It then pushes the item at the array index to the top of the stack. The size each item in the array is determined by the byte following the opcode 2 bytes
54 ARRAY_U8_STORE Pops 3 items off the stack, the first being the value to set, second being an array index and last being the pointer to an array. It the sets the value at the index in the array to first value. The size each item in the array is determined by the byte following the opcode 2 bytes
55 LOCAL_U8 Pushes the pointer to the frame variable at the index specified by the byte following the opcode 2 bytes
56 LOCAL_U8_LOAD Pushes the value of the frame variable at the index specified by the byte following the opcode 2 bytes
57 LOCAL_U8_STORE Pops an item off the stack, then sets the frame variable at the index specified by the byte following the opcode to the item 2 bytes
58 STATIC_U8 Pushes the pointer to the static variable at the index specified by the byte following the opcode 2 bytes
59 STATIC_U8_LOAD Pushes the value of the static variable at the index specified by the byte following the opcode 2 bytes
60 STATIC_U8_STORE Pops an item off the stack, then sets the static variable at the index specified by the byte following the opcode to the item 2 bytes
61 IADD_U8 Adds the byte directly after the opcode to the integer value at the top of the stack, then pushes the new value to the top of the stack 2 bytes
62 IMUL_U8 Multiplies the byte directly after the opcode to the integer value at the top of the stack, then pushes the new value to the top of the stack 2 bytes
63 IOFFSET Pops an index and a pointer to a struct off the stack, pushes the pointer to the item at 8 times the index in the struct 1 byte
64 IOFFSET_U8 Pops an pointer to a struct off the stack, pushes the pointer to the item at the index specified by 8 times the byte following the opcode 2 bytes
65 IOFFSET_U8_LOAD Pops an pointer to a struct off the stack, pushes the value of the item at the index specified by 8 times the byte following the opcode 2 bytes
66 IOFFSET_U8_STORE Pops an value and a pointer to a struct off the stack, sets the item at the index specified by 8 times the byte following the opcode to the value popped of the stack 2 bytes
67 PUSH_CONST_S16 Pushes a signed short to the stack, the value is the 2 bytes following the opcode 3 bytes
68 IADD_S16 Adds the short directly after the opcode to the integer value at the top of the stack, then pushes the new value to the top of the stack 3 bytes
69 IMUL_S16 Multiplies the short directly after the opcode to the integer value at the top of the stack, then pushes the new value to the top of the stack 3 bytes
70 IOFFSET_S16 Pops an pointer to a struct off the stack, pushes the pointer to the item at the index specified by 8 times the 2 bytes following the opcode 3 bytes
71 IOFFSET_S16_LOAD Pops an pointer to a struct off the stack, pushes the value of the item at the index specified by 8 times the 2 bytes following the opcode 3 bytes
72 IOFFSET_S16_STORE Pops an value and a pointer to a struct off the stack, sets the item at the index specified by 8 times the 2 bytes following the opcode to the value popped of the stack 3 bytes
73 ARRAY_U16 Pops 2 items off the stack, the first being an array index, second being the pointer to an array. It then pushes the pointer to theindex in the array to the top of the stack. The size each item in the array is determined by the 2 bytes following the opcode 3 bytes
74 ARRAY_U16_LOAD Pops 2 items off the stack, the first being an array index, second being the pointer to an array. It then pushes the item at the array index to the top of the stack. The size each item in the array is determined by the 2 bytes following the opcode 3 bytes
75 ARRAY_U16_STORE Pops 3 items off the stack, the first being the value to set, second being an array index and last being the pointer to an array. It the sets the value at the index in the array to first value. The size each item in the array is determined by the 2 bytes following the opcode 3 bytes
76 LOCAL_U16 Pushes the pointer to the frame variable at the index specified by the 2 bytes following the opcode 3 bytes
77 LOCAL_U16_LOAD Pushes the value of the frame variable at the index specified by the 2 bytes following the opcode 3 bytes
78 LOCAL_U16_STORE Pops an item off the stack, then sets the frame variable at the index specified by the 2 bytes following the opcode to the item 3 bytes
79 STATIC_U16 Pushes the pointer to the static variable at the index specified by the 2 bytes following the opcode 3 bytes
80 STATIC_U16_LOAD Pushes the value of the static variable at the index specified by the 2 bytes following the opcode 3 bytes
81 STATIC_U16_STORE Pops an item off the stack, then sets the static variable at the index specified by the 2 bytes following the opcode to the item 3 bytes
82 GLOBAL_U16 Pushes the pointer to the global variable at the index specified by the 2 bytes following the opcode 3 bytes
83 GLOBAL_U16_LOAD Pushes the value of the global variable at the index specified by the 2 bytes following the opcode 3 bytes
84 GLOBAL_U16_STORE Pops an item off the stack, then sets the global variable at the index specified by the 2 bytes following the opcode to the item 3 bytes
85 J Performs a relative jump to a new location in the code, the relative offset is the signed short following the opcode 3 bytes
86 JZ Performs a relative jump to a new location in the code if the item at the top of the stack is zero, the relative offset is the signed short following the opcode 3 bytes
87 IEQ_JZ Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is not equal to the second. The relative offset is the signed short following the opcode 3 bytes
88 INE_JZ Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is equal to the second. The relative offset is the signed short following the opcode 3 bytes
89 IGT_JZ Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is less than or equal to the second. The relative offset is the signed short following the opcode 3 bytes
90 IGE_JZ Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is less than the second. The relative offset is the signed short following the opcode 3 bytes
91 ILT_JZ Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is greater than or equal to the second. The relative offset is the signed short following the opcode 3 bytes
92 ILE_JZ Pops 2 items off the stack, Performs an integer comparison on them and performs a relative jump to a new location in the code if the first is greater than the second. The relative offset is the signed short following the opcode 3 bytes
93 CALL Calls a function within the script, and puts the return address on top of the stack. The location of the function is defined in the next 3 bytes after the opcode 4 bytes
94 GLOBAL_U24 Pushes the pointer to the global variable at the index specified by the 3 bytes following the opcode 4 bytes
95 GLOBAL_U24_LOAD Pushes the value of the global variable at the index specified by the 3 bytes following the opcode 4 bytes
96 GLOBAL_U24_STORE Pops an item off the stack, then sets the global variable at the index specified by the 3 bytes following the opcode to the item 4 bytes
97 PUSH_CONST_U24 Pushes an unsigned 24 bit integer to the stack, the value is the 3 bytes following the opcode 4 bytes
98 SWITCH Pops the item to compare off the stack, and then jumps to location corresponding to that item. After the opcode byte it contains a byte defining the number of possible entries, and after that the number of possible entries times 6 are taken up with repeating instances of 4 bytes of the index identifier, and 2 bytes of the relative jump offset to jump to if that index is correct (note jump offset is unsigned unlike branch instructions) (Byte after opcode * 6) + 2 bytes
99 STRING Pops an integer off the stack, then returns the pointer to the string stored at that index in the String Table 1 byte
100 STRINGHASH Pops the pointer to a string off the stack. The computes a jenkins-one-at-a-time hash on the string and pushes the result to the stack 1 byte
101 TEXT_LABEL_ASSIGN_STRING Pops a pointer to a destination buffer and a string, copies the string to the destination buffer. The size of the buffer is specified in the byte following the opcode 2 bytes
102 TEXT_LABEL_ASSIGN_INT Pops a pointer to a destination buffer and a integer, converts the integer to a string and stores it in the destination buffer. The size of the buffer is specified in the byte following the opcode 2 bytes
103 TEXT_LABEL_APPEND_STRING Pops a pointer to a destination buffer and a string, appends the string to the string in the destination buffer. The size of the buffer is specified in the byte following the opcode 2 bytes
104 TEXT_LABEL_APPEND_INT Pops a pointer to a destination buffer and a integer, converts the integer to a string and appends it to the string in the destination buffer. The size of the buffer is specified in the byte following the opcode 2 bytes
105 TEXT_LABEL_COPY Pops 3 items off the stack. Copies the third item's memory into the first item's memory with repeating defined by the second item. It then appends a null terminator to the first item's memory 1 byte
106 CATCH Sets up a safe area that has the ability to catch errors - not used in release builds of GTA 1 byte
107 THROW Indicates an area that handles a script error relative to the catch opcode - not used in release builds of GTA 1 byte
108 CALLINDIRECT Calls a function within the script, and puts the return address on top of the stack. The location of the function is defined in the integer at the top of the stack 1 byte
109 PUSH_CONST_M1 Pushes the integer -1 to the top of the stack 1 byte
110 PUSH_CONST_0 Pushes the integer 0 to the top of the stack 1 byte
111 PUSH_CONST_1 Pushes the integer 1 to the top of the stack 1 byte
112 PUSH_CONST_2 Pushes the integer 2 to the top of the stack 1 byte
113 PUSH_CONST_3 Pushes the integer 3 to the top of the stack 1 byte
114 PUSH_CONST_4 Pushes the integer 4 to the top of the stack 1 byte
115 PUSH_CONST_5 Pushes the integer 5 to the top of the stack 1 byte
116 PUSH_CONST_6 Pushes the integer 6 to the top of the stack 1 byte
117 PUSH_CONST_7 Pushes the integer 7 to the top of the stack 1 byte
118 PUSH_CONST_FM1 Pushes the float -1.0 to the top of the stack 1 byte
119 PUSH_CONST_F0 Pushes the float 0.0 to the top of the stack 1 byte
120 PUSH_CONST_F1 Pushes the float 1.0 to the top of the stack 1 byte
121 PUSH_CONST_F2 Pushes the float 2.0 to the top of the stack 1 byte
122 PUSH_CONST_F3 Pushes the float 3.0 to the top of the stack 1 byte
123 PUSH_CONST_F4 Pushes the float 4.0 to the top of the stack 1 byte
124 PUSH_CONST_F5 Pushes the float 5.0 to the top of the stack 1 byte
125 PUSH_CONST_F6 Pushes the float 6.0 to the top of the stack 1 byte
126 PUSH_CONST_F7 Pushes the float 7.0 to the top of the stack 1 byte
127 IS_BIT_SET Added in v1.0.2612.1. Pops the value and the bit to test from the stack and pushes the result of value & (1 << bit). Replaced the IS_BIT_SET native 1 byte

Native Functions

All Natives used by the script are stored in a table of hashes (seemingly random unlike on X360/PS3 versions where they were a jenkins hash of the native name). The address of the table and size can be read from the YSC Header. The native hashes are rotated right by the size of the codeSize + the index of the native in the table. To get the hash of a native from a native table index use this. The nativeTable can be got from reading the pointer from the header and masking it with 0xFFFFFF. Then returning that position in the YSC File.

QWORD getNativeHash(WORD index, const QWORD* nativeTable, DWORD codeSize)
{
	BYTE rotate = (index + codeSize) & 0x3F;
	return nativeTable[index] << rotate | nativeTable[index] >> (64 - rotate);
}

Since game version b350. Rockstar began changing the hashes of the natives each game update. Its unsure if they are random or not, but either way trying to disassemble scripts in patch b350 or later will require translating all hashes from the nativeTable(after rotating them) into their vanilla game hash. This can be done using the translation tables Alexander Blade provides in here: GTA Net GTAForums: Script/Native Documentation