Shining Force II Hacking: Xenometal's SF2DISASM workshop

Newest work: Character Expansion

A place for Shining Force 2 hack discussion, editing tools, new hacks etc.

Moderator: Shining Moderators

Post Reply
User avatar
xenometal
Shining Member
Shining Member
Posts: 439
Joined: Tue Mar 28 2006 3:05am
Location: Canada
Status: Offline

Xenometal's SF2DISASM workshop

Post by xenometal »

Originally titled [Patch] Mithril Shop
Image
Bowie: "I'll, uh, have a Gisarme, please."
Does exactly what is says on the tin.

More precisely, this implements a customized routine which let you access an exclusive shop and buy a single weapon in exchange for a piece of Mithril. Gotta pay the full price now, though!

The .ips patch below is Plug & Play and meant to be applied to a vanilla rom. It simply lets you buy the weapons that are normally available through the blacksmith.

But there's more!

For modders, I've added support for multiple kinds of materials that the blacksmith will accept, each granting access to its own shop. So, it's now fairly easy to have, say, Small Mithril to craft magic rings and/or Dark Block for cursed weapons as in SF3. Try it for yourself! Load the included save state (Kega Fusion) and see how the blacksmith reacts when you hand him a Wooden Panel or Cotton Balloon.

Modding instructions:
Spoiler
Go to offset 0x21D2A (or if working with assembly, search for the "MithrilShopMaterials:" label) to find data that follows the same structure as the regular shops, that is to say, an array of lists where the first byte determines the size, or number of entries in the list, followed by item indexes.

First is a list of accepted materials, then actual shop inventories.

Finally, there's a convenient block of unused space (up to offset 0x21FD2), so feel free to expand as you wish.
Code: blacksmithactions.asm

Patch: sf2-mithril-shop.ips

EDIT: Updated .ips patch download link.
Last edited by xenometal on Mon May 14 2018 6:56am, edited 4 times in total.
User avatar
Wiz
Shining Member
Shining Member
Posts: 181
Joined: Sun Mar 18 2007 2:43pm
Location: Blois, France
Contact:
Status: Offline

Re: [Patch] Mithril Shop

Post by Wiz »

I was happy when I saw you fork SF2DISASM on GitHub, and now I'm even more happy to see you made several branches.

Go Xenometal go ! :)
The SF2 Disassembly Super Thread / sf2hack Discord / Currently not available for tech support (sorry!)
User avatar
Diego_Didakus
Shining Hero
Shining Hero
Posts: 614
Joined: Wed May 05 2010 2:48pm
Status: Offline

Re: [Patch] Mithril Shop

Post by Diego_Didakus »

Wow, its really great! so we dont need to reload save states anymore. This way makes more sense to me, I believe it should work like this in the original.
Check out my projects: https://quasarcorpsgame.com.br/

Speaking...tires me.
Fighting...tires me
I'm tired.
User avatar
Nuburan
Shining Member
Shining Member
Posts: 263
Joined: Thu Dec 22 2011 8:55pm
Status: Offline

Re: [Patch] Mithril Shop

Post by Nuburan »

Thank you! I always dread that part of the game.
User avatar
xenometal
Shining Member
Shining Member
Posts: 439
Joined: Tue Mar 28 2006 3:05am
Location: Canada
Status: Offline

Item and Spell Expansion

Post by xenometal »

Hey, I hope you've been enjoying the Mithril Shop patch!

I figured I'd keep posts related to my SF2DISASM work in the same thread, so I'm renaming it "Xenometal's SF2DISASM workshop".

And with that done, I'm presenting you my newest work: the Item and Spell Expansion patch!
Image
"It's spelled, 'spell'."
Features:
  • Allows up to 255 items, and up to 63 spells (4 levels each)
  • Normally unused spell indexes won't crash the game anymore
  • Every spell can be assigned an element and effect subroutine
  • Enough room for icons; no more spells sharing an icon with the Jewels of Light and Evil
  • TODO: Rewrite the hardcoded weapon sprites to reference a table - done! :thumbsup:
  • TODO: Do something about Deals section data in RAM
Unlike the Mithril Shop, it doesn't really make sense to release this as a .ips patch since this is intended as a tool for modders working with SF2DISASM, but I'd be happy upload one along with a save state to quickly see the patch in action if there's a demand.

Quick start guide:
Spoiler
The procedure is much like obtaining SF2DISASM itself as detailed by Wiz in The SF2 Disassembly Super Thread, with a couple of important additions.

1. Get the patched SF2DISASM branch :
https://github.com/xenometal/SF2DISASM/ ... ansion.zip

2. Split :
- Put the original US ROM in BIN format (not SMD) in the rom/ directory, with the following filename : sf2.bin
- Then run split/split.bat. This may take from a few seconds to around a minute.
This will split the ROM's original data in thousands of tiny binary files in the disasm/ directory.

3. Patch :
- A new patch/ directory has been added for the purpose of expanding various game data which were previously split from the ROM. This includes the Floating IPS utility which supports .ips and .bps patching formats.
- Run patch/patch.bat. This will automatically apply the necessary patches as outlined in the accompanying patchfiles.txt.

4. Build :
- Run the build/buildexpanded.bat script to make a 4MB ROM! This is required because the ROM layout had to be rearranged to include expanded data. For this reason, the regular 2MB ROM is not supported.
Now, I must admit that even though it seemingly works pretty well on the surface, this hasn't been thoroughly tested so bugs are to be expected. It goes without saying that any and all feedback will be appreciated. :)
Last edited by xenometal on Sat Apr 14 2018 4:55am, edited 1 time in total.
User avatar
Wiz
Shining Member
Shining Member
Posts: 181
Joined: Sun Mar 18 2007 2:43pm
Location: Blois, France
Contact:
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by Wiz »

Just a quick note, as I rediscovered this recently : chest items may be limited to index 127, because higher indexes are used for gold amounts.
You'll find this in code\common\exploration\explorationfunctions_0.asm :

Code: Select all

loc_239C8:
		clr.w   d0
		move.w  d0,((TEXT_NAME_INDEX_1-$1000000)).w
		cmpi.w  #$80,d2 
		blt.s   loc_239EE
		bsr.s   GetChestGoldAmount
Gold amounts don't need such a big range of indexes as it relies on a few registered amounts in a "Chest Gold Amounts" table, but you'll still have to sacrifice either those gold amounts or some item indexes which won't be available in chests.
The SF2 Disassembly Super Thread / sf2hack Discord / Currently not available for tech support (sorry!)
User avatar
xenometal
Shining Member
Shining Member
Posts: 439
Joined: Tue Mar 28 2006 3:05am
Location: Canada
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by xenometal »

Thanks for bringing this up. As I'm mostly focusing on the menus, stats and battle engine I tend to forget about the exploration part of the game. :sweatdrop:

Now, wait a minute. I'm probably being silly so correct me if I'm wrong, but are there actually chests that contain gold in SF2? I just had a look through Moogie's guide to refresh my memory, and she doesn't mention any. Is that an unused functionality?
User avatar
Wiz
Shining Member
Shining Member
Posts: 181
Joined: Sun Mar 18 2007 2:43pm
Location: Blois, France
Contact:
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by Wiz »

Oh no that's not a silly observation at all, you must be right, I was also wondering if that was ever used in the game ... anyway, let's try it !
Ahah yeah !
It works very well with chests on map 19 (Granseal Castle), and I could change the gold amounts available to find the limit : you can fill chests with up to 32767 gold coins ($7FFF) ! :)
The SF2 Disassembly Super Thread / sf2hack Discord / Currently not available for tech support (sorry!)
User avatar
Diego_Didakus
Shining Hero
Shining Hero
Posts: 614
Joined: Wed May 05 2010 2:48pm
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by Diego_Didakus »

Its unused in the game
Check out my projects: https://quasarcorpsgame.com.br/

Speaking...tires me.
Fighting...tires me
I'm tired.
User avatar
xenometal
Shining Member
Shining Member
Posts: 439
Joined: Tue Mar 28 2006 3:05am
Location: Canada
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by xenometal »

