IMG

 
IMG
IMG   IMG
  Welcome to GTAForums! Be sure to check out the Grand Theft Auto V Forum.

You are not registered! (If you are, click here to login) Registering is fast, free and easy and allows you to instantly reply to any topic on GTAForums.
Why wait? Click here to register your own unique username and become part of the ever-growing community!


( Log In | Register | Revalidate Validation E-mail )
Quick Log-In:
  IMG
       
>
Forum Rules GTA Modification Forums

Please post mod releases in the Mod Showroom

GTAGarage.com
free mod hosting from GTANet, simply login with your GTAForums account details

GTAModding.com
GTANet's modding wiki

GTA Modding Chatroom
provided by irc.gtanet.com (Don't have an IRC client? Click here)


  Reply to this topicStart new topicStart Poll

 Reading memory of Vehicle in SA

 Reading Coordinates from current car
 
ikkentim  
Posted: Thursday, May 10 2012, 17:05
Quote Post


Player Hater
Group Icon
Group: Members
Joined: May 10, 2012

nl.gif

XXXXX



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)#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

This post has been edited by ikkentim on Thursday, May 10 2012, 17:07
Users WebsitePM
  Top
 

 
Bad.boy!  
Posted: Thursday, May 10 2012, 17:27
Quote Post


SA modder
Group Icon
Group: Members
Joined: Jun 20, 2010

nl.gif

XXXXX



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
PM
  Top
 

 
ikkentim  
Posted: Thursday, May 10 2012, 17:37
Quote Post


Player Hater
Group Icon
Group: Members
Joined: May 10, 2012

nl.gif

XXXXX



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.
Users WebsitePM
  Top
 

 
Bad.boy!  
Posted: Thursday, May 10 2012, 17:51
Quote Post


SA modder
Group Icon
Group: Members
Joined: Jun 20, 2010

nl.gif

XXXXX



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.

This post has been edited by Bad.boy! on Thursday, May 10 2012, 17:54
PM
  Top
 

 
ikkentim  
Posted: Thursday, May 10 2012, 18:07
Quote Post


Player Hater
Group Icon
Group: Members
Joined: May 10, 2012

nl.gif

XXXXX



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
Users WebsitePM
  Top
 

 
Bad.boy!  
Posted: Thursday, May 10 2012, 18:16
Quote Post


SA modder
Group Icon
Group: Members
Joined: Jun 20, 2010

nl.gif

XXXXX



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

 
fastman92  
Posted: Thursday, May 10 2012, 18:28
Quote Post


фастман92 | ف
Group Icon
Group: Members
Joined: Jul 28, 2009

pl.gif

XXXXX



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
Users WebsitePMMSN
  Top
 

 
SilentPL  
Posted: Thursday, May 10 2012, 18:35
Quote Post


Senior File Manager
Group Icon
Group: Members
Joined: Feb 1, 2010

pl.gif

Member Award




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.
Users WebsitePMMSNXbox Live
  Top
 

 
ikkentim  
Posted: Thursday, May 10 2012, 20:43
Quote Post


Player Hater
Group Icon
Group: Members
Joined: May 10, 2012

nl.gif

XXXXX



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!

This post has been edited by ikkentim on Thursday, May 10 2012, 20:48
Users WebsitePM
  Top
 

 

0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)

0 Members:

Topic Options Reply to this topicStart new topicStart Poll
Search topic for posted by (exact match)



 
IMG IMG