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 Error onOpenProcess vs "Select a Process to Open Bu

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

Joined: 09 Jan 2013
Posts: 19

PostPosted: Mon Jun 09, 2014 7:35 pm    Post subject: Lua Error onOpenProcess vs "Select a Process to Open Bu Reply with quote

Lua Error onOpenProcess vs "Select a Process to Open Button
---------------------------------------------------------------
(I haven't restarted the game while testing the trainer, and I have the right version of the game open [since the trainer attaches itself to other DX# executables of the game]).

Hi, I've got a not-standalone-yet trainer that auto-attaches to the process, and when readInteger() gets called, it returns a nil value for an attribute that should be 500, but when I use the button in CE, it's reads correctly.
What's strange is the same attribute on the address list is shown as 500 too.

If it's any indicator:
Code:
function onOpenProcess()
    print("Target Process detected.")
    print("Initializing Style Decayer...")
    local start = os.time()
    local stop
    local is_init = false --whether or not AOBScan was used
--    print("This is DMC4StyleDecay.meterobj "..DMC4StyleDecay.meterobj)
    if DMC4StyleDecay.meterobj == nil then --not filled in by .ini
       print("Running AOBScan for Style Meter object.")
       is_init = DMC4Core.initStyleMeter()
       if is_init then --check if scan went well
           DMC4StyleDecay.meterobj = DMC4Core.stymeter
       else
           print("Initialization failed.")
           return
       end
    end --if meterobj is nil
    DMC4StyleDecay.initialize()
    stop = os.time()
    print("Initialization Time (Seconds): ".. os.difftime(stop,start))
end

function close()
    closeCE()
end

---------Call Functions Here--------------
form_show(UDF1)
processlist = getAutoAttachList()
local used_ini = initialize()
if used_ini == false then
    strings_add(processlist, "DevilMayCry4_DX9.exe")
    strings_add(processlist, "DevilMayCry4_DX10.exe")
end
print(readInteger('["DevilMayCry4_DX9.exe"+00A558CC]+1c8'))


Code:
function DMC4StyleDecay.initialize()
    --array of threshholds for combo meter rank up's read from game.
    local rankuparray = DMC4StyleDecay.meterobj..'+1c8'
    local rankupthh   = 0                --threshhold for ranking up style.
    local lvalue                         --value the gauge will be at when the rank goes down.
    --For when the game hasn't initialized the threshholds array i.e before player started a mission.
    local lazyassume  = {500, 700, 900, 1000, 1500, 750, 1250, 1250}
    print("meterobj is "..DMC4StyleDecay.meterobj)
    print("rankuparray is "..rankuparray)
    print("test1 "..readInteger('["DevilMayCry4_DX9.exe"+00A558CC]+1c8')) --this is line 36
    print("rankuparray has "..readInteger(rankuparray))
    rankupthh = readInteger(rankuparray)
    if rankupthh ~= 0 and
       rankupthh ~= nil then
        --Copies over data from game memory; only 7 ranks available.
        for i=1, 7 do
--          print("iteration at.."..i)
            DMC4StyleDecay.residues[i] = rankupthh * DMC4StyleDecay.percentage
            rankuparray = rankuparray..'+4' --traverse game's array of threshholds
            rankupthh = readInteger(rankuparray)
        end --end for
    else --game has not initialized the array
        print("Using assumption...")
        for i=1, 7 do
            DMC4StyleDecay.residues[i] = lazyassume[i] * DMC4StyleDecay.percentage
        end
    end
    --Using CE's timer object.
    DMC4StyleDecay.ctimer = createTimer(DMC4StyleDecay, false) --OFF, & get destroyed with this object
    timer_setInterval(DMC4StyleDecay.ctimer, DMC4StyleDecay.cinterval)
    timer_onTimer(DMC4StyleDecay.ctimer, DMC4StyleDecay.decay)
    timer_setEnabled(DMC4StyleDecay.ctimer, true) --ON
end


This gets printed out when I let the trainer auto-attach:
Quote:
Target Process detected.
Initializing Style Decayer...
meterobj is ["DevilMayCry4_DX9.exe"+00A558CC]
rankuparray is ["DevilMayCry4_DX9.exe"+00A558CC]+1c8
Error:...s\DevilMayCry4_StyleDecrement\lib/DMC4StyleDecay.lua:36: attempt to concatenate a nil value

But when I use CE's button to pick a process to select this gets printed
Quote:
Target Process detected.
Initializing Style Decayer...
meterobj is ["DevilMayCry4_DX9.exe"+00A558CC]
rankuparray is ["DevilMayCry4_DX9.exe"+00A558CC]+1c8
test1 500
rankuparray has 500
Error:...s\DevilMayCry4_StyleDecrement\lib/DMC4StyleDecay.lua:44: attempt to perform arithmetic on local 'rankupthh' (a nil value)

(This function works properly when the trainer uses a result from an AOBScan).

This has me stumped for a while.
EDIT: My title was probably too long.
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Mon Jun 09, 2014 8:18 pm    Post subject: Reply with quote

umm.... so, the point of the whole thread is just to ask why print(readInteger('["DevilMayCry4_DX9.exe"+00A558CC]+1c8')) doesn't return what you expect?

Try
a = readInteger("DevilMayCry4_DX9.exe+00A558CC")
print(a)
and
print(readInteger(a+456))
and check to see if they match the addresses in your addresslist. Chances are, you've got a bad pointer in there somewhere.

_________________
A nagy kapu mellett, mindig van egy kis kapu.
----------------------
Come on...
Back to top
View user's profile Send private message
hydris
Newbie cheater
Reputation: 0

Joined: 09 Jan 2013
Posts: 19

PostPosted: Mon Jun 09, 2014 8:43 pm    Post subject: Reply with quote

justa_dude wrote:
umm.... so, the point of the whole thread is just to ask why print(readInteger('["DevilMayCry4_DX9.exe"+00A558CC]+1c8')) doesn't return what you expect?

Try
a = readInteger("DevilMayCry4_DX9.exe+00A558CC")
print(a)
and
print(readInteger(a+456))
and check to see if they match the addresses in your addresslist. Chances are, you've got a bad pointer in there somewhere.


Well, it doesn't return what I expect if I let it auto-attach, but if I use the button to manually attach the same process then execute the script, it works fine- the difference between the autoAttach and clicking the button is what's confusing me.

I tried your suggestion, and it's acting differently between the different ways of attaching too- though when I attach it manually, it's printing out 500 like the rest.
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Mon Jun 09, 2014 9:14 pm    Post subject: Reply with quote

use 'or' statement.
Whenever you're trying to print use some data, and it could be nil, you can use 'or' statement.
For example
Code:
print(a or 'a is nil');
a = 'a is not nil'
print(a or 'a is nil');


Try this script.
Although I'd order it bit more.. (define vars for each reading, and verify that they're not nil and such).
Code:
function onOpenProcess()
    print("Target Process detected.")
    print("Initializing Style Decayer...")
    local start = os.clock() -- More accurate
    local stop
    local is_init = false --whether or not AOBScan was used