Of course they had to sign-extend the value gotten from the table so that it's possible to obtain a negative amount of gold. That makes sense! :lol:

Ah well, if it's unused then I don't necessarily have to support it, do I? I just made all items available from chests by default, and I'm leaving it to modders discretion whether they want to make use of that feature in their project (search for the "CHEST_GOLD_AMOUNTS_START:" label in sf2enums.asm).

I've also patched enemy equipment data according to the new format, so they have their weapons correctly equipped.
jordanelias
Newbie
Newbie
Posts: 10
Joined: Mon Aug 14 2017 10:04pm
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by jordanelias »

All hail.
User avatar
xenometal
Shining Member
Shining Member
Posts: 439
Joined: Tue Mar 28 2006 3:05am
Location: Canada
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by xenometal »

Turns out there wasn't too much work involved in expanding the weapon sprites+palettes table after all! Thanks to Wiz's great write-up detailing the workings of this system, I figured I could just skip the hardcoded range and expand the table to the maximum number of entries. This way, we trade a bit of ROM space in order to afford the convenience of turning any item into a visible weapon.

However, another issue has presented itself; the Deals section. There's only enough room in RAM to keep track of item amounts (up to fifteen) for 128 item indexes under the current system, so expanded items cannot be added to deals at the moment. This will eventually need to be addressed somehow.

Ideally, I'll stumble upon a sizable chunk of unused RAM, otherwise some compromise will have to be made... :shifty:
User avatar
Flygon
Powered by Jets
Shining Hero
Posts: 874
Joined: Sun Jan 18 2009 4:04am
Location: Victoria, Australia
Contact:
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by Flygon »

How much SRAM are you able to address?

Theoretically, you'd probably be able to get away with addressing about as much as you want. Not that there's probably much need for addressing more than half a megabyte.

Do emulators choke up when addressing more than the standard amount? From a hardware perspective, it's fairly trivial.

Yes, using more SRAM is cheating, but I don't care, if NES games pulled that crap all the time, the Mega Drive should be allowed to too. :)
User avatar
xenometal
Shining Member
Shining Member
Posts: 439
Joined: Tue Mar 28 2006 3:05am
Location: Canada
Status: Offline

Full Class Names

Post by xenometal »

Are you suggesting to use SRAM as if it was "working" RAM? The thought didn't occur to me at first, but now that you mention it, I recall that Final Conflict seemed to be doing just that from what I could tell.

Unfortunately, I don't think I can address any SRAM at all, since the 4MB expanded ROM is taking up all of the 0x000000-0x3FFFFF addressing space. BigNailCow apparently implemented an SRAM bankswitching routine to handle game saving/loading, but I don't know the details.

Wiz did mention that SRAM size could be doubled if needed, this could open interesting opportunities if we had an extra 16KB of RAM to work with.

As for whether that's cheating, well, why does it matter as long as the hardware is happy to play along with it? I say, let's just crank all of the knobs up to 11 and call it a day. :biggrin:

--

Here's a quick patch in the meantime that implements full class names.
Image Image
Image Image
Why Sheela? Because.
This includes a variant of BigNailCow's 3 digit stats hack, and as you can see, also preserves the ability to display the vanilla class name abbreviations where space is limited.

I'd like to know your opinion on the new window layout designs in terms of aesthetics, readability, etc.

Something to note is that I had to split the "class name + character name" header in the main status window into two lines due to some longer string combinations running outside the border (looking at you, "Pegasus Knight Chester"!) It does have the side effect of looking a bit jarring when the string is short enough that it could fit on one line, though. Hmmm...
Last edited by xenometal on Mon May 14 2018 6:36am, edited 1 time in total.
User avatar
Diego_Didakus
Shining Hero
Shining Hero
Posts: 614
Joined: Wed May 05 2010 2:48pm
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by Diego_Didakus »

Looks really good. Normally as second img shows the class names comes after the name, why it is first(mastermonk sheela) in the first image? something to do with space?

I think its great that in battle and small windows still has abreviation, its a good use of space and remais some classic flavor :P
Check out my projects: https://quasarcorpsgame.com.br/

