df-structures icon indicating copy to clipboard operation
df-structures copied to clipboard

Identified some of markup_text_boxst

Open alattalatta opened this issue 2 years ago • 3 comments

I'm no reverse engineer but I was able to figure out what these do by evaluating lua scripts. (Steam 50.07)

markup_text_boxst.unk1

Is a vector of words. Line breaks are also words of its own, but not spaces. Each word can have a hyperlink. (See markup_text_boxst.unk_v50_2)

  • unk_00: The word, string.
  • unk_24: Index of markup_text_boxst.unk_v50_2 vector. This is for hyperlinking. -1 for none, i.e. plain text.
  • unk_28: Position of the word along the X axis. -1 for line breaks.
  • unk_2c: Position of the word along the Y axis. -1 for line breaks.
  • ~~unk_30~~

So for a sentence "Serid Skincrafts was a anaconda.", markup_text_boxst.unk1[1] would be

unk_00: "Skincrafts"
unk_24: -1
unk_28: 6
unk_2c: 0

markup_text_boxst.unk_v50_2

Is a vector of hyperlinks.

  • unk_0: Type of target. See #569.
  • unk_4: ID of target.
  • ~~unk_8: Always -1?~~

For historical figures, I can:

local id = markup_text_boxst.unk_v50_2[index].unk_4
return df.historical_figure.find(id)

to retrieve the figure this hyperlink points.

markup_text_boxst.unk_v50_3

markup_text_boxst's width.

markup_text_boxst.unk_v50_4

markup_text_boxst's height.

alattalatta avatar Feb 28 '23 03:02 alattalatta

Just stumbled across this after preparing some changes to the variable names, since I've finished cleaning up the whole reverse engineered function to something readable. I can confirm via the code that unk_24 is an index in unk_v50_2.

On my df-structures branch, I went and renamed these variables: unk1 -> hypertext (This is the vector containing the hyperlink entries. Entries are type markup_text_boxst.T_hypertext.) unk_00 -> text unk_24 -> legends_page_ref_index (See legends_page_ref struct below.) unk_28 -> text_pos_x unk_2c -> text_pos_y unk_30 -> flags (Flag B is set whenever text is empty, probably indicates line break?)

I haven't confirmed unk_v50_3 and unk_v50_4 personally, but those can be box_width and box_height. world.status.unk_v50_1 could be renamed to world.status.active_popup_text_box.

I renamed unk_v50_2 to legends_page_refs and created a struct legends_page_ref for it in df.refs.xml like this:

<enum-type type-name='legends_page_ref_type'>
    <enum-item name='NONE' value='-1'/>
    <enum-item name='HF'/>
    <enum-item name='SITE'/>
    <enum-item name='ARTIFACT'/>
    <enum-item name='BOOK'/>
    <enum-item name='SR'/> SUBREGION?
    <enum-item name='FL'/> FEATURE_LAYER?
    <enum-item name='ENT'/> ENTITY?
    <enum-item name='AB'/> ABSTRACT_BUILDING?
    <enum-item name='EPOP'/> ENTITY_POP?
    <enum-item name='ART_IMAGE'/>
    <enum-item name='ERA'/>
    <enum-item name='HEC'/>
</enum-type>

<struct-type type-name='legends_page_ref'>
    <enum name='type' base-type='int32_t' type-name='legends_page_ref_type'/>
    <int32_t name='ref1' init-value='-1'/>
    <int32_t name='ref2' init-value='-1'/> only used when type is AB or ART_IMAGE
</struct-type>

Therefore unk_0, unk_4, and unk_8 are renamed type, ref1, and ref2, respectively.

The reverse engineered function takes a popup_message and parses its text string looking for something like [LPAGE:HF:1337]hyperlink text[/LPAGE] to create the ref. That example should result in a hypertext entry with text = "hyperlink text" which indexes to a legends_page_ref with type = legends_page_ref_type::HF (i.e., 0) and ref1 = 1337 (and ref2 = -1.)

Edit: Changed unk_v50_2 from lpage_refs to legends_page_refs after confirmation in comment below.

Bumber64 avatar Nov 19 '23 07:11 Bumber64

Does something happen when you click on a hyperlink? In your example, "Skincrafts" is just plain text with an index of -1, so you might have to manually create an entry in the vector to index to (unless "Serid" has the hyperlink.)

If that opens a page with info about the HF, then we might also test the other ref types by putting in arbitrary ref numbers for those.

Are there restrictions on when these hyperlinks work, e.g., worldgen and tutorial but not dwarf mode popups?

Edit: Looks like dwarf mode popups don't have working hyperlinks. I hacked an announcement string and DF parsed it into the proper hyperlink structures, but the resulting popup doesn't have clickable text. The unparsed string shows up in alerts, which indicates announcements don't really support doing this, it's just re-using a function intended for other markup text boxes. Tutorial popups don't work either. Activity info at least overwrites text color to blue but still isn't clickable. Worldgen creates these naturally but links don't work. Guess I could try diplomacy screens?

Edit II: It works in legends mode! Go figure the 'L' in "LPAGE" stands for "Legends", as I initially suspected.

Bumber64 avatar Nov 19 '23 08:11 Bumber64

I think this can be marked closed now?

Bumber64 avatar Dec 05 '23 08:12 Bumber64