Files
isaac-port/notes/items/weapons_knife.md
T

206 lines
14 KiB
Markdown

# Mom's Knife (8.0.0) as Isaac's weapon: Rep+ 1.9.7.17 decompile transcription
Line refs `U:n` = `./decompile.sh 0x961b00` (Entity_Knife::Update), `F:n` = `./decompile.sh 0xa03f90`
(Weapon_Knife::Fire), the same numbering as the dumps in this folder (f_0x*.c). Scope: one knife, player owner, no
modifier items. A tear-flag mask like `c34b60` means a BitSet128 global at 0x00c34b60. These masks are only non-zero
when an item adds those tear flags, so they are false in the plain case.
## 0. Frame model (applies to everything below)
- Manager::Update 0x954cd0: even frames call Game::Update. Odd frames call Game::interpolate_update **only when the
interpolation option is on**. That pass calls each entity's Interpolate (vtable +0x10).
- Entity_Knife::Interpolate 0x967db0 (subtype 0): `_isInterpolating(+0x175)=1`, then it runs the **whole Update again**.
At the next even frame, Manager restores pos from +0x344/+0x348 and clears the flag. Knife state
(distance, rotation, anchor) is NOT restored.
- In Update, `_knifeVelocity` and the 0.7 friction step are gated by `!_isInterpolating`. The distance step, the
rotation lerps and the anchor lerp are not gated, so they run twice per game frame.
- Weapon_Knife::Fire takes (dir, isShooting, isInterpolated). Charge increments only when `!isInterpolated`.
- "per tick" below means per Update call. With interpolation on, that is 2 calls per 30 Hz game frame.
## 1. Held (not thrown) state
Setup, run on every Fire call (Weapon_Knife::Fire F:440-470; spawn via Weapon::fire_knife 0x9f6a60 -> Entity_Player::FireKnife 0x7aded0):
```
if weapon.knife[0] == null:
knife = Spawn(8, variant 0, player.pos, vel 0, spawner player, subtype 0); knife.parent = player
knife flag 0x200000 (cantOverwrite=1); rotationOffset = 0
knife._rotation(+0x438) = SLOT_ANGLE[0] = 0.0 ; table 0xb81710 = {0,180,90,-90} (slots 1..3 = Mom's Eye 55 / Loki's Horns 87)
knife.Update() once
init_knife(knife) 0xa05070 (every Fire call):
color = weapon tear color; tearFlags = owner tear flags
collisionDamage = Weapon::get_damage 0x9f3c80 = player._damage(+0x1470)
posOffset = (player.posOffset.x, player.posOffset.y - 10) ; 0xa050d0..
+ (0,-15) if player entity flag bit 57 (0x0200000000000000)
+ GetFlyingOffset/0.65 = (0, -4/0.65) when player.canFly and room type != 0x10 (0x782630)
Entity_Knife::Init 0x960c10: anim = anm2 default ("Idle"), gridCollisionClass 0, maxDistance 100, charge 0,
velocity 0, isFlying 0, collisionDamage 22 (overwritten by init_knife).
```
Aim and rotation in Fire (F:476-570). This runs only while the knife is not flying (Marked or Tractor Beam force it):
```
aim = dir (Fire's 1st arg)
if !isShooting and charge(+0x14) > 0: aim = weapon._direction(+0x20) ; last held aim, used on release
if aim == (0,0): aim = by player._headDirection: 0 -> (-1,0), 1 -> (0,-1), 2 -> (1,0), 3 -> (0,1)
(Tractor Beam, modifier bit 6: snap aim to the dominant axis)
knife._rotation = wrap180(atan2(aim.y, aim.x)deg + SLOT_ANGLE[slot]); knife._rotationOffset = 0
```
Update, held branch (root knife, `!_isFlying`, U:420-465):
```
if knife.parent == null or !player.HasWeaponType(4): Remove ; U:199, local_134.y = 4 for variant 0
HOLD_DISTANCE = 30.0 ; U:154 (4 for clubs, 0.1 for swords)
if game.frame - knife.spawnFrame < 2 or |displayRot - _rotation| <= 0.1:
displayRot(+0x440) = _rotationOffset + _rotation ; snap
else:
displayRot = LerpAngleDeg(displayRot, _rotationOffset + _rotation, 0.3) ; U:428; 1.0 with Tractor Beam (397)
; LerpAngleDeg 0x6828b0: shortest-path lerp, result wrapped to [-180,180]
targetPosition = 0; target = null
pos = player.pos + (cos, sin)(displayRot) * 30 ; U:458 (player.pos, not its posOffset)
anchorPosition(+0x44c) = player.pos
basePosOffsetY(+0x4d4) = posOffset.y
spriteAngle = atan2(pos - player.pos)deg ; local_ec
```
Sprite (U:925-929, the non-swing/non-sword branch; it runs in flight too):
```
sprite.rotation = normalize180(spriteAngle - 90); layer0.flipX = (sprite.rotation > 0)
```
- Animation: only "Idle" (DefaultAnimation). It has one 32x32 frame, pivot (16,18), from effects/effect_momsknife.png.
The anm2 also has "Rotation" (16 frames), but no knife code plays it. Shoot plays its anim only for variants 1-4/8/9.
The anm2 has no events.
- Render z (GetRenderZ 0x9665e0) = floor(pos.y*100 + 10030 + 0.5). _knifeDepthOffset stays 0 for variant 0.
- Fire also sets the player's head timers each call (F:722-786): `_blinkTime(+0x1338) = max(_blinkTime, 7)`, or 15
when the knife flies with distance < 25 and velocity > 0. While flying, `_headDirectionTime(+0x133c) = max(.., 2)`.
## 2. Charge
```
maxCharge = Weapon_Knife::GetMaxCharge 0xa05010 = max(weapon._maxFireDelay(+0x10), 0.001) * 4
; 0 with Ludovico (modifier bit 4). Chocolate Milk bit 0 is NOT read here.
; weapon._maxFireDelay = player._maxfiredelay(+0x1460), copied each update (0x77ce06)
Fire, isShooting and knife not flying (F:704-720):
if !isInterpolated: charge(+0x14) = min(charge + owner._speedMultiplier(+0x39c, normally 1.0), maxCharge)
weapon._direction(+0x20) = get_aim_direction(dir) ; 0x9f33e0: player aim vector (+0x163c buffer), Marked overrides
Fire, !isShooting and knife not flying and charge > 0 -> RELEASE (F:576-701):
used = min(charge, maxCharge)
Weapon::TriggerTearEffects(dir, 1) ; item synergies only
for each knife slot: Entity_Knife::Shoot(knife, used / maxCharge, range) ; section 3
charge = 0; weapon._direction = (0,0)
```
- There is no minimum charge and no 0.2 floor (unlike Weapon_Bone). One charged frame throws with share
1/maxCharge. While the knife flies, fire input neither charges nor re-throws.
- Charge bar (Weapon::GetChargeBarAmount 0x9f4150) = clamp(charge / maxCharge, 0, 1). Soy Milk (bit 7) gives 0.
## 3. Throw
Range (F:135-137, 587-596, 640-649):
```
range = min(player._tearrange(+0x1480) * 0.6, 300.0) ; 260*0.6 with no player; cap 100000 with mask c34b60
range = max(range, 0.1) ; 0x3dcccccd floor; Marked computes its own
```
Entity_Knife::Shoot(c, range) 0x966ef0, variant 0:
```
accel = -2.0 ; -1.0 if tearFlags & c34b60; x0.75 only for variants 1-4/8/9; x0.75 + hop (c345e0)
maxDistance(+0x45c) = c * range
knifeDistance(+0x444) = 0; isFlying(+0x464) = 1; charge(+0x460) = c
knifeVelocity(+0x448) = sqrt(|c*range / (accel * -0.5)|) * -accel = 2*sqrt(c*range) (v^2 = 2*|a|*D)
UpdateHomingPath 0x967180: clears _usedTearFlags (Monstro's Lung 229 and Tech X 395 branches there)
; variant 0 does NOT clear its hit list or change animation/sprite rotation in Shoot (clubs only)
```
Flight (root knife, isFlying, U:470-560, 575-615):
```
spd = _speedMultiplier (x0.5 with mask c348e0, x0.75 with c348a0)
displayRot = LerpAngleDeg(displayRot, _rotationOffset + _rotation, 0.8) ; _rotation is frozen while flying
knifeDistance += spd * knifeVelocity * 0.5 ; every pass (also interpolation)
if !isInterpolating: ; asm 0x962632
a = (knifeVelocity > 0) ? -2.0 : -5.0 ; -0.5 / -0.75 with c34b60
knifeVelocity = knifeVelocity + a * spd
if knifeDistance < 0: ; RETURNED (U:523-536)
knifeDistance = 0; isFlying = 0; prism/multidimensional flags = 0; target = null
posOffset.y = basePosOffsetY ; no sound for variant 0 (0xf9 is for swing weapons)
(_charge and the now-negative _knifeVelocity are NOT reset)
anchor: if anchor == (0,0): anchor = player.pos
t = clamp(knifeDistance / maxDistance, 0, 1)
f = 1 - charge * t * 0.8 ; U:593
anchor = anchor + (player.pos - anchor) * f ; every pass
pos = anchor + (cos, sin)(displayRot) * (knifeDistance + 30) ; U:608 (no c34b60)
spriteAngle = atan2(pos - player.pos)deg -> sprite as in section 1
```
- Isaac's movement: at the launch point (t=0) and once back, the anchor is Isaac. Near max distance at full
charge, the anchor follows Isaac by only 20% per pass. The knife keeps its path, and the angle is measured from
Isaac, so the sprite tilts as he moves.
- No room clamp and no grid collision for variant 0. gridCollisionClass is 0, and Room::GetClampedPosition sits only
in the Ludovico branch, so the knife goes through rocks and walls.
- Derived per game frame with interpolation on: d += (v_n + v_(n+1))/2, so the peak lands exactly at maxDistance after v0/2 frames.
Default Isaac (range 260, MaxFireDelay 10, full charge): D = 156, v0 = 24.98, about 12.5 frames out and about 7.9
frames back (a = -5). With interpolation off, only half of each step runs: d += v_n/2 per frame, so the peak is about D/2.
## 4. Damage and hits (Entity_Knife::HandleCollision 0x9666f0)
```
Lua PreKnifeCollision may override; skip if !visible
skip if collider IsEnemy and has entity flag 0x20000000 (friendly)
if collider.type == 4 (bomb) and flying and knifeVelocity > 0: ; pushes bombs
ang = (int)spriteAngle, stored by Update at U:958 (field this[1]._variant)
bomb.vel += ((cos,sin)(ang) * knifeVelocity*0.6 - bomb.vel*0.8) * bomb.speedMul / bomb.friction
if (collider.IsVulnerableEnemy and !knife.IsDescendantOf(collider)) or type in {33 fireplace, 292 movable TNT, 245 poop}:
if collider in hitList: no hit
hitList.insert(collider)
p = player.GetTearHitParams(weaponType 4, dmgScale 1.0, sign = +-1 random, source=spawner) ; 0x7bf6c0
; p.damage(+0x48) = player._damage x the item multipliers in GetTearHitParams (none when plain)
if Isaac::Random(isFlying ? 2 : 6) == 0: flags = p.flags (proc roll) else flags = knife.tearFlags
k = clamp(knife._charge * knife._knifeVelocity / 3, 0, 1) ; asm 0x966a33-0x966a6e
damage = (2 + 4*k) * p.damage ; collisionDamage instead if there is no player
dmgFlags = get_tear_flags_from_player 0x67d1f0 (0 when plain; 0x4000 blue-fly roll with Mulligan 151 etc.)
collider.TakeDamage(damage, dmgFlags, EntityRef(knife: type/variant/spawner, pos, velocity, flags), 30)
; countdown 30 is used only with damage flag 0x40 (Entity::TakeDamage 0x6ace60), not set here
if type 33: stop
Entity_Tear::ApplyTearFlagEffects(collider, knife.pos, flags, knife, damage)
apply_hit_effects 0x96ae70 (variant 0: only 1 in 4 rolls run tear-flag procs; all are tear-flag gated)
if collider.type == 9 (projectile): destroyed only with tear mask c34c60 (1/5 or 1/20 roll), otherwise ignored
return 1 (no physical push)
```
- Held: _charge is 0 before the first throw. After a return, _knifeVelocity is still negative. Either way k = 0,
so **held = 2 x damage**.
- Thrown, outbound: k = min(1, c*v/3), up to **6 x damage**. It falls off as v drops below 3/c. On the return leg
v <= 0, so it is **2 x damage**.
- Re-hit rate: Update clears hitList when `IsFrame(3, 0)`, i.e. game.frameCount % 3 == 0 (U:1669, Entity::IsFrame
0x6ac710). The same enemy takes at most one hit per 3-game-frame window, held or thrown.
- Knockback: the knife code applies none (only the bomb push). The EntityRef carries knife pos and velocity, and
the knife's velocity is about 0 because Update sets pos directly. Generic TakeDamage knockback was not traced.
- Grid (U:1704-1767, every non-interpolated Update while visible, held or thrown):
`Room::DamageGridWithSource(gridIndexAt(knife.pos), damage 1, source knife)`. The bridge-making branch needs tear
masks c34a30|c34980.
## 5. Sounds and effects
- Plain variant 0 plays no sound anywhere: not in Fire, Shoot, Update, HandleCollision or apply_hit_effects.
- Sound 0xf9 is the swing weapons' return sound.
- Sound 0x96 (volume 0.5) and effect 1000.14 are the hop landing under mask c345e0.
- Effect 1000.53 is the trail under mask c34ac0 (every 2nd frame, 1/2).
- All other sounds sit in item branches (TriggerTearEffects, apply_hit_effects).
- Any hurt sound comes from the victim's own TakeDamage.
## 6. Fire delay
- Weapon_Knife::Fire never reads weapon._fireDelay(+0xc), which Weapon::Update 0x9f34f0 counts down.
- Throws are gated only by "knife not flying" plus "charge > 0 on release".
- MaxFireDelay enters only through maxCharge (4 x MaxFireDelay frames for a full throw).
- A fully charged throw needs 4*MaxFireDelay game frames of holding. Back-to-back taps re-throw as soon as the
knife is back.
## Synergy branches seen (one line each, not transcribed)
- Ludovico (modifier bit 4; F:139-350, U:1000-1120)
- Tractor Beam 397 (bit 6: axis snap, lerp 1.0)
- Marked 394 (weapon +0x28 target; auto-release and range)
- Mom's Eye 55 / Loki's Horns 87 (extra slots)
- multishot (Weapon_MultiShotParams: rotationOffset per spread, random-dir extra knives)
- Monstro's Lung 229 / Tech X 395 (UpdateHomingPath)
- Brimstone 118 (sub-knives every 2nd frame on the return, U:871)
- Technology 68 (laser to the knife, U:1285)
- Angelic Prism (spawn_child_knife)
- Tiny Planet-like mask c34b60 (spiral, accel -1/-0.5/-0.75, range cap 100000)
- hop mask c345e0, spiral masks c348e0/c348a0, wiggle c34870, homing, screen wrap c348d0, magnet c34b20
- temp effect 0x6e -> knife variant 5
## Could not determine
- Which entity flag bit 57 is (it adds the -15 knife offset); not looked up.
- The player-side caller of Weapon::Fire. I did not trace exactly what `dir` is (raw shoot joystick vs normalized),
or whether the player's Interpolate calls Fire with isInterpolated=1. The charge step assumes it does
(REPENTOGON's prototype names the arg IsInterpolated).
- The interpolation option's default. Flight distance depends on it (section 3). I report the code as written; I
did not test it in game.
- Knockback that Entity_NPC/Entity TakeDamage derives from the knife EntityRef (not traced).
- get_tear_flags_from_player's 0.66 blue-fly chance condition (player +0x202c==0 && +0x20a9==0 && +0x17dc>2).
Fields unnamed; it may fire in the plain case.