示例#1
0
        /// <summary>
        /// Saves BigFile to a given location.
        /// </summary>
        /// <param name="filename">Filename.</param>
        public void Save(string filename = "bigfile.big")
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Console.WriteLine($"we'll need {TotalSize / 1024.0f / 1024.0f}MB for {Entries.Count} files:");

            byte[] final_big = new byte[TotalSize];

            using (BinaryWriterEx bw = new BinaryWriterEx(new MemoryStream(final_big)))
            {
                bw.Write((int)0);
                bw.Write(Entries.Count);

                bw.Jump(3 * 2048);

                foreach (BigEntry c in Entries)
                {
                    Console.Write(".");

                    int pos = (int)bw.BaseStream.Position;
                    c.Offset = pos / Meta.SectorSize;

                    bw.Write(c.Data);

                    bw.Jump(pos + c.SizePadded);
                }

                Console.WriteLine();

                bw.Jump(8);

                foreach (BigEntry c in Entries)
                {
                    bw.Write(c.Offset);
                    bw.Write(c.Size);
                }

                Console.WriteLine("Dumping to disk...");

                Helpers.WriteToFile(filename, final_big);
            }

            sw.Stop();

            Console.WriteLine($"BIG file created in {sw.Elapsed.TotalSeconds}");
        }
示例#2
0
        /// <summary>
        /// Writes VAG data to stream using binary writer.
        /// </summary>
        /// <param name="bw">BinaryWriterEx object.</param>
        public void Write(BinaryWriterEx bw)
        {
            //make sure magic string and version are correct
            magic   = "VAGp";
            version = 3;

            bw.Write(magic.ToCharArray());
            bw.WriteBig(version);
            bw.WriteBig(reserved);
            bw.WriteBig(dataSize);
            bw.WriteBig(sampleFreq);
            bw.WriteBig(unk1);
            bw.WriteBig(unk2);
            bw.WriteBig(unk3);

            int pos = (int)bw.BaseStream.Position;

            bw.Write(SampleName.ToCharArray());
            bw.Jump(pos + 16);

            foreach (var frame in Frames)
            {
                frame.Write(bw);
            }
        }
示例#3
0
        private void SaveLEV()
        {
            using (BinaryWriterEx bw = new BinaryWriterEx(File.OpenWrite(path)))
            {
                bw.Jump(4);

                scn.header.Write(bw);

                bw.Jump(scn.header.ptrRestartPts + 4);

                foreach (Pose pa in scn.restartPts)
                {
                    pa.Write(bw);
                }

                bw.Jump(scn.header.ptrInstances + 4);

                foreach (PickupHeader ph in scn.pickups)
                {
                    ph.Write(bw);
                }


                bw.Jump(scn.meshinfo.ptrVertexArray + 4);

                foreach (Vertex v in scn.verts)
                {
                    v.Write(bw);
                }


                bw.Jump(scn.meshinfo.ptrQuadBlockArray + 4);

                foreach (QuadBlock qb in scn.quads)
                {
                    qb.Write(bw);
                }

                bw.Jump(scn.header.ptrVcolAnim + 4);

                foreach (VertexAnim vc in scn.vertanims)
                {
                    vc.Write(bw);
                }

                bw.Jump(scn.meshinfo.ptrVisDataArray + 4);

                foreach (VisData v in scn.visdata)
                {
                    v.Write(bw);
                }

                bw.Jump(scn.header.ptrAiNav + 4);
                scn.nav.Write(bw);
            }
        }
示例#4
0
文件: LNG.cs 项目: rjayhub/CTR-tools
        /// <summary>
        /// Writes all entries to stream using binary writer.
        /// </summary>
        /// <param name="filename">BinaryWriterEx object.</param>
        public void Write(BinaryWriterEx bw)
        {
            List <string> dEntries = new List <string>();

            foreach (var entry in Entries)
            {
                if (!dEntries.Contains(entry))
                {
                    dEntries.Add(entry);
                }
            }

            var list = new Dictionary <string, int>();

            bw.Write((int)Entries.Count());
            bw.Seek(4); //get back here when we know the offset

            foreach (string entry in dEntries)
            {
                Console.WriteLine(entry);
                list.Add(entry, (int)bw.BaseStream.Position);
                bw.Write(Encoding.Default.GetBytes(entry.Replace("|", "" + (char)0xD)));
                bw.Write((byte)0);
            }

            bw.Jump(((bw.BaseStream.Position / 4) + 1) * 4);

            int lastoff = (int)bw.BaseStream.Position;

            foreach (var entry in Entries)
            {
                bw.Write(list[entry]);
            }

            bw.Write("MISSING MSG\0".ToCharArray());

            bw.Jump(4);
            bw.Write(lastoff);
        }
示例#5
0
        /// <summary>
        /// Exports decompressed WAV sound.
        /// </summary>
        /// <param name="filename">Target WAV filename.</param>
        public void ExportWav(string filename)
        {
            using (BinaryWriterEx wav = new BinaryWriterEx(File.Create(filename)))
            {
                wav.Write("RIFF".ToCharArray());
                wav.Write((int)0);
                wav.Write("WAVE".ToCharArray());
                wav.Write("fmt ".ToCharArray());
                wav.Write((int)16);
                wav.Write((short)1);
                wav.Write((short)1);
                wav.Write(sampleFreq);
                wav.Write(sampleFreq * 2);
                wav.Write((short)2);
                wav.Write((short)16);
                wav.Write("data".ToCharArray());
                wav.Write((int)0);

                //every next frame uses these values from previous frame, hence passed as ref
                double s_1 = 0.0;
                double s_2 = 0.0;

                foreach (VagFrame frame in Frames)
                {
                    wav.Write(frame.GetRawData(ref s_1, ref s_2));
                }

                int streamSize = (int)wav.BaseStream.Position;

                wav.Jump(4);
                wav.Write(streamSize - 8);

                wav.Jump(40);
                wav.Write(streamSize - 44);
            }
        }
示例#6
0
        /// <summary>
        /// Writes CTR model in original CTR format.
        /// </summary>
        /// <param name="bw">BinaryWriterEx object.</param>
        /// <param name="mode">Write mode (writes wither header or data).</param>
        public void Write(BinaryWriterEx bw, CtrWriteMode mode)
        {
            int pos = 0;

            switch (mode)
            {
            case CtrWriteMode.Header:
                pos = (int)bw.BaseStream.Position;
                bw.Write(name.ToCharArray().Take(16).ToArray());
                bw.Jump(pos + 16);
                bw.Write(unk0);
                bw.Write(lodDistance);
                bw.Write(billboard);
                scale.Write(bw);
                bw.Write(ptrCmd);
                bw.Write(ptrVerts);
                bw.Write(ptrTex);
                bw.Write(ptrClut);
                bw.Write(unk3);
                bw.Write(numAnims);
                bw.Write(ptrAnims);
                bw.Write(unk4);

                break;

            case CtrWriteMode.Data:

                //write commands

                bw.Jump(ptrCmd + 4);

                bw.Write(cmdNum);

                foreach (var c in drawList)
                {
                    bw.Write(c.GetValue());
                }

                bw.Write(0xFFFFFFFF);


                //write texturelayouts

                if (tl.Count > 0)
                {
                    bw.Jump(ptrTex + 4);

                    pos = (int)bw.BaseStream.Position;

                    for (int i = 0; i < tl.Count; i++)
                    {
                        //CtrModel.ptrs.Add((int)bw.BaseStream.Position - 4);

                        UIntPtr ptr = (UIntPtr)(pos + 4 * tl.Count + i * 12);
                        bw.Write(ptr);
                    }

                    foreach (var t in tl)
                    {
                        t.Write(bw);
                    }
                }


                //write vertices

                bw.Jump(ptrVerts + 4);

                posOffset.Write(bw);

                bw.Seek(16);

                bw.Write(vrenderMode);

                Console.WriteLine(name);

                foreach (var x in vtx)
                {
                    x.Write(bw);
                    Console.WriteLine(x.X.ToString("X2") + x.Y.ToString("X2") + x.Z.ToString("X2"));
                }

                Console.WriteLine("---");


                //write clut

                bw.Jump(ptrClut + 4);

                foreach (var x in cols)
                {
                    x.W = 0;
                    x.Write(bw);
                    Console.WriteLine(x.X.ToString("X2") + x.Y.ToString("X2") + x.Z.ToString("X2") + x.W.ToString("X2"));
                }


                break;

            default: Helpers.Panic(this, "unknown mode"); break;
            }
        }