示例#1
0
        public static GND Load(MemoryStreamReader data)
        {
            string header = data.ReadBinaryString(4);

            if (!string.Equals(header, GND.Header))
            {
                throw new Exception("GroundLoader.Load: Header (" + header + ") is not \"GRGN\"");
            }

            string version    = Convert.ToString(data.ReadByte());
            string subversion = Convert.ToString(data.ReadByte());

            version += "." + subversion;

            GND gnd = new GND(version);

            gnd.width  = data.ReadUInt();
            gnd.height = data.ReadUInt();
            gnd.zoom   = data.ReadFloat();

            ParseTextures(gnd, data);
            ParseLightmaps(gnd, data);

            gnd.tiles    = ParseTiles(gnd, data);
            gnd.surfaces = ParseSurfaces(gnd, data);

            return(gnd);
        }
示例#2
0
        /// <summary>
        /// Load a GAT file
        /// </summary>
        /// <param name="data">GAT file data</param>
        public static GAT Load(MemoryStreamReader data)
        {
            string header = data.ReadBinaryString(4);

            //check for valid gat file
            if (!string.Equals(header, GAT.Header))
            {
                throw new Exception("AltitudeLoader.Load: Header (" + header + ") is not \"GRAT\"");
            }

            //load parameters
            string version    = Convert.ToString(data.ReadByte());
            string subversion = Convert.ToString(data.ReadByte());

            version += "." + subversion;
            uint width  = data.ReadUInt();
            uint height = data.ReadUInt();

            GAT.Cell[] cells = new GAT.Cell[width * height];

            //load the cells
            for (int i = 0; i < width * height; i++)
            {
                Vector4 heights = new Vector4();
                heights[0]       = data.ReadFloat() * 0.2f;         // height 1
                heights[1]       = data.ReadFloat() * 0.2f;         // height 2
                heights[2]       = data.ReadFloat() * 0.2f;         // height 3
                heights[3]       = data.ReadFloat() * 0.2f;         // height 4
                cells[i].Heights = heights;
                cells[i].type    = GAT.TYPE_TABLE[data.ReadUInt()]; // type
            }

            //exports
            return(new GAT(width, height, cells, version));
        }
示例#3
0
        public void Read(MemoryStreamReader br, int size)
        {
            byte invType = (byte)br.ReadByte();

            var count = (br.Length - br.Position) / BLOCK_SIZE;

            for (int i = 0; i < count; i++)
            {
                var itemInfo = new ItemInfo();

                itemInfo.index     = br.ReadShort();     // 2
                itemInfo.ItemID    = (int)br.ReadUInt(); // 4
                itemInfo.itemType  = br.ReadByte();      // 1
                itemInfo.amount    = br.ReadShort();     // 2
                itemInfo.wearState = (int)br.ReadUInt(); // 4
                itemInfo.slot      = new ItemInfo.Slot() // 8
                {
                    card1 = (int)br.ReadUInt(),
                    card2 = (int)br.ReadUInt(),
                    card3 = (int)br.ReadUInt(),
                    card4 = (int)br.ReadUInt()
                };
                itemInfo.expireTime = br.ReadInt();  // 4
                itemInfo.flag       = br.ReadByte(); // 4

                Inventory.Add(itemInfo);
            }
        }
示例#4
0
        public void Read(MemoryStreamReader br, int Size)
        {
            var size            = br.ReadShort();
            var normal_slot     = br.ReadByte(); //MIN_CHARS 15
            var premium_slot    = br.ReadByte(); //chars_vip;
            var billing_slot    = br.ReadByte();
            var producible_slot = br.ReadByte();
            var valid_slot      = br.ReadByte(); //MAX_CHARS 15

            br.Seek(9, SeekOrigin.Current);
        }
示例#5
0
 /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
 public void Read(MemoryStreamReader br, int size)
 {
     mapID      = (int)br.ReadUInt();
     id         = (int)br.ReadUInt();
     identified = br.ReadByte();
     x          = br.ReadShort();
     y          = br.ReadShort();
     amount     = br.ReadShort();
     subX       = br.ReadByte();
     subY       = br.ReadByte();
 }
