|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Razi Expert Cheater Reputation: 1
Joined: 17 Jan 2018 Posts: 202
|
Posted: Fri Feb 23, 2018 2:19 am Post subject: How to write in specific bit? |
|
|
I want to write to a specific bit, when the CECheckBox1 is On, then write to a third bit, value = 1 in the address 0x009E868D. And when the CECheckBox1 is Off, then write to a third bit, value = 0 in the address 0x009E868D. Can you tell me how to do this? |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25287 Location: The netherlands
|
Posted: Fri Feb 23, 2018 2:28 am Post subject: |
|
|
Code: |
function setbit(address, bitnr, state)
if (bitnr>7) then error('setbit only works for byte sizes. rewrite this for bigger values') end
b=readBytes(address,1)
if (state==1) then
b=b | (1<<bitnr)
else
b=b & ~(1<<bitnr)
end
writeBytes(address,b)
end
|
bitnumber counts from 0 _________________
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 |
|
|
Razi Expert Cheater Reputation: 1
Joined: 17 Jan 2018 Posts: 202
|
Posted: Sat Feb 24, 2018 10:11 am Post subject: |
|
|
Thank you for answer.
Then to change bits in the 4 bytes:
Code: | function setbit(address, bitnr, state)
if (bitnr>31) then error('setbit works with 4 bytes sizes.') end
b=readInteger(address)
if (state==1) then
b=b | (1<<bitnr)
else
b=b & ~(1<<bitnr)
end
writeInteger(address,b)
end
--to call this function
UDF1.CECheckBox1.OnClick = function(sender)
if UDF1.CECheckBox1.Checked == true then
setbit('009E868C', 2, 1) -- where 2 - 3rd bit. -- where '009E868C' - address.
elseif UDF1.CECheckBox1.Checked == false then
setbit('009E868C', 2, 0)
end
end |
or to read 3rd bit:
Code: | a = readInteger('address')
local bit3 = ((a >> 2) & 0x01)
if bit3 == 1 then
UDF1.CECheckBox1.Checked = true
elseif bit3 == 0 then
UDF1.CECheckBox1.Checked = false
end |
or to write in 3rd bit:
Code: | UDF1.CECheckBox1.OnClick = function(sender)
if UDF1.CECheckBox1.Checked == true then
writeInteger('address', a | (1<<2)) -- where a = readInteger('address')
elseif UDF1.CECheckBox1.Checked == false then
writeInteger('address', a & ~(1<<2))
end
end |
|
|
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
|
|