Quantcast

Jump to content

» «
Photo

New keypresses

5 replies to this topic
Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#1

Posted 29 December 2005 - 12:08 PM

This uses methods in this topic and addresses found by my (available in the memory address topic) to work. Vice City stores the last 30 characters pressed in an array in memory, once I found this the rest was easy(ish).

CODE
:newkeypresses      
03A4: name_thread "keys"
\\ Uses memory addresses A10942 - A10960 found by me - 30 byte array of last 30 characters pressed.
\\ First we need to set up CyQ's ASM to do the reading:
0004: 8288?? = -1995422835&&
0004: 8292?? = 1342335705&&
0004: 8296?? = -1025694744&&
0004: 8300?? = 1949868543&&
0004: 8304?? = 495648893&&
0004: 8308?? = 8221756&&
0004: 8312?? = -1070589815&&
0004: 8316?? = 10011777&&
0004: 8320?? = 1599930368&&
0004: 8324?? = 79846238&&
0004: 8328?? = 272862464&&
0004: 8332?? = 23779721&&
0004: 8336?? = -587536304&&
0004: 8340?? = 950140866&&
0004: 8344?? = -1962902156&&
0004: 8348?? = 1949868800&&
0004: 8352?? = 1133314173&&
0004: 8356?? = 1792641296&&
0004: 8360?? = 568872961&&
0004: 8364?? = 822067931&&
0004: 8368?? = -1731952192&&
0004: 8372?? = 1560281088&&
0004: 8376?? = -1034199457&&
0004: 8380?? = 4&&    
\\ Now set the OpCode pointers.
03FD: set_player -5035& handling_responsiveness  8532704&&
0124: write_mem_address  6850752&& value  8532745&&

\\ Up to here sets up the memory reading code

0125: read_mem_address  10553666&& into $key
008B: 0@ =  1292??

\\ Then we read in a variable
\\ Each key is 1 byte but we read 4

:newkeypressloop
0001: wait 100? ms
0125: read_mem_address  10553666&& into $key
00D6: if 0?
803c:   NOT $key == 0@
004D: jump if false ££newkeypressloop

:newkeypress
008B: 0@ =  $key
\\ We need to strip the excess bytes but also preserve the data, we want the most recent key, so we need to remove the 3 higher bytes:
0016: 0@ /= 16777216&&
0012: 0@ *= 16777216&&
008B: 1@ =  $key
0062: 1@ -= 0@
\\ Now 1@ contains just the first byte which we can test.


\\ Check it's the right code or jump to the next cheat.
00D6: if 0?
0039:   1@ == 65?
004D: jump if false ££newkeypressloop
\\ If the last key pressed was 'A' this will be true.

\\ Do whatever you want here

0002: jump ££newkeypressloop


If you want more keys to be pressed (e.g. to enter a cheat) you will need to test for larger numbers.

Demarest
  • Demarest

    what could be

  • BUSTED!
  • Joined: 12 Jul 2003

#2

Posted 29 December 2005 - 02:59 PM

And since this is for VC, the LC team can finally have authentic cheats. IF there's enough room to acomodate all that code.

Does it have to be one key at a time? Or can you check to see if GESUNDHEIT was the last X keys pressed? And if you can, do you have to use bit coding to strip apart a DWORD to test individual bytes?

BTW, your best contribution yet! I wish we could crack SCM-based mem-hacking for GTA3 and SA.

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#3

Posted 29 December 2005 - 04:32 PM

