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 


remove addresses that are not accessed in the search results

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

Joined: 09 Feb 2021
Posts: 83

PostPosted: Fri Dec 26, 2025 9:16 am    Post subject: remove addresses that are not accessed in the search results Reply with quote

This is an auxiliary tool for finding pointer methods in the ce tutorial.
The problems encountered before
The ai gave this answer.
It has not been tested yet to see if it can be used
There is no game testing at present.
If you have encountered this problem, you can try using this tool to test whether it can be used.


Made by ai


Memory Address Access Monitor - Auto Delete Version
Code:

-- Cheat Engine Lua Script: Memory Address Access Monitor (Auto Delete Version)
-- Automatically deletes unaccessed addresses without confirmation

-- Create main form
local f = createForm()
if not f then
  showMessage("Failed to create form")
  return
end

f.Position = poScreenCenter
f.Width = 550
f.Height = 300
f.Caption = 'Address Access Monitor - Auto Delete'
f.BorderIcons = '[biSystemMenu,biMinimize]'

-- Create panel for styling
local panel = createPanel(f)
panel.Align = alClient
panel.BevelOuter = bvLowered

-- Create title label
local titleLabel = createLabel(panel)
titleLabel.Left = 10
titleLabel.Top = 10
titleLabel.Caption = 'Address Access Monitor - Auto Delete'
titleLabel.Font.Size = 14
titleLabel.Font.Style = '[fsBold]'

-- Create status label
local statusLabel = createLabel(panel)
statusLabel.Left = 10
statusLabel.Top = 40
statusLabel.Width = 500
statusLabel.Caption = 'Waiting to start...'

-- Create current address label
local addrLabel = createLabel(panel)
addrLabel.Left = 10
addrLabel.Top = 70
addrLabel.Width = 300
addrLabel.Caption = 'Current Address: None'
addrLabel.Font.Color = 0x0000FF

-- Create progress bar
local progressBar = createProgressBar(panel)
progressBar.Left = 10
progressBar.Top = 100
progressBar.Width = 500
progressBar.Height = 20

-- Create statistics label
local statsLabel = createLabel(panel)
statsLabel.Left = 10
statsLabel.Top = 130
statsLabel.Width = 400
statsLabel.Caption = 'Stats: 0/0 (0%)'

-- Create options panel
local optionsPanel = createPanel(panel)
optionsPanel.Left = 10
optionsPanel.Top = 160
optionsPanel.Width = 500
optionsPanel.Height = 40
optionsPanel.BevelOuter = bvNone

-- Create "Auto delete unaccessed addresses" checkbox
local chkAutoDelete = createCheckBox(optionsPanel)
chkAutoDelete.Left = 10
chkAutoDelete.Top = 10
chkAutoDelete.Width = 200
chkAutoDelete.Caption = 'Auto delete unaccessed addresses'
chkAutoDelete.Checked = true

-- Create button panel
local buttonPanel = createPanel(panel)
buttonPanel.Left = 10
buttonPanel.Top = 210
buttonPanel.Width = 500
buttonPanel.Height = 40
buttonPanel.BevelOuter = bvNone

-- Create start button
local btnStart = createButton(buttonPanel)
btnStart.Left = 10
btnStart.Top = 5
btnStart.Width = 80
btnStart.Height = 30
btnStart.Caption = 'Start Monitor'

-- Create stop button
local btnStop = createButton(buttonPanel)
btnStop.Left = 100
btnStop.Top = 5
btnStop.Width = 80
btnStop.Height = 30
btnStop.Caption = 'Stop Monitor'
btnStop.Enabled = false

-- Create delete now button
local btnDeleteNow = createButton(buttonPanel)
btnDeleteNow.Left = 190
btnDeleteNow.Top = 5
btnDeleteNow.Width = 120
btnDeleteNow.Height = 30
btnDeleteNow.Caption = 'Delete Unaccessed Now'
btnDeleteNow.Enabled = false

-- Create close button
local btnClose = createButton(buttonPanel)
btnClose.Left = 320
btnClose.Top = 5
btnClose.Width = 80
btnClose.Height = 30
btnClose.Caption = 'Close'

-- Variable initialization
local isRunning = false
local currentIndex = 0
local totalItems = 0
local accessTable = {}
local foundList = nil
local monitorTimer = nil

-- Function: Clean up all breakpoints
function cleanupBreakpoints()
  if foundList and foundList.Items then
    for i = 0, foundList.Items.Count - 1 do
      if foundList.Items[i] then
        local success, err = pcall(function()
          debug_removeBreakpoint(foundList.Items[i].Caption)
        end)
        -- Ignore errors when removing breakpoints
      end
    end
  end
end

-- Function: Set breakpoint
function setupBreakpoint(index)
  if not foundList or not foundList.Items or index >= foundList.Items.Count then
    return false
  end
 
  local item = foundList.Items[index]
  if not item then
    return false
  end
 
  local address = item.Caption
  if not address or address == '' then
    return false
  end
 
  -- Reset access status
  accessTable[index] = 0
 
  -- Set breakpoint
  local success, err = pcall(function()
    debug_setBreakpoint(address, 1, bptAccess, function()
      accessTable[index] = 1
      print(string.format("Address %s (index %d) was accessed", address, index))
    end)
  end)
 
  return success
end

-- Function: Update display
function updateDisplay()
  if not isRunning or currentIndex >= totalItems then
    return
  end
 
  -- Update current address display
  if foundList and foundList.Items[currentIndex] then
    addrLabel.Caption = string.format("Current Address: %s (Index %d/%d)",
      foundList.Items[currentIndex].Caption, currentIndex + 1, totalItems)
  end
 
  -- Update progress bar
  progressBar.Position = currentIndex + 1
 
  -- Calculate number of accessed addresses
  local accessedCount = 0
  for i = 0, math.min(currentIndex, totalItems - 1) do
    if accessTable[i] == 1 then
      accessedCount = accessedCount + 1
    end
  end
 
  -- Update statistics
  local percent = totalItems > 0 and math.floor((currentIndex + 1) / totalItems * 100) or 0
  statsLabel.Caption = string.format("Stats: %d/%d set | %d accessed (%d%%)",
    currentIndex + 1, totalItems, accessedCount, percent)
end

-- Function: Delete unaccessed addresses (no confirmation)
function deleteUnaccessedAddresses()
  if not foundList or not foundList.Items or foundList.Items.Count == 0 then
    return 0
  end
 
  -- Count unaccessed addresses
  local unaccessedCount = 0
  local toDelete = {}
 
  for i = foundList.Items.Count - 1, 0, -1 do
    if accessTable[i] and accessTable[i] == 0 then
      table.insert(toDelete, i)
      unaccessedCount = unaccessedCount + 1
    end
  end
 
  if unaccessedCount == 0 then
    return 0
  end
 
  -- Delete directly, no confirmation
  local deletedCount = 0
  for _, index in ipairs(toDelete) do
    if index < foundList.Items.Count then
      foundList.Items[index].Selected = false  -- Deselect
      foundList.Items.delete(index)
      deletedCount = deletedCount + 1
    end
  end
 
  -- Update total count
  totalItems = foundList.Items.Count
 
  -- Reset access table
  accessTable = {}
  for i = 0, totalItems - 1 do
    accessTable[i] = 0
  end
 
  -- Update display
  progressBar.Max = totalItems
  progressBar.Position = 0
 
  -- Immediately output deletion info
  print(string.format("Deleted %d unaccessed addresses, %d addresses remaining", deletedCount, totalItems))
 
  return deletedCount
end

-- Function: Process next address
function processNextAddress()
  if not isRunning or currentIndex >= totalItems then
    -- Monitoring completed
    if monitorTimer then
      monitorTimer.destroy()
      monitorTimer = nil
    end
   
    statusLabel.Caption = string.format("Monitoring completed! Total %d addresses monitored", totalItems)
   
    -- Auto delete unaccessed addresses (if enabled)
    local deletedCount = 0
    if chkAutoDelete.Checked then
      deletedCount = deleteUnaccessedAddresses()
      if deletedCount > 0 then
        statusLabel.Caption = string.format("Monitoring completed! Deleted %d unaccessed addresses, %d addresses remaining",
          deletedCount, totalItems)
      end
    end
   
    -- Calculate final access statistics
    local accessedCount = 0
    for i = 0, totalItems - 1 do
      if accessTable[i] == 1 then
        accessedCount = accessedCount + 1
      end
    end
   
    statsLabel.Caption = string.format("Final Stats: %d/%d addresses accessed", accessedCount, totalItems)
   
    btnStart.Enabled = true
    btnStop.Enabled = false
    btnDeleteNow.Enabled = true
    return
  end
 
  -- Remove previous breakpoint (if not the first one)
  if currentIndex > 0 then
    local prevItem = foundList.Items[currentIndex - 1]
    if prevItem then
      -- Check if previous address was accessed
      if accessTable[currentIndex - 1] == 0 then
        prevItem.Selected = true
      end
     
      -- Remove previous breakpoint
      pcall(function()
        debug_removeBreakpoint(prevItem.Caption)
      end)
    end
  end
 
  -- Set current breakpoint
  if setupBreakpoint(currentIndex) then
    statusLabel.Caption = string.format("Monitoring address %d/%d", currentIndex + 1, totalItems)
  else
    statusLabel.Caption = string.format("Failed to set breakpoint for address %d", currentIndex + 1)
  end
 
  -- Update display
  updateDisplay()
 
  -- Move to next address
  currentIndex = currentIndex + 1
