View previous topic :: View next topic |
Author |
Message |
kucingkembar Advanced Cheater Reputation: 0
Joined: 08 Oct 2020 Posts: 71
|
Posted: Sun Nov 01, 2020 2:28 am Post subject: Count true + true + true = 3 |
|
|
i like to count bit value in cheat engine
Code: |
Count =
readInteger("Example.exe+ABC123") & (1 << 0) +
readInteger("Example.exe+ABC124") & (1 << 0) +
readInteger("Example.exe+ABC125") & (1 << 0)
Print(Count)
|
and answer should be 3
how to do that? |
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 942
|
Posted: Sun Nov 01, 2020 3:32 am Post subject: |
|
|
May read https://en.wikipedia.org/wiki/Hamming_weight , or search popcount
tl;dr
Lua in wiki's last 64 bit popcount:
Code: | function popcount64(x)
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
return (x * 0x0101010101010101) >> 56
end
--test
for i=0,15 do
local j = (i<<16) | i -- x2
local k = (i<<50) | (i<<40) | (i<<30) | (i<<20) | (i<<10) | i -- x6
print(i,popcount64(i),popcount64(j),popcount64(k))
end
--- ie.
local x = readInteger("Example.exe+ABC123")
print(x and popcount64(x) or 'not readable')
|
_________________
- Retarded. |
|
Back to top |
|
|
kucingkembar Advanced Cheater Reputation: 0
Joined: 08 Oct 2020 Posts: 71
|
Posted: Sun Nov 01, 2020 3:51 am Post subject: |
|
|
thanks for the reply,
to be honest I do not understand any Lua script you write (sorry),
anyway this is the substitute code I write
Code: |
Count = 0
if (readInteger("example.exe+123ABC") & (1 << 0) == 1) then
Count = Count + 1
end
if (readInteger("example.exe+123ABD") & (1 << 0) == 1) then
Count = Count + 1
end
if (readInteger("example.exe+123ABE") & (1 << 0) == 1) then
Count = Count + 1
end
Print(Count)
|
it seems the code I write quite long and not so efficient (it using 3 "IF")
and I just want to make it a single line(like the code in my post)
thanks again for reply, sorry if i rude
EDIT : maybe the better question : how to convert Bit data type to numeral data type like byte or int |
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 942
|
Posted: Sun Nov 01, 2020 5:47 am Post subject: |
|
|
Look like you only need count the 1st bit of 3 consecutive bytes, may be this...
Code: |
-- common memory read
local value = readInteger("example.exe+123ABc")-- read 4 bytes, no need to read each one by one
-- apply popcount64 with values masked by 0x010101
local count = value and popcount64(value & 0x010101)
-- or
-- count individual bit by shift and masks x3
local count = value and (value & 1) + ((value>>8) & 1) +((value>>16) & 1)
|
btw, (1 << 0) is just 1. _________________
- Retarded. |
|
Back to top |
|
|
kucingkembar Advanced Cheater Reputation: 0
Joined: 08 Oct 2020 Posts: 71
|
Posted: Sun Nov 01, 2020 6:07 am Post subject: |
|
|
thank you for the answer,
but I too stupid to understand what your code does,
I think i will stick with that "long and not so efficient" for now,
thank you again, and sorry for the inconvenient |
|
Back to top |
|
|
|