Jump to content
Sign in to follow this  
Crazycolorz5

Determining Equipped Item(FE7)

Recommended Posts

Hello. I wanted to figure out how the game determines what item slot a character has equipped for various reasons. Usually slot one, but the unit could have an item in slot one and weapon in slot two, or be unequipped. SURE, I could write my own, but first off, I want to see how the game does it, and second off, it's easier just to write a bl call. Okay, so I set out debugging FE7. I figured that equipping is vital to attacking, so I checked docs for battle routines, and the closest I came to actually determining equipped item is in Nintenlord's "pre battle.txt" which tells me that byte 0x48 after 0203A3F0 will contain "Equipped item after battle"(and also 0x4A for "Eqipped item pre battle").

So I set my debugger to auto-break after detecting a write to 0203A43A, and I played around a bit. It does indeed pause when I go to the pre-battle screen, when I press R over a unit and when I go into the items menu(and for that matter, it re-updates when I scroll around on item menus). Most importantly, it does seem to contain the equipped item. So analyzed the code that was editing it, and moved up a little bit and found (at 08028806) a ldrh r0, [r0], which always loads the correct item ID, meaning if I could find how the game generated the r0 pointer, that would be the pointer to the slot of the correctly equip-able item. My debugger reports r0 as being 0203A40E, whis is by nintenlord's notes the item 1 slot. So then in turn I tried to figure out how the computer gets the correct equip in that slot (It correctly loads the items if I stick a vulnerary in slot 1, although it does trip up if there are no equip-able items, though I can probably look at writes to 0203A43A with no equips to see how it determines that.) (Now that I type that maybe that's an indication that I still have yet to find the exact routine that checks for that).

So I set my debugger again to stop when that byte was edited... and I came across a subroutine that I realized copies data from one section of the RAM to another (It's at 090BFFC2). Oh great. After running a few times, it doesn't always use the same source ram(though it is always in the 3000000s, the quickly-accessible RAM).

So uh, I still need to find the subroutine, and does anyone want to guide me on how to proceed from here? I'm really at a loss.

Share this post


Link to post
Share on other sites

what are you trying to do exactly? the equipped item is always the first entry in the inventory_data array in the unit struct located at 0203A3F0; i wouldn't be surprised if there's some marker somewhere in the standard unit struct (the kind that fills the array at 0202BD50) that determines which inventory slot contains the equipped item so it can get moved into the proper place when unit data gets copied over

Share this post


Link to post
Share on other sites

Yeah, basically, I either need that byte to determine which item is equipped, or I want to figure out what subroutine forces the equip to the first entry.

Edit(more info): 0203A3F0 is only updated under certain circumstances, so if I need to check equipped item in some other, possibly un-updated, circumstance, I need to know how to either to force it to update or what subroutine to call to determine it(Or, exactly how the game finds it and re-implement that. I want to avoid implementing a method that's different from the game's original way.)

Edit(additional thought): Though I don't think there's a byte in the standard unit struct that tells anything about equipment. Shuffling around items and weapons in their inventory with a memory viewer open reveal no changes besides the code of the items themselves.

Edited by Crazycolorz5

Share this post


Link to post
Share on other sites

what exactly are you attempting to do? 0203A3F0 is the struct for whatever unit is currently loaded as "active" (meaning either their data is open or if they start a fight or whatever); you'd be better off backtracing the the entire struct (instead of just the item data) when it gets transferred from the player_units array and just making special note of when items get transferred

Edited by CT075

Share this post


Link to post
Share on other sites

Yeah, but that's the problem. It's transferred from a section of 3000000-RAm, and the offset seems to vary slightly each time. Also, a lot of other things are copied to there so it's difficult to track.

Share this post


Link to post
Share on other sites

it'd probably be easier to readbreak from a specific unit

still not entirely sure what you might be trying to do that would entail needing that exact subroutine; maybe a change of approach is being called for?

Share this post


Link to post
Share on other sites

Taking a page out of @icecube's book (http://forums.feshrine.net/index.php?showtopic=5224) and posting documentation on stuff that puzzled me way back but now I'm more experienced... and crap.

Anyway, on the unit structs at 0203A3F0, the 0x4A halfword is the equipped item (as an item data, which I mean 0x0000AABB, AA=durability, BB=ID)

The in-game method for getting the equipped item of a unit is at 0x16764 (FE7) (see http://feuniverse.us/t/getters-for-equipped-item/411 for more details)

I haven't found a getter to get the position in the inventory that that item is at, but you can either loop through or debug the item screen (they need the index to know where to draw the E and the bar thing, right?). Or like, copy-paste most of the code at the equipped item getter but return the index instead of the actual item.

Share this post


Link to post
Share on other sites

idk maybe rather than just scattered things like this, we can have a grand unified library of built in functions. Including but not limited to what you have there, as well as the getters for stats and other random things.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...