Beispiel #1
0
        public bool Load(string filePath)
        {
            filePath = filePath.ToUpper();

            // Load file
            if (!managedFile.Load(filePath, FileUsage.UseMemory, true))
            {
                return(false);
            }

            // Read file
            if (!Initialize())
            {
                return(false);
            }

            // Managed file is no longer needed
            managedFile.Close();


            return(true);
        }
        bool LoadSaveName(int save)
        {
            if (!saveGameDict.ContainsKey(save))
            {
                return(false);
            }

            FileProxy file = new FileProxy(Path.Combine(saveGameDict[save], SaveNameTxt), FileUsage.UseMemory, true);

            saveName = file.ReadCString(0, 0);
            file.Close();

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Load PAK file.
        /// </summary>
        /// <param name="filePath">Absolute path to PAK file.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath)
        {
            // Validate filename
            if (!filePath.EndsWith("CLIMATE.PAK", StringComparison.InvariantCultureIgnoreCase) &&
                !filePath.EndsWith("POLITIC.PAK", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            // Load file
            if (!managedFile.Load(filePath, FileUsage.UseMemory, true))
            {
                return(false);
            }

            // Expand each row of PAK file into buffer
            BinaryReader offsetReader = managedFile.GetReader(0);
            BinaryReader rowReader    = managedFile.GetReader();

            for (int row = 0; row < pakHeightValue; row++)
            {
                // Get offsets
                UInt32 offset    = offsetReader.ReadUInt32();
                int    bufferPos = pakWidthValue * row;
                rowReader.BaseStream.Position = offset;

                // Unroll PAK row into buffer
                int rowPos = 0;
                while (rowPos < pakWidthValue)
                {
                    // Get PakRun data
                    UInt16 count = rowReader.ReadUInt16();
                    Byte   value = rowReader.ReadByte();

                    // Do PakRun
                    for (int c = 0; c < count; c++)
                    {
                        pakExtractedBuffer[bufferPos + rowPos++] = value;
                    }
                }
            }

            // Managed file is no longer needed
            managedFile.Close();

            return(true);
        }
        /// <summary>
        /// Load PAK file.
        /// </summary>
        /// <param name="FilePath">Absolute path to PAK file.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string FilePath)
        {
            // Validate filename
            FilePath = FilePath.ToUpper();
            if (!FilePath.EndsWith("CLIMATE.PAK") && !FilePath.EndsWith("POLITIC.PAK"))
            {
                return(false);
            }

            // Load file
            if (!ManagedFile.Load(FilePath, FileUsage.UseMemory, true))
            {
                return(false);
            }

            // Expand each row of PAK file into buffer
            BinaryReader offsetReader = ManagedFile.GetReader(0);
            BinaryReader rowReader    = ManagedFile.GetReader();

            for (int row = 0; row < PakRowCountValue; row++)
            {
                // Get offsets
                UInt32 offset    = offsetReader.ReadUInt32();
                int    bufferPos = PakRowLengthValue * row;
                rowReader.BaseStream.Position = offset;

                // Unroll PAK row into buffer
                int rowPos = 0;
                while (rowPos < PakRowLengthValue)
                {
                    // Get PakRun data
                    UInt16 count = rowReader.ReadUInt16();
                    Byte   value = rowReader.ReadByte();

                    // Do PakRun
                    for (int c = 0; c < count; c++)
                    {
                        PakExtractedBuffer[bufferPos + rowPos++] = value;
                    }
                }
            }

            // Managed file is no longer needed
            ManagedFile.Close();

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Read file.
        /// </summary>
        /// <returns>True if succeeded, otherwise false.</returns>
        private bool Read()
        {
            //try
            //{
            // Step through file
            BinaryReader Reader = managedFile.GetReader();

            if (!ReadHeader(Reader))
            {
                return(false);
            }

            Numfiles = Reader.ReadInt32();

            var DataOffsets = new int[Numfiles];

            for (int row = 0; row < Numfiles; row++)
            {
                var offset = Reader.ReadInt32();
                Reader.BaseStream.Position += 4;
                DataOffsets[row]            = offset;
            }
            // DataOffsets[Numfiles] = (int)Reader.BaseStream.Length;

            imgRecord = new MCBitmap[Numfiles];

            this.ReadMinHeightWidth(Reader, DataOffsets);

            for (int row = 0; row < Numfiles; row++)
            {
                if (DataOffsets[row] == 0)
                {
                    InitEmptyBmp(row);
                    continue;
                }

                Reader.BaseStream.Position = DataOffsets[row];
                if (!ReadShpHeader(Reader))
                {
                    return(false);
                }

                var bmp = new MCBitmap();

                if (!ReadShpData(Reader, out bmp))
                {
                    InitEmptyBmp(row);
                    UnityEngine.Debug.Log("Error Reader Header");
                    continue;
                }


                bmp.Name = row.ToString();

                imgRecord[row] = bmp;
            }

            //} catch (Exception e)
            //{
            //    UnityEngine.Debug.Log(e.Message);
            //    managedFile.Close();
            //    return false;
            //}

            managedFile.Close();

            return(true);
        }