示例#6
0
        public static SPR Load(MemoryStreamReader data)
        {
            var header = data.ReadBinaryString(2);

            if (!header.Equals(SPR.Header))
            {
                throw new Exception("SpriteLoader.Load: Header (" + header + ") is not \"SP\"");
            }

            SPR spr = new SPR();

            string subversion = Convert.ToString(data.ReadByte());
            string version    = Convert.ToString(data.ReadByte());

            version += "." + subversion;

            spr.version       = version;
            spr.indexedCount  = data.ReadUShort();
            spr._indexedCount = spr.indexedCount;

            var dversion = double.Parse(version, CultureInfo.InvariantCulture);

            if (dversion > 1.1)
            {
                spr.rgbaCount = data.ReadUShort();
            }

            spr.frames    = new SPR.Frame[spr.indexedCount + spr.rgbaCount];
            spr.rgbaIndex = spr.indexedCount;

            if (dversion < 2.1)
            {
                ReadIndexedImage(spr, data);
            }
            else
            {
                ReadIndexedImageRLE(spr, data);
            }

            ReadRgbaImage(spr, data);

            if (dversion > 1.0)
            {
                long position = data.Position;
                data.Seek(-1024, System.IO.SeekOrigin.End);
                spr.palette = data.ReadBytes(1024);
                data.Seek(position, System.IO.SeekOrigin.Begin);
            }

            return(spr);
        }
示例#7
0
 public void Read(MemoryStreamReader br, int size)
 {
     mapID          = (int)br.ReadUInt();
     id             = (int)br.ReadUInt();
     itemType       = br.ReadUShort();
     identified     = (byte)br.ReadByte();
     x              = br.ReadShort();
     y              = br.ReadShort();
     subX           = (byte)br.ReadByte();
     subY           = (byte)br.ReadByte();
     amount         = br.ReadShort();
     showDropEffect = br.ReadByte();
     dropEffectMode = br.ReadShort();
 }
示例#8
0
        public void Read(MemoryStreamReader br, int size)
        {
            int numChars = (int)((br.Length - 23) / 144);

            MaxSlots       = br.ReadByte();
            PremiumSlots   = br.ReadByte();
            AvailableSlots = br.ReadByte();

            br.Seek(20, SeekOrigin.Current);

            Chars = new List <CharacterData>();
            for (int i = 0; i < numChars; i++)
            {
                Chars.Add(CharacterData.parse(br));
            }
        }
示例#9
0
        public void Read(MemoryStreamReader br, int size)
        {
            LoginID1  = br.ReadInt();
            AccountID = br.ReadInt();
            LoginID2  = br.ReadInt();

            br.Seek(30, SeekOrigin.Current);

            Sex = (byte)br.ReadByte();

            br.Seek(17, SeekOrigin.Current);

            long serverCount = (br.Length - br.Position) / BLOCK_SIZE;

            Servers = new CharServerInfo[serverCount];
            for (int i = 0; i < serverCount; i++)
            {
                CharServerInfo csi = new CharServerInfo();
                csi.IP        = new IPAddress(br.ReadUInt());
                csi.Port      = br.ReadUShort();
                csi.Name      = br.ReadBinaryString(20);
                csi.UserCount = br.ReadUShort();
                csi.State     = br.ReadShort();
                csi.Property  = br.ReadUShort();

                Servers[i] = csi;
            }
        }
示例#10
0
 public void Read(MemoryStreamReader br, int size)
 {
     GID    = br.ReadUInt();
     type   = br.ReadByte();
     value  = br.ReadShort();
     value2 = br.ReadShort();
 }
示例#11
0
 public void Read(MemoryStreamReader br, int size)
 {
     index         = br.ReadShort();
     equipLocation = br.ReadInt();
     ViewID        = br.ReadShort();
     result        = br.ReadByte();
 }
示例#12
0
 /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
 public void Read(MemoryStreamReader fp, int size)
 {
     this.index  = fp.ReadShort();
     this.id     = fp.ReadShort();
     this.AID    = fp.ReadUInt();
     this.count  = fp.ReadShort();
     this.result = (byte)fp.ReadByte();
 }
