コード例 #1
0
ファイル: SHNFile.cs プロジェクト: Wicious/Spark-Editor
        /// <summary>
        /// Saves the file. The progress parameter is a way for us
        /// to report progress to the calling thread.
        /// </summary>
        /// <param name="progress"></param>
        public async Task Save(string filePath, IProgress<int> progress)
        {
            var stream = new MemoryStream();
            writer = new BinaryWriter(stream);

            writer.Write(DataHeader);
            writer.Write(RowCount);
            writer.Write(getDefaultRecordLength());
            writer.Write(ColumnCount);

            foreach (SHNColumn col in Columns)
            {
                if (col.ColumnName.Contains("UnkCol"))
                {
                    writer.Write(new byte[0x30]);
                }
                else
                {
                    writer.WriteString(col.ColumnName, 0x30);
                }

                if (col.SHNType == SHNType.UnknownLengthString)
                    writer.Write((uint)0x1A);
                else
                    writer.Write(getIDFromType(col.DataType));

                writer.Write(col.Length);
            }

            writeRows(new Progress<int>(p => progress.Report(p)));

            var length = stream.Length;
            var destinationArray = new byte[length];

            Array.Copy(stream.GetBuffer(), destinationArray, length);

            if (Encryption != null)
                Crypter.Crypt(Encryption, destinationArray, 0, destinationArray.Length);
            else
                Crypter.Crypt(destinationArray, 0, destinationArray.Length);

            writer.Close();
            writer = new BinaryWriter(File.Create(filePath));

            writer.Write(BaseHeader);
            writer.Write(destinationArray.Length + 0x24);
            writer.Write(destinationArray);
            writer.Close();

            FilePath = filePath;
        }
コード例 #2
0
ファイル: crTDX.cs プロジェクト: DevilboxGames/ToxicRagers
        public static byte[] Save(TDX tdx)
        {
            byte[] buffer;

            using (MemoryStream ms = new MemoryStream())
            using (BinaryWriter bw = new BinaryWriter(ms))
            {
                bw.Write(new byte[] { 0, 2 });

                bw.Write((short)tdx.MipMaps[0].Width);
                bw.Write((short)tdx.MipMaps[0].Height);
                bw.Write((short)tdx.MipMaps.Count);
                bw.Write((int)tdx.flags);
                bw.WriteString(tdx.ShortFormat);

                for (int i = 0; i < tdx.MipMaps.Count; i++) { bw.Write(tdx.MipMaps[i].Data); }

                bw.Flush();
                ms.Flush();

                buffer = ms.ToArray();
            }

            return buffer;
        }
コード例 #3
0
        private void SaveInner(BinaryWriter writer)
        {
            writer.Write(_achievements.Count);
            for (int i = 0; i < _achievements.Length; i++)
            {
                writer.WriteString(_achievements[i].Name);
                writer.Write(_achievements[i].Progression);

                object tag = _achievements[i].Tag;
                if (tag is IBinarySerializable) // ... i guess this is ok
                {
                    writer.Write(tag.Cast<IBinarySerializable>());
                }
            }
        }
コード例 #4
0
ファイル: ModelListFile.cs プロジェクト: Jiwan/Revise
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.Write((short)ModelFiles.Count);

            ModelFiles.ForEach(modelFile => {
                writer.WriteString(modelFile);
                writer.Write((byte)0);
            });

            writer.Write((short)TextureFiles.Count);

            TextureFiles.ForEach(texture => {
                writer.WriteString(texture.FilePath);
                writer.Write((byte)0);
                writer.Write((short)(texture.UseSkinShader ? 1 : 0));
                writer.Write((short)(texture.AlphaEnabled ? 1 : 0));
                writer.Write((short)(texture.TwoSided ? 1 : 0));
                writer.Write((short)(texture.AlphaTestEnabled ? 1 : 0));
                writer.Write(texture.AlphaReference);
                writer.Write((short)(texture.DepthTestEnabled ? 1 : 0));
                writer.Write((short)(texture.DepthWriteEnabled ? 1 : 0));
                writer.Write((short)texture.BlendType);
                writer.Write((short)(texture.UseSpecularShader ? 1 : 0));
                writer.Write(texture.Alpha);
                writer.Write((short)texture.GlowType);
                writer.Write(texture.GlowColour.ToVector3());
            });

            writer.Write((short)EffectFiles.Count);

            EffectFiles.ForEach(effectFile => {
                writer.WriteString(effectFile);
                writer.Write((byte)0);
            });

            writer.Write((short)Objects.Count);

            Objects.ForEach(@object => {
                writer.Write((int)@object.BoundingCylinder.Radius);
                writer.Write((int)@object.BoundingCylinder.Center.X);
                writer.Write((int)@object.BoundingCylinder.Center.Y);

                writer.Write((short)@object.Parts.Count);

                if (@object.Parts.Count > 0) {
                    @object.Parts.ForEach(part => {
                        writer.Write(part.Model);
                        writer.Write(part.Texture);

                        if (part.Position != Vector3.Zero) {
                            writer.Write((byte)ModelListPropertyType.Position);
                            writer.Write((byte)(sizeof(float) * 3));
                            writer.Write(part.Position);
                        }

                        if (part.Rotation != Quaternion.Zero) {
                            writer.Write((byte)ModelListPropertyType.Rotation);
                            writer.Write((byte)(sizeof(float) * 4));
                            writer.Write(part.Rotation, true);
                        }

                        if (part.Scale != Vector3.Zero) {
                            writer.Write((byte)ModelListPropertyType.Scale);
                            writer.Write((byte)(sizeof(float) * 3));
                            writer.Write(part.Scale);
                        }

                        if (part.AxisRotation != Quaternion.Zero) {
                            writer.Write((byte)ModelListPropertyType.AxisRotation);
                            writer.Write((byte)(sizeof(float) * 4));
                            writer.Write(part.AxisRotation, true);
                        }

                        if (part.Parent != 0) {
                            writer.Write((byte)ModelListPropertyType.Parent);
                            writer.Write((byte)sizeof(short));
                            writer.Write(part.Parent);
                        }

                        if (part.Collision != 0) {
                            writer.Write((byte)ModelListPropertyType.Collision);
                            writer.Write((byte)sizeof(short));
                            writer.Write((short)part.Collision);
                        }

                        if (string.Compare(part.AnimationFilePath, string.Empty) != 0) {
                            writer.Write((byte)ModelListPropertyType.ConstantAnimation);
                            writer.WriteByteString(part.AnimationFilePath);
                        }

                        if (part.VisibleRangeSet != 0) {
                            writer.Write((byte)ModelListPropertyType.VisibleRangeSet);
                            writer.Write((byte)sizeof(short));
                            writer.Write(part.VisibleRangeSet);
                        }

                        if (!part.UseLightmap) {
                            writer.Write((byte)ModelListPropertyType.UseLightmap);
                            writer.Write((byte)sizeof(short));
                            writer.Write((short)0);
                        }

                        if (part.BoneIndex != 0) {
                            writer.Write((byte)ModelListPropertyType.BoneIndex);
                            writer.Write((byte)sizeof(short));
                            writer.Write(part.BoneIndex);
                        }

                        if (part.DummyIndex != 0) {
                            writer.Write((byte)ModelListPropertyType.DummyIndex);
                            writer.Write((byte)sizeof(short));
                            writer.Write(part.DummyIndex);
                        }

                        for (int i = 0; i < part.MonsterAnimations.Length; i++) {
                            string animationFile = part.MonsterAnimations[i];

                            if (string.Compare(animationFile, string.Empty) != 0) {
                                writer.Write((byte)((byte)ModelListPropertyType.Animation + i));
                                writer.WriteByteString(animationFile);
                            }
                        }

                        for (int i = 0; i < part.AvatarAnimations.Length; i++) {
                            string animationFile = part.AvatarAnimations[i];

                            if (string.Compare(animationFile, string.Empty) != 0) {
                                writer.Write((byte)((byte)ModelListPropertyType.Animation + ModelListPart.MONSTER_ANIMATION_COUNT + i));
                                writer.WriteByteString(animationFile);
                            }
                        }

                        writer.Write((byte)0);
                    });

                    writer.Write((short)@object.Effects.Count);

                    @object.Effects.ForEach(effect => {
                        writer.Write((short)effect.EffectType);
                        writer.Write(effect.Effect);

                        if (effect.Position != Vector3.Zero) {
                            writer.Write((byte)ModelListPropertyType.Position);
                            writer.Write((byte)(sizeof(float) * 3));
                            writer.Write(effect.Position);
                        }

                        if (effect.Rotation != Quaternion.Zero) {
                            writer.Write((byte)ModelListPropertyType.Rotation);
                            writer.Write((byte)(sizeof(float) * 4));
                            writer.Write(effect.Rotation, true);
                        }

                        if (effect.Scale != Vector3.Zero) {
                            writer.Write((byte)ModelListPropertyType.Scale);
                            writer.Write((byte)(sizeof(float) * 3));
                            writer.Write(effect.Scale);
                        }

                        if (effect.Parent != 0) {
                            writer.Write((byte)ModelListPropertyType.Parent);
                            writer.Write((byte)sizeof(short));
                            writer.Write(effect.Parent);
                        }

                        writer.Write((byte)0);
                    });

                    writer.Write(@object.BoundingBox.Minimum);
                    writer.Write(@object.BoundingBox.Maximum);
                }
            });
        }
