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 


Lua Script Crash Cheat Engine

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

Joined: 16 Aug 2013
Posts: 26

PostPosted: Thu Sep 01, 2016 12:53 pm    Post subject: Lua Script Crash Cheat Engine Reply with quote

I make a function that search values between 2 numbers, and it returns those values which found in current game. But my CE crash sometimes even 2 number difference is tow low.Below is my code
Code:
  for val= 19791800  , 19791900  do
      searchV = {(assert(tonumber(val),"Could not convert first argument to number"))}
      for i,v in ipairs(searchV) do
        v = math.floor(v)
        local res = AOBScan(string.format("%02X %02X %02X %02X", v & 0xff, v>>8 & 0xff, v>>16 & 0xff, v>>24 & 0xff), "+W-C", 1, 4)
        if res then
           ShowMessage( val)
        end
      end
  end
  ShowMessage("finish")
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Sep 01, 2016 3:45 pm    Post subject: Reply with quote

Uh... what the heck are you trying to do?
You are controlling your outer loop, so val will ALWAYS be a number.
Why are you using tonumber()? It's already a number!
Why are you using math.floor()? You defined it as a whole number and it will increment as a whole number!
What the hell is the point of doing a separate AOBScan()? You're searching through a range anyway, use a range in your scan!

I suppose you could be crashing cause you never use res.Destroy() after you're done with it.
I guess if you want to simplify whatever it is you're trying to do...
Although, you should simplify it further by using MemScan.firstScan() to scan the range for you.
Code:
  for val=19791800, 19791900 do
    local res = AOBScan(string.format("%02X %02X %02X %02X", v & 0xff, v>>8 & 0xff, v>>16 & 0xff, v>>24 & 0xff), "+W-C", 1, 4)
    if res then
      ShowMessage(val)
      res.Destroy()
    end
  end
  ShowMessage("finish")

Or if you just want to manually scan in CE using your range, you can loop through those results with:
Code:
local found = getCurrentMemscan().FoundList
values = {}
for i=0,found.Count-1,1 do
  values[found.Value[i]] = true
end
for i in pairs(values) do
  print(i)
end
Back to top
View user's profile Send private message
azamalvi
Cheater
Reputation: 0

Joined: 16 Aug 2013
Posts: 26

PostPosted: Fri Sep 02, 2016 5:44 am    Post subject: Reply with quote

Sorry I forgot to mention that I am not strong in VB enough. Thanks for the point you mentioned. Now when I am running your above piece of code it is showing me below error
Code:
Error:[string "  for val=19791800, 19791900 do..."]:2: attempt to perform bitwise operation on a nil value (global 'v')
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Sep 02, 2016 11:22 am    Post subject: Reply with quote

Forgot to rename variables.
Code:
  for v=19791800, 19791900 do
    local res = AOBScan(string.format("%02X %02X %02X %02X", v & 0xff, v>>8 & 0xff, v>>16 & 0xff, v>>24 & 0xff), "+W-C", 1, 4)
    if res then
      ShowMessage(v)
      res.Destroy()
    end
  end
  ShowMessage("finish")
Back to top
View user's profile Send private message
azamalvi
Cheater
Reputation: 0

Joined: 16 Aug 2013
Posts: 26

PostPosted: Fri Sep 02, 2016 11:56 am    Post subject: Reply with quote

I have noticed that this script is also taking too long time. It takes approximately 4 minutes. I am surprised that if I search values using Cheat Engine Builtin function "Value Between" then the result comes in nano sec. Why our script is too slow. Can we improve it like CE function. Btw thanks for your effort.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Sep 02, 2016 2:24 pm    Post subject: Reply with quote

As I said before, you should be using memscan.firstScan()
Code:
local memscan = createMemScan()
local foundlist = createFoundList(memscan)
memscan.firstScan(
  soValueBetween, vtDword, rtRounded,
  "19791800", "19791900", 0, 0xffffffffffffffff, "+W-C",
  fsmAligned, "4", false, false, false, false)
memscan.waitTillDone()
foundlist.initialize()
local values = {}
local value = foundlist.Value
for i = 0, foundlist.Count - 1 do
  values[value[i]] = true
end
foundlist.destroy()
memscan.destroy()
for i in pairs(values) do
  print(i)
end
Back to top
View user's profile Send private message
azamalvi
Cheater
Reputation: 0

Joined: 16 Aug 2013
Posts: 26

PostPosted: Sat Sep 03, 2016 2:58 am    Post subject: Reply with quote

Thank you soo much Zanzer Smile
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 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