Esempio n. 1
0
        private void SetFile(int key)
        {
            if (bigFileview.BigFileViewModel == null)
            {
                Log("no.");
                return;
            }

            BigFileFile file = bigFileview.BigFileViewModel.BigFile.FileMap[key];

            if (file != null)
            {
                //groupFile.Header = file.Name;
                //lblKey.Content = string.Format("{0:X8}", key);
                //lblPath.Content = file.FullFolderPath;
                //if (bigFileview.BigFileViewModel.BigFile is UnpackedBigFile)
                //{
                //    lblRenamed.Content = (bigFileview.BigFileViewModel.BigFile as UnpackedBigFile).RenamedMapping[key].FileName;
                //}
                bigFileview.BigFileFolderTreeComponent.SelectedFile = file;
            }
            else
            {
                Log("File key not found!");
            }
        }
Esempio n. 2
0
        static void CheckFiles()
        {
            Console.Write("File path: ");
            string path = Console.ReadLine();

            if (!File.Exists(path) && !Directory.Exists(path))
            {
                Environment.Exit(69);
            }

            LogManager.GlobalLogFlags = LogFlags.Error | LogFlags.Info;

            BigFile bigFile = BigFile.OpenBigFile(path);

            bigFile.LoadFromDisk();

            for (int i = 0; i < bigFile.FileMap.FilesList.Length; i++)
            {
                BigFileFile file = bigFile.FileMap.FilesList[i];

                if (file.FileInfo.Offset == -1)
                {
                    LogManager.GlobalLogFlags = LogFlags.All;
                    file.FileInfo.DebugLog(log);
                    LogManager.GlobalLogFlags = LogFlags.Error | LogFlags.Info;
                }
            }

            Console.ReadLine();
        }
        private int[] internal_ReadFileHeader(Stream stream, BigFileFile file, IOBuffers buffers, BigFileFlags flags = DEFAULT_FLAGS)
        {
            int fileSize = internal_ReadFileRaw(stream, file, buffers, flags);

            if (fileSize == -1)
            {
                return(new int[0]);
            }

            int referenceNum = BitConverter.ToInt32(buffers[fileSize], 0);

            if (referenceNum * 4 >= fileSize)
            {
                log.Error("referenceNum * 4 > fileSize\n{0}>{1}", referenceNum, fileSize);
                return(new int[0]);
            }

            int[] header = new int[referenceNum];

            for (int i = 0; i < referenceNum; i++)
            {
                header[i] = BitConverter.ToInt32(buffers[fileSize], (i * 4) + 4);
            }

            return(header);
        }
        private int internal_ReadFileData(Stream stream, BigFileFile file, IOBuffers buffers, BigFileFlags flags = DEFAULT_FLAGS)
        {
            int fileSize = internal_ReadFileRaw(stream, file, buffers, flags);

            if (fileSize == -1)
            {
                return(-1);
            }

            int referenceNum = BitConverter.ToInt32(buffers[fileSize], 0);

            if (referenceNum * 4 >= fileSize)
            {
                log.Error("referenceNum * 4 > fileSize\n{0}>{1}", referenceNum, fileSize);
                return(-1);
            }

            int dataSize = fileSize - (referenceNum + 1) * 4;

            byte[] dataBuffer = buffers[dataSize];
            byte[] fileBuffer = buffers[fileSize];

            for (int i = 0; i < dataSize; i++)
            {
                dataBuffer[i] = fileBuffer[i + (referenceNum + 1) * 4];
            }

            return(dataSize);
        }
Esempio n. 5
0
        public void ChangeDisplayedTextures()
        {
            List <BigFileFile> imports = new List <BigFileFile>();

            foreach (BigFileFile textureFile in textureMetadataFiles)
            {
                if (textureFile.ArchetypeAs <TextureMetadataFileArchetype>().Format == textureType)
                {
                    imports.Add(textureFile);
                }
            }

            if (ImportStart > imports.Count - 1)
            {
                Debug.LogErrorFormat("ImportStart larger than imports count ({0} > {1})", ImportStart, imports.Count);
                return;
            }

            if (ImportStart + ImportCount > imports.Count)
            {
                ImportCount = imports.Count - ImportStart;
            }

            sel = 0;
            fileNames.Clear();
            displayedFiles.Clear();
            for (int i = ImportStart; i < ImportStart + ImportCount; i++)
            {
                BigFileFile file = imports[i];
                fileNames.Add(file.Name);
                displayedFiles.Add(file);
            }
        }
Esempio n. 6
0
        public void LoadTextureFile()
        {
            if (Transparent)
            {
                testPlane.GetComponent <Renderer>().material.ChangeRenderMode(BlendMode.Transparent);
            }
            else
            {
                testPlane.GetComponent <Renderer>().material.ChangeRenderMode(BlendMode.Opaque);
            }

            loadedPayload?.Unload();

            BigFileFile curr = displayedFiles[sel];
            TextureMetadataFileArchetype arch = curr.ArchetypeAs <TextureMetadataFileArchetype>();

            loadedPayload = arch.Payload.File;
            List <BigFileFile> list = new List <BigFileFile>
            {
                loadedPayload
            };

            m_bigFile.FileLoader.LoadFiles(list);

            texture          = new Texture2D(arch.Width, arch.Height, ImportAs, false);
            texture.wrapMode = TextureWrapMode.Clamp;
            texture.LoadRawTextureData(arch.Payload.Data);
            texture.Apply();

            testPlane.GetComponent <Renderer>().material.mainTexture = texture;
            testPlane.transform.localScale = new Vector3(arch.Width / arch.Height, 1, 1);
            Camera.main.orthographicSize   = Mathf.Clamp(5 + (.37f * (testPlane.transform.localScale.x - 1)), 5, 100);
        }
 public override int[] ReadFileHeader(BigFileFile file, IOBuffers buffers, BigFileFlags flags)
 {
     int[] header;
     using (FileStream fs = File.OpenRead(packedBigFile.MetadataFileInfo.FullName))
     {
         header = internal_ReadFileHeader(fs, file, buffers, flags);
     }
     return(header);
 }
Esempio n. 8
0
        public static BigFileFileArchetype CreateArchetype(this BigFileFile file)
        {
            if (archetypes.ContainsKey(file.FileInfo.FileType))
            {
                return((BigFileFileArchetype)Activator.CreateInstance(archetypes[file.FileInfo.FileType].GetType()));
            }

            return(new DefaultFileArchetype());
        }
        public override int ReadFileData(BigFileFile file, IOBuffers buffers, BigFileFlags flags)
        {
            int size = -1;

            using (FileStream fs = File.OpenRead(packedBigFile.MetadataFileInfo.FullName))
            {
                size = internal_ReadFileData(fs, file, buffers, flags);
            }
            return(size);
        }
Esempio n. 10
0
        public override int[] ReadFileHeader(BigFileFile file, IOBuffers buffers, BigFileFlags flags)
        {
            string fileName = unpackedBigFile.Directory.FullName + "\\"
                              + BigFileConst.UNPACK_DIR
                              + unpackedBigFile.RenamedMapping[file.FileInfo.Key].FileName
                              + BigFileConst.UNPACKED_HEADER_FILE_EXTENSION;

            int fileSize = -1;

            byte[] buffer;
            using (FileStream fs = File.OpenRead(fileName))
            {
                fileSize = (int)fs.Length;
                buffer   = buffers[fileSize];
                fs.Read(buffer, 0, fileSize);
            }

            if (fileSize == 0)
            {
                return(new int[0]);
            }

            int referenceNum = BitConverter.ToInt32(buffer, 0);

            if (referenceNum * 4 + 4 > fileSize)
            {
                throw new Exception("referenceNum * 4 + 4 > fileSize");
            }

            if (referenceNum <= 0)
            {
                return(new int[0]);
            }

            int[] header = new int[referenceNum];
            for (int i = 1; i <= referenceNum; i++)
            {
                header[i - 1] = BitConverter.ToInt32(buffer, i * 4);
            }
            return(header);
        }