コード例 #5
0
 /// <summary>
 /// A simple hello world function that sends the passed message to the server
 /// then immediately returns. To receive notification of the server's response,
 /// add an event handler to <see cref="OnHelloComplete"/>.
 /// </summary>
 /// <param name="message">A String that contains the message to send to the
 /// server.</param>
 public void HelloAsync(string message)
 {
     MemoryStream ms = new MemoryStream();
     BinaryWriter bw = new BinaryWriter(ms, Encoding.UTF8);
     bw.Write(HelloProtocol.PROTOCOL_IDENTIFIER);
     bw.WriteString(message);
     Session.Send(ms);
     Log(Level.Info, string.Format("Client says: {0}", message));
 }
コード例 #6
0
ファイル: UALSpec.cs プロジェクト: IDWMaster/UALCompiler
        public override byte[] Serialize()
        {
            MemoryStream mstream = new MemoryStream ();
            BinaryWriter mwriter = new BinaryWriter (mstream);
            //Export data types
            var module = assembly.MainModule;
            mwriter.Write (module.Types.Count);
            foreach (var et in module.Types) {
                //Name of data type
                mwriter.WriteString (et.FullName);
                //Serialized form of data type, prefixed with length for fast-load (we will load and compile 1 class at a time)
                byte[] data = new UALType (et).Serialize ();
                mwriter.Write (data.Length);
                mwriter.Write (data);

            }

            //Export methods import table
            mwriter.Write (UALMethod.MethodTable.Count);
            foreach (var et in UALMethod.MethodTable) {
                mwriter.Write (et.Value);
                mwriter.WriteString (et.Key);
            }

            return mstream.ToArray ();
        }
