Author Topic: A hex upon ye!  (Read 1239 times)

Offline Andyr

  • Dance Commander
  • PPG
  • Planewalker
  • *****
  • Posts: 3178
  • Gender: Male
    • The Gibberlings Three IE mod community
A hex upon ye!
« on: April 15, 2005, 06:10:43 PM »
I am trying to add Wraithform to a store without using ADD_CRE_ITEM for the next UB so it does not appear on the top of the style. I have borrowed code from Cam from Tutu Tweaks, but need a hand adapting something. This is what I have at the moment:

Code: [Select]
COPY_EXISTING ~scrolls.sto~ ~override/scrolls.sto~     /* The Pen and Parchment Store */
  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"
  SET "orig_sale_num" = "%sale_num%"
  SET "wraithform_added" = 0
  SET "wraithform_insert" = 0
  WHILE ("%sale_num%" > 0) BEGIN
    READ_LONG ("%sale_offset%" +        (("%sale_num%" - 1) * 0x1C)) "item1"
    READ_LONG ("%sale_offset%" + 0x04 + (("%sale_num%" - 1) * 0x1C)) "item2"
    PATCH_IF (("%item1%" = 0x51314C524353) AND ("%item2%" = 0X51314C524353) AND ("%wraithform_insert%" = 0)) BEGIN // between Vampiric Touch and Ghost Armour
      SET "wraithform_insert" = "%sale_num%"
    END
    SET "sale_num" = ("%sale_num%" - 1)
  END
  PATCH_IF ("%wraithform_insert%" > 0) BEGIN
    WRITE_LONG 0x38 ("%orig_sale_num%" + 1)
    INSERT_BYTES ("%sale_offset%" + ("%wraithform_insert%" * 0x1C)) 28
      WRITE_ASCII ("%sale_offset%" +        ("%wraithform_insert%" * 0x1C)) ~u!scrl03~
      WRITE_LONG  ("%sale_offset%" + 0x10 + ("%wraithform_insert%" * 0x1C)) 1 // identified
      WRITE_LONG  ("%sale_offset%" + 0x14 + ("%wraithform_insert%" * 0x1C)) 5 // quantity
    PATCH_IF NOT ("%item_offset%" < "%sale_offset%") BEGIN
      WRITE_LONG 0x2C ("%item_offset%" + 0x1C)
    END
    PATCH_IF NOT ("%drink_offset%" < "%sale_offset%") BEGIN
      WRITE_LONG 0x4C ("%drink_offset%" + 0x1C)
    END
    PATCH_IF NOT ("%cure_offset%" < "%sale_offset%") BEGIN
      WRITE_LONG 0x70 ("%cure_offset%" + 0x1C)
    END
  END

The problem is in here.

Code: [Select]
    PATCH_IF (("%item1%" = 0x51314C524353) AND ("%item2%" = 0X51314C524353) AND ("%wraithform_insert%" = 0)) BEGIN // between Vampiric Touch and Ghost Armour
Looking at Cam's code, I had assumed this was the hex for the name for the .ITM files I was looking to place it in between. However, WeiDU can't convert this to an integer, and the sequence is longer than what Cam's original code had (0x then 8 characters, not 12 or 10 as I have). So, what I'd like to know is how can I convert item filenames to hex/ASCII/whatever it wants? :) I used NI for the above example, selecting the .ITM name and then "view as hex".
"We are the Gibberlings Three, as merry a band as you ever did see..." - Home of IE mods

<jcompton> Suggested plugs include "Click here so Compton doesn't ban me. http://www.pocketplane.net/ub"

I am unfortunately not often about these days so the best way to get hold of me is via email.

Offline Andyr

  • Dance Commander
  • PPG
  • Planewalker
  • *****
  • Posts: 3178
  • Gender: Male
    • The Gibberlings Three IE mod community
Re: A hex upon ye!
« Reply #1 on: April 15, 2005, 06:38:59 PM »
Ok, Sim says using ASCII instead and STRING_COMPARE. He also suggest we don't need to check for the item after. The following code is adding it to the bottom of the .STO file, though. Anyone got any more ideas? :)

Code: [Select]
COPY_EXISTING ~scrolls.sto~ ~override/scrolls.sto~     /* The Pen and Parchment Store */
  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"
  SET "orig_sale_num" = "%sale_num%"
  SET "wraithform_added" = 0
  SET "wraithform_insert" = 0
  WHILE ("%sale_num%" > 0) BEGIN
    READ_ASCII ("%sale_offset%" +        (("%sale_num%" - 1) * 0x1C)) "item1"
    READ_ASCII ("%sale_offset%" + 0x04 + (("%sale_num%" - 1) * 0x1C)) "item2"
//    PATCH_IF (("%item1%" STRING_COMPARE_CASE "scrl1Q") = 0) AND ("%item2%" STRING_COMPARE_CASE "scrl1T") = 0) AND ("%wraithform_insert%" = 0)) BEGIN
    PATCH_IF ((("%item%" STRING_COMPARE_CASE "scrl1Q") = 0) AND ("%wraithform_insert%" = 0)) BEGIN
// between Vampiric Touch and Ghost Armour
      SET "wraithform_insert" = "%sale_num%"
    END
    SET "sale_num" = ("%sale_num%" - 1)
  END
  PATCH_IF ("%wraithform_insert%" > 0) BEGIN
    WRITE_LONG 0x38 ("%orig_sale_num%" + 1)
    INSERT_BYTES ("%sale_offset%" + ("%wraithform_insert%" * 0x1C)) 28
      WRITE_ASCII ("%sale_offset%" +        ("%wraithform_insert%" * 0x1C)) ~u!scrl03~
      WRITE_LONG  ("%sale_offset%" + 0x10 + ("%wraithform_insert%" * 0x1C)) 1 // identified
      WRITE_LONG  ("%sale_offset%" + 0x14 + ("%wraithform_insert%" * 0x1C)) 5 // quantity
    PATCH_IF NOT ("%item_offset%" < "%sale_offset%") BEGIN
      WRITE_LONG 0x2C ("%item_offset%" + 0x1C)
    END
    PATCH_IF NOT ("%drink_offset%" < "%sale_offset%") BEGIN
      WRITE_LONG 0x4C ("%drink_offset%" + 0x1C)
    END
    PATCH_IF NOT ("%cure_offset%" < "%sale_offset%") BEGIN
      WRITE_LONG 0x70 ("%cure_offset%" + 0x1C)
    END
  END

Note: the commented-out line was my attempt to check for both items to see if that fixed it, but uncommenting it and getting rid of the PATCH_IF in the example above introduces a parse error.

