546 - bombShield(int a, int script)


Sets the bomb invulnerability flag (a=0 false, a=1 true), the caller's ANM script will change to script when a bomb is active.

611 - etEx(int etId, int async, int type, float a, float b)


Adds bullet transformation to bullet manager etId, Transformation of flag type determines the specific behaviour of the bullet. Documentation can be found here.

BulletEffectType-67108864 - etExDelay(string et, string isAsync, string time)


Hide the bullet for time frames. During this time, it will not move, will be invisible and won't have a hitbox. If used as a first transformation, can be used to delay when the bullet actually appears.

6 - isDelayedSpawn


While this flag is set, the bullet will be invisible and not have a hitbox. This flag is cleared once the delay timer ends.

4 - short_timer


Integer value between -1 and 15 inclusive (by default -1). If non-negative, shooters using short_timer shoot their bullets and timer increments by 1 per frame until 15 is reached. Once 15, timer reset to -1 or 0 depending on Z key state.

5 - long_timer


Integer value between -1 and 120 inclusive (by default -1). If non-negative, shooters using long_timer shoot their bullets and timer increments by 1 per frame until 120 is reached. Once 120, timer reset to -1 or 0 depending on Z key state.

503 - flagClear(int n)


Clears flag(s) according to n. Refer to the flag table here for exact values.

91 - floatTime(int slot, float var, int time, int mode, float start, float final)


In time frames using mode mode, variable var changes from start to final. slot is used to set the slot to be used by this ins, every enemy has 8 slots.

-9980 - F1


Local float variable, inherited by spawned enemies.

-9984 - I1


Local integer variable, inherited by spawned enemies.

-9989 - ANGLE_PLAYER


Angle from the enemy to the player.

-9962 - BOSS_Y


Final Y position of the boss.

-9990 - PLAYER_Y


Player's Y position.

-9963 - BOSS_X


Final X position of the boss.

-9991 - PLAYER_X


Player's X position.

81 - circlePos(float varX, float varY, float angle, float radius)


Performs following operation: varX = cos(angle) * radius and varY = cos(angle) * radius

-9981 - F0


Local float variable, inherited by spawned enemies.

300 - enmCreate(string sub, float x, float y, int hp, int score, int item)


Creates an enemy using subroutine sub at coordinates (x, y) (relative to position of the parent), health of created enemy is hp, score bonus is score and item drop is item.

601 - etOn(int etId)


Shoots bullet(s) using properties from bullet manager etId.

23 - wait(int time)


Stops sub execution for time frames.

1 - delete()


Returns to the top of current call stack.

2 - GAME_SPEED


The value controls by how much faster the game speed is run. This variable is often set to a number between 0 and 1. This value is often changed when a (final) boss dies or when a photo is taken. Its default value is 1.

-9985 - I0


Local integer variable, inherited by spawned enemies.

-9983 - I2


Local integer variable, inherited by spawned enemies.

-9982 - I3


Local integer variable, inherited by spawned enemies.

-9954 - ENEMY_HP


Enemy's current HP.

3 - goheiExists


A flag that determines if a gohei exists on-screen or not. Flag is set to true by active gohei. Flag is set to false if gohei goes off-screen or is despawning.

-9926 - GI0


Global integer value. Value is initialised to 0 on stage load but not on stage reset.

-9925 - GI1


Global integer value. Value is initialised to 0 on stage load but not on stage reset.

-9924 - GI2


Global integer value. Value is initialised to 0 on stage load but not on stage reset.

-9923 - GI3


Global integer value. Value is initialised to 0 on stage load but not on stage reset.

17 - distortion(int a)


Triggers distortion effects on the edge of the screen. The meaning of the argument is not entirely clear. SA uses a value of 1 to create distortion at the bottom of the screen, while UFO uses this same value to create distortion at the top.

539 - spell3(int id, int timeRate, int unused, string name)


Declares a spell-card with id id and name unused. The ID passed to the spell-creating function is id + difficulty - 2 (with easy=0, normal=1, ..., overdrive=5). timeRate determines how much time the spell circle takes to shrink (in frames), as well as how fast the spell bonus decreases.

514 - setInterrupt(int slot, int hp, int duration, string subroutine)


Sets an interrupt on slot slot. Once caller's HP reaches hp or duration frames have passed since this instruction was called, the caller will terminate all subroutines it's currently running and execute subroutine subroutine.

270 - enmCreate270(string sub, float x, float y, int hp, int score, int item)


Creates an enemy using subroutine sub at coordinates (x, y) (relative to position of the stage background camera), health of created enemy is hp, score bonus is score and item drop is item.

Laser Midpoint Bug


Specifications


  • Versions: 1.00 - 1.00a - 1.00b
  • Difficulty: Easy - Normal - Hard - Lunatic - Extra - Phantasm
  • Mode: Main game - Practice mode
  • Shottype: ReimuA - ReimuB - MarisaA - MarisaB - SakuyaA - SakuyaB

What happens


When a straight laser spawns, there is a small period of time before the laser fully appears and disappears. During these times, the laser only shows a thin warning line that warns the player about a spawning/despawning laser. This warning line usually does not have a hitbox except in one spot, which is in the middle of the laser.

An in-game screenshot of ReimuB dying to Alice's attack.
Figure 1: ReimuB is being hit by a laser as the laser is despawning, which should not happen.

How it happens


This bug can be replicated by being at the midpoint of the laser while the laser is spawning or despawning naturally: if a laser despawns by getting cancelled, then this midpoint bug will not occur. Since it is the midpoint, it is rather small. On top of this, the hitbox only stays for a few frames. In PCB, this bug can happen on almost any attack that features a laser. Below is a table listing every section of the game with a laser, and whether it's possible to get hit on the spawning phase, or on the despawning phase.