コード例 #7
0
ファイル: UALSpec.cs プロジェクト: IDWMaster/UALCompiler
        public override byte[] Serialize()
        {
            //OPCODE list:

            /**
             * 0 -- Load argument
             * 1 -- Call function
             * 2 -- Load string immediate
             * 3 -- Return
             * 4 -- Load Int32 immediate (LE)
             * 5 -- Store local variable
             * 6 -- Branch to absolute UAL offset (32-bit offset)
             * 7 -- Load local variable
             * 8 -- Add
             * 9 -- Branch on <= (ble!!!)
             * 10 -- NOPE! You're not gonna do anything here!
             * 11 -- Branch on equal
             * 12 -- Branch on not equal
             * 13 -- Branch on greater than
             * 14 -- Branch on greater than or equal to
             * 15 -- Subtract
             * 16 -- Multiply
             * 17 -- Divide
             * 18 -- Remainder
             * 19 -- Shift Democrat
             * 20 -- Shift Republican
             * 21 -- And
             * 22 -- Or
             * 23 -- Xor
             * 24 -- NOT
             * 25 -- Load immediate ON THE DOUBLE!
             * 26 -- Load buffer immediate
             * 255 -- End of code segment
             * */

            Console.WriteLine ("Entering " + info.FullName);
            MemoryStream mstream = new MemoryStream ();
            BinaryWriter mwriter = new BinaryWriter (mstream);
            if (info.Body.Instructions.Count == 0 || info.IsConstructor) { //TODO: Constructor support (maybe?)
                mwriter.Write (false); //Native method invocation
                return mstream.ToArray ();
            }
            mwriter.Write (true); //Is .NET method?

            //Body of method
            var body = info.Body;

            //Variable count

            mwriter.Write (body.Variables.Count);

            foreach (var et in body.Variables) {
                mwriter.WriteString (et.VariableType.FullName);
            }

            //IL code for method
            var instructions = body.Instructions;

            Dictionary<int,int> UALOffsetTable = new Dictionary<int, int> ();
            //List of code positions needing UAL offsets
            List<Tuple<int,long>> pendingLocations = new List<Tuple<int, long>> ();

            int InstructionStartPoint = (int)mstream.Position;

            ///<summary>Emits a UAL OPCODE</summary>
            /// <param name="opcode">The OPCODE to emit</param>
            code_emit emitInstruction = delegate(Instruction il,byte opcode) {
                UALOffsetTable[il.Offset] = (int)mstream.Position;
                mwriter.Write(opcode);
            };

            foreach (var et in instructions) {
                Console.WriteLine (et);

                if ((int)et.OpCode.Code >= (int)Mono.Cecil.Cil.Code.Ldarg_0 && ((int)et.OpCode.Code <= (int)Mono.Cecil.Cil.Code.Ldarg_3)) {
                    int argnum = 3-((int)Code.Ldarg_3 - (int)et.OpCode.Code);
                    emitInstruction(et,0); //Load argument
                    mwriter.Write (argnum); //Argument number
                    continue;
                }
                if ((int)et.OpCode.Code >= (int)Code.Ldc_I4_0 && (int)et.OpCode.Code <= (int)Code.Ldc_I4_8) {
                    int lval = 8 - ((int)Code.Ldc_I4_8 - (int)et.OpCode.Code);
                    emitInstruction (et,(byte)4);
                    mwriter.Write (lval);
                    continue;
                }
                if ((int)et.OpCode.Code >= (int)Code.Stloc_0 && (int)et.OpCode.Code <= (int)Code.Stloc_3) {
                    int lval = 3 - ((int)Code.Stloc_3 - (int)et.OpCode.Code);
                    emitInstruction (et,(byte)5);
                    mwriter.Write (lval);
                    continue;
                }
                if (et.OpCode.Code == Code.Stloc_S) {
                    emitInstruction (et, (byte)5);
                    mwriter.Write ((et.Operand as VariableReference).Index);
                    continue;
                }
                if ((int)et.OpCode.Code >= (int)Code.Ldloc_0 && (int)et.OpCode.Code <= (int)Code.Ldloc_3) {
                    int lval = 3 - ((int)Code.Ldloc_3 - (int)et.OpCode.Code);
                    emitInstruction (et,(byte)7);
                    mwriter.Write (lval);
                    continue;
                }
                if (et.OpCode.Code == Code.Ldloc_S) {
                    emitInstruction (et, (byte)7);
                    mwriter.Write ((et.Operand as VariableReference).Index);
                    continue;
                }
                    switch (et.OpCode.Code) {
                    case Mono.Cecil.Cil.Code.Call:
                        {
                            var method = et.Operand as MemberReference; //Method to invoke
                            emitInstruction(et,(byte)1);
                            mwriter.Write (GetMethodPointer (method.FullName));
                        }
                        break;
                    case Mono.Cecil.Cil.Code.Ldstr:
                        emitInstruction (et,(byte)2);
                        mwriter.WriteString (et.Operand as string);
                        break;
                case Mono.Cecil.Cil.Code.Nop:
                    emitInstruction (et, 10);
                        break;
                    case Code.Ret:
                        //Return from function call
                        emitInstruction (et,(byte)3);
                        break;
                case Code.Br:
                    emitInstruction (et, 6);
                    pendingLocations.Add (new Tuple<int, long> ((et.Operand as Instruction).Offset, mstream.Position));
                    mwriter.Write ((int)0);
                    break;
                case Code.Add:
                    emitInstruction (et, 8);
                    break;
                case Code.Ldc_I4_S:
                    //Load int immediate
                    emitInstruction (et, 4);
                    mwriter.Write ((int)(sbyte)et.Operand);
                    break;
                case Code.Ldc_I4:
                    //Load int immediate
                    emitInstruction (et, 4);
                    mwriter.Write ((int)et.Operand);
                    break;
                case Code.Ble:
                    emitInstruction (et, 9);
                    pendingLocations.Add (new Tuple<int, long> ((et.Operand as Instruction).Offset, mstream.Position));
                    mwriter.Write ((int)0);
                    break;
                case Code.Beq:
                    emitInstruction (et, 11);
                    pendingLocations.Add (new Tuple<int, long> ((et.Operand as Instruction).Offset, mstream.Position));
                    mwriter.Write ((int)0);
                    break;
                case Code.Bne_Un:
                    emitInstruction (et, 12);
                    pendingLocations.Add (new Tuple<int, long> ((et.Operand as Instruction).Offset, mstream.Position));
                    mwriter.Write ((int)0);
                    break;
                case Code.Bgt:
                    emitInstruction (et, 13);
                    pendingLocations.Add (new Tuple<int, long> ((et.Operand as Instruction).Offset, mstream.Position));
                    mwriter.Write ((int)0);
                    break;
                case Code.Bge:
                    emitInstruction (et, 14);
                    pendingLocations.Add (new Tuple<int, long> ((et.Operand as Instruction).Offset, mstream.Position));
                    mwriter.Write ((int)0);
                    break;
                case Code.Sub:
                    emitInstruction (et, 15);
                    break;
                case Code.Mul:
                    emitInstruction (et, 16);
                    break;
                case Code.Div:
                    emitInstruction (et, 17);
                    break;
                case Code.Rem:
                    emitInstruction (et, 18);
                    break;

                    //Binary instructions

                case Code.Shl:
                    emitInstruction (et, 19);
                    break;
                case Code.Shr:
                    emitInstruction (et, 20);
                    break;
                case Code.And:
                    emitInstruction (et, 21);
                    break;
                case Code.Or:
                    emitInstruction (et, 22);
                    break;
                case Code.Xor:
                    emitInstruction (et,23);
                    break;
                case Code.Not:
                    emitInstruction (et, 24);
                    break;
                case Code.Ldc_R8:
                    emitInstruction (et, 25);
                    mwriter.Write ((double)et.Operand);
                    break;

                    default:
                        Console.WriteLine ("Unknown OPCODE: " + et.OpCode);
                        break;
                    }

            }
            mwriter.Write ((byte)255);
            //Update everything that needs a UAL offset
            foreach (var et in pendingLocations) {
                mstream.Position = et.Item2;
                mwriter.Write (UALOffsetTable [et.Item1]-InstructionStartPoint);
            }
            return mstream.ToArray ();
        }
コード例 #8
0
ファイル: LevelOfDetailFile.cs プロジェクト: Jiwan/Revise
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.WriteString(Name);
            writer.Write((byte)0);

            for (int h = 0; h < Height; h++) {
                for (int w = 0; w < Width; w++) {
                    writer.Write(values[h, w]);
                }
            }
        }
