WeiDUorg / weidu

WeiDU is a program used to develop, distribute and install modifications for games based on the Infinity Engine.
http://www.weidu.org
GNU General Public License v2.0
90 stars 20 forks source link

BAND and BOR should not be broken #138

Closed 4Luke4 closed 5 years ago

4Luke4 commented 5 years ago

So, if you execute the following block

COPY_EXISTING_REGEXP    ~.+\.cre~   ~override~
PATCH_IF (%SOURCE_SIZE% > 0x2d3) BEGIN
    READ_LONG 0x010 flags
    READ_BYTE 0x234 level_1
    READ_BYTE 0x235 level_2
    READ_BYTE 0x273 class
        SET original_class_thief = BIT6
    PATCH_IF (class == 9 OR class == 13 OR class == 15) && (flags BAND original_class_thief == original_class_thief) BEGIN  // Fighter-Thief, Mage-Thief, Cleric-Thief ----> dual-classed (original class: thief)
        PATCH_IF (level_1 > 1) BEGIN
            // something...
        END
    END
END
BUT_ONLY

you'll fail to patch only dual-classed thieves (original class: Thief). For instance, you'll patch WIVEN.cre (whose set flags are BIT0, BIT24 and BIT26). I suspect BAND being broken.....

The same holds if you use BOR:

COPY_EXISTING_REGEXP    ~.+\.cre~   ~override~
PATCH_IF (%SOURCE_SIZE% > 0x2d3) BEGIN
    READ_BYTE 0x010 flags_1st_tier
    READ_BYTE 0x234 level_1
    READ_BYTE 0x235 level_2
    READ_BYTE 0x273 class
    PATCH_IF (class == 9 OR class == 13 OR class == 15) && (flags_1st_tier BOR 0b10111111 == 0b11111111) BEGIN  // Fighter-Thief, Mage-Thief, Cleric-Thief ----> dual-classed (original class: thief)
        PATCH_IF (level_1 > 1) BEGIN
            // something...
        END
    END
END
BUT_ONLY
FredrikLindgren commented 5 years ago

You are getting the operator precedence wrong. You need parentheses around the BAND/BOR expression: ((flags BAND original_class_thief) == original_class_thief)

4Luke4 commented 5 years ago

You are getting the operator precedence wrong. You need parentheses around the BAND/BOR expression: ((flags BAND original_class_thief) == original_class_thief)

Yes, you're right. Shouldn't WeiDU throw some sort of warning in such cases?

FredrikLindgren commented 5 years ago

This is equivalent to 2 * 4 + 2 = 12. If you expect the result to be 12, you need parentheses around the addition, because it has lower precedence than multiplication. There's no way for WeiDU to know whether 10 or 12 is the result you expect. But I can agree the precedence order is unintuitive.

4Luke4 commented 5 years ago

This is equivalent to 2 * 4 + 2 = 12. If you expect the result to be 12, you need parentheses around the addition, because it has lower precedence than multiplication. There's no way for WeiDU to know whether 10 or 12 is the result you expect. But I can agree the precedence order is unintuitive.

Is this related to the difference between Regular Grammars and CF Grammars (i.e., rigid linear structure vs. tree-like structure)?

FredrikLindgren commented 5 years ago

I wouldn't think so. The precedence order seems to be a holdover from when C was designed. TP2 kind of just went along with it, I suppose.

https://stackoverflow.com/questions/4685072/operator-precedence-bitwise-lower-than