示例#1
0
        static void Main(string[] args)
        {
            var GameDirectory = @"C:\Juegos\brave_s";

            if (args.Length == 0)
            {
                Console.Error.WriteLine("Must specify the game path");
            }
            else
            {
                GameDirectory = args[0];
            }

            var PartsDirectory = GameDirectory + @"\parts";

            Console.WriteLine("Images...");
            foreach (var FileIn in Directory.EnumerateFiles(PartsDirectory, "*.crp"))
            {
                //var FileOut = Path.GetDirectoryName(FileIn) + @"\" + Path.GetFileNameWithoutExtension(FileIn) + ".png";
                var FileOutU   = Path.GetDirectoryName(FileIn) + @"\" + Path.GetFileNameWithoutExtension(FileIn) + ".crp.u";
                var FileOutPng = Path.GetDirectoryName(FileIn) + @"\" + Path.GetFileNameWithoutExtension(FileIn) + ".png";
                Console.WriteLine("{0} -> {1}", FileIn, FileOutPng);
                if (!File.Exists(FileOutU))
                {
                    File.WriteAllBytes(FileOutU, Lz.DecodeStream(File.OpenRead(FileIn)));
                }
                if (!File.Exists(FileOutPng))
                {
                    BraveImage.DecodeImage(File.OpenRead(FileIn)).Save(FileOutPng);
                }
            }

#if true
            Console.WriteLine("Script...");
            foreach (var FileIn in Directory.EnumerateFiles(GameDirectory + @"\scenario", "*.dat"))
            {
                var FileOutU   = Path.GetDirectoryName(FileIn) + @"\" + Path.GetFileNameWithoutExtension(FileIn) + ".scr";
                var FileOutAsm = Path.GetDirectoryName(FileIn) + @"\" + Path.GetFileNameWithoutExtension(FileIn) + ".asm";
                Console.WriteLine("{0}...", FileIn);

                if (!File.Exists(FileOutU))
                {
                    var Bytes    = File.ReadAllBytes(FileIn);
                    var BytesOut = Decrypt.DecryptDataWithKey(Bytes, Decrypt.Key23);
                    File.WriteAllBytes(FileOutU, BytesOut);
                    Console.WriteLine("{0} -> {1}", FileIn, FileOutU);
                }

                if (!File.Exists(FileOutAsm))
                {
                    var Script = new Script(new MemoryStream(Decrypt.DecryptDataWithKey(File.ReadAllBytes(FileIn), Decrypt.Key23)));
                    File.WriteAllLines(FileOutAsm, Script.ParseAll().Select(Item => Item.ToString()));
                }
            }

            Console.WriteLine("Base...");
            foreach (var FileIn in Directory.EnumerateFiles(GameDirectory + @"\", "*.dat"))
            {
                var FileOut = Path.GetDirectoryName(FileIn) + @"\" + Path.GetFileNameWithoutExtension(FileIn) + ".scr";
                var Bytes   = File.ReadAllBytes(FileIn);
                if (!File.Exists(FileOut))
                {
                    var BytesOut = Decrypt.DecryptData(Bytes);
                    File.WriteAllBytes(FileOut, BytesOut);
                    Console.WriteLine("{0} -> {1}", FileIn, FileOut);
                }
            }

            Console.WriteLine("Saves...");
            foreach (var FileIn in Directory.EnumerateFiles(GameDirectory + @"\save", "*.sav"))
            {
                var FileOut = Path.GetDirectoryName(FileIn) + @"\" + Path.GetFileNameWithoutExtension(FileIn) + ".sav.u";
                var Bytes   = File.ReadAllBytes(FileIn);
                if (!File.Exists(FileOut))
                {
                    var BytesOut = Decrypt.DecryptData(Bytes);
                    File.WriteAllBytes(FileOut, BytesOut);
                    Console.WriteLine("{0} -> {1}", FileIn, FileOut);
                }
            }

            Console.WriteLine("Maps...");
            foreach (var FileIn in Directory.EnumerateFiles(GameDirectory + @"\map", "*.dat"))
            {
                var FileOut    = Path.GetDirectoryName(FileIn) + @"\" + Path.GetFileNameWithoutExtension(FileIn) + ".map";
                var FileOutPng = Path.GetDirectoryName(FileIn) + @"\" + Path.GetFileNameWithoutExtension(FileIn) + ".png";
                Console.WriteLine("{0} -> {1}", FileIn, FileOut);
                if (!File.Exists(FileOut))
                {
                    var Bytes    = File.ReadAllBytes(FileIn);
                    var BytesOut = Decrypt.DecryptData(Bytes);
                    File.WriteAllBytes(FileOut, BytesOut);
                }
                if (!File.Exists(FileOutPng))
                {
                    var Map = new Map(PartsDirectory, GameDirectory + @"\cgdb.dat");
                    Map.Load(new MemoryStream(File.ReadAllBytes(FileOut)));
                    Map.Render().Save(FileOutPng);
                }
            }

            Console.WriteLine("Sound...");
            {
                try { Directory.CreateDirectory(GameDirectory + @"\sound"); }
                catch { }
                var Audio = (new Audio(NumberOfChannels: 2)).Load(File.OpenRead(GameDirectory + @"\sound.pck"));
                foreach (var Entry in Audio.Entries)
                {
                    var FileOut = String.Format(@"{0}\sound\{1}.wav", GameDirectory, Entry.Name);
                    Console.WriteLine("{0}", FileOut);
                    if (!File.Exists(FileOut))
                    {
                        File.WriteAllBytes(FileOut, Entry.GetWave().ToArray());
                    }
                }
            }

            Console.WriteLine("Voices...");
            {
                var Audio = (new Audio(NumberOfChannels: 1)).Load(File.OpenRead(GameDirectory + @"\voice\voice.pck"));
                foreach (var Entry in Audio.Entries)
                {
                    var FileOut = String.Format(@"{0}\voice\{1}.wav", GameDirectory, Entry.Name);
                    Console.WriteLine("{0}", FileOut);
                    if (!File.Exists(FileOut))
                    {
                        File.WriteAllBytes(FileOut, Entry.GetWave().ToArray());
                    }
                }
            }
#endif
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_Stream"></param>
        /// <returns></returns>
        unsafe static public Bitmap DecodeImage(Stream _Stream)
        {
            var Stream       = new MemoryStream(Lz.DecodeStream(_Stream));
            var BinaryReader = new BinaryReader(Stream);

            var Magic = BinaryReader.ReadBytes(14);

            if (Encoding.ASCII.GetString(Magic) != "(C)CROWD ARPG\0")
            {
                throw (new InvalidDataException("Invalid file"));
            }

            var Key    = BinaryReader.ReadBytes(8);
            var Header = BinaryReader.ReadBytes(16);

            // STEP1
            for (int n = 0; n < 0x10; n++)
            {
                Header[n] = Decrypt.DecryptPrimitive(DecodeImageKey[n], Header[n]);
            }

            //printf("----------------\n");

            // STEP2
            for (int n = 0; n < 0x10; n++)
            {
                Header[n] = Decrypt.DecryptPrimitive(Header[n], Key[n % 8]);
            }

            var HeaderReader = new BinaryReader(new MemoryStream(Header));

            var Width  = HeaderReader.ReadInt32();
            var Height = HeaderReader.ReadInt32();
            var Skip   = HeaderReader.ReadInt32();

            Stream.Seek(Skip, SeekOrigin.Current);

            var Image = new Bitmap(Width, Height);
            //var ImageData = BinaryReader.ReadBytes(Width * Height * 2);


            var EncodedData = BinaryReader.ReadBytes(Width * Height * 2);

            fixed(byte *_EncodedDataPtr = EncodedData)
            {
                var EncodedDataPtr = (ushort *)_EncodedDataPtr;
                var BitmapData     = Image.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                var Base           = (byte *)BitmapData.Scan0;

                for (int y = 0; y < Height; y++)
                {
                    var Ptr = &Base[BitmapData.Stride * y];

                    for (int x = 0; x < Width; x++)
                    {
                        var PixelData = *EncodedDataPtr++;
                        var b         = (byte)ExtractScale(PixelData, 0, 5, 0xff);
                        var g         = (byte)ExtractScale(PixelData, 5, 6, 0xff);
                        var r         = (byte)ExtractScale(PixelData, 11, 5, 0xff);

                        //ff00ff

                        // FUCSIA -> Transparent
                        if ((r == 0xFF) && (g == 0x00) && (b == 0xFF))
                        {
                            Ptr[0] = 0;
                            Ptr[1] = 0;
                            Ptr[2] = 0;
                            Ptr[3] = 0x00;
                        }
                        else
                        {
                            Ptr[0] = b;
                            Ptr[1] = g;
                            Ptr[2] = r;
                            Ptr[3] = 0xFF;
                        }

                        Ptr += 4;
                        //Image.SetPixel(x, y, Color.FromArgb(0xFF, r, g, b));
                    }
                }

                Image.UnlockBits(BitmapData);
            }

            return(Image);
        }