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 


[Solved]Define lua function local variable into c code

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

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Tue Oct 12, 2021 10:21 am    Post subject: [Solved]Define lua function local variable into c code Reply with quote

As title says.I've used auto assemble in lua to execute c code and asm script that allows to call game function,but calling lua function with parametres won't do anything
_________________
void(__cdecl *Haxing)(HWND hGameWindow)


Last edited by Frouk on Tue Oct 12, 2021 11:20 am; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Oct 12, 2021 10:29 am    Post subject: Reply with quote

is the lua function in the game or in CE ?

if in CE use {$luacode value=reg}

and call whatever function you like

_________________
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
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Tue Oct 12, 2021 10:31 am    Post subject: Reply with quote

This is a function in lua table that connects to c code
Code:

function gameSetWorldHeat(DesiredHeatLevel)
local s = [[
alloc(worldHeat,1024)
createThread(worldHeat)

worldHeat:
{$ccode tmp=eax}
typedef int(__cdecl *fGame_SetWorldHeat)(float,void);

fGame_SetWorldHeat Game_SetWorldHeat = (fGame_SetWorldHeat)0x65C550;

Game_SetWorldHeat(DesiredHeatLevel) //Must be setted but won't
{$asm}
ret

dealloc(worldHeat)
]]
autoAssemble(s)
end

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Oct 12, 2021 10:59 am    Post subject: Reply with quote

ok but what is your issue/what you want to do?
_________________
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
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Tue Oct 12, 2021 11:04 am    Post subject: Reply with quote

I call function like this:
Code:
gameSetWorldHeat(5)

But after function was called there's no difference beetween values(value didn't changed)

EDIT:
I tried string.format and it worked

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4290

PostPosted: Tue Oct 12, 2021 11:31 am    Post subject: Reply with quote

You have alloc and dealloc in the same script. I don't know what exactly happens, but it's wrong.
The simplest thing you can do is use globalalloc and no dealloc.

In the script, DesiredHeatLevel is just part of the string literal. It isn't the parameter passed to the function. You need to use string.format if you want to format the string with the argument.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Oct 12, 2021 11:32 am    Post subject: Reply with quote

oh yes, that dealloc won't work
_________________
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
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Tue Oct 12, 2021 12:40 pm    Post subject: Reply with quote

For me alloc and dealloc works in one script,idk how,but its working
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4290

PostPosted: Tue Oct 12, 2021 1:43 pm    Post subject: Reply with quote

The code executes fine but the script leaks memory every time it's run. Replace alloc with globalalloc and remove dealloc. globalalloc only allocates memory once so it doesn't leak.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Tue Oct 12, 2021 1:52 pm    Post subject: Reply with quote

Ok i will
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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