/vicehook/NATIVES.txt

[DIR] Index of /vicehook
[TXT] NATIVES.txt  2026-12-01 21:58    5.4K  raw file

How GTA VI's script VM differs from GTA V, and how spawning works

Notes from building ViceHook, a script hook for GTA VI story mode
under VIctory (the Xbox Series build v1.0.2.1). If you have written
Script Hook V plugins for GTA V, most of what you know carries over:
a plugin registers a script, loops with WAIT and calls natives. What
sits underneath does not. Addresses below are offsets from the game
image's base in that one build.


1. Natives have no name hashes
------------------------------

In GTA V a native is looked up by a 64-bit hash, through a
registration table. GTA VI has no such table. Each native's handler
carries its own 64-bit id instead, and writes it out when it is called
with a negative argument count.

ViceHook reads the game's exception table to find every handler, asks
each one for its id at start, and binds natives by id, so no address
is hard-coded. On 1.0.2.1, 6,820 of the 6,829 ids the NativeDB knows
are found. About 4,700 natives still have no name.


2. Cells, entities, vectors
---------------------------

- Arguments and results are 8-byte cells.
- An entity is a 16-byte reference, two cells, not GTA V's int
  handle.
- A Vector3 is two cells: x and y in the first, z in the second.
- Headings are radians. Model keys are 64-bit, not 32-bit joaat
  hashes: the player's model is 0x6B13B6B43F959856.
- There is no global array. Shared script state lives in module
  statics.
- There are no script drawing natives: the game's UI is data-bound.
  So ViceHook draws its own overlay, a click-through window over the
  game drawn with Direct2D, for menus, text, images and notifications.


3. Where plugin code runs
-------------------------

ViceHook detours the handler of PLAYER_PED_ID, which nearly every game
script calls every frame (about 100,000 call sites in 722 programs).
Once per game frame it ticks the plugin scripts from inside that call:
on the game's update path, with a real game script thread current.
Each plugin script is a fiber that runs until its next WAIT.

The ticks always happen inside the same game script thread (the one
calling on most frames, chosen again if it ends). That matters because
many ped and entity flags belong to the script thread that set them:
a flag set from one thread could not be cleared from another.

Every native call is guarded. A fault is caught, logged once per
native, and returns zeros instead of taking the game down.


4. There is no CREATE_PED
-------------------------

GTA VI creates entities through async natives, VI_CREATE_PED_ASYNC,
VI_CREATE_VEHICLE_ASYNC and VI_CREATE_OBJECT_ASYNC. Each returns a
task object, not an entity. The entity appears in the task when the
request completes, a frame or two later. A plain call from a plugin
fails, for four reasons:

1. The last argument is a task type token, and it belongs to the
   calling script program. The task constructor asks the current
   script thread for its program and looks the token up in that
   program's own type table. The same number means a different type
   in another program, and the built-in generic Task types crash the
   game.
2. The task is held weakly, so the script runtime reclaims it within
   a frame unless something keeps a reference.
3. Model keys are 64-bit, and natives.h (from the NativeDB) still types
   them as 32-bit hashes.
4. The task is a pooled script object, so it can only be made under a
   script heap that has a pool for it.

ScriptHook VI's published notes (github.com/modpapi/scripthook-vi)
covered much of this. It spawns by running the game's own script
wrapper functions, which needs a script VM function caller that
ViceHook does not have.


5. ViceHook's route
-------------------

Because plugin scripts already run inside a real game script's native
call, the "current program" is a real running program with its own
type table. So the question became: which token, in that program,
names the creation task type?

- Tracing the game's own create calls (ViceHook's tracer logs each
  call's arguments, result and thread) gave tokens. They did not
  carry over: modules are listed in a different order in each
  program, so token numbers are per program.
- What does carry over is the type's identity: a 64-bit hash in its
  type record. The game's object creates use task type
  0x5A67CA801EB43EC7 in every program, vehicles 0xB160382E3F59FF92 and
  peds 0x50C400F33D4A0D55.
- ViceHook scans the calling program's type ranges for that hash to
  get the right token, makes the call, and pins the task with the
  engine's own strong-handle helper. The garbage collector moves the
  task within a frame, so the current address is read from the strong
  slot, not kept.
- When the task's status reaches 5, the 16-byte entity reference sits
  at +0x28. The model needs no REQUEST_MODEL first.
- The pin is released only once the task has finished. Releasing it
  while the task was still running corrupted the heap and crashed the
  game two seconds later, inside an unrelated heap walk.
- VIctory rewrites the game's reads of its thread-local block
  (gs:[0x58]) to return that address + 0x80, so code outside the game
  has to add the same offset.

The result is spawnObject, spawnVehicle and spawnPed in the SDK
(v0.3.0) and the console's spawn command. Objects and vehicles were
spawned in game through both; peds through a test plugin making the
same calls spawnPed makes.

The full research log, with every address and every experiment that
crashed, is docs/SPAWNING.md in https://github.com/0x000NULL/vicehook.

Generated 2026-12-04 05:16 UTC by indexgen