Modding => PSX FFT Hacking => Topic started by: BigManStan on March 07, 2016, 08:37:06 pm
Title: ASM Questions
Post by: BigManStan on March 07, 2016, 08:37:06 pm
Hi all,
New to FFT hacking and hacking in general. This is my first foray into assembly language coding and I had a few questions on how stuff is done.
1) I want to create a new routine in free space that is called from existing code. In order to do that I need to use 2 instructions I assume, a jump and delay slot. Assuming this is correct, what is done with the instructions that are overwritten by the jump/delay?
I was studying Xifanie's Weapon Strike fix v1 as an example, and it looked like the 2 existing instructions that were stomped (saving $31 to stack) were tacked on to the end of the Weapon Strike routine before jumping back to the original code. I was wondering if this is a general solution that can be used.
2) Temporary registers: If I call a routine from my code that is in the middle of an existing routine in the original code, and the original code is using the temporary registers (4-7 I think) do I need my routine to handle saving the temporary registers? I was reading some assembly stuff and it says that saving temporaries is the caller's responsibility, not the callee's but in this situation I would need to overwrite even more existing code lines to do this. I was wondering how this works? Does my code need to save them (seems bad) or do I need to overwrite more lines from the existing code to do this?
And please let me know if I am way off base with these questions, or if I am lacking some fundamental knowledge. I am very new to assembly and hacking so there may be some holes in my knowledge that I am not aware of.
Thanks!
Title: Re: ASM Questions
Post by: Choto on March 07, 2016, 09:35:22 pm
1) You just have to make sure that everything that you bump out of place gets returned the way it should have been after your routine finishes. The simplest way is just to execute the commands that got stomped on at the beginning of your routine. However, depending on the situation you may want to move them around if needed.
2) One little trick is that you can look further down the routine and see if any registers get straight-overwritten by an ori or load command. Basically if the game doesn't use what's in that register and overwrites it, it's safe to use up until that point. Otherwise, you can save registers on the stack, or even a designated location in free space that you reserve. It will take additional commands to do so, but it's not bad at all. You can run these commands in your custom routine as soon as you jump. There's a quite a bit of free space so number of commands isn't a huge deal.
Hope it helps!
Title: Re: ASM Questions
Post by: Xifanie on March 08, 2016, 07:59:06 am
Oh please don't use my old hacks as examples... I didn't even have any "coding practice" back then. In fact, that hack doesn't even work as advertised; it only affects formula 2D. Please forget everything you saw in that hack and just focus on these aspects: - Use registers that are are overwritten afterwards to your heart's contents - If you need more registers, usually the stack range is only used for temporarily storing registers, so if you see addiu r29, r29, 0xFFEC and addiu r29, r29, 0x0014 with sw/lw r??, 0x0008/0x000C/0x00010(r29), that means 0x0000 and 0x0004 are free to use. Just increase the range if you need more and save the registers yourself then load them back before jumping back - Try to ONLY use r1 for memory addresses - Don't do that shit I used to do with mflo/mtlo/mfhi/mthi to temporarily store registers. It's ugly and using the stack is way cleaner... not to mention that it can't be used if you plan to use mult/div.
Title: Re: ASM Questions
Post by: BigManStan on March 08, 2016, 01:32:33 pm
Thanks for the helpful replies.
I wanted to be diligent about maintaining the program state and using the stack correctly, especially since I was planning on calling some of the existing FFT routines from within my code.
Xifanie, I was only looking at the jump and return portions of your hack, so hopefully my coding standards haven't been damaged too badly :P
Title: Re: ASM Questions
Post by: Choto on March 09, 2016, 10:33:44 pm
No problemo, you seem well spoken and we always help people who help themselves. Looking forward to seeing what you cook up!
Ask us if you get stuck on something, ASM is really easy once you know how to do it.
Title: Re: ASM Questions
Post by: BigManStan on March 10, 2016, 09:57:35 pm
Cool, thanks :)
I thought I would post a preview of what I'm working on. I'm currently exploring the concept of dynamically generated skillsets.
Specifically, what I wanted was some type of class/skillset that can inherit the abilities of monsters that are in battle with me. I originally drew this up to be a skillset that's equipped to a 'specialty monster' (eg Archaic Demon, Byblos, etc) but if it makes some sense I could extend it so it's a full fledged job. I have no interest in overriding a current generic class for this.
Anyway, as a proof of concept I wanted to develop a skillset that just groups all the abilities of monsters that players select for battle in the formation screen. The skills would only be present while in battle, and not in the overworld.
What I have so far is the code that will populate the skillset with monster abilities at the start of battle. It's very rough around the edges at this point.
Good Stuff: - Abilities work properly - Selectable in act menu and in status screen in battle - AI will use abilities, although the available abilities are from the player's team rather than their team. Unsure if slot 2 is required for the AI to have access to all abilities.
Needs Work: - Missing animations if the sprite set is missing the correct stuff, I think - Abilities use MP - Speed is displayed in the status screen for some abilities, ideally they should all display 0 or 'Now' if they do not have a CT - Erase the skillset at the end of battle - I want to not include abilities that require monster skill
Nice to Have: - Have the code search allied units instead of player units. This would allow enemy formations to use their own monster skills. - Have all abilities be instant-learned if I expand this to a job.
Most of these issues are just stuff I haven't gotten to yet, I have just reached the point where I have a first release that does something! Feel free to offer any input or critique.
Patch:
<Patch name="Battle Monsters Skillset v0.1"> <Description> This patch dynamically generates a skillset in skillset [SETID] (default 94, an unused skillset) at the start of battle.
The generated skillset consists of up to 16 unique monster skills, sourced from monsters brought by the player to battle. </Description>
#This code will generate a skillset with up to 16 unique abilities #sourced from player controlled monsters in battle. #Any non-R/S/M abilities in the selected skillset will be overwritten.
Title: Re: ASM Questions
Post by: BigManStan on March 21, 2016, 02:30:29 pm
Hello all,
I am trying to code some junk related to skillsets. I was wondering, is there an area in memory that identifies a unit that is currently selected? I have scoured the data location information and haven't seen anything for this.
I would like to override the 'Load Ability from Skillset' routine, and have it do different things depending on what unit the skillset is being loaded for. However, I have not yet found a reliable way to identify the unit. The 'acting unit' ID locations have worked somewhat, but they fail in cases like when I'm viewing a unit's skills in the status menu when it's not that unit's turn.
If anyone knows anything regarding this, help is appreciated. I might be barking down the wrong tree, I know that the unit ID is not something that is officially passed along to the 'Load Ability...' routine, so it might be impossible for me to 100% determine the unit the skillset is being loaded for in all cases.
Thanks!
Title: Re: ASM Questions
Post by: Xifanie on March 21, 2016, 03:41:40 pm
Really not sure what to say... it's hard to suggest anything not knowing exactly what you're trying to code. I have personally worked with that section a month ago (I think, or will have to eventually), and there would at least always be the address for the learned abilities of the currently affected unit in an active register.
Title: Re: ASM Questions
Post by: BigManStan on March 21, 2016, 07:43:26 pm
Hmm, okay, I'll bite.
I am trying to create a new skillset with a theme of synergy between the skillset's user and allied monsters on the team. (Unsure of the name, was thinking 'Empathy' or 'Beast Mastery')
The skillset will consist of a 'normal', fixed set of skills (at least 1, up to 4 I was thinking), and the rest of the skill slots being always blank on the world screens but able to be dynamically filled with monster skills of allied monsters in battle.
The main driver of the skillset, and first fixed skill is a 'Bond' ability which allows the user to apply a 'Bond' status, with only allowed targets being allied monsters ('bondees'). When a monster is under 'Bond' status, it's non Monster Skill abilities will be available for the caster that applied Bond to the unit (the 'bonder'). I was also planning on the other 3 fixed abilities for this skillset to only target allied monsters as well, and have additional enhancements if the monster is Bonded to the caster.
The issue that I was getting at, is that if there are multiple units with this skillset, or multiple 'bonders', each instance of their available skills may differ depending on the 'bondees' that each 'bonder' has. I have a table in memory that stores the relationships between bonders and bondees, and if I was able to determine the requesting unit, when the game asks for an ability from that skillset, I could consult the bond table to determine the correct skills to provide when the routine is called.
I have been making an alpha version of this with the Bond status and table mechanics working correctly (I can post the code if anyone is curious) and I have been developing this using a routine that just overwrites a skillset with the bonded abilities when Bond is applied/removed so that the game can just read the altered skillset, and it works good. The problem here is that I would need a free skillset for every unit in battle that wants to use this.
tl;dr: I want to have a single skillset that can behave differently in battle depending on the unit that it is assigned to. Therefore it would be necessary for me to determine the unit that is making the load request, for a skill from the skillset.
If anyone is interested, there are more details and ideas that I have for this here:
- A unit with the skillset may apply 'Bond' status to allied monsters using the Bond ability. Have not determined the parameters for this, but I was thinking a melee range no charge, 100% success rate skill.
- Only allied, 'true' monsters with monster skillsets can be Bonded.
- A unit under Bond status benefits the 'bonder'. The bonder has access to all monster skills of the 'bondee'.
- A bonder may have multiple bondees. Bondees can only have a single 'bonder'.
- 12 ability slots will be available for bondee skills, they will be listed in order of CT remaining for Bond status on each bondee (newest bonded units skills listed first)
- Bond will have a finite CT. Positive-status dispelling abilities should remove it.
- When Bond status removed, the bondee skills will no longer be available to bonder. A different bonder applying Bond to an already Bonded unit will remove the existing bond and create a new bond to itself.
- Not sure yet if the bond should go away on bondee death, bonder death, both or none.
Other Ability Ideas:
'Swap', 'Save', ...: - Target allied monsters. Invalid units not targetable. Caster will exchange position with the targeted unit, dealing damage equal to the difference between target unit HP and caster HP in an AoE around the targeted unit.
- Percent success of Swap will decrease based on distance between the units. Will always have 100% success rate if units are Bonded, and always 0% success rate if either positions of the exchanged units are illegal.
'Sacrifice', 'Martyr': - Target allied monsters. Invalid units not targetable. Caster dies on successful resolution of ability. Target unit HP/MP healed to full and unit receives Quick status. 25% chance of adding each of Haste / Protect / Shell.
- If units are Bonded, target receives Haste, Protect and Shell 100% in addition to other effects.
Support Ability: 'Initial Bond' - Starts a battle with 1 ally unit already Bonded to this unit. The ally to bond is determined by closest bondable unit on the formation screen. Ties are randomly determined.
Reaction Ability: (no idea what to call it) - May react using the reaction abilities of any bonded units. Precedence may be determined by using the reaction stacking hack (I think)
Title: Re: ASM Questions
Post by: Xifanie on March 21, 2016, 07:56:53 pm
Well, how I coded the bonus skillset for the ARH2 was making an exception for a unique skillset (Bonus Skillset), and have it parse every single ability in the game (0x000-0x16F); if the conditions matched, it would add the ability to the list of available skills (I don't know if you've seen/found that yet), if not, it would just try the next ability.
I could potentially share my spreadsheet, but it's a big hack and it might not be simple to find what you're looking for... how I work is that I take a lot of temporary notes that I just discard permanently because well, I'm done with them. In fact I'm not sure if my hack itself writes to the available abilities or just transfers the ability ID... it's been too long. ¯\(°_o)/¯
Title: Re: ASM Questions
Post by: BigManStan on March 21, 2016, 08:19:22 pm
Cool, I would take a look if you had it available. I'm a bit of an Excel doofus so it may be difficult for me to examine, is the assembly backing the spreadsheet accessible from within the spreadsheet to look at?
I remember seeing the 'Bonus Abilities' section; looks cool; I was wondering what the 'requirements' for an ability are, exactly? Might be similar to what I'm looking for, if the Bonus Ability skillset has a single skillset id but can display lists that are different from unit to unit...regardless, thanks for the feedback.
Title: Re: ASM Questions
Post by: Xifanie on March 21, 2016, 08:27:53 pm
Actually, both regular skillsets and the bonus skillset skills have custom, different requirements event. With the ARH2 you can give Fire the "Flame Rod equipped" requirement for the bonus skillset, while keeping the regular skillset one perfectly intact... just like you can a skill permanently available to a special character no matter the job, or have Holy Sword Skills require a sword (just like in vanilla) while giving access to all Holy Sword skills when Excalibur is equipped.
I'll PM you the spreadsheet because it might not be ready for public release (since 22 people downloaded my sheet, and none reported it was, in fact, not working), but I left a bunch of notes to describe what sections does what... it's all in ASM format. So, yeah.
Title: Re: ASM Questions
Post by: BigManStan on May 14, 2016, 03:14:05 am
Hello again,
I was wondering if there is any description of the contents of save files? I've been scouring the wiki and there is tons of info about in-game memory but I can't find a lot about save file contents. I may not be looking in the right places though, if there is any info please let me know. I was looking at story progression data specifically, since FFTastic doesn't seem to handle that.
Title: Re: ASM Questions
Post by: Xifanie on May 14, 2016, 05:21:37 am