Jump to content

Using mtasa-blue game header files in a own project


Recommended Posts

Good day.

I'm trying to write a little injectable dll, that hooks some GTA:SA functions.

I got the information from the "Documenting GTA:SA Memory addresses" thread in gtaforums.com (http://gtaforums.com/topic/194199-docum ... -adresses/).

Is there any way to use only the Headerfiles from the mtasa-blue core so I can allocate them by memory addresses?

For example:

CVehicle *cveh = (CVehicle) 0x000000;

When I try to use the CVehicle.h header, there are a lot of missing other headers and definitions.

So is there a bundle of Standalone Headerfiles?

Link to comment

It's probably impossible for you to be able to use the CVehicle class object's independently given the object orientated nature of the game without a lot of modifications first. It probably also depends on other objects as well as other virtual interfaces and abstractions such as CEntity and other renderware structures. You can work around this by padding your reference structure with junk till you reach the desired offset.

As well as allocating the object, you're going to have to find a way to add the created vehicle to the object pool somehow or stream it if it's not already handled. I'm not sure on the specifics of what actually goes on in the process of streaming and creating.

However, I imagine you could use a wide array of methods to create a vehicle, and then when you actually create it, you can cast that memory address to an structure or interface, and then modify what you feel is necessary. Also keep in mind CVehicle is just an abstract class. If you wish to access the base entity and all of its flags and members, then you should use the CVehicleSAInterface class that's found in game_sa\CVehicleSA.h

Personally, I recommend just using as much game_sa structures as possible in your source code, again, because of how entangled it is with other base entities. And they'll probably be useful in what ever else you'll be doing later on.

Here's an example of structure padding, you can actually find a ton of examples in the MTA source code:

Say your CVehicleSAInterface structure only contains this:

  
class CVehicleSAInterface : public ... 
{ 
    /* previous code omitted for demonstration purposes */ 
    unsigned char m_nSpecialColModel; 
    CEntity *pEntityWeAreOnForVisibilityCheck; 
    CFire *m_pFire; 
  
    float m_fSteerAngle; // +1172 
    float m_f2ndSteerAngle; // used for steering 2nd set of wheels or elevators etc.. 
    float m_fGasPedal; // 0...1  // +1180 
    float m_fBrakePedal; // 0...1 
    /* likewise */ 
} 
  

And you want to control the steering angle!

But for what ever reason you don't want to include CEntity, and CFire having no plans on modifying them. (You can probably get away with excluding CFire, but you will definitely have to CEntitySA)

Since 32-bit pointers are... 32-bit, and two 32-bit numbers is the equivalent to 64-bits or 8-bytes, you pad your structure with the sizeof ( CEntity * ) + the sizeof ( CFire * ) combined. Thus you can change your code to this:

  
class CVehicleSAInterface /*: public ... */ 
{ 
    /* previous code omitted for demonstration purposes */ 
    unsigned char m_nSpecialColModel; 
     /* padding CEntity and CFire out! */ 
    int pad69 [ 2 ]; 
    /* or you could use any of these: */ 
    /* 
    short pad420 [ 4 ]; 
    char pad666 [ 8 ];  
    */ 
  
    float m_fSteerAngle; // +1172 
    float m_f2ndSteerAngle; // used for steering 2nd set of wheels or elevators etc.. 
    float m_fGasPedal; // 0...1  // +1180 
    float m_fBrakePedal; // 0...1 
    /* likewise */ 
} 
  

You can now feel free to do something like this!

  
/* warning, code does not actually reflect the gta-sa memory layout. do not use... or fuck it, why not? */ 
int * cj_ptr = 0xBADBEEF; 
/* imaginary offset */ 
CVehicleSA * cj_current_veh_ptr_offset = cj_ptr + 420; 
  
/* muahahaha, i am haxor */ 
cj_current_veh_ptr_offset->m_fSteerAngle = 180; 
  

Err, assuming there's no other interfaces or base classes to worry about and nothing goes wrong with absurd values. But in reality... yeah.

Just save yourself the trouble and use all of the game_sa interfaces, man. :|

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...