コード例 #9
0
ファイル: cFBX.cs プロジェクト: DevilboxGames/ToxicRagers
        public void Save(string path)
        {
            using (BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.Create)))
            {
                bw.WriteString("Kaydara FBX Binary");
                bw.Write(new byte[] { 0x20, 0x20, 0x0, 0x1A, 0x0 });
                bw.Write(this.version);

                this.calc_offsets_children_root((int)bw.BaseStream.Position, false);
                this.write_children_root(bw, false);

                bw.Write(new byte[] { 0xfa, 0xbc, 0xab, 0x09, 0xd0, 0xc8, 0xd4, 0x66, 0xb1, 0x76, 0xfb, 0x83, 0x1c, 0xf7, 0x26, 0x7e });
                bw.Write(new byte[4]);

                int ofs = (int)bw.BaseStream.Position;
                int pad = ((ofs + 15) & ~15) - ofs;
                if (pad == 0) { pad = 16; }
                bw.Write(new byte[pad]);

                bw.Write(this.version);
                bw.Write(new byte[120]);
                bw.Write(new byte[] { 0xf8, 0x5a, 0x8c, 0x6a, 0xde, 0xf5, 0xd9, 0x7e, 0xec, 0xe9, 0x0c, 0xe3, 0x75, 0x8f, 0x29, 0x0b });
            }
        }
コード例 #10
0
ファイル: SayMessageAction.cs プロジェクト: Jiwan/Revise
 /// <summary>
 /// Writes the condition data to the underlying stream.
 /// </summary>
 /// <param name="writer">The writer.</param>
 public void Write(BinaryWriter writer)
 {
     if (UseText) {
         writer.WriteString(Text);
     } else {
         writer.Write(StringID);
     }
 }
コード例 #11
0
ファイル: LanguageFile.cs プロジェクト: Jiwan/Revise
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.Unicode);

            writer.Write(ColumnCount);
            writer.Write(rows.Count);

            long[,] offsets = new long[rows.Count, ColumnCount];

            for (int i = 0; i < rows.Count; i++) {
                LanguageRow row = rows[i];

                for (int j = 0; j < ColumnCount; j++) {
                    offsets[i, j] = stream.Position;

                    writer.Write(0);
                    writer.Write((short)row[j].Length);
                }
            }

            for (int i = 0; i < rows.Count; i++) {
                LanguageRow row = rows[i];

                for (int j = 0; j < ColumnCount; j++) {
                    long offset = stream.Position;
                    writer.WriteString(row[j], Encoding.Unicode);

                    long previousPosition = stream.Position;
                    stream.Seek(offsets[i, j], SeekOrigin.Begin);

                    writer.Write((int)offset);

                    stream.Seek(previousPosition, SeekOrigin.Begin);
                }
            }
        }
コード例 #12
0
ファイル: sCNT.cs プロジェクト: DevilboxGames/ToxicRagers
        private static void Save(BinaryWriter bw, CNT cnt)
        {
            int nameLength = cnt.Name.Length;
            int padding = (((nameLength / 4) + (nameLength % 4 > 0 ? 1 : 0)) * 4) - nameLength;

            bw.Write(nameLength);
            bw.WriteString(cnt.Name);
            bw.Write(new byte[padding]);

            bw.Write((byte)0);

            bw.Write((int)0);

            bw.Write(cnt.Transform.M11);
            bw.Write(cnt.Transform.M12);
            bw.Write(cnt.Transform.M13);
            bw.Write(cnt.Transform.M21);
            bw.Write(cnt.Transform.M22);
            bw.Write(cnt.Transform.M23);
            bw.Write(cnt.Transform.M31);
            bw.Write(cnt.Transform.M32);
            bw.Write(cnt.Transform.M33);
            bw.Write(cnt.Transform.M41);
            bw.Write(cnt.Transform.M42);
            bw.Write(cnt.Transform.M43);

            bw.WriteString(cnt.Section.ToString());

            switch (cnt.Section)
            {
                case NodeType.LITg:
                    if (cnt.EmbeddedLight)
                    {
                        bw.Write(2);
                        LIGHT.Save(bw, cnt.Light);
                    }
                    else
                    {
                        bw.Write(3);
                        nameLength = cnt.LightName.Length;
                        padding = (((nameLength / 4) + (nameLength % 4 > 0 ? 1 : 0)) * 4) - nameLength;

                        bw.Write(cnt.LightName.Length);
                        bw.WriteString(cnt.LightName);
                        bw.Write(new byte[padding]);
                    }
                    break;

                case NodeType.MODL:
                case NodeType.SKIN:
                    nameLength = cnt.Model.Length;
                    padding = (((nameLength / 4) + (nameLength % 4 > 0 ? 1 : 0)) * 4) - nameLength;

                    bw.Write(nameLength);
                    bw.WriteString(cnt.Model);
                    bw.Write(new byte[padding]);
                    break;

                case NodeType.NULL:
                    break;

                default:
                    throw new NotImplementedException(string.Format("Save code for CNT section {0} does not exist!", cnt.Section));
            }

            bw.Write(cnt.Children.Count);
            foreach (CNT c in cnt.Children) { Save(bw, c); }
            bw.Write((int)0);
        }
