Author Topic: CRE portraits and colors  (Read 295 times)

Offline Andrea C.

  • Planewalker
  • *****
  • Posts: 80
  • Gender: Male
CRE portraits and colors
« on: May 11, 2017, 02:24:13 PM »
I failed again  :'(

I wrote code to restore the original BG:EE portraits and color offsets for characters that make a comeback in BGII:EE (Imoen, Minsc, Jaheira, Edwin, Viconia.) While it installs no problem, it seems to literally do nothing:

Code: [Select]
COPY_EXISTING_REGEXP GLOB ~.*\.cre~ ~override~
READ_ASCII 0x8 name
PATCH_IF (~%name%~ STR_EQ ~%Imoen%~) BEGIN
  WRITE_ASCII 0x34 ~%BDIMOENM.BMP%~ // small portrait
  WRITE_ASCII 0x3c ~%BDIMOENL.BMP%~ // large portrait
  WRITE_BYTE 0x2c 25 // metal color
  WRITE_BYTE 0x2d 143 // minor color
  WRITE_BYTE 0x2e 144 // major color
  WRITE_BYTE 0x2f 157 // skin color
  WRITE_BYTE 0x30 26 // leather color
  WRITE_BYTE 0x31 92 // armor color
  WRITE_BYTE 0x32 4 // hair color

This is the first snippet of code, where I try to patch Imoen.

I suspect I probably got the whole ~ and % business wrong—still have to get the hang of it. Right? Or is it something else?

Offline Mike1072

  • Planewalker
  • *****
  • Posts: 287
  • Gender: Male
Re: CRE portraits and colors
« Reply #1 on: May 11, 2017, 08:07:17 PM »
1) File extensions (.bmp) should not be included in the portrait fields (or any other resource fields).

2) The name of the creature is stored as a strref at 0x8 in the .cre file.  This means the file does not contain the actual text for the name: it contains a number which corresponds to an entry in dialog.tlk that has the text.  To get the text, you'll need to use READ_STRREF instead of READ_ASCII.

3) There seems to be some confusion between literal text and variables.  The % signs are used to retrieve the value of a variable.

Suppose I define a variable using TEXT_SPRINT film ~Star Wars~.  This creates a variable named film and sets its value to Star Wars.

Code: [Select]
TEXT_SPRINT x ~%film%~
The variable named x now also has the value Star Wars.

Without the %, it treats that as literal text instead of a variable.

Code: [Select]
TEXT_SPRINT y ~film~
The variable named y now has the value film.

4) Putting this all together:

Code: [Select]
READ_STRREF 0x8 name
PATCH_IF (~%name%~ STR_EQ ~imoen~) BEGIN
  WRITE_ASCII 0x34 ~BDIMOENM~ #8 // small portrait
  WRITE_ASCII 0x3c ~BDIMOENL~ #8 // large portrait
  // etc.

Here we compare ~%name%~ to ~imoen~, so we are getting the value of the variable called name and comparing that to the literal text imoen.  STR_EQ is an alias for STRING_EQUAL_CASE.  It does a comparison that's not case-sensitive, so the names IMOEN, imoen, and Imoen would all match.  If you wanted it to be case sensitive and only match Imoen, you should change it to ~%name%~ STRING_EQUAL ~Imoen~.

We write in the literal text BDIMOENM and BDIMOENL as the portrait resources.  I added #8 to the WRITE_ASCII line, which is a good habit to get into when you are writing to a resource field that's 8 characters long.  In this particular case, your filenames are 8 characters long, so it has no effect.  However, if you were writing a filename that was less than 8 characters, it would be necessary.  (Suppose the existing value in the file was BDIMOENM and you used WRITE_ASCII 0x34 ~NEWIM~ without #8.  Only those first 5 characters would be overwritten, and you would end up with the nonsense value NEWIMENM.)

Offline Andrea C.

  • Planewalker
  • *****
  • Posts: 80
  • Gender: Male
Re: CRE portraits and colors
« Reply #2 on: May 12, 2017, 02:08:49 PM »
Hi Mike,

thanks a lot for that!

Worked like a charm :)


With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: