Jump to content

Photo

Question to Changing Item Usability via WRITE_BYTE


6 replies to this topic

#1 jastey

jastey
  • Gibberlings
  • 7513 posts
  • Gender:Female

Posted 08 June 2018 - 02:10 AM

In Jarl's Tweak Pack, one of the components offers to make Jaheira's alignment Neutral Good.

 

This comes along with it:

 

COPY_EXISTING ~misc5x.itm~ ~override~
READ_BYTE 0x1e "use1"
READ_BYTE 0x21 "use2"
WRITE_BYTE 0x1e (("%use1%" BOR 0b00001000) BAND 0b11111011)
WRITE_BYTE 0x21 ("%use2%" BOR 0b10000000)
BUT_ONLY_IF_IT_CHANGES

 

"Misc5X.itm" is the Harper's Pin which originally is only usable by True Neutral Fighter-Druids.

 

The above code changes this to Neutal Good Fighter-Druids, which is great. My questions:

 

-is the above code the optimum if it comes to tp2 coding or is there a potential compatibility issue with other possible tweaks? What I mean is, what exactly does the code do, does it only change the True Neutral to Neutral Good or does it overwrite something else, meaning would this still work if another tweak changes Jaheira's kit or even class including the appropriate usability flags of the Harper Pin, too?

 

EDIT: I am aware that this is for BGII/BGT only, as the item is resctricted to Jaheira only for BGII:EE via some opcode not available for BGII: Am I assuming correctly that this resctriction in BGII:EE is independent on the NPC's alignment and thus not affected by alignment tweaks?


Edited by jastey, 08 June 2018 - 02:14 AM.


#2 argent77

argent77
  • Modders
  • 823 posts
  • Gender:Male

Posted 08 June 2018 - 04:47 AM

That two initial read operations are not strictly needed, because WeiDU automatically reads the content into the variable THIS for each write operation.

The logic of the write operations looks correct though. With the hint from above and the use of some helpful WeiDU constants it would result in:

COPY_EXISTING ~misc5x.itm~ ~override~
  WRITE_BYTE 0x1e ((THIS BOR BIT3) BAND BNOT BIT2)
  WRITE_BYTE 0x21 (THIS BOR BIT7)
 BUT_ONLY

Or combined into a single write operation:

COPY_EXISTING ~misc5x.itm~ ~override~
  WRITE_LONG 0x1e ((THIS BOR BIT3 BOR BIT31) BAND BNOT BIT2)
 BUT_ONLY

You can optionally replace BOR by |, BAND by & and BNOT by ` (back quote sign) to reduce code length.

Btw, the code makes "...Neutral" and "Half-Orc" unusable and "Good" usable. And yes, NPC-specific restrictions in EE games are only tied to creature (script) name. Alignment, race, etc. doesn't matter.



#3 jastey

jastey
  • Gibberlings
  • 7513 posts
  • Gender:Female

Posted 08 June 2018 - 06:12 AM

Thank you! That was very helpful.

I wonder what the bit 31 is for, actually. As I see it,

 

COPY_EXISTING ~misc5x.itm~ ~override~
WRITE_BYTE 0x1e ((THIS BOR BIT3) BAND BNOT BIT2)
BUT_ONLY

 

would do the trick for Jaheira's alignment change to Neutral Good just fine because it's already unusable by half-orcs and that's nothing to do with an alignment change, I would say.



#4 argent77

argent77
  • Modders
  • 823 posts
  • Gender:Male

Posted 08 June 2018 - 06:20 AM

Well, unfixpacked BG2 would allow half-orcs to wear the item. So I guess it was only added as a precaution.
 



#5 jastey

jastey
  • Gibberlings
  • 7513 posts
  • Gender:Female

Posted 08 June 2018 - 07:49 AM

Ah! Thank you very much for the info. Indeed I am working with a BGT with BG2Fixpack applied.



#6 Mike1072

Mike1072
  • Gibberling Poobah
  • 2521 posts
  • Gender:Male
  • Location:Canada

Posted 08 June 2018 - 02:48 PM

EDIT: I am aware that this is for BGII/BGT only, as the item is resctricted to Jaheira only for BGII:EE via some opcode not available for BGII: Am I assuming correctly that this resctriction in BGII:EE is independent on the NPC's alignment and thus not affected by alignment tweaks?


According to some testing done by earlier me, restrictions to specific characters via the EE opcode are cumulative with restrictions in the item header.  For example, if the item was restricted to Jaheira, but something made it unusable by fighter/druids, she wouldn't be able to use it.



#7 jastey

jastey
  • Gibberlings
  • 7513 posts
  • Gender:Female

Posted 09 June 2018 - 12:21 AM

That's good to know! Thanks.





Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users