コード例 #13
0
ファイル: sMDL.cs プロジェクト: DevilboxGames/ToxicRagers
        public void Save(string path)
        {
            int nameLength, padding;
            this.CalculateExtents();

            using (BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.Create)))
            {
                bw.Write(new byte[] { 0x45, 0x23 });    // Magic Number
                bw.Write(new byte[] { 2, 6 });          // Version (6.2)

                bw.Write(new byte[] { 0, 0, 0, 0 });    // Checksum, to calculate
                bw.Write((int)this.flags);

                int prepDataSize = 4 + (this.faces.Count * 16) + 4 + (this.verts.Count * 44) + 2;

                for (int i = 0; i < this.meshes.Count; i++)
                {
                    var mesh = this.meshes[i];

                    prepDataSize += 52;
                    prepDataSize += (4 * mesh.StripList.Count);

                    prepDataSize += 12;
                    prepDataSize += (4 * mesh.TriList.Count);
                }

                bw.Write(prepDataSize);                 // PREP data size

                bw.Write(this.faces.Count);             // USER face count
                bw.Write(this.verts.Count);             // USER vert count

                bw.Write(0);                            // Back filled post save

                bw.Write(this.extents.Radius);
                bw.Write(this.extents.Min.X);
                bw.Write(this.extents.Min.Y);
                bw.Write(this.extents.Min.Z);
                bw.Write(this.extents.Max.X);
                bw.Write(this.extents.Max.Y);
                bw.Write(this.extents.Max.Z);
                bw.Write(this.extents.Centre.X);
                bw.Write(this.extents.Centre.Y);
                bw.Write(this.extents.Centre.Z);

                bw.Write((short)this.Meshes.Count);

                for (int i = 0; i < this.Meshes.Count; i++)
                {
                    nameLength = this.Meshes[i].Name.Length;
                    padding = (((nameLength / 4) + (nameLength % 4 > 0 ? 1 : 0)) * 4) - nameLength + 4;

                    bw.Write(nameLength);
                    bw.WriteString(this.Meshes[i].Name);
                    bw.Write(new byte[padding]);
                }

                bw.Write(this.faces.Count);

                for (int i = 0; i < this.faces.Count; i++)
                {
                    bw.Write((short)this.faces[i].MaterialID);
                    bw.Write((short)0);
                    bw.Write(this.faces[i].Verts[0]);
                    bw.Write(this.faces[i].Verts[1]);
                    bw.Write(this.faces[i].Verts[2]);
                }

                bw.Write(this.verts.Count);

                for (int i = 0; i < this.verts.Count; i++)
                {
                    bw.Write(this.verts[i].Position.X);
                    bw.Write(this.verts[i].Position.Y);
                    bw.Write(this.verts[i].Position.Z);

                    bw.Write(this.verts[i].Normal.X);
                    bw.Write(this.verts[i].Normal.Y);
                    bw.Write(this.verts[i].Normal.Z);

                    bw.Write(this.verts[i].UV.X);
                    bw.Write(this.verts[i].UV.Y);

                    bw.Write(this.verts[i].UV2.X);
                    bw.Write(this.verts[i].UV2.Y);

                    bw.Write(this.verts[i].Colour.R);
                    bw.Write(this.verts[i].Colour.G);
                    bw.Write(this.verts[i].Colour.B);
                    bw.Write(this.verts[i].Colour.A);
                }

                bw.Write((short)this.meshes.Count);

                for (int i = 0; i < this.meshes.Count; i++)
                {
                    var mesh = this.meshes[i];

                    bw.Write(mesh.Extents.Centre.X);
                    bw.Write(mesh.Extents.Centre.Y);
                    bw.Write(mesh.Extents.Centre.Z);
                    bw.Write(mesh.Extents.Radius);
                    bw.Write(mesh.Extents.Min.X);
                    bw.Write(mesh.Extents.Min.Y);
                    bw.Write(mesh.Extents.Min.Z);
                    bw.Write(mesh.Extents.Max.X);
                    bw.Write(mesh.Extents.Max.Y);
                    bw.Write(mesh.Extents.Max.Z);

                    // TriangleStrips
                    bw.Write(mesh.StripOffset);
                    bw.Write(mesh.StripVertCount);
                    bw.Write(mesh.StripList.Count);

                    for (int j = 0; j < mesh.StripList.Count; j++)
                    {
                        bw.Write((uint)mesh.StripList[j].Index | (mesh.StripList[j].Degenerate ? 0x80000000 : 0x0));
                    }

                    bw.Write(mesh.TriListOffset);
                    bw.Write(mesh.TriListVertCount);
                    bw.Write(mesh.TriList.Count);

                    for (int j = 0; j < mesh.TriList.Count; j++)
                    {
                        bw.Write(mesh.TriList[j].Index);
                    }
                }

                if (this.flags.HasFlag(Flags.USERData))
                {
                    bw.Write(0);

                    for (int i = 0; i < this.verts.Count; i++)
                    {
                        bw.Write(this.verts[i].Position.X);
                        bw.Write(this.verts[i].Position.Y);
                        bw.Write(this.verts[i].Position.Z);
                        bw.Write(1);
                    }

                    for (int i = 0; i < this.faces.Count; i++)
                    {
                        var v12 = this.verts[this.faces[i].Verts[1]].Normal - this.verts[this.faces[i].Verts[0]].Normal;
                        var v13 = this.verts[this.faces[i].Verts[2]].Normal - this.verts[this.faces[i].Verts[0]].Normal;
                        var n = Vector3.Cross(v12, v13).Normalised;
                        var d = Vector3.Dot(n, this.verts[this.faces[i].Verts[0]].Normal);

                        bw.Write(d);
                        bw.Write(n.X);
                        bw.Write(n.Y);
                        bw.Write(n.Z);
                        bw.Write(this.verts[this.faces[i].Verts[0]].Normal.X);
                        bw.Write(this.verts[this.faces[i].Verts[0]].Normal.Y);
                        bw.Write(this.verts[this.faces[i].Verts[0]].Normal.Z);
                        bw.Write(this.verts[this.faces[i].Verts[1]].Normal.X);
                        bw.Write(this.verts[this.faces[i].Verts[1]].Normal.Y);
                        bw.Write(this.verts[this.faces[i].Verts[1]].Normal.Z);
                        bw.Write(this.verts[this.faces[i].Verts[2]].Normal.X);
                        bw.Write(this.verts[this.faces[i].Verts[2]].Normal.Y);
                        bw.Write(this.verts[this.faces[i].Verts[2]].Normal.Z);
                        bw.Write(this.faces[i].MaterialID);
                        bw.Write(0);
                        bw.Write(this.faces[i].Verts[0]);
                        bw.Write(this.faces[i].Verts[1]);
                        bw.Write(this.faces[i].Verts[2]);
                        bw.Write(this.verts[this.faces[i].Verts[0]].Colour.R); bw.Write(this.verts[this.faces[i].Verts[0]].Colour.G); bw.Write(this.verts[this.faces[i].Verts[0]].Colour.B); bw.Write(this.verts[this.faces[i].Verts[0]].Colour.A);
                        bw.Write(this.verts[this.faces[i].Verts[1]].Colour.R); bw.Write(this.verts[this.faces[i].Verts[1]].Colour.G); bw.Write(this.verts[this.faces[i].Verts[1]].Colour.B); bw.Write(this.verts[this.faces[i].Verts[1]].Colour.A);
                        bw.Write(this.verts[this.faces[i].Verts[2]].Colour.R); bw.Write(this.verts[this.faces[i].Verts[2]].Colour.G); bw.Write(this.verts[this.faces[i].Verts[2]].Colour.B); bw.Write(this.verts[this.faces[i].Verts[2]].Colour.A);
                        bw.Write(this.verts[this.faces[i].Verts[0]].UV.X);
                        bw.Write(this.verts[this.faces[i].Verts[0]].UV.Y);
                        bw.Write(this.verts[this.faces[i].Verts[0]].UV2.X);
                        bw.Write(this.verts[this.faces[i].Verts[0]].UV2.Y);
                        bw.Write(this.verts[this.faces[i].Verts[1]].UV.X);
                        bw.Write(this.verts[this.faces[i].Verts[1]].UV.Y);
                        bw.Write(this.verts[this.faces[i].Verts[1]].UV2.X);
                        bw.Write(this.verts[this.faces[i].Verts[1]].UV2.Y);
                        bw.Write(this.verts[this.faces[i].Verts[2]].UV.X);
                        bw.Write(this.verts[this.faces[i].Verts[2]].UV.Y);
                        bw.Write(this.verts[this.faces[i].Verts[2]].UV2.X);
                        bw.Write(this.verts[this.faces[i].Verts[2]].UV2.Y);
                        bw.Write((byte)0);
                        bw.Write(0);
                    }

                    for (int i = 0; i < this.faces.Count; i++) { bw.Write(i); }

                    bw.Write(this.verts.Count);

                    for (int i = 0; i < this.verts.Count; i++) { bw.Write(i); }

                    if (this.flags.HasFlag(Flags.USERSkinData))
                    {

                    }
                }
            }

            using (BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.Open)))
            {
                bw.Seek(24, SeekOrigin.Begin);
                bw.Write((int)(bw.BaseStream.Length - 28));
            }
        }