示例#13
0
        public static ACT Load(MemoryStreamReader data)
        {
            string header = data.ReadBinaryString(2);

            if (!header.Equals(ACT.Header))
            {
                throw new Exception("ActionLoader.Load: Header \"" + header + "\" is not \"AC\"");
            }

            string subversion = Convert.ToString(data.ReadByte());
            string version    = Convert.ToString(data.ReadByte());

            version += "." + subversion;

            double dversion = double.Parse(version, CultureInfo.InvariantCulture);

            ACT act = new ACT();

            act.version = version;

            ReadActions(act, data);

            if (dversion >= 2.1)
            {
                //sounds
                var count = data.ReadInt();
                act.sounds = new string[count];

                for (int i = 0; i < count; i++)
                {
                    act.sounds[i] = data.ReadBinaryString(40);
                }

                //delay
                if (dversion >= 2.2)
                {
                    for (int i = 0; i < act.actions.Length; i++)
                    {
                        act.actions[i].delay = data.ReadFloat() * 25;
                    }
                }
            }

            return(act);
        }
示例#14
0
 public void Read(MemoryStreamReader fp, int size)
 {
     AID          = fp.ReadUInt();
     targetID     = fp.ReadUInt();
     xPos         = fp.ReadShort();
     yPos         = fp.ReadShort();
     SKID         = fp.ReadUShort();
     property     = fp.ReadUInt();
     delayTime    = fp.ReadUInt();
     isDisposable = (byte)fp.ReadByte();
 }
示例#15
0
        private static GND.Tile[] ParseTiles(GND gnd, MemoryStreamReader data)
        {
            uint count = data.ReadUInt();

            GND.Tile[] tiles = new GND.Tile[count];

            var ATLAS_COLS     = Math.Round(Math.Sqrt(gnd.textures.Length));
            var ATLAS_ROWS     = Math.Ceiling(Math.Sqrt(gnd.textures.Length));
            var ATLAS_WIDTH    = Math.Pow(2, Math.Ceiling(Math.Log(ATLAS_COLS * 258) / Math.Log(2)));
            var ATLAS_HEIGHT   = Math.Pow(2, Math.Ceiling(Math.Log(ATLAS_ROWS * 258) / Math.Log(2)));
            var ATLAS_FACTOR_U = ATLAS_COLS * 258 / ATLAS_WIDTH;
            var ATLAS_FACTOR_V = ATLAS_ROWS * 258 / ATLAS_HEIGHT;
            var ATLAS_PX_U     = 1 / 258f;
            var ATLAS_PX_V     = 1 / 258f;

            for (int i = 0; i < count; i++)
            {
                var tile = tiles[i] = new GND.Tile();
                tile.textureStart = new Vector4(data.ReadFloat(), data.ReadFloat(), data.ReadFloat(), data.ReadFloat());
                tile.textureEnd   = new Vector4(data.ReadFloat(), data.ReadFloat(), data.ReadFloat(), data.ReadFloat());
                tile.texture      = data.ReadUShort();
                tile.light        = data.ReadUShort();
                var r = (byte)data.ReadByte();
                var g = (byte)data.ReadByte();
                var b = (byte)data.ReadByte();
                var a = (byte)data.ReadByte();
                tile.color   = new byte[] { r, g, b, a };
                tile.texture = (ushort)gnd.textureLookupList[tile.texture];

                var start = tile.texture % ATLAS_COLS;
                var end   = Math.Floor(tile.texture / ATLAS_COLS);

                for (int j = 0; j < 4; j++)
                {
                    tile.textureStart[j] = (float)((start + tile.textureStart[j] * (1 - ATLAS_PX_U * 2) + ATLAS_PX_U) * ATLAS_FACTOR_U / ATLAS_COLS);
                    tile.textureEnd[j]   = (float)((end + tile.textureEnd[j] * (1 - ATLAS_PX_V * 2) + ATLAS_PX_V) * ATLAS_FACTOR_V / ATLAS_ROWS);
                }
            }

            return(tiles);
        }
示例#16
0
        private static void ReadIndexedImageRLE(SPR spr, MemoryStreamReader data)
        {
            for (int i = 0; i < spr.indexedCount; i++)
            {
                var width  = data.ReadUShort();
                var height = data.ReadUShort();
                var _data  = new byte[width * height];
                var end    = data.ReadUShort() + data.Position;

                var index = 0;
                while (data.Position < end)
                {
                    var c = _data[index++] = (byte)data.ReadByte();
                    if (c == 0)
                    {
                        var count = data.ReadByte();

                        if (count == 0)
                        {
                            _data[index++] = 0;
                        }
                        else
                        {
                            for (int j = 1; j < count; j++)
                            {
                                _data[index++] = c;
                            }
                        }
                    }
                }

                spr.frames[i] = new SPR.Frame()
                {
                    type   = SPR.TYPE_PAL,
                    width  = width,
                    height = height,
                    data   = _data
                };
            }
        }
