Jump to content


Photo

a question to weidu guru


  • Please log in to reply
31 replies to this topic

#21 Gort

Gort
  • Validating
  • 614 posts

Posted 26 August 2007 - 09:53 PM

huh, 1 more question. I'm trying to delete an item from a store, and the code corrupts file completely
COPY_EXISTING ~arled.sto~ ~override~
READ_LONG 0x34 ~4sale_off~
READ_SHORT 0x38 ~4sale_num~
DELETE_BYTES (~%4sale_off%~ + 0x1c) 0x1c
SET ~4sale_num~ = (~%4sale_num%~ - 1)
WRITE_SHORT 0x34 ~%4sale_num%~
I'm not really sure about offsets here, I forgot the piece of code I used at home computer and wrote this from memory, but they are correct for sure there and the file is still corrupted.

#22 Rabain

Rabain

    God

  • Member
  • 653 posts

Posted 27 August 2007 - 06:13 AM

Use ADD_STORE_ITEM to replace an existing store item with another:

http://www.weidu.org...tml#@default373
A knight without armour in a savage land...

#23 Gort

Gort
  • Validating
  • 614 posts

Posted 27 August 2007 - 06:35 PM

I don't want to replace. I want to delete. Here's the exact code I use:
COPY_EXISTING ~arled.sto~ ~override~
  PATCH_IF (SOURCE_SIZE > 0x9a) BEGIN
	READ_LONG 0x34 "4sale_off"
	READ_LONG 0x38 "4sale_num"
	DELETE_BYTES ("%4sale_off%" + (1 * 0x1c)) 0x1c
  END
  WRITE_LONG 0x38 ("%4sale_num%" - 1)
BUT_ONLY_IF_IT_CHANGES
it should work perfect, just perfect. Yet it doesn't.

#24 SConrad

SConrad

    I swear to drunk I'm not God

  • Administrator
  • 11148 posts

Posted 27 August 2007 - 06:50 PM

This is most likely because you're not correcting the offsets after the items for sale offset. They need to be updated to ("%*_off%" - 0x1c), as you are deleting that many bytes previously in the file. :)

Posted Image Khadion NPC mod - Team leader, head designer
Posted Image Hubelpot NPC mod - Team leader, coder
Posted Image NPC Damage - Coder
Posted Image PC Soundsets - Coder, voice actor
Posted Image Brythe NPC mod - Designer
Posted Image DragonLance TC - Glory of Istar - Designer
Posted Image The NPC Interaction Expansion Project - Writer for Cernd, Sarevok
Posted Image The Jerry Zinger Show - Producer

Iron Modder 5 - Winner


#25 Gort

Gort
  • Validating
  • 614 posts

Posted 28 August 2007 - 09:33 PM

SConrad saves the day, as usual. Previosly I only deleted effects from spells, and it seems they are placed at the end of the file, so I didn't bother about other offsets. Thank you.

Edited by Gort, 28 August 2007 - 09:34 PM.


#26 SConrad

SConrad

    I swear to drunk I'm not God

  • Administrator
  • 11148 posts

Posted 28 August 2007 - 10:00 PM

You're welcome. It's a very common pitfall, and easy to overlook. :)

Posted Image Khadion NPC mod - Team leader, head designer
Posted Image Hubelpot NPC mod - Team leader, coder
Posted Image NPC Damage - Coder
Posted Image PC Soundsets - Coder, voice actor
Posted Image Brythe NPC mod - Designer
Posted Image DragonLance TC - Glory of Istar - Designer
Posted Image The NPC Interaction Expansion Project - Writer for Cernd, Sarevok
Posted Image The Jerry Zinger Show - Producer

Iron Modder 5 - Winner


#27 Gort

Gort
  • Validating
  • 614 posts

Posted 29 August 2007 - 06:17 PM

Use ADD_STORE_ITEM to replace an existing store item with another:

http://www.weidu.org...tml#@default373

do you know how does this function handle case when a store has duplicate entries?

Edited by Gort, 29 August 2007 - 06:20 PM.


#28 Gort

Gort
  • Validating
  • 614 posts

Posted 30 August 2007 - 06:44 PM

ok, while trying to construct regexp I need I've found that
COPY_EXISTING ~zzz.dlg~ ~override~
	  PATCH_IF (~abqw~ STRING_MATCHES_REGEXP ~ab\|cd~ = 0) BEGIN
		PATCH_PRINT ~yes~
	  END
	  ELSE BEGIN
		PATCH_PRINT ~no~
	  END
BUT_ONLY_IF_IT_CHANGES
returns "yes". Looks like a bug, doesn't it?

#29 Mike1072

Mike1072
  • Modder
  • 539 posts

Posted 30 August 2007 - 08:39 PM

ok, while trying to construct regexp I need I've found that

COPY_EXISTING ~zzz.dlg~ ~override~
	  PATCH_IF (~abqw~ STRING_MATCHES_REGEXP ~ab\|cd~ = 0) BEGIN
		PATCH_PRINT ~yes~
	  END
	  ELSE BEGIN
		PATCH_PRINT ~no~
	  END
BUT_ONLY_IF_IT_CHANGES
returns "yes". Looks like a bug, doesn't it?

I'm no WeiDU guru, but I have a little bit of experience with regular expressions. It looks like 'ab\|cd' is matching the 'ab' and correctly returning 0.

#30 Gort

Gort
  • Validating
  • 614 posts

Posted 30 August 2007 - 09:06 PM

my string is "abqw", not "ab". And "match" means "match", not "contain" (for which there's a separate function STRING_CONTAINS_REGEXP)

Edited by Gort, 30 August 2007 - 09:11 PM.


#31 Mike1072

Mike1072
  • Modder
  • 539 posts

Posted 30 August 2007 - 10:29 PM

my string is "abqw", not "ab". And "match" means "match", not "contain" (for which there's a separate function STRING_CONTAINS_REGEXP)

Ah, my experiences with regular expressions would provide a hit if the text contained the regexp anywhere, and I thought I recalled that being referred to as "matching". Seems like that's not the case here, though - thanks for the info.

#32 Gort

Gort
  • Validating
  • 614 posts

Posted 31 August 2007 - 03:03 AM

SConrad?:D