コード例 #14
0
ファイル: Column.cs プロジェクト: ricardodemauro/SharpHSQL
        /**
         * Method declaration
         *
         *
         * @param out
         * @param l
         * @param type
         * @param data
         *
         * @throws IOException
         */
        public static void writeData(BinaryWriter dout, int l, int[] type, object[] data)
        {
            for (int i = 0; i < l; i++)
            {
                object o = data[i];

                if (o == null)
                {
                    dout.Write(NULL);
                }
                else
                {
                    int t = type[i];

                    dout.Write(t);

                    switch (t)
                    {

                        case NULL:
                            o = null;
                            break;

                        case FLOAT:
                        case REAL:
                            dout.Write((float)o);
                            break;

                        case DOUBLE:
                            dout.Write((double)o);
                            break;

                        case BIT:
                            dout.Write((bool)o);
                            break;

                        case TINYINT:
                            dout.Write((byte)o);
                            break;

                        case SMALLINT:
                            dout.Write((short)o);
                            break;

                        case INTEGER:
                            dout.Write((int)o);
                            break;

                        case BIGINT:
                            dout.Write((long)o);
                            break;

                        case BINARY:
                        case VARBINARY:
                        case LONGVARBINARY:
                        case OTHER:
                            byte[] b = ((ByteArray)o).byteValue();
                            dout.Write(b.Length);
                            dout.Write(b);
                            break;

                        default:
                            dout.WriteString(o.ToString());
                            break;
                    }
                }
            }
        }
コード例 #15
0
ファイル: sIMG.cs プロジェクト: DevilboxGames/ToxicRagers
        public void Save(string path)
        {
            using (BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.Create)))
            {
                BasicFlags basic = 0;
                AdvancedFlags compression = 0;
                int dataSize = 0;

                if (this.planeFormat == PlaneFormat.Format1planeARGB)
                {
                    dataSize = this.planes.First().Output.Length;
                }
                else
                {
                    basic = BasicFlags.Compressed;

                    if (this.planes.Any(p => p.Method == CompressionMethod.RLE && p.PoorCompression))
                    {
                        Parallel.ForEach(
                            this.planes,
                            p =>
                            {
                                p.Compress(CompressionMethod.Huffman);
                            }
                        );

                        compression = AdvancedFlags.Huffman;
                    }
                    else if (this.planes.Any(p => p.Method == CompressionMethod.Huffman))
                    {
                        compression = AdvancedFlags.Huffman;
                    }

                    dataSize = (this.planes.Count * 4) + this.planes.Sum(p => p.DataSize);
                }

                bw.WriteString("IMAGEMAP");
                bw.Write(new byte[] { 0x1, 0x1 }); // version 1.1
                bw.Write((byte)(basic | BasicFlags.DisableDownSample | BasicFlags.DisableMipMaps));
                bw.Write((byte)(compression | AdvancedFlags.DontAutoJPEG));
                bw.Write((int)planeFormat);
                bw.Write(dataSize);
                bw.Write((short)this.width);
                bw.Write((short)this.height);
                bw.Write(0x64);

                if (this.planeFormat != PlaneFormat.Format1planeARGB)
                {
                    foreach (var plane in this.planes.OrderByDescending(p => p.Index))
                    {
                        bw.Write(plane.DataSize);
                    }
                }

                foreach (var plane in this.planes.OrderByDescending(p => p.Index))
                {
                    bw.Write(plane.Output);
                }
            }
        }
コード例 #16
0
ファイル: CameraFile.cs プロジェクト: osROSE/UnityRose
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.WriteString(FILE_IDENTIFIER);
            writer.Write((int)ProjectionType);

            writer.Write(ModelView);
            writer.Write(Projection);

            writer.Write(FieldOfView);
            writer.Write(AspectRatio);
            writer.Write(NearPlane);
            writer.Write(FarPlane);

            writer.Write(Eye);
            writer.Write(Center);
            writer.Write(Up);
        }
コード例 #17
0
ファイル: MotionFile.cs プロジェクト: Jiwan/Revise
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.WriteString(FILE_IDENTIFIER);
            writer.Write((byte)0);

            writer.Write(FramesPerSecond);
            writer.Write(FrameCount);
            writer.Write(ChannelCount);

            channels.ForEach(channel => {
                writer.Write((int)channel.Type);
                writer.Write(channel.Index);
            });

            for (int i = 0; i < FrameCount; i++) {
                channels.ForEach(channel => {
                    channel.WriteFrame(writer, i);
                });
            }
        }
