Difference between revisions of "020A"

From GTAMods Wiki
Jump to navigation Jump to search
m
(example and disassembly)
 
Line 1: Line 1:
 +
{{TocRight}}
 
{{OpCode
 
{{OpCode
 
| games      = {{Icon|t}}
 
| games      = {{Icon|t}}
Line 33: Line 34:
 
|7 ||CARLOCK_LOCKED_BUT_CAN_BE_DAMAGED ||locked but doors can fall off
 
|7 ||CARLOCK_LOCKED_BUT_CAN_BE_DAMAGED ||locked but doors can fall off
 
|}
 
|}
 +
 +
== Example ==
 +
The following example allows the vehicle you are in to be locked when holding [[00E1|button 6]] (HANDBRAKE key) and unlocked when not holding it.
 +
{{Pre|class=sb-code|1=
 +
<span class="c1">// set constants</span>
 +
<span class="k">const</span>
 +
PLAYER_CAR = <span class="nv">0@</span>
 +
<span class="k">end</span>
 +
 +
<span class="k">while</span> <span class="k">true</span>
 +
    <span class="k">wait</span> <span class="m">10</span>
 +
    <span class="k">if</span>
 +
        [[0256]]:  player <span class="nv">$PLAYER_CHAR</span> defined
 +
    <span class="k">then</span>
 +
        <span class="k">if</span>
 +
            00DF:  actor <span class="nv">$PLAYER_ACTOR</span> in_any_car
 +
        <span class="k">then</span>
 +
            03C0: PLAYER_CAR = actor <span class="nv">$PLAYER_ACTOR</span> car_no_save
 +
            <span class="k">if</span>
 +
                [[00E1]]:  key_pressed <span class="m">0</span> <span class="m">6</span>  <span class="c1">// handbrake key</span>
 +
            <span class="k">then</span>
 +
                020A: set_car PLAYER_CAR door_status_to <span class="m">2</span>  <span class="c1">// CARLOCK_LOCKED</span>
 +
            <span class="k">else</span>
 +
                020A: set_car PLAYER_CAR door_status_to <span class="m">1</span>  <span class="c1">// CARLOCK_UNLOCKED</span>
 +
            <span class="k">end</span>
 +
        <span class="k">end</span>
 +
    <span class="k">end</span>
 +
<span class="k">end</span>
 +
}}
 +
 +
== Disassembled code ==
 +
These are disassembled code for this opcode both from PC v1.0 US.
 +
=== GTA III ===
 +
<syntaxhighlight lang="nasm">
 +
loc_442DAC:
 +
    lea    eax, [ebp+10h]                    ; get address of script's current instruction pointer
 +
    mov    ecx, ebp                          ; get address of script for thiscall
 +
    push    2                                ; push 2 for two parameters to collect
 +
    push    eax                              ; push address of script's current instruction pointer
 +
    call    CRunningScript::CollectParameters ; call CRunningScript::CollectParameters(uint *,short)
 +
    mov    eax, ds:ScriptParams[0]          ; get value of first parameter, the vehicle handle
 +
    mov    ecx, ds:CPools::ms_pVehiclePool  ; get address of vehicle pool for thiscall
 +
    push    eax                              ; push vehicle handle
 +
    call    CPool_CVehicle_CAutomobile::GetAt ; call CPool<CVehicle, CAutomobile>::GetAt(int) to get address of vehicle
 +
    mov    ecx, ds:ScriptParams[1]          ; get value of second parameter, the car lock
 +
    mov    [eax+224h], ecx                  ; offset vehicle address by 0x224 and set its car lock
 +
    xor    al, al                            ; return 0
 +
</syntaxhighlight>
 +
 +
=== Vice City ===
 +
<syntaxhighlight lang="nasm">
 +
loc_4578E9:
 +
    lea    eax, [ebp+10h]                    ; get address of script's current instruction pointer
 +
    mov    ecx, ebp                          ; get address of script for thiscall
 +
    push    2                                ; push 2 for two parameters to collect
 +
    push    eax                              ; push address of script's current instruction pointer
 +
    call    CRunningScript::CollectParameters ; call CRunningScript::CollectParameters(uint *,short)
 +
    mov    eax, ds:ScriptParams[0]          ; get value of first parameter, the vehicle handle
 +
    mov    ecx, ds:CPools::ms_pVehiclePool  ; get address of vehicle pool for thiscall
 +
    push    eax                              ; push vehicle handle
 +
    call    CPool_CVehicle_CAutomobile::GetAt ; call CPool<CVehicle, CAutomobile>::GetAt(int) to get address of vehicle
 +
    mov    ecx, ds:ScriptParams[1]          ; get value of second parameter, the car lock
 +
    mov    [eax+230h], ecx                  ; offset vehicle address by 0x230 and set its car lock
 +
    xor    al, al                            ; return 0
 +
</syntaxhighlight>
  
 
== Keywords ==
 
== Keywords ==
 
set, car, vehicle, door, lock, status
 
set, car, vehicle, door, lock, status

Latest revision as of 23:36, 20 January 2017

GTA III Vice City San Andreas LOCK_CAR_DOORS


Description
Sets the door lock status of the vehicle
Syntax
020A: set_car [car handle] door_status_to [int]
Parameter
[car handle]
The handle of the vehicle
[int]
Car lock (see below)
Native analog
LOCK_CAR_DOORS

This opcode sets the door status of the vehicle. Of course, the opcode only affects vehicles with a working door. In GTA III, this opcode behaves exactly as opcode 0135.

Car locks

Car lock Enum Description
0 CARLOCK_NONE
1 CARLOCK_UNLOCKED unlocked car
2 CARLOCK_LOCKED locked car – properties include doors can't fall off, no one can enter but can exit, anyone can enter if door left wide open or fallen off
3 CARLOCK_LOCKOUT_PLAYER_ONLY locked for the player, not locked for NPCs
4 CARLOCK_LOCKED_PLAYER_INSIDE locked, the player is stuck in the car
5 CARLOCK_LOCKED_INITIALLY locked when not in car, unlocks when in car
6 CARLOCK_FORCE_SHUT_DOORS animation will never leave door opened, always closes door
7 CARLOCK_LOCKED_BUT_CAN_BE_DAMAGED locked but doors can fall off

Example

The following example allows the vehicle you are in to be locked when holding button 6 (HANDBRAKE key) and unlocked when not holding it.

// set constants
const
PLAYER_CAR = 0@
end

while true
    wait 10
    if
        0256:   player $PLAYER_CHAR defined
    then
        if
            00DF:   actor $PLAYER_ACTOR in_any_car
        then
            03C0: PLAYER_CAR = actor $PLAYER_ACTOR car_no_save
            if
                00E1:   key_pressed 0 6  // handbrake key
            then
                020A: set_car PLAYER_CAR door_status_to 2  // CARLOCK_LOCKED
            else
                020A: set_car PLAYER_CAR door_status_to 1  // CARLOCK_UNLOCKED
            end
        end
    end
end

Disassembled code

These are disassembled code for this opcode both from PC v1.0 US.

GTA III

loc_442DAC:
    lea     eax, [ebp+10h]                    ; get address of script's current instruction pointer
    mov     ecx, ebp                          ; get address of script for thiscall
    push    2                                 ; push 2 for two parameters to collect
    push    eax                               ; push address of script's current instruction pointer
    call    CRunningScript::CollectParameters ; call CRunningScript::CollectParameters(uint *,short)
    mov     eax, ds:ScriptParams[0]           ; get value of first parameter, the vehicle handle
    mov     ecx, ds:CPools::ms_pVehiclePool   ; get address of vehicle pool for thiscall
    push    eax                               ; push vehicle handle
    call    CPool_CVehicle_CAutomobile::GetAt ; call CPool<CVehicle, CAutomobile>::GetAt(int) to get address of vehicle
    mov     ecx, ds:ScriptParams[1]           ; get value of second parameter, the car lock
    mov     [eax+224h], ecx                   ; offset vehicle address by 0x224 and set its car lock
    xor     al, al                            ; return 0

Vice City

loc_4578E9:
    lea     eax, [ebp+10h]                    ; get address of script's current instruction pointer
    mov     ecx, ebp                          ; get address of script for thiscall
    push    2                                 ; push 2 for two parameters to collect
    push    eax                               ; push address of script's current instruction pointer
    call    CRunningScript::CollectParameters ; call CRunningScript::CollectParameters(uint *,short)
    mov     eax, ds:ScriptParams[0]           ; get value of first parameter, the vehicle handle
    mov     ecx, ds:CPools::ms_pVehiclePool   ; get address of vehicle pool for thiscall
    push    eax                               ; push vehicle handle
    call    CPool_CVehicle_CAutomobile::GetAt ; call CPool<CVehicle, CAutomobile>::GetAt(int) to get address of vehicle
    mov     ecx, ds:ScriptParams[1]           ; get value of second parameter, the car lock
    mov     [eax+230h], ecx                   ; offset vehicle address by 0x230 and set its car lock
    xor     al, al                            ; return 0

Keywords

set, car, vehicle, door, lock, status