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 


Issue with luacall()

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
BanCheese
Cheater
Reputation: 0

Joined: 22 Oct 2014
Posts: 49

PostPosted: Sat Nov 15, 2014 4:15 pm    Post subject: Issue with luacall() Reply with quote

So I've been trying to use luacall() in a script. When I assemble and inject it, my code works fine, but the luacall() stuff isn't there. Here's the script:

Code:

alloc(newmem,2048)
alloc(modulename,2048)
label(returnhere)
label(originalcode)
label(popandoriginalcode)
label(findlenloop)
label(cmploop)
label(aftercmploop)
label(changeesi)
label(exit)

modulename:
db 68, 69


newmem:
push eax
push ebx
push ecx
push edx

mov ebx,[esp+28]
cmp [esp+10],ebx
jne popandoriginalcode

mov eax, 0
mov ecx, 0018EA50
cmploop:
mov dl,[modulename+eax]
cmp dl,0
je aftercmploop
cmp [ecx+eax],dl

jne popandoriginalcode
inc eax
jmp cmploop
aftercmploop:


luacall(readRegionFromFile("script.lua", 00186444))

mov eax, 00186444
findlenloop:
mov dl, [eax]
cmp dl,00
je changeesi
inc eax
jmp findlenloop

changeesi:
mov esi,eax

popandoriginalcode:
pop edx
pop ecx
pop ebx
pop eax

originalcode:
mov edx,[ebp+08]
mov eax,edi

exit:
jmp returnhere

"Jcmp.dll"+5F705D:
jmp newmem
returnhere:

"Jcmp.dll"+5F5111:
jmp Jcmp.dll+5F511F


Here's a pic of the debugger, with an arrow where the luacall() is supposed to be. When I step through that area, it passes like there's nothing there. What am I doing wrong?

Well, I'm not allowed to post links yet, so I hope this is allowed: i(dot)imgur(dot)com/OPKBJvS.png

_________________
A guy who likes memory hacking.
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: Sat Nov 15, 2014 5:27 pm    Post subject: Reply with quote

luacall is a command processor, not an assembler command

that means that as soon as the auto assembler script gets executed it will load script.lua into 00186444

_________________
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
BanCheese
Cheater
Reputation: 0

Joined: 22 Oct 2014
Posts: 49

PostPosted: Sat Nov 15, 2014 6:06 pm    Post subject: Reply with quote

*Sigh* I'm an idiot. Well, is there any way to call that function in real time?
_________________
A guy who likes memory hacking.
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: Sat Nov 15, 2014 6:28 pm    Post subject: Reply with quote

using the lua template
but why load it at runtime? Does the file change multiple times after injection?
And if it does, why not use writeString to update it when the user wants

_________________
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
BanCheese
Cheater
Reputation: 0

Joined: 22 Oct 2014
Posts: 49

PostPosted: Sat Nov 15, 2014 7:46 pm    Post subject: Reply with quote

I suppose it doesn't have to be in real time -- I thought of a way to get around that. Anyway, I'm now I'm using readRegionFromFile("script.lua", scriptstorage), where scriptstorage is memory that I've alloc'd. For some reason, it won't load anything in. Note that this was also happening with the static address as seen above, even when the game was paused and thus not writing to those addresses. What dir should I be putting the file in, and can I specify a full path, too? Thanks!
_________________
A guy who likes memory hacking.
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: Sat Nov 15, 2014 7:54 pm    Post subject: Reply with quote

you have to specify a full path (and make sure the address has enough memory)

Easiest path is inside the cheat engine folder because then you can use
Code:

filename=getCheatEngineDir()+'script.lua'


alternatively, you could let the use choose the file using an OpenDialog
Code:

local od=createOpenDialog(nil)
od.execute()
filename=od.filename
od.destroy()



(also if you didn't allocate it yourself, use fullAccess(address,size) first to make the memory writable)

_________________
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
BanCheese
Cheater
Reputation: 0

Joined: 22 Oct 2014
Posts: 49

PostPosted: Sat Nov 15, 2014 8:02 pm    Post subject: Reply with quote

Hmm, I tried what you said, but it still isn't loading anything.

Code:

{$lua}
local od = createOpenDialog(nil)
od.execute()
filename = od.filename
print(filename)
od.destroy()
readRegionFromFile(filename, scriptstorage)
{$asm}


print(filename) Prints out a valid path (with the drive letter). OH. Just got an idea while writing this. The path has backslashes; does CE want forward slashes?

Oh, and yes, I did allocate it myself, so I already have full access.

Any ideas?
Thanks!

_________________
A guy who likes memory hacking.
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: Sat Nov 15, 2014 8:09 pm    Post subject: Reply with quote

does scriptstorage hold a valid address ? And you're sure it's big enough to hold the file you picked ?

add print(string.format("scriptstorage=%x", scriptstorage))

the path has to have slashes the way the OS wants it (so in windows backslashes)

_________________
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
BanCheese
Cheater
Reputation: 0

Joined: 22 Oct 2014
Posts: 49

PostPosted: Sat Nov 15, 2014 8:13 pm    Post subject: Reply with quote

Hmm, you're right, it wouldn't print because scriptstorage is nil. Do I need to 'import' the variable into lua, or something like that?

Code:

alloc(newmem,2048)
alloc(modulename,2048)
alloc(scriptstorage,1000000)
label(returnhere)
label(originalcode)
label(popandoriginalcode)
label(findlenloop)
label(cmploop)
label(aftercmploop)
label(copyloop)
label(changeesi)
label(exit)

{$lua}
local od = createOpenDialog(nil)
od.execute()
filename = od.filename
print(filename)
print(string.format("scriptstorage=%x", scriptstorage))
od.destroy()
readRegionFromFile(filename, scriptstorage)
{$asm}


It's worth it to note that yes, the alloc is getting detected. When I execute it, CE gives me the little pop with the address for it.

_________________
A guy who likes memory hacking.
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: Sat Nov 15, 2014 8:19 pm    Post subject: Reply with quote

ah yes, unlike luacall {$lua} runs before the alloc is executed

change your script to:
Code:

alloc(newmem,2048)
alloc(modulename,2048)
label(returnhere)
label(originalcode)
label(popandoriginalcode)
label(findlenloop)
label(cmploop)
label(aftercmploop)
label(copyloop)
label(changeesi)
label(exit)
label(scriptstorage)

{$lua}
autoAssemble([[
globalalloc(scriptstorage,1000000)
]])

--globalalloc will allocate it once and reuse it over each time (it also registers it automatically for you)

local scriptstorage=getAddress("scriptstorage")

local od = createOpenDialog(nil)
od.execute()
filename = od.filename
print(filename)
print(string.format("scriptstorage=%x", scriptstorage))
od.destroy()
readRegionFromFile(filename, scriptstorage)

{$asm}


edit: I had a second script but that wouldn't have worked (alloc'ed memory gets allocated after everything has been done)

_________________
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
BanCheese
Cheater
Reputation: 0

Joined: 22 Oct 2014
Posts: 49

PostPosted: Sat Nov 15, 2014 8:31 pm    Post subject: Reply with quote

Well, I hate to keep buggin' you, but it still isn't working. Here's my code:

Code:
{$lua}
function importFile(scriptstorage)
  local od = createOpenDialog(nil)
  od.execute()
  filename = od.filename
  print(filename)
  print("location: " .. scriptstorage)
  od.destroy()
  readRegionFromFile(filename, scriptstorage)
end
{$asm}

alloc(newmem,2048)
alloc(modulename,2048)
alloc(scriptstorage,1000000)
label(returnhere)
label(originalcode)
label(popandoriginalcode)
label(findlenloop)
label(cmploop)
label(aftercmploop)
label(copyloop)
label(changeesi)
label(exit)

luacall(importFile(scriptstorage))


Here's my error (From the lua console):
Code:
Error:[string "local syntaxcheck=......"]:7: attempt to concatenate local 'scriptstorage' (a nil value)


So for some reason it's STILL nil. Any ideas? Thanks!

_________________
A guy who likes memory hacking.
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: Sat Nov 15, 2014 8:31 pm    Post subject: Reply with quote

yeah, that version of the script won't work. luacall doesn't know what the address is going to be. check the other solution
_________________
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
BanCheese
Cheater
Reputation: 0

Joined: 22 Oct 2014
Posts: 49

PostPosted: Sat Nov 15, 2014 8:35 pm    Post subject: Reply with quote

Yes! It works, thanks so much! I've been working on this script for weeks and I'm really happy to finally have it done. Thanks again!
_________________
A guy who likes memory hacking.
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