Jump to content

WeiDU store patching - cures


aVENGER_(RR)

Recommended Posts

At the moment, I'm using this code to expand the curative spell selection of temple priests:

 

COPY_EXISTING_REGEXP GLOB ~^.+\.sto$~ ~override~									  // parses through all stores in the game (even those added by mods)
 READ_LONG 0x34 "sale_offset"
 READ_LONG 0x38 "sale_num"
 READ_LONG 0x2c "item_offset"
 READ_LONG 0x4c "drink_offset"
 READ_LONG 0x70 "cure_offset"
 READ_LONG 0x74 "cure_number"
PATCH_IF ("%cure_number%" > 0) BEGIN												  // Only patch stores which offer temple services
 SET "count" = 0																	 // New cure count
 FOR (index = 0; index < cure_number; index = index + 1) BEGIN
READ_ASCII ("%cure_offset%" +		("%index%" * 0x0c)) "cure"
PATCH_IF ("%cure%" STRING_EQUAL ~SPPR307~) AND (NOT FILE_CONTAINS_EVALUATED(~%SOURCE_FILE%~ ~SPPR317~)) BEGIN  // Add Cure Disease below Remove Curse if not already available in the temple
  INSERT_BYTES  ("%cure_offset%" + 0x00 + (("%index%" + 1) * 0x0c)) 0x0c
	WRITE_ASCII ("%cure_offset%" + 0x00 + (("%index%" + 1) * 0x0c)) ~SPPR317~ #8  // spell reference (Cure Disease)
	WRITE_LONG  ("%cure_offset%" + 0x08 + (("%index%" + 1) * 0x0c)) 200		   // spell price
SET "count" = ("count" + 1)												   // update new cure count
END
PATCH_IF ("%cure%" STRING_EQUAL ~SPPR401~) AND (NOT FILE_CONTAINS_EVALUATED(~%SOURCE_FILE%~ ~SPPR404~)) BEGIN  // Adds Neutralize Poison below Cure Serious Wounds if not already available in the temple
  INSERT_BYTES  ("%cure_offset%" + 0x00 + (("%index%" + 1) * 0x0c)) 0x0c
	WRITE_ASCII ("%cure_offset%" + 0x00 + (("%index%" + 1) * 0x0c)) ~SPPR404~ #8  // spell reference (Neutralize Poison)
	WRITE_LONG  ("%cure_offset%" + 0x08 + (("%index%" + 1) * 0x0c)) 250		   // spell price
SET "count" = ("count" + 1)												   // update new cure count
END
PATCH_IF ("%cure%" STRING_EQUAL ~SPPR404~) AND (NOT FILE_CONTAINS_EVALUATED(~%SOURCE_FILE%~ ~SPPR417~)) BEGIN  // Adds Lesser Restoration below Neutralize Poison if not already available in the temple
  INSERT_BYTES  ("%cure_offset%" + 0x00 + (("%index%" + 1) * 0x0c)) 0x0c
	WRITE_ASCII ("%cure_offset%" + 0x00 + (("%index%" + 1) * 0x0c)) ~SPPR417~ #8  // spell reference (Lesser Restoration)
	WRITE_LONG  ("%cure_offset%" + 0x08 + (("%index%" + 1) * 0x0c)) 250		   // spell price
