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 


Search for Array and substitute following bytes
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
toebab
Newbie cheater
Reputation: 0

Joined: 23 Oct 2013
Posts: 10

PostPosted: Wed Oct 23, 2013 12:07 pm    Post subject: Search for Array and substitute following bytes Reply with quote

Hi,
im automating for a game. This is what needs to be done;
Search for an array of bytes. It will result with a bunch of adresses.
Based on a user selection, it should pick one specific address

Now comes the part where im lost.
The script would have to change some bytes in a an array of bytes, AFTER the found result.
Is this technically possible with scripting?

Im good in VB and im experienced in reading other language code, but I have no idea how to fix the changing bytes (like I now have to do it manually)

Any help would be greatly appreciated
Rob
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Wed Oct 23, 2013 12:19 pm    Post subject: Reply with quote

Ask yourself how you do it and then just write a script to do that

here's a start:
Code:

aobresult=AOBScan("90 90 90")
if (aobresult~=nil) then
  print("Results found: "..aobresult.Count)
  if aobresult.Count>0 then
    print("First result="..aobresult[0])
  end

  if aobresult.Count>1 then
    print("Second result="..aobresult[1])
  end

  if aobresult.Count>2 then
    print("Third result="..aobresult[2])
  end

  --....imagine what might be here....


  --when done doping "things"
  aobresult.destroy()
  aobresult=nil
else
  print("No results found")
end


now just pick the correct address based on whatever ruleset you use yourself, and then modify the bytes

Either using autoAssemble() scripts, or just writeBytes(address,{bytes})
(For code you might want to call fullAccess(address, aobsize) first )

_________________
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


Last edited by Dark Byte on Wed Oct 30, 2013 3:47 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
toebab
Newbie cheater
Reputation: 0

Joined: 23 Oct 2013
Posts: 10

PostPosted: Wed Oct 23, 2013 12:38 pm    Post subject: Reply with quote

Thanx! youve helped me 3 steps ahead !
Back to top
View user's profile Send private message
toebab
Newbie cheater
Reputation: 0

Joined: 23 Oct 2013
Posts: 10

PostPosted: Mon Oct 28, 2013 2:46 pm    Post subject: CE Script not updating Reply with quote

Hi,
I have been working on getting the script to work but for some reason, it doesnt seem to update.
For example, I run the script you posted and it gives me the 4 lines of output. (just the way I want it)
Now I change the text Third Output into 3rd Output and run it again and it still gives me the text Third Output
Any idea what I am doing wrong?



Screenshot_1.png
 Description:
 Filesize:  58.7 KB
 Viewed:  23034 Time(s)

Screenshot_1.png


Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Mon Oct 28, 2013 3:16 pm    Post subject: Reply with quote

don't forget to click Execute script before clicking on CEPanel1 (or whatever component/eventmethod links to CEPanel1Click)
_________________
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: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Mon Oct 28, 2013 4:22 pm    Post subject: Reply with quote

I'm assuming that you're doing something like this..
Code:

text = readString(address,length);
writeString(address, 'your text');

so in this case, it'd return the text that was before you wrote to it.
This how it should be.
Code:

writeString(address, 'your text');
text = readString(address,length);

_________________
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
toebab
Newbie cheater
Reputation: 0

Joined: 23 Oct 2013
Posts: 10

PostPosted: Mon Oct 28, 2013 6:54 pm    Post subject: correct Reply with quote

Yep, daspamer.
Thats what im trying to accomplish but it goes slow since im totally new to the language.
So far I managed to havent been able to read the actual bytes. when I say readbytes(address, 64) or readstring(address, 64) it either gives me 255 from the bytes or ???? from the string but its a work in progress and I dont give up easily:-)
The thing that really slows down my trial and error is the fact that it not always updates the scipt after I change something .
This is exactly what im trying to do:
When I look at the memory browser of one of the results of the search, it shows me whats on the picture
Now, what I want to accomplish is,
I take the value of bytes 17, 18, 19 and 20 and write that onto bytes 21, 22, 23 and 24 (and some other bytes, in that same area)
I feel like such an idiot for not being able to figure it out myself but I really really appreciate your help so far!



Screenshot_1.png
 Description:
 Filesize:  20.15 KB
 Viewed:  22971 Time(s)

Screenshot_1.png


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

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Mon Oct 28, 2013 7:37 pm    Post subject: Reply with quote

The max length you can read is 255, but you can do this.
Code:
-- .. stufflocal output = ''
for i=1,WantedLength do
output = output.. readbytes(address+i, 1)
end
return output
-- .. stuff


