Jump to content

Question about dwInterface in source


Recommended Posts

Hello community! I tried to use this code to switch on/off a car in GTA:SA.

  
  
void SwitchEngine(bool bStat) 
{ 
    DWORD dwThis = (DWORD)0; 
    DWORD dwEngineOn = (DWORD)bStat; 
    DWORD dwFunc = 0x41BDD0; 
  
    _asm 
    { 
        mov     ecx, dwThis 
        push    dwEngineOn 
        call    dwFunc 
    } 
} 
  

When I adapted this to my code I supposed that this will fail because the car has to be specified and I don't know what values are dwInterface to use on dwThis. I suppose this variable contains my own car instance but if I'm in GTA:SA, What value does dwThis be? Thanks in advance.

Link to comment
  • MTA Team

dwThis or dwInterface are usually referring to the instance (e.g. a Vehicle).

In your particular example you'll have to get a valid CVehicleSAInterface pointer into dwThis to specify which vehicle's engine you want to toggle. How you get this pointer depends on the vehicle you wish to modify. For example if you want to switch off the local player's vehicle you'll want to have a look at the global player structure.

Link to comment

Thanks for the info sbx, I've been researching Interfaces classes and I know that the interface is m_pInterface and the funcs are SetInterface and GetInterface. I've been looking for createVehicle function which (I suppose) that contains the _asm function where dwReturn is the Interface of that vehicle ( SetInterface(dwReturn) ) but I didn't find the function, where is it located at source?

Link to comment

It's more complicated than that. But if you simply want to switch the engine on/off of the vehicle the player is currently in, according to http://www.gtamodding.com/?title=Memory_Addresses_(SA), the address of the player's CPed structure is 0xB6F5F0, and the offset in that structure to a pointer to the last or currently driven vehicle is 0x58C. To know whether you're actually in the vehicle, you can check offset 0x46C (byte) for the value 1 (in vehicle). It's worth mentioning that the address is for GTA:SA 1.0. The offsets, however, are probably the same on other versions.

Edit: The address 0xBA18FC should contain a pointer to the currently driven vehicle. It will be a null pointer if the player is on foot.

Edited by Guest
Link to comment

The function should be like this:

void SwitchEngine (bool bStat) 
{ 
    if (mem.Read <byte> (0xB6F5F0 + 0x46C) == 1) 
    { 
        static DWORD dwThis = 0xB6F5F0 + 0x58C; 
        static DWORD dwFunc = 0x41BDD0; 
        DWORD dwEngineOn = (bool)bStat; 
  
        __asm  
        { 
            mov ecx, dwThis 
            push dwEngineOn 
            call dwFunc 
        } 
    } 
} 

Edited by Guest
Link to comment

I've tested this and doesn't work, first of all the condition doesn't work aswell it gives me 26 if I don't use

    DWORD first = mem.Read<DWORD>(0xB6F5F0); 
    if (mem.Read<byte> (first + 0x46C) == 1) 
     

this gives me 1 if I'm on car, and when I press the key the car doesn't switch the state, what is going on?

Link to comment

Oh, sorry. That was my fault. I should be dereferencing the address 0xB6F5F0 which points to the structure, and only then add the offset.

void SwitchEngine (bool bStat) 
{ 
    DWORD CPed = *(DWORD*)0xB6F5F0; 
  
    if (mem.Read <byte> (CPed + 0x46C) == 1) 
    { 
        DWORD dwThis = *(DWORD*)(CPed + 0x58C); 
        DWORD dwFunc = 0x41BDD0; 
        DWORD dwEngineOn = (bool)bStat; 
  
        __asm  
        { 
            mov ecx, dwThis 
            push dwEngineOn 
            call dwFunc 
        } 
    } 
} 

Edited by Guest
Link to comment

I'm really glad I could help. The problem is that the address 0xB6F5F0 points to the address of structure (it's a pointer to the structure). Assume that 0xDEADBEEF is the address of the structure. 0xB6F5F0 contains the value 0xDEADBEEF, so I need to dereference 0xB6F5F0 (get the value of the address) to get 0xDEADBEEF, and then I can add the offset 0x58C to it.

Link to comment
  • Recently Browsing   0 members

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