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 


Extending Context Menu of Data Dissect Structure Entry
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3229

PostPosted: Sat Aug 10, 2024 7:31 am    Post subject: Extending Context Menu of Data Dissect Structure Entry Reply with quote

Hi all,
I am seeking LUA expert support to extend the Context Menu that appears when you right-click on an entry in the Data Dissect Window.

Here's the pseudo-code I am thinking about - if that makes any sense Very Happy

Code:

// The means to register the menu item and register a function to invoke
MyRightMenuItem ("Section Name", "Get entry info...", &GetEntryInfo())

// The function to register
GetEntryInfo()
{
  if IsValid(address) HandleValidEntry(); // We check if all is good and do something about it
  else HandleInValidEntry(); // We log it, pop an error or something
}


I have really no clue how to get this done - if, at all, possible.
Thank you!
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 147

Joined: 06 Jul 2014
Posts: 4570

PostPosted: Sat Aug 10, 2024 2:13 pm    Post subject: Reply with quote

Use `registerFormAddNotification`:
https://forum.cheatengine.org/viewtopic.php?t=620675

_________________
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
AylinCE
Grandmaster Cheater Supreme
Reputation: 34

Joined: 16 Feb 2017
Posts: 1432

PostPosted: Sat Aug 10, 2024 4:32 pm    Post subject: Reply with quote

Just an example targeting adding a right click menu to the relevant section.

I hope you have the codes you will use in the click ready.

Code:
function popupblaclick1(sender)
  showMessage('Menu 1 was clicked')
end

function popupblaclick2(sender)
  showMessage('Menu 2 was clicked')
end

-----------------------------------------------
local exFrm1 = ""

function addPPMn11()
 for i=0,getFormCount()-1 do
  local formClassName = getForm(i).ClassName
  if formClassName=='TfrmStructures2' then
     aa4 = getForm(i).pmStructureView
     exFrm1 = getForm(i)
     pmenu_items=menu_getItems(aa4)
     if mi1 then mi1.Destroy() end
     mi1=createMenuItem(aa4)
     menuItem_setCaption(mi1,'Menu i1')
     menuItem_onClick(mi1,popupblaclick1)
     menuItem_add(pmenu_items, mi1)

     if mi2 then mi2.Destroy() end
     mi2=createMenuItem(aa4)
     menuItem_setCaption(mi2,'Menu i2')
     menuItem_onClick(mi2,popupblaclick2)
     menuItem_add(pmenu_items, mi2)
  end
 end
end

  registerFormAddNotification(function(exFrm1)
    local t=createTimer()
    t.Interval = 1
    t.OnTimer = function (timer)
      timer.destroy()
      addPPMn11()
    end
  end)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3229

PostPosted: Sun Aug 25, 2024 12:53 pm    Post subject: Reply with quote

Thank you both!

AylinCE wrote:
Just an example targeting adding a right click menu to the relevant section.

I added an [ENABLE] and a [DISABLE] section, assigned to Cheat Table.
I enable it, and it appears to be doing nothing - at least, there are no new menu items appearing in the popup.
Am I using it wrong?
Thanks!

Edit
Managed to fix it.
Next question is, how do I get the value right-clicked from the sender - so I can do something with it...

Final code (for posterity):
Code:
[ENABLE]
{$lua}
function getFormStructureDissect()
  for k,v in ipairs(enumStructureForms()) do if v.ClassName=="TfrmStructures2" then return v end end
  return nil
end

function popupLookupNameIDClick(sender)
  showMessage('popupLookupNameIDClick!')
end

local frmDissect

function fn_AddPopupMenuItems()
  if miNameIDLookup then miNameIDLookup.destroy() end
  frmDissect=getFormStructureDissect()
  if frmDissect~=nil then
    local pmDissect = frmDissect.pmStructureView  -- pmDissect = TfrmStructures2.PopupMenu
    local mnItemDissect=pmDissect.getItems()      -- mnItemDissect = main MenuItem of TfrmStructures2.PopupMenu

    miNameIDLookup=createMenuItem(pmDissect)
    miNameIDLookup.setCaption('Find Name from ID')
    miNameIDLookup.setOnClick(popupLookupNameIDClick)
    mnItemDissect.Add(miNameIDLookup)
  end
end

local function pmRegTimer_tick(thisTimer) ---- Timer callback
  thisTimer.Active = false
  fn_AddPopupMenuItems()
  print('Registered popupLookupNameIDClick.')
  thisTimer.destroy()
  thisTimer=nil
end

objPopupMenuNotification= registerFormAddNotification(function(frmDissect)
  local t=createTimer(getMainForm())
  t.Interval = 200
  t.OnTimer = pmRegTimer_tick
  end
end)

[DISABLE]
{$lua}
if syntaxcheck then return end

unregisterFormAddNotification(objPopupMenuNotification)

if miNameIDLookup then
  miNameIDLookup.destroy()
  print('Destroyed popupLookupNameIDClick.')
end


Last edited by Csimbi on Mon Aug 26, 2024 10:44 am; edited 3 times in total
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3229

PostPosted: Mon Aug 26, 2024 10:39 am    Post subject: Reply with quote