コード例 #18
0
ファイル: ConversationFile.cs プロジェクト: Jiwan/Revise
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            Encoding encoding = Encoding.GetEncoding("EUC-KR");
            BinaryWriter writer = new BinaryWriter(stream, encoding);

            short functionMask = 0;

            for (int i = 0; i < Functions.Length; i++) {
                ConversationFunction function = Functions[i];

                if (function.IsEnabled) {
                    functionMask |= (short)(1 << i);
                }
            }

            writer.Write(functionMask);

            for (int i = 0; i < Functions.Length; i++) {
                ConversationFunction function = Functions[i];
                writer.WriteString(function.Name, 32);
            }

            writer.Write((ushort)0xCCCC);

            long offsets = stream.Position;

            writer.Write(0);
            writer.Write(0);

            long conversationOffset = stream.Position;

            writer.Write(0);
            writer.Write(0);

            writer.Write(0);
            writer.Write(0);

            long messageOffset = stream.Position;

            for (int i = 0; i < Messages.Count; i++) {
                writer.Write(0);
            }

            for (int i = 0; i < Messages.Count; i++) {
                long offset = stream.Position - messageOffset;

                ConversationMessage message = Messages[i];
                writer.Write(message.ID);
                writer.Write((int)message.Type);
                writer.Write(message.TargetWindow);
                writer.WriteString(message.Condition, 32);
                writer.WriteString(message.Action, 32);
                writer.Write(message.StringID);

                long nextMessageOffset = stream.Position;

                stream.Seek(messageOffset + sizeof(int) * i, SeekOrigin.Begin);
                writer.Write((int)offset);

                stream.Seek(nextMessageOffset, SeekOrigin.Begin);
            }

            long menuOffset = stream.Position;

            for (int i = 0; i < Menus.Count; i++) {
                writer.Write(0);
            }

            for (int i = 0; i < Menus.Count; i++) {
                long offset = stream.Position;

                ConversationMenu menu = Menus[i];
                int menuSize = sizeof(int) * 2 + menu.Messages.Count * (sizeof(int) * 5 + 32 + 32);
                writer.Write(menuSize);
                writer.Write(menu.Messages.Count);

                for (int j = 0; j < menu.Messages.Count; j++) {
                    writer.Write(0);
                }

                for (int j = 0; j < menu.Messages.Count; j++) {
                    long menuItemOffset = stream.Position - offset;

                    ConversationMessage message = menu.Messages[j];
                    writer.Write(Obfuscate(message.ID, menu.Messages.Count, menuSize));
                    writer.Write(Obfuscate((int)message.Type, menu.Messages.Count, menuSize));
                    writer.Write(Obfuscate(message.TargetWindow, menu.Messages.Count, menuSize));

                    byte[] condition = encoding.GetBytes(message.Condition);
                    Array.Resize(ref condition, 32);
                    Obfuscate(condition, menu.Messages.Count, menuSize);

                    byte[] action = encoding.GetBytes(message.Action);
                    Array.Resize(ref action, 32);
                    Obfuscate(action, menu.Messages.Count, menuSize);

                    writer.Write(condition);
                    writer.Write(action);
                    writer.Write(Obfuscate(message.StringID, menu.Messages.Count, menuSize));

                    long nextMessageOffset = stream.Position;

                    stream.Seek(offset + sizeof(int) * 2 + sizeof(int) * j, SeekOrigin.Begin);
                    writer.Write(Obfuscate((int)menuItemOffset, menu.Messages.Count, menuSize));

                    stream.Seek(nextMessageOffset, SeekOrigin.Begin);
                }

                long nextMenuOffset = stream.Position;

                stream.Seek(menuOffset + sizeof(int) * i, SeekOrigin.Begin);
                writer.Write((int)(offset - menuOffset));

                stream.Seek(nextMenuOffset, SeekOrigin.Begin);
            }

            long scriptOffset = stream.Position;

            byte[] script = new byte[Script.Length];
            Array.Copy(Script, script, Script.Length);

            Obfuscate(script, script.Length, (int)(scriptOffset + sizeof(int) + script.Length));

            writer.Write(script.Length);
            writer.Write(script);

            stream.Seek(offsets, SeekOrigin.Begin);

            writer.Write((int)conversationOffset);
            writer.Write((int)scriptOffset);

            writer.Write(Messages.Count);
            writer.Write((int)(messageOffset - conversationOffset));

            writer.Write(Menus.Count);
            writer.Write((int)(menuOffset - conversationOffset));
        }
コード例 #19
0
ファイル: UALSpec.cs プロジェクト: IDWMaster/UALCompiler
        public override byte[] Serialize()
        {
            MemoryStream mstream = new MemoryStream ();
            BinaryWriter mwriter = new BinaryWriter (mstream);
            mwriter.Write (t.Methods.Count);
            foreach (var et in t.Methods) {
                //Name of method
                mwriter.WriteString (et.FullName);
                byte[] data = new UALMethod (et).Serialize();
                mwriter.Write (data.Length);
                mwriter.Write (data);

            }

            //Write all fields
            mwriter.Write (t.Fields.Count);
            foreach (var et in t.Fields) {
                mwriter.WriteString (et.Name);
                mwriter.Write (new UALField (et).Serialize ());
            }

            return mstream.ToArray ();
        }
コード例 #20
0
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));
            AlignedBinaryWriter alignedWriter = new AlignedBinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.Write(Patterns.Count);
            writer.Write(IdleInterval);
            writer.Write(DamageRate);
            writer.WriteIntString(Name);

            Patterns.ForEach(pattern => {
                writer.WriteString(pattern.Name, 32);
                writer.Write(pattern.Events.Count);

                pattern.Events.ForEach(@event => {
                    writer.WriteString(@event.Name, 32);
                    writer.Write(@event.Conditions.Count);

                    @event.Conditions.ForEach(condition => {
                        writer.Write(0);
                        writer.Write((int)condition.Type | CONDITION_MASK);

                        alignedWriter.Reset();
                        condition.Write(alignedWriter);
                        alignedWriter.Align();

                        int size = alignedWriter.TotalWrote + 8;

                        stream.Seek(-size, SeekOrigin.Current);
                        writer.Write(size);

                        stream.Seek(size - 4, SeekOrigin.Current);
                    });

                    writer.Write(@event.Actions.Count);

                    @event.Actions.ForEach(action => {
                        writer.Write(0);
                        writer.Write((int)action.Type | ACTION_MASK);

                        alignedWriter.Reset();
                        action.Write(alignedWriter);
                        alignedWriter.Align();

                        int size = alignedWriter.TotalWrote + 8;

                        stream.Seek(-size, SeekOrigin.Current);
                        writer.Write(size);

                        stream.Seek(size - 4, SeekOrigin.Current);
                    });
                });
            });
        }
