Jump to content

append text in a patch?


Recommended Posts

Posted

I want to add some text to various class and/or kit descriptions. (I'd rather  not overwrite the whole description, because the mod is not traified.)  So I do something like this:

COPY_EXISTING ~clastext.2da~ ~override~
    COUNT_2DA_COLS cols
    COUNT_2DA_ROWS cols rows
    READ_2DA_ENTRY 1 4 cols berserker_desc
BUT_ONLY

ACTION_GET_STRREF %berserker_desc% berserker_description
OUTER_INNER_PATCH_SAVE %berserker_description% new_berserker_description
  ...?
END

How do I simply  add text to the end of that string?

I feel like I am forgetting something I should have learned in Remedial Weidu for Beginners...

Posted (edited)

Try this:

ACTION_GET_STRREF berserker_desc "berserker_description"
OUTER_PATCH_SAVE "new_berserker_description" "%berserker_description%" BEGIN
  SET offset = BUFFER_LENGTH

  // If text is stored in the string variable "my_text"
  SET text_len = STRING_LENGTH "%my_text%"
  INSERT_BYTES offset text_len
  WRITE_ASCIIE offset "%my_text%" (text_len)

  // If text is stored in a file
  SET text_len = SIZE_OF_FILE "%MOD_FOLDER%/text/my_text.txt"
  INSERT_BYTES offset text_len
  WRITE_FILE offset "%MOD_FOLDER%/text/my_text.txt"
END

I haven't tested it, but it should work.

Edit: I totally forgot the most obvious solution:

ACTION_GET_STRREF berserker_desc "berserker_description"
OUTER_SPRINT new_berserker_description "%berserker_description%" ^ "%new_text%"

 

Edited by argent77
Posted

String concatenation is a valid operation in WeiDU. Get the old string, ^ it with your addition, and then do the usual things with your new string to get it in the tlk and use it.

I've done this with descriptions myself; for my "Bling Fist" kit mod, I created a bunch of item descriptions by concatenating several pieces. About fifty description fragments in the tra, combined in various ways at install time to form full descriptions for three times that many items.

Here's the block of my code that I did that in, though without the context building the arrays I used:

Spoiler
ACTION_PHP_EACH UpgradeItems AS item1 => letter1 BEGIN
	COPY_EXISTING ~J8BBL6.ITM~ ~override/J8BBL6%letter1%.ITM~
		SPRINT desc1 @1601
		SPRINT desc3 @1611
		SPRINT descstr ~%desc1%~^~%item1_3%~^~%desc3%~^~%item1_5%~
		SAY DESC ~%descstr%~
		SAY UNIDENTIFIED_DESC ~%descstr%~
	BUT_ONLY
	ACTION_PHP_EACH UpgradeItems AS item2 => letter2 BEGIN
		ACTION_IF (item1_0 != item2_0) BEGIN
			COPY_EXISTING ~J8BBL6%letter1%.ITM~ ~override/J8BBL6%letter1%%letter2%.ITM~
				SPRINT desc1 @1601
				SPRINT desc4 @1612
				SPRINT descstr ~%desc1%~^~%item1_3%~^~%item2_4%~^~%desc4%~^~%item1_5%~^~%item2_5%~
				SAY DESC ~%descstr%~
				SAY UNIDENTIFIED_DESC ~%descstr%~
				LPF DELETE_ITEM_HEADER INT_VAR header_type=3 END
			BUT_ONLY
		END
	END
END

All of those fragments that go into the descriptions come from @ references eventually, though I created string variables for them as intermediate steps. A tra reference is almost, but not quite, a string variable, and behaves a little oddly when you mutilate the strings like this. Or maybe it's from when I tried to use @ followed by a variable instead of by a literal number. I wasn't too bothered about whether I had the best way of doing things once I had a way that worked.

Or in other words, here's my version of what you're trying to do:

ACTION_GET_STRREF %berserker_desc% berserker_description
OUTER_SPRINT new_berserker_description ~%berserker_description%~^~%berserker_addendum%~
OUTER_SET new_berserker_desc = RESOLVE_STR_REF (~%new_berserker_description%~)

/* And then put that new number into a bunch of 2DA files */

 

Posted

This is probably more hacky than the above posts, but I did something like this in a mod:

 

Spoiler
OUTER_TEXT_SPRINT addtodesc ~Testing - Added to Berserker~

COPY_EXISTING - ~clastext.2da~ ~~
  READ_2DA_ENTRIES_NOW ~clastext_table~ 3
  COUNT_2DA_ROWS 3 rows

  FOR (r = 1; r < rows; ++r) BEGIN
    READ_2DA_ENTRY_FORMER ~clastext_table~ r 0 kitname
    PATCH_IF (~%kitname%~ STRING_EQUAL_CASE ~BERSERKER~) BEGIN    // if kit is berserker
      READ_2DA_ENTRY_FORMER ~clastext_table~ r 4 kitdesc          // column 4 = kit description
      GET_STRREF %kitdesc%  kitdesctext
    END
  END

<<<<<<<< .../temp/inlined
%kitdesctext%


%addtodesc%
>>>>>>>>

OUTER_TEXT_SPRINT inlined ~.../temp/inlined~
COPY - ~%inlined%~  ~%inlined%~    EVALUATE_BUFFER
COPY - ~%inlined%~  ~%inlined%~    READ_ASCII 0x0 ~newdesc~ (%SOURCE_SIZE%) NULL
STRING_SET_EVALUATE kitdesc  ~%newdesc%~

 

 

Basically, copy the original text and the added text to an inlined file, or make whatever REPLACE_TEXTUALLY edits you want. Then read it and set it back to the description string.

Posted

Ha ha, @Dan_P if I had spent more time pondering it by myself that's about what I would have come up with. Except instead of an inline file I probably would have made a real text file in an external directory. (You should see the way I use to put dialogues together…)

Thanks @jmerry and @argent77 that’s exactly what I need. 

Guest morpheus562
Posted (edited)

Here is what I do to update Kit descriptions. This one is for the Blade, and it targets both the normal class text and the sod class text. If you don't target the sod class text, then you will have inconsistencies for players using EET during the BGEE portion of the game.

///////////////////////////////////////////////////////////////////////////
// Update Kit Descriptions                                               //
///////////////////////////////////////////////////////////////////////////
ACTION_FOR_EACH description IN 
    clastext 
    sodcltxt 
  BEGIN
    ACTION_IF FILE_EXISTS_IN_GAME ~%description%.2da~ BEGIN
      COPY_EXISTING ~%description%.2DA~ ~override~
      COUNT_2DA_COLS col_count
      COUNT_2DA_ROWS col_count rows
      FOR (index = 0; index < rows; ++index) BEGIN
        READ_2DA_ENTRY index 0 col_count row_name
        PATCH_IF "%row_name%" STRING_EQUAL_CASE "BLADE" BEGIN
          READ_2DA_ENTRY index 4 col_count blade_desc
          SPRINT old_blade @3504
          SPRINT new_blade @3505
          GET_STRREF %blade_desc% blade_text
          INNER_PATCH_SAVE blade_text ~%blade_text%~ BEGIN
            REPLACE_TEXTUALLY ~%old_blade%~ ~%new_blade%~
          END
          INNER_ACTION BEGIN
            STRING_SET_EVALUATE ~%blade_desc%~ ~%blade_text%~
          END
        END
      END
      BUT_ONLY
    END
  END

@3504 is the old snippet of text and @3505 is the new text being inserted.

@3504 = ~May place 3 slots in Two-Weapon Style.~
@3505 = ~May place 3 slots in Two-Weapon Style.
– May achieve Specialization (2 slots) in melee weapons.~

 

Edited by morpheus562
Posted

@morpheus562 in fact you also need to target BGCLATXT.2da, in addition to CLASTEXT and SODCLTXT. The ideal way to do it is to find any and all class text files in CAMPAIGN.2da, and patch them all. 

As far as how you edit the description: yes, that is my go-to technique. However, that relies on the mod being traified such that your .tra string @3504 perfectly matches the phrase in whatever language the player is using. Since I’m making substantial changes to a basic game system, I want to make sure the player gets the information. In this case I only have a Polish translation, so by appending text to the bottom of the description, it will work seamlessly in English and Polish; while in French, say, they will get English proficiency information at the bottom of the French description. 

Not ideal, but we have to choose from among several not-ideal solutions. 

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...