Ejemplo n.º 1
0
Archivo: Pack.cs Proyecto: MetLob/tinke
        public static sFolder Unpack2(IPluginHost pluginHost, sFile file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file.path));
            sFolder unpack = new sFolder();
            unpack.files = new List<sFile>();

            // Read offset table
            uint num_files = br.ReadUInt32() / 4;
            br.BaseStream.Position -= 4;
            for (int i = 0; i < num_files; i++)
            {
                sFile currFile = new sFile();
                currFile.name = file.name + i.ToString();
                if (i == 0)
                    currFile.name += ".ncer";
                else if (i == 1)
                    currFile.name += ".nanr";
                else if (i == 2)
                    currFile.name += ".ncgr";
                currFile.offset = br.ReadUInt32();
                currFile.path = file.path;

                if (i + 1 == num_files) // Last file
                    currFile.size = (uint)br.BaseStream.Length - currFile.offset;
                else
                    currFile.size = br.ReadUInt32() - currFile.offset;
                br.BaseStream.Position -= 4;

                unpack.files.Add(currFile);
            }

            br.Close();
            return unpack;
        }
Ejemplo n.º 2
0
Archivo: Pack.cs Proyecto: MetLob/tinke
        public static sFolder Unpack(IPluginHost pluginHost, sFile file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file.path));
            sFolder unpack = new sFolder();
            unpack.files = new List<sFile>();

            // Read offset table
            uint currOffset = 0x00;
            ushort size = 0x00;
            for (int i = 0; ; i++)
            {
                currOffset = br.ReadUInt32();
                size = br.ReadUInt16(); // Size of the file, if it's compressed, size of the decompressed file
                br.ReadUInt16(); // Compress flag
                if (size == 0x00)
                    break;

                sFile currFile = new sFile();
                currFile.name = file.name + '_' + i.ToString() + ".dbin";
                currFile.offset = currOffset;
                currFile.path = file.path;

                currOffset = br.ReadUInt32();
                currFile.size = currOffset - currFile.offset;
                br.BaseStream.Position -= 4;

                unpack.files.Add(currFile);
            }

            br.Close();
            return unpack;
        }
Ejemplo n.º 3
0
Archivo: Main.cs Proyecto: MetLob/tinke
        public string Pack(ref sFolder unpacked, sFile file)
        {
            string fileOut = pluginHost.Get_TempFile();
            PAC.Pack(file.path, fileOut, ref unpacked);

            return fileOut;
        }
Ejemplo n.º 4
0
Archivo: PACK.cs Proyecto: MetLob/tinke
        public static sFolder Unpack(string file, IPluginHost pluginHost)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));
            sFolder unpacked = new sFolder();
            unpacked.files = new List<sFile>();

            uint num_files = (br.ReadUInt32() / 0x04) - 1;
            br.ReadUInt32(); // Pointer table
            for (int i = 0; i < num_files; i++)
            {
                uint startOffset = br.ReadUInt32();
                long currPos = br.BaseStream.Position;
                br.BaseStream.Position = startOffset;

                sFile newFile = new sFile();
                newFile.name = "File " + (i + 1).ToString("X") + ".bin";
                newFile.offset = startOffset + 4;
                newFile.path = file;
                newFile.size = br.ReadUInt32();

                br.BaseStream.Position = currPos;
                unpacked.files.Add(newFile);
            }

            br.Close();
            return unpacked;
        }