Pattern Spawning Despawning
Alice's mid-spell-card Yes (20f) Yes (16f)
Merlin's 2nd non-spell Yes (34f) No*
Merlin's 3rd non-spell Yes (10f) Yes (20f)
Prismrivers' 3rd spell-card Yes (14f) Yes (16f)
Prismrivers' 4th spell-card Yes (104f) No*
Yuyuko's 1st spell-card No** Yes (20f)
Yuyuko's 7th spell-card Yes (30f) Yes (36f)
Ran's 3rd spell-card Yes (10f) Yes (30f)
Ran's 6th spell-card (blue) No, No, Yes (30f) Yes (16f), Yes (16f), Yes (32f)
Ran's 6th spell-card (red) No Yes (32f)
Ran's 9th spell-card No No*
Yukari's 3rd spell-card Yes (10f) Yes (30f)
Yukari's 4th spell-card No Yes (30f)
Yukari's 5th spell-card No Yes (30f)
Yukari's 6th spell-card (blue) No, No, Yes (30f) Yes (16f), Yes (16f), Yes (32f)
Yukari's 6th spell-card (red) No Yes (32f)
Yukari's 9th spell-card No No*

*While the despawning conditions are met, the lasers take longer to despawn than what the attack lasts for, rendering it not possible.
**While the spawning conditions are met, it cannot actually happen because the laser midpoint is offscreen for the entire duration of the spawning phase.

Ran and Yukari's 6th spell-card has three different values. This is because the lasers there are different from one another.

Why it happens


The tiny hitbox at the midpoint has a width equal to the full width of the laser, and a height equal to the visual width of the laser. Presumably, ZUN intended for lasers hitbox's length to match the laser length and the width to match the visual width of the laser. This way, the laser's hitbox would get wider as the laser sprite thickens right before fully materializing, and shrink as the sprite thins when it begins to despawn. However, it seems like ZUN accidentally mixed up the fields for hitbox width and height.

Two lasers, one not fixed and the other fixed.
Figure 2: This image compares the current hitbox with the possible intended fix. (1) Current laser. (2) Fixed laser. While this does make more sense, it also means that there is a smaller hitbox in the fixed laser now.

But why does this sometimes happen with some lasers? To understand the cause of this bug, we must first understand how lasers work in this game.

Laser States


A laser progresses through five visual states over its lifetime. They are explained through the following figure:

Four lasers, each representing a different state from left to right.
Figure 3: This image shows all laser states labelled 1 (left) through 5 (right). (1) Spawning laser without hitbox. (2) Spawning laser with hitbox. (3) Active laser. (4) Despawning laser with hitbox. (5) Despawning laser without hitbox.

In the code, a laser can take many parameters, but we will be focussing only on the following parameters:

  • hitbox_start_time: time until laser's partial hitbox materializes (state 1 -> state 2)
  • start_time: time until laser fully materializes (state 1 -> state 3)
  • duration: time the laser is active for (state 3 -> state 4)
  • hitbox_end_delay: time the laser's partial hitbox is active for (state 4 -> state 5)
  • despawn_duration: time until the laser fully despawns (state 4 -> despawn)

A rough pseudocode layout is shown below describing the logic of the states and parameters:

laser_state = SPAWNING
timer = 0

while (true) {
    if (laser_state == SPAWNING) {
        if (timer >= hitbox_start_time) {
            activate_laser_midpoint_hitbox()
        }   

        if (timer >= start_time) {
            laser_state = ACTIVE
            timer = 0
        }
    }
    if (laser_state == ACTIVE) {
        if (timer < duration) {
            activate_laser_hitbox()
        } else {
            laser_state = DESPAWNING
            timer = 0
        }   
    }
    if (laser_state == DESPAWNING) {
        if (timer < hitbox_end_delay) {
            activate_laser_midpoint_hitbox()
        }
        if (timer >= despawn_duration) {
            despawn_laser()
        }
    }
    timer++
}

Hitbox while spawning (states 1, 2)


if (laser_state == SPAWNING) {
    if (timer >= hitbox_start_time) {
        activate_laser_midpoint_hitbox()
    }   

    if (timer >= start_time) {
        laser_state = ACTIVE
        timer = 0
    }
}

For the laser to only have the hitbox in its midpoint, it means that time >= hitbox_start_time must be true and time >= start_time must be false, or to put it simply, hitbox_start_time < start_time must be true. The duration the midpoint will have a hitbox is equal to start_time - hitbox_start_time.

Hitbox while despawning (states 4, 5)


if (laser_state == DESPAWNING) {
    if (timer < hitbox_end_delay) {
        activate_laser_midpoint_hitbox()
    }
    if (timer >= despawn_duration) {
        despawn_laser()
    }
}

For the laser to only have the hitbox in its midpoint, it means that time < hitbox_end_delay must be true and time >= despawn_duration must be false, or to put it simply, hitbox_end_delay > 0 must be true. Every laser in PCB has hitbox_end_delay > 0, so it means every laser has a hitbox in its midpoint while despawning. The duration the midpoint will have a hitbox is equal to min(hitbox_end_delay, despawn_duration).



Replays


  • Replay sp0@brkx by "sp0". Lunatic, ReimuB, 1.00b. 「March 24, 2019」. Download link (Note: Alice's mid-spell-card laser death)
  • Replay laserbug by "icterine". Easy, ReimuB, 1.00b. 「February 16, 2026」. Download link (Note: Prismrivers' 4th spell-card laser death)

Videos


This section has no content yet. Would you like to add to this section? Contact me if you are interested!