Jump to content

WeiDU CRE patching - how to add BG2 proficiencies?


aVENGER_(RR)

Recommended Posts

Heh, then here's some more reading material for you (and me ;)).

 

My next question may sound rather trivial but I was unable to find an answer in the WeiDU documentation. :cry: Well, here goes - how do I remove an item from a creature's slot? In this particular case, a Kensai/Thief (C6YEAN.CRE) is wearing leather armor and I'd like to either move it into one of his free inventory slots or to remove it entirely from his CRE. Any clues?

Link to comment

Well, looking at the creature in NI... what "I" would do is just copy existing and re-assign my own override script to that creature and add my items to his inventory. Then use the script to change out the gear on creation and destroy the junk.

 

Cuv

Link to comment

Nythrun can come up with something 50 times larger than it needs to be ( :p ), but in general, you just want to empty the slot where the item is (you don't actually need to delete the item reference from the CRE; the engine purges junk that isn't in the inventory when it's loaded).

COPY_EXISTING C6YEAN.CRE OVERRIDE
 READ_LONG 0x2b8 so
 WRITE_SHORT so + 0x2 `0x0
BUT_ONLY_IF_IT_CHANGES

Standard stickiness comes up if you only want to clear the slot if it's filled by a certain item (just read the item index and read at the items offset + (index * 0x14)) or if you want to delete a certain item but aren't sure what slot it's in (iterate through the items list, tracking the counter, and write in the slot list + (counter * 0x2) if you find your item; or just replace the item with HELMNOAN for NPCs).

Link to comment

Thanks devSin! I didn't really know how having an invalid item in the armor slot would affect anything, but apparently there seems to be no harm done. Just to be safe, I'm using this command instead of clearing the slot entirely:

 

COPY_EXISTING ~C6YEAN.CRE~ ~override~ // Yeanasha
 ADD_CRE_ITEM ~HELMNOAN~ #0 #0 #0 ~UNDROPPABLE~ ~ARMOR~ // Clears armor slot (he's a Kensai and thus shouldn't wear any armor)
  BUT_ONLY_IF_IT_CHANGES

 

This seems to neatly bump Yeanasha's Leather Armor +2 into an empty inventory slot. :cry: BTW, just thinking out loud here, but wouldn't it be nice to have a MOVE_CRE_ITEM WeiDU command? That could be useful when someone wants to either move an item which a creature possess from a certain slot to a different slot or remove it completely. The syntax would be similar to the ADD_CRE_ITEM command but MOVE_CRE_ITEM would naturally require two slot designations. For example:

 

COPY_EXISTING ~C6YEAN.CRE~ ~override~ // Yeanasha
MOVE_CRE_ITEM ~LEAT11.ITM~ ~UNDROPPABLE~ ~ARMOR~ ~INV1~ // move armor to the first free inventory slot and make it undroppable

 

Also, this command could allow for removing the item completely by introducing a new ~VOID~ slot, so we could have:

COPY_EXISTING ~C6YEAN.CRE~ ~override~ // Yeanasha
MOVE_CRE_ITEM ~LEAT11.ITM~ ~NONE~ ~ARMOR~ ~VOID~ // delete the armor from the CRE file

 

Any chance of something like this being implemented?

Link to comment

You may want REPLACE_CRE_ITEM, which will do just that; the armor will be replaced completely rather than bumped into inventory (unless the Kensai likes carrying around useless armor for fun :cry: )

 

I'd rather delete it entirely myself (it takes maybe ten lines of code), but I'm fussy.

Link to comment
You may want REPLACE_CRE_ITEM, which will do just that; the armor will be replaced completely rather than bumped into inventory (unless the Kensai likes carrying around useless armor for fun ;) )

 

Whoa, somehow I seem to have completely overlooked the existence of that command. :cry: Thanks, this should prove handy.

 

I'd rather delete it entirely myself (it takes maybe ten lines of code), but I'm fussy.

 

Feel free to post it, I may want to completely remove a few items from certain creatures in some other instances of my mod.

Link to comment

OK.

 

DEFINE_PATCH_MACRO ~DELETE_CRE_ITEM~ BEGIN
 PATCH_IF (SOURCE_SIZE > 0x2d3) THEN BEGIN
READ_LONG  0x02bc "ilo"
READ_LONG  0x02c0 "ilc"
FOR ("i1" = 0x00; "i1" < "ilc"; "i1" += 0x01) BEGIN
  READ_ASCII ("ilo" + (0x14 * "i1")) ~item~
  PATCH_IF (~%item%~ STRING_EQUAL_CASE ~%item_to_delete%~) THEN BEGIN
	WRITE_LONG 0x02c0 ("ilc" - 0x01)
	DELETE_BYTES ("ilo" + (0x14 * "i1")) 0x14
	PATCH_FOR_EACH "o1" IN 0x02a0 0x02a8 0x02b0 0x02b8 0x02c4 BEGIN
	  READ_LONG  "o1" "o2"
	  WRITE_LONG "o1" (("o2" > "ilo") ? ("o2" - 0x14) : "o2")
	END
	READ_LONG 0x02b8 "iso"
	FOR ("i2" = "iso"; "i2" < ("iso" + 0x4c); "i2" += 0x02) BEGIN
	  READ_SHORT  "i2" "sl"
	  WRITE_SHORT "i2" (("sl" = "i1") ? 0xffff : ((("sl" > "i1") AND ("sl" != 0xffff)) ? ("sl" - 0x01) : "sl"))
	END
	SET "i1" = "ilc"
  END
END
 END
END

COPY_EXISTING ~c6yean.cre~ ~override~
 SPRINT ~item_to_delete~ ~leat11~
 LAUNCH_PATCH_MACRO ~DELETE_CRE_ITEM~
BUT_ONLY

 

It might even parse :cry:

 

This way, when someone installs Improved Addlepation or some such after your mod, and it goes looking through NPC kensai to see if they have any armor, it won't return a false positive and ActionOverride(Player1,DestroySelf()) or whatever. It only matters if you're concerned with possibly fooling other people's creature patches; for your own work setting the slot assignment to -1 really ought to suffice.

Link to comment

Sure. I've just shunted the bulk of it into a macro to make that easier, but it's pretty much the same as it was before.

 

Writing your own macros is great way to simulate any high-level WeiDU command you might want that doesn't exist; I recommend it highly :cry: You should be able to find lots of examples scattered around the various fora.

Link to comment

Wow, that's absolutely fantastic! ;) Thanks, I'll definitively look into macros a bit closer. :cry: For now, two more things are puzzling me:

 

1) Where should I place the DEFINE_PATCH_MACRO block? Currently, I've just pasted it after the BEGIN line of the fourth component of my mod since the previous three components don't alter any creatures. So far, it seems to work fine.

 

2) In case I want to delete several different items from a CRE, can I somehow define them all at once or do I have to do it separately for each item like so:

 

COPY_EXISTING ~ARLED.CRE~ ~override~ // Arledrian 
SPRINT ~item_to_delete~ ~bow05~ // removes the Short Bow (which would otherwise mess up Arledrian's dual-wielding)
LAUNCH_PATCH_MACRO ~DELETE_CRE_ITEM~ // Launches the macro
SPRINT ~item_to_delete~ ~sw1h08~ // removes the Short Sword +1 (otherwise it might mess up EquipMostDamagingMelee())
LAUNCH_PATCH_MACRO ~DELETE_CRE_ITEM~ // Launches the macro
SPRINT ~item_to_delete~ ~arow02~ // removes the Arrows +1 (useless without a bow)
LAUNCH_PATCH_MACRO ~DELETE_CRE_ITEM~ // Launches the macro
.
.
.
a bunch of other stuff
.
.
.
BUT_ONLY_IF_IT_CHANGES

Link to comment

ETA for clipping all of these snippets for the development wikki, Monday AM.

 

question - instead of Nythrun's Code Snippets, should I be building all of this into the Common Code bank, or simply add all of them to a Modders Code Bank with appropriate authorship references?

 

Either way, I need to pull CamDawg's and the bigg's stuff, etc to an easy to search reference too.

Link to comment

COPY_EXISTING ~arled.cre~ ~override~
 PATCH_FOR_EACH ~item_to_delete~ IN ~bow05~ ~sw1h08~ ~arow02~ BEGIN
LAUNCH_PATCH_MACRO ~DELETE_CRE_ITEM~
 END
 OTHER_PATCHES
BUT_ONLY_IF_IT_CHANGES_EVEN_IF_THERE_IS_A_SHORTER_VERSION_CAUSE_WES_AND_BIGG_LIKE_SOME_PROLIX_KEYWOR
DS_WITH_WHICH_TO_MOCK_WEIDU_SYNTAX

 

Macros need to be defined or included before use, that's really the only restriction. If you're planning to use something across multiple components, it'll save typing if it's stuck in the ALWAYS .... END section of the .tp2 header.

 

/meh

 

I love how the code is fifty times longer than need be, and yet would be improved by using cut and paste instead of a recursive function, so it's harder to maintain, longer to parse, and more space consuming.

 

You're killin' me here.

Link to comment

I heard that some of the text editors you moddarz use are going to get copy and paste functions in their next updates! This could be the end of patch macros!

 

I'd suggest you save yourself the time required to care about some of the latest BiggDU features. I'm stuck on some really early WeiDU actions in a lot of places, and I do just fine.

Link to comment
I heard that some of the text editors you moddarz use are going to get copy and paste functions in their next updates! This could be the end of patch macros!

 

I'd suggest you save yourself the time required to care about some of the latest BiggDU features. I'm stuck on some really early WeiDU actions in a lot of places, and I do just fine.

 

100k install scripts FTW.

Link to comment

Cam, so far I've been using the method you supplied in this post for adding BG2-style proficiencies to creatures. However, I've recently noticed that DLTCEP reports a "Creature will be reordered, harmless inconsistency" warning whenever I open a creature which has been patched in this way. I've managed to narrow down the issue to the following code block:

 

SET "new_fx" = 2												  // effect number
 READ_BYTE   0x33 "fx_type"
 READ_LONG  0x2b0 "known_off"
 READ_LONG  0x2b8 "slot_off"
 READ_LONG  0x2bc "itm_off"
 READ_LONG  0x2c4 "fx_off"
 READ_LONG  0x2c8 "fx_num"
 WRITE_LONG 0x2c8 ("%fx_num%" + "%new_fx%")
 SET "offset" = ((0x30 + (0xd8 * "%fx_type%")) * "%new_fx%")
 PATCH_IF ("%known_off%" >= "%fx_off%") BEGIN
WRITE_LONG 0x2b0 ("%known_off%" + "%offset%")
 END
 PATCH_IF ("%slot_off%" >= "%fx_off%") BEGIN
WRITE_LONG 0x2b8 ("%slot_off%" + "%offset%")
 END
 PATCH_IF ("%itm_off%" >= "%fx_off%") BEGIN
WRITE_LONG 0x2bc ("%itm_off%" + "%offset%")
 END

 INSERT_BYTES   ("%fx_off%"							  ) (0x30 + (0xd8 * "%fx_type%")) // 2 stars in Long Sword
WRITE_SHORT  ("%fx_off%"		+ (0x08 * "%fx_type%")) 233	  // opcode: prof
WRITE_LONG   ("%fx_off%" + 0x04 + (0x10 * "%fx_type%"))   2	  // number of stars
WRITE_LONG   ("%fx_off%" + 0x08 + (0x10 * "%fx_type%"))  90	  // proficiency
WRITE_LONG   ("%fx_off%" + 0x0c + (0x10 * "%fx_type%"))   9	  // instant/permanent
WRITE_LONG   ("%fx_off%" + 0x12 + (0x18 * "%fx_type%")) 100	  // probability

 INSERT_BYTES   ("%fx_off%"							  ) (0x30 + (0xd8 * "%fx_type%"))  // 2 stars in Long Bow
WRITE_SHORT  ("%fx_off%"		+ (0x08 * "%fx_type%")) 233	  // opcode: prof
WRITE_LONG   ("%fx_off%" + 0x04 + (0x10 * "%fx_type%"))   2	  // number of stars
WRITE_LONG   ("%fx_off%" + 0x08 + (0x10 * "%fx_type%")) 104	  // proficiency
WRITE_LONG   ("%fx_off%" + 0x0c + (0x10 * "%fx_type%"))   9	  // instant/permanent
WRITE_LONG   ("%fx_off%" + 0x12 + (0x18 * "%fx_type%")) 100	  // probability

 

Apparently, something in there causes the "harmless inconsistency" warning to trigger (if I comment out that block, the warning disappears). BTW, I should note that once installed, everything works perfectly in-game i.e. the proficiencies are being properly applied. Any ideas what's wrong?

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...