Exemplo n.º 1
0
        public MapChunkHeader(byte[] data)
        {
            using (MemoryStream ms = new MemoryStream(data))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Flags               = (MapChunkFlags)br.ReadUInt32();
                    this.MapIndexX           = br.ReadUInt32();
                    this.MapIndexY           = br.ReadUInt32();
                    this.TextureLayerCount   = br.ReadUInt32();
                    this.ModelReferenceCount = br.ReadUInt32();

                    if (this.Flags.HasFlag(MapChunkFlags.UsesHighResHoles))
                    {
                        this.HighResHoles = br.ReadUInt64();
                    }

                    this.HeightmapOffset       = br.ReadUInt32();
                    this.VertexNormalOffset    = br.ReadUInt32();
                    this.TextureLayersOffset   = br.ReadUInt32();
                    this.ModelReferencesOffset = br.ReadUInt32();
                    this.AlphaMapsOffset       = br.ReadUInt32();
                    this.AlphaMapsSize         = br.ReadUInt32();
                    this.BakedShadowsOffset    = br.ReadUInt32();
                    this.BakedShadowsSize      = br.ReadUInt32();

                    this.AreaID = br.ReadUInt32();
                    this.WorldModelObjectReferenceCount = br.ReadUInt32();

                    // TODO: Turn into bitmapped boolean field
                    if (!this.Flags.HasFlag(MapChunkFlags.UsesHighResHoles))
                    {
                        this.LowResHoles = br.ReadUInt16();
                    }

                    this.Unknown = br.ReadUInt16();

                    // TODO: This is a set of 8 by 8 2-bit integers. Shift and read into a byte array.
                    this.LowResTextureMap = br.ReadUInt16();

                    this.PredTex        = br.ReadUInt32();
                    this.NoEffectDoodad = br.ReadUInt32();

                    this.SoundEmittersOffset = br.ReadUInt32();
                    this.SoundEmitterCount   = br.ReadUInt32();
                    this.LiquidOffset        = br.ReadUInt32();
                    this.LiquidSize          = br.ReadUInt32();

                    this.MapTilePosition = br.ReadVector3();

                    if (this.Flags.HasFlag(MapChunkFlags.HasVertexShading))
                    {
                        this.VertexShadingOffset = br.ReadUInt32();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public MapChunkHeader(byte[] data)
        {
            using (MemoryStream ms = new MemoryStream(data))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Flags = (MapChunkFlags)br.ReadUInt32();
                    this.MapIndexX = br.ReadUInt32();
                    this.MapIndexY = br.ReadUInt32();
                    this.TextureLayerCount = br.ReadUInt32();
                    this.ModelReferenceCount = br.ReadUInt32();

                    if (this.Flags.HasFlag(MapChunkFlags.UsesHighResHoles))
                    {
                        this.HighResHoles = br.ReadUInt64();
                    }

                    this.HeightmapOffset = br.ReadUInt32();
                    this.VertexNormalOffset = br.ReadUInt32();
                    this.TextureLayersOffset = br.ReadUInt32();
                    this.ModelReferencesOffset = br.ReadUInt32();
                    this.AlphaMapsOffset = br.ReadUInt32();
                    this.AlphaMapsSize = br.ReadUInt32();
                    this.BakedShadowsOffset = br.ReadUInt32();
                    this.BakedShadowsSize = br.ReadUInt32();

                    this.AreaID = br.ReadUInt32();
                    this.WorldModelObjectReferenceCount = br.ReadUInt32();

                    // TODO: Turn into bitmapped boolean field
                    if (!this.Flags.HasFlag(MapChunkFlags.UsesHighResHoles))
                    {
                        this.LowResHoles = br.ReadUInt16();
                    }

                    this.Unknown = br.ReadUInt16();

                    // TODO: This is a set of 8 by 8 2-bit integers. Shift and read into a byte array.
                    this.LowResTextureMap = br.ReadUInt16();

                    this.predTex = br.ReadUInt32();
                    this.noEffectDoodad = br.ReadUInt32();

                    this.SoundEmittersOffset = br.ReadUInt32();
                    this.SoundEmitterCount = br.ReadUInt32();
                    this.LiquidOffset = br.ReadUInt32();
                    this.LiquidSize = br.ReadUInt32();

                    this.MapTilePosition = br.ReadVector3f();

                    if (this.Flags.HasFlag(MapChunkFlags.HasVertexShading))
                    {
                        this.VertexShadingOffset = br.ReadUInt32();
                    }
                }
            }
        }
