Jump to content


Photo

rhomboidspace


  • Please log in to reply
7 replies to this topic

#1 rhomboidspace

rhomboidspace
  • Member
  • 11 posts

Posted 04 February 2009 - 08:08 AM

I would like to make a patch that increases the capacity of bags, but make the capacity different based on what the bag carries. I was looking for a patch if command that compairs the name of the store to the the type of bag, but can't find a direct route to do this, any sugestions.  I guess i could try compairing the item name that the sto matches up with since there is a way to check the string names if items, but that seems kind of the long way around, is there a shorter method that i might have missed?

Also how do you copy an existing resource, but rename the copy?

PS: this is relating to using WIEDU.

Edited by rhomboidspace, 04 February 2009 - 08:12 AM.


#2 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 04 February 2009 - 09:33 AM

I would like to make a patch that increases the capacity of bags, but make the capacity different based on what the bag carries.

You can check which item types a bag can 'buy'. Something like
COPY_EXISTING_REGEXP GLOB ~.*\.sto~ ~override~
  READ_LONG 0x8 store_type
  PATCH_IF (store_type=5) BEGIN // if container
	SET arrow=0
	SET amulet=0
	SET armor=0
	SET scroll=0
// ... and so on...	
	READ_LONG 0x2c type_off
	READ_LONG 0x30 type_num
	FOR (i=0;i<type_num;i+=1) BEGIN
	  READ_LONG (type_off+i*0x4) item_type
	  PATCH_IF (item_type=1) BEGIN // if buys amulets
		SET amulet=1
	  END
	  PATCH_IF (item_type=5) BEGIN
		SET arrow=1
	  END
	  PATCH_IF (item_type=11) BEGIN
		SET scroll=1
	  END
//... and so on...
	END // end of the FOR loop
	PATCH_IF ( (amulet=1) AND (armor=0) ) BEGIN // buy amulets but not armor, a bit unreliable with just two checks but I hope you've got the idea
	  WRITE_SHORT 0x22 100 // set the capacity to 100
	END
	PATCH_IF (armor=1) BEGIN // if it buys armor then it likely buys everything
	  WRITE_SHORT 0x22 200
	END
//... and so on again...
  END // initial PATCH_IF (store_type=5)
BUT_ONLY_IF_IT_CHANGES

Also how do you copy an existing resource, but rename the copy?

COPY_EXISTING ~oldname~ ~dir/newname~

Edited by GeN1e, 04 February 2009 - 09:35 AM.

Retired from modding.


#3 rhomboidspace

rhomboidspace
  • Member
  • 11 posts

Posted 04 February 2009 - 03:09 PM

COPY_EXISTING ~oldname~ ~dir/newname~


i'm looking for a method for using regexp, how to search for files who's names follow a pattern, and change some characters in the filename and keep others, i guess the regexp tutorial isn't quite fully understandable to me.

#4 Sasha Al'Therin

Sasha Al'Therin
  • Modder
  • 615 posts

Posted 04 February 2009 - 04:27 PM

COPY_EXISTING ~oldname~ ~dir/newname~


i'm looking for a method for using regexp, how to search for files who's names follow a pattern, and change some characters in the filename and keep others, i guess the regexp tutorial isn't quite fully understandable to me.

First off what you are wanting is hard to do on the fly. It's not impossible but hard. You have to do somethings that really should not be done because if you screw up the code it can cause untold problems anything from a continues loop during install to a full crash during the game.
It is generally a bad idea to copy a resource into weidu's memory and then to copy the same resource again. However, if you are careful not to make any changes to the outer instance of the resource and you rename the resource when you do make changes then you should be safe.

Here is an example:

OUTER_SET count = 0
OUTER_SPRINT modprefix ~ab~ //that's mine don't use it
COPY_EXISTING_REGEXP GLOB ~^.+\.sto$~ ~override~
PATCH_IF (~%SOURCE_FILE%~ STRING_EQUALS_CASE ~^bag.*~) BEGIN
SET count = %count% + 1
SPRINT newfilename ~%modprefix%_bag%count%~
SPRINT oldfilename ~%SOURCE_FILE%~
INNER_ACTION BEGIN
COPY_EXISTING ~%oldfilename%.sto~ ~override\%newfilename%.sto~
//make your patch changes here to increase or decrease a bag's container capacity
BUT_ONLY_IF_IT_CHANGES
END
END
BUT_ONLY_IF_IT_CHANGES

To explain what is done:
The outer-set sets the variable count to 0
The outer-sprint sets modprefix to ab which is my prefix so use something else
The copy_existing_regexp glob will copy all store file including mod added files (drop the glob to not access mod added files)
The patch-if will only let you work with those files that match your criteria in this example any store that starts with bag
the set increase our count variable by 1
the first sprint assigns the new file name by which for the first file to be modified will be ab_bag1
the second sprint assigns the the original file name to a variable becomes in some instances weidu will change the value of SOURCE_FILE even though you don't want it to. (better to be safe than sorry)
The inner-action tells weidu that you are starting a new action inside the current action
The copy_existing copies the original store file that you want to modify into the new file name that you want to give it.
Following this will be whatever changes you wish to make to the capacity of the container
The first boiic ends the second copy
The first end ends the inner-action
The second end ends the patch-if
and the last boiic ends the first copy
The first copy will let you do a regexp search of all sto files.
The patch_if will only let you work on those store files that match your criteria
The first sprint assigns a new name

You could also try the following. It is safer by far, but could prove to be less powerful in searching and changing the file name as you see fit.

OUTER_SET num = 0
OUTER_SPRINT modprefix ~ab~ //that's mine don't use it
COPY_EXISTING_REGEXP GLOB ~^bag.*\.sto$~ ~override\%ab%_bag%num%.sto~
SET num = %num% + 1
//make your patch changes here to increase or decrease a bag's container capacity
BUT_ONLY_IF_IT_CHANGES

Here we set num to 0 and we set our modprefix
We then copy the resource but look for what we want in the file name to begin with in this case any store file that begins with bag. At the same time we tell it to save the store with a new name which in this case the first store to be modified would be ab_bag0.sto
We then increase num by one so that as files are read and modified the new file names will be different because the value of num has been increased.


The first option allows you to search for multiple file name configurations by having multiple patch-if statements. The second option requires you to have an entirely new block of code for each file name configuration that you are wanting to search for and modify.

I'm sure this is all clear as mud. I don't even have a good grasp of the regexp myself, but I do know what has worked for me and what has worked for others...

My working mods:
an AI Party Script for BG2 game engine DOWNLOAD LINK ONLY!
Interactive Tweaks for BG series with some IWD support. DOWNLOAD LINK ONLY!
Rest For 8 Hours an IWD mod
-------------------------------------------
My contributions: BG1Fixpack, BG1Tweaks
On Hold: Solestia an NPC for SOA
-------------------------------------------
My website: http://sasha-altheri...s.com/index.htm


#5 Mike1072

Mike1072
  • Modder
  • 539 posts

Posted 04 February 2009 - 06:18 PM

First off what you are wanting is hard to do on the fly. It's not impossible but hard. You have to do somethings that really should not be done because if you screw up the code it can cause untold problems anything from a continues loop during install to a full crash during the game.
It is generally a bad idea to copy a resource into weidu's memory and then to copy the same resource again. However, if you are careful not to make any changes to the outer instance of the resource and you rename the resource when you do make changes then you should be safe.

I think this could be done a little less dodgily (but probably not any quicker) if you used arrays. One pass through the files to add the ones you want to the array, and then another that copies, renames, and modifies those as you see fit.

#6 rhomboidspace

rhomboidspace
  • Member
  • 11 posts

Posted 06 February 2009 - 09:52 AM

i've figured out how to selectively increase the quanities of bags, but what i'm still having trouble with is copying animation bams for my nice little 1h crossbow.  for now i'm just using normal crossbow animations for all the non-attack animations, and untill i get the patience to make 1h animations that work just using dagger thrust animations for attacking.  on my system i just found all the animations needed and manually copied and renamed them, but I really would like to find some kind of method using COPY_EXISTING_REGEXP to extract all proper animations, and rename them, that way none of possible the animations are missed, to prevent crashes.  any sugestions.  even if someone could slightly explain better how _REGEXP works in renaming might allow me to be able to figure it out myself.

#7 Mike1072

Mike1072
  • Modder
  • 539 posts

Posted 06 February 2009 - 01:04 PM

i've figured out how to selectively increase the quanities of bags, but what i'm still having trouble with is copying animation bams for my nice little 1h crossbow. for now i'm just using normal crossbow animations for all the non-attack animations, and untill i get the patience to make 1h animations that work just using dagger thrust animations for attacking. on my system i just found all the animations needed and manually copied and renamed them, but I really would like to find some kind of method using COPY_EXISTING_REGEXP to extract all proper animations, and rename them, that way none of possible the animations are missed, to prevent crashes. any sugestions. even if someone could slightly explain better how _REGEXP works in renaming might allow me to be able to figure it out myself.

If you have a concrete list of the files you wish to copy, it's probably easier to just do COPY_EXISTING on that list, renaming each one individually. Given this list of files, a text editor with regular expression search/replace capability can be a quick way to generate the renamed files if you are renaming on some sort of pattern.

Example of normal COPY_EXISTING on multiple files:
COPY_EXISTING ~file1~ ~override/renamed1~
			  ~file2~ ~override/renamed2~
			  ~file3~ ~override/renamed3~


#8 Sasha Al'Therin

Sasha Al'Therin
  • Modder
  • 615 posts

Posted 06 February 2009 - 01:37 PM

First off what you are wanting is hard to do on the fly. It's not impossible but hard. You have to do somethings that really should not be done because if you screw up the code it can cause untold problems anything from a continues loop during install to a full crash during the game.
It is generally a bad idea to copy a resource into weidu's memory and then to copy the same resource again. However, if you are careful not to make any changes to the outer instance of the resource and you rename the resource when you do make changes then you should be safe.

I think this could be done a little less dodgily (but probably not any quicker) if you used arrays. One pass through the files to add the ones you want to the array, and then another that copies, renames, and modifies those as you see fit.

You may be right. I don't know everything there is to know about weidu. I certainly don't know how to use an array or how to even create one...

My working mods:
an AI Party Script for BG2 game engine DOWNLOAD LINK ONLY!
Interactive Tweaks for BG series with some IWD support. DOWNLOAD LINK ONLY!
Rest For 8 Hours an IWD mod
-------------------------------------------
My contributions: BG1Fixpack, BG1Tweaks
On Hold: Solestia an NPC for SOA
-------------------------------------------
My website: http://sasha-altheri...s.com/index.htm