コード例 #1
0
        public void CreateEmptyOTB(string filePath, SupportedClient client, bool isTemporary = true)
        {
            ServerItem item = new ServerItem();

            item.SpriteHash = new byte[16];
            item.ClientId   = 100;
            item.ID         = 100;

            ServerItemList items = new ServerItemList();

            items.MajorVersion  = 3;
            items.MinorVersion  = client.OtbVersion;
            items.BuildNumber   = 1;
            items.ClientVersion = client.Version;
            items.Add(item);

            if (!File.Exists(filePath))
            {
                using (File.Create(filePath))
                {
                    ////
                }
            }

            OtbWriter writer = new OtbWriter(items);

            if (writer.Write(filePath))
            {
                this.Open(filePath);
                this.IsTemporary = isTemporary;
                this.Saved       = !isTemporary;
            }
        }
コード例 #2
0
ファイル: OtbLoader.cs プロジェクト: CkyLua/ItemEditor
        public static bool Open(string filename, ref ServerItemList items)
        {
            FileStream fileStream = new FileStream(filename, FileMode.Open);

            try
            {
                using (OtbLoader reader = new OtbLoader(fileStream))
                {
                    //get root node
                    BinaryReader nodeReader = reader.getRootNode();
                    if (nodeReader == null)
                    {
                        return(false);
                    }

                    nodeReader.ReadByte();                     //first byte of otb is 0
                    nodeReader.ReadUInt32();                   //4 bytes flags, unused

                    byte attr = nodeReader.ReadByte();
                    if ((RootAttribute)attr == RootAttribute.ROOT_ATTR_VERSION)
                    {
                        UInt16 datalen = nodeReader.ReadUInt16();
                        if (datalen != 140)                         // 4 + 4 + 4 + 1 * 128
                        {
                            Trace.WriteLine(String.Format("Size of version header is invalid, updated .otb version?"));
                            return(false);
                        }

                        items.dwMajorVersion = nodeReader.ReadUInt32();                         //major, file version
                        items.dwMinorVersion = nodeReader.ReadUInt32();                         //minor, client version
                        items.dwBuildNumber  = nodeReader.ReadUInt32();                         //build number, revision
                        nodeReader.BaseStream.Seek(128, SeekOrigin.Current);
                    }

                    nodeReader = reader.getChildNode();
                    if (nodeReader == null)
                    {
                        return(false);
                    }

                    do
                    {
                        ServerItem item = new ServerItem();

                        byte itemGroup = nodeReader.ReadByte();

                        switch ((ItemGroup)itemGroup)
                        {
                        case ItemGroup.NONE: item.type = ItemType.None; break;

                        case ItemGroup.GROUND: item.type = ItemType.Ground; break;

                        case ItemGroup.SPLASH: item.type = ItemType.Splash; break;

                        case ItemGroup.FLUID: item.type = ItemType.Fluid; break;

                        case ItemGroup.CONTAINER: item.type = ItemType.Container; break;

                        case ItemGroup.DEPRECATED: item.type = ItemType.Deprecated; break;

                        default: break;
                        }

                        ItemFlag flags = (ItemFlag)nodeReader.ReadUInt32();

                        item.isUnpassable    = ((flags & ItemFlag.BLOCK_SOLID) == ItemFlag.BLOCK_SOLID);
                        item.blockMissiles   = ((flags & ItemFlag.BLOCK_MISSILE) == ItemFlag.BLOCK_MISSILE);
                        item.blockPathfinder = ((flags & ItemFlag.BLOCK_PATHFINDER) == ItemFlag.BLOCK_PATHFINDER);
                        item.isPickupable    = ((flags & ItemFlag.PICKUPABLE) == ItemFlag.PICKUPABLE);
                        item.isMoveable      = ((flags & ItemFlag.MOVEABLE) == ItemFlag.MOVEABLE);
                        item.isStackable     = ((flags & ItemFlag.STACKABLE) == ItemFlag.STACKABLE);
                        item.alwaysOnTop     = ((flags & ItemFlag.ALWAYS_ON_TOP) == ItemFlag.ALWAYS_ON_TOP);
                        item.isVertical      = ((flags & ItemFlag.VERTICAL_WALL) == ItemFlag.VERTICAL_WALL);
                        item.isHorizontal    = ((flags & ItemFlag.HORIZONTAL_WALL) == ItemFlag.HORIZONTAL_WALL);
                        item.isHangable      = ((flags & ItemFlag.HANGABLE) == ItemFlag.HANGABLE);
                        item.isRotatable     = ((flags & ItemFlag.ROTABLE) == ItemFlag.ROTABLE);
                        item.isReadable      = ((flags & ItemFlag.READABLE) == ItemFlag.READABLE);
                        item.multiUse        = ((flags & ItemFlag.USEABLE) == ItemFlag.USEABLE);
                        item.hasElevation    = ((flags & ItemFlag.HAS_ELEVATION) == ItemFlag.HAS_ELEVATION);
                        item.ignoreLook      = ((flags & ItemFlag.IGNORE_LOOK) == ItemFlag.IGNORE_LOOK);
                        item.allowDistRead   = ((flags & ItemFlag.ALLOW_DISTANCE_READ) == ItemFlag.ALLOW_DISTANCE_READ);
                        item.isAnimation     = ((flags & ItemFlag.ANIMATION) == ItemFlag.ANIMATION);
                        item.fullGround      = ((flags & ItemFlag.FULL_GROUND) == ItemFlag.FULL_GROUND);

                        while (nodeReader.PeekChar() != -1)
                        {
                            ItemAttribute attribute = (ItemAttribute)nodeReader.ReadByte();
                            UInt16        datalen   = nodeReader.ReadUInt16();

                            switch (attribute)
                            {
                            case ItemAttribute.SERVER_ID:
                                item.id = nodeReader.ReadUInt16();
                                break;

                            case ItemAttribute.CLIENT_ID:
                                item.spriteId = nodeReader.ReadUInt16();
                                break;

                            case ItemAttribute.GROUND_SPEED:
                                item.groundSpeed = nodeReader.ReadUInt16();
                                break;

                            case ItemAttribute.NAME:
                                item.name = new string(nodeReader.ReadChars(datalen));
                                break;

                            case ItemAttribute.SPRITE_HASH:
                                item.SpriteHash = nodeReader.ReadBytes(datalen);
                                break;

                            case ItemAttribute.MINIMAP_COLOR:
                                item.minimapColor = nodeReader.ReadUInt16();
                                break;

                            case ItemAttribute.MAX_READ_WRITE_CHARS:
                                item.maxReadWriteChars = nodeReader.ReadUInt16();
                                break;

                            case ItemAttribute.MAX_READ_CHARS:
                                item.maxReadChars = nodeReader.ReadUInt16();
                                break;

                            case ItemAttribute.LIGHT:
                                item.lightLevel = nodeReader.ReadUInt16();
                                item.lightColor = nodeReader.ReadUInt16();
                                break;

                            case ItemAttribute.TOP_ORDER:
                                item.alwaysOnTopOrder = nodeReader.ReadByte();
                                break;

                            case ItemAttribute.TRADE_AS:
                                item.tradeAs = nodeReader.ReadUInt16();
                                break;

                            default:
                                nodeReader.BaseStream.Seek(datalen, SeekOrigin.Current);
                                break;
                            }
                        }

                        if (item.SpriteHash == null && item.type != ItemType.Deprecated)
                        {
                            item.SpriteHash = new byte[16];
                        }

                        items.Add(item);
                        nodeReader = reader.getNextNode();
                    } while (nodeReader != null);
                }
            }
            finally
            {
                fileStream.Close();
            }

            return(true);
        }