示例#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
        public void Load(Stream Stream)
        {
            var BinaryReader = new BinaryReader(Stream);

            Stream.Position = 8;

            for (int n = 0; n < 32; n++)
            {
                var Part = ReadEntry(BinaryReader);
                if (Part.PartId >= 0)
                {
                    Part.Bitmap = BraveImage.DecodeImage(File.OpenRead(String.Format(@"{0}\{1}.CRP", PartsPath, Part.Name)));
                }
                Parts[Part.PartId] = Part;
            }

            if (BinaryReader.ReadInt32() != -1)
            {
                throw(new NotImplementedException());
            }

            Unk1   = BinaryReader.ReadByte();
            Width  = (int)BinaryReader.ReadInt16();
            Height = (int)BinaryReader.ReadInt16();

            Cells = new Cell[Width, Height];

            BinaryReader.ReadUInt32();

            for (int y = 0; y < Height; y++)
            {
                //Console.WriteLine("----------------");
                for (int x = 0; x < Width; x++)
                {
                    int V0 = BinaryReader.ReadSByte();
                    if (V0 != -1)
                    {
                        var PartId = BinaryReader.ReadSByte();
                        int ImageX = BinaryReader.ReadInt16();
                        int ImageY = BinaryReader.ReadInt16();
                        //Console.WriteLine("A:{0:X8} : {1}, {2}", PartId, ImageX, ImageY);
                        Cells[x, y].BackgroundLayer = new CellLayer(Parts[PartId], ImageX, ImageY);
                    }

                    int V1 = BinaryReader.ReadSByte();
                    if (V1 != -1)                     // FAKE! It checks memory (0042E1D3)
                    {
                        var PartId = BinaryReader.ReadSByte();
                        int ImageX = BinaryReader.ReadInt16();
                        int ImageY = BinaryReader.ReadInt16();
                        //Console.WriteLine("B:{0:X8} : {1}, {2}", PartId, ImageX, ImageY);
                        Cells[x, y].ObjectLayer = new CellLayer(Parts[PartId], ImageX, ImageY);
                    }

                    var V2 = BinaryReader.ReadByte();
                    var V3 = BinaryReader.ReadByte();

                    Cells[x, y].V0   = V0;
                    Cells[x, y].V1   = V1;
                    Cells[x, y].Info = V2;
                    Cells[x, y].V3   = V3;

                    //if (V2 != 0xFF && V2 != 0x00)
#if false
                    var ObjectLayer = Cells[x, y].ObjectLayer;
                    if (ObjectLayer.Part != null)
                    {
                        //if (V2 != 0x00)
                        {
                            Console.WriteLine("V2: ({0},{1}) : ({2},{3}) : {4}", x, y, x * 40, y * 40, V2);
                            if (ObjectLayer.Part != null)
                            {
                                Console.WriteLine(" ---> {0} : ({1},{2})", ObjectLayer.Part.Name, ObjectLayer.X, ObjectLayer.Y);
                                Console.WriteLine(" ---> {0},{1},{2},{3}", V0, V1, V2, V3);
                            }
                        }
                    }
                    //Console.WriteLine("{0}, {1}", V2, V3);
#endif
                }
            }

            Unk2 = (int)BinaryReader.ReadInt32();

            //Console.WriteLine(Stream.Position);
        }