Hi everyone.
I'm back on this after admittedly a fairly long time.
I was wondering why exactly this code didn't work:
COPY_EXISTING_REGEXP GLOB ~.*\.cre~ ~override~
READ_LONG 0x2bc itemsoffset
READ_LONG 0x2b8 itemslot
READ_LONG 0x2c0 itemnumber
READ_SSHORT (itemslot + 0x04) shieldslot
PATCH_IF (shieldslot > 0) BEGIN
READ_ASCII ((LONG_AT 0x02bc) + %shieldslot% * 0x14) itemname
INNER_ACTION BEGIN
COPY ~%itemname%.itm~ ~override~
READ_SHORT 0x1c itemtype ELSE 0
PATCH_IF (itemtype = 12) BEGIN
SET validslot = 1
END
BUT_ONLY
END
END
ELSE BEGIN
SET validslot = 1
END
PATCH_IF (validslot = 1) BEGIN
READ_LONG 0x28 current
PATCH_PHP_EACH cd_animation_map AS old => new BEGIN
PATCH_IF (old = current) BEGIN
WRITE_LONG 0x28 new
END
END
END
BUT_ONLY
So I looked at a CRE I knew was getting patched despite wielding a weapon in their off-hand: OHBJOKER.CRE (from The Black Pits II)
0x2b8 corresponds indeed to item slots.
To get to the shield slot, I'm adding 0x04 as per the "values and expressions" tutorial from the WeiDU documentation:
Next, we’re going to read in the shield slot to make sure that it’s empty. We do this by taking the "itemslot" variable and adding 0x04 to it which we know is always going to be the shield slot. (You can verify this by looking at a creature file in NI. If you look at the offset 0x2b8 it will have the offset for item slots. If you add 0x04 to that number, it should equal the offset for the shield slot.)
However, 0x2b8 + 0x04 equals 0x2bc according to Google; a far cry from the 0x1fa0 that I can see in NI as the shield slot. How do I get to 0x04? On a related note, why do I need to read the item offset and go through all this trouble instead of reading 0x1fa0 directly? I mean, obviously that won't work or it would be all over WeiDU's documentation; I'm trying to understand the reason why it doesn't work and the reason why 0x2b8 + 0x04 should get me that slot in particular.The value at 0x2b8 is 0x1f9c.
0x1f9c + 0x04 = 0x1fa0 which is exactly the offset for shield. This offset's value for OHBJOKER.CRE is "1", indicating that the shield slot is populated.
The code that follows is less clear:
READ_ASCII ((LONG_AT 0x02bc) + %shieldslot% * 0x14) itemname
I reckon from the WeiDU documentation that items are always 0x14, but that doesn't tell me why I need to multiply (item offset + shield slot) by it. This results in
(0x1efc + 0x1fa0) = 0x3E9C * 0x14 = 0x4E430
whereas the shield slot item's offset is 0x1f10.
What am I missing?
Also, should this:
PATCH_IF (shieldslot > 0) BEGIN
be this:
PATCH_IF (shieldslot > "0") BEGIN
instead?
Does it even make a difference?