Ace Combat levels

Eggheads talking about bytes and stuff.
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: Ace Combat levels

Post by Krishty »

Found part of the sun vector.

In the sky file, at +62 bytes, there is a 16-bit number. It is always in -2048, +2048 range, which I assume is -180°…+180° relative to North with positive numbers towards East.
  • M01 Awakening (sun SE): 1310 = 115°
  • M20 Megafloat (sun SW): -1474 = -129°
  • M09 Scylla and Charybdis (sun S): 2048 = 180°
  • M11 Reaching for Stars (sun N): -102 = -9°
Now I just need to find elevation …

Edit: That’s the 16-bit number just before that. 0 is horizon, 1024 is zenith.
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: Ace Combat levels

Post by Krishty »

Sun angles are implemented and working well. The last thing of interest is time of day / weather.

Time of day is important because the F-22 model shows in the wrong colors (e.g. bright day F-22 during night missions) and because the in-game clock shows the wrong time, of course.

Weather is not yet implemented in TFXplorer but AC3 must have a flag for that somewhere as missions can play in rain, snow, storm.
mikew
Data Genius
Posts: 603
Joined: 2022-Jan-09, 20:21

Re: Ace Combat levels

Post by mikew »

According to the internet, the first mission 'Awakening' has a feature where if all the primary targets are destroyed within 3 minutes, a second wave appears as a mission update. That time has to be specified somewhere, together with the rules about how the mission ends if those primary targets are not destroyed within 3 minutes.
Anyway, another time related mystery apart from time of day...
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: Ace Combat levels

Post by Krishty »

mikew wrote: 2024-Jan-21, 20:25 According to the internet, the first mission 'Awakening' has a feature where if all the primary targets are destroyed within 3 minutes, a second wave appears as a mission update. That time has to be specified somewhere, together with the rules about how the mission ends if those primary targets are not destroyed within 3 minutes.
Anyway, another time related mystery apart from time of day...
Absolutely – and I guess there’s plenty of unknown blocks in the mission file where that could be hidden. The time of day + weather settings, however, I suspect in the sky file because the game would create weather effects together with the skybox. At least if it is well designed, I mean 😂
mikew wrote: 2024-Jan-20, 23:26Heh, I kind of regretted that '24 bit integer' comment, as while they indeed looked like 24 bit integers, it would be unusual if they were used like that.
I just made sense out of that and out of the altitude indicator problems.

So the numbers look like 24-bit integers because if you divide them by 256 (i.e. cut off the eight least significant bits), they are pretty even. For example, the start location Y for the player in M01 Awakening is FE69C000. That’s -26,624,000 as a 32-bit number, and -104,000 if you divide by 256, which is too nice to be a coincidence. Also, 1040 m are very close to the 3404 ft the HUD displays when the mission starts.

I’m now sure I was wrong with my original understanding of the coordinate system:
Krishty wrote: 2023-Aug-20, 01:10The coordinate system for placing objects is the following:
  • coordinate origin is the center of the map
     
  • Y is down towards ground; X/Z are North/East (I forgot which one exactly); surprisingly this is exactly what I picked for TFXplorer years ago
     
  • coordinates are in 16384th part of a meter; terrain tiles have 512 m sidelength (in terrain meshes the vertex coordinates are usually in 25 cm)
     
  • so every level with its 256×256 tiles is addressed via 32-bit integer ranging from -2^30 to +2^30, thus exactly filling the range of a 32-bit integer when computing offsets from the leftmost point to the rightmost and vice versa
     
  • you will often find coordinates that are evenly divisable by 1000 or 10000; these are easy to identify in a hex editor and it seems like the designers really liked them
Coordinates are not meters × 16384, they are centimeters × 256 (or meters × 25,600). Alas, levels are not 128×128 km, but 100×100 km. This leaves us with a rather ugly tile size of 100 km / 256 tiles = 390.625 m, but it makes altitude consistent with the game and explains why so many numbers align with 100, 1000, and 10000.

I cannot verify any of this right now because I’m desparately trying to get the terrain API finished, but it would make so much sense.
mikew
Data Genius
Posts: 603
Joined: 2022-Jan-09, 20:21

Re: Ace Combat levels

Post by mikew »

I still can't see anything obvious for 'Time of Day', so tried to see if the sun position could help.
Plotting out the sun azimuths and elevations doesn't really help...

While all missions with a negative sun elevation are night missions, there are some night missions with the sun high in the sky according to those values from 0.dat.
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: Ace Combat levels

Post by Krishty »

Krishty wrote: 2024-Jan-21, 20:28I’m now sure I was wrong with my original understanding of the coordinate system
No I wasn’t. Coordinates are fine as they are. My calculation is documented here and it is very accurate.

It seems just that altitude, for some reason, is divided by 1.25 🤷

————
mikew wrote: 2024-Jan-22, 13:55While all missions with a negative sun elevation are night missions, there are some night missions with the sun high in the sky according to those values from 0.dat.
Right, in this case it’s the Moon I guess! The engine doesn’t seem to tell apart Sun and Moon; both are just sprites in the sky that illuminate the scene with some color.

I’m trying to find the sky box function in the EXE. Maybe this sheds some light …

————

In other news, I adjusted my code to understand the US/EU version of AC3 and the demo as well.

US/EU differs greatly in briefings: the text is not baked into a texture, but it’s actual ANSI strings in small files. I was able to extract it and automatically convert it to RTF for displaying in TFXplorer:
image.png
image.png (47.79 KiB) Viewed 1828 times
Not spectacular at all, but it is the first briefing that is procedurally generated (kind of) instead of hard-coded. This is an important proof-of-concept and paves the way for displaying TAW’s briefings some day.
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: Ace Combat levels

Post by Krishty »

Maybe this is of use:
image.png
image.png (36.85 KiB) Viewed 1818 times
It’s an array of 35 structures, each with four bytes. It has something to do with the missions. It could be the 35 missions you can freely choose from Mission Simulator after beating the game. (Is that 35? If not, what else?)

I know (from disassembly) the 3rd byte gives the index of the mission in the game files plus 5. E.g. you see that index [0] has 1 there, because M01 Awakening is directory 5 + 1. Zero would denote that unaccessible alpha mission, and that never appears.

The last number has to do with briefing index in the game files.

I don’t quite know what’s going on there, and I am curious about the first byte. It’s a signed number, going from -47 to 52?!

Nothing urgent. Just something that I found interesting.
mikew
Data Genius
Posts: 603
Joined: 2022-Jan-09, 20:21

Re: Ace Combat levels

Post by mikew »

Krishty wrote: 2024-Jan-27, 23:50I don’t quite know what’s going on there, and I am curious about the first byte. It’s a signed number, going from -47 to 52?!
I'd suggest that the first 2 bytes are combined into a little-endian 16 bit number, since the 2nd byte increments when the 1st byte reaches 0xff.
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: Ace Combat levels

Post by Krishty »

mikew wrote: 2024-Jan-28, 16:09I'd suggest that the first 2 bytes are combined into a little-endian 16 bit number, since the 2nd byte increments when the 1st byte reaches 0xff.
You’re absolutely correct! The numbers start at 465. In the game files, there is a kind of data that starts at directory 464 (mind you that the unused mission at index zero is not listed), so it’s probably an index into that.

This data is odd because I don’t see any obvious structure in it:
image.png
image.png (98.98 KiB) Viewed 1752 times
I don’t think it’s sound because it’s missing the characteristic wwwwww markers of PSX ADPCM … maybe something RLE-compressed 🤔
mikew
Data Genius
Posts: 603
Joined: 2022-Jan-09, 20:21

Re: Ace Combat levels

Post by mikew »

I don't have a clue, but if I open that file and display it graphically, there appears to be blocks of regularity. This is at 396 bytes per row:
axeac.png
axeac.png (196.97 KiB) Viewed 1742 times
I haven't looked at those higher number directories before...
User avatar
Krishty
Site Admin
Posts: 1364
Joined: 2022-Jan-09, 00:59

Re: Ace Combat levels

Post by Krishty »

I had a look at AC3’s disassembly again. It’s pretty hard because opposed to TAW, it includes little to no debug strings. (Remember that we reversed TAW’s flight model because we found a debug string that printed speed, altitude, etc)

There is hardly any string handling in general, as almost all in-game text is laid out in texture atlases like these:
image.png
image.png (12.26 KiB) Viewed 1592 times
But a few strings I did find: EASY, NORMAL, HARD, VERY HARD, POINT, and PRESS START BUTTON TO EXIT.

The latter can be found on the HUD during replay. So I got a rough idea where HUD rendering code is.

POINT is harder: It is only referenced once, in the mission where you must follow Dision:
image.png
image.png (143.99 KiB) Viewed 1592 times
Now EASY, NORMAL, HARD, VERY HARD were trivial to identify: It’s what you see when a mission starts!
image.png
image.png (28.7 KiB) Viewed 1592 times
Note that the font matches. So the text written in this font is the only text that is printed from strings, instead of being pre-baked into textures.

I tried understanding more HUD code, but without any initial clues or strings it’s too large and too complex to identify anything of value.

If we look at the mission start animation for another second, it also displays the level name:
image.png
image.png (240.44 KiB) Viewed 1592 times
This code was just a few lines down! Tracing back the registers involved, I was able to identify the memory location where the mission index is stored as well as the difficulty level.
image.png
image.png (69.38 KiB) Viewed 1592 times
The blinking cursor during level name display unveiled the location of the animation timer, and so on.

But really the mission index was the most important discovery. Asking Ghidra for references lists more than 100 locations with hard-coded game logic. This shattered my hopes that mission-specific scripting was done in the data files … no, it’s in the code.
image.png
image.png (54.06 KiB) Viewed 1592 times
These locations already say a lot. E.g. one function checks specifically for five missions … and it’s the exact missions with the battle airship Sphyrna. Patterns emerge.

Still, this doesn’t help us with AI or flight model. But one expression caught my eye – testing for Ghosts of the Past and an integer that we have seen quite often in data files!
image.png
image.png (8.29 KiB) Viewed 1592 times
Ghosts of the Past is the infamous ravine mission where you are not allowed to climb above a certain altitude. How high? I fired up TFXplorer to measure the top of the cliffs (where you fail the mission) and it’s about 800 meters. The number in the code is 10,485,760, leading to a factor of ~13,100.

That’s close enough to the scale factor of 16,384 I calculated earlier (plus the confusion about altitude) that it leads me to believe I found the XYZ coordinates of the player!

Now the flight model shouldn’t be so hard to find any more …
Post Reply