Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Fri Mar 25, 2016 5:50 pm Post subject: How to call lua function in ASM? Noob alert. |
|
|
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:
.....
.....
|
|
|