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 


How to write in specific bit?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 202

PostPosted: Fri Feb 23, 2018 2:19 am    Post subject: How to write in specific bit? Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Fri Feb 23, 2018 2:28 am    Post subject: This post has 2 review(s) Reply with quote

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
View user's profile Send private message MSN Messenger
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 202

PostPosted: Sat Feb 24, 2018 10:11 am    Post subject: Reply with quote

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
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