Speaking...tires me.
Fighting...tires me
I'm tired.
User avatar
Remuko
Member
Member
Posts: 37
Joined: Thu Jul 02 2009 3:36am
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by Remuko »

xenometal wrote:Are you suggesting to use SRAM as if it was "working" RAM? The thought didn't occur to me at first, but now that you mention it, I recall that Final Conflict seemed to be doing just that from what I could tell.

Unfortunately, I don't think I can address any SRAM at all, since the 4MB expanded ROM is taking up all of the 0x000000-0x3FFFFF addressing space. BigNailCow apparently implemented an SRAM bankswitching routine to handle game saving/loading, but I don't know the details.

Wiz did mention that SRAM size could be doubled if needed, this could open interesting opportunities if we had an extra 16KB of RAM to work with.

As for whether that's cheating, well, why does it matter as long as the hardware is happy to play along with it? I say, let's just crank all of the knobs up to 11 and call it a day. :biggrin:

--

Here's a quick patch in the meantime that implements full class names.
Image Image
Image Image
Why Sheela? Because.
This includes a variant of BigNailCow's 3 digit stats hack, and as you can see, also preserves the ability to display the vanilla class name abbreviations where space is limited.

I'd like to know your opinion on the new window layout designs in terms of aesthetics, readability, etc.

Something to note is that I had to split the "class name + character name" header in the main status window into two lines due to some longer string combinations running outside the border (looking at you, "Pegasus Knight Chester"!) It does have the side effect of looking a bit jarring when the string is short enough that it could fit on one line, though. Hmmm...

I'm curious in one of those Sheela pics from the menus, it has the bit on the side that shows the map sprite, but it has a number 19 above her sprite. What's that about?
User avatar
xenometal
Shining Member
Shining Member
Posts: 439
Joined: Tue Mar 28 2006 3:05am
Location: Canada
Status: Offline

Character Expansion

Post by xenometal »

DiegoMM wrote:Looks really good. Normally as second img shows the class names comes after the name, why it is first(mastermonk sheela) in the first image? something to do with space?

I think its great that in battle and small windows still has abreviation, its a good use of space and remais some classic flavor :P
That's how it is in the original game, e.g., "MMNK SHEELA". I aimed to stay as close as possible to the original layout, but it's not a problem to swap the two strings positions should that be preferable. As for what's preferable, well, that's subjective so I'm open to suggestions.

By the way, there's a visual oddity that I've purposefully omitted in the above pictures. :shifty: In the characters listing window, "Pegasus Knight" is running out of space, so the "t" is being overwritten by the level... That's servicable as-is, but hardly looks good! A solution could be to kill the EXP reading and shift LV all the way to the right I guess, but I'm really not sure how preferable that would be! In fact, "Pegasus Knight" is just being a pain in general. Damn you, "Pegasus Knight"!
Remuko wrote:I'm curious in one of those Sheela pics from the menus, it has the bit on the side that shows the map sprite, but it has a number 19 above her sprite. What's that about?
My bad. I took the picture while in debug mode (which is a feature of the original game, so unrelated to my work). Don't worry, it won't show up when playing normally.

--

So, I figure it's about time that I share my work on a much requested feature: Character Expansion
Image
You can finally play as your favorite character: Elis
Download link: Latest patched disassembly

