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 do I get the mr being destroyed

 
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: Mon Jan 22, 2018 6:42 am    Post subject: How do I get the mr being destroyed Reply with quote

This is the copied & modified code from a previous thread I made:
Code:

ceList.createMemoryTimer = function( theForm, theFunc, interval )
  local item = ceList.createMemoryHeader()
  item.zTimer = {
    Timer = nil,
    Form = theForm,
    Action = theAction,
    Interval = interval,
    ceEnable = function(mr, b4, cur)
      if ( mr.zTimer.Timer == nil ) then
        mr.zTimer.Timer = createTimer( mr.zTimer.Form, false )
        mr.zTimer.Timer.setInterval( mr.zTimer.Interval )
        mr.zTimer.Timer.OnTimer = mr.zTimer.Action
      end
      mr.zTimer.Timer.setEnabled( true )
      return true
    end,
    ceDisable = function(mr, b4, cur)
      mr.zTimer.Timer.setEnabled( false )
      return true
    end,
    ceDestroy = function()
      if ( item.zTimer.Timer ) then
        item.zTimer.Timer.destroy()
      end
    end
  }
  item.OnActivate = item.zTimer.Enable
  item.OnDeactivate = item.zTimer.Disable
  item.OnDestroy = item.zTimer.Destroy
  item.DontSave = true
  return item
end

As you will have noticed that last function made doesn't receive the mr object which is problematic, I was hoping there is a way round this without requiring the caller to provide a function that calls our destructive function from their reference of the item object.

_________________
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
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Jan 22, 2018 7:16 am    Post subject: Reply with quote

Code:
mr = AddressList.createMemoryRecord()
mr.OnDestroy = function(...)
  print('destroying')
  local args = {...}
  for k,v in pairs(args) do
    print(('%s %s %s'):format(k,v, v==mr))
  end
  print('destroyed')
end
shows

Code:
destroying
1 userdata: 0000000002AF6398 true
destroyed


in CE 6.7, so it does in fact seem to pass the memory record. edit: also tested in 6.6 and same results (after using getAddressList() since AddressList was added in 6.7 like MainForm).

Though...calling mr.destroy() does not seem to trigger OnDestroy in CE 6.7, mr.delete() does however so apparently that's the proper way to handle that Smile
edit: destroy not triggering OnDestroy was a bug introduced in 6.6, it is now fixed on github for the next release Smile
Back to top
View user's profile Send private message
zxuiji
Advanced Cheater
Reputation: 1

Joined: 26 Sep 2016
Posts: 70

PostPosted: Mon Jan 22, 2018 8:39 am    Post subject: Reply with quote

Okay that seems fine then however I'm now encountering the problem of my functions not being called, reverted to old code for the inventory for now but I will revisit it later today after adding some things to my zSetAbility function for some thing else (looks for parameters in a provided object and sets the appropriate addresses based on their values )

Edit: After countless tries I give up, let's see if someone else can fix it: [Removed]
Edit 2: Got it working via a slightly convoluted way:
Code:

local ceList = getAddressList()
local ceForm = getMainForm()
local ceTimers = {}
local ceTimeri = {}

ceList.createMemoryHeader = function()
  local item = ceList.createMemoryRecord()
  item.isGroupHeader = true
  return item
end

function ceNewTimer(mr,theForm,theFunc,milSec)
  local t = createTimer( theForm, false )
  t.setInterval( milSec )
  t.setOnTimer( theFunc )
  ceTimers[mr.Index] = t
  return t
end

function ceDelTimer(mr)
  local t = ceTimers[mr.Index]
  if ( t ) then
    t.Enabled = false
    t.destroy()
    ceTimers[mr.Index] = nil
  end
end

function ceBegTimer(mr, b4, cur)
  local t = ceTimers[mr.Index]
  local ti = ceTimeri[mr.Index]
  if t == nil then
    t = ceNewTimer( mr, ti.zForm, ti.zFunc, ti.zMs )
  end
  if t then
    ceTimers[mr.Index].Enabled = true
  end
  return true
end

function ceEndTimer(mr, b4, cur)
  if ceTimers[mr.Index] then
    ceTimers[mr.Index].Enabled = false
  end
  return true
end

ceList.createMemoryTimer = function( theDesc, theForm, theFunc, milSec )
  local mr = ceList.createMemoryHeader()
  mr.setDescription( theDesc )
  ceTimeri[mr.Index] = {
    zForm = theForm,
    zFunc = theFunc,
    zMs   = milSec
  }
  ceTimers[mr.Index] = nil
  --ceNewTimer(mr,theForm,theFunc,milSec)
  mr.OnActivate = function(mr,b4,cur) return ceBegTimer(mr,b4,cur) end
  mr.OnDeactivate = function(mr,b4,cur) return ceEndTimer(mr,b4,cur) end
  mr.OnDestroy = function(mr) return ceDelTimer(mr) end
  mr.DontSave = true
  return mr
end

function zTimer( theDesc, theForm, theFunc, milSec )
  local mr = ceList.getMemoryRecordByDescription( theDesc )
  if ( mr ) then
    ceDelTimer(mr)
    mr:destroy()
    --ceNewTimer(mr,theForm,theFunc,interval)
  end
  mr = ceList.createMemoryTimer( theDesc, theForm, theFunc, milSec )
  return mr
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