Jump to content

Recommended Posts

Do I need to make a bunch of null/zeroed LOCAL_SET's in case someone doesn't need to use a certain variable?
That's probably the "safest" method, in case someone hasn't initialised them. Null doesn't work for SETs - they'd have to be zero or whatever the default value should be. I think null ~~ works for SPRINTs.
Anything else I need to know? Has someone already done this?
I was working on a macro that would clone a header and all effects and paste them as a new header, but I don't know if I finished it.
I assume that in the macro section of the tp2 I would put:

DEFINE_PATCH_MACRO ~ADD_ABILITY_HEADER~ BEGIN

my patches

END

I think the preferred method these days is to include your code as a separate .tpp file, then PATCH_INCLUDE ~mymod/lib/mymacro.tpp~ but either method is equivalent (the former makes code more portable between mods, and possibly more readable).

Share this post


Link to post

I suggest prefixing the internal variables of the macro to lower the potential for overwriting some from outside the macro.

Share this post


Link to post

Check me to make sure everything is okay.

In tp2 "header" after author I apply:

PATCH_INCLUDE ~mymod/lib/mymacro.tpp~

In the tp2 component section I apply:

COPY ~somefile.xxx~ ~override~
SET what I want
SPRINT what I want
LAUNCH_PATCH_MACRO ~ADD_ITEM_HEADER~

and the following would be the tpp code:

DEFINE_PATCH_MACRO ~ADD_ITM_HEADER~ BEGIN
PATCH_IF (%SOURCE_SIZE% > 114) AND (%SOURCE_EXT% STRING_EQUAL_CASE ~itm~) BEGIN
PATCH_IF !(VARIABLE_IS_SET ~%attack_type%~) BEGIN
 SET ~%attack_type%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%id_req%~) BEGIN
 SET ~%id_req%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%use_location%~) BEGIN
 SET ~%use_location%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%use_icon%~) BEGIN
 SPRINT ~%use_icon%~ ~~
END
PATCH_IF !(VARIABLE_IS_SET ~%target_type%~) BEGIN
 SET ~%target_type%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%target_count%~) BEGIN
 SET ~%target_count%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%range%~) BEGIN
 SET ~%range%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%proj_type%~) BEGIN
 SET ~%proj_type%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%speed%~) BEGIN
 SET ~%speed%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%thac0_bonus%~) BEGIN
 SET ~%thac0_bonus%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%d_sides%~) BEGIN
 SET ~%d_sides%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%d_rolls%~) BEGIN
 SET ~%d_rolls%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%damage_bonus%~) BEGIN
 SET ~%damage_bonus%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%damage_type%~) BEGIN
 SET ~%damage_type%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%charges%~) BEGIN
 SET ~%charges%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%charge_removal%~) BEGIN
 SET ~%charge_removal%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%flag%~) BEGIN
 SET ~%flag%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%proj_anim%~) BEGIN
 SET ~%proj_anim%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%overhand%~) BEGIN
 SET ~%overhand%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%backhand%~) BEGIN
 SET ~%backhand%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%thrust%~) BEGIN
 SET ~%thrust%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%bow%~) BEGIN
 SET ~%bow%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%xbow%~) BEGIN
 SET ~%xbow%~ = 0
END
PATCH_IF !(VARIABLE_IS_SET ~%sling%~) BEGIN
 SET ~%sling%~ = 0
