# lib_strref function library

Dependencies: lib_2da, lib_anon, lib_array, lib_fn, lib_ini, lib_sfo, lib_struct, lib_sugar, lib_tools, lib_ui

## Description

Functions in this library are designed to automatically apply an SFO standard function to every strref found in a given file.

## Public functions

strref_2da(function:s)=() patch

Acting on the current file, assumed to be a 2da file, apply 'function' to each of the strrefs in it.

Note that detection of which numbers in a 2da file are strrefs is of necessity a bit heuristic. We assume that

- no integer lower than 160 is a strref (the actual values from 1-100 in BG2 are dialog strings not referenced in 2das)
- no integer larger than 299999 is a strref (this is way bigger than any actual dlg)
- no integer in the following 2das is a strref: banttimg clearair extanim extspeed happy pplane raisdead randcolr repmodst splashs2 splashsc startare startbp startpos strmod strmodex xpbonus xpcap xplevel xplist
- no integer <10000 in the following is a strref: end15fps endmve1 endmve2 endmve3 intro intro15f melissan xnewarea
- no integer in columns 0-2 of clastext is a strref
- nothing in hex notation is a strref
- all other integers are strrefs

strref_apply(function:f)=() patch

Apply the (SFO standard patch) function 'function' to every strref in the current file, replacing it with the output. Currently doesn't do wmp files.

strref_script(function:s)=() patch

Acting on the current file, assumed to be a decompiled script, apply 'function' to each of the strrefs in it

## Internal functions

These should not be called from outside the library itself.

strref_opcode(opcode_offset:i, parameter1_offset:i, parameter2_offset:i, special_offset:i, function:s)=() patch

Read the opcode at opcode_offset and, if appropriate, apply 'function' to any strref encoded in it

strref_struct(function:f)=() patch

Go through a struct file, applying 'function' to each strref in it and returning the new one. Also does opcodes.

strref_struct_helper(struct:a, strtype:s, function:f)=(struct:a) patch