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 


Problems with LUA
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
dl748
Advanced Cheater
Reputation: 0

Joined: 05 Mar 2016
Posts: 75

PostPosted: Sat Oct 15, 2016 3:55 am    Post subject: Problems with LUA Reply with quote

I'm having a problem with LUA that I'm not having with the AA. When I create a script with [ENABLE] [DISABLE], the enable runs every time I edit and save the script, which doesn't happen when its dealing with asm. Is there a method to determine if the script is being enabled/disabled in LUA?

Code:
[ENABLE]
{$lua}
showMessage("Hello")
{$asm}

[DISABLE]


a message box pops up when enabled, but not disable but it ALSO runs when you edit and save it, even if script is disabled.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Oct 15, 2016 5:09 am    Post subject: Reply with quote

Add
Code:

if syntaxcheck then return end

To the start of your lua block

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

Joined: 05 Mar 2016
Posts: 75

PostPosted: Sat Oct 15, 2016 1:35 pm    Post subject: Reply with quote

Thanks works perfectly!

I have one more question, do you not execute code in order? It seems that LUA code executes BEFORE AA code

Code:
[ENABLE]
alloc(datablock, $1000)

datablock:
  dd 0

{$lua}
dataloc = getAddress("datablock")


The getAddress fails unless i wrap it in a timer or something that delays the execution of the code. Is this by design?
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 15, 2016 1:45 pm    Post subject: Reply with quote

Correct, Lua executes first.
Code:
{$lua}
autoAssemble([[
alloc(datablock, $1000)
datablock:
  dd 0
registersymbol(datablock)
]])
dataloc = getAddress("datablock")
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Oct 15, 2016 2:29 pm    Post subject: Reply with quote

Yes, lua executes first.
the return value of lua is parsed by the auto assembler
e.g:
Code:

alloc(bla,4096)
label(xxx)
label(routine1)
label(routine2)

{$lua}
if oldgameversion then
  return [[
xxx:
jmp routine1
]]
else
return [[
xxx:
jmp routine2
]]
end
{$asm}

bla:
jmp xxx

routine1:
db 'do something'

routine2:
db 'do something else'




can either result in:
Code:

alloc(bla,4096)
label(xxx)
label(routine1)
label(routine2)

xxx:
jmp routine1



bla:
jmp xxx

rounte1:
db 'do something'

routine2:
db 'do something else'


or
Code:

alloc(bla,4096)
label(xxx)
label(routine1)
label(routine2)

xxx:
jmp routine2


bla:
jmp xxx

rounte1:
db 'do something'

routine2:
db 'do something else'

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

Joined: 05 Mar 2016
Posts: 75

PostPosted: Fri Oct 21, 2016 5:44 pm    Post subject: Reply with quote

Thanks, everything is working perfectly except one last thing.

When I call registerSymbol() the first time, the table updates with the correct values, but when i unregisterSymbol() via [DISABLE] and then registerSymbol() again with the [ENABLE] The table doesn't update with the new values, I have to double click the address and then click cancel, then that table entry updates (the rest do not)

Is there a way to tell Cheat Engine to force a resolve of all table entries with a symbol in it via lua?
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Oct 22, 2016 4:40 am    Post subject: Reply with quote

Post your script. If you don't want to post whole script, remove all not needed parts (leave the most important things). Then, we can help you to fix that.

Why we need the script? To understand what you really want. For example you wrote registerSymbol(), but we do not know if you are using "registersymbol AutoAssemble command" or "registerSymbol Lua function inside {$Lua} block inside AutoAssemble script".

_________________
Back to top
View user's profile Send private message MSN Messenger
dl748
Advanced Cheater
Reputation: 0

Joined: 05 Mar 2016
Posts: 75

PostPosted: Sun Oct 23, 2016 10:32 pm    Post subject: Reply with quote

i thought registerSymbol() was only in lua.

anyway here is here is the code

Code:

[ENABLE]
{$lua}
if syntaxcheck then return end
registerSymbol("MYTEST", getAddress("MYEXE.EXE+1123A"))

[DISABLE]
{$lua}
if syntaxcheck then return end
unregisterSymbol("MYTEST")


Then i create a table entry with MYTEST symbol in it.

When I initially load cheat engine and check the script. (MYTEST) changes to the address of the entry. When I uncheck the script, the table entry still has the same value in it. When i double click the address, a window pops up saying that MYTEST = ??? and then when I click cancel or press ESC, the table entry refreshes to (MYTEST). When I recheck the script, it stays (MYTEST) until i double click the address, then it shows a number instead of ???.. When i click the cancel or press ESC, the table entry THEN refreshes to the correct value.


Update:

I take that back, it does update, but after a really long time, 30 secs to 2 mins. The auto assembler happens immediately.

Also I have to double click and cancel every table entry that contains a registered symbol in order to force the update. i.e. If i make 2 entries called MYTEST, and click the check box to run the enable script. If i double click one and cancel, it updates but not not the second one. I have to do that manually as well.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon Oct 24, 2016 4:11 pm    Post subject: Reply with quote

Code:
[ENABLE]
label(MYTEST)
MYEXE.EXE+1123A:
MYTEST:
registersymbol(MYTEST)
[DISABLE]
unregistersymbol(MYTEST)
Back to top
View user's profile Send private message
dl748
Advanced Cheater
Reputation: 0

Joined: 05 Mar 2016
Posts: 75

PostPosted: Tue Oct 25, 2016 12:53 am    Post subject: Reply with quote

