 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Redouane Master Cheater
Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Sat Feb 14, 2015 1:01 pm Post subject: Problem with Bytes |
|
|
This is possibly a bug in CE:
(Found it while making a cheat)
I allocated some memory on a process,at address 0x0x00a70000,now this script gives odd results:
| Code: | a = 0x00a70000 -- address of the allocated block
b = a + 0x20; -- 0x20 bytes after, b = 0xa70020
writeBytes(a,0x90,0x80,0x70,0x60) -- now a contains the bytes 90 80 70 60
writeBytes(b,0x5,0x10,0x15,0x20) -- now b contains 05 10 15 20
writeBytes(b,readBytes(a,4),0x50,0x40)
--[[ Now,I was expecting b to contain the bytes 90 80 70 60 50 40 but instead,it contains 90 50 40 20
]]-- |
Is it a bug?
[EDIT] looks like the thing is in Lua,tried with Lua.exe,and functions that return more than one value have this issue
|
|
| Back to top |
|
 |
BanCheese Cheater
Reputation: 0
Joined: 22 Oct 2014 Posts: 49
|
Posted: Sat Feb 14, 2015 2:10 pm Post subject: |
|
|
This is intended behavior. The "writeBytes" function takes an address and single byte parameters. Therefore, your last call to writeBytes is only writing the first byte of a, which is 0x90.
_________________
A guy who likes memory hacking. |
|
| Back to top |
|
 |
Redouane Master Cheater
Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Sat Feb 14, 2015 2:26 pm Post subject: |
|
|
| BanCheese wrote: | | This is intended behavior. The "writeBytes" function takes an address and single byte parameters. Therefore, your last call to writeBytes is only writing the first byte of a, which is 0x90. |
No,the syntax is :
| Code: | writeBytes(address, x,x,x,x,...) : Write the given bytes to the given address from a table
or
writeBytes(address, table) : Write the given bytes to the given address from a table |
Try remplacing the line :
| Code: | | writeBytes(b,readBytes(a,4),0x50,0x40) |
In my code with :
| Code: | | writeBytes(b,0x90,0x80,0x70,0x60,0x50,0x40) |
And see the result.
|
|
| Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sat Feb 14, 2015 7:26 pm Post subject: |
|
|
As mentioned above, syntax is:
writeBytes(address, x,x,x,x,...)
Or
writeBytes(address, table)
Both return the number of bytes written.
Also. There's no
writeBytes(address, table, x, x, x, x, ...)
and there's no;
writeBytes(address, x, x, table, x, x, ...)
So, even using readBytes(a,4,true) won't solve this.
Reminder:
readBytes(address,bytecount,true) -- function returns table
readBytes(address,bytecount) \
> multiple results function, bytecount integer values
readBytes(address,bytecount,false) /
readBytes(address) -- returns one byte (integer)
But, this is Lua, we can fix that ourselves. Here, use this script at the beginning:
| Code: | if OrigWriteBytes==nil then OrigWriteBytes=writeBytes end
function writeBytes(address, ...)
local bytetable={}
for _,v in ipairs{...} do
if type(v)=='table' then
for _,w in ipairs(v) do bytetable[#bytetable+1]=w end
else
bytetable[#bytetable+1]=v
end
end
return OrigWriteBytes(address,bytetable)
end |
Then all above is possible, for example:
| Code: | writeBytes(a,0x90,0x80,0x70,0x60)
writeBytes(b, 0x10, readBytes(a,4,true), 0x50, 0x40) |
will write 0x10 ,0x90, 0x80, 0x70, 0x60, 0x50, 0x40 at b address.
| rnib wrote: | | and functions that return more than one value have this issue |
This is how Lua works.
In Lua 5.2 this code:
| Code: | function test(...)
return ...
end
function multiplereturn(val)
return val,val+1,val+2
end
print( test('one','two','three') )
print( test('one', unpack({'two','three'}), 'four') )
print( test(1,2,3,multiplereturn(4),7,8) ) |
Will print:
one two three
one two four
1 2 3 4 7 8
Instead of:
one two three
one two three four
1 2 3 4 5 6 7 8
So, calling function with multiple results, as argument inside another function call, doesn't work as you think.
This: | Code: | | test(1,2,3,multiplereturn(4),7,8) |
is the same as this one:
| Code: | local tmp = multiplereturn(4) -- tmp=4, and 5 and 6 is discarded
test(1,2,3,tmp,7,8) |
This is how Lua works.
_________________
|
|
| 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
|
|