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.

Hourai Jewel Bounce


Specifications


  • Versions: 1.00 - 1.00a - 1.00b - 1.00c - 1.00d
  • Difficulty: Easy - Normal - Hard - Lunatic - Extra - Last Word
  • Mode: Main game - Practice mode - Spell Practice
  • Shottype: Border Team - Magic Team - Ghost Team - Scarlet Team - Reimu - Yukari - Marisa - Alice - Youmu - Yuyuko - Sakuya - Remilia

What happens


On Kaguya's 5th spell-card, there is a chance that a bullet from below bounces upward. This comes from the initial wave the familiars shoot.

A bullet is approaching from underneath Youmu
Figure 1: Youmu is about to get hit by a bullet coming from under her

How it happens


To get this, you usually have to be unlucky. However, since there is no RNG involved there are normalised set-ups one could use to get this bug.

Why it happens


In order to understand this phenomenon, we need to take a look at the bullet's transformation properties.

Bullet transformations


Bullet transformations or transformations are special properties that are given to a bullet. The bullet could for example be immune against bombs, or the bullet could change color, or a certain sound could play when the bullet is first shot.

In the context of this glitch, there are two relevant bullet transformations at play:

  • Transformation 2048 - bounce on all walls except bottom
  • Transformation 128 - sets angle towards player

The bullets that use this transformation are shot by the first wave of the familiar enemies.

Bullet transformations order


The bullet transformations are applied one after the other in a specific sequence. The sequence in which the bullet transformations are applied on this attack are as follows:

Transformation 2048 → Transformation 128 → Transformation 16384

Note that transformation 16384 is not relevant for the bug in this case.

Out of Bounds


A bullet is considered to be Out of Bounds or OoB from below if the bullet's position meets the criteria y > 448 + (sprite_y / 2). The rice bullets have a sprite of 16 by 16, so that means the bullet is out of bounds if y > 456.

Game frame events


On every game frame, every bullet on-screen executes a certain sequence of code. The sequence (in short) goes as follows:

  1. The game checks if the bullet has an active transformation.
  2. The game executes the relevant code tied to the active transformation.
  3. The game updates the bullet's angle and position accordingly.
  4. The game checks if the bullet is OoB.

Pseudo-code


Below is a more extensive explanation of the order of events written in pseudo-code.

if (no transform active) {
    activate next transform in list;
    reset tr_timer to 0;
}
if (transform 128 active) {
    if (tr_timer >= delay_time) {
        change bullet angle to aim towards player;
        deactivate this transform;
    }
    else {
        tr_timer += 1;
    }
}
if (transform 1024 or 2048 active) {
    if (bullet out of bounds) {
        if (transform == 2048 && y > 456) {
            don't change bullet angle;
        }
        else {
            change bullet angle;
        }
        deactivate this transform;
    }
}

update bullet position according to speed and angle;

if (bullet out of bounds) {
    if (transform 128, 1024 or 2048 active) {
        oob_timer += 1;
    }
    else if (oob_timer > 0) {
        oob_timer -= 1;
    }
    else {
        delete this bullet;
    }
}
else {
    oob_timer = 0;
}

A few notes:

  • Everything that happens in a frame that is not relevant to this has been left out.
  • tr_timer is a timer that counts the amount of frames a transform has been active.
  • delay_time in transform 128 refers to a value set in the etEx ECL instruction. In this case, the value is equal to 1.
  • oob_timer is a timer that prevents the bullet from being deleted out of bounds if it is nonzero.

Explanation


  1. The bullet is shot. Transformation 2048 is active.
  2. After some time, the bullet reaches one frame before it is out of bounds.
  3. The next frame the bullet's position updates and it is now OoB going downward. However, since a transformation is active a counter oob_timer is increased by 1. The bullet isn't deleted.
  4. The next frame transformation 2048 is still active. The bullet meets the condition y > 456. This results in the bullet not changing its angle. The transformation is then deactivated, meaning there's no transformation on the bullet. The bullet's position is updated (it still goes downward). The bullet is OoB going downward but oob_timer is equal to 1, so oob_timer decreases by 1 and now has a value of 0.
  5. The next frame transform 128 is activated, setting tr_timer to 0. Since tr_timer >= delay_time is false (0 >= 1 with the value 1 being the 4th parameter of the etEx instruction), tr_timer increases by 1. The bullet is still OoB still going downward. Transformation 128 is active, so oob_timer increases by 1.
  6. The next frame transformation 128 is still active, This time, the condition tr_timer >= delay_time is met. The bullet's angle changes to be toward the player. The bullet no longer has an active transformation. The bullet's position updates to go upwards. The bullet is still OoB but oob_timer is equal to 1, so oob_timer decreases by 1 and now has a value of 0.
  7. The next frame transformation 16384 is applied. The bullet's position updates. However, this time the bullet no longer is OoB. The bullet has successfully done the bounce.

Below is a simple diagram of the explanation. Since the speed of the bullet is constant, the length of the vectors are the same.

A 2D diagram is shown with vectors, each vector explaining what happens
Figure 2: A diagram of the aforementioned explanation.

However, in this diagram the bullet is coming at a very skew angle from y = 456, and the bullet is perpendicular to y = 456 once it is aimed towards the player. While this is achievable in-game (by moving the player character to be above a bottom corner), this is not what is happening in the initial image.

A 2D diagram with vectors, each vector explaining what happens
Figure 3: A diagram of a bullet coming in from a very skew angle

This diagram is more realistic as to what is happening in the initial image. The tip of the green arrow is barely above y = 456. If at step 3 the bullet was slightly farther away from y = 456, it would have meant that at step 7 the bullet is still OoB meaning it would have despawned.

Conclusion


The Hourai Jewel bounce bug is triggered through a series of very unlikely events that are indeterminable in a real run. The bounce happens because the bullet does not immediately despawn once out of bounds. The bullet does not despawn immediately because it has a number of bullet transformations to do first. Due to mathematical reasons, this can only happen if the initial angle of the bullet is less than the angle towards the player.


Replays


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

Videos


A Discord message
Figure 4: Rivers's legacy