Exemple #1
0
        public static Vector3 ToVector3(uint vec, int intPart = 0, int fracPart = 9)
        {
            var buffer = new byte[] { 0x00, 0x00 };
            var coords = new[] { (ushort)(vec & 0x3FF), (ushort)((vec >> 10) & 0x3FF), (ushort)((vec >> 20) & 0x3FF) };

            var m = new MemoryStream(buffer);

            var ew = new EndianBinaryWriterEx(m, Endianness.LittleEndian);
            var er = new EndianBinaryReaderEx(m, Endianness.LittleEndian);

            ew.Write(coords[0]);
            m.Position = 0;
            float x = er.ReadFixedPoint(true, intPart, fracPart);

            m.Position = 0;
            ew.Write(coords[1]);
            m.Position = 0;
            float y = er.ReadFixedPoint(true, intPart, fracPart);

            m.Position = 0;
            ew.Write(coords[2]);
            m.Position = 0;
            float z = er.ReadFixedPoint(true, intPart, fracPart);

            m.Close();

            return(x, y, z);
        }
Exemple #2
0
        public static byte[] StringDataToBytes(string text)
        {
            var split = Regex.Replace(Regex.Replace(text, @"(\\.)", " "), @"\s+", " ").Trim().Split(' ');

            var m  = new MemoryStream();
            var ew = new EndianBinaryWriterEx(m, Endianness.LittleEndian);

            foreach (var value in split)
            {
                switch (value.Length)
                {
                case 2:
                    ew.Write(byte.Parse(value, NumberStyles.HexNumber));
                    break;

                case 4:
                    ew.Write(ushort.Parse(value, NumberStyles.HexNumber));
                    break;

                case 8:
                    ew.Write(uint.Parse(value, NumberStyles.HexNumber));
                    break;
                }
            }

            var bytes = m.ToArray();

            m.Close();

            return(bytes);
        }
 public override void Write(EndianBinaryWriterEx ew)
 {
     ew.Write(CourseID);
     ew.Write(Class);
     ew.Write(CPUDifficulty);
     ew.WritePadding(4);
 }
 public void Write(EndianBinaryWriterEx ew)
 {
     ew.Write(Signature, Encoding.ASCII, false);
     ew.Write(FileSize);
     ew.Write(FILE_VERSION);
     ew.Write(SectionTableOffset);
     ew.Write(SectionsOffset);
 }
Exemple #5
0
 public void Write(EndianBinaryWriterEx ew)
 {
     ew.Write(columnsCount);
     ew.Write(rowsCount);
     for (int i = 0; i < items.Length; i++)
     {
         items[i].Write(ew);
     }
 }
 public override void Write(EndianBinaryWriterEx ew)
 {
     ew.Write((UInt32)DriverAmount);
     for (uint i = 0; i < DriverAmount; i++)
     {
         for (uint j = 0; j < 4; j++)
         {
             ew.Write(DriverChoices[i][j]);
         }
     }
     ew.WritePadding(4);
 }