Exemplo n.º 3
0
        private List <byte> Read4BitAlphaMap(byte[] compressedAlphaMap, MapChunkFlags mapFlags)
        {
            var decompressedAlphaMap = new List <byte>();

            for (var y = 0; y < 64; y++)
            {
                for (var x = 0; x < 32; x++)
                {
                    if (mapFlags.HasFlag(MapChunkFlags.DoNotRepairAlphaMaps))
                    {
                        // Fill in normally
                        var alpha1 = (byte)(compressedAlphaMap[x + (y * 32)] & 0xf0);
                        var alpha2 = (byte)((compressedAlphaMap[x + (y * 32)] << 4) & 0xf0);

                        var normalizedAlpha1 = (byte)(alpha1 * 17);
                        var normalizedAlpha2 = (byte)(alpha2 * 17);

                        decompressedAlphaMap.Add(normalizedAlpha1);
                        decompressedAlphaMap.Add(normalizedAlpha2);
                    }
                    else
                    {
                        // Bottom row
                        if (y == 63)
                        {
                            var yminus = y - 1;

                            // Attempt to repair map on vertical axis
                            var alpha1 = (byte)(compressedAlphaMap[x + (yminus * 32)] & 0xf0);
                            var alpha2 = (byte)((compressedAlphaMap[x + 1 + (yminus * 32)] << 4) & 0xf0);

                            var normalizedAlpha1 = (byte)(alpha1 * 17);
                            var normalizedAlpha2 = (byte)(alpha2 * 17);

                            decompressedAlphaMap.Add(normalizedAlpha1);
                            decompressedAlphaMap.Add(normalizedAlpha2);
                        }
                        else if (x == 31)
                        {
                            var xminus = x - 1;

                            // Attempt to repair map on horizontal axis
                            var alpha           = (byte)(compressedAlphaMap[xminus + (y * 32)] << 4 & 0xf0);
                            var normalizedAlpha = (byte)(alpha * 17);

                            decompressedAlphaMap.Add(normalizedAlpha);
                        }
                        else
                        {
                            // Fill in normally
                            var alpha1 = (byte)(compressedAlphaMap[x + (y * 32)] & 0xf0);
                            var alpha2 = (byte)((compressedAlphaMap[x + (y * 32)] << 4) & 0xf0);

                            var normalizedAlpha1 = (byte)(alpha1 * 17);
                            var normalizedAlpha2 = (byte)(alpha2 * 17);

                            decompressedAlphaMap.Add(normalizedAlpha1);
                            decompressedAlphaMap.Add(normalizedAlpha2);
                        }
                    }
                }
            }

            return(decompressedAlphaMap);
        }
Exemplo n.º 4
0
 public List<byte> GetAlphaMap(uint MapOffset, TextureLayerFlags LayerFlags, MapChunkFlags MapFlags/*, TerrainTileFlags TileFlags*/)
 {
     return null;
 }
Exemplo n.º 5
0
        private List<byte> Read4BitAlphaMap(byte[] CompressedAlphaMap, MapChunkFlags MapFlags)
        {
            List<byte> DecompressedAlphaMap = new List<byte>();
            for (int y = 0; y < 64; y++)
            {
                for (int x = 0; x < 32; x++)
                {
                    if (MapFlags.HasFlag(MapChunkFlags.DoNotRepairAlphaMaps))
                    {
                        //fill in normally
                        byte alpha1 = (byte)((CompressedAlphaMap[x + y * 32]) & 0xf0);
                        byte alpha2 = (byte)((CompressedAlphaMap[x + y * 32] << 4) & 0xf0);

                        byte normalizedAlpha1 = (byte)(alpha1 * 17);
                        byte normalizedAlpha2 = (byte)(alpha2 * 17);

                        DecompressedAlphaMap.Add(normalizedAlpha1);
                        DecompressedAlphaMap.Add(normalizedAlpha2);
                    }
                    else
                    {
                        // Bottom row
                        if (y == 63)
                        {
                            int yminus = y - 1;
                            //attempt to repair map on vertical axis

                            byte alpha1 = (byte)((CompressedAlphaMap[x + yminus * 32]) & 0xf0);
                            byte alpha2 = (byte)((CompressedAlphaMap[x + 1 + yminus * 32] << 4) & 0xf0);

                            byte normalizedAlpha1 = (byte)(alpha1 * 17);
                            byte normalizedAlpha2 = (byte)(alpha2 * 17);

                            DecompressedAlphaMap.Add(normalizedAlpha1);
                            DecompressedAlphaMap.Add(normalizedAlpha2);
                        }
                        else if (x == 31)
                        {
                            int xminus = x - 1;

                            //attempt to repair map on horizontal axis
                            byte alpha = (byte)(CompressedAlphaMap[xminus + y * 32] << 4 & 0xf0);
                            byte normalizedAlpha = (byte)(alpha * 17);

                            DecompressedAlphaMap.Add(normalizedAlpha);
                        }
                        else
                        {
                            //fill in normally
                            byte alpha1 = (byte)((CompressedAlphaMap[x + y * 32]) & 0xf0);
                            byte alpha2 = (byte)((CompressedAlphaMap[x + y * 32] << 4) & 0xf0);

                            byte normalizedAlpha1 = (byte)(alpha1 * 17);
                            byte normalizedAlpha2 = (byte)(alpha2 * 17);

                            DecompressedAlphaMap.Add(normalizedAlpha1);
                            DecompressedAlphaMap.Add(normalizedAlpha2);
                        }
                    }
                }
            }

            return DecompressedAlphaMap;
        }
Exemplo n.º 6
0
 public IEnumerable <byte> GetAlphaMap(uint mapOffset, TextureLayerFlags layerFlags, MapChunkFlags mapFlags /*, TerrainTileFlags TileFlags*/)
 {
     return(null);
 }
Exemplo n.º 7
0
        private List <byte> Read4BitAlphaMap(byte[] compressedAlphaMap, MapChunkFlags mapFlags)
        {
            List <byte> decompressedAlphaMap = new List <byte>();

            for (int y = 0; y < 64; y++)
            {
                for (int x = 0; x < 32; x++)
                {
                    if (mapFlags.HasFlag(MapChunkFlags.DoNotRepairAlphaMaps))
                    {
                        //fill in normally
                        byte alpha1 = (byte)((compressedAlphaMap[x + y * 32]) & 0xf0);
                        byte alpha2 = (byte)((compressedAlphaMap[x + y * 32] << 4) & 0xf0);

                        byte normalizedAlpha1 = (byte)(alpha1 * 17);
                        byte normalizedAlpha2 = (byte)(alpha2 * 17);

                        decompressedAlphaMap.Add(normalizedAlpha1);
                        decompressedAlphaMap.Add(normalizedAlpha2);
                    }
                    else
                    {
                        // Bottom row
                        if (y == 63)
                        {
                            int yminus = y - 1;
                            //attempt to repair map on vertical axis

                            byte alpha1 = (byte)((compressedAlphaMap[x + yminus * 32]) & 0xf0);
                            byte alpha2 = (byte)((compressedAlphaMap[x + 1 + yminus * 32] << 4) & 0xf0);

                            byte normalizedAlpha1 = (byte)(alpha1 * 17);
                            byte normalizedAlpha2 = (byte)(alpha2 * 17);

                            decompressedAlphaMap.Add(normalizedAlpha1);
                            decompressedAlphaMap.Add(normalizedAlpha2);
                        }
                        else if (x == 31)
                        {
                            int xminus = x - 1;

                            //attempt to repair map on horizontal axis
                            byte alpha           = (byte)(compressedAlphaMap[xminus + y * 32] << 4 & 0xf0);
                            byte normalizedAlpha = (byte)(alpha * 17);

                            decompressedAlphaMap.Add(normalizedAlpha);
                        }
                        else
                        {
                            //fill in normally
                            byte alpha1 = (byte)((compressedAlphaMap[x + y * 32]) & 0xf0);
                            byte alpha2 = (byte)((compressedAlphaMap[x + y * 32] << 4) & 0xf0);

                            byte normalizedAlpha1 = (byte)(alpha1 * 17);
                            byte normalizedAlpha2 = (byte)(alpha2 * 17);

                            decompressedAlphaMap.Add(normalizedAlpha1);
                            decompressedAlphaMap.Add(normalizedAlpha2);
                        }
                    }
                }
            }

            return(decompressedAlphaMap);
        }
Exemplo n.º 8
0
 public List <byte> GetAlphaMap(uint MapOffset, TextureLayerFlags LayerFlags, MapChunkFlags MapFlags /*, TerrainTileFlags TileFlags*/)
 {
     return(null);
 }