Ejemplo n.º 5
0
        public static sFolder Unpack(sFile tableFile, string dataFile)
        {
            FileStream fs = new FileStream(tableFile.path, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            sFolder unpacked = new sFolder();
            unpacked.files = new List<sFile>();

            uint numFiles = br.ReadUInt32();
            string baseName = Path.GetFileNameWithoutExtension(tableFile.name);

            for (int i = 0; i < numFiles; i++)
            {
                sFile file = new sFile();
                file.name = baseName + "_" + i.ToString() + ".bin";
                file.path = dataFile;
                file.offset = br.ReadUInt32();
                file.size = br.ReadUInt32();
                br.ReadUInt32();    // Decoded size

                unpacked.files.Add(file);
            }

            br = null;
            fs.Close();
            fs.Dispose();
            fs = null;

            return unpacked;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get a "sFolder" variable with all files and folders from the main folder path.
        /// </summary>
        /// <param name="folderPath">Folder to read</param>
        /// <param name="currFolder">Empty folder</param>
        /// <returns></returns>
        public static sFolder Recursive_GetDirectories(string folderPath, sFolder currFolder)
        {
            foreach (string file in Directory.GetFiles(folderPath))
            {
                sFile newFile = new sFile();
                newFile.name = Path.GetFileName(file);
                newFile.offset = 0x00;
                newFile.path = file;
                newFile.size = (uint)new FileInfo(file).Length;

                if (!(currFolder.files is List<sFile>))
                    currFolder.files = new List<sFile>();
                currFolder.files.Add(newFile);
            }

            foreach (string folder in Directory.GetDirectories(folderPath))
            {
                sFolder newFolder = new sFolder();
                newFolder.name = new DirectoryInfo(folder).Name;
                newFolder = Recursive_GetDirectories(folder, newFolder);

                if (!(currFolder.folders is List<sFolder>))
                    currFolder.folders = new List<sFolder>();
                currFolder.folders.Add(newFolder);
            }

            return currFolder;
        }
Ejemplo n.º 7
0
Archivo: DATA.cs Proyecto: MetLob/tinke
        public static sFolder Unpack(sFile file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file.path));
            sFolder unpack = new sFolder();
            unpack.files = new List<sFile>();

            br.BaseStream.Position = 0x10;  // Header

            const int num_files = 0x1246;
            for (int i = 0; i < num_files; i++)
            {
                sFile newFile = new sFile();
                newFile.name = "File_" + i.ToString() + '.';
                newFile.size = br.ReadUInt32();
                newFile.offset = br.ReadUInt32();
                newFile.path = file.path;

                long currPos = br.BaseStream.Position;
                br.BaseStream.Position = newFile.offset;
                string ext = new String(br.ReadChars(3));
                if (ext != "IMY" && ext != "MAP")
                    ext = "BIN";
                newFile.name += ext;
                br.BaseStream.Position = currPos;

                unpack.files.Add(newFile);
            }

            br.Close();
            return unpack;
        }
Ejemplo n.º 8
0
Archivo: FAT.cs Proyecto: MetLob/tinke
        public static void EscribirFAT(string salida, sFolder root, int nFiles, uint offsetFAT, uint offsetOverlay9,
            uint offsetOverlay7)
        {
            BinaryWriter bw = new BinaryWriter(new FileStream(salida, FileMode.Create));
            Console.Write("File Allocation Table (FAT)...");

            UInt32 offset = (uint)(offsetFAT + nFiles * 0x08 + 0x240 + 0x600); // Comienzo de la sección de archivos (FAT+banner)

            for (int i = 0; i < nFiles; i++)
            {
                sFile currFile = Search_File(i, root);
                if (currFile.name.StartsWith("overlay9"))
                {
                    bw.Write(offsetOverlay9);
                    offsetOverlay9 += currFile.size;
                    bw.Write(offsetOverlay9);
                    continue;
                }
                else if (currFile.name.StartsWith("overlay7"))
                {
                    bw.Write(offsetOverlay7);
                    offsetOverlay7 += currFile.size;
                    bw.Write(offsetOverlay7);
                    continue;
                }

                bw.Write(offset); // Offset de inicio del archivo
                offset += currFile.size;
                bw.Write(offset); // Offset de fin del archivo
            }

            bw.Flush();
            bw.Close();
            Console.WriteLine(Tools.Helper.GetTranslation("Messages", "S09"), new FileInfo(salida).Length);
        }
Ejemplo n.º 9
0
        public static sFolder Decrypt(sFile item, int blockSize, IPluginHost pluginHost)
        {
            sFolder unpacked = new sFolder();
            unpacked.files = new List<sFile>();

            byte[] data = File.ReadAllBytes(item.path);
            int numBlocks = data.Length / blockSize;

            for (int i = 0; i < numBlocks; i++)
            {
                byte[] block = new byte[blockSize];
                Array.Copy(data, i * blockSize, block, 0, blockSize);
                Decrypt(ref block);
                Array.Copy(block, 0, data, i * blockSize, blockSize);
            }

            string fileout = pluginHost.Get_TempFile();
            File.WriteAllBytes(fileout, data);

            sFile newItem = new sFile();
            newItem.path = fileout;
            newItem.offset = 0;
            newItem.name = item.name;
            newItem.size = (uint)data.Length;
            unpacked.files.Add(newItem);

            return unpacked;
        }
