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 read/write 7/9 bit value?

 
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: Sun Jun 03, 2018 1:44 am    Post subject: How to read/write 7/9 bit value? Reply with quote

How to read/write 7/9 bit value? I need to read/write 9 bit value with CEComboBox. And read/write 7 bit value (starting from second bit) with edit box.
In the game, each item in the item list is stored as a word value with the quantity, expressed as a 7-bit value, concatenated with the item's index, expressed as a 9-bit value between the range of 0-320. In Binary: QQQQQQQXXXXXXXXX Where X is the index and Q is the quantity.
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: Sun Jun 03, 2018 2:10 am    Post subject: Reply with quote

read quantity:
Code:

quantity=(wordvalue >> 9) & 0x7f


write quantity:
Code:

wordvalue=(wordvalue & 0x1ff) | (quantity << 9)


read index:
Code:

index=wordvalue & 0x1ff;


write index:
Code:

wordvalue=(wordvalue & 0xfe00) | index

_________________
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: Mon Jun 04, 2018 2:40 am    Post subject: Reply with quote

I can read index with code:
Code:
for x = 1, 20 do
    local offset = x*2-2
    cacheTable_CEEditsiteminv[x].ItemIndex = (bAnd(0xFFFF, readInteger(0x009E8ACC+offset))) & 0x1ff
    if bAnd(0xFFFF, readInteger(0x009E8ACC+offset)) == 0xFFFF then
    cacheTable_CEEditsiteminv[x].ItemIndex = 0x140
    end
end


And can read quantity with code:
Code:
for x = 1, 20 do
    local offset = x*2-2
    cacheTable_CEEditsqtyinv[x].Text = (bAnd(0xFFFF, readInteger(0x009E8ACC+offset)) >> 9) & 0x7f
end


But I can't write index with next code:
Code:
for x = 1, 20 do
cacheTable_CEEditsiteminv[x].OnSelect = function(sender)
local offset1 = x*2-2

index=(bAnd(0xFFFF, readInteger(0x009E8ACC+offset))) & 0x1ff   --I think that the error lies in these two lines
wordvalue1= (wordToByteTable(sender.ItemIndex) & 0xfe00) | index

writeBytes(0x009E8ACC+offset1, wordvalue1)
end
end


And can't write quantity with next code:
Code:
for x = 1, 20 do
  local offset = x*2-2
  local currentCEEditsqtyinv = cacheTable_CEEditsqtyinv[x]

  cacheTable_CEEditsqtyinv[x].OnKeyPress = function(sender, key)
      timer.Enabled = false
      local a = tonumber(sender.Text)
      if (a~=nil) and isKeyPressed(VK_RETURN) then

        quantity=(bAnd(0xFFFF, readInteger(0x009E8ACC+offset)) >> 9) & 0x7f   --I think that the error lies in these two lines
        wordvalue=(wordToByteTable(currentCEEditsqtyinv.Text) & 0x1ff) | (quantity << 9)

        writeBytes(0x009E8ACC + offset, wordvalue)
        timer.Enabled = true
      end
      return key
    end

end


What i'm doing wrong?
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: Mon Jun 04, 2018 3:52 am    Post subject: Reply with quote

I think wordToByteTable(sender.ItemIndex) is wrong as sender.ItemIndex is at most the number of records-1 in the list
_________________
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: Tue Jun 05, 2018 8:58 am    Post subject: Reply with quote

For newbies like me. I can write index with next code:
Code:
UDF1.CEComboBox184.OnSelect = function(sender)
quantity=((byteTableToWord(readBytes(0x009E8ACC, 2,true))) >> 9) & 0x7f
wordvalue1=((UDF1.CEComboBox184.ItemIndex) & 0x1ff) | (quantity << 9)
writeBytes(0x009E8ACC, wordToByteTable(wordvalue1))
end


And can write quantity with next code:
Code:
UDF1.CEEdit300.OnKeyPress = function(sender, key)
      timer.Enabled = false
      local a = tonumber(sender.Text)
      if (a~=nil) and isKeyPressed(VK_RETURN) then

        index=(byteTableToWord(readBytes(0x009E8ACC, 2,true))) & 0x1FF
        wordvalue=((UDF1.CEEdit300.Text) & 0x7f) << 9 | index
        writeBytes(0x009E8ACC, wordToByteTable(wordvalue))
        timer.Enabled = true
      end
      return key
    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