Just wait till you see what I've been working on the last day for this! The answer to about all your questions is YES (except the 3/SA part, not even looked into that yet, but we'll see) (and the bitcoding part, you CAN do it that way but I've a better way).

Seemann
  • Seemann

    Ruhe

  • Members
  • Joined: 03 Sep 2004
  • Russia
  • Best Tool 2013 "Sanny Builder"

#4

Posted 22 November 2006 - 12:21 PM Edited by Seemann, 23 November 2006 - 07:53 AM.

Same method is available for San Andreas.

MA 0x969110 is the start of an array that keeps 30 last pressed keys in SA.
So, accessing to this address allows to create new keypress checks and even create new cheats/passwords in run-time.

Using this I've got simple integer value for an array index that points at this address: -229908.

Though,
CODE
0@ = -229908
008B: 1@ = &0(0@,1i)

stores last 4 chars to 1@.

I've written different variants how to check out one, two, three, four, five last chars and even 16 ones.

CODE

// custom keypresses, v. SA

// EXAMPLE 1: TEST 1 key press (space)
0@ = -229908
while true
 008B: 1@ = &0(0@,1i)  // get last keypresses
 0085: 2@ = 1@        
 div(1@, 256)          // 1char 256, 2chars: 65536: 3chars: 16777216
 mul(1@, 256)          // same
 0062: 2@ -= 1@        // get needed number of chars (1)
 
 if
   2@ == 32 //0x20     // test if it's SPACE
 then  
    03E5: text_box 'CHEAT1'  // Cheat activated
    Break
 end
 wait 1000
end

// EXAMPLE 2: TEST 2 keys ('NO')
0@ = -229908
while true
 008B: 1@ = &0(0@,1i)  // get last keypresses
 0085: 2@ = 1@        
 div(1@, 65536)        // 1char 256, 2chars: 65536: 3chars: 16777216
 mul(1@, 65536)        // same
 0062: 2@ -= 1@        // get needed number of chars (2)
 if
   2@ == 20047 //0x4e4f        // test if player typed NO
 then  
   03E5: text_box 'CHEAT1'  // Cheat activated
   Break
 end
 wait 1000
end

// EXAMPLE 3: TEST 3 keys ('WOW')
0@ = -229908
while true
 008B: 1@ = &0(0@,1i)     // get last keypresses
 0085: 2@ = 1@        
 div(1@, 16777216)        // 1char 256, 2chars: 65536: 3chars: 16777216
 mul(1@, 16777216)        // same
 0062: 2@ -= 1@           // get needed number of chars  (3)
 if
   2@ == 5721943 //0x574f57         // test if player typed WOW
 then
     03E5: text_box 'CHEAT1'  // Cheat activated
   Break
 end
 wait 1000
end


// EXAMPLE 4: TEST 4 keys ('HACK')
0@ = -229908
while true
 if
   &0(0@,1i) == 1212236619 //0x4841434B  // test if player typed HACK
 then
   03E5: text_box 'CHEAT1'  // Cheat activated
   Break
 end
 wait 1000
end


// EXAMPLE 5: TEST 5 keys ('SANNY')

// test 5th char 's' from address +4b, then test 'anny' from the beginning;

//  addr      keys
// -229908: X X X X    |  -229908: A N N Y
// -229907: X X X O <- |  -229907: _ _ _ S                    

while true
 0@ = -229907 // +32bits; next 4 bytes/chars in the last keypresses block
 008B: 1@ = &0(0@,1i)
 0085: 2@ = 1@        
 div(1@, 256)
 mul(1@, 256)
 0062: 2@ -= 1@        // 5th char is the last in the second block:
 if
   2@ == 83 //0x53          // test if S is the 5th pressed key
 then
    0@ = -229908
    008B: 3@ = &0(0@,1i)
    if 3@ == 1095650905 //0x414E4E59  // test if player also typed ANNY after that
    then  
      03E5: text_box 'CHEAT1'  // Cheat activated
      Break
    end    
 end
 wait 1000
end

     
// EXAMPLE 6: TEST 16 keys: '1234567812345678'
0@ = -57477
while true
 if
   &0(0@,1v) == "8765432187654321" // test if last pressed key combo is "1234567812345678"
 then
   03E5: text_box 'CHEAT1'  // Cheat activated
   Break
 end
 wait 1000
end


Edit:
Just realised that the code I posted works only for me (with newest version of SB), because SB v2.99 doesn't support hex numbers in a math expression. So, I converted these numbers to decimal format in order the code can be compiled.

Seemann
  • Seemann

    Ruhe

  • Members
  • Joined: 03 Sep 2004
  • Russia
  • Best Tool 2013 "Sanny Builder"

#5

Posted 07 March 2007 - 01:23 PM

You can check if ANY key is pressed via the mission scripts.

1. Open the keyslist
http://sannybuilder....ev/keycodes.htm
Find the key you need to check.

2. First column contains the index pointing to the key related memory address. Using the array's method of reading the memory you can get the current state of the key.

3. The keys located at the column KeyLo returns 0xFF when pressed. The keys located at the column KeyHi returns 0xFF0000 when pressed.

4. Read the mem addy using index and compare the value with the conforming constant.


Example1. Check ENTER
CODE
0@ = 304490 // Enter's index

:loop
wait 0
&0(0@,1i) == 0x00FF0000 // KeyHi
jf @loop

player.money($player_char) += 100 // Enter pressed!



Example2. Check TILDE (~)
CODE
0@ = 304550 // Tilde's index

:loop
wait 0
&0(0@,1i) == 0xFF // KeyLo
jf @loop

player.money($player_char) += 100 // Tilde pressed!


Example3. Combined checks: Num1+ Num2
CODE
0@ = 304484 // Num1,Num2 index

:loop
wait 0
&0(0@,1i) == 0x00FF00FF // Num1+Num2
jf @loop

player.money($player_char) += 100 // Whoa! Num1+Num2 pressed!




All indexes are for version 1.0

DIMICH
  • DIMICH

    Player Hater

  • Members
  • Joined: 08 Mar 2007

#6

Posted 15 March 2007 - 02:35 PM

How to use this in VC? blush.gif




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users