예제 #1
0
        private static RemapSegment[] InitSegments(RemapHeader header, MapEntry[] mapEntries)
        {
            var segments = new RemapSegment[header.MapSegmentCount];
            int entryIdx = 0;

            for (int i = 0; i < header.MapSegmentCount; i++)
            {
                var seg = new RemapSegment();
                seg.Entries.Add(mapEntries[entryIdx]);
                seg.Offset = mapEntries[entryIdx].VirtualOffset;
                mapEntries[entryIdx].Segment = seg;
                entryIdx++;

                while (entryIdx < mapEntries.Length &&
                       mapEntries[entryIdx - 1].VirtualOffsetEnd == mapEntries[entryIdx].VirtualOffset)
                {
                    mapEntries[entryIdx].Segment  = seg;
                    mapEntries[entryIdx - 1].Next = mapEntries[entryIdx];
                    seg.Entries.Add(mapEntries[entryIdx]);
                    entryIdx++;
                }

                seg.Length  = seg.Entries[seg.Entries.Count - 1].VirtualOffsetEnd - seg.Entries[0].VirtualOffset;
                segments[i] = seg;
            }

            return(segments);
        }
예제 #2
0
        private MapEntry GetMapEntry(long offset)
        {
            int segmentIdx = GetSegmentFromVirtualOffset(offset);

            if (segmentIdx < Segments.Length)
            {
                RemapSegment segment = Segments[segmentIdx];

                foreach (MapEntry entry in segment.Entries)
                {
                    if (entry.VirtualOffsetEnd > offset)
                    {
                        return(entry);
                    }
                }
            }

            throw new ArgumentOutOfRangeException(nameof(offset));
        }