Author Topic: 171/172 bug with IF clauses?  (Read 1651 times)

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 859
  • Dreaming of a red Xmas
    • The Gibberlings Three
171/172 bug with IF clauses?
« on: January 24, 2005, 06:59:53 AM »
With 169, I added IF ~ITM~ or IF ~CRE~ to my REGEXP patches to exclude zero-byte files as suggested here. Worked like a charm with 169, however with 171 and 172 I'm getting errors. This is what I'm trying with:

Code: [Select]
PRINT @1
COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~ // looking for scrolls
  READ_SHORT  0x1C "type"
  PATCH_IF ("%type%" = 11) BEGIN // scrolls
    WRITE_SHORT 0x38 9999
  END
  IF ~ITM~
  BUT_ONLY_IF_IT_CHANGES

It seems IF ~ITM~ is not guarding against 0-byte file copies under 171 or 172. IPLOT01K.itm is a zero-byte item that's included in one of the game biffs; this is the error message when executing the code above:

Code: [Select]
ERROR: illegal 2-byte read from offset 28 of 0-byte file IPLOT01K.ITM
Stopping installation because of error.

ERROR Installing [Unlimited Potion Stacking], rolling back to previous state
[Tutu_Tweaks/backup/231/UNSETSTR.231] SET_STRING uninstall info not found
[Tutu_Tweaks/backup/231/UNINSTALL.231] loaded, 86 bytes
Will uninstall   4 files for [SETUP-TUTU_TWEAKS.TP2] component 231.
  Deleting [override/C!Tutu03.xxx] (to restore original game condition)
  Deleting [override/BAZPLO04.ITM] (to restore original game condition)
  Restoring backed-up [Tutu_Tweaks/backup/231/BAZPLO07.ITM]
[Tutu_Tweaks/backup/231/BAZPLO07.ITM] loaded, 114 bytes
  Restoring backed-up [Tutu_Tweaks/backup/231/BTEST1.ITM]
[Tutu_Tweaks/backup/231/BTEST1.ITM] loaded, 514 bytes
Uninstalled      4 files for [SETUP-TUTU_TWEAKS.TP2] component 231.

I'm not sure if it'll help or not, but items listed under ALLOW_MISSING are fine with the IF ~ITM~ predicate. For example, this works fine even though a number of items listed here are not present but included under ALLOW_MISSING:

Code: [Select]
COPY_EXISTING ~_CHAN04.ITM~  ~override~
              ~_CHAN05.ITM~  ~override~
              ~_ICHAN04.ITM~ ~override~
              ~BAND01.ITM~   ~override~
              ~BAND02.ITM~   ~override~
              ~BAND03.ITM~   ~override~
              ~BAND04.ITM~   ~override~
              ~CHAN04.ITM~   ~override~
              ~CHAN05.ITM~   ~override~
              ~CHAN18.ITM~   ~override~
              ~ICHAN04.ITM~  ~override~
              ~J#SPLI06.ITM~ ~override~
              ~VISCHAN2.ITM~ ~override~
  WRITE_SHORT 0x1C 207
  IF ~ITM~

I can re-work these using PATCH_IF FILE_SIZE checks, but I wanted to report this in case this is unintended behavior.
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: 171/172 bug with IF clauses?
« Reply #1 on: January 24, 2005, 03:28:09 PM »
Yeah, I'm not sure what WeiDU was doing before (well, apparently reading off the end of an array!). After I added that explicit bounds check I ran into the same problem Ease's infinite stacking. Here's what I have:

Code: [Select]
COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~
  PATCH_IF SOURCE_SIZE > 0x70 THEN BEGIN
    READ_SHORT  0x1C "type"
    READ_SHORT  0x38 "max"
    READ_SHORT  0x68 "max_abil"
    READ_SHORT  0x70 "max_fx"
    WHILE (("%type%" = 9)     // potions
        OR ("%type%" = 11) // scrolls
        OR (("%max%" > 1) AND (("%type%" = 5) OR ("%type%" = 14) OR
            ("%type%" = 31) OR ("%type%" = 24) OR ("%type%" = 25) OR
            ("%type%" = 16))) // ammo
        OR ((("%max_abil%" = 0) AND ("%max_fx%" = 0)) AND
          (("%type%" = 1) OR ("%type%" = 34) OR ("%type%" = 33) OR ("%type%" = 10)))) // jewelry
    BEGIN
      WRITE_SHORT 0x38 9999
      SET "type" = 100
    END
  END
  BUT_ONLY_IF_IT_CHANGES

The "problem" isn't with IF ~ITM~, it's with the READ_SHORT (which is evaluated first).

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 859
  • Dreaming of a red Xmas
    • The Gibberlings Three
Re: 171/172 bug with IF clauses?
« Reply #2 on: January 24, 2005, 03:30:30 PM »
I'll start the code switchover then. Thanks Wes.
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: 171/172 bug with IF clauses?
« Reply #3 on: January 24, 2005, 03:41:45 PM »
It occurs to me that there is no safe way to use IF_EVAL (or whatnot) because you can't count on the reads working. You might legitimately want to do this:

Code: [Select]
COPY_REGEXP "*.ITM" "override"
  READ_SHORT TYPE_OFFSET type
  // do some work
  IF_EVAL "type" = SCROLL_TYPE

But you can't. You can rework it with BUT_ONLY_IF_IT_CHANGES and PATCH_IF, but why not take this as an excuse to add more feature bloat?

We now introduce:

READ_SHORT "offsetExp" "variable" ELSE "errorValueExp"

It's just like READ_SHORT, but if the offsetExp is out of bounds no error is printed, the execution does not abort, and "variable" is assigned "errorValueExp".

Coming up next: WeiDU exception handling. Grr.

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: 171/172 bug with IF clauses?
« Reply #4 on: January 24, 2005, 03:48:34 PM »
Coming up next: WeiDU exception handling. Grr.
Ooh, I'm all giddy! All sorts of bad things start happening when you start doing things the "proper" way. There's already one error in logic pointed out by bounds-checking (read, then test, vs. test, then read); now we'll see what else comes crashing down!

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 859
  • Dreaming of a red Xmas
    • The Gibberlings Three
Re: 171/172 bug with IF clauses?
« Reply #5 on: January 24, 2005, 03:56:24 PM »
Isn't IF_EVAL already on the long list of Weimer-disapproved WeiDU syntax? ;)
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline weimer

  • Moderator
  • Planewalker
  • *****
  • Posts: 2222
  • Gender: Male
    • WeiDU and Weimer Mods
Re: 171/172 bug with IF clauses?
« Reply #6 on: January 24, 2005, 04:47:23 PM »
If you use only Weimer-approved syntax you're left with just"BEGIN" at this point. :-)

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: