Jump to content

Modify .spl files

Recommended Posts

I wish to update/change fields some files in my .spl files

Do i have to write line of code for every change in each effect or there is some function to do that

I have .spl with effect no.0
target: self 1
power: 4
which i wish to change to
target: preset target
power: 0

Currently my code looks like this

COPY ~golden_horse/test_spl/rqtest1.spl~ ~override/rqtest1.spl~
 WRITE_ASCII 0x09c ~1~
 WRITE_ASCII 0x09d ~0~

Edited by svj
Link to comment

Of course there are functions. And you should never use raw number offsets for anything outside a file's fixed-size header (the first 0x72 bytes in the case of a spell); it's very easy to get lost and modify the wrong thing, and mods can move things around anyway.


Link to comment
10 hours ago, jmerry said:

(see WeiDU documentation for details)

Where.... here.
Also mentioning that you can use the * in the file's name during copy to copy multiple files, etc would likely to be useful... and all the PATCH_IF's etc (the following sections in the later link).
As in, not assuming things.

Edited by Jarno Mikkola
Link to comment

So for single spell i ended up with this.

COPY ~golden_horse/test_spl/rqtest1.spl~ ~override/rqtest1.spl~
  header = 0
  target = 2
  power = 0

Link to comment

So, what that function invocation would do:

- Since "header" is zero, look only at the first header. In most spells, this is the version of the effect you get at minimum caster level. Spells that vary based on caster level have one header for each possible level of the caster.

- Since "match_opcode" is its default value of -1, we match all effects within the one header we're looking at.

- Since "target" is 2 and "power" is 0, we set those values for every effect we're looking at. Every effect in the first header now affects "Preset Target" and hits as a level zero spell.

Is that what you wanted to do?

Link to comment
Posted (edited)

These are test spells they do not have more powerful versions of themselves

They do have multiple effects under one single Spell Ability 0 as Near Infinity marks it If i understand your terminology Spell ability 0 in NI = header 0

Power value is poorly explained in IEDSP i only understand it affects spell power level as in Timestop is level 9 spell and i did wished to lower spell level to 0

Edited by svj
Link to comment

"Power Level" is mainly relevant for how it interacts with spell protections. Larloch's Minor Drain is power level 1, so it spends one level of a spell deflection effect. Detect Invisibility is power level 0, so it passes right through virtually all spell defenses; only Spell Immunity: Divination or Non-Detection block it. Spell Thrust is power level 4, so it goes over a Minor Globe of Invulnerability (and removes it) but is blocked by a full Globe of Invulnerability.

The overall level of a spell - what level it is in the spellbook - is a field in the header, and it has no relation to the "power level" of its effects.

Link to comment
11 minutes ago, svj said:

COPY_EXISTING_REGEXP ~golden_horse/test_spl/~ ~override/~

Multiple things... the ~override~ needs to be like this, not the above.
And you are using COPY_EXISTING_REGEXP ... so you need the file to be a game file, not mod file. As the _REGEXP means existing file in the game files.
And then you need to use a * in the command.
Like say:

  SAY // ... whatever

The - GLOB - is there for this reason.

You can use COPY ~golden_horse/test_spl~ ~override~ ... to "move" multiple files to the game... while editing them.

Edited by Jarno Mikkola
Link to comment

Some sample copying commands from my tweak collection, so you can see which one is appropriate in various situations:

	COPY_EXISTING "ohrbear6.SPL" ~override~

Copy one spell already in the game files.

	COPY_EXISTING ~SPPR504.SPL~ ~override~
	              ~SPPR550.SPL~ ~override~
	              ~SPPR712.SPL~ ~override~
	              ~SPJA01.SPL~ ~override~
	              ~BHAAL4A.SPL~ ~override~

Copy a list of spells from the game files. In this case, resurrection spells that can target outside the party. This list form is quite broadly useful.


Copy all the creatures; the "^.+" is a regexp expression that matches one or more arbitrary characters, "\." matches a period because "." is a reserved character with special meaning, and "CRE" matches that string. (The example @Jarno Mikkola gave is flawed, and would match "HARMONY RITM" if such a file existed; regexp voodoo requires great precision.)

	ACTION_PHP_EACH resistance AS name => res BEGIN
		COPY_EXISTING ~%res%.SPL~ ~override~

Copy a bunch of spells using a previously defined array; I built that "resistance" array by reading SPELL.IDS, so the list formulation above wouldn't have worked directly. (A later END is also needed to close the EACH loop)

	COPY ~jtweaks/resource/noober/J8#SCRNO.ITM~ ~override~ // Summoning scroll

Copy a file from my mod folder to the override. Nice and simple, but note that COPY needs the path unlike COPY_EXISTING.

	ACTION_BASH_FOR ~music~ ~^.+\.MUS$~ BEGIN // Song assembly playlists

A particularly exotic example, copying all the existing music playlists. COPY_EXISTING can't find anything in the music folder, so I have to use COPY instead. (A later END is needed to close the FOR loop)


