Skip to content

Question about WEIDU functions from a novice

seraglioseraglio Member Posts: 122


Actually I'm not even a novice!

Up to this point I haven't bothered with weidu as I see it as a packaging/batch processing/productivity tool. For my little home projects I haven't needed those kind of functions.

I've kinda come up with an idea, a personal project that I might try if its feasible. I'm not going to outline all the details, precisely because its probably not feasible, especially if I can't use weidu to make the grunt work easier.

Basically imagine I'm writing my own personal version of Spell Revisions. I need to touch every spell in the game. For this project, I'd basically need to multiply every caster level entry in every spell 10x, the way Spell Revisions increased each spell to scale to level 50. Yeaah...


So take fireball, spwi304.spl. It has 6 "abilities" (sorry I'm still new and use NI not DLTCEP...I'm sure the later has a better description). These correspond with "minimum level", which I think is the minimum caster level for each ability within the spell; minimum caster level 1 (5d6), and caster levels 6-10.

I would need WEIDU to make copies these 6 "abilities", increasing the minimum caster level to a bogus number each time. So Fireball would have 66 entries/abilities, the current 6, another 6 starting at minimum level 101 through 106, another 6 with a minimum level of 201-206, and so on.

Spells with more minimum caster entries, that scale to level 20, like Armor of faith...same thing. Twenty new entries starting at 101-120, twenty new entries 201-220...etc.

I'd actually need this for EVERY spell in the game. Unfortunately, for my purposes, it doesn't matter whether I actually make any changes to some spells or not, all spells will need base, higher level entries as placeholders even if nothing else changes. My BG2 installation shows 4411 .spls. Hehe. Anyway, I assume Spell Revisions did something similar, and didn't do it by hand. So I'm hoping A: Weidu can run that task for me easily and more and B: drastically increasing the size of .spl files isn't going to kill performance, though I have to increase the size/depth with Weidu before I can do any performance testing. That's the minimum I need to know before I can even continue any theorycraft on the actual project.

Comments

  • AquadrizztAquadrizzt Member Posts: 1,065
    edited March 2017
    This is doable in Weidu but requires quite a bit of understanding not only of programming in general, but also how Weidu and the IE file structures work.

    And the extended headers you are referring to are pretty small, so I wouldn't worry about adding a lot of them. However, I'd be quite careful to refine the list of spells you modify to only involve spells that are actual cast by characters, rather than by the game at specific instances (for example, the Machine of Lum the Mad ability bonuses are each awarded via a spell). You could easily code a list of all spells you are interesting in modifying, and then have Weidu iterate through that list and make the requisite modifications.

    You're trying to do some variation on metamagic, aren't you?
  • The user and all related content has been deleted.
  • The user and all related content has been deleted.
  • GrammarsaladGrammarsalad Member Posts: 2,582
    edited March 2017

    I'm actually not seeing any kind of ADD_SPELL_HEADER or CLONE_HEADER functions in the Weidu docs. So you would have to clone the headers semi-manually, or come up with a really nifty function to do it automatically. Either way it would be a pain.

    @subtledoctor
    I think that Ardanis created something like an ADD_SPELL_HEADER macro for kit revisions

    Edit: spelling (... and that is why i couldn't @ him...)
    Post edited by Grammarsalad on
  • seraglioseraglio Member Posts: 122
    Thanks guys, I'm gonna have to get over my Weidu bigotry and sit down and learn this. Programming not an issue I'm an IT guy, although I have been corrupted by the ease of Python, sooo love that language. Laziness is the issue =)

    And you all got it, looking for a way to integrate "meta-magic" like features into spells, while not actually creating new spells. I've been very frustrated with some of the opcode functions and finally decided that all the time I spent trying to get specific functions to work the way "I" would like them to I could have probably just rewritten all the basic spells. Just looking at different ways of doing it with minimum impact and within the scope of my limited skills.

    Another thing I'd like to do with it is expand Wild Mages. In short, I think the main useful mechanic of wild mages is their caster level variation. But because of the minimum caster level in most spells (and maximum), it goes un-utilised. Imagine a Neera that can actually cast a 1d6 fireball....with some pathetic animation and maybe summoning an angry mephit. And on the other end, conjuring a greater than 10d6 fireball ( I probably wouldn't go 15d6, since at level 20 that will always be conjured)...with a screenshake, possibly a wing buffet and burning damage over time. In the middle casting range....a chance of a frostball or lightningball instead of a fireball. All without assigning her custom spells....just bump her caster level up +500 and fill in the caster levels as desired from there. That's the idea. It should be usable for short term, single cast metamagic feats or kits that always have a variation on casting, like Necros with save penalties and modifications to their base necromancy spells like more powerful animate dead.

    And yeah, I didn't want to touch spells that don't need it, but I want to be sure to account for things like assassin poison and bounty hunter traps that use caster level. And dispels. And anything else I'm not thinking about yet. Anything that has a single header, and is not castable by pcs/npcs could be skipped. Just trying to determine feasibility now.
  • ArdanisArdanis Member Posts: 1,736
    edited March 2017
    Copying the headers is not too difficult (assuming you're comfortable with WeiDU, anyway), but I'm not sure I see the point unless you also modify them somehow in the process? Other than level requirements, at least? That could be more effort-consuming than just duplicating things.

    I think that Adarnis created something like an ADD_SPELL_HEADER macro for kit revisions

    There's a copy of ADD_SPELL_HEADER function in Detectable Spells library (at least in the version that ships with latest SR/IR). Or, if you prefer, here's the actual code:
    DEFINE_PATCH_FUNCTION ~ADD_SPELL_HEADER~
      INT_VAR
        type=1
        location=4
        target=1
        target_count=0
        range=0
        required_level=1
        speed=0
        projectile=1
    
        copy_header=0
        insert_point=~-1~
      STR_VAR
        icon=~~
      RET
        insert_point
    BEGIN
      LPF ~FJ_SPL_ITM_REINDEX~ END
      hs=0x28
    
      READ_LONG 0x64 ho
      READ_SHORT 0x68 hc
      READ_LONG 0x6a eo
      insert_point = (insert_point>hc || insert_point<0) ? hc : insert_point
      copy_header = (copy_header<0) ? 0 : copy_header
    
      PATCH_IF copy_header>hc BEGIN
        PATCH_WARN ~Unable to copy %copy_header%th header, %SOURCE_FILE% contains only %hc% headers!~
      END ELSE BEGIN
        INSERT_BYTES ho+insert_point*hs hs
        hc+=1
        eo+=hs
        PATCH_IF copy_header BEGIN
          READ_SHORT ho+(copy_header - 1)*hs+0x1e ec
          READ_SHORT ho+(copy_header - 1)*hs+0x20 ei
          READ_ASCII eo+ei*0x30 effs (ec*0x30)
          READ_ASCII ho+(copy_header - 1)*hs copy (hs)
          WRITE_ASCIIE ho+insert_point*hs ~%copy%~ (hs)
        END
        WRITE_SHORT 0x68 hc
        WRITE_LONG 0x6a eo
    
        READ_SHORT 0x70 ei // technically, it is a counter
        FOR (i=ho;i<ho+hc*hs;i+=hs) BEGIN
          READ_SHORT i+0x1e ec
          WRITE_SHORT i+0x20 ei
          ei+=ec
        END
    
        PATCH_IF copy_header BEGIN
          READ_SHORT ho+insert_point*hs+0x1e ec
          READ_SHORT ho+insert_point*hs+0x20 ei
          INSERT_BYTES eo+ei*0x30 ec*0x30
          WRITE_ASCIIE eo+ei*0x30 ~%effs%~ (ec*0x30)
        END ELSE BEGIN
          off=ho+insert_point*hs
          WRITE_BYTE off type
          WRITE_BYTE off+0x2 location
          WRITE_ASCIIE off+0x4 ~%icon%~ (8)
          WRITE_BYTE off+0xc target
          WRITE_BYTE off+0xd target_count
          WRITE_SHORT off+0xe range
          WRITE_SHORT off+0x10 required_level
          WRITE_LONG off+0x12 speed
          WRITE_SHORT off+0x26 projectile
        END
      END
    END


    PS *Scratches head* Actually, the way I read it now, it appears to have some cloning functionality as well, what do you know... It's been quite a while since I wrote that, so I don't exactly remember the context, but guess you can modify it to write new level requirements as it clones headers.
  • kjeronkjeron Member Posts: 2,367
    @seraglio
    You cannot alter the casting level for innate spells anyway, nor can you alter the casting level of characters that do not normally receive access to priest/wizard spellbooks.
    The only spells you really need to worry about are SPPR###, SPWI###, SPRA###, and any subspells they cast.

    Unfortunately Caster level is capped and overflows at 255 back to 0.
    A spell header/ability minimum level is not capped, but values above 255 can only be called through opcodes that can "Cast at Specific Level", and may or may not use the correct level if cast normally.

    I've tried it before, so I know it is functionally doable, I just never managed something that wasn't cumbersome for the user, which I found to be the real challenge.
  • tbone1tbone1 Member Posts: 1,985
    edited March 2017
    @seraglio According to Larry Wall, the three great virtues of a programmer are laziness, impatience, and hubris.
Sign In or Register to comment.