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 identify the MR from its Popup Menu command?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Tue Dec 16, 2014 3:47 pm    Post subject: How to identify the MR from its Popup Menu command? Reply with quote

So, it seems the memoryrecord on the addressList shared a common Popup/context menu. The menu is from the parent of the AddressList as a TPanel.

Code:
local al = getAddressList()

local mm = al.Parent.PopupMenu.Items


The ClassName of al.Parent is TPanel. mm is now the shared popup menu.

It seems when we right-click a memory record, some menuitem on the shared popup menu will be filtered according to the 'type' of mr, and the resulted menu view is displayed.

Here is to insert an custom menuitem on the shared popup menu. (Note: it will added to the shared menu a new menuitem each time it run)

Code:
local nm = createMenuItem(mm)
nm.Caption = "TEST"
--mm.add(nm)
nm.OnClick = function(sender,b,c) print(sender.ClassName, b and "B" or "b", c and "C" or "c") end

mm.insert(0,nm)


By clicking the custom "TEST' menu, the debug print this:

Code:
TMenuItem b c


That mean the menu OnClick only provided the menuItem information but no more.

The question: how the OnClick function know which MemoryRecord is being right-clicked?

Thank you~
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Tue Dec 16, 2014 5:31 pm    Post subject: Reply with quote

The menu item doesn't know which memory record triggered it
It has to check which records are selected and then apply what it has to on those entries
tip : addresslist class:
Code:
 
property:
SelectedRecord: MemoryRecord - The main selected record

method:
getSelectedRecords():  Returns a table containing all the selected records

_________________
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
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Tue Dec 16, 2014 5:40 pm    Post subject: Reply with quote

Dark Byte wrote:
The menu item doesn't know which memory record triggered it
It has to check which records are selected and then apply what it has to on those entries
tip : addresslist class:
Code:
 
property:
SelectedRecord: MemoryRecord - The main selected record

method:
getSelectedRecords():  Returns a table containing all the selected records


Got it, thank you!

Yet another question: Is there way to affect how a (may be custom) menuItem displayed (eg. visiblility, change its sub-menu etc.) after right-clicking a MR but before the popup menu (or the sub menu of a custom menuitem) displayed?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Tue Dec 16, 2014 6:56 pm    Post subject: Reply with quote

You can override the OnPopup property of the PopupMenu object (undocumented, but published)

This example will only show the item when something is selected:
Code:

al = getAddressList()
local mm = al.Parent.PopupMenu
if nm==nil then
  nm = createMenuItem(mm)
  nm.Caption = "TEST"
  nm.OnClick = function(sender) print('bla') end

  mm.Items.insert(0,nm)
end

if oldOnPopup==nil then
  oldOnPopup=mm.OnPopup

  mm.OnPopup=function(sender)
               nm.Visible=al.SelCount>0
               oldOnPopup(sender)
             end
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
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Thu Dec 25, 2014 6:13 am    Post subject: Reply with quote

How to clone a memory record? I mean the similar effect of copy and paste mr from the popup menu, but with lua.

Thank you~
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Thu Dec 25, 2014 6:18 am    Post subject: Reply with quote

There is no way. The closest you can come is reading the properties of the original one and apply them to the new one.

i guess you could invoke the onclick of the copy and paste menu items after setting the selected property of the original record

_________________
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
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Thu Dec 25, 2014 8:31 am    Post subject: Reply with quote

Thank you~

But the getPropertyList of MR is not complete.
It has type,child etc. copied, but not, for example, 'script' content or 'description'.

Code:
local MRClone
MRClone = function(s)
  local pl,rs = getPropertyList(s)
  if pl ~= nil then
    rs = getAddressList().createMemoryRecord()
    for i=0,pl.Count-1 do
      local pn = pl[i]
      print(i,pn)
      if pn ~= 'ID' and pn ~= 'Index' and pn ~= 'Child' and pn ~= 'Parent'then
--        local ok,source = pcall(getMethodProperty,s,pn)
--        if ok and source and type(source) == 'function' then
--          setMethodProperty(rs,pn,source)
--        else
          local ok,source = pcall(getProperty,s,pn)
          if ok and source then setProperty(rs,pn,source) end
--        end
      end
    end
    pl.destroy()
    for i=0,s.Count-1 do
       local newchild = MRClone(s[i])
       newchild.appendToEntry(rs)
--       print(s[i].Parent.Description)
--       print(newchild.Parent.Description)
    end
  end
  return rs
end
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Thu Dec 25, 2014 8:36 am    Post subject: Reply with quote

Read the manual (main.lua)
Code:

MemoryRecord Class:
The memoryrecord objects are the entries you see in the addresslist

properties
  ID: Integer - Unique ID
  Index: Integer - The index ID for this record. 0 is top. (ReadOnly)
  Description: string- The description of the memory record
  Address: string - Get/set the interpretable address string. Usefull for simple address settings.
  OffsetCount: integer - The number of offsets. Set to 0 for a normal address
  Offset[] : integer - Array to access each offset
  CurrentAddress: integer - The address the memoryrecord points to
  Type: ValueType - The variable type of this record. See vtByte to vtCustom
    If the type is vtString then the following properties are available:
     String.Size: Number of characters in the string
     String.Unicode: boolean

    If the type is vtBinary then the following properties are available
      Binary.Startbit: First bit to start reading from
      Binary.Size : Number of bits

    If the type is vtByteArray then the following propertes are available
      Aob.Size : Number of bytes

  CustomTypeName: String - If the type is vtCustomType this will contain the name of the CustomType
  Script: String - If the type is vtAutoAssembler this will contain the auto assembler script
  Value: string - The value in stringform.
  Selected: boolean - Set to true if selected (ReadOnly)
  Active: boolean - Set to true to activate/freeze, false to deactivate/unfreeze
  Color: integer

  Count: Number of children
  Child[index] : Array to access the child records
  [index] = Child[index]

  HotkeyCount: integer - Number of hotkeys attached to this memory record
  Hotkey[] : Array to index the hotkeys

  OnActivate: function()
  OnDeactivate: function()
  OnDestroy: function()
methods
  getDescription()
  setDescription()
  getAddress() : Returns the interpretable addressstring of this record. If it is a pointer, it returns a second result as a table filled with the offsets
  setAddress(string) : Sets the interpretable address string, and if offsets are provided make it a pointer

  getOffsetCount(): Returns the number of offsets for this memoryrecord
  setOffsetCount(integer): Lets you set the number of offsets

  getOffset(index) : Gets the offset at the given index
  setOffset(index, value) : Sets the offset at the given index

  getCurrentAddress(): Returns the current address as an integer (the final result of the interpretable address and pointer offsets)

  appendToEntry(memrec): Appends the current memory record to the given memory record

  getHotkey(index): Returns the hotkey from the hotkey array
  getHotkeyByID(integer): Returns the hotkey with the given id


Script contains the script
Description contains the description

_________________
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
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Thu Dec 25, 2014 8:53 am    Post subject: Reply with quote

ok. I've not tried yet, but I suspect Hotkey[] and Offset[] and similar may not set as Property directly? [ANSWERED]

Update:
ok, I'll try.


Last edited by panraven on Thu Dec 25, 2014 9:01 am; edited 2 times in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Thu Dec 25, 2014 8:58 am    Post subject: Reply with quote

OffsetCount and the subsequent offsets should be writable. (but if you're not sure, there's also setOffsetCount() )

HotkeyCount is readonly though. For those you'll need to create new hotkeys with the same key combination and effect

_________________
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
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