示例#17
0
        public void Read(MemoryStreamReader br, int size)
        {
            Tick = br.ReadInt();
            var posDir = br.ReadPos();

            PosX = posDir[0];
            PosY = posDir[1];
            Dir  = posDir[2];

            br.Seek(2, SeekOrigin.Current);

            Font = br.ReadShort();
            Sex  = br.ReadByte();
        }
示例#18
0
 public void Read(MemoryStreamReader fp, int size)
 {
     ActionRequest = new EntityActionRequest()
     {
         GID         = fp.ReadUInt(),
         targetGID   = fp.ReadUInt(),
         startTime   = fp.ReadUInt(),
         sourceSpeed = (ushort)fp.ReadInt(),
         targetSpeed = (ushort)fp.ReadInt(),
         damage      = fp.ReadShort(),
         count       = fp.ReadShort(),
         action      = (ActionRequestType)fp.ReadByte(),
         leftDamage  = fp.ReadShort()
     };
 }
示例#19
0
        public void Read(MemoryStreamReader br, int size)
        {
            ActionRequest = new EntityActionRequest()
            {
                GID         = br.ReadUInt(),
                targetGID   = br.ReadUInt(),
                startTime   = br.ReadUInt(),
                sourceSpeed = (ushort)br.ReadInt(),
                targetSpeed = (ushort)br.ReadInt(),
                damage      = br.ReadInt()
            };

            br.Seek(1, SeekOrigin.Current);

            ActionRequest.count      = br.ReadShort();
            ActionRequest.action     = (ActionRequestType)br.ReadByte();
            ActionRequest.leftDamage = br.ReadInt();
        }
示例#20
0
        public void Read(MemoryStreamReader br, int size)
        {
            var count = Math.Max(0, (br.Length - br.Position) / BLOCK_SIZE);

            for (int i = 0; i < count; i++)
            {
                var skill = new SkillInfo()
                {
                    SkillID     = br.ReadShort(),
                    SkillType   = br.ReadInt(),
                    Level       = br.ReadShort(),
                    SpCost      = br.ReadShort(),
                    AttackRange = br.ReadShort(),
                    SkillName   = br.ReadBinaryString(24),
                    CanUpgrade  = br.ReadByte() == 1
                };

                skills.Add(skill);
            }
        }
示例#21
0
        public void Read(MemoryStreamReader br, int size)
        {
            byte invType = (byte)br.ReadByte();

            var count = (br.Length - br.Position) / BLOCK_SIZE;

            for (int i = 0; i < count; i++)
            {
                var itemInfo = new ItemInfo {
                    index = br.ReadShort(),

                    ItemID = (int)br.ReadUInt(),

                    itemType = br.ReadByte(),

                    location  = (int)br.ReadUInt(),
                    wearState = (int)br.ReadUInt(),
                    refine    = (byte)br.ReadByte(),

                    slot = new ItemInfo.Slot()
                    {
                        card1 = (int)br.ReadUInt(),
                        card2 = (int)br.ReadUInt(),
                        card3 = (int)br.ReadUInt(),
                        card4 = (int)br.ReadUInt()
                    },

                    expireTime        = br.ReadInt(),
                    bindOnEquip       = br.ReadUShort(),
                    wItemSpriteNumber = br.ReadUShort(),
                    randomOptionCount = (byte)br.ReadByte(),
                    options           = new List <ItemInfo.Option>()
                };

                for (int j = 0; j < 5; j++)
                {
                    itemInfo.options.Add(new ItemInfo.Option()
                    {
                        optIndex = br.ReadShort(),
                        value    = br.ReadShort(),
                        param1   = (byte)br.ReadByte()
                    });
                }

                itemInfo.flag = br.ReadByte();

                Inventory.Add(itemInfo);
            }
        }
示例#22
0
        /**
         * 0a37
         * <index>.W
         * <amount>.W
         * <name id>.W
         * <identified>.B
         * <damaged>.B
         * <refine>.B
         * <card1>.W
         * <card2>.W
         * <card3>.W
         * <card4>.W
         * <equip location>.L
         * <item type>.B
         * <result>.B
         * <expire time>.L
         * <bindOnEquipType>.W
         * { <option id>.W <option value>.W <option param>.B }*5
         * <favorite>.B
         * <view id>.W
         * (ZC_ITEM_PICKUP_ACK_V7)
         */
        public void Read(MemoryStreamReader br, int size)
        {
            itemInfo = new ItemInfo {
                index  = br.ReadShort(),
                amount = br.ReadShort(),
                ItemID = (int)br.ReadUInt()
            };
            IsIdentified       = br.ReadByte() == 1;
            itemInfo.IsDamaged = br.ReadByte() == 1;
            itemInfo.refine    = (byte)br.ReadByte();

            itemInfo.slot = new ItemInfo.Slot()
            {
                card1 = (int)br.ReadUInt(),
                card2 = (int)br.ReadUInt(),
                card3 = (int)br.ReadUInt(),
                card4 = (int)br.ReadUInt()
            };

            itemInfo.location    = br.ReadInt();
            itemInfo.itemType    = br.ReadByte();
            result               = br.ReadByte();
            itemInfo.expireTime  = br.ReadInt();
            itemInfo.bindOnEquip = br.ReadUShort();

            itemInfo.options = new List <ItemInfo.Option>();
            for (int j = 0; j < 5; j++)
            {
                itemInfo.options.Add(new ItemInfo.Option()
                {
                    optIndex = br.ReadShort(),
                    value    = br.ReadShort(),
                    param1   = (byte)br.ReadByte()
                });
            }

            IsFavorite      = br.ReadByte() == 1;
            itemInfo.flag   = IsIdentified ? 0x1 : 0;
            itemInfo.flag  |= IsFavorite ? 0x2 : 0;
            itemInfo.viewID = br.ReadShort();
        }
        public void HandlePacket(Packet message)
        {
            if (message is McpeWrapper wrapper)
            {
                var messages = new List <Packet>();

                // Get bytes to process
                ReadOnlyMemory <byte> payload = wrapper.payload;

                // Decrypt bytes

                if (CryptoContext != null && CryptoContext.UseEncryption)
                {
                    // This call copies the entire buffer, but what can we do? It is kind of compensated by not
                    // creating a new buffer when parsing the packet (only a mem-slice)
                    payload = CryptoUtils.Decrypt(payload, CryptoContext);
                }

                // Decompress bytes

                var stream = new MemoryStreamReader(payload.Slice(0, payload.Length - 4));                 // slice away adler
                if (stream.ReadByte() != 0x78)
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.Error($"Incorrect ZLib header. Expected 0x78 0x9C 0x{wrapper.Id:X2}\n{Packet.HexDump(wrapper.payload)}");
                    }
                    if (Log.IsDebugEnabled)
                    {
                        Log.Error($"Incorrect ZLib header. Decrypted 0x{wrapper.Id:X2}\n{Packet.HexDump(payload)}");
                    }
                    throw new InvalidDataException("Incorrect ZLib header. Expected 0x78 0x9C");
                }
                stream.ReadByte();
                using (var deflateStream = new DeflateStream(stream, CompressionMode.Decompress, false))
                {
                    using var s = new MemoryStream();
                    deflateStream.CopyTo(s);
                    s.Position = 0;

                    int count = 0;
                    // Get actual packet out of bytes
                    while (s.Position < s.Length)
                    {
                        count++;

                        uint len = VarInt.ReadUInt32(s);
                        ReadOnlyMemory <byte> internalBuffer = s.GetBuffer().AsMemory((int)s.Position, (int)len);
                        s.Position += len;
                        int id = internalBuffer.Span[0];

                        //if (Log.IsDebugEnabled)
                        //	Log.Debug($"0x{internalBuffer[0]:x2}\n{Packet.HexDump(internalBuffer)}");

                        try
                        {
                            messages.Add(PacketFactory.Create((byte)id, internalBuffer, "mcpe") ??
                                         new UnknownPacket((byte)id, internalBuffer));
                        }
                        catch (Exception)
                        {
                            if (Log.IsDebugEnabled)
                            {
                                Log.Warn($"Error parsing bedrock message #{count} id={id}\n{Packet.HexDump(internalBuffer)}");
                            }
                            //throw;
                            return;                             // Exit, but don't crash.
                        }
                    }

                    if (s.Length > s.Position)
                    {
                        throw new Exception("Have more data");
                    }
                }

                foreach (Packet msg in messages)
                {
                    // Temp fix for performance, take 1.
                    //var interact = msg as McpeInteract;
                    //if (interact?.actionId == 4 && interact.targetRuntimeEntityId == 0) continue;

                    msg.ReliabilityHeader = new ReliabilityHeader()
                    {
                        Reliability           = wrapper.ReliabilityHeader.Reliability,
                        ReliableMessageNumber = wrapper.ReliabilityHeader.ReliableMessageNumber,
                        OrderingChannel       = wrapper.ReliabilityHeader.OrderingChannel,
                        OrderingIndex         = wrapper.ReliabilityHeader.OrderingIndex,
                    };

                    RakOfflineHandler.TraceReceive(Log, msg);
                    try
                    {
                        HandleCustomPacket(msg);
                    }
                    catch (Exception e)
                    {
                        Log.Warn($"Bedrock message handler error", e);
                    }
                }

                wrapper.PutPool();
            }
            else if (message is UnknownPacket unknownPacket)
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Warn($"Received unknown packet 0x{unknownPacket.Id:X2}\n{Packet.HexDump(unknownPacket.Message)}");
                }

                unknownPacket.PutPool();
            }
            else
            {
                Log.Error($"Unhandled packet: {message.GetType().Name} 0x{message.Id:X2} for user: {_session.Username}, IP {_session.EndPoint.Address}");
                if (Log.IsDebugEnabled)
                {
                    Log.Warn($"Unknown packet 0x{message.Id:X2}\n{Packet.HexDump(message.Bytes)}");
                }
            }
        }
示例#24
0
        public void Read(MemoryStreamReader br, int size)
        {
            entityData = new EntitySpawnData();

            entityData.objecttype = (EntityType)br.ReadByte();

            entityData.AID = br.ReadUInt();
            entityData.GID = br.ReadUInt();

            entityData.speed       = br.ReadShort();
            entityData.bodyState   = br.ReadShort();
            entityData.healthState = br.ReadShort();

            entityData.effectState = br.ReadInt();

            entityData.job = br.ReadShort();

            entityData.head = br.ReadUShort();

            entityData.Weapon        = br.ReadUInt();
            entityData.Accessory     = br.ReadUShort();
            entityData.moveStartTime = br.ReadUInt();
            entityData.Shield        = br.ReadUInt();

            /**
             * might represent emblem/guild_id1/guild_id0
             * rA clif.cpp #1102
             */
            entityData.Accessory2 = br.ReadUShort();
            entityData.Accessory3 = br.ReadUShort();

            entityData.HairColor    = br.ReadShort();
            entityData.ClothesColor = br.ReadShort();
            entityData.headDir      = br.ReadShort();

            entityData.Robe = br.ReadUShort();

            entityData.GUID = br.ReadUInt();

            entityData.GEmblemVer = br.ReadShort();
            entityData.honor      = br.ReadShort();

            entityData.virtue = br.ReadInt();

            entityData.isPKModeON = (byte)br.ReadByte();
            entityData.sex        = (byte)br.ReadByte();

            entityData.PosDir = br.ReadPos2();

            entityData.xSize = (byte)br.ReadByte();
            entityData.ySize = (byte)br.ReadByte();
            entityData.state = (byte)br.ReadByte();

            entityData.clevel = br.ReadShort();
            entityData.font   = br.ReadShort();

            entityData.MaxHP = br.ReadInt();
            entityData.HP    = br.ReadInt();

            entityData.isBoss = (byte)br.ReadByte();

            entityData.body = br.ReadUShort();
            entityData.name = br.ReadBinaryString(24);
        }
