Now that I've moved on from asking basic "Why this don't work!?" questions, I've gotten to the concept phase. Title doesn't describe it too well, but, ehm, character limits.
Situation: I have a TMemoryStream[, that I search through for seven
FF hex byte combinations, from 6-18 bytes in length. These are separators that precede a placed NPC's data, and since they vary in size, I need to get their index in the stream, without having invalid indexes.
...An example might explain it better. Say I have the following separator in the Stream:
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
The above separator is 18 bytes in length. If I search the whole TMemoryStream for 18 FF bytes, I'm A-OK. But I then have to search the stream for smaller sequences of FF bytes, the smallest being 6 FF bytes.
If I were to search for 6 FF bytes, the above stream would give me thirteen indexes, which are "invalid". The "sub-indexes" are invalid, as I need to get entire sequence of FF bytes, to know how many bytes I need to move forward to get to the wanted NPC data.
I thought two TStringLists would do the trick, one for the indices, the other for the length of the valid separators. But they're too rigid; if I use
.Sorted := true;, I lose the 1:1 nature of the two TStringLists (can't do
FirstList[iCounter]; SecondList[iCounter];).
So yeah, kinda stuck 'ere.
Github repo's
here.
And here's the function that adds the indexes and separator lengths:
Function GetNPCData(msMAPFile: TMemoryStream; dwordPointer: DWord;
Out tstrlistSeparatorPos,
tstrlistSeparatorLength: TStringList): recordNPCArray;
var
msSubStream: TMemoryStream;
iCounter, byteArrayLength: Byte;
iSubCounter: Word;
iPosResult: integer;
tpaCurrentArray: TPatternArray;
begin
if Length(arrayNPCDataSeparators) = 0 then
FillMetaArrays();
msMAPFile.Seek(dwordPointer, 0);
msSubStream := TMemoryStream.Create;
msSubStream.CopyFrom(msMAPFile, 2000);
for iCounter := 1 to 7 do begin //For each separator
tpaCurrentArray := arrayNPCDataSeparators[iCounter];
byteArrayLength := Length(tpaCurrentArray);
for iSubCounter := 1 to (msSubStream.Size - (byteArrayLength - 1) ) do begin
iPosResult := SearchTMemStream(msSubStream, tpaCurrentArray);
if iPosResult > -1 then begin
tstrlistSeparatorPos.Add(IntToStr(iPosResult));
tstrlistSeparatorLength.Add(IntToStr(byteArrayLength));
end; //End "If separator found in stream"
end; //End "For bytes in stream"
end; //End "For each separator"
msSubStream.Free;
end;