--    print("This is DMC4StyleDecay.meterobj "..DMC4StyleDecay.meterobj)
    if DMC4StyleDecay.meterobj == nil then --not filled in by .ini
       print("Running AOBScan for Style Meter object.")
       is_init = DMC4Core.initStyleMeter()
       if is_init then --check if scan went well
           DMC4StyleDecay.meterobj = DMC4Core.stymeter
       else
           print("Initialization failed.")
           return
       end
    end --if meterobj is nil
    DMC4StyleDecay.initialize()
    print("Initialization Time (Seconds): ".. os.clock() - start)
end

function close()
    closeCE()
end

---------Call Functions Here--------------
form_show(UDF1)
processlist = getAutoAttachList()
local used_ini = initialize()
if used_ini == false then
    strings_add(processlist, "DevilMayCry4_DX9.exe")
    strings_add(processlist, "DevilMayCry4_DX10.exe")
end
print((readInteger('["DevilMayCry4_DX9.exe"+00A558CC]+1c8') or 'Error could not read address'))

function DMC4StyleDecay.initialize()
    --array of threshholds for combo meter rank up's read from game.
    local rankuparray = DMC4StyleDecay.meterobj..'+1c8'
    local rankupthh   = 0                --threshhold for ranking up style.
    local lvalue                         --value the gauge will be at when the rank goes down.
    --For when the game hasn't initialized the threshholds array i.e before player started a mission.
    local lazyassume  = {500, 700, 900, 1000, 1500, 750, 1250, 1250}
    print("meterobj is "..DMC4StyleDecay.meterobj)
    print("rankuparray is "..rankuparray)
    print("test1 "..(readInteger('["DevilMayCry4_DX9.exe"+00A558CC]+1c8') or ' - Failed... could not read data')) --this is line 36
    print("rankuparray has "..(readInteger(rankuparray) or ' nil '))
    rankupthh = readInteger(rankuparray)
    if rankupthh ~= 0 and
       rankupthh ~= nil then
        --Copies over data from game memory; only 7 ranks available.
        for i=1, 7 do
--          print("iteration at.."..i)
            DMC4StyleDecay.residues[i] = rankupthh * DMC4StyleDecay.percentage
            rankuparray = rankuparray..'+4' --traverse game's array of threshholds
            rankupthh = readInteger(rankuparray)
        end --end for
    else --game has not initialized the array
        print("Using assumption...")
        for i=1, 7 do
            DMC4StyleDecay.residues[i] = lazyassume[i] * DMC4StyleDecay.percentage
        end
    end
    --Using CE's timer object.
    DMC4StyleDecay.ctimer = createTimer(DMC4StyleDecay, false) --OFF, & get destroyed with this object
    timer_setInterval(DMC4StyleDecay.ctimer, DMC4StyleDecay.cinterval)
    timer_onTimer(DMC4StyleDecay.ctimer, DMC4StyleDecay.decay)
    timer_setEnabled(DMC4StyleDecay.ctimer, true) --ON
end


EDIT:
Here a script that should fit your needs, and prevent issues that you had.
Take a look on the process_name variable, it should/can speed lot's of stuff for you.
I didn't test the script below, by theory it should work.
Code:
-- Deciding which process is opened... we'll use the var process_name to read memory
-- Since lua throws error when trying to call type on some of C.E functions, so I used nil incase it doesn't return anything..
local process_name = ((type(getProcessIDFromProcessName("DevilMayCry4_DX9.exe") or nil)=='number') and "DevilMayCry4_DX9.exe" or (type(getProcessIDFromProcessName("DevilMayCry4_DX10.exe") or nil)=='number') and "DevilMayCry4_DX10.exe") or false
-- Check the print("test1 ...) to see how you could use it.
function TargetOpened()
   print('Attached successfully');
    print("Initializing Style Decayer...")
    local start = os.clock() -- More accurate
   if DMC4StyleDecay.meterobj == nil then
       print("Running AOBScan for Style Meter object.")
       if (DMC4Core.initStyleMeter()) then
           DMC4StyleDecay.meterobj = DMC4Core.stymeter
       else
           print("Initialization failed.")
           return
       end
    end
    DMC4StyleDecay.initialize()
    print("Initialization Time (Seconds): ".. os.clock() - start)
end
DMC4StyleDecay={}
function DMC4StyleDecay.initialize()
    local rankuparray = DMC4StyleDecay.meterobj..'+1c8'
    local rankupthh   = 0
    local lazyassume  = {500, 700, 900, 1000, 1500, 750, 1250, 1250}
    print("meterobj is "..DMC4StyleDecay.meterobj)
    print("rankuparray is "..rankuparray)
    print("test1 "..(readInteger('["' .. process_name .. '"+00A558CC]+1c8') or ' - Failed... could not read data')) -- Should work if attached... so the or ' - Failed ' .. is not really required
    print("rankuparray has "..(readInteger(rankuparray) or ' no elements ')) -- Same here...
    rankupthh = readInteger(rankuparray)
    if (rankupthh ~= 0 and rankupthh ~= nil) then
        for i=1, 7 do
            DMC4StyleDecay.residues[i] = rankupthh * DMC4StyleDecay.percentage
            rankuparray = rankuparray..'+4'
            rankupthh = readInteger(rankuparray)
        end
    else
        print("Using assumption...")
        for i=1, 7 do
            DMC4StyleDecay.residues[i] = lazyassume[i] * DMC4StyleDecay.percentage
        end
    end
    DMC4StyleDecay.ctimer = createTimer(DMC4StyleDecay, false)
    timer_setInterval(DMC4StyleDecay.ctimer, DMC4StyleDecay.cinterval)
    timer_onTimer(DMC4StyleDecay.ctimer, DMC4StyleDecay.decay)
    timer_setEnabled(DMC4StyleDecay.ctimer, true)
end
form_show(UDF1);
local used_ini = initialize();
if (process_name == false) then -- If none of processes are found, it's value will be false, so here we'll say theres no process running.
   return showMessage('Game is not running!');
else
    openProcess(process_name); -- Open the game process..
   TargetOpened();
end

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
hydris
Newbie cheater
Reputation: 0

Joined: 09 Jan 2013
Posts: 19

PostPosted: Mon Jun 09, 2014 11:08 pm    Post subject: Reply with quote

When I try running the script with your changes, Cheat Engine crashes with c00..5- which could be anything else really, but I see where you're getting at (ditch autoattachlist).

[Though, the thing about my script is that it's to work with 4 different releases of the game (besides DX9, DX10, there's also the debug versions that were released accidentally)- I have an .ini file that lets me adjust the trainer to whatever I renamed the executable to {then in initialize() it feeds the names to an auto-attach list}.]
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Tue Jun 10, 2014 12:05 am    Post subject: Reply with quote

It feels to me like you guys are making this waaaayyyy more complicated than it needs to be (a failing I perceive with most Lua stuff, honestly).

That said, you could perhaps try adding a delay and/or refreshing symbols after you attach (though this might be done automatically when you attach anyway). I can't think of any other reason that autoattach would produce different results from attaching manually.

_________________
A nagy kapu mellett, mindig van egy kis kapu.
----------------------
Come on...
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Tue Jun 10, 2014 3:18 am    Post subject: Reply with quote

onOpenProcess can get called multiple times, and sometimes even from a different thread.
When cheat engine closes a process it's called as well

Add a check to see if test1 is nil, and if so abort and wait for another attempt

Or what i recommend is only creating a timer and launch/destroy and relaunch when onOpenProcess is called. And in that timer do the initialization

_________________
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
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Tue Jun 10, 2014 12:23 pm    Post subject: Reply with quote

hydris wrote:
When I try running the script with your changes, Cheat Engine crashes with c00..5- which could be anything else really, but I see where you're getting at (ditch autoattachlist).

[Though, the thing about my script is that it's to work with 4 different releases of the game (besides DX9, DX10, there's also the debug versions that were released accidentally)- I have an .ini file that lets me adjust the trainer to whatever I renamed the executable to {then in initialize() it feeds the names to an auto-attach list}.]

Disable temporary functions that initialize and such, and check if it attached successfully, without crashing ( If it printed all stuff as well).
If it does, check the initialize scripts.

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
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