Author Topic: Say one wanted to...  (Read 2572 times)

Offline Joe

  • Planewalker
  • *****
  • Posts: 582
  • Gender: Male
Say one wanted to...
« on: November 17, 2008, 03:41:35 AM »
...tell WeiDU to make items usable by a class (wizard slayer, for example).

How might this be executed in the .tp2 file?

Offline SixOfSpades

  • Planewalker
  • *****
  • Posts: 821
  • Gender: Male
    • Volothamp's Comeuppance
Re: Say one wanted to...
« Reply #1 on: November 17, 2008, 01:00:04 PM »
You'll need Shadowkeeper (easiest lising of item names + filenames) and Near Infinity (for the hex offset values).

COPY_EXISTING ~belt10.itm~ ~override~  // Belt of Inertial Barrier
         ~clck05.itm~ ~override~  // Cloak of Balduran
         ~clck30.itm~ ~override~  // Cloak of Bravery
         ~clck03.itm~ ~override~  // Cloak of Displacement
         ~clck26.itm~ ~override~  // Cloak of Mirroring
         ~clck01.itm~ ~override~  // Cloak of Protection+1
         ~clck02.itm~ ~override~  // Cloak of Protection+2
         ~clck24.itm~ ~override~  // Cloak of Reflection
         ~clck25.itm~ ~override~  // Cloak of the Stars
         ~clck28.itm~ ~override~  // Shadow Thief Cloak
  READ_BYTE "0x2f" "usab2"
  WRITE_BYTE "0x2f" ("%usab2%" BAND "0b11111101") // make selected items usable by Wizard Slayers
 BUT_ONLY_IF_IT_CHANGES

Pull up an item, any item, in Near Infinity, and find the "Unusable by" sections: The first one is for Race/Class/Alignment, and the other four are for kits. The check marks always mean no: If the item carries a check-mark flag in any area that matches a character's traits, then that character cannot use the item. We want to allow usability, so we'll be removing flags. Find the Unusable by section that contains the Wizard Slayer: It's at Hex Offset 2f (go to the Options tab at the top of the screen, and make sure "Show Hex Offsets" is selected). So we want to mess with the flags from 2f; that's why we READ_BYTE the flags from 0x2f, and store them in memory as usab2, which is just a temporary variable name. Now we change the flags with the operator BAND, which means Bitwise AND: It goes through each of the 8 bits in "usab2" and "11111101", and if there is a 1 (a flag) in both of those bits, the result is also a flag. If not, the result is NO flag. It's tough to explain, let me give you an example.

     11110000          11110000
BAND 10101010      BOR 10101010
-------------      ------------
     10100000          11111010

Each of the columns adds straight down: In the BAND equation, if there is a 1 in both rows, the result is 1; if not, the result is 0. I've included BAND's counterpart, BOR (Bitwise OR), for comparison. In the BOR equation, if there is a 1 in either row, the result is 1; otherwise, the result is 0.

