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 


Lua Function Call Difficulties.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Profound_Darkness
Newbie cheater
Reputation: 0

Joined: 21 May 2015
Posts: 23

PostPosted: Mon Jun 15, 2015 6:24 pm    Post subject: Lua Function Call Difficulties. Reply with quote

So I'm trying to get a register symbol dynamically (I don't know the address yet in the {$lua} section) and am having trouble.

The problem I'm having now is that when I step over the LuaFunctionCall in the code below, eax is 0 and nothing prints. When I step into LuaFunctionCall after the "call CELUA_ExecuteFunction" line eax is 19 (hex) and nothing prints. I've gone so far as to start a from scratch (fresh start of CE) cheat table for the game and have just the included script below.

By comparison when I run similar code meant to be run against Tutorial (comes with CE) everything is fine, eax is 0 in both of the cases I mentioned above.

You can find the original example I've based this on over in viewtopic.php?p=5557169. I've marked all the lines I touched in order to alter the example there fit to the game.

Hoping someone might have a troubleshooting step I might try. I don't know Lua that well and I've only been messing with asm in CE for a couple of weeks (though not completely new to asm in general).

The only difference I can think of is that the code in the game gets executed FREQUENTLY while the code in Tutorial gets executed when you click 'hit me'. Even if I set a breakpoint in the game on the jump into newmem and then hit F9 to run, nothing prints (in the game).

(aside)
If anyone is interested, the end goal is to have a linked list call table which when a new item is added the Lua call is used to register a symbol name to the memory in the list. That symbol is then used in the disable section to shut off that call (eventually the code which reads/follows the list updates the list with to remove the call). The list doesn't support insertion, only append.

Code:

[ENABLE]
{$lua}
openLuaServer("CELUASERVER")

function myfunction(param) --create a global function called myfunction
  print("this function got called")
  print("Do something with "..string.format("%x", param))
end

{$asm}

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

aobscan(aobVarReadSet,DD 45 08 C7 46 04 00 00 00 00 DD 5E 08 5E 5D C3 CC CC 56) // added this line
registersymbol(aobVarReadSet) // and this line

alloc(newmem,128)
alloc(myluascript, 2048)
label(returnhere)
label(originalcode)
label(exit)

myluascript:
db 'myfunction(parameter)',0

newmem: //this is allocated memory, you have read,write,execute access
//placeyour code here
push eax

push ebx
push myluascript
call LuaFunctionCall
pop eax

originalcode: // changed this to match the game's original code.
fld qword ptr [ebp+08] // db DD 45 08 //
mov [esi+04],00000000 // db C7 46 04 00000000 //
fstp qword ptr [esi+08] // db DD 5E 08 //

exit:
jmp returnhere

aobVarReadSet: // this was a static reference in the original example
jmp newmem
nop
nop // the extra nops here weren't in the original example.
nop
nop
nop
nop
nop
nop
returnhere:

[DISABLE] // this whole section is extra from the original.
aobVarReadSet:
db DD 45 08 C7 46 04 00 00 00 00 DD 5E 08 5E 5D C3 CC CC 56

dealloc(newmem)
dealloc(myluascript)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Mon Jun 15, 2015 6:29 pm    Post subject: Reply with quote

run the game as administrator

change
Code:

db 'myfunction(parameter)',0

to
Code:

db 'myfunction',0

_________________
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
Profound_Darkness
Newbie cheater
Reputation: 0

Joined: 21 May 2015
Posts: 23

PostPosted: Mon Jun 15, 2015 8:53 pm    Post subject: Reply with quote

Embarassed administrator did it. A bit disappointed I hadn't tried that already... Thanks.
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