SAMPProjects / Open-SAMP-API

An open source API for GTA SA:MP
GNU Lesser General Public License v3.0
63 stars 15 forks source link

GetVehicleID() #25

Open Montero98 opened 8 years ago

Montero98 commented 8 years ago

Dear developers of the API, i am missing the function "GetVehicleID" with which users would be able to read a vehicles ID on the server. I really need this function for my program, so i would be very happy, if this could be included.

I hope, i'll get a reply soon. Best Regards, Montero

Montero98 commented 8 years ago

@mschnitzer now it should be correct ;)

JohnnyCrazy commented 8 years ago

@Montero98 :+1:

myudev commented 8 years ago

@Montero98 you mean to get the vehicle by id? or to get the ID based on a GTA:SA vehicle ptr?

Montero98 commented 8 years ago

@myudev I mean, the specific ID of the vehicle i am sitting in.

myudev commented 8 years ago

@Montero98 oh, ok I can provide you guys with offsets, implementing isn't that hard @MarcelGerber . samp.dll+0x1B0A0 is a class function where you can get the Vehicle ID by GTA:SA Ptr. It's easy to scan for it via pattern (here is the pattern: "\xE8\x00\x00\x00\x00\x66\x3B\xC3", "x????xxx").

The Class pointer is a bit "harder", but i successfully got it since sa-mp 0.3z via pattern scanning offset (samp.dll+0xA6C66) and reading the following 3 mov instructions. The class is the "Vehicle pool" class.

Here is inline assembler code (or... just cast it):

DWORD dwVehicle = 0x0;
DWORD FindVehicleIDFromGtaPtr = 0x1B0A0; // or "\xE8\x00\x00\x00\x00\x66\x3B\xC3", "x????xxx"
static unsigned short vehicleID_Return;
vehicleID_Return = 65535;
if (dwVehicle != nullptr && FindVehicleIDFromGtaPtr != nullptr)
{
    __asm mov eax, dwVehicle
    __asm push eax
    __asm mov ecx, dwVehiclePool
    __asm call FindVehicleIDFromGtaPtr
    __asm mov[vehicleID_Return], ax
}

Hope it helps.

ghost commented 8 years ago

@myudev Nice work, we implement it, if an developer (also you) have time :+1:

Montero98 commented 8 years ago

Thank you for your help @myudev . But i am not as good as to implement your code into the api - so i have to hope, that some developers of the api have the time to implement it as soon as possible, because i really need this function.

Montero98 commented 8 years ago

How is it going? @MarcelGerber @shadowlif @myudev