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 


r/w script to auto refresh when values move

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

Joined: 16 Apr 2013
Posts: 97

PostPosted: Sat Mar 05, 2022 1:39 pm    Post subject: r/w script to auto refresh when values move Reply with quote

Is there any way to make a +r+w aob keep refreshing?
For example, a script like this

Code:
[ENABLE]
{$lua}

if syntaxcheck then return end
function aob_register(sym, pat)
  instr = AOBScan(pat, "+r+w")
  addy = instr[0]
  instr.destroy()
  addy = tonumber(addy, 16)
  unregisterSymbol(sym)
  registerSymbol(sym, addy)
end

aob_register("pPos1","2E BD BB B3 ?? ?? ?? ?? C0 CC 4C 3E ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 33 33 33 40 EF EE EE 3F")

{$asm}
[DISABLE]
unregistersymbol(pPos1)


I'd like it to refind this aob on its own
As it stands, I have to disable and reenable when values move
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Sat Mar 05, 2022 1:59 pm    Post subject: Reply with quote

There is no r flag in the protections string.

Constantly scanning the process's entire address space just to update a single value seems like a ridiculous waste of resources to me. Code injection (search "injection copy") and/or pointers would be far better.

But if you must, use a timer. Search the forums (e.g. "createTimer") for examples.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Sat Mar 05, 2022 5:21 pm    Post subject: Reply with quote

For context - this is for Bluestacks (an android emulator). Finding the coords of a character. Currently no way to hook instructions. So, all has to be done in memory. I tried a create time method, but maybe not doing it right. Here is what I tried:

Code:
[ENABLE]
{$lua}

if syntaxcheck then return end
function aob_register(sym, pat)
  instr = AOBScan(pat, "+r+w")
  addy = instr[0]
  instr.destroy()
  addy = tonumber(addy, 16)
  unregisterSymbol(sym)
  registerSymbol(sym, addy)
end

if tm then tm.destroy() end
tm = createTimer()
tm.Interval = 1

tm.onTimer = function()

aob_register("pPos1","2E BD BB B3 ?? ?? ?? ?? C0 CC 4C 3E ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 33 33 33 40 EF EE EE 3F")

end
{$asm}

[DISABLE]
unregistersymbol(pPos1)
{$lua}
tm.destroy()


It enables, but doesn't seem to update as I move my character as they normally do.

**EDIT: Started working, but yea - I can hear my PC working hard and values are a little sluggish to change. Is there any less resource intensive way to achieve this?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Sat Mar 05, 2022 7:36 pm    Post subject: Reply with quote

You might be able to install ceserver on the emulator and do something with that.

I don't have any experience with bluestacks, so I can't help you much. Maybe look at other people's tables (not necessarily for the same game) and see what they do.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Sun Mar 06, 2022 3:11 pm    Post subject: Reply with quote

I might not have explained well. This approach is not exclusive to Bluestacks. I'm just trying to understand if there's a good way to make it keep searching for the aob automatically.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Sun Mar 06, 2022 3:59 pm    Post subject: Reply with quote

No. I stand by my previous statement: it's ridiculous to constantly scan a process's entire address space just to update a single value.
I think it's a bad idea to do aobscans for mutable data regardless, but so many people do it that I don't find much meaning in talking about it.

Code injection (search "injection copy") and/or pointers are far better for automatically updating a value if it changes locations. (regardless of when this change occurs)

Emulators make that harder for obvious reasons. Approaching it from the same level as the emulated architecture might be easier (i.e. ceserver, or modify the rom directly).

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Sun Mar 06, 2022 4:51 pm    Post subject: Reply with quote

I've tried CE Server in bluestacks and DB himself says it's not quite there yet. I can make scripts via ce server, but enabling them always crashes. Bluestacks is the only emulator I've encountered this with. Console emulators all work fine with using instructions, so I don't know what makes android emulation different. That's beyond the scope of my question tho. Just know that I've thoroughly explored other avenues and I'm with you - I wouldn't use this method if it wasn't the only working method I've found. Was just hoping to improve on it by automating the refresh.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1528

PostPosted: Sun Mar 06, 2022 6:01 pm    Post subject: Reply with quote