end

-- Function: Start monitoring
function startMonitoring()
  -- Check if process is attached
  local pid = getOpenedProcessID()
  if pid == 0 then
    showMessage("Please attach to a process first")
    return
  end
 
  -- Get FoundList3
  local mainForm = getMainForm()
  if not mainForm then
    showMessage("Failed to get main form")
    return
  end
 
  foundList = mainForm.Foundlist3
  if not foundList or not foundList.Items then
    showMessage("No scan results found, please perform a scan first")
    return
  end
 
  totalItems = foundList.Items.Count
  if totalItems == 0 then
    showMessage("Scan results are empty")
    return
  end
 
  -- Initialize access table
  accessTable = {}
  for i = 0, totalItems - 1 do
    accessTable[i] = 0
  end
 
  -- Reset index
  currentIndex = 0
 
  -- Set UI state
  isRunning = true
  btnStart.Enabled = false
  btnStop.Enabled = true
  btnDeleteNow.Enabled = false
  progressBar.Max = totalItems
  progressBar.Position = 0
 
  -- Clean up previous breakpoints
  cleanupBreakpoints()
 
  -- Start debugging
  if not debugProcess() then
    showMessage("Failed to start debugging")
    stopMonitoring()
    return
  end
 
  -- Create timer (process one address every second)
  if monitorTimer then
    monitorTimer.destroy()
  end
 
  monitorTimer = createTimer(1000)
  monitorTimer.Interval = 1000
  monitorTimer.OnTimer = processNextAddress
 
  statusLabel.Caption = string.format("Starting to monitor %d addresses...", totalItems)
  print(string.format("Starting to monitor %d addresses, unaccessed addresses will be automatically deleted after monitoring", totalItems))
end

-- Function: Stop monitoring
function stopMonitoring()
  isRunning = false
 
  if monitorTimer then
    monitorTimer.destroy()
    monitorTimer = nil
  end
 
  -- Clean up all breakpoints
  cleanupBreakpoints()
 
  -- Update UI
  statusLabel.Caption = "Monitoring stopped"
  btnStart.Enabled = true
  btnStop.Enabled = false
  btnDeleteNow.Enabled = true
 
  -- Show statistics
  local accessedCount = 0
  for i = 0, totalItems - 1 do
    if accessTable[i] == 1 then
      accessedCount = accessedCount + 1
    end
  end
 
  statsLabel.Caption = string.format("Current Stats: %d/%d addresses accessed", accessedCount, totalItems)
end

-- Set button events
btnStart.onClick = startMonitoring
btnStop.onClick = stopMonitoring

btnDeleteNow.onClick = function()
  local deleted = deleteUnaccessedAddresses()
  if deleted > 0 then
    statusLabel.Caption = string.format("Deleted %d unaccessed addresses, %d addresses remaining", deleted, totalItems)
    showMessage(string.format("Deleted %d unaccessed addresses", deleted))
  else
    showMessage("No unaccessed addresses to delete")
  end
end

btnClose.onClick = function()
  stopMonitoring()
  f.close()
end

-- Form close event
f.onClose = function()
  stopMonitoring()
  return caFree
end

-- Add usage instructions
local helpLabel = createLabel(panel)
helpLabel.Left = 10
helpLabel.Top = 260
helpLabel.Width = 500
helpLabel.Caption = 'Tip: After monitoring, unaccessed addresses will be automatically deleted. You can also click "Delete Unaccessed Now" at any time.'
helpLabel.Font.Color = 0x008000

-- Show form
f.show()

-- Status message
print("========================================")
print("Address Access Monitor - Auto Delete Version loaded")
print("Feature: Monitor address access and automatically delete unaccessed addresses")
print("========================================")
print("Usage:")
print("1. Attach to target process")
print("2. Perform memory scan")
print("3. Click 'Start Monitor' button")
print("4. Trigger program to access relevant memory addresses")
print("5. After monitoring, unaccessed addresses will be automatically deleted")
print("========================================")


Features of This Script:

1 Monitors address access in real-time using breakpoints

2 Automatically deletes unaccessed addresses after monitoring completes

3 No confirmation dialogs - deletion happens immediately

4 Progress tracking with visual progress bar

5 Real-time statistics showing accessed vs. unaccessed addresses

6 Manual deletion option at any time

Usage Instructions:

1 Attach Cheat Engine to the target process

2 Perform a memory scan to populate the address list

3 Click "Start Monitor" to begin monitoring

4 Interact with the target program to trigger memory accesses

5 After monitoring completes, unaccessed addresses will be automatically deleted

6 Alternatively, click "Delete Unaccessed Now" to manually delete at any time

This script is particularly useful for narrowing down memory scans by eliminating addresses that aren't actually being accessed by the program during your monitoring period.
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 98

Joined: 14 Jul 2007
Posts: 3340

PostPosted: Sat Dec 27, 2025 9:22 am    Post subject: Reply with quote

Interesting idea.
How is performance when you have 1M+ addresses in the list?
Back to top
View user's profile Send private message
etioplmld
Advanced Cheater
Reputation: 0

Joined: 09 Feb 2021
Posts: 83

PostPosted: Sat Dec 27, 2025 9:43 am    Post subject: Reply with quote

This is used after the step of "finding out what accessed this address",Search for the most likely value, and there are at most only a few thousand addresses
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 98

Joined: 14 Jul 2007
Posts: 3340

PostPosted: Sun Dec 28, 2025 6:21 am    Post subject: Reply with quote

Ah, I see. I misunderstood, sorry.
Thanks for letting me know.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1535

PostPosted: Sun Dec 28, 2025 10:16 am    Post subject: Reply with quote

I believe this delete reference is undefined.
Assuming you've tried this code, did you define it elsewhere?
Code:
foundList.Items.delete(index)


Examine the following code to simulate a real deletion:
Code:
local fl = getMainForm().Foundlist3

local function getRemoveSelectedMenuItem(listview)
  local pm = listview.PopupMenu
  if not pm or not pm.Items then return nil end
  for i=0, pm.Items.Count-1 do
    if pm.Items[i].Name == "Removeselectedaddresses1" then
      return pm.Items[i]
    end
  end
  return nil
end

local miRemove = getRemoveSelectedMenuItem(fl)
assert(miRemove, "Could not find Removeselectedaddresses1 menu item")


local function removeUnreadableOrChanged(listview, removeMenuItem)
  -- all line unselect
  for i=0, listview.Items.Count-1 do
    listview.Items[i].Selected = false
  end

  -- check
  for i=0, listview.Items.Count-1 do
    local item = listview.Items[i]
    if item then
      local address  = item.Caption
      local value    = item.SubItems[0]
      local previous = item.SubItems[1]

      local unreadable = (value == "???") or not item
      local changed    = (not unreadable) and (value ~= previous)

      if unreadable or changed then
        if unreadable then
          print("Unreadable: "..address.." Value="..tostring(value).." Previous="..tostring(previous))

          item.Selected = true
        else
          print("Changed: "..address.." Value="..tostring(value).." Previous="..tostring(previous))
        end

      end
    end
  end

  -- selected (unreadable) delete
  removeMenuItem.DoClick()
end

-- execute
removeUnreadableOrChanged(fl, miRemove)


-- or
Code:
local fl = getMainForm().Foundlist3

-- Menu search ..
local function getRemoveSelectedMenuItem(listview)
  local pm = listview.PopupMenu
  for i=0, pm.Items.Count-1 do
    if pm.Items[i].Name == "Removeselectedaddresses1" then
      return pm.Items[i]
    end
  end
end

local miRemove = assert(getRemoveSelectedMenuItem(fl), "Menu item not found")

-- Wrapper fonksiyon
function deleteItem(listview, index)
  if listview.Items[index] then
    listview.Items[index].Selected = true
    miRemove.DoClick()
  end
end

-- use
deleteItem(fl, 1)

_________________
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
etioplmld
Advanced Cheater
Reputation: 0

Joined: 09 Feb 2021
Posts: 83

PostPosted: Mon Dec 29, 2025 12:57 am    Post subject: Reply with quote

When experimenting on a certain Unreal game, it popped up that the debugger could not be attached. The code that could barely run in previous ce versions also reported the same error. The ai had no idea why, and Google had no result. It ended before it even began.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1535

PostPosted: Mon Dec 29, 2025 7:01 am    Post subject: Reply with quote

You should first give it CE Defines and celua.txt. Smile

Things that AI does well:

    It organizes existing and complex code very well (grids and Lua modeling).

    It finds very good and global function names. (I often ask it for the module or function name. Smile ).

    It performs calculations very well. It has good calculations and ideas in lines of code that require mathematics.

    When I create a code or module, I have it write which line, function, and what it does, and the inline comments. (It never gets tired of doing this. Smile )

    Formulate the idea, write the code, test and organize step by step, and only leave the cleanup to AI at the 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
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