Callirgos Posted May 29, 2013 Share Posted May 29, 2013 Hi. I'm trying to set the flag on an item to magical. I'm pretty comfortable patching other things like weight, cost, and abilities, but I can't find an example for the flags 00HELMBH 00HFHMBH do not have the "magical" flags set for them Link to comment
Mike1072 Posted May 29, 2013 Share Posted May 29, 2013 The item flags are a 4-byte bitfield at offset 0x18 in the file. The IESDP lists which bits corresponds to which flags here. In the table, Byte 1 is the byte at 0x18, Byte 2 is the byte at 0x19, Byte 3 is the byte at 0x1a, and Byte 4 is the byte at 0x1b. The magical flag is bit 6 of Byte 1, so we only need to worry about that byte. What we want to do is read the byte at 0x18 and set bit 6 to true (1) while leaving its other bits as they are. This is best accomplished using a bitwise operation. A bitwise OR can be used to set specific bits to true (1), while a bitwise AND can be used to set specific bits to false (0). To set bit 6 to true, we will perform a bitwise OR operation using the binary value 01000000 (bits are numbered from the right side starting at 0). This will set bit 6 to 1 and not change any other bits. Using WeiDU TP2 code, we can read the byte, change a single bit, and write the byte using separate commands like this: READ_BYTE 0x18 flags1 // read first byte of flags SET flags1 = flags1 | 0b01000000 // set bit 6 (magical flag) to true WRITE_BYTE 0x18 flags1 // write updated value to file Or we can condense those steps into a single line of code: WRITE_BYTE 0x18 (THIS | 0b01000000) // set magical flag to true In WeiDU TP2 code, THIS is a substitute for the current value in the file, | is the bitwise OR operator, and 0b01000000 is the binary value 01000000. Link to comment
Callirgos Posted May 29, 2013 Author Share Posted May 29, 2013 Thank you for this great explanation! Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.