Ejemplo n.º 1
0
        public override void Open(OpenFileDialog openFileDialog, bool export = false, bool useGTFSView = false)
        {
            openFileDialog.FileName = "";
            openFileDialog.Filter   = "All Hotel Dusk|*.anm;*.frm;*.wpf;*.bin;*.txt;*.dtx|"
                                      + "All Files (*.*)|*.*";

            DialogResult res = openFileDialog.ShowDialog();

            if (res == DialogResult.OK)
            {
                string[] filenameParts = openFileDialog.SafeFileName.Split('.');
                Array.Reverse(filenameParts);

                if (filenameParts[0].ToUpper() == "FRM")
                {
                    GTFS fs  = new GTFS(openFileDialog.FileName);
                    FRM  frm = new FRM(fs);

                    new FormImage(frm.bitmap).Show();
                }
                else if (filenameParts[0].ToUpper() == "ANM")
                {
                    GTFS fs  = new GTFS(openFileDialog.FileName);
                    ANM  anm = new ANM(fs);

                    new FormImageAnimated(anm.BitmapsBlended()).Show();
                }
                else if (filenameParts[0].ToUpper() == "WPF")
                {
                    WPF.Open(openFileDialog);
                }
                else if (filenameParts[0].ToUpper() == "WPFBIN" || filenameParts[0].ToUpper() == "BIN")
                {
                    GTFS fs = new GTFS(openFileDialog.FileName);

                    byte[] magic = GT.ReadBytes(fs, 4, false);
                    fs.Position = 0;
                    if (magic.SequenceEqual(LRIM.Magic))
                    {
                        LRIM lrim = new LRIM(fs);
                    }
                    else
                    {
                        WPFBIN wpfbin = new WPFBIN(fs);
                        new FormImage(wpfbin.bitmap).Show();
                    }
                }
                else if (filenameParts[0].ToUpper() == "DTX")
                {
                    GTFS   fs     = new GTFS(openFileDialog.FileName);
                    WPFBIN wpfbin = new WPFBIN(fs);
                    new FormImage(wpfbin.bitmap).Show();
                    //GTFS compressed = new GTFS(openFileDialog.FileName);
                    //GTFS decompressed = Decompress.ToGTFS(compressed);
                    //decompressed.WriteBytesToFile("GT-KH-DecompDTX.gtbin");
                }
                else if (filenameParts[0].ToUpper() == "TXT")
                {
                    GTFS compressed   = new GTFS(openFileDialog.FileName);
                    GTFS decompressed = Decompress.ToGTFS(compressed);
                    //decompressed.WriteBytesToFile("GT-KH-DecompTXT.gtbin");

                    byte[] test = GT.ReadBytes(decompressed, 4, false);
                    decompressed.Position = 0;

                    if (test[0] == 0 || test[1] == 0 || test[2] == 0 || test[3] == 3)
                    {
                        int total = GT.ReadInt32(decompressed, 4, false);
                        for (int i = 0; i < total; i++)
                        {
                            int offset = GT.ReadInt32(decompressed, 4, false);
                        }

                        long baseOffset = decompressed.Position;

                        string input = GT.ReadASCII(decompressed, (int)(decompressed.Length - 1 - baseOffset), false);
                        input = input.Replace((char)0x00, (char)0x20);

                        new FormText(input).Show();
                    }
                    else
                    {
                        string input = GT.ReadASCII(decompressed, decompressed.Length - 1, false);
                        input = input.Replace("\n", "\r\n");

                        new FormText(input).Show();
                    }
                }
                else
                {
                    MessageBox.Show("Unexpected file extension: " + filenameParts[0]);
                }
            }
        }
Ejemplo n.º 2
0
        public WPFBIN(GTFS fs)
        {
            int header = GT.ReadInt32(fs, 4, false);

            if (header == 0)
            {
                fs.Seek(16, SeekOrigin.Begin);
            }
            else if (header == 14302482)
            {
                //123DDA00
                fs.Seek(32, SeekOrigin.Begin);
            }
            else if (header == 31079698)
            {
                //123DDA01
                fs = Decompress.ToGTFS(fs);
                //fs.WriteBytesToFile("GT-KH-Decomp.gtbin");

                header = GT.ReadInt32(fs, 4, false);

                if (header == 0)
                {
                    fs.Seek(16, SeekOrigin.Begin);
                }
                else
                {
                    Console.WriteLine();
                }
            }
            else
            {
                throw new Exception();
            }

            bool flip = false;

            int height = GT.ReadUInt16(fs, 2, flip);
            int width  = GT.ReadUInt16(fs, 2, flip);

            int heightConfirm = GT.ReadUInt16(fs, 2, flip);
            int widthConfirm  = GT.ReadUInt16(fs, 2, flip);
            int four          = GT.ReadUInt16(fs, 2, flip);

            if (height != heightConfirm || width != widthConfirm)
            {
                throw new Exception();
            }

            //if (four != 4)
            //Console.WriteLine("Wasn't 4, may be a problem?");

            int paletteLen = GT.ReadUInt16(fs, 2, flip);
            int thirtytwo  = GT.ReadUInt16(fs, 4, flip);

            if (thirtytwo != 32)
            {
                throw new Exception();
            }

            int headerLen = (int)fs.Position;

            paletteLen = paletteLen * 2;

            long offsetStart = headerLen + paletteLen; //560
            long offsetLast;

            fs.Position = offsetStart;

            if (width <= 0 || height <= 0)
            {
                throw new Exception();
            }

            bitmap = new Bitmap(width, height);
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int look = fs.ReadByte();
                    offsetLast = fs.Position;

                    fs.Seek(look * 2 + headerLen, SeekOrigin.Begin); //+48 for header
                    byte left  = (byte)fs.ReadByte();
                    byte right = (byte)fs.ReadByte();
                    //ushort palette = (ushort)(left | right << 8);
                    ushort palette = (ushort)(right | left << 8);

                    bitmap.SetPixel(x, height - y - 1, FRM.Palette2Color(palette));

                    //bmp.SetPixel(x, y, Color.FromArgb(look, look, look));

                    fs.Seek(offsetLast, SeekOrigin.Begin);
                }
            }
        }