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 


How to disable AA script in Lua?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Feb 26, 2016 12:22 pm    Post subject: How to disable AA script in Lua? Reply with quote

I have the following AA script in Lua, which stores the [ENABLE] part and [DISABLE] part:
Code:

t={
    [[
    ------- This is the [ENABLE] part
    ]],
    [[
    -------This is the [DISABLE] part
    ]]
    }



I know that I can use "autoAssemble(t[1][1])" to execute the [ENABLE] part, however, Dark Byte said that "autoAssemble(t[1][2])" cannot be used to execute the [DISABLE] part. So my question is: how should I execute the [DISABLE] part? BTW, all the codes are in Lua, nothing is in the cheat table.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Fri Feb 26, 2016 12:36 pm    Post subject: Reply with quote

you can assemble disable sections, but dealloc won't work
for dealloc to work it needs to be inside a cheat table entry

_________________
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
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Feb 26, 2016 1:07 pm    Post subject: Reply with quote

Dark Byte wrote:
you can assemble disable sections, but dealloc won't work
for dealloc to work it needs to be inside a cheat table entry


Is it OK if I do not dealloc them? They are just 4kb of memory. Very Happy
I cannot use a cheat table because I do not know how to transfer data from Lua to AA scrippt in CT. Sad
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Fri Feb 26, 2016 1:10 pm    Post subject: Reply with quote

Ce 6.5 have a not yet exposed lua function DeAlloc (case sensitive), I'm not sure if it is safe to use and exactly how its use, but seems working.

If 'newmem' is the symbol used in the AA alloc command of the Enable part, and registered, so that lua can be referred it,
Code:
DeAlloc('newmem')

will deallocate the respective memory.
But all AA alloc symbols in same Enable part will be group together, this function behavior is deallocate all grouped alloc symbol if one of them is deallocted by DeAlloc, and it seems no error even the symbol is already deallocated.
Not test, should work(?)
Given DisableScript is the disable part
Code:

DisableScript:gsub('%s*[dD][eE][aA][lL][lL][oO][cC]%s*%(%s*([_%a][_%w%.]*)%s*%)',function(sym)DeAlloc(sym)end)
local DisableSucceeded = autoAssemble(DisableScript)
...
print(tostring(  DisableSucceeded ))-- etc.


*note:
In an AA script , there should be 3 part,
Common Part before the line [ENABLE]
Enable Part between [ENABLE][DISABLE]
Disable Part after [DISABLE]

When Converting AA Script for use of Lua function autoAssemble, the EnableScript should be Common Part +Enable Part, while
DisableScript should be Common Part +Disable Part.
Better remove all comment in AA script, so that DeAlloc may not run on a commented symbol using in other script.

Without DeAlloc, ie. ce 6.4, the memory cannot be deallocted by lua, causing negligible memory leak.

from DB's response, he seems forget this function? My ce 6.5 is from offical Wink


ADDED:
In main.lua, Memory Record Class
Code:
  Script: String - If the type is vtAutoAssembler this will contain the auto assembler script
 

so in lua, given a memory record object mr, this should set the script:
Code:

mr.Type = vtAutoAssembler
mr.Script = scriptText

_________________
- Retarded.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Feb 26, 2016 2:50 pm    Post subject: Reply with quote

panraven wrote:
Ce 6.5 have a not yet exposed lua function DeAlloc (case sensitive), I'm not sure if it is safe to use and exactly how its use, but seems working.

If 'newmem' is the symbol used in the AA alloc command of the Enable part, and registered, so that lua can be referred it,
Code:
DeAlloc('newmem')

will deallocate the respective memory.
But all AA alloc symbols in same Enable part will be group together, this function behavior is deallocate all grouped alloc symbol if one of them is deallocted by DeAlloc, and it seems no error even the symbol is already deallocated.
Not test, should work(?)
Given DisableScript is the disable part
Code:

DisableScript:gsub('%s*[dD][eE][aA][lL][lL][oO][cC]%s*%(%s*([_%a][_%w%.]*)%s*%)',function(sym)DeAlloc(sym)end)
local DisableSucceeded = autoAssemble(DisableScript)
...
print(tostring(  DisableSucceeded ))-- etc.


*note:
In an AA script , there should be 3 part,
Common Part before the line [ENABLE]
Enable Part between [ENABLE][DISABLE]
Disable Part after [DISABLE]

When Converting AA Script for use of Lua function autoAssemble, the EnableScript should be Common Part +Enable Part, while
DisableScript should be Common Part +Disable Part.
Better remove all comment in AA script, so that DeAlloc may not run on a commented symbol using in other script.

