Jump to content


Photo

Fixing 2da


  • Please log in to reply
3 replies to this topic

#1 Mad Mate

Mad Mate
  • Member
  • 191 posts

Posted 21 September 2014 - 11:23 AM

Hi!

I would like some help from experienced modder. I want to fix some mods and to learn to code in the process, so I can make some of my own.

And I stumbled on iiKeynames mod that makes 2da file from door names, keys and areas. Code looks like this:

 

INNER_ACTION BEGIN
                COPY_EXISTING ~iiKeyDoors.2da~ ~override~
                  APPEND ~iiKeyDoors.2da~ ~%door_name% ii_%key_item% %area_resref%~  // door, item, area
              END

 

But problem is that 2 areas in BG2 have space in door name (Door Room, Door Dragons Lair), so later when mod tries to append script to areas:

 

COPY_EXISTING ~iiKeyDoors.2da~ ~override~
    COUNT_2DA_ROWS ~1~ "Tokenrows"
    FOR (Tokenindex = 1; Tokenindex < Tokenrows; Tokenindex = Tokenindex + 1) BEGIN
      READ_2DA_ENTRY "%Tokenindex%" 0 3 "door"
      READ_2DA_ENTRY "%Tokenindex%" 1 3 "variable"
      READ_2DA_ENTRY "%Tokenindex%" 2 3 "area"

it wrongly detect space in door name as next column.

What to change in this code?

Thanks in advance!


Edited by Mad Mate, 21 September 2014 - 11:23 AM.


#2 The Imp

The Imp

    Not good, see EVIL is better. You'll LIVE.

  • Member
  • 5148 posts

Posted 21 September 2014 - 03:29 PM

You are not actually reading the door_name on those rows, so they won't need a fix, but somewhere else...
Or you could assume that the regular BG2 game has those and go around them by fixing it from the beginning and skip the steps on those .are's. Again that is elsewhere...

The faulty code is here:


COPY_EXISTING_REGEXP GLOB ~^\([^Xx]\|[Xx][^Rr]\|[Xx][Rr][^2]\).*\.are$~ ~override~
  PATCH_IF (SOURCE_SIZE > 0x11b) THEN BEGIN // protects against invalid files
    READ_LONG 0xA4 "door_count"
    READ_LONG 0xA8 "door_offset"
    SPRINT %area_resref% "%SOURCE_RES%"

    FOR (index = 0; index < %door_count% - 1; index = index + 1) BEGIN
      READ_ASCII (%door_offset% + (index * 200) + 0) %door_name%
      READ_LONG (%door_offset% + (index * 200) + 40) %flags%

...

Will have to look at it more intensely some other time...


Edited by The Imp, 21 September 2014 - 03:30 PM.

Yep, Jarno Mikkola. my Mega Mod FAQ. Use of the BWS, and how to use it(scroll down that post a bit). 
OK, desert dweller, welcome to the sanity, you are free to search for the limit, it's out there, we drew it in the sand. Ouh, actually it was still snow then.. but anyways.


#3 Mad Mate

Mad Mate
  • Member
  • 191 posts

Posted 21 September 2014 - 04:07 PM

Thank you, Imp for answering!

I'm really a noob in coding, but I'm trying to learn.

So, problem is in code that is reading door_name from game. I thought that problem is in 2da file that is created.

Mod processes all areas OK, except AR0405 and AR1401 that have doornames with spaces.

Do you think that spaces should be converted to underline in 2da?



#4 Wisp

Wisp
  • Modder
  • 1353 posts

Posted 27 September 2014 - 03:30 AM

The conventional way around this issue is to substitute space for some other symbol (not otherwise found in strings, e.g., #) and then substitute back to space before you write the string to a non-2DA file. You can use INNER_PATCH_SAVE and REPLACE_TEXTUALLY for this.