Ejemplo n.º 10
0
Archivo: DPK.cs Proyecto: MetLob/tinke
        public static string Pack(ref sFolder unpacked, string file, int id)
        {
            unpacked.files.Sort(SortFiles);

            string fileOut = file + "new";
            Unpack(file, DPK.pluginHost);
            byte[] fileData;

            uint numberOfFiles = (uint)unpacked.files.Count;

            MemoryStream packedFiles = new MemoryStream();
            MemoryStream headerData = new MemoryStream();
            MemoryStream packedFile = new MemoryStream();
            uint headerLength = 4 + 12 * numberOfFiles + Padding(numberOfFiles);
            uint offset = headerLength;

            for (int i = 0; i < numberOfFiles; i++)
            {
                byte[] subFile = new byte[unpacked.files[i].size];
                fileData = Helper.ReadFile(unpacked.files[i].path);
                for (uint j = 0, k = unpacked.files[i].offset; j < unpacked.files[i].size; j++, k++)
                {
                    try
                    {
                        subFile[j] = fileData[k];
                    }
                    catch { }
                }

                sFile newFile = unpacked.files[i];
                //newFile.name = unpacked.files[i].name.Remove(unpacked.files[i].name.LastIndexOf('.'));
                newFile.size = (uint)subFile.Length;
                newFile.offset = offset;
                newFile.path = fileOut;
                offset += newFile.size;
                unpacked.files[i] = newFile;
                packedFiles.Write(subFile, 0, subFile.Length);
            }

            BinaryWriter headerWriter = new BinaryWriter(headerData);
            headerWriter.Write(numberOfFiles);
            for (int i = 0; i < numberOfFiles; i++)
            {
                headerWriter.Write(uint.Parse(unpacked.files[i].name.Remove(unpacked.files[i].name.LastIndexOf('.'))));
                headerWriter.Write(unpacked.files[i].offset);
                headerWriter.Write(unpacked.files[i].size);
            }
            byte padding = 0xEE;
            for (uint i = Padding(numberOfFiles); i > 0; i--)
            {
                headerWriter.Write(padding);
            }

            headerData.WriteTo(packedFile);
            packedFiles.WriteTo(packedFile);

            Helper.WriteFile(fileOut, packedFile.ToArray(), 0, (int)packedFile.Length);

            return fileOut;
        }
Ejemplo n.º 11
0
Archivo: WMAP.cs Proyecto: MetLob/tinke
        static uint HEADER = 0x50414d57; // "WMAP"

        #endregion Fields

        #region Methods

        public static sFolder Unpack(string fileIn, string name)
        {
            name = Path.GetFileNameWithoutExtension(name);

            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));
            sFolder unpack = new sFolder();
            unpack.files = new List<sFile>();

            if (br.ReadUInt32() != HEADER)
            {
                br.Close();
                br = null;
                throw new FormatException("Invalid header!");
            }

            uint num_files = br.ReadUInt32();
            br.ReadUInt32();    // Unknown 1
            br.ReadUInt32();    // Unknown 2

            for (int i = 0; i < num_files; i++)
            {
                sFile cfile = new sFile();
                cfile.name = name + '_' + i.ToString() + ".bin";
                cfile.offset = br.ReadUInt32();
                cfile.size = br.ReadUInt32();
                cfile.path = fileIn;
                unpack.files.Add(cfile);
            }

            br.Close();
            br = null;
            return unpack;
        }
Ejemplo n.º 12
0
Archivo: PACK.cs Proyecto: MetLob/tinke
        public static void Pack(string output, ref sFolder unpackedFiles)
        {
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(output));

            // Write pointers
            bw.Write((uint)((unpackedFiles.files.Count + 1) * 4)); // Pointer table size
            uint currOffset = 0x00; // Pointer table offset
            bw.Write(currOffset);
            currOffset += (uint)(unpackedFiles.files.Count + 1) * 4 + 4;

            List<byte> buffer = new List<byte>();
            for (int i = 0; i < unpackedFiles.files.Count; i++)
            {
                BinaryReader br = new BinaryReader(File.OpenRead(unpackedFiles.files[i].path));
                br.BaseStream.Position = unpackedFiles.files[i].offset;
                buffer.AddRange(BitConverter.GetBytes((uint)unpackedFiles.files[i].size));
                buffer.AddRange(br.ReadBytes((int)unpackedFiles.files[i].size));
                br.Close();

                sFile newFile = unpackedFiles.files[i];
                newFile.offset = currOffset + 4;
                newFile.path = output;
                unpackedFiles.files[i] = newFile;

                bw.Write(currOffset);
                currOffset += unpackedFiles.files[i].size + 4;
            }

            // Write files
            bw.Write(buffer.ToArray());

            bw.Flush();
            bw.Close();
        }
Ejemplo n.º 13
0
Archivo: Main.cs Proyecto: MetLob/tinke
        public string Pack(ref sFolder unpacked, sFile file)
        {
            if (file.name.ToUpper().EndsWith(".DPK"))
                return DPK.Pack(ref unpacked, file.path, file.id);

            return null;
        }
Ejemplo n.º 14
0
Archivo: KPCN.cs Proyecto: MetLob/tinke
        public static sFolder Unpack(string file, string name)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));
            sFolder unpacked = new sFolder();
            unpacked.files = new List<sFile>();

            // Header
            char[] type = br.ReadChars(4);
            uint first_fileOffset = br.ReadUInt32();
            uint num_files = br.ReadUInt32();

            for (int i = 0; i < num_files; i++)
            {
                uint unknown = br.ReadUInt32();

                sFile newFile = new sFile();
                newFile.name = name + '_' + i.ToString() + ".bin";
                newFile.offset = br.ReadUInt32();
                newFile.size = br.ReadUInt32();
                newFile.path = file;

                unpacked.files.Add(newFile);
            }

            br.Close();
            return unpacked;
        }
Ejemplo n.º 15
0
Archivo: PCM.cs Proyecto: MetLob/tinke
        public static void Pack(string fileOut, sFolder unpack)
        {
            string tempFile = Path.GetTempFileName();
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(tempFile));

            BinaryReader br;
            uint f_size;
            byte[] name;

            // Write file data
            for (int i = 0; i < unpack.files.Count; i++)
            {
                f_size = unpack.files[i].size;
                f_size += 0x10 - (f_size % 0x10);

                // Write header
                bw.Write(0x20);
                bw.Write(f_size + 0x20);
                bw.Write(0x00);
                bw.Write(unpack.files[i].size);

                name = Encoding.ASCII.GetBytes(unpack.files[i].name);
                for (int j = 0; j < 0x10; j++)
                    if (j < name.Length)
                        bw.Write(name[j]);
                    else
                        bw.Write((byte)0x00);

                br = new BinaryReader(File.OpenRead(unpack.files[i].path));
                br.BaseStream.Position = unpack.files[i].offset;
                bw.Write(br.ReadBytes((int)unpack.files[i].size));
                br.Close();
                br = null;

                do
                    bw.Write((byte)0x00);
                while (bw.BaseStream.Position % 0x10 != 0);
            }

            f_size = (uint)bw.BaseStream.Length;
            bw.Flush();
            bw.Close();
            bw = null;

            // Write final file
            bw = new BinaryWriter(File.OpenWrite(fileOut));
            bw.Write(0x10);
            bw.Write(f_size + 0x10);
            bw.Write(unpack.files.Count);
            bw.Write(new char[] { 'L', 'P', 'C', 'K' });
            bw.Write(File.ReadAllBytes(tempFile));
            bw.Flush();
            bw.Close();
            bw = null;

            File.Delete(tempFile);
        }
Ejemplo n.º 16
0
Archivo: Main.cs Proyecto: MetLob/tinke
        public string Pack(ref sFolder unpacked, sFile file)
        {
            if (file.name.ToUpper().EndsWith(".LZS"))
                return LZS.Compress(unpacked.files[0].path, file.path, pluginHost);
            else if (file.name.ToUpper().EndsWith(".RESC"))
                return RESC.Pack(file.path, ref unpacked, pluginHost);

            return null;
        }