Without DeAlloc, ie. ce 6.4, the memory cannot be deallocted by lua, causing negligible memory leak.

from DB's response, he seems forget this function? My ce 6.5 is from offical Wink


ADDED:
In main.lua, Memory Record Class
Code:
  Script: String - If the type is vtAutoAssembler this will contain the auto assembler script
 

so in lua, given a memory record object mr, this should set the script:
Code:

mr.Type = vtAutoAssembler
mr.Script = scriptText

It seems a bit complicated for me, but thanks a lot. Can y ou explain what the common part is? I haven't seen that part in the template provided by code injection.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Fri Feb 26, 2016 3:08 pm    Post subject: Reply with quote

explain?:
In an AA script , there should be 3 part,
Common Part before the line [ENABLE]
Enable Part between [ENABLE][DISABLE]
Disable Part after [DISABLE]

[ENABLE] in 1st line, means common part is empty.

It is not necessary to create an aa script with concrete common part, just remind that there is a common part in case someone want to convert aa script in memory record for lua usage.

_________________
- Retarded.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Fri Feb 26, 2016 3:13 pm    Post subject: Reply with quote

Assume you have such AA script:

Code:
define(address, gamename.exe+0348033C)

[ENABLE]

stuff_1_here
stuff_1_here
stuff_1_here


[DISABLE]

stuff_2_here
stuff_2_here
stuff_2_here




When enabling CE will do this
Code:
define(address, gamename.exe+0348033C)


stuff_1_here
stuff_1_here
stuff_1_here



When disabling:
Code:
define(address, gamename.exe+0348033C)

stuff_2_here
stuff_2_here
stuff_2_here








About deAlloc function...
I requested it to be added in CE6.5.

I think DB didn't forget about it. I think he didn't want to write about it because you are a beginner. You really should use memory records.






fmanager wrote:
I cannot use a cheat table because I do not know how to transfer data from Lua to AA scrippt in CT. Sad

What data? Can you be more specific?

_________________


Last edited by mgr.inz.Player on Fri Feb 26, 2016 4:04 pm; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Fri Feb 26, 2016 3:19 pm    Post subject: Reply with quote

mgr.inz.Player wrote:

...
I think DB didn't forget about it. I think he didn't want to write about it because you are a beginner. You really should use memory records.


I see~
Is there risk of crash?

_________________
- Retarded.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Fri Feb 26, 2016 3:34 pm    Post subject: Reply with quote

assume you have AA script which allocates memory region, and you are using "user symbol" to keep the address of that region.

You enable the cheat with autoAssemble() and NUMPAD1 hotkey
and disable the cheat with autoAssemble(), deAlloc() and NUMPAD2 hotkey


Doing NUMPAD2 for the first time will work as should. Cheat is disabled.

Now imagine you accidentally pressed NUMPAD2 again. Two scenarios:
- deAlloc() will do nothing wrong (virtualfreeex will just fail and DeAlloc will return false).

- deAlloc() will free the memory allocated by game - can lead to game crash.




To fix this, you have use DeAlloc() and unregisterSymbol() in Lua. And extra variable...

Example, this is straight forward AA script (Infinite Health cheat) placed in memory record (address list entry):
Code:
[ENABLE]
alloc(InfiniteHealth,2048,BlackOps3.exe)
aobscanmodule(InfiniteHealthAOB,BlackOps3.exe,8B 83 C8 02 00 00 48 8B)
registersymbol(InfiniteHealthAOB)
label(return)

InfiniteHealth:
  mov [rbx+000002C8],#999
  jmp return

InfiniteHealthAOB:
  jmp InfiniteHealth
  nop
return:

[DISABLE]
InfiniteHealthAOB:
  db 8B 83 C8 02 00 00

unregistersymbol(InfiniteHealthAOB)

dealloc(InfiniteHealth)






If someone don't want to use memory records, here:
Code:
InfiniteHealth_enable = [[
alloc(InfiniteHealth,2048,BlackOps3.exe)
label(InfiniteHealthUserSymbol)
registersymbol(InfiniteHealthUserSymbol)

aobscanmodule(InfiniteHealthAOB,BlackOps3.exe,8B 83 C8 02 00 00 48 8B)
registersymbol(InfiniteHealthAOB)
label(return)

InfiniteHealth:
InfiniteHealthUserSymbol:
  mov [rbx+000002C8],#999
  jmp return

InfiniteHealthAOB:
  jmp InfiniteHealth
  nop
return:
]]

InfiniteHealth_disable = [[
InfiniteHealthAOB:
  db 8B 83 C8 02 00 00

unregistersymbol(InfiniteHealthAOB)
]]

