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 


Create structure from popup menu

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

Joined: 19 Apr 2023
Posts: 25

PostPosted: Thu Apr 18, 2024 11:32 pm    Post subject: Create structure from popup menu Reply with quote

I have to use Structure Dissect very often, but manually updating the viewing address every time is very annoying for me. So I decided to write such a script. Which should add a direct transition to the Structure Dissect window to the mouse menu item.
But I ran into a problem. The "createStructureForm" method creates a window structure, but does not create a structure, that is, it does not call the "Define new structure Ctrl+N" button.
So I wanted to know about creation, how can I call createStructureForm along with "Define new Structure"???


Code:
function isOpenStructureDissect()
  for i = 0, getFormCount() - 1 do
    local frm = getForm(i)
    if frm.ClassName=="TfrmStructures2" then
       for i = 0, frm.getComponentCount() -1 do
          if "TEdit"==frm.getComponent(i).ClassName then
             frm.getComponent(i).Text="FFFFFFFF"
          end
       end
       return true
    end
  end
  return false
end

if isOpenStructureDissect() then
    print("OPEN")
else
    createStructureForm("FFFFFFFF",nil,"TEST")
    print("CLOSE")
end
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 459

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

PostPosted: Fri Apr 19, 2024 1:20 am    Post subject: Reply with quote

https://github.com/cheat-engine/cheat-engine/blob/dc08c7db1d9b936e4e486ad78e7aa73308b6bb5b/Cheat%20Engine/bin/celua.txt#L2718

create the structure and then use autoGuess(address,0,4096)

set the Name property and then call addToGlobalStructureList()

when done set the MainStruct property of the structure form to the created structure

---

also, you don't have to scan through all the forms to find a structure dissect window, you can also use enumStructureForms()

and instead of scanning for an edit box you can go through the structureColumns and assign the address or addressText there

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

Joined: 14 Jul 2007
Posts: 3110

PostPosted: Fri Apr 19, 2024 1:35 am    Post subject: Reply with quote

I use it a lot too, so I am curious how this idea plays out.
Be sure to post your extension when you're done.
Thanks!
Back to top
View user's profile Send private message
24quant42
Cheater
Reputation: 0

Joined: 19 Apr 2023
Posts: 25

PostPosted: Fri Apr 19, 2024 8:17 am    Post subject: Reply with quote

Dark Byte wrote:
https://github.com/cheat-engine/cheat-engine/blob/dc08c7db1d9b936e4e486ad78e7aa73308b6bb5b/Cheat%20Engine/bin/celua.txt#L2718

Thank you) I understood a lot from this document)


Csimbi wrote:
I use it a lot too, so I am curious how this idea plays out.
Be sure to post your extension when you're done.
Thanks!


Okay, I'll send it


-------------------------------------------------------

https://github.com/cheat-engine/cheat-engine/blob/dc08c7db1d9b936e4e486ad78e7aa73308b6bb5b/Cheat%20Engine/images/Cheat%20Engine%20Icons/structure128x128.png

I also wanted to attach this icon, but I couldn’t add something to the Popup menu item.
In general, here we keep it for those who need it.
I tested it in different versions, I’m not a master of LUA, but I know a little. If you find any errors, I will be glad if you correct and attach them.




Code:
function getFormStructureDissect()
  for k,v in ipairs(enumStructureForms()) do
      if v.ClassName=="TfrmStructures2" then
         return v
      end
  end
  return nil
end

function MyMenuItemClick()
  local addrList = getAddressList()
  if addrList.getSelectedRecord()~=nil then
    local addr=addrList.getSelectedRecord().Address
    local structFrm=getFormStructureDissect()
    --Struct
    if getStructureCount()<=0 then
        local struct=createStructure("Struct")
        struct.setName("Struct")
        struct.autoGuess(addr,0,4096)
        struct.addToGlobalStructureList()
    else
        if structFrm~=nil then
            structFrm.Column[0].AddressText=addr
        end
    end
    --Struct Form
    if structFrm~=nil then
        local struct=getStructure(0)
        sleep(200)
        structFrm.MainStruct=struct
    else
        local newStructFrm=createStructureForm(addr)
        local struct=getStructure(0)
        sleep(200)
        newStructFrm.MainStruct=struct
    end
  else
    showMessage("Select one address from the list of addresses")
  end
end

--Mouse PopupMenu--
local addrPopupMenu=getMainForm().PopupMenu2
local addrMenuItems=addrPopupMenu.Items
local itemCaption="Show Structure/Dissect"

function isItemStructureDissectExists()
for i=0, addrMenuItems.Count-1 do
    if addrMenuItems[i].Caption==itemCaption then
        return true
    end
end
return false
end

if not isItemStructureDissectExists() then
  local customMenu=createMenuItem(addrPopupMenu)
  customMenu.Caption=itemCaption
  customMenu.OnClick = MyMenuItemClick
  addrMenuItems.insert(addrMenuItems.Count-1, customMenu)
end



1111.png
 Description:
 Filesize:  22.63 KB
 Viewed:  275 Time(s)

1111.png


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