Jump to content

How to change the exact icon of a spell scroll in SR 3.1.03 ?


Recommended Posts

2 hours ago, Prof Errata said:

IT WORKS ! YOUPI ! Thank you Mike, now I can send my mod !

Glad to hear.

2 hours ago, Prof Errata said:

NB: you are Canadian, so do you live near of the province of Quebec ?

Nope; other side of the country.  We all learn some French in school, though.

Link to comment
16 hours ago, Mike1072 said:

The main issue with writing over the entire text field can be solved like this:


WRITE_ASCII 0x76 ~ISCRL1R~ #8

This is likely to work if the file hasn't been changed between when SR is installed and your mod is installed.

However, it's good practice to not rely on this, and there is a safer way to code this sort of thing.

The icon will not always be stored at offset 0x76.  The icon field is part of the extended header section of the file.  An item may have one or more extended headers, also known as abilities.  They are each 0x38 bytes in length and they may not be located directly after the header.

We can find out how many abilities there are and where they start in the file by reading that information from the header, in offsets 0x68 and 0x64.  Then we can loop through each ability and change its icon.

Here's the full code:


ACTION_IF (FILE_EXISTS_IN_GAME ~scrlw801.itm~) THEN BEGIN // SR Wraithform
  COPY_EXISTING ~scrlw801.itm~ ~override~
    PATCH_IF (SOURCE_SIZE > 0x71) THEN BEGIN // protects against invalid files
      READ_LONG  0x64 abilities_offset
      READ_SHORT 0x68 num_abilities
      FOR (i = 0; i < num_abilities; i += 1) BEGIN // loop through abilities
        // update icon
        WRITE_ASCII (abilities_offset + 0x38*i + 0x04) ~ISCRL1R~ #8
      END
    END
    BUT_ONLY
END

 

I've used that sort of setup for spells, but I hadn't considered that items with more than one extended header (or none at all) might also change the location. That #8 for 8 bytes is also very helpful to know. Thanks!

Edited by Bartimaeus
Link to comment

Depending on what kind of item it is, those abilities might be something like ranged version / melee version, or they could be separate magical abilities.  So for something like changing an icon, I'd probably add some sort of check during the loop to make sure I was modifying the right one.

I wanted to put some code out there that wouldn't rely on arbitrary unsafe offsets outside the file header.  If you're modifying a file where you aren't sure of its exact contents, you can't be sure that the data you want will be located at those offsets. (Even if it almost always will be.)

Subtledoctor's probably right that there are functions that can do this sort of thing as well, but it helps to know how the underlying data is structured.  Knowing how to code it yourself also gives the advantage that you can implement more complicated logic in your patches that you might not be able to do with pre-made functions.

Link to comment

Dear Mike, I need your help again. Recently my mod have been modified for BG2EE integration, and yet the problem with this SCRLW801.ITM has reappeared…Argh…well, i hope that this problem will be resolved once for all, I put here the beta and the WeiDU log. Thanks by advance. Note if you could correct moreover the possible grammatical inaccuracies of the readme, I would be enchanted.

NB: the spell keep its normal icon once memorized.

Kaya_v2beta.rar

WeiDU.log

Link to comment

The code you have is changing the icons for the extended headers (item abilities).

If you want to change the inventory icon as well, you need to add this line of code when you patch SCRLW801.ITM:

      WRITE_ASCII 0x3a ~ISCRL1R~ #8 // update inventory icon

I would insert it right after this line:

    PATCH_IF (SOURCE_SIZE > 0x71) THEN BEGIN // protects against invalid files

 

Link to comment

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