Skip to content

Short introduction to WeiDU and simple mod template

24

Comments

  • FrecheFreche Member Posts: 473
    edited February 2013
    @Miloch when patching an item into a store, is there a way to add it somewhere in the middle?
    I'm looking at unmodded Taerums store with DLTCEP, lets say I want to add it after #40 BULL02 (Bullet +1)
    Is it possible?
  • CorsymyrCorsymyr Member Posts: 146
    edited February 2013
    Here is the information from the WeiDU Documentation:

    "Valid options for position are:
    FIRST will add the item at the top of the stack. This is the default, equivalent to putting nothing there.
    LAST will add the item to the bottom of the stack.
    BEFORE olditem will add the item exactly before olditem, or to the top of the stack if olditem is missing.
    AFTER olditem will add the item exactly after olditem, or to the bottom of the stack if olditem is missing.
    As of 192, if there’s a list of items in BEFORE|AFTER olditem (IE ~item1 item2 item3), we add the new item BEFORE or AFTER the first item that is present in the list.
    As of 211, you can specify a (zero-based) hardcoded position via AT position."


    Since you are looking to add it at a point specific my thoughts would be to do something like this:

    COPY_EXISTING ~TAERUM.STO~ ~OVERRIDE\TAERUM.STO~
    ADD_STORE_ITEM ~myitem.itm~ AT #41 ~myitem.itm~ //the exact location of your item

    Hopefully that works out for you ...
  • FrecheFreche Member Posts: 473
    Thank you. Will try it when I'm back home after the weekend.
  • WispWisp Member Posts: 1,102
    You should only use AT if you really want it as the nth store item every time, regardless of whatever else is for sale. In this case, if another mod were to add one or more items at the start of the store, BULL02 would no longer be item #40, so myitem would no longer be placed after BULL02.
    (Also, the provided syntax is wrong. ADD_STORE_ITEM myitem AT 41 #charge1 #charge2 #charge3 flags #maxinstack would be correct.)
  • FrecheFreche Member Posts: 473
    edited February 2013
    New question, how do I remove an equip effect from an item?
    I have been trying with DELETE_ITEM_EQEFFECT but I get some kind of parse error when trying to install.
    COPY_EXISTING ~clck03.itm~ ~override~
    READ_SHORT 0x1c item_type
    PATCH_IF item_type=32 BEGIN
    opcode_to_delete = 65
    DELETE_ITEM_EQEFFECT
    END
    BUT_ONLY
    I know SCS already patches this item but, I'm trying to learn and the cloak is a good place to start.
  • WispWisp Member Posts: 1,102
    @Freche
    It's

    LPF DELETE_ITEM_EQEFFECT
    INT_VAR
    opcode_to_delete = 65
    END
  • CerevantCerevant Member Posts: 2,314
    @Wisp et al,

    1) Is there a way to "include" a file containing macros/functions/etc for use in a TP2 mod?
    2) Does READ_2DA_ENTRY et al take a row/column number, string lookup value, or both?
    3) The header for the worldmap gives an offset and count for the number of areas/links. Would it be be considered bad form if (in the case of deleted links) the count was less than the allocated space? I'd like to avoid

    (I'm hot on the trail of a technique to mod the Worldmap in a much more readable way by translating it to a set of 2DAs, modding the 2DAs, then writing those values into a new worldmap)
  • WispWisp Member Posts: 1,102
    Cerevant said:


    1) Is there a way to "include" a file containing macros/functions/etc for use in a TP2 mod?

    INCLUDE ~path/to/file~
    There is also PATCH_INCLUDE.
    Cerevant said:


    2) Does READ_2DA_ENTRY et al take a row/column number, string lookup value, or both?

    READ_2DA_ENTRY takes numbers. READ_2DA_ENTRIES_NOW/READ_2DA_ENTRY_FORMER work a bit differently but effectively take numbers as well.
    Cerevant said:


    3) The header for the worldmap gives an offset and count for the number of areas/links. Would it be be considered bad form if (in the case of deleted links) the count was less than the allocated space? I'd like to avoid

    It would not only be bad form, it would be file corruption. There are rather rigorous constraints for how worldmap links need to be indexed.

  • CerevantCerevant Member Posts: 2,314
    edited February 2013
    READ_2DA_ENTRY takes numbers. READ_2DA_ENTRIES_NOW/READ_2DA_ENTRY_FORMER work a bit differently but effectively take numbers as well.
    So is there no way to look something up in a 2DA by the values, i.e. as if it were an associative array?
    It would not only be bad form, it would be file corruption. There are rather rigorous constraints for how worldmap links need to be indexed.
    I don't think it is as bad as you think - unused space in the file should be ignored as long as all the offsets and counts (in the file header and the links themselves) are correct. Regardless, after further thought, it will probably be easier to build the WMP from scratch using my 2DAs as input, rather than trying to patch the existing one.

    Yes, I'm writing a WMP parser/compiler using a TP2. How freaking meta is that?
  • WispWisp Member Posts: 1,102
    edited February 2013
    Cerevant said:


    So is there no way to look something up in a 2DA by the values, i.e. as if it were an associative array?

    Not at present, but it is pretty easy to do and I agree it would be quite nifty, so I can add it to the todo list.
    Cerevant said:


    I don't think it is as bad as you think - unused space in the file should be ignored as long as all the offsets and counts (in the file header and the links themselves) are correct.

    Perhaps not, but aside from plain incorrectness, there is also violating the file's well-formedness (which typically does not manifest itself as corruption until the N+1th patch).
    Cerevant said:


    Regardless, after further thought, it will probably be easier to build the WMP from scratch using my 2DAs as input, rather than trying to patch the existing one.

    Yes, I'm writing a WMP parser/compiler using a TP2. How freaking meta is that?

    You might want to have a look at the BP–BGT Worldmap mod, which already does this. Most of the relevant code should be pretty portable too.
  • CerevantCerevant Member Posts: 2,314
    edited February 2013
    What an awesome mod! It seems to be using a different approach than I have in mind, but I might be able to steal some ideas from it. Looks like it only adds areas / links, but doesn't delete them.

    My concept is to dump all of the data in the existing worldmap to a set of 2da files (minimum of 3) - in effect decompiling the world map. Then someone could write a tp2 that would use 2da mod techniques (READ_2DA_ENTRY, SET_2DA_ENTRY, etc) and plain text (NESW instead of bit values) to mod the 2da files.
    Once that is complete, there would be a function to "compile" the 2DA files into a new worldmap.

    The advantage to this approach is that it is much more mod friendly, in that you do not need to go looking up offsets and arrange your inputs in a certain order. This approach is essential if you want to delete any links/areas, since there doesn't seem to be a way to do this without rebuilding most/all of the wmp file.

    Does BGEE have any translations for the World Map text? Looking at this mod made me realize that the strings in the world map are hard coded, and I'm not seeing any world map resources in the translation directories. Don't know how I got that into my head. Map uses string references, problem solved
    Post edited by Cerevant on
  • WispWisp Member Posts: 1,102
    Cerevant said:

    Looks like it only adds areas / links, but doesn't delete them.

    It deletes all areas and links at the outset. The WMP is then built from the header up using 2DA data (so anything not mirrored by the 2DA data is lost).
    Cerevant said:


    My concept is to dump all of the data in the existing worldmap to a set of 2da files (minimum of 3) - in effect decompiling the world map. Then someone could write a tp2 that would use 2da mod techniques (READ_2DA_ENTRY, SET_2DA_ENTRY, etc) and plain text (NESW instead of bit values) to mod the 2da files.
    Once that is complete, there would be a function to "compile" the 2DA files into a new worldmap.

    The advantage to this approach is that it is much more mod friendly, in that you do not need to go looking up offsets and arrange your inputs in a certain order. This approach is essential if you want to delete any links/areas, since there doesn't seem to be a way to do this without rebuilding most/all of the wmp file.

    Sounds interesting.
  • CerevantCerevant Member Posts: 2,314
    Wisp said:

    It deletes all areas and links at the outset. The WMP is then built from the header up using 2DA data (so anything not mirrored by the 2DA data is lost).

    Okay - It didn't look like all the data was there, but maybe I missed something - its a big mod. I'll have to take a closer look.
  • ErgErg Member Posts: 1,756
    edited February 2013
    @Wisp et al,

    I made a small WEIDU mod to patch an item and I would like to customise his description to reflect the changes, so I used SAY 84 ~New Item Description etc.~

    That works fine; a new string is added at the end of DIALOG.TLK (I have an hard link to the actual file in 0766) and I can install and uninstall the mod without problems. However I've noticed that uninstalling the mod will not revert the DIALOG.TLK to his former state (i.e. the new description is still in DIALOG.TLK, even if the item is reverted back to his previous version and uses the old description).

    So it seems like the backup only takes care of the files in override, but it doesn't restore the DIALOG.TLK.

    Is this intended behaviour? Am I doing something wrong? Is there a way to backup and restore also DIALOG.TLK when uninstalling (other than a manual backup)?

    Thanks in advance
  • WispWisp Member Posts: 1,102
    @Erg
    Yes, strings remaining in the TLK is intended behaviour. If you want to restore the TLK you would need to do it manually, but I wonder why you care?
  • ErgErg Member Posts: 1,756
    Wisp said:

    Yes, strings remaining in the TLK is intended behaviour. If you want to restore the TLK you would need to do it manually, but I wonder why you care?

    It's just that the idea of leaving unnecessary strings in the DIALOG.TLK file seems somehow wrong to me, but I agree that it's not that big of a deal.
  • WispWisp Member Posts: 1,102
    Consider the alternatives (of which "broken saves" are one).
  • HooHoo Member Posts: 128
    Hello, I first appreciate the great introduction of how to start Weidu modding.

    I have a question, I want to allow that Druids including kits can use shortbows/longbows/medium shields/all of nonmetal armors.

    I'd tried to modify all of each weapon's usability in DLTCEP for it, but I finally gave it up and felt that this work are really insane things... Honestly, even the modifications are applied only what I exactly modified so such modification has no compatibility with any other item pack mods.

    I guess Item Revisions mod works as I wish and I've read IR's TP2 file, however, I need some guide for understanding it. Could you give me some advise?
  • WispWisp Member Posts: 1,102
    edited March 2013
    Hoo said:


    I have a question, I want to allow that Druids including kits can use shortbows/longbows/medium shields/all of nonmetal armors.

    I guess Item Revisions mod works as I wish and I've read IR's TP2 file, however, I need some guide for understanding it. Could you give me some advise?

    Hmm, this is actually rather difficult. Explaining it all would be too complicated for it to be posted here, at the tail end of a very basic introduction to using WeiDU, and writing a non-crappy function for it would take too long. But in short, the engine has unusability flags in item files. (DLTCEP inverts this into "usability flags," but it is not how the engine works.) To unflag druids for an item with WeiDU, we need read the current unusability value from the item and engage in some binary arithmetic to change the value to one that does not include druids. You can do this with code like this (ideally there should be a higher-level function that abstracts the details of the engine, but for now we'll have to make do):

    OUTER_SET druid_unusable_flag = BIT30
    OUTER_SET item_class_unusability_field = 0x1e

    COPY_EXISTING bow01.itm override
    shld01.itm override
    /* more items */
    WRITE_LONG item_class_unusibility_field THIS BAND BNOT druid_unusable_flag
    BUT_ONLY
    You can add more items as you see fit. Finding out the values for druid_unusable_flag and item_class_unusability_field is probably best done with NI, or the IESDP. Note that there are also 4 distinct fields for kit unusabilities.
    This is probably not much, but I hope it at least gives you a place to start.
  • HooHoo Member Posts: 128
    Wisp said:


    Hmm, this is actually rather difficult. Explaining it all would be too complicated for it to be posted here, at the tail end of a very basic introduction to using WeiDU, and writing a non-crappy function for it would take too long. But in short, the engine has unusability flags in item files. (DLTCEP inverts this into "usability flags," but it is not how the engine works.) To unflag druids for an item with WeiDU, we need read the current unusability value from the item and engage in some binary arithmetic to change the value to one that does not include druids. You can do this with code like this (ideally there should be a higher-level function that abstracts the details of the engine, but for now we'll have to make do):


    OUTER_SET druid_unusable_flag = BIT30
    OUTER_SET item_class_unusability_field = 0x1e

    COPY_EXISTING bow01.itm override
    shld01.itm override
    /* more items */
    WRITE_LONG item_class_unusibility_field THIS BAND BNOT druid_unusable_flag
    BUT_ONLY
    You can add more items as you see fit. Finding out the values for druid_unusable_flag and item_class_unusability_field is probably best done with NI, or the IESDP. Note that there are also 4 distinct fields for kit unusabilities.
    This is probably not much, but I hope it at least gives you a place to start.
    Thank you for the advise! I'm done for the component that Druids can use bows/arrows by referring your comments and several tutorial in readme of Weidu like this:

    COPY_EXISTING_REGEXP GLOB ~.*\.itm~ ~override~ //copies all item files
    PATCH_IF ("%SOURCE_SIZE%" > "0x71") BEGIN // avoid crashing on empty items
    READ_BYTE "0x1F" "fighter" //reads the byte containing the fighter usability flag
    PATCH_IF (("%fighter%" BAND "0b00001000") = "0b00000000") BEGIN // if it is usable by fighters
    READ_BYTE "0x21" "druid" //reads the byte containing bard usability flag
    READ_SHORT "0x1C" "type" //reads the byte containing item type
    PATCH_IF ("%type%" = "5") OR ("%type%" = "15") BEGIN // if it is a arrow or bow
    WRITE_BYTE "0x21" ("%druid%" BAND "0b10111111") // makes usable by bards
    END
    END
    END
    BUT_ONLY_IF_IT_CHANGES
    Now I meet another challenge, which allows Druids using small and medium shields. The problem is that there are only one item type for shields. So some more factor should be required to distinguish between large shields and the other shields. I found that all of large shields use "Large Shield" as its General Name and "6640" as StringRef.

    Could I use such factor, General Name or StringRef, like "type" to identify in detail for excepting large shields?
  • WispWisp Member Posts: 1,102
    edited March 2013
    Hoo said:


    Could I use such factor, General Name or StringRef, like "type" to identify in detail for excepting large shields?

    You probably could use the strref, yes. Using the literal string will break on other languages or require you to add an excessive number of comparisons. You can also use a list of known items instead of using a regexp.
  • AbelAbel Member Posts: 785
    edited January 2014
    Nice thread that I'm very proud to revive ;) !

    I want to edit an existing BCS script. So I'm thinking about creating a TP2 for a WeiDU setup.
    I'm currently looking at the Readme tutorials (link) and wondering what action I should use to do this.

    I see there's: COMPILE [ EVALUATE_BUFFER ] sourceFile list [ patch list ] [ USING traFile list ]. But I guess I would need to extract the script as BAF first and modify it.
    There's also: EXTEND_TOP existingBCS newFile patch list but I need to add lines at a another point and inside an existing IF ... END block.

    Under the "patch" section: REPLACE_BCS_BLOCK [ EVALUATE_BUFFER ] optcase oldFile newFile [ ON_MISMATCH patch list END ]. I guess I would use this with COMPILE?

    So what should I do? Do I have to provide a BAF/BCS file? Can I modify it on the fly? What actions should I use?

    Edit: impatient as I am I tried to do it and it works! It's just a few lines of code, but still, it's a first!
    Here's the TP2:
    BACKUP ~abel_bp2plenty_mod/backup~
    AUTHOR ~Abel, http://forum.baldursgate.com/messages/add/Abel~
    BEGIN ~Black Pits II Containers of Plenty +2~
    COPY_EXISTING ~OHBHUB.BCS~ ~override~
    REPLACE_BCS_BLOCK ~abel_bp2plenty_mod/baf/OHBHUB_OLD.BAF~ ~abel_bp2plenty_mod/baf/OHBHUB_NEW.BAF~
    BUT_ONLY_IF_IT_CHANGES
    I wonder about the REPLACE_BCS_BLOCK action though. Does it really need a full block or would a line be enough?

    Also, no one mentioned the EXE needed for the setup. It's actually WeiDU.exe renamed to your mod folder name (explanation there).

    Oh, and one last thing. I first used Wordpad and Notepad to create and edit the files and it screws everything. So I switched toNotepad++ and downloaded the language packs there.
    Post edited by Abel on
  • WispWisp Member Posts: 1,102
    @Abel

    REPLACE_BCS_BLOCK replaces one or more BCS blocks (i.e., the replacement is done at the BCS level), which are exactly matched. The old script is compiled to BCS if it's BAF, so the BAF needs to be complete and valid. You can also look into REPLACE_TEXTUALLY, which can replace a single line. You'd use it together with DECOMPILE_AND_PATCH.
  • elminsterelminster Member, Developer Posts: 16,315
    edited October 2016
    Hi,

    So here is the scenario. I'm basically largely entirely new to Weidu so I'm just trying to get my bearings here.

    In this example I want to an itm file (sw1h62.itm) that I have modified and have it be moved into the persons override folder.

    Since I changed the degree at which bonuses are granted for the item I also had to change the items description. Anyways @CrevsDaak helped me out here a bit but is what I have here alright? Also since the only description I'm changing is the identified description is including the generic description for bastard swords even necessary?


    BACKUP ~elmin_tweaks/backup~
    AUTHOR ~elminster, ~
    BEGIN ~elminster tweaks~
    COPY ~itm folder/sw1h62.itm~ ~override~
    SAY 0x8 ~Bastard Sword~
    SAY 0xC ~Foebane +3~
    SAY 0x50 ~Also known as the hand-and-a-half sword, the bastard sword derives its name from the fact that it is halfway between the two-handed sword and the long sword. The bastard sword has a double-edged blade and a long grip, which can accommodate both hands if preferred. The overall length of the bastard sword ranges between four feet and four feet ten inches.

    STATISTICS:

    Damage: 2d4 (slashing)
    Speed Factor: 8
    Proficiency Type: Bastard Sword
    Type: One-handed
    Requires:
    11 Strength

    Weight: 10.~

    SAY 0x54 ~The archmage Demron created this powerful blade for Captain Fflar of Myth Drannor. When the elven city fell, the sword was lost beneath the rubble of the once great metropolis.

    STATISTICS:

    THAC0: +3
    Damage: 2d4+3, +6 damage vs. undead, lyncanthropes, rakshasa, and extraplanar beings (demons, planatars, dark planatars, solars, anti-solars, elementals, githyanki, imps, mephits, genie, and tiefling)
    Damage type: Slashing
    Speed Factor: 5
    Proficiency Type: Bastard Sword
    Type: One-handed
    Requires:
    11 Strength

    Weight: 7~


    Post edited by elminster on
  • IsayaIsaya Member, Translator (NDA) Posts: 752
    Since you're making a fixpack, you should only apply minimal changes to existing files. If you only change the identified description, don't use SAY for any other text in order to keep it as it is.
    Everyone is not playing the game in English. Although BG2EE is not officially translated, there are unofficial translations at least for the original BG II content. If one installs your mod as in your example, one will loose translation for the name and unidentified description.

    Also, it would be more readable to use constants instead of hex values:
    COPY ~Mod/item.itm~ ~override~ SAY NAME1 ~unidentified name~ SAY NAME2 ~identified name~ SAY UNIDENTIFIED_DESC ~unidentified description~ SAY DESC ~identified description~

    A fixpack usually tries to avoid overwriting a file like this and changes the file by patching it (changing a bonus value, adding or removing an effect) dynamically during installation. BG2 Fixpack is a good example of that.
    However this requires a much deeper WeiDU knowledge. So go on overwriting the files until you become more used to WeiDU.
  • elminsterelminster Member, Developer Posts: 16,315
    Ahh thanks for the help
  • CrevsDaakCrevsDaak Member Posts: 7,155
    Also, you might not need to update the any of the names nor the unidentified description, since you are only changing the ID description. I'd place the Foebane thingie in the Fixes part of the mod, since it's making it according to it's description.
  • AstroBryGuyAstroBryGuy Member Posts: 3,437
    edited July 2014
    @Wisp - I was helping with an installation problem for the Drizzt Saga mod, and I noted that the current version of tisunpack bundled with WeiDU v236 for OSX is dynamically linked to libjpeg.8.dylib. This library apparently isn't included with OSX by default.

    For those who need it, a version of the library with an OSX-friendly installer can be found here (it's an older version of libjpeg, but it works with the tispack binary).

    http://ethan.tira-thompson.com/Mac_OS_X_Ports.html
  • WispWisp Member Posts: 1,102
    @AstroBryGuy‌
    Okay. Would you happen to know if MosPack is also dynamically linked? (I would guess it is.)
    I don't suppose you would be able to provide me with statically linked executables?
  • AstroBryGuyAstroBryGuy Member Posts: 3,437
    @‌ Wisp - Yes, mospack also appears to by dynamically linked to libjpeg.8.dylib.

    And sorry, but I don't have a compiler loaded on my Macbook.
Sign In or Register to comment.