øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=1993.msg22099e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexb58e.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=1993.30e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexb58e.html.zx©,g^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈÐC7OKtext/htmlISO-8859-1gzip0|ÖC7ÿÿÿÿÿÿÿÿTue, 10 Mar 2020 06:15:27 GMT0ó°° ®0®P®€§²ð®¨,g^ÿÿÿÿÿÿÿÿ Final Fantasy IV: Side Project (Random AI Routine complete!)

Author Topic: Final Fantasy IV: Side Project (Random AI Routine complete!)  (Read 10576 times)

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #30 on: January 02, 2015, 06:49:16 PM »
Thanks Chillyfeez! Well that's everything done with the Shadow Party, and I've increased the levels of enemies as suggested to assure they don't get too powerful, too quickly (though there is still the worry that the decrease in stats may make them too weak, but we'll see). Now it's time for me to do my part and get the randomized enemy AI up and running.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #31 on: January 02, 2015, 07:34:51 PM »
So I hit my first roadblock... what I did with my Dragon Speech hack is force it to look only at the first enemy's typing. This obviously wouldn't work in randomized AI and there is no easy way to discern what monsters are Type0,1, or 2 within the stats, so after pondering the question for a while I think I'll have to do something a little different. I think I'll have to tie randomized AI to (unused) magical evasion and put it in a byte where it's not doing anything. While it sacrifices (dummied)magical evasion, I'm not too worried, since magical evasion can get rather crazy in default FFIV and in some respects its little wonder they axed it in the manner they did. This should give me full control of which enemy's will have what AI.

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #32 on: January 02, 2015, 07:58:12 PM »
Is this something that's only looking at enemies' unused stat bytes?
Because ATB uses at least one (maybe more?) unused stat byte of each player character.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #33 on: January 02, 2015, 08:10:35 PM »
Is this something that's only looking at enemies' unused stat bytes?
Because ATB uses at least one (maybe more?) unused stat byte of each player character.

Indeed it uses only enemy bytes, I'll give an example of what I mean...

Imp will use Random AI set 01, so his Magic Evasion in the editor will be set to 01.

Using the info. I've recorded down on my Evasion fix...

$03/90E9   9D 22 20   STA $2022,x[$7E:22A2]   A:0001   X:0280   Y:0083   P:envMxdIzC - Store Magic Defense Multiplier into Monster's stats
$03/90EC   AD 1D 29   LDA $291D  [$7E:291D]   A:0001   X:0280   Y:0083   P:envMxdIzC - Load Magical Evasion
$03/90EF   9D 24 20   STA $2024,x[$7E:22A4]   A:0028   X:0280   Y:0083   P:envMxdIzC - Load Magical Evasion into Monster's stats (where Magical Defense Base will be)
$03/90F2   AD 1E 29   LDA $291E  [$7E:291E]   A:0028   X:0280   Y:0083   P:envMxdIzC - Load Magical Defense Base
$03/90F5   9D 24 20   STA $2024,x[$7E:22A4]   A:0009   X:0280   Y:0083   P:envMxdIzC - Store Magical Defense Base over Magical Evasion

I just change...

$03/90EF   9D 24 20   STA $2024,x[$7E:22A4]   A:0028   X:0280   Y:0083   P:envMxdIzC - Load Magical Evasion into Monster's stats (where Magical Defense Base will be)

To 9D3420 which will store Magical Evasion into Monster's Right Hand Quantity which is never looked at by the game and use that as an easy reference point for all monsters to find the AI Pattern they should be using when the routine calls for it.


 :edit: Oh, I see. You're using that byte as well, thankfully you still have that old piece of code hanging there in the jump. So I can still change it without worrying, phew I was worried there for a second.
« Last Edit: January 02, 2015, 08:18:17 PM by Grimoire LD »

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #34 on: January 02, 2015, 08:44:01 PM »
Oh, yeah, I forgot that level-up uses some unused monster bytes... But just as place holders for the calculations, I think.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #35 on: January 02, 2015, 09:42:14 PM »
I will have to think carefully on how I want to tackle this, I have the record and the jump in data, but I tried to set up an AI pattern and came to the realization that there really is not enough room for the 64 monster types, and even if there was it would be the most inefficient means of coding ever conceived at least in a basic set up, so what I need to do is create a set of bytes that are in ROM Data for the 64 (possibly more if I have room in ROM) Randomized AI Setups.

The plan is this...

1. Look in ROM for 800 free consecutive bytes. (320 in hex)
2. Write the AI abilities into these bytes starting from Imp AI and onwards.

3. Write the routine consisting of...

Create Random Number between 0-3 - store it in Monster's Left-Handed quantity - Look at Magic Evasion - x4 it, store it in X, Add the random number in left handed quantity to X. Load ROM Address where the AI is stored +X(to get to the correct AI) -  A BEQ for 00 to allow for basic Fight command. Maybe something special for Ally Targeting commands, and that should do it.

This is much more efficient than my original plan, now I just need to find those 320 Bytes and I'll be golden.

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #36 on: January 02, 2015, 10:05:36 PM »
The empty spaces around the summon images should be more than enough if you can't find it anywhere else.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #37 on: January 02, 2015, 10:17:04 PM »
The empty spaces around the summon images should be more than enough if you can't find it anywhere else.

Thanks for the suggestion Chillyfeez, I think though that I might have just found a gigantic amount right underneath the Title Screen's graphics. Starting from 438C0 to 44000, that's more than enough, and then some. At first I thought it may have been the blackness around the title screen, but it does not appear to be.

In LoRom this is at... 08B8C0

This should really get me started then.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #38 on: January 03, 2015, 12:06:30 AM »
And I've hit another snag that I wasn't anticipating. Enemy using Commands is Nothing like characters using command. For giving a character randomized command is an absurdly simple process, here it is the opposite thereof. Enemies don't follow the same rules and may use a different matter all together to draw their next attack from, if such is the case I will need to strike at the core of the basic AI system instead of trying to treat them as semi-PC's and thinking that they can use Spells from Commands.

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #39 on: January 03, 2015, 01:03:27 AM »
Hmm... Yeah.

You might have to set a breakpoint to where the AI scripts are loaded into RAM... It's gonna require some custom coding.

Maybe what you can do is take one of those unused/disused AI commands you guys were talking about recently and write a new routine for it... You could essentially copy one of the "cast a spell" routines, except preempt that with the RNG that determines which spell, if that makes any sense at all...

Or just work it into one of the "cast a spell" routines... For instance, I don't know what spell BF is or who uses it, but let's pretend for the sake of demonstration it can be done without. You would tell the AI reading code (during a JSL) that after it loads the battle command into A, if A=BF, then jump to the specialized RNG code (otherwise proceed as normal).

Sorry if that sounds like babble... Let me know if you need me to clarify, unless you've already figured something else out.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #40 on: January 03, 2015, 06:53:47 AM »
BF is the graphic for Zeromus' Full Heal attack, that's it. So while not unused, it is rather strange that they created a slot for it when i think they could have just used the initial Zeromus Elixir attack and add a graphic to it. But I know of a spell that is completely unused (aside from the two below W. Meteo) and that is DullSong, it's meant to be used in a counter script by Milon-Z but was never given to him for some reason (Rubicante also has an unused counter script) DullSong also has the added benefit of suppressing its name so no chance of "RandomAI" showing up for the player to see. That was my first attempt, but then I saw that monsters use commands differently and by the time they use a spell they don't seem to have the capacity to change what the spell will be, at least not in the same way PC's do. So that plan was out. The second plan was to use Cid's "Crash" command and tie random skills into that and though I have the code working perfectly (if they were PC's) it doesn't work the same for enemies.

So my plan is to trace back in enemy AI until I find what puts the default spell into the Spell Action byte and manipulate it from its source with a jump to custom code that checks to see if  the spell is DullSong (now called RandomAI) and if so to move forward in my custom code. I'll hopefully be able to figure this out when I get home from work today.


 :edit: And accomplished! I can easily branch it into the code which looks at the AI routine, look for the specific spell (in this case DullSong) and move off of my custom code from there, this actually might be Much cleaner than I originally anticipated! Expect some updates when I get home later tonight!
« Last Edit: January 03, 2015, 08:01:45 AM by Grimoire LD »

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #41 on: January 03, 2015, 08:27:14 AM »
Oh, good.
I was just looking into this and about to post some findings/ideas, but it looks like you're all set.
Looking forward to what you come up with.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Final Fantasy IV: Side Project
« Reply #42 on: January 03, 2015, 06:00:35 PM »
I expected this to take at least 80 to 100 bytes, boy was I wrong! The basic set-up has been implemented and works to perfection!  It is such a simple method that I utilized, but first the important notes...

(the current hex will lead directly into my code and I'll explain their function lateR)

Code: [Select]
$03/B557 AE C1 35 LDX $35C1  [$7E:35C1] A:0007 X:0006 Y:FFFF P:envMxdizc - Load AI Pointer into A.
$03/B55A 7B TDC A:0007 X:0780 Y:FFFF P:envMxdizc - Clear A
$03/B55B A8 TAY A:0000 X:0780 Y:FFFF P:envMxdiZc - Transfer A to Y.
$03/B55C BD 5F 40 LDA $405F,x[$7E:47DF] A:0000 X:0780 Y:0000 P:envMxdiZc - Load AI Command into A.
$03/B55F C9 FF CMP #$FF A:0076 X:0780 Y:0000 P:envMxdizc - Is it End?
$03/B561 D0 07 BNE $07    [$B56A] A:0076 X:0780 Y:0000 P:envMxdizc - If not, branch.
----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------
$03/B56A 20 F0 FE JSR $FEF0  [$03:FEF0] A:0076 X:0780 Y:0000 P:envMxdizc - Jump to custom subroutine.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
$03/FEF0 BD 5F 40 LDA $405F,x[$7E:47DF] A:0076 X:0780 Y:0000 P:envMxdizc - Load AI Command into A (used as a looping point at times)
$03/FEF3 C9 76 CMP #$76 A:0076 X:0780 Y:0000 P:envMxdizc - Is it Random AI?
$03/FEF5 D0 1C BNE $1C    [$FF13] A:0076 X:0780 Y:0000 P:envMxdiZC - If not, branch to end.
----------------------------------------------------------------------------------------------
$03/FEF7 DA PHX A:0076 X:0780 Y:0000 P:envMxdiZC - Push X (to retrieve at end of custom routine)
$03/FEF8 A2 00 00 LDX #$0000 A:0076 X:0780 Y:0000 P:envMxdiZC - Load 0000 into X.
$03/FEFB A9 03 LDA #$03 A:0076 X:0000 Y:0000 P:envMxdiZC - Load 03 into A.
$03/FEFD 20 79 83 JSR $8379  [$03:8379] A:0003 X:0000 Y:0000 P:envMxdizC - Produce a random number between 00-03.
$03/FF00 A6 A6 LDX $A6    [$00:00A6] A:0001 X:0000 Y:0000 P:envMxdizc - Load Unit Identifier into X.
$03/FF02 9D 26 20 STA $2026,x[$7E:2426] A:0001 X:0400 Y:0000 P:envMxdizc - Store Random Number in Left-Hand Quantity (unused by enemies)
$03/FF05 BD 24 20 LDA $2024,x[$7E:2424] A:0001 X:0400 Y:0000 P:envMxdizc - Load Enemy's AI Pattern number (Magical Evasion) from Right-Hand quantity
$03/FF08 0A ASL A A:0001 X:0400 Y:0000 P:envMxdizc - x2 A
$03/FF09 0A ASL A A:0002 X:0400 Y:0000 P:envMxdizc - x2 A (Four bytes comprise the random AI for each monster and this x4 gets you accurately to the Random AI for that number.
$03/FF0A 7D 26 20 ADC $2026,x[$7E:2426] A:0004 X:0400 Y:0000 P:envMxdizc - Add the random value onto A.
$03/FF0D AA TAX A:0005 X:0400 Y:0000 P:envMxdizc - Transfer A to X
$03/FF0E BF BC B8 08 LDA $08B8BC,x[$08:B8C1] A:0005 X:0005 Y:0000 P:envMxdizc - Load A from Random AI Pointers - AI 1 - Option 2.
$03/FF12 FA PLX A:0002 X:0005 Y:0000 P:envMxdizc - Pull X (to bring X to its proper reading from the start of the custom routine)
$03/FF13 60 RTS A:0002 X:0780 Y:0000 P:envMxdizc - Return to normal AI Procedure.

And that took a grand total of 23 bytes to accomplish.

So now Imps can do...



This...



That...



Or even this!



(Note: Imps are not likely getting Wall, the rest seems fair enough)


I have to give the AI some real credit, by cracking into it at such an early juncture nothing from RandomAI's default spell setting has been loaded and so everything is loaded from this random choice of four options, so the AI won't do anything stupid like casting Cure on your party or using Slow on itself and it is completely non-intrusive. It has purposely been placed over an unused move and changing what moves you want the AI to randomly use is a simple matter of taking their Magic Evasion x4 and going from there so hackers that may normally be scared away by my more complicated hacks should find this one remarkably easy to work with.


So all of the hacking is now complete! Now it's just a matter of figuring out what randomized AI I want for 100 enemies.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Final Fantasy IV: Side Project (Random AI Routine complete!)
« Reply #43 on: January 03, 2015, 07:53:36 PM »
At least it looked like it worked to perfection in principle, but Chillyfeez your Level Up Mod also messes with Magical Evasion, which is 1/3 the basis of this hack (hence enemies use the wrong Random AI set). Is there anyway to disable the function that seems to alter Magical Evasion?

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Final Fantasy IV: Side Project (Random AI Routine complete!)
« Reply #44 on: January 03, 2015, 08:38:37 PM »
Yeah. That should be doable.
Let's see... Did I post the disasembly for that mod...?

 :edit:
I did, but... Which stat are you talking about specifically?
It looks like, in the commented disassembly, I talked about adjusting magic defense base and magic defense multiplier, but not magic defense percentage (which is what I thought you were talking about).
« Last Edit: January 03, 2015, 08:44:24 PM by chillyfeez »