Cite as
Xeeynamo/ff7-decomp
Original
https://github.com/Xeeynamo/ff7-decomp
Pinned
Xeeynamo/ff7-decomp @ fc71ccc0cda69d23cb8236a9cfbecae8bce23876
Accessed
2026-10-22
Licence
AGPL-3.0 (the repository's LICENSE file, which GitHub's API also reports). The README says nothing about the rights to the game's code or data; the game code it rebuilds is Square's. The README's "AI / LLM stance" says the decompiled code must be its contributors' own work and that the project will enforce its license against "hostile" forks.
Credit
Xeeynamo and the ff7-decomp contributors, who decompiled the PlayStation game into C that compiles to the original bytes. Every function name, field name, and comment quoted in ff7 claims is theirs.
Notes
The README builds from "Final Fantasy VII (USA) (Disc 1)", the North American release; config/us.yaml checks each overlay against a SHA-1 (the main executable SCUS_941.63, and the battle overlay BATTLE/BATTLE.X, decompressed, against c82690f814b18664c3b2d024f4edeea5743995d9). The battle overlay's code is src/battle/battle.c, battle1.c, battle2.c, and battle3.c (battle.c holds the damage, hit, critical, and Limit gauge code). Functions not yet decompiled stay as `INCLUDE_ASM` stubs, 8 of them in battle.c at the pinned commit, so every C function in the file is part of the matching build. decomp.dev reported 66.2% of the game's code matched on 2026-10-22 (docs/notes/next-decomp-jobs.md). Random numbers come from a 256-byte table in KERNEL.BIN (src/main/btlrand.c), which the repo doesn't hold.

Cited on

Claims (4)

In the North American release, BattleSetTmpDmgAsPhysical takes the attacker's physical attack S (physAttack after stat multipliers) and the action's level L (characterLevel) and computes (⌊L·S/32⌋ · ⌊(L + S)/32⌋ + S) × (512 − the target's defense) × the attack's power, over 8,192: a base of S + ⌊L·S/32⌋·⌊(L + S)/32⌋, scaled by power/16 and by (512 − defense)/512 (computed). It then doubles the damage when damageFlags bit $2 is set, the bit a critical sets and that this same function also sets for any attack whose attackFlags bit $2000 is clear (ff7/critical), multiplies it by 1.5 under Berserk, for a short-range attack or an enemy's Attack command halves it once if the target or the attacker is in the back row (other attacks ignore rows), halves it for a defending target, multiplies it by the target's backDamageMult/8 when the unnamed unk234 bit 0 is set, quarters it under Frog, applies the Sadness, multi-target, and Barrier modifiers, and sets it to 0 under Mini. Last, BattleAddRndModifierAndZeroCheck multiplies by 3,841 plus a random byte, over 4,096 (93.8–100%, computed), and raises 0 to 1, so a Mini attacker deals 1. Final Fantasy VI's CalcDmgMod also lets defense remove a share, but as (255 − Defense)/256, with a variance of 224–255 over 256 applied before it.src/battle/battle.c L4491–4497src/battle/battle.c L4569–4623src/battle/battle.c L4552–4565src/main/btlrand.c L19Code
In the North American release, BattleRollPhysicalHit hits when a roll of 1–100 (BattleGetRnd164) is under the hit chance: the attack's hit % (targetAttackPercent) plus a quarter of the attacker's dexterity, plus the attacker's Df%, less the target's Df%, cut by 30% under Fury, and raised to at least 1, which never hits. A party member's Df% is a quarter of its dexterity plus its physical evade and an enemy's is its physical evade alone, so a party attacker's dexterity counts twice. The chance is instead 255 against a target under Death, Sleep, Confusion, Stop, Petrify, Manipulate, or Paralysis, for the Death, Nullify, and Absorb affinities and one unnamed affinity flag, and for two flags the code leaves unnamed (unk234 bit 0, unk218 bit 5). Before the roll, a 0–99 roll under the attacker's luck/4 makes a sure hit; failing that, when an enemy attacks a party member and the same roll is under the target's luck/4, the attack misses, even at 255. BattleGetRnd164 scales a 16-bit random number by 99/65,535 and adds 1, so it gives 100 only for $FFFF, and a chance h of 2–100 hits about (h − 1) times in 99 (computed for evenly spread 16-bit values). Final Fantasy VI instead scales the hit rate by the target's stored evade (magic evade, through a bug) and rolls 0–99 against it.src/battle/battle.c L5702–5780src/battle/battle.c L5920–5929src/battle/battle.c L6008–6013src/battle/battle.c L6667–6670src/main/btlrand.c L19–21Code
In the North American release, BattleRollCriticalHit is entry 2 of the hit-formula table, so it runs only for an attack whose hit-formula script includes it, and only if the hit roll didn't mark a miss. Its chance is (the action's level + the attacker's luck − the target's level)/4, plus the weapon's critical % for a party member, or 255 under Lucky Girl; a 1–100 roll at or under the chance sets bit 1 ($2) of damageFlags. BattleSetTmpDmgAsPhysical doubles the damage when that bit is set, and sets it itself for an attack whose attackFlags bit $2000 is clear. So a chance c of 0–99 crits about c times in 99 (computed for evenly spread 16-bit values). Final Fantasy VI crits on a random byte under 8, 1 in 32, whatever the stats, and a critical adds 2 to the damage multiplier, which its code comments as damage ×2.src/battle/battle.c L5825–5847src/battle/batini.c L346src/battle/battle.c L5044–5053src/battle/battle.c L4443–4451src/battle/battle.c L4580–4591src/battle/battle.c L6669–6670Code
In the North American release, when an enemy's action takes HP from a party member, BattleApplyDamageAndChargeLimitGauge adds ⌊300 × damage / max HP⌋ × 256 over the character's HP divisor to the Limit gauge, with 512 in place of 256 under Fury and 128 under Sadness, and caps the gauge at 255; the damage counts in full, even past the HP the character had left. It adds nothing for healing, MP damage, a character whose limit level is 4 or more, or a turn flag the code leaves unnamed (turnFlags bit 3). The divisor is read from KERNEL.BIN per character and limit level (hpDivisor), so the code alone doesn't give its values.src/battle/battle.c L4252–4311src/battle/batini.c L388include/game.h L786–797Code