Author Topic: feature request: help modders deal with malformed .2da files  (Read 731 times)

Offline subtledoctor

  • Planewalker
  • *****
  • Posts: 119
This came up recently:
http://www.shsforums.net/topic/56670-big-world-setup-an-attempt-to-update-the-program/?p=596273

- Something there is messing up kitlist.2da
- Divine Remix messes up alignment.2da
- Siege of Dragonspear, unmodded, ships with a malformed xplevel.2da
- BG2EE, unmodded, ships with a malformed kitlist.2da

Yes it would be nice if we lived in a perfect world where all mods worked perfectly, but problems happen.  Question is, how can we make it easy to work around problems.  Currently, COUNT_2DA_COLS only counts the maximum number of columns; there is no way to find out what the minimum number of columns is.  And currently, if READ_2DA_ENTRY tries to read an entry from a missing column, that the whole install bombs out.  It would be nice if:

1) There was a way to detect .2da rows whose column count doesn't match COUNT_2DA_COLS, so we could skip reading those rows; or,

2) READ_2DA_ENTRY on a missing column simply populated the result with a zero or null value and moved on and let the install continue.

To make this more concrete by way of discussing the linked example, my mod needs to read the KITIDS value from a set of kits in kitlist.2da.  Several kits fail to populate that column - in fact, a kit added by the game's developers doesn't populate that column.  It would be great if I could READ_2DA_ENTRY and then simply ask PATCH_IF IS_AN_INT before trying to perform an operation on the value.  But if I'm not mistaking, reading it to even find out that it isn't an int causes the install to bomb out.  So I'm kind of at a loss.  How do I find and avoid the hole, without stepping in it?

Offline GeN1e

  • Planewalker
  • *****
  • Posts: 267
  • Gender: Male
Re: feature request: help modders deal with malformed .2da files
« Reply #1 on: August 04, 2017, 04:46:32 PM »
This ignores the Grizzly Bear row of 39 because its column count is too low:
Code: [Select]
COPY_EXISTING - kitlist.2da override
  COUNT_2DA_COLS cols
  READ_2DA_ENTRIES_NOW kits cols
  FOR (r=0;r<kits;r+=1) BEGIN
    READ_2DA_ENTRY_FORMER kits r 0 row
    READ_2DA_ENTRY_FORMER kits r 9 entry
    PATCH_PRINT ~row %row%, %entry%~
  END

Offline Wisp

  • Moderator
  • Planewalker
  • *****
  • Posts: 1082
Re: feature request: help modders deal with malformed .2da files
« Reply #2 on: August 06, 2017, 08:51:23 AM »
As I think has come up elsewhere, patches with a required column count parameter will skip all rows which have too few rows. If you do not read outside of this required column count, you will not read from rows with too few columns. GeN1e's code also uses this.

Fundamentally, 2DA handling needs a largely different approach than the current one. The off-by-one errors alone are infuriating.

Offline subtledoctor

  • Planewalker
  • *****
  • Posts: 119
Re: feature request: help modders deal with malformed .2da files
« Reply #3 on: August 06, 2017, 12:05:44 PM »
Yeah, thanks, this was a case of 'modding while tired' a.k.a. 'modding while being a parent'

 

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)?: