Quantcast

Jump to content

» «
Photo

Reading memory of Vehicle in SA

8 replies to this topic
ikkentim
  • ikkentim

    Player Hater

  • Members
  • Joined: 10 May 2012

#1

Posted 10 May 2012 - 05:05 PM Edited by ikkentim, 10 May 2012 - 05:07 PM.

Hello Everyone,

I am trying to read the position of the car you are currently in.
I know the basics of how memory reading works etc, but I can't properly figure out how to read the values from the vehicle's position...

I found some reference here:
http://www.gtamoddin...esses_(SA)#Cars

There it says the following things:

QUOTE
0xB6F980 - Is the direct pointer to the pool start (CVehicle)
0xBA18FC - Current vehicle pointer
0x969084 - First vehicle you got into

xB74494 - Contains a pointer to main struct
This struct:
+0 = Contains a pointer to the first element in the pool
+4 = Contains a pointer to a byte map indicating which elements are in use
+8 = [dword] Is the maximum number of elements in the pool
+12 = [dword] Is the current number of elements in the pool

Each vehicle object is 2584 (0xA18) bytes. It starts at 0xC502AA0.
For each vehicle in the pool:
+20 = [byte] Contains a pointer to the rotation/position matrix (84 bytes):
+0 = [float] X-axis Rotation (Grad)
+4 = [float] Y-axis Rotation (Grad)
+8 = [float] Z-axis Rotation (Grad)
+16 = [float] X-axis Rotation (Looking)
+20 = [float] Y-axis Rotation (Looking)
+ 24 = [float] Z-axis Rotation (Looking)
+48 = [float] X-axis Position
+52 = [float] Y-axis Position
+56 = [float] Z-axis Position


I tried taking where 0xBA18FC points to, then adding 68 to it, but no success...
Does anyone have any experience with this?

Thanks in advance!
ikkentim

PS.
I'm new here moto_whistle.gif
Forgot [Q] before the title

Bad.boy!
  • Bad.boy!

    SA modder

  • Feroci
  • Joined: 20 Jun 2010
  • Netherlands

#2

Posted 10 May 2012 - 05:27 PM

Could you explain what you are making, some kind of trainer or a cleo/scm script. Because in cleo you can use:
CODE
0811: 0@ = actor $PLAYER_ACTOR car // versionC

ikkentim
  • ikkentim

    Player Hater

  • Members
  • Joined: 10 May 2012

#3

Posted 10 May 2012 - 05:37 PM

QUOTE (Bad.boy! @ Thursday, May 10 2012, 17:27)
Could you explain what you are making, some kind of trainer or a cleo/scm script. Because in cleo you can use:
CODE
0811: 0@ = actor $PLAYER_ACTOR car // versionC

No, I just want the data, so I can calculate the cars location and show it on an lcd screen. When I know how to get the vehicle's position, I also know how to calculate the speed of the vehicle, since that will be very easy to calculate too then.

Bad.boy!
  • Bad.boy!

    SA modder

  • Feroci
  • Joined: 20 Jun 2010
  • Netherlands

#4

Posted 10 May 2012 - 05:51 PM Edited by Bad.boy!, 10 May 2012 - 05:54 PM.

How about:
CODE
02E3: 6@ = car 0@ speed
00AA: store_car 0@ position_to 3@ 4@ 5@


"distance = ▲velocity * ▲time" is to much calculating.
"▲ = end - begin" can't find the proper character

Also it's in 3d so that would be even more calculating, and there's a memory adress for speed too.

ikkentim
  • ikkentim

    Player Hater

  • Members
  • Joined: 10 May 2012

#5

Posted 10 May 2012 - 06:07 PM

QUOTE (Bad.boy! @ Thursday, May 10 2012, 17:51)
How about:
CODE
02E3: 6@ = car 0@ speed
00AA: store_car 0@ position_to 3@ 4@ 5@


"distance = ▲velocity * ▲time" is to much calculating.
"▲ = end - begin" can't find the proper character

Also it's in 3d so that would be even more calculating, and there's a memory adress for speed too.

As I said, I want to do it by reading memory

Bad.boy!
  • Bad.boy!

    SA modder

  • Feroci
  • Joined: 20 Jun 2010
  • Netherlands

#6

Posted 10 May 2012 - 06:16 PM

I'm really bad in memory adresses, but the current vehicle is: CPed +0x58C.

fastman92
  • fastman92

    фастман92 | ف

  • Members
  • Joined: 28 Jul 2009
  • None

#7

Posted 10 May 2012 - 06:28 PM

CODE
{$CLEO}
0000: NOP

:velocity
wait 0
if
Actor.Driving($PLAYER_ACTOR)
else_jump @velocity
0811: 0@ = actor $PLAYER_ACTOR car_nosave
0A97: 1@ = car 0@ struct
1@ += 0x44      // RwV3D m_vVelocity: X
0A8E: 2@ = 1@ + 4 // int   ; m_vVelocity: Y
0A8E: 3@ = 1@ + 8 // int   ; m_vVelocity:: Z


   while Actor.Driving($PLAYER_ACTOR)
   wait 0    
   0A8D: 4@ = read_memory 1@ size 4 virtual_protect FALSE
   006B: 4@ *= 4@  // (float)
   
   0A8D: 5@ = read_memory 2@ size 4 virtual_protect FALSE    
   006B: 5@ *= 5@  // (float)
   005B: 4@ += 5@  // (float)
   
   0A8D: 5@ = read_memory 3@ size 4 virtual_protect FALSE    
   006B: 5@ *= 5@  // (float)
   005B: 4@ += 5@  // (float)
   
   01FB: 4@ = square_root 4@
   4@ *= 50.0
   
   0AD1: show_formatted_text_highpriority "Car velocity: %.3f" time 2000 4@      
   end
jump @velocity

Silent
  • Silent

    Moderating Cookie Monster

  • Feroci
  • Joined: 01 Feb 2010
  • Poland
  • Most Helpful [GTA] 2013
    Most Helpful [Modding] 2013
    Most Talented [Modding] 2013
    Best Map 2013 "ViceCityStories PC Edition"
    Best Vehicle 2013 "III Aircraft"
    Most Helpful [Modding] 2012
    Modder of the Year 2012

#8

Posted 10 May 2012 - 06:35 PM

Not sure if it will be the fastest way, but:
Read CPlayerPed pointer from CPlayerInfo.pPed, which comes always at 0xB7CD98. Then, as Bad.boy said, read CVehile pointer from CPed.pVehicle, which comes at CPed + 0x58C. Then, if you want to do it in real R* style, you have to use some checks - Rockstar gets the entity position by:
1. Reading CMatrix pointer from CPlaceable structure (which is the 3rd level of CVehicle parent), which in your case comes at CVehicle + 0x14.
2. Then, they check if pointer isn't NULL. If it isn't null, position is in CVector structure at CMatrix + 30h (the previous pointer you read). Otherwise, if it IS NULL, position is in CVector which comes at CVehicle + 0x4 member.

Confusing, but it turns out to be nice in well-structured piece of code.

ikkentim
  • ikkentim

    Player Hater

  • Members
  • Joined: 10 May 2012

#9

Posted 10 May 2012 - 08:43 PM Edited by ikkentim, 10 May 2012 - 08:48 PM.

QUOTE (SilentPL @ Thursday, May 10 2012, 18:35)
Not sure if it will be the fastest way, but:
Read CPlayerPed pointer from CPlayerInfo.pPed, which comes always at 0xB7CD98. Then, as Bad.boy said, read CVehile pointer from CPed.pVehicle, which comes at CPed + 0x58C. Then, if you want to do it in real R* style, you have to use some checks - Rockstar gets the entity position by:
1. Reading CMatrix pointer from CPlaceable structure (which is the 3rd level of CVehicle parent), which in your case comes at CVehicle + 0x14.
2. Then, they check if pointer isn't NULL. If it isn't null, position is in CVector structure at CMatrix + 30h (the previous pointer you read). Otherwise, if it IS NULL, position is in CVector which comes at CVehicle + 0x4 member.

Confusing, but it turns out to be nice in well-structured piece of code.

Could you tell me what CMatrix' structure looks like?
As i did all what you said, it looks like a pointer to the CMatrix' address,
but do I need to add something to get the info I need (posX,Y,Z)?

EDIT: Got It! Needed to add 48! smile.gif Thank you so so much!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users