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 


Checking successful proc attachment

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

Joined: 18 Dec 2011
Posts: 76

PostPosted: Tue Jul 09, 2013 3:43 am    Post subject: Checking successful proc attachment Reply with quote

Trying to breach some LUA here with no prior knowledge, and i'm having trouble with the simplest things.

I just want a simple button that on click attaches to the game process and checks whether it was successful (i.e. process actually exists), and then does stuff when it worked or throws up a message if it didn't.
This is what i got:
Code:
function Button_AttachClick(sender)
  openProcess(game.exe)
  dspid = getOpenedProcessID()
  if (dspid ~= 0) then
    -- do stuff
  else
    showMessage( "game.exe not running" )
  end
end


This spits out an error message in the LUA console, though, and i don't know how to interpret it.
Error:[string "function DST_AttachClick(sender)..."]:2: attempt to index global 'game' (a nil value)

What am i doing wrong?
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Tue Jul 09, 2013 3:49 am    Post subject: Reply with quote

The process name is string so it should be "game.exe" and not game.exe.
_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
HenryEx
Advanced Cheater
Reputation: 1

Joined: 18 Dec 2011
Posts: 76

PostPosted: Tue Jul 09, 2013 3:58 am    Post subject: Reply with quote

oh man


Thanks for the quick answer. Apparently i can't pay attention.

Edit:
It seems i have another quick question or two pertaining to this.

I want to make sure the trainer is attached to the correct game version and everything is in place. Is there something like the AA's ASSERT() function i can use as a lua condition?

Also, trying to use writeBytes instead of a table entry script. Can i use addresses like in AA? So for example, would this be valid:
Code:
writeBytes(game.exe+ABC, 01,10,FF)
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Jul 09, 2013 5:09 am    Post subject: Reply with quote

btw, getOpenedProcessID is not designed for that. It still return process ID even after user close that process.

It should look like this:

Code:
function Button_AttachClick(sender)
  local success = openProcess("game.exe")
  if success then
    -- do stuff
  else
    showMessage( "game.exe not running" )
  end
end


and, to check if process still exist, use this:
Code:
local exist = readInteger("game.exe")
  if exist==nil then
    showMessage( "game.exe process closed" )
  else
    -- do stuff
  end






HenryEx wrote:

I want to make sure the trainer is attached to the correct game version and everything is in place. Is there something like the AA's ASSERT() function i can use as a lua condition?

Also, trying to use writeBytes instead of a table entry script. Can i use addresses like in AA? So for example, would this be valid:
Code:
writeBytes(game.exe+ABC, 01,10,FF)

writeBytes, try this:
Code:
writeBytes("game.exe+ABC", 0x01,0x10,0xFF)



About "AA assert", you have to use readBytes.
You can also use AOBScan or MemScan/FoundList objects.

Here, something like AA assert, readBytes used:
Code:
function checkSignature(address,bytesString)
  bytesString = bytesString:gsub(' ','')
  bytesString = bytesString:upper()

  if #bytesString % 2 ~= 0 then return false end

  local count = #bytesString / 2
  local bytes = readBytes(address,count,true)

  for k,v in pairs(bytes) do
    bytes[k] = string.format('%02X',v)
  end

  if table.concat(bytes) == bytesString then
    return true
  else
    return false
  end
end

-- usage
if checkSignature('game.exe','4D 5A 90 00 03 00') then
  -- signature OK, do stuff
else
  -- unknown game version
end

_________________
Back to top
View user's profile Send private message MSN Messenger
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Tue Jul 09, 2013 7:40 am    Post subject: Reply with quote

You can use this for attaching and making sure that you're still attached.
http://forum.cheatengine.org/viewtopic.php?p=5480102&highlight=#5480102
As well.

An example.
Code:
function VerifyProcess(Proccess)
   local SL=createStringlist()
   getProcesslist(SL)
   for i=0,strings_getCount(SL)-1 do
      local entry = strings_getString(SL,i)
      local processname = entry:sub(10,255)
      local PID = tonumber('0x'..entry:sub(1,8))
      if PID==Proccess then
         object_destroy(SL)
         return processname
      end
   end
   object_destroy(SL)
   return nil
end   

function VerifyOpened()
   if VerifyProcess(getOpenedProcessID())==nil then
      openProcess("game.exe")
      VerifyProcess(getOpenedProcessID())
   end
end


ProcessChecker = createTimer(nil,false)
timer_setInterval(ProcessChecker,30000)
timer_onTimer(ProcessChecker,VerifyOpened)
timer_setEnabled(ProcessChecker,true)


Also you can create a loop..which will cause a freeze too, until the program is found.
Code:
function VerifyProcess(Proccess)
   local SL=createStringlist()
   getProcesslist(SL)
   for i=0,strings_getCount(SL)-1 do
      local entry = strings_getString(SL,i)
      local processname = entry:sub(10,255)
      local PID = tonumber('0x'..entry:sub(1,8))
      if PID==Proccess then
         object_destroy(SL)
         return processname
      end
   end
   object_destroy(SL)
   return nil
end

function VerifyOpened()
   if VerifyProcess(getOpenedProcessID())==nil then
      openProcess("game.exe")
      VerifyProcess(getOpenedProcessID())
      VerifyOpened()
   end
end

ProcessChecker = createTimer(nil,false)
timer_setInterval(ProcessChecker,30000)
timer_onTimer(ProcessChecker,VerifyOpened)
timer_setEnabled(ProcessChecker,true)

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
HenryEx
Advanced Cheater
Reputation: 1

Joined: 18 Dec 2011
Posts: 76

PostPosted: Tue Jul 09, 2013 10:35 am    Post subject: Reply with quote

Thanks a lot! I wouldd +Rep you, but apparently i cannot. Oh well.

I'm close to actually getting something working, but here's a last thing i'm wondering about, even though by now it's kind of off-topic.

I'm trying to create three different hotkeys for a function. I'd say they need to look something like this:

Code:
      createHotkey( switchfunction(toggle), ?) -- toggle hotkey
      createHotkey( switchfunction(true), ?) -- ON hotkey
      createHotkey( switchfunction(false), ?) -- OFF hotkey


I'm not sure. Can you declare a function with arguments for a hotkey? Or do i have to make three extra functions to pass the arguments to the switchfunction?

Also, these are supposed to be 2 button hotkeys. I guess i need to just put both keys, separated with comma? Is there some kind of table where i can look up the codes for keyboard keys?
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Jul 09, 2013 10:46 am    Post subject: Reply with quote

read this file, from line 148 (+ use google):
C:\Program Files\Cheat Engine 6.3\defines.lua

VK_MENU is ALT
VK_RETURN is ENTER




about hotkeys and function with arguments:
Code:
function test(sender)
  if sender==hotkey1 then print('hotkey1 used') end
  if sender==hotkey2 then print('hotkey2 used') end
end

hotkey1 = createHotkey( test,VK_F2,VK_SHIFT)
hotkey2 = createHotkey( test,VK_F3,VK_SHIFT)



or this:

Code:
function test(arg)
  print(arg)
end

createHotkey( function () test(1) end,VK_F2,VK_SHIFT)
createHotkey( function () test(2) end,VK_F3,VK_SHIFT)



Note, if you test your script (developing stage) you probably want to execute Lua script multiple times... Remember to destroy existing objects such as: timers, hotkeys.


Edit:
typo, VK_SHIFT

_________________


Last edited by mgr.inz.Player on Tue Jul 09, 2013 11:28 am; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger
HenryEx
Advanced Cheater
Reputation: 1

Joined: 18 Dec 2011
Posts: 76

PostPosted: Tue Jul 09, 2013 11:22 am    Post subject: Reply with quote

It completely slipped my mind that i could look up the codes in defines.

So i have to encapsulate my switchfunction with function() and end when creating a hotkey with arguments, huh? I never would have guessed that.
What does this even do, create a local mini-function called 'function' just within that one hotkey or something?

Well, it works! Thanks a lot.


I noticed you used VH_Shift in your examples, was that just a typo or is that something different than VK_ keys?
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Jul 09, 2013 11:27 am    Post subject: Reply with quote

HenryEx wrote:

So i have to encapsulate my switchfunction with function() and end when creating a hotkey with arguments

Well, both examples are good.

_________________
Back to top
View user's profile Send private message 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