Results 1 to 3 of 3

Thread: How to diversify missile units' ranges

  1. #1
    Satori's Avatar Tiro
    Join Date
    Feb 2010
    Location
    in the pure land
    Posts
    296

    Icon7 How to diversify missile units' ranges

    Since I haven't seen it realized in any mod so far, I began wondering if my fellow modders wouldn't know how to do it or if they merely consider it not being worth or too arduous a task?
    Anyway, inspired by Agostinos wonderful tutorial on basic hex editing, I decided to contribute a tutorial rather than releasing a mod of my own (that would just conflict with your already customized tables).

    In this tutorial we're working on unmodded tables of version 1.00 Build 3241.0
    (The attached archive includes a list with byte sequences that might come handy when doing searches/pastes with your hex editor. In that list scroll all the way down for projectiles)

    The reader might not yet be familiar with advanced hex editing, therefore allow me to introduce into the problem first.

    Generally one can discriminate between two levels of hex editing tables:

    1. Simple in place editing of values/attributes of already existing objects in tables, without ever altering data size.

    2. Inserting new bytes or even whole entries/rows into tables, thus altering their size (and potentially messing up their
    inner structure)

    The first way we can mod many things like, for instance, unit stats and surely solve quite a few other problems. Certain problems, however, require us to take the next step.

    Let's assume we're not happy (I ain't at all) with mediocre Ashigaru archers firing at the same range as better trained and better equipped Samurai. So we'd really like to nerf their range from 150 to 125 or whatever. That would surely make Samurai archers more worthwhile recruiting.

    After some poking around in table "unit_stats_land" we find that "range" is not an attribute of missile units there. How do we know? Well, a search for their range value that we know is 150 decimal, 0x96, as with Ashigaru/Wako/Samurai archers, restricted to the units' respective entries, brings an empty result set.

    Further analyzing missile units' entries, we find identifiers "shogun_arrow", "shogun_arrow_long" and others. Some more research/guessing and we eventually know they are referencing "types of" projectiles in another table, suitably named "projectiles". In that table, within it's entry for "shogun_arrow", we do find a value of 150, 0x96, defining the range as an attribute of a certain projectile.

    Spoiler Alert, click show to read: 


    The problem with this value: it's being shared, referenced by not only Ashigaru but Samurai (and Wako) archers as well. Simply altering it would give all those unit types the very same range once again.
    What we actually need is another type of projectile, defining a range of 125, 0x7d, and being referenced by Ashigaru (and maybe Wako) archers only.
    And to achieve that, there is no way around inserting a whole new row into table "projectiles".

    Now this is (one way) how to get it done:

    1. Make a clone of the entry of "shogun_arrow_long" by copying the block 1F63-2064 and inserting it at offset 1F63

    Spoiler Alert, click show to read: 


    2. Alter the value for range at offset 202f from 0xaf to 0x7d ( 175 to 125 or whatever you prefer)

    Spoiler Alert, click show to read: 


    3. Now we must provide for a unique identifier. We can do it quick'n'dirty or the proper (yes, more tedious) way. In this case, It would surely suffice to alter the character sequence starting at offset 1fab from "long" to "shrt" (for short, duh!) But as an exercise of hexing skills that are likey to come handy in other situations we will do it properly here.

    We want our identifier to be explicit, so we choose "shogun_arrow_short" instead. That's only one character more than "shogun_arrow_long". Since we're dealing with UTF16 (two byte) characters here, we must insert 2 more zeroed bytes at offset 1fb2.

    Spoiler Alert, click show to read: 


    We then alter the identifier to s.h.o.g.u.n._.a.r.r.o.w._.s.h.o.r.t by overwriting existing bytes accordingly.

    Spoiler Alert, click show to read: 


    Whenever altering the length of a parsable string in a table, as we just did here, we must not forget to adjust the value immediately preceding it. That value, in this case 0x11, defines the character count of the subsequent (not null terminated!) string and, if not set correctly, would corrupt the parsing. We must increase ours at offset 1f8f by 1, from 17 to 18, 0x11 to 0x12, to ensure our new identifier will get parsed completely.

    Spoiler Alert, click show to read: 



    That's it for for a new short range arrow.

    4. In an analogous manner we clone and then customize another entry for a new projectile named "shogun_matchlock_long" from existing "shogun_matchlock", defining a distinct range of say 120 for usage/reference by Samurai matchlock units (and maybe Warrior Monks) only, making them more valuable than cheap Ashigaru matchlocks with their shorter range of 100. (And perhaps lower their accuracy a little more to make up for the longer range)

    Spoiler Alert, click show to read: 


    5. Whenever inserting a new row into the table (or deleting a row from it!) we must adjust one more value. At offset 57 we must increase/decrease a value that keeps track of the table's row count by as many as we inserted/deleted rows. Assuming we actually inserted 2 new rows for 2 new projectiles, we increase it by 2, from 0x29 to 0x2b.

    Spoiler Alert, click show to read: 


    That's it for the table "projectiles". (you may want to take the opportunity to shorten the too long range of mounted Samurai archers. They're referencing another projectile, "shogun_arrow_rider". I suggest decreasing their range value and instead give them more ammo in table "unit_stats_land" to keep their tactical value high)

    Now for the table "unit_stats_land":

    6. For each missile unit type that we want to reference one of the new projectiles we (first search it's entry in "unit_stats_land", then) copy the whole byte sequence of the respective identifier including it's preceding character count from it's respective entry in table "projectiles"...

    Spoiler Alert, click show to read: 


    ...and paste (insert!) it into the unit's entry in table "unit_stats_land" by selecting the corresponding byte sequence (including char count!) there and hitting Ctrl-V:

    Spoiler Alert, click show to read: 


    We're done. Let's save, pack and test our tables!

    Provided that we handled our bytes correctly, we should now have a working mod with more diversified ranges of our missile units.

    Enjoy the variety!

    Hoping I could help with it,
    Your Satori
    "Where ignorance is bliss, 'tis folly to be wise." (Thomas Gray)

  2. #2

    Default Re: How to diversify missile units' ranges

    thx,great tutorial. tested and worked

  3. #3

    Default Re: How to diversify missile units' ranges

    I didn't know about the char and row count until now... thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •