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 


Just LUA Questions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
vng21092
Grandmaster Cheater
Reputation: 15

Joined: 05 Apr 2013
Posts: 644

PostPosted: Thu Oct 08, 2015 7:10 pm    Post subject: Just LUA Questions Reply with quote

Hey guys, just a quick question. Does LUA have an equivalent of aobScanModule? If so, whats the syntax? Thanks.

Last edited by vng21092 on Sat Oct 17, 2015 7:50 pm; edited 1 time in total
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Oct 08, 2015 8:07 pm    Post subject: Reply with quote

Code:
local memscan = createMemScan()
local foundlist = createFoundList(memscan)
local bytes = "48 83 EC 28 E8 9B 03 00 00"
local module = "Calculator.exe"
local start = getAddress(module)
local stop = start + getModuleSize(module)
memscan.firstScan(
  soExactValue, vtByteArray, rtRounded,
  bytes, nil, start, stop, "+X-C-W",
  fsmNotAligned, "1", true, false, false, false)
memscan.waitTillDone()
foundlist.initialize()
local address = foundlist.Address
for i = 0, foundlist.Count-1 do
  print(address[i])
end
foundlist.Destroy()
memscan.Destroy()
Back to top
View user's profile Send private message
vng21092
Grandmaster Cheater
Reputation: 15

Joined: 05 Apr 2013
Posts: 644

PostPosted: Thu Oct 08, 2015 8:30 pm    Post subject: Reply with quote

...wow that's a lot to take in, thanks. Just out of curiosity I was just reading up one of DBs older posts about aobscan where an array was returned. Near the end of the code he wrote
Code:
aob.destroy()
aob = nil
What exactly does the destroy function do? And why set the variable to nil afterwards? Is there a downside to not doing this?
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Oct 08, 2015 11:20 pm    Post subject: Reply with quote

Destroy cleans up the object on the Delphi side. Given that everything Cheat Engine exposes to Lua is just wrapped objects from Delphi, they need to be cleaned up in certain cases.

Setting to nil is more or less just cleanup code to ensure the object is not attempted to be used again. More or less garbage collection in a sense. It isn't needed once destroy is used, the object is already cleaned up at that point on the Delphi side.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Fri Oct 09, 2015 3:47 am    Post subject: Reply with quote

The 'nil' is necessary in some case I guess. It may cause 'access violation' in some case if not.
Code:
local withNil = true
function localSL()
  local sl = createStringlist()
  sl.Destroy()
  if withNil then
    sl = nil
  end
  return sl
end
print("--- with nil")
local lsl = localSL()
print(lsl and lsl.Count or -1)
print("--- without nil")
withNil=false
lsl = localSL()
print(lsl and lsl.Count or -1)

_________________
- Retarded.
Back to top
View user's profile Send private message
vng21092
Grandmaster Cheater
Reputation: 15

Joined: 05 Apr 2013
Posts: 644

PostPosted: Fri Oct 09, 2015 7:39 am    Post subject: Reply with quote

ahh gotcha, thanks guys. Another question (sorry, trying to learn LUA), it seems that every time I edit a asm script with a luaCall in it, whenever I press "OK" the LUA part gets executed, is there anyway to stop that from happening? If I hit assign to cheat table the script doesn't get executed but when I edit it, it does.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Fri Oct 09, 2015 7:53 am    Post subject: Reply with quote

Hmm, that's weird as luacall should also execute on assign to cheat table

Anyhow, I recommend you use this kind of code instead:
Code:

{$lua}
if syntaxcheck==false then
  --your lua code here
end
{$asm}


that way the lua code only gets executed when it's actually executed

_________________
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
vng21092
Grandmaster Cheater
Reputation: 15

Joined: 05 Apr 2013
Posts: 644

PostPosted: Fri Oct 09, 2015 9:12 am    Post subject: Reply with quote

hmm thanks DB that worked, but then I tried implementing this WITHIN the lua script itself but I guess it doesn't work that way?

Code:
 function newFunction()
    if (syntaxcheck == false) then
        ...my code...
    end
end


and then in the asm window I just wanna see

Code:
luaCall(myFunction())
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Oct 09, 2015 11:12 am    Post subject: Reply with quote

That code is only preventing the function's code from running during script creation/update.
The rest of your Lua is still running. Maybe try something like:
Code:
{$lua}
if syntaxcheck then return end
{$asm}
[ENABLE]
blahblah
[DISABLE]
blahblah
Back to top
View user's profile Send private message
vng21092
Grandmaster Cheater
Reputation: 15

Joined: 05 Apr 2013
Posts: 644

PostPosted: Sat Oct 10, 2015 8:41 pm    Post subject: Reply with quote

does ASM have any methods that can read the data off a LUA variable?
Code:
[Enable]

{$lua}
thisnumber = 1

{$asm}
cmp thisnumber,1

[Disable]
something like that?
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Oct 10, 2015 9:01 pm    Post subject: Reply with quote

Code:
[ENABLE]
{$lua}
autoAssemble([[
alloc(myvar,4)
registersymbol(myvar)
]])
writeInteger("myvar", 1)
{$asm}
cmp [myvar],1
[DISABLE]
unregistersymbol(myvar)
dealloc(myvar)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Oct 11, 2015 1:14 am    Post subject: Reply with quote

registersymbol, and i think $globalluavar, but that one is ambiguous to use (difficult to predict if it's going to get handled as an hex, int or string)

also, the return value of lua sections will be interpreted as an autoassembler command (or multiple if you return a string with muktiple lines)
you can do something like:
Code:
 
{$lua}
a1=0x123456
a2=a1+0x10

return string.format([[
define(a1,%x)
define(a2,%x)
]],  a1, a2)
{$asm}

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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