Beispiel #1
0
        private static void WriteAsMap(Stream stream, M4 mapModel)
        {
            var mapHeader = new SubModelMapHeader
            {
                Type             = Map,
                DmaChainMapCount = mapModel.VifPackets.Count,

                Unk04      = mapModel.unk04,
                Unk08      = mapModel.unk08,
                NextOffset = mapModel.nextOffset,
                va4        = mapModel.va4,
                Count1     = mapModel.count1, // in a form, ignored by the game engine
            };

            BinaryMapping.WriteObject(stream, mapHeader);

            var dmaChainMapDescriptorOffset = (int)stream.Position;

            stream.Position += mapModel.VifPackets.Count * 0x10;

            mapHeader.Offset1 = (int)stream.Position;
            stream.Position  += mapModel.alb2.Count * 4;
            var alb2Offsets = new List <int>();

            foreach (var alb2 in mapModel.alb2)
            {
                alb2Offsets.Add((int)stream.Position);
                WriteAlb2(stream, alb2);
            }

            var endAlb2Offset = Helpers.Align((int)stream.Position, 4);

            stream.Position = mapHeader.Offset1;
            foreach (var alb2Offset in alb2Offsets)
            {
                stream.Write(alb2Offset);
            }
            stream.Position = endAlb2Offset;

            mapHeader.Offset2 = endAlb2Offset;
            stream.Write(endAlb2Offset + 4 + mapModel.unknownTable.Length * 4);
            stream.Write(mapModel.unknownTable);
            WriteAlb2(stream, mapModel.alb1t2);

            stream.AlignPosition(0x10);

            var dmaChainVifOffsets = new List <int>();

            foreach (var dmaChainMap in mapModel.VifPackets)
            {
                var vifPacketIndex = 0;
                dmaChainVifOffsets.Add((int)stream.Position);

                foreach (var packetCount in dmaChainMap.DmaPerVif)
                {
                    BinaryMapping.WriteObject(stream, new DmaTag
                    {
                        Qwc     = packetCount,
                        Address = 0,
                        TagId   = packetCount > 0 ? 1 : 6,
                        Irq     = false,
                    });

                    var packetLength = packetCount * 0x10 + 8;
                    stream.Write(dmaChainMap.VifPacket, vifPacketIndex, packetLength);

                    vifPacketIndex += packetLength;
                }
            }

            stream.AlignPosition(0x80);
            stream.SetLength(stream.Position);

            stream.Position = dmaChainMapDescriptorOffset;
            for (var i = 0; i < mapModel.VifPackets.Count; i++)
            {
                var dmaChainMap = mapModel.VifPackets[i];
                BinaryMapping.WriteObject(stream, new DmaChainMap
                {
                    VifOffset    = dmaChainVifOffsets[i],
                    TextureIndex = dmaChainMap.TextureId,
                    Unk08        = dmaChainMap.Unk08,
                    Unk0c        = dmaChainMap.Unk0c
                });
            }

            stream.Position = 0;
            BinaryMapping.WriteObject(stream, mapHeader);
        }
Beispiel #2
0
        private static void WriteAsMap(Stream stream, M4 mapModel)
        {
            var mapHeader = new SubModelMapHeader
            {
                Type             = Map,
                DmaChainMapCount = mapModel.VifPackets.Count,

                Unk04      = mapModel.unk04,
                Unk08      = mapModel.unk08,
                NextOffset = mapModel.nextOffset,
                va4        = mapModel.va4,
                CountVifPacketRenderingGroup = Convert.ToInt16(mapModel.vifPacketRenderingGroup.Count),
            };

            BinaryMapping.WriteObject(stream, mapHeader);

            var dmaChainMapDescriptorOffset = (int)stream.Position;

            stream.Position += mapModel.VifPackets.Count * 0x10;

            mapHeader.OffsetVifPacketRenderingGroup = (int)stream.Position;
            stream.Position += mapModel.vifPacketRenderingGroup.Count * 4;
            var groupOffsets = new List <int>();

            foreach (var group in mapModel.vifPacketRenderingGroup)
            {
                groupOffsets.Add((int)stream.Position);
                WriteUInt16List(stream, group);
            }

            // capture remapTable offset here
            var remapTableOffsetToOffset = Helpers.Align((int)stream.Position, 4);

            // seek back and fill offsets
            stream.Position = mapHeader.OffsetVifPacketRenderingGroup;
            foreach (var offset in groupOffsets)
            {
                stream.Write(offset);
            }

            // write remapTable here
            stream.Position = remapTableOffsetToOffset;
            mapHeader.OffsetToOffsetDmaChainIndexRemapTable = remapTableOffsetToOffset;
            var remapTableOffset = remapTableOffsetToOffset + 4;

            stream.Write(remapTableOffset);
            WriteUInt16List(stream, mapModel.DmaChainIndexRemapTable);

            stream.AlignPosition(0x10);

            var dmaChainVifOffsets = new List <int>();

            foreach (var dmaChainMap in mapModel.VifPackets)
            {
                var vifPacketIndex = 0;
                dmaChainVifOffsets.Add((int)stream.Position);

                foreach (var packetCount in dmaChainMap.DmaPerVif)
                {
                    BinaryMapping.WriteObject(stream, new DmaTag
                    {
                        Qwc     = packetCount,
                        Address = 0,
                        TagId   = packetCount > 0 ? 1 : 6,
                        Irq     = false,
                    });

                    var packetLength = packetCount * 0x10 + 8;
                    stream.Write(dmaChainMap.VifPacket, vifPacketIndex, packetLength);

                    vifPacketIndex += packetLength;
                }
            }

            stream.AlignPosition(0x80);
            stream.SetLength(stream.Position);

            stream.Position = dmaChainMapDescriptorOffset;
            for (var i = 0; i < mapModel.VifPackets.Count; i++)
            {
                var dmaChainMap = mapModel.VifPackets[i];
                BinaryMapping.WriteObject(stream, new DmaChainMap
                {
                    VifOffset    = dmaChainVifOffsets[i],
                    TextureIndex = dmaChainMap.TextureId,
                    Unk08        = dmaChainMap.Unk08,
                    Unk0a        = dmaChainMap.IsTransparentFlag,
                    Unk0c        = dmaChainMap.Unk0c
                });
            }

            stream.Position = 0;
            BinaryMapping.WriteObject(stream, mapHeader);
        }