|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Christbru Newbie cheater Reputation: 0
Joined: 11 Jan 2013 Posts: 15
|
Posted: Sun Jan 13, 2013 7:52 am Post subject: How to re-attach in a cheat table |
|
|
I'm creating a program and I would like to have a button that I can use to relocate the window, say the game opens, the program attaches because it's in the auto attach list. the program closes, how do I reload the auto attach, or have a button to manually tell it to attach?
Code: | function RELOCATEBUTTONClick(sender)
addresslist=getAddressList()
strings_add(getAutoAttachList(), "Game.exe")
end |
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Jan 13, 2013 8:29 am Post subject: |
|
|
Probably you should make your own procedure for that.
Tip: use 'timer' object
Or you can add button, set onClick event:
Code: | function CEButton1Click(sender)
openProcess("Game.exe")
end |
_________________
|
|
Back to top |
|
|
Christbru Newbie cheater Reputation: 0
Joined: 11 Jan 2013 Posts: 15
|
Posted: Sun Jan 13, 2013 4:38 pm Post subject: |
|
|
I don't think I can do that because this inserts a d3d gui, wouldn't attempting to switch processes break connection to it?
[Edit]
Ok nevermind, relocating doesn't break the connection... but it does lag the game a bit, is there any way for my to detect whether it's connected? So I can put a condition in the loop that only if it's not connected will it try to re-attatch
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Sun Jan 13, 2013 5:14 pm Post subject: |
|
|
after the first time opening start a timer that constantly reads a known address. (e.g readInteger("game.exe"))
If it returns nil instead of a number, it means the process is closed, so while it's nil try to open the process
_________________
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 |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Mon Jan 14, 2013 11:04 am Post subject: |
|
|
@DB
checking result of readInteger("game.exe") isn't the same as checking getOpenedProcessID() ?
_________________
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Mon Jan 14, 2013 12:28 pm Post subject: |
|
|
getOpenedProcessID() will return the processid of the process, even if it has been closed
_________________
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 |
|
|
Infernus1 How do I cheat? Reputation: 0
Joined: 07 Jan 2013 Posts: 6
|
Posted: Tue Jan 15, 2013 10:40 pm Post subject: |
|
|
Doesn't seem to work, always returns null. Running 32-bit CE on 64-bit. (Shouldn't matter proly)
Possibly it's converting the "notepad.exe" adress wrong?
Code: | -- form
local Trainer_Example = { }
-- process
local process_name = "notepad.exe";
----------------------------------------------------------------------------------
-- func: Trainer_Example.Main( .. )
-- desc: Prepares script for overall actions.
----------------------------------------------------------------------------------
function Trainer_Example.Main( )
-- ========= Main Form ========== --
Trainer_Example.Form = createForm( true ); -- Main trainer form pointer.
control_setSize( Trainer_Example.Form, 300, 200 ); -- Set size of form
form_centerScreen( Trainer_Example.Form ) -- Center form
control_setCaption( Trainer_Example.Form, "Process Attacher" ); -- Set form title.
form_onClose(Trainer_Example.Form, closeCleanup) -- Set onClose function
-- =========== Other =========== --
Trainer_Example.process_checker = InitTimer( Trainer_Example.main_panel, 5000, false, process_checker )
return true;
end
--================================================================================
-- CUSTOM FUNCTIONS --
--================================================================================
function InitTimer( owner, tickRate, status, func )
timer = createTimer( owner )
if( timer == nil ) then
return nil;
end
timer_setInterval( timer, tickRate )
timer_onTimer( timer, func )
timer_setEnabled( timer, status )
return timer;
end
--================================================================================
-- TIMERS --
--================================================================================
function process_checker(t)
status = readInteger( process_name )
if status == nil then
print("not attached to process")
else
print("attached to process")
end
end
--================================================================================
-- EVENTS --
--================================================================================
function onOpenProcess()
print("trying to attach to process")
end
function closeCleanup(sender)
closeCE()
return caFree
end
--================================================================================
----------------------------- Start execution --------------------------------
Trainer_Example.Main();
pid = getOpenedProcessID()
if pid == 0 then
print("auto attaching first time")
strings_add(getAutoAttachList(), process_name) -- attach to process
else
openProcess( pid ) -- if cheat engine is open, it will use this one? wtf
end
timer_setEnabled( Trainer_Example.process_checker, true ) -- timer... |
First attempt launching the script without notepad open
Code: | auto attaching first time
not attached to process
not attached to process
not attached to process
not attached to process
not attached to process |
Second attempt launching the script without notepad open. Opening notepad in about 20 sec. Looks like process opens in CE, but it doesn't respond to the script...
Results:
Code: | auto attaching first time
not attached to process
not attached to process
not attached to process
trying to attach to process
not attached to process
not attached to process
not attached to process |
Third attempt launching the script with notepad open.
Results:
Code: | auto attaching first time
trying to attach to process
not attached to process
not attached to process
not attached to process |
Fourth attempt, starting with notepad open, closing and reopening it.
Results:
Code: | auto attaching first time
trying to attach to process
not attached to process
not attached to process
not attached to process
not attached to process
-- should be here something
not attached to process
not attached to process
not attached to process
-- and here.. but wtf
not attached to process
|
Well, what could possible be wrong...? Damn life is hard o.O
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Wed Jan 16, 2013 4:00 am Post subject: |
|
|
AutoAttach will stop working if you have attempted to open at least one process
Also, openProcess(0) will not open cheat engine, but it will disable the autoattach routine since you've tried to open a process (that doesn't exist)
try this code instead:
Code: |
-- form
local Trainer_Example = { }
-- process
local process_name = "notepad.exe";
----------------------------------------------------------------------------------
-- func: Trainer_Example.Main( .. )
-- desc: Prepares script for overall actions.
----------------------------------------------------------------------------------
function Trainer_Example.Main( )
-- ========= Main Form ========== --
Trainer_Example.Form = createForm( true ); -- Main trainer form pointer.
control_setSize( Trainer_Example.Form, 300, 200 ); -- Set size of form
form_centerScreen( Trainer_Example.Form ) -- Center form
control_setCaption( Trainer_Example.Form, "Process Attacher" ); -- Set form title.
form_onClose(Trainer_Example.Form, closeCleanup) -- Set onClose function
-- =========== Other =========== --
Trainer_Example.process_checker = InitTimer( Trainer_Example.main_panel, 5000, false, process_checker )
return true;
end
--================================================================================
-- CUSTOM FUNCTIONS --
--================================================================================
function InitTimer( owner, tickRate, status, func )
timer = createTimer( owner )
if( timer == nil ) then
return nil;
end
timer_setInterval( timer, tickRate )
timer_onTimer( timer, func )
timer_setEnabled( timer, status )
return timer;
end
--================================================================================
-- TIMERS --
--================================================================================
function process_checker(t)
status = readInteger( process_name )
if status == nil then
print("not attached to process "..process_name)
openProcess(process_name)
else
print("attached to process")
end
end
--================================================================================
-- EVENTS --
--================================================================================
function onOpenProcess()
print("trying to attach to process")
end
function closeCleanup(sender)
closeCE()
return caFree
end
--================================================================================
----------------------------- Start execution --------------------------------
Trainer_Example.Main();
timer_setEnabled( Trainer_Example.process_checker, true ) -- timer...
|
_________________
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 |
|
|
Infernus1 How do I cheat? Reputation: 0
Joined: 07 Jan 2013 Posts: 6
|
Posted: Wed Jan 16, 2013 9:45 am Post subject: |
|
|
That sucks that it does... I acctualy thought about openProcess(0) before. It's a nice trick thought , but wtf
Attempt one with notepad opened:
Cheat engine shows that it's attached to process 00001f68-???
Code: | not attached to process notepad.exe
trying to attach to process
not attached to process notepad.exe
trying to attach to process
not attached to process notepad.exe
trying to attach to process
not attached to process notepad.exe |
Attempt two with notepad closed and reopened:
Code: | not attached to process notepad.exe
not attached to process notepad.exe
not attached to process notepad.exe
trying to attach to process
not attached to process notepad.exe
trying to attach to process
not attached to process notepad.exe
trying to attach to process |
Looks like cheat engine fails to open and after free the process since it shows question marks at the end ???.
There should be some functions to free the attaching, but it doesn't looks like there's. Have been digging throw main.lua, but couldn't find anything good. Sux.
I have thought about doing the attaching throw this function:
Code: |
local process_name = "notepad.exe";
function FindProcessPids()
local stringList_object = createStringlist(); -- will hold all current
local process_list = createStringlist(); -- will hold "process_name" processes
getProcesslist(stringList_object)
for i = 1 , strings_getCount(stringList_object)-1 do --skip system
process_text = strings_getString( stringList_object , i)
if string.find(string.lower(process_text), process_name) then
j = string.find( process_text , '-' )
pid = '0x' .. string.sub( process_text , 1, j - 1 )
strings_add(process_list, tonumber( pid ))
--strings_add(process_list, process_text)
print(process_text .. " pid: " .. tonumber( pid ))
end
end
return process_list;
end |
Since, the list always gets filled with current working pids. So, it can't fail
It's your code, I only modified it a bit.
Only problem with this code is that if there's 2 processes of same type, it will choose the first one to attach to.. and user maybe doesn't want that. (comboBox? >.>)
------------------------------------------------------
EDIT1:
Mhm, your code above works perfectly. Tested on different processes. Thought notepad.exe and calc.exe, doesn't want to open. Wierd.
|
|
Back to top |
|
|
gpain How do I cheat? Reputation: 0
Joined: 16 May 2014 Posts: 1
|
Posted: Fri May 16, 2014 12:40 pm Post subject: |
|
|
Is there a way to get to recheck for the new process without setting a timer in the script?. Like we can do in the settings tab of CE.
If not is possible to introduce that feature? ( a parameter to the StringList Object or smt like that )
Thanks
EDIT: Ok i saw that having enabled "Even autoattach when another process has already been selected" option works. Any way doing this from script?
|
|
Back to top |
|
|
Redouane Master Cheater Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Mon May 26, 2014 6:15 am Post subject: |
|
|
gpain wrote: | Is there a way to get to recheck for the new process without setting a timer in the script?. Like we can do in the settings tab of CE.
If not is possible to introduce that feature? ( a parameter to the StringList Object or smt like that )
Thanks
EDIT: Ok i saw that having enabled "Even autoattach when another process has already been selected" option works. Any way doing this from script? |
Short algorithm that should do the trick:
Code: | do
local t = createTimer( getMainForm( ) )
-- Avoiding repetitive global access
local PID , _read , _open = getOpenedProcessID , readBytes , openProcess
t.Interval , t.onTimer = 1000 , function ( )
local _ = ( ( PID() == 0 ) or not _read( 0x01000000 , 1 ) ) and _open'notepad.exe'
-- Same as local _ = ( ( PID() ~= 0 ) and _read( 0x01000000 , 1 ) ) or _open'notepad.exe'
--[[ Some other code you may need to execute every second example:recalculate editbox value or label caption etc.]]--
end
end |
This code won't call openProcess if the target 'notepad.exe' is currently opened (will call it once only).
Change 'notepad.exe' to your target process name,and 01000000 to the base address of the main module,you may also change the timer interval (in ms).
What's the difference between createTimer(getMainForm()) and createTimer(true)?
[EDIT] PID is a function,not the process id.
[EDIT2] Fixed 'notepad.exe' module base,it's 01000000 not 00400000.
|
|
Back to top |
|
|
CptBrian How do I cheat? Reputation: 0
Joined: 19 Sep 2019 Posts: 9
|
Posted: Mon May 18, 2020 9:51 pm Post subject: Auto Re-Attach Game Process Mini-Tutorial |
|
|
I've seen threads go back 9 years of people unable to get trainers auto-reattaching to processes upon opening the process again.
It's still a big problem.
If we could just implement the following CE setting through Lua, everything would be fine:
"Even autoattach when another process has already been selected"
But we aren't able to yet.
Update: I've finally got a solution that works.
• Place a Timer on the trainer and set its interval to somewhere between 1000 and 2000ms; I'm using 1200 at the moment.
• Go to the timer object's Events tab in editor and add an "OnTimer" function to it using the [...] button.
• Use this code for the function and adjust it for your project:
Code: |
function FORMNAME_TIMERNAMETimer(sender)
local Difficulty=AddressList.getMemoryRecordByDescription('Difficulty')
if(Difficulty.Value == nil) or (Difficulty.Value < "1") or (Difficulty.Value > "3") then
openProcess("YOUR-GAME-NAME.exe")
end
end
|
This function is constantly running at your timer's set interval. It's there to re-attach the process between multiple game sessions or remove the requirement of needing the game open before the trainer.
openProcess at the bottom will always grab the newest instance of the process, which is what you want for reattachment.
Replace "Difficulty" with a fitting pointer/address for this scenario.
The "Difficulty" pointer/address is being read from my cheat table's address list so I don't need to input it manually.
For the address, I chose Difficulty, because it meets the following conditions:
• The pointer finds this address immediately upon launching the game.
• The address never moves or "flickers" unusual values; it's stable.
• Its value is always 1, 2 or 3, so it's easy to check if the returned value is wrong / not found.
Just checking for a nil value wasn't enough for me, because spaghetti, which is why I added the other two checks as fail-safes, also knowing some programs may register "nil" as a value of either 0 or <0.
Another example I have is a "Game Speed" address I've found which is always at a value of 1 from the moment the game launches, and never changes, so the following could be done with that:
Code: |
local GameSpeed=AddressList.getMemoryRecordByDescription('Game Speed')
if(GameSpeed.Value == nil) or (GameSpeed.Value ~= "1") then
|
Or just the second condition alone.
|
|
Back to top |
|
|
paul44 Expert Cheater Reputation: 2
Joined: 20 Jul 2017 Posts: 152
|
Posted: Sat Nov 14, 2020 6:02 am Post subject: my "solution" to autoAttach ~ purely feedbacking h |
|
|
I've tried out most suggestions here (and elsewhere), but kept on hitting the wall at some point; never really got it working as I wanted. Span over the last 3 months or so, I finally (?) came up with this: [ https://www.dropbox.com/s/laq6grzrqj3kmv2/CE%20AutoAttachProcess.pdf?dl=0 ].
This routine seems to do the trick without receiving all sorts of error/warning messages at some point. The purpose of this doc is to give - in a nutshell - actions I've taken in order to get to the '5th' page (~UpdateWinTitle). And it really took me a long time to get to this point; some "issues" are mentioned in this topic already... That said: if you come across a "pitfall" of sorts, please let me know...!
(btw: i've done all this in relation to my work on a 'Compact view mode')
FYI: I still do have some open issues to tackle though:
1. 'auto-closing' mem_records: v7x does a great job, apart from the 'locked values'. Is this known? possible workaround ?
I can loop through each mr and get them disabled; see my v6.x remark in that respect. if anyone knows of a quick solution, steer me in the right direction...
2. open 'different' game/process_name: currently I completely rely on 'myGame' variable (which should work fine for 99% of the users). however: I make use of several exe's for testing/support purposes (eg: AC BF has 5-6 different official (!) exes just for its final v1.07 release ~ which I renamed accordingly ~> AC4BFSP_CN.exe - intro CN support).
So: either i need to catch the processname from a [File ~ Open process] action somehow (can this be launched/executed from lua? ~ menuitem/button), or use 'createOpenDialog()' to update my 'myGame' variable... no experience here (yet), and suggestions always welcome...
-EDIT-: solved this part using 'createOpenDialog()'; and found a way of obtaining the exe's dir_location. (dialog will always open in "current" dir, which seems to be the CT location)
some other usefull links: (yep, tried out most of this stuff )
[ https://wiki.cheatengine.org/index.php?title=Tutorials:Lua:Setup_Auto_Attach ]
[ https://forum.cheatengine.org/viewtopic.php?t=583278&sid=ddc9fc6c2d4cd75df64985c08f4e8a53 ]
[ https://forum.cheatengine.org/viewtopic.php?t=529853&sid=2e3817b3d8c461b1d0e678a28f30c4ac ]
|
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Sun Nov 15, 2020 7:40 am Post subject: |
|
|
@paul44, hopefully this will suit
You don't need to disable the timer as long as the current process is open it will not perform any action (other than readInteger and compare 2 variables).
Note: this script should attach to either of your AC BF processes (assuming they are all follow AC4BFSP_FN.exe format)
Regarding unfreezing address, simply loop through all addresslist entries and set active to 0.
Code: | myGame = ""; -- well to trigger caption change once on start
function getACProcess()
for processId,processName in pairs(getProcesslist()) do
if (processName:match("AC%d?BF%w*_?%w*%.exe")) then -- checks if process name has AC*number?*BF*letters/underscore/letters* does not care if you input that number or letters or underscore
myGame = processName;
openProcess(processId);
waitForSections(); -- wait until the sections have been enumerated otherwise getAddress might first time;
return true;
end
end
myGame = nil; -- reset
return false; -- did not find the process
end
processTimer = createTimer( getMainForm() );
processTimer.interval = 100; -- 100ms
processTimer.onTimer = function (sender)
local lmyGame = myGame;
if (not readInteger(myGame)) then
if (getACProcess()) then -- found process
local startAddress = getAddress(myGame);
-- if (myStartAddress == startAddress) then return end; -- no point? as it most likely to change when you're switching/re-attaching to a process
local endAddress = startAddress + nCheckMemRange; -- getModuleSize(myGame);
if ((getStaticAddr(sCheckProc,0,"",3,startAddress,endAddress) or 0) == 0) then
myGame = nil; -- uhh getStaticAddr is not consistent?
end
end
end
if (lmyGame~=myGame) then
getMainForm().Caption = ("Cheat Engine v%.1f - %s"):format(getCEVersion(),myGame and myGame or "No game process is found");
end
end |
_________________
|
|
Back to top |
|
|
paul44 Expert Cheater Reputation: 2
Joined: 20 Jul 2017 Posts: 152
|
Posted: Sun Nov 15, 2020 10:41 am Post subject: still running... |
|
|
@DaSpamer:
thx, I will have a look at it, though it is unlikely that I'll change my routine as it is working now (espec. considering the amount of time I've spent (still) on this vehicle...)
I figured so much that one needs to traverse mem_records to get them 'unocked'; but at least I got it confirmed now...
btw1: my timer never gets destroyed, unless set via an "option" (= autoattach once)
btw2: the current script has been extended since then, incl
a) 'AC4BFSP_FN.exe format' (I will definitely check out/compare your solution with mine): yep, i pretty much use the same approach as you did, with your pattern being a bit more "generic". I did not want to go that far; but duly noted though... (depending feedback from gamers, I might use that one)
b) using 'createOpenDialog(self)', in case one does not follow 'format a)' (ps: no longer using Addr-checks)
btw3: I ran into a snack here as I can't seem to set the 'load_dialog.InitalDir' to the game's exe_location. (not going to discuss it here, as I plan to open a new topic related to this issue; but also to explain how I did "catch" that location)
=> I got pretty much "everything" solved now by using the 'OnOpenProcess' fn !
ps: did my testing from 2 perspectives:
1. respective EXEs running, then loading table (+ always test "crash" scenario)
2. table loaded, then run resp. EXEs (+ "crash")
(there is a minor aesthetic snack - upon using 'openProcess' dialog - but it makes no difference functionality-wise... I'll get that sorted out evt)
-EDIT-
I've updated this post (and my pdf-link in prev post) to reflect current status. From my point of view, "closing my request(s)"...
thx for the assistance.
Last edited by paul44 on Sat Nov 21, 2020 3:19 am; edited 1 time in total |
|
Back to top |
|
|
|
|
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
|
|