Drivium wrote:
I might not have explained well. This approach is not exclusive to Bluestacks. I'm just trying to understand if there's a good way to make it keep searching for the aob automatically.


Don't always call Aob automatically.
Call aob once, (assign local to note the first found result) save it to the address list with a description and code a timer into Lua Script and signal it to read your aob code continuously.

If the value you set for it changes (the local you assigned), add something to the code.

If the above explanation helps you, I can suggest a suitable code for it.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Sun Mar 06, 2022 6:10 pm    Post subject: Reply with quote

Yes, I love that idea. How would I go about it?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4706

PostPosted: Sun Mar 06, 2022 7:08 pm    Post subject: Reply with quote

You can add a hotkey to make it easier to run.

As AylinCE said, if you can identify when the value becomes invalid, you can automatically trigger an aobscan then.

Data will usually be aligned to some amount. You can use the fast scan options to speed up scans somewhat.

Assuming the aob signature is unique, you can use that to exit a scan early. (AOBScanUnique, MemScan.IsUnique)

If you know it's going to be in a particular memory region, you can enumerate the memory regions (enumMemoryRegions) and only scan in certain regions (MemScan class). Maybe look at the memory regions' sizes and/or reuse the region the previous result was in.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1528

PostPosted: Sun Mar 06, 2022 10:07 pm    Post subject: Reply with quote

Define new replacement code for "orgValue" in Timer.

When you activate the CheckBox, the code will be ready in the address list and the timer will check if the code has changed.

If the aob code changes, "orgValue" will fix it over and over.

Disable CheckBox to turn off the timer.
To activate it again, the Address list will be cleared.

Code:

if form then form.destroy() form=nil end

form = createForm()
form.Position = poDesktopCenter
form.Popupmode = 0;
form.Width = 320
form.Height = 240

local MtvChk2 = createCheckBox(form)
MtvChk2.setPosition(50,50) MtvChk2.caption="Code deActive"

if codeTim then codeTim.Destroy() codeTim=nil end
codeTim=createTimer() codeTim.Interval=50 codeTim.Enabled=false

function getByteString(address, bytecount)
 local bytes = readBytes(address, bytecount, true)
 if bytes then
 local result = ""
 for i = 1, #bytes do
 if #result > 0 then result = result .. " " end
 result = result .. string.format("%02X", bytes[i]) end
 return result end
end

local addressList = getAddressList()
local mr1
local orgValue=""
local newValue=""

function addAddres1(adrr,adrr1)
local memRec = addressList.createMemoryRecord()
memRec.Type=8
memRec.ShowAsHex=true
memRec.Description= 'MyDescription'
memRec.Address=adrr
memRec.Value=adrr1
end


MtvChk2.OnChange=function()
local search=tostring("2E BD BB B3 ?? ?? ?? ?? C0 CC 4C 3E ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 33 33 33 40 EF EE EE 3F")
if MtvChk2.checked==true then
local aobs1=AOBScan(search)
if aobs1~=nil then
aobs2=(getByteString(stringlist_getString(aobs1,1-1), 24))
addAddres1(stringlist_getString(aobs1,1-1),aobs2)
mr1 = addressList.getMemoryRecordByDescription("MyDescription")
if mr1 then
MtvChk2.caption="Code Active"
codeTim.Enabled=true
end
end
else -- hack deactive -- address delete ..
codeTim.Enabled=false
addrCnt = addresslist_getCount(addressList)
if addrCnt>0 then
memoryrecord_delete(addresslist_getMemoryRecord(addressList,"MyDescription"))
end
MtvChk2.caption="Code deActive"
end
end

codeTim.OnTimer=function()
--your search result value:

orgValue="" --your replace aob code
newValue=mr1.Value

 if newValue~=orgValue then
  mr1.Value=orgValue
  newValue=mr1.Value
 end
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Mon Mar 07, 2022 9:45 am    Post subject: Reply with quote

I'm not sure how to implement this. Does this replace my existing cheat or go with it?

I put your script in Table > Show Cheat Table Lua Script. Then executed it. I activated the box in the form that came up. I'm not clear what's supposed to happen or how to prep my existing code to work with this.

Edit: Just noticed it added a cheat with my aob to the list. Not sure what to do with that.
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