SET "count" = ("count" + 1)												   // update new cure count
END
PATCH_IF ("%cure%" STRING_EQUAL ~SPPR502~) AND (NOT FILE_CONTAINS_EVALUATED(~%SOURCE_FILE%~ ~RR#PR514~)) BEGIN  // Add Mass Cure below Cure Critical Wounds if not already available in the temple
  INSERT_BYTES  ("%cure_offset%" + 0x00 + (("%index%" + 1) * 0x0c)) 0x0c
	WRITE_ASCII ("%cure_offset%" + 0x00 + (("%index%" + 1) * 0x0c)) ~RR#PR514~ #8 // spell reference (custom Mass Cure, targets party)
	WRITE_LONG  ("%cure_offset%" + 0x08 + (("%index%" + 1) * 0x0c)) 300		   // spell price
SET "count" = ("count" + 1)												   // update new cure count
END
 END
  WRITE_LONG 0x74 ("%cure_number%" + "%count%")									  // update total number of available cures
// correct offsets
READ_LONG 0x74 "cure_number"
READ_LONG 0x2c "sale_offset"
READ_LONG 0x2c "item_offset"
READ_LONG 0x4c "drink_offset"
PATCH_IF NOT ("%item_offset%" < "%sale_offset%") BEGIN
  WRITE_LONG 0x2c ("%item_offset%" + ("%count%" * 0x0c))
END
PATCH_IF NOT ("%drink_offset%" < "%sale_offset%") BEGIN
  WRITE_LONG 0x4c ("%drink_offset%" + ("%count%" * 0x0c))
END
PATCH_IF NOT ("%cure_offset%" < "%sale_offset%") BEGIN
  WRITE_LONG 0x70 ("%sale_offset%" + ("%count%" * 0x0c))
END
END
BUT_ONLY_IF_IT_CHANGES

 

However, it seems that I'm not re-indexing the stores properly after patching-in the new spells. This appears to have little effect on temple stores from the unmodded game (which are indexed in a standard manner) but I've received reports that it can corrupt stores added by some older mods which are indexed in a non-standard manner. If someone could show me how to modify the patching/re-indexing code in order to cater for such cases I'd be much obliged.

Link to comment
// correct offsets
READ_LONG 0x74 "cure_number"
READ_LONG 0x2c "sale_offset"
READ_LONG 0x2c "item_offset"
READ_LONG 0x4c "drink_offset"
PATCH_IF NOT ("%item_offset%" < "%sale_offset%") BEGIN
  WRITE_LONG 0x2c ("%item_offset%" + ("%count%" * 0x0c))
END
PATCH_IF NOT ("%drink_offset%" < "%sale_offset%") BEGIN
  WRITE_LONG 0x4c ("%drink_offset%" + ("%count%" * 0x0c))
END
PATCH_IF NOT ("%cure_offset%" < "%sale_offset%") BEGIN
  WRITE_LONG 0x70 ("%sale_offset%" + ("%count%" * 0x0c))
END
END
BUT_ONLY_IF_IT_CHANGES

 

However, it seems that I'm not re-indexing the stores properly after patching-in the new spells. This appears to have little effect on temple stores from the unmodded game (which are indexed in a standard manner) but I've received reports that it can corrupt stores added by some older mods which are indexed in a non-standard manner. If someone could show me how to modify the patching/re-indexing code in order to cater for such cases I'd be much obliged.

The offset that sale_offset is read from should be 0x34.

 

Your bigger problem though is that you are comparing all other offsets to sale_offset, when you should be comparing all other offsets to cure_offset.

Link to comment

Well, the code reads the same value for buy and sell item lists (so always alters 0x2C). Your code is also funky at 0x70 (WRITE_LONG sale_offset instead of cure_offset).

 

As long as you have the checks (which you already do), you should be OK. As Mike1072 points out, since you're adding at cure_offset, you only want to patch the offsets > cure_offset, which should do the right thing.

Link to comment

Thanks a bunch guys. If I understand you correctly, changing the re-indexing block to this should resolve the issue:

 

// correct offsets
READ_LONG 0x74 "cure_number"
READ_LONG 0x34 "sale_offset"
READ_LONG 0x2c "item_offset"
READ_LONG 0x4c "drink_offset"
READ_LONG 0x70 "cure_offset"
PATCH_IF ("%item_offset%" > "%cure_offset%") BEGIN
  WRITE_LONG 0x2c ("%item_offset%" + ("%count%" * 0x0c))
END
PATCH_IF ("%drink_offset%" > "%cure_offset%") BEGIN
  WRITE_LONG 0x4c ("%drink_offset%" + ("%count%" * 0x0c))
END
PATCH_IF ("%sale_offset%" > "%cure_offset%") BEGIN
  WRITE_LONG 0x34 ("%sale_offset%" + ("%count%" * 0x0c))
END

 

I'll do some testing when I get back from work.

Link to comment

If it helps for comparison, here's CamDawg's "add cures to BG [Tutu || BGT ] temples"

 

  /* CamDawg's Temple Healing Fix */
 /* give all stores the normal suite of cures available */
 COPY_EXISTING_REGEXP GLOB ~^.+\.sto$~ ~override~
READ_BYTE 0x10 "flags" ELSE 0
PATCH_IF (("%flags%" BAND 0b00010000) = 0b00010000) BEGIN // if sures available; also filters out invalid files
  READ_LONG 0x2c "buy_off"   ELSE 0
  READ_LONG 0x34 "sale_off"  ELSE 0
  READ_LONG 0x4c "drink_off" ELSE 0
  READ_LONG 0x70 "cure_off"  ELSE 0
  READ_LONG 0x74 "cure_num"  ELSE 0
  SET "new_cure" = 0
  SET "sppr103" = 0 // cure light wounds
  SET "sppr212" = 0 // slow poison
  SET "sppr303" = 0 // dispel magic
  SET "sppr307" = 0 // remove curse
  SET "sppr401" = 0 // cure serious wounds
  SET "sppr502" = 0 // cure light wounds
  SET "sppr504" = 0 // raise dead
  SET "sppr607" = 0 // cure critical wounds
  SET "sppr712" = 0 // resurrection
  SET "sppr713" = 0 // greater restoration
  // check if cures already available
  FOR (index = 0; index < cure_num; index = index + 1) BEGIN
	READ_ASCII ("%cure_off%" + ("%index%" * 0x0c)) "resref"
	PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr103" = 0) BEGIN
	  SET "sppr103" = 1
	END ELSE
	PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr212" = 0) BEGIN
	  SET "sppr212" = 1
	END ELSE
	PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr303" = 0) BEGIN
	  SET "sppr303" = 1
	END ELSE
	PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr307" = 0) BEGIN
	  SET "sppr307" = 1
	END ELSE
	PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr401" = 0) BEGIN
	  SET "sppr401" = 1
	END ELSE
	PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr502" = 0) BEGIN
	  SET "sppr502" = 1
	END ELSE
	PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr504" = 0) BEGIN
	  SET "sppr504" = 1
	END ELSE
	PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr607" = 0) BEGIN
	  SET "sppr607" = 1
	END ELSE
	PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr712" = 0) BEGIN
	  SET "sppr712" = 1
	END ELSE
	PATCH_IF ("%resref%" STRING_COMPARE_CASE "sppr713" = 0) BEGIN
	  SET "sppr713" = 1
	END
  END
  // add cures if not already present
  PATCH_IF ("%sppr103%" = 0) BEGIN // if cure not already available
	INSERT_BYTES  ("%cure_off%" +		("%cure_num%" * 0x0c)) 0x0c
	  WRITE_ASCII ("%cure_off%" +		("%cure_num%" * 0x0c)) ~sppr103~ // resref
	  WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 50		// price
	SET "cure_num" = "%cure_num%" + 1
	SET "new_cure" = "%new_cure%" + 1
  END
  PATCH_IF ("%sppr212%" = 0) BEGIN // if cure not already available
	INSERT_BYTES  ("%cure_off%" +		("%cure_num%" * 0x0c)) 0x0c
	  WRITE_ASCII ("%cure_off%" +		("%cure_num%" * 0x0c)) ~sppr212~ // resref
	  WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 150	   // price
	SET "cure_num" = "%cure_num%" + 1
	SET "new_cure" = "%new_cure%" + 1
  END
  PATCH_IF ("%sppr303%" = 0) BEGIN // if cure not already available
	INSERT_BYTES  ("%cure_off%" +		("%cure_num%" * 0x0c)) 0x0c
	  WRITE_ASCII ("%cure_off%" +		("%cure_num%" * 0x0c)) ~sppr303~ // resref
	  WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 200	   // price
	SET "cure_num" = "%cure_num%" + 1
	SET "new_cure" = "%new_cure%" + 1
  END
  PATCH_IF ("%sppr307%" = 0) BEGIN // if cure not already available
	INSERT_BYTES  ("%cure_off%" +		("%cure_num%" * 0x0c)) 0x0c
	  WRITE_ASCII ("%cure_off%" +		("%cure_num%" * 0x0c)) ~sppr307~ // resref
	  WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 500	   // price
	SET "cure_num" = "%cure_num%" + 1
	SET "new_cure" = "%new_cure%" + 1
  END
  PATCH_IF ("%sppr401%" = 0) BEGIN // if cure not already available
	INSERT_BYTES  ("%cure_off%" +		("%cure_num%" * 0x0c)) 0x0c
	  WRITE_ASCII ("%cure_off%" +		("%cure_num%" * 0x0c)) ~sppr401~ // resref
	  WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 100	   // price
	SET "cure_num" = "%cure_num%" + 1
	SET "new_cure" = "%new_cure%" + 1
  END
  PATCH_IF ("%sppr502%" = 0) BEGIN // if cure not already available
	INSERT_BYTES  ("%cure_off%" +		("%cure_num%" * 0x0c)) 0x0c
	  WRITE_ASCII ("%cure_off%" +		("%cure_num%" * 0x0c)) ~sppr502~ // resref
	  WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 200	   // price
	SET "cure_num" = "%cure_num%" + 1
	SET "new_cure" = "%new_cure%" + 1
  END
  PATCH_IF ("%sppr504%" = 0) BEGIN // if cure not already available
	INSERT_BYTES  ("%cure_off%" +		("%cure_num%" * 0x0c)) 0x0c
	  WRITE_ASCII ("%cure_off%" +		("%cure_num%" * 0x0c)) ~sppr504~ // resref
	  WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 750	   // price
	SET "cure_num" = "%cure_num%" + 1
	SET "new_cure" = "%new_cure%" + 1
  END
  PATCH_IF ("%sppr607%" = 0) BEGIN // if cure not already available
	INSERT_BYTES  ("%cure_off%" +		("%cure_num%" * 0x0c)) 0x0c
	  WRITE_ASCII ("%cure_off%" +		("%cure_num%" * 0x0c)) ~sppr607~ // resref
	  WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 750	   // price
	SET "cure_num" = "%cure_num%" + 1
	SET "new_cure" = "%new_cure%" + 1
  END
  PATCH_IF ("%sppr712%" = 0) BEGIN // if cure not already available
	INSERT_BYTES  ("%cure_off%" +		("%cure_num%" * 0x0c)) 0x0c
	  WRITE_ASCII ("%cure_off%" +		("%cure_num%" * 0x0c)) ~sppr712~ // resref
	  WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 1000	  // price
	SET "cure_num" = "%cure_num%" + 1
	SET "new_cure" = "%new_cure%" + 1
  END
  PATCH_IF ("%sppr713%" = 0) BEGIN // if cure not already available
	INSERT_BYTES  ("%cure_off%" +		("%cure_num%" * 0x0c)) 0x0c
	  WRITE_ASCII ("%cure_off%" +		("%cure_num%" * 0x0c)) ~sppr713~ // resref
	  WRITE_LONG  ("%cure_off%" + 0x08 + ("%cure_num%" * 0x0c)) 750	   // price
	SET "cure_num" = "%cure_num%" + 1
	SET "new_cure" = "%new_cure%" + 1
  END
  // adjust offsets and counts if cures inserted
  PATCH_IF ("%new_cure%" > 0) BEGIN
	WRITE_LONG 0x74 "%cure_num%"
	PATCH_IF ("%buy_off%" > "%cure_off%") BEGIN
	  WRITE_LONG 0x2c ("%buy_off%" + ("%new_cure%" * 0x0c))
	END
	PATCH_IF ("%sale_off%" > "%cure_off%") BEGIN
	  WRITE_LONG 0x34 ("%sale_off%" + ("%new_cure%" * 0x0c))
	END
	PATCH_IF ("%drink_off%" > "%cure_off%") BEGIN
	  WRITE_LONG 0x4c ("%drink_off%" + ("%new_cure%" * 0x0c))
	END
  END
END
BUT_ONLY_IF_IT_CHANGES

Link to comment
If it helps for comparison, here's CamDawg's "add cures to BG [Tutu || BGT ] temples"

 

It sure does. Thanks a bunch! :)

 

BTW, which mod is that code from? I remember searching high and low for cure patching examples when I conceived this component, but I couldn't find any in the obvious places so I wrote my own from scratch. It would have certainly saved me a lot of headaches back then. :)

Link to comment

Archived

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

×
×
  • Create New...