Tonyx97 Posted July 24, 2015 Share Posted July 24, 2015 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 sbx320 Posted July 25, 2015 MTA Team Share Posted July 25, 2015 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
Tonyx97 Posted July 25, 2015 Author Share Posted July 25, 2015 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
ixjf Posted July 25, 2015 Share Posted July 25, 2015 (edited) 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 July 25, 2015 by Guest Link to comment
Tonyx97 Posted July 25, 2015 Author Share Posted July 25, 2015 Okay, thanks you, I'll try now. Link to comment
Tonyx97 Posted July 25, 2015 Author Share Posted July 25, 2015 Yea I tested it that it give me 24, Should I use that value as dwThis or dwInterface? Because I tested it and the game crashes. Link to comment
ixjf Posted July 25, 2015 Share Posted July 25, 2015 What value gave you 24? The offset of the player state? Make sure you read only 1 byte. Link to comment
Tonyx97 Posted July 25, 2015 Author Share Posted July 25, 2015 mem.Read<byte>(0xB6F5F0 + 0x58C); -> CPed + Vehicle = 24 mem.Read<byte>(0xB6F5F0 + 0x46C); -> CPed + Check = 1 Link to comment
ixjf Posted July 25, 2015 Share Posted July 25, 2015 (edited) You're not reading the address correctly. A pointer is 4 bytes, but you're only reading the first byte. Edited July 25, 2015 by Guest Link to comment
Tonyx97 Posted July 25, 2015 Author Share Posted July 25, 2015 EDIT: Okey, I can get values correctly now http://gyazo.com/7966e542708ddcda6230980e0f21eb30 I pass from 4 bytes directly to byte value. I'll try if this works on GTA. Link to comment
ixjf Posted July 25, 2015 Share Posted July 25, 2015 You only need to read 1 byte for the player state, you could have left it as it was. The pointers, however, have to be DWORDs. Link to comment
Tonyx97 Posted July 25, 2015 Author Share Posted July 25, 2015 This is so weird because I'm using CE to get values as byte and the values I got on my program are the same as I got in CE and when I try to switch engine state the game crashes. Link to comment
Tonyx97 Posted July 25, 2015 Author Share Posted July 25, 2015 This is whole function http://gyazo.com/5607514fb13062d1323ceff512f09af3 And I call it here http://gyazo.com/ac16750ab5272b671212929174944766 (this is obviously in while loop) Link to comment
ixjf Posted July 25, 2015 Share Posted July 25, 2015 (edited) 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 July 25, 2015 by Guest Link to comment
Tonyx97 Posted July 25, 2015 Author Share Posted July 25, 2015 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
ixjf Posted July 25, 2015 Share Posted July 25, 2015 (edited) 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 July 25, 2015 by Guest Link to comment
Tonyx97 Posted July 25, 2015 Author Share Posted July 25, 2015 It finally works correctly, thanks you ixfj so much for your time really A little question, what was the difference between you told me and the new code? I mean the "dereferencing" of an address like *(DWORD*). Link to comment
ixjf Posted July 25, 2015 Share Posted July 25, 2015 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
Tonyx97 Posted July 25, 2015 Author Share Posted July 25, 2015 Wow everything is clear now thanks! Link to comment
Recommended Posts