|
 |
|
|
|
|
|
GTA Modification Forums
Reading memory of Vehicle in SA Reading Coordinates from current car
 |
|
 |
| |
ikkentim  |
Posted: Thursday, May 10 2012, 17:05
|
Player Hater

Group: Members
Joined: May 10, 2012


|
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.gtamodding.com/index.php?title=...esses_(SA)#CarsThere 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  Forgot [Q] before the title This post has been edited by ikkentim on Thursday, May 10 2012, 17:07
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
ikkentim  |
Posted: Thursday, May 10 2012, 17:37
|
Player Hater

Group: Members
Joined: May 10, 2012


|
| 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.
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
fastman92  |
Posted: Thursday, May 10 2012, 18:28
|
фастман92 | ف

Group: Members
Joined: Jul 28, 2009


|
| 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 |
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
SilentPL  |
Posted: Thursday, May 10 2012, 18:35
|
Senior File Manager

Group: Members
Joined: Feb 1, 2010



|
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  |
Posted: Thursday, May 10 2012, 20:43
|
Player Hater

Group: Members
Joined: May 10, 2012


|
| 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!  Thank you so so much! This post has been edited by ikkentim on Thursday, May 10 2012, 20:48
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
| |
 |
|
 |
|
|
|
|