From 850845757e66f07efea855b5774eea185e2e26c7 Mon Sep 17 00:00:00 2001 From: Dethrace Labs <78985374+dethrace-labs@users.noreply.github.com> Date: Sun, 30 Nov 2025 14:05:30 +1300 Subject: [PATCH] FindPreviousChunk matching --- src/DETHRACE/common/piping.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/DETHRACE/common/piping.c b/src/DETHRACE/common/piping.c index e1ac5a18..3a308780 100644 --- a/src/DETHRACE/common/piping.c +++ b/src/DETHRACE/common/piping.c @@ -1758,27 +1758,30 @@ tPipe_chunk* FindPreviousChunk(tU8* pPtr, tPipe_chunk_type pType, tChunk_subject ptr = pPtr; chunk_counter = 0; masked_index = pIndex & 0x0fff; - while (1) { - if (!MoveSessionPointerBackOne(&ptr)) { - reached_end = chunk_counter >= gMax_rewind_chunks; - chunk_counter++; - } else { + do { + if (MoveSessionPointerBackOne(&ptr) != 0 || gMax_rewind_chunks <= chunk_counter++) { reached_end = 1; + } else { + reached_end = 0; } + if (!reached_end) { gEnd_of_session = ptr + LengthOfSession((tPipe_session*)ptr) - sizeof(tU16); mr_chunky = &((tPipe_session*)ptr)->chunks; - for (i = 0; i < ((tPipe_session*)ptr)->number_of_chunks && ((tPipe_session*)ptr)->chunk_type == pType; i++) { - if ((mr_chunky->subject_index & 0xfff) == masked_index) { - return mr_chunky; + for (i = 0; i < ((tPipe_session*)ptr)->number_of_chunks; i++) { + if (((tPipe_session*)ptr)->chunk_type == pType) { + if ((mr_chunky->subject_index & 0xfff) == masked_index) { + return mr_chunky; + } else { + AdvanceChunkPtr(&mr_chunky, pType); + } + } else { + break; } - AdvanceChunkPtr(&mr_chunky, pType); } } - if (reached_end) { - return NULL; - } - } + } while (!reached_end); + return NULL; } // IDA: void __usercall UndoModelGeometry(tPipe_chunk **pChunk@)