From 365d8ea3462ce7e010b16d8d45b552d8a2bf7b3d Mon Sep 17 00:00:00 2001 From: nmlgc Date: Wed, 4 May 2022 21:09:33 +0200 Subject: [PATCH] [Maintenance] [th01] Shootout lasers: Add a safe subscript wrapper Part of P0193, funded by Ember2528. --- th01/main/boss/b20j.cpp | 5 +---- th01/main/boss/b20m.cpp | 4 +--- th01/main/bullet/laser_s.hpp | 4 ++++ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/th01/main/boss/b20j.cpp b/th01/main/boss/b20j.cpp index 80c345c4..778ed16e 100644 --- a/th01/main/boss/b20j.cpp +++ b/th01/main/boss/b20j.cpp @@ -1355,10 +1355,7 @@ void pattern_lasers_and_3_spread(void) } target_y = PLAYFIELD_BOTTOM; - // Quite a roundabout way of preventing a buffer overflow, but fine. - shootout_lasers[ - (boss_phase_frame / INTERVAL) % SHOOTOUT_LASER_COUNT - ].spawn( + shootout_laser_safe(boss_phase_frame / INTERVAL).spawn( SWORD_CENTER_X, SWORD_CENTER_Y, target_left, target_y, (to_sp(8.5f) / 2), V_WHITE, 30, 5 diff --git a/th01/main/boss/b20m.cpp b/th01/main/boss/b20m.cpp index 60eee151..a995bfb7 100644 --- a/th01/main/boss/b20m.cpp +++ b/th01/main/boss/b20m.cpp @@ -1846,9 +1846,7 @@ void near pattern_radial_stacks_and_lasers(void) target_y = polar_y(CENTER_Y, 600, angle); mdrv2_se_play(7); if((boss_phase_frame % 15) == 0) { - shootout_lasers[ - ((boss_phase_frame - 215) / 15) % SHOOTOUT_LASER_COUNT - ].spawn( + shootout_laser_safe((boss_phase_frame - 215) / 15).spawn( CENTER_X, CENTER_Y, target_x, target_y, pattern_state.speed_multiplied_by_8, V_WHITE, 20, 4 ); diff --git a/th01/main/bullet/laser_s.hpp b/th01/main/bullet/laser_s.hpp index 5d8565a9..ceb9e826 100644 --- a/th01/main/bullet/laser_s.hpp +++ b/th01/main/bullet/laser_s.hpp @@ -126,6 +126,10 @@ extern CShootoutLaser shootout_lasers[SHOOTOUT_LASER_COUNT]; } \ } +// Quite a roundabout way of preventing buffer overflows, but fine. +#define shootout_laser_safe(i) \ + shootout_lasers[(i) % SHOOTOUT_LASER_COUNT] + #define shootout_lasers_unput_and_reset_broken(i) { \ for(i = 0; i < SHOOTOUT_LASER_COUNT; i++) { \ shootout_lasers[i].unput_and_reset(); \