/// <summary>
        /// Creates a new purchasable outfit.
        /// </summary>
        /// <param name="Str">The stream used to create the purchasable outfit from.</param>
        public PurchasableOutfit(Stream Str)
        {
            using (IoBuffer Reader = new IoBuffer(Str))
            {
                Reader.ByteOrder = ByteOrder.BIG_ENDIAN;

                m_Version = Reader.ReadUInt32();
                m_Gender = Reader.ReadUInt32();
                m_AssetIDSize = Reader.ReadUInt32();

                Reader.ReadUInt32(); //AssetID prefix... typical useless Maxis value.

                m_OutfitAssetID = Reader.ReadUInt64();
            }
        }
Exemplo n.º 2
0
        private Bone ReadBone(IoBuffer reader)
        {
            var bone = new Bone();
            bone.Unknown = reader.ReadInt32();
            bone.Name = reader.ReadPascalString();
            bone.ParentName = reader.ReadPascalString();
            bone.HasProps = reader.ReadByte();
            if (bone.HasProps != 0)
            {
                var propertyCount = reader.ReadInt32();
                var property = new PropertyListItem();

                for (var i = 0; i < propertyCount; i++)
                {
                    var pairCount = reader.ReadInt32();
                    for (var x = 0; x < pairCount; x++)
                    {
                        property.KeyPairs.Add(new KeyValuePair<string, string>(
                            reader.ReadPascalString(),
                            reader.ReadPascalString()
                        ));
                    }
                }
                bone.Properties.Add(property);
            }

            var xx = -reader.ReadFloat();
            bone.Translation = new Vector3(
                xx,
                reader.ReadFloat(),
                reader.ReadFloat()
            );
            bone.Rotation = new Vector4(
                reader.ReadFloat(),
                -reader.ReadFloat(),
                -reader.ReadFloat(),
                reader.ReadFloat()
            );
            bone.CanTranslate = reader.ReadInt32();
            bone.CanRotate = reader.ReadInt32();
            bone.CanBlend = reader.ReadInt32();
            bone.WiggleValue = reader.ReadFloat();
            bone.WigglePower = reader.ReadFloat();
            return bone;
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //tcp
//            var acceptor = new AsyncSocketAcceptor();
//            acceptor.FilterChain.AddLast("logger", new LoggingFilter());

            //udp
            var acceptor = new AsyncDatagramAcceptor();

            acceptor.SessionConfig.ReuseAddress = true;


            acceptor.Activated       += (s, e) => Console.WriteLine("ACTIVATED");
            acceptor.Deactivated     += (s, e) => Console.WriteLine("DEACTIVATED");
            acceptor.SessionCreated  += (s, e) => e.Session.Config.SetIdleTime(IdleStatus.BothIdle, 10);
            acceptor.SessionOpened   += (s, e) => Console.WriteLine("OPENED");
            acceptor.SessionClosed   += (s, e) => Console.WriteLine("CLOSED");
            acceptor.SessionIdle     += (s, e) => Console.WriteLine("*** IDLE #" + e.Session.GetIdleCount(IdleStatus.BothIdle) + " ***");
            acceptor.ExceptionCaught += (s, e) =>
            {
                Console.WriteLine(e.Exception);
                e.Session.Close(true);
            };
            acceptor.MessageReceived += (s, e) =>
            {
                var income = (IoBuffer)e.Message;
//                var resvData = income.GetInt64();
//                Console.WriteLine("Received : " + resvData);
//                var outcome = IoBuffer.Allocate(income.Capacity);
//                outcome.PutInt64(resvData);

                var msg = income.Duplicate().GetString(Encoding.UTF8);
                Console.WriteLine("Received : " + msg);

                var outcome = IoBuffer.Allocate(income.Capacity);
                outcome.Put(income);
                outcome.Flip();
                e.Session.Write(outcome);
            };

            acceptor.Bind(new IPEndPoint(IPAddress.Any, Port));
            Console.WriteLine("UDPServer listening on port " + Port);
            Console.ReadLine();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Reads a SPR2 chunk from a stream.
        /// </summary>
        /// <param name="iff">An Iff instance.</param>
        /// <param name="stream">A Stream object holding a SPR2 chunk.</param>
        public override void Read(IffFile iff, Stream stream)
        {
            using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
            {
                var  version     = io.ReadUInt32();
                uint spriteCount = 0;

                if (version == 1000)
                {
                    spriteCount      = io.ReadUInt32();
                    DefaultPaletteID = io.ReadUInt32();
                    var offsetTable = new uint[spriteCount];
                    for (var i = 0; i < spriteCount; i++)
                    {
                        offsetTable[i] = io.ReadUInt32();
                    }

                    Frames = new SPR2Frame[spriteCount];
                    for (var i = 0; i < spriteCount; i++)
                    {
                        var frame = new SPR2Frame(this);
                        io.Seek(SeekOrigin.Begin, offsetTable[i]);

                        var guessedSize = ((i + 1 < offsetTable.Length) ? offsetTable[i + 1] : (uint)stream.Length) - offsetTable[i];

                        frame.Read(version, io, guessedSize);
                        Frames[i] = frame;
                    }
                }
                else if (version == 1001)
                {
                    DefaultPaletteID = io.ReadUInt32();
                    spriteCount      = io.ReadUInt32();

                    Frames = new SPR2Frame[spriteCount];
                    for (var i = 0; i < spriteCount; i++)
                    {
                        var frame = new SPR2Frame(this);
                        frame.Read(version, io, 0);
                        Frames[i] = frame;
                    }
                }
            }
        }
Exemplo n.º 5
0
    void Start()
    {
        if (FileHelper.BeFileExists(OutputURL))
        {
            File.Delete(OutputURL);
        }

        byte[] bs = FileHelper.Get(InputURL);

        Log.i("bs.len:" + bs.Length);

        IoBuffer buffer = new IoBuffer(1000000);

        buffer.PutBytes(bs);

        int dataNum = buffer.GetInt();

        FileHelper.WriteMessage(OutputURL, "数据条数:" + dataNum);

        do
        {
            if (BeTest)
            {
                string key = buffer.GetString();//key

                //这句代表一个treeItem的开头
                if (key.Equals("ID"))
                {
                    FileHelper.WriteMessage(OutputURL, "----------------分割线---------------");
                }
                string value = buffer.GetString(); //value
                string type  = buffer.GetString(); //type
                string s     = "[" + key + "][" + value + "][" + type + "]";
                FileHelper.WriteMessage(OutputURL, s);
            }
            else
            {
                string value1 = buffer.GetString();
                FileHelper.WriteMessage(OutputURL, value1);
            }
        }while (buffer.HasData());

        Log.i("数据查看器生成数据完毕");
    }
Exemplo n.º 6
0
        void OnLevelFight(TestServerSocket socket, IoBuffer s)
        {
            IoBuffer outStream = socket.GetStream();
            TestRole role      = socket.m_hero;

            int           levelId   = s.ReadInt32();
            TestLevelInfo levelInfo = role.m_levelPart.m_levelInfos.Get(levelId);

            //检查开没开启
            if (levelInfo == null && levelId != 1 && role.m_levelPart.m_levelInfos.Get(levelId - 1) == null)
            {
                Debuger.LogError("关卡没有开启");
                outStream.Write(false);
                socket.Send(TestMSG.TMSG_LEVEL, TMSG_LEVEL.FIGHT_OVER, outStream);
                return;
            }

            //检查今天的挑战数
            if (levelInfo != null && levelInfo.EnterCount >= 5)
            {
                Debuger.LogError("每天只能挑战5次");
                outStream.Write(false);
                socket.Send(TestMSG.TMSG_LEVEL, TMSG_LEVEL.FIGHT_OVER, outStream);
                return;
            }

            //挑战次数加一
            if (levelInfo == null)
            {
                levelInfo = new TestLevelInfo();
                levelInfo.levelId.Value = levelId;
                role.m_levelPart.m_levelInfos[levelId] = levelInfo;
            }
            levelInfo.star.Value = Mathf.Max((int)levelInfo.star, Random.Range(1, 3));
            levelInfo.Add();

            //给奖励,50金币,1把武器
            role.m_propPart.Add(enTestProp.gold, 50);
            role.m_bagPart.Add(Random.Range(0, 2), 1);

            outStream.Write(true);
            socket.Send(TestMSG.TMSG_LEVEL, TMSG_LEVEL.FIGHT_OVER, outStream);
        }
Exemplo n.º 7
0
        public void Serialize(IoBuffer output, ISerializationContext context)
        {
            output.PutUInt32((uint)Items.Count);
            foreach (var item in Items)
            {
                output.Put(item.Rank);

                if (item.TargetId != null && item.TargetId.HasValue)
                {
                    output.PutBool(true);
                    output.PutUInt32(item.TargetId.Value);
                    output.PutPascalVLCString(item.TargetName);
                }
                else
                {
                    output.PutBool(false);
                }
            }
        }
Exemplo n.º 8
0
        public void Serialize(IoBuffer output, object value, ISerializationContext context, bool clsIdPrefix)
        {
            if (value == null)
            {
                return;
            }
            var serializer = GetSerializer(value.GetType());

            if (serializer == null)
            {
                return;
            }

            if (clsIdPrefix)
            {
                output.PutUInt32(serializer.GetClsid(value).Value);
            }
            serializer.Serialize(output, value, context);
        }
Exemplo n.º 9
0
        public void Read(byte[] bytes)
        {
            using (var io = IoBuffer.FromBytes(bytes, ByteOrder.LITTLE_ENDIAN)){
                this.GUID = io.ReadUInt32();
                //132 was object of type
                this.Flags       = io.ReadByte();
                this.TargetOwner = (VMVariableScope)io.ReadByte();
                this.Local       = io.ReadByte();
                this.TargetData  = io.ReadByte();

                if ((Flags & 0x80) == 0)
                {
                    //clobber this, we should always set flag for saving.
                    Flags      |= 0x80;
                    TargetOwner = VMVariableScope.StackObjectID;
                    TargetData  = 0;
                }
            }
        }
Exemplo n.º 10
0
        //no difference!

        public override void Read(IffFile iff, Stream stream)
        {
            using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
            {
                var    zero    = io.ReadInt32();
                var    version = io.ReadInt32();    //2 in tso
                string magic   = io.ReadCString(4); //NSCF
                var    count   = io.ReadInt32();

                LanguageSets[0].Strings = new STRItem[count];
                for (int i = 0; i < count; i++)
                {
                    string name, desc;
                    float  value;
                    if (version == 2)
                    {
                        name  = io.ReadVariableLengthPascalString();
                        value = io.ReadFloat();
                        desc  = io.ReadVariableLengthPascalString();
                    }
                    else
                    {
                        name = io.ReadNullTerminatedString();
                        if (name.Length % 2 == 0)
                        {
                            io.ReadByte();                       //padding to 2 byte align
                        }
                        value = io.ReadFloat();
                        desc  = io.ReadNullTerminatedString();
                        if (desc.Length % 2 == 0)
                        {
                            io.ReadByte();                       //padding to 2 byte align
                        }
                    }

                    LanguageSets[0].Strings[i] = new STRItem()
                    {
                        Value   = name + ": " + value,
                        Comment = desc
                    };
                }
            }
        }
Exemplo n.º 11
0
        public void Deserialize(IoBuffer input, ISerializationContext context)
        {
            Unknown1  = input.GetUInt32();
            MessageId = input.GetUInt32();
            Unknown2  = input.GetUInt32();

            var vectorSize = input.GetUInt32();

            DotPath = new uint[vectorSize];
            for (int i = 0; i < vectorSize; i++)
            {
                DotPath[i] = input.GetUInt32();
            }

            var valueType = input.GetUInt32();

            this.Value = context.ModelSerializer.Deserialize(valueType, input, context);
            //this.ReasonText = input.GetPascalVLCString();
        }
Exemplo n.º 12
0
        public IDecodingState Decode(IoBuffer input, IProtocolDecoderOutput output)
        {
            while (input.HasRemaining)
            {
                switch (_counter)
                {
                case 0:
                    _highByte = input.Get() & 0xff;
                    break;

                case 1:
                    _counter = 0;
                    return(FinishDecode((Int16)((_highByte << 8) | (input.Get() & 0xff)), output));
                }

                _counter++;
            }
            return(this);
        }
Exemplo n.º 13
0
        public DGRP3DMesh(DGRP dgrp, Stream source, GraphicsDevice gd)
        {
            using (var cstream = new GZipStream(source, CompressionMode.Decompress))
            {
                using (var io = IoBuffer.FromStream(cstream, ByteOrder.LITTLE_ENDIAN))
                {
                    var fsom = io.ReadCString(4);
                    Version            = io.ReadInt32();
                    ReconstructVersion = io.ReadInt32();
                    if (ReconstructVersion != 0 && ReconstructVersion < CURRENT_RECONSTRUCT)
                    {
                        throw new Exception("Reconstruction outdated, must be rerun!");
                    }
                    Name = io.ReadPascalString();

                    var geomCount = io.ReadInt32();
                    Geoms = new List <Dictionary <Texture2D, DGRP3DGeometry> >();
                    for (int i = 0; i < geomCount; i++)
                    {
                        var d        = new Dictionary <Texture2D, DGRP3DGeometry>();
                        var subCount = io.ReadInt32();
                        for (int j = 0; j < subCount; j++)
                        {
                            var geom = new DGRP3DGeometry(io, dgrp, gd, Version);
                            if (geom.Pixel == null && geom.PrimCount > 0)
                            {
                                throw new Exception("Invalid Mesh! (old format)");
                            }
                            d.Add(geom.Pixel, geom);
                        }
                        Geoms.Add(d);
                    }

                    var x  = io.ReadFloat();
                    var y  = io.ReadFloat();
                    var z  = io.ReadFloat();
                    var x2 = io.ReadFloat();
                    var y2 = io.ReadFloat();
                    var z2 = io.ReadFloat();
                    Bounds = new BoundingBox(new Vector3(x, y, z), new Vector3(x2, y2, z2));
                }
            }
        }
Exemplo n.º 14
0
        //玩家操作
        void DrawHandle()
        {
            TestPropertyPart prop  = m_hero.m_propPart;
            TestBagPart      bag   = m_hero.m_bagPart;
            TestTaskPart     task  = m_hero.m_taskPart;
            TestLevelPart    level = m_hero.m_levelPart;


            using (new AutoBeginHorizontal(GUILayout.Height(150)))
            {
                //重命名
                using (new AutoBeginVertical())
                {
                    inputName = GUILayout.TextField(inputName, GUILayout.Width(150));
                    if (GUILayout.Button("改名字", GUILayout.Width(50)))
                    {
                        IoBuffer s = m_socket.GetStream();
                        s.Write(inputName);
                        m_socket.Send(TestMSG.TMSG_ROLE, TMSG_ROLE.RENAME, s);
                    }
                }

                //任务操作


                //关卡操作
                using (new AutoBeginVertical())
                {
                    if (GUILayout.Button("挑战关卡1", GUILayout.Width(70)))
                    {
                        IoBuffer s = m_socket.GetStream();
                        s.Write(1);
                        m_socket.Send(TestMSG.TMSG_LEVEL, TMSG_LEVEL.FIGHT_OVER, s);
                    }
                    if (GUILayout.Button("挑战关卡2", GUILayout.Width(70)))
                    {
                        IoBuffer s = m_socket.GetStream();
                        s.Write(2);
                        m_socket.Send(TestMSG.TMSG_LEVEL, TMSG_LEVEL.FIGHT_OVER, s);
                    }
                }
            }
        }
Exemplo n.º 15
0
    /// <summary>
    /// 接受dialog返回数据
    /// </summary>
    /// <param name="bs">Bs.</param>
    private void OnDialogReturnValue(byte[] bs)
    {
        IoBuffer _ib = new IoBuffer();

        _ib.PutBytes(bs);

        string _key   = _ib.GetString();            //从输入框返回要修改的key值
        string _value = _ib.GetString();            //从输入框返回的要修改的value值
        string _type  = _ib.GetString();            //从输入框返回的修改类型值,比如字符串类型,或者列表类型

        string _TreeItemIDStr = TreeItemID.ToString();

        //Log.i("KVListItem", "OnDialogReturnValue", "=======>iNDEX:" + Index, BeShowLog);

        _MyKVContainer.ModifyKVItem(_TreeItemIDStr, Index, _key, _value, _type);

        _ib.Clear();
        _ib = null;
    }
Exemplo n.º 16
0
        /// <inheritdoc/>
        protected override IoBuffer GetNextBuffer(System.IO.Stream stream)
        {
            Byte[] bytes = new Byte[WriteBufferSize];

            Int32 off = 0;
            Int32 n   = 0;

            while (off < bytes.Length && (n = stream.Read(bytes, off, bytes.Length - off)) > 0)
            {
                off += n;
            }

            if (n <= 0 && off == 0)
            {
                return(null);
            }

            return(IoBuffer.Wrap(bytes, 0, off));
        }
Exemplo n.º 17
0
        public void Read(Stream stream)
        {
            using (var io = IoBuffer.FromStream(stream)){
                var version = io.ReadUInt32();

                ThumbnailFileID = io.ReadUInt32();
                ThumbnailTypeID = io.ReadUInt32();

                var numBindings = io.ReadUInt32();
                Bindings = new AppearanceBinding[numBindings];

                for (var i = 0; i < numBindings; i++){
                    Bindings[i] = new AppearanceBinding {
                        FileID = io.ReadUInt32(),
                        TypeID = io.ReadUInt32()
                    };
                }
            }
        }
Exemplo n.º 18
0
 public override void Serialize(IoBuffer output, ISerializationContext context)
 {
     output.PutEnum(Type);
     output.PutInt32(Messages.Length);
     foreach (var msg in Messages)
     {
         byte[] dat;
         using (var str = new MemoryStream())
         {
             msg.Save(str);
             dat = str.ToArray();
         }
         output.PutInt32(dat.Length);
         foreach (var b in dat)
         {
             output.Put(b);
         }
     }
 }
Exemplo n.º 19
0
        private void BeginSend()
        {
            IWriteRequest req = CurrentWriteRequest;

            if (req == null)
            {
                req = WriteRequestQueue.Poll(this);

                if (req == null)
                {
                    Interlocked.Exchange(ref _writing, 0);
                    return;
                }

                CurrentWriteRequest = req;
            }

            IoBuffer buf = req.Message as IoBuffer;

            if (buf == null)
            {
                IFileRegion file = req.Message as IFileRegion;
                if (file == null)
                {
                    EndSend(new InvalidOperationException("Don't know how to handle message of type '"
                                                          + req.Message.GetType().Name + "'.  Are you missing a protocol encoder?"),
                            true);
                }
                else
                {
                    BeginSendFile(req, file);
                }
            }
            else if (buf.HasRemaining)
            {
                BeginSend(req, buf);
            }
            else
            {
                EndSend(0);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Processes receive events.
        /// </summary>
        /// <param name="e"></param>
        public void ProcessReceive(SocketAsyncEventArgs e)
        {
            if (e.SocketError == SocketError.Success)
            {
                if (e.BytesTransferred > 0)
                {
                    _readBuffer.Position = e.BytesTransferred;
                    _readBuffer.Flip();

                    if (ReuseBuffer)
                    {
                        EndReceive(_readBuffer);
                    }
                    else
                    {
                        IoBuffer buf = IoBuffer.Allocate(_readBuffer.Remaining);
                        buf.Put(_readBuffer);
                        buf.Flip();
                        EndReceive(buf);
                    }

                    return;
                }
                else
                {
                    // closed
                    //Processor.Remove(this);
                    this.FilterChain.FireInputClosed();
                }
            }
            else if (e.SocketError != SocketError.OperationAborted &&
                     e.SocketError != SocketError.Interrupted &&
                     e.SocketError != SocketError.ConnectionReset)
            {
                EndReceive(new SocketException((Int32)e.SocketError));
            }
            else
            {
                // closed
                Processor.Remove(this);
            }
        }
Exemplo n.º 21
0
        public Po(byte[] data)
        {
            this.saveData = new Dictionary <object, object>();
            Init();
            if (data == null)
            {
                return;
            }
            IoBuffer buffer = new IoBuffer();

            buffer.Write(data, 0, data.Length);
            IoBufferReader rd = new IoBufferReader(buffer);
            Dictionary <object, object> saveData = (Dictionary <object, object>)rd.Read();

            if (saveData == null)
            {
                return;
            }
            ReadData(saveData);
        }
Exemplo n.º 22
0
 public int DeCode(Session session, OnPackageRev handler)
 {
     try
     {
         IoBuffer       buffer = session.ReceiveBuffer;
         IoBufferReader reader = new IoBufferReader(buffer);
         reader.readInt();
         int cmd = reader.readInt();
         Dictionary <object, object> param = (Dictionary <object, object>)reader.Read();
         Msg msg = new Msg(cmd);
         msg.ParamMap = param;
         handler(msg);
         return(OK);
     }
     catch (Exception e)
     {
         logReport.OnWarningReport("decode not ok,protocal erro,ex:" + e.StackTrace);
         return(NOT_OK);
     }
 }
Exemplo n.º 23
0
        public override void Serialize(IoBuffer output, ISerializationContext context)
        {
            output.PutBool(NominationMode);
            output.PutInt32(Candidates.Count);

            foreach (var candidate in Candidates)
            {
                output.PutUInt32(candidate.ID);
                output.PutPascalVLCString(candidate.Name);
                output.PutUInt32(candidate.Rating);

                if (!NominationMode)
                {
                    output.PutPascalVLCString(candidate.LastNhoodName);
                    output.PutUInt32(candidate.LastNhoodID);
                    output.PutUInt32(candidate.TermNumber);
                    output.PutPascalVLCString(candidate.Message);
                }
            }
        }
Exemplo n.º 24
0
    public void ReName()
    {
        //base.ReName ();
        InputTextDialog.Open(
            delegate(byte[] bts)
        {
            //创建文件夹
            IoBuffer ib = new IoBuffer();
            ib.PutBytes(bts);
            string newName = ib.GetString();
            Name           = newName;//这个名称不设置的化,当重命名后,再复制黏贴就出问题,显示的是未改名前的名称
            ResizeTextRect(newName);

            //刷TreeContainer的W.这里w的算法,跟上面Create中一致
            float _w = this.CurItemLeftOffset + UIEnum.ItemImageW + 4 + UIEnum.ItemImageW + Tools.GetStringW(this.ItemNameText.text, UIEnum.FontSize);
            MyTreeContainer.SetTreeW(_w);
            MyTreeContainer.RefreshTreeArea();
        }
            );
    }
        public override void Serialize(IoBuffer output, object value, ISerializationContext context)
        {
            IList list        = (IList)value;
            var   genericType = value.GetType().GetGenericArguments()[0];

            var _struct = GetStruct(genericType);

            if (_struct == null)
            {
                throw new Exception("Unable to map " + genericType + " to a tso struct");
            }

            output.PutUInt32((uint)list.Count);

            foreach (var item in list)
            {
                var property = ConvertToProperty(_struct, item, context);
                property.Serialize(output, context);
            }
        }
Exemplo n.º 26
0
            public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
            {
                _counter++;

                IoBuffer buf = writeRequest.Message as IoBuffer;

                if (buf == null)
                {
                    throw new AssertFailedException("Wrong message type");
                }
                if (_counter == 3)
                {
                    Assert.AreEqual(1, buf.Limit);
                    Assert.AreEqual(0, buf.Get());
                }
                else
                {
                    Assert.AreEqual(10, buf.Limit);
                }
            }
Exemplo n.º 27
0
            public void Write(IoBuffer buf)
            {
                if (_closed)
                {
                    return;
                }

                lock (_syncRoot)
                {
                    if (_buf.HasRemaining)
                    {
                        _buf.Compact().Put(buf).Flip();
                    }
                    else
                    {
                        _buf.Clear().Put(buf).Flip();
                        Monitor.PulseAll(_syncRoot);
                    }
                }
            }
            public override void MessageReceived(INextFilter nextFilter, IoSession session, Object message)
            {
                AbstractIoSession s = session as AbstractIoSession;

                if (s != null)
                {
                    IoBuffer buf = message as IoBuffer;
                    if (buf == null || !buf.HasRemaining)
                    {
                        s.IncreaseReadMessages(DateTime.Now);
                    }
                }

                // Update the statistics
                session.Service.Statistics.UpdateThroughput(DateTime.Now);

                // Propagate the message
                session.Handler.MessageReceived(session, message);
                // TODO IsUseReadOperation
            }
Exemplo n.º 29
0
        public void Read(Stream stream)
        {
            using (var reader = IoBuffer.FromStream(stream))
            {
                var magic = reader.ReadCString(4);
                Version  = reader.ReadInt32();
                ID       = reader.ReadUInt32();
                NhoodID  = reader.ReadUInt32();
                SenderID = reader.ReadUInt32();

                Subject    = reader.ReadLongPascalString();
                Body       = reader.ReadLongPascalString();
                SenderName = reader.ReadLongPascalString();
                Time       = reader.ReadInt64();
                Type       = (BulletinType)reader.ReadInt32();
                Flags      = (BulletinFlags)reader.ReadInt32();

                LotID = reader.ReadUInt32();
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Reads a SPRFrame from a stream.
        /// </summary>
        /// <param name="iff">An Iff instance.</param>
        /// <param name="stream">A Stream object holding a SPRFrame.</param>
        public void Read(uint version, IoBuffer io)
        {
            if (version == 1001)
            {
                var spriteFersion = io.ReadUInt32();
                var size          = io.ReadUInt32();
                this.Version = spriteFersion;
            }
            else
            {
                this.Version = version;
            }

            var reserved = io.ReadUInt32();
            var height   = io.ReadUInt16();
            var width    = io.ReadUInt16();

            this.Init(width, height);
            this.Decode(io);
        }
Exemplo n.º 31
0
 public object Deserialize(uint clsid, IoBuffer buffer)
 {
     if (cNetMessageParametersById.ContainsKey(clsid))
     {
         var instance = (IoBufferDeserializable)Activator.CreateInstance(cNetMessageParametersById[clsid]);
         //instance.Deserialize(buffer);
         return(instance);
     }
     else if (ClassesById.ContainsKey(clsid))
     {
         var instance = (IoBufferDeserializable)Activator.CreateInstance(ClassesById[clsid]);
         //instance.Deserialize(buffer);
         return(instance);
     }
     else if (clsid == cTSOValue_string)
     {
         return(buffer.GetPascalVLCString());
     }
     return(null);
 }
Exemplo n.º 32
0
        /// <summary>
        /// Reads an Outfit from the supplied Stream.
        /// </summary>
        /// <param name="stream">A Stream instance.</param>
        public void Read(Stream stream)
        {
            using (var io = IoBuffer.FromStream(stream))
            {
                var version = io.ReadUInt32();
                var unknown = io.ReadUInt32();

                LightAppearanceFileID = io.ReadUInt32();
                LightAppearanceTypeID = io.ReadUInt32();

                MediumAppearanceFileID = io.ReadUInt32();
                MediumAppearanceTypeID = io.ReadUInt32();

                DarkAppearanceFileID = io.ReadUInt32();
                DarkAppearanceTypeID = io.ReadUInt32();

                HandGroup = io.ReadUInt32();
                Region    = io.ReadUInt32();
            }
        }
Exemplo n.º 33
0
        private PropertyList ReadPropertyList(IoBuffer io)
        {
            var propsCount = io.ReadUInt32();
            var result = new PropertyListItem[propsCount];

            for (var y = 0; y < propsCount; y++)
            {
                var item = new PropertyListItem();
                var pairsCount = io.ReadUInt32();
                for (var z = 0; z < pairsCount; z++)
                {
                    item.KeyPairs.Add(new KeyValuePair<string, string>(
                        io.ReadPascalString(),
                        io.ReadPascalString()
                    ));
                }
                result[y] = item;
            }

            return new PropertyList
            {
                Items = result
            };
        }
Exemplo n.º 34
0
        private void Decode(IoBuffer io)
        {
            var y = 0;
            var endmarker = false;

            var hasPixels = (this.Flags & 0x01) == 0x01;
            var hasZBuffer = (this.Flags & 0x02) == 0x02;
            var hasAlpha = (this.Flags & 0x04) == 0x04;

            var numPixels = this.Width * this.Height;
            if (hasPixels)
            {
                this.PixelData = new Color[numPixels];
            }
            if (hasZBuffer)
            {
                this.ZBufferData = new byte[numPixels];
            }
            if (hasAlpha)
            {
                this.AlphaData = new byte[numPixels];
            }

            var palette = Parent.ChunkParent.Get<PALT>(this.PaletteID);
            var transparentPixel = palette.Colors[TransparentColorIndex];

            while (!endmarker)
            {
                var marker = io.ReadUInt16();
                var command = marker >> 13;
                var count = marker & 0x1FFF;

                switch (command)
                {
                    /** Fill with pixel data **/
                    case 0x00:
                        var bytes = count;
                        bytes -= 2;

                        var x = 0;

                        while (bytes > 0)
                        {
                            var pxMarker = io.ReadUInt16();
                            var pxCommand = pxMarker >> 13;
                            var pxCount = pxMarker & 0x1FFF;
                            bytes -= 2;

                            switch (pxCommand)
                            {
                                case 0x01:
                                case 0x02:
                                    var pxWithAlpha = pxCommand == 0x02;
                                    for (var col = 0; col < pxCount; col++)
                                    {
                                        var zValue = io.ReadByte();
                                        var pxValue = io.ReadByte();
                                        bytes -= 2;

                                        var pxColor = palette.Colors[pxValue];
                                        if (pxWithAlpha)
                                        {
                                            pxColor.A = io.ReadByte();
                                            bytes--;
                                        }
                                        else
                                        {
                                            if (pxColor.PackedValue == transparentPixel.PackedValue)
                                            {
                                                pxColor.A = 0;
                                            }
                                        }
                                        var offset = (y * Width) + x;
                                        this.PixelData[offset] = pxColor;
                                        this.ZBufferData[offset] = zValue;
                                        x++;
                                    }
                                    if (pxWithAlpha)
                                    {
                                        /** Padding? **/
                                        if ((pxCount * 3) % 2 != 0)
                                        {
                                            bytes--;
                                            io.ReadByte();
                                        }
                                    }
                                    break;
                                case 0x03:
                                    for (var col = 0; col < pxCount; col++)
                                    {
                                        var offset = (y * Width) + x;
                                        this.PixelData[offset] = transparentPixel;
                                        this.PixelData[offset].A = 0;
                                        if (hasZBuffer)
                                        {
                                            this.ZBufferData[offset] = 255;
                                        }
                                        x++;
                                    }
                                    break;
                                case 0x06:
                                    for (var col = 0; col < pxCount; col++)
                                    {
                                        var pxIndex = io.ReadByte();
                                        bytes--;
                                        var offset = (y * Width) + x;
                                        var pxColor = palette.Colors[pxIndex];
                                        byte z = 0;
                                        if (pxColor.PackedValue == transparentPixel.PackedValue)
                                        {
                                            pxColor.A = 0;
                                            z = 255;
                                        }
                                        this.PixelData[offset] = pxColor;
                                        if (hasZBuffer)
                                        {
                                            this.ZBufferData[offset] = z;
                                        }
                                        x++;
                                    }
                                    if (pxCount % 2 != 0)
                                    {
                                        bytes--;
                                        io.ReadByte();
                                    }
                                    break;
                            }
                        }

                        /** If row isnt filled in, the rest is transparent **/
                        while (x < Width)
                        {
                            var offset = (y * Width) + x;
                            if (hasZBuffer)
                            {
                                this.ZBufferData[offset] = 255;
                            }
                            x++;
                        }
                        break;
                    /**  Leave the next count rows in the color channel filled with the transparent color, in the z-buffer channel filled with 255, and in the alpha channel filled with 0. **/
                    case 0x04:
                        for (var row = 0; row < count; row++)
                        {
                            for (var col = 0; col < Width; col++)
                            {
                                var offset = (row * Width) + col;
                                if (hasPixels)
                                {
                                    this.PixelData[offset] = transparentPixel;
                                }
                                if (hasAlpha)
                                {
                                    this.PixelData[offset].A = 0;
                                }
                                if (hasZBuffer)
                                {
                                    ZBufferData[offset] = 255;
                                }
                            }
                        }
                        break;
                    case 0x05:
                        endmarker = true;
                        break;
                }
                y++;
            }
        }
Exemplo n.º 35
0
        public void Read(uint version, IoBuffer io)
        {
            if (version == 1001)
            {
                var spriteVersion = io.ReadUInt32();
                var spriteSize = io.ReadUInt32();
            }

            this.Width = io.ReadUInt16();
            this.Height = io.ReadUInt16();
            this.Flags = io.ReadUInt32();
            //this.PaletteID = io.ReadUInt16();
            io.ReadUInt16();

            if (this.PaletteID == 0 || this.PaletteID == 0xA3A3)
            {
                this.PaletteID = (ushort)Parent.DefaultPaletteID;
            }

            TransparentColorIndex = io.ReadUInt16();

            var y = io.ReadInt16();
            var x = io.ReadInt16();
            this.Position = new Vector2(x, y);

            this.Decode(io);
        }
Exemplo n.º 36
0
        public void Read(uint version, IoBuffer io)
        {
            uint spriteCount = 0;
            if (version < 20003)
            {
                spriteCount = io.ReadUInt16();
                Direction = io.ReadByte();
                Zoom = io.ReadByte();
            }
            else
            {
                Direction = io.ReadUInt32();
                Zoom = io.ReadUInt32();
                spriteCount = io.ReadUInt32();
            }

            this.Sprites = new DGRPSprite[spriteCount];
            for (var i = 0; i < spriteCount; i++)
            {
                var sprite = new DGRPSprite(Parent);
                sprite.Read(version, io);
                this.Sprites[i] = sprite;
            }
        }
Exemplo n.º 37
0
        public void Read(uint version, IoBuffer io)
        {
            if (version == 1001)
            {
                var spriteFersion = io.ReadUInt32();
                var size = io.ReadUInt32();
                this.Version = spriteFersion;
            }
            else
            {
                this.Version = version;
            }

            var reserved = io.ReadUInt32();
            var height = io.ReadUInt16();
            var width = io.ReadUInt16();
            this.Init(width, height);
            this.Decode(io);
        }
Exemplo n.º 38
0
        private void Decode(IoBuffer io)
        {
            var palette = Parent.ChunkParent.Get<PALT>(Parent.PaletteID);
            if (palette == null)
            {
                palette = DEFAULT_PALT;
            }

            var y = 0;
            var endmarker = false;

            while (!endmarker)
            {
                var command = io.ReadByte();
                var count = io.ReadByte();

                switch (command)
                {
                    /** Start marker **/
                    case 0x00:
                    case 0x10:
                        break;
                    /** Fill row with pixel data **/
                    case 0x04:
                        var bytes = count - 2;
                        var x = 0;

                        while (bytes > 0)
                        {
                            var pxCommand = io.ReadByte();
                            var pxCount = io.ReadByte();
                            bytes -= 2;

                            switch (pxCommand)
                            {
                                /** Next {n} pixels are transparent **/
                                case 0x01:
                                    x += pxCount;
                                    break;
                                /** Next {n} pixels are the same palette color **/
                                case 0x02:
                                    var index = io.ReadByte();
                                    var padding = io.ReadByte();
                                    bytes -= 2;

                                    var color = palette.Colors[index];
                                    for (var j = 0; j < pxCount; j++)
                                    {
                                        this.SetPixel(x, y, color);
                                        x++;
                                    }
                                    break;
                                /** Next {n} pixels are specific palette colours **/
                                case 0x03:
                                    for (var j = 0; j < pxCount; j++)
                                    {
                                        var index2 = io.ReadByte();
                                        var color2 = palette.Colors[index2];
                                        this.SetPixel(x, y, color2);
                                        x++;
                                    }
                                    bytes -= pxCount;
                                    if (pxCount % 2 != 0)
                                    {
                                        //Padding
                                        io.ReadByte();
                                        bytes--;
                                    }
                                    break;
                            }
                        }

                        y++;
                        break;
                    /** End marker **/
                    case 0x05:
                        endmarker = true;
                        break;
                    /** Leave next rows transparent **/
                    case 0x09:
                        y += count;
                        continue;
                }

            }
        }
Exemplo n.º 39
0
        public void Read(uint version, IoBuffer io)
        {
            if (version < 20003)
            {
                //Unknown ignored "Type" field
                var type = io.ReadUInt16();
                SpriteID = io.ReadUInt16();
                SpriteFrameIndex = io.ReadUInt16();

                var flagsRaw = io.ReadUInt16();
                Flags = (DGRPSpriteFlags)flagsRaw;

                SpriteOffset.X = io.ReadInt16();
                SpriteOffset.Y = io.ReadInt16();

                if (version == 20001)
                {
                    ObjectOffset.Z = io.ReadFloat();
                }
            }
            else
            {
                SpriteID = io.ReadUInt32();
                SpriteFrameIndex = io.ReadUInt32();
                SpriteOffset.X = io.ReadInt32();
                SpriteOffset.Y = io.ReadInt32();
                ObjectOffset.Z = io.ReadFloat();
                Flags = (DGRPSpriteFlags)io.ReadUInt32();
                if (version == 20004)
                {
                    ObjectOffset.X = io.ReadFloat();
                    ObjectOffset.Y = io.ReadFloat();
                }
            }

            this.Flip = (Flags & DGRPSpriteFlags.Flip) == DGRPSpriteFlags.Flip;
        }