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

 
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: 96

Joined: 14 Jul 2007
Posts: 3180

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: 146

Joined: 06 Jul 2014
Posts: 4469

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: 1402

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: 96

Joined: 14 Jul 2007
Posts: 3180

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: 96

Joined: 14 Jul 2007
Posts: 3180

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: 1058
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
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