User:HertzDevil/Reverse-engineering notes


 * Progress
 * Data types

Resonant Battles growth settings
The internal level of all thieves and guardians is the highest level of the player's units in the team, plus a value that depends on the player's Interval and chosen battle difficulty:

For example, entering a Resonant Battle at Advanced difficulty with a Lv. 40 team on Interval 21 results in an internal level of 56. Enemy stats are then calculated from their base stat values and growth rates. After that, thief stats are corrected as follows:


 * The HP stat is multiplied by 150%.
 * The Def/Res stats are raised to 50% of the unit's internal level if they are lower than that.
 * A random bonus between 0 and 3 (inclusive) is added to every stat.

Guardian stats are corrected as follows:


 * The HP and Atk stats are multiplied by 150%.
 * The Def/Res stats are raised to 75% of the unit's internal level if they are lower than that.
 * A random bonus between 0 and 3 (inclusive) is added to every stat.

Random skills
Training Tower, Tempest Trials, and Allegiance Battles may equip random skills on units.

Only legal skills from the random pool may be equipped. This means:
 * The unit must be able to inherit the skill normally;
 * The unit's level is between  and  ;
 * is non-zero;
 * is 1 or 2.

Heroes do not own evolved and refined weapons; additionally, random Heroes cannot equip any weapons they do not already own (note that weapon skills never have  set).

Growth percentages
The game internally stores growth rates of all Heroes and generic units as percentages. Only multiples of 5% are ever used; however, growth rates are defined for growth percentages that are not multiples of 5 (this has been verified by a debugger). The growth percentage is multiplied by an additional rarity factor:

The truncated result produces the following master growth table:

This table is used directly for the randomization of stat growth tables (see below). Stat growth values can be derived from this table by, or directly calculated by.

