Quick and dirty land texture swap (hex edit)

1 post / 0 new
Rot's picture
Lead DeveloperDeveloperQuest Developer
2014-03-16 17:45
Last seen:
1 week 2 days ago

Needed: tes3cmd, hex editor, notepad++ or other regex text editor

tes3cmd dump --type LTEX "SectionFile.esp" > SectionFileLTEX.txt

Looking for the index value of the LTEX to switch.


The index value used by CELL records is that value +1.

Here we'll switch T_Mw_Terr_GrassAT to T_Mw_TerrGrassAT, etc, so values:
153+1 switched to 150+1
154+1 switched to 151+1
155+1 switched to 149+1

In hexadecimal:
9A switched to 97
9B switched to 98
9C switched to 96

Now dump a cell's LAND with tes3cmd to look at the record to modify
tes3cmd dump --type LAND "SectionFile.esp" > SectionFileLAND.txt

The modification will be in  "VTEX:", a 16x16 array. tes3cmd can't do it, so we'll hex it.

To work on smaller files let's only export the LAND with its textures:
tes3cmd dump --type LAND --type LTEX --raw-with-header "TR_AanthirinNorth_v.07_LAND.ESP" "TR_AanthirinNorth_v.07.ESP"

Now open the LAND file in a hex editor and copy ANSI into the text editor
For testing, temporarily delete all VTEX...LAND that have exactly 516 characters between them:
regex replace VTEX(.{516})LAND with nothing,
is the number of things getting deleted the number of cells? yes, then search for VTEX, is there any match left? no, good. It would be a strange coincidence but since we'll basically edit raw data this is a necessary step to ensure we won't edit the wrong things.

Now copy the HEX data into the text editor (assuming your hex editor can't do the following regex operations itself). Warning: check your clipboard/copy-paste limitations. If there are more millions of characters than they can handle, repeat in several steps
to make computations faster for the text editor we'll cut the VTEX sections into new lines,
regex replace 56 54 45 58 (.{1547}) 4C 41 4E 44 with \r\n56 54 45 58 $1 4C 41 4E 44\r\n
Notepad++: Macro > Start Recording
regex replace ^56 54 45 58 (.*?) 9A  (one space at the end) with 56 54 45 58 $1 97  (one space at the end)
replace a few times,
Notepad++: Macro > Stop Recording, Macro > Run a macro multiple times...,  and check run it until the end of file.
Repeat until nothing is replaced.

Repeat for the other values to swap.
put the VTEX lines back into their place:
regex replace \r\n56 54 45 58 (.{1547}) 4C 41 4E 44\r\n with 56 54 45 58 $1 4C 41 4E 44
copy the HEX back into the hex editor and save. The character count should be the same.

Merge back LAND and section.