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 free memory properly in Lua autoAssemble?

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

Joined: 21 Feb 2016
Posts: 115

PostPosted: Fri Jul 21, 2017 3:47 pm    Post subject: How to free memory properly in Lua autoAssemble? Reply with quote

I've been told before that dealloc does not work in autoAssemble disable section string, if this is the case then how can I free the memory allocated in the first section

Would this work?

Code:

function enable()
    autoAssemble([[
 
    alloc(hook,124)
    registersymbol(hook)
    //etc..

    ]])
end

function disable()
    autoAssemble([[

    unregistersymbol(hook)

    ]])

    deAlloc('hook')
end
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Fri Jul 21, 2017 4:12 pm    Post subject: Reply with quote

Try search "disableinfo".
eg. http://forum.cheatengine.org/viewtopic.php?t=604767#5726898

Note that in ce 6.7 with disableinfo, the autoAssemble script can be exactly same in a memory record with [ENABLE]/[DISABLE]section, except the 'memrec' variable in Lua block {$lua}.

_________________
- Retarded.
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: Fri Jul 21, 2017 4:52 pm    Post subject: Re: How to free memory properly in Lua autoAssemble? Reply with quote

deAlloc, it is the oldest solution since CE6.5, it should do the trick. But, it is not perfect if you have more than one alloc.


e.g. you have this memory record AA script:
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)



version with deAlloc will look like this:
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
    if autoAssemble(InfiniteHealth_disable) then
      deAlloc('InfiniteHealthUserSymbol')
      unregisterSymbol('InfiniteHealthUserSymbol')
      InfiniteHealthCheatIsEnabled = false
    end
  end
end








With CE6.7, this:
Code:
InfiniteHealthScript = [[
[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)
]]

function enableInfiniteHealthCheat()
  if not InfiniteHealthCheatIsEnabled then
    InfiniteHealthCheatIsEnabled,InfiniteHealthCheatDisableinfo = autoAssemble(InfiniteHealthScript)
  end
end

function disableInfiniteHealthCheat()
  if InfiniteHealthCheatIsEnabled then
    if autoAssemble(InfiniteHealthScript,InfiniteHealthCheatDisableinfo) then
      InfiniteHealthCheatIsEnabled = false
    end
  end
end

_________________


Last edited by mgr.inz.Player on Fri Jul 21, 2017 5:04 pm; edited 3 times in total
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 Jul 21, 2017 4:52 pm    Post subject: Reply with quote

I've found this to be cumbersome. I generally use allocateSharedMemory(), I can't wait until deallocateShareMemory() works but right now, I do a single allocation and just reuse when needed.
Back to top
View user's profile Send private message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Fri Jul 21, 2017 6:15 pm    Post subject: Reply with quote

Thanks guys didn't know about disableinfo being added, works as intended
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