function enableInfiniteHealthCheat()
  if not InfiniteHealthCheatIsEnabled then
    InfiniteHealthCheatIsEnabled = autoAssemble(InfiniteHealth_enable)
  end
end

function disableInfiniteHealthCheat()
  if InfiniteHealthCheatIsEnabled then
    autoAssemble(InfiniteHealth_disable)
    deAlloc('InfiniteHealthUserSymbol')
    unregisterSymbol('InfiniteHealthUserSymbol')
    InfiniteHealthCheatIsEnabled = false
  end
end




Edit:
found typos.

_________________


Last edited by mgr.inz.Player on Mon Mar 07, 2016 12:29 pm; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Fri Feb 26, 2016 5:03 pm    Post subject: Reply with quote

Thanks, at least I see that lua enable/disable action should be respect the equivalence of Memory Record Active/Deactive state, ie. InfiniteHealthCheatIsEnabled .

mgr.inz.Player wrote:

...
Code:

...
[DISABLE]
InfiniteHealthAOB:
  db 8B 83 C8 02 00 00

unregistersymbol(InfiniteHealthAOB)

dealloc(InfiniteHealth)
...
...
InfiniteHealth_disable = [[
InfiniteHealthAOB:
  db 8B 83 C8 02 00 00

unregistersymbol(InfiniteHealthAOB)
]]


the two disable parts (also enable part) are not exactly the same, so the conversion from MemoryRecord AA to Lua-autoAssemble mostly need manual editing, I guess.

_________________
- Retarded.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Feb 26, 2016 8:05 pm    Post subject: Reply with quote

fmanager wrote:
I cannot use a cheat table because I do not know how to transfer data from Lua to AA scrippt in CT. Sad

What data? Can you be more specific?[/quote]

Thanks for the reply. I want to pass a user input variable from CEEdit1 to the AA script. I tried to follow your instruction and wrote the following code, but it sometimes crashes the game or has no effect at all, I don't know whats wrong with it:
Code:

number = 0

statsChange_enable = [[
alloc(newmem,4096)
  label(returnhere)
  label(originalcode)
  label(exit)
  label(addStats1)

  newmem:
  cmp byte ptr [ebx+19],$number
  jl addStats1
  jmp exit

  addStats1:
  movzx eax,byte ptr [number]
  mov byte ptr [ebx+19],al
  jmp exit

  originalcode:
  movzx eax,byte ptr [ebx+19]
  cmp eax,ecx

  exit:
  jmp returnhere

  "game.exe"+5A7E3A:
  jmp newmem
  nop
  returnhere:
  ]]

statsChange_disable = [[
dealloc(newmem)
  "game.exe"+5A7E3A:
  movzx eax,byte ptr [ebx+19]
  cmp eax,ecx
  ]]


function CEButton1Click(sender)
number = tonumber(getProperty(UDF1.CEEdit1,"Text"))
if number == nil or number <= 0 or number > 250 then
  showMessage("Input out of range.")
else
    writeInteger("number",number)
      autoAssemble(statsChange_enable)
      local t = createTimer(sender, false)
      -----showMessage("test 1")
      t.OnTimer = function()
      autoAssemble(statsChange_disable)
      t.Enabled = false
      -----showMessage("test 2")
      end
      t.Interval = 1000
      t.Enabled = true
end
end


I cannot use "writeBytes" because it will return "failure attempt to determine what number means.
Thanks in advance.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Sat Feb 27, 2016 5:42 am    Post subject: Reply with quote

For that, you need "user defined symbol", "memory record" and Lua.

Enable section should look like this:
Code:
  alloc(newmem,4096)
  label(returnhere)
  label(exit)

  label(userInputStat)
  registersymbol(userInputStat)

  newmem:
  mov al,[userInputStat]
  cmp byte ptr [ebx+19],al
  jge exit

  mov byte ptr [ebx+19],al

  exit:
  movzx eax,byte ptr [ebx+19] //originalcode
  cmp eax,ecx                 //originalcode
  jmp returnhere

  userInputStat:
  dd #35


  "game.exe"+5A7E3A:
  jmp newmem
  nop
  returnhere:




CEButton1Click function like this
Code:
function CEButton1Click(sender)
  local number = tonumber(UDF1.CEEdit1.Text)
  if number then

    -- in case it is not enabled, activate/enable it
    getAddressList().getMemoryRecordByDescription('Infinite Stats').Active = true

    -- update
    writeInteger('userInputStat',number)
  end
end



example.CT
 Description:

Download
 Filename:  example.CT
 Filesize:  1.84 KB
 Downloaded:  732 Time(s)


_________________
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