END
READ_LONG 0x64 ~ab__abil_loc~
READ_SHORT 0x68 ~ab__abil_num~
READ_SHORT 0x6a ~ab__fx_loc~
SET ab__abil_size = 56
SET ab__new_abil_loc = (%ab__abil_loc% +(%ab__abil_num% *%ab__abil_size))  //sets new header at end of existing header list if any
SET ab__new_fx_loc = (%ab__fx_loc% + %ab__abil_size%)				  //increases effects location by ability size
INSERT_BYTES %ab__new_abil_loc% %ab__abil_size%					//insert enough bytes for one ability at new location
  WRITE_SHORT 0x68 (%ab__abil_num% + 1)						  //update number of headers in file
  WRITE_LONG 0x6a (%ab__new_fx_loc%)							 //update effects location in file
  WRITE_BYTE  (%ab__new_abil_loc% + 0x0) ~%attack_type%~			  // attack type
  WRITE_BYTE  (%ab__new_abil_loc% + 0x1) ~%id_req%~				   // id required 0-yes 1-no
  WRITE_BYTE  (%ab__new_abil_loc% + 0x2) ~%use_location%~			 // use location -- followed by a 3 byte unknown
  WRITE_EVALUATED_ASCII (%ab__new_abil_loc% + 0x4) ~%use_icon%~	   // use icon
  WRITE_BYTE  (%ab__new_abil_loc% + 0xc) ~%target_type%~			  // type of target
  WRITE_BYTE  (%ab__new_abil_loc% + 0xd) ~%target_count%~			 // target count
  WRITE_SHORT (%ab__new_abil_loc% + 0xe) ~%range%~					// range
  WRITE_BYTE  (%ab__new_abil_loc% + 0x10) ~%proj_type%~			   // projectile type
  WRITE_BYTE  (%ab__new_abil_loc% + 0x12) ~%speed%~				   // speed
  WRITE_BYTE  (%ab__new_abil_loc% + 0x14) ~%thac0_bonus%~			 // THAC0 bonus
  WRITE_BYTE  (%ab__new_abil_loc% + 0x16) ~%d_sides%~				 // dice sides
  WRITE_SHORT (%ab__new_abil_loc% + 0x18) ~%d_rolls%~				 // dice rolls
  WRITE_SHORT (%ab__new_abil_loc% + 0x1a) ~%damage_bonus%~			// damage_bonus
  WRITE_SHORT (%ab__new_abil_loc% + 0x1c) ~%damage_type%~			 // damage type
  WRITE_SHORT (%ab__new_abil_loc% + 0x22) ~%charges%~				 // charges
  WRITE_SHORT (%ab__new_abil_loc% + 0x24) ~%charge_removal%~		  // charge removal
  WRITE_SHORT (%ab__new_abil_loc% + 0x26) ~%flag%~					// flag -- followed by a 2 byte unknown
  WRITE_SHORT (%ab__new_abil_loc% + 0x2a) ~%proj_anim%~			   // projectile animation
  WRITE_SHORT (%ab__new_abil_loc% + 0x2c) ~%overhand%~				// overhand
  WRITE_SHORT (%ab__new_abil_loc% + 0x2e) ~%backhand%~				// backhand
  WRITE_SHORT (%ab__new_abil_loc% + 0x30) ~%thrust%~				  // thrust
  WRITE_SHORT (%ab__new_abil_loc% + 0x32) ~%bow%~					 // bow
  WRITE_SHORT (%ab__new_abil_loc% + 0x34) ~%xbow%~					// crossbow
  WRITE_SHORT (%ab__new_abil_loc% + 0x36) ~%sling%~				   // sling
END

I've not included anything for these two variables as this only adds a header and not an effect so there won't be an effect count nor would a effect loc be needed.

0x001e	  2 (word)	  Count of feature blocks
0x0020 	2 (word) 	Offset to feature blocks

However, if the macro add_item_effect only adjusts the existing values, then I see a need to give something to the effect location. Any ideas? Should it just be the same as the master effects location as assigned in the main portion of the itm file?

Share this post


Link to post
In tp2 "header" after author I apply:
PATCH_INCLUDE ~mymod/lib/mymacro.tpp~

In the tp2 component section I apply:

COPY ~somefile.xxx~ ~override~

SET what I want

SPRINT what I want

LAUNCH_PATCH_MACRO ~ADD_ITEM_HEADER~

PATCH_INCLUDE ~mymod/lib/mymacro.tpp~

and the following would be the tpp code:
DEFINE_PATCH_MACRO ~ADD_ITM_HEADER~ BEGIN

PATCH_IF (%SOURCE_SIZE% > 114) AND (%SOURCE_EXT% STRING_EQUAL_CASE ~itm~) BEGIN

However, if the macro add_item_effect only adjusts the existing values, then I see a need to give something to the effect location. Any ideas? Should it just be the same as the master effects location as assigned in the main portion of the itm file?
Not sure what you're saying on that last bit. ADD_ITEM_EFFECT is a different (WeiDU library) macro, right? If you wanted to use your macro, then LAUNCH_PATCH_MACRO ADD_ITEM_EFFECT after it, you could do that.

Share this post


Link to post

I tried it and it didn't work. I tried it as a macro and I tried it as a simple patch_include. It never added the bytes to apply the changes, but when I moved everything back inside the patch and did it "normally" (in the exact same location) it ran fine. I guess I should stick with regular code and let others create macros.

 

Also using weidu 208, the ADD_ITEM_EFFECT macro didn't work. I may have done something wrong, weidu instructions can be counter-intuitive sometimes. I ended up doing that manually. Although, the DELETE_ITEM_EFFECT worked perfectly when I used it on a different file.

Share this post


Link to post

Please post your working and non-working code. If the above is what you used for a macro (or the WeiDU macros), I'm sure you used something different than this:

COPY ~somefile.xxx~ ~override~
SET what I want
SPRINT what I want
LAUNCH_PATCH_MACRO ~ADD_ITEM_HEADER~

Edit: Are you really sure you want this?

PATCH_IF (%SOURCE_SIZE% > 114)

114 = 0x72, and I believe it should be IF > 0x71 for items (as the minimum valid size is 0x72).

Edited by Miloch

Share this post


Link to post
Please post your working and non-working code. If the above is what you used for a macro (or the WeiDU macros), I'm sure you used something different than this:

COPY ~somefile.xxx~ ~override~
SET what I want
SPRINT what I want
LAUNCH_PATCH_MACRO ~ADD_ITEM_HEADER~