WHILE loops > me. :(
"We are the Gibberlings Three, as merry a band as you ever did see..." - Home of IE mods

<jcompton> Suggested plugs include "Click here so Compton doesn't ban me. http://www.pocketplane.net/ub"

I am unfortunately not often about these days so the best way to get hold of me is via email.

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 832
  • Dreaming of a red Xmas
    • The Gibberlings Three
Re: A hex upon ye!
« Reply #2 on: April 15, 2005, 07:23:33 PM »
Typo.

Code: [Select]
    READ_ASCII ("%sale_offset%" + 0x04 + (("%sale_num%" - 1) * 0x1C)) "item2"
is no longer necessary, and in

Code: [Select]
    READ_ASCII ("%sale_offset%" +        (("%sale_num%" - 1) * 0x1C)) "item1"
"item1" should be "item".

The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline Andyr

  • Dance Commander
  • PPG
  • Planewalker
  • *****
  • Posts: 3178
  • Gender: Male
    • The Gibberlings Three IE mod community
Re: A hex upon ye!
« Reply #3 on: April 15, 2005, 07:29:08 PM »
This code works, for future reference:

Code: [Select]
COPY_EXISTING ~scrolls.sto~ ~override/scrolls.sto~     /* The Pen and Parchment Store */
  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"
  SET "orig_sale_num" = "%sale_num%"
  SET "wraithform_added" = 0
  SET "wraithform_insert" = 0
  WHILE ("%sale_num%" > 0) BEGIN
    READ_ASCII ("%sale_offset%" +        (("%sale_num%" - 1) * 0x1C)) "item"
    PATCH_IF ((("%item%" STRING_COMPARE_CASE "scrl1Q") = 0) AND ("%wraithform_insert%" = 0)) BEGIN
      SET "wraithform_insert" = "%sale_num%"
    END
    SET "sale_num" = ("%sale_num%" - 1)
  END
  PATCH_IF ("%wraithform_insert%" > 0) BEGIN
    WRITE_LONG 0x38 ("%orig_sale_num%" + 1)
    INSERT_BYTES ("%sale_offset%" + ("%wraithform_insert%" * 0x1C)) 28
      WRITE_ASCII ("%sale_offset%" +        ("%wraithform_insert%" * 0x1C)) ~u!scrl03~
      WRITE_LONG  ("%sale_offset%" + 0x10 + ("%wraithform_insert%" * 0x1C)) 1 // identified
      WRITE_LONG  ("%sale_offset%" + 0x14 + ("%wraithform_insert%" * 0x1C)) 5 // quantity
    PATCH_IF NOT ("%item_offset%" < "%sale_offset%") BEGIN
      WRITE_LONG 0x2C ("%item_offset%" + 0x1C)
    END
    PATCH_IF NOT ("%drink_offset%" < "%sale_offset%") BEGIN
      WRITE_LONG 0x4C ("%drink_offset%" + 0x1C)
    END
    PATCH_IF NOT ("%cure_offset%" < "%sale_offset%") BEGIN
      WRITE_LONG 0x70 ("%cure_offset%" + 0x1C)
    END
  END

NI doesn't show it in the right place in the View tab though looking at the offsets in Edit it is there. Thanks again, Cam! :D
"We are the Gibberlings Three, as merry a band as you ever did see..." - Home of IE mods

<jcompton> Suggested plugs include "Click here so Compton doesn't ban me. http://www.pocketplane.net/ub"

I am unfortunately not often about these days so the best way to get hold of me is via email.

Offline CamDawg

  • Infidel
  • Planewalker
  • *****
  • Posts: 832
  • Dreaming of a red Xmas
    • The Gibberlings Three
Re: A hex upon ye!
« Reply #4 on: April 15, 2005, 07:37:52 PM »
Ah, the sloppy code of my youth.

Code: [Select]
COPY_EXISTING ~scrolls.sto~ ~override~     // The Pen and Parchment Store
  READ_LONG  0x34 "sale_offset"
  READ_LONG  0x38 "sale_num"
  WRITE_LONG 0x38 ("%sale_num%" + 1)
  READ_LONG  0x2C "item_offset"
  READ_LONG  0x4C "drink_offset"
  READ_LONG  0x70 "cure_offset"
  WHILE ("%sale_num%" > 0) BEGIN
    SET "sale_num" = ("%sale_num%" - 1)
    READ_ASCII ("%sale_offset%" + ("%sale_num%" * 0x1C)) "item"
    PATCH_IF (("%item%" STRING_COMPARE_CASE "scrl1t" = 0) OR ("%sale_num%" = 0)) BEGIN
      INSERT_BYTES  ("%sale_offset%" +        ("%sale_num%" * 0x1C)) 0x1c
        WRITE_ASCII ("%sale_offset%" +        ("%sale_num%" * 0x1C)) ~u!scrl03~
        WRITE_LONG  ("%sale_offset%" + 0x10 + ("%sale_num%" * 0x1C)) 1 // identified
        WRITE_LONG  ("%sale_offset%" + 0x14 + ("%sale_num%" * 0x1C)) 5 // quantity
      SET "sale_num" = 0
    END
  END
  PATCH_IF NOT ("%item_offset%" < "%sale_offset%") BEGIN
    WRITE_LONG 0x2C ("%item_offset%" + 0x1C)
  END
  PATCH_IF NOT ("%drink_offset%" < "%sale_offset%") BEGIN
    WRITE_LONG 0x4C ("%drink_offset%" + 0x1C)
  END
  PATCH_IF NOT ("%cure_offset%" < "%sale_offset%") BEGIN
    WRITE_LONG 0x70 ("%cure_offset%" + 0x1C)
  END

This should be a smidge faster, and has the additional failsafe of adding the scroll just in case scrl1t is not found.
The Gibberlings Three - Home of IE Mods

The BG2 Fixpack - All the fixes of Baldurdash, plus a few hundred more. Now available, with more fixes being added in every release.

Offline Andyr

  • Dance Commander
  • PPG
  • Planewalker
  • *****
  • Posts: 3178
  • Gender: Male
    • The Gibberlings Three IE mod community
Re: A hex upon ye!
« Reply #5 on: April 15, 2005, 07:41:09 PM »
Groovy.
"We are the Gibberlings Three, as merry a band as you ever did see..." - Home of IE mods

<jcompton> Suggested plugs include "Click here so Compton doesn't ban me. http://www.pocketplane.net/ub"

I am unfortunately not often about these days so the best way to get hold of me is via email.

Offline Grim Squeaker

  • Fallen
  • Planewalker
  • *****
  • Posts: 1019
  • Gender: Male
Re: A hex upon ye!
« Reply #6 on: April 19, 2005, 03:58:47 AM »
Not that I understand all of that code, but might it be an idea to automate it as some kind of INSERT_STORE_ITEM or something.
« Last Edit: April 19, 2005, 05:07:33 AM by Grim Squeaker »
"You alone can make my song take flight..."

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: