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 


Problem with one timer that keep runing

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

Joined: 27 Sep 2018
Posts: 43

PostPosted: Wed Apr 15, 2020 8:40 am    Post subject: Problem with one timer that keep runing Reply with quote

Hi.
And first : thank all of you great dev for your help !

I have a problem with a lua script i'm trying to understand and change

Code:

function openRightProcess(processname, howmanyprocesses, whichprocess)

  local processlist=createStringlist()
  local processnameLower = processname:lower()
  print("test here")

  local timer = createTimer(getMainForm())
  timer.Interval = 100
  timer.OnTimer =
  function (t)

    local tmp={}
    getProcesslist(processlist)

    for i=0,processlist.Count-1 do
      if processlist[i]:sub(10):lower() == processnameLower then
         tmp[1+#tmp]=processlist[i]
      end
    end

    Print("test here too")

    if #tmp>=howmanyprocesses and CorrectProcess == 0 then
      Sleep(10000)
      processlist.destroy()
      t.destroy()
      openProcess(tonumber(tmp[whichprocess]:sub(1,8),16))
      PID = tonumber(tmp[whichprocess]:sub(1,8),16)

      local res = AOBScan("89 82 ?? ?? ?? ?? 8B 82 ?? ?? ?? ?? 83 F8")

      if res ~= nil then
        for i=0, res.Count-1, 1 do
          CorrectProcess = PID
          res.destroy()
        end
      end
    end
  end
end

function Initialize()
  PID = 0
  CorrectProcess = 0

  for i=1,3 do
      openRightProcess(DefaultProcess, 3, i)
  end

  local ytimer = createTimer(nil)
  ytimer.Interval = 100

  ytimer.OnTimer =
  function (y)
    if CorrectProcess ~= 0 then
      print (CorrectProcess)
      y.destroy()
      openProcess(CorrectProcess)
    end
  end
end

function myForm_CEButton1Click(sender)
  DefaultProcess = 'My process.exe'
  PID = 0
  CorrectProcess = 0
  Initialize()
end


So when i click the "Button" the script try to attach the good process by checking with an aobscan in each of my 3 "My process.exe"
In my Lua Engine i have :
test here
test here
test here

it's
Code:

for i=1,3 do
      openRightProcess(DefaultProcess, 3, i)
  end


test here too
test here too
test here too

my 3 timer

then my pid process (as integer)

and then the "test here too" keep on popping

i have try a : t.destroy() -> execute in lua engine


t.destroy()

Error:[string "t.destroy()
..."]:1: attempt to index a nil value (global 't')
Script Error

i think the problem is in the fact the "openRightProcess" is open 3 time even if it's the first or second process the good one.

So how to change that ?

and why t.destroy() didn't work ?

I have some other question cause i'm trying to port AA -> lua seen lot of vid but i'm a bit stuck.

as : how to add :
myoffset = copyMemory("MyAddress+2",4 ,"WantedOffset") <- copy my offset
but i need to add my base address to this offset something like:
myadress = 0x80005000 + myoffset

Edit :
This seems to work :
Print(string.format("%x", (readInteger("MyAddress+2")+0x80005000) * 256))

but why the print give me 5 bytes ? with 00 ending.

Edit2:
Print(string.format("%.8s", tostring(string.format("%x", (readInteger("MYAddress+2")+0x80005000) * 256))))

no more 00... but still don't understand why it add 00


someone may help me on discord or by PM here or mail ?
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