Okay, this works for the most part - however, the popup menu item keeps disappearing.
For example, when I add a new column, the popup menu item disappears.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1065
Location: 0x90

PostPosted: Fri Aug 30, 2024 2:31 pm    Post subject: Reply with quote

Save this as a Lua file within the autorun directory. It will add the respective item to the popupmenu of the Structure Dissect form. The function attached to that particular object returns the index of the menu item.
Code:

local function addItemToPopupMenu(form)
  if form.findComponentByName('miNameIDLookup') then miNameIDLookup.destroy(); miNameIDLookup = nil end

  local miNameIDLookup = createMenuItem(form.pmStructureView)
  local miSep = createMenuItem(form.pmStructureview)
  miSep.Name = 'miNewSep1'
  miSep.Caption = '-'
  form.pmStructureView.Items.add(miSep)

  miNameIDLookup.Name = 'miNameIDLookup'
  miNameIDLookup.Caption = 'Find Name from ID'
  miNameIDLookup.OnClick = function (sender)
                             print('popupLookupNameIDClick! with index: ' .. sender.MenuIndex)
                           end
  form.pmStructureView.Items.add(miNameIDLookup)
end

local function formCreateNotify(form)
  if form.ClassName ~= 'TfrmStructures2' then return end

  local timer = createTimer(MainForm)
  timer.Interval = 15
  timer.OnTimer = function(t)
                    addItemToPopupMenu(form)
                    t.destroy()
                  end
end

registerFormAddNotification(formCreateNotify)
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3229

PostPosted: Tue Sep 17, 2024 1:17 pm    Post subject: Reply with quote

It would appear new windows do not get the new popup menu item.
How would I make it so that the popup menu is registered for each dissect window that is opened?
Thank you!
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 465

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

PostPosted: Tue Sep 17, 2024 2:40 pm    Post subject: Reply with quote

registerFormAddNotification should have done that
_________________
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
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3229

PostPosted: Wed Sep 18, 2024 8:46 am    Post subject: Reply with quote

For some reason, it's the first dissect window only.

Code:
objPopupMenuNotification=registerFormAddNotification(function(frmDissect)
  local t=createTimer(getMainForm())
  t.Interval = 200
  t.OnTimer = pmRegTimer_tick
end)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 465

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

PostPosted: Wed Sep 18, 2024 2:35 pm    Post subject: Reply with quote

How does pmRegTimer_tick get the frmDissect parameter passed to the callback?
_________________
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
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3229

PostPosted: Wed Sep 18, 2024 3:34 pm    Post subject: Reply with quote

Code:

local frmDissect => this is a global in scope of the script (I think :D)

local function pmRegTimer_tick(thisTimer) ---- Timer callback
  thisTimer.Active = false
  fn_AddPopupMenuItems()
  --print('Registered popupLookupNameIDClick.')
  thisTimer.destroy()
  thisTimer=nil
end
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 465

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

PostPosted: Wed Sep 18, 2024 4:35 pm    Post subject: Reply with quote

you do need to assign the parameter given to the function to that local var though. And since they have the same name that's going to be problematic

change objPopupMenuNotification=registerFormAddNotification(function(frmDissect) to objPopupMenuNotification=registerFormAddNotification(function(newfrmDissect)

and then in the function assign do a frmDissect=newfrmDissect

_________________
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
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3229

PostPosted: Thu Sep 19, 2024 4:29 am    Post subject: Reply with quote

Dark Byte wrote:
...

Thank you!

No luck though - the new popup menuitems are still missing in a new window
Code:
objPopupMenuNotification=registerFormAddNotification(function(newfrmDissect)
  frmDissect=newfrmDissect
  local t=createTimer(getMainForm())
  t.Interval = 200
  t.OnTimer = pmRegTimer_tick
end)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 147

Joined: 06 Jul 2014
Posts: 4570

PostPosted: Thu Sep 19, 2024 10:40 am    Post subject: Reply with quote

registerFormAddNotification gets called for every form. Check the class name

Code:
function forEachAndFutureForm(classname, func)
  local i
  for i=0,getFormCount()-1 do
    local f = getForm(i)
    if f.ClassName==classname then
      func(f)
    end
  end

  registerFormAddNotification(function(f)
    if classname==f.ClassName then
      f.registerFirstShowCallback(func)
    end
  end)
end

forEachAndFutureForm('TfrmStructures2',function(f)
  local mi = createMenuItem(f.pmStructureView)
  mi.Name = 'miHelloWorld'
  mi.Caption = 'Hello'
  mi.OnClick = function() print'Hello' end

  f.pmStructureView.Items.add(mi)
end)

_________________
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
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3229

PostPosted: Sat Sep 21, 2024 2:24 pm    Post subject: Reply with quote

ParkourPenguin wrote:
registerFormAddNotification gets called for every form. Check the class name


I'll say, okay and admit I am not sure what am I looking at.
Is this something I should be building into my code or it this built into CE?
I am not very good with LUA - thank you for your patience!


Last edited by Csimbi on Sun Sep 22, 2024 8:16 am; edited 1 time in total
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
Goto page 1, 2  Next
Page 1 of 2

 
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