Exemple #7
0
        public byte[] Write()
        {
            var m  = new MemoryStream();
            var ew = new EndianBinaryWriterEx(m, Endianness.LittleEndian);

            ew.Write(amountsOfTables);

            foreach (var itemTable in itemTableRace)
            {
                itemTable.Write(ew);
            }
            foreach (var itemTableSpecialItemBox in itemTableSpecialItemBox)
            {
                itemTableSpecialItemBox.Write(ew);
            }
            foreach (var itemTableBalloon in itemTableBalloon)
            {
                itemTableBalloon.Write(ew);
            }
            foreach (var itemTableShine in itemTableShine)
            {
                itemTableShine.Write(ew);
            }

            byte[] result = m.ToArray();
            ew.Close();
            return(result);
        }
            public override void Write(EndianBinaryWriterEx ew)
            {
                EndianBinaryWriterEx tempWritter = new EndianBinaryWriterEx(new MemoryStream(), Endianness.LittleEndian); // I don't know how else I can do this without a hardcoded size...

                tempWritter.Write(new ushort());                                                                          // offsetPlayer
                tempWritter.Write(new ushort());                                                                          // offsetCPU
                tempWritter.Write(new byte());                                                                            // Mode
                tempWritter.Write(new byte());                                                                            // SpawnItemBoxes
                tempWritter.WritePadding(4);

                UInt16 baseOffset = (UInt16)tempWritter.BaseStream.Position;
                EndianBinaryWriterEx sectionWritter = new EndianBinaryWriterEx(new MemoryStream(), Endianness.LittleEndian);

                if (Mode == ItemMode.Custom)
                {
                    UInt16 offsetPlayer = baseOffset, offsetCPU = baseOffset;

                    offsetPlayer += (UInt16)sectionWritter.BaseStream.Position;
                    PlayerConfig.Write(sectionWritter);

                    offsetCPU += (UInt16)sectionWritter.BaseStream.Position;
                    CPUConfig.Write(sectionWritter);

                    ew.Write(offsetPlayer);                  // offsetPlayer
                    ew.Write(offsetCPU);                     // offsetCPU
                    ew.Write((byte)Mode);
                    ew.Write((byte)(SpawnItemBoxes ? 1 : 0));
                    ew.WritePadding(4);
                    ew.Write((sectionWritter.BaseStream as MemoryStream).ToArray(), 0, (int)sectionWritter.BaseStream.Length);
                }
                else
                {
                    ew.Write((ushort)0xFFFF);                     // offsetPlayer
                    ew.Write((ushort)0xFFFF);                     // offsetCPU
                    ew.Write((byte)Mode);
                    ew.Write((byte)(SpawnItemBoxes ? 1 : 0));
                    ew.WritePadding(4);
                }

                ew.WritePadding(4);

                return;
            }
        public byte[] Write()
        {
            if (Viewer != null)
            {
                Viewer.SaveData();
            }

            EndianBinaryWriterEx sectionWritter = new EndianBinaryWriterEx(new MemoryStream(), Endianness.LittleEndian);
            List <Tuple <BaseSection.SectionType, UInt32> > sectionOffsets = new List <Tuple <BaseSection.SectionType, UInt32> >();

            foreach (var section in Sections)
            {
                sectionOffsets.Add(Tuple.Create(section.GetSectionType(), (UInt32)sectionWritter.BaseStream.Position));
                section.Write(sectionWritter);
            }

            EndianBinaryWriterEx sectionTableWritter = new EndianBinaryWriterEx(new MemoryStream(), Endianness.LittleEndian);

            sectionTableWritter.Write((UInt32)Sections.Count);
            foreach (var section in sectionOffsets)
            {
                sectionTableWritter.Write((UInt32)section.Item1);
                sectionTableWritter.Write((UInt32)section.Item2);
            }

            Header.FileSize           = (uint)(CMSNHeader.HeaderSize + sectionTableWritter.BaseStream.Length + sectionWritter.BaseStream.Length);
            Header.SectionTableOffset = (UInt16)CMSNHeader.HeaderSize;
            Header.SectionsOffset     = (uint)(Header.SectionTableOffset + sectionTableWritter.BaseStream.Length);

            EndianBinaryWriterEx ew = new EndianBinaryWriterEx(new MemoryStream(), Endianness.LittleEndian);

            Header.Write(ew);
            ew.Write((sectionTableWritter.BaseStream as MemoryStream).ToArray(), 0, (int)sectionTableWritter.BaseStream.Length);
            ew.Write((sectionWritter.BaseStream as MemoryStream).ToArray(), 0, (int)sectionWritter.BaseStream.Length);

            return((ew.BaseStream as MemoryStream).ToArray());
        }
 public void Write(EndianBinaryWriterEx ew)
 {
     ew.Write((UInt16)RouletteSpeed.Frames);
     ew.Write((UInt16)GiveItemOffset.Frames);
     ew.Write((UInt16)GiveItemEach.Frames);
     ew.Write(GiveItemID);
     ew.Write((byte)ConfigMode);
     for (int i = 0; i < Probabilities.Length; i++)
     {
         for (int j = 0; j < Probabilities[i].Length; j++)
         {
             ew.Write(Probabilities[i][j]);
         }
     }
     ew.WritePadding(4);
 }
 public virtual void Write(EndianBinaryWriterEx ew)
 {
     ew.Write((byte)(((byte)Type & 0x1F) | (Option << 5)));
     ew.Write(Params.ToArray(), 0, Params.Count);
 }
Exemple #12
0
        public static byte[] Encode(IEnumerable <DisplayListCommand> commands)
        {
            var m  = new MemoryStream();
            var ew = new EndianBinaryWriterEx(m, Endianness.LittleEndian);

            int offset = 0;
            int packed = 0;

            var cmdList = commands.ToList();

            var nops = (cmdList.Count % 4) == 0 ? 0 : 4 - (cmdList.Count % 4);

            //Add NOPs at the end
            for (int i = 0; i < nops; i++)
            {
                cmdList.Add(new DisplayListCommand(G3dCommand.Nop));
            }

            var commandQueue = new Queue <DisplayListCommand>();

            bool param0Flag = false;

            void Flush()
            {
                packed = 0;

                var count = commandQueue.Count;

                for (int i = 0; i < count; i++)
                {
                    var cmd = commandQueue.Dequeue();

                    //m.Position = offset;

                    switch (cmd.G3dCommand)
                    {
                    default:
                    case G3dCommand.Identity:
                    case G3dCommand.PushMatrix:
                    case G3dCommand.End:
                    case G3dCommand.Nop:
                        break;

                    case G3dCommand.TexCoord:
                        ew.WriteFixedPoint(cmd.RealArgs[0], true, 11, 4);
                        ew.WriteFixedPoint(cmd.RealArgs[1], true, 11, 4);
                        offset += 4;
                        break;

                    case G3dCommand.VertexXY:
                    case G3dCommand.VertexXZ:
                    case G3dCommand.VertexYZ:
                        ew.WriteFx16s(cmd.RealArgs);
                        offset += 4;
                        break;

                    case G3dCommand.Begin:
                    case G3dCommand.RestoreMatrix:
                        ew.Write(cmd.IntArgs[0]);
                        offset += 4;
                        break;

                    case G3dCommand.VertexDiff:
                        var vec2 = VecFx10.FromVector3((cmd.RealArgs[0] * 8, cmd.RealArgs[1] * 8,
                                                        cmd.RealArgs[2] * 8));
                        ew.Write(vec2);
                        offset += 4;
                        break;

                    case G3dCommand.VertexShort:
                        var vec3 = VecFx10.FromVector3((cmd.RealArgs[0], cmd.RealArgs[1], cmd.RealArgs[2]), 3,
                                                       6);
                        ew.Write(vec3);
                        offset += 4;
                        break;

                    case G3dCommand.Normal:
                        var vec = VecFx10.FromVector3((cmd.RealArgs[0], cmd.RealArgs[1], cmd.RealArgs[2]));
                        ew.Write(vec);
                        offset += 4;
                        break;

                    case G3dCommand.Color:
                        var color = GFXUtil.ConvertColorFormat(
                            (uint)Color.FromArgb(0, (int)cmd.IntArgs[0], (int)cmd.IntArgs[1],
                                                 (int)cmd.IntArgs[2]).ToArgb(),
                            ColorFormat.ARGB8888, ColorFormat.ABGR1555);
                        ew.Write(color);
                        offset += 4;
                        break;

                    case G3dCommand.Vertex:
                        ew.WriteFx16s(cmd.RealArgs);
                        ew.Write((ushort)0);
                        offset += 8;
                        break;
                    }
                }

                if (param0Flag)
                {
                    ew.Write(0);
                    offset += 4;

                    param0Flag = false;
                }
            }

            foreach (var command in cmdList)
            {
                if (command.G3dCommand != G3dCommand.Nop)
                {
                    param0Flag = packed > 0 && (command.G3dCommand == G3dCommand.Identity ||
                                                command.G3dCommand == G3dCommand.PushMatrix ||
                                                command.G3dCommand == G3dCommand.End);
                }

                //m.Position = offset;

                commandQueue.Enqueue(command);
                ew.Write((byte)command.G3dCommand);
                packed++;
                offset++;

                if (packed == 4)
                {
                    Flush();
                }
            }

            var dl = m.ToArray();

            m.Close();

            return(dl);
        }
Exemple #13
0
 public override void Write(EndianBinaryWriterEx ew)
 {
     ew.Write(balloons, 0, 0x03);
 }
Exemple #14
0
 public override void Write(EndianBinaryWriterEx ew)
 {
     ew.Write(positions, 0, 0x08);
 }
Exemple #15
0
 public override void Write(EndianBinaryWriterEx ew)
 {
     ew.Write(itemboxes, 0, 0x10);
 }
Exemple #16
0
 public override void Write(EndianBinaryWriterEx ew)
 {
     ew.Write(shines, 0, 0x03);
 }