示例#25
0
 /// Character status (ZC_STATUS).
 /// 00bd
 /// <stpoint>.W
 /// <str>.B <need str>.B
 /// <agi>.B <need agi>.B
 /// <vit>.B <need vit>.B
 /// <int>.B <need int>.B
 /// <dex>.B <need dex>.B
 /// <luk>.B <need luk>.B
 /// <atk>.W <atk2>.W
 /// <matk min>.W <matk max>.W
 /// <def>.W <def2>.W
 /// <mdef>.W <mdef2>.W
 /// <hit>.W
 /// <flee>.W <flee2>.W
 /// <crit>.W
 /// <aspd>.W <aspd2>.W
 public void Read(MemoryStreamReader br, int size)
 {
     stpoint  = br.ReadShort();
     str      = br.ReadByte();
     needStr  = br.ReadByte();
     agi      = br.ReadByte();
     needAgi  = br.ReadByte();
     vit      = br.ReadByte();
     needVit  = br.ReadByte();
     inte     = br.ReadByte();
     needInte = br.ReadByte();
     dex      = br.ReadByte();
     needDex  = br.ReadByte();
     luk      = br.ReadByte();
     needLuk  = br.ReadByte();
     atk      = br.ReadShort();
     atk2     = br.ReadShort();
     matkMin  = br.ReadShort();
     matkMax  = br.ReadShort();
     def      = br.ReadShort();
     def2     = br.ReadShort();
     mdef     = br.ReadShort();
     mdef2    = br.ReadShort();
     hit      = br.ReadShort();
     flee     = br.ReadShort();
     flee2    = br.ReadShort();
     crit     = br.ReadShort();
     aspd     = br.ReadShort();
     aspd2    = br.ReadShort();
 }
示例#26
0
        private static ACT.Frame ReadLayers(ACT act, MemoryStreamReader data)
        {
            var count   = data.ReadUInt();
            var layers  = new ACT.Layer[count];
            var version = double.Parse(act.version, CultureInfo.InvariantCulture);

            for (int i = 0; i < count; i++)
            {
                var layer = layers[i] = new ACT.Layer()
                {
                    pos      = new Vector2Int(data.ReadInt(), data.ReadInt()),
                    index    = data.ReadInt(),
                    isMirror = data.ReadInt() != 0,
                    scale    = Vector2.one,
                    color    = Color.white
                };

                // RoRebuild checks if only if it's greater
                if (version > 2.0)
                {
                    layer.color[0] = data.ReadByte() / 255f; //r
                    layer.color[1] = data.ReadByte() / 255f; //g
                    layer.color[2] = data.ReadByte() / 255f; //b
                    layer.color[3] = data.ReadByte() / 255f; //a

                    layer.scale[0] = data.ReadFloat();
                    layer.scale[1] = version <= 2.3 ? layer.scale[0] : data.ReadFloat();

                    layer.angle   = data.ReadInt();
                    layer.sprType = data.ReadInt();

                    if (version >= 2.5)
                    {
                        layer.width  = data.ReadInt();
                        layer.height = data.ReadInt();
                    }
                }
            }

            var soundId = version >= 2.0 ? data.ReadInt() : -1;

            Vector2Int[] pos = null;

            if (version >= 2.3)
            {
                pos = new Vector2Int[data.ReadInt()];
                for (int i = 0; i < pos.Length; i++)
                {
                    data.Seek(4, System.IO.SeekOrigin.Current);
                    pos[i] = new Vector2Int(data.ReadInt(), data.ReadInt());
                    data.Seek(4, System.IO.SeekOrigin.Current);
                }
            }

            return(new ACT.Frame()
            {
                layers = layers.Where(t => t.index >= 0).ToArray(),
                soundId = soundId,
                pos = pos
            });
        }
示例#27
0
        private void ParseSection(SubChunk section, ReadOnlyMemory <byte> data)
        {
            var reader = new MemoryStreamReader(data);

            var version = reader.ReadByte();

            if (version != 8)
            {
                throw new Exception("Wrong chunk version");
            }

            var storageSize = reader.ReadByte();

            for (int storage = 0; storage < storageSize; storage++)
            {
                byte paletteAndFlag = (byte)reader.ReadByte();
                bool isRuntime      = (paletteAndFlag & 1) != 0;
                if (isRuntime)
                {
                    throw new Exception("Can't use runtime for persistent storage.");
                }
                int bitsPerBlock  = paletteAndFlag >> 1;
                int blocksPerWord = (int)Math.Floor(32d / bitsPerBlock);
                int wordCount     = (int)Math.Ceiling(4096d / blocksPerWord);

                long blockIndex = reader.Position;
                reader.Position += wordCount * 4;

                int paletteSize = reader.ReadInt32();

                var palette = new Dictionary <int, int>();
                for (int j = 0; j < paletteSize; j++)
                {
                    var file = new NbtFile
                    {
                        BigEndian = false,
                        UseVarInt = false
                    };
                    file.LoadFromStream(reader, NbtCompression.None);
                    var tag = (NbtCompound)file.RootTag;

                    Block block = BlockFactory.GetBlockByName(tag["name"].StringValue);
                    if (block != null && block.GetType() != typeof(Block) && !(block is Air))
                    {
                        List <IBlockState> blockState = ReadBlockState(tag);
                        block.SetState(blockState);
                    }
                    else
                    {
                        block = new Air();
                    }

                    palette.Add(j, block.GetRuntimeId());
                }

                long nextStore = reader.Position;
                reader.Position = blockIndex;

                int position = 0;
                for (int wordIdx = 0; wordIdx < wordCount; wordIdx++)
                {
                    uint word = reader.ReadUInt32();
                    for (int block = 0; block < blocksPerWord; block++)
                    {
                        if (position >= 4096)
                        {
                            continue;                                           // padding bytes
                        }
                        int state = (int)((word >> ((position % blocksPerWord) * bitsPerBlock)) & ((1 << bitsPerBlock) - 1));
                        int x     = (position >> 8) & 0xF;
                        int y     = position & 0xF;
                        int z     = (position >> 4) & 0xF;
                        if (state > palette.Count)
                        {
                            Log.Error($"Got wrong state={state} from word. bitsPerBlock={bitsPerBlock}, blocksPerWord={blocksPerWord}, Word={word}");
                        }

                        if (storage == 0)
                        {
                            section.SetBlockByRuntimeId(x, y, z, palette[state]);
                        }
                        else
                        {
                            section.SetLoggedBlockByRuntimeId(x, y, z, palette[state]);
                        }
                        position++;
                    }
                }
                reader.Position = nextStore;
            }
        }
示例#28
0
 public void Read(MemoryStreamReader fp, int size)
 {
     this.GID  = fp.ReadUInt();
     this.type = (byte)fp.ReadByte();
 }
示例#29
0
    public static CharacterData parse(MemoryStreamReader br)
    {
        CharacterData cd = new CharacterData();

        cd.GID = br.ReadInt();
        cd.Exp = br.ReadInt();
        br.Seek(4, SeekOrigin.Current);
        cd.Zeny   = br.ReadInt();
        cd.JobExp = br.ReadInt();
        br.Seek(4, SeekOrigin.Current);
        cd.JobLevel    = br.ReadInt();
        cd.BodyState   = br.ReadInt();
        cd.HealthState = br.ReadInt();
        cd.Option      = br.ReadInt();
        cd.Karma       = br.ReadInt();
        cd.Manner      = br.ReadInt();

        cd.StatusPoint = br.ReadShort();

        cd.HP    = br.ReadInt();
        cd.MaxHP = br.ReadInt();

        cd.SP           = br.ReadShort();
        cd.MaxSP        = br.ReadShort();
        cd.Speed        = br.ReadShort();
        cd.Job          = br.ReadShort();
        cd.Hair         = br.ReadShort();
        cd.Body         = br.ReadShort();
        cd.Weapon       = br.ReadShort();
        cd.BaseLevel    = br.ReadShort();
        cd.SkillPoint   = br.ReadShort();
        cd.Accessory    = br.ReadShort();
        cd.Shield       = br.ReadShort();
        cd.Accessory2   = br.ReadShort();
        cd.Accessory3   = br.ReadShort();
        cd.HairColor    = br.ReadShort();
        cd.ClothesColor = br.ReadShort();

        cd.Name = br.ReadBinaryString(24);

        cd.Str = (byte)br.ReadByte();
        cd.Agi = (byte)br.ReadByte();
        cd.Vit = (byte)br.ReadByte();
        cd.Int = (byte)br.ReadByte();
        cd.Dex = (byte)br.ReadByte();
        cd.Luk = (byte)br.ReadByte();

        cd.Slot   = br.ReadShort();
        cd.Rename = br.ReadShort();

        cd.MapName = br.ReadBinaryString(16);

        cd.DeleteDate = br.ReadInt();
        cd.Robe       = br.ReadInt();
        cd.Moves      = br.ReadInt();
        cd.AddOns     = br.ReadInt();

        cd.Sex = br.ReadByte();

        return(cd);
    }
示例#30
0
 public void Read(MemoryStreamReader br, int size)
 {
     this.GID        = br.ReadUInt();
     this.objecttype = (byte)br.ReadByte();
     this.value      = br.ReadUInt();
 }