예제 #1
0
        public static void pack_baa(string projectDir, jBAAProjectFile project, string fileName)
        {
            if (fileName == null)
            {
                fileName = project.originalFile;
            }

            var blockStrm  = File.OpenWrite(fileName);
            var blockWrite = new BeBinaryWriter(blockStrm);

            Console.WriteLine("Prewriting BAA header data");
            // Prewrite header data so it's length is absolute
            blockWrite.Write(libJAudio.Loaders.JA_BAALoader.BAA_Header);
            for (int i = 0; i < project.includes.Length; i++)
            {
                var w  = project.includes[i];
                var sz = baa_GetSectionHeaderInfo(w);
                blockWrite.Write(w.hash);
                for (int k = 0; k < sz.size; k++)
                {
                    blockWrite.Write((int)0x00);
                }
            }
            blockWrite.Write(libJAudio.Loaders.JA_BAALoader.BAA_Footer);
            blockWrite.Flush();
            var head_anchor = 4L; // Start past the AA_<
            var tail_anchor = blockWrite.BaseStream.Position;

            Console.WriteLine($"Header ends at 0x{tail_anchor:X}");
            Console.WriteLine($"-> Project has {project.includes.Length} includes.");
            Console.WriteLine("-> Building project...");
            for (int i = 0; i < project.includes.Length; i++)
            {
                var dep  = project.includes[i];                           // load include
                var data = File.ReadAllBytes($"{projectDir}/{dep.path}"); // read include data
                Console.WriteLine($"->\t{projectDir}/{dep.path}\tL:0x{data.Length:X} added.");
                var sPos = tail_anchor;                                   // set start pos to tail anchor
                blockWrite.Write(data);                                   // sprawl data into file
                while ((blockWrite.BaseStream.Position & 0xF) != 8)
                {
                    blockWrite.Write((byte)0x00);
                    blockWrite.Flush();
                }
                var ePos = blockWrite.BaseStream.Position;              // store end position
                tail_anchor = ePos;                                     // set tail anchor to end pos
                blockWrite.BaseStream.Position = head_anchor;           // jump to head anchor
                baa_PackSection((int)sPos, (int)ePos, dep, blockWrite); // write section header
                head_anchor = blockWrite.BaseStream.Position;           // update head anchor.
                blockWrite.BaseStream.Position = tail_anchor;           // reseek to tail anchor.
                // repeat :)
            }

            Console.WriteLine($"-> Flushing into {fileName}");
            blockWrite.Flush();
            blockStrm.Flush();
            blockWrite.Close();
            blockStrm.Close();
            Console.WriteLine("Done.");
        }
예제 #2
0
        public static void unpack_baa(JAIInitSection[] data, BeBinaryReader br, string projDir, string initName)
        {
            try
            {
                Directory.CreateDirectory(projDir);
                Directory.CreateDirectory(projDir + "/include");
            }
            catch (Exception e)
            {
                cmdarg.assert("Could not create project directory: {0}", e.Message);
            }

            var pFile = new jBAAProjectFile();

            pFile.originalFile = initName;
            pFile.projectName  = projDir;
            pFile.includes     = new jBAAIncludeRecord[data.Length];
            Console.WriteLine("Unpack BAA");
            var fileIndex = 0;

            for (int i = 0; i < data.Length; i++)
            {
                var cSect = data[i];
                var size  = baa_GetSectionSize(cSect, br); // load section size from function (because BAA omits data for a lot of this :) )
                br.BaseStream.Position = cSect.start;
                var sectionData = br.ReadBytes(size);
                var extension   = util.GetFileExtension(cSect);
                File.WriteAllBytes($"{projDir}/include/{fileIndex}{extension}", sectionData);
                Console.WriteLine($"->\tWrote {fileIndex}{extension}");
                pFile.includes[i] = new jBAAIncludeRecord()
                {
                    hash  = cSect.raw_header,
                    path  = $"include/{fileIndex}{extension}",
                    type  = cSect.type.ToString(),
                    uid   = cSect.number,
                    flags = cSect.flags,
                };

                fileIndex++;
            }
            var convertedData = JsonConvert.SerializeObject(pFile, Formatting.Indented);

            File.WriteAllText($"{projDir}/project.json", convertedData);
        }