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.

Negative Spell Bonus


Specifications


  • Versions: 1.00a
  • Difficulty: Easy - Normal - Hard - Lunatic - Extra
  • Mode: Main game - Practice mode
  • Shottype: ReimuA - ReimuB - ReimuC - MarisaA - MarisaB - MarisaC

What happens


It is possible to achieve a negative Spell Card Bonus (SCB) on Yuugi's first spell-card (枷符「咎人の外さぬ枷」) on the difficulties Hard/Lunatic. Capturing the spell-card with a negative value decreases the current score. The SCB displayed will not be very comprehensible:

A screenshot with the text
Figure 1: A negative SCB is gotten, displaying a weird bonus

If the spell is captured with an SCB of exactly 0, no score is obtained and no score value is displayed:

A screenshot with the text
Figure 2: Spell Bonus is gotten but no bonus is provided

How it happens


This is done by timing down Yuugi's first spell-card (枷符「咎人の外さぬ枷」) on either Hard or Lunatic difficulty. To be more precise, the player must time down this spell-card to a time below 04.68s for the SCB to become negative. This bug does not appear anywhere else, or when doing this spell-card on Easy/Normal mode.

A screenshot of the fight with Yuugi on her first spell-card
Figure 3: An SCB of zero is shown at exactly t=04.68s

Why it happens


How SCB is calculated


The rate at which the SCB decreases is determined by the ECL instruction spell3. The timeRate parameter is the only parameter that influences the SCB. Calculating the SCB at a given point is done with the following formula:

int compute_output_score(max_score, time_rate, current_time) {
    if current_time < 300 // scb decreases only after first 5 seconds (300 frames)
        return max_score
    int score_div_10 = floor(max_score / 10)
    int score_loss = truncate((max_score - score_div_10) / (time_rate - 300))
    int score = max_score - (score_loss * (current_time - 300))
    score = score - (score % 10)
    return score
}
  • max_score is the maximum score obtainable from capturing the spell-card. This value is hard-coded.
  • time_rate is the second value passed in the ECL instruction spell3.
  • current_time is a number the user passes to calculate what the SCB is at that given time.

Examples:

  • compute_output_score(6000000, 2100, 1000) outputs an SCB of 3900000;
  • compute_output_score(6000000, 2100, 2099) outputs 603000;
  • compute_output_score(6000000, 300, 123456789) throws a division by 0 error and would crash the game, but this has not appeared in any ZUNcode (yet).

In the example of Yuugi's first spell-card, the ECL instruction spell3 has a timeRate of 2100. The max_score is 6000000, which is hard-coded for this stage on Lunatic. For this spell-card to obtain a negative spell-card the output of compute_output_score would have to be below 0, or in other words we have to find a value t such that compute_output_score(6000000, 2100, t) < 0. For this to be true, t must be 2301 or greater. But how would this be possible?

The ECL instruction setInterrupt


The ECL instruction setInterrupt has a parameter duration. This parameter determines how long a pattern lasts for. For example, if duration is 3600 then the attack lasts for 3600 frames or 60 seconds.

The duration parameter of setInterrupt should always be equal or less than the value timeRate of spell3. This is true for every spell-card in Touhou except for one spell-card, Yuugi's first spell-card.

On Yuugi's first spell-card, the duration parameter of setInterrupt is 2580 (= 43.00s). In contrast, the timeRate parameter of spell3 on Hard/Lunatic is 2100. This means that it is possible to get a t value greater than the time_rate value. This happens because ZUN forgot to change the duration parameter to 2100 for Hard/Lunatic.

Below is the ECL code that is responsible for this bug. setInterrupt's duration parameter is the same for the spell on Easy/Normal and Hard/Lunatic despite the different timeRate value.

setInterrupt(0, 0, 2580, "Boss2");
if (EASY or NORMAL) {
    spell(30, 2580, 500000, "怪輪「地獄の苦輪」");
} else if (HARD or LUNATIC) {
    spell3(32, 2100, 500000, "枷符「咎人の外さぬ枷」");
} 

This issue could easily be fixed by changing the timeRate value from 2100 to 2580.

setInterrupt(0, 0, 2580, "Boss2");
if (EASY or NORMAL) {
    spell(30, 2580, 500000, "怪輪「地獄の苦輪」");
} else if (HARD or LUNATIC) {
    spell3(32, 2580, 500000, "枷符「咎人の外さぬ枷」");
} 

Alternatively, the spell-card duration could be reduced to 2100 frames on Hard/Lunatic:

if (EASY or NORMAL) {
    setInterrupt(0, 0, 2580, "Boss2");
    spell(30, 2580, 500000, "怪輪「地獄の苦輪」");
} else if (HARD or LUNATIC) {
    setInterrupt(0, 0, 2100, "Boss2");
    spell3(32, 2100, 500000, "枷符「咎人の外さぬ枷」");
} 

Conclusion


The negative SCB bug on Yuugi's first spell-card comes from a mismatch between the spell duration and the timeRate parameter used in Spell Card Bonus (SCB) calculation. This inconsistency allows the SCB formula to produce negative values when the spell is timed down. Due to a simple oversight, this behaviour is unique to this spell-card on the difficulties Hard/Lunatic.


Replays


  • Replay Nylilsa by "Nylilsa". Hard, ReimuA, 1.00a. 「February 15, 2023」. Download link
  • Replay Nylilsa by "Nylilsa". Lunatic, MarisaB, 1.00a. 「September 13, 2022」. Download link

Videos


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

All Subterranean Animism pages:
Negative Spell Bonus · ReimuA 2 Power Damage · Mid-boss skips · ReimuC Desync · Score Desync · ReimuA Desync · Stage 6 Desync · Stage transition Desync · Extra Relocking · Extra Leaderboard Crash · 999.99s Spell Timer · Stage Transition Death Crash · Slowdown Item Duplication
All Ecl-related pages:
All Overflow-related pages: