Jump to content


Photo

patching .STO files to accept more item types


5 replies to this topic

#1 subtledoctor

subtledoctor
  • Modders
  • 2316 posts
  • Gender:Male

Posted 22 January 2018 - 09:31 AM

I have a bit of hackneyed code that was donated, and then adapted, and TBH I'm not really sure how it works.  Apparently, it is messing up  various .STO files from various old "mega" mods like TDD, RoT, etc.  I have no idea what it is about those .STO files that makes them disagree with this code, and I have no idea what this code is doing to mess them up.

 

So, I think it's finally time to reach out for some help.  The goal here is, for any store that buys weapons, expand the list of purchased items to include bastard swords (type = 69), greatswords (type = 57), and clubs (type  = 44).

 

Here is the code at the moment.  Can anyone spot what's wrong with it?  Or a better way to achieve this?

COPY_EXISTING_REGEXP    ~.*\.sto~    override
    READ_SHORT    0x8    type
    READ_LONG    0x2c    buy_off
    READ_LONG    0x30    buy_num
    SET    buy_add = 0    //    Number of categories to add, to update offsets
    SET    add_category = 0    //    Initialize check variable
    FOR    (i = 0; i < 3; ++i)    BEGIN    SET $add_category(~%i%~) = 1    END    //    Initialize check variable
    FOR    (i = 0; i < buy_num; ++i)    BEGIN
        READ_BYTE    (buy_off + i * 0x4)    category
        PATCH_MATCH    category WITH
            15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 WHEN add_category = 0    BEGIN    // Match any Weapon Categories
                ++add_category
            END
            69    BEGIN    //    Match Bastard Sword Category / No Unnecessary Duplication
                SET add_category_0 = 0
            END
            57    BEGIN    //    Match Greatsword Category / No Unnecessary Duplication
                SET add_category_1 = 0
            END
            44    BEGIN    //    Match Club Category / No Unnecessary Duplication
                SET add_category_2 = 0
            END
            DEFAULT
        END
    END
    //    Add categories
    PATCH_IF    add_category    BEGIN
        PATCH_IF    add_category_0    BEGIN
            INSERT_BYTES    (buy_off + buy_num * 0x4)    0x4
            WRITE_BYTE    (buy_off + buy_num * 0x4)    69
            ++buy_add
        END
        PATCH_IF    add_category_1    BEGIN
            INSERT_BYTES    (buy_off + buy_num * 0x4)    0x4
            WRITE_BYTE    (buy_off + buy_num * 0x4)    57
            ++buy_add
        END
        PATCH_IF    add_category_2    BEGIN    
            INSERT_BYTES    (buy_off + buy_num * 0x4)    0x4
            WRITE_BYTE    (buy_off + buy_num * 0x4)    44
            ++buy_add
        END
        //    Update offsets
        WRITE_LONG    0x30    (THIS + buy_add)
        READ_LONG    0x34    items_off
        PATCH_IF    items_off >= buy_off    BEGIN    
            WRITE_LONG    0x34    (THIS + buy_add)
        END
        READ_LONG    0x4c    drink_off
        PATCH_IF    drink_off >= buy_off    BEGIN
            WRITE_LONG    0x4c    (THIS + buy_add)
        END
        READ_LONG    0x70    cures_off
        PATCH_IF    cures_off >= buy_off    BEGIN
            WRITE_LONG    0x70    (THIS + buy_add)
        END
    END
BUT_ONLY
 

Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE


#2 CamDawg

CamDawg

    Just a simple country Hyper-Chicken

  • Gibberling Poobah
  • 9390 posts
  • Gender:Not Telling

Posted 22 January 2018 - 09:42 AM

I believe these three lines like this at the end:

WRITE_LONG    0x34    (THIS + buy_add)

should be

WRITE_LONG    0x34    (THIS + (buy_add * 0x04))

buy_add is the number of categories it has added, and each one pushes the other offsets back by 0x04.

 

Tweaks has code that lets you do it via array, if you'd like an alternative.


I came here with a simple dream: a dream of killing all humans. And this is how it must end? Who's the real seven billion ton robot monster here? Not I. Not... I.


#3 Roxanne

Roxanne

    Modder

  • Modders
  • 1831 posts
  • Gender:Female
  • Location:Auckland, NZ

Posted 22 January 2018 - 09:43 AM

I have seen the effect of this code in many stores in my EET install as well, not only old mega mods but also newer versions of mods are affected. I saw it for Drittr Saga EET version, Grey Clan, the new TDDz, RoT, the new EET DSotSC, etc. It only affects some sto-files, not all added by those mods. The result is that those stores are empty and in NI all items to sell appear as Null. (some offset seems to be wrong)

I found the intact versions of the stores always in the backup folder of one of the mods in your signature, but I guess you know that already,


Edited by Roxanne, 22 January 2018 - 09:44 AM.

The Sandrah Saga

another piece of *buggy, cheesy, unbalanced junk*


#4 kjeron

kjeron
  • Members
  • 84 posts

Posted 22 January 2018 - 11:23 AM

That looks like my fault, but CamDawg has the right answer. Looking it now, I'm surprised it wasn't causing me any problems, unless all vanilla store files just happen to have item types listed last.

Edited by kjeron, 22 January 2018 - 11:23 AM.


#5 Roxanne

Roxanne

    Modder

  • Modders
  • 1831 posts
  • Gender:Female
  • Location:Auckland, NZ

Posted 22 January 2018 - 11:41 AM

That looks like my fault, but CamDawg has the right answer. Looking it now, I'm surprised it wasn't causing me any problems, unless all vanilla store files just happen to have item types listed last.

This seems to be the source of it. Stores that have no issue with the tweak are those that have purchased item types last. The ones that get *shoplifted* are the ones that have the list of itmes to sell in the end.


The Sandrah Saga

another piece of *buggy, cheesy, unbalanced junk*


#6 subtledoctor

subtledoctor
  • Modders
  • 2316 posts
  • Gender:Male

Posted 22 January 2018 - 11:45 AM

Sweet! Easy fix.

Faiths & Powers: Spell spheres and kit pack for priests and paladins
Might & Guile: Tweaks and kits for warriors and rogues
Scales of Balance: Game tweaks and rule overhauls
NPC_EE: More options for NPCs in BGEE, SoD, & BG2EE




Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users