Features:
  • Currently supports the two dummied out character slots, as I'm unsure whether we can easily repurpose superfluous enemy slots at this time.
  • Basic functionalities in and out of battles have been tested; it seems to work fine! :thumbsup:
  • Saving/Loading works (although I didn't have to do anything; the engine already supported it. ;) )
  • Reworking of the portrait assignment routine for force members.
When I say basic functionalities, I mean common actions that we typically perform when playing SF. Off the top of my head:
  • Out of battle:
  • Stats generation (level-up to starting level at new game start)
  • Recruitment/Appointment to the active force
  • Transferring items
  • Equipping weapons
  • Resurrection

    In-battle:
  • Presence on the battlefield (normally, even if we manage to hack one of the dummied out characters into our active force, they couldn't participate in battle. In fact, they wouldn't seem to even exist at all!)
  • Getting a turn
  • Attacking an enemy
  • Being targeted by enemy attacks
  • Gaining EXP/Leveling up
  • Stats being reset after battle
On the other hand, I didn't get to test some edge cases/hardcoded effect routines such as, say, Aura 4 targeting the whole force or Prism Flowers death ray of doom moderate annoyance. Use at your own risk, and bug reports are welcomed!

As for "reworking of the portrait assignment routine for force members", we must know that the character index is normally used as the portrait index for force members. In vanilla SF2, we have the first 30 portraits which are reserved for our force immediately followed by Elis' and Astral's; this means that our new recruits are forced to use these two portraits by default. In addition, there are some further hardcoded shenanigans going on that override portrait index based on class (for those who get a new portrait upon promotion.) This poses a problem whenever we want to repurpose classes; all our ninja would belong to Slade!

In other words, the current system is hot garbage, so I wrote a routine that instead retrieves a portrait based on a character's map sprite, referencing a table that already exists (thanks to Earl for reminding me of it!)

Thankfully, Wiz has recently released a nice tool that allows us to easily modify this data, so it shouldn't be too much trouble to set up your new characters. Basically, once you've defined a base map sprite in "disasm\data\stats\allies\allyspriteids.bin" (here's another beautifully hardcoded system, by the way), then you simply make sure that a portrait is linked to it in "disasm\data\spritedialogdefs.bin" using Wiz's SF2DialogPropertiesManager tool.

Let me know how it goes!
User avatar
Diego_Didakus
Shining Hero
Shining Hero
Posts: 614
Joined: Wed May 05 2010 2:48pm
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by Diego_Didakus »

wonderful! cant wait to try.
How can we make then join the force?
Check out my projects: https://quasarcorpsgame.com.br/

Speaking...tires me.
Fighting...tires me
I'm tired.
User avatar
xenometal
Shining Member
Shining Member
Posts: 439
Joined: Tue Mar 28 2006 3:05am
Location: Canada
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by xenometal »

That's... a good question! I've just been using the Debug/Battle Test mode to test things out for now. Here's a patch that'll let you access that feature along with the Special Configuration mode more easily. That'll make it so that at the Sega logo, you'll only need to press either Up and/or Down to activates these modes, respectively.

As for the Battle Test, first press Up to activate Debug mode (you'll hear the "cursed item" jingle), then press Up again and hold it until you see a textbox that says "Battle number?". Um, yeah, so it's not the most user-friendly thing ever but it's serviceable. :lol:

On the other hand, if you're asking how to add the characters into the game world and have them join "properly" after some dialogue and whatnot, well, that's a fairly complex question to answer! I don't even know all the details myself at this time, but the gist of it is that it involves "mapsetups" (ASM files located in "disasm\data\maps\entries\mapXX\mapsetups"), more specifically the "s2.asm" files that handle entity events such as NPC interaction. You'll also want to refer to Wiz's Cutscene Documentation.

If you're up to it, I suggest to give a look at the mapsetups for map08 (Ribble) for the event that lets you recruit May, as that's about the simplest example of a character join event, i.e., some NPC randomly wandering the map, you talk to them, they join.
User avatar
SirHedge
Shining Hero
Shining Hero
Posts: 1189
Joined: Sat Mar 15 2008 4:10am
Status: Offline

Re: Xenometal's SF2DISASM workshop

Post by SirHedge »

xenometal wrote:However, another issue has presented itself; the Deals section. There's only enough room in RAM to keep track of item amounts (up to fifteen) for 128 item indexes under the current system, so expanded items cannot be added to deals at the moment. This will eventually need to be addressed somehow.
Was re-reading this thread today and wondered on the issues with deals and expanded items: what about changing the deals code to not track quantities for each item and instead just track up to 64 unique items? Considering there are limited items that can even make it to deals, wouldn't that be acceptable? Or is that too much of a rewrite for the overall code?

EDIT: It also occurred to me that this explain the "why 15 mithrils" questions. Programmatically, why can't have more than 15 of any item go into deals. So 15 mithrils were the most they could add without risking glitches.
Post Reply