Ejemplo n.º 1
0
        public Sprite(DatFileEntry entry, Color[] palette)
        {
            Entry = entry;

            int i = 0;

            NumFrames = entry.Data[i++];
            Frames    = new Bitmap[NumFrames];

            for (int frame = 0; frame < NumFrames; frame++)
            {
                int width  = entry.Data[i++];
                int height = entry.Data[i++];

                Frames[frame] = new Bitmap(width, height);

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        Color color = palette[entry.Data[i++]];
                        Frames[frame].SetPixel(x, y, color);
                    }
                }
            }

            Ready = true;
        }
Ejemplo n.º 2
0
        public bool Unpack()
        {
            if (!File.Exists(path))
            {
                Error = "File not found!";
                return(false);
            }

            Files = new List <DatFileEntry>();

            byte[] data = File.ReadAllBytes(path);

            int numEntries = BitConverter.ToUInt16(data, 0);
            int offset     = 2;

            Log = "Num entries: " + numEntries.ToString() + Environment.NewLine;

            for (int i = 0; i < numEntries; i++)
            {
                DatFileEntry entry = new DatFileEntry();

                entry.ID = i;

                entry.Size = BitConverter.ToInt32(data, offset);
                offset    += 4;

                entry.Modified = BitConverter.ToInt32(data, offset);
                offset        += 4;

                entry.Offset = BitConverter.ToInt32(data, offset);
                offset      += 4;

                entry.Filename = ""; // 13 chars, null-terminated

                int j;
                for (j = 0; j < 13; j++)
                {
                    if (data[offset + j] == 0)
                    {
                        entry.Filename = Encoding.UTF8.GetString(data, offset, j);
                        break;
                    }
                }
                offset += 13;

                entry.Data = data.SubArray(entry.Offset, entry.Size);

                Files.Add(entry);
                Log += entry.ToString() + Environment.NewLine;
            }

            return(true);
        }
Ejemplo n.º 3
0
        public Map(DatFileEntry entry)
        {
            Entry = entry;

            int i = 0;

            Width  = entry.Data[i];
            i     += 2;
            Height = entry.Data[i];
            i     += 2;

            loadPalette();

            // load cells
            int numCells = Width * Height;

            Cells = new MapCell[numCells];

            for (int j = 0; j < numCells; j++)
            {
                MapCell cell = new MapCell();
                cell.TileID      = entry.Data[i] + entry.Data[i + 1] * 256;
                cell.ShootableID = entry.Data[i + 2];
                cell.EntityID    = entry.Data[i + 3];
                Cells[j]         = cell;
                i += 4;
            }

            // load tiles
            Tiles = new MapTile[512];

            for (int j = 0; j < 512; j++)
            {
                MapTile tile = new MapTile();
                if (!tile.Load(entry.Data.SubArray(i, 64), Palette))
                {
                    return;
                }

                Tiles[j] = tile;
                i       += 64;
            }

            loadPositions();
            loadPaletteRotation();

            Ready = true;
        }
Ejemplo n.º 4
0
        // not used (trying to do everything in memory)
        public bool WriteUnpackedFiles(string targetDir)
        {
            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }

            for (int i = 0; i < Files.Count; i++)
            {
                DatFileEntry file = Files[i];
                if (!file.Write(targetDir))
                {
                    Error = $"Failed to write file '{file.Filename}' to '{targetDir}'";
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
        public bool Load()
        {
            if (Ready)
            {
                return(true);
            }

            Archive = new DatFile(ArchiveFile);

            // unpack archive
            if (!Archive.Unpack())
            {
                Error = "Processing archive failed: " + Archive.Error;
                return(false);
            }

            // load frame pcx which contains the main game palette
            DatFileEntry framePcx = Archive.GetByName(PcxContainingMainPalette);

            if (framePcx == null)
            {
                Error = $"Unable to find '{PcxContainingMainPalette}'";
                return(false);
            }

            try
            {
                PcxFile pcx = framePcx.GetPicture();
                MainPalette    = (Color[])pcx.Palette.Clone();
                MainPalette[0] = Color.Transparent;
            }
            catch (Exception e)
            {
                Error = $"Failed to decode PCX image '{PcxContainingMainPalette}': {e.Message}";
                return(false);
            }

            Ready = true;
            return(true);
        }