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 


How to call lua function in ASM? Noob alert.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Mar 25, 2016 5:50 pm    Post subject: How to call lua function in ASM? Noob alert. Reply with quote

I want to get a random number when some actions are taken in game and then compare the random number to a value, at last I want to do some actions based on the result of the comparison. However, I couldn't make it work.
Please see the following code, most of them are from template. Thanks in advance.
Code:

---Most of the code in here is from the template except the lua function and the "real" code, which startes at "alloc(newmem,2048)"
{$lua}
openLuaServer("CELUASERVER")

function myfunction(param)   <-------- a lua function that will create a random value named "rate"
                                       I want to pass "rate" to ASM
  math.randomseed(os.time())
  rate = math.random(0,10)
end
{$asm}

---template starts--------------

loadlibrary(luaclient-i386.dll)
luacall(openLuaServer('CELUASERVER'))
globalalloc(luainit, 128)
globalalloc(LuaFunctionCall, 128)
label(luainit_exit)
globalalloc(luaserverinitialized, 4)
globalalloc(luaservername, 12)

luaservername:
db 'CELUASERVER',0

luainit:
cmp [luaserverinitialized],0
jne luainit_exit
push luaservername
call CELUA_Initialize //this function is defined in the luaclient dll
mov [luaserverinitialized],eax
luainit_exit:
ret

LuaFunctionCall:
push ebp
mov ebp,esp
call luainit

push [ebp+c]
push [ebp+8]
call CELUA_ExecuteFunction
pop ebp
ret 8
//luacall call example:
//push integervariableyouwishtopasstolua
//push addresstostringwithfunction  //(The lua function will have access to the variable passed by name "parameter")
//call LuaFunctionCall
//When done EAX will contain the result of the lua function

----template ends-------------

[ENABLE]                <--------------- starts here
alloc(newmem,2048)
alloc(myluascript,2048)
label(returnhere)
label(originalcode)
label(exit)
label(doSomething)

myluascript:
db 'myfunction(parameter)',0

newmem:
push eax
push ebx
push myluascript
call LuaFunctionCall
//pop eax
cmp byte ptr [ebx+04],al   <------------- "I want to compare the value of "rate" with "byte ptr [ebx+04]". If I use "rate" instead of
                                       "al", the value of "rate" is always the same, it seems the lua function is only called once and
                                        will not be called when the action in game repeats. If I use "al", al is always "00000000""


pop eax
je doSomething
jmp originalcode

doSomething:
.....
.....
jmp exit

originalcode:
.....
.....

exit:
jmp returnhere

"game.exe"+110000:
jmp newmem
returnhere:




[DISABLE]
dealloc(newmem)
"game.exe"+110000:
.....
.....

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