Unfortunately that doesn't work in LUA. I gave you a simple reproducible example to demonstrate the problem I'm seeing.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Oct 25, 2016 3:06 am    Post subject: Reply with quote

Script provideed by Zanzer doesn't use Lua.




Try this one:
Code:
[ENABLE]
alloc(newmemmytest,8)
label(MYTEST)
registersymbol(MYTEST)

newmemmytest:
MYTEST:
dq MYEXE.EXE+1123A


[DISABLE]
dealloc(newmemmytest)
unregistersymbol(MYTEST)


This is pure AA script, also no Lua involved. Add level-one pointer with MYTEST as base, offsets is zero.
Cheat table entries will update immediately.

_________________
Back to top
View user's profile Send private message MSN Messenger
dl748
Advanced Cheater
Reputation: 0

Joined: 05 Mar 2016
Posts: 75

PostPosted: Tue Oct 25, 2016 10:17 am    Post subject: Reply with quote

Right, which is why I said it doesn't work in LUA. I created a simple example to demonstrate the problem I'm seeing. My actual script is very long and does dynamic creation of Symbols and Table Entries. I already know that the AA script works and is immediate, but what I'm saying is that registersymbol() and registerSymbol() seem to do 2 completely different things and if there was a function like 'updateSymbolTable()' or 'symbolTableRefreshed()' which forces the showing table to refresh the display of those symbols.

In AA, registersymbol() -> refreshes the table view
In LUA, registerSymbol() -> does not refresh the table view

I've even tried to "HACK" it by calling autoAssemble() to generate the symbol, but that doesn't work either

Code:

local function myregistersymbol(name, addr)
  autoAssemble("label(" .. name .. ")\r\n\r\n" .. string.format("%X", addr) .. ":\r\n"..name..":\r\n\r\nregistersymbol("..name..")")
end


It does register the symbol, but the table does not update.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Oct 25, 2016 11:30 am    Post subject: Reply with quote

you can force a reinterpretation of all addresses in the addresslist using
Code:

local al=getAddressList()
local i
for i=0,al.Count-1 do
  al[i].Address=al[i].Address
end

_________________
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
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Oct 25, 2016 2:46 pm    Post subject: Reply with quote

@DB, this solution has a downside, it will damage memrecs with pointers (if any).

memoryrecord_setAddress(L: PLua_state) if only one argument passed (Address property), it sets offsetCount to zero. We have to use setAddress method with second argument (a table with offsets).


Also:
CE source code comment wrote:
update 12/31/2011. Reinterpretaddress now also calls it automatically for it's children. So only call for the level 1 entries

So, we can force stronger reinterpretation on only top level memrecs (memrecs without Parent).


This should be better :
Code:
local al=getAddressList()

for i=0,al.Count-1 do
  if al[i].Parent==nil then
    local a,poffsets = al[i].getAddress()
    al[i].setAddress(a,poffsets)
  end
end









@dl748, you see

You wrote this:
Quote:
but when i unregisterSymbol() via [DISABLE] and then registerSymbol() again with the [ENABLE] The table doesn't update with the new values,

Instead of: "when, with Lua, I unregisterSymbol and registerSymbol it again, the table doesn't update with the new values"

Quote:
Right, which is why I said it doesn't work in LUA. I created a simple example to demonstrate the problem I'm seeing

Then, you should provide that example as pure Lua code, and not Lua blocks inside AA script. But, we are getting closer, step-by-step.


Quote:
I take that back, it does update, but after a really long time, 30 secs to 2 mins

In CE, there is ReinterpretAddress (internal CE function), it can work in two modes: weak and strong

Weaker version of ReinterpretAddress is taken after activating memory record with AA script (with symbols) or every 7.5 seconds (if you have "update interval" set to 500 milliseconds, in main CE settings). registerSymbol in Lua do not call ReinterpretAddress so you have to wait a little.

"update interval" is used to refresh address list:
- "Value" column every INTERVAL
- "Address" column (reinterpreting in weak mode) every INTERVAL*15

So, set "update interval" to 100milliseconds, ReinterpretAddress (weak mode) will launch every 1.5 seconds.


To force ReinterpretAddress in strong mode, execute below function after you made changes (after you change symbols with unregisterSymbol and registerSymbol)
Code:
function forceStrongReinterpretAddresses()
  local al=getAddressList()

  for i=0,al.Count-1 do
    if al[i].Parent==nil then
      local a,poffsets = al[i].getAddress()
      al[i].setAddress(a,poffsets)
    end
  end
end



Or use this Lua script, it will modify CE itself (self inject). It will force usage of stronger version of ReinterpretAddress.
Script only for CE6.6.0.1 released 10/10/2016:
Code:
autoAssemble([[define(address,cheatengine-x86_64.exe+1D2184)
define(bytes,40 88 D6 48 C7 45 F8 00 00 00 00)
assert(address,bytes)
address:
mov sil,01]],true)

_________________
Back to top
View user's profile Send private message MSN Messenger
dl748
Advanced Cheater
Reputation: 0

Joined: 05 Mar 2016
Posts: 75

PostPosted: Wed Oct 26, 2016 12:46 pm    Post subject: Reply with quote

Thanks I'll give that a try.

I would have given a "PURE" lua example if i knew how to actually do that. From what I've gathered the script that you define in a table entry defaults to AA. So I'm not sure how to tell an entry that it is a "PURE" lua without using {$lua} to force it in the script.
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
Goto page 1, 2  Next
Page 1 of 2

 
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