コード例 #21
0
ファイル: ModelFile.cs プロジェクト: osROSE/UnityRose
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.WriteString(FILE_IDENTIFIER_8);
            writer.Write((byte)0);

            writer.Write((int)format);

            writer.Write(BoundingBox.min);
            writer.Write(BoundingBox.max);

            writer.Write((short)BoneTable.Count);

            BoneTable.ForEach(bone => {
                writer.Write(bone);
            });

            writer.Write((short)Vertices.Count);

            Vertices.ForEach(vertex => {
                writer.Write(vertex.Position);
            });

            if (NormalsEnabled) {
                Vertices.ForEach(vertex => {
                    writer.Write(vertex.Normal);
                });
            }

            if (ColoursEnabled) {
                Vertices.ForEach(vertex => {
                    writer.Write(vertex.Colour.a);
                    writer.Write(vertex.Colour.r);
                    writer.Write(vertex.Colour.g);
                    writer.Write(vertex.Colour.b);
                });
            }

            if (BonesEnabled) {
                Vertices.ForEach(vertex => {
                    writer.Write(vertex.BoneWeights);
                    writer.Write(vertex.BoneIndices);
                });
            }

            if (TangentsEnabled) {
                Vertices.ForEach(vertex => {
                    writer.Write(vertex.Tangent);
                });
            }

            if (TextureCoordinates1Enabled) {
                Vertices.ForEach(vertex => {
                    writer.Write(vertex.TextureCoordinates[0]);
                });
            }

            if (TextureCoordinates2Enabled) {
                Vertices.ForEach(vertex => {
                    writer.Write(vertex.TextureCoordinates[1]);
                });
            }

            if (TextureCoordinates3Enabled) {
                Vertices.ForEach(vertex => {
                    writer.Write(vertex.TextureCoordinates[2]);
                });
            }

            if (TextureCoordinates4Enabled) {
                Vertices.ForEach(vertex => {
                    writer.Write(vertex.TextureCoordinates[3]);
                });
            }

            writer.Write((short)Indices.Count);

            Indices.ForEach(index => {
                writer.Write(index);
            });

            writer.Write((short)Materials.Count);

            Materials.ForEach(material => {
                writer.Write(material);
            });

            writer.Write((short)Strips.Count);

            Strips.ForEach(strip => {
                writer.Write(strip);
            });

            writer.Write((short)Pool);
        }
コード例 #22
0
ファイル: DataFile.cs プロジェクト: Jiwan/Revise
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.WriteString(FILE_IDENTIFIER);
            writer.Write('1');
            writer.Write(0);
            writer.Write(RowCount + 1);
            writer.Write(ColumnCount);
            writer.Write(RowHeight);

            writer.Write(GetRootColumnWidth());

            columns.ForEach(column => {
                writer.Write(column.Width);
            });

            writer.WriteShortString(GetRootColumnName());

            columns.ForEach(column => {
                writer.WriteShortString(column.Name);
            });

            rows.ForEach(row => {
                writer.WriteShortString(row[0]);
            });

            long position = stream.Position;

            rows.ForEach(row => {
                for (int i = 1; i < ColumnCount; i++) {
                    writer.WriteShortString(row[i]);
                }
            });

            stream.Seek(FILE_IDENTIFIER.Length + 1, SeekOrigin.Begin);
            writer.Write((int)position);
        }
コード例 #23
0
        protected override void WriteInner(BinaryWriter writer)
        {
            writer.Write(_achievements.Count);
            for (int i = 0; i < _achievements.Length; i++)
            {
                writer.WriteString(_achievements[i].Name);
                writer.Write(_achievements[i].Progression);

                IBinarySerializable tag = _achievements[i].Tag as IBinarySerializable;
                if (tag != null) // ... i guess this is ok
                {
                    writer.Write(tag);
                }
            }
        }
コード例 #24
0
ファイル: crLIGHT.cs プロジェクト: DevilboxGames/ToxicRagers
        public static void Save(BinaryWriter bw, LIGHT light)
        {
            bw.Write((int)light.type);
            bw.Write(light.r);
            bw.Write(light.g);
            bw.Write(light.b);
            bw.Write(light.intensity);
            bw.Write(light.range);
            bw.Write(light.inner);
            bw.Write(light.outer);
            bw.Write(light.nearClip);
            bw.Write((int)light.flags);
            bw.Write(light.shadResX);
            bw.Write(light.shadResY);
            bw.Write(light.shadCoverX);
            bw.Write(light.shadCoverY);
            bw.Write(light.shadowBias);
            bw.Write(light.shadIntensity);
            bw.Write(light.splitCount);
            bw.Write(light.splitDistribution);
            bw.Write(light.shadDistMin);
            bw.Write(light.shadDistMax);
            bw.Write((light.bUseEdgeCol ? 1 : 0));
            bw.Write(light.edgeColR);
            bw.Write(light.edgeColG);
            bw.Write(light.edgeColB);
            bw.Write(light.edgeColA);
            bw.Write(light.goboScaleX);
            bw.Write(light.goboScaleY);
            bw.Write(light.goboOffsetX);
            bw.Write(light.goboOffsetY);

            if (light.goboTexture != null)
            {
                int nameLength = light.goboTexture.Length;
                int padding = (((nameLength / 4) + (nameLength % 4 > 0 ? 1 : 0)) * 4) - nameLength;

                bw.Write(nameLength);
                bw.WriteString(light.goboTexture);
                bw.Write(new byte[padding]);
            }
            else
            {
                bw.Write(0);
            }
        }
コード例 #25
0
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.Write((short)SkeletonFiles.Count);

            SkeletonFiles.ForEach(file => {
                writer.WriteString(file);
                writer.Write((byte)0);
            });

            writer.Write((short)MotionFiles.Count);

            MotionFiles.ForEach(file => {
                writer.WriteString(file);
                writer.Write((byte)0);
            });

            writer.Write((short)EffectFiles.Count);

            EffectFiles.ForEach(file => {
                writer.WriteString(file);
                writer.Write((byte)0);
            });

            writer.Write((short)Characters.Count);

            Characters.ForEach(character => {
                writer.Write(character.IsEnabled);

                if (character.IsEnabled) {
                    writer.Write(character.ID);
                    writer.WriteString(character.Name);
                    writer.Write((byte)0);

                    writer.Write((short)character.Objects.Count);

                    character.Objects.ForEach(@object => {
                        writer.Write(@object.Object);
                    });

                    writer.Write((short)character.Animations.Count);

                    character.Animations.ForEach(animation => {
                        writer.Write((short)animation.Type);
                        writer.Write(animation.Animation);
                    });

                    writer.Write((short)character.Effects.Count);

                    character.Effects.ForEach(effect => {
                        writer.Write(effect.Bone);
                        writer.Write(effect.Effect);
                    });
                }
            });
        }
コード例 #26
0
ファイル: BoneFile.cs プロジェクト: Jiwan/Revise
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.WriteString(FILE_IDENTIFIER_3);
            writer.Write(Bones.Count);

            Bones.ForEach(bone => {
                writer.Write(bone.Parent);
                writer.WriteString(bone.Name);
                writer.Write((byte)0);
                writer.Write(bone.Translation);
                writer.Write(bone.Rotation, true);
            });

            writer.Write(DummyBones.Count);

            DummyBones.ForEach(dummy => {
                writer.WriteString(dummy.Name);
                writer.Write(dummy.Parent);
                writer.Write((byte)0);
                writer.Write(dummy.Translation);
                writer.Write(dummy.Rotation, true);
            });
        }