Exemple #1
0
        public bool LoadFromOtb(string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new Exception("Couldn't open file " + fileName);
            }

            using (FileReader reader = new FileReader(fileName))
            {
                BinaryNode node = reader.GetRootNode();

                PropertyReader props = reader.GetPropertyReader(node);

                props.ReadByte();
                props.ReadUInt32();

                byte attr = props.ReadByte();
                if ((RootAttr)attr == RootAttr.ROOT_ATTR_VERSION)
                {
                    var datalen = props.ReadUInt16();

                    if (datalen != 140)
                    {
                        throw new Exception("Size of version header is invalid.");
                    }

                    MajorVersion = props.ReadUInt32();
                    MinorVersion = props.ReadUInt32();
                    BuildNumber  = props.ReadUInt32();
                }
                node = node.Child;

                switch (MajorVersion)
                {
                case 1: throw new Exception("Old version of items.otb detected, a newer version of items.otb is required. Version: 1");

                case 2: throw new Exception("Old version of items.otb detected, a newer version of items.otb is required. Version: 2");

                case 3: return(LoadFromOtbVer3(node, reader));

                default: throw new Exception("Unsupported items.otb version (version " + MajorVersion);
                }
            }
        }
Exemple #2
0
        private void LoadOtbm()
        {
            if (!File.Exists(FileName))
            {
                throw new Exception(string.Format("File not found {0}.", FileName));
            }

            // FileName = fileName;
            MapName = Path.GetFileName(FileName);
            var tileLocations = new HashSet <ulong>();

            using (var reader = new FileReader(FileName))
            {
                BinaryNode node = reader.GetRootNode();

                PropertyReader props = reader.GetPropertyReader(node);

                props.ReadByte(); // junk?

                version = props.ReadUInt32();
                Width   = props.ReadUInt16();
                Height  = props.ReadUInt16();

                majorVersionItems = props.ReadUInt32();
                minorVersionItems = props.ReadUInt32();

                if (minorVersionItems != 40)
                {
                    if (Settings.GetBoolean(Key.BLOCKING_VERSION))
                    {
                        MessageBox.Show("O mapa não esta na versão 9.6. favor converter o mesmo para 9.6 no RME");
                        ReadOnly      = true;
                        this.FileName = "";
                        this.MapName  = "";
                        Generic.Abort();
                    }
                }

                if (version <= 0)
                {
                    //In otbm version 1 the count variable after splashes/fluidcontainers and stackables
                    //are saved as attributes instead, this solves alot of problems with items
                    //that is changed (stackable/charges/fluidcontainer/splash) during an update.
                    throw new Exception(
                              "This map needs to be upgraded by using the latest map editor version to be able to load correctly.");
                }


                Items = Global.items;

                if (version > 3)
                {
                    throw new Exception("Unknown OTBM version detected.");
                }

                if (majorVersionItems < 3)
                {
                    throw new Exception(
                              "This map needs to be upgraded by using the latest map editor version to be able to load correctly.");
                }

                if (majorVersionItems > Items.MajorVersion)
                {
                    throw new Exception("The map was saved with a different items.otb version, an upgraded items.otb is required.");
                }

                if (minorVersionItems > Items.MinorVersion)
                {
                    //Trace.WriteLine("This map needs an updated items.otb.");
                }

                node = node.Child;

                reader.clearRootNode();


                if ((OtMapNodeTypes)node.Type != OtMapNodeTypes.MAP_DATA)
                {
                    throw new Exception("Could not read data node.");
                }

                props = reader.GetPropertyReader(node);

                while (props.PeekChar() != -1)
                {
                    byte attribute = props.ReadByte();
                    switch ((OtMapAttribute)attribute)
                    {
                    case OtMapAttribute.DESCRIPTION:
                        var description = props.GetString();
                        //Descriptions.Add(description);
                        break;

                    case OtMapAttribute.EXT_SPAWN_FILE:
                        spawnFile = props.GetString();
                        break;

                    case OtMapAttribute.EXT_HOUSE_FILE:
                        houseFile = props.GetString();
                        break;

                    default:
                        throw new Exception("Unknown header node.");
                    }
                }

                BinaryNode nodeMapData = node.Child;
                while (nodeMapData != null)
                {
                    switch ((OtMapNodeTypes)nodeMapData.Type)
                    {
                    case OtMapNodeTypes.TILE_AREA:
                        ParseTileArea(reader, nodeMapData, replaceTiles, tileLocations);
                        break;

                    case OtMapNodeTypes.TOWNS:
                        ParseTowns(reader, nodeMapData);
                        break;
                    }
                    nodeMapData = nodeMapData.Next;
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            //LoadSpawn(Path.Combine(Path.GetDirectoryName(fileName), spawnFile), tileLocations);
        }