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 


Need example for Lua ASM creation

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
zxuiji
Advanced Cheater
Reputation: 1

Joined: 26 Sep 2016
Posts: 70

PostPosted: Sat Oct 13, 2018 2:54 am    Post subject: Need example for Lua ASM creation Reply with quote

I'll start with psuedo code for hat I want:
Code:

function OnActivateAction()
...
mem = allocInHookedApp( size )
src = assembleIntoString(([[jmp %x
nop nop]]):format(mem))
dst = assembleIntoString(([[set 0
return]])
writeBytes( ptr, src )
writeBytes( mem, dst )
...
end

I'm basically importing some scripts made by others into my own table but want the ability to fiddle with them later which is easier to do with lua

_________________
Those who do not trust in christ to save them from their sins will only experience hell when their soul is released from it's earthly vessel.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 150

Joined: 06 Jul 2014
Posts: 4652

PostPosted: Sat Oct 13, 2018 9:00 am    Post subject: Reply with quote

Use the autoAssemble function to write AA scripts in Lua.

Code:
local myscript = [[
[ENABLE]
aobscan(foo,12 34 ab cd)
registersymbol(foo)
foo+2:
  db 56 78
[DISABLE]
foo+2:
  db ab cd
unregistersymbol(foo)
]]

-- enable script
local enabled, disableinfo = autoAssemble(myscript)
assert(enabled, 'script did not enable')
-- disable script
local disabled = autoAssemble(myscript, disableinfo)
assert(disabled, 'script did not disable')

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
zxuiji
Advanced Cheater
Reputation: 1

Joined: 26 Sep 2016
Posts: 70

PostPosted: Sun Oct 14, 2018 12:00 pm    Post subject: Reply with quote

Forgot about this already XD, I tried what you said but failed to get it working so I tried this little snippet in my memory record builder:
Code:

if x.asm then
    r.Type = vtAutoAssembler
    r.Script = x.asm

Which seems to respond fine but I got a bug elsewhere in my code preveting me from seeing it working so I will get back to you when I fix it.

Edit: Okay, so I managed to fix the bug and seperated the aobscan out for multiple functions to make use of but now I'm struggling to make the asm (for reference sake the original asm was made by Squall8) part work:
Code:

[ENABLE]
sChocoboUseST:
  db 90 90 90 90 90 90 90 90

[DISABLE]
sChocoboUseST:
  db F3 0F 11 87 CC 00 00 00

Did have the game running (crashed on me while I was typing this) and have confirmed the symbol is found and exists (got memory record above this entry using the symbol for the address and the type as byte array). Any ideas to why it's not working?

Edit 2: Turns out the asm part wasn't actually executing, I must be missing something then

Edit 3: At long last I got it to work by doing both the Type/Script thing AND your autoAssembler method, result is this section of code:
Code:

r.Type = vtAutoAssembler
    r.Script = (asm:format(x.asm.enable,x.asm.disable))
    --[[
Named list of internal symbols, so one can see if it is functioning, mrAddOffset is just a wrapper for creating memory records using symbols for their address and name
    --]]
    if x.internal then
      for j,y in pairs(x.internal) do
        local tmp = mrAddOffset(y,y)
        tmp.appendToEntry(r)
      end
    end
    r.OnActivate = function(r,b,c)
      local x = s.findSymbolByIndex(r.Index)
      if not x then return false end
      local success, info = autoAssemble(r.Script)
      if not success then return false end
      x.disableInfo = info
      return true
    end
    r.OnDeactivate = function(r,b,c)
      local x = s.findSymbolByIndex(r.Index)
      if not x or not x.disableInfo then
        return false
      end
      local success, msg = autoAssemble(r.Script,x.disableInfo)
      if not success then
        print(msg)
        return false
      end
      return true
    end
    r.OnDestroy = function(r)
      r.OnDeactivate(r)
    end

_________________
Those who do not trust in christ to save them from their sins will only experience hell when their soul is released from it's earthly vessel.
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 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