That's exactly what I had in my component. When I couldn't get it to work, I reverted to the old method of doing it with in the file. I've since ditched all that non-working stuff. But, hey, if you can get one working with what is here, I'm sure there are people who might use it for custom items.

 

Edit: Are you really sure you want this?
PATCH_IF (%SOURCE_SIZE% > 114)

114 = 0x72, and I believe it should be IF > 0x71 for items (as the minimum valid size is 0x72).

Maybe I did mean 0x71. I've got the 0x71 in my mod right now so it could have just been a typo...

Share this post


Link to post
Something is broken.
Only the documentation, I think. Pretty sure I've used all these successfully, but yes, you do have to initialise all the variables in many cases (even if set to zero). IIRC, they are only "set by default" after the first time the macro runs, so you still need to set them all before that first run.

 

@plainab, if that was *exactly* what you had, no wonder it fails. "SET what I want" etc. is not valid syntax :). But I suspect it wasn't patching because your SOURCE_SIZE check was too high.

Share this post


Link to post
@plainab, if that was *exactly* what you had, no wonder it fails. "SET what I want" etc. is not valid syntax :). But I suspect it wasn't patching because your SOURCE_SIZE check was too high.
Grrrr.... :party:

Oh, well. I only needed to do one file and it is a custom file so I just did it with in the tp2 patch. It works there. Job is done. I'm happy. But I guess the macro library is not. So if you want to fix it up and polish it off and give it some "Documentation" so that it works and others can use it.... Be my guest. :D

Share this post


Link to post

I found myself in need of ADD_SPELL_ABILITY_HEADER but it is not among the new standard macros in WeiDU and I could not find such code anywhere so I decided to give it a try, based on Ascension64's ADD_ITEM_EFFECT. It appears to work as intended based on a couple of different tests and if it does not contain any glaring errors I may have overlooked, it would be cool if someone who knows how to do so made it into a WeiDU macro.

 

COPY_EXISTING ~myspell.spl~ ~override~
 READ_LONG 0x64 "abilitiesoffset"
 READ_SHORT 0x68 "#abilities"
 READ_LONG 0x6a "effectsoffset"

 //add ability header
 INSERT_BYTES "%abilitiesoffset%" 0x28

 //ability fields
 WRITE_BYTE "%abilitiesoffset%" 1 //type
 WRITE_BYTE ("%abilitiesoffset%" + 0x1) 2 //unknown
 WRITE_SHORT ("%abilitiesoffset%" + 0x2) 3 //ability icon location
 WRITE_ASCII ("%abilitiesoffset%" + 0x4) ~4~ //icon
 WRITE_BYTE ("%abilitiesoffset%" + 0xc) 5 //target type
 WRITE_BYTE ("%abilitiesoffset%" + 0xd) 6 //# targets
 WRITE_SHORT ("%abilitiesoffset%" + 0xe) 7 //range
 WRITE_SHORT ("%abilitiesoffset%" + 0x10) 8 //minimum level
 WRITE_SHORT ("%abilitiesoffset%" + 0x12) 9 //casting speed
 WRITE_SHORT ("%abilitiesoffset%" + 0x14) 10 //to hit
 WRITE_SHORT ("%abilitiesoffset%" + 0x16) 11 //dicesize
 WRITE_SHORT ("%abilitiesoffset%" + 0x18) 12 //# dice
 WRITE_SHORT ("%abilitiesoffset%" + 0x1a) 13 //enchanted
 WRITE_SHORT ("%abilitiesoffset%" + 0x1c) 14 //damage type
 WRITE_SHORT ("%abilitiesoffset%" + 0x1e) 15 //# effects 
 WRITE_SHORT ("%abilitiesoffset%" + 0x20) 16 //effect index
 WRITE_SHORT ("%abilitiesoffset%" + 0x22) 17 //# charges
 WRITE_SHORT ("%abilitiesoffset%" + 0x24) 18 //unknown
 WRITE_SHORT ("%abilitiesoffset%" + 0x26) 19 //projectile type

 //update # ability headers
 SET "%#abilities%" += 1
 WRITE_SHORT 0x68 "%#abilities%"

 //update effect offset
 SET "%effectsoffset%" += 0x28
 WRITE_LONG 0x6a "%effectsoffset%"
 END

Share this post


Link to post
Only the documentation, I think.

 

No, something is broken. ADD_SPELL_EFFECT does not update the effect index correctly when adding an effect to an empty ability header. If it is not empty, it works fine.

Edited by Echon

Share this post


Link to post

Is there any way we could take a look at the code behind these macros? Gort's link does not work, and there is no way we could extract them from the WeiDU executable.

 

-Galactygon

Share this post


Link to post

Simple. Download weidu source code from weidu.org, extract, look at WeiDU/src/tph.ml ... the macros are in there in plain text.

 

Send bigg fixes. :laugh:

Edited by erik

Share this post


Link to post
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...