Exemplo n.º 1
0
        /*
         * Reads a db file from stream, using the version information
         * contained in the header read from it.
         */
        public DBFile Decode(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            reader.BaseStream.Position = 0;
            DBFileHeader    header = readHeader(reader);
            List <TypeInfo> infos  = DBTypeMap.GetVersionedInfos(typeName, header.Version);

            if (infos.Count == 0)
            {
                infos.AddRange(DBTypeMap.GetAllInfos(typeName));
            }
            foreach (TypeInfo realInfo in infos)
            {
                try
                {
#if DEBUG
                    Console.WriteLine("Parsing version {1} with info {0}", string.Join(",", realInfo.Fields), header.Version);
#endif
                    DBFile result = ReadFile(reader, header, realInfo);
                    return(result);
                }
                catch (Exception) { }
            }
            return(null);
            // throw new DBFileNotSupportedException(string.Format("No applicable type definition found"));
        }
Exemplo n.º 2
0
        /*
         * Query if given packed file can be decoded.
         * Is not entirely reliable because it only reads the header and checks if a
         * type definition is available for the given GUID and/or type name and version.
         * The actual decode tries out all available type infos for that type name
         * but that is less efficient because it has to read the whole file at least once
         * if successful.
         */
        public static bool CanDecode(PackedFile packedFile, out string display)
        {
            bool   result = true;
            string key    = DBFile.Typename(packedFile.FullPath);

            if (DBTypeMap.IsSupported(key))
            {
                try
                {
                    DBFileHeader header     = PackedFileDbCodec.readHeader(packedFile);
                    int          maxVersion = DBTypeMap.MaxVersion(key);
                    if (maxVersion != 0 && header.Version > maxVersion)
                    {
                        display = string.Format("{0}: needs {1}, has {2}", key, header.Version, DBTypeMap.MaxVersion(key));
                        result  = false;
                    }
                    else
                    {
                        display = string.Format("Version: {0}", header.Version);
                    }
                }
                catch (Exception x)
                {
                    display = string.Format("{0}: {1}", key, x.Message);
                }
            }
            else
            {
                display = string.Format("{0}: no definition available", key);
                result  = false;
            }
            return(result);
        }
Exemplo n.º 3
0
        private static PackFile currentPackFile;        // Full pack file full of tables

        static void Main(string[] args)
        {
            Console.Out.WriteLine("--- BASIC AS F**K PACK FILE EDITOR ---");
            Console.Out.WriteLine("Loading file from path: " + FILES_CURRENT_DIR);

            // Load pack file from system into memory
            var codec = new PackFileCodec();

            currentPackFile = codec.Open(PACK_FILE);

            DBTypeMap.InitializeAllTypeInfos(FILES_CURRENT_DIR);



            // Get datatable for buildings_units_allowed_tables ->> template_data__core
            DataTable landUnitsTable = GetDataTable("land_units_table");



            // Save the currently edited pack file back out to system
            SaveAsFile("custom_unit.pack");
        }