Ejemplo n.º 17
0
Archivo: PCK2.cs Proyecto: MetLob/tinke
        public static sFolder Read(string file, int id, IPluginHost pluginHost)
        {
            pluginHost.Decompress(file);
            string dec_file = pluginHost.Get_Files().files[0].path;

            BinaryReader br = new BinaryReader(File.OpenRead(dec_file));
            sFolder decompressed = new sFolder();
            sPCK2 pck2 = new sPCK2();
            pck2.file_id = id;

            // Read the header
            pck2.header.header_size = br.ReadUInt32();
            pck2.header.file_size = br.ReadUInt32();
            pck2.header.id = br.ReadChars(4);
            pck2.header.unknown = br.ReadUInt32();

            // Read all files
            decompressed.files = new List<sFile>();
            br.BaseStream.Position = pck2.header.header_size;
            while (br.BaseStream.Position != br.BaseStream.Length)
            {
                long pos = br.BaseStream.Position;
                sPCK2.File newFile = new sPCK2.File();
                newFile.header_size = br.ReadUInt32();
                newFile.size = br.ReadUInt32();
                newFile.unknown = br.ReadUInt32();
                newFile.data_size = br.ReadUInt32();

                newFile.name = "";
                char c = br.ReadChar();
                while (c != '\x0')
                {
                    newFile.name += c;
                    c = br.ReadChar();
                }

                br.BaseStream.Position = pos + newFile.header_size;
                newFile.data = br.ReadBytes((int)newFile.data_size);
                br.BaseStream.Position = pos + newFile.size;

                // Save the new file
                sFile savedFile = new sFile();
                savedFile.name = newFile.name;
                savedFile.offset = 0x00;
                savedFile.size = newFile.data_size;
                savedFile.path = Path.GetTempPath() + Path.DirectorySeparatorChar + newFile.name;
                File.WriteAllBytes(savedFile.path, newFile.data);
                decompressed.files.Add(savedFile);
            }

            br.Close();

            return decompressed;
        }
Ejemplo n.º 18
0
        public string Pack(ref sFolder unpacked, sFile file)
        {
            if (file.id >= 0x23 && file.id <= 0x93)
            {
                string output = pluginHost.Get_TempFile();
                BinaryWriter bw = new BinaryWriter(File.OpenWrite(output));

                // Unknown first 0x14 bytes
                BinaryReader br = new BinaryReader(File.OpenRead(file.path));
                bw.Write(br.ReadBytes(0x14));
                br.Close();
                br = null;

                // Write offset
                uint offset = 0xCC;
                List<byte> buffer = new List<byte>();
                for (int i = 0; i < 0x17; i++)
                {
                    bw.Write(offset);

                    // Write the file data to a temp buffer
                    sFile cfile = unpacked.files[i];
                    br = new BinaryReader(File.OpenRead(cfile.path));
                    br.BaseStream.Position = cfile.offset;
                    buffer.AddRange(br.ReadBytes((int)cfile.size));
                    br.Close();
                    br = null;

                    // Update file info
                    cfile.offset = offset;
                    cfile.path = output;
                    unpacked.files[i] = cfile;

                    offset += cfile.size;   // Update offset
                }
                // Write size
                for (int i = 0; i < 0x17; i++)
                    bw.Write(unpacked.files[i].size);
                bw.Flush();

                // Write data
                bw.Write(buffer.ToArray());

                // Close and return
                bw.Flush();
                bw.Close();
                bw = null;
                return output;
            }

            return null;
        }
Ejemplo n.º 19
0
Archivo: Main.cs Proyecto: MetLob/tinke
        public String Pack(ref sFolder unpacked, sFile file)
        {
            System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path));
            string type = new String(Encoding.ASCII.GetChars(br.ReadBytes(4)));
            br.Close();

            if (type == "NARC" || type == "CRAN")
                return new NARC(pluginHost).Pack(file, ref unpacked);
            else if (file.name.ToUpper().EndsWith("UTILITY.BIN"))
                return new Utility(pluginHost).Pack(file.path, ref unpacked);

            return null;
        }
Ejemplo n.º 20
0
Archivo: SPDL.cs Proyecto: MetLob/tinke
        public static void Pack(string file, string original, ref sFolder unpacked, IPluginHost pluginHost)
        {
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(file));
            BinaryReader br = new BinaryReader(File.OpenRead(original));

            // Copy header
            bw.Write(br.ReadBytes(0x50));

            // Write file info
            uint offset = 0x800;
            for (int i = 0; i < unpacked.files.Count; i++) {
                bw.Write(br.ReadBytes(0x08));
                bw.Write(unpacked.files[i].size);	br.BaseStream.Position += 4;
                bw.Write(offset);					br.BaseStream.Position += 4;

                offset += unpacked.files[i].size;
                if (offset % 0x800 != 0)
                    offset += 0x800 - (offset % 0x800);
            }

            br.Close();

            // Write files
            bw.Write(new byte[0x800 - bw.BaseStream.Position]);
            for (int i = 0; i < unpacked.files.Count; i++) {
                sFile cfile = unpacked.files[i];

                uint startOffset = (uint)bw.BaseStream.Position;

                // Write info
                BinaryReader brfile = new BinaryReader(File.OpenRead(cfile.path));
                brfile.BaseStream.Position = cfile.offset;
                bw.Write(brfile.ReadBytes((int)cfile.size));
                brfile.Close();

                // Write padding
                while (bw.BaseStream.Position % 0x800 != 0)
                    bw.Write((byte)0);

                // Update file info
                cfile.offset = startOffset;
                cfile.path = file;
                unpacked.files[i] = cfile;
            }

            // Update file size
            bw.BaseStream.Position = 0x08;
            bw.Write((uint)bw.BaseStream.Length);

            bw.Close();
        }
Ejemplo n.º 21
0
Archivo: Main.cs Proyecto: MetLob/tinke
        public string Pack(ref sFolder unpacked, sFile file)
        {
            if (file.name.ToUpper().EndsWith("ROMFILE.BIN"))
            {
                String packFile = pluginHost.Get_TempFile();
                if (File.Exists(packFile))
                    File.Delete(packFile);

                PACK.Pack(packFile, ref unpacked);
                return packFile;
            }

            return null;
        }
Ejemplo n.º 22
0
Archivo: LINK.cs Proyecto: MetLob/tinke
        public static void Pack(string fileIn, string fileOut, ref sFolder unpacked)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));
            br.BaseStream.Position = 0x08;
            uint block_size = br.ReadUInt32();
            br.Close();

            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut));

            bw.Write(new char[] { 'L', 'I', 'N', 'K' });
            bw.Write(unpacked.files.Count);
            bw.Write(block_size);
            bw.Write(0x00);

            unpacked.files.Sort(SortFiles);

            uint offset = block_size;
            List<byte> buffer = new List<byte>();
            for (int i = 0; i < unpacked.files.Count; i++)
            {
                br = new BinaryReader(File.OpenRead(unpacked.files[i].path));
                br.BaseStream.Position = unpacked.files[i].offset;
                buffer.AddRange(br.ReadBytes((int)unpacked.files[i].size));
                while (buffer.Count % block_size != 0)
                    buffer.Add(0x00);
                br.Close();

                bw.Write(offset / block_size);
                bw.Write(unpacked.files[i].size);

                sFile upFile = unpacked.files[i];
                upFile.offset = offset;
                upFile.path = fileOut;
                unpacked.files[i] = upFile;

                offset += unpacked.files[i].size;
                if (offset % block_size != 0)  // Padding
                    offset += (block_size - (offset % block_size));
            }
            byte[] rem = new byte[0];
            if (bw.BaseStream.Position % block_size != 0)
                rem = new byte[block_size - (bw.BaseStream.Position % block_size)];
            bw.Write(rem);
            bw.Flush();

            bw.Write(buffer.ToArray());
            bw.Flush();

            bw.Close();
        }
Ejemplo n.º 23
0
Archivo: PAC.cs Proyecto: MetLob/tinke
        public static sFolder Unpack(string file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));
            sFolder unpacked = new sFolder();
            unpacked.files = new System.Collections.Generic.List<sFile>();

            uint type = br.ReadUInt32();
            uint unknown = br.ReadUInt32();		// Maybe type of pack file
            uint num_files = br.ReadUInt32();

            uint offset = br.ReadUInt32();
            for (int i = 0; i < num_files; i++)
            {
                sFile newFile = new sFile();
                newFile.name = "File" + i.ToString();
                newFile.offset = offset;
                newFile.path = file;

                // Get the size using the next offset
                if (i + 1 != num_files)
                {
                    offset = br.ReadUInt32();
                    newFile.size = offset - newFile.offset;
                }
                else
                    newFile.size = (uint)(br.BaseStream.Length - newFile.offset);

                // Get the type of file
                br.BaseStream.Position = 0x2c + i * 4;
                uint file_type = br.ReadUInt32();
                br.BaseStream.Position = 0x0C + (i + 2) * 4;

                if (file_type == 0)
                    newFile.name += ".bmd0";
                else if (file_type == 1)
                    newFile.name += ".btx0";
                else if (file_type == 2)
                    newFile.name += ".btp0";
                else if (file_type == 7)
                    newFile.name += ".bta0";
                else
                    newFile.name += ".bin";

                unpacked.files.Add(newFile);
            }

            br.Close();
            return unpacked;
        }
Ejemplo n.º 24
0
Archivo: FAT.cs Proyecto: MetLob/tinke
        public static sFolder LeerFAT(string file, UInt32 offset, UInt32 size, sFolder root)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));
            br.BaseStream.Position = offset;

            for (int i = 0; i < size / 0x08; i++)
            {
                UInt32 currOffset = br.ReadUInt32();
                UInt32 currSize = br.ReadUInt32() - currOffset;
                Asignar_Archivo(i, currOffset, currSize, file, root);
            }

            br.Close();
            return root;
        }
Ejemplo n.º 25
0
        public static sFolder Get_DecompressedFiles(string txtFile, int num, IPluginHost pluginHost)
        {
            String[] files = File.ReadAllLines(txtFile);
            sFolder decompressed = new sFolder();
            decompressed.files = new List<sFile>();

            String currFolder = files[0].Substring((pluginHost.Get_TempFolder() + Path.DirectorySeparatorChar).Length);
            currFolder = currFolder.Substring(0, currFolder.IndexOf(Path.DirectorySeparatorChar));
            String relativePath = pluginHost.Get_TempFolder() + Path.DirectorySeparatorChar + currFolder;
            currFolder = "";

            decompressed = Recursive_GetDirectories(relativePath, decompressed);

            return decompressed;
        }
Ejemplo n.º 26
0
Archivo: KPCN.cs Proyecto: MetLob/tinke
        public static void Pack(string fileOut, string fileIn, ref sFolder unpacked, IPluginHost pluginHost)
        {
            // I need the original file to read all unknown values
            List<uint> unknowns = new List<uint>();
            #region Read unknowns values
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));
            br.BaseStream.Position += 8;
            uint num_files = br.ReadUInt32();
            for (int i = 0; i < num_files; i++)
            {
                unknowns.Add(br.ReadUInt32());
                br.BaseStream.Position += 8;
            }
            br.Close();
            #endregion

            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut));

            uint offset = (uint)unpacked.files.Count * 0x0C + 0x0C;
            bw.Write(new char[] { 'K', 'P', 'C', 'N' });
            bw.Write(offset);
            bw.Write((uint)unpacked.files.Count);

            for (int i = 0; i < unpacked.files.Count; i++)
            {
                sFile newFile = unpacked.files[i];
                newFile.offset = offset;
                newFile.path = fileOut;
                unpacked.files[i] = newFile;

                bw.Write(unknowns[i]);
                bw.Write(offset);
                bw.Write(unpacked.files[i].size);
                offset += unpacked.files[i].size;
            }

            for (int i = 0; i < unpacked.files.Count; i++)
            {
                br = new BinaryReader(File.OpenRead(unpacked.files[i].path));
                br.BaseStream.Position = unpacked.files[i].offset;

                bw.Write(br.ReadBytes((int)unpacked.files[i].size));
                br.Close();
            }

            bw.Flush();
            bw.Close();
        }
Ejemplo n.º 27
0
Archivo: RESC.cs Proyecto: MetLob/tinke
        public static String Pack(string original_file, ref sFolder unpacked, IPluginHost pluginHost)
        {
            String fileOut = pluginHost.Get_TempFolder() + Path.DirectorySeparatorChar + "new_" + Path.GetFileName(original_file);
            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut));
            BinaryReader br = new BinaryReader(File.OpenRead(original_file));

            // Write header
            bw.Write(br.ReadBytes(0x10));

            // Write pointer table
            uint offset = (uint)unpacked.files.Count * 0x30 + 0x10;
            uint[] offset_files = new uint[unpacked.files.Count];
            for (int i = 0; i < unpacked.files.Count; i++)
            {
                offset_files[i] = offset;
                bw.Write(br.ReadBytes(0x18));   // File name and extension
                bw.Write(unpacked.files[i].size);
                bw.Write(offset);
                offset += unpacked.files[i].size;

                br.BaseStream.Seek(8, SeekOrigin.Current);
                bw.Write(br.ReadBytes(0x10));   // Unknown values
            }
            bw.Flush();
            br.Close();

            // Write file data
            for (int i = 0; i < unpacked.files.Count; i++)
            {
                br = new BinaryReader(File.OpenRead(unpacked.files[i].path));
                br.BaseStream.Position = unpacked.files[i].offset;

                bw.Write(br.ReadBytes((int)unpacked.files[i].size));
                bw.Flush();
                br.Close();

                sFile newFile = unpacked.files[i];
                newFile.offset = offset_files[i];
                newFile.path = fileOut;
                unpacked.files[i] = newFile;
            }
            bw.Flush();
            bw.Close();

            return fileOut;
        }
Ejemplo n.º 28
0
        public string Pack(ref sFolder unpacked, sFile file)
        {
            if (file.id != 0x14)
                return null;

            String fileOut = pluginHost.Get_TempFile();

            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut));

            bw.Write((ushort)0x0C); // Offset of file entries
            bw.Write((ushort)0x08); // Lenght of file entry
            bw.Write((uint)0x00);   // Always 0x00
            bw.Write((uint)unpacked.files.Count);

            // File entries
            uint offset = 0x00;
            uint[] offset_files = new uint[unpacked.files.Count];
            for (int i = 0; i < unpacked.files.Count; i++)
            {
                offset_files[i] = offset;
                bw.Write(offset);
                bw.Write(unpacked.files[i].size);

                offset += unpacked.files[i].size;
            }
            bw.Flush();

            // File data
            uint first_file_offset = (uint)unpacked.files.Count * 0x8 + 0xC;
            for (int i = 0; i < unpacked.files.Count; i++)
            {
                BinaryReader br = new BinaryReader(File.OpenRead(unpacked.files[i].path));
                br.BaseStream.Position = unpacked.files[i].offset;
                bw.Write(br.ReadBytes((int)unpacked.files[i].size));
                br.Close();
                bw.Flush();

                sFile newFile = unpacked.files[i];
                newFile.offset = offset_files[i] + first_file_offset;
                newFile.path = fileOut;
                unpacked.files[i] = newFile;
            }

            bw.Close();
            return fileOut;
        }
Ejemplo n.º 29
0
        public sFolder Create_TreeFolders(List<BTNF_MainEntry> entries, int idFolder, string nameFolder)
        {
            sFolder currFolder = new sFolder();

            currFolder.name = nameFolder;
            currFolder.id = (ushort)idFolder;
            currFolder.files = entries[idFolder & 0xFFF].files;

            if (entries[idFolder & 0xFFF].folders is List<sFolder>) // If there is folders inside.
            {
                currFolder.folders = new List<sFolder>();

                foreach (sFolder subFolder in entries[idFolder & 0xFFF].folders)
                    currFolder.folders.Add(Create_TreeFolders(entries, subFolder.id, subFolder.name));
            }

            return currFolder;
        }
Ejemplo n.º 30
0
Archivo: FNT.cs Proyecto: MetLob/tinke
        public static sFolder Jerarquizar_Carpetas(List<Estructuras.MainFNT> tables, int idFolder, string nameFolder)
        {
            sFolder currFolder = new sFolder();

            currFolder.name = nameFolder;
            currFolder.id = (ushort)idFolder;
            currFolder.files = tables[idFolder & 0xFFF].subTable.files;

            if (tables[idFolder & 0xFFF].subTable.folders is List<sFolder>) // Si tiene carpetas dentro.
               {
                currFolder.folders = new List<sFolder>();

                foreach (sFolder subFolder in tables[idFolder & 0xFFF].subTable.folders)
                    currFolder.folders.Add(Jerarquizar_Carpetas(tables, subFolder.id, subFolder.name));
               }

            return currFolder;
        }