COPY can get files from anywhere, but the path must be specified and it can't extract game files from the BIF archives.

COPY_EXISTING only looks in the BIF archives and the override folder, but always grabs the currently active version - override if there's a copy there, BIFs if there isn't.

If you attempt to copy a file that doesn't exist at all, you get an error. Unless you use IF_EXISTS when you close that copy operation; that performs an existence check before you try to do anything with the file, and skips it if the check fails.

Link to comment
39 minutes ago, jmerry said:

(The example @Jarno Mikkola gave is flawed, and would match "HARMONY RITM" if such a file existed; regexp voodoo requires great precision.)

Erhm, the code is from weiduy documentation... and erhm, the game files can only have 8 characters, which includes the SPACE as a character, so your file doesn't actually match.

Edited by Jarno Mikkola
Link to comment

The documentation? So it is. It's still a flawed example which doesn't do exactly what it was meant to. It doesn't search for filenames that start with "HARM" and have the extension ".ITM" as presumably intended; it instead searches for filenames that start with "HARM" and end with "ITM" with at least one additional character in the middle. That's what failing to escape reserved characters does for you.

Link to comment

I apologize for wasting your time... but my mod is not going to add any new spells into bg2. These spells are just for my internal testing purposes to verify if my items work as intended

COPY_EXISTING_REGEXP ~golden_horse/test_spl/~ ~override/~ actually does what i want from this function

It does copy from directory golden_horse/test_spl/ to override/ and modifies the fields which i want...

Link to comment
5 hours ago, svj said:

COPY_EXISTING_REGEXP ~golden_horse/test_spl/~ ~override/~ actually does what i want from this function

It does copy from directory golden_horse/test_spl/ to override/ and modifies the fields which i want...


I don't trust that assertion. At all. Because that's just not how COPY_EXISTING works. You claim that it'll copy from your mod folder but use what's already in the game as a filter for what to copy. I haven't ever tested the first point because it's self-evidently in opposition to how COPY_EXISTING is described in the documentation and an obvious case for just using COPY, but the second has come up in my experience and it's definitely false. COPY_EXISTING a filename that isn't a game resource, and WeiDU will error out unless you guard against it with an IF_EXISTS check.

If you want to copy a list of files from somewhere, just COPY that list. It's your mod folder, and you should know what's in it. Just list out those files. Or if for some reason it's an inconveniently long list, that ACTION_BASH_FOR construct I posted lets you use regexps with a COPY command.

Link to comment

~/games/bg2/prefix/drive_c/GOG Games/Baldur's Gate 2/override

ls rqtest*
ls: cannot access 'rqtest*': No such file or directory


weinstall setup_golden_horse.tp2 
weidu --log "setup-setup_golden_horse.debug" "setup_golden_horse.tp2"
[weidu] WeiDU version 24900

Install Component [Golden Horse mercenary company Mod (Requires Throne of Bhaal)]?
[R]e-Install, [N]o Change or ninstall or [Q]uit? n

Skipping [Golden Horse mercenary company Mod (Requires Throne of Bhaal)]

Install Component [Revan's class]?
[N]o, [Q]uit or choose one:
 1] Change Revan's class from Mage/Thief >>> TO >>> Mage/Assassin multi-class
 2] Change Revan's class from Mage/Thief >>> TO >>> Fighter/Mage/Thief multi-class

Install Component [rqpton tests]?
nstall, or [N]ot Install or [Q]uit? i

Installing [rqpton tests] [v0.10b]
Copying and patching 1 file ...
ERROR: illegal 1-byte read from offset 1213472800 of 10132-byte file golden_horse/test_spl//rqtest.d
ERROR: [golden_horse/test_spl//rqtest.d] -> [override//rqtest.d] Patching Failed (COPY) (Failure("golden_horse/test_spl//rqtest.d: read out of bounds"))


Press ENTER to exit.


ls rqtest*
rqtest10.spl  rqtest14.spl  rqtest18.spl  rqtest21.spl  rqtest25.spl  rqtest29.spl  rqtest32.spl  rqtest4.spl  rqtest9.spl
rqtest11.spl  rqtest15.spl  rqtest19.spl  rqtest22.spl  rqtest26.spl  rqtest2.spl   rqtest33.spl  rqtest6.spl
rqtest12.spl  rqtest16.spl  rqtest1.spl   rqtest23.spl  rqtest27.spl  rqtest30.spl  rqtest34.spl  rqtest7.spl
rqtest13.spl  rqtest17.spl  rqtest20.spl  rqtest24.spl  rqtest28.spl  rqtest31.spl  rqtest3.spl   rqtest8.spl

~/games/bg2/prefix/drive_c/GOG Games/Baldur's Gate 2/override

Complaints about byte read offset nonsense is from unfinished D-file that i had in test_spl directory but as you can see it does copy contents of the test_spl to override

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.

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