From 339dc5dd30e5fbaef299ac0339c86b8761259a5e Mon Sep 17 00:00:00 2001 From: benlp91 <137918874+benlp91@users.noreply.github.com> Date: Thu, 21 Nov 2024 00:19:56 +0100 Subject: [PATCH] CONCEAL_MAP_RECT script command still works when out of bounds (#3700) Co-authored-by: walter253 <130906143+walt253@users.noreply.github.com> Co-authored-by: Loobinex --- src/lvl_script_commands.c | 50 +++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/lvl_script_commands.c b/src/lvl_script_commands.c index f92ce76e6a..bc34659a0c 100644 --- a/src/lvl_script_commands.c +++ b/src/lvl_script_commands.c @@ -867,8 +867,7 @@ static void conceal_map_rect_check(const struct ScriptLine *scline) { conceal_all = 0; } - else - if ((strcmp(scline->tp[5], "ALL") == 0) || (strcmp(scline->tp[5], "1") == 0)) + else if ((strcmp(scline->tp[5], "ALL") == 0) || (strcmp(scline->tp[5], "1") == 0)) { conceal_all = 1; } @@ -887,14 +886,52 @@ static void conceal_map_rect_check(const struct ScriptLine *scline) MapSubtlCoord start_y = y - (height / 2); MapSubtlCoord end_y = y + (height / 2) + (height & 1); - if ((start_x < 0) || (end_x > gameadd.map_subtiles_x) || (start_y < 0) || (end_y > gameadd.map_subtiles_y)) + if (start_x < 0) + { + SCRPTWRNLOG("Starting X coordinate '%ld' (from %ld-%ld/2) is out of range, fixing it to '0'.", start_x,x,width); + start_x = 0; + } + else if (start_x > gameadd.map_subtiles_x) + { + SCRPTWRNLOG("Starting X coordinate '%ld' (from %ld-%ld/2) is out of range, fixing it to '%ld'.", start_x, x, width, gameadd.map_subtiles_x); + start_x = gameadd.map_subtiles_x; + } + if (end_x < 0) { - SCRPTERRLOG("Conceal coordinates out of range, trying to conceal from (%ld,%ld) to (%ld,%ld) on map that's %ldx%ld subtiles", - start_x, start_y, end_x, end_y, gameadd.map_subtiles_x, gameadd.map_subtiles_y); + SCRPTWRNLOG("Ending X coordinate '%ld' (from %ld+%ld/2) is out of range, fixing it to '0'.", end_x, x, width); + end_x = 0; + } + else if (end_x > gameadd.map_subtiles_x) + { + SCRPTWRNLOG("Ending X coordinate '%ld' (from %ld+%ld/2) is out of range, fixing it to '%ld'.", end_x, x, width, gameadd.map_subtiles_x); + end_x = gameadd.map_subtiles_x; + } + if (start_y < 0) + { + SCRPTWRNLOG("Starting Y coordinate '%ld' (from %ld-%ld/2) is out of range, fixing it to '0'.", start_y, y, height); + start_y = 0; + } + else if (start_y > gameadd.map_subtiles_y) + { + SCRPTWRNLOG("Starting Y coordinate '%ld' (from %ld-%ld/2) is out of range, fixing it to '%ld'.", start_y, y, height, gameadd.map_subtiles_y); + start_y = gameadd.map_subtiles_y; + } + if (end_y < 0) + { + SCRPTWRNLOG("Ending Y coordinate '%ld' (from %ld+%ld/2) is out of range, fixing it to '0'.", end_y, y, height); + end_y = 0; + } + else if (end_y > gameadd.map_subtiles_y) + { + SCRPTWRNLOG("Ending Y coordinate '%ld' (from %ld+%ld/2) is out of range, fixing it to '%ld'.", end_y, y, height, gameadd.map_subtiles_y); + end_y = gameadd.map_subtiles_y; + } + if ((x < 0) || (x > gameadd.map_subtiles_x) || (y < 0) || (y > gameadd.map_subtiles_y)) + { + SCRPTERRLOG("Conceal coordinates out of range, trying to set conceal center point to (%ld,%ld) on map that's %ldx%ld subtiles", x, y, gameadd.map_subtiles_x, gameadd.map_subtiles_y); DEALLOCATE_SCRIPT_VALUE return; } - value->plyr_range = scline->np[0]; value->shorts[1] = start_x; value->shorts[2] = end_x; @@ -912,7 +949,6 @@ static void conceal_map_rect_process(struct ScriptContext *context) MapSubtlCoord start_y = context->value->shorts[3]; MapSubtlCoord end_y = context->value->shorts[4]; TbBool conceal_all = context->value->shorts[5]; - conceal_map_area(context->player_idx, start_x, end_x, start_y, end_y, conceal_all); }