Esempio n. 11
0
        public int GetBytesSizeAndSeekToStartOfFileData(Stream stream, BigFileFile file, BigFileFlags flags = DEFAULT_FLAGS)
        {
            if (file.FileInfo.Offset == -1)
            {
                log.Error(string.Format("Can't seek to file: {0} (key:{1:X8}) because offset is -1!", file.Name, file.FileInfo.Key));
                return(-1);
            }

            int dataOffset = packedBigFile.FileUtil.CalculateDataOffset(ref packedBigFile.SegmentHeader, ref packedBigFile.FileHeader);

            stream.Seek((uint)dataOffset + (uint)(file.FileInfo.Offset * 8), SeekOrigin.Begin);

            int size = -1;

            if (file.FileInfo.ZIP == 0)
            {
                stream.Read(sizeBuffer, 0, 4);
                size = BitConverter.ToInt32(sizeBuffer, 0);
            }
            else
            {
                stream.Read(sizeBuffer, 0, 8); //4 bytes for on disk size, 4 bytes for decompressed size

                if ((flags & BigFileFlags.Decompress) != 0)
                {
                    size = BitConverter.ToInt32(sizeBuffer, 4);
                }
                else
                {
                    size = BitConverter.ToInt32(sizeBuffer, 0) - 4; //subtract 4 because yeti engine takes the decompressed size with the actual file data
                }
            }

            if (size == 0)
            {
                throw new Exception("wtf");
            }

            return(size);
        }
Esempio n. 12
0
        public override int ReadFileRaw(BigFileFile file, IOBuffers buffers, BigFileFlags flags)
        {
            int[] header     = ReadFileHeader(file, buffers, flags);
            int   dataSize   = ReadFileData(file, buffers, flags);
            int   headerSize = header.Length * 4 + 4;

            byte[] dataBuffer = buffers[dataSize];
            byte[] buffer     = buffers[dataSize + headerSize];
            for (int i = dataSize - 1; i >= 0; i--)
            {
                buffer[i + headerSize] = dataBuffer[i];
            }


            header.Length.ToByteArray(buffer, 0);
            for (int i = 0; i < header.Length; i++)
            {
                header[i].ToByteArray(buffer, i * 4 + 4);
            }

            return(dataSize + headerSize);
        }
Esempio n. 13
0
        public override int ReadFileData(BigFileFile file, IOBuffers buffers, BigFileFlags flags)
        {
            string fullFileName = unpackedBigFile.Directory.FullName
                                  + "\\" + BigFileConst.UNPACK_DIR
                                  + unpackedBigFile.RenamedMapping[file.FileInfo.Key].FileName;

            int size = -1;

            byte[] buffer = buffers[4];
            using (FileStream fs = File.OpenRead(fullFileName))
            {
                size   = (int)fs.Length;
                buffer = buffers[size];
                fs.Read(buffer, 0, size);
            }

            if (size == 0)
            {
                size = -1;
            }

            return(size);
        }
Esempio n. 14
0
        private int internal_ReadFileRaw(Stream stream, BigFileFile file, IOBuffers buffers, BigFileFlags flags = DEFAULT_FLAGS)
        {
            log.Debug("Reading file: " + file.Name);

            int bytesSize = GetBytesSizeAndSeekToStartOfFileData(stream, file, flags);

            if (bytesSize == -1)
            {
                log.Error("There was an error reading the file!");
                return(-1);
            }

            byte[] buffer = buffers[bytesSize];

            log.Debug(string.Format("    > [ZIP: {0}] [flags: {1}] [size: {2}]", file.FileInfo.ZIP, flags, bytesSize));

            if (file.FileInfo.ZIP == 0)
            {
                stream.Read(buffer, 0, bytesSize);
            }
            else
            {
                if ((flags & BigFileFlags.Decompress) != 0)
                {
                    using (ZlibStream zs = new ZlibStream(stream, Ionic.Zlib.CompressionMode.Decompress, true))
                    {
                        zs.Read(buffer, 0, bytesSize);
                    }
                }
                else
                {
                    stream.Read(buffer, 0, bytesSize);
                }
            }

            return(bytesSize);
        }
Esempio n. 15
0
 public abstract int[] ReadFileHeader(BigFileFile file, IOBuffers buffers, BigFileFlags flags);
Esempio n. 16
0
        static void CompareFiles()
        {
            LogManager.GlobalLogFlags = LogFlags.Error | LogFlags.Info;

            Console.Write("Bigfile 1: ");
            string path1 = Console.ReadLine();

            Console.Write("Bigfile 2: ");
            string path2 = Console.ReadLine();

            IOBuffers buffer1 = new IOBuffers();
            IOBuffers buffer2 = new IOBuffers();

            Console.Write("File key: ");
            int key = 0;

            key = Convert.ToInt32(Console.ReadLine(), 16);
            if (key == 0)
            {
                Environment.Exit(420);
            }

            BigFile file1 = BigFile.OpenBigFile(path1);
            BigFile file2 = BigFile.OpenBigFile(path2);

            if (file1 == null)
            {
                Console.WriteLine("file 1 null");
                Console.ReadLine();
                Environment.Exit(911);
            }
            if (file2 == null)
            {
                Console.WriteLine("file 2 null");
                Console.ReadLine();
                Environment.Exit(911);
            }

            file1.LoadFromDisk();
            Console.Write("Press enter...");
            Console.ReadLine();
            file2.LoadFromDisk();
            Console.Write("Press enter...");
            Console.ReadLine();

            BigFileFile bigFileFile1 = file1.FileMap[key];
            BigFileFile bigFileFile2 = file2.FileMap[key];

            int[] header1 = file1.FileReader.ReadFileHeader(bigFileFile1, buffer1, file1.FileReader.DefaultFlags);
            int[] header2 = file2.FileReader.ReadFileHeader(bigFileFile2, buffer2, file2.FileReader.DefaultFlags);

            int size1 = file1.FileReader.ReadFileRaw(bigFileFile1, buffer1, file1.FileReader.DefaultFlags);
            int size2 = file2.FileReader.ReadFileRaw(bigFileFile2, buffer2, file2.FileReader.DefaultFlags);

            int chksum1 = 0;
            int chksum2 = 0;

            for (int i = 0; i < size1; i++)
            {
                chksum1 += buffer1[size1][i];
            }
            for (int i = 0; i < size2; i++)
            {
                chksum2 += buffer2[size2][i];
            }

            Console.Clear();

            Console.WriteLine("Size 1: " + size1);
            Console.WriteLine("Checksum 1: " + chksum1);
            Console.WriteLine("Size 2: " + size2);
            Console.WriteLine("Checksum 2: " + chksum2);

            Console.Write("Header 1, length: {0} : ", header1.Length);
            for (int i = 0; i < header1.Length; i++)
            {
                Console.Write("{0:X8} ", header1[i]);
            }
            Console.Write("\nHeader 2, length: {0} : ", header2.Length);
            for (int i = 0; i < header2.Length; i++)
            {
                Console.Write("{0:X8} ", header2[i]);
            }

            Console.WriteLine("");

            LogManager.GlobalLogFlags = LogFlags.All;

            bigFileFile1.FileInfo.DebugLog(log);
            bigFileFile2.FileInfo.DebugLog(log);


            Console.ReadLine();
        }
Esempio n. 17
0
 public abstract int ReadFileData(BigFileFile file, IOBuffers buffers, BigFileFlags flags);