or just do
[code]
print(readBytes(address,0xff)..readBytes(address+255,0xff)..readBytes(address+510,0xff));
-- you can set the length to hex (don't forget 0x) or as decimal

_________________
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
toebab
Newbie cheater
Reputation: 0

Joined: 23 Oct 2013
Posts: 10

PostPosted: Mon Oct 28, 2013 8:36 pm    Post subject: got it! Reply with quote

removed...

Last edited by toebab on Mon Nov 25, 2013 10:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Tue Oct 29, 2013 8:57 am    Post subject: Reply with quote

I'm not sure why C.E converts each aob and aob to decimal when reading the bytes. perhaps it's a bug?
Also don't remove the IN<1 part from DEC_HEX function, else when it will come across zero (0) it'll return nil.

Use this code.
Code:
function DEC_HEX(IN)
   if IN<=0 then
      return '0'
   end
   local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
   while IN>0 do
      I=I+1
      IN,D=math.floor(IN/B),math.mod(IN,B)+1
      OUT=string.sub(K,D,D)..OUT
   end
   return OUT
end
function CEPanel1Click(sender)
   local aobresult = AOBScan("FF FF FF FF 01 00 00 00 02 00 00 00 00 00 00 00");
   if (aobresult~=nil) then
      print("Results found: "..aobresult.Count);
      for i=0,aobresult.Count -1 do
         print(i); --> address index
         ReadBytes = readBytes(aobresult[i].."+11",4,true); --> Reads from the address[i]+11 the 4 aobs, and returns as table (true);
            for _,String in pairs(ReadBytes) do --> for each entry and entry in the table ReadBytes do..
            local Hex = DEC_HEX(String) --> converting each byte and byte that stored in the ReadBytes Table
            if Hex:len()==1 then
               Hex = '0' .. Hex --> Just incase, making the bytes 2 character length
            end
            ReadBytes[_] = '0x' .. Hex --> Making it writeable
         end
         writeBytes(aobresult[i] .. "+15", unpack(ReadBytes)); --> Google unpack lua, for more information
      end
      aobresult.destroy();--> destroys result if aobresult is not nil, and since we defined it locally, we do not need to set it back to nil;
   end
end

_________________
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
toebab
Newbie cheater
Reputation: 0

Joined: 23 Oct 2013
Posts: 10

PostPosted: Thu Oct 31, 2013 8:42 am    Post subject: Thanx! Reply with quote

Thanx Daspamer!
you helped me a lot (again!)
Back to top
View user's profile Send private message
toebab
Newbie cheater
Reputation: 0

Joined: 23 Oct 2013
Posts: 10

PostPosted: Tue Nov 19, 2013 1:04 pm    Post subject: Current Status Reply with quote

This game has adresses in predictable ranges, but I dont want to loop the search command to change all valid ranges. That would make the script to powerful (and I suspect it to be easier to detect).

The thing im working on now is adding a form with attach to the proper process and some fancy buttons to select what needs to be reset..

Is there a way to attach a created form to the script and make it an exe?
When I try to do it, it creates the trainer but the form doesnt show up.
(and since I use a form to start changing adresses, it doesnt do anything without a form)


Last edited by toebab on Mon Nov 25, 2013 10:49 pm; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Nov 19, 2013 2:16 pm    Post subject: Reply with quote

Add code to main lua script to show the form.
e.g:
Code:

formname.show()


and make it execute when the script is executed. (so outside of a function)

_________________
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: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Tue Nov 19, 2013 4:58 pm    Post subject: Reply with quote

Check my signature, I've wrote a pretty simple script but it's long one.

If you need any help with trainer feel free to contact me via skype (cheatertankionline), or PM, or this thread.

Here's example of trainer
Code:

f = createForm();
f.height = 50;
f.width = 200;
f.Caption = 'Trainer';
processb = createButton(f);
processb.top = 10;
processb.left = 50;
processb.Caption = 'Attach';
processb.onClick = function (sender) openProcess('explorer.exe'); sender.Caption = 'Attached'; sender.Enabled = false; end;
hackb = createButton(f);
hackb.top = 10;
hackb.left = 130;
hackb.Caption = 'DoStuff..';
hackb.onClick = function (sender) print('It did something...'); sender.Caption = 'DidStuff...'; end;


This should work (didn't test it, wrote it from my tablet).

_________________
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
toebab
Newbie cheater
Reputation: 0

Joined: 23 Oct 2013
Posts: 10

PostPosted: Wed Nov 20, 2013 11:37 am    Post subject: wow Reply with quote

Hi Daspamer,
Thanx so much for your help!
Since I hope others will benefit from it, it think its easiest to keep the conv in here.

The issues im having so far is, I cant find any sample code on how to create a list box, fill it with the processes, pick one value and attach to that process.
Im pretty sure its just a few lines of code, but all the examples I find attach to a fixed process name or id.

The other issue I have is, when I run the script, it causes CE to not respond till it is done doing its magic. This results in me not being able to put progressbars or such in the trainer. Is there an equivalent of the VB command DoEVents in lua? If the script could repaint objects in the form while performing the magic, I could include a current status box in it (and eliminating the regular print to debug log
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
Goto page 1, 2  Next
Page 1 of 2

 
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