Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Call vtbl function

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Mon May 30, 2022 1:18 am    Post subject: Call vtbl function Reply with quote

So i tried to call function from virtual table, it crashes for me, am i doing something wrong?
So the virtual table is having a lot of functions like fix, teleport, blow and etc.
Virtual table is pointing to the class of vehicle function(for car its CAutomobile::Fix, for bike CBike::Fix and etc.)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25791
Location: The netherlands

PostPosted: Mon May 30, 2022 1:57 am    Post subject: Reply with quote

very likely you're doing it wrong yes

Called it from the wrong thread?
Gave the wrong parameters?
Used the wrong calling convention?

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Mon May 30, 2022 2:21 am    Post subject: Reply with quote

all function that in vtbl are having only one parameter(vehicle *this) where vehicle represents the type of it
i'm calling the function as default
Code:
((int(__cdecl *)(int))addr)(vehicle);
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25791
Location: The netherlands

PostPosted: Mon May 30, 2022 2:25 am    Post subject: Reply with quote

is the target 32-bit ?
and is addr correct?
and are you sure it's __cdecl ? (If it's 32-bit, the function ends with a ret. If it ends with ret 4 , it's stdcall )

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Mon May 30, 2022 2:39 am    Post subject: Reply with quote

yes target is 32 bit
and its virtual table addr will change corresponding to a vehicle type
i'm doing this to "fix" vehicle
Code:
local vtbl = readPointer(FindPlayerPed().ped:GetVehicle().addr)
local vtbl_fix = readPointer(vtbl+0xC8) --> fix function

local s = [[
globalalloc(fixVtbl,128)
createThread(fixVtbl)

fixVtbl:
{$ccode}
((int(__cdecl *)(int))0x%x)(%d); // i guess its digits?
{$asm}
ret
]]

autoAssemble(s:format(vtbl_fix,FindPlayerPed().ped:GetVehicle().addr))


in IDA end of function is retn
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25791
Location: The netherlands

PostPosted: Mon May 30, 2022 5:08 am    Post subject: Reply with quote

check if the function you're calling assumes ECX is filled in, or if it takes it from the stack each time

else try
Code:

fixVtbl:
mov ecx,%x
{$ccode}
((int(__cdecl *)(int))0x%x)(%d); // i guess its digits?
{$asm}
ret
]]

autoAssemble(s:format(FindPlayerPed().ped:GetVehicle().addr, vtbl_fix,FindPlayerPed().ped:GetVehicle().addr))


also, instead of ccode you could try executeMethod:
Code:

executeMethod(1, nil, vtbl_fix, FindPlayerPed().ped:GetVehicle().addr)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Mon May 30, 2022 5:20 am    Post subject: Reply with quote

i'll try it
Back to top
View user's profile Send private message
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Thu Jun 02, 2022 6:03 am    Post subject: Reply with quote

It works, thank you

EDIT:

How is execute method works?
Also is that possible to call an empty function(no parameters) with executeMethod?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25791
Location: The netherlands

PostPosted: Thu Jun 02, 2022 9:41 am    Post subject: Reply with quote

https://github.com/cheat-engine/cheat-engine/blob/6237bee483ae7610c033b671f40370b61a4e7478/Cheat%20Engine/bin/celua.txt#L472

the example I gave is the version where you give no parameters . To add parameters add them to the call of executeMethod

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites