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 


The Easist way to get ACCESS VIOLATION

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Sun May 12, 2024 7:59 am    Post subject: The Easist way to get ACCESS VIOLATION Reply with quote

Is there a way to detect if a cheat table is open? And is there a way to close it without deleting any information? (Auto-save is on)

Is there a way to disable load-associated cheat table confirmation?

I've run into an issue after making a script to auto-load CT on attachment.

If CE prompts me with load-associated cheat table confirmation when I click "no" everything goes fine. But when I click "yes" I get an instant "ACCESS VIOLATION" error.

Is there a way I could tag someone? I want to tag Dark Byte and Parkour Penguin
Sorry DB I've destroyed your software. I'm the only one getting this error.

The script:
Code:

local lfs = require("lfs")
local file = ""
local foundFile = ""
local foundFilePath = ""
local fileDir = ""
local searchDirectory = "D:\\Bla\\Bla\\Bla"
local fileExtension = ".ct"

function showMessageBox(TXT)
  createThread(function (thread)
    local StartTime = os.clock()
    while os.clock() - StartTime < 1.5 do sleep(5) end
    doKeyPress(VK_ESCAPE)
    thread.terminate()
  end,thread)
  ShowMessage(translate(TXT))
  return translate(TXT)
end

function getCTfile()
   local foundFileCount = 0
   local processName = process:gsub("%.exe$", "")
   for _,filePath in ipairs(getFileList(searchDirectory, '*.ct', true)) do
     --print(file)
     if string.find(string.lower(filePath), string.lower(processName), 1, true) then
        foundFileCount = foundFileCount + 1

        --print("Found file full path: "..filePath)
        file = extractFileName(filePath)
        --print("Found file name: "..file)
        fileDir = extractFilePath(filePath)
        --print("Found file directory: "..fileDir)
        foundFile = file
        foundFilePath = filePath

       if foundFileCount > 1 then
          --Load Dialog
         loadCTDialog = createOpenDialog()
         loadCTDialog.Title = "Load Cheat Table"
         loadCTDialog.FileName = foundFile
         loadCTDialog.InitialDir = fileDir
         loadCTDialog.DefaultExt = ".ct"
         loadCTDialog.Filter = "Cheat Table Files (*.ct)|*.ct"
         loadCTDialog.Options = "[ofOverwritePrompt, ofHideReadOnly, ofEnableSizing]"
           --print("Found more than one file matching the description")

         if loadCTDialog.Execute() then
            loadTable(loadCTDialog.FileName)
         else
            return
         end
        end
     end
   end
     if foundFileCount == 1 then
      loadTable(foundFilePath)
      showMessageBox("*** Cheat table has been load ***\n *** "..foundFile.." ***")
   end
end

MainForm.OnProcessOpened = function()
   createThread(function() getCTfile() end)
end



PS: I'm not sure where this post belongs but I still believe it has to do with Lua scripting. Move it as you wish
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Sun May 12, 2024 2:01 pm    Post subject: Reply with quote

Why createThread everywhere? Just use timers when needed. I don't see any need to here.

`ShowMessage` - use `showMessage` instead

Don't do anything with the GUI in a separate thread. No `createOpenDialog`, no `showMessage`, no `loadTable` (accesses the address list), even `doKeyPress` might be bad

What's the deal with `doKeyPress(VK_ESCAPE)`?

You're calling `createOpenDialog` in the loop... I think you meant to do that after looping through the return value of `getFileList`


Other things that aren't really an issue:
`MainForm.OnProcessOpened` is a single function. Some other extension might need it. Hook it and call the old function (if it exists)
You're not using lfs
You can search for file names in the recursive query (e.g. "*filename*.ct")
You're completely ignoring stuff like "what if the user already selected to load a table from CE's default auto load table on process opened mechanism" or "what if the process was opened via the autoattach list"
The only thing this does that CE doesn't already do is make the search recursive and allow files that include the processname but aren't an exact match
If there's more than 1 file, this just gives up and tells the user to figure it out, so I really don't see anything good this adds

_________________
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
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Sun May 12, 2024 2:24 pm    Post subject: Reply with quote

I am absolutely new to Lua and you know that very well since you were the first to encourage me to learn Lua.

I will consider your tips and fix the script accordingly, however, this kind of script is pretty useful for me since I have many scripts.

Could you elaborate more on timers?

The showMesssgaeBox function was copied from another script I found. I'll try to fix it and show you what I've got.
Thank you
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Sun May 12, 2024 2:39 pm    Post subject: Reply with quote

I'm just confused because I have no idea what you're trying to do. At this point it looks like you're just looking for a way to automatically click "File -> Load" in a convoluted manner.

Only use createThread when you have a very specific need to run something in another thread. In the majority of cases, simply using a timer to run something asynchronously is good enough.
Code:
-- running something once
createTimer(1000, function()
  ...
end)

-- running something in a loop
mytimer = mytimer or createTimer()
mytimer.Interval = 1000
mytimer.OnTimer = function(t)
  ...
end


Don't just copy and paste code because someone else wrote it. Learn from it.

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