Jump to content
Gryz

FE7 - Making Enemies Escape

Recommended Posts

How to make enemy units and NPC units leave the battlefield:

1. Define escape tiles

Escape tile format:
4 bytes: [x, y, exit, 00]

x = x coordinate of escape tile.
y = y coordinate of escape tile.
The top-left corner of the map is (0,0).

exit = Determines what animation is used when the unit steps on the escape tile.
00 = Move left then disappear.
01 = Move right then disappear.
02 = Move down then disappear.
03 = Move up then disappear.
05 = Disappear without moving.
The game uses 00-03 for escape tiles located on the edges of the map. 05 is used on escape tiles located on stairs.

Create a sequence of escape tiles and then terminate it with FF 00 00 00.

Example - Chapter 7x escape points (01, 01, stairs) and (03, 01, stairs):
01 01 05 00 03 01 05 00 FF 00 00 00

The escape tiles used in FE7 chapters begin at address 0x1D3974.

2. Set pointers to escape tiles

Enemy units and NPC units have separate pointers to escape tile data. The pointers are stored in the same order as the chapters in the Chapter Data Editor nightmare module. The enemy pointer table is at address 0xB97100. The NPC pointer table is at address 0xB971C0.

Simple nightmare module for modifying pointers:
(Chapters.txt referring to the same file used by the Chapter Data Editor)

Enemy Pointers

Spoiler

1
Enemy Escape Pointer Editor
0xB97100
47
4
Chapters.txt
NULL

Escape Pointer
0
4
NEHU


NPC Pointers

Spoiler

1
NPC Escape Pointer Editor
0xB971C0
47
4
Chapters.txt
NULL

Escape Pointer
0
4
NEHU


Chapters without escape tiles point to FF 00 00 00.
FE7 chapters without escape tiles point to the FF 00 00 00 located at address 0x1D3A5C.

3. Set enemy and NPC AI bytes with Chapter Unit Editor

AI byte 1 - Aggression Factor
00 = Attack or steal from units that are in-range.
06 = Do not attack or steal.

AI byte 2 - Looting and Escaping
04 = Open/loot doors-chests-villages. After no more targets, remain on the map and attack.
05 = Open/loot doors-chests-villages. After no more targets, move towards nearest escape tile.
0C = Immediately start moving towards escape tiles. Ignore foes.

The standard in-game Brigand uses 00 + 04 for their first two AI bytes.
The standard in-game Thief uses 06 + 05 for their first two AI bytes.

You can't give units specific targets, so you have to manipulate their behavior through door/chest/village placement, starting position, inventory, and escape tile locations. Be careful with door placement. Even if all chests are opened, units will go after unopened doors (instead of escaping) if they still has Door Keys or Lockpicks. However, units will ignore unopened doors and begin to escape if inventory becomes full. Also, units won't use the five-durability Chest Key.

...

Okay. Thanks for reading

Edited by Primefusion

Share this post


Link to post
Share on other sites

Wow! Props to you for this discovery, man. How did you find this data?

I'll try and see if this can be applied to FE8 too, but I have high hopes for it.

Share this post


Link to post
Share on other sites

I found this data in the stupidest way possible - idiotic brute force.
I knew 1,1 and 3,1 were the escape coordinates for chapter 7x. I used a hex editor to find-and-replace the many, many, many instances of 01 01 and 03 01 until the game didn't scream + crash and the thief actually disappeared in a different spot. That moment... was simply beautiful. Then I had to play guessing games with the address ranges until I narrowed it down to the exact location of the coordinates. So, I am no hacking pro, just a persistent and lucky bastard. But I am glad to know that FE hacking holds a bright future in which players will be pissed off as thieves run away with the chapter's treasure.

Share this post


Link to post
Share on other sites

This is very slick, nice work. I've been doing some testing with this and I got some interesting results. Whether or not a thief has a lockpick vs. some combination of chest and door keys seems to change their behavior. In one of my chapters I have a thief spawn that can reach either of two chests in one turn, but one is further away than the other. If the thief has a lockpick he actually goes for the far chest first, before getting the near chest, opening the door to the room, and escaping.

When I spawn him with a chest key and a door key he goes for the near chest and refuses to open the door even though he has a door key. I have to open the door for him before he tries to escape. Very strange...

Edit: Should probably mention he was using the StealFromChests AI ( [0x06,0x05,0x09,0x00] ) and that the near chest has a Mend staff and the far chest a Horseslayer.

Either way, here's some quick macros for everyone to use:

#define LeaveLeft 0x00
#define LeaveRight 0x01
#define LeaveDown 0x02
#define LeaveUp 0x03
#define LeavePoof 0x05

#define EscapePoint(XX,YY,LeaveWay) "BYTE XX YY LeaveWay 0x00"
#define EndEscapeList "BYTE 0xFF 0x00 0x00 0x00"
Edited by Primefusion

Share this post


Link to post
Share on other sites

So, I am no hacking pro, just a persistent and lucky bastard.