THIS IS IMPORTANT: (Largely because it's counter-intuitive.)
You'll see that in Near Infinity, section 2f is marked
Berserker (0)
Wizard Slayer (1)
Kensai (2)
Cavalier (3)
Inquisitor (4)
Undead Hunter (5)
Abjurer (6)
Conjurer (7)
Just remember that this is BACKWARDS, and you'll be fine. The Wizard Slayer, which is listed as being second from the first, is actually second from last when it comes to actually dealing with the binary flags. So, an item flagged against Berserkers, Wizard Slayers, and Undead Hunters will have a 2f value of 00100011. Let's run the above code on this item.

  READ_BYTE "0x2f" "usab2" // grab the value 00100011 and store it in memory

     00100011
BAND 11111101
-------------
     00100001

  WRITE_BYTE "0x2f" ("%usab2%" BAND "0b11111101") // write the value 00100001 in the same location you just read from
 BUT_ONLY_IF_IT_CHANGES // if nothing changed, don't bother doing anything at all

And once that operation is complete, the item is still flagged against Berserkers and Undead Hunters--but not Wizard Slayers.
« Last Edit: November 17, 2008, 01:49:41 PM by SixOfSpades »

Offline Joe

  • Planewalker
  • *****
  • Posts: 582
  • Gender: Male
Re: Say one wanted to...
« Reply #2 on: November 18, 2008, 12:41:38 AM »
Excellent reply, Six, but I am still damn confused (my fault, not yours).

If I put

"COPY_EXISTING ~belt10.itm~ ~override~  // Belt of Inertial Barrier
         ~clck05.itm~ ~override~  // Cloak of Balduran
         ~clck30.itm~ ~override~  // Cloak of Bravery
         ~clck03.itm~ ~override~  // Cloak of Displacement
         ~clck26.itm~ ~override~  // Cloak of Mirroring
         ~clck01.itm~ ~override~  // Cloak of Protection+1
         ~clck02.itm~ ~override~  // Cloak of Protection+2
         ~clck24.itm~ ~override~  // Cloak of Reflection
         ~clck25.itm~ ~override~  // Cloak of the Stars
         ~clck28.itm~ ~override~  // Shadow Thief Cloak
  READ_BYTE "0x2f" "usab2"
  WRITE_BYTE "0x2f" ("%usab2%" BAND "0b11111101") // make selected items usable by Wizard Slayers
 BUT_ONLY_IF_IT_CHANGES"

into a .tp2 file and ran that, what would happen? In other words, could I then just add the appropriate items to complete the list?

I suspect your in-depth explanation after that is a look under the hood, a justification of the coding, but I may be wrong.

Offline SixOfSpades

  • Planewalker
  • *****
  • Posts: 821
  • Gender: Male
    • Volothamp's Comeuppance
Re: Say one wanted to...
« Reply #3 on: November 18, 2008, 01:57:13 PM »
Yes, everything I wrote after the first batch of code is an explanation/analysis of said code. And yes, you can choose which items to open up to Wizard Slayers simply by removing the items I selected (Belt of Intertial Barrier and a bunch of Cloaks) and writing in a bunch of different items to take their place. There is no limit (that I know of) to the number of items that can be placed in a single COPY_EXISTING.

But let me ask you this: Do you just want to correct the default Wizard Slayer's ridiculous item restrictions, or do you actually want to write mods? If you just want to make the one change on your home system, then sure, the best thing to do would be to take the code I posted above, swap the items around, run it on your PC and be happy with a Wizard Slayer that can actually wear Kaligun's Amulet of Magic Resistance. But if you want to actually become a modder, there is an ancient, sacred ritual through which all coders must pass if they hope to reach the hallowed status of modder: You crack open the TP2s of other mods, and steal their code. Sure, you'll also have to study README-WeiDU.html in order to understand what the hell you're doing, and copy down various Tutorials for even greater insight, but basically it all boils down to stealing other people's code. That Wizard Slayer fragment I posted? Based off a chunk I tore out of Ashes of Embers. But I couldn't call it my code until I understood why every little piece of it did what it did. So once Version 2 of my Kitpack comes out (around the turn of the year, I think), you'll be able to see what I do with the Wizard Slayer, and hopefully by then you'll be able to read the code and understand what it all does. And hack it apart and use the pieces to help you construct mods of your own. :)

Offline Joe

  • Planewalker
  • *****
  • Posts: 582
  • Gender: Male
Re: Say one wanted to...
« Reply #4 on: November 19, 2008, 01:46:26 AM »
Haha, well, at the moment, all I want to do is amend the poor item restrictions, but I am versed in code-thievery. It's been a while, though.

And in the past I simply manually changed item usability with the IEE.

I copied and pasted the code into a .tp2 and this is what I got:

[SETUP-JOE.TP2] PARSE ERROR at line 1 column 0-12
Near Text: COPY_EXISTING
   GLR parse error

[SETUP-JOE.TP2]  ERROR at line 1 column 0-12
Near Text: COPY_EXISTING
   Parsing.Parse_error
ERROR: parsing [SETUP-JOE.TP2]: Parsing.Parse_error
ERROR: problem parsing TP file [SETUP-JOE.TP2]: Parsing.Parse_error

FATAL ERROR: Parsing.Parse_error

Do I need to have these files extracted and in a folder of my own, to be copied into the BGII override?

Offline Mike1072

  • Planewalker
  • *****
  • Posts: 296
  • Gender: Male
Re: Say one wanted to...
« Reply #5 on: November 19, 2008, 02:38:36 AM »
Don't forget to add the header information to the .tp2, including your backup folder, author name, and a BEGIN ~Component Name~ for the component.  I'd just copy/paste another you have handy and modify.
« Last Edit: November 19, 2008, 02:42:02 AM by Mike1072 »

Offline Joe

  • Planewalker
  • *****
  • Posts: 582
  • Gender: Male
Re: Say one wanted to...
« Reply #6 on: November 19, 2008, 04:19:34 AM »
Welp, that did it. Thanks a lot guys.

Now all I have to do is figger out which items to make usable to Wizard Slayers.

Offline Joe

  • Planewalker
  • *****
  • Posts: 582
  • Gender: Male
Re: Say one wanted to...
« Reply #7 on: November 19, 2008, 08:10:39 PM »
'Kay, so, new problem. It seems that the usability changes worked for everything except Carsomyr. The description changes did, but not usability.

Here's my .tp2:

Quote
BACKUP ~Joe\Backup~
AUTHOR ~Joe~

BEGIN ~Joe~

COPY_EXISTING
         ~belt10.itm~ ~override~  // Belt of Inertial Barrier
         ~clck05.itm~ ~override~  // Cloak of Balduran
         ~clck30.itm~ ~override~  // Cloak of Bravery
         ~clck03.itm~ ~override~  // Cloak of Displacement
         ~clck26.itm~ ~override~  // Cloak of Mirroring
         ~clck01.itm~ ~override~  // Cloak of Protection+1
         ~clck02.itm~ ~override~  // Cloak of Protection+2
         ~clck24.itm~ ~override~  // Cloak of Reflection
         ~clck25.itm~ ~override~  // Cloak of the Stars
         ~clck28.itm~ ~override~  // Shadow Thief Cloak
    ~CLCK08.itm~ ~override~
    ~CLCK31.itm~ ~override~
    ~BRAC06.itm~ ~override~
    ~BRAC07.itm~ ~override~
    ~BRAC09.itm~ ~override~
    ~BRAC10.itm~ ~override~
    ~BRAC21.itm~ ~override~
    ~BELT02.itm~ ~override~
    ~BELT03.itm~ ~override~
    ~BELT04.itm~ ~override~
    ~BELT06.itm~ ~override~
    ~BELT07.itm~ ~override~
    ~BELT08.itm~ ~override~
    ~BELT11.itm~ ~override~
    ~RING02.itm~ ~override~
    ~RING05.itm~ ~override~
    ~RING06.itm~ ~override~
    ~RING07.itm~ ~override~
         ~RING09.itm~ ~override~
         ~RING25.itm~ ~override~
         ~RING27.itm~ ~override~
         ~RING28.itm~ ~override~
         ~RING29.itm~ ~override~
         ~RING31.itm~ ~override~
         ~RING33.itm~ ~override~
         ~RING34.itm~ ~override~
         ~RING39.itm~ ~override~
         ~RING41.itm~ ~override~
         ~RING42.itm~ ~override~
         ~RING46.itm~ ~override~
         ~BOOT01.itm~ ~override~
         ~BOOT03.itm~ ~override~
         ~BOOT05.itm~ ~override~
         ~BOOT11.itm~ ~override~
         ~BOOT12.itm~ ~override~
         ~AMUL14.itm~ ~override~
         ~AMUL17.itm~ ~override~
         ~AMUL18.itm~ ~override~
         ~AMUL19.itm~ ~override~
         ~AMUL20.itm~ ~override~
         ~AMUL23.itm~ ~override~
         ~AMUL25.itm~ ~override~
         ~AMUL26.itm~ ~override~
         ~HELM03.itm~ ~override~
         ~HELM04.itm~ ~override~
         ~HELM06.itm~ ~override~
         ~HELM07.itm~ ~override~
         ~HELM14.itm~ ~override~
         ~HELM16.itm~ ~override~
         ~HELM17.itm~ ~override~
         ~HELM21.itm~ ~override~
         ~HELM31.itm~ ~override~
         ~HELM32.itm~ ~override~
         ~MISC3H.itm~ ~override~
         ~POTN02.itm~ ~override~
         ~POTN03.itm~ ~override~
         ~POTN04.itm~ ~override~
         ~POTN05.itm~ ~override~
         ~POTN06.itm~ ~override~
         ~POTN07.itm~ ~override~
         ~POTN08.itm~ ~override~
         ~POTN09.itm~ ~override~
         ~POTN10.itm~ ~override~
         ~POTN11.itm~ ~override~
         ~POTN12.itm~ ~override~
         ~POTN13.itm~ ~override~
         ~POTN14.itm~ ~override~
         ~POTN17.itm~ ~override~
         ~POTN20.itm~ ~override~
         ~POTN21.itm~ ~override~
         ~POTN26.itm~ ~override~
         ~POTN27.itm~ ~override~
         ~POTN31.itm~ ~override~
         ~POTN33.itm~ ~override~
         ~POTN34.itm~ ~override~
         ~POTN35.itm~ ~override~
         ~POTN38.itm~ ~override~
         ~POTN40.itm~ ~override~
         ~POTN41.itm~ ~override~
         ~POTN42.itm~ ~override~
         ~POTN47.itm~ ~override~
         ~POTN55.itm~ ~override~
         ~sw2h10.itm~ ~override~
         ~sw2h19.itm~ ~override~
  READ_BYTE "0x2f" "usab2"
  WRITE_BYTE "0x2f" ("%usab2%" BAND "0b11111101")
 BUT_ONLY_IF_IT_CHANGES

COPY_EXISTING ~sw2h10.itm~ ~override~
 SAY NAME1 ~Two-Handed Sword~ // unidentified name for items OR spell name
 SAY NAME2 ~Carsomyr +5~ // identified name for items; not used for spells
 SAY UNIDENTIFIED_DESC ~A derivative of the long sword, the two-handed sword is significantly longer, both in blade and hilt.  Its primary function is cleaving mounted knights and breaking up pike formations.~
 SAY DESC ~Carsomyr +5
The Holy Avenger:  Carsomyr

Carsomyr is a weapon of legend, perhaps one of the most powerful blades
ever forged on Faerun, though its origin and history is thought
purposefully forgotten, such that the sword itself never overshadow the
importance of the struggles that must be fought today.  It is infused
with the very essence of virtue, and requires as much from any warrior
that would hope to wield it.  The evils of the Realms must truly stand
aside when this weapon is brought to bear, their magic dispelled with a
word, steadfastly resisted with ease.  Carsomyr also harbors a special
distaste for the forces of evil and chaos, and such creatures must fear
additional damage from its touch in battle.

STATISTICS

Equipped Abilities:
+15% Magic Resistance
Dispel Magic 3 times per day

Combat Abilities:
+5 damage to chaotic evil opponents in addition to other bonuses.
Dispels magic whenever the sword strikes an opponent
THAC0:  +5 bonus
Damage:  1D12 +5
Damage type:  slashing
Weight:  7
Speed Factor:  5
Proficiency Type:  Two handed sword
Type:  2-handed
Requires:  14 Strength

Usable By:
Wizard Slayers
Paladins~

COPY_EXISTING ~sw2h19.itm~ ~override~
 SAY NAME1 ~Two-Handed Sword~ // unidentified name for items OR spell name
 SAY NAME2 ~Carsomyr +6~ // identified name for items; not used for spells
 SAY UNIDENTIFIED_DESC ~A derivative of the long sword, the two-handed sword is significantly longer, both in blade and hilt.  Its primary function is cleaving mounted knights and breaking up pike formations.~
 SAY DESC ~Carsomyr +6
The Holy Avenger:  Carsomyr

Even a Holy Relic as powerful as Carsomyr is made even greater when combined
  with the Eye of Tyr.

STATISTICS

Equipped Abilities:
+15% Magic Resistance
Dispel Magic 3 times per day

Combat Abilities:
+6 damage to chaotic evil opponents in addition to other bonuses.
Dispels magic whenever the sword strikes an opponent
THAC0:  +6 bonus
Damage:  1D12 +6
Damage type:  slashing
Weight:  7
Speed Factor:  5
Proficiency Type:  Two handed sword
Type:  2-handed
Requires:  14 Strength

Usable By:
Wizard Slayers
Paladins~
 
// change carsomyr to add 15 MR instead of setting 50
COPY_EXISTING ~sw2h10.itm~  ~override~ // carsomyr +5
              ~sw2h19.itm~  ~override~ // carsomyr +6
  READ_LONG   0x6a "fx_off"
  READ_SHORT  0x70 "fx_num"
  FOR (index = 0; index < fx_num; index = index + 1) BEGIN
    READ_SHORT ("%fx_off%" +        ("%index%" * 0x30)) "opcode"
    PATCH_IF ("%opcode%" = 166) BEGIN
      WRITE_LONG  ("%fx_off%" + 0x04 + ("%index%" * 0x30)) 15 // 15% MR
      WRITE_LONG  ("%fx_off%" + 0x08 + ("%index%" * 0x30))  0 // increase/decrease
    END
  END
  BUT_ONLY_IF_IT_CHANGES


Offline Mike1072

  • Planewalker
  • *****
  • Posts: 296
  • Gender: Male
Re: Say one wanted to...
« Reply #8 on: November 19, 2008, 08:44:03 PM »
Kits are not allowed to use any items that their parent class cannot use, so if you wanted Wizard Slayers to be able to use it, you'd have to make it usable by Fighters, too.

Offline Joe

  • Planewalker
  • *****
  • Posts: 582
  • Gender: Male
Re: Say one wanted to...
« Reply #9 on: November 20, 2008, 12:05:39 AM »
Alright, so now I've got to figure out how to unlock it for Fighters, then lock it to all fighters but Wizard Slayers.

Numbers, numbers.....madness! I shall give it a go.

 

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)?: