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 


Use a string to feed a PID to "openpricess(processid).

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Tustart123
How do I cheat?
Reputation: 0

Joined: 21 Mar 2012
Posts: 5

PostPosted: Fri Mar 30, 2012 9:58 am    Post subject: Use a string to feed a PID to "openpricess(processid). Reply with quote

So thanks to Wiccaan and Dark byte I was able to produce a script that quickly and effectively parses the command prompt TASKLIST, outputs the result as CSV then splits that to take the two processes with the same exact name. I was then able to extract the single exact string from the process ID that is presented first in the tasklist (but taken second by cheatengine's autoattack).

So what I have is a string for the exact PID1.

Code:
PID1 = (strings_getString(LB1Items, 0))


That does work and test printing the PID1 returns the correct PID1 that I want to open.

Now the issue is.

"Openprocess(processname)" opens the wrong process. It opens the wrong version.

I need to figure out how to take my "PID1" string and feed it to "openprocess(processID)" so that it will open.

I have tried several things and most return an error. I have had no luck with searching the internet for some kind of code to do this.

The things that do not return an error but simply does not work are these.

Code:
openProcess (readInteger(PID1))

and
Code:
openProcess(PID1)


I am looking for any method of taking a string variable which contains the 4 number processID and using openprocess(processid) (or any method that would achieve the same results).

I hope that is clear and I can get some guidance soon. I think I am really close to getting my standalone trainer working. [/code]
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Fri Mar 30, 2012 10:19 am    Post subject: Reply with quote

openProcess needs an integer if you wish to open by processID. If you give it a string, it will look for a processname with that number.

Use
Code:

openProcess(tonumber(PID1))

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Tustart123
How do I cheat?
Reputation: 0

Joined: 21 Mar 2012
Posts: 5

PostPosted: Fri Mar 30, 2012 2:03 pm    Post subject: Reply with quote

Dark Byte wrote:
openProcess needs an integer if you wish to open by processID. If you give it a string, it will look for a processname with that number.

Use
Code:

openProcess(tonumber(PID1))


Thanks for that. It is defiantly in the right direction however I am running into a little bit of an issue.

the string containing my PID does not want to convert to a number and I can not figure out why. Here are the results from some debugging code.

Code:
a = "4988"
b = tonumber(a)

print (type(a)) ------> string
print (type(b)) ------> number

print (a) -----> "4988"
print (b) -----> 4988



That works. However, the string I have (using the code suggested by somebody in the post directly below this one).
Code:

c = (strings_getString(listboxItems, 1))
d = tonumber(c)

print (type(c)) -----> string
print (type(d)) -----> nil

print (c) ----> "4988"
print (d) ---->         


so (d) prints nothing and returns a nil value.


For some reason tonumber does not work on the string I received from getstring, but will work on a string I make (with the exact same value) (IE a does convert but c does not).

I assume there is something hidden that is stopping this but I can not figure it out.

Here is the entire code for my parser and correct PID retriever.

Code:

local target = "abc.exe";
local f = io.popen( string.format( "TASKLIST /FI \"IMAGENAME eq %s\" /FO csv", target ) );
assert( f, "Failed to obtain results from TASKLIST.exe!" );

    for x in f:lines() do
        -- Strip the header line so we don't try to read it as a process..
        local input = string.gsub( x, "(.*),\"Mem Usage\"", '' );
        if string.len( input ) > 0 then
            local parts = input:split( "[^,]+" );
            print( #parts );
            print( parts[1] ); -- prints the process name
            print( parts[2] ); -- prints the process id
            strings_add(LB1Items, parts[2])
            PID1 = (strings_getString(LB1Items, 0))
        end
    end


Basically I have two programs with the name "abc.exe". One with a processid of 5284 on the bottom and one with a process id of 4988 on the top.

Cheatengine autoattack to abc.exe takes the bottom, I need it to take the top. So that code above returns the parsed string of 4988 for the top abc.exe flawlessly.

So essentially using the above code

Code:
print (PID1) -----> "4988"
openProcess(tonumber(PID1))


Does not work.

Code:
PIDTest = "4988"
print (PIDTest) ------> "4988"
openProcess(tonumber(PIDTest))

Does work

Sorry this is so long, I just want to be as clear as possible as it does not make any sense to me why openProcess(tonumber(PID1)) is not working. There is nothing wrong with that code, as tests using strings with the exact same values does work.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Fri Mar 30, 2012 2:30 pm    Post subject: Reply with quote

it could be that PID1 contains some extra characters, like spaces, tabs, perhaps even a linefeed...

not sure if lua contains an easy trim function,but I found this:
Code:

    function trim (s)
      return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
    end

and
http://lua-users.org/wiki/StringTrim

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Tustart123
How do I cheat?
Reputation: 0

Joined: 21 Mar 2012
Posts: 5

PostPosted: Fri Mar 30, 2012 4:24 pm    Post subject: Reply with quote

Dark Byte wrote:
it could be that PID1 contains some extra characters, like spaces, tabs, perhaps even a linefeed...

not sure if lua contains an easy trim function,but I found this:
Code:

    function trim (s)
      return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
    end

and
/////StringTrim



Your guidance was helpful. It allowed me to find the mistake I made in my debugging results.

I missed the fact that
Code:
a = "4988"
print (a) ----> 4988


Strings do not inherently contain the " symbol and the regex that split the parse included the " symbols.
My string was test printing with quotes so it was "4988"

I was able to use
Code:
PID1Fix = string.sub(PID1, 2, -2)

This resulted in a string without the quotes.
so
Code:
PID1 = (strings_getString(ListBox, 0))
print (PID1) ----> "4988"
PID1Fix = string.sub(PID1, 2, -2)
print (PID1Fix) ----> 4988
openProcess(tonumber(PID1Fix))


Opens the correct process. Thank you again for the help.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Fri Mar 30, 2012 6:46 pm    Post subject: Reply with quote

One thing I recommend changing, but not sure:
Code:

string.gsub( x, "(.*),\"Mem Usage\"", '' );


some systems might not contain that specific string. (non english)
Perhaps instead of looking for the string you could count the number of columns

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
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