From 2cc796a042811edd7877425b326fda1009e63a47 Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 11 Oct 2023 16:11:14 +0100 Subject: [PATCH] M_AssignSprayCans: Don't handle the prepended cans in reverse order Was messing around with part-duplicating this code for Prison Egg CDs, and realised a corruption/overwriting bug if you had more freebie Spray Cans than the standard ones. --- src/m_cond.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/m_cond.c b/src/m_cond.c index 53d199d98..330b65c5a 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -806,14 +806,15 @@ static void M_AssignSpraycans(void) M_Shuffle_UINT16(tempcanlist + prependoffset - (prependlen - 1), prependlen); // Put at the front of the main list - // (technically reverses the prepend order, but it + // (technically messes with the main order, but it // was LITERALLY just shuffled so it doesn't matter) - while (prependlen) + i = 0; + while (i < prependlen) { - prependlen--; - tempcanlist[listlen] = tempcanlist[prependlen]; - tempcanlist[prependlen] = tempcanlist[prependoffset - prependlen]; + tempcanlist[listlen] = tempcanlist[i]; + tempcanlist[i] = tempcanlist[prependoffset - i]; listlen++; + i++; } }