Difference between revisions of "00E2"

From GTAMods Wiki
Jump to navigation Jump to search
m
(rewritten code)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Icon|3}} '''GET_PAD_STATE'''
+
{{OpCode
<hr />
+
| games      = {{Icon|3}} {{Icon|SA}}
'''Description'''
+
| command    = GET_PAD_STATE
: Gets the current button pressed
+
| description = Gets the state of the button
'''Syntax'''
+
| syntax1    = 00E2: get_player [''int1''] key [''int2''] state_to [''var'']
: 00E2: get_player [''int1''] key [''int2''] state_to [''var'']
+
| p1t        = [''int1'']
'''Parameter'''
+
| p1d        = [[00E1#Joypads|Joypad]] (usually 0)
: [''int1'']
+
| p2t        = [''int2'']
:: Pad, normally 0 for pad 1 (player 1), 1 for pad 2 (player 2)
+
| p2d        = [[00E1#Joypad buttons|Joypad button]]
: [''int2'']
+
| p3t        = [''var'']
:: [[00E1|Button index]]
+
| p3d        = Variable to store the state, an integer value
: [''var'']
+
}}
:: Variable to store the status
 
  
This opcode gets the status of the button. It returns a value between 0 and 255, 255 meaning the button is completely pressed down. For left and right sticks (buttons 0 to 3), it returns a value between -128 and 128, -128 meaning the stick is completely pressed one way and 128 meaning the stick is completely pressed the other way.
+
This opcode gets the state of the button. It returns a value between 0 and 255, 255 meaning the button is completely pressed down. For left and right analogue sticks (buttons 0 to 3), it returns a value between -128 and 128, -128 meaning the stick is completely pressed in one direction and 128 meaning the stick is completely pressed in the other direction. This opcode was never called in the original script of GTA III.
  
 
== For Vice City ==
 
== For Vice City ==
This opcode does not exist in Vice City but it is possible to retrieve the status of the button in the same manner as GTA III. The following example, using Sanny Builder with [[CLEO]] for Vice City in an external script (not the main one) and tested on US v1.0, retrieves the value of the status of the button for pad 0.
+
This opcode does not exist in Vice City but it is possible to retrieve the state of the button in the same manner as GTA III. The following example, using Sanny Builder with [[CLEO]] for Vice City in an external script (not the main one) and tested on US v1.0, should work similarly to this opcode.
<syntaxhighlight lang="scm">
+
{{Pre|class=sb-code|1=
:opcode_00E2
+
<span class="nl">:opcode_00E2</span>
// 0@ - input param (button)
+
<span class="c1">// 0@ - input param (joypad)</span>
0@ *= 2  // offset in memory
+
<span class="c1">// 1@ - input param (joypad button)</span>
0@ += 0x7DBCB0 // add to base memory location
+
05E2: call_function <span class="m">0x4AB060</span> num_params <span class="m">1</span> pop <span class="m">1</span> <span class="nv">0@</span> store_to <span class="nv">0@</span>  <span class="c1">// CPad::GetPad</span>
05E0: 0@ = read_memory 0@ size 2 virtual_protect 1 // retrieve status of button
+
<span class="nv">1@</span> *= <span class="m">2</span> <span class="c1">// size of each button</span>
05F6: ret 1 0@
+
005A: <span class="nv">1@</span> += <span class="nv">0@</span> <span class="c1">// add to base address for pad</span>
</syntaxhighlight>
+
05E0: <span class="nv">0@</span> = read_memory <span class="nv">1@</span> size <span class="m">2</span> virtual_protect <span class="m">0</span>  <span class="c1">// read state of button</span>
 +
<span class="k">if</span>
 +
    <span class="nv">0@</span> &gt; <span class="m">32767</span> <span class="c1">// state of button is stored as signed short</span>
 +
<span class="k">then</span>
 +
    <span class="nv">0@</span> -= <span class="m">65536</span>
 +
<span class="k">end</span>
 +
05F6: ret <span class="m">1</span> <span class="nv">0@</span>
 +
}}
 +
 
 
Use this line as a substitute for opcode 00E2. This can be placed anywhere within the external script:
 
Use this line as a substitute for opcode 00E2. This can be placed anywhere within the external script:
<syntaxhighlight lang="scm">
+
{{Pre|class=sb-code|1=
05F5: call_scm_func @opcode_00E2 inputs 1 button [button] result [variable]
+
05F5: call_scm_func <span class="nl">@opcode_00E2</span> inputs <span class="m">2</span> pad [int1] button [int2] result [<span class="k">var</span>]
</syntaxhighlight>
+
}}
Note that this code's result does not distinguish between a dword (4 bytes) or a word (2 bytes), meaning that a pressed left or right stick can be interpreted as a dword value of 65408, which is a word value of -128 (0xFF80 in hex).
 
  
 
== Keywords ==
 
== Keywords ==
Line 35: Line 41:
  
 
== See also ==
 
== See also ==
* [[0494]], an alternative to getting status of the stick (buttons 0 to 3)
+
* {{Icon|t}} [[00E1]], checks if the button is pressed
 
+
* {{Icon|t}} [[0494]], an alternative to getting state of the stick (buttons 0 to 3)
[[Category:OpCodes]]
 
[[Category:Code Snippets]]
 

Latest revision as of 07:04, 6 December 2016

GTA III San Andreas GET_PAD_STATE


Description
Gets the state of the button
Syntax
00E2: get_player [int1] key [int2] state_to [var]
Parameter
[int1]
Joypad (usually 0)
[int2]
Joypad button
[var]
Variable to store the state, an integer value

This opcode gets the state of the button. It returns a value between 0 and 255, 255 meaning the button is completely pressed down. For left and right analogue sticks (buttons 0 to 3), it returns a value between -128 and 128, -128 meaning the stick is completely pressed in one direction and 128 meaning the stick is completely pressed in the other direction. This opcode was never called in the original script of GTA III.

For Vice City

This opcode does not exist in Vice City but it is possible to retrieve the state of the button in the same manner as GTA III. The following example, using Sanny Builder with CLEO for Vice City in an external script (not the main one) and tested on US v1.0, should work similarly to this opcode.

:opcode_00E2
// 0@ - input param (joypad)
// 1@ - input param (joypad button)
05E2: call_function 0x4AB060 num_params 1 pop 1 0@ store_to 0@  // CPad::GetPad
1@ *= 2  // size of each button
005A: 1@ += 0@  // add to base address for pad
05E0: 0@ = read_memory 1@ size 2 virtual_protect 0  // read state of button
if
    0@ > 32767  // state of button is stored as signed short
then
    0@ -= 65536
end
05F6: ret 1 0@

Use this line as a substitute for opcode 00E2. This can be placed anywhere within the external script:

05F5: call_scm_func @opcode_00E2 inputs 2 pad [int1] button [int2] result [var]

Keywords

get, button, key, press, pressed, keypress

See also

  • GTA III Vice City San Andreas 00E1, checks if the button is pressed
  • GTA III Vice City San Andreas 0494, an alternative to getting state of the stick (buttons 0 to 3)