Example #1
0
        public void Visit(IntegerEnum integer, byte data)
        {
            Content.Add(integer.Value);

            if (model.GetNextRun(integer.Source) is not ITableRun containingTable)
            {
                return;
            }
            var offset    = containingTable.ConvertByteOffsetToArrayOffset(integer.Source);
            var enumValue = model.ReadMultiByteValue(offset.SegmentStart, containingTable.ElementContent[offset.SegmentIndex].Length);
            var segment   = containingTable.ElementContent[offset.SegmentIndex];

            if (segment is ArrayRunRecordSegment recordSegment)
            {
                segment = recordSegment.CreateConcrete(model, integer.Source);
            }
            if (segment is not ArrayRunEnumSegment enumSeg)
            {
                return;
            }
            var parentAddress = model.GetAddressFromAnchor(new(), -1, enumSeg.EnumName);

            if (model.GetNextRun(parentAddress) is not ArrayRun parentArray)
            {
                return;
            }
            foreach (var array in model.GetRelatedArrays(parentArray))
            {
                int segOffset = 0;
                foreach (var seg in array.ElementContent)
                {
                    var itemIndex   = enumValue + array.ParentOffset.BeginningMargin;
                    var destination = model.ReadPointer(array.Start + array.ElementLength * itemIndex + segOffset);
                    segOffset += seg.Length;
                    if (seg.Type != ElementContentType.Pointer)
                    {
                        continue;
                    }
                    if (model.GetNextRun(destination) is not ISpriteRun spriteRun)
                    {
                        continue;
                    }
                    var paletteRuns = spriteRun.FindRelatedPalettes(model, array.Start + array.ElementLength * itemIndex);
                    Content.Add(ReadonlyPixelViewModel.Create(model, spriteRun, paletteRuns.FirstOrDefault(), true));
                    return;
                }
            }
        }