Jump to content

Need a smarter way to check when patching gtime.ids.


Recommended Posts

Posted

BG1NPC patches this for Ajantis Romance:

APPEND ~gtimes.ids~ ~3600 AJROM_TIMER~ UNLESS ~AJROM_TIMER~

Sir Ajantis for BGII patches this:

APPEND ~gtimes.ids~ ~3600 C#AJROM_TIMER~

If Ajantis BGII is installed before the BG1 romance, patching the gtime.ids fails because it detects "AJROM_TIMER" - which is nonsense of course.

How would I make the check so it does what it's supposed to without giving a false positive if the name snippet is detected?

Posted

Slightly overkill, but EEex uses something like this:

DEFINE_ACTION_FUNCTION B3_ESCAPE_STRING
    STR_VAR
        str = ~~
    RET
        escaped_str
BEGIN
    ACTION_DEFINE_ASSOCIATIVE_ARRAY to_escape BEGIN ~$~ => 1 ~^~ => 1 ~.~ => 1 ~*~ => 1 ~+~ => 1 ~?~ => 1 ~[~ => 1 ~]~ => 1 ~\~ => 1 END
    OUTER_PATCH_SAVE escaped_str ~%str%~ BEGIN
        limit = BUFFER_LENGTH
        FOR (i = 0; i < limit; ++i) BEGIN
            READ_ASCII i character (1)
            PATCH_IF VARIABLE_IS_SET EVAL ~to_escape_%character%~ BEGIN
                INSERT_BYTES i 1
                WRITE_ASCII i ~\~
                ++i
                ++limit
            END
        END
    END
END

DEFINE_ACTION_FUNCTION B3_APPEND_UNIQUE_IDS
    STR_VAR
        file_name = ~~
        column_one = ~~
        column_two = ~~
BEGIN
    LAF B3_ESCAPE_STRING STR_VAR str = EVAL ~%column_one%~ RET column_one_escaped = escaped_str END
    LAF B3_ESCAPE_STRING STR_VAR str = EVAL ~%column_two%~ RET column_two_escaped = escaped_str END
    APPEND ~%file_name%.IDS~ ~%column_one% %column_two%~ UNLESS ~^[ %TAB%]*%column_one_escaped%[ %TAB%]+%column_two_escaped%[ %TAB%]*%MNL%*$~
END

This appends an entry only if there isn't an exact match already present in the file, (barring whitespace). Used like:

LAF B3_APPEND_UNIQUE_IDS STR_VAR file_name = ~GTIMES~ column_one = ~3600~ column_two = ~AJROM_TIMER~ END
LAF B3_APPEND_UNIQUE_IDS STR_VAR file_name = ~GTIMES~ column_one = ~3600~ column_two = ~C#AJROM_TIMER~ END

(I started writing this before argent commented so I'm still posting it🤷‍♂️)

Posted

Or you could just set the timer to a variable, use that in scripts/dialogue, compile with EVALUATE_BUFFER, and avoid patching gtimes altogether.

Posted
1 hour ago, Bubb said:

Slightly overkill, but EEex uses something like this

I'll be blunt: Is what @argent77 posted less save to use or would you strongly recommend using your EEx approach?

1 hour ago, CamDawg said:

you could just set the timer to a variable, use that in scripts/dialogue, compile with EVALUATE_BUFFER, and avoid patching gtimes altogether.

For BG1NPC that would be possible, but I'd have to replace all romance timer for all romances in all baf- and d-files, and I'll go the easiest way.

Posted (edited)
1 hour ago, jastey said:

I'll be blunt: Is what @argent77 posted less save to use or would you strongly recommend using your EEx approach?

For this specific case argent's suggestion is more elegant. My solution is more generalized -- it should work for all symbol names and should continue to function even if a mod decided to go crazy with whitespace.

Edit: Argent's solution also needs to be tweaked slightly:

APPEND ~gtimes.ids~ ~3600 AJROM_TIMER~ UNLESS ~[ %TAB%]AJROM_TIMER%MNL%*$~

Without that %MNL%* WeiDU doesn't match the EOL anchor when Windows-style newlines are being used, (a source of much agony in the Discord).

Edited by Bubb
Posted

Unless I'm missing something, you could avoid regexp entirely and just do

ACTION_IF IDS_OF_SYMBOL (gtimes AJROM_TIMER) <0 
BEGIN
     APPEND gtimes.ids "3600 AJROM_TIMER"
END
     
                                         
                                        

Similarly, I think Bubb's function could just be coded as 

DEFINE_ACTION_FUNCTION B3_APPEND_UNIQUE_IDS
	INT_VAR column_one=0
		file_name=~~
		column_two=~~
BEGIN
	ACTION_IF !(IDS_OF_SYMBOL ("%file_name%" "%column_two%")=column_one) BEGIN
		APPEND "%file_name%.ids" "%column_one% %column_two%"
	END
END

 

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...