Enemy stats for derived maps
Certain game modes (Chain Challenge, Squad Assault, Blessed Gardens) derive their maps from existing story / paralogue maps. Chain Challenge scenarios use base maps at their respective difficulties, whereas the other two game modes always use base maps at Lunatic. Their stats are determined as follows:


 * First, if the unit's rarity is increased, then the usual base stat changes for playable Heroes apply, using the base stats defined in either  or.
 * Each stat is increased by, where   is the unit's original level,   ≥   is the new level,   is the growth percentage at the unit's old rarity, and   ≥   is the growth percentage at the new rarity. Levels above 40 are defined as follows:
 * {|class="wikitable mw-collapsed mw-collapsible"

! Game mode !! Difficulty !! Levels
 * rowspan=6| Chain Challenge || Lunatic, single-chapter Story || 40/41/42/43/45
 * Hard, double-chapter Story || 40/40/41/41/43/42/42/43/43/45
 * Lunatic, double-chapter Story || 45/45/46/46/48/47/47/48/48/50
 * Lunatic, single-chapter Paralogue || 40/42/45
 * Hard, double-chapter Paralogue || 40/41/43/42/43/45
 * Lunatic, double-chapter Paralogue || 45/46/48/47/48/50
 * Squad Assault || Lunatic || 50/50/50/50/50
 * rowspan=2| Blessed Gardens || Lunatic || 45
 * Infernal || 50
 * rowspan=2| Blessed Grounds || Odd-numbered Grounds || 45
 * Even-numbered Grounds || 50
 * Tempest Trials || Lunatic, Lv. 40 || 40/41/42/43/44/45/45
 * }
 * A few special cases:
 * If only the level is changed, the formula reduces to.
 * If only the rarity is changed, the formula reduces to.
 * If both rarity and level are unchanged, no stat boosts occur at this stage.
 * Infernal || 50
 * rowspan=2| Blessed Grounds || Odd-numbered Grounds || 45
 * Even-numbered Grounds || 50
 * Tempest Trials || Lunatic, Lv. 40 || 40/41/42/43/44/45/45
 * }
 * A few special cases:
 * If only the level is changed, the formula reduces to.
 * If only the rarity is changed, the formula reduces to.
 * If both rarity and level are unchanged, no stat boosts occur at this stage.
 * If only the level is changed, the formula reduces to.
 * If only the rarity is changed, the formula reduces to.
 * If both rarity and level are unchanged, no stat boosts occur at this stage.


 * The HP of all enemies is further calculated as, where   is a global multiplier that depends only on the game mode:
 * {|class="wikitable mw-collapsed mw-collapsible"

! Game mode !! Difficulty !! HP factor
 * rowspan=9| Chain Challenge || Normal, single-chapter || 1.1
 * Hard, single-chapter || 1.2
 * Lunatic, single-chapter || 1.3
 * Normal, double-chapter Story || 1.1 for first half, 1.2 for second half
 * Hard, double-chapter Story || 1.2 for first half, 1.3 for second half
 * Lunatic, double-chapter Story || 1.3 for first half, 1.4 for second half
 * Normal, double-chapter Paralogue || 1.1
 * Hard, double-chapter Paralogue || 1.2
 * Lunatic, double-chapter Paralogue || 1.3
 * Squad Assault || Lunatic || 1.3
 * rowspan=4| Blessed Gardens || Normal || 0.8
 * Hard || 0.8
 * Lunatic || 1.1
 * Infernal || 1.5
 * rowspan=2| Blessed Grounds || Odd-numbered Grounds || 1.1
 * Even-numbered Grounds || 1.5
 * rowspan=7| Tempest Trials || Normal, Lv. 8 || 0.90/0.90/0.90
 * Normal, Lv. 14 || 0.90/0.90/0.95
 * Normal, Lv. 20 || 0.95/0.95/1.00
 * Hard, Lv. 25 || 1.00/1.00/1.00/1.05
 * Hard, Lv. 30 || 1.00/1.00/1.05/1.05/1.10
 * Lunatic, Lv. 35 || 1.00/1.05/1.10/1.15/1.20
 * Lunatic, Lv. 40 || 1.00/1.05/1.10/1.15/1.20/1.25/1.30
 * }
 * Skills are promoted as follows:
 * While  points to a valid skill name, and the unit's rarity is higher than or equal to , the current skill is replaced by  ; this continues until no more promotions can be made. Skills are never demoted, and promotion takes place even if the unit's rarity does not change between the base map and the derived map. Empty skill slots in the base map are never occupied in derived maps.
 * Additionally, only skills with  nonzero and also less than or equal to a per-map tier are allowed to promote. Currently this tier number is always 1 on scenarios for derived maps, so Staff weapons, Assists, and Specials are never promoted (see table below).
 * Slight deviations occur for weapon promotion depending on whether the unit is a Hero or an enemy:
 * If a Hero owns the original weapon skill, and the  check passes, their default weapon at the new rarity is chosen.
 * If an enemy unit is at and its   refers to a valid weapon skill, that skill is chosen, regardless of its   value, and regardless of which original weapon skill the unit has (unless it didn't have a weapon).
 * Even-numbered Grounds || 1.5
 * rowspan=7| Tempest Trials || Normal, Lv. 8 || 0.90/0.90/0.90
 * Normal, Lv. 14 || 0.90/0.90/0.95
 * Normal, Lv. 20 || 0.95/0.95/1.00
 * Hard, Lv. 25 || 1.00/1.00/1.00/1.05
 * Hard, Lv. 30 || 1.00/1.00/1.05/1.05/1.10
 * Lunatic, Lv. 35 || 1.00/1.05/1.10/1.15/1.20
 * Lunatic, Lv. 40 || 1.00/1.05/1.10/1.15/1.20/1.25/1.30
 * }
 * Skills are promoted as follows:
 * While  points to a valid skill name, and the unit's rarity is higher than or equal to , the current skill is replaced by  ; this continues until no more promotions can be made. Skills are never demoted, and promotion takes place even if the unit's rarity does not change between the base map and the derived map. Empty skill slots in the base map are never occupied in derived maps.
 * Additionally, only skills with  nonzero and also less than or equal to a per-map tier are allowed to promote. Currently this tier number is always 1 on scenarios for derived maps, so Staff weapons, Assists, and Specials are never promoted (see table below).
 * Slight deviations occur for weapon promotion depending on whether the unit is a Hero or an enemy:
 * If a Hero owns the original weapon skill, and the  check passes, their default weapon at the new rarity is chosen.
 * If an enemy unit is at and its   refers to a valid weapon skill, that skill is chosen, regardless of its   value, and regardless of which original weapon skill the unit has (unless it didn't have a weapon).
 * Lunatic, Lv. 40 || 1.00/1.05/1.10/1.15/1.20/1.25/1.30
 * }
 * Skills are promoted as follows:
 * While  points to a valid skill name, and the unit's rarity is higher than or equal to , the current skill is replaced by  ; this continues until no more promotions can be made. Skills are never demoted, and promotion takes place even if the unit's rarity does not change between the base map and the derived map. Empty skill slots in the base map are never occupied in derived maps.
 * Additionally, only skills with  nonzero and also less than or equal to a per-map tier are allowed to promote. Currently this tier number is always 1 on scenarios for derived maps, so Staff weapons, Assists, and Specials are never promoted (see table below).
 * Slight deviations occur for weapon promotion depending on whether the unit is a Hero or an enemy:
 * If a Hero owns the original weapon skill, and the  check passes, their default weapon at the new rarity is chosen.
 * If an enemy unit is at and its   refers to a valid weapon skill, that skill is chosen, regardless of its   value, and regardless of which original weapon skill the unit has (unless it didn't have a weapon).

(Random enemy stats, like those in Tempest Trials and Training Tower, have not been determined. HP factors for Tempest Trials are shown for convenience.)

exists if and only if the skill is inheritable, not a Sacred Seal, and both  and   are nonzero. The table below lists the skill types that have canonical upgrades:

Growth vectors
The file  contains the seemingly random growth vectors used in the game. The decompressed file contains 2496 XOR-encrypted 64-bit little-endian bit vectors starting from address, where the n-th bit indicates whether a given stat should increase when the hero reaches level n. An example of reading the vectors directly from the binary file:

For example, Brave Lyn's neutral growth vectors are: (the used portions are shown in boldface) Here ID is the lowest 6 bits of the  field, as there are 64 possible variations for each stat growth amount between 1 and 39. This growth vector ID, together with the growth amount determined by the hero's rarity and the stat's GP, uniquely identifies the growth vector used by that stat. It is possible to infer missing entries from the complete stat tables as long as exactly one out of 64 variations correlates with the given entries, or even guess the vector ID if one or two of the given stats are incorrect.

Growth vector IDs change with the hero's IVs: (they warp around 00-63)

the hero's rarity:

and a single byte from the structs under   that hold hero data:

Deriving growth vector IDs
Growth vector IDs can be calculated as the sum of the following terms, keeping only the 6 lowest bits (i.e. modulo 64):


 * 3 × (5-star level 1 neutral base stat);
 * A constant offset depending on the stat being calculated for, which increases "randomness":
 * {|class="wikitable default"

! HP !! Atk !! Spd !! Def !! Res
 * -35 || -28 || -21 || -14 || -7
 * }
 * The growth percentage corresponding to the Hero's rarity and the stat's GP;
 * The hero's base vector ID . It is currently unknown if the highest 2 bits are computationally meaningful since the modulo operation discards them.
 * The hero's base vector ID . It is currently unknown if the highest 2 bits are computationally meaningful since the modulo operation discards them.

Brave Lyn's base vector ID is. The growth vector IDs for her neutral stats can be computed as follows:


 * HP: (3 × 16 + (−35) + 51 + 157) mod 64 = 221 mod 64 = 29
 * Atk: (3 × 7 + (−28) + 68 + 157) mod 64 = 218 mod 64 = 26
 * Spd: (3 × 9 + (−21) + 68 + 157) mod 64 = 231 mod 64 = 39
 * Def: (3 × 5 + (−14) + 34 + 157) mod 64 = 192 mod 64 = 0
 * Res: (3 × 6 + (−7) + 57 + 157) mod 64 = 225 mod 64 = 33

This matches her vector IDs given at the top. This has been verified to match all pre-existing 5-star stat tables on this wiki.

Identical stat growths
Due to the modulo operation it is theoretically possible that two completely different stats on the same hero use the same growth vector: (currently this is limited to HP/Atk base being 7 higher than Def/Res and GPs being the same)

Out-of-bound growth rates
After rarity correction, if the growth rate is 0%, the stat uses a fixed growth vector, regardless of the Hero's base vector ID: 01100000 11001111 10111010 01100001 01110001 This is in fact the XOR cipher used for the growth vectors (see example code above). Because the growth vector files does not store empty vectors, it is possible that the game is accessing memory before the list of growth vectors; if it reads zeroes, the resulting growth vector is simply the XOR value itself. It is also possible that, depending on the Hero's base vector ID, the game may read the file's HSDArc header instead of zeroed memory.

If the growth rate is 100% or above, the integral part is applied to every level up, and the fractional part uses the growth vector mechanism as above. Growth rates can never be below 0%.