but see doing what you did is something most people can't (or at least, don't know how to) do but is extremely useful

you might not be a 'pro' but in my eyes you're already better than most hackers because you can do things on your own and use basic logic/experimentation to figure things out instead of completely relying on others

We kind of associate 'pros' with people like Nintenlord/Xeld/Cam/whoever can do fancy stuff with ASM, but hacking started and improved with mostly people NOT well-versed in ASM (though they may have learned ASM later), i.e. I'm pretty sure SpyroDi/Pukachi, IcyToast, etc. didn't know ASM, and often times basic fundamental hacking skills can you get farther in the long-run (based on my own experiences with hacking Fire Emblem and many other games, so it's just an opinion)

sorry, just wanted to say I value those skills you have, even if they really are just persistence and luck :P

Share this post


Link to post
Share on other sites

Either way, here's some quick macros for everyone to use:

#define LeaveLeft 0x00
#define LeaveRight 0x01
#define LeaveDown 0x02
#define LeaveUp 0x03
#define LeavePoof 0x05

#define EscapePoint(XX,YY,LeaveWay) "BYTE XX YY LeaveWay 0x00"
#define EndEscapeList "BYTE 0xFF 0x00 0x00 0x00"

Improving this, you can also add these macros:

#define EscapePointerListOffset 0xB97100
#define EscapePointer(id,offset) "ORG EscapePointerListOffset+(4*id); POIN offset; ORG offset"

"id" is the Chapter ID and "offset" is the offset where the data is written.

Example:

EscapePointer(Ch21,0xD0DD00)
EscapePoint(0x00,0x01,LeaveLeft)
EndEscapeList

You have to use these codes at the end of your script.

Edited by Mikey Séregon

Share this post


Link to post
Share on other sites

So, I managed to find where FE8 puts its values for escape tiles. You could say Gryz's work inspired me.

The earliest set of escape coordinates used are located at $D84E0, and is used by chapters that don't have escaping enemies.

There are some escape coordinates before D84E0, up to as early as D83D0, but they don't appear to be used.

The pointer table to these escape coordinates is at $5A8188.

Otherwise, they follow the same format as FE7's system.

Edited by Vennobennu

Share this post


Link to post
Share on other sites

Does that work for NPC thieves?

Also what happens if someone waits on the escape tile? Do they disappear or do they stay?

Share this post


Link to post
Share on other sites

Yes, and they'll stay if you block the escape tile.

But since NPC thieves can't pass through enemies, if there's any treasure chests behind an enemy unit the NPC will just walk up to the enemy and stand there.

Unless you set them to attack enemies too, which has its own set of problems.

Share this post


Link to post
Share on other sites

Oh my god this is amazing and the best thing I have seen yet. This is awesome. This is the best. This is so awesome. And this will make a great break-on-read point for when we take a look at the actual AI code.

Share this post


Link to post
Share on other sites

One thing - it appears that FE8 has a separate pointer table for NPC units; it starts at $5A828C. By default it is filled up with pointers to the null list, but of course you can change it to be whatever you like.

Share this post


Link to post
Share on other sites

Heyyyyyyyyyyyyy he used my methods woohoo!

Nice work, mind if I post this on FEU?

You should join the other wizards at http://feuniverse.us/

FEU is alive?

Alright. I'll share this info on FEU as well.

This is very slick, nice work. I've been doing some testing with this and I got some interesting results. Whether or not a thief has a lockpick vs. some combination of chest and door keys seems to change their behavior.

I did some testing and I'm puzzled.

On some chapters, like 7x and 11H, I can give the Door Key + Chest Key combo to a thief and he will function fine. But on some other chapters, like 17 and 23x, I encounter your scenario where thieves refuse to use Door Keys, but are okay with using a Lockpick. It's almost like certain doors or chapters are flagged to not allow Door Keys to be used. Weird.

Also, I found out the AI won't use the five-durability Chest Key.

One thing - it appears that FE8 has a separate pointer table for NPC units; it starts at $5A828C. By default it is filled up with pointers to the null list, but of course you can change it to be whatever you like.

Wait a minute, if FE8 has pointers for NPC units...

Wow. It turns out that FE7 has pointers for the NPC units right after the enemy pointers as well. They begin at address 0xB971C0. I'll update the first post with the new info. In addition, I'll edit the module for enemy pointers since it has too many entries which causes it to overlap with the NPC data.

Hooray. Now we can have villagers that flee instead of being target practice.

The only FE7 chapter with escape points for NPC units is chapter 17 Whereabouts Unknown. The coordinates are for the area below the entrance. But this is unused since the stupid Caelin soldiers charge towards the enemies and Lucius doesn't move.

For completion, here is the escape data for FE6:

Escape tile coordinates start at address 0x10D9A8

Enemy pointer table at 0x5C86B8

NPC pointer table at 0x5C876C

In-game chapters only use a single coordinate, although the game can support multiple coordinates.

Finally, thanks for the various compliments everyone - it really means a lot.

Share this post


Link to post
Share on other sites

So, I am no hacking pro, just a persistent and lucky bastard.

You made a plan and stuck to it, that's a good start. You should definitely learn how to use a debugger and save yourself the grief in the future though >_>

That said, intuition will get you everywhere.

Edited by Aleph

Share this post


Link to post
Share on other sites
When I spawn him with a chest key and a door key he goes for the near chest and refuses to open the door even though he has a door key. I have to open the door for him before he tries to escape. Very strange...
I did some testing and I'm puzzled.

On some chapters, like 7x and 11H, I can give the Door Key + Chest Key combo to a thief and he will function fine. But on some other chapters, like 17 and 23x, I encounter your scenario where thieves refuse to use Door Keys, but are okay with using a Lockpick. It's almost like certain doors or chapters are flagged to not allow Door Keys to be used. Weird.

It took some time, but I finally unlocked the secrets of the Door Key!

There's a chapter array at 1D3A60 that controls the AI's ability to use Door Keys, Lockpicks, and Antitoxins.

Bit 01 = Enable Door Key in chapter. Bit 02 = Enable Lockpick in chapter. Bit 04 = Enable Antitoxin in chapter.

All FE7 chapters allow the AI to use Lockpicks and Antitoxins.

Chapters that prohibit AI from using Door Keys: 6, 17, 23x, 27 Jerme, 32x.

[spoiler=Long and boring explanation. Do not read.]How exactly do these items get used? Please don't ask me that. It's complex and messy. Well, here is my current theory based on what I have observed and tested so far...

Door Key, Lockpick(1), Antitoxin conditions:

1. Primary AI (AI1) fails. Generally, this happens when the unit has no target for attack, steal, staff. AI1 0x06 always fails.

2. Secondary AI (AI2) fails or AI2 = 0x04 (brigand AI) or AI2 = 0x05 (thief AI). AI2 0x00 fails when the unit has no available path to foes due to walls/terrain. AI2 0x03 always fails.

3. AI1 cannot be 0x03, 0x04, 0x05 (action without movement) and AI4 cannot be 0x20.

4. Item cannot be disabled by the chapter array.

Door Key: Move towards doors and open.

Lockpick(1): Move towards doors/chests and open (requires STEAL ability).

Antitoxin: If poisoned, retreat and cure poison.

If unit has multiple of these items that can be used, priority is given to the lowest in inventory.

Then if AI2 = 0x04 (brigand AI) or 0x05 (thief AI) and none of the above items were used:

Chest Key (1-use): Move towards chests and open.

Lockpick(2): Move towards CHESTS (not doors) and open (requires STEAL ability).

Note: the chapter's item bans do not apply to the Lockpick here.

Usage priority to the top Lockpick/Chest Key in inventory.

The Chest Key with 5-uses cannot be used by the AI.

Note that there are 2 opportunities to use Lockpicks

Lockpick(1): Can open both doors and chests, but can be blocked by the item ban.

Lockpick(2): Requires brigand/thief AI, can only open chests, and is unaffected by the item ban.

So, a thief carrying a Lockpick in a chapter with Lockpicks disabled = a thief that will only open chests and will ignore all doors.

A thief with Door Key + Chest Key will be absolutely determined to use the Door Key before opening any chests. This is due to the Door Key check always occurring before the Chest Key check.

Why did I say Lockpick AI requires the steal ability?

Class/char ability 0x08 (Lockpick): Determines whether to gray out Lockpick in inventory and if the player units can use it. For AI-controlled units, the game mistakenly checks class/char ability 0x04 (steal) for Lockpick functionality. This means enemy/NPC Assassins cannot use Lockpicks by default.

Quicker explanation:

If enemies aren't using Door Keys at all, check the chapter's item ban list. If you want attack-in-range enemies to hold/drop Door Keys without using them, you will need to disable Door Keys.

Door Keys with common AI:

Enemies with "aggressive AI" (00/00) should never use Door Keys unless they are put in a locked room away from the player units.

Enemies with "attack-in-range AI" (00/03) will actually leave their positions and move towards doors if Door Keys aren't disabled for the chapter.

Enemies with "stand still AI" (03/03) should never use Door Keys regardless of the item settings for chapter.

Enemies with "thief AI" (06/05) and carrying a combo of Door Keys + Chest Keys will seek to use Door Keys before using Chest Keys.

[spoiler=Nightmare Module]1

FE7 Door Key, Lockpick, Antitoxin AI Editor

0x1D3A60

48

4

Chapters.txt

NULL

Enable item for AI

0

1

NDHU

KeyLockAnti.txt

[spoiler=KeyLockAnti.txt]8

0x00 ---

0x01 Door Key

0x02 Lockpick

0x03 Door Key, Lockpick

0x04 Antitoxin

0x05 Door Key, Antitoxin

0x06 Lockpick, Antitoxin

0x07 Door Key, Lockpick, Antitoxin

Edited by Gryz

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.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...